diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt index 097ed4e5f1d..8c45cf0a20c 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt @@ -137,7 +137,7 @@ fun StorageComponentContainer.configureJavaSpecificComponents( JavaResolverSettings.create( isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines), correctNullabilityForNotNullTypeParameter = languageVersionSettings.supportsFeature(LanguageFeature.ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated), - enhancementImprovements = languageVersionSettings.supportsFeature(LanguageFeature.ImprovementsAroundTypeEnhancement), + typeEnhancementImprovements = languageVersionSettings.supportsFeature(LanguageFeature.ImprovementsAroundTypeEnhancement) ) ) diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt index 119d42ab717..b474fa1e2bf 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.load.java.structure.impl.classFiles import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaAnnotation.Companion.computeTargetType +import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaAnnotation.Companion.translatePath import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -33,7 +34,9 @@ internal class AnnotationsCollectorFieldVisitor( override fun visitAnnotation(desc: String, visible: Boolean) = BinaryJavaAnnotation.addAnnotation(field, desc, context, signatureParser) - override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, desc: String, visible: Boolean): AnnotationVisitor? { + override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, descriptor: String?, visible: Boolean): AnnotationVisitor? { + if (descriptor == null) return null + val typeReference = TypeReference(typeRef) if (typePath != null) { @@ -42,13 +45,13 @@ internal class AnnotationsCollectorFieldVisitor( when (typeReference.sort) { TypeReference.FIELD -> { val targetType = computeTargetType(field.type, translatedPath) - return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, desc, context, signatureParser) + return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, descriptor, context, signatureParser, true) } } } return when (typeReference.sort) { - TypeReference.FIELD -> BinaryJavaAnnotation.addAnnotation(field.type as JavaPlainType, desc, context, signatureParser) + TypeReference.FIELD -> BinaryJavaAnnotation.addAnnotation(field.type as JavaPlainType, descriptor, context, signatureParser, true) else -> null } } @@ -119,19 +122,23 @@ internal class AnnotationsAndParameterCollectorMethodVisitor( } ?: return null return BinaryJavaAnnotation.addAnnotation( - computeTargetType(baseType, translatePath(typePath)) as JavaPlainType, desc, context, signatureParser + computeTargetType(baseType, translatePath(typePath)) as JavaPlainType, desc, context, signatureParser, true ) } - val targetType = when (typeReference.sort) { - TypeReference.METHOD_RETURN -> (member as? BinaryJavaMethod)?.returnType as JavaPlainType - TypeReference.METHOD_TYPE_PARAMETER -> member.typeParameters[typeReference.typeParameterIndex] as BinaryJavaTypeParameter - TypeReference.METHOD_FORMAL_PARAMETER -> member.valueParameters[typeReference.formalParameterIndex].type as JavaPlainType - TypeReference.METHOD_TYPE_PARAMETER_BOUND -> BinaryJavaAnnotation.computeTypeParameterBound(member.typeParameters, typeReference) as JavaPlainType - else -> null - } ?: return null + val (targetType, isFreshlySupportedAnnotation) = when (typeReference.sort) { + TypeReference.METHOD_RETURN -> + (member as? BinaryJavaMethod)?.returnType as JavaPlainType to false + TypeReference.METHOD_TYPE_PARAMETER -> + member.typeParameters[typeReference.typeParameterIndex] as BinaryJavaTypeParameter to true + TypeReference.METHOD_FORMAL_PARAMETER -> + member.valueParameters[typeReference.formalParameterIndex].type as JavaPlainType to false + TypeReference.METHOD_TYPE_PARAMETER_BOUND -> + BinaryJavaAnnotation.computeTypeParameterBound(member.typeParameters, typeReference) as JavaPlainType to true + else -> return null + } - return BinaryJavaAnnotation.addAnnotation(targetType, desc, context, signatureParser) + return BinaryJavaAnnotation.addAnnotation(targetType, desc, context, signatureParser, isFreshlySupportedAnnotation) } enum class PathElementType { ARRAY_ELEMENT, WILDCARD_BOUND, ENCLOSING_CLASS, TYPE_ARGUMENT } @@ -140,7 +147,8 @@ internal class AnnotationsAndParameterCollectorMethodVisitor( class BinaryJavaAnnotation private constructor( desc: String, private val context: ClassifierResolutionContext, - override val arguments: Collection + override val arguments: Collection, + override val isFreshlySupportedTypeUseAnnotation: Boolean ) : JavaAnnotation { companion object { @@ -148,10 +156,11 @@ class BinaryJavaAnnotation private constructor( fun createAnnotationAndVisitor( desc: String, context: ClassifierResolutionContext, - signatureParser: BinaryClassSignatureParser + signatureParser: BinaryClassSignatureParser, + isFreshlySupportedTypeUseAnnotation: Boolean = false ): Pair { val arguments = mutableListOf() - val annotation = BinaryJavaAnnotation(desc, context, arguments) + val annotation = BinaryJavaAnnotation(desc, context, arguments, isFreshlySupportedTypeUseAnnotation) return annotation to BinaryJavaAnnotationVisitor(context, signatureParser, arguments) } @@ -160,9 +169,11 @@ class BinaryJavaAnnotation private constructor( annotationOwner: MutableJavaAnnotationOwner, desc: String, context: ClassifierResolutionContext, - signatureParser: BinaryClassSignatureParser + signatureParser: BinaryClassSignatureParser, + isFreshlySupportedAnnotation: Boolean = false ): AnnotationVisitor { - val (javaAnnotation, annotationVisitor) = createAnnotationAndVisitor(desc, context, signatureParser) + val (javaAnnotation, annotationVisitor) = + createAnnotationAndVisitor(desc, context, signatureParser, isFreshlySupportedAnnotation) annotationOwner.annotations.add(javaAnnotation) return annotationVisitor } diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt index 9872e5c5d00..35b9f415a26 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryJavaClass.kt @@ -83,10 +83,11 @@ class BinaryJavaClass( override fun isFromSourceCodeInScope(scope: SearchScope): Boolean = false override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, descriptor: String?, visible: Boolean): AnnotationVisitor? { - val typeReference = TypeReference(typeRef) if (descriptor == null) return null + val typeReference = TypeReference(typeRef) + if (typePath != null) { val translatedPath = BinaryJavaAnnotation.translatePath(typePath) diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/ClassifierResolutionContext.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/ClassifierResolutionContext.kt index 67f3593021c..681d135f2bf 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/ClassifierResolutionContext.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/ClassifierResolutionContext.kt @@ -50,11 +50,9 @@ class ClassifierResolutionContext private constructor( internal fun addTypeParameters(newTypeParameters: Collection) { if (newTypeParameters.isEmpty()) return - typeParameters = - newTypeParameters - .fold(typeParameters) { acc, typeParameter -> - acc.put(typeParameter.name.identifier, typeParameter) - } + typeParameters = newTypeParameters.fold(typeParameters) { acc, typeParameter -> + acc.put(typeParameter.name.identifier, typeParameter) + } } private fun resolveClass(classId: ClassId) = Result(classesByQName(classId), classId.asSingleFqName().asString()) @@ -77,7 +75,7 @@ class ClassifierResolutionContext private constructor( // See com.intellij.psi.impl.compiled.StubBuildingVisitor.GUESSING_MAPPER private fun convertNestedClassInternalNameWithSimpleHeuristic(internalName: String): ClassId? { val splitPoints = SmartList() - for (p in 0 until internalName.length) { + for (p in internalName.indices) { val c = internalName[p] if (c == '$' && p > 0 && internalName[p - 1] != '/' && p < internalName.length - 1 && internalName[p + 1] != '$') { splitPoints.add(p) diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.java b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.java new file mode 100644 index 00000000000..5269a0556e3 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.java @@ -0,0 +1,6 @@ +import org.jetbrains.annotations.NotNull; + +public class ClassTypeParameterBound { + ClassTypeParameterBound(T x) { } + ClassTypeParameterBound() { } +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt new file mode 100644 index 00000000000..424a5f7730c --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +ImprovementsAroundTypeEnhancement +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// SKIP_TXT + +fun main(x: ClassTypeParameterBound<String?>, y: ClassTypeParameterBound, a: String?, b: String) { + val x2 = ClassTypeParameterBound<String?>() + val y2 = ClassTypeParameterBound() + + val x3 = ClassTypeParameterBound(a) + val y3 = ClassTypeParameterBound(b) + + val x4: ClassTypeParameterBound<String?> = ClassTypeParameterBound() + val y4: ClassTypeParameterBound = ClassTypeParameterBound() +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.java b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.java new file mode 100644 index 00000000000..74e7708be28 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.java @@ -0,0 +1,6 @@ +import org.jetbrains.annotations.NotNull; + +public class ClassTypeParameterBoundWithWarnings { + ClassTypeParameterBoundWithWarnings() { } + ClassTypeParameterBoundWithWarnings(T x) { } +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt new file mode 100644 index 00000000000..29f07a9f8e4 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// SKIP_TXT + +// TODO: report warnings "UPPER_BOUND_VIOLATED" +fun main(x: ClassTypeParameterBoundWithWarnings, y: ClassTypeParameterBoundWithWarnings, a: String?, b: String) { + val x2 = ClassTypeParameterBoundWithWarnings() + val y2 = ClassTypeParameterBoundWithWarnings() + + val x3 = ClassTypeParameterBoundWithWarnings(a) + val y3 = ClassTypeParameterBoundWithWarnings(b) + + val x4: ClassTypeParameterBoundWithWarnings = ClassTypeParameterBoundWithWarnings() + val y4: ClassTypeParameterBoundWithWarnings = ClassTypeParameterBoundWithWarnings() +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.java b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.java new file mode 100644 index 00000000000..bfe37d1e4f1 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.java @@ -0,0 +1,13 @@ +import org.jetbrains.annotations.*; + +public class ReturnType { + public interface A {} + + public A<@Nullable String, @Nullable T> foo1() { return null; } + public A<@Nullable String, @NotNull T> foo2() { return null; } + public A<@NotNull String, @NotNull T> foo3 = null; + public @NotNull T [] foo4 = null; + public ReturnType<@Nullable String> foo41 = null; + public T foo411 = null; + public @Nullable String [] foo5() { return null; } +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt new file mode 100644 index 00000000000..15e609df195 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +ImprovementsAroundTypeEnhancement +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun takeNotNullStringAndKNullable(x: ReturnType.A) {} +fun takeNullableStringAndKNullable(x: ReturnType.A) {} +fun takeNotNullStringAndNotNullK(x: ReturnType.A) {} +fun takeNullableStringAndNotNullK(x: ReturnType.A) {} +fun takeNotNullString(x: String) {} + +fun takeArrayOfNotNullString(x: Array) {} +fun takeArrayOfNullableString(x: Array) {} +fun takeArrayOfNotNullK(x: Array) {} +fun takeArrayOfNullableK(x: Array) {} + +// FILE: main.kt +fun main(a: ReturnType) { + val x1 = ..ReturnType.A<@org.jetbrains.annotations.Nullable kotlin.String?, @org.jetbrains.annotations.Nullable R?>?)")!>a.foo1() + takeNotNullStringAndKNullable(x1) + takeNullableStringAndKNullable(x1) + takeNotNullStringAndNotNullK(", "ReturnType.A!")!>x1) + takeNullableStringAndNotNullK(x1) + takeNotNullString(a.foo41.foo411) + + val x2 = ..ReturnType.A<@org.jetbrains.annotations.Nullable kotlin.String?, @org.jetbrains.annotations.NotNull R!!>?)")!>a.foo2() + takeNotNullStringAndKNullable(x2) + takeNullableStringAndKNullable(x2) + takeNotNullStringAndNotNullK(", "ReturnType.A!")!>x2) + takeNullableStringAndNotNullK(x2) + + val x3 = ..ReturnType.A<@org.jetbrains.annotations.NotNull kotlin.String, @org.jetbrains.annotations.NotNull R!!>?)")!>a.foo3 + takeNotNullStringAndKNullable(x3) + takeNullableStringAndKNullable(x3) + takeNotNullStringAndNotNullK(x3) + takeNullableStringAndNotNullK(", "ReturnType.A!")!>x3) + + val x4 = ..kotlin.Array?)")!>a.foo4 + takeArrayOfNotNullString(x4) + takeArrayOfNullableString(x4) + takeArrayOfNotNullK(x4) + takeArrayOfNullableK(x4) + + val x5 = ..kotlin.Array?)")!>a.foo5() + takeArrayOfNotNullString(x5) + takeArrayOfNullableString(x5) + takeArrayOfNotNullK(x5) + takeArrayOfNullableK(x5) +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.java b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.java new file mode 100644 index 00000000000..11f6a7d2e1d --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.java @@ -0,0 +1,13 @@ +import org.jetbrains.annotations.*; + +public class ReturnTypeWithWarnings { + public interface A {} + + public A<@Nullable String, @Nullable T> foo1() { return null; } + public A<@Nullable String, @NotNull T> foo2() { return null; } + public A<@NotNull String, @NotNull T> foo3 = null; + public @NotNull T [] foo4 = null; + public ReturnTypeWithWarnings<@Nullable String> foo41 = null; + public T foo411 = null; + public @Nullable String [] foo5() { return null; } +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt new file mode 100644 index 00000000000..85355f00247 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +fun takeNotNullStringAndKNullable(x: ReturnTypeWithWarnings.A) {} +fun takeNullableStringAndKNullable(x: ReturnTypeWithWarnings.A) {} +fun takeNotNullStringAndNotNullK(x: ReturnTypeWithWarnings.A) {} +fun takeNullableStringAndNotNullK(x: ReturnTypeWithWarnings.A) {} +fun takeNotNullString(x: String) {} + +fun takeArrayOfNotNullString(x: Array) {} +fun takeArrayOfNullableString(x: Array) {} +fun takeArrayOfNotNullK(x: Array) {} +fun takeArrayOfNullableK(x: Array) {} + +// FILE: main.kt +fun main(a: ReturnTypeWithWarnings) { + val x1 = ..ReturnTypeWithWarnings.A<(@org.jetbrains.annotations.Nullable kotlin.String..@org.jetbrains.annotations.Nullable kotlin.String?), (@org.jetbrains.annotations.Nullable R..@org.jetbrains.annotations.Nullable R?)>?)")!>a.foo1() + takeNotNullStringAndKNullable(", "ReturnTypeWithWarnings.A!")!>x1) + takeNullableStringAndKNullable(x1) + takeNotNullStringAndNotNullK(", "ReturnTypeWithWarnings.A!"), TYPE_MISMATCH("Any", "R!"), TYPE_MISMATCH("Any", "R!")!>x1) + takeNullableStringAndNotNullK(x1) + takeNotNullString(a.foo41.foo411) + + val x2 = ..ReturnTypeWithWarnings.A<(@org.jetbrains.annotations.Nullable kotlin.String..@org.jetbrains.annotations.Nullable kotlin.String?), (@org.jetbrains.annotations.NotNull R..@org.jetbrains.annotations.NotNull R?)>?)")!>a.foo2() + takeNotNullStringAndKNullable(", "ReturnTypeWithWarnings.A!")!>x2) + takeNullableStringAndKNullable(", "ReturnTypeWithWarnings.A!")!>x2) + takeNotNullStringAndNotNullK(", "ReturnTypeWithWarnings.A!"), TYPE_MISMATCH("Any", "R!"), TYPE_MISMATCH("Any", "R!")!>x2) + takeNullableStringAndNotNullK(x2) + + val x3 = ..ReturnTypeWithWarnings.A<(@org.jetbrains.annotations.NotNull kotlin.String..@org.jetbrains.annotations.NotNull kotlin.String?), (@org.jetbrains.annotations.NotNull R..@org.jetbrains.annotations.NotNull R?)>?)")!>a.foo3 + takeNotNullStringAndKNullable(", "ReturnTypeWithWarnings.A!")!>x3) + takeNullableStringAndKNullable(", "ReturnTypeWithWarnings.A!")!>x3) + takeNotNullStringAndNotNullK(x3) + takeNullableStringAndNotNullK(", "ReturnTypeWithWarnings.A!"), TYPE_MISMATCH("Any", "R!"), TYPE_MISMATCH("Any", "R!")!>x3) + + val x4 = ..kotlin.Array)")!>a.foo4 + takeArrayOfNotNullString(x4) + takeArrayOfNullableString(x4) + takeArrayOfNotNullK(x4) + takeArrayOfNullableK(", "Array<(out) R!!>")!>x4) + + val x5 = ?..kotlin.Array?)")!>a.foo5() + takeArrayOfNotNullString(x5) + takeArrayOfNullableString(x5) + takeArrayOfNotNullK(x5) + takeArrayOfNullableK(x5) +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.java b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.java new file mode 100644 index 00000000000..322ff878d18 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.java @@ -0,0 +1,13 @@ +import org.jetbrains.annotations.*; + +public class ValueParameter { + public interface A {} + + public void foo1(A<@Nullable String, @Nullable T> x) { } + public void foo2(A<@Nullable String, @NotNull T> x) { } + public void foo3(A<@NotNull String, @NotNull T> x) { } + public void foo4(@NotNull T [] x) { } + public void foo41(@Nullable String x) { } + public void foo411(T x) { } + public void foo5(@Nullable String [] x) { } +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt new file mode 100644 index 00000000000..7a7175a9522 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +ImprovementsAroundTypeEnhancement +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS +// SKIP_TXT + +fun getNotNullStringAndKNullable() = null as ValueParameter.A +fun getNullableStringAndKNullable() = null as ValueParameter.A +fun getNotNullStringAndNotNullK() = null as ValueParameter.A +fun getNullableStringAndNotNullK() = null as ValueParameter.A +fun getNotNullString() = null as String + +fun getArrayOfNotNullString() = null as Array +fun getArrayOfNullableString() = null as Array +fun getArrayOfNotNullK() = null as Array +fun getArrayOfNullableK() = null as Array + +// FILE: main.kt +fun main(a: ValueParameter) { + a.foo1(getNotNullStringAndKNullable()) + a.foo1(getNullableStringAndKNullable()) + a.foo1(getNotNullStringAndNotNullK()) + a.foo1(getNullableStringAndNotNullK()) + + a.foo2(getNotNullStringAndKNullable()) + a.foo2(getNullableStringAndKNullable()) + a.foo2(getNotNullStringAndNotNullK()) + a.foo2(getNullableStringAndNotNullK()) + + a.foo3(getNotNullStringAndKNullable()) + a.foo3(getNullableStringAndKNullable()) + a.foo3(getNotNullStringAndNotNullK()) + a.foo3(getNullableStringAndNotNullK()) + + a.foo4(getArrayOfNotNullString()) + a.foo4(getArrayOfNullableString()) + a.foo4(getArrayOfNotNullK()) + a.foo4(getArrayOfNullableK()) + + a.foo5(getArrayOfNotNullString()) + a.foo5(getArrayOfNullableString()) + a.foo5(getArrayOfNotNullK()) + a.foo5(getArrayOfNullableK()) + + a.foo41(getNotNullString()) + a.foo411(getNotNullString()) +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.java b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.java new file mode 100644 index 00000000000..7fd49516069 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.java @@ -0,0 +1,13 @@ +import org.jetbrains.annotations.*; + +public class ValueParameterWithWarnings { + public interface A {} + + public void foo1(A<@Nullable String, @Nullable T> x) { } + public void foo2(A<@Nullable String, @NotNull T> x) { } + public void foo3(A<@NotNull String, @NotNull T> x) { } + public void foo4(@NotNull T [] x) { } + public void foo41(@Nullable String x) { } + public void foo411(T x) { } + public void foo5(@Nullable String [] x) { } +} diff --git a/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt new file mode 100644 index 00000000000..95819ad9598 --- /dev/null +++ b/compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt @@ -0,0 +1,45 @@ +// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS +// SKIP_TXT + +fun getNotNullStringAndKNullable() = null as ValueParameterWithWarnings.A +fun getNullableStringAndKNullable() = null as ValueParameterWithWarnings.A +fun getNotNullStringAndNotNullK() = null as ValueParameterWithWarnings.A +fun getNullableStringAndNotNullK() = null as ValueParameterWithWarnings.A +fun getNotNullString() = null as String + +fun getArrayOfNotNullString() = null as Array +fun getArrayOfNullableString() = null as Array +fun getArrayOfNotNullK() = null as Array +fun getArrayOfNullableK() = null as Array + +// FILE: main.kt +fun main(a: ValueParameterWithWarnings) { + a.foo1(getNotNullStringAndKNullable()) + a.foo1(getNullableStringAndKNullable()) + a.foo1(getNotNullStringAndNotNullK()) + a.foo1(getNullableStringAndNotNullK()) + + a.foo2(getNotNullStringAndKNullable()) + a.foo2(getNullableStringAndKNullable()) + a.foo2(getNotNullStringAndNotNullK()) + a.foo2(getNullableStringAndNotNullK()) + + a.foo3(getNotNullStringAndKNullable()) + a.foo3(getNullableStringAndKNullable()) + a.foo3(getNotNullStringAndNotNullK()) + a.foo3(getNullableStringAndNotNullK()) + + a.foo4(getArrayOfNotNullString()) + a.foo4(getArrayOfNullableString()) + a.foo4(getArrayOfNotNullK()) + a.foo4(getArrayOfNullableK()) + + a.foo5(getArrayOfNotNullString()) + a.foo5(getArrayOfNullableString()) + a.foo5(getArrayOfNotNullK()) + a.foo5(getArrayOfNullableK()) + + a.foo41(getNotNullString()) + a.foo411(getNotNullString()) +} diff --git a/compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic_DisabledImprovements.txt b/compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic_DisabledImprovements.txt new file mode 100644 index 00000000000..49fe9fe9a8f --- /dev/null +++ b/compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic_DisabledImprovements.txt @@ -0,0 +1,14 @@ +package test + +public open class Basic_DisabledImprovements { + public constructor Basic_DisabledImprovements() + public/*package*/ open fun foo(/*0*/ p0: R!): kotlin.Unit + + public interface G { + public abstract fun foo(/*0*/ p0: R!): kotlin.Unit + } + + public interface G1 { + public abstract fun foo(/*0*/ p0: R!): kotlin.Unit + } +} diff --git a/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.java b/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.java index d559293052e..c95657b6586 100644 --- a/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.java +++ b/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.java @@ -4,15 +4,14 @@ package test; import org.jetbrains.annotations.*; -public class Basic { - interface G { - } +public class Basic { + interface G extends G2<@NotNull T, @NotNull String> { } - interface G2 { - } + interface G2 { } public interface MyClass { - void f(G<@NotNull String> p); - void f(G2<@Nullable String, @NotNull Integer> p); + void f1(G<@NotNull String> p); + G2<@Nullable String, @NotNull Integer> f2(); + void f3(@NotNull T x); } } diff --git a/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.txt b/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.txt index 48ab6fa460e..7ac5bd3fe4d 100644 --- a/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.txt +++ b/compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.txt @@ -1,16 +1,17 @@ package test -public open class Basic { - public constructor Basic() +public open class Basic { + public constructor Basic() - public/*package*/ interface G { + public/*package*/ interface G : test.Basic.G2<@org.jetbrains.annotations.NotNull T, @org.jetbrains.annotations.NotNull kotlin.String> { } public/*package*/ interface G2 { } public interface MyClass { - public abstract fun f(/*0*/ p0: test.Basic.G2<@org.jetbrains.annotations.Nullable kotlin.String?, @org.jetbrains.annotations.NotNull kotlin.Int>!): kotlin.Unit - public abstract fun f(/*0*/ p0: test.Basic.G<@org.jetbrains.annotations.NotNull kotlin.String>!): kotlin.Unit + public abstract fun f1(/*0*/ p0: test.Basic.G<@org.jetbrains.annotations.NotNull kotlin.String>!): kotlin.Unit + public abstract fun f2(): test.Basic.G2<@org.jetbrains.annotations.Nullable kotlin.String?, @org.jetbrains.annotations.NotNull kotlin.Int>! + public abstract fun f3(/*0*/ @org.jetbrains.annotations.NotNull p0: @org.jetbrains.annotations.NotNull T): kotlin.Unit } } diff --git a/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.java b/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.java index 3aa3ae514db..20ae7c5392d 100644 --- a/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.java +++ b/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.java @@ -1,4 +1,4 @@ -// !LANGUAGE: +// !LANGUAGE: -ImprovementsAroundTypeEnhancement package test; diff --git a/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.txt b/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.txt new file mode 100644 index 00000000000..aaa86bc0d34 --- /dev/null +++ b/compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.txt @@ -0,0 +1,14 @@ +package test + +public open class Basic_DisabledImprovements { + public constructor Basic_DisabledImprovements() + public/*package*/ open fun foo(/*0*/ r: R!): kotlin.Unit + + public interface G { + public abstract fun foo(/*0*/ r: R!): kotlin.Unit + } + + public interface G1 { + public abstract fun foo(/*0*/ r: R!): kotlin.Unit + } +} diff --git a/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.java b/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.java index 6d00a4e6999..b476de95f1b 100644 --- a/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.java +++ b/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.java @@ -5,15 +5,14 @@ package test; import org.jetbrains.annotations.*; -public class Basic { - interface G { - } +public class Basic implements G2<@NotNull T, @NotNull String> { + interface G { } - interface G2 { - } + interface G2 { } public interface MyClass { - void f(G<@NotNull String> p); - void f(G2<@Nullable String, @NotNull Integer> p); + void f1(G<@NotNull String> p); + G2<@Nullable String, @NotNull Integer> f2(); + void f3(@NotNull T x) { }; } } diff --git a/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.txt b/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.txt index 5d7173d954b..aa62b4828b0 100644 --- a/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.txt +++ b/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.txt @@ -1,7 +1,7 @@ package test -public open class Basic { - public constructor Basic() +public open class Basic : G2 { + public constructor Basic() public/*package*/ interface G { } @@ -10,7 +10,8 @@ public open class Basic { } public interface MyClass { - public abstract fun f(/*0*/ p: test.Basic.G2<@org.jetbrains.annotations.Nullable kotlin.String?, @org.jetbrains.annotations.NotNull kotlin.Int>!): kotlin.Unit - public abstract fun f(/*0*/ p: test.Basic.G<@org.jetbrains.annotations.NotNull kotlin.String>!): kotlin.Unit + public abstract fun f1(/*0*/ p: test.Basic.G<@org.jetbrains.annotations.NotNull kotlin.String>!): kotlin.Unit + public abstract fun f2(): test.Basic.G2<@org.jetbrains.annotations.Nullable kotlin.String?, @org.jetbrains.annotations.NotNull kotlin.Int>! + public abstract fun f3(/*0*/ @org.jetbrains.annotations.NotNull x: @org.jetbrains.annotations.NotNull T): kotlin.Unit } } diff --git a/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic_DisabledImprovements.txt b/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic_DisabledImprovements.txt index 2ce1a78b2fb..9b6ffd2351f 100644 --- a/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic_DisabledImprovements.txt +++ b/compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic_DisabledImprovements.txt @@ -26,7 +26,7 @@ public open class Basic_DisabledImprovements!): kotlin.Unit public abstract fun f6(/*0*/ p: test.Basic_DisabledImprovements.G!): kotlin.Unit public abstract fun f7(/*0*/ p: test.Basic_DisabledImprovements.G<@org.jetbrains.annotations.NotNull test.Basic_DisabledImprovements.A.B<*, *>>!): kotlin.Unit - public abstract fun f8(): test.Basic_DisabledImprovements.G!>! + public abstract fun f81(): test.Basic_DisabledImprovements.G!>! public abstract fun f9(): test.Basic_DisabledImprovements.G<@org.jetbrains.annotations.Nullable test.Basic_DisabledImprovements.A.B<*, *>?>! } } diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsCompiledJavaDiagnosticTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsCompiledJavaDiagnosticTestGenerated.java new file mode 100644 index 00000000000..3d3e1d606f0 --- /dev/null +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignAnnotationsCompiledJavaDiagnosticTestGenerated.java @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.checkers; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class ForeignAnnotationsCompiledJavaDiagnosticTestGenerated extends AbstractForeignAnnotationsCompiledJavaDiagnosticTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTypeEnhancementOnCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("ClassTypeParameterBound.kt") + public void testClassTypeParameterBound() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt"); + } + + @TestMetadata("ClassTypeParameterBoundWithWarnings.kt") + public void testClassTypeParameterBoundWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt"); + } + + @TestMetadata("ReturnType.kt") + public void testReturnType() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt"); + } + + @TestMetadata("ReturnTypeWithWarnings.kt") + public void testReturnTypeWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt"); + } + + @TestMetadata("ValueParameter.kt") + public void testValueParameter() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt"); + } + + @TestMetadata("ValueParameterWithWarnings.kt") + public void testValueParameterWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt"); + } +} diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathTestGenerated.java index ad6569ce9f8..654e7666322 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathTestGenerated.java @@ -129,4 +129,47 @@ public class ForeignJava8AnnotationsNoAnnotationInClasspathTestGenerated extends runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancement/simple.kt"); } } + + @TestMetadata("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeEnhancementOnCompiledJava extends AbstractForeignJava8AnnotationsNoAnnotationInClasspathTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTypeEnhancementOnCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("ClassTypeParameterBound.kt") + public void testClassTypeParameterBound() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt"); + } + + @TestMetadata("ClassTypeParameterBoundWithWarnings.kt") + public void testClassTypeParameterBoundWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt"); + } + + @TestMetadata("ReturnType.kt") + public void testReturnType() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt"); + } + + @TestMetadata("ReturnTypeWithWarnings.kt") + public void testReturnTypeWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt"); + } + + @TestMetadata("ValueParameter.kt") + public void testValueParameter() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt"); + } + + @TestMetadata("ValueParameterWithWarnings.kt") + public void testValueParameterWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt"); + } + } } diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTestGenerated.java index e30b43baf87..c1a3cf480ce 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTestGenerated.java @@ -129,4 +129,47 @@ public class ForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTe runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancement/simple.kt"); } } + + @TestMetadata("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeEnhancementOnCompiledJava extends AbstractForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTypeEnhancementOnCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("ClassTypeParameterBound.kt") + public void testClassTypeParameterBound() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt"); + } + + @TestMetadata("ClassTypeParameterBoundWithWarnings.kt") + public void testClassTypeParameterBoundWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt"); + } + + @TestMetadata("ReturnType.kt") + public void testReturnType() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt"); + } + + @TestMetadata("ReturnTypeWithWarnings.kt") + public void testReturnTypeWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt"); + } + + @TestMetadata("ValueParameter.kt") + public void testValueParameter() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt"); + } + + @TestMetadata("ValueParameterWithWarnings.kt") + public void testValueParameterWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt"); + } + } } diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java index bdfef3aeeac..d63396f3bbe 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/ForeignJava8AnnotationsTestGenerated.java @@ -129,4 +129,47 @@ public class ForeignJava8AnnotationsTestGenerated extends AbstractForeignJava8An runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancement/simple.kt"); } } + + @TestMetadata("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeEnhancementOnCompiledJava extends AbstractForeignJava8AnnotationsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTypeEnhancementOnCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("ClassTypeParameterBound.kt") + public void testClassTypeParameterBound() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt"); + } + + @TestMetadata("ClassTypeParameterBoundWithWarnings.kt") + public void testClassTypeParameterBoundWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt"); + } + + @TestMetadata("ReturnType.kt") + public void testReturnType() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt"); + } + + @TestMetadata("ReturnTypeWithWarnings.kt") + public void testReturnTypeWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt"); + } + + @TestMetadata("ValueParameter.kt") + public void testValueParameter() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt"); + } + + @TestMetadata("ValueParameterWithWarnings.kt") + public void testValueParameterWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt"); + } + } } diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/javac/JavacForeignJava8AnnotationsTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/javac/JavacForeignJava8AnnotationsTestGenerated.java index 18ec7c9c912..06657adadb2 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/javac/JavacForeignJava8AnnotationsTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/checkers/javac/JavacForeignJava8AnnotationsTestGenerated.java @@ -129,4 +129,47 @@ public class JavacForeignJava8AnnotationsTestGenerated extends AbstractJavacFore runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancement/simple.kt"); } } + + @TestMetadata("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TypeEnhancementOnCompiledJava extends AbstractJavacForeignJava8AnnotationsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTypeEnhancementOnCompiledJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("ClassTypeParameterBound.kt") + public void testClassTypeParameterBound() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBound.kt"); + } + + @TestMetadata("ClassTypeParameterBoundWithWarnings.kt") + public void testClassTypeParameterBoundWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ClassTypeParameterBoundWithWarnings.kt"); + } + + @TestMetadata("ReturnType.kt") + public void testReturnType() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnType.kt"); + } + + @TestMetadata("ReturnTypeWithWarnings.kt") + public void testReturnTypeWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ReturnTypeWithWarnings.kt"); + } + + @TestMetadata("ValueParameter.kt") + public void testValueParameter() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameter.kt"); + } + + @TestMetadata("ValueParameterWithWarnings.kt") + public void testValueParameterWithWarnings() throws Exception { + runTest("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava/ValueParameterWithWarnings.kt"); + } + } } diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java index bb0a0cef3f3..f02f9b91ef2 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java @@ -62,6 +62,11 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test { public void testBasic() throws Exception { runTest("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic.java"); } + + @TestMetadata("Basic_DisabledImprovements.java") + public void testBasic_DisabledImprovements() throws Exception { + runTest("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic_DisabledImprovements.java"); + } } @TestMetadata("compiler/testData/loadJava8/compiledJava/typeUseAnnotations") @@ -86,6 +91,11 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test { runTest("compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.java"); } + @TestMetadata("Basic_DisabledImprovements.java") + public void testBasic_DisabledImprovements() throws Exception { + runTest("compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic_DisabledImprovements.java"); + } + @TestMetadata("ClassTypeParameterBounds.java") public void testClassTypeParameterBounds() throws Exception { runTest("compiler/testData/loadJava8/compiledJava/typeUseAnnotations/ClassTypeParameterBounds.java"); @@ -151,6 +161,11 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test { public void testBasic() throws Exception { runTest("compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic.java"); } + + @TestMetadata("Basic_DisabledImprovements.java") + public void testBasic_DisabledImprovements() throws Exception { + runTest("compiler/testData/loadJava8/sourceJava/typeParameterAnnotations/Basic_DisabledImprovements.java"); + } } @TestMetadata("compiler/testData/loadJava8/sourceJava/typeUseAnnotations") @@ -175,6 +190,11 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test { runTest("compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic.java"); } + @TestMetadata("Basic_DisabledImprovements.java") + public void testBasic_DisabledImprovements() throws Exception { + runTest("compiler/testData/loadJava8/sourceJava/typeUseAnnotations/Basic_DisabledImprovements.java"); + } + @TestMetadata("ClassTypeParameterBounds.java") public void testClassTypeParameterBounds() throws Exception { runTest("compiler/testData/loadJava8/sourceJava/typeUseAnnotations/ClassTypeParameterBounds.java"); diff --git a/compiler/tests/org/jetbrains/kotlin/cli/jvm/KotlinCliJavaFileManagerTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/jvm/KotlinCliJavaFileManagerTest.kt index f9f613fedac..275d5915a0f 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/jvm/KotlinCliJavaFileManagerTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/jvm/KotlinCliJavaFileManagerTest.kt @@ -28,6 +28,8 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.index.JavaRoot import org.jetbrains.kotlin.cli.jvm.index.JvmDependenciesIndexImpl import org.jetbrains.kotlin.cli.jvm.index.SingleJavaFileRootsIndex +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder import org.jetbrains.kotlin.name.ClassId @@ -204,10 +206,10 @@ class KotlinCliJavaFileManagerTest : KotlinTestWithEnvironment() { val root = StandardFileSystems.local().findFileByPath(javaFilesDir.path)!! coreJavaFileManager.initialize( - JvmDependenciesIndexImpl(listOf(JavaRoot(root, JavaRoot.RootType.SOURCE))), - emptyList(), - SingleJavaFileRootsIndex(emptyList()), - usePsiClassFilesReading = false + JvmDependenciesIndexImpl(listOf(JavaRoot(root, JavaRoot.RootType.SOURCE))), + emptyList(), + SingleJavaFileRootsIndex(emptyList()), + usePsiClassFilesReading = false ) return coreJavaFileManager diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/context.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/context.kt index 2b9cac7f802..8f72c08ae9a 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/context.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/context.kt @@ -81,7 +81,7 @@ class JavaResolverComponents( interface JavaResolverSettings { val isReleaseCoroutines: Boolean val correctNullabilityForNotNullTypeParameter: Boolean - val enhancementImprovements: Boolean + val typeEnhancementImprovements: Boolean object Default : JavaResolverSettings { override val isReleaseCoroutines: Boolean @@ -90,7 +90,7 @@ interface JavaResolverSettings { override val correctNullabilityForNotNullTypeParameter: Boolean get() = false - override val enhancementImprovements: Boolean + override val typeEnhancementImprovements: Boolean get() = false } @@ -98,12 +98,12 @@ interface JavaResolverSettings { fun create( isReleaseCoroutines: Boolean, correctNullabilityForNotNullTypeParameter: Boolean, - enhancementImprovements: Boolean, + typeEnhancementImprovements: Boolean ): JavaResolverSettings = object : JavaResolverSettings { override val isReleaseCoroutines get() = isReleaseCoroutines override val correctNullabilityForNotNullTypeParameter get() = correctNullabilityForNotNullTypeParameter - override val enhancementImprovements get() = enhancementImprovements + override val typeEnhancementImprovements get() = typeEnhancementImprovements } } } diff --git a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java index 6d4f6f0646a..b1d8877591d 100644 --- a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java +++ b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java @@ -60,6 +60,11 @@ public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8Runtim public void testBasic() throws Exception { runTest("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic.java"); } + + @TestMetadata("Basic_DisabledImprovements.java") + public void testBasic_DisabledImprovements() throws Exception { + runTest("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations/Basic_DisabledImprovements.java"); + } } @TestMetadata("compiler/testData/loadJava8/compiledJava/typeUseAnnotations") @@ -84,6 +89,11 @@ public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8Runtim runTest("compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic.java"); } + @TestMetadata("Basic_DisabledImprovements.java") + public void testBasic_DisabledImprovements() throws Exception { + runTest("compiler/testData/loadJava8/compiledJava/typeUseAnnotations/Basic_DisabledImprovements.java"); + } + @TestMetadata("ClassTypeParameterBounds.java") public void testClassTypeParameterBounds() throws Exception { runTest("compiler/testData/loadJava8/compiledJava/typeUseAnnotations/ClassTypeParameterBounds.java");