com.intellij.psi
Class PsiManager

java.lang.Object
  extended by com.intellij.psi.PsiManager
All Implemented Interfaces:
UserDataHolder

public abstract class PsiManager
extends java.lang.Object
implements UserDataHolder

The main entry point for accessing the PSI services for a project.


Constructor Summary
PsiManager()
           
 
Method Summary
abstract  void addPsiTreeChangeListener(PsiTreeChangeListener listener)
          Adds a listener for receiving notifications about all changes in the PSI tree of the project.
abstract  boolean areElementsEquivalent(PsiElement element1, PsiElement element2)
          Checks if the specified two PSI elements (possibly invalid) represent the same source element (for example, a class with the same full-qualified name).
abstract  boolean arePackagesTheSame(PsiElement element1, PsiElement element2)
          Checks if the specified PSI elements belong to the same package.
abstract  void checkMove(PsiElement element, PsiElement newContainer)
          Checks if it is possible to move the specified PSI element under the specified container, and throws an exception if the move is not possible.
abstract  void dropResolveCaches()
          Clears the resolve caches of the PSI manager.
abstract  PsiClass findClass(java.lang.String qualifiedName)
          Deprecated. use findClass(String, GlobalSearchScope)
abstract  PsiClass findClass(java.lang.String qualifiedName, GlobalSearchScope scope)
          Searches the specified scope within the project for a class with the specified full-qualified name and returns one if it is found.
abstract  PsiClass[] findClasses(java.lang.String qualifiedName, GlobalSearchScope scope)
          Searches the specified scope within the project for classes with the specified full-qualified name and returns all found classes.
abstract  PsiDirectory findDirectory(VirtualFile file)
          Returns the PSI directory corresponding to the specified virtual file system directory.
abstract  PsiFile findFile(VirtualFile file)
          Returns the PSI file corresponding to the specified virtual file.
abstract  PsiPackage findPackage(java.lang.String qualifiedName)
          Searches the project for the package with the specified full-qualified name and retunrs one if it is found.
abstract  void finishBatchFilesProcessingMode()
          Notifies the PSI manager that a batch operation sequentially processing multiple files is finishing.
abstract  PsiAspectManager getAspectManager()
          Returns the aspect manager for the project, which can be used to access AspectJ-related functionality.
abstract  CachedValuesManager getCachedValuesManager()
          Returns the cached values manager for the project, which can be used to create values which are automatically recalculated based on changes of the elements on which they depend.
abstract  CodeStyleManager getCodeStyleManager()
          Returns the code style manager for the project.
abstract  PsiConstantEvaluationHelper getConstantEvaluationHelper()
          Returns the constant expression evaluator for the project.
abstract  LanguageLevel getEffectiveLanguageLevel()
          Returns the language level set for this project.
abstract  PsiElementFactory getElementFactory()
          Returns the element factory for the project, which can be used to create instances of Java and XML PSI elements.
static PsiManager getInstance(Project project)
          Returns the PSI manager instance for the specified project.
abstract  JavadocManager getJavadocManager()
          Returns the JavaDoc manager for the project, which can be used to retrieve information about JavaDoc tags known to IDEA.
abstract  PsiModificationTracker getModificationTracker()
          Returns the modification tracker for the project, which can be used to get the PSI modification count value.
abstract  PsiNameHelper getNameHelper()
          Returns the name helper for the project, which can be used to validate and parse Java identifiers.
abstract  Project getProject()
          Returns the project with which the PSI manager is associated.
abstract  PsiResolveHelper getResolveHelper()
          Returns the resolve helper for the project, which can be used to resolve references and check accessibility of elements.
abstract  PsiDirectory[] getRootDirectories(int rootType)
          Deprecated.  
abstract  PsiSearchHelper getSearchHelper()
          Returns the search helper for the project, which provides low-level search and find usages functionality.
abstract  PsiShortNamesCache getShortNamesCache()
          Returns the short name cache for the project, which can be used to locate files, classes, methods and fields by non-qualified names.
abstract  boolean isDisposed()
          Checks if the PSI manager has been disposed and the PSI for this project can no longer be used.
abstract  boolean isInPackage(PsiElement element, PsiPackage aPackage)
          Checks if the specified PSI element belongs to the specified package.
abstract  boolean isInProject(PsiElement element)
          Checks if the specified PSI element belongs to the sources of the project.
abstract  boolean isPartOfPackagePrefix(java.lang.String packageName)
          Checks if the specified package name is part of the package prefix for any of the modules in this project.
abstract  void moveDirectory(PsiDirectory dir, PsiDirectory newParentDir)
          Moves the specified directory to the specified parent directory.
abstract  void moveFile(PsiFile file, PsiDirectory newParentDir)
          Moves the specified file to the specified directory.
abstract  void performActionWithFormatterDisabled(java.lang.Runnable r)
          Disables automatic formatting of modified PSI elements, runs the specified operation and re-enables the formatting.
abstract  void registerShortNamesCache(PsiShortNamesCache cache)
          Registers a custom short name cache implementation for the project, which is used in addition to the standard IDEA implementation.
abstract  void reloadFromDisk(PsiFile file)
          Reloads the contents of the specified PSI file and its associated document (if any) from the disk.
abstract  void removePsiTreeChangeListener(PsiTreeChangeListener listener)
          Removes a listener for receiving notifications about all changes in the PSI tree of the project.
abstract  void setEffectiveLanguageLevel(LanguageLevel languageLevel)
          Sets the language level to use for this project.
abstract  void startBatchFilesProcessingMode()
          Notifies the PSI manager that a batch operation sequentially processing multiple files is starting.
abstract  PsiMigration startMigration()
          Initiates a migrate refactoring.
 
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
 

Constructor Detail

PsiManager

public PsiManager()
Method Detail

getInstance

@NotNull
public static PsiManager getInstance(@NotNull
                                             Project project)
Returns the PSI manager instance for the specified project.

Parameters:
project - the project for which the PSI manager is requested.
Returns:
the PSI manager instance.

getProject

@NotNull
public abstract Project getProject()
Returns the project with which the PSI manager is associated.

Returns:
the project instance.

getRootDirectories

@NotNull
public abstract PsiDirectory[] getRootDirectories(int rootType)
Deprecated. 


findFile

@Nullable
public abstract PsiFile findFile(@NotNull
                                          VirtualFile file)
Returns the PSI file corresponding to the specified virtual file.

Parameters:
file - the file for which the PSI is requested.
Returns:
the PSI file, or null if there is no PSI for the specified file in this project.

findDirectory

@Nullable
public abstract PsiDirectory findDirectory(@NotNull
                                                    VirtualFile file)
Returns the PSI directory corresponding to the specified virtual file system directory.

Parameters:
file - the directory for which the PSI is requested.
Returns:
the PSI directory, or null if there is no PSI for the specified directory in this project.

findClass

@Nullable
public abstract PsiClass findClass(@NotNull
                                            java.lang.String qualifiedName)
Deprecated. use findClass(String, GlobalSearchScope)

Searches the project and all its libraries for a class with the specified full-qualified name and returns one if it is found.

Parameters:
qualifiedName - the full-qualified name of the class to find.
Returns:
the PSI class, or null if no class with such name is found.

findClass

@Nullable
public abstract PsiClass findClass(@NotNull
                                            java.lang.String qualifiedName,
                                            @NotNull
                                            GlobalSearchScope scope)
Searches the specified scope within the project for a class with the specified full-qualified name and returns one if it is found.

Parameters:
qualifiedName - the full-qualified name of the class to find.
scope - the scope to search.
Returns:
the PSI class, or null if no class with such name is found.

findClasses

@NotNull
public abstract PsiClass[] findClasses(@NotNull
                                               java.lang.String qualifiedName,
                                               @NotNull
                                               GlobalSearchScope scope)
Searches the specified scope within the project for classes with the specified full-qualified name and returns all found classes.

Parameters:
qualifiedName - the full-qualified name of the class to find.
scope - the scope to search.
Returns:
the array of found classes, or an empty array if no classes are found.

findPackage

@Nullable
public abstract PsiPackage findPackage(@NotNull
                                                java.lang.String qualifiedName)
Searches the project for the package with the specified full-qualified name and retunrs one if it is found.

Parameters:
qualifiedName - the full-qualified name of the package to find.
Returns:
the PSI package, or null if no package with such name is found.

areElementsEquivalent

public abstract boolean areElementsEquivalent(@Nullable
                                              PsiElement element1,
                                              @Nullable
                                              PsiElement element2)
Checks if the specified two PSI elements (possibly invalid) represent the same source element (for example, a class with the same full-qualified name). Can be used to match two versions of the PSI tree with each other after a reparse.

Parameters:
element1 - the first element to check for equivalence
element2 - the second element to check for equivalence
Returns:
true if the elements are equivalent, false if the elements are different or it was not possible to determine the equivalence

reloadFromDisk

public abstract void reloadFromDisk(@NotNull
                                    PsiFile file)
Reloads the contents of the specified PSI file and its associated document (if any) from the disk.

Parameters:
file - the PSI file to reload.

addPsiTreeChangeListener

public abstract void addPsiTreeChangeListener(@NotNull
                                              PsiTreeChangeListener listener)
Adds a listener for receiving notifications about all changes in the PSI tree of the project.

Parameters:
listener - the listener instance.

removePsiTreeChangeListener

public abstract void removePsiTreeChangeListener(@NotNull
                                                 PsiTreeChangeListener listener)
Removes a listener for receiving notifications about all changes in the PSI tree of the project.

Parameters:
listener - the listener instance.

getCodeStyleManager

@NotNull
public abstract CodeStyleManager getCodeStyleManager()
Returns the code style manager for the project. The code style manager can be used to reformat code fragments, get names for elements according to the user's code style and work with import statements and full-qualified names.

Returns:
the code style manager instance.

getElementFactory

@NotNull
public abstract PsiElementFactory getElementFactory()
Returns the element factory for the project, which can be used to create instances of Java and XML PSI elements.

Returns:
the element factory instance.

getSearchHelper

@NotNull
public abstract PsiSearchHelper getSearchHelper()
Returns the search helper for the project, which provides low-level search and find usages functionality. It can be used to perform operations like finding references to an element, finding overriding / inheriting elements, finding to do items and so on.

Returns:
the search helper instance.

getResolveHelper

@NotNull
public abstract PsiResolveHelper getResolveHelper()
Returns the resolve helper for the project, which can be used to resolve references and check accessibility of elements.

Returns:
the resolve helper instance.

getShortNamesCache

@NotNull
public abstract PsiShortNamesCache getShortNamesCache()
Returns the short name cache for the project, which can be used to locate files, classes, methods and fields by non-qualified names.

Returns:
the short name cache instance.

registerShortNamesCache

public abstract void registerShortNamesCache(@NotNull
                                             PsiShortNamesCache cache)
Registers a custom short name cache implementation for the project, which is used in addition to the standard IDEA implementation. Should not be used by most plugins.

Parameters:
cache - the short name cache instance.

startMigration

@NotNull
public abstract PsiMigration startMigration()
Initiates a migrate refactoring. The refactoring is finished when PsiMigration.finish() is called.

Returns:
the migrate operation object.

getJavadocManager

@NotNull
public abstract JavadocManager getJavadocManager()
Returns the JavaDoc manager for the project, which can be used to retrieve information about JavaDoc tags known to IDEA.

Returns:
the JavaDoc manager instance.

getNameHelper

@NotNull
public abstract PsiNameHelper getNameHelper()
Returns the name helper for the project, which can be used to validate and parse Java identifiers.

Returns:
the name helper instance.

getConstantEvaluationHelper

@NotNull
public abstract PsiConstantEvaluationHelper getConstantEvaluationHelper()
Returns the constant expression evaluator for the project.

Returns:
the evaluator instance.

getModificationTracker

@NotNull
public abstract PsiModificationTracker getModificationTracker()
Returns the modification tracker for the project, which can be used to get the PSI modification count value.

Returns:
the modification tracker instance.

getAspectManager

@NotNull
public abstract PsiAspectManager getAspectManager()
Returns the aspect manager for the project, which can be used to access AspectJ-related functionality.

Returns:
the aspect manager instance.

getCachedValuesManager

@NotNull
public abstract CachedValuesManager getCachedValuesManager()
Returns the cached values manager for the project, which can be used to create values which are automatically recalculated based on changes of the elements on which they depend.

Returns:
the cached values manager instance.

moveFile

public abstract void moveFile(@NotNull
                              PsiFile file,
                              @NotNull
                              PsiDirectory newParentDir)
                       throws IncorrectOperationException
Moves the specified file to the specified directory.

Parameters:
file - the file to move.
newParentDir - the directory to move the file into.
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

moveDirectory

public abstract void moveDirectory(@NotNull
                                   PsiDirectory dir,
                                   @NotNull
                                   PsiDirectory newParentDir)
                            throws IncorrectOperationException
Moves the specified directory to the specified parent directory.

Parameters:
dir - the directory to move.
newParentDir - the directory to move dir into.
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

checkMove

public abstract void checkMove(@NotNull
                               PsiElement element,
                               @NotNull
                               PsiElement newContainer)
                        throws IncorrectOperationException
Checks if it is possible to move the specified PSI element under the specified container, and throws an exception if the move is not possible. Does not actually modify anything.

Parameters:
element - the element to check the move possibility.
newContainer - the target container element to move into.
Throws:
IncorrectOperationException - if the modification is not supported or not possible for some reason.

startBatchFilesProcessingMode

public abstract void startBatchFilesProcessingMode()
Notifies the PSI manager that a batch operation sequentially processing multiple files is starting. Memory occupied by cached PSI trees is released more eagerly during such a batch operation.


finishBatchFilesProcessingMode

public abstract void finishBatchFilesProcessingMode()
Notifies the PSI manager that a batch operation sequentially processing multiple files is finishing. Memory occupied by cached PSI trees is released more eagerly during such a batch operation.


isDisposed

public abstract boolean isDisposed()
Checks if the PSI manager has been disposed and the PSI for this project can no longer be used.

Returns:
true if the PSI manager is disposed, false otherwise.

getEffectiveLanguageLevel

@NotNull
public abstract LanguageLevel getEffectiveLanguageLevel()
Returns the language level set for this project.

Returns:
the language level instance.

isPartOfPackagePrefix

public abstract boolean isPartOfPackagePrefix(java.lang.String packageName)
Checks if the specified package name is part of the package prefix for any of the modules in this project.

Parameters:
packageName - the package name to check.
Returns:
true if it is part of the package prefix, false otherwise.

setEffectiveLanguageLevel

public abstract void setEffectiveLanguageLevel(@NotNull
                                               LanguageLevel languageLevel)
Sets the language level to use for this project. For tests only.

Parameters:
languageLevel - the language level to set.

dropResolveCaches

public abstract void dropResolveCaches()
Clears the resolve caches of the PSI manager. Can be used to reduce memory consumption in batch operations sequentially processing multiple files.


isInPackage

public abstract boolean isInPackage(@NotNull
                                    PsiElement element,
                                    @NotNull
                                    PsiPackage aPackage)
Checks if the specified PSI element belongs to the specified package.

Parameters:
element - the element to check the package for.
aPackage - the package to check.
Returns:
true if the element belongs to the package, false otherwise.

arePackagesTheSame

public abstract boolean arePackagesTheSame(@NotNull
                                           PsiElement element1,
                                           @NotNull
                                           PsiElement element2)
Checks if the specified PSI elements belong to the same package.

Parameters:
element1 - the first element to check.
element2 - the second element to check.
Returns:
true if the elements are in the same package, false otherwise.

isInProject

public abstract boolean isInProject(@NotNull
                                    PsiElement element)
Checks if the specified PSI element belongs to the sources of the project.

Parameters:
element - the element to check.
Returns:
true if the element belongs to the sources of the project, false otherwise.

performActionWithFormatterDisabled

public abstract void performActionWithFormatterDisabled(java.lang.Runnable r)
Disables automatic formatting of modified PSI elements, runs the specified operation and re-enables the formatting. Can be used to improve performance of PSI write operations.

Parameters:
r - the operation to run.