Class JavaManager

  • All Implemented Interfaces:
    IFolderFileChangeListener, org.eclipse.core.resources.IResourceDeltaVisitor, org.eclipse.core.resources.IResourceVisitor

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      booleanaddJavaResourceChangeListener​(IFolderFileChangeListener listener)
      Adds a resource change listener for Java projects.
      voidaddParser​(IJavaSourceParser<?> parser)
      Adds a parser.
      voidclean​(org.eclipse.jdt.core.IJavaProject javaProject)
      Cleans a project, called by the Java Compilation participant.
      voiddispose()
      Called when disposed of.
      booleandoesJavaProjectNeedRebuild​(org.eclipse.core.resources.IProject project)
      Checks if a Java project needs rebuild or not, i.e.
      voidenterRefactorHold()
      Call causing entering of refactoring operation, called from operations that perform "workspace threaded" operation such as moving resources affecting refactoring.
      voidexitRefactorHold()
      Exiting a refactor-hold operation (after a call to "enterRefactorHold").
      voidflagRefactoringRequired​(ParsedJavaSource js)
      A JavaSource flags the requirement for a refactoring operation.
      java.util.ArrayList<ParsedJavaSource>getAllParsedSources()
      Gets a new array of all ParsedJavaSource files containing a TypeFileProcessor and are valid.
      java.util.List<java.lang.String>getAvailableMethods​(org.eclipse.jdt.core.IType clazz, java.lang.String instanceAnnotation, java.lang.String staticAnnotation)
      Gets the list of methods that can match the specified annotations.
      java.lang.StringgetFullyQualifiedName​(org.eclipse.core.resources.IContainer folder)
      Gets the fully qualified package name for a folder.
      java.lang.StringgetFullyQualifiedName​(org.eclipse.core.runtime.IPath rootPath)
      From a full path (from the workspace root), get the fully qualified name of the package.
      static JavaManagergetInstance()
      Gets the instance of the singleton.
      JavaProjectgetJavaProject​(org.eclipse.core.resources.IProject project)
      Gets or creates new Java project for a project.
      org.eclipse.core.resources.IFolder[]getJavaSourceFolders​(org.eclipse.core.resources.IProject project)
      Gets the cached Java source folders for a project.
      ParsedJavaSourcegetParsedJavaSource​(org.eclipse.core.resources.IResource resource)
      Gets a ParsedJavaSource instance from a resource.
      ParsedJavaSourcegetParsedJavaSource​(org.eclipse.jdt.core.IType type)
      Gets a ParsedJavaSource instance from a type.
      java.lang.String[]getParserPluginIDs()
      Gets the parser plug-in IDs.
      java.util.List<JavaClass>getPublicOrStaticClasses()
      Gets all the JavaClasses available in all projects that are parsed.
      JavaProject[]getPureJavaProjects()
      Gets the pure Java projects, i.e.
      protected booleanisFileProcessed​(org.eclipse.core.resources.IFile file)
      Checks if file is processed.
      voidloadJavaState​(ModuleModel model, org.eclipse.core.runtime.IProgressMonitor monitor)
      Called when a Module project is loading, to load the Java parsed files.
      voidonClose​(org.eclipse.core.resources.IProject project)
      Called from ProjectManager when a project has been closed.
      voidonFileAdded​(org.eclipse.core.resources.IFile file)
      File has been added.
      voidonFileChanged​(org.eclipse.core.resources.IFile file, int flags)
      File has been changed (markers, contents, etc).
      voidonFileMoved​(org.eclipse.core.resources.IFile newFile, org.eclipse.core.resources.IFile oldFile)
      File has been moved.
      voidonFileRemoved​(org.eclipse.core.resources.IFile file)
      File has been removed.
      voidonFolderAdded​(org.eclipse.core.resources.IFolder folder)
      Folder has been added.
      voidonFolderMoved​(org.eclipse.core.resources.IFolder newFolder, org.eclipse.core.resources.IFolder oldFolder)
      File has been moved.
      voidonFolderRemoved​(org.eclipse.core.resources.IFolder folder)
      File has been removed.
      voidonOpen​(ModuleModel model)
      Called when a Module project is opened, to register itself in the JavaProject.
      voidonOpen​(org.eclipse.core.resources.IProject project, org.eclipse.core.runtime.IProgressMonitor monitor)
      Called when a project is a Java project, assigns the root and Java containers.
      voidonRefactoringChange​(org.eclipse.core.resources.IFile file, java.lang.String classFQN, java.lang.String oldFQN, java.lang.String newFQN)
      Called from Refactoring Rename for classes or methods.
      voidonRefactoringChange​(org.eclipse.core.runtime.IPath oldName, org.eclipse.core.runtime.IPath newName)
      Called from Refactoring Move or Rename or compilation units.
      booleanremoveJavaResourceChangeListener​(IFolderFileChangeListener listener)
      Removes a resource change listener for Java projects.
      booleanvisitResource​(org.eclipse.core.resources.IResourceDelta delta)
      Processes a resource when called from ProjectManager or ModuleModel visiting...
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEBUG

        public static boolean DEBUG
        Debug output.
    • Method Detail

      • getInstance

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

        public void onClose​(org.eclipse.core.resources.IProject project)
        Called from ProjectManager when a project has been closed.
      • dispose

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

        public boolean doesJavaProjectNeedRebuild​(org.eclipse.core.resources.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 java.lang.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​(org.eclipse.core.resources.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 org.eclipse.core.resources.IFolder[] getJavaSourceFolders​(org.eclipse.core.resources.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​(org.eclipse.core.resources.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​(org.eclipse.core.resources.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​(org.eclipse.core.resources.IFile file)
                         throws org.eclipse.core.runtime.CoreException
        File has been added.
        Specified by:
        onFileAdded in interface IFolderFileChangeListener
        Overrides:
        onFileAdded in class FileChangesCollection
        Parameters:
        file - The file.
        Throws:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFileChanged

        public void onFileChanged​(org.eclipse.core.resources.IFile file,
                                  int flags)
                           throws org.eclipse.core.runtime.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:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFileMoved

        public void onFileMoved​(org.eclipse.core.resources.IFile newFile,
                                org.eclipse.core.resources.IFile oldFile)
                         throws org.eclipse.core.runtime.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:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFileRemoved

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

        public java.lang.String getFullyQualifiedName​(org.eclipse.core.resources.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 java.lang.String getFullyQualifiedName​(org.eclipse.core.runtime.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​(org.eclipse.core.resources.IFolder folder)
                           throws org.eclipse.core.runtime.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:
        org.eclipse.core.runtime.CoreException - For failures.
      • onFolderMoved

        public void onFolderMoved​(org.eclipse.core.resources.IFolder newFolder,
                                  org.eclipse.core.resources.IFolder oldFolder)
                           throws org.eclipse.core.runtime.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:
        org.eclipse.core.runtime.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,
                                  org.eclipse.core.runtime.IProgressMonitor monitor)
        Called when a Module project is loading, to load the Java parsed files.
      • onOpen

        public void onOpen​(org.eclipse.core.resources.IProject project,
                           org.eclipse.core.runtime.IProgressMonitor monitor)
        Called when a project is a Java project, assigns the root and Java containers.
      • getAllParsedSources

        public java.util.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​(org.eclipse.core.runtime.IPath oldName,
                                        org.eclipse.core.runtime.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​(org.eclipse.core.resources.IFile file,
                                        java.lang.String classFQN,
                                        java.lang.String oldFQN,
                                        java.lang.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​(org.eclipse.jdt.core.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​(org.eclipse.jdt.core.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​(org.eclipse.core.resources.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 java.util.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 java.util.List<java.lang.String> getAvailableMethods​(org.eclipse.jdt.core.IType clazz,
                                                                    java.lang.String instanceAnnotation,
                                                                    java.lang.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.