public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiFileWithStubSupport, Queryable, java.lang.Cloneable
Queryable.Contributor, Queryable.PrintInfo, Queryable.Util
Modifier and Type | Field and Description |
---|---|
static Key<java.lang.Boolean> |
BUILDING_STUB |
protected IElementType |
myContentElementType |
protected PsiManagerEx |
myManager |
protected PsiFile |
myOriginalFile |
FLAGS_LOCKED, ICON_PLACEHOLDER
BATCH_REFERENCE_PROCESSING
EMPTY_ARRAY
EMPTY_NAVIGATABLE_ELEMENT_ARRAY
EMPTY_NAVIGATION_ITEM_ARRAY
Modifier | Constructor and Description |
---|---|
protected |
PsiFileImpl(FileViewProvider provider) |
protected |
PsiFileImpl(IElementType elementType,
IElementType contentElementType,
FileViewProvider provider) |
Modifier and Type | Method and Description |
---|---|
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.
|
protected void |
assertReadAccessAllowed() |
void |
beforeAstChange() |
StubTree |
calcStubTree() |
FileElement |
calcTreeElement() |
boolean |
canNavigate()
Indicates whether this instance supports navigation of any kind.
|
boolean |
canNavigateToSource()
Indicates whether this instance supports navigation to source (that means some kind of editor).
|
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.
|
void |
checkSetName(java.lang.String name)
Checks if it is possible to rename the element to the specified name,
and throws an exception if the rename is not possible.
|
void |
clearCaches()
Invalidate any file-specific cache in this method.
|
protected PsiFileImpl |
clone() |
protected PsiFileImpl |
cloneImpl(FileElement treeElementClone) |
PsiElement |
copy()
Creates a copy of the file containing the PSI element and returns the corresponding
element in the created copy.
|
TreeElement |
createContentLeafElement(java.lang.CharSequence leafText) |
protected FileElement |
createFileElement(java.lang.CharSequence docText) |
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.
|
StubTree |
derefStub() |
<T> T |
findChildByClass(java.lang.Class<T> aClass) |
<T> T [] |
findChildrenByClass(java.lang.Class<T> aClass) |
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.
|
PsiDirectory |
getContainingDirectory()
Returns the directory containing the file.
|
PsiFile |
getContainingFile()
Returns the file containing the PSI element.
|
IElementType |
getContentElementType() |
PsiElement |
getContext()
Returns the element which should be used as the parent of this element in a tree up
walk during a resolve operation.
|
IStubFileElementType |
getElementTypeForStubBuilder() |
IFileElementType |
getFileElementType() |
PsiElement |
getFirstChild()
Returns the first child of the PSI element.
|
StubElement |
getGreenStub()
A green stub is a stub object that can co-exist with tree (AST).
|
StubTree |
getGreenStubTree() |
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.
|
long |
getModificationStamp()
Gets the modification stamp value.
|
java.lang.String |
getName()
Returns the name of the element.
|
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.
|
FileASTNode |
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.
|
PsiFile |
getOriginalFile()
If the file is a non-physical copy of a file, returns the original file which had
been copied.
|
PsiDirectory |
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.
|
PsiFile [] |
getPsiRoots()
If the file contains multiple interspersed languages, returns the roots for
PSI trees for each of these languages.
|
PsiReference |
getReference()
Returns the reference from this PSI element to another PSI element (or elements), if one exists.
|
PsiReference [] |
getReferences()
Returns all references from this PSI element to other PSI elements.
|
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.
|
StubElement |
getStub() |
StubbedSpine |
getStubbedSpine() |
StubTree |
getStubTree() |
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.
|
FileElement |
getTreeElement() |
SearchScope |
getUseScope()
Returns the scope in which references to this element are searched.
|
FileViewProvider |
getViewProvider() |
VirtualFile |
getVirtualFile()
Returns the virtual file corresponding to the PSI file.
|
protected void |
init(IElementType elementType,
IElementType contentElementType) |
boolean |
isContentsLoaded() |
boolean |
isDirectory() |
boolean |
isEquivalentTo(PsiElement another)
This method shouldn't be called by clients directly, because there are no guarantees of it being symmetric.
|
boolean |
isPhysical()
Checks if an actual source or class file corresponds to the element.
|
boolean |
isTemplateDataFile() |
boolean |
isValid()
Checks if this PSI element is valid.
|
boolean |
isWritable()
Checks if the contents of the element can be modified (if it belongs to a
non-read-only source file.)
|
void |
markInvalidated() |
void |
navigate(boolean requestFocus)
Open editor and select/navigate to the object there if possible.
|
void |
onContentReload() |
boolean |
processChildren(PsiElementProcessor<PsiFileSystemItem> processor) |
boolean |
processDeclarations(PsiScopeProcessor processor,
ResolveState state,
PsiElement lastParent,
PsiElement place)
Passes the declarations contained in this PSI element and its children
for processing to the specified scope processor.
|
void |
putInfo(java.util.Map<java.lang.String,java.lang.String> info) |
static void |
putInfo(PsiFile psiFile,
java.util.Map<java.lang.String,java.lang.String> info) |
PsiElement |
replace(PsiElement newElement)
Replaces this PSI element (along with all its children) with another element
(along with the children).
|
void |
setContentElementType(IElementType contentElementType) |
PsiElement |
setName(java.lang.String name)
Renames the element.
|
void |
setOriginalFile(PsiFile originalFile) |
void |
setTreeElementPointer(FileElement element) |
void |
subtreeChanged()
Called by the PSI framework when the contents of the file changes.
|
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.
|
java.lang.String |
toString()
toString() should never be presented to the user.
|
buildRowIcon, computeBaseIcon, createLayeredIcon, getAdjustedBaseIcon, getBaseIcon, getElementIcon, getIcon, iconWithVisibilityIfNeeded, isNativeFileType, isVisibilitySupported, overlayIcons, registerIconLayer, transformFlags
changeUserMap, clearUserData, copyCopyableDataTo, copyUserDataTo, getCopyableUserData, getUserData, getUserDataString, getUserMap, isUserDataEmpty, putCopyableUserData, putUserData, putUserDataIfAbsent, replace, setUserMap
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getFileType
protected IElementType myContentElementType
protected PsiFile myOriginalFile
protected final PsiManagerEx myManager
public static final Key<java.lang.Boolean> BUILDING_STUB
protected PsiFileImpl(IElementType elementType, IElementType contentElementType, FileViewProvider provider)
protected PsiFileImpl(FileViewProvider provider)
public void setContentElementType(IElementType contentElementType)
public IElementType getContentElementType()
protected void init(IElementType elementType, IElementType contentElementType)
public TreeElement createContentLeafElement(java.lang.CharSequence leafText)
public boolean isDirectory()
isDirectory
in interface PsiFileSystemItem
public FileElement getTreeElement()
public VirtualFile getVirtualFile()
PsiFile
getVirtualFile
in interface PsiFile
getVirtualFile
in interface PsiFileSystemItem
null
if the file exists only in memory.public boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor)
processChildren
in interface PsiFileSystemItem
public boolean isValid()
PsiElement
PsiDocumentManager.commitDocument(com.intellij.openapi.editor.Document)
).
(In this case an attempt to change PSI will result in an exception).
Any access to invalid elements results in PsiInvalidElementAccessException
.
Once invalid, elements can't become valid again.
Elements become invalid in following cases:
PsiElement.delete()
)isValid
in interface PsiElement
PsiUtilCore.ensureValid(PsiElement)
public final void markInvalidated()
markInvalidated
in interface PsiFileEx
public boolean isContentsLoaded()
isContentsLoaded
in interface PsiFileEx
protected void assertReadAccessAllowed()
public StubbedSpine getStubbedSpine()
getStubbedSpine
in interface PsiFileWithStubSupport
public IStubFileElementType getElementTypeForStubBuilder()
protected FileElement createFileElement(java.lang.CharSequence docText)
public void clearCaches()
PsiFile
clearCaches
in interface PsiFile
public java.lang.String getText()
PsiElement
getText
in interface PsiElement
PsiElement.textMatches(java.lang.CharSequence)
,
PsiElement.textContains(char)
public int getTextLength()
PsiElement
getTextLength
in interface PsiElement
public TextRange getTextRange()
PsiElement
getTextRange
in interface PsiElement
public PsiElement getNextSibling()
PsiElement
getNextSibling
in interface PsiElement
public PsiElement getPrevSibling()
PsiElement
getPrevSibling
in interface PsiElement
public long getModificationStamp()
PsiFile
getModificationStamp
in interface PsiFile
VirtualFile.getModificationStamp()
public void subtreeChanged()
PsiFile
PsiFile.clearCaches()
since file contents can be reloaded completely (without any specific subtree change) without this method being called.subtreeChanged
in interface PsiFile
protected PsiFileImpl clone()
clone
in class UserDataHolderBase
public java.lang.String getName()
PsiNamedElement
getName
in interface NavigationItem
getName
in interface PsiFileSystemItem
getName
in interface PsiNamedElement
public PsiElement setName(java.lang.String name) throws IncorrectOperationException
PsiNamedElement
setName
in interface PsiNamedElement
name
- the new element name.this
or a different element if the rename caused the element to be replaced).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public void checkSetName(java.lang.String name)
PsiCheckedRenameElement
checkSetName
in interface PsiCheckedRenameElement
name
- the new name to check the renaming possibility for.public boolean isWritable()
PsiElement
isWritable
in interface PsiElement
public PsiDirectory getParent()
PsiElement
getParent
in interface PsiElement
getParent
in interface PsiFile
getParent
in interface PsiFileSystemItem
public PsiDirectory getContainingDirectory()
PsiFile
getContainingDirectory
in interface PsiFile
null
if the file exists only in memory.public PsiFile getContainingFile()
PsiElement
getContainingFile
in interface PsiElement
public void delete() throws IncorrectOperationException
PsiElement
delete
in interface PsiElement
IncorrectOperationException
- if the modification is not supported
or not possible for some reason (for example, the file containing the element is read-only).public void checkDelete() throws IncorrectOperationException
PsiElement
checkDelete
in interface PsiElement
IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiFile getOriginalFile()
PsiFile
getOriginalFile
in interface PsiFile
public void setOriginalFile(PsiFile originalFile)
public PsiFile [] getPsiRoots()
PsiFile
getPsiRoots
in interface PsiFile
this
if the file has only a single language.public boolean isPhysical()
PsiElement
PsiDocumentManager.getDocument(PsiFile)
returns null for non-physical elements.
Not to be confused with FileViewProvider.isPhysical()
.isPhysical
in interface PsiElement
public Language getLanguage()
PsiElement
getLanguage
in interface PsiElement
public IFileElementType getFileElementType()
getFileElementType
in interface PsiFile
public FileViewProvider getViewProvider()
getViewProvider
in interface PsiFile
public void setTreeElementPointer(FileElement element)
public PsiElement findElementAt(int offset)
PsiElement
findElementAt
in interface PsiElement
offset
- the relative offset for which the PSI element is requested.public PsiReference findReferenceAt(int offset)
PsiElement
findReferenceAt
in interface PsiElement
offset
- the relative offset for which the reference is requested.public char [] textToCharArray()
PsiElement
textToCharArray
in interface PsiElement
public <T> T [] findChildrenByClass(java.lang.Class<T> aClass)
public <T> T findChildByClass(java.lang.Class<T> aClass)
public boolean isTemplateDataFile()
public PsiElement getContext()
PsiElement
getParent()
,
but the context can be overridden for some elements like code fragments (see
JavaCodeFragmentFactory.createCodeBlockCodeFragment(String, PsiElement, boolean)
).getContext
in interface PsiElement
public void onContentReload()
onContentReload
in interface PsiFileEx
public StubElement getStub()
getStubTree()
, or null if the file is not stub-based or AST has been loaded.public final StubElement getGreenStub()
getStub()
, can be non-null
even if the AST has been loaded in this file. It can be used in cases when retrieving information from a stub is cheaper
than from AST.getStub()
,
getStubTree()
public StubTree getStubTree()
getStubTree
in interface PsiFileWithStubSupport
public StubTree derefStub()
protected PsiFileImpl cloneImpl(FileElement treeElementClone)
public final PsiManager getManager()
PsiElement
getManager
in interface PsiElement
public PsiElement getNavigationElement()
PsiElement
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.)getNavigationElement
in interface PsiElement
public PsiElement getOriginalElement()
PsiElement
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.)getOriginalElement
in interface PsiElement
public final FileElement calcTreeElement()
public PsiElement [] getChildren()
PsiElement
getChildren
in interface PsiElement
public PsiElement getFirstChild()
PsiElement
getFirstChild
in interface PsiElement
public PsiElement getLastChild()
PsiElement
getLastChild
in interface PsiElement
public void acceptChildren(PsiElementVisitor visitor)
PsiElement
acceptChildren
in interface PsiElement
visitor
- the visitor to pass the children to.public int getStartOffsetInParent()
PsiElement
getStartOffsetInParent
in interface PsiElement
public int getTextOffset()
PsiElement
PsiNamedElement
, this should return the offset in the file of the
name identifier.)getTextOffset
in interface PsiElement
public boolean textMatches(java.lang.CharSequence text)
PsiElement
textMatches
in interface PsiElement
text
- the character sequence to compare with.public boolean textMatches(PsiElement element)
PsiElement
textMatches
in interface PsiElement
element
- the element to compare the text with.public boolean textContains(char c)
PsiElement
textContains
in interface PsiElement
c
- the character to search for.public final PsiElement copy()
PsiElement
copy
in interface PsiElement
public PsiElement add(PsiElement element) throws IncorrectOperationException
PsiElement
add
in interface PsiElement
element
- the child element to add.element
or its copy).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiElement addBefore(PsiElement element, PsiElement anchor) throws IncorrectOperationException
PsiElement
addBefore
in interface PsiElement
element
- the child element to add.anchor
- the anchor before which the child element is inserted (must be a child of this PSI element)element
or its copy).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiElement addAfter(PsiElement element, PsiElement anchor) throws IncorrectOperationException
PsiElement
addAfter
in interface PsiElement
element
- the child element to add.anchor
- the anchor after which the child element is inserted (must be a child of this PSI element)element
or its copy).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public final void checkAdd(PsiElement element)
PsiElement
checkAdd
in interface PsiElement
element
- the child element to check the add possibility.public PsiElement addRange(PsiElement first, PsiElement last) throws IncorrectOperationException
PsiElement
addRange
in interface PsiElement
first
- the first child element to add.last
- the last child element to add (must have the same parent as first
)first
or its copy).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiElement addRangeBefore(PsiElement first, PsiElement last, PsiElement anchor) throws IncorrectOperationException
PsiElement
addRangeBefore
in interface PsiElement
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)first
or its copy).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiElement addRangeAfter(PsiElement first, PsiElement last, PsiElement anchor) throws IncorrectOperationException
PsiElement
addRangeAfter
in interface PsiElement
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)first
or its copy).IncorrectOperationException
- if the modification is not supported or not possible for some reason.public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException
PsiElement
deleteChildRange
in interface PsiElement
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)IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiElement replace(PsiElement newElement) throws IncorrectOperationException
PsiElement
replace
in interface PsiElement
newElement
- the element to replace this element with.newElement
or its copy)IncorrectOperationException
- if the modification is not supported or not possible for some reason.public PsiReference getReference()
PsiElement
PsiElement.getReferences()
for an example), returns the first associated reference.getReference
in interface PsiElement
ReferencesSearch
public PsiReference [] getReferences()
PsiElement
PsiPolyVariantReference
should be used instead
of returning multiple references.
Actually, it's preferable to call PsiReferenceService.getReferences(com.intellij.psi.PsiElement, com.intellij.psi.PsiReferenceService.Hints)
instead
as it allows adding references by plugins when the element implements ContributedReferenceHost
.getReferences
in interface PsiElement
PsiReferenceService.getReferences(com.intellij.psi.PsiElement, com.intellij.psi.PsiReferenceService.Hints)
,
ReferencesSearch
public boolean processDeclarations(PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place)
PsiElement
processDeclarations
in interface PsiElement
processor
- the processor receiving the declarations.lastParent
- the child of this element has been 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.public GlobalSearchScope getResolveScope()
PsiElement
getResolveScope
in interface PsiElement
public SearchScope getUseScope()
PsiElement
getUseScope
in interface PsiElement
PsiSearchHelper.getUseScope(PsiElement)
public ItemPresentation getPresentation()
getPresentation
in interface NavigationItem
public void navigate(boolean requestFocus)
Navigatable
navigate
in interface Navigatable
requestFocus
- true
if focus requesting is necessarypublic boolean canNavigate()
Navigatable
Navigatable.canNavigateToSource()
returns true
.
We assume that this method should return true
in such case,
so implement this method respectively.canNavigate
in interface Navigatable
false
if navigation is not possible for any reason.public boolean canNavigateToSource()
Navigatable
false
.
In such cases it is not recommended to do batch navigation for all navigatables
available via CommonDataKeys.NAVIGATABLE_ARRAY
,
because it may lead to opening several modal dialogs.
Use OpenSourceUtil.navigate(com.intellij.pom.Navigatable...)
to process such arrays correctly.canNavigateToSource
in interface Navigatable
false
if navigation to source is not possible for any reason.public final Project getProject()
PsiElement
getProject
in interface PsiElement
public FileASTNode getNode()
PsiElement
getNode
in interface PsiElement
getNode
in interface PsiFile
public boolean isEquivalentTo(PsiElement another)
PsiElement
PsiManager.areElementsEquivalent(PsiElement, PsiElement)
internally, which clients should invoke instead.
Implementations of this method should return true
if the parameter is resolve-equivalent to this
, i.e. it represents
the same entity from the language perspective. See also PsiManager.areElementsEquivalent(PsiElement, PsiElement)
documentation.isEquivalentTo
in interface PsiElement
public final StubTree getGreenStubTree()
getGreenStub()
as a root, or null if there's no green stub availablepublic StubTree calcStubTree()
public void putInfo(java.util.Map<java.lang.String,java.lang.String> info)
public static void putInfo(PsiFile psiFile, java.util.Map<java.lang.String,java.lang.String> info)
public java.lang.String toString()
PsiElement
toString
in interface PsiElement
toString
in class java.lang.Object
public final void beforeAstChange()