[KAPT4] A temporary workaround for KT-60482
This commit is contained in:
committed by
Space Team
parent
7bc521ab92
commit
6475942ced
@@ -0,0 +1,106 @@
|
|||||||
|
/**
|
||||||
|
* public final annotation class Anno : kotlin/Annotation {
|
||||||
|
*
|
||||||
|
* // signature: <init>(Lkotlin/reflect/KClass;)V
|
||||||
|
* public constructor(klass: kotlin/reflect/KClass<*>)
|
||||||
|
*
|
||||||
|
* // getter: klass()Ljava/lang/Class;
|
||||||
|
* public final val klass: kotlin/reflect/KClass<*>
|
||||||
|
* public final get
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||||
|
public abstract @interface Anno {
|
||||||
|
|
||||||
|
public abstract java.lang.Class<?> klass();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class ErrorMissingAnnotation : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@ABC()
|
||||||
|
public final class ErrorMissingAnnotation {
|
||||||
|
|
||||||
|
public ErrorMissingAnnotation() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class ErrorMultipleMissingAnnotations : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@ABC()
|
||||||
|
@CDE()
|
||||||
|
public final class ErrorMultipleMissingAnnotations {
|
||||||
|
|
||||||
|
public ErrorMultipleMissingAnnotations() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class ErrorSomeMissingAnnotations : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@CDE()
|
||||||
|
@Anno(klass = ABC.class)
|
||||||
|
@ABC()
|
||||||
|
public final class ErrorSomeMissingAnnotations {
|
||||||
|
|
||||||
|
public ErrorSomeMissingAnnotations() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final class FullyQualifiedMissingAnnotation : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@com.example.XYZ()
|
||||||
|
public final class FullyQualifiedMissingAnnotation {
|
||||||
|
|
||||||
|
public FullyQualifiedMissingAnnotation() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
// FIR_BLOCKED: KT-60482
|
|
||||||
// CORRECT_ERROR_TYPES
|
// CORRECT_ERROR_TYPES
|
||||||
|
|
||||||
@file:Suppress("UNRESOLVED_REFERENCE", "ANNOTATION_ARGUMENT_MUST_BE_CONST")
|
@file:Suppress("UNRESOLVED_REFERENCE", "ANNOTATION_ARGUMENT_MUST_BE_CONST")
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@ABC
|
@ABC(x = 42)
|
||||||
class ErrorMissingAnnotation
|
class ErrorMissingAnnotation
|
||||||
|
|
||||||
@ABC @CDE
|
@ABC @CDE
|
||||||
@@ -15,6 +14,10 @@ class ErrorSomeMissingAnnotations
|
|||||||
|
|
||||||
annotation class Anno(val klass: KClass<*>)
|
annotation class Anno(val klass: KClass<*>)
|
||||||
|
|
||||||
// EXPECTED_ERROR: (kotlin:10:1) cannot find symbol
|
@com /* ??? */ . example /* ???? */ . // ???
|
||||||
// EXPECTED_ERROR: (kotlin:13:1) cannot find symbol
|
/* ??? */ XYZ ("param")
|
||||||
// EXPECTED_ERROR: (kotlin:7:1) cannot find symbol
|
class FullyQualifiedMissingAnnotation
|
||||||
|
|
||||||
|
// EXPECTED_ERROR: (kotlin:12:1) cannot find symbol
|
||||||
|
// EXPECTED_ERROR: (kotlin:6:1) cannot find symbol
|
||||||
|
// EXPECTED_ERROR: (kotlin:9:1) cannot find symbol
|
||||||
|
|||||||
@@ -91,3 +91,26 @@ public final class ErrorSomeMissingAnnotations {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass;
|
||||||
|
|
||||||
|
@com.example.XYZ()
|
||||||
|
/**
|
||||||
|
* public final class FullyQualifiedMissingAnnotation : kotlin/Any {
|
||||||
|
*
|
||||||
|
* // signature: <init>()V
|
||||||
|
* public constructor()
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class FullyQualifiedMissingAnnotation {
|
||||||
|
|
||||||
|
public FullyQualifiedMissingAnnotation() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ package org.jetbrains.kotlin.kapt4
|
|||||||
|
|
||||||
import com.google.common.collect.HashMultimap
|
import com.google.common.collect.HashMultimap
|
||||||
import com.google.common.collect.Multimap
|
import com.google.common.collect.Multimap
|
||||||
|
import com.intellij.lang.ASTNode
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||||
import com.sun.tools.javac.code.Flags
|
import com.sun.tools.javac.code.Flags
|
||||||
import com.sun.tools.javac.code.TypeTag
|
import com.sun.tools.javac.code.TypeTag
|
||||||
import com.sun.tools.javac.parser.Tokens
|
import com.sun.tools.javac.parser.Tokens
|
||||||
@@ -34,6 +36,7 @@ import org.jetbrains.kotlin.kapt3.base.stubs.KaptStubLineInformation
|
|||||||
import org.jetbrains.kotlin.kapt3.base.util.TopLevelJava9Aware
|
import org.jetbrains.kotlin.kapt3.base.util.TopLevelJava9Aware
|
||||||
import org.jetbrains.kotlin.kapt3.stubs.MemberData
|
import org.jetbrains.kotlin.kapt3.stubs.MemberData
|
||||||
import org.jetbrains.kotlin.kapt3.stubs.MembersPositionComparator
|
import org.jetbrains.kotlin.kapt3.stubs.MembersPositionComparator
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForNamedClassLike
|
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForNamedClassLike
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.*
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.*
|
||||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||||
@@ -41,6 +44,7 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
import org.jetbrains.kotlin.name.isOneSegmentFQN
|
import org.jetbrains.kotlin.name.isOneSegmentFQN
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.stubs.elements.KtAnnotationEntryElementType
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.getCalleeExpressionIfAny
|
import org.jetbrains.kotlin.resolve.calls.util.getCalleeExpressionIfAny
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
||||||
@@ -296,7 +300,35 @@ internal class Kapt4StubGenerator {
|
|||||||
annotation: PsiAnnotation,
|
annotation: PsiAnnotation,
|
||||||
packageFqName: String
|
packageFqName: String
|
||||||
): JCAnnotation? {
|
): JCAnnotation? {
|
||||||
val rawQualifiedName = annotation.qualifiedName ?: return null
|
fun collectNameParts(node: ASTNode, builder: StringBuilder, takeNext: Boolean) {
|
||||||
|
when (node) {
|
||||||
|
is LeafPsiElement -> {
|
||||||
|
when (node.elementType) {
|
||||||
|
KtTokens.IDENTIFIER, KtTokens.DOT -> builder.append((node as ASTNode).text)
|
||||||
|
}
|
||||||
|
if (takeNext) node.treeNext?.let { collectNameParts(it, builder, true) }
|
||||||
|
}
|
||||||
|
else ->
|
||||||
|
if (node.elementType is KtAnnotationEntryElementType) {
|
||||||
|
collectNameParts(node.firstChildNode.treeNext, builder, false)
|
||||||
|
} else {
|
||||||
|
collectNameParts(node.firstChildNode, builder, true)
|
||||||
|
if (takeNext) node.treeNext?.let { collectNameParts(it, builder, true) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun qualifiedName(node: ASTNode): String = buildString {
|
||||||
|
collectNameParts(node, this, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val rawQualifiedName = when (annotation.qualifiedName) {
|
||||||
|
// A temporary fix for KT-60482
|
||||||
|
"<error>" -> (annotation as? KtLightElement<*, *>)?.kotlinOrigin?.node?.let { qualifiedName(it) }
|
||||||
|
else -> annotation.qualifiedName
|
||||||
|
} ?: return null
|
||||||
|
|
||||||
val fqName = treeMaker.getQualifiedName(rawQualifiedName)
|
val fqName = treeMaker.getQualifiedName(rawQualifiedName)
|
||||||
|
|
||||||
if (BLACKLISTED_ANNOTATIONS.any { fqName.startsWith(it) }) return null
|
if (BLACKLISTED_ANNOTATIONS.any { fqName.startsWith(it) }) return null
|
||||||
|
|||||||
Reference in New Issue
Block a user