From ac2cb9af7404dba9506cfd90b20c6595dbf3d5cd Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 23 Apr 2015 15:40:16 +0300 Subject: [PATCH] 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 --- .../kotlin/backend/common/CodegenUtil.java | 37 ++++----- .../common/DataClassMethodGenerator.java | 15 ++-- .../org/jetbrains/kotlin/codegen/AsmUtil.java | 14 +--- .../kotlin/codegen/ClosureCodegen.java | 8 +- .../kotlin/codegen/ExpressionCodegen.java | 15 ++-- .../kotlin/codegen/FunctionCodegen.java | 4 +- .../codegen/ImplementationBodyCodegen.java | 26 +++--- .../kotlin/codegen/JvmRuntimeTypes.java | 6 +- .../codegen/intrinsics/IntrinsicMethods.java | 11 +-- .../kotlin/codegen/state/JetTypeMapper.java | 10 +-- .../di/InjectorForLazyResolveWithJava.java | 2 +- .../kotlin/di/InjectorForReplWithJava.java | 2 +- .../di/InjectorForTopDownAnalyzerForJvm.java | 2 +- .../java/sam/SingleAbstractMethodUtils.java | 4 +- .../SignaturesPropagationData.java | 3 +- .../kotlin/di/InjectorForBodyResolve.java | 2 +- .../kotlin/di/InjectorForLazyBodyResolve.java | 2 +- ...njectorForLazyLocalClassifierAnalyzer.java | 2 +- .../kotlin/di/InjectorForLazyResolve.java | 2 +- .../kotlin/di/InjectorForMacros.java | 2 +- .../kotlin/idea/MainFunctionDetector.java | 5 +- .../org/jetbrains/kotlin/psi/JetPsiUtil.java | 21 +---- .../kotlin/resolve/OverrideResolver.java | 4 +- .../jetbrains/kotlin/resolve/TypeResolver.kt | 4 +- .../resolve/calls/CallExpressionResolver.java | 6 +- .../smartcasts/DataFlowValueFactory.java | 4 +- .../resolve/calls/tasks/dynamicCalls.kt | 5 +- .../kotlin/resolve/inline/InlineUtil.java | 5 +- .../validation/DeprecatedSymbolValidator.kt | 3 +- .../BasicExpressionTypingVisitor.java | 26 ++---- .../ControlStructureTypingVisitor.java | 8 +- .../expressions/ExpressionTypingUtils.java | 21 +++++ .../PatternMatchingTypingVisitor.java | 10 ++- .../expressions/TypeReconstructionUtil.java | 5 +- ...otlinLightClassForExplicitDeclaration.java | 7 +- .../builtins/BuiltInsSerializerExtension.kt | 6 +- .../jetbrains/kotlin/di/InjectorForTests.java | 2 +- .../descriptors/LazyJavaClassDescriptor.kt | 30 +++---- .../LazyJavaTypeParameterDescriptor.kt | 2 +- .../java/lazy/types/LazyJavaTypeResolver.kt | 14 ++-- .../kotlin/builtins/KotlinBuiltIns.java | 80 +++++++++++++++---- .../impl/PropertyDescriptorImpl.java | 5 +- .../impl/PropertySetterDescriptorImpl.java | 5 +- .../impl/TypeParameterDescriptorImpl.java | 7 +- .../kotlin/resolve/DescriptorFactory.java | 6 +- .../kotlin/resolve/DescriptorUtils.java | 10 +-- .../kotlin/resolve/DescriptorUtils.kt | 5 +- .../kotlin/resolve/constants/ArrayValue.java | 4 +- .../kotlin/resolve/constants/ConstantUtils.kt | 13 ++- .../kotlin/resolve/constants/EnumValue.java | 7 +- .../kotlin/resolve/constants/NullValue.java | 2 +- .../types/checker/TypeCheckingProcedure.java | 5 +- .../deserialization/TypeDeserializer.kt | 2 +- .../DeserializedTypeParameterDescriptor.java | 5 +- .../DeprecatedAnnotationVisitor.java | 3 +- .../kotlin/idea/completion/smart/Utils.kt | 10 ++- .../OverrideImplementMethodsHandler.kt | 4 +- .../idea/codeInsight/CodeInsightUtils.java | 18 ++--- .../codeInsight/GotoSuperActionHandler.java | 4 +- .../KotlinExpressionSurrounder.java | 6 +- .../expression/KotlinNotSurrounder.java | 3 +- .../ReplaceContainsIntention.kt | 6 +- .../callableBuilder/typeUtils.kt | 9 +-- .../KotlinIntroduceVariableHandler.java | 5 +- .../rename/AutomaticVariableRenamer.kt | 3 +- .../di/InjectorForTopDownAnalyzerForJs.java | 2 +- .../js/descriptorUtils/descriptorUtils.kt | 3 +- .../callTranslator/FunctionCallCases.kt | 15 ++-- .../declaration/JsDataClassGenerator.java | 9 ++- .../js/translate/utils/JsDescriptorUtils.java | 6 +- .../js/translate/utils/TranslationUtils.java | 3 +- 71 files changed, 334 insertions(+), 288 deletions(-) diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java index d8bee3d0e1c..3d4400a8798 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.java @@ -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 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); diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.java b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.java index 0763be63f7d..0d76103f577 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.java +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.java @@ -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 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 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 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; } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 543a3568a56..d02a76f84cf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -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 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 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) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 06490cce22c..7ed2381ea32 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -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 { } 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 { 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(); } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index bd328464cfe..2db46ec524c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -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 implements LocalLookup { - private static final Set 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 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 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 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; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index f4441faad17..499329d17eb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -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; } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index a10beb0823b..4c4384fd087 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -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 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 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 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() { @@ -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); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java index 46788642eea..3009141e8e6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmRuntimeTypes.java @@ -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()), diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java index e7bb3434e7a..fa44fb39ea3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicMethods.java @@ -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 namedMethods = new HashMap(); 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()) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java index 32e657fbd5e..835f8b36c8f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/JetTypeMapper.java @@ -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; diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForLazyResolveWithJava.java b/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForLazyResolveWithJava.java index 3725e1553c0..5fc3051c882 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForLazyResolveWithJava.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForLazyResolveWithJava.java @@ -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(); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForReplWithJava.java b/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForReplWithJava.java index d9bbf48882a..c421a805d5a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForReplWithJava.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForReplWithJava.java @@ -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(); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJvm.java index e7a23db9a6a..81b2839ee99 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJvm.java @@ -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(); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java index 2459e13b97c..b0049885fcd 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java @@ -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) { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java index e9768306be6..9d2adf882d6 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/kotlinSignature/SignaturesPropagationData.java @@ -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 )); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForBodyResolve.java b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForBodyResolve.java index 3ae412aa617..5b6a2a039f4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForBodyResolve.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForBodyResolve.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyBodyResolve.java b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyBodyResolve.java index 01370383c55..bb4505261df 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyBodyResolve.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyBodyResolve.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyLocalClassifierAnalyzer.java b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyLocalClassifierAnalyzer.java index 5218e2c1d9e..99f3ade8ef5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyLocalClassifierAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyLocalClassifierAnalyzer.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyResolve.java b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyResolve.java index 4c30b1ccabe..d606d35c442 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyResolve.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForLazyResolve.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForMacros.java b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForMacros.java index c8ed69d4d55..e93b5f356e0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForMacros.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/di/InjectorForMacros.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.java b/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.java index 98c942239c5..0a09f9a2b64 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/idea/MainFunctionDetector.java @@ -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 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 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; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java index 48a330eb619..5ca5944e572 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java @@ -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 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 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()); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java index b7be409a686..da5596a85ca 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java @@ -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); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index f81fe3fa856..faeb550f1e5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -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) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.java index 7ba30276148..ed7fa246638 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallExpressionResolver.java @@ -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; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java index f924e2e8d65..cb66d462583 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java @@ -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); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt index 593a0d2884b..00f7ca2eaea 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/dynamicCalls.kt @@ -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 } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java index 075952609bc..0db3556e99c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java @@ -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) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt index 3654f47bd49..b207c771560 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt @@ -33,7 +33,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils public class DeprecatedSymbolValidator : SymbolUsageValidator { private val JAVA_DEPRECATED = FqName(javaClass().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 { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 37aefd809f6..5a647c2c9a6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -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); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 79de70fe0c0..cec6437744a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -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; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java index ee22faf0bc5..d4ec9b5440b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingUtils.java @@ -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); + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java index 4f1b8915431..1418ec69ccf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/PatternMatchingTypingVisitor.java @@ -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)); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/TypeReconstructionUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/TypeReconstructionUtil.java index 6ec0e79f3c8..7aa8a81068a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/TypeReconstructionUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/TypeReconstructionUtil.java @@ -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()) { diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightClassForExplicitDeclaration.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightClassForExplicitDeclaration.java index 445ce36706d..574be83018a 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightClassForExplicitDeclaration.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightClassForExplicitDeclaration.java @@ -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; diff --git a/compiler/serialization/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt b/compiler/serialization/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt index 9537c3cd2ac..b5b4de0c193 100644 --- a/compiler/serialization/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt +++ b/compiler/serialization/src/org/jetbrains/kotlin/serialization/builtins/BuiltInsSerializerExtension.kt @@ -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()) } } diff --git a/compiler/tests/org/jetbrains/kotlin/di/InjectorForTests.java b/compiler/tests/org/jetbrains/kotlin/di/InjectorForTests.java index ec947d0f35c..dba802011a4 100644 --- a/compiler/tests/org/jetbrains/kotlin/di/InjectorForTests.java +++ b/compiler/tests/org/jetbrains/kotlin/di/InjectorForTests.java @@ -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); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassDescriptor.kt index 3c8ca289b54..193ca90b999 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassDescriptor.kt @@ -16,27 +16,27 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.load.java.structure.JavaClass +import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorBase -import org.jetbrains.kotlin.resolve.scopes.JetScope -import org.jetbrains.kotlin.types.JetType -import org.jetbrains.kotlin.types.TypeConstructor +import org.jetbrains.kotlin.load.java.components.TypeUsage +import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext import org.jetbrains.kotlin.load.java.lazy.child -import org.jetbrains.kotlin.load.java.components.TypeUsage import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations import org.jetbrains.kotlin.load.java.lazy.types.toAttributes -import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor -import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.types.AbstractClassTypeConstructor -import java.util.ArrayList -import org.jetbrains.kotlin.utils.toReadOnlyList -import org.jetbrains.kotlin.load.java.structure.JavaType +import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.load.java.structure.JavaClassifierType +import org.jetbrains.kotlin.load.java.structure.JavaType +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper +import org.jetbrains.kotlin.resolve.scopes.JetScope +import org.jetbrains.kotlin.types.AbstractClassTypeConstructor +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.types.TypeConstructor +import org.jetbrains.kotlin.utils.toReadOnlyList +import java.util.ArrayList class LazyJavaClassDescriptor( private val outerC: LazyJavaResolverContext, @@ -138,7 +138,7 @@ class LazyJavaClassDescriptor( }) } - if (result.isNotEmpty()) result.toReadOnlyList() else listOf(KotlinBuiltIns.getInstance().getAnyType()) + if (result.isNotEmpty()) result.toReadOnlyList() else listOf(c.module.builtIns.getAnyType()) } override fun getSupertypes(): Collection = supertypes() diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaTypeParameterDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaTypeParameterDescriptor.kt index bce6447e63f..9c90a12c3a0 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaTypeParameterDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaTypeParameterDescriptor.kt @@ -45,7 +45,7 @@ class LazyJavaTypeParameterDescriptor( override fun resolveUpperBounds(): Set { val bounds = javaTypeParameter.getUpperBounds() if (bounds.isEmpty()) { - return setOf(KotlinBuiltIns.getInstance().getDefaultBound()) + return setOf(c.module.builtIns.getDefaultBound()) } else { return bounds.map { diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt index ed4e5eb9c47..0c060907872 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/lazy/types/LazyJavaTypeResolver.kt @@ -56,8 +56,8 @@ class LazyJavaTypeResolver( return when (javaType) { is JavaPrimitiveType -> { val primitiveType = javaType.getType() - if (primitiveType != null) KotlinBuiltIns.getInstance().getPrimitiveJetType(primitiveType) - else KotlinBuiltIns.getInstance().getUnitType() + if (primitiveType != null) c.module.builtIns.getPrimitiveJetType(primitiveType) + else c.module.builtIns.getUnitType() } is JavaClassifierType -> if (PLATFORM_TYPES && attr.allowFlexible && attr.howThisTypeIsUsed != SUPERTYPE) @@ -76,7 +76,7 @@ class LazyJavaTypeResolver( val javaComponentType = arrayType.getComponentType() val primitiveType = (javaComponentType as? JavaPrimitiveType)?.getType() if (primitiveType != null) { - val jetType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetType(primitiveType) + val jetType = c.module.builtIns.getPrimitiveArrayJetType(primitiveType) return@run if (PLATFORM_TYPES && attr.allowFlexible) FlexibleJavaClassifierTypeCapabilities.create(jetType, TypeUtils.makeNullable(jetType)) else TypeUtils.makeNullableAsSpecified(jetType, !attr.isMarkedNotNull) @@ -87,12 +87,12 @@ class LazyJavaTypeResolver( if (PLATFORM_TYPES && attr.allowFlexible) { return@run FlexibleJavaClassifierTypeCapabilities.create( - KotlinBuiltIns.getInstance().getArrayType(INVARIANT, componentType), - TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getArrayType(OUT_VARIANCE, componentType))) + c.module.builtIns.getArrayType(INVARIANT, componentType), + TypeUtils.makeNullable(c.module.builtIns.getArrayType(OUT_VARIANCE, componentType))) } val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT || isVararg) OUT_VARIANCE else INVARIANT - val result = KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType) + val result = c.module.builtIns.getArrayType(projectionKind, componentType) return@run TypeUtils.makeNullableAsSpecified(result, !attr.isMarkedNotNull) }.replaceAnnotations(attr.annotations) } @@ -214,7 +214,7 @@ class LazyJavaTypeResolver( // C<*> = C>> // this way we lose some type information, even when the case is not so bad, but it doesn't seem to matter val projectionKind = if (parameter.getVariance() == OUT_VARIANCE) INVARIANT else OUT_VARIANCE - TypeProjectionImpl(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType()) + TypeProjectionImpl(projectionKind, c.module.builtIns.getNullableAnyType()) } else makeStarProjection(parameter, attr) diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index be507c6023b..a84626f7d69 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -42,6 +42,7 @@ import java.util.*; import static kotlin.KotlinPackage.single; import static org.jetbrains.kotlin.builtins.PrimitiveType.*; +import static org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName; public class KotlinBuiltIns { public static final Name BUILT_INS_PACKAGE_NAME = Name.identifier("kotlin"); @@ -157,11 +158,23 @@ public class KotlinBuiltIns { public final FqNameUnsafe string = fqNameUnsafe("String"); public final FqNameUnsafe array = fqNameUnsafe("Array"); + public final FqNameUnsafe _boolean = fqNameUnsafe("Boolean"); + + public final FqNameUnsafe _char = fqNameUnsafe("Char"); + public final FqNameUnsafe _byte = fqNameUnsafe("Byte"); + public final FqNameUnsafe _short = fqNameUnsafe("Short"); + public final FqNameUnsafe _int = fqNameUnsafe("Int"); + public final FqNameUnsafe _long = fqNameUnsafe("Long"); + + public final FqNameUnsafe _float = fqNameUnsafe("Float"); + public final FqNameUnsafe _double = fqNameUnsafe("Double"); + public final FqName data = fqName("data"); public final FqName deprecated = fqName("deprecated"); public final FqName tailRecursive = fqName("tailRecursive"); public final FqName inline = fqName("inline"); public final FqName noinline = fqName("noinline"); + public final FqName inlineOptions = fqName("inlineOptions"); public final FqNameUnsafe kClass = new FqName("kotlin.reflect.KClass").toUnsafe(); @@ -350,11 +363,6 @@ public class KotlinBuiltIns { return getBuiltInClassByName("data"); } - @NotNull - public ClassDescriptor getInlineOptionsClassAnnotation() { - return getBuiltInClassByName("inlineOptions"); - } - @NotNull public ClassDescriptor getDeprecatedAnnotation() { return getBuiltInClassByName("deprecated"); @@ -687,12 +695,16 @@ public class KotlinBuiltIns { public static boolean isPrimitiveArray(@NotNull JetType type) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); - return descriptor != null && getPrimitiveTypeByArrayClassFqName(DescriptorUtils.getFqName(descriptor)) != null; + return descriptor != null && getPrimitiveTypeByArrayClassFqName(getFqName(descriptor)) != null; } public static boolean isPrimitiveType(@NotNull JetType type) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); - return !type.isMarkedNullable() && descriptor != null && getPrimitiveTypeByFqName(DescriptorUtils.getFqName(descriptor)) != null; + return !type.isMarkedNullable() && descriptor instanceof ClassDescriptor && isPrimitiveClass((ClassDescriptor) descriptor); + } + + public static boolean isPrimitiveClass(@NotNull ClassDescriptor descriptor) { + return getPrimitiveTypeByFqName(getFqName(descriptor)) != null; } // Functions @@ -746,7 +758,7 @@ public class KotlinBuiltIns { if (declarationDescriptor == null) return false; - FqNameUnsafe fqName = DescriptorUtils.getFqName(declarationDescriptor); + FqNameUnsafe fqName = getFqName(declarationDescriptor); return classes.contains(fqName); } @@ -799,7 +811,7 @@ public class KotlinBuiltIns { private static boolean isConstructedFromGivenClass(@NotNull JetType type, @NotNull FqNameUnsafe fqName) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); - return descriptor != null && fqName.equals(DescriptorUtils.getFqName(descriptor)); + return descriptor != null && fqName.equals(getFqName(descriptor)); } private static boolean isNotNullConstructedFromGivenClass(@NotNull JetType type, @NotNull FqNameUnsafe fqName) { @@ -807,12 +819,52 @@ public class KotlinBuiltIns { } public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) { - FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor); + FqNameUnsafe fqName = getFqName(descriptor); return FQ_NAMES.any.equals(fqName) || FQ_NAMES.nothing.equals(fqName); } public static boolean isAny(@NotNull ClassDescriptor descriptor) { - return isAny(DescriptorUtils.getFqName(descriptor)); + return isAny(getFqName(descriptor)); + } + + public static boolean isBoolean(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._boolean); + } + + public static boolean isBoolean(@NotNull ClassDescriptor classDescriptor) { + return FQ_NAMES._boolean.equals(getFqName(classDescriptor)); + } + + public static boolean isChar(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._char); + } + + public static boolean isInt(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._int); + } + + public static boolean isByte(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._byte); + } + + public static boolean isLong(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._long); + } + + public static boolean isShort(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._short); + } + + public static boolean isFloat(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._float); + } + + public static boolean isDouble(@NotNull JetType type) { + return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._double); + } + + private static boolean isConstructedFromGivenClassAndNotNullable(@NotNull JetType type, @NotNull FqNameUnsafe fqName) { + return isConstructedFromGivenClass(type, fqName) && !type.isMarkedNullable(); } public static boolean isAny(@NotNull FqNameUnsafe fqName) { @@ -854,15 +906,15 @@ public class KotlinBuiltIns { } public static boolean isKClass(@NotNull ClassDescriptor descriptor) { - return FQ_NAMES.kClass.equals(DescriptorUtils.getFqName(descriptor)); + return FQ_NAMES.kClass.equals(getFqName(descriptor)); } public static boolean isNonPrimitiveArray(@NotNull ClassDescriptor descriptor) { - return FQ_NAMES.array.equals(DescriptorUtils.getFqName(descriptor)); + return FQ_NAMES.array.equals(getFqName(descriptor)); } public static boolean isCloneable(@NotNull ClassDescriptor descriptor) { - return FQ_NAMES.cloneable.equals(DescriptorUtils.getFqName(descriptor)); + return FQ_NAMES.cloneable.equals(getFqName(descriptor)); } public static boolean isData(@NotNull ClassDescriptor classDescriptor) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java index 6ba6ba7d43e..1f667d97f40 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.descriptors.impl; 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.descriptors.annotations.Annotations; import org.jetbrains.kotlin.name.Name; @@ -31,6 +30,8 @@ import org.jetbrains.kotlin.types.Variance; import java.util.*; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; + public class PropertyDescriptorImpl extends VariableDescriptorImpl implements PropertyDescriptor { private final Modality modality; private Visibility visibility; @@ -263,7 +264,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr // it can not be assigned to because of the projection substitutedDescriptor.setSetterProjectedOut(true); substitutedValueParameters = Collections.singletonList( - PropertySetterDescriptorImpl.createSetterParameter(newSetter, KotlinBuiltIns.getInstance().getNothingType()) + PropertySetterDescriptorImpl.createSetterParameter(newSetter, getBuiltIns(newOwner).getNothingType()) ); } if (substitutedValueParameters.size() != 1) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java index 970f6a6b71c..de7dcf57509 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java @@ -22,12 +22,13 @@ import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.types.JetType; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import java.util.Collections; import java.util.List; import java.util.Set; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; + public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertySetterDescriptor { private ValueParameterDescriptor parameter; @@ -87,7 +88,7 @@ public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl @NotNull @Override public JetType getReturnType() { - return KotlinBuiltIns.getInstance().getUnitType(); + return getBuiltIns(this).getUnitType(); } @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java index 0b76f250845..8912060691b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/TypeParameterDescriptorImpl.java @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.descriptors.impl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.SourceElement; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; @@ -34,6 +33,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; + public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor { public static TypeParameterDescriptor createWithDefaultBound( @NotNull DeclarationDescriptor containingDeclaration, @@ -45,7 +46,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor ) { TypeParameterDescriptorImpl typeParameterDescriptor = createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index, SourceElement.NO_SOURCE); - typeParameterDescriptor.addUpperBound(KotlinBuiltIns.getInstance().getDefaultBound()); + typeParameterDescriptor.addUpperBound(getBuiltIns(containingDeclaration).getDefaultBound()); typeParameterDescriptor.setInitialized(); return typeParameterDescriptor; } @@ -125,7 +126,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor checkUninitialized(); if (upperBounds.isEmpty()) { - doAddUpperBound(KotlinBuiltIns.getInstance().getDefaultBound()); + doAddUpperBound(getBuiltIns(getContainingDeclaration()).getDefaultBound()); } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java index e7b64bd7041..a39f612201c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve; 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.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.impl.*; @@ -31,6 +30,7 @@ import java.util.Collections; import static org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER; import static org.jetbrains.kotlin.resolve.DescriptorUtils.getDefaultConstructorVisibility; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; public class DescriptorFactory { private static class DefaultConstructorDescriptor extends ConstructorDescriptorImpl { @@ -90,7 +90,7 @@ public class DescriptorFactory { CallableMemberDescriptor.Kind.SYNTHESIZED, enumClass.getSource()); return values.initialize(null, NO_RECEIVER_PARAMETER, Collections.emptyList(), Collections.emptyList(), - KotlinBuiltIns.getInstance().getArrayType(Variance.INVARIANT, enumClass.getDefaultType()), Modality.FINAL, + getBuiltIns(enumClass).getArrayType(Variance.INVARIANT, enumClass.getDefaultType()), Modality.FINAL, Visibilities.PUBLIC); } @@ -100,7 +100,7 @@ public class DescriptorFactory { SimpleFunctionDescriptorImpl.create(enumClass, Annotations.EMPTY, DescriptorUtils.ENUM_VALUE_OF, CallableMemberDescriptor.Kind.SYNTHESIZED, enumClass.getSource()); ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl( - valueOf, null, 0, Annotations.EMPTY, Name.identifier("value"), KotlinBuiltIns.getInstance().getStringType(), false, null, + valueOf, null, 0, Annotations.EMPTY, Name.identifier("value"), getBuiltIns(enumClass).getStringType(), false, null, enumClass.getSource() ); return valueOf.initialize(null, NO_RECEIVER_PARAMETER, Collections.emptyList(), diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java index 2b2a107fef7..91539377dd1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java @@ -39,8 +39,10 @@ import org.jetbrains.kotlin.types.checker.JetTypeChecker; import java.util.*; +import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isAny; import static org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.*; import static org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; public class DescriptorUtils { public static final Name ENUM_VALUES = Name.identifier("values"); @@ -329,7 +331,7 @@ public class DescriptorUtils { return type; } } - return KotlinBuiltIns.getInstance().getAnyType(); + return getBuiltIns(classDescriptor).getAnyType(); } @NotNull @@ -345,10 +347,6 @@ public class DescriptorUtils { return (ClassDescriptor) descriptor; } - public static boolean isAny(@NotNull DeclarationDescriptor superClassDescriptor) { - return superClassDescriptor.equals(KotlinBuiltIns.getInstance().getAny()); - } - @NotNull public static Visibility getDefaultConstructorVisibility(@NotNull ClassDescriptor classDescriptor) { ClassKind classKind = classDescriptor.getKind(); @@ -429,7 +427,7 @@ public class DescriptorUtils { if (type instanceof LazyType || type.isMarkedNullable()) return true; - KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); + KotlinBuiltIns builtIns = getBuiltIns(variable); return KotlinBuiltIns.isPrimitiveType(type) || JetTypeChecker.DEFAULT.equalTypes(builtIns.getStringType(), type) || JetTypeChecker.DEFAULT.equalTypes(builtIns.getNumber().getDefaultType(), type) || diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt index 43b0bf8d340..73c8d72f1f2 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.kt @@ -102,11 +102,14 @@ public fun ClassDescriptor.getSuperClassNotAny(): ClassDescriptor? { return null } -public fun ClassDescriptor.getSuperClassOrAny(): ClassDescriptor = getSuperClassNotAny() ?: KotlinBuiltIns.getInstance().getAny() +public fun ClassDescriptor.getSuperClassOrAny(): ClassDescriptor = getSuperClassNotAny() ?: builtIns.getAny() public val ClassDescriptor.secondaryConstructors: List get() = getConstructors().filterNot { it.isPrimary() } +public val DeclarationDescriptor.builtIns: KotlinBuiltIns + get() = module.builtIns + /** * Returns containing declaration of dispatch receiver for callable adjusted to fake-overridden cases * diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.java index 8aa6d762c7b..afae9e14363 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ArrayValue.java @@ -32,8 +32,8 @@ public class ArrayValue extends CompileTimeConstant> boolean canBeUsedInAnnotations, boolean usesVariableAsConstant) { super(value, canBeUsedInAnnotations, false, usesVariableAsConstant); - assert KotlinBuiltIns.getInstance().isArray(type) || - KotlinBuiltIns.getInstance().isPrimitiveArray(type) : "Type should be an array, but was " + type + ": " + value; + assert KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type) + : "Type should be an array, but was " + type + ": " + value; this.type = type; } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt index 3d37e26d175..0dff6a49e5f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/ConstantUtils.kt @@ -64,19 +64,18 @@ private fun getIntegerValue( return IntegerValueTypeConstant(value, canBeUsedInAnnotation, usesVariableAsConstant) } - val builtIns = KotlinBuiltIns.getInstance() - - return when (TypeUtils.makeNotNullable(expectedType)) { - builtIns.getLongType() -> LongValue(value, canBeUsedInAnnotation, isPureIntConstant, usesVariableAsConstant) - builtIns.getShortType() -> when (value) { + val notNullExpected = TypeUtils.makeNotNullable(expectedType) + return when { + KotlinBuiltIns.isLong(notNullExpected) -> LongValue(value, canBeUsedInAnnotation, isPureIntConstant, usesVariableAsConstant) + KotlinBuiltIns.isShort(notNullExpected) -> when (value) { value.toShort().toLong() -> ShortValue(value.toShort(), canBeUsedInAnnotation, isPureIntConstant, usesVariableAsConstant) else -> defaultIntegerValue(value) } - builtIns.getByteType() -> when (value) { + KotlinBuiltIns.isByte(notNullExpected) -> when (value) { value.toByte().toLong() -> ByteValue(value.toByte(), canBeUsedInAnnotation, isPureIntConstant, usesVariableAsConstant) else -> defaultIntegerValue(value) } - builtIns.getCharType() -> IntValue(value.toInt(), canBeUsedInAnnotation, isPureIntConstant, usesVariableAsConstant) + KotlinBuiltIns.isChar(notNullExpected) -> IntValue(value.toInt(), canBeUsedInAnnotation, isPureIntConstant, usesVariableAsConstant) else -> defaultIntegerValue(value) } } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.java index fe2fec22c7b..05a092cf9bc 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/EnumValue.java @@ -33,6 +33,11 @@ public class EnumValue extends CompileTimeConstant { @NotNull @Override public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) { + return getType(); + } + + @NotNull + private JetType getType() { JetType type = getClassObjectType(value); assert type != null : "Enum entry must have a class object type: " + value; return type; @@ -53,7 +58,7 @@ public class EnumValue extends CompileTimeConstant { @Override public String toString() { - return getType(KotlinBuiltIns.getInstance()) + "." + value.getName(); + return getType() + "." + value.getName(); } @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.java index 379a873cb46..a4ec8773aa7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/constants/NullValue.java @@ -32,7 +32,7 @@ public class NullValue extends CompileTimeConstant { @NotNull @Override public JetType getType(@NotNull KotlinBuiltIns kotlinBuiltIns) { - return KotlinBuiltIns.getInstance().getNullableNothingType(); + return kotlinBuiltIns.getNullableNothingType(); } @Override diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/TypeCheckingProcedure.java b/core/descriptors/src/org/jetbrains/kotlin/types/checker/TypeCheckingProcedure.java index a3754174e43..96959eae9ab 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/TypeCheckingProcedure.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/TypeCheckingProcedure.java @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.types.*; import java.util.List; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; import static org.jetbrains.kotlin.types.Variance.*; public class TypeCheckingProcedure { @@ -57,9 +58,9 @@ public class TypeCheckingProcedure { return isOutProjected ? parameter.getUpperBoundsAsType() : argument.getType(); } - public static JetType getInType(TypeParameterDescriptor parameter, TypeProjection argument) { + public static JetType getInType(@NotNull TypeParameterDescriptor parameter, @NotNull TypeProjection argument) { boolean isOutProjected = argument.getProjectionKind() == OUT_VARIANCE || parameter.getVariance() == OUT_VARIANCE; - return isOutProjected ? KotlinBuiltIns.getInstance().getNothingType() : argument.getType(); + return isOutProjected ? getBuiltIns(parameter).getNothingType() : argument.getType(); } private final TypeCheckingProcedureCallbacks constraints; diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt index 3b4da174a39..d307cc69019 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -103,7 +103,7 @@ public class TypeDeserializer( fun typeArgument(parameter: TypeParameterDescriptor?, typeArgumentProto: ProtoBuf.Type.Argument): TypeProjection { return if (typeArgumentProto.getProjection() == ProtoBuf.Type.Argument.Projection.STAR) if (parameter == null) - TypeBasedStarProjectionImpl(KotlinBuiltIns.getInstance().getNullableAnyType()) + TypeBasedStarProjectionImpl(c.components.moduleDescriptor.builtIns.getNullableAnyType()) else StarProjectionImpl(parameter) else TypeProjectionImpl(variance(typeArgumentProto.getProjection()), type(typeArgumentProto.getType())) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.java b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.java index 6e6474f4bfe..0f61ee14831 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.java +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.java @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.serialization.deserialization.descriptors; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.SourceElement; import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor; import org.jetbrains.kotlin.serialization.ProtoBuf; @@ -30,6 +29,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; + public class DeserializedTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor { private final ProtoBuf.TypeParameter proto; private final TypeDeserializer typeDeserializer; @@ -50,7 +51,7 @@ public class DeserializedTypeParameterDescriptor extends AbstractLazyTypeParamet @Override protected Set resolveUpperBounds() { if (proto.getUpperBoundCount() == 0) { - return Collections.singleton(KotlinBuiltIns.getInstance().getDefaultBound()); + return Collections.singleton(getBuiltIns(this).getDefaultBound()); } Set result = new LinkedHashSet(proto.getUpperBoundCount()); for (ProtoBuf.Type upperBound : proto.getUpperBoundList()) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/DeprecatedAnnotationVisitor.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/DeprecatedAnnotationVisitor.java index f8db609aa35..86fe3843fe3 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/DeprecatedAnnotationVisitor.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/DeprecatedAnnotationVisitor.java @@ -49,7 +49,6 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito TokenSet.create(JetTokens.EQ, JetTokens.PLUSEQ, JetTokens.MINUSEQ, JetTokens.MULTEQ, JetTokens.DIVEQ, JetTokens.PERCEQ, JetTokens.PLUSPLUS, JetTokens.MINUSMINUS); private static final FqName JAVA_DEPRECATED = new FqName(Deprecated.class.getName()); - private static final FqName KOTLIN_DEPRECATED = DescriptorUtils.getFqNameSafe(KotlinBuiltIns.getInstance().getDeprecatedAnnotation()); protected DeprecatedAnnotationVisitor(AnnotationHolder holder, BindingContext bindingContext) { super(holder, bindingContext); @@ -221,7 +220,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito @Nullable private static AnnotationDescriptor getDeprecated(DeclarationDescriptor descriptor) { - AnnotationDescriptor kotlinDeprecated = descriptor.getAnnotations().findAnnotation(KOTLIN_DEPRECATED); + AnnotationDescriptor kotlinDeprecated = descriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.deprecated); return kotlinDeprecated != null ? kotlinDeprecated : descriptor.getAnnotations().findAnnotation(JAVA_DEPRECATED); } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 17baa76032e..8b673bfde84 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.util.FuzzyType import org.jetbrains.kotlin.idea.util.makeNotNullable import org.jetbrains.kotlin.idea.util.nullability import org.jetbrains.kotlin.idea.util.TypeNullability +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns class ArtificialElementInsertHandler( val textBeforeCaret: String, val textAfterCaret: String, val shortenRefs: Boolean) : InsertHandler{ @@ -233,10 +234,11 @@ fun functionType(function: FunctionDescriptor): JetType? { null else extensionReceiverType ?: memberReceiverType - return KotlinBuiltIns.getInstance().getFunctionType(function.getAnnotations(), - receiverType, - function.getValueParameters().map { it.getType() }, - function.getReturnType() ?: return null) + return function.builtIns.getFunctionType( + function.getAnnotations(), receiverType, + function.getValueParameters().map { it.getType() }, + function.getReturnType() ?: return null + ) } fun LookupElementFactory.createLookupElement( diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/codeInsight/OverrideImplementMethodsHandler.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/codeInsight/OverrideImplementMethodsHandler.kt index 25fb3ac0e8e..1e4f89a6fbc 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/codeInsight/OverrideImplementMethodsHandler.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/codeInsight/OverrideImplementMethodsHandler.kt @@ -268,9 +268,7 @@ public abstract class OverrideImplementMethodsHandler : LanguageCodeInsightActio newDescriptor.addOverriddenDescriptor(descriptor) val returnType = descriptor.getReturnType() - val builtIns = KotlinBuiltIns.getInstance() - - val returnsNotUnit = returnType != null && builtIns.getUnitType() != returnType + val returnsNotUnit = returnType != null && !KotlinBuiltIns.isUnit(returnType) val isAbstract = descriptor.getModality() == Modality.ABSTRACT val delegation = generateUnsupportedOrSuperCall(classOrObject, descriptor) diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java index 9a84c06224c..c146fc69985 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/CodeInsightUtils.java @@ -34,6 +34,8 @@ import org.jetbrains.kotlin.types.JetType; import java.util.ArrayList; import java.util.List; +import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.*; + public class CodeInsightUtils { @Nullable @@ -186,30 +188,28 @@ public class CodeInsightUtils { @Nullable public static String defaultInitializer(JetType type) { - KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); if (type.isMarkedNullable()) { return "null"; } - else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) || - type.equals(builtIns.getShortType()) || type.equals(builtIns.getByteType())) { + else if (isInt(type) || isLong(type) || isShort(type) || isByte(type)) { return "0"; } - else if (type.equals(builtIns.getFloatType())) { + else if (isFloat(type)) { return "0.0f"; } - else if (type.equals(builtIns.getDoubleType())) { + else if (isDouble(type)) { return "0.0"; } - else if (type.equals(builtIns.getCharType())) { + else if (isChar(type)) { return "'\\u0000'"; } - else if (type.equals(builtIns.getBooleanType())) { + else if (isBoolean(type)) { return "false"; } - else if (type.equals(builtIns.getUnitType())) { + else if (isUnit(type)) { return "Unit"; } - else if (type.equals(builtIns.getStringType())) { + else if (isString(type)) { return "\"\""; } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/GotoSuperActionHandler.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/GotoSuperActionHandler.java index bcf798d53f5..367b229c84b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/GotoSuperActionHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/GotoSuperActionHandler.java @@ -44,6 +44,8 @@ import org.jetbrains.kotlin.types.JetType; import java.util.Collection; import java.util.List; +import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isAny; + public class GotoSuperActionHandler implements CodeInsightActionHandler { @Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { @@ -96,7 +98,7 @@ public class GotoSuperActionHandler implements CodeInsightActionHandler { List superDeclarations = ContainerUtil.mapNotNull(superDescriptors, new Function() { @Override public PsiElement fun(DeclarationDescriptor descriptor) { - if (KotlinBuiltIns.getInstance().getAny() == descriptor) { + if (descriptor instanceof ClassDescriptor && isAny((ClassDescriptor) descriptor)) { return null; } return DescriptorToSourceUtils.descriptorToDeclaration(descriptor); diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinExpressionSurrounder.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinExpressionSurrounder.java index 39972fca279..478318fd62c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinExpressionSurrounder.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinExpressionSurrounder.java @@ -23,15 +23,15 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; import org.jetbrains.kotlin.psi.JetCallExpression; import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetQualifiedExpression; -import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode; import org.jetbrains.kotlin.types.JetType; +import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isUnit; + public abstract class KotlinExpressionSurrounder implements Surrounder { @Override @@ -45,7 +45,7 @@ public abstract class KotlinExpressionSurrounder implements Surrounder { return false; } JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).getType(expression); - if (type == null || type.equals(KotlinBuiltIns.getInstance().getUnitType())) { + if (type == null || isUnit(type)) { return false; } return isApplicable(expression); diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinNotSurrounder.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinNotSurrounder.java index 2ec84fa858b..e381969fcc5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinNotSurrounder.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinNotSurrounder.java @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; import org.jetbrains.kotlin.psi.JetExpression; import org.jetbrains.kotlin.psi.JetParenthesizedExpression; import org.jetbrains.kotlin.psi.JetPrefixExpression; -import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode; import org.jetbrains.kotlin.types.JetType; @@ -43,7 +42,7 @@ public class KotlinNotSurrounder extends KotlinExpressionSurrounder { @Override public boolean isApplicable(@NotNull JetExpression expression) { JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).getType(expression); - return KotlinBuiltIns.getInstance().getBooleanType().equals(type); + return type != null && KotlinBuiltIns.isBoolean(type); } @Nullable diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/ReplaceContainsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/ReplaceContainsIntention.kt index 0244b54f14b..19d4e391a5f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/ReplaceContainsIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/attributeCallReplacements/ReplaceContainsIntention.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.psi.JetPsiFactory import org.jetbrains.kotlin.psi.JetPsiUtil import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns public open class ReplaceContainsIntention : AttributeCallReplacementIntention("replace.contains.with.in") { @@ -32,10 +33,11 @@ public open class ReplaceContainsIntention : AttributeCallReplacementIntention(" } override fun replaceCall(call: CallDescription, editor: Editor) { - val ret = call.resolved.getResultingDescriptor().getReturnType() + val resultingDescriptor = call.resolved.getResultingDescriptor() + val ret = resultingDescriptor.getReturnType() ?: return intentionFailed(editor, "undefined.returntype") - if (!JetTypeChecker.DEFAULT.isSubtypeOf(ret, KotlinBuiltIns.getInstance().getBooleanType())) { + if (!resultingDescriptor.builtIns.isBooleanOrSubtype(ret)) { return intentionFailed(editor, "contains.returns.boolean") } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index 9902466b66e..a2843b41bc0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -92,12 +92,11 @@ fun JetExpression.guessTypes( module: ModuleDescriptor, coerceUnusedToUnit: Boolean = true ): Array { - val builtIns = KotlinBuiltIns.getInstance() if (coerceUnusedToUnit && this !is JetDeclaration && isUsedAsStatement(context) - && getNonStrictParentOfType() == null) return array(builtIns.getUnitType()) + && getNonStrictParentOfType() == null) return array(module.builtIns.getUnitType()) // if we know the actual type of the expression val theType1 = context.getType(this) @@ -166,14 +165,14 @@ fun JetExpression.guessTypes( val property = context[BindingContext.DECLARATION_TO_DESCRIPTOR, parent.getParent() as JetProperty] as PropertyDescriptor val delegateClassName = if (property.isVar()) "ReadWriteProperty" else "ReadOnlyProperty" val delegateClass = module.resolveTopLevelClass(FqName("kotlin.properties.$delegateClassName")) - ?: return array(builtIns.getAnyType()) + ?: return array(module.builtIns.getAnyType()) val receiverType = (property.getExtensionReceiverParameter() ?: property.getDispatchReceiverParameter())?.getType() - ?: builtIns.getNullableNothingType() + ?: module.builtIns.getNullableNothingType() val typeArguments = listOf(TypeProjectionImpl(receiverType), TypeProjectionImpl(property.getType())) array(TypeUtils.substituteProjectionsForParameters(delegateClass, typeArguments)) } parent is JetStringTemplateEntryWithExpression && parent.getExpression() == this -> { - array(KotlinBuiltIns.getInstance().getStringType()) + array(module.builtIns.getStringType()) } else -> array() // can't infer anything } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java index 44ccbb6513c..93eb11c263a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java @@ -37,12 +37,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.analyzer.AnalysisResult; import org.jetbrains.kotlin.analyzer.AnalyzerPackage; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage; import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils; +import org.jetbrains.kotlin.idea.core.refactoring.JetNameSuggester; import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyIntention; import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention; -import org.jetbrains.kotlin.idea.core.refactoring.JetNameSuggester; import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl; import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle; import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil; @@ -151,7 +150,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase { return; } if (expressionType != null && - JetTypeChecker.DEFAULT.equalTypes(KotlinBuiltIns.getInstance().getUnitType(), expressionType)) { + JetTypeChecker.DEFAULT.equalTypes(analysisResult.getModuleDescriptor().getBuiltIns().getUnitType(), expressionType)) { showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.expression.has.unit.type")); return; } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/AutomaticVariableRenamer.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/AutomaticVariableRenamer.kt index 65771574228..a770bf9691a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/AutomaticVariableRenamer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/AutomaticVariableRenamer.kt @@ -38,6 +38,7 @@ import org.jetbrains.kotlin.psi.JetParameter import org.jetbrains.kotlin.psi.JetVariableDeclaration import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.source.PsiSourceElement import org.jetbrains.kotlin.types.JetType import java.util.ArrayList @@ -97,7 +98,7 @@ public class AutomaticVariableRenamer( private fun JetType.isCollectionLikeOf(classPsiElement: PsiNamedElement): Boolean { val klass = this.getConstructor().getDeclarationDescriptor() as? ClassDescriptor ?: return false - if (KotlinBuiltIns.isArray(this) || DescriptorUtils.isSubclass(klass, KotlinBuiltIns.getInstance().getCollection())) { + if (KotlinBuiltIns.isArray(this) || DescriptorUtils.isSubclass(klass, klass.builtIns.getCollection())) { val typeArgument = this.getArguments().singleOrNull()?.getType() ?: return false val typePsiElement = ((typeArgument.getConstructor().getDeclarationDescriptor() as? ClassDescriptor)?.getSource() as? PsiSourceElement)?.psi return classPsiElement == typePsiElement || typeArgument.isCollectionLikeOf(classPsiElement) diff --git a/js/js.frontend/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJs.java b/js/js.frontend/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJs.java index 1360f0f39f9..85159962e3d 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJs.java +++ b/js/js.frontend/src/org/jetbrains/kotlin/di/InjectorForTopDownAnalyzerForJs.java @@ -156,7 +156,7 @@ public class InjectorForTopDownAnalyzerForJs { 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(); diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt index 1efe8ea88a5..fb6c7bb9e58 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/descriptorUtils/descriptorUtils.kt @@ -25,12 +25,13 @@ import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.types.TypeProjection import com.intellij.openapi.util.text.StringUtil +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns public val JetType.nameIfStandardType: Name? get() { val descriptor = getConstructor().getDeclarationDescriptor() - if (descriptor?.getContainingDeclaration() == KotlinBuiltIns.getInstance().getBuiltInsPackageFragment()) { + if (descriptor?.getContainingDeclaration() == descriptor?.builtIns?.getBuiltInsPackageFragment()) { return descriptor?.getName() } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt index 2235fb08fb4..25aa82e5622 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/FunctionCallCases.kt @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.js.translate.callTranslator import com.google.dart.compiler.backend.js.ast.* import com.intellij.util.SmartList -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.Visibilities @@ -33,6 +32,7 @@ import org.jetbrains.kotlin.js.translate.utils.PsiUtils import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.expressions.OperatorConventions import java.util.ArrayList @@ -166,17 +166,18 @@ object NativeSetterCallCase : AnnotatedAsNativeXCallCase(PredefinedAnnotation.NA object InvokeIntrinsic : FunctionCallCase { fun canApply(callInfo: FunctionCallInfo): Boolean { - if (callInfo.callableDescriptor.getName() != OperatorConventions.INVOKE) + val callableDescriptor = callInfo.callableDescriptor + if (callableDescriptor.getName() != OperatorConventions.INVOKE) return false - val parameterCount = callInfo.callableDescriptor.getValueParameters().size() - val funDeclaration = callInfo.callableDescriptor.getContainingDeclaration() + val parameterCount = callableDescriptor.getValueParameters().size() + val funDeclaration = callableDescriptor.getContainingDeclaration() val reflectionTypes = callInfo.context.getReflectionTypes() - return if (callInfo.callableDescriptor.getExtensionReceiverParameter() == null) - funDeclaration == KotlinBuiltIns.getInstance().getFunction(parameterCount) || + return if (callableDescriptor.getExtensionReceiverParameter() == null) + funDeclaration == callableDescriptor.builtIns.getFunction(parameterCount) || funDeclaration == reflectionTypes.getKFunction(parameterCount) else - funDeclaration == KotlinBuiltIns.getInstance().getExtensionFunction(parameterCount) || + funDeclaration == callableDescriptor.builtIns.getExtensionFunction(parameterCount) || funDeclaration == reflectionTypes.getKExtensionFunction(parameterCount) || funDeclaration == reflectionTypes.getKMemberFunction(parameterCount) } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/JsDataClassGenerator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/JsDataClassGenerator.java index 49c240fa525..8cee01b3594 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/JsDataClassGenerator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/JsDataClassGenerator.java @@ -30,6 +30,9 @@ import org.jetbrains.kotlin.psi.JetParameter; import java.util.ArrayList; import java.util.List; +import static kotlin.KotlinPackage.first; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; + class JsDataClassGenerator extends DataClassMethodGenerator { private final TranslationContext context; private final List output; @@ -90,7 +93,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator { public void generateToStringMethod(@NotNull List classProperties) { // TODO: relax this limitation, with the data generation logic fixed. assert !classProperties.isEmpty(); - FunctionDescriptor prototypeFun = CodegenUtil.getAnyToStringMethod(); + FunctionDescriptor prototypeFun = CodegenUtil.getAnyToStringMethod(getBuiltIns(first(classProperties))); JsFunction functionObj = generateJsMethod(prototypeFun); JsProgram jsProgram = context.program(); @@ -115,7 +118,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator { @Override public void generateHashCodeMethod(@NotNull List classProperties) { - FunctionDescriptor prototypeFun = CodegenUtil.getAnyHashCodeMethod(); + FunctionDescriptor prototypeFun = CodegenUtil.getAnyHashCodeMethod(getBuiltIns(first(classProperties))); JsFunction functionObj = generateJsMethod(prototypeFun); JsProgram jsProgram = context.program(); @@ -142,7 +145,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator { @Override public void generateEqualsMethod(@NotNull List classProperties) { assert !classProperties.isEmpty(); - FunctionDescriptor prototypeFun = CodegenUtil.getAnyEqualsMethod(); + FunctionDescriptor prototypeFun = CodegenUtil.getAnyEqualsMethod(getBuiltIns(first(classProperties))); JsFunction functionObj = generateJsMethod(prototypeFun); JsFunctionScope funScope = functionObj.getScope(); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java index 03cafc45b07..16e5d6827f4 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsDescriptorUtils.java @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsPackage; import org.jetbrains.kotlin.js.translate.context.TranslationContext; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.JetExpression; -import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver; @@ -43,11 +42,12 @@ import static org.jetbrains.kotlin.js.config.LibrarySourcesConfig.BUILTINS_JS_MO import static org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isNativeObject; import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration; import static org.jetbrains.kotlin.resolve.DescriptorUtils.*; +import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; public final class JsDescriptorUtils { // TODO: maybe we should use external annotations or something else. private static final Set FAKE_CLASSES = ContainerUtil.immutableSet( - getFqNameSafe(KotlinBuiltIns.getInstance().getAny()).asString() + KotlinBuiltIns.FQ_NAMES.any.asString() ); private JsDescriptorUtils() { @@ -157,7 +157,7 @@ public final class JsDescriptorUtils { public static boolean isBuiltin(@NotNull DeclarationDescriptor descriptor) { PackageFragmentDescriptor containingPackageFragment = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor.class); - return containingPackageFragment == KotlinBuiltIns.getInstance().getBuiltInsPackageFragment(); + return containingPackageFragment == getBuiltIns(descriptor).getBuiltInsPackageFragment(); } @Nullable diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/TranslationUtils.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/TranslationUtils.java index 5dd7384b6b6..7b73d3f8e9a 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/TranslationUtils.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/TranslationUtils.java @@ -215,8 +215,7 @@ public final class TranslationUtils { if (operationDescriptor == null || !(operationDescriptor instanceof FunctionDescriptor)) return true; JetType returnType = operationDescriptor.getReturnType(); - if (returnType != null && - KotlinBuiltIns.getInstance().getCharType().equals(returnType) || (KotlinBuiltIns.getInstance().getLongType().equals(returnType))) return false; + if (returnType != null && (KotlinBuiltIns.isChar(returnType) || KotlinBuiltIns.isLong(returnType))) return false; if (context.intrinsics().getFunctionIntrinsic((FunctionDescriptor) operationDescriptor).exists()) return true;