com.intellij.psi
Interface PsiElement

All Superinterfaces:
Iconable, UserDataHolder
All Known Subinterfaces:
_PsiAdvice, _PsiArgTypePattern, _PsiAspect, _PsiAspectField, _PsiAspectFile, _PsiAspectMethod, _PsiBasicTypePattern, _PsiExecutionPointcut, _PsiIdPattern, _PsiIdPatternElement, _PsiIntertypeDeclaration, _PsiIntertypeField, _PsiIntertypeMethod, _PsiIntroduction, _PsiModifierPattern, _PsiModifierPatternList, _PsiParameterRef, _PsiPointcut, _PsiPointcutDef, _PsiPointcutRef, _PsiPrimitiveTypePattern, _PsiTargetPointcut, _PsiThisPointcut, _PsiTypeNamePattern, _PsiTypeNamePatternElement, _PsiTypePattern, _PsiWithincodePointcut, _PsiWithinPointcut, CssAttribute, CssBlock, CssClass, CssDeclaration, CssElement, CssFile, CssIdSelector, CssImport, CssPseudoClass, CssPseudoElement, CssRuleset, CssRulesetList, CssSelector, CssSelectorList, CssSelectorSuffix, CssSimpleSelector, CssString, CssStylesheet, CssTermList, ELBinaryExpression, ELConditionalExpression, ELExpression, ELExpressionHolder, ELFunctionCallExpression, ELLiteralExpression, ELParameterList, ELParenthesizedExpression, ELSelectExpression, ELSliceExpression, ELUnaryExpression, ELVariable, HtmlTag, ImplicitVariable, JspFile, JspImplicitVariable, PsiAdvice, PsiAfterAdvice, PsiAndPointcut, PsiAndTypePattern, PsiAnnotation, PsiAnnotationMemberValue, PsiAnnotationMethod, PsiAnnotationParameterList, PsiAnonymousClass, PsiAntElement, PsiAnyParametersPattern, PsiAnyTypePattern, PsiArgPattern, PsiArgsPointcut, PsiArgTypePattern, PsiArgWildcardPattern, PsiAroundAdvice, PsiArrayAccessExpression, PsiArrayInitializerExpression, PsiArrayInitializerMemberValue, PsiArrayPatternElement, PsiArrayTypePattern, PsiAspect, PsiAspectAssociation, PsiAspectField, PsiAspectFile, PsiAspectMethod, PsiAssertStatement, PsiAssignmentExpression, PsiBasicTypePattern, PsiBeforeAdvice, PsiBinaryExpression, PsiBinaryFile, PsiBlockStatement, PsiBreakStatement, PsiCall, PsiCallExpression, PsiCallPointcut, PsiCatchSection, PsiCflowBelowPointcut, PsiCflowPointcut, PsiClass, PsiClassInitializer, PsiClassObjectAccessExpression, PsiClassPattern, PsiCodeBlock, PsiCodeFragment, PsiComment, PsiCompiledElement, PsiCompoundPointcut, PsiCompoundTypePattern, PsiConditionalExpression, PsiConstructorCall, PsiConstructorPattern, PsiContinueStatement, PsiDeclarationStatement, PsiDirectory, PsiDocComment, PsiDocCommentOwner, PsiDocTag, PsiDocTagValue, PsiDocToken, PsiDominatesClause, PsiDoWhileStatement, PsiEmptyStatement, PsiEnumConstant, PsiEnumConstantInitializer, PsiErrorElement, PsiErrorIntroduction, PsiExcludeTypePattern, PsiExecutionPointcut, PsiExpression, PsiExpressionCodeFragment, PsiExpressionList, PsiExpressionListStatement, PsiExpressionStatement, PsiField, PsiFieldAccessPointcut, PsiFieldGetPointcut, PsiFieldPattern, PsiFieldSetPointcut, PsiFile, PsiFileSystemItem, PsiForeachStatement, PsiForStatement, PsiHandlerPointcut, PsiIdentifier, PsiIdPattern, PsiIdPatternElement, PsiIfPointcut, PsiIfStatement, PsiImportList, PsiImportStatement, PsiImportStatementBase, PsiImportStaticReferenceElement, PsiImportStaticStatement, PsiInheritorsPattern, PsiInitializationPointcut, PsiInlineDocTag, PsiInstanceOfExpression, PsiIntertypeDeclaration, PsiIntertypeField, PsiIntertypeMethod, PsiIntroduction, PsiJavaCodeReferenceCodeFragment, PsiJavaCodeReferenceElement, PsiJavaFile, PsiJavaToken, PsiJoinPointStaticPart, PsiKeyword, PsiLabeledStatement, PsiLiteralExpression, PsiLocalVariable, PsiMember, PsiMethod, PsiMethodCallExpression, PsiMethodPattern, PsiModifierList, PsiModifierListOwner, PsiModifierPattern, PsiModifierPatternList, PsiNamedElement, PsiNameValuePair, PsiNewExpression, PsiNonPointcut, PsiOrPointcut, PsiOrTypePattern, PsiPackage, PsiPackageStatement, PsiParameter, PsiParameterList, PsiParameterPattern, PsiParameterRef, PsiParametersPattern, PsiParameterTypePattern, PsiParametrizedPattern, PsiParenthesizedExpression, PsiParentsIntroduction, PsiPerCflowAssociation, PsiPerCflowbelowAssociation, PsiPerPointcutAssociation, PsiPerTargetAssociation, PsiPerThisAssociation, PsiPlainText, PsiPlainTextFile, PsiPointcut, PsiPointcutDef, PsiPointcutRef, PsiPostfixExpression, PsiPrefixExpression, PsiPrimitiveTypePattern, PsiReferenceExpression, PsiReferenceList, PsiReferenceParameterList, PsiRegularMethodPattern, PsiResultRestriction, PsiReturningRestriction, PsiReturnStatement, PsiSingletonAssociation, PsiSofteningIntroduction, PsiStatement, PsiStaticInitializationPointcut, PsiSuperExpression, PsiSwitchLabelStatement, PsiSwitchStatement, PsiSynchronizedStatement, PsiTargetPointcut, PsiThisExpression, PsiThisJoinPoint, PsiThisPointcut, PsiThrowingRestriction, PsiThrowsPattern, PsiThrowStatement, PsiTryStatement, PsiTypeCastExpression, PsiTypeCodeFragment, PsiTypeElement, PsiTypeNamePattern, PsiTypeNamePatternElement, PsiTypeParameter, PsiTypeParameterList, PsiTypeParameterListOwner, PsiTypePattern, PsiVariable, PsiVerificationIntroduction, PsiWarningIntroduction, PsiWhileStatement, PsiWhiteSpace, PsiWithincodePointcut, PsiWithinPointcut, WebDirectoryElement, XmlAttlistDecl, XmlAttribute, XmlAttributeDecl, XmlAttributeValue, XmlComment, XmlDecl, XmlDoctype, XmlDocument, XmlElement, XmlElementContentSpec, XmlElementDecl, XmlEntityDecl, XmlEntityRef, XmlEnumeratedType, XmlFile, XmlMarkupDecl, XmlNotationDecl, XmlProcessingInstruction, XmlProlog, XmlTag, XmlTagChild, XmlText, XmlToken
All Known Implementing Classes:
ASTWrapperPsiElement

public interface PsiElement
extends UserDataHolder, Iconable

The common base interface for all elements of the PSI tree.


Field Summary
static PsiElement[] EMPTY_ARRAY
          The empty array of PSI elements which can be reused to avoid unnecessary allocations.
 
Fields inherited from interface com.intellij.openapi.util.Iconable
ICON_FLAG_CLOSED, ICON_FLAG_OPEN, ICON_FLAG_READ_STATUS, ICON_FLAG_VISIBILITY
 
Method Summary
 void accept(PsiElementVisitor visitor)
          Passes the element to the specified visitor.
 void acceptChildren(PsiElementVisitor visitor)
          Passes the children of the element to the specified visitor.
 PsiElement add(PsiElement element)
          Adds a child to this PSI element.
 PsiElement addAfter(PsiElement element, PsiElement anchor)
          Adds a child to this PSI element, after the specified anchor element.
 PsiElement addBefore(PsiElement element, PsiElement anchor)
          Adds a child to this PSI element, before the specified anchor element.
 PsiElement addRange(PsiElement first, PsiElement last)
          Adds a range of elements as children to this PSI element.
 PsiElement addRangeAfter(PsiElement first, PsiElement last, PsiElement anchor)
          Adds a range of elements as children to this PSI element, after the specified anchor element.
 PsiElement addRangeBefore(PsiElement first, PsiElement last, PsiElement anchor)
          Adds a range of elements as children to this PSI element, before the specified anchor element.
 void checkAdd(PsiElement element)
          Deprecated. not all PSI implementations implement this method correctly.
 void checkDelete()
          Deprecated. not all PSI implementations implement this method correctly.
 PsiElement copy()
          Creates a copy of the file containing the PSI element and returns the corresponding element in the created copy.
 void delete()
          Deletes this PSI element from the tree.
 void deleteChildRange(PsiElement first, PsiElement last)
          Deletes a range of children of this PSI element from the tree.
 PsiElement findElementAt(int offset)
          Finds a leaf PSI element at the specified offset from the start of the text range of this node.
 PsiReference findReferenceAt(int offset)
          Finds a reference at the specified offset from the start of the text range of this node.
 PsiElement[] getChildren()
          Returns the array of children for the PSI element.
 PsiFile getContainingFile()
          Returns the file containing the PSI element.
 PsiElement getContext()
          Returns the element which should be used as the parent of this element in a tree up walk during a resolve operation.
<T> T
getCopyableUserData(Key<T> key)
          Returns a copyable user data object attached to this element.
 PsiElement getFirstChild()
          Returns the first child of the PSI element.
 Language getLanguage()
          Returns the language of the PSI element.
 PsiElement getLastChild()
          Returns the last child of the PSI element.
 PsiManager getManager()
          Returns the PSI manager for the project to which the PSI element belongs.
 PsiElement getNavigationElement()
          Returns the PSI element which should be used as a navigation target when navigation to this PSI element is requested.
 PsiElement getNextSibling()
          Returns the next sibling of the PSI element.
 ASTNode getNode()
          Returns the AST node corresponding to the element.
 PsiElement getOriginalElement()
          Returns the PSI element which corresponds to this element and belongs to either the project source path or class path.
 PsiElement getParent()
          Returns the parent of the PSI element.
 PsiElement getPrevSibling()
          Returns the previous sibling of the PSI element.
 Project getProject()
          Returns the project to which the PSI element belongs.
 PsiReference getReference()
          Returns the reference associated with this PSI element.
 PsiReference[] getReferences()
          Returns all references associated with this PSI element.
 GlobalSearchScope getResolveScope()
          Returns the scope in which the declarations for the references in this PSI element are searched.
 int getStartOffsetInParent()
          Returns the text offset of the PSI element relative to its parent.
 java.lang.String getText()
          Returns the text of the PSI element.
 int getTextLength()
          Returns the length of text of the PSI element.
 int getTextOffset()
          Returns the offset in the file to which the caret should be placed when performing the navigation to the element.
 TextRange getTextRange()
          Returns the text range in the document occupied by the PSI element.
 SearchScope getUseScope()
          Returns the scope in which references to this element are searched.
 boolean isPhysical()
          Checks if an actual source or class file corresponds to the element.
 boolean isValid()
          Checks if the PSI element corresponds to the current state of the underlying document.
 boolean isWritable()
          Checks if the contents of the element can be modified (if it belongs to a non-read-only source file.)
 boolean processDeclarations(PsiScopeProcessor processor, PsiSubstitutor substitutor, PsiElement lastParent, PsiElement place)
          Passes the declarations contained in this PSI element and its children for processing to the specified scope processor.
<T> void
putCopyableUserData(Key<T> key, T value)
          Attaches a copyable user data object to this element.
 PsiElement replace(PsiElement newElement)
          Replaces this PSI element (along with all its children) with another element (along with the children).
 boolean textContains(char c)
          Checks if the text of this element contains the specified character.
 boolean textMatches(java.lang.CharSequence text)
          Checks if the text of this PSI element is equal to the specified character sequence.
 boolean textMatches(PsiElement element)
          Checks if the text of this PSI element is equal to the text of the specified PSI element.
 char[] textToCharArray()
          Returns the text of the PSI element as a character array.
 
Methods inherited from interface com.intellij.openapi.util.UserDataHolder
getUserData, putUserData
 
Methods inherited from interface com.intellij.openapi.util.Iconable
getIcon
 

Field Detail

EMPTY_ARRAY

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

Method Detail

getProject

Project getProject()
Returns the project to which the PSI element belongs.

Returns:
the project instance.

getLanguage

@NotNull
Language getLanguage()
Returns the language of the PSI element.

Returns:
the language instance.

getManager

PsiManager getManager()
Returns the PSI manager for the project to which the PSI element belongs.

Returns:
the PSI manager instance.

getChildren

@NotNull
PsiElement[] getChildren()
Returns the array of children for the PSI element.

Returns:
the array of child elements.

getParent

PsiElement getParent()
Returns the parent of the PSI element.

Returns:
the parent of the element, or null if the element has no parent.

getFirstChild

@Nullable
PsiElement getFirstChild()
Returns the first child of the PSI element.

Returns:
the first child, or null if the element has no children.

getLastChild

@Nullable
PsiElement getLastChild()
Returns the last child of the PSI element.

Returns:
the last child, or null if the element has no children.

getNextSibling

@Nullable
PsiElement getNextSibling()
Returns the next sibling of the PSI element.

Returns:
the next sibling, or null if the node is the last in the list of siblings.

getPrevSibling

@Nullable
PsiElement getPrevSibling()
Returns the previous sibling of the PSI element.

Returns:
the previous sibling, or null if the node is the first in the list of siblings.

getContainingFile

PsiFile getContainingFile()
Returns the file containing the PSI element.

Returns:
the file instance.

getTextRange

TextRange getTextRange()
Returns the text range in the document occupied by the PSI element.

Returns:
the text range.

getStartOffsetInParent

int getStartOffsetInParent()
Returns the text offset of the PSI element relative to its parent.

Returns:
the relative offset.

getTextLength

int getTextLength()
Returns the length of text of the PSI element.

Returns:
the text length.

findElementAt

PsiElement findElementAt(int offset)
Finds a leaf PSI element at the specified offset from the start of the text range of this node.

Parameters:
offset - the relative offset for which the PSI element is requested.
Returns:
the element at the offset, or null if none is found.

findReferenceAt

@Nullable
PsiReference findReferenceAt(int offset)
Finds a reference at the specified offset from the start of the text range of this node.

Parameters:
offset - the relative offset for which the reference is requested.
Returns:
the reference at the offset, or null if none is found.

getTextOffset

int getTextOffset()
Returns the offset in the file to which the caret should be placed when performing the navigation to the element. (For classes implementing PsiNamedElement, this should return the offset in the file of the name identifier.)

Returns:
the offset of the PSI element.

getText

java.lang.String getText()
Returns the text of the PSI element.

Returns:
the element text.

textToCharArray

@NotNull
char[] textToCharArray()
Returns the text of the PSI element as a character array.

Returns:
the element text as a character array.

getNavigationElement

PsiElement getNavigationElement()
Returns the PSI element which should be used as a navigation target when navigation to this PSI element is requested. The method can either return this or substitute a different element if this element does not have an associated file and offset. (For example, if the source code of a library is attached to a project, the navigation element for a compiled library class is its source class.)

Returns:
the navigation target element.

getOriginalElement

PsiElement getOriginalElement()
Returns the PSI element which corresponds to this element and belongs to either the project source path or class path. The method can either return this or substitute a different element if this element does not belong to the source path or class path. (For example, the original element for a library source file is the corresponding compiled class file.)

Returns:
the original element.

textMatches

boolean textMatches(@NotNull
                    java.lang.CharSequence text)
Checks if the text of this PSI element is equal to the specified character sequence.

Parameters:
text - the character sequence to compare with.
Returns:
true if the text is equal, false otherwise.

textMatches

boolean textMatches(@NotNull
                    PsiElement element)
Checks if the text of this PSI element is equal to the text of the specified PSI element.

Parameters:
element - the element to compare the text with.
Returns:
true if the text is equal, false otherwise.

textContains

boolean textContains(char c)
Checks if the text of this element contains the specified character.

Parameters:
c - the character to search for.
Returns:
true if the character is found, false otherwise.

accept

void accept(@NotNull
            PsiElementVisitor visitor)
Passes the element to the specified visitor.

Parameters:
visitor - the visitor to pass the element to.

acceptChildren

void acceptChildren(@NotNull
                    PsiElementVisitor visitor)
Passes the children of the element to the specified visitor.

Parameters:
visitor - the visitor to pass the children to.

copy

PsiElement copy()
Creates a copy of the file containing the PSI element and returns the corresponding element in the created copy. Resolve operations performed on elements in the copy of the file will resolve to elements in the copy, not in the original file.

Returns:
the element in the file copy corresponding to this element.

add

PsiElement add(@NotNull
               PsiElement element)
               throws IncorrectOperationException
Adds a child to this PSI element.

Parameters:
element - the child element to add.
Returns:
the element which was actually added (either element or its copy).
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

addBefore

PsiElement addBefore(@NotNull
                     PsiElement element,
                     PsiElement anchor)
                     throws IncorrectOperationException
Adds a child to this PSI element, before the specified anchor element.

Parameters:
element - the child element to add.
anchor - the anchor before which the child element is inserted (must be a child of this PSI element)
Returns:
the element which was actually added (either element or its copy).
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

addAfter

PsiElement addAfter(@NotNull
                    PsiElement element,
                    PsiElement anchor)
                    throws IncorrectOperationException
Adds a child to this PSI element, after the specified anchor element.

Parameters:
element - the child element to add.
anchor - the anchor after which the child element is inserted (must be a child of this PSI element)
Returns:
the element which was actually added (either element or its copy).
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

checkAdd

void checkAdd(@NotNull
              PsiElement element)
              throws IncorrectOperationException
Deprecated. not all PSI implementations implement this method correctly.

Checks if it is possible to add the specified element as a child to this element, and throws an exception if the add is not possible. Does not actually modify anything.

Parameters:
element - the child element to check the add possibility.
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

addRange

PsiElement addRange(PsiElement first,
                    PsiElement last)
                    throws IncorrectOperationException
Adds a range of elements as children to this PSI element.

Parameters:
first - the first child element to add.
last - the last child element to add (must have the same parent as first)
Returns:
the first child element which was actually added (either first or its copy).
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

addRangeBefore

PsiElement addRangeBefore(PsiElement first,
                          PsiElement last,
                          PsiElement anchor)
                          throws IncorrectOperationException
Adds a range of elements as children to this PSI element, before the specified anchor element.

Parameters:
first - the first child element to add.
last - the last child element to add (must have the same parent as first)
anchor - the anchor before which the child element is inserted (must be a child of this PSI element)
Returns:
the first child element which was actually added (either first or its copy).
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

addRangeAfter

PsiElement addRangeAfter(PsiElement first,
                         PsiElement last,
                         PsiElement anchor)
                         throws IncorrectOperationException
Adds a range of elements as children to this PSI element, after the specified anchor element.

Parameters:
first - the first child element to add.
last - the last child element to add (must have the same parent as first)
anchor - the anchor after which the child element is inserted (must be a child of this PSI element)
Returns:
the first child element which was actually added (either first or its copy).
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

delete

void delete()
            throws IncorrectOperationException
Deletes this PSI element from the tree.

Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason (for example, the file containing the element is read-only).

checkDelete

void checkDelete()
                 throws IncorrectOperationException
Deprecated. not all PSI implementations implement this method correctly.

Checks if it is possible to delete the specified element from the tree, and throws an exception if the add is not possible. Does not actually modify anything.

Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

deleteChildRange

void deleteChildRange(PsiElement first,
                      PsiElement last)
                      throws IncorrectOperationException
Deletes a range of children of this PSI element from the tree.

Parameters:
first - the first child to delete (must be a child of this PSI element)
last - the last child to delete (must be a child of this PSI element)
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

replace

PsiElement replace(@NotNull
                   PsiElement newElement)
                   throws IncorrectOperationException
Replaces this PSI element (along with all its children) with another element (along with the children).

Parameters:
newElement - the element to replace this element with.
Returns:
the element which was actually inserted in the tree (either newElement or its copy)
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

isValid

boolean isValid()
Checks if the PSI element corresponds to the current state of the underlying document. The element is no longer valid after the document has been reparsed and a new PSI tree has been built for it.

Returns:
true if the element is valid, false otherwise.

isWritable

boolean isWritable()
Checks if the contents of the element can be modified (if it belongs to a non-read-only source file.)

Returns:
true if the element can be modified, false otherwise.

getReference

@Nullable
PsiReference getReference()
Returns the reference associated with this PSI element. If the element has multiple associated references (see getReferences() for an example), returns the first associated reference.

Returns:
the reference instance, or null if the PSI element does not have any associated references.

getReferences

@NotNull
PsiReference[] getReferences()
Returns all references associated with this PSI element. An element can be associated with multiple references when, for example, the element is a string literal containing multiple sub-strings which are valid full-qualified class names. If an element contains only one text fragment which acts as a reference but the reference has multiple possible targets, PsiPolyVariantReference should be used instead of returning multiple references.

Returns:
the array of references, or an empty array if the element has no associated references.

getCopyableUserData

<T> T getCopyableUserData(Key<T> key)
Returns a copyable user data object attached to this element.

Parameters:
key - the key for accessing the user data object.
Returns:
the user data object, or null if no such object is found in the current element.
See Also:
putCopyableUserData(com.intellij.openapi.util.Key, Object)

putCopyableUserData

<T> void putCopyableUserData(Key<T> key,
                             T value)
Attaches a copyable user data object to this element. Copyable user data objects are copied when the PSI elements are copied.

Parameters:
key - the key for accessing the user data object.
value - the user data object to attach.
See Also:
getCopyableUserData(com.intellij.openapi.util.Key)

processDeclarations

boolean processDeclarations(PsiScopeProcessor processor,
                            PsiSubstitutor substitutor,
                            PsiElement lastParent,
                            PsiElement place)
Passes the declarations contained in this PSI element and its children for processing to the specified scope processor.

Parameters:
processor - the processor receiving the declarations.
substitutor - the class providing the mapping between type parameters and their values.
lastParent - the child of this element which was processed during the previous step of the tree up walk (declarations under this element do not need to be processed again)
place - the original element from which the tree up walk was initiated.
Returns:
true if the declaration processing should continue or false if it should be stopped.

getContext

PsiElement getContext()
Returns the element which should be used as the parent of this element in a tree up walk during a resolve operation. For most elements, this returns getParent(), but the context can be overridden for some elements like code fragments (see PsiElementFactory.createCodeBlockCodeFragment(String, PsiElement, boolean)).

Returns:
the resolve context element.

isPhysical

boolean isPhysical()
Checks if an actual source or class file corresponds to the element. Non-physical elements include, for example, PSI elements created for the watch expressions in the debugger. Non-physical elements do not generate tree change events. Also, PsiDocumentManager.getDocument(PsiFile) returns null for non-physical elements.

Returns:
true if the element is physical, false otherwise.

getResolveScope

GlobalSearchScope getResolveScope()
Returns the scope in which the declarations for the references in this PSI element are searched.

Returns:
the resolve scope instance.

getUseScope

@NotNull
SearchScope getUseScope()
Returns the scope in which references to this element are searched. The implementation of this method is usually delegated to PsiSearchHelper.getUseScope(PsiElement).

Returns:
the search scope instance.

getNode

ASTNode getNode()
Returns the AST node corresponding to the element.

Returns:
the AST node instance.