Remove some usages of KotlinBuiltIns.getInstance()
Introduce DeclarationDescriptor.builtIns extension to get builtins where descriptors are available Introduce various utilities in KotlinBuiltIns to check for primitive types and get fq names of builtins
This commit is contained in:
@@ -22,22 +22,24 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.CallResolverUtil;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
|
||||
/**
|
||||
* Backend-independent utility class.
|
||||
*/
|
||||
@@ -70,30 +72,25 @@ public class CodegenUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FunctionDescriptor getAnyEqualsMethod() {
|
||||
ClassDescriptor anyClass = KotlinBuiltIns.getInstance().getAny();
|
||||
FunctionDescriptor function =
|
||||
getDeclaredFunctionByRawSignature(anyClass, Name.identifier(EQUALS_METHOD_NAME),
|
||||
KotlinBuiltIns.getInstance().getBoolean(),
|
||||
anyClass);
|
||||
public static FunctionDescriptor getAnyEqualsMethod(@NotNull KotlinBuiltIns builtIns) {
|
||||
ClassDescriptor anyClass = builtIns.getAny();
|
||||
FunctionDescriptor function = getDeclaredFunctionByRawSignature(
|
||||
anyClass, Name.identifier(EQUALS_METHOD_NAME), builtIns.getBoolean(), anyClass
|
||||
);
|
||||
assert function != null;
|
||||
return function;
|
||||
}
|
||||
|
||||
public static FunctionDescriptor getAnyToStringMethod() {
|
||||
ClassDescriptor anyClass = KotlinBuiltIns.getInstance().getAny();
|
||||
FunctionDescriptor function =
|
||||
getDeclaredFunctionByRawSignature(anyClass, Name.identifier(TO_STRING_METHOD_NAME),
|
||||
KotlinBuiltIns.getInstance().getString());
|
||||
public static FunctionDescriptor getAnyToStringMethod(@NotNull KotlinBuiltIns builtIns) {
|
||||
ClassDescriptor anyClass = builtIns.getAny();
|
||||
FunctionDescriptor function = getDeclaredFunctionByRawSignature(anyClass, Name.identifier(TO_STRING_METHOD_NAME), builtIns.getString());
|
||||
assert function != null;
|
||||
return function;
|
||||
}
|
||||
|
||||
public static FunctionDescriptor getAnyHashCodeMethod() {
|
||||
ClassDescriptor anyClass = KotlinBuiltIns.getInstance().getAny();
|
||||
FunctionDescriptor function =
|
||||
getDeclaredFunctionByRawSignature(anyClass, Name.identifier(HASH_CODE_METHOD_NAME),
|
||||
KotlinBuiltIns.getInstance().getInt());
|
||||
public static FunctionDescriptor getAnyHashCodeMethod(@NotNull KotlinBuiltIns builtIns) {
|
||||
ClassDescriptor anyClass = builtIns.getAny();
|
||||
FunctionDescriptor function = getDeclaredFunctionByRawSignature(anyClass, Name.identifier(HASH_CODE_METHOD_NAME), builtIns.getInt());
|
||||
assert function != null;
|
||||
return function;
|
||||
}
|
||||
@@ -206,7 +203,7 @@ public class CodegenUtil {
|
||||
|
||||
public static boolean isEnumValueOfMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
JetType nullableString = TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getStringType());
|
||||
JetType nullableString = TypeUtils.makeNullable(getBuiltIns(functionDescriptor).getStringType());
|
||||
return DescriptorUtils.ENUM_VALUE_OF.equals(functionDescriptor.getName())
|
||||
&& methodTypeParameters.size() == 1
|
||||
&& JetTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters.get(0).getType(), nullableString);
|
||||
|
||||
+8
-7
@@ -19,18 +19,19 @@ package org.jetbrains.kotlin.backend.common;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetClass;
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.JetParameter;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingContextUtils;
|
||||
import org.jetbrains.kotlin.resolve.OverrideResolver;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
|
||||
/**
|
||||
* A platform-independent logic for generating data class synthetic methods.
|
||||
* TODO: data class with zero components gets no toString/equals/hashCode methods. This is inconsistent and should be
|
||||
@@ -100,22 +101,22 @@ public abstract class DataClassMethodGenerator {
|
||||
}
|
||||
|
||||
private void generateDataClassToStringIfNeeded(@NotNull List<PropertyDescriptor> properties) {
|
||||
ClassDescriptor stringClass = KotlinBuiltIns.getInstance().getString();
|
||||
ClassDescriptor stringClass = getBuiltIns(classDescriptor).getString();
|
||||
if (!hasDeclaredNonTrivialMember(CodegenUtil.TO_STRING_METHOD_NAME, stringClass)) {
|
||||
generateToStringMethod(properties);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDataClassHashCodeIfNeeded(@NotNull List<PropertyDescriptor> properties) {
|
||||
ClassDescriptor intClass = KotlinBuiltIns.getInstance().getInt();
|
||||
ClassDescriptor intClass = getBuiltIns(classDescriptor).getInt();
|
||||
if (!hasDeclaredNonTrivialMember(CodegenUtil.HASH_CODE_METHOD_NAME, intClass)) {
|
||||
generateHashCodeMethod(properties);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDataClassEqualsIfNeeded(@NotNull List<PropertyDescriptor> properties) {
|
||||
ClassDescriptor booleanClass = KotlinBuiltIns.getInstance().getBoolean();
|
||||
ClassDescriptor anyClass = KotlinBuiltIns.getInstance().getAny();
|
||||
ClassDescriptor booleanClass = getBuiltIns(classDescriptor).getBoolean();
|
||||
ClassDescriptor anyClass = getBuiltIns(classDescriptor).getAny();
|
||||
if (!hasDeclaredNonTrivialMember(CodegenUtil.EQUALS_METHOD_NAME, booleanClass, anyClass)) {
|
||||
generateEqualsMethod(properties);
|
||||
}
|
||||
@@ -162,7 +163,7 @@ public abstract class DataClassMethodGenerator {
|
||||
for (CallableDescriptor overridden : OverrideResolver.getOverriddenDeclarations(function)) {
|
||||
if (overridden instanceof CallableMemberDescriptor
|
||||
&& ((CallableMemberDescriptor) overridden).getKind() == CallableMemberDescriptor.Kind.DECLARATION
|
||||
&& !overridden.getContainingDeclaration().equals(KotlinBuiltIns.getInstance().getAny())) {
|
||||
&& !overridden.getContainingDeclaration().equals(getBuiltIns(classDescriptor).getAny())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isBoolean;
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isPrimitiveClass;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isInterface;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.ABI_VERSION_FIELD_NAME;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass;
|
||||
@@ -66,16 +68,6 @@ import static org.jetbrains.kotlin.types.TypeUtils.isNullableType;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class AsmUtil {
|
||||
private static final Set<ClassDescriptor> PRIMITIVE_NUMBER_CLASSES = Sets.newHashSet(
|
||||
KotlinBuiltIns.getInstance().getByte(),
|
||||
KotlinBuiltIns.getInstance().getShort(),
|
||||
KotlinBuiltIns.getInstance().getInt(),
|
||||
KotlinBuiltIns.getInstance().getLong(),
|
||||
KotlinBuiltIns.getInstance().getFloat(),
|
||||
KotlinBuiltIns.getInstance().getDouble(),
|
||||
KotlinBuiltIns.getInstance().getChar()
|
||||
);
|
||||
|
||||
private static final Set<Type> STRING_BUILDER_OBJECT_APPEND_ARG_TYPES = Sets.newHashSet(
|
||||
getType(String.class),
|
||||
getType(StringBuffer.class),
|
||||
@@ -150,7 +142,7 @@ public class AsmUtil {
|
||||
if (!(descriptor instanceof ClassDescriptor)) {
|
||||
return false;
|
||||
}
|
||||
return PRIMITIVE_NUMBER_CLASSES.contains(descriptor);
|
||||
return isPrimitiveClass((ClassDescriptor) descriptor) && !isBoolean((ClassDescriptor) descriptor);
|
||||
}
|
||||
|
||||
public static Type correctElementType(Type type) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import kotlin.Function1;
|
||||
import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
|
||||
import org.jetbrains.kotlin.codegen.context.ClosureContext;
|
||||
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil;
|
||||
@@ -51,6 +50,7 @@ import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConst;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.CLOSURE;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.OtherOrigin;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
|
||||
}
|
||||
else {
|
||||
this.superInterfaceTypes = Collections.singletonList(samType.getType());
|
||||
this.superClassType = KotlinBuiltIns.getInstance().getAnyType();
|
||||
this.superClassType = getBuiltIns(funDescriptor).getAnyType();
|
||||
}
|
||||
|
||||
this.closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||
@@ -364,8 +364,8 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
|
||||
public static FunctionDescriptor getErasedInvokeFunction(@NotNull FunctionDescriptor elementDescriptor) {
|
||||
int arity = elementDescriptor.getValueParameters().size();
|
||||
ClassDescriptor elementClass = elementDescriptor.getExtensionReceiverParameter() == null
|
||||
? KotlinBuiltIns.getInstance().getFunction(arity)
|
||||
: KotlinBuiltIns.getInstance().getExtensionFunction(arity);
|
||||
? getBuiltIns(elementDescriptor).getFunction(arity)
|
||||
: getBuiltIns(elementDescriptor).getExtensionFunction(arity);
|
||||
return elementClass.getDefaultType().getMemberScope().getFunctions(OperatorConventions.INVOKE).iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ import org.jetbrains.org.objectweb.asm.commons.Method;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isInt;
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.*;
|
||||
@@ -97,6 +98,7 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isObject;
|
||||
import static org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage.getResolvedCall;
|
||||
import static org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage.getResolvedCallWithAssert;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.OtherOrigin;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.TraitImpl;
|
||||
@@ -105,8 +107,6 @@ import static org.jetbrains.kotlin.serialization.deserialization.Deserialization
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implements LocalLookup {
|
||||
private static final Set<DeclarationDescriptor> INTEGRAL_RANGES = KotlinBuiltIns.getInstance().getIntegralRanges();
|
||||
|
||||
private final GenerationState state;
|
||||
final JetTypeMapper typeMapper;
|
||||
private final BindingContext bindingContext;
|
||||
@@ -791,8 +791,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
StackValue result = invokeFunction(fakeCall, hasNextCall, StackValue.local(iteratorVarIndex, asmTypeForIterator));
|
||||
result.put(result.type, v);
|
||||
|
||||
JetType type = hasNextCall.getResultingDescriptor().getReturnType();
|
||||
assert type != null && JetTypeChecker.DEFAULT.isSubtypeOf(type, KotlinBuiltIns.getInstance().getBooleanType());
|
||||
FunctionDescriptor hasNext = hasNextCall.getResultingDescriptor();
|
||||
JetType type = hasNext.getReturnType();
|
||||
assert type != null && JetTypeChecker.DEFAULT.isSubtypeOf(type, getBuiltIns(hasNext).getBooleanType());
|
||||
|
||||
Type asmType = asmType(type);
|
||||
StackValue.coerce(asmType, Type.BOOLEAN_TYPE, v);
|
||||
@@ -3190,7 +3191,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
Type lhsType = expressionType(lhs);
|
||||
|
||||
boolean keepReturnValue = Boolean.TRUE.equals(bindingContext.get(VARIABLE_REASSIGNMENT, expression))
|
||||
|| !KotlinBuiltIns.getInstance().getUnitType().equals(descriptor.getReturnType());
|
||||
|| !KotlinBuiltIns.isUnit(descriptor.getReturnType());
|
||||
|
||||
callAugAssignMethod(expression, resolvedCall, callable, lhsType, keepReturnValue);
|
||||
|
||||
@@ -3527,7 +3528,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
assert operationDescriptor != null;
|
||||
if (arrayType.getSort() == Type.ARRAY &&
|
||||
indices.size() == 1 &&
|
||||
operationDescriptor.getValueParameters().get(0).getType().equals(KotlinBuiltIns.getInstance().getIntType())) {
|
||||
isInt(operationDescriptor.getValueParameters().get(0).getType())) {
|
||||
assert type != null;
|
||||
Type elementType;
|
||||
if (KotlinBuiltIns.isArray(type)) {
|
||||
@@ -4043,7 +4044,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
JetType jetType = bindingContext.getType(rangeExpression);
|
||||
assert jetType != null;
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
return INTEGRAL_RANGES.contains(descriptor);
|
||||
return getBuiltIns(descriptor).getIntegralRanges().contains(descriptor);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -69,6 +69,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
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.JvmSerializationBindings.*;
|
||||
import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
|
||||
@@ -522,8 +523,7 @@ public class FunctionCodegen {
|
||||
return name.equals("hashCode") || name.equals("toString");
|
||||
}
|
||||
else if (parameters.size() == 1 && name.equals("equals")) {
|
||||
ValueParameterDescriptor parameter = parameters.get(0);
|
||||
return parameter.getType().equals(KotlinBuiltIns.getInstance().getNullableAnyType());
|
||||
return isNullableAny(parameters.get(0).getType());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getSecondaryConstructors;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.*;
|
||||
@@ -337,7 +338,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
if (superClassType == null) {
|
||||
if (descriptor.getKind() == ClassKind.ENUM_CLASS) {
|
||||
superClassType = KotlinBuiltIns.getInstance().getEnumType(descriptor.getDefaultType());
|
||||
superClassType = getBuiltIns(descriptor).getEnumType(descriptor.getDefaultType());
|
||||
superClassAsmType = typeMapper.mapType(superClassType);
|
||||
}
|
||||
if (descriptor.getKind() == ClassKind.ENUM_ENTRY) {
|
||||
@@ -422,8 +423,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
JetType paramType = function.getValueParameters().get(0).getType();
|
||||
if (KotlinBuiltIns.isArray(returnType) && KotlinBuiltIns.isArray(paramType)) {
|
||||
JetType elementType = function.getTypeParameters().get(0).getDefaultType();
|
||||
if (JetTypeChecker.DEFAULT.equalTypes(elementType, KotlinBuiltIns.getInstance().getArrayElementType(returnType))
|
||||
&& JetTypeChecker.DEFAULT.equalTypes(elementType, KotlinBuiltIns.getInstance().getArrayElementType(paramType))) {
|
||||
if (JetTypeChecker.DEFAULT.equalTypes(elementType, getBuiltIns(descriptor).getArrayElementType(returnType))
|
||||
&& JetTypeChecker.DEFAULT.equalTypes(elementType, getBuiltIns(descriptor).getArrayElementType(paramType))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -433,7 +434,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateToArray() {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
KotlinBuiltIns builtIns = getBuiltIns(descriptor);
|
||||
if (!isSubclass(descriptor, builtIns.getCollection())) return;
|
||||
|
||||
int access = descriptor.getKind() == ClassKind.TRAIT ?
|
||||
@@ -489,10 +490,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
@Override
|
||||
public void generateEqualsMethod(@NotNull List<PropertyDescriptor> properties) {
|
||||
KotlinBuiltIns builtins = getBuiltIns(descriptor);
|
||||
FunctionDescriptor equalsFunction = CodegenUtil.getDeclaredFunctionByRawSignature(
|
||||
descriptor, Name.identifier(CodegenUtil.EQUALS_METHOD_NAME),
|
||||
KotlinBuiltIns.getInstance().getBoolean(),
|
||||
KotlinBuiltIns.getInstance().getAny()
|
||||
descriptor, Name.identifier(CodegenUtil.EQUALS_METHOD_NAME), builtins.getBoolean(), builtins.getAny()
|
||||
);
|
||||
|
||||
assert equalsFunction != null : String.format("Should be called only for classes with non-trivial '%s'. In %s, %s",
|
||||
@@ -564,8 +564,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Override
|
||||
public void generateHashCodeMethod(@NotNull List<PropertyDescriptor> properties) {
|
||||
FunctionDescriptor hashCodeFunction = CodegenUtil.getDeclaredFunctionByRawSignature(
|
||||
descriptor, Name.identifier(CodegenUtil.HASH_CODE_METHOD_NAME),
|
||||
KotlinBuiltIns.getInstance().getInt()
|
||||
descriptor, Name.identifier(CodegenUtil.HASH_CODE_METHOD_NAME), getBuiltIns(descriptor).getInt()
|
||||
);
|
||||
|
||||
assert hashCodeFunction != null : String.format("Should be called only for classes with non-trivial '%s'. In %s, %s",
|
||||
@@ -620,8 +619,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Override
|
||||
public void generateToStringMethod(@NotNull List<PropertyDescriptor> properties) {
|
||||
FunctionDescriptor toString = CodegenUtil.getDeclaredFunctionByRawSignature(
|
||||
descriptor, Name.identifier(CodegenUtil.TO_STRING_METHOD_NAME),
|
||||
KotlinBuiltIns.getInstance().getString()
|
||||
descriptor, Name.identifier(CodegenUtil.TO_STRING_METHOD_NAME), getBuiltIns(descriptor).getString()
|
||||
);
|
||||
|
||||
assert toString != null : String.format("Should be called only for classes with non-trivial '%s'. In %s, %s",
|
||||
@@ -795,7 +793,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
private void generateEnumValuesMethod() {
|
||||
Type type = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(INVARIANT, descriptor.getDefaultType()));
|
||||
Type type = typeMapper.mapType(getBuiltIns(descriptor).getArrayType(INVARIANT, descriptor.getDefaultType()));
|
||||
|
||||
FunctionDescriptor valuesFunction =
|
||||
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES), new Function1<FunctionDescriptor, Boolean>() {
|
||||
@@ -1445,7 +1443,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
reg += argTypes[i].getSize();
|
||||
}
|
||||
|
||||
if (KotlinBuiltIns.getInstance().isCloneable(containingTrait) && traitMethod.getName().equals("clone")) {
|
||||
if (KotlinBuiltIns.isCloneable(containingTrait) && traitMethod.getName().equals("clone")) {
|
||||
// A special hack for Cloneable: there's no kotlin/Cloneable$$TImpl class at runtime,
|
||||
// and its 'clone' method is actually located in java/lang/Object
|
||||
iv.invokespecial("java/lang/Object", "clone", "()Ljava/lang/Object;", false);
|
||||
@@ -1654,7 +1652,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||
InstructionAdapter iv = codegen.v;
|
||||
|
||||
Type arrayAsmType = typeMapper.mapType(KotlinBuiltIns.getInstance().getArrayType(INVARIANT, descriptor.getDefaultType()));
|
||||
Type arrayAsmType = typeMapper.mapType(getBuiltIns(descriptor).getArrayType(INVARIANT, descriptor.getDefaultType()));
|
||||
v.newField(OtherOrigin(myClass), ACC_PRIVATE | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC, ENUM_VALUES_FIELD_NAME,
|
||||
arrayAsmType.getDescriptor(), null, null);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.MutableClassDescriptor;
|
||||
@@ -27,13 +27,13 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils;
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.createJavaModule;
|
||||
|
||||
public class JvmRuntimeTypes {
|
||||
@@ -110,7 +110,7 @@ public class JvmRuntimeTypes {
|
||||
classDescriptor.getMemberScope(typeArguments)
|
||||
);
|
||||
|
||||
JetType functionType = KotlinBuiltIns.getInstance().getFunctionType(
|
||||
JetType functionType = getBuiltIns(descriptor).getFunctionType(
|
||||
Annotations.EMPTY,
|
||||
receiverParameter == null ? null : receiverParameter.getType(),
|
||||
ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
|
||||
|
||||
@@ -22,10 +22,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
@@ -57,9 +55,6 @@ public class IntrinsicMethods {
|
||||
private static final ToString TO_STRING = new ToString();
|
||||
private static final Clone CLONE = new Clone();
|
||||
|
||||
private static final FqNameUnsafe KOTLIN_ANY_FQ_NAME = DescriptorUtils.getFqName(KotlinBuiltIns.getInstance().getAny());
|
||||
private static final FqNameUnsafe KOTLIN_STRING_FQ_NAME = DescriptorUtils.getFqName(KotlinBuiltIns.getInstance().getString());
|
||||
|
||||
private final Map<String, IntrinsicMethod> namedMethods = new HashMap<String, IntrinsicMethod>();
|
||||
private static final IntrinsicMethod ARRAY_ITERATOR = new ArrayIterator();
|
||||
private final IntrinsicsMap intrinsicsMap = new IntrinsicsMap();
|
||||
@@ -116,9 +111,9 @@ public class IntrinsicMethods {
|
||||
|
||||
declareIntrinsicFunction("Cloneable", "clone", 0, CLONE);
|
||||
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, KOTLIN_ANY_FQ_NAME, "toString", 0, TO_STRING);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, KOTLIN_ANY_FQ_NAME, "identityEquals", 1, IDENTITY_EQUALS);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, KOTLIN_STRING_FQ_NAME, "plus", 1, STRING_PLUS);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, KotlinBuiltIns.FQ_NAMES.any, "toString", 0, TO_STRING);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, KotlinBuiltIns.FQ_NAMES.any, "identityEquals", 1, IDENTITY_EQUALS);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, KotlinBuiltIns.FQ_NAMES.string, "plus", 1, STRING_PLUS);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, null, "arrayOfNulls", 1, new NewArray());
|
||||
|
||||
for (PrimitiveType type : PrimitiveType.values()) {
|
||||
|
||||
@@ -67,11 +67,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isUnit;
|
||||
import static org.jetbrains.kotlin.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isVarCapturedInClosure;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class JetTypeMapper {
|
||||
@@ -186,9 +188,7 @@ public class JetTypeMapper {
|
||||
return Type.VOID_TYPE;
|
||||
}
|
||||
|
||||
if (returnType.equals(KotlinBuiltIns.getInstance().getUnitType())
|
||||
&& !TypeUtils.isNullableType(returnType)
|
||||
&& !(descriptor instanceof PropertyGetterDescriptor)) {
|
||||
if (isUnit(returnType) && !TypeUtils.isNullableType(returnType) && !(descriptor instanceof PropertyGetterDescriptor)) {
|
||||
if (sw != null) {
|
||||
sw.writeAsmType(Type.VOID_TYPE);
|
||||
}
|
||||
@@ -936,8 +936,8 @@ public class JetTypeMapper {
|
||||
|
||||
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration.getKind() == ClassKind.ENUM_CLASS || containingDeclaration.getKind() == ClassKind.ENUM_ENTRY) {
|
||||
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, KotlinBuiltIns.getInstance().getStringType());
|
||||
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, KotlinBuiltIns.getInstance().getIntType());
|
||||
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, getBuiltIns(descriptor).getStringType());
|
||||
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, getBuiltIns(descriptor).getIntType());
|
||||
}
|
||||
|
||||
if (closure == null) return;
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
@@ -221,7 +221,7 @@ public class InjectorForReplWithJava {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
+1
-1
@@ -219,7 +219,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
+2
-2
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.types.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.types.Variance.INVARIANT;
|
||||
|
||||
public class SingleAbstractMethodUtils {
|
||||
@@ -121,8 +122,7 @@ public class SingleAbstractMethodUtils {
|
||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||
parameterTypes.add(parameter.getType());
|
||||
}
|
||||
return KotlinBuiltIns.getInstance().getFunctionType(
|
||||
Annotations.EMPTY, null, parameterTypes, returnType);
|
||||
return getBuiltIns(function).getFunctionType(Annotations.EMPTY, null, parameterTypes, returnType);
|
||||
}
|
||||
|
||||
private static boolean isSamInterface(@NotNull ClassDescriptor klass) {
|
||||
|
||||
+2
-1
@@ -50,6 +50,7 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.load.java.components.TypeUsage.*;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.types.Variance.INVARIANT;
|
||||
|
||||
public class SignaturesPropagationData {
|
||||
@@ -263,7 +264,7 @@ public class SignaturesPropagationData {
|
||||
stableName != null ? stableName : originalParam.getName(),
|
||||
altType,
|
||||
originalParam.declaresDefaultValue(),
|
||||
varargCheckResult.isVararg ? KotlinBuiltIns.getInstance().getArrayElementType(altType) : null,
|
||||
varargCheckResult.isVararg ? getBuiltIns(originalParam).getArrayElementType(altType) : null,
|
||||
SourceElement.NO_SOURCE
|
||||
));
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class InjectorForBodyResolve {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
@@ -157,7 +157,7 @@ public class InjectorForLazyBodyResolve {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ public class InjectorForLazyLocalClassifierAnalyzer {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
@@ -136,7 +136,7 @@ public class InjectorForLazyResolve {
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
this.expressionTypingComponents = new ExpressionTypingComponents();
|
||||
this.expressionTypingServices = new ExpressionTypingServices(expressionTypingComponents);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
@@ -112,7 +112,7 @@ public class InjectorForMacros {
|
||||
this.defaultProvider = DefaultProvider.INSTANCE$;
|
||||
this.symbolUsageValidator = defaultProvider.getSymbolUsageValidator();
|
||||
this.statementFilter = new StatementFilter();
|
||||
this.callExpressionResolver = new CallExpressionResolver(getCallResolver());
|
||||
this.callExpressionResolver = new CallExpressionResolver(getCallResolver(), kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(getCallResolver());
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
|
||||
public class MainFunctionDetector {
|
||||
private final NotNullFunction<JetNamedFunction, FunctionDescriptor> getFunctionDescriptor;
|
||||
|
||||
@@ -69,14 +71,13 @@ public class MainFunctionDetector {
|
||||
|
||||
ValueParameterDescriptor parameter = parameters.get(0);
|
||||
JetType parameterType = parameter.getType();
|
||||
KotlinBuiltIns kotlinBuiltIns = KotlinBuiltIns.getInstance();
|
||||
if (!KotlinBuiltIns.isArray(parameterType)) return false;
|
||||
|
||||
List<TypeProjection> typeArguments = parameterType.getArguments();
|
||||
if (typeArguments.size() != 1) return false;
|
||||
|
||||
JetType typeArgument = typeArguments.get(0).getType();
|
||||
if (!JetTypeChecker.DEFAULT.equalTypes(typeArgument, kotlinBuiltIns.getStringType())) return false;
|
||||
if (!JetTypeChecker.DEFAULT.equalTypes(typeArgument, getBuiltIns(functionDescriptor).getStringType())) return false;
|
||||
|
||||
if (DescriptorUtils.isTopLevelDeclaration(functionDescriptor)) return true;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -241,7 +240,7 @@ public class JetPsiUtil {
|
||||
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
||||
for (JetAnnotationEntry annotation : annotationEntries) {
|
||||
Name shortName = getShortName(annotation);
|
||||
if (KotlinBuiltIns.getInstance().getDeprecatedAnnotation().getName().equals(shortName)) {
|
||||
if (KotlinBuiltIns.FQ_NAMES.deprecated.shortName().equals(shortName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -332,14 +331,6 @@ public class JetPsiUtil {
|
||||
return qualifiedParent.getReceiverExpression() == expression || isLHSOfDot(qualifiedParent);
|
||||
}
|
||||
|
||||
public static boolean isVoidType(@Nullable JetTypeReference typeReference) {
|
||||
if (typeReference == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return KotlinBuiltIns.getInstance().getUnit().getName().asString().equals(typeReference.getText());
|
||||
}
|
||||
|
||||
// SCRIPT: is declaration in script?
|
||||
public static boolean isScriptDeclaration(@NotNull JetDeclaration namedDeclaration) {
|
||||
return getScript(namedDeclaration) != null;
|
||||
@@ -732,16 +723,6 @@ public class JetPsiUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement skipSiblingsForwardByPredicate(@Nullable PsiElement element, Predicate<PsiElement> elementsToSkip) {
|
||||
if (element == null) return null;
|
||||
for (PsiElement e = element.getNextSibling(); e != null; e = e.getNextSibling()) {
|
||||
if (elementsToSkip.apply(e)) continue;
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Delete given element and all the elements separating it from the neighboring elements of the same class
|
||||
public static void deleteElementWithDelimiters(@NotNull PsiElement element) {
|
||||
PsiElement paramBefore = PsiTreeUtil.getPrevSiblingOfType(element, element.getClass());
|
||||
|
||||
@@ -30,7 +30,6 @@ import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
@@ -50,6 +49,7 @@ import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.*;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.classCanHaveAbstractMembers;
|
||||
import static org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
|
||||
public class OverrideResolver {
|
||||
|
||||
@@ -722,7 +722,7 @@ public class OverrideResolver {
|
||||
|
||||
@NotNull
|
||||
private JetAnnotationEntry findDataAnnotationForDataClass(@NotNull DeclarationDescriptor dataClass) {
|
||||
ClassDescriptor stdDataClassAnnotation = KotlinBuiltIns.getInstance().getDataClassAnnotation();
|
||||
ClassDescriptor stdDataClassAnnotation = getBuiltIns(dataClass).getDataClassAnnotation();
|
||||
AnnotationDescriptor annotation = dataClass.getAnnotations().findAnnotation(DescriptorUtils.getFqNameSafe(stdDataClassAnnotation));
|
||||
if (annotation == null) {
|
||||
throw new IllegalStateException("No data annotation is found for data class " + dataClass);
|
||||
|
||||
@@ -231,8 +231,8 @@ public class TypeResolver(
|
||||
val returnTypeRef = type.getReturnTypeReference()
|
||||
val returnType = if (returnTypeRef != null)
|
||||
resolveType(c.noBareTypes(), returnTypeRef)
|
||||
else KotlinBuiltIns.getInstance().getUnitType()
|
||||
result = type(KotlinBuiltIns.getInstance().getFunctionType(annotations, receiverType, parameterTypes, returnType))
|
||||
else moduleDescriptor.builtIns.getUnitType()
|
||||
result = type(moduleDescriptor.builtIns.getFunctionType(annotations, receiverType, parameterTypes, returnType))
|
||||
}
|
||||
|
||||
override fun visitDynamicType(type: JetDynamicType) {
|
||||
|
||||
+4
-2
@@ -60,9 +60,11 @@ import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
public class CallExpressionResolver {
|
||||
|
||||
private final CallResolver callResolver;
|
||||
private final KotlinBuiltIns builtIns;
|
||||
|
||||
public CallExpressionResolver(@NotNull CallResolver callResolver) {
|
||||
public CallExpressionResolver(@NotNull CallResolver callResolver, @NotNull KotlinBuiltIns builtIns) {
|
||||
this.callResolver = callResolver;
|
||||
this.builtIns = builtIns;
|
||||
}
|
||||
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
@@ -349,7 +351,7 @@ public class CallExpressionResolver {
|
||||
|
||||
CompileTimeConstant<?> value = ConstantExpressionEvaluator.evaluate(expression, context.trace, context.expectedType);
|
||||
if (value instanceof IntegerValueConstant && ((IntegerValueConstant) value).isPure()) {
|
||||
return BasicExpressionTypingVisitor.createCompileTimeConstantTypeInfo(value, expression, context);
|
||||
return ExpressionTypingUtils.createCompileTimeConstantTypeInfo(value, expression, context, builtIns);
|
||||
}
|
||||
|
||||
JetTypeInfo typeInfo;
|
||||
|
||||
+2
-2
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.JetNodeTypes;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
@@ -34,6 +33,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.*;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isNullableNothing;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.REFERENCE_TARGET;
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ public class DataFlowValueFactory {
|
||||
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
||||
}
|
||||
if (type.isError()) return DataFlowValue.ERROR;
|
||||
if (KotlinBuiltIns.getInstance().getNullableNothingType().equals(type)) {
|
||||
if (isNullableNothing(type)) {
|
||||
return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
|
||||
}
|
||||
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext, containingDeclarationOrModule);
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.jetbrains.kotlin.psi.ValueArgument
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression
|
||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
|
||||
object DynamicCallableDescriptors {
|
||||
|
||||
@@ -195,7 +196,7 @@ object DynamicCallableDescriptors {
|
||||
val receiverType = funLiteral.getReceiverTypeReference()?.let { DynamicType }
|
||||
val parameterTypes = funLiteral.getValueParameters().map { DynamicType }
|
||||
|
||||
return KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, DynamicType)
|
||||
return owner.builtIns.getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, DynamicType)
|
||||
}
|
||||
|
||||
for (arg in call.getValueArguments()) {
|
||||
@@ -213,7 +214,7 @@ object DynamicCallableDescriptors {
|
||||
|
||||
arg.getSpreadElement() != null -> {
|
||||
hasSpreadOperator = true
|
||||
outType = KotlinBuiltIns.getInstance().getArrayType(Variance.OUT_VARIANCE, DynamicType)
|
||||
outType = owner.builtIns.getArrayType(Variance.OUT_VARIANCE, DynamicType)
|
||||
varargElementType = DynamicType
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMapping;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch;
|
||||
@@ -71,9 +70,7 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
private static boolean hasInlineOption(@NotNull ValueParameterDescriptor descriptor, @NotNull InlineOption option) {
|
||||
AnnotationDescriptor annotation = descriptor.getAnnotations().findAnnotation(
|
||||
DescriptorUtils.getFqNameSafe(KotlinBuiltIns.getInstance().getInlineOptionsClassAnnotation())
|
||||
);
|
||||
AnnotationDescriptor annotation = descriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.inlineOptions);
|
||||
if (annotation != null) {
|
||||
CompileTimeConstant<?> argument = firstOrNull(annotation.getAllValueArguments().values());
|
||||
if (argument instanceof ArrayValue) {
|
||||
|
||||
+1
-2
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
public class DeprecatedSymbolValidator : SymbolUsageValidator {
|
||||
private val JAVA_DEPRECATED = FqName(javaClass<Deprecated>().getName())
|
||||
private val KOTLIN_DEPRECATED = DescriptorUtils.getFqNameSafe(KotlinBuiltIns.getInstance().getDeprecatedAnnotation())
|
||||
|
||||
override fun validateCall(targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
|
||||
val deprecated = targetDescriptor.getDeprecatedAnnotation()
|
||||
@@ -86,7 +85,7 @@ public class DeprecatedSymbolValidator : SymbolUsageValidator {
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.getDeclaredDeprecatedAnnotation(): AnnotationDescriptor? {
|
||||
return getAnnotations().findAnnotation(KOTLIN_DEPRECATED) ?: getAnnotations().findAnnotation(JAVA_DEPRECATED)
|
||||
return getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.deprecated) ?: getAnnotations().findAnnotation(JAVA_DEPRECATED)
|
||||
}
|
||||
|
||||
private fun createDeprecationDiagnostic(element: PsiElement, descriptor: DeclarationDescriptor, deprecated: AnnotationDescriptor): Diagnostic {
|
||||
|
||||
+5
-21
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
|
||||
import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver;
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext;
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CheckValueArgumentsMode;
|
||||
@@ -66,6 +65,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
|
||||
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
|
||||
import org.jetbrains.kotlin.util.slicedMap.WritableSlice;
|
||||
import org.jetbrains.kotlin.utils.ThrowingList;
|
||||
|
||||
@@ -89,7 +89,6 @@ import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType;
|
||||
import static org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.createCallForSpecialConstruction;
|
||||
import static org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.*;
|
||||
import static org.jetbrains.kotlin.types.expressions.TypeReconstructionUtil.reconstructBareType;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
|
||||
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@@ -132,7 +131,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
|
||||
assert value != null : "CompileTimeConstant should be evaluated for constant expression or an error should be recorded " + expression.getText();
|
||||
return createCompileTimeConstantTypeInfo(value, expression, context);
|
||||
return createCompileTimeConstantTypeInfo(value, expression, context, components.builtIns);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -188,7 +187,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetTypeInfo typeInfo = facade.getTypeInfo(left, contextWithNoExpectedType);
|
||||
|
||||
JetType subjectType = typeInfo.getType();
|
||||
JetType targetType = reconstructBareType(right, possiblyBareTarget, subjectType, context.trace);
|
||||
JetType targetType = reconstructBareType(right, possiblyBareTarget, subjectType, context.trace, components.builtIns);
|
||||
|
||||
if (subjectType != null) {
|
||||
checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, subjectType);
|
||||
@@ -911,27 +910,12 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
CompileTimeConstant<?> value = ConstantExpressionEvaluator.evaluate(expression, contextWithExpectedType.trace,
|
||||
contextWithExpectedType.expectedType);
|
||||
if (value != null) {
|
||||
return createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType);
|
||||
return createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType, components.builtIns);
|
||||
}
|
||||
|
||||
return DataFlowUtils.checkType(typeInfo.replaceType(result), expression, contextWithExpectedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetTypeInfo createCompileTimeConstantTypeInfo(
|
||||
@NotNull CompileTimeConstant<?> value,
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull ExpressionTypingContext context
|
||||
) {
|
||||
JetType expressionType = value.getType(KotlinBuiltIns.getInstance());
|
||||
if (value instanceof IntegerValueTypeConstant && context.contextDependency == INDEPENDENT) {
|
||||
expressionType = ((IntegerValueTypeConstant) value).getType(context.expectedType);
|
||||
ArgumentTypeResolver.updateNumberType(expressionType, expression, context);
|
||||
}
|
||||
|
||||
return TypeInfoFactoryPackage.createCheckedTypeInfo(expressionType, context, expression);
|
||||
}
|
||||
|
||||
private JetTypeInfo visitExclExclExpression(@NotNull JetUnaryExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
assert baseExpression != null;
|
||||
@@ -1120,7 +1104,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType
|
||||
);
|
||||
if (value != null) {
|
||||
return createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType);
|
||||
return createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType, components.builtIns);
|
||||
}
|
||||
return DataFlowUtils.checkType(result, expression, contextWithExpectedType);
|
||||
}
|
||||
|
||||
+6
-2
@@ -39,7 +39,10 @@ import org.jetbrains.kotlin.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.CommonSupertypes;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
|
||||
|
||||
@@ -51,6 +54,7 @@ import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||
import static org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.*;
|
||||
import static org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.createCallForSpecialConstruction;
|
||||
import static org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.createDataFlowInfoForArgumentsForIfCall;
|
||||
@@ -605,7 +609,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
) {
|
||||
JetType expectedType;
|
||||
if (function instanceof JetSecondaryConstructor) {
|
||||
expectedType = KotlinBuiltIns.getInstance().getUnitType();
|
||||
expectedType = getBuiltIns(descriptor).getUnitType();
|
||||
}
|
||||
else if (function instanceof JetFunction) {
|
||||
JetFunction jetFunction = (JetFunction) function;
|
||||
|
||||
+21
@@ -22,6 +22,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
||||
@@ -29,6 +30,9 @@ import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant;
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassReceiver;
|
||||
@@ -43,6 +47,7 @@ import java.util.List;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.PROCESSED;
|
||||
import static org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||
|
||||
public class ExpressionTypingUtils {
|
||||
|
||||
@@ -236,4 +241,20 @@ public class ExpressionTypingUtils {
|
||||
|
||||
private ExpressionTypingUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetTypeInfo createCompileTimeConstantTypeInfo(
|
||||
@NotNull CompileTimeConstant<?> value,
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull ExpressionTypingContext context,
|
||||
@NotNull KotlinBuiltIns kotlinBuiltIns
|
||||
) {
|
||||
JetType expressionType = value.getType(kotlinBuiltIns);
|
||||
if (value instanceof IntegerValueTypeConstant && context.contextDependency == INDEPENDENT) {
|
||||
expressionType = ((IntegerValueTypeConstant) value).getType(context.expectedType);
|
||||
ArgumentTypeResolver.updateNumberType(expressionType, expression, context);
|
||||
}
|
||||
|
||||
return TypeInfoFactoryPackage.createCheckedTypeInfo(expressionType, context, expression);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPac
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isBoolean;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
@@ -63,7 +64,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
DataFlowInfo newDataFlowInfo = conditionInfo.and(typeInfo.getDataFlowInfo());
|
||||
context.trace.record(BindingContext.DATAFLOW_INFO_AFTER_CONDITION, expression, newDataFlowInfo);
|
||||
}
|
||||
return DataFlowUtils.checkType(typeInfo.replaceType(KotlinBuiltIns.getInstance().getBooleanType()), expression, contextWithExpectedType);
|
||||
return DataFlowUtils.checkType(typeInfo.replaceType(components.builtIns.getBooleanType()), expression, contextWithExpectedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,7 +190,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
argumentForSubject, rangeExpression, context);
|
||||
DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo();
|
||||
newDataFlowInfo.set(new DataFlowInfos(dataFlowInfo, dataFlowInfo));
|
||||
if (!KotlinBuiltIns.getInstance().getBooleanType().equals(typeInfo.getType())) {
|
||||
JetType type = typeInfo.getType();
|
||||
if (type == null || !isBoolean(type)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_RANGE.on(condition));
|
||||
}
|
||||
}
|
||||
@@ -258,7 +260,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
context = context.replaceDataFlowInfo(typeInfo.getDataFlowInfo());
|
||||
if (conditionExpected) {
|
||||
JetType booleanType = KotlinBuiltIns.getInstance().getBooleanType();
|
||||
JetType booleanType = components.builtIns.getBooleanType();
|
||||
if (!JetTypeChecker.DEFAULT.equalTypes(booleanType, type)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(expression, type));
|
||||
}
|
||||
@@ -291,7 +293,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
TypeResolutionContext typeResolutionContext = new TypeResolutionContext(context.scope, context.trace, true, /*allowBareTypes=*/ true);
|
||||
PossiblyBareType possiblyBareTarget = components.typeResolver.resolvePossiblyBareType(typeResolutionContext, typeReferenceAfterIs);
|
||||
JetType targetType = TypeReconstructionUtil.reconstructBareType(typeReferenceAfterIs, possiblyBareTarget, subjectType, context.trace);
|
||||
JetType targetType = TypeReconstructionUtil.reconstructBareType(typeReferenceAfterIs, possiblyBareTarget, subjectType, context.trace, components.builtIns);
|
||||
|
||||
if (TypesPackage.isDynamic(targetType)) {
|
||||
context.trace.report(DYNAMIC_NOT_ALLOWED.on(typeReferenceAfterIs));
|
||||
|
||||
+3
-2
@@ -37,11 +37,12 @@ public class TypeReconstructionUtil {
|
||||
@NotNull JetTypeReference right,
|
||||
@NotNull PossiblyBareType possiblyBareTarget,
|
||||
@Nullable JetType subjectType,
|
||||
@NotNull BindingTrace trace
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull KotlinBuiltIns builtIns
|
||||
) {
|
||||
if (subjectType == null) {
|
||||
// Recovery: let's reconstruct as if we were casting from Any, to get some type there
|
||||
subjectType = KotlinBuiltIns.getInstance().getAnyType();
|
||||
subjectType = builtIns.getAnyType();
|
||||
}
|
||||
TypeReconstructionResult reconstructionResult = possiblyBareTarget.reconstruct(subjectType);
|
||||
if (!reconstructionResult.isAllArgumentsInferred()) {
|
||||
|
||||
+3
-4
@@ -477,9 +477,8 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
return false;
|
||||
}
|
||||
|
||||
ClassDescriptor deprecatedAnnotation = KotlinBuiltIns.getInstance().getDeprecatedAnnotation();
|
||||
String deprecatedName = deprecatedAnnotation.getName().asString();
|
||||
FqNameUnsafe deprecatedFqName = DescriptorUtils.getFqName(deprecatedAnnotation);
|
||||
FqName deprecatedFqName = KotlinBuiltIns.FQ_NAMES.deprecated;
|
||||
String deprecatedName = deprecatedFqName.shortName().asString();
|
||||
|
||||
for (JetAnnotationEntry annotationEntry : jetModifierList.getAnnotationEntries()) {
|
||||
JetTypeReference typeReference = annotationEntry.getTypeReference();
|
||||
@@ -491,7 +490,7 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
FqName fqName = JetPsiUtil.toQualifiedName((JetUserType) typeElement);
|
||||
if (fqName == null) continue;
|
||||
|
||||
if (deprecatedFqName.equals(fqName.toUnsafe())) return true;
|
||||
if (deprecatedFqName.equals(fqName)) return true;
|
||||
if (deprecatedName.equals(fqName.asString())) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
+4
-2
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.serialization.AnnotationSerializer
|
||||
import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
||||
@@ -59,9 +60,10 @@ public object BuiltInsSerializerExtension : SerializerExtension() {
|
||||
for (annotation in callable.getAnnotations()) {
|
||||
proto.addExtension(BuiltInsProtoBuf.callableAnnotation, AnnotationSerializer.serializeAnnotation(annotation, stringTable))
|
||||
}
|
||||
val compileTimeConstant = (callable as? PropertyDescriptor)?.getCompileTimeInitializer()
|
||||
val propertyDescriptor = callable as? PropertyDescriptor ?: return
|
||||
val compileTimeConstant = propertyDescriptor.getCompileTimeInitializer()
|
||||
if (compileTimeConstant != null && compileTimeConstant !is NullValue) {
|
||||
val type = compileTimeConstant.getType(KotlinBuiltIns.getInstance())
|
||||
val type = compileTimeConstant.getType(propertyDescriptor.builtIns)
|
||||
proto.setExtension(BuiltInsProtoBuf.compileTimeValue, AnnotationSerializer.valueProto(compileTimeConstant, type, stringTable).build())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class InjectorForTests {
|
||||
this.callCompleter = new CallCompleter(argumentTypeResolver, candidateResolver);
|
||||
this.taskPrioritizer = new TaskPrioritizer(storageManager);
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver);
|
||||
this.callExpressionResolver = new CallExpressionResolver(callResolver, kotlinBuiltIns);
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(callResolver);
|
||||
this.forLoopConventionsChecker = new ForLoopConventionsChecker();
|
||||
this.localClassifierAnalyzer = new LocalClassifierAnalyzer(getDescriptorResolver(), getFunctionDescriptorResolver(), getTypeResolver(), annotationResolver);
|
||||
|
||||
Reference in New Issue
Block a user