com.intellij.psi
Interface PsiReference

All Known Subinterfaces:
PsiImportStaticReferenceElement, PsiJavaCodeReferenceElement, PsiJavaReference, PsiPolyVariantReference, PsiReferenceExpression

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.

See Also:
PsiElement.getReference(), PsiElement.getReferences()

Field Summary
static PsiReference[] EMPTY_ARRAY
          The empty array of PSI references which can be reused to avoid unnecessary allocations.
 
Method Summary
 PsiElement bindToElement(PsiElement element)
          Changes the reference so that it starts to point to the specified element.
 java.lang.String 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).
 PsiElement getElement()
          Returns the underlying (referencing) element of the reference.
 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.
 java.lang.Object[] getVariants()
          Returns the array of PsiElement and/or CandidateInfo instances representing all identifiers that are visible at the location of the reference.
 PsiElement handleElementRename(java.lang.String newElementName)
          Called when the reference target element has been renamed, in order to change the reference text according to the new name.
 boolean isReferenceTo(PsiElement element)
          Checks if the reference targets the specified element.
 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.
 PsiElement resolve()
          Returns the element which is the target of the reference.
 

Field Detail

EMPTY_ARRAY

static final PsiReference[] EMPTY_ARRAY
The empty array of PSI references which can be reused to avoid unnecessary allocations.

Method Detail

getElement

PsiElement getElement()
Returns the underlying (referencing) element of the reference.

Returns:
the underlying element of the reference.

getRangeInElement

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.

Returns:
Relative range in element

resolve

@Nullable
PsiElement 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.

getCanonicalText

java.lang.String 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(java.lang.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

PsiElement bindToElement(PsiElement element)
                         throws IncorrectOperationException
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

boolean isReferenceTo(PsiElement element)
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.

getVariants

java.lang.Object[] getVariants()
Returns the array of PsiElement and/or CandidateInfo instances representing all identifiers that are visible at the location of the reference. The contents of the returned array is used to build the lookup list for basic code completion. (The list of visible identifiers must not be filtered by the completion prefix string - the filtering is performed later by IDEA core.)

Returns:
the array of available identifiers.

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 refence is soft, false otherwise.