[KAPT] Support type annotations in K2 KAPT. Fixes KT-64479
This commit is contained in:
committed by
Space Team
parent
7e9d6e601d
commit
0dd3abba2a
@@ -0,0 +1,86 @@
|
|||||||
|
package org.jetbrains;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final annotation class org/jetbrains/A : kotlin/Annotation {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.TYPE, kotlin.annotation.AnnotationTarget.TYPE_PARAMETER})
|
||||||
|
@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE_USE, java.lang.annotation.ElementType.TYPE_PARAMETER})
|
||||||
|
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||||
|
public abstract @interface A {
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
package org.jetbrains;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class org/jetbrains/Outer : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // nested class: Inner
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class Outer {
|
||||||
|
|
||||||
|
public Outer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class org/jetbrains/Outer.Inner : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public static final class Inner {
|
||||||
|
|
||||||
|
public Inner() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
package org.jetbrains;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* package {
|
||||||
|
*
|
||||||
|
* // signature: foo(Ljava/util/List;Lorg/jetbrains/Outer$Inner;I)Ljava/lang/String;
|
||||||
|
* public final fun foo(x: @org/jetbrains/A kotlin/collections/List<@org/jetbrains/A kotlin/String>, y: @org/jetbrains/A org/jetbrains/Outer.Inner, z: @org/jetbrains/A kotlin/Int): @org/jetbrains/A kotlin/String
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class TypeAnnotationsKt {
|
||||||
|
|
||||||
|
public TypeAnnotationsKt() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public static final java.lang.@org.jetbrains.A() String foo(@org.jetbrains.annotations.NotNull()
|
||||||
|
java.util.@org.jetbrains.A() List<java.lang.@org.jetbrains.A() String> x, @org.jetbrains.annotations.NotNull()
|
||||||
|
org.jetbrains.Outer.@org.jetbrains.A() Inner y, @org.jetbrains.A()
|
||||||
|
int z) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package org.jetbrains
|
||||||
|
|
||||||
|
@Target(allowedTargets = [AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER])
|
||||||
|
annotation class A
|
||||||
|
|
||||||
|
class Outer {
|
||||||
|
class Inner
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(x: @A List<@A String>, y: @A Outer.Inner, z: @A Int): @A String = ""
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package org.jetbrains;
|
||||||
|
|
||||||
|
@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.TYPE, kotlin.annotation.AnnotationTarget.TYPE_PARAMETER})
|
||||||
|
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||||
|
@java.lang.annotation.Target(value = {})
|
||||||
|
/**
|
||||||
|
* public final annotation class org/jetbrains/A : kotlin/Annotation {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public abstract @interface A {
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
package org.jetbrains;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class org/jetbrains/Outer : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // nested class: Inner
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class Outer {
|
||||||
|
|
||||||
|
public Outer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class org/jetbrains/Outer.Inner : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public static final class Inner {
|
||||||
|
|
||||||
|
public Inner() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
package org.jetbrains;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* package {
|
||||||
|
*
|
||||||
|
* // signature: foo(Ljava/util/List;Lorg/jetbrains/Outer$Inner;I)Ljava/lang/String;
|
||||||
|
* public final fun foo(x: @org/jetbrains/A kotlin/collections/List<@org/jetbrains/A kotlin/String>, y: @org/jetbrains/A org/jetbrains/Outer.Inner, z: @org/jetbrains/A kotlin/Int): @org/jetbrains/A kotlin/String
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class TypeAnnotationsKt {
|
||||||
|
|
||||||
|
public TypeAnnotationsKt() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public static final java.lang.String foo(@org.jetbrains.annotations.NotNull()
|
||||||
|
java.util.List<java.lang.String> x, @org.jetbrains.annotations.NotNull()
|
||||||
|
org.jetbrains.Outer.Inner y, int z) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -715,6 +715,12 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla
|
|||||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/topLevel.kt");
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/topLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("typeAnnotations.kt")
|
||||||
|
public void testTypeAnnotations() throws Exception {
|
||||||
|
runTest("plugins/kapt3/kapt3-compiler/testData/converter/typeAnnotations.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("unresolvedDelegateExpression.kt")
|
@TestMetadata("unresolvedDelegateExpression.kt")
|
||||||
public void testUnresolvedDelegateExpression() throws Exception {
|
public void testUnresolvedDelegateExpression() throws Exception {
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ private class StubGenerator(
|
|||||||
print(method.name, "(")
|
print(method.name, "(")
|
||||||
method.parameterList.parameters.forEachIndexed{ index, parameter ->
|
method.parameterList.parameters.forEachIndexed{ index, parameter ->
|
||||||
if (index > 0) print(", ")
|
if (index > 0) print(", ")
|
||||||
printTypeSignature(parameter.type)
|
printTypeSignature(parameter.type, false)
|
||||||
}
|
}
|
||||||
print(")")
|
print(")")
|
||||||
}
|
}
|
||||||
@@ -430,14 +430,11 @@ private class StubGenerator(
|
|||||||
|
|
||||||
private fun Printer.printType(type: PsiType) {
|
private fun Printer.printType(type: PsiType) {
|
||||||
recordErrorTypes(type)
|
recordErrorTypes(type)
|
||||||
type.annotations.forEach {
|
printTypeSignature(type, true)
|
||||||
printAnnotation(it, false)
|
|
||||||
}
|
|
||||||
printTypeSignature(type)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Printer.printTypeSignature(type: PsiType) {
|
private fun Printer.printTypeSignature(type: PsiType, annotated: Boolean) {
|
||||||
printWithNoIndent((if (type is PsiClassType && isErroneous(type)) type.rawType() else type).canonicalText.replace('$', '.'))
|
printWithNoIndent((if (type is PsiClassType && isErroneous(type)) type.rawType() else type).getCanonicalText(annotated).replace('$', '.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Printer.printTypeParams(typeParameters: Array<PsiTypeParameter>) {
|
private fun Printer.printTypeParams(typeParameters: Array<PsiTypeParameter>) {
|
||||||
|
|||||||
+6
@@ -715,6 +715,12 @@ public class KotlinKapt4ContextTestGenerated extends AbstractKotlinKapt4ContextT
|
|||||||
runTest("plugins/kapt4/../kapt3/kapt3-compiler/testData/converter/topLevel.kt");
|
runTest("plugins/kapt4/../kapt3/kapt3-compiler/testData/converter/topLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("typeAnnotations.kt")
|
||||||
|
public void testTypeAnnotations() throws Exception {
|
||||||
|
runTest("plugins/kapt4/../kapt3/kapt3-compiler/testData/converter/typeAnnotations.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("unresolvedDelegateExpression.kt")
|
@TestMetadata("unresolvedDelegateExpression.kt")
|
||||||
public void testUnresolvedDelegateExpression() throws Exception {
|
public void testUnresolvedDelegateExpression() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user