diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/java/KSAnnotationJavaImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/java/KSAnnotationJavaImpl.kt index e8a7b884d5..6706cf3b29 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/java/KSAnnotationJavaImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/java/KSAnnotationJavaImpl.kt @@ -4,7 +4,6 @@ import com.google.devtools.ksp.KSObjectCache import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.impl.ResolverAAImpl import com.google.devtools.ksp.impl.symbol.kotlin.KSErrorType -import com.google.devtools.ksp.impl.symbol.kotlin.KSTypeImpl import com.google.devtools.ksp.impl.symbol.kotlin.KSTypeReferenceImpl import com.google.devtools.ksp.impl.symbol.kotlin.KSValueArgumentImpl import com.google.devtools.ksp.impl.symbol.kotlin.analyze @@ -38,9 +37,12 @@ import com.intellij.psi.PsiReference import com.intellij.psi.PsiType import com.intellij.psi.impl.source.PsiAnnotationMethodImpl import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue +import org.jetbrains.kotlin.analysis.api.components.buildClassType import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin import org.jetbrains.kotlin.analysis.api.types.KtType +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName class KSAnnotationJavaImpl private constructor(private val psi: PsiAnnotation) : KSAnnotation { companion object : KSObjectCache() { @@ -49,8 +51,10 @@ class KSAnnotationJavaImpl private constructor(private val psi: PsiAnnotation) : } private val type: KtType by lazy { - (ResolverAAImpl.instance.getClassDeclarationByName(psi.qualifiedName!!)!!.asStarProjectedType() as KSTypeImpl) - .type + // TODO: local class annotations? + analyze { + buildClassType(ClassId.topLevel(FqName(psi.qualifiedName!!))) + } } override val annotationType: KSTypeReference by lazy { diff --git a/kotlin-analysis-api/testData/errorTypes.kt b/kotlin-analysis-api/testData/errorTypes.kt new file mode 100644 index 0000000000..d2b8c0829f --- /dev/null +++ b/kotlin-analysis-api/testData/errorTypes.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ErrorTypeProcessor +// EXPECTED: +// kotlin.collections.MutableMap +// kotlin.collections.Map +// kotlin.String +// ERROR TYPE +// errorInComponent is assignable from errorAtTop: true +// errorInComponent is assignable from class C: false +// Any is assignable from errorInComponent: true +// class C is assignable from errorInComponent: false +// Any is assignable from class C: true +// Cls's super type is Error type: true +// Cls's annotation is Error type: true +// END +// FILE: a.kt +class C { + val errorAtTop = mutableMapOf() + val errorInComponent: Map +} + +// FILE: Cls.java + +@NonExistingAnnotation +public class Cls extends NonExistType { + +} diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ErrorTypeProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ErrorTypeProcessor.kt index 956aa16d11..f6d59a255e 100644 --- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ErrorTypeProcessor.kt +++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/ErrorTypeProcessor.kt @@ -41,22 +41,22 @@ class ErrorTypeProcessor : AbstractTestProcessor() { errorInComponent.type.resolve().arguments.forEach { result.add(it.type!!.resolve().print()) } result.add( "errorInComponent is assignable from errorAtTop: ${ - errorAtTop.type.resolve().isAssignableFrom(errorAtTop.type.resolve()) + errorInComponent.type.resolve().isAssignableFrom(errorAtTop.type.resolve()) }" ) result.add( "errorInComponent is assignable from class C: ${ - errorAtTop.type.resolve().isAssignableFrom(classC.asStarProjectedType()) + errorInComponent.type.resolve().isAssignableFrom(classC.asStarProjectedType()) }" ) result.add( "Any is assignable from errorInComponent: ${ - resolver.builtIns.anyType.isAssignableFrom(errorAtTop.type.resolve()) + resolver.builtIns.anyType.isAssignableFrom(errorInComponent.type.resolve()) }" ) result.add( "class C is assignable from errorInComponent: ${ - classC.asStarProjectedType().isAssignableFrom(errorAtTop.type.resolve()) + classC.asStarProjectedType().isAssignableFrom(errorInComponent.type.resolve()) }" ) result.add( diff --git a/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt index e68fae1267..efb72a5dc1 100644 --- a/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt +++ b/test-utils/src/test/kotlin/com/google/devtools/ksp/test/KSPAATest.kt @@ -232,11 +232,10 @@ class KSPAATest : AbstractKSPAATest() { runTest("../test-utils/testData/api/equivalentJavaWildcards.kt") } - @Disabled @TestMetadata("errorTypes.kt") @Test fun testErrorTypes() { - runTest("../test-utils/testData/api/errorTypes.kt") + runTest("../kotlin-analysis-api/testData/errorTypes.kt") } @TestMetadata("functionTypeAlias.kt") diff --git a/test-utils/testData/api/errorTypes.kt b/test-utils/testData/api/errorTypes.kt index ab2a4afea3..41b22480c6 100644 --- a/test-utils/testData/api/errorTypes.kt +++ b/test-utils/testData/api/errorTypes.kt @@ -24,7 +24,7 @@ // ERROR TYPE // errorInComponent is assignable from errorAtTop: false // errorInComponent is assignable from class C: false -// Any is assignable from errorInComponent: false +// Any is assignable from errorInComponent: true // class C is assignable from errorInComponent: false // Any is assignable from class C: true // Cls's super type is Error type: true