com.intellij.extapi.psi
Class ASTWrapperPsiElement

java.lang.Object
  extended by ElementBase
      extended by com.intellij.extapi.psi.ASTWrapperPsiElement
All Implemented Interfaces:
NavigationItem, Iconable, UserDataHolder, Navigatable, PsiElement

public class ASTWrapperPsiElement
extends ElementBase
implements PsiElement, NavigationItem

Created by IntelliJ IDEA. User: max Date: Jan 20, 2005 Time: 2:54:30 PM To change this template use File | Settings | File Templates.


Field Summary
 
Fields inherited from interface com.intellij.psi.PsiElement
EMPTY_ARRAY
 
Fields inherited from interface com.intellij.openapi.util.Iconable
ICON_FLAG_CLOSED, ICON_FLAG_OPEN, ICON_FLAG_READ_STATUS, ICON_FLAG_VISIBILITY
 
Constructor Summary
ASTWrapperPsiElement(ASTNode node)
           
 
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.
 boolean canNavigate()
           
 boolean canNavigateToSource()
           
 void checkAdd(PsiElement element)
          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.
 void checkDelete()
          Checks if it is possible to delete the specified element from the tree, and throws an exception if the add is not possible.
 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.
 FileStatus getFileStatus()
           
 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.
 java.lang.String getName()
           
 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.
 ItemPresentation getPresentation()
           
 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.)
 void navigate(boolean requestFocus)
          Open editor and select/navigate to the object there if possible.
 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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.intellij.openapi.util.UserDataHolder
getUserData, putUserData
 
Methods inherited from interface com.intellij.openapi.util.Iconable
getIcon
 

Constructor Detail

ASTWrapperPsiElement

public ASTWrapperPsiElement(ASTNode node)
Method Detail

getProject

public Project getProject()
Description copied from interface: PsiElement
Returns the project to which the PSI element belongs.

Specified by:
getProject in interface PsiElement
Returns:
the project instance.

getManager

public PsiManager getManager()
Description copied from interface: PsiElement
Returns the PSI manager for the project to which the PSI element belongs.

Specified by:
getManager in interface PsiElement
Returns:
the PSI manager instance.

getChildren

public PsiElement[] getChildren()
Description copied from interface: PsiElement
Returns the array of children for the PSI element.

Specified by:
getChildren in interface PsiElement
Returns:
the array of child elements.

getParent

public PsiElement getParent()
Description copied from interface: PsiElement
Returns the parent of the PSI element.

Specified by:
getParent in interface PsiElement
Returns:
the parent of the element, or null if the element has no parent.

getFirstChild

public PsiElement getFirstChild()
Description copied from interface: PsiElement
Returns the first child of the PSI element.

Specified by:
getFirstChild in interface PsiElement
Returns:
the first child, or null if the element has no children.

getLastChild

public PsiElement getLastChild()
Description copied from interface: PsiElement
Returns the last child of the PSI element.

Specified by:
getLastChild in interface PsiElement
Returns:
the last child, or null if the element has no children.

getNextSibling

public PsiElement getNextSibling()
Description copied from interface: PsiElement
Returns the next sibling of the PSI element.

Specified by:
getNextSibling in interface PsiElement
Returns:
the next sibling, or null if the node is the last in the list of siblings.

getPrevSibling

public PsiElement getPrevSibling()
Description copied from interface: PsiElement
Returns the previous sibling of the PSI element.

Specified by:
getPrevSibling in interface PsiElement
Returns:
the previous sibling, or null if the node is the first in the list of siblings.

getContainingFile

public PsiFile getContainingFile()
Description copied from interface: PsiElement
Returns the file containing the PSI element.

Specified by:
getContainingFile in interface PsiElement
Returns:
the file instance.

getTextRange

public TextRange getTextRange()
Description copied from interface: PsiElement
Returns the text range in the document occupied by the PSI element.

Specified by:
getTextRange in interface PsiElement
Returns:
the text range.

getStartOffsetInParent

public int getStartOffsetInParent()
Description copied from interface: PsiElement
Returns the text offset of the PSI element relative to its parent.

Specified by:
getStartOffsetInParent in interface PsiElement
Returns:
the relative offset.

getTextLength

public int getTextLength()
Description copied from interface: PsiElement
Returns the length of text of the PSI element.

Specified by:
getTextLength in interface PsiElement
Returns:
the text length.

findElementAt

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

Specified by:
findElementAt in interface PsiElement
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

public PsiReference findReferenceAt(int offset)
Description copied from interface: PsiElement
Finds a reference at the specified offset from the start of the text range of this node.

Specified by:
findReferenceAt in interface PsiElement
Parameters:
offset - the relative offset for which the reference is requested.
Returns:
the reference at the offset, or null if none is found.

getTextOffset

public int getTextOffset()
Description copied from interface: PsiElement
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.)

Specified by:
getTextOffset in interface PsiElement
Returns:
the offset of the PSI element.

getText

public java.lang.String getText()
Description copied from interface: PsiElement
Returns the text of the PSI element.

Specified by:
getText in interface PsiElement
Returns:
the element text.

textToCharArray

public char[] textToCharArray()
Description copied from interface: PsiElement
Returns the text of the PSI element as a character array.

Specified by:
textToCharArray in interface PsiElement
Returns:
the element text as a character array.

getNavigationElement

public PsiElement getNavigationElement()
Description copied from interface: PsiElement
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.)

Specified by:
getNavigationElement in interface PsiElement
Returns:
the navigation target element.

getOriginalElement

public PsiElement getOriginalElement()
Description copied from interface: PsiElement
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.)

Specified by:
getOriginalElement in interface PsiElement
Returns:
the original element.

textMatches

public boolean textMatches(java.lang.CharSequence text)
Description copied from interface: PsiElement
Checks if the text of this PSI element is equal to the specified character sequence.

Specified by:
textMatches in interface PsiElement
Parameters:
text - the character sequence to compare with.
Returns:
true if the text is equal, false otherwise.

textMatches

public boolean textMatches(PsiElement element)
Description copied from interface: PsiElement
Checks if the text of this PSI element is equal to the text of the specified PSI element.

Specified by:
textMatches in interface PsiElement
Parameters:
element - the element to compare the text with.
Returns:
true if the text is equal, false otherwise.

textContains

public boolean textContains(char c)
Description copied from interface: PsiElement
Checks if the text of this element contains the specified character.

Specified by:
textContains in interface PsiElement
Parameters:
c - the character to search for.
Returns:
true if the character is found, false otherwise.

accept

public void accept(PsiElementVisitor visitor)
Description copied from interface: PsiElement
Passes the element to the specified visitor.

Specified by:
accept in interface PsiElement
Parameters:
visitor - the visitor to pass the element to.

acceptChildren

public void acceptChildren(PsiElementVisitor visitor)
Description copied from interface: PsiElement
Passes the children of the element to the specified visitor.

Specified by:
acceptChildren in interface PsiElement
Parameters:
visitor - the visitor to pass the children to.

copy

public PsiElement copy()
Description copied from interface: PsiElement
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.

Specified by:
copy in interface PsiElement
Returns:
the element in the file copy corresponding to this element.

add

public PsiElement add(PsiElement element)
               throws IncorrectOperationException
Description copied from interface: PsiElement
Adds a child to this PSI element.

Specified by:
add in interface PsiElement
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

public PsiElement addBefore(PsiElement element,
                            PsiElement anchor)
                     throws IncorrectOperationException
Description copied from interface: PsiElement
Adds a child to this PSI element, before the specified anchor element.

Specified by:
addBefore in interface PsiElement
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

public PsiElement addAfter(PsiElement element,
                           PsiElement anchor)
                    throws IncorrectOperationException
Description copied from interface: PsiElement
Adds a child to this PSI element, after the specified anchor element.

Specified by:
addAfter in interface PsiElement
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

public void checkAdd(PsiElement element)
              throws IncorrectOperationException
Description copied from interface: PsiElement
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.

Specified by:
checkAdd in interface PsiElement
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

public PsiElement addRange(PsiElement first,
                           PsiElement last)
                    throws IncorrectOperationException
Description copied from interface: PsiElement
Adds a range of elements as children to this PSI element.

Specified by:
addRange in interface PsiElement
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

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

Specified by:
addRangeBefore in interface PsiElement
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

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

Specified by:
addRangeAfter in interface PsiElement
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

public void delete()
            throws IncorrectOperationException
Description copied from interface: PsiElement
Deletes this PSI element from the tree.

Specified by:
delete in interface PsiElement
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

public void checkDelete()
                 throws IncorrectOperationException
Description copied from interface: PsiElement
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.

Specified by:
checkDelete in interface PsiElement
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

deleteChildRange

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

Specified by:
deleteChildRange in interface PsiElement
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

public PsiElement replace(PsiElement newElement)
                   throws IncorrectOperationException
Description copied from interface: PsiElement
Replaces this PSI element (along with all its children) with another element (along with the children).

Specified by:
replace in interface PsiElement
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

public boolean isValid()
Description copied from interface: PsiElement
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.

Specified by:
isValid in interface PsiElement
Returns:
true if the element is valid, false otherwise.

isWritable

public boolean isWritable()
Description copied from interface: PsiElement
Checks if the contents of the element can be modified (if it belongs to a non-read-only source file.)

Specified by:
isWritable in interface PsiElement
Returns:
true if the element can be modified, false otherwise.

getReference

public PsiReference getReference()
Description copied from interface: PsiElement
Returns the reference associated with this PSI element. If the element has multiple associated references (see PsiElement.getReferences() for an example), returns the first associated reference.

Specified by:
getReference in interface PsiElement
Returns:
the reference instance, or null if the PSI element does not have any associated references.

getReferences

public PsiReference[] getReferences()
Description copied from interface: PsiElement
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.

Specified by:
getReferences in interface PsiElement
Returns:
the array of references, or an empty array if the element has no associated references.

processDeclarations

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

Specified by:
processDeclarations in interface PsiElement
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

public PsiElement getContext()
Description copied from interface: PsiElement
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)).

Specified by:
getContext in interface PsiElement
Returns:
the resolve context element.

isPhysical

public boolean isPhysical()
Description copied from interface: PsiElement
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.

Specified by:
isPhysical in interface PsiElement
Returns:
true if the element is physical, false otherwise.

getResolveScope

public GlobalSearchScope getResolveScope()
Description copied from interface: PsiElement
Returns the scope in which the declarations for the references in this PSI element are searched.

Specified by:
getResolveScope in interface PsiElement
Returns:
the resolve scope instance.

getUseScope

public SearchScope getUseScope()
Description copied from interface: PsiElement
Returns the scope in which references to this element are searched. The implementation of this method is usually delegated to PsiSearchHelper.getUseScope(PsiElement).

Specified by:
getUseScope in interface PsiElement
Returns:
the search scope instance.

getPresentation

public ItemPresentation getPresentation()
Specified by:
getPresentation in interface NavigationItem

getName

public java.lang.String getName()
Specified by:
getName in interface NavigationItem

navigate

public void navigate(boolean requestFocus)
Description copied from interface: Navigatable
Open editor and select/navigate to the object there if possible. Just do nothing if navigation is not possible like in case of a package

Specified by:
navigate in interface Navigatable

canNavigate

public boolean canNavigate()
Specified by:
canNavigate in interface Navigatable
Returns:
false if navigation is not possible for any reason.

canNavigateToSource

public boolean canNavigateToSource()
Specified by:
canNavigateToSource in interface Navigatable
Returns:
false if navigation to source is not possible for any reason. Source means some kind of editor

getFileStatus

public FileStatus getFileStatus()
Specified by:
getFileStatus in interface NavigationItem

getCopyableUserData

public <T> T getCopyableUserData(Key<T> key)
Description copied from interface: PsiElement
Returns a copyable user data object attached to this element.

Specified by:
getCopyableUserData in interface PsiElement
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:
PsiElement.putCopyableUserData(com.intellij.openapi.util.Key, Object)

putCopyableUserData

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

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

getNode

public ASTNode getNode()
Description copied from interface: PsiElement
Returns the AST node corresponding to the element.

Specified by:
getNode in interface PsiElement
Returns:
the AST node instance.

getLanguage

public Language getLanguage()
Description copied from interface: PsiElement
Returns the language of the PSI element.

Specified by:
getLanguage in interface PsiElement
Returns:
the language instance.