Class JavaManager

All Implemented Interfaces:
IFolderFileChangeListener, IResourceDeltaVisitor, IResourceVisitor

public class JavaManager extends FileChangesCollection
Class used to listen to workspace changes file in any Java project.
Author:
Christopher Mindus
  • Field Details

    • DEBUG

      public static boolean DEBUG
      Debug output.
  • Method Details

    • getInstance

      public static JavaManager getInstance()
      Gets the instance of the singleton.
    • onClose

      public void onClose(IProject project)
      Called from ProjectManager when a project has been closed.
    • dispose

      public void dispose()
      Called when disposed of.
    • doesJavaProjectNeedRebuild

      public boolean doesJavaProjectNeedRebuild(IProject project)
      Checks if a Java project needs rebuild or not, i.e. when first opened.
      Returns:
      true if a full build is required, false otherwise.
    • addParser

      public void addParser(IJavaSourceParser<?> parser)
      Adds a parser. This should be done as soon as possible.
    • getParserPluginIDs

      public String[] getParserPluginIDs()
      Gets the parser plug-in IDs.
    • addJavaResourceChangeListener

      public boolean addJavaResourceChangeListener(IFolderFileChangeListener listener)
      Adds a resource change listener for Java projects. If the listener also implements the interface com.iizigo.java.IClasspathChangeListener, it will receive notifications when the classpath is changed.
      Parameters:
      listener - The listener.
      Returns:
      true if successful, false for already added.
    • removeJavaResourceChangeListener

      public boolean removeJavaResourceChangeListener(IFolderFileChangeListener listener)
      Removes a resource change listener for Java projects.
      Parameters:
      listener - The listener.
      Returns:
      true if successful, false for already added.
    • getJavaProject

      public JavaProject getJavaProject(IProject project)
      Gets or creates new Java project for a project.
      Returns:
      null if not a Java project or project is not open.
    • getPureJavaProjects

      public JavaProject[] getPureJavaProjects()
      Gets the pure Java projects, i.e. excluding Module projects.
      Returns:
      The array of projects, never null.
    • getJavaSourceFolders

      public IFolder[] getJavaSourceFolders(IProject project)
      Gets the cached Java source folders for a project.
      Parameters:
      project - The project.
      Returns:
      null if not a Java project.
    • visitResource

      public boolean visitResource(IResourceDelta delta)
      Processes a resource when called from ProjectManager or ModuleModel visiting...
      Returns:
      true if the resource and children has been processed, false otherwise.
    • isFileProcessed

      protected boolean isFileProcessed(IFile file)
      Checks if file is processed.
      Overrides:
      isFileProcessed in class FileChangesCollection
      Parameters:
      file - The file.
      Returns:
      true if file is a Java source file, false otherwise.
    • onFileAdded

      public void onFileAdded(IFile file) throws CoreException
      File has been added.
      Specified by:
      onFileAdded in interface IFolderFileChangeListener
      Overrides:
      onFileAdded in class FileChangesCollection
      Parameters:
      file - The file.
      Throws:
      CoreException - For failures.
    • onFileChanged

      public void onFileChanged(IFile file, int flags) throws CoreException
      File has been changed (markers, contents, etc).

      Subclasses should override to process the event, no need to call the super method.

      Specified by:
      onFileChanged in interface IFolderFileChangeListener
      Overrides:
      onFileChanged in class FileChangesCollection
      Parameters:
      file - The file.
      flags - How the file was changed, from IResourceDelta, where the important ones are CONTENT, MARKERS, ENCODING, LOCAL_CHANGE, DERIVED_CHANGED, REPLACED.
      Throws:
      CoreException - For failures.
    • onFileMoved

      public void onFileMoved(IFile newFile, IFile oldFile) throws CoreException
      File has been moved.
      Specified by:
      onFileMoved in interface IFolderFileChangeListener
      Overrides:
      onFileMoved in class FileChangesCollection
      Parameters:
      newFile - The new file.
      oldFile - The old file.
      Throws:
      CoreException - For failures.
    • onFileRemoved

      public void onFileRemoved(IFile file) throws CoreException
      File has been removed.
      Specified by:
      onFileRemoved in interface IFolderFileChangeListener
      Overrides:
      onFileRemoved in class FileChangesCollection
      Parameters:
      file - The file.
      Throws:
      CoreException - For failures.
    • getFullyQualifiedName

      public String getFullyQualifiedName(IContainer folder)
      Gets the fully qualified package name for a folder.
      Parameters:
      folder - The folder name.
      Returns:
      The fully qualified package name, null if not inside a Java project source folder.
    • getFullyQualifiedName

      public String getFullyQualifiedName(IPath rootPath)
      From a full path (from the workspace root), get the fully qualified name of the package.
      Parameters:
      rootPath - The root path of a folder.
      Returns:
      The fully qualified package name, null if not inside a Java project source folder.
    • onFolderAdded

      public void onFolderAdded(IFolder folder) throws CoreException
      Folder has been added.

      Subclasses should override to process the event, no need to call the super method.

      Specified by:
      onFolderAdded in interface IFolderFileChangeListener
      Overrides:
      onFolderAdded in class FileChangesCollection
      Parameters:
      folder - The folder.
      Throws:
      CoreException - For failures.
    • onFolderMoved

      public void onFolderMoved(IFolder newFolder, IFolder oldFolder) throws CoreException
      File has been moved.
      Specified by:
      onFolderMoved in interface IFolderFileChangeListener
      Overrides:
      onFolderMoved in class FileChangesCollection
      Parameters:
      newFolder - The new folder.
      oldFolder - The old folder.
      Throws:
      CoreException - For failures.
    • onFolderRemoved

      public void onFolderRemoved(IFolder folder) throws CoreException
      File has been removed.
      Specified by:
      onFolderRemoved in interface IFolderFileChangeListener
      Overrides:
      onFolderRemoved in class FileChangesCollection
      Parameters:
      folder - The folder.
      Throws:
      CoreException - For failures.
    • onOpen

      public void onOpen(ModuleModel model)
      Called when a Module project is opened, to register itself in the JavaProject.
    • loadJavaState

      public void loadJavaState(ModuleModel model, IProgressMonitor monitor)
      Called when a Module project is loading, to load the Java parsed files.
    • onOpen

      public void onOpen(IProject project, IProgressMonitor monitor)
      Called when a project is a Java project, assigns the root and Java containers.
    • getAllParsedSources

      public ArrayList<ParsedJavaSource> getAllParsedSources()
      Gets a new array of all ParsedJavaSource files containing a TypeFileProcessor and are valid. The array can be modified without affecting anything.
    • onRefactoringChange

      public void onRefactoringChange(IPath oldName, IPath newName)
      Called from Refactoring Move or Rename or compilation units.
      Parameters:
      oldName - Full path of old Java file.
      newName - Full path of new Java file.
    • onRefactoringChange

      public void onRefactoringChange(IFile file, String classFQN, String oldFQN, String newFQN)
      Called from Refactoring Rename for classes or methods. The "FQN" is for classes including packages, and enclosed classes are separated by '.' and not '$'. For methods, it's the name followed by ',' and "returnType(param1,..,paramN)" as JavaHelper.getSignature gives.
      Parameters:
      file - Affected Java source file.
      classFQN - The class fully qualified name, null for classes (only for methods).
      oldFQN - The old fully qualified name or "oldName,signature".
      newFQN - The new fully qualified name or "newName,signature".
    • clean

      public void clean(IJavaProject javaProject)
      Cleans a project, called by the Java Compilation participant.
      Parameters:
      javaProject - The project to clean.
    • enterRefactorHold

      public void enterRefactorHold()
      Call causing entering of refactoring operation, called from operations that perform "workspace threaded" operation such as moving resources affecting refactoring.
    • exitRefactorHold

      public void exitRefactorHold()
      Exiting a refactor-hold operation (after a call to "enterRefactorHold").
    • flagRefactoringRequired

      public void flagRefactoringRequired(ParsedJavaSource js)
      A JavaSource flags the requirement for a refactoring operation. The refactoring requirement arises from a change in the references due to: - moved properties, using drag-drop or by dialog box (both int SWT-thread), - renamed and/or moved properties, from drag-drop or dialog box (runs in a "workspace" thread). When this is called, a refactoring operations is triggered in the
      Parameters:
      js -
    • getParsedJavaSource

      public ParsedJavaSource getParsedJavaSource(IType type)
      Gets a ParsedJavaSource instance from a type.
      Parameters:
      type - The type.
      Returns:
      The ParsedJavaSource instance, or null if not found.
    • getParsedJavaSource

      public ParsedJavaSource getParsedJavaSource(IResource resource)
      Gets a ParsedJavaSource instance from a resource.
      Parameters:
      resource - The resource, should be an IFile, otherwise it returns null.
      Returns:
      The ParsedJavaSource instance, or null if not found.
    • getPublicOrStaticClasses

      public List<JavaClass> getPublicOrStaticClasses()
      Gets all the JavaClasses available in all projects that are parsed. Matching classes are public and public static inner classes.
    • getAvailableMethods

      public List<String> getAvailableMethods(IType clazz, String instanceAnnotation, String staticAnnotation)
      Gets the list of methods that can match the specified annotations.
      Parameters:
      clazz - The class to search in for the instanceAnnotation.
      instanceAnnotation - The instance annotation to search the class for, null for none.
      staticAnnotation - Static annotation to search classes for static methods.