Review fixes around type enhancement and loading type use annotations

This commit is contained in:
Victor Petukhov
2020-12-17 15:37:16 +03:00
parent 9a52863fbd
commit 48d9812d9e
19 changed files with 148 additions and 338 deletions
@@ -18,7 +18,6 @@ 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
@@ -38,20 +37,14 @@ internal class AnnotationsCollectorFieldVisitor(
if (descriptor == null) return null
val typeReference = TypeReference(typeRef)
val targetType = if (typePath != null) computeTargetType(field.type, typePath) else field.type
if (typePath != null) {
val translatedPath = translatePath(typePath)
when (typeReference.sort) {
TypeReference.FIELD -> {
val targetType = computeTargetType(field.type, translatedPath)
return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, descriptor, context, signatureParser, true)
}
}
}
if (targetType !is MutableJavaAnnotationOwner) return null
return when (typeReference.sort) {
TypeReference.FIELD -> BinaryJavaAnnotation.addAnnotation(field.type as JavaPlainType, descriptor, context, signatureParser, true)
TypeReference.FIELD -> BinaryJavaAnnotation.addAnnotation(
targetType, descriptor, context, signatureParser, isFreshlySupportedAnnotation = true
)
else -> null
}
}
@@ -69,7 +62,9 @@ internal class AnnotationsAndParameterCollectorMethodVisitor(
private var visibleAnnotableParameterCount = parametersCountInMethodDesc
private var invisibleAnnotableParameterCount = parametersCountInMethodDesc
override fun visitAnnotationDefault(): AnnotationVisitor? =
val freshlySupportedPositions = setOf(TypeReference.METHOD_TYPE_PARAMETER, TypeReference.METHOD_TYPE_PARAMETER_BOUND)
override fun visitAnnotationDefault(): AnnotationVisitor =
BinaryJavaAnnotationVisitor(context, signatureParser) {
member.safeAs<BinaryJavaMethod>()?.annotationParameterDefaultValue = it
}
@@ -91,7 +86,6 @@ internal class AnnotationsAndParameterCollectorMethodVisitor(
override fun visitAnnotation(desc: String, visible: Boolean) =
BinaryJavaAnnotation.addAnnotation(member, desc, context, signatureParser)
@Suppress("NOTHING_TO_OVERRIDE")
override fun visitAnnotableParameterCount(parameterCount: Int, visible: Boolean) {
if (visible) {
visibleAnnotableParameterCount = parameterCount
@@ -109,39 +103,30 @@ internal class AnnotationsAndParameterCollectorMethodVisitor(
return BinaryJavaAnnotation.addAnnotation(member.valueParameters[index], 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? {
val typeReference = TypeReference(typeRef)
if (typePath != null) {
val baseType = when (typeReference.sort) {
TypeReference.METHOD_RETURN -> member.safeAs<BinaryJavaMethod>()?.returnType
TypeReference.METHOD_FORMAL_PARAMETER -> member.valueParameters[typeReference.formalParameterIndex].type
TypeReference.METHOD_TYPE_PARAMETER_BOUND ->
BinaryJavaAnnotation.computeTypeParameterBound(member.typeParameters, typeReference)
else -> null
} ?: return null
fun getTargetType(baseType: JavaType) =
if (typePath != null) {
computeTargetType(baseType, typePath) to true
} else {
baseType to (typeReference.sort in freshlySupportedPositions)
}
return BinaryJavaAnnotation.addAnnotation(
computeTargetType(baseType, translatePath(typePath)) as JavaPlainType, desc, context, signatureParser, true
val (annotationOwner, isFreshlySupportedAnnotation) = when (typeReference.sort) {
TypeReference.METHOD_RETURN -> getTargetType(member.safeAs<BinaryJavaMethod>()?.returnType ?: return null)
TypeReference.METHOD_TYPE_PARAMETER -> member.typeParameters[typeReference.typeParameterIndex] to true
TypeReference.METHOD_FORMAL_PARAMETER -> getTargetType(member.valueParameters[typeReference.formalParameterIndex].type)
TypeReference.METHOD_TYPE_PARAMETER_BOUND -> getTargetType(
BinaryJavaAnnotation.computeTypeParameterBound(member.typeParameters, typeReference)
)
}
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, isFreshlySupportedAnnotation)
}
if (annotationOwner !is MutableJavaAnnotationOwner) return null
enum class PathElementType { ARRAY_ELEMENT, WILDCARD_BOUND, ENCLOSING_CLASS, TYPE_ARGUMENT }
return BinaryJavaAnnotation.addAnnotation(annotationOwner, descriptor, context, signatureParser, isFreshlySupportedAnnotation)
}
}
class BinaryJavaAnnotation private constructor(
@@ -150,9 +135,7 @@ class BinaryJavaAnnotation private constructor(
override val arguments: Collection<JavaAnnotationArgument>,
override val isFreshlySupportedTypeUseAnnotation: Boolean
) : JavaAnnotation {
companion object {
fun createAnnotationAndVisitor(
desc: String,
context: ClassifierResolutionContext,
@@ -178,66 +161,52 @@ class BinaryJavaAnnotation private constructor(
return annotationVisitor
}
internal fun translatePath(path: TypePath): List<Pair<AnnotationsAndParameterCollectorMethodVisitor.PathElementType, Int?>> {
val length = path.length
val list = mutableListOf<Pair<AnnotationsAndParameterCollectorMethodVisitor.PathElementType, Int?>>()
for (i in 0 until length) {
when (path.getStep(i)) {
TypePath.INNER_TYPE -> {
continue
}
TypePath.ARRAY_ELEMENT -> {
list.add(AnnotationsAndParameterCollectorMethodVisitor.PathElementType.ARRAY_ELEMENT to null)
@OptIn(ExperimentalStdlibApi::class)
private fun translatePath(path: TypePath) = buildList {
for (i in 0 until path.length) {
when (val step = path.getStep(i)) {
// TODO: process inner types and apply an annotation to the corresponding type component
TypePath.INNER_TYPE -> continue
TypePath.ARRAY_ELEMENT, TypePath.WILDCARD_BOUND -> add(step to 0)
TypePath.TYPE_ARGUMENT -> add(step to path.getStepArgument(i))
}
}
}
internal fun computeTargetType(baseType: JavaType, typePath: TypePath) =
translatePath(typePath).fold(baseType) { targetType, (typePathKind, typeArgumentIndex) ->
when (typePathKind) {
TypePath.TYPE_ARGUMENT -> {
require(targetType is JavaClassifierType)
targetType.typeArguments[typeArgumentIndex]
?: throw IllegalArgumentException("There must be no less than ${typeArgumentIndex + 1} type arguments")
}
TypePath.WILDCARD_BOUND -> {
list.add(AnnotationsAndParameterCollectorMethodVisitor.PathElementType.WILDCARD_BOUND to null)
// TODO: think about processing annotated wildcards themselves
require(targetType is JavaWildcardType)
targetType.bound
?: throw IllegalArgumentException("Wildcard mast have a bound for annotation of WILDCARD_BOUND position")
}
TypePath.TYPE_ARGUMENT -> {
list.add(AnnotationsAndParameterCollectorMethodVisitor.PathElementType.TYPE_ARGUMENT to path.getStepArgument(i))
}
}
}
return list
}
internal fun computeTargetType(
baseType: JavaType,
typePath: List<Pair<AnnotationsAndParameterCollectorMethodVisitor.PathElementType, Int?>>
): JavaType {
var targetType = baseType
for (element in typePath) {
when (element.first) {
AnnotationsAndParameterCollectorMethodVisitor.PathElementType.TYPE_ARGUMENT -> {
if (targetType is JavaClassifierType) {
targetType = targetType.typeArguments[element.second!!]!!
}
}
AnnotationsAndParameterCollectorMethodVisitor.PathElementType.WILDCARD_BOUND -> {
if (targetType is JavaWildcardType) {
targetType = targetType.bound!!
}
}
AnnotationsAndParameterCollectorMethodVisitor.PathElementType.ARRAY_ELEMENT -> {
if (targetType is JavaArrayType) {
targetType = targetType.componentType
}
TypePath.ARRAY_ELEMENT -> {
require(targetType is JavaArrayType)
targetType.componentType
}
else -> targetType
}
}
return targetType
}
internal fun computeTypeParameterBound(typeParameters: List<JavaTypeParameter>, typeReference: TypeReference): JavaClassifierType {
val typeParameter = typeParameters[typeReference.typeParameterIndex]
internal fun computeTypeParameterBound(
typeParameters: List<JavaTypeParameter>,
typeReference: TypeReference
): JavaClassifierType {
val typeParameter = typeParameters[typeReference.typeParameterIndex] as BinaryJavaTypeParameter
val boundIndex =
if (typeParameter.hasImplicitObjectClassBound) typeReference.typeParameterBoundIndex - 1 else typeReference.typeParameterBoundIndex
require(typeParameter is BinaryJavaTypeParameter) { "Type parameter must be a binary type parameter" }
return typeParameters[typeReference.typeParameterIndex].upperBounds.toList()[boundIndex]
val boundIndex = if (typeParameter.hasImplicitObjectClassBound) {
typeReference.typeParameterBoundIndex - 1
} else {
typeReference.typeParameterBoundIndex
}
return typeParameter.upperBounds.elementAt(boundIndex)
}
}
@@ -56,7 +56,7 @@ class BinaryJavaClass(
// In accordance with JVMS, super class always comes before the interface list
private val superclass: JavaClassifierType? get() = supertypes.firstOrNull()
private val interfaces: List<JavaClassifierType> get() = supertypes.drop(1)
private val implementedInterfaces: List<JavaClassifierType> get() = supertypes.drop(1)
override val annotationsByFqName by buildLazyValueForMap()
@@ -86,38 +86,22 @@ class BinaryJavaClass(
if (descriptor == null)
return null
fun getTargetType(baseType: JavaType) =
if (typePath != null) BinaryJavaAnnotation.computeTargetType(baseType, typePath) else baseType
val typeReference = TypeReference(typeRef)
if (typePath != null) {
val translatedPath = BinaryJavaAnnotation.translatePath(typePath)
when (typeReference.sort) {
TypeReference.CLASS_EXTENDS -> {
val baseType: JavaType = if (typeReference.superTypeIndex == -1) superclass!! else interfaces[typeReference.superTypeIndex]
val targetType = BinaryJavaAnnotation.computeTargetType(baseType, translatedPath)
return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, descriptor, context, signatureParser, true)
}
TypeReference.CLASS_TYPE_PARAMETER_BOUND -> {
val baseType = computeTypeParameterBound(typeParameters, typeReference)
val targetType = BinaryJavaAnnotation.computeTargetType(baseType, translatedPath)
return BinaryJavaAnnotation.addAnnotation(targetType as JavaPlainType, descriptor, context, signatureParser, true)
}
}
val annotationOwner = when (typeReference.sort) {
TypeReference.CLASS_EXTENDS ->
getTargetType(if (typeReference.superTypeIndex == -1) superclass!! else implementedInterfaces[typeReference.superTypeIndex])
TypeReference.CLASS_TYPE_PARAMETER -> typeParameters[typeReference.typeParameterIndex]
TypeReference.CLASS_TYPE_PARAMETER_BOUND -> getTargetType(computeTypeParameterBound(typeParameters, typeReference))
else -> return null
}
return when (typeReference.sort) {
TypeReference.CLASS_TYPE_PARAMETER ->
BinaryJavaAnnotation.addAnnotation(
typeParameters[typeReference.typeParameterIndex] as BinaryJavaTypeParameter, descriptor, context, signatureParser, true
)
TypeReference.CLASS_TYPE_PARAMETER_BOUND ->
BinaryJavaAnnotation.addAnnotation(
computeTypeParameterBound(typeParameters, typeReference) as JavaPlainType, descriptor, context, signatureParser, true
)
else -> null
}
if (annotationOwner !is MutableJavaAnnotationOwner) return null
return BinaryJavaAnnotation.addAnnotation(annotationOwner, descriptor, context, signatureParser, isFreshlySupportedAnnotation = true)
}
override fun visitEnd() {
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.load.java.structure.impl.classFiles
import org.jetbrains.kotlin.load.java.structure.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.org.objectweb.asm.ClassReader
+1 -1
View File
@@ -1,3 +1,3 @@
error: unknown API version: 239.42
Supported API versions: 1.2 (DEPRECATED), 1.3, 1.4, 1.5 (EXPERIMENTAL)
Supported API versions: 1.2 (DEPRECATED), 1.3, 1.4, 1.5 (EXPERIMENTAL), 1.6 (EXPERIMENTAL)
COMPILATION_ERROR
+1 -1
View File
@@ -1,3 +1,3 @@
error: unknown language version: 239.42
Supported language versions: 1.2 (DEPRECATED), 1.3, 1.4, 1.5 (EXPERIMENTAL)
Supported language versions: 1.2 (DEPRECATED), 1.3, 1.4, 1.5 (EXPERIMENTAL), 1.6 (EXPERIMENTAL)
COMPILATION_ERROR
@@ -2,13 +2,13 @@ package test
public open class Basic {
public constructor Basic()
public/*package*/ open fun </*0*/ R : kotlin.Any!, /*1*/ _A : R!, /*2*/ K : kotlin.Any!> foo(/*0*/ R!): kotlin.Unit
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE_PARAMETER}) @kotlin.annotation.Retention(value = ...) public final annotation class A : kotlin.Annotation {
public final val value: kotlin.String
public final fun <get-value>(): kotlin.String
public interface G</*0*/ T : kotlin.Any!> {
public abstract fun </*0*/ R : kotlin.Any!> foo(/*0*/ R!): kotlin.Unit
}
public interface G</*0*/ @test.Basic.A(value = "") T : kotlin.Any!> {
public abstract fun </*0*/ @test.Basic.A(value = "abc") R : kotlin.Any!> foo(/*0*/ R!): kotlin.Unit
public interface G1</*0*/ T : kotlin.Any!, /*1*/ E : T!, /*2*/ X : kotlin.Any!> {
public abstract fun </*0*/ R : kotlin.Any!, /*1*/ _A : R!> foo(/*0*/ R!): kotlin.Unit
}
}
@@ -0,0 +1,32 @@
package test
public open class Basic_DisabledImprovements</*0*/ T : kotlin.Any!> {
public/*package*/ constructor Basic_DisabledImprovements</*0*/ T : kotlin.Any!>(/*0*/ test.Basic_DisabledImprovements.G<kotlin.String!>!)
public/*package*/ open class A {
public/*package*/ constructor A()
public/*package*/ open inner class B</*0*/ A : kotlin.Any!, /*1*/ B : kotlin.Any!> {
public/*package*/ constructor B</*0*/ A : kotlin.Any!, /*1*/ B : kotlin.Any!>()
}
}
public/*package*/ interface G</*0*/ T : kotlin.Any!> : test.Basic_DisabledImprovements.G2<T!, kotlin.String!> {
}
public/*package*/ interface G2</*0*/ A : kotlin.Any!, /*1*/ B : kotlin.Any!> {
}
public interface MyClass</*0*/ TT : kotlin.Any!> {
public abstract fun f1(/*0*/ test.Basic_DisabledImprovements.G<kotlin.String!>!): kotlin.Unit
public abstract fun </*0*/ T : kotlin.Any!, /*1*/ K : test.Basic_DisabledImprovements.G<kotlin.Array<(out) kotlin.String!>!>!> f10(/*0*/ T!): kotlin.Unit
public abstract fun f2(): test.Basic_DisabledImprovements.G2<kotlin.String!, kotlin.Int!>!
public abstract fun </*0*/ T : kotlin.Any!> f3(/*0*/ T!): kotlin.Unit
public abstract fun f4(/*0*/ test.Basic_DisabledImprovements.G<kotlin.Array<(out) kotlin.String!>!>!): kotlin.Unit
public abstract fun f5(/*0*/ test.Basic_DisabledImprovements.G<*>!): kotlin.Unit
public abstract fun f6(/*0*/ test.Basic_DisabledImprovements.G<*>!): kotlin.Unit
public abstract fun f7(/*0*/ test.Basic_DisabledImprovements.G<test.Basic_DisabledImprovements.A.B<*, *>!>!): kotlin.Unit
public abstract fun f81(): test.Basic_DisabledImprovements.G<test.Basic_DisabledImprovements.A.B<*, *>!>!
public abstract fun f9(): test.Basic_DisabledImprovements.G<test.Basic_DisabledImprovements.A.B<*, *>!>!
}
}
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.checkers
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.MockLibraryUtil.compileJavaFilesLibraryToJar
import java.io.File
import kotlin.io.path.ExperimentalPathApi
@@ -18,26 +17,21 @@ abstract class AbstractForeignAnnotationsCompiledJavaDiagnosticTest : AbstractDi
files: List<TestFile>
) {
val ktFiles = files.filter { !it.name.endsWith(".java") }
val dir = createTempDirectory()
val javaFile = File("${wholeFile.parentFile.path}/${wholeFile.nameWithoutExtension}.java")
File("$dir/${wholeFile.nameWithoutExtension}.java").apply { createNewFile() }.writeText(javaFile.readText())
File(FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH).copyRecursively(File("$dir/annotations/"))
assertExists(javaFile)
val javaFilesDir = createTempDirectory().toFile().also {
File(FOREIGN_JDK8_ANNOTATIONS_SOURCES_PATH).copyRecursively(File("$it/annotations/"))
javaFile.copyTo(File("$it/${javaFile.name}"))
}
super.doMultiFileTest(
wholeFile,
ktFiles,
compileJavaFilesLibraryToJar(dir.toString(), "foreign-annotations"),
compileJavaFilesLibraryToJar(javaFilesDir.path, "java-files"),
usePsiClassFilesReading = false,
excludeNonTypeUseJetbrainsAnnotations = true
)
}
override fun doTest(filePath: String) {
val file = File(filePath)
val expectedText = KotlinTestUtils.doLoadFile(file)
doMultiFileTest(file, createTestFilesFromFile(file, expectedText))
}
}
@@ -8,6 +8,7 @@ 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.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -25,7 +26,7 @@ public class ForeignAnnotationsCompiledJavaDiagnosticTestGenerated extends Abstr
}
public void testAllFilesPresentInTypeEnhancementOnCompiledJava() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests/typeEnhancementOnCompiledJava"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("ClassTypeParameterBound.kt")
@@ -26,7 +26,7 @@ public class ForeignJava8AnnotationsNoAnnotationInClasspathTestGenerated extends
}
public void testAllFilesPresentInTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify");
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify", "typeEnhancementOnCompiledJava");
}
@TestMetadata("checkerFramework.kt")
@@ -129,47 +129,4 @@ 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");
}
}
}
@@ -26,7 +26,7 @@ public class ForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTe
}
public void testAllFilesPresentInTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify");
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify", "typeEnhancementOnCompiledJava");
}
@TestMetadata("checkerFramework.kt")
@@ -129,47 +129,4 @@ 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");
}
}
}
@@ -26,7 +26,7 @@ public class ForeignJava8AnnotationsTestGenerated extends AbstractForeignJava8An
}
public void testAllFilesPresentInTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify");
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify", "typeEnhancementOnCompiledJava");
}
@TestMetadata("checkerFramework.kt")
@@ -129,47 +129,4 @@ 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");
}
}
}
@@ -26,7 +26,7 @@ public class JavacForeignJava8AnnotationsTestGenerated extends AbstractJavacFore
}
public void testAllFilesPresentInTests() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify");
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/foreignAnnotationsJava8/tests"), Pattern.compile("^(.+)\\.kt$"), null, true, "jspecify", "typeEnhancementOnCompiledJava");
}
@TestMetadata("checkerFramework.kt")
@@ -129,47 +129,4 @@ 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");
}
}
}
@@ -30,19 +30,22 @@ fun main(args: Array<String>) {
generateTestGroupSuite(args) {
testGroup("compiler/tests-java8/tests", "compiler/testData") {
testClass<AbstractForeignJava8AnnotationsTest> {
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify"))
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify", "typeEnhancementOnCompiledJava"))
}
testClass<AbstractJavacForeignJava8AnnotationsTest> {
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify"))
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify", "typeEnhancementOnCompiledJava"))
}
testClass<AbstractForeignJava8AnnotationsNoAnnotationInClasspathTest> {
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify"))
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify", "typeEnhancementOnCompiledJava"))
}
testClass<AbstractForeignJava8AnnotationsNoAnnotationInClasspathWithPsiClassReadingTest> {
model("foreignAnnotationsJava8/tests", excludeDirs = listOf("jspecify"))
model(
"foreignAnnotationsJava8/tests",
excludeDirs = listOf("jspecify", "typeEnhancementOnCompiledJava")
)
}
testClass<AbstractJspecifyAnnotationsTest> {
@@ -55,7 +55,7 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test {
}
public void testAllFilesPresentInTypeParameterAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
}
@TestMetadata("Basic.java")
@@ -78,7 +78,7 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test {
}
public void testAllFilesPresentInTypeUseAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeUseAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeUseAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
}
@TestMetadata("BaseClassTypeArguments.java")
@@ -154,7 +154,7 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test {
}
public void testAllFilesPresentInTypeParameterAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/sourceJava/typeParameterAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/sourceJava/typeParameterAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
}
@TestMetadata("Basic.java")
@@ -177,7 +177,7 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test {
}
public void testAllFilesPresentInTypeUseAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/sourceJava/typeUseAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/sourceJava/typeUseAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
}
@TestMetadata("BaseClassTypeArguments.java")
@@ -48,8 +48,10 @@ interface JavaTypeParameterListOwner : JavaElement {
interface JavaAnnotation : JavaElement {
val arguments: Collection<JavaAnnotationArgument>
val classId: ClassId?
val isIdeExternalAnnotation: Boolean get() = false
val isFreshlySupportedTypeUseAnnotation: Boolean get() = false
val isIdeExternalAnnotation: Boolean
get() = false
val isFreshlySupportedTypeUseAnnotation: Boolean
get() = false
fun resolve(): JavaClass?
}
@@ -261,11 +261,7 @@ class SignatureEnhancement(
* class A extends B<@NotNull Integer> {}
*/
fun enhanceSuperType(type: KotlinType, context: LazyJavaResolverContext) =
SignatureParts(
null, type, emptyList(), false, context,
AnnotationQualifierApplicabilityType.TYPE_USE,
typeParameterBounds = true
).enhance().type
SignatureParts(null, type, emptyList(), false, context, AnnotationQualifierApplicabilityType.TYPE_USE).enhance().type
private fun ValueParameterDescriptor.hasDefaultValueInAnnotation(type: KotlinType) =
when (val defaultValue = getDefaultValueFromAnnotation()) {
@@ -53,7 +53,7 @@ public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8Runtim
}
public void testAllFilesPresentInTypeParameterAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeParameterAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
}
@TestMetadata("Basic.java")
@@ -76,7 +76,7 @@ public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8Runtim
}
public void testAllFilesPresentInTypeUseAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeUseAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/loadJava8/compiledJava/typeUseAnnotations"), Pattern.compile("^(.+)\\.java$"), null, true);
}
@TestMetadata("BaseClassTypeArguments.java")
@@ -6,15 +6,15 @@ interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToo
/**
* Allow using declarations only from the specified version of bundled libraries
* Possible values: "1.2 (DEPRECATED)", "1.3", "1.4", "1.5 (EXPERIMENTAL)"
* Possible values: "1.2 (DEPRECATED)", "1.3", "1.4", "1.5 (EXPERIMENTAL)", "1.6 (EXPERIMENTAL)"
* Default value: null
*/
var apiVersion: kotlin.String?
/**
* Provide source compatibility with the specified version of Kotlin
* Possible values: "1.2 (DEPRECATED)", "1.3", "1.4", "1.5 (EXPERIMENTAL)"
* Possible values: "1.2 (DEPRECATED)", "1.3", "1.4", "1.5 (EXPERIMENTAL)", "1.6 (EXPERIMENTAL)"
* Default value: null
*/
var languageVersion: kotlin.String?
}
}