com.intellij.psi
Interface PsiFile

All Superinterfaces:
Iconable, PsiElement, PsiFileSystemItem, PsiNamedElement, UserDataHolder
All Known Subinterfaces:
CssFile, JspFile, PsiAspectFile, PsiBinaryFile, PsiCodeFragment, PsiExpressionCodeFragment, PsiJavaCodeReferenceCodeFragment, PsiJavaFile, PsiPlainTextFile, PsiTypeCodeFragment, XmlFile

public interface PsiFile
extends PsiElement, PsiFileSystemItem

A PSI element representing a file.


Field Summary
static PsiFile[] EMPTY_ARRAY
          The empty array of PSI files which can be reused to avoid unnecessary allocations.
 
Method Summary
 boolean canContainJavaCode()
          Checks if the file is a Java source file or Java code fragment.
 PsiFile createPseudoPhysicalCopy()
          Creates a copy which is considered physical (see PsiElement.isPhysical()) for a PSI file which is not backed by a VirtualFile.
 PsiJavaCodeReferenceElement findImportReferenceTo(PsiClass aClass)
          For Java/JSP files only: returns the single-class import statement which references the specified class, or null if there is no such statement.
 PsiDirectory getContainingDirectory()
          Returns the directory containing the file.
 FileType getFileType()
          Returns the file type for the file.
 PsiJavaCodeReferenceElement[] getImplicitlyImportedPackageReferences()
          For Java/JSP files only: returns the list of reference elements for the implicitly imported packages (for example, java.lang).
 java.lang.String[] getImplicitlyImportedPackages()
          For Java/JSP files only: returns the list of names of implicitly imported packages (for example, java.lang).
 long getModificationStamp()
          Gets the modification stamp value.
 PsiElement[] getOnDemandImports(boolean includeImplicit, boolean checkIncludes)
          For Java/JSP files only: returns the list of classes or packages which have been imported on demand (for example, javax.swing.*)
 PsiFile getOriginalFile()
          If the file is a non-physical copy of a file, returns the original file which had been copied.
 PsiFile[] getPsiRoots()
          If the file contains multiple interspersed languages, returns the roots for PSI trees for each of these languages.
 PsiClass[] getSingleClassImports(boolean checkIncludes)
          For Java/JSP files only: returns the list of classs which have been imported as single-class imports.
 VirtualFile getVirtualFile()
          Returns the virtual file corresponding to the PSI file.
 void setModificationStamp(long modificationStamp)
          Sets the modification stamp value.
 
Methods inherited from interface com.intellij.psi.PsiFileSystemItem
checkSetName
 
Methods inherited from interface com.intellij.psi.PsiNamedElement
getName, setName
 

Field Detail

EMPTY_ARRAY

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

Method Detail

getVirtualFile

@Nullable
VirtualFile getVirtualFile()
Returns the virtual file corresponding to the PSI file.

Returns:
the virtual file, or null if the file exists only in memory.

getContainingDirectory

@Nullable
PsiDirectory getContainingDirectory()
Returns the directory containing the file.

Returns:
the containing directory, or null if the file exists only in memory.

getModificationStamp

long getModificationStamp()
Gets the modification stamp value. Modification stamp is a value changed by any modification of the content of the file. Note that it is not related to the file modification time.

Returns:
the modification stamp value
See Also:
VirtualFile.getModificationStamp(), setModificationStamp(long)

setModificationStamp

void setModificationStamp(long modificationStamp)
Sets the modification stamp value. Modification stamp is a value changed by any modification of the content of the file. Note that it is not related to the file modification time.

Parameters:
modificationStamp - the new modification stamp value.
See Also:
getModificationStamp()

getOnDemandImports

@NotNull
PsiElement[] getOnDemandImports(boolean includeImplicit,
                                        @Deprecated
                                        boolean checkIncludes)
For Java/JSP files only: returns the list of classes or packages which have been imported on demand (for example, javax.swing.*)

Parameters:
includeImplicit - if true, implicitly imported packages (like java.lang) are included.
checkIncludes - deprecated, no longer used
Returns:
the list of PsiClass or PsiPackage elements for the imports.

getSingleClassImports

@NotNull
PsiClass[] getSingleClassImports(@Deprecated
                                         boolean checkIncludes)
For Java/JSP files only: returns the list of classs which have been imported as single-class imports.

Parameters:
checkIncludes - deprecated, no longer used.
Returns:
the list of PsiClass elements for the import.

getImplicitlyImportedPackages

@NotNull
java.lang.String[] getImplicitlyImportedPackages()
For Java/JSP files only: returns the list of names of implicitly imported packages (for example, java.lang).

Returns:
the list of implicitly imported package names.

getImplicitlyImportedPackageReferences

@NotNull
PsiJavaCodeReferenceElement[] getImplicitlyImportedPackageReferences()
For Java/JSP files only: returns the list of reference elements for the implicitly imported packages (for example, java.lang).

Returns:
the list of implicitly imported package reference elements.

findImportReferenceTo

@Nullable
PsiJavaCodeReferenceElement findImportReferenceTo(PsiClass aClass)
For Java/JSP files only: returns the single-class import statement which references the specified class, or null if there is no such statement.

Parameters:
aClass - the class to return the import statement for.
Returns:
the Java code reference under the import statement, or null if there is no such statement.

getOriginalFile

@Nullable
PsiFile getOriginalFile()
If the file is a non-physical copy of a file, returns the original file which had been copied. Otherwise, returns null.

Returns:
the original file of a copy, or null if the file is not a copy.

canContainJavaCode

boolean canContainJavaCode()
Checks if the file is a Java source file or Java code fragment.

Returns:
true if the file is a Java source file or Java code fragment, false otherwise

getFileType

@NotNull
FileType getFileType()
Returns the file type for the file.

Returns:
the file type instance.

getPsiRoots

@NotNull
PsiFile[] getPsiRoots()
If the file contains multiple interspersed languages, returns the roots for PSI trees for each of these languages. (For example, a JSPX file contains JSP, XML and Java trees.)

Returns:
the array of PSI roots, or a single-element array containing this if the file has only a single language.

createPseudoPhysicalCopy

@NotNull
PsiFile createPseudoPhysicalCopy()
Creates a copy which is considered physical (see PsiElement.isPhysical()) for a PSI file which is not backed by a VirtualFile. This allows, for example, to obtain a Document instance for such a file.

Returns:
the pseudo-physical copy of the file.