[AA] Support getting type from get and set annotation calls
#KTIJ-26206 Fixed
This commit is contained in:
committed by
Space Team
parent
c9eebffbfa
commit
362675a1b5
+18
@@ -52,12 +52,30 @@ public class Fe10IdeNormalAnalysisSourceModuleTypeReferenceTestGenerated extends
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryBackingField.kt")
|
||||
public void testAnnotationEntryBackingField() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryGetter.kt")
|
||||
public void testAnnotationEntryGetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryGetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryOnParameter.kt")
|
||||
public void testAnnotationEntryOnParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryOnParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntrySetter.kt")
|
||||
public void testAnnotationEntrySetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntrySetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationOnFunction.kt")
|
||||
public void testAnnotationOnFunction() throws Exception {
|
||||
|
||||
+12
-6
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFir
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbol
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbolOfTypeSafe
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.ConeTypeCompatibilityChecker
|
||||
@@ -30,11 +29,10 @@ import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.fullyExpandedClass
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
|
||||
import org.jetbrains.kotlin.fir.realPsi
|
||||
import org.jetbrains.kotlin.fir.psi
|
||||
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
@@ -120,10 +118,18 @@ internal class KtFirTypeProvider(
|
||||
if (parent.receiverTypeReference === ktTypeReference) firCallable?.receiverParameter?.typeRef else firCallable?.returnTypeRef
|
||||
}
|
||||
parent is KtConstructorCalleeExpression && parent.parent is KtAnnotationEntry -> {
|
||||
val firDeclaration = getFirDeclaration(parent.parent as KtAnnotationEntry, ktTypeReference)
|
||||
fun FirMemberDeclaration.findAnnotationTypeRef(annotationEntry: KtAnnotationEntry) = annotations.find {
|
||||
it.psi === annotationEntry
|
||||
}?.annotationTypeRef
|
||||
|
||||
val annotationEntry = parent.parent as KtAnnotationEntry
|
||||
val firDeclaration = getFirDeclaration(annotationEntry, ktTypeReference)
|
||||
if (firDeclaration != null) {
|
||||
firDeclaration.annotations.find { it.realPsi === parent.parent }?.annotationTypeRef
|
||||
?: (firDeclaration as? FirProperty)?.backingField?.annotations?.find { it.realPsi === parent.parent }?.annotationTypeRef
|
||||
firDeclaration.findAnnotationTypeRef(annotationEntry) ?: (firDeclaration as? FirProperty)?.run {
|
||||
backingField?.findAnnotationTypeRef(annotationEntry)
|
||||
?: getter?.findAnnotationTypeRef(annotationEntry)
|
||||
?: setter?.findAnnotationTypeRef(annotationEntry)
|
||||
}
|
||||
} else {
|
||||
ktTypeReference.getOrBuildFir(firResolveSession)
|
||||
}
|
||||
|
||||
+18
@@ -52,12 +52,30 @@ public class FirIdeDependentAnalysisSourceModuleTypeReferenceTestGenerated exten
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryBackingField.kt")
|
||||
public void testAnnotationEntryBackingField() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryGetter.kt")
|
||||
public void testAnnotationEntryGetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryGetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryOnParameter.kt")
|
||||
public void testAnnotationEntryOnParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryOnParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntrySetter.kt")
|
||||
public void testAnnotationEntrySetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntrySetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationOnFunction.kt")
|
||||
public void testAnnotationOnFunction() throws Exception {
|
||||
|
||||
+18
@@ -52,12 +52,30 @@ public class FirIdeNormalAnalysisSourceModuleTypeReferenceTestGenerated extends
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryBackingField.kt")
|
||||
public void testAnnotationEntryBackingField() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryGetter.kt")
|
||||
public void testAnnotationEntryGetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryGetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryOnParameter.kt")
|
||||
public void testAnnotationEntryOnParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryOnParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntrySetter.kt")
|
||||
public void testAnnotationEntrySetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntrySetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationOnFunction.kt")
|
||||
public void testAnnotationOnFunction() throws Exception {
|
||||
|
||||
+18
@@ -52,12 +52,30 @@ public class FirStandaloneNormalAnalysisSourceModuleTypeReferenceTestGenerated e
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryBackingField.kt")
|
||||
public void testAnnotationEntryBackingField() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryGetter.kt")
|
||||
public void testAnnotationEntryGetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryGetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntryOnParameter.kt")
|
||||
public void testAnnotationEntryOnParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryOnParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationEntrySetter.kt")
|
||||
public void testAnnotationEntrySetter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntrySetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotationOnFunction.kt")
|
||||
public void testAnnotationOnFunction() throws Exception {
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
annotation class Anno
|
||||
|
||||
@field:An<caret>no
|
||||
val x = 0
|
||||
analysis/analysis-api/testData/components/typeProvider/typeReference/annotationEntryBackingField.txt
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
expression: Anno
|
||||
ktType: Anno
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
annotation class Anno
|
||||
|
||||
@get:An<caret>no
|
||||
val x = 0
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
expression: Anno
|
||||
ktType: Anno
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
annotation class Anno
|
||||
|
||||
@set:An<caret>no
|
||||
var x = 0
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
expression: Anno
|
||||
ktType: Anno
|
||||
Reference in New Issue
Block a user