mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
rename PsiElement2Declaration factory methods to reflect their semantics; add docs
GitOrigin-RevId: ed04a96d426f68ee2b37e54896ca98a51a269803
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5f2df49a3d
commit
89fa9f9dcd
@@ -46,8 +46,13 @@ class PsiElement2Declaration implements PsiSymbolDeclaration {
|
||||
return myDeclarationRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts target element of unknown origin to a {@code PsiSymbolDeclaration}.
|
||||
* E.g. when searching for declarations of a {@link Psi2Symbol PsiElement symbol} we lose info about origin,
|
||||
* because the symbol could be obtained from reference or another declaration or any other old code.
|
||||
*/
|
||||
@Nullable
|
||||
static PsiSymbolDeclaration createFromPsi(@NotNull PsiElement targetElement) {
|
||||
static PsiSymbolDeclaration createFromTargetPsiElement(@NotNull PsiElement targetElement) {
|
||||
if (targetElement instanceof PsiNameIdentifierOwner) {
|
||||
PsiElement identifyingElement = ((PsiNameIdentifierOwner)targetElement).getIdentifyingElement();
|
||||
if (identifyingElement != null) {
|
||||
@@ -57,9 +62,15 @@ class PsiElement2Declaration implements PsiSymbolDeclaration {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts target element obtained from an element at caret to a {@code PsiSymbolDeclaration}.
|
||||
*
|
||||
* @param declaredElement target element (symbol); used for target-based actions, e.g. Find Usages
|
||||
* @param declaringElement element at caret from which {@code declaredElement} was obtained; used to determine the declaration range
|
||||
*/
|
||||
@NotNull
|
||||
static PsiSymbolDeclaration createFromPsi(@NotNull PsiElement targetElement, @NotNull PsiElement declaringElement) {
|
||||
return new PsiElement2Declaration(targetElement, declaringElement, getDeclarationRangeFromPsi(declaringElement));
|
||||
static PsiSymbolDeclaration createFromDeclaredPsiElement(@NotNull PsiElement declaredElement, @NotNull PsiElement declaringElement) {
|
||||
return new PsiElement2Declaration(declaredElement, declaringElement, getDeclarationRangeFromPsi(declaringElement));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -44,7 +44,7 @@ class PsiElementDeclarationSearcher : PsiSymbolDeclarationSearcher {
|
||||
|
||||
private fun fromPsiElement(psi: PsiElement, searchScope: SearchScope): PsiSymbolDeclaration? {
|
||||
if (psi in searchScope) {
|
||||
return PsiElement2Declaration.createFromPsi(psi)
|
||||
return PsiElement2Declaration.createFromTargetPsiElement(psi)
|
||||
}
|
||||
else {
|
||||
return null
|
||||
|
||||
@@ -30,7 +30,7 @@ fun PsiFile.allDeclarationsAround(offsetInFile: Int): Collection<PsiSymbolDeclar
|
||||
for ((leaf, _) in leavesAroundOffset(offsetInFile)) {
|
||||
val namedElement: PsiElement? = TargetElementUtil.getNamedElement(leaf)
|
||||
if (namedElement != null) {
|
||||
return listOf(PsiElement2Declaration.createFromPsi(namedElement, leaf))
|
||||
return listOf(PsiElement2Declaration.createFromDeclaredPsiElement(namedElement, leaf))
|
||||
}
|
||||
}
|
||||
return emptyList()
|
||||
|
||||
Reference in New Issue
Block a user