mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Uast: UAnnotation.namePsiElement added
as a workaround until Kotlin will implement `UAnnotationEx`
This commit is contained in:
@@ -15,8 +15,12 @@
|
||||
*/
|
||||
package org.jetbrains.uast
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtilRt
|
||||
import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.SyntaxTraverser
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.uast.internal.acceptList
|
||||
import org.jetbrains.uast.internal.log
|
||||
import org.jetbrains.uast.visitor.UastTypedVisitor
|
||||
@@ -71,6 +75,31 @@ interface UAnnotation : UElement, UResolvable {
|
||||
visitor.visitAnnotation(this, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handy method to get psiElement for reporting warnings and putting gutters
|
||||
*/
|
||||
val UAnnotation?.namePsiElement: PsiElement?
|
||||
get() {
|
||||
if (this is UAnnotationEx) return this.uastAnchor?.sourcePsi
|
||||
// A workaround for IDEA-184211
|
||||
val sourcePsiElement = this?.sourcePsiElement ?: return null
|
||||
val identifier = sourcePsiElement.navigationElement ?: return null
|
||||
val qualifiedName = this.qualifiedName
|
||||
if (qualifiedName != null) {
|
||||
val shortName = StringUtilRt.getShortName(qualifiedName)
|
||||
SyntaxTraverser.psiTraverser(sourcePsiElement)
|
||||
.filter { psi -> psi.references.isNotEmpty() && psi.text.contains(shortName) }
|
||||
.traverse()
|
||||
.first()
|
||||
?.let {
|
||||
return PsiTreeUtil.getDeepestFirst(it)
|
||||
}
|
||||
}
|
||||
|
||||
return PsiTreeUtil.getDeepestFirst(identifier)
|
||||
}
|
||||
|
||||
|
||||
interface UAnnotationEx : UAnnotation {
|
||||
val uastAnchor: UElement?
|
||||
}
|
||||
Reference in New Issue
Block a user