public interface PsiReference
A reference to a PSI element. For example, the variable name used in an expression.
The "Go to Declaration" action can be used to go from a reference to the element it references.
Generally returned from
PsiElement#getReferences() and PsiReferenceService#getReferences,
but may be contributed to some elements by third party plugins via PsiReferenceContributor.- See Also:
-
PsiPolyVariantReferencePsiElement.getReference()PsiElement#getReferences()PsiReferenceService#getReferences(PsiElement, PsiReferenceService.Hints)PsiReferenceBasePsiReferenceContributor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ArrayFactory<PsiReference>static final PsiReference[] -
Method Summary
Modifier and TypeMethodDescriptionbindToElement(@NotNull PsiElement element) Changes the reference so that it starts to point to the specified element.@NotNull StringReturns the name of the reference target element which does not depend on import statements and other context (for example, the full-qualified name of the class if the reference targets a Java class).@NotNull PsiElementReturns the underlying (referencing) element of the reference.@NotNull com.intellij.openapi.util.TextRangeReturns the part of the underlying element which serves as a reference, or the complete text range of the element if the entire element is a reference.handleElementRename(@NotNull String newElementName) Called when the reference target element has been renamed, in order to change the reference text according to the new name.booleanisReferenceTo(@NotNull PsiElement element) Checks if the reference targets the specified element.booleanisSoft()Returns false if the underlying element is guaranteed to be a reference, or true if the underlying element is a possible reference which should not be reported as an error if it fails to resolve.@Nullable PsiElementresolve()Returns the element which is the target of the reference.
-
Field Details
-
EMPTY_ARRAY
-
ARRAY_FACTORY
-
-
Method Details
-
getElement
Returns the underlying (referencing) element of the reference.- Returns:
- the underlying element of the reference.
-
getRangeInElement
@NotNull @NotNull com.intellij.openapi.util.TextRange getRangeInElement()Returns the part of the underlying element which serves as a reference, or the complete text range of the element if the entire element is a reference. Sample: PsiElement representing a fully qualified name with multiple dedicated PsiReferences, each bound to the range it resolves to (skipping the '.' separator).PsiElement text: qualified.LongName PsiReferences: [Ref1---]X[Ref2--]
whereRef1would resolve to a "namespace" andRef2to an "element".- Returns:
- Relative range in element
-
resolve
Returns the element which is the target of the reference.- Returns:
- the target element, or null if it was not possible to resolve the reference to a valid target.
- See Also:
-
PsiPolyVariantReference#multiResolve(boolean)
-
getCanonicalText
Returns the name of the reference target element which does not depend on import statements and other context (for example, the full-qualified name of the class if the reference targets a Java class).- Returns:
- the canonical text of the reference.
-
handleElementRename
PsiElement handleElementRename(@NotNull @NotNull String newElementName) throws IncorrectOperationException Called when the reference target element has been renamed, in order to change the reference text according to the new name.- Parameters:
newElementName- the new name of the target element.- Returns:
- the new underlying element of the reference.
- Throws:
IncorrectOperationException- if the rename cannot be handled for some reason.
-
bindToElement
Changes the reference so that it starts to point to the specified element. This is called, for example, by the "Create Class from New" quickfix, to bind the (invalid) reference on which the quickfix was called to the newly created class.- Parameters:
element- the element which should become the target of the reference.- Returns:
- the new underlying element of the reference.
- Throws:
IncorrectOperationException- if the rebind cannot be handled for some reason.
-
isReferenceTo
Checks if the reference targets the specified element.- Parameters:
element- the element to check target for.- Returns:
- true if the reference targets that element, false otherwise.
-
isSoft
boolean isSoft()Returns false if the underlying element is guaranteed to be a reference, or true if the underlying element is a possible reference which should not be reported as an error if it fails to resolve. For example, a text in an XML file which looks like a full-qualified Java class name is a soft reference.- Returns:
- true if the reference is soft, false otherwise.
-