[FIR IDE] Fix annotation call reference resolve to ctor
This commit is contained in:
+1
-1
@@ -89,7 +89,7 @@ internal class FileStructure(
|
||||
val firFile = firFileBuilder.getFirFileResolvedToPhaseWithCaching(
|
||||
container,
|
||||
moduleFileCache,
|
||||
FirResolvePhase.IMPORTS,
|
||||
FirResolvePhase.TYPES,
|
||||
checkPCE = true
|
||||
)
|
||||
RootStructureElement(
|
||||
|
||||
+22
-3
@@ -8,17 +8,36 @@ package org.jetbrains.kotlin.idea.references
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtClassKind
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtImportAlias
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
internal class KtFirSimpleNameReference(
|
||||
expression: KtSimpleNameExpression
|
||||
) : KtSimpleNameReference(expression), KtFirReference {
|
||||
|
||||
private fun KtAnalysisSession.fixUpAnnotationCallResolveToCtor(resultsToFix: Collection<KtSymbol>): Collection<KtSymbol> {
|
||||
if (resultsToFix.isEmpty()) return resultsToFix
|
||||
|
||||
val isAnnotationCall = (((expression.parent as? KtUserType)
|
||||
?.parent as? KtTypeReference)
|
||||
?.parent as? KtConstructorCalleeExpression)
|
||||
?.parent is KtAnnotationEntry
|
||||
if (!isAnnotationCall) return resultsToFix
|
||||
|
||||
return resultsToFix.map { targetSymbol ->
|
||||
if (targetSymbol is KtFirClassOrObjectSymbol && targetSymbol.classKind == KtClassKind.ANNOTATION_CLASS) {
|
||||
targetSymbol.getMemberScope().getConstructors().firstOrNull() ?: targetSymbol
|
||||
} else targetSymbol
|
||||
}
|
||||
}
|
||||
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
check(this is KtFirAnalysisSession)
|
||||
return FirReferenceResolveHelper.resolveSimpleNameReference(this@KtFirSimpleNameReference, this)
|
||||
val results = FirReferenceResolveHelper.resolveSimpleNameReference(this@KtFirSimpleNameReference, this)
|
||||
return fixUpAnnotationCallResolveToCtor(results)
|
||||
}
|
||||
|
||||
override fun doCanBeReferenceTo(candidateTarget: PsiElement): Boolean {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FILE: main.kt
|
||||
public? final? [RAW_FIR] fun foofoo(): Int {
|
||||
public? final? [TYPES] fun foofoo(): R|kotlin/Int| {
|
||||
^foofoo barbar#()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_FIR
|
||||
|
||||
@file:[kotlin.<caret>Deprecated("message")]
|
||||
|
||||
package foo
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_FIR
|
||||
|
||||
@file:[<caret>D("message")]
|
||||
|
||||
package foo
|
||||
|
||||
Reference in New Issue
Block a user