Use Java 8 lambdas instead of anonymous classes in compiler modules
This commit is contained in:
@@ -88,14 +88,7 @@ public class RunUtils {
|
||||
|
||||
public static void executeOnSeparateThread(@NotNull RunSettings settings) {
|
||||
assert !settings.waitForEnd : "Use execute() instead";
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
RunUtils.run(settings);
|
||||
}
|
||||
});
|
||||
|
||||
t.start();
|
||||
new Thread(() -> run(settings)).start();
|
||||
}
|
||||
|
||||
private static RunResult run(RunSettings settings) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -501,14 +500,11 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
public static StackValue genToString(StackValue receiver, Type receiverType) {
|
||||
return StackValue.operation(JAVA_STRING_TYPE, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
Type type = stringValueOfType(receiverType);
|
||||
receiver.put(type, v);
|
||||
v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;", false);
|
||||
return null;
|
||||
}
|
||||
return StackValue.operation(JAVA_STRING_TYPE, v -> {
|
||||
Type type = stringValueOfType(receiverType);
|
||||
receiver.put(type, v);
|
||||
v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;", false);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -573,18 +569,15 @@ public class AsmUtil {
|
||||
return StackValue.cmp(opToken, leftType, left, right);
|
||||
}
|
||||
|
||||
return StackValue.operation(Type.BOOLEAN_TYPE, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
left.put(leftType, v);
|
||||
right.put(rightType, v);
|
||||
genAreEqualCall(v);
|
||||
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
|
||||
left.put(leftType, v);
|
||||
right.put(rightType, v);
|
||||
genAreEqualCall(v);
|
||||
|
||||
if (opToken == KtTokens.EXCLEQ || opToken == KtTokens.EXCLEQEQEQ) {
|
||||
genInvertBoolean(v);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
if (opToken == KtTokens.EXCLEQ || opToken == KtTokens.EXCLEQEQEQ) {
|
||||
genInvertBoolean(v);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -130,12 +128,7 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
|
||||
@NotNull
|
||||
public List<OutputFile> getCurrentOutput() {
|
||||
return ContainerUtil.map(generators.keySet(), new Function<String, OutputFile>() {
|
||||
@Override
|
||||
public OutputFile fun(String relativeClassFilePath) {
|
||||
return new OutputClassFile(relativeClassFilePath);
|
||||
}
|
||||
});
|
||||
return CollectionsKt.map(generators.keySet(), OutputClassFile::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,16 +176,13 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
|
||||
private PackagePartRegistry buildNewPackagePartRegistry(@NotNull FqName packageFqName) {
|
||||
String packageFqNameAsString = packageFqName.asString();
|
||||
return new PackagePartRegistry() {
|
||||
@Override
|
||||
public void addPart(@NotNull String partShortName, @Nullable String facadeShortName) {
|
||||
PackageParts packageParts = partsGroupedByPackage.get(packageFqNameAsString);
|
||||
if (packageParts == null) {
|
||||
packageParts = new PackageParts(packageFqNameAsString);
|
||||
partsGroupedByPackage.put(packageFqNameAsString, packageParts);
|
||||
}
|
||||
packageParts.addPart(partShortName, facadeShortName);
|
||||
return (partShortName, facadeShortName) -> {
|
||||
PackageParts packageParts = partsGroupedByPackage.get(packageFqNameAsString);
|
||||
if (packageParts == null) {
|
||||
packageParts = new PackageParts(packageFqNameAsString);
|
||||
partsGroupedByPackage.put(packageFqNameAsString, packageParts);
|
||||
}
|
||||
packageParts.addPart(partShortName, facadeShortName);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
|
||||
@@ -49,7 +48,6 @@ import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.MethodVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
@@ -241,12 +239,9 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
|
||||
ProtoBuf.Function functionProto = serializer.functionProto(freeLambdaDescriptor).build();
|
||||
|
||||
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.SYNTHETIC_CLASS, 0, new Function1<AnnotationVisitor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(AnnotationVisitor av) {
|
||||
writeAnnotationData(av, serializer, functionProto);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.SYNTHETIC_CLASS, 0, av -> {
|
||||
writeAnnotationData(av, serializer, functionProto);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -284,22 +279,19 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
public StackValue putInstanceOnStack(@NotNull ExpressionCodegen codegen, @Nullable StackValue functionReferenceReceiver) {
|
||||
return StackValue.operation(
|
||||
functionReferenceTarget != null ? K_FUNCTION : asmType,
|
||||
new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
if (isConst(closure)) {
|
||||
v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor());
|
||||
}
|
||||
else {
|
||||
v.anew(asmType);
|
||||
v.dup();
|
||||
|
||||
codegen.pushClosureOnStack(classDescriptor, true, codegen.defaultCallGenerator, functionReferenceReceiver);
|
||||
v.invokespecial(asmType.getInternalName(), "<init>", constructor.getDescriptor(), false);
|
||||
}
|
||||
|
||||
return Unit.INSTANCE;
|
||||
v -> {
|
||||
if (isConst(closure)) {
|
||||
v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor());
|
||||
}
|
||||
else {
|
||||
v.anew(asmType);
|
||||
v.dup();
|
||||
|
||||
codegen.pushClosureOnStack(classDescriptor, true, codegen.defaultCallGenerator, functionReferenceReceiver);
|
||||
v.invokespecial(asmType.getInternalName(), "<init>", constructor.getDescriptor(), false);
|
||||
}
|
||||
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,15 +17,11 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
public interface CompilationErrorHandler {
|
||||
|
||||
CompilationErrorHandler THROW_EXCEPTION = new CompilationErrorHandler() {
|
||||
@Override
|
||||
public void reportException(Throwable exception, String fileUrl) {
|
||||
if (exception instanceof RuntimeException) {
|
||||
throw (RuntimeException) exception;
|
||||
}
|
||||
throw new IllegalStateException(exception);
|
||||
CompilationErrorHandler THROW_EXCEPTION = (exception, fileUrl) -> {
|
||||
if (exception instanceof RuntimeException) {
|
||||
throw (RuntimeException) exception;
|
||||
}
|
||||
throw new IllegalStateException(exception);
|
||||
};
|
||||
|
||||
void reportException(Throwable exception, String fileUrl);
|
||||
|
||||
@@ -22,19 +22,11 @@ import org.jetbrains.kotlin.psi.KtParameter;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
|
||||
|
||||
public interface DefaultParameterValueLoader {
|
||||
|
||||
StackValue genValue(ValueParameterDescriptor descriptor, ExpressionCodegen codegen);
|
||||
|
||||
DefaultParameterValueLoader DEFAULT = new DefaultParameterValueLoader() {
|
||||
@Override
|
||||
public StackValue genValue(
|
||||
ValueParameterDescriptor descriptor,
|
||||
ExpressionCodegen codegen
|
||||
) {
|
||||
KtParameter jetParameter = (KtParameter) descriptorToDeclaration(descriptor);
|
||||
assert jetParameter != null;
|
||||
return codegen.gen(jetParameter.getDefaultValue());
|
||||
}
|
||||
DefaultParameterValueLoader DEFAULT = (descriptor, codegen) -> {
|
||||
KtParameter ktParameter = (KtParameter) descriptorToDeclaration(descriptor);
|
||||
assert ktParameter != null;
|
||||
return codegen.gen(ktParameter.getDefaultValue());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,8 +20,8 @@ import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Trinity;
|
||||
import gnu.trove.TObjectIntHashMap;
|
||||
import gnu.trove.TObjectIntIterator;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -115,15 +115,7 @@ public class FrameMap {
|
||||
descriptors.add(Trinity.create(descriptor, varIndex, varSize));
|
||||
}
|
||||
|
||||
Collections.sort(descriptors, new Comparator<Trinity<DeclarationDescriptor, Integer, Integer>>() {
|
||||
@Override
|
||||
public int compare(
|
||||
Trinity<DeclarationDescriptor, Integer, Integer> left,
|
||||
Trinity<DeclarationDescriptor, Integer, Integer> right
|
||||
) {
|
||||
return left.second - right.second;
|
||||
}
|
||||
});
|
||||
Collections.sort(descriptors, Comparator.comparingInt(left -> left.second));
|
||||
|
||||
sb.append("size=").append(myMaxIndex);
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -65,6 +62,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
@@ -79,7 +77,8 @@ import java.util.Set;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isNullableAny;
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isAnnotationOrJvmInterfaceWithoutDefaults;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isJvm8InterfaceWithDefaultsMember;
|
||||
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.METHOD_FOR_FUNCTION;
|
||||
import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
|
||||
import static org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.*;
|
||||
@@ -277,20 +276,17 @@ public class FunctionCodegen {
|
||||
v, "Default Impl delegate in interface", Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC,
|
||||
new Method(defaultImplMethod.getName() + JvmAbi.DEFAULT_IMPLS_DELEGATE_SUFFIX, defaultImplMethod.getDescriptor()),
|
||||
element, JvmDeclarationOrigin.NO_ORIGIN,
|
||||
state, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter adapter) {
|
||||
Method interfaceMethod = typeMapper.mapAsmMethod(functionDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
Type type = typeMapper.mapOwner(functionDescriptor);
|
||||
generateDelegateToMethodBody(
|
||||
-1, adapter,
|
||||
interfaceMethod,
|
||||
type.getInternalName(),
|
||||
Opcodes.INVOKESPECIAL,
|
||||
true
|
||||
);
|
||||
return null;
|
||||
}
|
||||
state, adapter -> {
|
||||
Method interfaceMethod = typeMapper.mapAsmMethod(functionDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
Type type = typeMapper.mapOwner(functionDescriptor);
|
||||
generateDelegateToMethodBody(
|
||||
-1, adapter,
|
||||
interfaceMethod,
|
||||
type.getInternalName(),
|
||||
Opcodes.INVOKESPECIAL,
|
||||
true
|
||||
);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -642,14 +638,11 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
private static String joinParameterNames(@NotNull List<VariableDescriptor> variables) {
|
||||
return org.jetbrains.kotlin.utils.StringsKt.join(CollectionsKt.map(variables, new Function1<VariableDescriptor, String>() {
|
||||
@Override
|
||||
public String invoke(VariableDescriptor descriptor) {
|
||||
// stub for anonymous destructuring declaration entry
|
||||
if (descriptor.getName().isSpecial()) return "$_$";
|
||||
return descriptor.getName().asString();
|
||||
}
|
||||
}), "_");
|
||||
// stub for anonymous destructuring declaration entry
|
||||
return StringsKt.join(
|
||||
CollectionsKt.map(variables, descriptor -> descriptor.getName().isSpecial() ? "$_$" : descriptor.getName().asString()),
|
||||
"_"
|
||||
);
|
||||
}
|
||||
|
||||
private static void generateFacadeDelegateMethodBody(
|
||||
@@ -815,23 +808,16 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
public static boolean isThereOverriddenInKotlinClass(@NotNull CallableMemberDescriptor descriptor) {
|
||||
return CollectionsKt.any(getAllOverriddenDescriptors(descriptor), new Function1<CallableMemberDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(CallableMemberDescriptor descriptor) {
|
||||
return !(descriptor.getContainingDeclaration() instanceof JavaClassDescriptor) &&
|
||||
isClass(descriptor.getContainingDeclaration());
|
||||
}
|
||||
});
|
||||
return CollectionsKt.any(
|
||||
getAllOverriddenDescriptors(descriptor),
|
||||
overridden -> !(overridden.getContainingDeclaration() instanceof JavaClassDescriptor) &&
|
||||
isClass(overridden.getContainingDeclaration())
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Function1<FunctionDescriptor, Method> getSignatureMapper(@NotNull KotlinTypeMapper typeMapper) {
|
||||
return new Function1<FunctionDescriptor, Method>() {
|
||||
@Override
|
||||
public Method invoke(FunctionDescriptor descriptor) {
|
||||
return typeMapper.mapAsmMethod(descriptor);
|
||||
}
|
||||
};
|
||||
return typeMapper::mapAsmMethod;
|
||||
}
|
||||
|
||||
public static boolean isMethodOfAny(@NotNull FunctionDescriptor descriptor) {
|
||||
@@ -862,18 +848,15 @@ public class FunctionCodegen {
|
||||
if (!(value instanceof ArrayValue)) return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
ArrayValue arrayValue = (ArrayValue) value;
|
||||
|
||||
List<String> strings = ContainerUtil.mapNotNull(
|
||||
List<String> strings = CollectionsKt.mapNotNull(
|
||||
arrayValue.getValue(),
|
||||
new Function<ConstantValue<?>, String>() {
|
||||
@Override
|
||||
public String fun(ConstantValue<?> constant) {
|
||||
if (constant instanceof KClassValue) {
|
||||
KClassValue classValue = (KClassValue) constant;
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(classValue.getValue());
|
||||
return mapper.mapClass(classDescriptor).getInternalName();
|
||||
}
|
||||
return null;
|
||||
(ConstantValue<?> constant) -> {
|
||||
if (constant instanceof KClassValue) {
|
||||
KClassValue classValue = (KClassValue) constant;
|
||||
ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(classValue.getValue());
|
||||
return mapper.mapClass(classDescriptor).getInternalName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
return ArrayUtil.toStringArray(strings);
|
||||
|
||||
@@ -21,8 +21,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -395,12 +393,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
KotlinBuiltIns builtIns = DescriptorUtilsKt.getBuiltIns(descriptor);
|
||||
if (!isSubclass(descriptor, builtIns.getCollection())) return;
|
||||
|
||||
if (CollectionsKt.any(DescriptorUtilsKt.getAllSuperclassesWithoutAny(descriptor), new Function1<ClassDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(ClassDescriptor classDescriptor) {
|
||||
return !(classDescriptor instanceof JavaClassDescriptor) && isSubclass(classDescriptor, builtIns.getCollection());
|
||||
}
|
||||
})) return;
|
||||
if (CollectionsKt.any(DescriptorUtilsKt.getAllSuperclassesWithoutAny(descriptor),
|
||||
classDescriptor -> !(classDescriptor instanceof JavaClassDescriptor) &&
|
||||
isSubclass(classDescriptor, builtIns.getCollection()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions(
|
||||
Name.identifier("toArray"), NoLookupLocation.FROM_BACKEND
|
||||
@@ -735,15 +732,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
functionCodegen.generateDefaultIfNeeded(
|
||||
context.intoFunction(function), function, OwnerKind.IMPLEMENTATION,
|
||||
new DefaultParameterValueLoader() {
|
||||
@Override
|
||||
public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) {
|
||||
assert ((ClassDescriptor) function.getContainingDeclaration()).isData()
|
||||
: "Function container must have [data] modifier: " + function;
|
||||
PropertyDescriptor property = bindingContext.get(BindingContext.VALUE_PARAMETER_AS_PROPERTY, valueParameter);
|
||||
assert property != null : "Copy function doesn't correspond to any property: " + function;
|
||||
return codegen.intermediateValueForProperty(property, false, null, StackValue.LOCAL_0);
|
||||
}
|
||||
(valueParameter, codegen) -> {
|
||||
assert ((ClassDescriptor) function.getContainingDeclaration()).isData()
|
||||
: "Function container must have [data] modifier: " + function;
|
||||
PropertyDescriptor property = bindingContext.get(BindingContext.VALUE_PARAMETER_AS_PROPERTY, valueParameter);
|
||||
assert property != null : "Copy function doesn't correspond to any property: " + function;
|
||||
return codegen.intermediateValueForProperty(property, false, null, StackValue.LOCAL_0);
|
||||
},
|
||||
null
|
||||
);
|
||||
@@ -785,14 +779,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
private void generateEnumValueOfMethod() {
|
||||
FunctionDescriptor valueOfFunction =
|
||||
CollectionsKt.single(descriptor.getStaticScope().getContributedFunctions(ENUM_VALUE_OF, NoLookupLocation.FROM_BACKEND), new Function1<FunctionDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(FunctionDescriptor descriptor) {
|
||||
return DescriptorUtilsKt.isEnumValueOfMethod(descriptor);
|
||||
}
|
||||
});
|
||||
MethodVisitor mv = v.newMethod(JvmDeclarationOriginKt.OtherOrigin(myClass, valueOfFunction), ACC_PUBLIC | ACC_STATIC, ENUM_VALUE_OF.asString(),
|
||||
"(Ljava/lang/String;)" + classAsmType.getDescriptor(), null, null);
|
||||
CollectionsKt.single(descriptor.getStaticScope().getContributedFunctions(ENUM_VALUE_OF, NoLookupLocation.FROM_BACKEND),
|
||||
DescriptorUtilsKt::isEnumValueOfMethod);
|
||||
MethodVisitor mv =
|
||||
v.newMethod(JvmDeclarationOriginKt.OtherOrigin(myClass, valueOfFunction), ACC_PUBLIC | ACC_STATIC, ENUM_VALUE_OF.asString(),
|
||||
"(Ljava/lang/String;)" + classAsmType.getDescriptor(), null, null);
|
||||
if (!state.getClassBuilderMode().generateBodies) return;
|
||||
|
||||
mv.visitCode();
|
||||
@@ -991,13 +982,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
if (JvmAbi.isCompanionObjectWithBackingFieldsInOuter(descriptor)) {
|
||||
ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen();
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
return parentCodegen.createOrGetClInitCodegen();
|
||||
}
|
||||
});
|
||||
generateInitializers(((ImplementationBodyCodegen) getParentCodegen())::createOrGetClInitCodegen);
|
||||
}
|
||||
else {
|
||||
generateInitializers(codegen);
|
||||
@@ -1061,12 +1046,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateInitializers(@NotNull ExpressionCodegen codegen) {
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
return codegen;
|
||||
}
|
||||
});
|
||||
generateInitializers(() -> codegen);
|
||||
}
|
||||
|
||||
private void generateClosureInitialization(@NotNull InstructionAdapter iv) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -176,14 +175,10 @@ public class JvmCodegenUtil {
|
||||
}
|
||||
|
||||
public static boolean hasAbstractMembers(@NotNull ClassDescriptor classDescriptor) {
|
||||
return CollectionsKt.any(DescriptorUtils.getAllDescriptors(classDescriptor.getDefaultType().getMemberScope()),
|
||||
new Function1<DeclarationDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof CallableMemberDescriptor &&
|
||||
((CallableMemberDescriptor) descriptor).getModality() == ABSTRACT;
|
||||
}
|
||||
}
|
||||
return CollectionsKt.any(
|
||||
DescriptorUtils.getAllDescriptors(classDescriptor.getDefaultType().getMemberScope()),
|
||||
descriptor -> descriptor instanceof CallableMemberDescriptor &&
|
||||
((CallableMemberDescriptor) descriptor).getModality() == ABSTRACT
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -816,12 +816,9 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
|
||||
int flags = isScript ? JvmAnnotationNames.METADATA_SCRIPT_FLAG : 0;
|
||||
|
||||
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.CLASS, flags, new Function1<AnnotationVisitor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(AnnotationVisitor av) {
|
||||
writeAnnotationData(av, serializer, classProto);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.CLASS, flags, av -> {
|
||||
writeAnnotationData(av, serializer, classProto);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.annotation.AnnotatedSimple;
|
||||
import org.jetbrains.kotlin.codegen.context.FieldOwnerContext;
|
||||
@@ -38,7 +36,6 @@ import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.serialization.DescriptorSerializer;
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf;
|
||||
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -100,12 +97,7 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
|
||||
}
|
||||
|
||||
if (state.getClassBuilderMode().generateBodies) {
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
return createOrGetClInitCodegen();
|
||||
}
|
||||
});
|
||||
generateInitializers(this::createOrGetClInitCodegen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,12 +123,9 @@ public class PackagePartCodegen extends MemberCodegen<KtFile> {
|
||||
DescriptorSerializer.createTopLevel(new JvmSerializerExtension(v.getSerializationBindings(), state));
|
||||
ProtoBuf.Package packageProto = serializer.packagePartProto(element.getPackageFqName(), members).build();
|
||||
|
||||
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.FILE_FACADE, 0, new Function1<AnnotationVisitor, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(AnnotationVisitor av) {
|
||||
writeAnnotationData(av, serializer, packageProto);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.FILE_FACADE, 0, av -> {
|
||||
writeAnnotationData(av, serializer, packageProto);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
||||
import org.jetbrains.kotlin.codegen.context.MethodContext;
|
||||
@@ -202,12 +201,7 @@ public class ScriptCodegen extends MemberCodegen<KtScript> {
|
||||
|
||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, methodContext, state, this);
|
||||
|
||||
generateInitializers(new Function0<ExpressionCodegen>() {
|
||||
@Override
|
||||
public ExpressionCodegen invoke() {
|
||||
return codegen;
|
||||
}
|
||||
});
|
||||
generateInitializers(() -> codegen);
|
||||
|
||||
iv.areturn(Type.VOID_TYPE);
|
||||
}
|
||||
|
||||
@@ -65,12 +65,9 @@ public abstract class StackValue {
|
||||
private static final String NULLABLE_LONG_TYPE_NAME = "java/lang/Long";
|
||||
|
||||
public static final StackValue.Local LOCAL_0 = local(0, OBJECT_TYPE);
|
||||
private static final StackValue UNIT = operation(UNIT_TYPE, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
v.visitFieldInsn(GETSTATIC, UNIT_TYPE.getInternalName(), JvmAbi.INSTANCE_FIELD, UNIT_TYPE.getDescriptor());
|
||||
return null;
|
||||
}
|
||||
private static final StackValue UNIT = operation(UNIT_TYPE, v -> {
|
||||
v.visitFieldInsn(GETSTATIC, UNIT_TYPE.getInternalName(), JvmAbi.INSTANCE_FIELD, UNIT_TYPE.getDescriptor());
|
||||
return null;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-7
@@ -22,7 +22,6 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import kotlin.Pair;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes;
|
||||
@@ -675,12 +674,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
|
||||
expression,
|
||||
bindingContext,
|
||||
shouldInlineConstVals,
|
||||
new Function1<ConstantValue<?>, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(@NotNull ConstantValue<?> constant) {
|
||||
return constant instanceof EnumValue || constant instanceof NullValue;
|
||||
}
|
||||
}
|
||||
constant -> constant instanceof EnumValue || constant instanceof NullValue
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen.context;
|
||||
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
@@ -160,12 +159,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
this.closure = closure;
|
||||
this.thisDescriptor = thisDescriptor;
|
||||
this.enclosingLocalLookup = localLookup;
|
||||
this.outerExpression = LockBasedStorageManager.NO_LOCKS.createNullableLazyValue(new Function0<StackValue.Field>() {
|
||||
@Override
|
||||
public StackValue.Field invoke() {
|
||||
return computeOuterExpression();
|
||||
}
|
||||
});
|
||||
this.outerExpression = LockBasedStorageManager.NO_LOCKS.createNullableLazyValue(this::computeOuterExpression);
|
||||
|
||||
if (parentContext != null) {
|
||||
parentContext.addChild(this);
|
||||
|
||||
+4
-10
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.codegen.inline;
|
||||
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil;
|
||||
import org.jetbrains.kotlin.codegen.ClassBuilder;
|
||||
@@ -350,15 +349,10 @@ public class AnonymousObjectTransformer extends ObjectTransformer<AnonymousObjec
|
||||
original.access, original.name, original.desc, original.signature,
|
||||
ArrayUtil.toStringArray(original.exceptions)
|
||||
),
|
||||
new Function0<MethodVisitor>() {
|
||||
@Override
|
||||
public MethodVisitor invoke() {
|
||||
return builder.newMethod(
|
||||
NO_ORIGIN, original.access, original.name, original.desc, original.signature,
|
||||
ArrayUtil.toStringArray(original.exceptions)
|
||||
);
|
||||
}
|
||||
}
|
||||
() -> builder.newMethod(
|
||||
NO_ORIGIN, original.access, original.name, original.desc, original.signature,
|
||||
ArrayUtil.toStringArray(original.exceptions)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||
@@ -272,15 +271,12 @@ public class InlineCodegen extends CallGenerator {
|
||||
}
|
||||
|
||||
SMAPAndMethodNode resultInCache = InlineCacheKt.getOrPut(
|
||||
state.getInlineCache().getMethodNodeById(), methodId, new Function0<SMAPAndMethodNode>() {
|
||||
@Override
|
||||
public SMAPAndMethodNode invoke() {
|
||||
SMAPAndMethodNode result = doCreateMethodNodeFromCompiled(directMember, state, asmMethod);
|
||||
if (result == null) {
|
||||
throw new IllegalStateException("Couldn't obtain compiled function body for " + functionDescriptor);
|
||||
}
|
||||
return result;
|
||||
state.getInlineCache().getMethodNodeById(), methodId, () -> {
|
||||
SMAPAndMethodNode result = doCreateMethodNodeFromCompiled(directMember, state, asmMethod);
|
||||
if (result == null) {
|
||||
throw new IllegalStateException("Couldn't obtain compiled function body for " + functionDescriptor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -315,13 +311,8 @@ public class InlineCodegen extends CallGenerator {
|
||||
) {
|
||||
if (isBuiltInArrayIntrinsic(callableDescriptor)) {
|
||||
ClassId classId = IntrinsicArrayConstructorsKt.getClassId();
|
||||
byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), classId, new Function0<byte[]>() {
|
||||
@Override
|
||||
public byte[] invoke() {
|
||||
return IntrinsicArrayConstructorsKt.getBytecode();
|
||||
}
|
||||
});
|
||||
|
||||
byte[] bytes =
|
||||
InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), classId, IntrinsicArrayConstructorsKt::getBytecode);
|
||||
return InlineCodegenUtil.getMethodNode(bytes, asmMethod.getName(), asmMethod.getDescriptor(), classId);
|
||||
}
|
||||
|
||||
@@ -332,23 +323,19 @@ public class InlineCodegen extends CallGenerator {
|
||||
|
||||
ClassId containerId = containingClasses.getImplClassId();
|
||||
|
||||
byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), containerId, new Function0<byte[]>() {
|
||||
@Override
|
||||
public byte[] invoke() {
|
||||
VirtualFile file = InlineCodegenUtil.findVirtualFile(state, containerId);
|
||||
if (file == null) {
|
||||
throw new IllegalStateException("Couldn't find declaration file for " + containerId);
|
||||
}
|
||||
try {
|
||||
return file.contentsToByteArray();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), containerId, () -> {
|
||||
VirtualFile file = InlineCodegenUtil.findVirtualFile(state, containerId);
|
||||
if (file == null) {
|
||||
throw new IllegalStateException("Couldn't find declaration file for " + containerId);
|
||||
}
|
||||
try {
|
||||
return file.contentsToByteArray();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return InlineCodegenUtil.getMethodNode(bytes, asmMethod.getName(), asmMethod.getDescriptor(), containerId);
|
||||
}
|
||||
|
||||
@@ -455,14 +442,8 @@ public class InlineCodegen extends CallGenerator {
|
||||
|
||||
CallableMemberDescriptor descriptor = getLabelOwnerDescriptor(codegen.getContext());
|
||||
Set<String> labels = getDeclarationLabels(DescriptorToSourceUtils.descriptorToDeclaration(descriptor), descriptor);
|
||||
LabelOwner labelOwner = new LabelOwner() {
|
||||
@Override
|
||||
public boolean isMyLabel(@NotNull String name) {
|
||||
return labels.contains(name);
|
||||
}
|
||||
};
|
||||
|
||||
List<MethodInliner.PointForExternalFinallyBlocks> infos = MethodInliner.processReturns(adapter, labelOwner, true, null);
|
||||
List<MethodInliner.PointForExternalFinallyBlocks> infos = MethodInliner.processReturns(adapter, labels::contains, true, null);
|
||||
generateAndInsertFinallyBlocks(
|
||||
adapter, infos, ((StackValue.Local) remapper.remap(parameters.getArgsSizeOnStack() + 1).value).index
|
||||
);
|
||||
@@ -759,19 +740,16 @@ public class InlineCodegen extends CallGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = infos.length - 1; i >= 0; i--) {
|
||||
ParameterInfo info = infos[i];
|
||||
if (!info.isSkippedOrRemapped()) {
|
||||
Type type = info.type;
|
||||
StackValue.Local local = StackValue.local(index[i], type);
|
||||
local.store(StackValue.onStack(type), codegen.v);
|
||||
if (info instanceof CapturedParamInfo) {
|
||||
info.setRemapValue(local);
|
||||
((CapturedParamInfo) info).setSynthetic(true);
|
||||
}
|
||||
Runnable runnable = () -> {
|
||||
for (int i = infos.length - 1; i >= 0; i--) {
|
||||
ParameterInfo info = infos[i];
|
||||
if (!info.isSkippedOrRemapped()) {
|
||||
Type type = info.type;
|
||||
StackValue.Local local = StackValue.local(index[i], type);
|
||||
local.store(StackValue.onStack(type), codegen.v);
|
||||
if (info instanceof CapturedParamInfo) {
|
||||
info.setRemapValue(local);
|
||||
((CapturedParamInfo) info).setSynthetic(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface LabelOwner {
|
||||
boolean isMyLabel(@NotNull String name);
|
||||
|
||||
LabelOwner SKIP_ALL = new LabelOwner() {
|
||||
@Override
|
||||
public boolean isMyLabel(@NotNull String name) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
LabelOwner SKIP_ALL = name -> false;
|
||||
|
||||
LabelOwner NOT_APPLICABLE = new LabelOwner() {
|
||||
@Override
|
||||
public boolean isMyLabel(@NotNull String name) {
|
||||
throw new RuntimeException("This operation not applicable for current context");
|
||||
}
|
||||
LabelOwner NOT_APPLICABLE = name -> {
|
||||
throw new RuntimeException("This operation not applicable for current context");
|
||||
};
|
||||
}
|
||||
|
||||
+1
-7
@@ -46,7 +46,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen.inline;
|
||||
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
@@ -430,12 +429,7 @@ public class MaxStackFrameSizeAndLocalsCalculator extends MaxLocalsCalculator {
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
private LabelWrapper getLabelWrapper(Label label) {
|
||||
return ContainerUtil.getOrCreate(labelWrappersMap, label, new Factory<LabelWrapper>() {
|
||||
@Override
|
||||
public LabelWrapper create() {
|
||||
return new LabelWrapper(label);
|
||||
}
|
||||
});
|
||||
return ContainerUtil.<Label, LabelWrapper>getOrCreate(labelWrappersMap, label, () -> new LabelWrapper(label));
|
||||
}
|
||||
|
||||
private void increaseStackSize(int variation) {
|
||||
|
||||
+7
-16
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.codegen.optimization.boxing;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.StrictBasicValue;
|
||||
import org.jetbrains.kotlin.codegen.optimization.common.UtilKt;
|
||||
@@ -100,12 +99,7 @@ public class RedundantBoxingMethodTransformer extends MethodTransformer {
|
||||
|
||||
List<BasicValue> variableValues = getValuesStoredOrLoadedToVariable(localVariableNode, node, frames);
|
||||
|
||||
Collection<BasicValue> boxed = CollectionsKt.filter(variableValues, new Function1<BasicValue, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(BasicValue value) {
|
||||
return value instanceof BoxedBasicValue;
|
||||
}
|
||||
});
|
||||
Collection<BasicValue> boxed = CollectionsKt.filter(variableValues, value -> value instanceof BoxedBasicValue);
|
||||
|
||||
if (boxed.isEmpty()) continue;
|
||||
|
||||
@@ -127,16 +121,13 @@ public class RedundantBoxingMethodTransformer extends MethodTransformer {
|
||||
}
|
||||
|
||||
private static boolean isUnsafeToRemoveBoxingForConnectedValues(List<BasicValue> usedValues, Type unboxedType) {
|
||||
return CollectionsKt.any(usedValues, new Function1<BasicValue, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(BasicValue input) {
|
||||
if (input == StrictBasicValue.UNINITIALIZED_VALUE) return false;
|
||||
if (!(input instanceof BoxedBasicValue)) return true;
|
||||
return CollectionsKt.any(usedValues, input -> {
|
||||
if (input == StrictBasicValue.UNINITIALIZED_VALUE) return false;
|
||||
if (!(input instanceof BoxedBasicValue)) return true;
|
||||
|
||||
BoxedValueDescriptor descriptor = ((BoxedBasicValue) input).getDescriptor();
|
||||
return !descriptor.isSafeToRemove() ||
|
||||
!(descriptor.getUnboxedType().equals(unboxedType));
|
||||
}
|
||||
BoxedValueDescriptor descriptor = ((BoxedBasicValue) input).getDescriptor();
|
||||
return !descriptor.isSafeToRemove() ||
|
||||
!(descriptor.getUnboxedType().equals(unboxedType));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import kotlin.Pair;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment;
|
||||
@@ -469,13 +468,11 @@ public class KotlinTypeMapper {
|
||||
) {
|
||||
return TypeSignatureMappingKt.mapType(
|
||||
kotlinType, AsmTypeFactory.INSTANCE, mode, typeMappingConfiguration, signatureVisitor,
|
||||
new Function3<KotlinType, Type, TypeMappingMode, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(KotlinType kotlinType, Type type, TypeMappingMode mode) {
|
||||
writeGenericType(kotlinType, type, signatureVisitor, mode);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
(ktType, asmType, typeMappingMode) -> {
|
||||
writeGenericType(ktType, asmType, signatureVisitor, typeMappingMode);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,10 +23,7 @@ import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface Progress {
|
||||
Progress DEAF = new Progress() {
|
||||
@Override
|
||||
public void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile) {
|
||||
}
|
||||
Progress DEAF = (sourceFiles, outputFile) -> {
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -158,14 +158,8 @@ public class SwitchCodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, shouldInlineConstVals, new Function1<ConstantValue<?>, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(
|
||||
@NotNull ConstantValue<?> constant
|
||||
) {
|
||||
return constant instanceof IntegerValueConstant;
|
||||
}
|
||||
});
|
||||
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, shouldInlineConstVals,
|
||||
constant -> constant instanceof IntegerValueConstant);
|
||||
}
|
||||
|
||||
private static boolean isStringConstantsSwitch(
|
||||
@@ -179,13 +173,7 @@ public class SwitchCodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, shouldInlineConstVals, new Function1<ConstantValue<?>, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(
|
||||
@NotNull ConstantValue<?> constant
|
||||
) {
|
||||
return constant instanceof StringValue || constant instanceof NullValue;
|
||||
}
|
||||
});
|
||||
return checkAllItemsAreConstantsSatisfying(expression, bindingContext, shouldInlineConstVals,
|
||||
constant -> constant instanceof StringValue || constant instanceof NullValue);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -81,14 +81,11 @@ public class GroupingMessageCollector implements MessageCollector {
|
||||
private Collection<String> sortedKeys() {
|
||||
List<String> sortedKeys = new ArrayList<String>(groupedMessages.keySet());
|
||||
// ensure that messages with no location i.e. perf, incomplete hierarchy are always reported first
|
||||
Collections.sort(sortedKeys, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
if (o1 == o2) return 0;
|
||||
if (o1 == null) return -1;
|
||||
if (o2 == null) return 1;
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
Collections.sort(sortedKeys, (o1, o2) -> {
|
||||
if (o1 == o2) return 0;
|
||||
if (o1 == null) return -1;
|
||||
if (o2 == null) return 1;
|
||||
return o1.compareTo(o2);
|
||||
});
|
||||
return sortedKeys;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -314,12 +313,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
return version;
|
||||
}
|
||||
|
||||
List<String> versionStrings = ArraysKt.map(LanguageVersion.values(), new Function1<LanguageVersion, String>() {
|
||||
@Override
|
||||
public String invoke(LanguageVersion version) {
|
||||
return version.getDescription();
|
||||
}
|
||||
});
|
||||
List<String> versionStrings = ArraysKt.map(LanguageVersion.values(), LanguageVersion::getDescription);
|
||||
String message = "Unknown " + versionOf + " version: " + value + "\n" +
|
||||
"Supported " + versionOf + " versions: " + StringsKt.join(versionStrings, ", ");
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
|
||||
@@ -21,13 +21,12 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
||||
@@ -226,16 +225,12 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
}
|
||||
|
||||
private static void reportCompiledSourcesList(@NotNull MessageCollector messageCollector, @NotNull List<KtFile> sourceFiles) {
|
||||
Iterable<String> fileNames = ContainerUtil.map(sourceFiles, new Function<KtFile, String>() {
|
||||
@Override
|
||||
public String fun(@Nullable KtFile file) {
|
||||
assert file != null;
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
return FileUtil.toSystemDependentName(virtualFile.getPath());
|
||||
}
|
||||
return file.getName() + "(no virtual file)";
|
||||
Iterable<String> fileNames = CollectionsKt.map(sourceFiles, file -> {
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
return FileUtil.toSystemDependentName(virtualFile.getPath());
|
||||
}
|
||||
return file.getName() + "(no virtual file)";
|
||||
});
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Compiling source files: " + Joiner.on(", ").join(fileNames),
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
|
||||
+10
-13
@@ -185,22 +185,19 @@ public class CompileEnvironmentUtil {
|
||||
continue;
|
||||
}
|
||||
|
||||
SequencesKt.forEach(FilesKt.walkTopDown(new File(sourceRootPath)), new Function1<File, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(File file) {
|
||||
if (file.isFile()) {
|
||||
VirtualFile originalVirtualFile = localFileSystem.findFileByPath(file.getAbsolutePath());
|
||||
VirtualFile virtualFile = originalVirtualFile != null ? virtualFileCreator.create(originalVirtualFile) : null;
|
||||
if (virtualFile != null && !processedFiles.contains(virtualFile)) {
|
||||
processedFiles.add(virtualFile);
|
||||
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
|
||||
if (psiFile instanceof KtFile) {
|
||||
result.add((KtFile) psiFile);
|
||||
}
|
||||
SequencesKt.forEach(FilesKt.walkTopDown(new File(sourceRootPath)), file -> {
|
||||
if (file.isFile()) {
|
||||
VirtualFile originalVirtualFile = localFileSystem.findFileByPath(file.getAbsolutePath());
|
||||
VirtualFile virtualFile = originalVirtualFile != null ? virtualFileCreator.create(originalVirtualFile) : null;
|
||||
if (virtualFile != null && !processedFiles.contains(virtualFile)) {
|
||||
processedFiles.add(virtualFile);
|
||||
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
|
||||
if (psiFile instanceof KtFile) {
|
||||
result.add((KtFile) psiFile);
|
||||
}
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+7
-14
@@ -39,7 +39,6 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
||||
@@ -207,20 +206,14 @@ public class KotlinJavaPsiFacade {
|
||||
);
|
||||
|
||||
List<PsiElementFinder> nonKotlinFinders = ArraysKt.filter(
|
||||
getProject().getExtensions(PsiElementFinder.EP_NAME), new Function1<PsiElementFinder, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(PsiElementFinder finder) {
|
||||
return (finder instanceof KotlinSafeClassFinder) ||
|
||||
!(finder instanceof NonClasspathClassFinder || finder instanceof KotlinFinderMarker || finder instanceof PsiElementFinderImpl);
|
||||
}
|
||||
});
|
||||
getProject().getExtensions(PsiElementFinder.EP_NAME),
|
||||
finder -> (finder instanceof KotlinSafeClassFinder) ||
|
||||
!(finder instanceof NonClasspathClassFinder ||
|
||||
finder instanceof KotlinFinderMarker ||
|
||||
finder instanceof PsiElementFinderImpl)
|
||||
);
|
||||
|
||||
elementFinders.addAll(CollectionsKt.map(nonKotlinFinders, new Function1<PsiElementFinder, KotlinPsiElementFinderWrapper>() {
|
||||
@Override
|
||||
public KotlinPsiElementFinderWrapper invoke(PsiElementFinder finder) {
|
||||
return wrap(finder);
|
||||
}
|
||||
}));
|
||||
elementFinders.addAll(CollectionsKt.map(nonKotlinFinders, KotlinJavaPsiFacade::wrap));
|
||||
|
||||
return elementFinders.toArray(new KotlinPsiElementFinderWrapper[elementFinders.size()]);
|
||||
}
|
||||
|
||||
+16
-19
@@ -27,27 +27,24 @@ import java.util.List;
|
||||
|
||||
public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
|
||||
private static final DiagnosticParameterRenderer<ConflictingJvmDeclarationsData> CONFLICTING_JVM_DECLARATIONS_DATA = new DiagnosticParameterRenderer<ConflictingJvmDeclarationsData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull ConflictingJvmDeclarationsData data, @NotNull RenderingContext context) {
|
||||
List<DeclarationDescriptor> renderedDescriptors = new ArrayList<DeclarationDescriptor>();
|
||||
for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
|
||||
DeclarationDescriptor descriptor = origin.getDescriptor();
|
||||
if (descriptor != null) {
|
||||
renderedDescriptors.add(descriptor);
|
||||
private static final DiagnosticParameterRenderer<ConflictingJvmDeclarationsData> CONFLICTING_JVM_DECLARATIONS_DATA =
|
||||
(data, context) -> {
|
||||
List<DeclarationDescriptor> renderedDescriptors = new ArrayList<DeclarationDescriptor>();
|
||||
for (JvmDeclarationOrigin origin : data.getSignatureOrigins()) {
|
||||
DeclarationDescriptor descriptor = origin.getDescriptor();
|
||||
if (descriptor != null) {
|
||||
renderedDescriptors.add(descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(renderedDescriptors, MemberComparator.INSTANCE);
|
||||
RenderingContext.Impl renderingContext = new RenderingContext.Impl(renderedDescriptors);
|
||||
Collections.sort(renderedDescriptors, MemberComparator.INSTANCE);
|
||||
RenderingContext.Impl renderingContext = new RenderingContext.Impl(renderedDescriptors);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (DeclarationDescriptor descriptor : renderedDescriptors) {
|
||||
sb.append(" ").append(Renderers.COMPACT.render(descriptor, renderingContext)).append("\n");
|
||||
}
|
||||
return ("The following declarations have the same JVM signature (" + data.getSignature().getName() + data.getSignature().getDesc() + "):\n" + sb).trim();
|
||||
}
|
||||
};
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (DeclarationDescriptor descriptor : renderedDescriptors) {
|
||||
sb.append(" ").append(Renderers.COMPACT.render(descriptor, renderingContext)).append("\n");
|
||||
}
|
||||
return ("The following declarations have the same JVM signature (" + data.getSignature().getName() + data.getSignature().getDesc() + "):\n" + sb).trim();
|
||||
};
|
||||
|
||||
private static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap("JVM");
|
||||
static {
|
||||
|
||||
+17
-29
@@ -17,10 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm.kotlinSignature;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -130,20 +127,19 @@ public class SignaturesPropagationData {
|
||||
|
||||
for (ValueParameterDescriptor originalParam : parameters) {
|
||||
int originalIndex = originalParam.getIndex();
|
||||
List<TypeAndName> typesFromSuperMethods = ContainerUtil.map(superFunctions,
|
||||
new Function<FunctionDescriptor, TypeAndName>() {
|
||||
@Override
|
||||
public TypeAndName fun(FunctionDescriptor superFunction) {
|
||||
ReceiverParameterDescriptor receiver = superFunction.getExtensionReceiverParameter();
|
||||
int index = receiver != null ? originalIndex - 1 : originalIndex;
|
||||
if (index == -1) {
|
||||
assert receiver != null : "can't happen: index is -1, while function is not extension";
|
||||
return new TypeAndName(receiver.getType(), originalParam.getName());
|
||||
}
|
||||
ValueParameterDescriptor parameter = superFunction.getValueParameters().get(index);
|
||||
return new TypeAndName(parameter.getType(), parameter.getName());
|
||||
List<TypeAndName> typesFromSuperMethods = CollectionsKt.map(
|
||||
superFunctions,
|
||||
superFunction -> {
|
||||
ReceiverParameterDescriptor receiver = superFunction.getExtensionReceiverParameter();
|
||||
int index = receiver != null ? originalIndex - 1 : originalIndex;
|
||||
if (index == -1) {
|
||||
assert receiver != null : "can't happen: index is -1, while function is not extension";
|
||||
return new TypeAndName(receiver.getType(), originalParam.getName());
|
||||
}
|
||||
});
|
||||
ValueParameterDescriptor parameter = superFunction.getValueParameters().get(index);
|
||||
return new TypeAndName(parameter.getType(), parameter.getName());
|
||||
}
|
||||
);
|
||||
|
||||
VarargCheckResult varargCheckResult = checkVarargInSuperFunctions(originalParam);
|
||||
|
||||
@@ -180,12 +176,7 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasStableParameterNames = CollectionsKt.any(superFunctions, new Function1<FunctionDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(FunctionDescriptor descriptor) {
|
||||
return descriptor.hasStableParameterNames();
|
||||
}
|
||||
});
|
||||
boolean hasStableParameterNames = CollectionsKt.any(superFunctions, CallableDescriptor::hasStableParameterNames);
|
||||
|
||||
return new ValueParameters(resultReceiverType, resultParameters, hasStableParameterNames);
|
||||
}
|
||||
@@ -224,13 +215,10 @@ public class SignaturesPropagationData {
|
||||
}
|
||||
|
||||
// sorting for diagnostic stability
|
||||
Collections.sort(superFunctions, new Comparator<FunctionDescriptor>() {
|
||||
@Override
|
||||
public int compare(@NotNull FunctionDescriptor fun1, @NotNull FunctionDescriptor fun2) {
|
||||
FqNameUnsafe fqName1 = getFqName(fun1.getContainingDeclaration());
|
||||
FqNameUnsafe fqName2 = getFqName(fun2.getContainingDeclaration());
|
||||
return fqName1.asString().compareTo(fqName2.asString());
|
||||
}
|
||||
Collections.sort(superFunctions, (fun1, fun2) -> {
|
||||
FqNameUnsafe fqName1 = getFqName(fun1.getContainingDeclaration());
|
||||
FqNameUnsafe fqName2 = getFqName(fun2.getContainingDeclaration());
|
||||
return fqName1.asString().compareTo(fqName2.asString());
|
||||
});
|
||||
return superFunctions;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.intellij.util.containers.Stack;
|
||||
import kotlin.Pair;
|
||||
import kotlin.TuplesKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -55,30 +54,27 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CheckerTestUtil {
|
||||
public static final Comparator<ActualDiagnostic> DIAGNOSTIC_COMPARATOR = new Comparator<ActualDiagnostic>() {
|
||||
@Override
|
||||
public int compare(@NotNull ActualDiagnostic o1, @NotNull ActualDiagnostic o2) {
|
||||
List<TextRange> ranges1 = o1.diagnostic.getTextRanges();
|
||||
List<TextRange> ranges2 = o2.diagnostic.getTextRanges();
|
||||
int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size();
|
||||
for (int i = 0; i < minNumberOfRanges; i++) {
|
||||
TextRange range1 = ranges1.get(i);
|
||||
TextRange range2 = ranges2.get(i);
|
||||
int startOffset1 = range1.getStartOffset();
|
||||
int startOffset2 = range2.getStartOffset();
|
||||
if (startOffset1 != startOffset2) {
|
||||
// Start early -- go first
|
||||
return startOffset1 - range2.getStartOffset();
|
||||
}
|
||||
int endOffset1 = range1.getEndOffset();
|
||||
int endOffset2 = range2.getEndOffset();
|
||||
if (endOffset1 != endOffset2) {
|
||||
// start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return endOffset2 - endOffset1;
|
||||
}
|
||||
public static final Comparator<ActualDiagnostic> DIAGNOSTIC_COMPARATOR = (o1, o2) -> {
|
||||
List<TextRange> ranges1 = o1.diagnostic.getTextRanges();
|
||||
List<TextRange> ranges2 = o2.diagnostic.getTextRanges();
|
||||
int minNumberOfRanges = ranges1.size() < ranges2.size() ? ranges1.size() : ranges2.size();
|
||||
for (int i = 0; i < minNumberOfRanges; i++) {
|
||||
TextRange range1 = ranges1.get(i);
|
||||
TextRange range2 = ranges2.get(i);
|
||||
int startOffset1 = range1.getStartOffset();
|
||||
int startOffset2 = range2.getStartOffset();
|
||||
if (startOffset1 != startOffset2) {
|
||||
// Start early -- go first
|
||||
return startOffset1 - range2.getStartOffset();
|
||||
}
|
||||
int endOffset1 = range1.getEndOffset();
|
||||
int endOffset2 = range2.getEndOffset();
|
||||
if (endOffset1 != endOffset2) {
|
||||
// start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return endOffset2 - endOffset1;
|
||||
}
|
||||
return ranges1.size() - ranges2.size();
|
||||
}
|
||||
return ranges1.size() - ranges2.size();
|
||||
};
|
||||
|
||||
private static final String IGNORE_DIAGNOSTIC_PARAMETER = "IGNORE";
|
||||
@@ -104,12 +100,7 @@ public class CheckerTestUtil {
|
||||
|
||||
List<Pair<MultiTargetPlatform, BindingContext>> sortedBindings = CollectionsKt.sortedWith(
|
||||
implementingModulesBindings,
|
||||
new Comparator<Pair<MultiTargetPlatform, BindingContext>>() {
|
||||
@Override
|
||||
public int compare(Pair<MultiTargetPlatform, BindingContext> o1, Pair<MultiTargetPlatform, BindingContext> o2) {
|
||||
return o1.getFirst().compareTo(o2.getFirst());
|
||||
}
|
||||
}
|
||||
(o1, o2) -> o1.getFirst().compareTo(o2.getFirst())
|
||||
);
|
||||
|
||||
for (Pair<MultiTargetPlatform, BindingContext> binding : sortedBindings) {
|
||||
@@ -299,12 +290,7 @@ public class CheckerTestUtil {
|
||||
|
||||
for (TextDiagnostic expectedDiagnostic : expectedDiagnostics) {
|
||||
Map.Entry<ActualDiagnostic, TextDiagnostic> actualDiagnosticEntry = CollectionsKt.firstOrNull(
|
||||
actualDiagnostics.entrySet(), new Function1<Map.Entry<ActualDiagnostic, TextDiagnostic>, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(Map.Entry<ActualDiagnostic, TextDiagnostic> entry) {
|
||||
return expectedDiagnostic.getDescription().equals(entry.getValue().getDescription());
|
||||
}
|
||||
}
|
||||
actualDiagnostics.entrySet(), entry -> expectedDiagnostic.getDescription().equals(entry.getValue().getDescription())
|
||||
);
|
||||
|
||||
if (actualDiagnosticEntry != null) {
|
||||
@@ -403,12 +389,7 @@ public class CheckerTestUtil {
|
||||
public static StringBuffer addDiagnosticMarkersToText(@NotNull PsiFile psiFile, @NotNull Collection<ActualDiagnostic> diagnostics) {
|
||||
return addDiagnosticMarkersToText(
|
||||
psiFile, diagnostics, Collections.<ActualDiagnostic, TextDiagnostic>emptyMap(),
|
||||
new Function<PsiFile, String>() {
|
||||
@Override
|
||||
public String fun(PsiFile file) {
|
||||
return file.getText();
|
||||
}
|
||||
}
|
||||
PsiElement::getText
|
||||
);
|
||||
}
|
||||
|
||||
@@ -623,12 +604,9 @@ public class CheckerTestUtil {
|
||||
diagnosticDescriptors.add(
|
||||
new DiagnosticDescriptor(range.getStartOffset(), range.getEndOffset(), diagnosticsGroupedByRanges.get(range)));
|
||||
}
|
||||
Collections.sort(diagnosticDescriptors, new Comparator<DiagnosticDescriptor>() {
|
||||
@Override
|
||||
public int compare(@NotNull DiagnosticDescriptor d1, @NotNull DiagnosticDescriptor d2) {
|
||||
// Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
|
||||
}
|
||||
Collections.sort(diagnosticDescriptors, (d1, d2) -> {
|
||||
// Start early -- go first; start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return (d1.start != d2.start) ? d1.start - d2.start : d2.end - d1.end;
|
||||
});
|
||||
return diagnosticDescriptors;
|
||||
}
|
||||
@@ -746,12 +724,7 @@ public class CheckerTestUtil {
|
||||
if (renderer instanceof AbstractDiagnosticWithParametersRenderer) {
|
||||
//noinspection unchecked
|
||||
Object[] renderParameters = ((AbstractDiagnosticWithParametersRenderer) renderer).renderParameters(diagnostic);
|
||||
List<String> parameters = ContainerUtil.map(renderParameters, new Function<Object, String>() {
|
||||
@Override
|
||||
public String fun(Object o) {
|
||||
return o != null ? o.toString() : "null";
|
||||
}
|
||||
});
|
||||
List<String> parameters = ContainerUtil.map(renderParameters, Object::toString);
|
||||
return new TextDiagnostic(diagnosticName, actualDiagnostic.platform, parameters);
|
||||
}
|
||||
return new TextDiagnostic(diagnosticName, actualDiagnostic.platform, null);
|
||||
@@ -817,12 +790,7 @@ public class CheckerTestUtil {
|
||||
result.append(name);
|
||||
if (parameters != null) {
|
||||
result.append("(");
|
||||
result.append(StringUtil.join(parameters, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return escape(s);
|
||||
}
|
||||
}, "; "));
|
||||
result.append(StringUtil.join(parameters, TextDiagnostic::escape, "; "));
|
||||
result.append(")");
|
||||
}
|
||||
return result.toString();
|
||||
|
||||
@@ -38,14 +38,11 @@ import java.util.List;
|
||||
|
||||
public class DiagnosticUtils {
|
||||
@NotNull
|
||||
private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR = new Comparator<TextRange>() {
|
||||
@Override
|
||||
public int compare(@NotNull TextRange o1, @NotNull TextRange o2) {
|
||||
if (o1.getStartOffset() != o2.getStartOffset()) {
|
||||
return o1.getStartOffset() - o2.getStartOffset();
|
||||
}
|
||||
return o1.getEndOffset() - o2.getEndOffset();
|
||||
private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR = (o1, o2) -> {
|
||||
if (o1.getStartOffset() != o2.getStartOffset()) {
|
||||
return o1.getStartOffset() - o2.getStartOffset();
|
||||
}
|
||||
return o1.getEndOffset() - o2.getEndOffset();
|
||||
};
|
||||
|
||||
private DiagnosticUtils() {
|
||||
@@ -163,22 +160,19 @@ public class DiagnosticUtils {
|
||||
|
||||
@NotNull
|
||||
public static List<Diagnostic> sortedDiagnostics(@NotNull Collection<Diagnostic> diagnostics) {
|
||||
Comparator<Diagnostic> diagnosticComparator = new Comparator<Diagnostic>() {
|
||||
@Override
|
||||
public int compare(@NotNull Diagnostic d1, @NotNull Diagnostic d2) {
|
||||
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||
Comparator<Diagnostic> diagnosticComparator = (d1, d2) -> {
|
||||
String path1 = d1.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
String path2 = d2.getPsiFile().getViewProvider().getVirtualFile().getPath();
|
||||
if (!path1.equals(path2)) return path1.compareTo(path2);
|
||||
|
||||
TextRange range1 = firstRange(d1.getTextRanges());
|
||||
TextRange range2 = firstRange(d2.getTextRanges());
|
||||
TextRange range1 = firstRange(d1.getTextRanges());
|
||||
TextRange range2 = firstRange(d2.getTextRanges());
|
||||
|
||||
if (!range1.equals(range2)) {
|
||||
return TEXT_RANGE_COMPARATOR.compare(range1, range2);
|
||||
}
|
||||
|
||||
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||
if (!range1.equals(range2)) {
|
||||
return TEXT_RANGE_COMPARATOR.compare(range1, range2);
|
||||
}
|
||||
|
||||
return d1.getFactory().getName().compareTo(d2.getFactory().getName());
|
||||
};
|
||||
List<Diagnostic> result = Lists.newArrayList(diagnostics);
|
||||
Collections.sort(result, diagnosticComparator);
|
||||
|
||||
+63
-123
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.diagnostics.rendering;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -27,14 +26,8 @@ import org.jetbrains.kotlin.config.LanguageVersion;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.diagnostics.TypeMismatchDueToTypeProjectionsData;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtTypeConstraint;
|
||||
import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.util.MappedExtensionProvider;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
@@ -59,16 +52,13 @@ public class DefaultErrorMessages {
|
||||
private static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap("Default");
|
||||
private static final MappedExtensionProvider<Extension, List<DiagnosticFactoryToRendererMap>> RENDERER_MAPS = MappedExtensionProvider.create(
|
||||
Extension.EP_NAME,
|
||||
new Function1<List<? extends Extension>, List<DiagnosticFactoryToRendererMap>>() {
|
||||
@Override
|
||||
public List<DiagnosticFactoryToRendererMap> invoke(List<? extends Extension> extensions) {
|
||||
List<DiagnosticFactoryToRendererMap> result = new ArrayList<DiagnosticFactoryToRendererMap>(extensions.size() + 1);
|
||||
for (Extension extension : extensions) {
|
||||
result.add(extension.getMap());
|
||||
}
|
||||
result.add(MAP);
|
||||
return result;
|
||||
extensions -> {
|
||||
List<DiagnosticFactoryToRendererMap> result = new ArrayList<DiagnosticFactoryToRendererMap>(extensions.size() + 1);
|
||||
for (Extension extension : extensions) {
|
||||
result.add(extension.getMap());
|
||||
}
|
||||
result.add(MAP);
|
||||
return result;
|
||||
});
|
||||
|
||||
@NotNull
|
||||
@@ -133,19 +123,15 @@ public class DefaultErrorMessages {
|
||||
RENDER_TYPE);
|
||||
MAP.put(TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS,
|
||||
"Type mismatch: inferred type is {1} but {0} was expected. Projected type {2} restricts use of {3}",
|
||||
new MultiRenderer<TypeMismatchDueToTypeProjectionsData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] render(@NotNull TypeMismatchDueToTypeProjectionsData object) {
|
||||
RenderingContext context =
|
||||
of(object.getExpectedType(), object.getExpressionType(), object.getReceiverType(), object.getCallableDescriptor());
|
||||
return new String[] {
|
||||
RENDER_TYPE.render(object.getExpectedType(), context),
|
||||
RENDER_TYPE.render(object.getExpressionType(), context),
|
||||
RENDER_TYPE.render(object.getReceiverType(), context),
|
||||
FQ_NAMES_IN_TYPES.render(object.getCallableDescriptor(), context)
|
||||
};
|
||||
}
|
||||
object -> {
|
||||
RenderingContext context =
|
||||
of(object.getExpectedType(), object.getExpressionType(), object.getReceiverType(), object.getCallableDescriptor());
|
||||
return new String[] {
|
||||
RENDER_TYPE.render(object.getExpectedType(), context),
|
||||
RENDER_TYPE.render(object.getExpressionType(), context),
|
||||
RENDER_TYPE.render(object.getReceiverType(), context),
|
||||
FQ_NAMES_IN_TYPES.render(object.getCallableDescriptor(), context)
|
||||
};
|
||||
});
|
||||
|
||||
MAP.put(MEMBER_PROJECTED_OUT, "Out-projected type ''{1}'' prohibits the use of ''{0}''", FQ_NAMES_IN_TYPES, RENDER_TYPE);
|
||||
@@ -198,20 +184,16 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MIXING_NAMED_AND_POSITIONED_ARGUMENTS, "Mixing named and positioned arguments is not allowed");
|
||||
MAP.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter");
|
||||
MAP.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", ELEMENT_TEXT);
|
||||
MAP.put(NAMED_ARGUMENTS_NOT_ALLOWED, "Named arguments are not allowed for {0}", new DiagnosticParameterRenderer<BadNamedArgumentsTarget>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull BadNamedArgumentsTarget target, @NotNull RenderingContext context) {
|
||||
switch (target) {
|
||||
case NON_KOTLIN_FUNCTION:
|
||||
return "non-Kotlin functions";
|
||||
case INVOKE_ON_FUNCTION_TYPE:
|
||||
return "function types";
|
||||
case HEADER_CLASS_MEMBER:
|
||||
return "members of header classes";
|
||||
default:
|
||||
throw new AssertionError(target);
|
||||
}
|
||||
MAP.put(NAMED_ARGUMENTS_NOT_ALLOWED, "Named arguments are not allowed for {0}", (target, context) -> {
|
||||
switch (target) {
|
||||
case NON_KOTLIN_FUNCTION:
|
||||
return "non-Kotlin functions";
|
||||
case INVOKE_ON_FUNCTION_TYPE:
|
||||
return "function types";
|
||||
case HEADER_CLASS_MEMBER:
|
||||
return "members of header classes";
|
||||
default:
|
||||
throw new AssertionError(target);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -333,28 +315,14 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DEPRECATION, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING);
|
||||
MAP.put(DEPRECATION_ERROR, "Using ''{0}'' is an error. {1}", DEPRECATION_RENDERER, STRING);
|
||||
|
||||
DiagnosticParameterRenderer<Pair<LanguageVersion, String>> sinceKotlinInfoMessage = new DiagnosticParameterRenderer<Pair<LanguageVersion, String>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull Pair<LanguageVersion, String> pair, @NotNull RenderingContext renderingContext) {
|
||||
String message = pair.getSecond();
|
||||
return pair.getFirst().getVersionString() + (message != null ? ". " + message : "");
|
||||
}
|
||||
DiagnosticParameterRenderer<Pair<LanguageVersion, String>> sinceKotlinInfoMessage = (pair, renderingContext) -> {
|
||||
String message = pair.getSecond();
|
||||
return pair.getFirst().getVersionString() + (message != null ? ". " + message : "");
|
||||
};
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}", DEPRECATION_RENDERER, new DiagnosticParameterRenderer<SinceKotlinInfo.Version>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull SinceKotlinInfo.Version obj, @NotNull RenderingContext renderingContext) {
|
||||
return obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only supported since Kotlin " + obj.asString() + " and";
|
||||
}
|
||||
}, sinceKotlinInfoMessage);
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION_ERROR, "''{0}''{1} cannot be used in Kotlin {2}", DEPRECATION_RENDERER, new DiagnosticParameterRenderer<SinceKotlinInfo.Version>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull SinceKotlinInfo.Version obj, @NotNull RenderingContext renderingContext) {
|
||||
return obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only available since Kotlin " + obj.asString() + " and";
|
||||
}
|
||||
}, sinceKotlinInfoMessage);
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION, "''{0}''{1} should not be used in Kotlin {2}", DEPRECATION_RENDERER,
|
||||
(obj, renderingContext) -> obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only supported since Kotlin " + obj.asString() + " and", sinceKotlinInfoMessage);
|
||||
MAP.put(SINCE_KOTLIN_INFO_DEPRECATION_ERROR, "''{0}''{1} cannot be used in Kotlin {2}", DEPRECATION_RENDERER,
|
||||
(obj, renderingContext) -> obj.equals(SinceKotlinInfo.Version.INFINITY) ? "" : " is only available since Kotlin " + obj.asString() + " and", sinceKotlinInfoMessage);
|
||||
|
||||
MAP.put(API_NOT_AVAILABLE, "This declaration is only available since Kotlin {0} and cannot be used with the specified API version {1}", STRING, STRING);
|
||||
|
||||
@@ -362,15 +330,12 @@ public class DefaultErrorMessages {
|
||||
MAP.put(PRE_RELEASE_CLASS, "{0} is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);
|
||||
MAP.put(INCOMPATIBLE_CLASS,
|
||||
"{0} was compiled with an incompatible version of Kotlin. {1}",
|
||||
TO_STRING, new DiagnosticParameterRenderer<IncompatibleVersionErrorData<?>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull IncompatibleVersionErrorData<?> incompatibility, @NotNull RenderingContext renderingContext) {
|
||||
return "The binary version of its metadata is " + incompatibility.getActualVersion() +
|
||||
", expected version is " + incompatibility.getExpectedVersion() + ".\n" +
|
||||
"The class is loaded from " + FileUtil.toSystemIndependentName(incompatibility.getFilePath());
|
||||
}
|
||||
});
|
||||
TO_STRING,
|
||||
(incompatibility, renderingContext) ->
|
||||
"The binary version of its metadata is " + incompatibility.getActualVersion() +
|
||||
", expected version is " + incompatibility.getExpectedVersion() + ".\n" +
|
||||
"The class is loaded from " + FileUtil.toSystemIndependentName(incompatibility.getFilePath())
|
||||
);
|
||||
|
||||
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
||||
MAP.put(LOCAL_INTERFACE_NOT_ALLOWED, "''{0}'' is an interface so it cannot be local. Try to use anonymous object or abstract class instead", NAME);
|
||||
@@ -493,14 +458,10 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(IMPLICIT_CAST_TO_ANY, "Conditional branch result of type {0} is implicitly cast to {1}",
|
||||
RENDER_TYPE, RENDER_TYPE);
|
||||
MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expressions are allowed here", new DiagnosticParameterRenderer<KtExpression>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtExpression expression, @NotNull RenderingContext context) {
|
||||
String expressionType = expression.toString();
|
||||
return expressionType.substring(0, 1) +
|
||||
expressionType.substring(1).toLowerCase();
|
||||
}
|
||||
MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expressions are allowed here", (expression, context) -> {
|
||||
String expressionType = expression.toString();
|
||||
return expressionType.substring(0, 1) +
|
||||
expressionType.substring(1).toLowerCase();
|
||||
});
|
||||
|
||||
MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE);
|
||||
@@ -613,13 +574,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNEXPECTED_SAFE_CALL, "Safe-call is not allowed here");
|
||||
MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE);
|
||||
MAP.put(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, "Non-null assertion (!!) is called on a lambda expression");
|
||||
MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new DiagnosticParameterRenderer<KtTypeConstraint>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtTypeConstraint typeConstraint, @NotNull RenderingContext context) {
|
||||
//noinspection ConstantConditions
|
||||
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
|
||||
}
|
||||
MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", (typeConstraint, context) -> {
|
||||
//noinspection ConstantConditions
|
||||
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
|
||||
}, DECLARATION_NAME);
|
||||
MAP.put(SMARTCAST_IMPOSSIBLE,
|
||||
"Smart cast to ''{0}'' is impossible, because ''{1}'' is a {2}", RENDER_TYPE, STRING, STRING);
|
||||
@@ -637,20 +594,16 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(MISPLACED_TYPE_PARAMETER_CONSTRAINTS, "If a type parameter has multiple constraints, they all need to be placed in the 'where' clause");
|
||||
|
||||
MultiRenderer<VarianceConflictDiagnosticData> varianceConflictDataRenderer = new MultiRenderer<VarianceConflictDiagnosticData>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] render(@NotNull VarianceConflictDiagnosticData data) {
|
||||
RenderingContext context =
|
||||
of(data.getTypeParameter(), data.getTypeParameter().getVariance(), data.getOccurrencePosition(),
|
||||
data.getContainingType());
|
||||
return new String[] {
|
||||
NAME.render(data.getTypeParameter(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getTypeParameter().getVariance(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getOccurrencePosition(), context),
|
||||
RENDER_TYPE.render(data.getContainingType(), context)
|
||||
};
|
||||
}
|
||||
MultiRenderer<VarianceConflictDiagnosticData> varianceConflictDataRenderer = data -> {
|
||||
RenderingContext context =
|
||||
of(data.getTypeParameter(), data.getTypeParameter().getVariance(), data.getOccurrencePosition(),
|
||||
data.getContainingType());
|
||||
return new String[] {
|
||||
NAME.render(data.getTypeParameter(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getTypeParameter().getVariance(), context),
|
||||
RENDER_POSITION_VARIANCE.render(data.getOccurrencePosition(), context),
|
||||
RENDER_TYPE.render(data.getContainingType(), context)
|
||||
};
|
||||
};
|
||||
MAP.put(TYPE_VARIANCE_CONFLICT, "Type parameter {0} is declared as ''{1}'' but occurs in ''{2}'' position in type {3}",
|
||||
varianceConflictDataRenderer);
|
||||
@@ -687,13 +640,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INCONSISTENT_TYPE_PARAMETER_VALUES, "Type parameter {0} of ''{1}'' has inconsistent values: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES);
|
||||
MAP.put(INCONSISTENT_TYPE_PARAMETER_BOUNDS, "Type parameter {0} of ''{1}'' has inconsistent bounds: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES);
|
||||
|
||||
MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", new DiagnosticParameterRenderer<KtSimpleNameExpression>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KtSimpleNameExpression nameExpression, @NotNull RenderingContext context) {
|
||||
//noinspection ConstantConditions
|
||||
return nameExpression.getReferencedName();
|
||||
}
|
||||
MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", (nameExpression, context) -> {
|
||||
//noinspection ConstantConditions
|
||||
return nameExpression.getReferencedName();
|
||||
}, RENDER_TYPE, RENDER_TYPE);
|
||||
|
||||
MAP.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING);
|
||||
@@ -745,21 +694,12 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " +
|
||||
"The function ''" + OperatorNameConventions.INVOKE.asString() + "()'' is not found",
|
||||
ELEMENT_TEXT, new DiagnosticParameterRenderer<KotlinType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull KotlinType type, @NotNull RenderingContext context) {
|
||||
if (type.isError()) return "";
|
||||
return " of type '" + RENDER_TYPE.render(type, context) + "'";
|
||||
}
|
||||
ELEMENT_TEXT, (type, context) -> {
|
||||
if (type.isError()) return "";
|
||||
return " of type '" + RENDER_TYPE.render(type, context) + "'";
|
||||
});
|
||||
MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT, new DiagnosticParameterRenderer<Boolean>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String render(@NotNull Boolean hasValueParameters, @NotNull RenderingContext context) {
|
||||
return hasValueParameters ? "..." : "";
|
||||
}
|
||||
});
|
||||
MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT,
|
||||
(hasValueParameters, context) -> hasValueParameters ? "..." : "");
|
||||
MAP.put(NON_TAIL_RECURSIVE_CALL, "Recursive call is not a tail call");
|
||||
MAP.put(TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED, "Tail recursion optimization inside try/catch/finally is not supported");
|
||||
|
||||
|
||||
@@ -17,20 +17,13 @@
|
||||
package org.jetbrains.kotlin.psi;
|
||||
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc;
|
||||
|
||||
public interface KtDeclaration extends KtExpression, KtModifierListOwner {
|
||||
KtDeclaration[] EMPTY_ARRAY = new KtDeclaration[0];
|
||||
|
||||
ArrayFactory<KtDeclaration> ARRAY_FACTORY = new ArrayFactory<KtDeclaration>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtDeclaration[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtDeclaration[count];
|
||||
}
|
||||
};
|
||||
ArrayFactory<KtDeclaration> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtDeclaration[count];
|
||||
|
||||
@Nullable
|
||||
KDoc getDocComment();
|
||||
|
||||
@@ -22,13 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface KtExpression extends KtElement {
|
||||
KtExpression[] EMPTY_ARRAY = new KtExpression[0];
|
||||
|
||||
ArrayFactory<KtExpression> ARRAY_FACTORY = new ArrayFactory<KtExpression>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtExpression[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtExpression[count];
|
||||
}
|
||||
};
|
||||
ArrayFactory<KtExpression> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtExpression[count];
|
||||
|
||||
@Override
|
||||
<R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data);
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class KtExpressionImplStub<T extends StubElement<?>> extends KtElementImplStub<T> implements KtExpression {
|
||||
@@ -41,12 +40,7 @@ public abstract class KtExpressionImplStub<T extends StubElement<?>> extends KtE
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
|
||||
return KtExpressionImpl.Companion.replaceExpression(this, newElement, new Function1<PsiElement, PsiElement>() {
|
||||
@Override
|
||||
public PsiElement invoke(PsiElement element) {
|
||||
return rawReplace(element);
|
||||
}
|
||||
});
|
||||
return KtExpressionImpl.Companion.replaceExpression(this, newElement, this::rawReplace);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.intellij.util.FileContentUtilCore;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.KtNodeTypes;
|
||||
@@ -258,19 +257,12 @@ public class KtFile extends PsiFileBase implements KtDeclarationContainer, KtAnn
|
||||
public List<KtAnnotationEntry> getDanglingAnnotations() {
|
||||
KotlinFileStub stub = getStub();
|
||||
KtModifierList[] danglingModifierLists = stub == null
|
||||
? findChildrenByClass(KtModifierList.class)
|
||||
: stub.getChildrenByType(
|
||||
KtStubElementTypes.MODIFIER_LIST,
|
||||
KtStubElementTypes.MODIFIER_LIST.getArrayFactory()
|
||||
);
|
||||
return ArraysKt.flatMap(
|
||||
danglingModifierLists,
|
||||
new Function1<KtModifierList, Iterable<KtAnnotationEntry>>() {
|
||||
@Override
|
||||
public Iterable<KtAnnotationEntry> invoke(KtModifierList modifierList) {
|
||||
return modifierList.getAnnotationEntries();
|
||||
}
|
||||
});
|
||||
? findChildrenByClass(KtModifierList.class)
|
||||
: stub.getChildrenByType(
|
||||
KtStubElementTypes.MODIFIER_LIST,
|
||||
KtStubElementTypes.MODIFIER_LIST.getArrayFactory()
|
||||
);
|
||||
return ArraysKt.flatMap(danglingModifierLists, KtModifierList::getAnnotationEntries);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.psi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.resolve.ImportPath;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -37,7 +35,7 @@ public class KtImportsFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtImportDirective createImportDirective(@NotNull ImportPath importPath) {
|
||||
private KtImportDirective createImportDirective(@NotNull ImportPath importPath) {
|
||||
KtImportDirective directive = importsCache.get(importPath);
|
||||
if (directive != null) {
|
||||
return directive;
|
||||
@@ -51,13 +49,6 @@ public class KtImportsFactory {
|
||||
|
||||
@NotNull
|
||||
public Collection<KtImportDirective> createImportDirectives(@NotNull Collection<ImportPath> importPaths) {
|
||||
return Collections2.transform(importPaths,
|
||||
new Function<ImportPath, KtImportDirective>() {
|
||||
@Override
|
||||
public KtImportDirective apply(@Nullable ImportPath path) {
|
||||
assert path != null;
|
||||
return createImportDirective(path);
|
||||
}
|
||||
});
|
||||
return CollectionsKt.map(importPaths, this::createImportDirective);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,9 @@ import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
||||
|
||||
public class KtSuperTypeListEntry extends KtElementImplStub<KotlinPlaceHolderStub<? extends KtSuperTypeListEntry>> {
|
||||
|
||||
private static final KtSuperTypeListEntry[] EMPTY_ARRAY = new KtSuperTypeListEntry[0];
|
||||
|
||||
public static ArrayFactory<KtSuperTypeListEntry> ARRAY_FACTORY = new ArrayFactory<KtSuperTypeListEntry>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtSuperTypeListEntry[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtSuperTypeListEntry[count];
|
||||
}
|
||||
};
|
||||
public static ArrayFactory<KtSuperTypeListEntry> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtSuperTypeListEntry[count];
|
||||
|
||||
public KtSuperTypeListEntry(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
|
||||
@@ -24,13 +24,7 @@ import java.util.List;
|
||||
public interface KtTypeElement extends KtElement {
|
||||
KtTypeElement[] EMPTY_ARRAY = new KtTypeElement[0];
|
||||
|
||||
ArrayFactory<KtTypeElement> ARRAY_FACTORY = new ArrayFactory<KtTypeElement>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KtTypeElement[] create(int count) {
|
||||
return count == 0 ? EMPTY_ARRAY : new KtTypeElement[count];
|
||||
}
|
||||
};
|
||||
ArrayFactory<KtTypeElement> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new KtTypeElement[count];
|
||||
|
||||
// may contain null
|
||||
@NotNull
|
||||
|
||||
+5
-9
@@ -58,16 +58,12 @@ public abstract class KtStubElementType<StubT extends StubElement, PsiT extends
|
||||
}
|
||||
//noinspection unchecked
|
||||
emptyArray = (PsiT[]) Array.newInstance(psiClass, 0);
|
||||
arrayFactory = new ArrayFactory<PsiT>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiT[] create(int count) {
|
||||
if (count == 0) {
|
||||
return emptyArray;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (PsiT[]) Array.newInstance(psiClass, count);
|
||||
arrayFactory = count -> {
|
||||
if (count == 0) {
|
||||
return emptyArray;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (PsiT[]) Array.newInstance(psiClass, count);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
@@ -36,7 +35,8 @@ import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.expressions.KotlinTypeInfo;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.util.slicedMap.*;
|
||||
import org.jetbrains.kotlin.util.slicedMap.MutableSlicedMap;
|
||||
import org.jetbrains.kotlin.util.slicedMap.ReadOnlySlice;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -233,15 +233,12 @@ public class BindingContextUtils {
|
||||
@NotNull BindingTrace trace, @Nullable TraceEntryFilter filter, boolean commitDiagnostics,
|
||||
@NotNull MutableSlicedMap map, MutableDiagnosticsWithSuppression diagnostics
|
||||
) {
|
||||
map.forEach(new Function3<WritableSlice, Object, Object, Void>() {
|
||||
@Override
|
||||
public Void invoke(WritableSlice slice, Object key, Object value) {
|
||||
if (filter == null || filter.accept(slice, key)) {
|
||||
trace.record(slice, key, value);
|
||||
}
|
||||
|
||||
return null;
|
||||
map.forEach((slice, key, value) -> {
|
||||
if (filter == null || filter.accept(slice, key)) {
|
||||
trace.record(slice, key, value);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!commitDiagnostics) return;
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.jetbrains.kotlin.types.expressions.ValueParameterResolver;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.util.Box;
|
||||
import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -149,21 +148,13 @@ public class BodyResolver {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations());
|
||||
|
||||
resolveFunctionBody(outerDataFlowInfo, trace, constructor, descriptor, declaringScope,
|
||||
new Function1<LexicalScope, DataFlowInfo>() {
|
||||
@Override
|
||||
public DataFlowInfo invoke(@NotNull LexicalScope headerInnerScope) {
|
||||
return resolveSecondaryConstructorDelegationCall(outerDataFlowInfo, trace, headerInnerScope,
|
||||
constructor, descriptor);
|
||||
}
|
||||
},
|
||||
new Function1<LexicalScope, LexicalScope>() {
|
||||
@Override
|
||||
public LexicalScope invoke(LexicalScope scope) {
|
||||
return new LexicalScopeImpl(
|
||||
scope, descriptor, scope.isOwnerDescriptorAccessibleByLabel(), scope.getImplicitReceiver(),
|
||||
LexicalScopeKind.CONSTRUCTOR_HEADER);
|
||||
}
|
||||
});
|
||||
headerInnerScope -> resolveSecondaryConstructorDelegationCall(
|
||||
outerDataFlowInfo, trace, headerInnerScope, constructor, descriptor
|
||||
),
|
||||
scope -> new LexicalScopeImpl(
|
||||
scope, descriptor, scope.isOwnerDescriptorAccessibleByLabel(), scope.getImplicitReceiver(),
|
||||
LexicalScopeKind.CONSTRUCTOR_HEADER
|
||||
));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -637,15 +628,11 @@ public class BodyResolver {
|
||||
) {
|
||||
return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null,
|
||||
LexicalScopeKind.DEFAULT_VALUE, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (ValueParameterDescriptor
|
||||
valueParameterDescriptor : unsubstitutedPrimaryConstructor.getValueParameters()) {
|
||||
handler.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
handler -> {
|
||||
for (ValueParameterDescriptor valueParameter : unsubstitutedPrimaryConstructor.getValueParameters()) {
|
||||
handler.addVariableDescriptor(valueParameter);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -739,20 +726,14 @@ public class BodyResolver {
|
||||
private ObservableBindingTrace createFieldTrackingTrace(PropertyDescriptor propertyDescriptor) {
|
||||
return new ObservableBindingTrace(trace).addHandler(
|
||||
BindingContext.REFERENCE_TARGET,
|
||||
new ObservableBindingTrace.RecordHandler<KtReferenceExpression, DeclarationDescriptor>() {
|
||||
@Override
|
||||
public void handleRecord(
|
||||
WritableSlice<KtReferenceExpression, DeclarationDescriptor> slice,
|
||||
KtReferenceExpression expression,
|
||||
DeclarationDescriptor descriptor
|
||||
) {
|
||||
if (expression instanceof KtSimpleNameExpression &&
|
||||
descriptor instanceof SyntheticFieldDescriptor) {
|
||||
trace.record(BindingContext.BACKING_FIELD_REQUIRED,
|
||||
propertyDescriptor);
|
||||
(slice, expression, descriptor) -> {
|
||||
if (expression instanceof KtSimpleNameExpression &&
|
||||
descriptor instanceof SyntheticFieldDescriptor) {
|
||||
trace.record(BindingContext.BACKING_FIELD_REQUIRED,
|
||||
propertyDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
private void resolvePropertyDelegate(
|
||||
@@ -850,13 +831,10 @@ public class BodyResolver {
|
||||
SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property);
|
||||
innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null,
|
||||
LexicalScopeKind.PROPERTY_ACCESSOR_BODY,
|
||||
LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addVariableDescriptor(fieldDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
LocalRedeclarationChecker.DO_NOTHING.INSTANCE, handler -> {
|
||||
handler.addVariableDescriptor(fieldDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
// Check parameter name shadowing
|
||||
for (KtParameter parameter : function.getValueParameters()) {
|
||||
if (SyntheticFieldDescriptor.NAME.equals(parameter.getNameAsName())) {
|
||||
@@ -914,16 +892,7 @@ public class BodyResolver {
|
||||
}
|
||||
// +1 is a work around against new Queue(0).addLast(...) bug // stepan.koltsov@ 2011-11-21
|
||||
Queue<DeferredType> queue = new Queue<DeferredType>(deferredTypes.size() + 1);
|
||||
trace.addHandler(DEFERRED_TYPE, new ObservableBindingTrace.RecordHandler<Box<DeferredType>, Boolean>() {
|
||||
@Override
|
||||
public void handleRecord(
|
||||
WritableSlice<Box<DeferredType>, Boolean> deferredTypeKeyDeferredTypeWritableSlice,
|
||||
Box<DeferredType> key,
|
||||
Boolean value
|
||||
) {
|
||||
queue.addLast(key.getData());
|
||||
}
|
||||
});
|
||||
trace.addHandler(DEFERRED_TYPE, (deferredTypeKeyDeferredTypeWritableSlice, key, value) -> queue.addLast(key.getData()));
|
||||
for (Box<DeferredType> deferredType : deferredTypes) {
|
||||
queue.addLast(deferredType.getData());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import kotlin.TuplesKt;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.collections.SetsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
||||
@@ -35,7 +34,6 @@ import org.jetbrains.kotlin.config.LanguageFeature;
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationSplitter;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.*;
|
||||
@@ -335,26 +333,23 @@ public class DescriptorResolver {
|
||||
TuplesKt.to(LanguageFeature.DestructuringLambdaParameters, languageVersionSettings)));
|
||||
}
|
||||
|
||||
destructuringVariables = new Function0<List<VariableDescriptor>>() {
|
||||
@Override
|
||||
public List<VariableDescriptor> invoke() {
|
||||
assert owner.getDispatchReceiverParameter() == null
|
||||
: "Destructuring declarations are only be parsed for lambdas, and they must not have a dispatch receiver";
|
||||
LexicalScope scopeForDestructuring =
|
||||
ScopeUtilsKt.createScopeForDestructuring(scope, owner.getExtensionReceiverParameter());
|
||||
destructuringVariables = () -> {
|
||||
assert owner.getDispatchReceiverParameter() == null
|
||||
: "Destructuring declarations are only be parsed for lambdas, and they must not have a dispatch receiver";
|
||||
LexicalScope scopeForDestructuring =
|
||||
ScopeUtilsKt.createScopeForDestructuring(scope, owner.getExtensionReceiverParameter());
|
||||
|
||||
List<VariableDescriptor> result =
|
||||
destructuringDeclarationResolver.resolveLocalVariablesFromDestructuringDeclaration(
|
||||
scope,
|
||||
destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
|
||||
ExpressionTypingContext.newContext(
|
||||
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE
|
||||
)
|
||||
);
|
||||
List<VariableDescriptor> result =
|
||||
destructuringDeclarationResolver.resolveLocalVariablesFromDestructuringDeclaration(
|
||||
scope,
|
||||
destructuringDeclaration, new TransientReceiver(type), /* initializer = */ null,
|
||||
ExpressionTypingContext.newContext(
|
||||
trace, scopeForDestructuring, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE
|
||||
)
|
||||
);
|
||||
|
||||
modifiersChecker.withTrace(trace).checkModifiersForDestructuringDeclaration(destructuringDeclaration);
|
||||
return result;
|
||||
}
|
||||
modifiersChecker.withTrace(trace).checkModifiersForDestructuringDeclaration(destructuringDeclaration);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
else {
|
||||
@@ -460,17 +455,14 @@ public class DescriptorResolver {
|
||||
KtPsiUtil.safeName(typeParameter.getName()),
|
||||
index,
|
||||
KotlinSourceElementKt.toSourceElement(typeParameter),
|
||||
new Function1<KotlinType, Void>() {
|
||||
@Override
|
||||
public Void invoke(KotlinType type) {
|
||||
if (!(containingDescriptor instanceof TypeAliasDescriptor)) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(typeParameter));
|
||||
}
|
||||
return null;
|
||||
type -> {
|
||||
if (!(containingDescriptor instanceof TypeAliasDescriptor)) {
|
||||
trace.report(Errors.CYCLIC_GENERIC_UPPER_BOUND.on(typeParameter));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
supertypeLoopsResolver
|
||||
);
|
||||
);
|
||||
trace.record(BindingContext.TYPE_PARAMETER, typeParameter, typeParameterDescriptor);
|
||||
return typeParameterDescriptor;
|
||||
}
|
||||
@@ -761,21 +753,11 @@ public class DescriptorResolver {
|
||||
typeAliasDescriptor.initialize(
|
||||
typeParameterDescriptors,
|
||||
storageManager.createRecursionTolerantLazyValue(
|
||||
new Function0<SimpleType>() {
|
||||
@Override
|
||||
public SimpleType invoke() {
|
||||
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
|
||||
}
|
||||
},
|
||||
() -> typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace),
|
||||
ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())
|
||||
),
|
||||
storageManager.createRecursionTolerantLazyValue(
|
||||
new Function0<SimpleType>() {
|
||||
@Override
|
||||
public SimpleType invoke() {
|
||||
return typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor);
|
||||
}
|
||||
},
|
||||
() -> typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor),
|
||||
ErrorUtils.createErrorType("Recursive type alias expansion for " + typeAliasDescriptor.getName().asString())
|
||||
)
|
||||
);
|
||||
@@ -817,12 +799,8 @@ public class DescriptorResolver {
|
||||
|
||||
Annotations allAnnotations = annotationResolver.resolveAnnotationsWithoutArguments(scopeForDeclarationResolution, modifierList, trace);
|
||||
AnnotationSplitter annotationSplitter =
|
||||
new AnnotationSplitter(storageManager, allAnnotations, new Function0<Set<AnnotationUseSiteTarget>>() {
|
||||
@Override
|
||||
public Set<AnnotationUseSiteTarget> invoke() {
|
||||
return AnnotationSplitter.getTargetSet(false, trace.getBindingContext(), wrapper);
|
||||
}
|
||||
});
|
||||
new AnnotationSplitter(storageManager, allAnnotations,
|
||||
() -> AnnotationSplitter.getTargetSet(false, trace.getBindingContext(), wrapper));
|
||||
|
||||
Annotations propertyAnnotations = new CompositeAnnotations(CollectionsKt.listOf(
|
||||
annotationSplitter.getAnnotationsForTargets(PROPERTY, FIELD, PROPERTY_DELEGATE_FIELD),
|
||||
@@ -1117,16 +1095,13 @@ public class DescriptorResolver {
|
||||
@NotNull KtDeclarationWithBody function,
|
||||
@NotNull FunctionDescriptor functionDescriptor
|
||||
) {
|
||||
return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace);
|
||||
KotlinType type = expressionTypingServices.getBodyExpressionType(
|
||||
trace, scope, dataFlowInfo, function, functionDescriptor);
|
||||
KotlinType result = transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
|
||||
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, result);
|
||||
return result;
|
||||
}
|
||||
return wrappedTypeFactory.createRecursionIntolerantDeferredType(trace, () -> {
|
||||
PreliminaryDeclarationVisitor.Companion.createForDeclaration(function, trace);
|
||||
KotlinType type = expressionTypingServices.getBodyExpressionType(
|
||||
trace, scope, dataFlowInfo, function, functionDescriptor);
|
||||
KotlinType result = transformAnonymousTypeIfNeeded(functionDescriptor, function, type, trace);
|
||||
functionsTypingVisitor.checkTypesForReturnStatements(function, trace, result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1152,12 +1127,8 @@ public class DescriptorResolver {
|
||||
AnnotationSplitter.PropertyWrapper propertyWrapper = new AnnotationSplitter.PropertyWrapper(parameter);
|
||||
Annotations allAnnotations = annotationResolver.resolveAnnotationsWithoutArguments(scope, parameter.getModifierList(), trace);
|
||||
AnnotationSplitter annotationSplitter =
|
||||
new AnnotationSplitter(storageManager, allAnnotations, new Function0<Set<AnnotationUseSiteTarget>>() {
|
||||
@Override
|
||||
public Set<AnnotationUseSiteTarget> invoke() {
|
||||
return AnnotationSplitter.getTargetSet(true, trace.getBindingContext(), propertyWrapper);
|
||||
}
|
||||
});
|
||||
new AnnotationSplitter(storageManager, allAnnotations,
|
||||
() -> AnnotationSplitter.getTargetSet(true, trace.getBindingContext(), propertyWrapper));
|
||||
|
||||
Annotations propertyAnnotations = new CompositeAnnotations(
|
||||
annotationSplitter.getAnnotationsForTargets(PROPERTY, FIELD),
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
@@ -66,31 +65,29 @@ public class FunctionDescriptorUtil {
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull LocalRedeclarationChecker redeclarationChecker
|
||||
) {
|
||||
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
return new LexicalScopeImpl(outerScope, descriptor, true, receiver, LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationChecker,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||
handler.addClassifierDescriptor(typeParameter);
|
||||
}
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
||||
if (valueParameterDescriptor instanceof ValueParameterDescriptorImpl.WithDestructuringDeclaration) {
|
||||
List<VariableDescriptor> entries =
|
||||
((ValueParameterDescriptorImpl.WithDestructuringDeclaration) valueParameterDescriptor)
|
||||
.getDestructuringVariables();
|
||||
for (VariableDescriptor entry : entries) {
|
||||
handler.addVariableDescriptor(entry);
|
||||
}
|
||||
}
|
||||
else {
|
||||
handler.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
return new LexicalScopeImpl(
|
||||
outerScope, descriptor, true, descriptor.getExtensionReceiverParameter(),
|
||||
LexicalScopeKind.FUNCTION_INNER_SCOPE, redeclarationChecker,
|
||||
handler -> {
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||
handler.addClassifierDescriptor(typeParameter);
|
||||
}
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
||||
if (valueParameterDescriptor instanceof ValueParameterDescriptorImpl.WithDestructuringDeclaration) {
|
||||
List<VariableDescriptor> entries =
|
||||
((ValueParameterDescriptorImpl.WithDestructuringDeclaration) valueParameterDescriptor)
|
||||
.getDestructuringVariables();
|
||||
for (VariableDescriptor entry : entries) {
|
||||
handler.addVariableDescriptor(entry);
|
||||
}
|
||||
}
|
||||
else {
|
||||
handler.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.calls;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import kotlin.Pair;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
||||
@@ -181,14 +180,9 @@ public class CallResolver {
|
||||
@NotNull TracingStrategy tracing,
|
||||
@NotNull NewResolutionOldInference.ResolutionKind<D> kind
|
||||
) {
|
||||
return callResolvePerfCounter.time(new Function0<OverloadResolutionResults<D>>() {
|
||||
@Override
|
||||
public OverloadResolutionResults<D> invoke() {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<D>(
|
||||
kind, name, null
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
}
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<D>>time(() -> {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<>(kind, name, null);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -208,14 +202,11 @@ public class CallResolver {
|
||||
@NotNull Collection<ResolutionCandidate<D>> candidates,
|
||||
@NotNull TracingStrategy tracing
|
||||
) {
|
||||
return callResolvePerfCounter.time(new Function0<OverloadResolutionResults<D>>() {
|
||||
@Override
|
||||
public OverloadResolutionResults<D> invoke() {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<D>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<D>(), null, candidates
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
}
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<D>>time(() -> {
|
||||
ResolutionTask<D> resolutionTask = new ResolutionTask<>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<>(), null, candidates
|
||||
);
|
||||
return doResolveCallOrGetCachedResults(context, resolutionTask, tracing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -498,22 +489,18 @@ public class CallResolver {
|
||||
@NotNull ResolutionCandidate<FunctionDescriptor> candidate,
|
||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
|
||||
) {
|
||||
return callResolvePerfCounter.time(new Function0<OverloadResolutionResults<FunctionDescriptor>>() {
|
||||
@Override
|
||||
public OverloadResolutionResults<FunctionDescriptor> invoke() {
|
||||
BasicCallResolutionContext basicCallResolutionContext =
|
||||
BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments);
|
||||
return callResolvePerfCounter.<OverloadResolutionResults<FunctionDescriptor>>time(() -> {
|
||||
BasicCallResolutionContext basicCallResolutionContext =
|
||||
BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments);
|
||||
|
||||
Set<ResolutionCandidate<FunctionDescriptor>> candidates = Collections.singleton(candidate);
|
||||
Set<ResolutionCandidate<FunctionDescriptor>> candidates = Collections.singleton(candidate);
|
||||
|
||||
ResolutionTask<FunctionDescriptor> resolutionTask =
|
||||
new ResolutionTask<FunctionDescriptor>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<FunctionDescriptor>(), null, candidates
|
||||
);
|
||||
ResolutionTask<FunctionDescriptor> resolutionTask =
|
||||
new ResolutionTask<FunctionDescriptor>(
|
||||
new NewResolutionOldInference.ResolutionKind.GivenCandidates<FunctionDescriptor>(), null, candidates
|
||||
);
|
||||
|
||||
|
||||
return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing);
|
||||
}
|
||||
return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-6
@@ -70,12 +70,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
|
||||
@NotNull
|
||||
public final Function1<KtExpression, KtExpression> expressionContextProvider;
|
||||
|
||||
public static final Function1<KtExpression, KtExpression> DEFAULT_EXPRESSION_CONTEXT_PROVIDER = new Function1<KtExpression, KtExpression>() {
|
||||
@Override
|
||||
public KtExpression invoke(KtExpression expression) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
public static final Function1<KtExpression, KtExpression> DEFAULT_EXPRESSION_CONTEXT_PROVIDER = expression -> null;
|
||||
|
||||
protected ResolutionContext(
|
||||
@NotNull BindingTrace trace,
|
||||
|
||||
+3
-16
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.inference;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
@@ -96,15 +95,8 @@ public class ConstraintsUtil {
|
||||
KotlinType type = constraintSystem.getTypeBounds(typeVariable).getValue();
|
||||
if (type == null) return true;
|
||||
|
||||
List<TypeParameterDescriptor> typeParametersUsedInSystem = CollectionsKt.map(
|
||||
constraintSystem.getTypeVariables(),
|
||||
new Function1<TypeVariable, TypeParameterDescriptor>() {
|
||||
@Override
|
||||
public TypeParameterDescriptor invoke(TypeVariable variable) {
|
||||
return variable.getOriginalTypeParameter();
|
||||
}
|
||||
}
|
||||
);
|
||||
List<TypeParameterDescriptor> typeParametersUsedInSystem =
|
||||
CollectionsKt.map(constraintSystem.getTypeVariables(), TypeVariable::getOriginalTypeParameter);
|
||||
|
||||
for (KotlinType upperBound : typeParameter.getUpperBounds()) {
|
||||
if (!substituteOtherTypeParametersInBound &&
|
||||
@@ -131,12 +123,7 @@ public class ConstraintsUtil {
|
||||
interestingMethods.add(method);
|
||||
}
|
||||
}
|
||||
Collections.sort(interestingMethods, new Comparator<Method>() {
|
||||
@Override
|
||||
public int compare(@NotNull Method method1, @NotNull Method method2) {
|
||||
return method1.getName().compareTo(method2.getName());
|
||||
}
|
||||
});
|
||||
Collections.sort(interestingMethods, Comparator.comparing(Method::getName));
|
||||
for (Iterator<Method> iterator = interestingMethods.iterator(); iterator.hasNext(); ) {
|
||||
Method method = iterator.next();
|
||||
try {
|
||||
|
||||
+2
-7
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.FilteringIterator;
|
||||
@@ -49,12 +48,8 @@ public class DiagnosticsWithSuppression implements Diagnostics {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Diagnostic> iterator() {
|
||||
return new FilteringIterator<Diagnostic, Diagnostic>(diagnostics.iterator(), new Condition<Diagnostic>() {
|
||||
@Override
|
||||
public boolean value(Diagnostic diagnostic) {
|
||||
return kotlinSuppressCache.getFilter().invoke(diagnostic);
|
||||
}
|
||||
});
|
||||
return new FilteringIterator<Diagnostic, Diagnostic>(diagnostics.iterator(),
|
||||
diagnostic -> kotlinSuppressCache.getFilter().invoke(diagnostic));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.lazy;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,7 +35,6 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.KtClassOrObjectInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
@@ -165,14 +163,7 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
this.trace = lockBasedLazyResolveStorageManager.createSafeTrace(delegationTrace);
|
||||
this.module = rootDescriptor;
|
||||
|
||||
this.packages =
|
||||
storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, LazyPackageDescriptor>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public LazyPackageDescriptor invoke(FqName fqName) {
|
||||
return createPackage(fqName);
|
||||
}
|
||||
});
|
||||
this.packages = storageManager.createMemoizedFunctionWithNullableValues(this::createPackage);
|
||||
|
||||
this.declarationProviderFactory = declarationProviderFactory;
|
||||
|
||||
@@ -196,19 +187,9 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
}
|
||||
};
|
||||
|
||||
fileAnnotations = storageManager.createMemoizedFunction(new Function1<KtFile, LazyAnnotations>() {
|
||||
@Override
|
||||
public LazyAnnotations invoke(KtFile file) {
|
||||
return createAnnotations(file, file.getAnnotationEntries());
|
||||
}
|
||||
});
|
||||
fileAnnotations = storageManager.createMemoizedFunction(file -> createAnnotations(file, file.getAnnotationEntries()));
|
||||
|
||||
danglingAnnotations = storageManager.createMemoizedFunction(new Function1<KtFile, LazyAnnotations>() {
|
||||
@Override
|
||||
public LazyAnnotations invoke(KtFile file) {
|
||||
return createAnnotations(file, file.getDanglingAnnotations());
|
||||
}
|
||||
});
|
||||
danglingAnnotations = storageManager.createMemoizedFunction(file -> createAnnotations(file, file.getDanglingAnnotations()));
|
||||
|
||||
syntheticResolveExtension = SyntheticResolveExtension.Companion.getInstance(project);
|
||||
}
|
||||
@@ -271,33 +252,25 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
|
||||
result.addAll(ContainerUtil.mapNotNull(
|
||||
provider.getClassOrObjectDeclarations(fqName.shortName()),
|
||||
new Function<KtClassLikeInfo, ClassifierDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor fun(KtClassLikeInfo classLikeInfo) {
|
||||
if (classLikeInfo instanceof KtClassOrObjectInfo) {
|
||||
//noinspection RedundantCast
|
||||
return getClassDescriptor(((KtClassOrObjectInfo) classLikeInfo).getCorrespondingClassOrObject(), location);
|
||||
}
|
||||
else if (classLikeInfo instanceof KtScriptInfo) {
|
||||
return getScriptDescriptor(((KtScriptInfo) classLikeInfo).getScript());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Unexpected " + classLikeInfo + " of type " + classLikeInfo.getClass().getName()
|
||||
);
|
||||
}
|
||||
classLikeInfo -> {
|
||||
if (classLikeInfo instanceof KtClassOrObjectInfo) {
|
||||
//noinspection RedundantCast
|
||||
return getClassDescriptor(((KtClassOrObjectInfo) classLikeInfo).getCorrespondingClassOrObject(), location);
|
||||
}
|
||||
else if (classLikeInfo instanceof KtScriptInfo) {
|
||||
return getScriptDescriptor(((KtScriptInfo) classLikeInfo).getScript());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Unexpected " + classLikeInfo + " of type " + classLikeInfo.getClass().getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
result.addAll(ContainerUtil.map(
|
||||
provider.getTypeAliasDeclarations(fqName.shortName()),
|
||||
new Function<KtTypeAlias, ClassifierDescriptor>() {
|
||||
@Override
|
||||
public ClassifierDescriptor fun(KtTypeAlias alias) {
|
||||
return (ClassifierDescriptor) lazyDeclarationResolver.resolveToDescriptor(alias);
|
||||
}
|
||||
}
|
||||
alias -> (ClassifierDescriptor) lazyDeclarationResolver.resolveToDescriptor(alias)
|
||||
));
|
||||
|
||||
return result;
|
||||
|
||||
+1
-7
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.lazy.declarations;
|
||||
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -29,12 +28,7 @@ public abstract class AbstractDeclarationProviderFactory implements DeclarationP
|
||||
|
||||
public AbstractDeclarationProviderFactory(@NotNull StorageManager storageManager) {
|
||||
this.packageDeclarationProviders =
|
||||
storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, PackageMemberDeclarationProvider>() {
|
||||
@Override
|
||||
public PackageMemberDeclarationProvider invoke(FqName fqName) {
|
||||
return createPackageMemberDeclarationProvider(fqName);
|
||||
}
|
||||
});
|
||||
storageManager.createMemoizedFunctionWithNullableValues(this::createPackageMemberDeclarationProvider);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-7
@@ -20,7 +20,6 @@ import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
@@ -45,12 +44,7 @@ public class FileBasedDeclarationProviderFactory extends AbstractDeclarationProv
|
||||
public FileBasedDeclarationProviderFactory(@NotNull StorageManager storageManager, @NotNull Collection<KtFile> files) {
|
||||
super(storageManager);
|
||||
this.storageManager = storageManager;
|
||||
this.index = storageManager.createLazyValue(new Function0<Index>() {
|
||||
@Override
|
||||
public Index invoke() {
|
||||
return computeFilesByPackage(files);
|
||||
}
|
||||
});
|
||||
this.index = storageManager.createLazyValue(() -> computeFilesByPackage(files));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+48
-105
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -142,24 +141,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
KtModifierList modifierList = classLikeInfo.getModifierList();
|
||||
if (kind.isSingleton()) {
|
||||
this.modality = storageManager.createLazyValue(new Function0<Modality>() {
|
||||
@Override
|
||||
public Modality invoke() {
|
||||
return Modality.FINAL;
|
||||
}
|
||||
});
|
||||
this.modality = storageManager.createLazyValue(() -> Modality.FINAL);
|
||||
}
|
||||
else {
|
||||
Modality defaultModality = kind == ClassKind.INTERFACE ? Modality.ABSTRACT : Modality.FINAL;
|
||||
this.modality = storageManager.createLazyValue(new Function0<Modality>() {
|
||||
@Override
|
||||
public Modality invoke() {
|
||||
return resolveModalityFromModifiers(classOrObject, defaultModality,
|
||||
c.getTrace().getBindingContext(),
|
||||
null,
|
||||
/* allowSealed = */ true);
|
||||
}
|
||||
});
|
||||
this.modality = storageManager.createLazyValue(
|
||||
() -> resolveModalityFromModifiers(classOrObject, defaultModality, c.getTrace().getBindingContext(),
|
||||
null, /* allowSealed = */ true));
|
||||
}
|
||||
|
||||
boolean isLocal = classOrObject != null && KtPsiUtil.isLocal(classOrObject);
|
||||
@@ -227,76 +215,49 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
);
|
||||
}
|
||||
|
||||
this.companionObjectDescriptor = storageManager.createNullableLazyValue(new Function0<ClassDescriptorWithResolutionScopes>() {
|
||||
@Override
|
||||
public ClassDescriptorWithResolutionScopes invoke() {
|
||||
return computeCompanionObjectDescriptor(getCompanionObjectIfAllowed());
|
||||
}
|
||||
});
|
||||
this.extraCompanionObjectDescriptors = storageManager.createMemoizedFunction(new Function1<KtObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(KtObjectDeclaration companionObject) {
|
||||
return computeCompanionObjectDescriptor(companionObject);
|
||||
}
|
||||
});
|
||||
this.forceResolveAllContents = storageManager.createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
@Override
|
||||
public Void invoke() {
|
||||
doForceResolveAllContents();
|
||||
return null;
|
||||
}
|
||||
this.companionObjectDescriptor = storageManager.createNullableLazyValue(
|
||||
() -> computeCompanionObjectDescriptor(getCompanionObjectIfAllowed())
|
||||
);
|
||||
this.extraCompanionObjectDescriptors = storageManager.createMemoizedFunction(this::computeCompanionObjectDescriptor);
|
||||
this.forceResolveAllContents = storageManager.createRecursionTolerantNullableLazyValue(() -> {
|
||||
doForceResolveAllContents();
|
||||
return null;
|
||||
}, null);
|
||||
|
||||
this.resolutionScopesSupport = new ClassResolutionScopesSupport(this, storageManager, new Function0<LexicalScope>() {
|
||||
@Override
|
||||
public LexicalScope invoke() {
|
||||
return getOuterScope();
|
||||
this.resolutionScopesSupport = new ClassResolutionScopesSupport(this, storageManager, this::getOuterScope);
|
||||
|
||||
this.parameters = c.getStorageManager().createLazyValue(() -> {
|
||||
KtClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
KtTypeParameterList typeParameterList = classInfo.getTypeParameterList();
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
if (classInfo.getClassKind() == ClassKind.OBJECT) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_OBJECT.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<KtTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
if (typeParameters.isEmpty()) return Collections.emptyList();
|
||||
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
});
|
||||
|
||||
this.parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
KtClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
KtTypeParameterList typeParameterList = classInfo.getTypeParameterList();
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
this.scopeForInitializerResolution = storageManager.createLazyValue(
|
||||
() -> ClassResolutionScopesSupportKt.scopeForInitializerResolution(
|
||||
this, createInitializerScopeParent(), classLikeInfo.getPrimaryConstructorParameters()
|
||||
)
|
||||
);
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
if (classInfo.getClassKind() == ClassKind.OBJECT) {
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_OBJECT.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<KtTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
if (typeParameters.isEmpty()) return Collections.emptyList();
|
||||
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, LazyClassDescriptor.this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
}
|
||||
});
|
||||
|
||||
this.scopeForInitializerResolution = storageManager.createLazyValue(new Function0<LexicalScope>() {
|
||||
@Override
|
||||
public LexicalScope invoke() {
|
||||
return ClassResolutionScopesSupportKt.scopeForInitializerResolution(LazyClassDescriptor.this,
|
||||
createInitializerScopeParent(),
|
||||
classLikeInfo.getPrimaryConstructorParameters());
|
||||
}
|
||||
});
|
||||
|
||||
this.sealedSubclasses = storageManager.createLazyValue(new Function0<Collection<ClassDescriptor>>() {
|
||||
@Override
|
||||
public Collection<ClassDescriptor> invoke() {
|
||||
// TODO: only consider classes from the same file, not the whole package fragment
|
||||
return DescriptorUtilsKt.computeSealedSubclasses(LazyClassDescriptor.this);
|
||||
}
|
||||
});
|
||||
// TODO: only consider classes from the same file, not the whole package fragment
|
||||
this.sealedSubclasses = storageManager.createLazyValue(() -> DescriptorUtilsKt.computeSealedSubclasses(this));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -390,13 +351,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
//noinspection unchecked
|
||||
return (Collection) CollectionsKt.filter(
|
||||
DescriptorUtils.getAllDescriptors(unsubstitutedMemberScope),
|
||||
new Function1<DeclarationDescriptor, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof CallableMemberDescriptor
|
||||
&& ((CallableMemberDescriptor) descriptor).getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
|
||||
}
|
||||
}
|
||||
descriptor -> descriptor instanceof CallableMemberDescriptor
|
||||
&& ((CallableMemberDescriptor) descriptor).getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -436,19 +392,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return CollectionsKt.map(
|
||||
CollectionsKt.filter(
|
||||
declarationProvider.getOwnerInfo().getCompanionObjects(),
|
||||
new Function1<KtObjectDeclaration, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(KtObjectDeclaration companionObject) {
|
||||
return companionObject != allowedCompanionObject;
|
||||
}
|
||||
}
|
||||
companionObject -> companionObject != allowedCompanionObject
|
||||
),
|
||||
new Function1<KtObjectDeclaration, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor invoke(KtObjectDeclaration companionObject) {
|
||||
return extraCompanionObjectDescriptors.invoke(companionObject);
|
||||
}
|
||||
}
|
||||
extraCompanionObjectDescriptors
|
||||
);
|
||||
}
|
||||
|
||||
@@ -623,12 +569,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
private class LazyClassTypeConstructor extends AbstractClassTypeConstructor {
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
return TypeParameterUtilsKt.computeConstructorTypeParameters(LazyClassDescriptor.this);
|
||||
}
|
||||
});
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(
|
||||
() -> TypeParameterUtilsKt.computeConstructorTypeParameters(LazyClassDescriptor.this)
|
||||
);
|
||||
|
||||
public LazyClassTypeConstructor() {
|
||||
super(LazyClassDescriptor.this.c.getStorageManager());
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
@@ -31,13 +29,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BoundsSubstitutor {
|
||||
private static final Function<TypeProjection,KotlinType> PROJECTIONS_TO_TYPES = new Function<TypeProjection, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType apply(TypeProjection projection) {
|
||||
return projection.getType();
|
||||
}
|
||||
};
|
||||
|
||||
private BoundsSubstitutor() {
|
||||
}
|
||||
|
||||
@@ -79,14 +70,8 @@ public class BoundsSubstitutor {
|
||||
// In the end, we want every parameter to have no references to those after it in the list
|
||||
// This gives us the reversed order: the one that refers to everybody else comes first
|
||||
List<TypeParameterDescriptor> topOrder = DFS.topologicalOrder(
|
||||
typeParameters,
|
||||
new DFS.Neighbors<TypeParameterDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<TypeParameterDescriptor> getNeighbors(TypeParameterDescriptor current) {
|
||||
return getTypeParametersFromUpperBounds(current, typeParameters);
|
||||
}
|
||||
});
|
||||
typeParameters, current -> getTypeParametersFromUpperBounds(current, typeParameters)
|
||||
);
|
||||
|
||||
assert topOrder.size() == typeParameters.size() : "All type parameters must be visited, but only " + topOrder + " were";
|
||||
|
||||
@@ -102,13 +87,7 @@ public class BoundsSubstitutor {
|
||||
) {
|
||||
return DFS.dfs(
|
||||
current.getUpperBounds(),
|
||||
new DFS.Neighbors<KotlinType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<KotlinType> getNeighbors(KotlinType current) {
|
||||
return Collections2.transform(current.getArguments(), PROJECTIONS_TO_TYPES);
|
||||
}
|
||||
},
|
||||
typeParameter -> CollectionsKt.map(typeParameter.getArguments(), TypeProjection::getType),
|
||||
new DFS.NodeHandlerWithListResult<KotlinType, TypeParameterDescriptor>() {
|
||||
@Override
|
||||
public boolean beforeChildren(KotlinType current) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -68,15 +67,12 @@ public class CommonSupertypes {
|
||||
}
|
||||
|
||||
private static int depth(@NotNull KotlinType type) {
|
||||
return 1 + maxDepth(CollectionsKt.map(type.getArguments(), new Function1<TypeProjection, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke(TypeProjection projection) {
|
||||
if (projection.isStarProjection()) {
|
||||
// any type is good enough for depth here
|
||||
return type.getConstructor().getBuiltIns().getAnyType();
|
||||
}
|
||||
return projection.getType();
|
||||
return 1 + maxDepth(CollectionsKt.map(type.getArguments(), projection -> {
|
||||
if (projection.isStarProjection()) {
|
||||
// any type is good enough for depth here
|
||||
return type.getConstructor().getBuiltIns().getAnyType();
|
||||
}
|
||||
return projection.getType();
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -336,28 +332,19 @@ public class CommonSupertypes {
|
||||
) {
|
||||
return DFS.dfs(
|
||||
Collections.singletonList(type),
|
||||
new DFS.Neighbors<SimpleType>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<? extends SimpleType> getNeighbors(SimpleType current) {
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(current);
|
||||
Collection<KotlinType> supertypes = current.getConstructor().getSupertypes();
|
||||
List<SimpleType> result = new ArrayList<SimpleType>(supertypes.size());
|
||||
for (KotlinType supertype : supertypes) {
|
||||
if (visited.contains(supertype.getConstructor())) {
|
||||
continue;
|
||||
}
|
||||
result.add(FlexibleTypesKt.lowerIfFlexible(substitutor.safeSubstitute(supertype, Variance.INVARIANT)));
|
||||
current -> {
|
||||
TypeSubstitutor substitutor = TypeSubstitutor.create(current);
|
||||
Collection<KotlinType> supertypes = current.getConstructor().getSupertypes();
|
||||
List<SimpleType> result = new ArrayList<SimpleType>(supertypes.size());
|
||||
for (KotlinType supertype : supertypes) {
|
||||
if (visited.contains(supertype.getConstructor())) {
|
||||
continue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
},
|
||||
new DFS.Visited<SimpleType>() {
|
||||
@Override
|
||||
public boolean checkAndMarkVisited(SimpleType current) {
|
||||
return visited.add(current.getConstructor());
|
||||
result.add(FlexibleTypesKt.lowerIfFlexible(substitutor.safeSubstitute(supertype, Variance.INVARIANT)));
|
||||
}
|
||||
return result;
|
||||
},
|
||||
current -> visited.add(current.getConstructor()),
|
||||
new DFS.NodeHandlerWithListResult<SimpleType, TypeConstructor>() {
|
||||
@Override
|
||||
public boolean beforeChildren(SimpleType current) {
|
||||
|
||||
@@ -28,20 +28,9 @@ import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.DEFERRED_TYPE;
|
||||
|
||||
public class DeferredType extends WrappedType {
|
||||
|
||||
private static final Function1 EMPTY_CONSUMER = new Function1<Object, Void>() {
|
||||
@Override
|
||||
public Void invoke(Object t) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function1<Boolean,KotlinType> RECURSION_PREVENTER = new Function1<Boolean, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke(Boolean firstTime) {
|
||||
if (firstTime) throw new ReenteringLazyValueComputationException();
|
||||
return ErrorUtils.createErrorType("Recursive dependency");
|
||||
}
|
||||
private static final Function1<Boolean, KotlinType> RECURSION_PREVENTER = firstTime -> {
|
||||
if (firstTime) throw new ReenteringLazyValueComputationException();
|
||||
return ErrorUtils.createErrorType("Recursive dependency");
|
||||
};
|
||||
|
||||
@NotNull
|
||||
@@ -62,11 +51,8 @@ public class DeferredType extends WrappedType {
|
||||
@NotNull Function0<KotlinType> compute
|
||||
) {
|
||||
//noinspection unchecked
|
||||
DeferredType deferredType = new DeferredType(storageManager.createLazyValueWithPostCompute(
|
||||
compute,
|
||||
RECURSION_PREVENTER,
|
||||
EMPTY_CONSUMER
|
||||
));
|
||||
DeferredType deferredType =
|
||||
new DeferredType(storageManager.createLazyValueWithPostCompute(compute, RECURSION_PREVENTER, t -> null));
|
||||
trace.record(DEFERRED_TYPE, new Box<DeferredType>(deferredType));
|
||||
return deferredType;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.CallHandle;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
|
||||
import java.util.*;
|
||||
@@ -174,17 +173,14 @@ public class TypeIntersector {
|
||||
private static boolean unify(KotlinType withParameters, KotlinType expected) {
|
||||
// T -> how T is used
|
||||
Map<TypeParameterDescriptor, Variance> parameters = new HashMap<TypeParameterDescriptor, Variance>();
|
||||
Function1<TypeParameterUsage, Unit> processor = new Function1<TypeParameterUsage, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(TypeParameterUsage parameterUsage) {
|
||||
Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor);
|
||||
if (howTheTypeIsUsedBefore == null) {
|
||||
howTheTypeIsUsedBefore = Variance.INVARIANT;
|
||||
}
|
||||
parameters.put(parameterUsage.typeParameterDescriptor,
|
||||
parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore));
|
||||
return Unit.INSTANCE;
|
||||
Function1<TypeParameterUsage, Unit> processor = parameterUsage -> {
|
||||
Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor);
|
||||
if (howTheTypeIsUsedBefore == null) {
|
||||
howTheTypeIsUsedBefore = Variance.INVARIANT;
|
||||
}
|
||||
parameters.put(parameterUsage.typeParameterDescriptor,
|
||||
parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore));
|
||||
return Unit.INSTANCE;
|
||||
};
|
||||
processAllTypeParameters(withParameters, Variance.INVARIANT, processor);
|
||||
processAllTypeParameters(expected, Variance.INVARIANT, processor);
|
||||
|
||||
+12
-45
@@ -23,8 +23,6 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.TuplesKt;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.KtNodeTypes;
|
||||
@@ -73,7 +71,6 @@ import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.Resolv
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
import org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperKt;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -720,30 +717,12 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
KotlinType[] result = new KotlinType[1];
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace,
|
||||
"trace to resolve object literal expression", expression);
|
||||
ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor> handler =
|
||||
new ObservableBindingTrace.RecordHandler<PsiElement, ClassDescriptor>() {
|
||||
|
||||
@Override
|
||||
public void handleRecord(
|
||||
WritableSlice<PsiElement, ClassDescriptor> slice,
|
||||
PsiElement declaration,
|
||||
ClassDescriptor descriptor
|
||||
) {
|
||||
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
|
||||
KotlinType defaultType = components.wrappedTypeFactory.createRecursionIntolerantDeferredType(
|
||||
context.trace,
|
||||
new Function0<KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke() {
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
});
|
||||
result[0] = defaultType;
|
||||
}
|
||||
}
|
||||
};
|
||||
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(temporaryTrace);
|
||||
traceAdapter.addHandler(CLASS, handler);
|
||||
traceAdapter.addHandler(CLASS, (slice, declaration, descriptor) -> {
|
||||
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
|
||||
result[0] = components.wrappedTypeFactory.createRecursionIntolerantDeferredType(context.trace, descriptor::getDefaultType);
|
||||
}
|
||||
});
|
||||
components.localClassifierAnalyzer.processClassOrObject(null, // don't need to add classifier of object literal to any scope
|
||||
context.replaceBindingTrace(traceAdapter)
|
||||
.replaceContextDependency(INDEPENDENT),
|
||||
@@ -1199,13 +1178,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
OverloadResolutionResults<FunctionDescriptor> resolutionResults =
|
||||
components.callResolver.resolveCallWithGivenName(newContext, call, operationSign, OperatorNameConventions.EQUALS);
|
||||
|
||||
traceInterpretingRightAsNullableAny.commit(new TraceEntryFilter() {
|
||||
@Override
|
||||
public boolean accept(@Nullable WritableSlice<?, ?> slice, Object key) {
|
||||
// the type of the right (and sometimes left) expression isn't 'Any?' actually
|
||||
if ((key == right || key == left) && slice == EXPRESSION_TYPE_INFO) return false;
|
||||
return true;
|
||||
}
|
||||
traceInterpretingRightAsNullableAny.commit((slice, key) -> {
|
||||
// the type of the right (and sometimes left) expression isn't 'Any?' actually
|
||||
if ((key == right || key == left) && slice == EXPRESSION_TYPE_INFO) return false;
|
||||
return true;
|
||||
}, true);
|
||||
|
||||
if (resolutionResults.isSuccess()) {
|
||||
@@ -1462,18 +1438,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
SenselessComparisonChecker.checkSenselessComparisonWithNull(
|
||||
expression, left, right, context,
|
||||
new Function1<KtExpression, KotlinType>() {
|
||||
@Override
|
||||
public KotlinType invoke(KtExpression expression) {
|
||||
return facade.getTypeInfo(expression, context).getType();
|
||||
}
|
||||
},
|
||||
new Function1<DataFlowValue, Nullability>() {
|
||||
@Override
|
||||
public Nullability invoke(DataFlowValue value) {
|
||||
return context.dataFlowInfo.getStableNullability(value);
|
||||
}
|
||||
});
|
||||
expr -> facade.getTypeInfo(expr, context).getType(),
|
||||
context.dataFlowInfo::getStableNullability
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -111,12 +111,7 @@ public class ExpressionTypingServices {
|
||||
trace, scope, dataFlowInfo, expectedType, contextDependency, statementFilter
|
||||
);
|
||||
if (contextExpression != expression) {
|
||||
context = context.replaceExpressionContextProvider(new Function1<KtExpression, KtExpression>() {
|
||||
@Override
|
||||
public KtExpression invoke(KtExpression arg) {
|
||||
return arg == expression ? contextExpression : null;
|
||||
}
|
||||
});
|
||||
context = context.replaceExpressionContextProvider(arg -> arg == expression ? contextExpression : null);
|
||||
}
|
||||
return expressionTypingFacade.getTypeInfo(expression, context, isStatement);
|
||||
}
|
||||
|
||||
+48
-52
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.types.expressions;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
|
||||
@@ -169,64 +168,61 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
|
||||
|
||||
@NotNull
|
||||
private KotlinTypeInfo getTypeInfo(@NotNull KtExpression expression, ExpressionTypingContext context, KtVisitor<KotlinTypeInfo, ExpressionTypingContext> visitor) {
|
||||
return typeInfoPerfCounter.time(new Function0<KotlinTypeInfo>() {
|
||||
@Override
|
||||
public KotlinTypeInfo invoke() {
|
||||
return typeInfoPerfCounter.time(() -> {
|
||||
try {
|
||||
KotlinTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||
if (recordedTypeInfo != null) {
|
||||
return recordedTypeInfo;
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.DATA_FLOW_INFO_BEFORE, expression, context.dataFlowInfo);
|
||||
|
||||
KotlinTypeInfo result;
|
||||
try {
|
||||
KotlinTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||
if (recordedTypeInfo != null) {
|
||||
return recordedTypeInfo;
|
||||
result = expression.accept(visitor, context);
|
||||
// Some recursive definitions (object expressions) must put their types in the cache manually:
|
||||
//noinspection ConstantConditions
|
||||
if (context.trace.get(BindingContext.PROCESSED, expression) == Boolean.TRUE) {
|
||||
KotlinType type = context.trace.getBindingContext().getType(expression);
|
||||
return result.replaceType(type);
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.DATA_FLOW_INFO_BEFORE, expression, context.dataFlowInfo);
|
||||
|
||||
KotlinTypeInfo result;
|
||||
try {
|
||||
result = expression.accept(visitor, context);
|
||||
// Some recursive definitions (object expressions) must put their types in the cache manually:
|
||||
//noinspection ConstantConditions
|
||||
if (context.trace.get(BindingContext.PROCESSED, expression) == Boolean.TRUE) {
|
||||
KotlinType type = context.trace.getBindingContext().getType(expression);
|
||||
return result.replaceType(type);
|
||||
}
|
||||
|
||||
if (result.getType() instanceof DeferredType) {
|
||||
result = result.replaceType(((DeferredType) result.getType()).getDelegate());
|
||||
}
|
||||
context.trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, result);
|
||||
if (result.getType() instanceof DeferredType) {
|
||||
result = result.replaceType(((DeferredType) result.getType()).getDelegate());
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
result = TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.PROCESSED, expression);
|
||||
|
||||
// todo save scope before analyze and fix debugger: see CodeFragmentAnalyzer.correctContextForExpression
|
||||
BindingContextUtilsKt.recordScope(context.trace, context.scope, expression);
|
||||
BindingContextUtilsKt.recordDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
|
||||
try {
|
||||
// Here we have to resolve some types, so the following exception is possible
|
||||
// Example: val a = ::a, fun foo() = ::foo
|
||||
recordTypeInfo(expression, result);
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
return result;
|
||||
context.trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, result);
|
||||
}
|
||||
catch (ProcessCanceledException | KotlinFrontEndException e) {
|
||||
throw e;
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
result = TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.trace.report(Errors.EXCEPTION_FROM_ANALYZER.on(expression, e));
|
||||
logOrThrowException(expression, e);
|
||||
return TypeInfoFactoryKt.createTypeInfo(
|
||||
ErrorUtils.createErrorType(e.getClass().getSimpleName() + " from analyzer"),
|
||||
context
|
||||
);
|
||||
|
||||
context.trace.record(BindingContext.PROCESSED, expression);
|
||||
|
||||
// todo save scope before analyze and fix debugger: see CodeFragmentAnalyzer.correctContextForExpression
|
||||
BindingContextUtilsKt.recordScope(context.trace, context.scope, expression);
|
||||
BindingContextUtilsKt.recordDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
|
||||
try {
|
||||
// Here we have to resolve some types, so the following exception is possible
|
||||
// Example: val a = ::a, fun foo() = ::foo
|
||||
recordTypeInfo(expression, result);
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (ProcessCanceledException | KotlinFrontEndException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
context.trace.report(Errors.EXCEPTION_FROM_ANALYZER.on(expression, e));
|
||||
logOrThrowException(expression, e);
|
||||
return TypeInfoFactoryKt.createTypeInfo(
|
||||
ErrorUtils.createErrorType(e.getClass().getSimpleName() + " from analyzer"),
|
||||
context
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,12 +54,9 @@ public class TrackingSlicedMap extends SlicedMapImpl {
|
||||
|
||||
@Override
|
||||
public void forEach(@NotNull Function3<WritableSlice, Object, Object, Void> f) {
|
||||
super.forEach(new Function3<WritableSlice, Object, Object, Void>() {
|
||||
@Override
|
||||
public Void invoke(WritableSlice slice, Object key, Object value) {
|
||||
f.invoke(((SliceWithStackTrace) slice).getWritableDelegate(), key, ((TrackableValue<?>) value).value);
|
||||
return null;
|
||||
}
|
||||
super.forEach((slice, key, value) -> {
|
||||
f.invoke(((SliceWithStackTrace) slice).getWritableDelegate(), key, ((TrackableValue<?>) value).value);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+12
-24
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava.finder;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
@@ -179,12 +178,7 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
||||
|
||||
Collection<FqName> subpackages = lightClassGenerationSupport.getSubPackages(packageFQN, scope);
|
||||
|
||||
Collection<PsiPackage> answer = Collections2.transform(subpackages, new Function<FqName, PsiPackage>() {
|
||||
@Override
|
||||
public PsiPackage apply(@Nullable FqName input) {
|
||||
return new KtLightPackage(psiManager, input, scope);
|
||||
}
|
||||
});
|
||||
Collection<PsiPackage> answer = Collections2.transform(subpackages, input -> new KtLightPackage(psiManager, input, scope));
|
||||
|
||||
return answer.toArray(new PsiPackage[answer.size()]);
|
||||
}
|
||||
@@ -219,29 +213,23 @@ public class JavaElementFinder extends PsiElementFinder implements KotlinFinderM
|
||||
@Override
|
||||
@Nullable
|
||||
public Condition<PsiFile> getPackageFilesFilter(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
return new Condition<PsiFile>() {
|
||||
@Override
|
||||
public boolean value(PsiFile input) {
|
||||
if (!(input instanceof KtFile)) {
|
||||
return true;
|
||||
}
|
||||
return psiPackage.getQualifiedName().equals(((KtFile) input).getPackageFqName().asString());
|
||||
return input -> {
|
||||
if (!(input instanceof KtFile)) {
|
||||
return true;
|
||||
}
|
||||
return psiPackage.getQualifiedName().equals(((KtFile) input).getPackageFqName().asString());
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Comparator<PsiElement> byClasspathComparator(@NotNull GlobalSearchScope searchScope) {
|
||||
return new Comparator<PsiElement>() {
|
||||
@Override
|
||||
public int compare(@NotNull PsiElement o1, @NotNull PsiElement o2) {
|
||||
VirtualFile f1 = PsiUtilCore.getVirtualFile(o1);
|
||||
VirtualFile f2 = PsiUtilCore.getVirtualFile(o2);
|
||||
if (f1 == f2) return 0;
|
||||
if (f1 == null) return -1;
|
||||
if (f2 == null) return 1;
|
||||
return searchScope.compare(f2, f1);
|
||||
}
|
||||
return (o1, o2) -> {
|
||||
VirtualFile f1 = PsiUtilCore.getVirtualFile(o1);
|
||||
VirtualFile f2 = PsiUtilCore.getVirtualFile(o2);
|
||||
if (f1 == f2) return 0;
|
||||
if (f1 == null) return -1;
|
||||
if (f2 == null) return 1;
|
||||
return searchScope.compare(f2, f1);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+14
-21
@@ -107,12 +107,8 @@ public class InterceptionInstrumenter {
|
||||
}
|
||||
|
||||
if (enterData.isEmpty() && normalReturnData.isEmpty() && exceptionData.isEmpty()) {
|
||||
dumpTasks.add(new DumpAction() {
|
||||
@Override
|
||||
public void dump(PrintStream out) {
|
||||
out.println("WARNING: No relevant methods found in " + field + " of type " + interceptorClass.getCanonicalName());
|
||||
}
|
||||
});
|
||||
dumpTasks.add(out -> out.println("WARNING: No relevant methods found in " + field +
|
||||
" of type " + interceptorClass.getCanonicalName()));
|
||||
}
|
||||
|
||||
String nameFromAnnotation = annotation.methodName();
|
||||
@@ -215,24 +211,21 @@ public class InterceptionInstrumenter {
|
||||
}
|
||||
|
||||
private void addDumpTask(Object interceptor, Method method, MethodInstrumenter instrumenter) {
|
||||
dumpTasks.add(new DumpAction() {
|
||||
@Override
|
||||
public void dump(PrintStream out) {
|
||||
out.println("<<< " + instrumenter + ": " + interceptor.getClass().getName() + " says:");
|
||||
try {
|
||||
if (method.getParameterTypes().length == 0) {
|
||||
method.invoke(interceptor);
|
||||
}
|
||||
else {
|
||||
method.invoke(interceptor, out);
|
||||
}
|
||||
dumpTasks.add(out -> {
|
||||
out.println("<<< " + instrumenter + ": " + interceptor.getClass().getName() + " says:");
|
||||
try {
|
||||
if (method.getParameterTypes().length == 0) {
|
||||
method.invoke(interceptor);
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new IllegalStateException(e);
|
||||
else {
|
||||
method.invoke(interceptor, out);
|
||||
}
|
||||
out.println(">>>");
|
||||
out.println();
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
out.println(">>>");
|
||||
out.println();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -56,16 +56,13 @@ public class Preloader {
|
||||
Method mainMethod = mainClass.getMethod("main", String[].class);
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (options.measure) {
|
||||
System.out.println();
|
||||
System.out.println("=== Preloader's measurements: ");
|
||||
System.out.format("Total time: %.3fs\n", (System.nanoTime() - startTime) / 1e9);
|
||||
}
|
||||
handler.done();
|
||||
new Thread(() -> {
|
||||
if (options.measure) {
|
||||
System.out.println();
|
||||
System.out.println("=== Preloader's measurements: ");
|
||||
System.out.format("Total time: %.3fs\n", (System.nanoTime() - startTime) / 1e9);
|
||||
}
|
||||
handler.done();
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.resolve.scopes;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
@@ -35,14 +34,11 @@ public final class ScopeUtils {
|
||||
return new LexicalScopeImpl(parent, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_HEADER,
|
||||
// redeclaration on type parameters should be reported early, see: DescriptorResolver.resolvePropertyDescriptor()
|
||||
LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) {
|
||||
handler.addClassifierDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
handler -> {
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) {
|
||||
handler.addClassifierDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import kotlin.io.FilesKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -82,14 +81,11 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
protected static List<String> findJavaSourcesInDirectory(@NotNull File directory) {
|
||||
List<String> javaFilePaths = new ArrayList<String>(1);
|
||||
|
||||
FileUtil.processFilesRecursively(directory, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (file.isFile() && FilesKt.getExtension(file).equals(JavaFileType.DEFAULT_EXTENSION)) {
|
||||
javaFilePaths.add(file.getPath());
|
||||
}
|
||||
return true;
|
||||
FileUtil.processFilesRecursively(directory, file -> {
|
||||
if (file.isFile() && FilesKt.getExtension(file).equals(JavaFileType.DEFAULT_EXTENSION)) {
|
||||
javaFilePaths.add(file.getPath());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return javaFilePaths;
|
||||
|
||||
+2
-14
@@ -17,10 +17,8 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
@@ -76,19 +74,9 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
String classFileRegex = StringUtil.escapeToRegexp(split[0] + ".class").replace("\\*", ".+");
|
||||
String methodName = split[1];
|
||||
|
||||
OutputFile outputFile = ContainerUtil.find(outputFiles.asList(), new Condition<OutputFile>() {
|
||||
@Override
|
||||
public boolean value(OutputFile outputFile) {
|
||||
return outputFile.getRelativePath().matches(classFileRegex);
|
||||
}
|
||||
});
|
||||
OutputFile outputFile = ContainerUtil.find(outputFiles.asList(), file -> file.getRelativePath().matches(classFileRegex));
|
||||
|
||||
String pathsString = StringUtil.join(outputFiles.asList(), new Function<OutputFile, String>() {
|
||||
@Override
|
||||
public String fun(OutputFile file) {
|
||||
return file.getRelativePath();
|
||||
}
|
||||
}, ", ");
|
||||
String pathsString = StringUtil.join(outputFiles.asList(), OutputFile::getRelativePath, ", ");
|
||||
assertNotNull("Couldn't find class file for pattern " + classFileRegex + " in: " + pathsString, outputFile);
|
||||
|
||||
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
@@ -115,12 +114,7 @@ public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
||||
}
|
||||
|
||||
private static String getActualLineNumbersAsString(List<String> lines) {
|
||||
return CollectionsKt.joinToString(lines, " ", "// ", "", -1, "...", new Function1<String, CharSequence>() {
|
||||
@Override
|
||||
public CharSequence invoke(String lineNumber) {
|
||||
return lineNumber;
|
||||
}
|
||||
});
|
||||
return CollectionsKt.joinToString(lines, " ", "// ", "", -1, "...", lineNumber -> lineNumber);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+5
-14
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
@@ -42,21 +41,13 @@ public abstract class AbstractTopLevelMembersInvocationTest extends AbstractByte
|
||||
File root = new File(filename);
|
||||
List<String> sourceFiles = new ArrayList<String>(2);
|
||||
|
||||
FileUtil.processFilesRecursively(root, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (file.getName().endsWith(".kt")) {
|
||||
sourceFiles.add(relativePath(file));
|
||||
return true;
|
||||
}
|
||||
FileUtil.processFilesRecursively(root, file -> {
|
||||
if (file.getName().endsWith(".kt")) {
|
||||
sourceFiles.add(relativePath(file));
|
||||
return true;
|
||||
}
|
||||
}, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
return !LIBRARY.equals(file.getName());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}, file -> !LIBRARY.equals(file.getName()));
|
||||
|
||||
File library = new File(root, LIBRARY);
|
||||
List<File> classPath = library.exists() ?
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -127,14 +126,7 @@ public class CodegenTestUtil {
|
||||
));
|
||||
options.addAll(additionalOptions);
|
||||
|
||||
List<File> fileList = CollectionsKt.map(fileNames, new Function1<String, File>() {
|
||||
@Override
|
||||
public File invoke(String input) {
|
||||
return new File(input);
|
||||
}
|
||||
});
|
||||
|
||||
KotlinTestUtils.compileJavaFiles(fileList, options);
|
||||
KotlinTestUtils.compileJavaFiles(CollectionsKt.map(fileNames, File::new), options);
|
||||
|
||||
return javaClassesTempDirectory;
|
||||
}
|
||||
|
||||
+3
-8
@@ -27,8 +27,6 @@ import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.MatchResult;
|
||||
import kotlin.text.Regex;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -71,12 +69,9 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
||||
@Language("RegExp")
|
||||
String RELATIVE_PATH_WITH_MIXED_SEPARATOR = Regex.Companion.escape(pathId) + "[-.\\w/\\\\]*";
|
||||
|
||||
return new Regex(RELATIVE_PATH_WITH_MIXED_SEPARATOR).replace(contentWithRelativePaths, new Function1<MatchResult, String>() {
|
||||
@Override
|
||||
public String invoke(MatchResult mr) {
|
||||
return FileUtil.toSystemIndependentName(mr.getValue());
|
||||
}
|
||||
});
|
||||
return new Regex(RELATIVE_PATH_WITH_MIXED_SEPARATOR).replace(
|
||||
contentWithRelativePaths, mr -> FileUtil.toSystemIndependentName(mr.getValue())
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -18,9 +18,7 @@ package org.jetbrains.kotlin.jvm.compiler;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import junit.framework.ComparisonFailure;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
@@ -31,7 +29,10 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.config.ContentRootsKt;
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
@@ -46,7 +47,6 @@ import org.jetbrains.kotlin.test.util.DescriptorValidator;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -142,12 +142,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
File expectedFile = new File(expectedFileName);
|
||||
File sourcesDir = new File(expectedFileName.replaceFirst("\\.txt$", ""));
|
||||
|
||||
FileUtil.copyDir(sourcesDir, new File(tmpdir, "test"), new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(@NotNull File pathname) {
|
||||
return pathname.getName().endsWith(".java");
|
||||
}
|
||||
});
|
||||
FileUtil.copyDir(sourcesDir, new File(tmpdir, "test"), pathname -> pathname.getName().endsWith(".java"));
|
||||
|
||||
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, getJdkKind());
|
||||
ContentRootsKt.addKotlinSourceRoot(configuration, sourcesDir.getAbsolutePath());
|
||||
@@ -159,12 +154,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
|
||||
AnalysisResult result = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
environment.getProject(), environment.getSourceFiles(), new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(),
|
||||
configuration, new Function1<GlobalSearchScope, PackagePartProvider>() {
|
||||
@Override
|
||||
public PackagePartProvider invoke(GlobalSearchScope scope) {
|
||||
return new JvmPackagePartProvider(environment, scope);
|
||||
}
|
||||
}
|
||||
configuration, scope -> new JvmPackagePartProvider(environment, scope)
|
||||
);
|
||||
|
||||
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
@@ -107,15 +106,12 @@ public class LoadDescriptorUtil {
|
||||
|
||||
@NotNull
|
||||
private static List<KtFile> createKtFiles(@NotNull List<File> kotlinFiles, @NotNull KotlinCoreEnvironment environment) {
|
||||
return CollectionsKt.map(kotlinFiles, new Function1<File, KtFile>() {
|
||||
@Override
|
||||
public KtFile invoke(File kotlinFile) {
|
||||
try {
|
||||
return KotlinTestUtils.createFile(kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), environment.getProject());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
return CollectionsKt.map(kotlinFiles, kotlinFile -> {
|
||||
try {
|
||||
return KotlinTestUtils.createFile(kotlinFile.getName(), FileUtil.loadFile(kotlinFile, true), environment.getProject());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+25
-35
@@ -17,9 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.annotation;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -27,17 +25,18 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry;
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationUseSiteTarget;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.renderer.*;
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy;
|
||||
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
@@ -55,15 +54,12 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
||||
|
||||
public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTestWithEnvironment {
|
||||
private static final DescriptorRenderer WITH_ANNOTATION_ARGUMENT_TYPES = DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setClassifierNamePolicy(ClassifierNamePolicy.SHORT.INSTANCE);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
options -> {
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setClassifierNamePolicy(ClassifierNamePolicy.SHORT.INSTANCE);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -126,21 +122,18 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
}
|
||||
|
||||
private void checkAnnotationsOnFile(String expectedAnnotation, KtFile file) {
|
||||
String actualAnnotation = StringUtil.join(file.getAnnotationEntries(), new Function<KtAnnotationEntry, String>() {
|
||||
@Override
|
||||
public String fun(KtAnnotationEntry annotationEntry) {
|
||||
AnnotationDescriptor annotationDescriptor = context.get(BindingContext.ANNOTATION, annotationEntry);
|
||||
assertNotNull(annotationDescriptor);
|
||||
String actualAnnotation = StringUtil.join(file.getAnnotationEntries(), annotationEntry -> {
|
||||
AnnotationDescriptor annotationDescriptor = context.get(BindingContext.ANNOTATION, annotationEntry);
|
||||
assertNotNull(annotationDescriptor);
|
||||
|
||||
KtAnnotationUseSiteTarget target = annotationEntry.getUseSiteTarget();
|
||||
KtAnnotationUseSiteTarget target = annotationEntry.getUseSiteTarget();
|
||||
|
||||
if (target != null) {
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(
|
||||
annotationDescriptor, target.getAnnotationUseSiteTarget());
|
||||
}
|
||||
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor, null);
|
||||
if (target != null) {
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(
|
||||
annotationDescriptor, target.getAnnotationUseSiteTarget());
|
||||
}
|
||||
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor, null);
|
||||
}, " ");
|
||||
|
||||
String expectedAnnotationWithTarget = "@" + AnnotationUseSiteTarget.FILE.getRenderName() + ":" + expectedAnnotation.substring(1);
|
||||
@@ -366,16 +359,13 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
}
|
||||
|
||||
private static String renderAnnotations(Annotations annotations, @Nullable AnnotationUseSiteTarget defaultTarget) {
|
||||
return StringUtil.join(annotations.getAllAnnotations(), new Function<AnnotationWithTarget, String>() {
|
||||
@Override
|
||||
public String fun(AnnotationWithTarget annotationWithTarget) {
|
||||
AnnotationUseSiteTarget targetToRender = annotationWithTarget.getTarget();
|
||||
if (targetToRender == defaultTarget) {
|
||||
targetToRender = null;
|
||||
}
|
||||
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationWithTarget.getAnnotation(), targetToRender);
|
||||
return StringUtil.join(annotations.getAllAnnotations(), annotationWithTarget -> {
|
||||
AnnotationUseSiteTarget targetToRender = annotationWithTarget.getTarget();
|
||||
if (targetToRender == defaultTarget) {
|
||||
targetToRender = null;
|
||||
}
|
||||
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationWithTarget.getAnnotation(), targetToRender);
|
||||
}, " ");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.testFramework.TestDataFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import junit.framework.TestCase;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
@@ -384,19 +382,11 @@ public class KotlinTestUtils {
|
||||
|
||||
public static void deleteOnShutdown(File file) {
|
||||
if (filesToDelete.isEmpty()) {
|
||||
ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ShutDownTracker.invokeAndWait(true, true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (File victim : filesToDelete) {
|
||||
FileUtil.delete(victim);
|
||||
}
|
||||
}
|
||||
});
|
||||
ShutDownTracker.getInstance().registerShutdownTask(() -> ShutDownTracker.invokeAndWait(true, true, () -> {
|
||||
for (File victim : filesToDelete) {
|
||||
FileUtil.delete(victim);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
filesToDelete.add(file);
|
||||
@@ -525,12 +515,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull String actual) {
|
||||
assertEqualsToFile(expectedFile, actual, new Function1<String, String>() {
|
||||
@Override
|
||||
public String invoke(String s) {
|
||||
return s;
|
||||
}
|
||||
});
|
||||
assertEqualsToFile(expectedFile, actual, s -> s);
|
||||
}
|
||||
|
||||
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull String actual, @NotNull Function1<String, String> sanitizer) {
|
||||
@@ -916,15 +901,12 @@ public class KotlinTestUtils {
|
||||
|
||||
Set<String> filePaths = collectPathsMetadata(testCaseClass);
|
||||
|
||||
FileUtil.processFilesRecursively(testDataDir, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (file.isFile() && filenamePattern.matcher(file.getName()).matches() && isCompatibleTarget(targetBackend, file)) {
|
||||
assertFilePathPresent(file, rootFile, filePaths);
|
||||
}
|
||||
|
||||
return true;
|
||||
FileUtil.processFilesRecursively(testDataDir, file -> {
|
||||
if (file.isFile() && filenamePattern.matcher(file.getName()).matches() && isCompatibleTarget(targetBackend, file)) {
|
||||
assertFilePathPresent(file, rootFile, filePaths);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -939,13 +921,7 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
private static Set<String> collectPathsMetadata(Class<?> testCaseClass) {
|
||||
return ContainerUtil.newHashSet(
|
||||
ContainerUtil.map(collectMethodsMetadata(testCaseClass), new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String pathData) {
|
||||
return nameToCompare(pathData);
|
||||
}
|
||||
}));
|
||||
return ContainerUtil.newHashSet(ContainerUtil.map(collectMethodsMetadata(testCaseClass), KotlinTestUtils::nameToCompare));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-10
@@ -24,8 +24,6 @@ import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.extensions.ExtensionsArea;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypeRegistry;
|
||||
import com.intellij.openapi.util.Getter;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
|
||||
@@ -46,14 +44,7 @@ public abstract class KtPlatformLiteFixture extends KtUsefulTestCase {
|
||||
|
||||
public void initApplication() {
|
||||
MockApplicationEx instance = new MockApplicationEx(getTestRootDisposable());
|
||||
ApplicationManager.setApplication(instance,
|
||||
new Getter<FileTypeRegistry>() {
|
||||
@Override
|
||||
public FileTypeRegistry get() {
|
||||
return FileTypeManager.getInstance();
|
||||
}
|
||||
},
|
||||
getTestRootDisposable());
|
||||
ApplicationManager.setApplication(instance, FileTypeManager::getInstance, getTestRootDisposable());
|
||||
getApplication().registerService(EncodingManager.class, CoreEncodingProjectManager.class);
|
||||
}
|
||||
|
||||
|
||||
+15
-24
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
@@ -210,23 +209,20 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
protected void runTest() throws Throwable {
|
||||
Throwable[] throwables = new Throwable[1];
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
KtUsefulTestCase.super.runTest();
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.fillInStackTrace();
|
||||
throwables[0] = e.getTargetException();
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
e.fillInStackTrace();
|
||||
throwables[0] = e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throwables[0] = e;
|
||||
}
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
super.runTest();
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
e.fillInStackTrace();
|
||||
throwables[0] = e.getTargetException();
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
e.fillInStackTrace();
|
||||
throwables[0] = e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throwables[0] = e;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -352,12 +348,7 @@ public abstract class KtUsefulTestCase extends TestCase {
|
||||
}
|
||||
|
||||
public static String toString(Collection<?> collection, String separator) {
|
||||
List<String> list = ContainerUtil.map2List(collection, new Function<Object, String>() {
|
||||
@Override
|
||||
public String fun(Object o) {
|
||||
return String.valueOf(o);
|
||||
}
|
||||
});
|
||||
List<String> list = ContainerUtil.map2List(collection, String::valueOf);
|
||||
Collections.sort(list);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean flag = false;
|
||||
|
||||
+10
-14
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.test.util;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -50,19 +49,16 @@ import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisit
|
||||
public class RecursiveDescriptorComparator {
|
||||
|
||||
private static final DescriptorRenderer DEFAULT_RENDERER = DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)));
|
||||
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||
options.setIncludePropertyConstant(true);
|
||||
options.setClassifierNamePolicy(ClassifierNamePolicy.FULLY_QUALIFIED.INSTANCE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
options -> {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)));
|
||||
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||
options.setIncludePropertyConstant(true);
|
||||
options.setClassifierNamePolicy(ClassifierNamePolicy.FULLY_QUALIFIED.INSTANCE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder;
|
||||
import org.jetbrains.kotlin.checkers.KotlinMultiFileTestWithJava;
|
||||
@@ -54,22 +52,14 @@ public abstract class AbstractCompilerLightClassTest extends KotlinMultiFileTest
|
||||
|
||||
@Override
|
||||
protected void doMultiFileTest(File file, Map<String, ModuleAndDependencies> modules, List<Void> files) throws IOException {
|
||||
LightClassTestCommon.INSTANCE.testLightClass(file, new Function1<String, PsiClass>() {
|
||||
@Override
|
||||
public PsiClass invoke(String s) {
|
||||
try {
|
||||
return createFinder(getEnvironment()).findClass(s, GlobalSearchScope.allScope(getEnvironment().getProject()));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
LightClassTestCommon.INSTANCE.testLightClass(file, s -> {
|
||||
try {
|
||||
return createFinder(getEnvironment()).findClass(s, GlobalSearchScope.allScope(getEnvironment().getProject()));
|
||||
}
|
||||
}, new Function1<String, String>() {
|
||||
@Override
|
||||
public String invoke(String s) {
|
||||
return LightClassTestCommon.INSTANCE.removeEmptyDefaultImpls(s);
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
});
|
||||
}, LightClassTestCommon.INSTANCE::removeEmptyDefaultImpls);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
|
||||
@@ -29,7 +28,6 @@ import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -237,15 +235,7 @@ public abstract class KotlinLightClassStructureTest extends KotlinAsJavaTestBase
|
||||
assertEquals(name, typeParameter.getName());
|
||||
assertEquals(index, typeParameter.getIndex());
|
||||
Set<String> expectedBounds = Sets.newHashSet(bounds);
|
||||
Set<String> actualBounds = Sets.newHashSet(Collections2.transform(
|
||||
Arrays.asList(typeParameter.getExtendsListTypes()),
|
||||
new Function<PsiClassType, String>() {
|
||||
@Override
|
||||
public String apply(PsiClassType input) {
|
||||
return input.getCanonicalText();
|
||||
}
|
||||
}
|
||||
));
|
||||
Set<String> actualBounds = Sets.newHashSet(ArraysKt.map(typeParameter.getExtendsListTypes(), PsiType::getCanonicalText));
|
||||
|
||||
assertEquals(expectedBounds, actualBounds);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cfg;
|
||||
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
|
||||
@@ -36,22 +35,19 @@ public abstract class AbstractControlFlowTest extends AbstractPseudocodeTest {
|
||||
) {
|
||||
int nextInstructionsColumnWidth = countNextInstructionsColumnWidth(pseudocode.getInstructionsIncludingDeadCode());
|
||||
|
||||
dumpInstructions(pseudocode, out, new Function3<Instruction, Instruction, Instruction, String>() {
|
||||
@Override
|
||||
public String invoke(Instruction instruction, Instruction next, Instruction prev) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Collection<Instruction> nextInstructions = instruction.getNextInstructions();
|
||||
dumpInstructions(pseudocode, out, (instruction, next, prev) -> {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Collection<Instruction> nextInstructions = instruction.getNextInstructions();
|
||||
|
||||
if (!sameContents(next, nextInstructions)) {
|
||||
result.append(" NEXT:").append(
|
||||
String.format("%1$-" + nextInstructionsColumnWidth + "s", formatInstructionList(nextInstructions)));
|
||||
}
|
||||
Collection<Instruction> previousInstructions = instruction.getPreviousInstructions();
|
||||
if (!sameContents(prev, previousInstructions)) {
|
||||
result.append(" PREV:").append(formatInstructionList(previousInstructions));
|
||||
}
|
||||
return result.toString();
|
||||
if (!sameContents(next, nextInstructions)) {
|
||||
result.append(" NEXT:").append(
|
||||
String.format("%1$-" + nextInstructionsColumnWidth + "s", formatInstructionList(nextInstructions)));
|
||||
}
|
||||
Collection<Instruction> previousInstructions = instruction.getPreviousInstructions();
|
||||
if (!sameContents(prev, previousInstructions)) {
|
||||
result.append(" PREV:").append(formatInstructionList(previousInstructions));
|
||||
}
|
||||
return result.toString();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.cfg;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import kotlin.jvm.functions.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
|
||||
@@ -47,25 +46,22 @@ public abstract class AbstractDataFlowTest extends AbstractPseudocodeTest {
|
||||
String usePrefix = " USE:";
|
||||
int initializersColumnWidth = countDataColumnWidth(initPrefix, pseudocode.getInstructionsIncludingDeadCode(), variableInitializers);
|
||||
|
||||
dumpInstructions(pseudocode, out, new Function3<Instruction, Instruction, Instruction, String>() {
|
||||
@Override
|
||||
public String invoke(Instruction instruction, Instruction next, Instruction prev) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Edges<InitControlFlowInfo> initializersEdges = variableInitializers.get(instruction);
|
||||
Edges<InitControlFlowInfo> previousInitializersEdges = variableInitializers.get(prev);
|
||||
String initializersData = "";
|
||||
if (initializersEdges != null && !initializersEdges.equals(previousInitializersEdges)) {
|
||||
initializersData = dumpEdgesData(initPrefix, initializersEdges);
|
||||
}
|
||||
result.append(String.format("%1$-" + initializersColumnWidth + "s", initializersData));
|
||||
|
||||
Edges<UseControlFlowInfo> useStatusEdges = useStatusData.get(instruction);
|
||||
Edges<UseControlFlowInfo> nextUseStatusEdges = useStatusData.get(next);
|
||||
if (useStatusEdges != null && !useStatusEdges.equals(nextUseStatusEdges)) {
|
||||
result.append(dumpEdgesData(usePrefix, useStatusEdges));
|
||||
}
|
||||
return result.toString();
|
||||
dumpInstructions(pseudocode, out, (instruction, next, prev) -> {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Edges<InitControlFlowInfo> initializersEdges = variableInitializers.get(instruction);
|
||||
Edges<InitControlFlowInfo> previousInitializersEdges = variableInitializers.get(prev);
|
||||
String initializersData = "";
|
||||
if (initializersEdges != null && !initializersEdges.equals(previousInitializersEdges)) {
|
||||
initializersData = dumpEdgesData(initPrefix, initializersEdges);
|
||||
}
|
||||
result.append(String.format("%1$-" + initializersColumnWidth + "s", initializersData));
|
||||
|
||||
Edges<UseControlFlowInfo> useStatusEdges = useStatusData.get(instruction);
|
||||
Edges<UseControlFlowInfo> nextUseStatusEdges = useStatusData.get(next);
|
||||
if (useStatusEdges != null && !useStatusEdges.equals(nextUseStatusEdges)) {
|
||||
result.append(dumpEdgesData(usePrefix, useStatusEdges));
|
||||
}
|
||||
return result.toString();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.util.ArrayUtil;
|
||||
import kotlin.Pair;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.io.FilesKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import kotlin.text.Charsets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
||||
@@ -130,23 +129,20 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
static List<String> readArgs(@NotNull String argsFilePath, @NotNull String tempDir) throws IOException {
|
||||
List<String> lines = FilesKt.readLines(new File(argsFilePath), Charsets.UTF_8);
|
||||
|
||||
return CollectionsKt.mapNotNull(lines, new Function1<String, String>() {
|
||||
@Override
|
||||
public String invoke(String arg) {
|
||||
if (arg.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Do not replace ':' after '\' (used in compiler plugin tests)
|
||||
String argsWithColonsReplaced = arg
|
||||
.replace("\\:", "$COLON$")
|
||||
.replace(":", File.pathSeparator)
|
||||
.replace("$COLON$", ":");
|
||||
|
||||
return argsWithColonsReplaced
|
||||
.replace("$TEMP_DIR$", tempDir)
|
||||
.replace("$TESTDATA_DIR$", new File(argsFilePath).getParent());
|
||||
return CollectionsKt.mapNotNull(lines, arg -> {
|
||||
if (arg.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Do not replace ':' after '\' (used in compiler plugin tests)
|
||||
String argsWithColonsReplaced = arg
|
||||
.replace("\\:", "$COLON$")
|
||||
.replace(":", File.pathSeparator)
|
||||
.replace("$COLON$", ":");
|
||||
|
||||
return argsWithColonsReplaced
|
||||
.replace("$TEMP_DIR$", tempDir)
|
||||
.replace("$TESTDATA_DIR$", new File(argsFilePath).getParent());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
@@ -121,14 +120,7 @@ public class InnerClassInfoGenTest extends CodegenTestCase {
|
||||
|
||||
private void checkAccess(@NotNull String outerName, @NotNull String innerName, int accessFlags) {
|
||||
String name = outerName + "$" + innerName;
|
||||
InnerClassAttribute attribute = CollectionsKt.single(extractInnerClasses(name),
|
||||
new Function1<InnerClassAttribute, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(InnerClassAttribute attribute) {
|
||||
return innerName.equals(attribute.innerName);
|
||||
}
|
||||
}
|
||||
);
|
||||
InnerClassAttribute attribute = CollectionsKt.single(extractInnerClasses(name), value -> innerName.equals(value.innerName));
|
||||
|
||||
InnerClassAttribute expectedAttribute = new InnerClassAttribute(name, outerName, innerName, accessFlags);
|
||||
|
||||
|
||||
+12
-13
@@ -17,13 +17,15 @@
|
||||
package org.jetbrains.kotlin.jvm.compiler;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.renderer.*;
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
||||
@@ -46,17 +48,14 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
||||
private static final RecursiveDescriptorComparator.Configuration CONFIGURATION =
|
||||
AbstractLoadJavaTest.COMPARATOR_CONFIGURATION.withRenderer(
|
||||
DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(Retention.class.getName())));
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
options -> {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(Retention.class.getName())));
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
+30
-50
@@ -20,7 +20,6 @@ import com.google.common.collect.Iterables;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import kotlin.Pair;
|
||||
import kotlin.collections.SetsKt;
|
||||
import kotlin.io.FilesKt;
|
||||
@@ -152,12 +151,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
|
||||
@NotNull
|
||||
private static File copyJarFileWithoutEntry(@NotNull File jarPath, @NotNull String... entriesToDelete) {
|
||||
return transformJar(jarPath, new Function2<String, byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] invoke(String s, byte[] bytes) {
|
||||
return bytes;
|
||||
}
|
||||
}, entriesToDelete);
|
||||
return transformJar(jarPath, (s, bytes) -> bytes, entriesToDelete);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -292,21 +286,16 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
@NotNull String... additionalOptions
|
||||
) throws Exception {
|
||||
int[] version = new JvmMetadataVersion(42, 0, 0).toArray();
|
||||
File library = transformJar(compileLibrary(libraryName), new Function2<String, byte[], byte[]>() {
|
||||
@Override
|
||||
public byte[] invoke(String name, byte[] bytes) {
|
||||
return WrongBytecodeVersionTest.Companion.transformMetadataInClassFile(bytes, new Function2<String, Object, Object>() {
|
||||
@Override
|
||||
public Object invoke(String name, Object value) {
|
||||
if (additionalTransformation != null) {
|
||||
Object result = additionalTransformation.invoke(name, value);
|
||||
if (result != null) return result;
|
||||
}
|
||||
return JvmAnnotationNames.METADATA_VERSION_FIELD_NAME.equals(name) ? version : null;
|
||||
File library = transformJar(
|
||||
compileLibrary(libraryName),
|
||||
(entryName, bytes) -> WrongBytecodeVersionTest.Companion.transformMetadataInClassFile(bytes, (fieldName, value) -> {
|
||||
if (additionalTransformation != null) {
|
||||
Object result = additionalTransformation.invoke(fieldName, value);
|
||||
if (result != null) return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return JvmAnnotationNames.METADATA_VERSION_FIELD_NAME.equals(fieldName) ? version : null;
|
||||
})
|
||||
);
|
||||
Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
|
||||
KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
|
||||
}
|
||||
@@ -509,20 +498,17 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
public void testWrongMetadataVersionBadMetadata() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion(
|
||||
"library",
|
||||
new Function2<String, Object, Object>() {
|
||||
@Override
|
||||
public Object invoke(String name, Object value) {
|
||||
if (JvmAnnotationNames.METADATA_DATA_FIELD_NAME.equals(name)) {
|
||||
String[] strings = (String[]) value;
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
byte[] bytes = strings[i].getBytes();
|
||||
for (int j = 0; j < bytes.length; j++) bytes[j] ^= 42;
|
||||
strings[i] = new String(bytes);
|
||||
}
|
||||
return strings;
|
||||
(name, value) -> {
|
||||
if (JvmAnnotationNames.METADATA_DATA_FIELD_NAME.equals(name)) {
|
||||
String[] strings = (String[]) value;
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
byte[] bytes = strings[i].getBytes();
|
||||
for (int j = 0; j < bytes.length; j++) bytes[j] ^= 42;
|
||||
strings[i] = new String(bytes);
|
||||
}
|
||||
return null;
|
||||
return strings;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -530,14 +516,11 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
public void testWrongMetadataVersionBadMetadata2() throws Exception {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion(
|
||||
"library",
|
||||
new Function2<String, Object, Object>() {
|
||||
@Override
|
||||
public Object invoke(String name, Object value) {
|
||||
if (JvmAnnotationNames.METADATA_STRINGS_FIELD_NAME.equals(name)) {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
return null;
|
||||
(name, value) -> {
|
||||
if (JvmAnnotationNames.METADATA_STRINGS_FIELD_NAME.equals(name)) {
|
||||
return ArrayUtil.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -648,18 +631,15 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
|
||||
File library2 = compileJava("library2");
|
||||
|
||||
// Copy everything from library2 to library1
|
||||
FileUtil.visitFiles(library2, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (!file.isDirectory()) {
|
||||
File newFile = new File(library1, FilesKt.relativeTo(file, library2).getPath());
|
||||
if (!newFile.getParentFile().exists()) {
|
||||
assert newFile.getParentFile().mkdirs();
|
||||
}
|
||||
assert file.renameTo(newFile);
|
||||
FileUtil.visitFiles(library2, file -> {
|
||||
if (!file.isDirectory()) {
|
||||
File newFile = new File(library1, FilesKt.relativeTo(file, library2).getPath());
|
||||
if (!newFile.getParentFile().exists()) {
|
||||
assert newFile.getParentFile().mkdirs();
|
||||
}
|
||||
return true;
|
||||
assert file.renameTo(newFile);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library1);
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -33,7 +32,10 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.renderer.*;
|
||||
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AdditionalClassPartsProvider;
|
||||
@@ -46,7 +48,6 @@ import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -64,16 +65,13 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
RecursiveDescriptorComparator.Configuration configuration =
|
||||
RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(
|
||||
DescriptorRenderer.Companion.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
options -> {
|
||||
options.setWithDefinedIn(false);
|
||||
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||
options.setVerbose(true);
|
||||
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
|
||||
options.setModifiers(DescriptorRendererModifier.ALL);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -113,12 +111,7 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
Collections.singletonList(new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule)),
|
||||
PlatformDependentDeclarationFilter.All.INSTANCE,
|
||||
AdditionalClassPartsProvider.None.INSTANCE,
|
||||
new Function1<String, InputStream>() {
|
||||
@Override
|
||||
public InputStream invoke(String path) {
|
||||
return ForTestCompileRuntime.runtimeJarClassLoader().getResourceAsStream(path);
|
||||
}
|
||||
}
|
||||
ForTestCompileRuntime.runtimeJarClassLoader()::getResourceAsStream
|
||||
);
|
||||
|
||||
builtInsModule.initialize(packageFragmentProvider);
|
||||
|
||||
@@ -20,8 +20,6 @@ import junit.framework.TestCase;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.util.ReenteringLazyValueComputationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -278,12 +276,7 @@ public class StorageManagerTest extends TestCase {
|
||||
}
|
||||
},
|
||||
null,
|
||||
new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String s) {
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
}
|
||||
s -> Unit.INSTANCE
|
||||
);
|
||||
}
|
||||
|
||||
@@ -306,19 +299,11 @@ public class StorageManagerTest extends TestCase {
|
||||
return rec.invoke();
|
||||
}
|
||||
},
|
||||
new Function1<Boolean, String>() {
|
||||
@Override
|
||||
public String invoke(Boolean aBoolean) {
|
||||
return "tolerant";
|
||||
}
|
||||
},
|
||||
new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String s) {
|
||||
counter.inc();
|
||||
assertEquals("tolerant", s);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
aBoolean -> "tolerant",
|
||||
s -> {
|
||||
counter.inc();
|
||||
assertEquals("tolerant", s);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -332,22 +317,16 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testPostComputeNoRecursion() throws Exception {
|
||||
CounterImpl counter = new CounterImpl();
|
||||
NotNullLazyValue<Collection<String>> v = m.createLazyValueWithPostCompute(
|
||||
new Function0<Collection<String>>() {
|
||||
@Override
|
||||
public Collection<String> invoke() {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
}
|
||||
() -> {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
},
|
||||
null,
|
||||
new Function1<Collection<String>, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(Collection<String> strings) {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
strings -> {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -359,21 +338,15 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testNullablePostComputeNoRecursion() throws Exception {
|
||||
CounterImpl counter = new CounterImpl();
|
||||
NullableLazyValue<Collection<String>> v = m.createNullableLazyValueWithPostCompute(
|
||||
new Function0<Collection<String>>() {
|
||||
@Override
|
||||
public Collection<String> invoke() {
|
||||
ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
}
|
||||
() -> {
|
||||
ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("first");
|
||||
return strings;
|
||||
},
|
||||
new Function1<Collection<String>, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(Collection<String> strings) {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
strings -> {
|
||||
counter.inc();
|
||||
strings.add("postComputed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -392,21 +365,15 @@ public class StorageManagerTest extends TestCase {
|
||||
return rec.invoke();
|
||||
}
|
||||
},
|
||||
new Function1<Boolean, String>() {
|
||||
@Override
|
||||
public String invoke(Boolean firstTime) {
|
||||
if (firstTime) {
|
||||
throw new ReenteringLazyValueComputationException();
|
||||
}
|
||||
return "second";
|
||||
firstTime -> {
|
||||
if (firstTime) {
|
||||
throw new ReenteringLazyValueComputationException();
|
||||
}
|
||||
return "second";
|
||||
},
|
||||
new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String s) {
|
||||
fail("Recursion-tolerating value should not be post computed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
s -> {
|
||||
fail("Recursion-tolerating value should not be post computed");
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -449,23 +416,13 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testExceptionHandlingStrategyForLazyValues() throws Exception {
|
||||
class RethrownException extends RuntimeException {}
|
||||
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(new LockBasedStorageManager.ExceptionHandlingStrategy() {
|
||||
@NotNull
|
||||
@Override
|
||||
public RuntimeException handleException(@NotNull Throwable throwable) {
|
||||
throw new RethrownException();
|
||||
}
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(throwable -> {
|
||||
throw new RethrownException();
|
||||
});
|
||||
try {
|
||||
m.createLazyValue(
|
||||
new Function0<Object>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object invoke() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
).invoke();
|
||||
m.createLazyValue(() -> {
|
||||
throw new RuntimeException();
|
||||
}).invoke();
|
||||
fail("Exception should have occurred");
|
||||
}
|
||||
catch (RethrownException ignored) {
|
||||
@@ -475,23 +432,13 @@ public class StorageManagerTest extends TestCase {
|
||||
public void testExceptionHandlingStrategyForMemoizedFunctions() throws Exception {
|
||||
class RethrownException extends RuntimeException {}
|
||||
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(new LockBasedStorageManager.ExceptionHandlingStrategy() {
|
||||
@NotNull
|
||||
@Override
|
||||
public RuntimeException handleException(@NotNull Throwable throwable) {
|
||||
throw new RethrownException();
|
||||
}
|
||||
LockBasedStorageManager m = LockBasedStorageManager.createWithExceptionHandling(throwable -> {
|
||||
throw new RethrownException();
|
||||
});
|
||||
try {
|
||||
m.createMemoizedFunction(
|
||||
new Function1<Object, Object>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object invoke(@Nullable Object o) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
).invoke("");
|
||||
m.createMemoizedFunction(o -> {
|
||||
throw new RuntimeException();
|
||||
}).invoke("");
|
||||
fail("Exception should have occurred");
|
||||
}
|
||||
catch (RethrownException ignored) {
|
||||
@@ -501,12 +448,7 @@ public class StorageManagerTest extends TestCase {
|
||||
// Utilities
|
||||
|
||||
private static <K, V> Function0<V> apply(Function1<K, V> f, K x) {
|
||||
return new Function0<V>() {
|
||||
@Override
|
||||
public V invoke() {
|
||||
return f.invoke(x);
|
||||
}
|
||||
};
|
||||
return () -> f.invoke(x);
|
||||
}
|
||||
|
||||
private interface Counter {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.types;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||
@@ -90,16 +89,16 @@ public class DefaultModalityModifiersTest extends KotlinTestWithEnvironment {
|
||||
KtDeclaration aClass = file.getDeclarations().get(0);
|
||||
assert aClass instanceof KtClass;
|
||||
AnalysisResult bindingContext = JvmResolveUtil.analyzeAndCheckForErrors(file, getEnvironment());
|
||||
DeclarationDescriptor classDescriptor = bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||
return new LexicalScopeImpl(ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
||||
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
});
|
||||
DeclarationDescriptor classDescriptor =
|
||||
bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||
return new LexicalScopeImpl(
|
||||
ScopeUtilsKt.memberScopeAsImportingScope(libraryScope), root, false, null,
|
||||
LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
handler -> {
|
||||
handler.addClassifierDescriptor((ClassifierDescriptor) classDescriptor);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private ClassDescriptorWithResolutionScopes createClassDescriptor(ClassKind kind, KtClass aClass) {
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
@@ -31,7 +29,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -96,14 +93,11 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
LexicalScope typeParameters = new LexicalScopeImpl(
|
||||
topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC,
|
||||
redeclarationChecker,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
|
||||
handler.addClassifierDescriptor(parameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
handler -> {
|
||||
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
|
||||
handler.addClassifierDescriptor(parameterDescriptor);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
return new LexicalChainedScope(
|
||||
@@ -157,15 +151,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
|
||||
BindingTrace trace = new BindingTraceContext();
|
||||
KotlinType type = container.getTypeResolver().resolveType(scope, jetTypeReference, trace, true);
|
||||
if (!trace.getBindingContext().getDiagnostics().isEmpty()) {
|
||||
fail("Errors:\n" + StringUtil.join(
|
||||
trace.getBindingContext().getDiagnostics(),
|
||||
new Function<Diagnostic, String>() {
|
||||
@Override
|
||||
public String fun(Diagnostic diagnostic) {
|
||||
return DefaultErrorMessages.render(diagnostic);
|
||||
}
|
||||
},
|
||||
"\n"));
|
||||
fail("Errors:\n" + StringUtil.join(trace.getBindingContext().getDiagnostics(), DefaultErrorMessages::render, "\n"));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import kotlin.Unit;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -31,7 +30,6 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
||||
import org.jetbrains.kotlin.psi.KtTypeProjection;
|
||||
@@ -69,12 +67,8 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
module = DslKt.getService(container, ModuleDescriptor.class);
|
||||
|
||||
builtinsImportingScope = ScopeUtilsKt.chainImportingScopes(
|
||||
CollectionsKt.map(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES, new Function1<FqName, ImportingScope>() {
|
||||
@Override
|
||||
public ImportingScope invoke(FqName fqName) {
|
||||
return ScopeUtilsKt.memberScopeAsImportingScope(module.getPackage(fqName).getMemberScope());
|
||||
}
|
||||
}), null);
|
||||
CollectionsKt.map(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
fqName -> ScopeUtilsKt.memberScopeAsImportingScope(module.getPackage(fqName).getMemberScope())), null);
|
||||
typeResolver = DslKt.getService(container, TypeResolver.class);
|
||||
x = createTypeVariable("X");
|
||||
y = createTypeVariable("Y");
|
||||
@@ -202,13 +196,10 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
LexicalScope withX = new LexicalScopeImpl(
|
||||
builtinsImportingScope, module,
|
||||
false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
|
||||
handler.addClassifierDescriptor(x);
|
||||
handler.addClassifierDescriptor(y);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
handler -> {
|
||||
handler.addClassifierDescriptor(x);
|
||||
handler.addClassifierDescriptor(y);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.utils;
|
||||
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -61,12 +60,7 @@ public final class Interner<T> {
|
||||
|
||||
@NotNull
|
||||
public List<T> getAllInternedObjects() {
|
||||
return CollectionsKt.sortedBy(interned.keySet(), new Function1<T, Integer>() {
|
||||
@Override
|
||||
public Integer invoke(T key) {
|
||||
return interned.get(key);
|
||||
}
|
||||
});
|
||||
return CollectionsKt.sortedBy(interned.keySet(), interned::get);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
||||
+3
-13
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.generators.tests.generator;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
@@ -31,12 +30,8 @@ import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SimpleTestClassModel implements TestClassModel {
|
||||
private static final Comparator<TestEntityModel> BY_NAME = new Comparator<TestEntityModel>() {
|
||||
@Override
|
||||
public int compare(@NotNull TestEntityModel o1, @NotNull TestEntityModel o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
};
|
||||
private static final Comparator<TestEntityModel> BY_NAME = Comparator.comparing(TestEntityModel::getName);
|
||||
|
||||
@NotNull
|
||||
private final File rootFile;
|
||||
private final boolean recursive;
|
||||
@@ -123,12 +118,7 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
}
|
||||
|
||||
private static boolean dirHasFilesInside(@NotNull File dir) {
|
||||
return !FileUtil.processFilesRecursively(dir, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
return file.isDirectory();
|
||||
}
|
||||
});
|
||||
return !FileUtil.processFilesRecursively(dir, File::isDirectory);
|
||||
}
|
||||
|
||||
private static boolean dirHasSubDirs(@NotNull File dir) {
|
||||
|
||||
+6
-16
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.generators.tests.generator;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -30,7 +29,6 @@ import org.jetbrains.kotlin.utils.Printer;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -80,23 +78,15 @@ public class SingleClassTestModel implements TestClassModel {
|
||||
|
||||
result.add(new TestAllFilesPresentMethodModel());
|
||||
|
||||
FileUtil.processFilesRecursively(rootFile, new Processor<File>() {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (!file.isDirectory() && filenamePattern.matcher(file.getName()).matches()) {
|
||||
result.addAll(getTestMethodsFromFile(file));
|
||||
}
|
||||
|
||||
return true;
|
||||
FileUtil.processFilesRecursively(rootFile, file -> {
|
||||
if (!file.isDirectory() && filenamePattern.matcher(file.getName()).matches()) {
|
||||
result.addAll(getTestMethodsFromFile(file));
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
ContainerUtil.sort(result, new Comparator<TestMethodModel>() {
|
||||
@Override
|
||||
public int compare(@NotNull TestMethodModel o1, @NotNull TestMethodModel o2) {
|
||||
return StringUtil.compare(o1.getName(), o2.getName(), true);
|
||||
}
|
||||
});
|
||||
ContainerUtil.sort(result, (o1, o2) -> StringUtil.compare(o1.getName(), o2.getName(), true));
|
||||
|
||||
methods = Lists.<MethodModel>newArrayList(result);
|
||||
}
|
||||
|
||||
@@ -197,15 +197,12 @@ public class JsConfig {
|
||||
if (initialized) return;
|
||||
|
||||
if (!getLibraries().isEmpty()) {
|
||||
Function1<VirtualFile, Unit> action = new Function1<VirtualFile, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(VirtualFile file) {
|
||||
String libraryPath = PathUtil.getLocalPath(file);
|
||||
assert libraryPath != null : "libraryPath for " + file + " should not be null";
|
||||
metadata.addAll(KotlinJavascriptMetadataUtils.loadMetadata(libraryPath));
|
||||
Function1<VirtualFile, Unit> action = file -> {
|
||||
String libraryPath = PathUtil.getLocalPath(file);
|
||||
assert libraryPath != null : "libraryPath for " + file + " should not be null";
|
||||
metadata.addAll(KotlinJavascriptMetadataUtils.loadMetadata(libraryPath));
|
||||
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
};
|
||||
|
||||
boolean hasErrors = checkLibFilesAndReportErrors(new Reporter() {
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.jetbrains.kotlin.js.patterns;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -34,23 +33,15 @@ public final class NamePredicate implements Predicate<Name> {
|
||||
|
||||
@NotNull
|
||||
public static final NamePredicate PRIMITIVE_NUMBERS = new NamePredicate(
|
||||
ContainerUtil.map(PrimitiveType.NUMBER_TYPES,
|
||||
new Function<PrimitiveType, String>() {
|
||||
@Override
|
||||
public String fun(PrimitiveType type) {
|
||||
return type.getTypeName().asString();
|
||||
}
|
||||
}));
|
||||
CollectionsKt.map(PrimitiveType.NUMBER_TYPES, (PrimitiveType type) -> type.getTypeName().asString())
|
||||
);
|
||||
|
||||
@NotNull
|
||||
public static final NamePredicate PRIMITIVE_NUMBERS_MAPPED_TO_PRIMITIVE_JS = new NamePredicate(
|
||||
ContainerUtil.mapNotNull(PrimitiveType.NUMBER_TYPES,
|
||||
new Function<PrimitiveType, String>() {
|
||||
@Override
|
||||
public String fun(PrimitiveType type) {
|
||||
return type != PrimitiveType.LONG ? type.getTypeName().asString() : null;
|
||||
}
|
||||
}));
|
||||
CollectionsKt.mapNotNull(PrimitiveType.NUMBER_TYPES, (PrimitiveType type) ->
|
||||
type != PrimitiveType.LONG ? type.getTypeName().asString() : null
|
||||
)
|
||||
);
|
||||
|
||||
@NotNull
|
||||
public static final NamePredicate STRING = new NamePredicate("String");
|
||||
|
||||
@@ -58,15 +58,8 @@ public class JsInliner extends JsVisitorWithContextImpl {
|
||||
// these are needed for error reporting, when inliner detects cycle
|
||||
private final Stack<JsFunction> namedFunctionsStack = new Stack<JsFunction>();
|
||||
private final LinkedList<JsCallInfo> inlineCallInfos = new LinkedList<JsCallInfo>();
|
||||
private final Function1<JsNode, Boolean> canBeExtractedByInliner = new Function1<JsNode, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(JsNode node) {
|
||||
if (!(node instanceof JsInvocation)) return false;
|
||||
|
||||
JsInvocation call = (JsInvocation) node;
|
||||
return hasToBeInlined(call);
|
||||
}
|
||||
};
|
||||
private final Function1<JsNode, Boolean> canBeExtractedByInliner =
|
||||
node -> node instanceof JsInvocation && hasToBeInlined((JsInvocation) node);
|
||||
|
||||
public static JsProgram process(@NotNull TranslationContext context) {
|
||||
JsProgram program = context.program();
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.jetbrains.kotlin.integration;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.js.test.rhino.RhinoFunctionResultChecker;
|
||||
@@ -58,12 +57,7 @@ public class AntTaskJsTest extends AbstractAntTaskTest {
|
||||
List<String> fileNames = new ArrayList<String>(Arrays.asList(jsFiles));
|
||||
fileNames.add(JS_OUT_FILE);
|
||||
|
||||
List<String> filePaths = ContainerUtil.map(fileNames, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return getOutputFileByName(s).getAbsolutePath();
|
||||
}
|
||||
});
|
||||
List<String> filePaths = CollectionsKt.map(fileNames, s -> getOutputFileByName(s).getAbsolutePath());
|
||||
|
||||
RhinoUtils.runRhinoTest(filePaths, new RhinoFunctionResultChecker("out", "foo", "box", "OK", withModuleSystem));
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user