diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 1120b599aaf..30085f4bec5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -851,7 +851,7 @@ public class ExpressionCodegen extends JetVisitor implem @Override protected void assignToLoopParameter() { Type arrayElParamType; - if (KotlinBuiltIns.getInstance().isArray(loopRangeType)) { + if (KotlinBuiltIns.isArray(loopRangeType)) { arrayElParamType = boxType(asmElementType); } else { @@ -3438,7 +3438,7 @@ public class ExpressionCodegen extends JetVisitor implem args.add(va.getArgumentExpression()); } - boolean isArray = KotlinBuiltIns.getInstance().isArray(arrayType); + boolean isArray = KotlinBuiltIns.isArray(arrayType); if (!isArray && args.size() != 1) { throw new CompilationException("primitive array constructor requires one argument", null, expression); } @@ -3492,7 +3492,7 @@ public class ExpressionCodegen extends JetVisitor implem } public void newArrayInstruction(@NotNull JetType arrayType) { - if (KotlinBuiltIns.getInstance().isArray(arrayType)) { + if (KotlinBuiltIns.isArray(arrayType)) { JetType elementJetType = arrayType.getArguments().get(0).getType(); putReifierMarkerIfTypeIsReifiedParameter( elementJetType, @@ -3519,7 +3519,7 @@ public class ExpressionCodegen extends JetVisitor implem operationDescriptor.getValueParameters().get(0).getType().equals(KotlinBuiltIns.getInstance().getIntType())) { assert type != null; Type elementType; - if (KotlinBuiltIns.getInstance().isArray(type)) { + if (KotlinBuiltIns.isArray(type)) { JetType jetElementType = type.getArguments().get(0).getType(); elementType = boxType(asmType(jetElementType)); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index be45a17e4eb..2698c78e705 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -264,7 +264,7 @@ public class JetTypeMapper { return asmType; } - if (descriptor instanceof ClassDescriptor && KotlinBuiltIns.getInstance().isArray(jetType)) { + if (descriptor instanceof ClassDescriptor && KotlinBuiltIns.isArray(jetType)) { if (jetType.getArguments().size() != 1) { throw new UnsupportedOperationException("arrays must have one type argument"); } @@ -683,11 +683,11 @@ public class JetTypeMapper { */ private static boolean forceBoxedReturnType(@NotNull FunctionDescriptor descriptor) { //noinspection ConstantConditions - if (!KotlinBuiltIns.getInstance().isPrimitiveType(descriptor.getReturnType())) return false; + if (!KotlinBuiltIns.isPrimitiveType(descriptor.getReturnType())) return false; for (FunctionDescriptor overridden : getAllOverriddenDescriptors(descriptor)) { //noinspection ConstantConditions - if (!KotlinBuiltIns.getInstance().isPrimitiveType(overridden.getOriginal().getReturnType())) return true; + if (!KotlinBuiltIns.isPrimitiveType(overridden.getOriginal().getReturnType())) return true; } return false; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagationData.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagationData.java index b0d7f65b229..55286aaa56f 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagationData.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/SignaturesPropagationData.java @@ -373,7 +373,7 @@ public class SignaturesPropagationData { assert isArrayType(originalType); - if (builtIns.isPrimitiveArray(originalType)) { + if (KotlinBuiltIns.isPrimitiveArray(originalType)) { // replace IntArray? with IntArray return new VarargCheckResult(TypeUtils.makeNotNullable(originalType), true); } @@ -387,7 +387,7 @@ public class SignaturesPropagationData { assert isArrayType(originalType); - if (builtIns.isPrimitiveArray(originalType)) { + if (KotlinBuiltIns.isPrimitiveArray(originalType)) { // replace IntArray with IntArray? return new VarargCheckResult(TypeUtils.makeNullable(originalType), false); } @@ -682,7 +682,7 @@ public class SignaturesPropagationData { private static boolean isArrayType(@NotNull JetType type) { KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); - return builtIns.isArray(type) || builtIns.isPrimitiveArray(type); + return KotlinBuiltIns.isArray(type) || KotlinBuiltIns.isPrimitiveArray(type); } private static class VarargCheckResult { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt index c53281d01f1..d26a2dd91fa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/evaluate/ConstantExpressionEvaluator.kt @@ -51,7 +51,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet DescriptorUtils.isClassObject(descriptor.getContainingDeclaration()) || DescriptorUtils.isStaticDeclaration(descriptor)) { val returnType = descriptor.getType() - return KotlinBuiltIns.getInstance().isPrimitiveType(returnType) || KotlinBuiltIns.getInstance().getStringType() == returnType + return KotlinBuiltIns.isPrimitiveType(returnType) || KotlinBuiltIns.isString(returnType) } return false } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/CompileTimeConstantUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/CompileTimeConstantUtils.java index 1a8c525a9c3..00c9b579267 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/CompileTimeConstantUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/CompileTimeConstantUtils.java @@ -72,13 +72,13 @@ public class CompileTimeConstantUtils { if (isEnumClass(typeDescriptor) || isAnnotationClass(typeDescriptor) || isJavaLangClass(typeDescriptor) || - builtIns.isPrimitiveArray(parameterType) || - builtIns.isPrimitiveType(parameterType) || + KotlinBuiltIns.isPrimitiveArray(parameterType) || + KotlinBuiltIns.isPrimitiveType(parameterType) || builtIns.getStringType().equals(parameterType)) { return true; } - if (builtIns.isArray(parameterType)) { + if (KotlinBuiltIns.isArray(parameterType)) { List arguments = parameterType.getArguments(); if (arguments.size() == 1) { JetType arrayType = arguments.get(0).getType(); diff --git a/compiler/frontend/src/org/jetbrains/jet/plugin/MainFunctionDetector.java b/compiler/frontend/src/org/jetbrains/jet/plugin/MainFunctionDetector.java index 15c73ec15ea..a3a1783809d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/plugin/MainFunctionDetector.java +++ b/compiler/frontend/src/org/jetbrains/jet/plugin/MainFunctionDetector.java @@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetDeclaration; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.TypeProjection; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; @@ -69,7 +68,7 @@ public class MainFunctionDetector { ValueParameterDescriptor parameter = parameters.get(0); JetType parameterType = parameter.getType(); KotlinBuiltIns kotlinBuiltIns = KotlinBuiltIns.getInstance(); - if (kotlinBuiltIns.isArray(parameterType)) { + if (KotlinBuiltIns.isArray(parameterType)) { List typeArguments = parameterType.getArguments(); if (typeArguments.size() == 1) { JetType typeArgument = typeArguments.get(0).getType(); diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt index 1e5e0621625..1d06c74867b 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/types/LazyJavaTypeResolver.kt @@ -308,7 +308,7 @@ class LazyJavaTypeResolver( // foo(int) and foo(Integer) // if we do not discriminate one of them, any call to foo(kotlin.Int) will result in overload resolution ambiguity // so, for such cases, we discriminate Integer in favour of int - if (!KotlinBuiltIns.getInstance().isPrimitiveType(otherType) || !KotlinBuiltIns.getInstance().isPrimitiveType(lowerBound)) { + if (!KotlinBuiltIns.isPrimitiveType(otherType) || !KotlinBuiltIns.isPrimitiveType(lowerBound)) { return Specificity.Relation.DONT_KNOW } // Int! >< Int? diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 5dc21e35a03..fc8a4a5d8a3 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -410,7 +410,7 @@ public class DescriptorUtils { if (type instanceof LazyType || type.isNullable()) return true; KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance(); - return builtIns.isPrimitiveType(type) || + return KotlinBuiltIns.isPrimitiveType(type) || JetTypeChecker.DEFAULT.equalTypes(builtIns.getStringType(), type) || JetTypeChecker.DEFAULT.equalTypes(builtIns.getNumber().getDefaultType(), type) || JetTypeChecker.DEFAULT.equalTypes(builtIns.getAnyType(), type); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index b465535392f..30b77b9c0e8 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -155,11 +155,24 @@ public class KotlinBuiltIns { public final FqNameUnsafe suppress = fqNameUnsafe("suppress"); public final FqNameUnsafe unit = fqNameUnsafe("Unit"); public final FqNameUnsafe string = fqNameUnsafe("String"); + public final FqNameUnsafe array = fqNameUnsafe("Array"); + public final FqName data = fqName("data"); public final FqName deprecated = fqName("deprecated"); public final FqName tailRecursive = fqName("tailRecursive"); public final FqName noinline = fqName("noinline"); + public final Set primitiveTypes; + public final Set primitiveArrays; + { + primitiveTypes = new HashSet(0); + primitiveArrays = new HashSet(0); + for (PrimitiveType primitiveType : PrimitiveType.values()) { + primitiveTypes.add(fqNameUnsafe(primitiveType.getTypeName().asString())); + primitiveArrays.add(fqNameUnsafe(primitiveType.getArrayTypeName().asString())); + } + } + public final Set functionClasses = computeIndexedFqNames("Function", FUNCTION_TRAIT_COUNT); public final Set extensionFunctionClasses = computeIndexedFqNames("ExtensionFunction", FUNCTION_TRAIT_COUNT); @@ -612,7 +625,7 @@ public class KotlinBuiltIns { @NotNull public JetType getArrayElementType(@NotNull JetType arrayType) { - if (arrayType.getConstructor().getDeclarationDescriptor() == getArray()) { + if (isArray(arrayType)) { if (arrayType.getArguments().size() != 1) { throw new IllegalStateException(); } @@ -725,16 +738,18 @@ public class KotlinBuiltIns { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public boolean isArray(@NotNull JetType type) { - return getArray().equals(type.getConstructor().getDeclarationDescriptor()); + public static boolean isArray(@NotNull JetType type) { + return isConstructedFromGivenClass(type, FQ_NAMES.array); } - public boolean isPrimitiveArray(@NotNull JetType type) { - return jetArrayTypeToPrimitiveJetType.containsKey(TypeUtils.makeNotNullable(type)); + public static boolean isPrimitiveArray(@NotNull JetType type) { + ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); + return descriptor != null && FQ_NAMES.primitiveArrays.contains(DescriptorUtils.getFqName(descriptor)); } - public boolean isPrimitiveType(@NotNull JetType type) { - return primitiveJetTypeToJetArrayType.containsKey(type); + public static boolean isPrimitiveType(@NotNull JetType type) { + ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); + return !type.isNullable() && descriptor != null && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor)); } // Functions diff --git a/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt b/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt index 8c9e14ee4ae..7c0b29e5f65 100644 --- a/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt +++ b/generators/src/org/jetbrains/jet/generators/evaluate/GenerateOperationsMap.kt @@ -51,7 +51,7 @@ fun generate(): String { val builtIns = KotlinBuiltIns.getInstance() [suppress("UNCHECKED_CAST")] val allPrimitiveTypes = builtIns.getBuiltInsPackageScope().getDescriptors() - .filter { it is ClassDescriptor && builtIns.isPrimitiveType(it.getDefaultType()) } as List + .filter { it is ClassDescriptor && KotlinBuiltIns.isPrimitiveType(it.getDefaultType()) } as List for (descriptor in allPrimitiveTypes + builtIns.getString()) { [suppress("UNCHECKED_CAST")] diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt index d473c8967aa..b4d8aafaa9b 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ReplaceWithOperatorAssignIntention.kt @@ -44,7 +44,7 @@ public class ReplaceWithOperatorAssignIntention : JetSelfTargetingIntention {