diff --git a/compiler/testData/diagnostics/testsWithStdLib/kotlinSignature/parameterNames.txt b/compiler/testData/diagnostics/testsWithStdLib/kotlinSignature/parameterNames.txt index 139f69b141e..c5884ed9b62 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/kotlinSignature/parameterNames.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/kotlinSignature/parameterNames.txt @@ -4,7 +4,7 @@ public/*package*/ /*synthesized*/ fun A(/*0*/ function: (kotlin.String) -> kotli public/*package*/ trait A { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public abstract fun foo(/*0*/ kotlinSignatureName: kotlin.String): kotlin.Unit + public abstract fun foo(/*0*/ kotlinSignatureName: kotlin.String!): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/InheritNullability.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/InheritNullability.txt index cb7313889bb..554a062984d 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/InheritNullability.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/InheritNullability.txt @@ -9,6 +9,6 @@ public trait InheritNullability { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(/*0*/ p0: kotlin.String!): kotlin.Unit + public abstract fun foo(/*0*/ org.jetbrains.annotations.NotNull() p0: kotlin.String!): kotlin.Unit } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/Kt3302.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/Kt3302.txt index f5a575f50cc..df35251adf1 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/Kt3302.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/Kt3302.txt @@ -4,7 +4,7 @@ public trait Kt3302 { public trait BSONObject { public abstract fun dummy(): kotlin.Unit - public abstract fun put(/*0*/ p0: kotlin.String!, /*1*/ p1: kotlin.Any!): kotlin.Any! + public abstract fun put(/*0*/ org.jetbrains.annotations.NotNull() p0: kotlin.String!, /*1*/ org.jetbrains.annotations.NotNull() p1: kotlin.Any!): kotlin.Any! } public trait BasicBSONObject : test.Kt3302.LinkedHashMap, test.Kt3302.BSONObject { diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NotNullToNullable.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NotNullToNullable.txt index 6ceeedeaca1..5ba26e4b454 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NotNullToNullable.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NotNullToNullable.txt @@ -9,6 +9,6 @@ public trait NotNullToNullable { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(/*0*/ p0: kotlin.String!): kotlin.Unit + public abstract fun foo(/*0*/ org.jetbrains.annotations.NotNull() p0: kotlin.String!): kotlin.Unit } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NullableToNotNull.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NullableToNotNull.txt index 49cbcd212a0..439d29941f9 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NullableToNotNull.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/NullableToNotNull.txt @@ -4,7 +4,7 @@ public trait NullableToNotNull { public trait Sub : test.NullableToNotNull.Super { public abstract override /*1*/ /*fake_override*/ fun dummy(): kotlin.Unit - public abstract override /*1*/ fun foo(/*0*/ p0: kotlin.String!): kotlin.Unit + public abstract override /*1*/ fun foo(/*0*/ org.jetbrains.annotations.NotNull() p0: kotlin.String!): kotlin.Unit } public trait Super { diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/SubclassFromGenericAndNot.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/SubclassFromGenericAndNot.txt index 3263a94fd4a..74d5e41db19 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/SubclassFromGenericAndNot.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/parameter/SubclassFromGenericAndNot.txt @@ -9,7 +9,7 @@ public trait SubclassFromGenericAndNot { public trait NonGeneric { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(/*0*/ p0: kotlin.String!): kotlin.Unit + public abstract fun foo(/*0*/ org.jetbrains.annotations.NotNull() p0: kotlin.String!): kotlin.Unit } public trait Sub : test.SubclassFromGenericAndNot.NonGeneric, test.SubclassFromGenericAndNot.Generic { diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullJavaSubtype.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullJavaSubtype.txt index 96601c107c5..992f1bacad8 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullJavaSubtype.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullJavaSubtype.txt @@ -4,7 +4,7 @@ public trait AddNotNullJavaSubtype { public trait Sub : test.AddNotNullJavaSubtype.Super { public abstract override /*1*/ /*fake_override*/ fun dummy(): kotlin.Unit - public abstract override /*1*/ fun foo(): kotlin.String! + org.jetbrains.annotations.NotNull() public abstract override /*1*/ fun foo(): kotlin.String! } public trait Super { diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullSameJavaType.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullSameJavaType.txt index 8ea0bc7028c..6e788437d87 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullSameJavaType.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNotNullSameJavaType.txt @@ -4,7 +4,7 @@ public trait AddNotNullSameJavaType { public trait Sub : test.AddNotNullSameJavaType.Super { public abstract override /*1*/ /*fake_override*/ fun dummy(): kotlin.Unit - public abstract override /*1*/ fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract override /*1*/ fun foo(): kotlin.CharSequence! } public trait Super { diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilityJavaSubtype.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilityJavaSubtype.txt index 15522438fdc..bb442611513 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilityJavaSubtype.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilityJavaSubtype.txt @@ -9,6 +9,6 @@ public trait AddNullabilityJavaSubtype { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.CharSequence! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilitySameJavaType.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilitySameJavaType.txt index 292920194a3..43d0a86e1a4 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilitySameJavaType.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/AddNullabilitySameJavaType.txt @@ -9,6 +9,6 @@ public trait AddNullabilitySameJavaType { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.CharSequence! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilityJavaSubtype.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilityJavaSubtype.txt index 3fcbf5a0af5..d691e724910 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilityJavaSubtype.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilityJavaSubtype.txt @@ -9,6 +9,6 @@ public trait InheritNullabilityJavaSubtype { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.CharSequence! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilitySameJavaType.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilitySameJavaType.txt index 76bf2bada04..18e5aeaf07b 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilitySameJavaType.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/InheritNullabilitySameJavaType.txt @@ -9,6 +9,6 @@ public trait InheritNullabilitySameJavaType { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.CharSequence! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnJavaSubtype.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnJavaSubtype.txt index 85075fdd9e1..954e7733553 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnJavaSubtype.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnJavaSubtype.txt @@ -14,6 +14,6 @@ public trait TwoSuperclassesReturnJavaSubtype { public trait Super2 { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.CharSequence! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnSameJavaType.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnSameJavaType.txt index 368946f6d20..caffc98defc 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnSameJavaType.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TwoSuperclassesReturnSameJavaType.txt @@ -14,6 +14,6 @@ public trait TwoSuperclassesReturnSameJavaType { public trait Super2 { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): kotlin.CharSequence! + org.jetbrains.annotations.NotNull() public abstract fun foo(): kotlin.CharSequence! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClass.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClass.txt index 0f787dc2fbf..c426c442b64 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClass.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClass.txt @@ -9,6 +9,6 @@ public trait TypeParamOfClass { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): T! + org.jetbrains.annotations.NotNull() public abstract fun foo(): T! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClassSubstituted.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClassSubstituted.txt index 0de1a7cba04..5e253a724b6 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClassSubstituted.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfClassSubstituted.txt @@ -9,6 +9,6 @@ public trait TypeParamOfClassSubstituted { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): T! + org.jetbrains.annotations.NotNull() public abstract fun foo(): T! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfFun.txt b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfFun.txt index 93af7f3b49d..6d53271ab54 100644 --- a/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfFun.txt +++ b/compiler/testData/loadJava/compiledJava/kotlinSignature/propagation/return/TypeParamOfFun.txt @@ -9,6 +9,6 @@ public trait TypeParamOfFun { public trait Super { public abstract fun dummy(): kotlin.Unit - public abstract fun foo(): T! + org.jetbrains.annotations.NotNull() public abstract fun foo(): T! } } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt b/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt index 7f81c6a2ba3..c908f229632 100644 --- a/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt +++ b/compiler/testData/loadJava/compiledJava/modality/ModalityOfFakeOverrides.txt @@ -10,7 +10,7 @@ public open class ModalityOfFakeOverrides : java.util.AbstractList): kotlin.Boolean - public open override /*1*/ fun get(/*0*/ index: kotlin.Int): kotlin.String! + org.jetbrains.annotations.NotNull() public open override /*1*/ fun get(/*0*/ index: kotlin.Int): kotlin.String! public open override /*1*/ /*fake_override*/ fun indexOf(/*0*/ o: kotlin.Any!): kotlin.Int public open override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun iterator(): kotlin.(Mutable)Iterator! diff --git a/compiler/testData/loadJava/compiledJava/mutability/LoadIterableWithNullability.txt b/compiler/testData/loadJava/compiledJava/mutability/LoadIterableWithNullability.txt index 6e2b4e22c1c..7819f7052b8 100644 --- a/compiler/testData/loadJava/compiledJava/mutability/LoadIterableWithNullability.txt +++ b/compiler/testData/loadJava/compiledJava/mutability/LoadIterableWithNullability.txt @@ -1,8 +1,8 @@ package test public trait LoadIterableWithNullability { - org.jetbrains.annotations.Mutable() public abstract fun getIterable(): kotlin.(Mutable)Iterable! - org.jetbrains.annotations.ReadOnly() public abstract fun getReadOnlyIterable(): kotlin.(Mutable)Iterable! - public abstract fun setIterable(/*0*/ org.jetbrains.annotations.Mutable() p0: kotlin.(Mutable)Iterable!): kotlin.Unit - public abstract fun setReadOnlyIterable(/*0*/ org.jetbrains.annotations.ReadOnly() p0: kotlin.(Mutable)Iterable!): kotlin.Unit + org.jetbrains.annotations.NotNull() org.jetbrains.annotations.Mutable() public abstract fun getIterable(): kotlin.(Mutable)Iterable! + org.jetbrains.annotations.NotNull() org.jetbrains.annotations.ReadOnly() public abstract fun getReadOnlyIterable(): kotlin.(Mutable)Iterable! + public abstract fun setIterable(/*0*/ org.jetbrains.annotations.Mutable() org.jetbrains.annotations.NotNull() p0: kotlin.(Mutable)Iterable!): kotlin.Unit + public abstract fun setReadOnlyIterable(/*0*/ org.jetbrains.annotations.ReadOnly() org.jetbrains.annotations.NotNull() p0: kotlin.(Mutable)Iterable!): kotlin.Unit } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/notNull/NotNullField.txt b/compiler/testData/loadJava/compiledJava/notNull/NotNullField.txt index 74cde22aa6e..3dd0fd24e50 100644 --- a/compiler/testData/loadJava/compiledJava/notNull/NotNullField.txt +++ b/compiler/testData/loadJava/compiledJava/notNull/NotNullField.txt @@ -2,5 +2,5 @@ package test public open class NotNullField { public constructor NotNullField() - public final var hi: kotlin.String! + org.jetbrains.annotations.NotNull() public final var hi: kotlin.String! } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/notNull/NotNullIntArray.txt b/compiler/testData/loadJava/compiledJava/notNull/NotNullIntArray.txt index a2d07e4d2ab..483d55d69c3 100644 --- a/compiler/testData/loadJava/compiledJava/notNull/NotNullIntArray.txt +++ b/compiler/testData/loadJava/compiledJava/notNull/NotNullIntArray.txt @@ -2,5 +2,5 @@ package test public open class NotNullIntArray { public constructor NotNullIntArray() - public open fun hi(): kotlin.IntArray! + org.jetbrains.annotations.NotNull() public open fun hi(): kotlin.IntArray! } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/notNull/NotNullMethod.txt b/compiler/testData/loadJava/compiledJava/notNull/NotNullMethod.txt index 60bea54eb8b..6eabff82036 100644 --- a/compiler/testData/loadJava/compiledJava/notNull/NotNullMethod.txt +++ b/compiler/testData/loadJava/compiledJava/notNull/NotNullMethod.txt @@ -2,5 +2,5 @@ package test public open class NotNullMethod { public constructor NotNullMethod() - public open fun hi(): kotlin.String! + org.jetbrains.annotations.NotNull() public open fun hi(): kotlin.String! } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/notNull/NotNullObjectArray.txt b/compiler/testData/loadJava/compiledJava/notNull/NotNullObjectArray.txt index 1cfe99e7f3a..4876cf001f6 100644 --- a/compiler/testData/loadJava/compiledJava/notNull/NotNullObjectArray.txt +++ b/compiler/testData/loadJava/compiledJava/notNull/NotNullObjectArray.txt @@ -2,5 +2,5 @@ package test public open class NotNullObjectArray { public constructor NotNullObjectArray() - public open fun hi(): kotlin.Array<(out) kotlin.Any!>! + org.jetbrains.annotations.NotNull() public open fun hi(): kotlin.Array<(out) kotlin.Any!>! } \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledJava/notNull/NotNullParameter.txt b/compiler/testData/loadJava/compiledJava/notNull/NotNullParameter.txt index b88bdda26a3..f27e3b1f14b 100644 --- a/compiler/testData/loadJava/compiledJava/notNull/NotNullParameter.txt +++ b/compiler/testData/loadJava/compiledJava/notNull/NotNullParameter.txt @@ -2,5 +2,5 @@ package test public open class NotNullParameter { public constructor NotNullParameter() - public open fun hi(/*0*/ p0: kotlin.String!): kotlin.Unit + public open fun hi(/*0*/ org.jetbrains.annotations.NotNull() p0: kotlin.String!): kotlin.Unit } \ No newline at end of file diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAnnotationNames.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAnnotationNames.java index 7942442f8e3..59ce7e14dc6 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAnnotationNames.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/JvmAnnotationNames.java @@ -98,17 +98,23 @@ public final class JvmAnnotationNames { public static final FqName OLD_KOTLIN_TRAIT_IMPL = new FqName("jet.KotlinTraitImpl"); private static final Set SPECIAL_ANNOTATIONS = new HashSet(); + private static final Set NULLABILITY_ANNOTATIONS = new HashSet(); static { - for (FqName fqName : Arrays.asList(KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SIGNATURE, JETBRAINS_NOT_NULL_ANNOTATION, - JETBRAINS_NULLABLE_ANNOTATION)) { + for (FqName fqName : Arrays.asList(KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SIGNATURE)) { SPECIAL_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName)); } SPECIAL_ANNOTATIONS.add(KotlinSyntheticClass.CLASS_NAME); + + for (FqName fqName : Arrays.asList(JETBRAINS_NOT_NULL_ANNOTATION, JETBRAINS_NULLABLE_ANNOTATION)) { + NULLABILITY_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName)); + } } - public static boolean isSpecialAnnotation(@NotNull ClassId classId) { + public static boolean isSpecialAnnotation(@NotNull ClassId classId, boolean javaSpecificAnnotationsAreSpecial) { JvmClassName className = JvmClassName.byClassId(classId); - return SPECIAL_ANNOTATIONS.contains(className) || className.getInternalName().startsWith("jet/runtime/typeinfo/"); + return (javaSpecificAnnotationsAreSpecial && NULLABILITY_ANNOTATIONS.contains(className)) + || SPECIAL_ANNOTATIONS.contains(className) + || className.getInternalName().startsWith("jet/runtime/typeinfo/"); } private JvmAnnotationNames() { diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/annotationUtils.kt b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/annotationUtils.kt index 0da8303a0a5..182b0d3f34b 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/annotationUtils.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/annotationUtils.kt @@ -24,14 +24,18 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.resolveAnnotation -class LazyJavaAnnotations(c: LazyJavaResolverContextWithTypes, val annotationOwner: JavaAnnotationOwner) : Annotations { +class LazyJavaAnnotations( + c: LazyJavaResolverContextWithTypes, + val annotationOwner: JavaAnnotationOwner, + private val extraLookup: (FqName) -> JavaAnnotation? = { null } +) : Annotations { private val annotationDescriptors = c.storageManager.createMemoizedFunctionWithNullableValues { (annotation: JavaAnnotation) -> c.resolveAnnotation(annotation) } override fun findAnnotation(fqName: FqName): AnnotationDescriptor? { - val jAnnotation = annotationOwner.findAnnotation(fqName) + val jAnnotation = annotationOwner.findAnnotation(fqName) ?: extraLookup(fqName) if (jAnnotation == null) return null return annotationDescriptors(jAnnotation) @@ -45,7 +49,7 @@ class LazyJavaAnnotations(c: LazyJavaResolverContextWithTypes, val annotationOwn } fun LazyJavaResolverContextWithTypes.resolveAnnotations(annotationsOwner: JavaAnnotationOwner): Annotations - = LazyJavaAnnotations(this, annotationsOwner) + = LazyJavaAnnotations(this, annotationsOwner) { fqName -> externalAnnotationResolver.findExternalAnnotation(annotationsOwner, fqName) } private fun GlobalJavaResolverContext.hasAnnotation(owner: JavaAnnotationOwner, annotationFqName: FqName): Boolean = owner.findAnnotation(annotationFqName) != null || externalAnnotationResolver.findExternalAnnotation(owner, annotationFqName) != null diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt index 87b69e802aa..636cb2695e0 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaAnnotationDescriptor.kt @@ -37,6 +37,7 @@ import org.jetbrains.jet.renderer.DescriptorRenderer import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap import org.jetbrains.jet.lang.resolve.resolveTopLevelClass import org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.kotlinFqNameToJavaFqName +import org.jetbrains.jet.lang.resolve.java.PLATFORM_TYPES private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument { override val name: Name? = null @@ -45,7 +46,7 @@ private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument { fun LazyJavaResolverContextWithTypes.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? { val classId = annotation.getClassId() - if (classId == null || JvmAnnotationNames.isSpecialAnnotation(classId)) return null + if (classId == null || JvmAnnotationNames.isSpecialAnnotation(classId, !PLATFORM_TYPES)) return null return LazyJavaAnnotationDescriptor(this, annotation) } diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaMemberScope.kt b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaMemberScope.kt index 750a4887733..a2540405f17 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaMemberScope.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/lazy/descriptors/LazyJavaMemberScope.kt @@ -34,8 +34,6 @@ import org.jetbrains.jet.lang.types.TypeUtils import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.resolve.java.lazy.hasNotNullAnnotation import org.jetbrains.jet.lang.resolve.java.lazy.types.LazyJavaTypeAttributes -import org.jetbrains.jet.lang.resolve.java.lazy.hasMutableAnnotation -import org.jetbrains.jet.lang.resolve.java.lazy.hasReadOnlyAnnotation import org.jetbrains.jet.lang.resolve.java.structure.JavaValueParameter import java.util.ArrayList import java.util.LinkedHashSet @@ -46,7 +44,7 @@ import org.jetbrains.jet.lang.resolve.java.resolver.ExternalSignatureResolver import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils import org.jetbrains.jet.utils.* import org.jetbrains.jet.lang.resolve.java.PLATFORM_TYPES -import org.jetbrains.jet.lang.types.lowerIfFlexible +import org.jetbrains.jet.lang.descriptors.annotations.Annotations public abstract class LazyJavaMemberScope( protected val c: LazyJavaResolverContextWithTypes, @@ -116,8 +114,9 @@ public abstract class LazyJavaMemberScope( fun resolveMethodToFunctionDescriptor(method: JavaMethod, record: Boolean = true): JavaMethodDescriptor { + val annotations = c.resolveAnnotations(method) val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod( - _containingDeclaration, c.resolveAnnotations(method), method.getName(), c.sourceElementFactory.source(method) + _containingDeclaration, annotations, method.getName(), c.sourceElementFactory.source(method) ) val c = c.child(functionDescriptorImpl, method.getTypeParameters().toSet()) @@ -126,13 +125,7 @@ public abstract class LazyJavaMemberScope( val valueParameters = resolveValueParameters(c, functionDescriptorImpl, method.getValueParameters()) val annotationMethod = method.getContainingClass().isAnnotationType() - val returnTypeAttrs = LazyJavaTypeAttributes(c, method, TypeUsage.MEMBER_SIGNATURE_COVARIANT, allowFlexible = !annotationMethod) { - if (c.hasReadOnlyAnnotation(method) && !c.hasMutableAnnotation(method)) - TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT - else - TypeUsage.MEMBER_SIGNATURE_COVARIANT - } - + val returnTypeAttrs = LazyJavaTypeAttributes(c, method, TypeUsage.MEMBER_SIGNATURE_COVARIANT, annotations, allowFlexible = !annotationMethod) val returnJavaType = method.getReturnType() ?: throw IllegalStateException("Constructor passed as method: $method") // Annotation arguments are never null in Java val returnType = c.typeResolver.transformJavaType(returnJavaType, returnTypeAttrs).let { @@ -174,10 +167,8 @@ public abstract class LazyJavaMemberScope( pair -> val (index, javaParameter) = pair - val typeUsage = LazyJavaTypeAttributes(c, javaParameter, TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT) { - if (c.hasMutableAnnotation(javaParameter)) TypeUsage.MEMBER_SIGNATURE_COVARIANT else TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT - } - + val annotations = c.resolveAnnotations(javaParameter) + val typeUsage = LazyJavaTypeAttributes(c, javaParameter, TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT, annotations) val (outType, varargElementType) = if (javaParameter.isVararg()) { val paramType = javaParameter.getType() @@ -213,7 +204,7 @@ public abstract class LazyJavaMemberScope( function, null, index, - c.resolveAnnotations(javaParameter), + annotations, name, outType, false, @@ -254,7 +245,7 @@ public abstract class LazyJavaMemberScope( val propertyDescriptor = createPropertyDescriptor(field) propertyDescriptor.initialize(null, null) - val propertyType = getPropertyType(field) + val propertyType = getPropertyType(field, propertyDescriptor.getAnnotations()) val effectiveSignature = c.externalSignatureResolver.resolveAlternativeFieldSignature(field, propertyType, isVar) val signatureErrors = effectiveSignature.getErrors() if (!signatureErrors.isEmpty()) { @@ -285,7 +276,7 @@ public abstract class LazyJavaMemberScope( c.sourceElementFactory.source(field)) } - private fun getPropertyType(field: JavaField): JetType { + private fun getPropertyType(field: JavaField, annotations: Annotations): JetType { // Fields do not have their own generic parameters val finalStatic = field.isFinal() && field.isStatic() @@ -293,7 +284,7 @@ public abstract class LazyJavaMemberScope( val allowFlexible = PLATFORM_TYPES && !(finalStatic && c.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field)) val propertyType = c.typeResolver.transformJavaType( field.getType(), - LazyJavaTypeAttributes(c, field, TypeUsage.MEMBER_SIGNATURE_INVARIANT, allowFlexible) + LazyJavaTypeAttributes(c, field, TypeUsage.MEMBER_SIGNATURE_INVARIANT, annotations, allowFlexible) ) if ((!allowFlexible || !PLATFORM_TYPES) && finalStatic) { return TypeUtils.makeNotNullable(propertyType) 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 a719bf42b88..cb4738618df 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 @@ -33,6 +33,10 @@ import java.util.HashSet import org.jetbrains.jet.lang.types.checker.JetTypeChecker import org.jetbrains.jet.lang.resolve.java.PLATFORM_TYPES import org.jetbrains.jet.lang.resolve.java.lazy.types.Flexibility.* +import org.jetbrains.jet.lang.descriptors.annotations.Annotations +import org.jetbrains.jet.lang.resolve.name.FqName +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames class LazyJavaTypeResolver( private val c: LazyJavaResolverContext, @@ -262,6 +266,8 @@ class LazyJavaTypeResolver( } } override fun isNullable(): Boolean = _nullable() + + override fun getAnnotations() = attr.annotations } public open class FlexibleJavaClassifierType protected ( @@ -312,6 +318,7 @@ trait JavaTypeAttributes { get() = INFLEXIBLE val allowFlexible: Boolean get() = true + val annotations: Annotations } fun JavaTypeAttributes.isFlexible() = flexibility != INFLEXIBLE @@ -326,23 +333,32 @@ class LazyJavaTypeAttributes( c: LazyJavaResolverContext, val annotationOwner: JavaAnnotationOwner, override val howThisTypeIsUsed: TypeUsage, - override val allowFlexible: Boolean = true, - computeHowThisTypeIsUsedAccordingToAnnotations: () -> TypeUsage = {howThisTypeIsUsed} + override val annotations: Annotations, + override val allowFlexible: Boolean = true ): JavaTypeAttributes { - override val howThisTypeIsUsedAccordingToAnnotations: TypeUsage by c.storageManager.createLazyValue( - computeHowThisTypeIsUsedAccordingToAnnotations - ) + override val howThisTypeIsUsedAccordingToAnnotations: TypeUsage by c.storageManager.createLazyValue { + if (annotations.isMarkedReadOnly() && !annotations.isMarkedMutable()) + TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT + else + TypeUsage.MEMBER_SIGNATURE_COVARIANT + } override val isMarkedNotNull: Boolean by c.storageManager.createLazyValue { c.hasNotNullAnnotation(annotationOwner) } } +private fun Annotations.isMarkedReadOnly() = findAnnotation(JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION) != null +private fun Annotations.isMarkedMutable() = findAnnotation(JvmAnnotationNames.JETBRAINS_MUTABLE_ANNOTATION) != null +private fun Annotations.isMarkedNotNull() = findAnnotation(JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION) != null + fun TypeUsage.toAttributes(allowFlexible: Boolean = true) = object : JavaTypeAttributes { override val howThisTypeIsUsed: TypeUsage = this@toAttributes override val howThisTypeIsUsedAccordingToAnnotations: TypeUsage get() = howThisTypeIsUsed override val isMarkedNotNull: Boolean = false override val allowFlexible: Boolean = allowFlexible + + override val annotations: Annotations = Annotations.EMPTY } fun JavaTypeAttributes.toFlexible(flexibility: Flexibility) = diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorLoader.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorLoader.java index 963db740e24..5332f1dffef 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorLoader.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/kotlin/AnnotationDescriptorLoader.java @@ -119,7 +119,7 @@ public class AnnotationDescriptorLoader extends BaseDescriptorLoader implements @NotNull final List result, @NotNull final ModuleDescriptor moduleDescriptor ) { - if (JvmAnnotationNames.isSpecialAnnotation(classId)) return null; + if (JvmAnnotationNames.isSpecialAnnotation(classId, true)) return null; final ClassDescriptor annotationClass = resolveClass(classId, moduleDescriptor); diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java index da8de39f60d..fc3075a767a 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java @@ -42,6 +42,7 @@ import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.plugin.JetBundle; import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; import org.jetbrains.jet.plugin.codeInsight.ShortenReferences; +import org.jetbrains.jet.plugin.util.UtilPackage; import org.jetbrains.jet.renderer.DescriptorRenderer; import java.util.ArrayList; @@ -172,12 +173,12 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { ) { @Override protected String getLookupString(JetType element) { - return DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(element); + return DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(UtilPackage.approximateFlexibleTypes(element, true)); } @Override protected String getResult(JetType element) { - return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(element); + return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(UtilPackage.approximateFlexibleTypes(element, true)); } }; diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java b/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java index 72051307a17..8346cd24896 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/inline/KotlinInlineValHandler.java @@ -63,6 +63,7 @@ import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage; import org.jetbrains.jet.plugin.codeInsight.ShortenReferences; import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; import org.jetbrains.jet.plugin.project.ResolveSessionForBodies; +import org.jetbrains.jet.plugin.util.UtilPackage; import org.jetbrains.jet.renderer.DescriptorRenderer; import java.util.List; @@ -356,7 +357,7 @@ public class KotlinInlineValHandler extends InlineActionHandler { return StringUtil.join(typeArguments, new Function() { @Override public String fun(JetType type) { - return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(type); + return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(UtilPackage.approximateFlexibleTypes(type, true)); } }, ", "); } diff --git a/idea/src/org/jetbrains/jet/plugin/util/TypeUtils.kt b/idea/src/org/jetbrains/jet/plugin/util/TypeUtils.kt index d4403cde7d8..4f161b0f4c8 100644 --- a/idea/src/org/jetbrains/jet/plugin/util/TypeUtils.kt +++ b/idea/src/org/jetbrains/jet/plugin/util/TypeUtils.kt @@ -19,10 +19,45 @@ package org.jetbrains.jet.plugin.util import org.jetbrains.jet.lang.types.JetType import org.jetbrains.jet.lang.types.TypeUtils import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns +import org.jetbrains.jet.lang.types.JetTypeImpl +import org.jetbrains.jet.lang.types.TypeProjectionImpl +import org.jetbrains.jet.lang.types.ErrorUtils +import org.jetbrains.jet.lang.resolve.java.kotlinSignature.CollectionClassMapping +import org.jetbrains.jet.lang.descriptors.ClassDescriptor +import org.jetbrains.jet.lang.types.FlexibleType +import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames fun JetType.makeNullable() = TypeUtils.makeNullable(this) fun JetType.makeNotNullable() = TypeUtils.makeNotNullable(this) fun JetType.supertypes(): Set = TypeUtils.getAllSupertypes(this) -fun JetType.isUnit(): Boolean = KotlinBuiltIns.getInstance().isUnit(this) \ No newline at end of file +fun JetType.isUnit(): Boolean = KotlinBuiltIns.getInstance().isUnit(this) + +public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true): JetType { + if (jetType is FlexibleType) { + val lowerClass = jetType.lowerBound.getConstructor().getDeclarationDescriptor() as? ClassDescriptor? + val isCollection = lowerClass != null && CollectionClassMapping.getInstance().isMutableCollection(lowerClass) + // (Mutable)Collection! -> MutableCollection? + // Foo<(Mutable)Collection!>! -> Foo>? + // Foo! -> Foo? + // Foo! -> Foo? + val approximation = + if (isCollection) + TypeUtils.makeNullableAsSpecified(if (jetType.isMarkedReadOnly()) jetType.upperBound else jetType.lowerBound, outermost) + else + if (outermost) jetType.upperBound else jetType.lowerBound + val approximated = approximateFlexibleTypes(approximation) + return if (jetType.isMarkedNotNull()) approximated.makeNotNullable() else approximated + } + return JetTypeImpl( + jetType.getAnnotations(), + jetType.getConstructor(), + jetType.isNullable(), + jetType.getArguments().map { TypeProjectionImpl(it.getProjectionKind(), approximateFlexibleTypes(it.getType(), false)) }, + ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true) + ) +} + +private fun JetType.isMarkedReadOnly() = getAnnotations().findAnnotation(JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION) != null +private fun JetType.isMarkedNotNull() = getAnnotations().findAnnotation(JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION) != null