Class JarManager


  • public class JarManager
    extends java.lang.Object
    Manages a list of jars and gets completions from them. This can be shared amongst multiple JavaCompletionProvider instances.
    Version:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean checkModified
      Whether to check datestamps on jars/directories when completion information is requested.
      private java.util.List<JarReader> classFileSources
      Locations of class files to get completions from.
    • Constructor Summary

      Constructors 
      Constructor Description
      JarManager()
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addClassFileSource​(java.io.File jarFile)
      Adds a jar to read from.
      boolean addClassFileSource​(LibraryInfo info)
      Adds a class file source to read from.
      void addCompletions​(org.fife.ui.autocomplete.CompletionProvider p, java.lang.String text, java.util.Set<org.fife.ui.autocomplete.Completion> addTo)
      Adds completions matching the specified text to a list.
      void addCurrentJreClassFileSource()
      Adds the current JVM's rt.jar (or class.jar if on OS X) to the list of class file sources.
      void clearClassFileSources()
      Removes all class file sources from the "build path".
      static boolean getCheckModifiedDatestamps()
      Returns whether the "last modified" time stamp on jars and class directories should be checked whenever completions are requested, and if the jar/directory has been modified since the last time, reload any cached class file data.
      ClassFile getClassEntry​(java.lang.String className)
      Returns a class file's entry.
      java.util.List<ClassFile> getClassesInPackage​(java.lang.String pkgName, boolean inPkg)
      Returns all classes in a package.
      java.util.List<ClassFile> getClassesWithUnqualifiedName​(java.lang.String name, java.util.List<ImportDeclaration> importDeclarations)
      Returns a list of all classes/interfaces/enums with a given (unqualified) name.
      java.util.List<LibraryInfo> getClassFileSources()
      Returns the jars on the "build path".
      SourceLocation getSourceLocForClass​(java.lang.String className)
      Returns the source location for a specific class.
      boolean removeClassFileSource​(java.io.File jar)
      Removes a jar from the "build path".
      boolean removeClassFileSource​(LibraryInfo toRemove)
      Removes a class file source from the "build path".
      static void setCheckModifiedDatestamps​(boolean check)
      Sets whether the "last modified" time stamp on jars and class directories should be checked whenever completions are requested, and if the jar/directory has been modified since the last time, reload any cached class file data.
      • Methods inherited from class java.lang.Object

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

      • classFileSources

        private java.util.List<JarReader> classFileSources
        Locations of class files to get completions from.
      • checkModified

        private static boolean checkModified
        Whether to check datestamps on jars/directories when completion information is requested.
    • Constructor Detail

      • JarManager

        public JarManager()
        Constructor.
    • Method Detail

      • addCompletions

        public void addCompletions​(org.fife.ui.autocomplete.CompletionProvider p,
                                   java.lang.String text,
                                   java.util.Set<org.fife.ui.autocomplete.Completion> addTo)
        Adds completions matching the specified text to a list.
        Parameters:
        p - The parent completion provider.
        text - The text to match.
        addTo - The list to add completion choices to.
      • addClassFileSource

        public boolean addClassFileSource​(java.io.File jarFile)
                                   throws java.io.IOException
        Adds a jar to read from. This is a convenience method for folks only reading classes from jar files.
        Parameters:
        jarFile - The jar to add. This cannot be null.
        Returns:
        Whether this jar was added (e.g. it wasn't already loaded, or it has a new source path).
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        addClassFileSource(LibraryInfo), addCurrentJreClassFileSource(), getClassFileSources(), removeClassFileSource(File)
      • addClassFileSource

        public boolean addClassFileSource​(LibraryInfo info)
                                   throws java.io.IOException
        Adds a class file source to read from.
        Parameters:
        info - The source to add. If this is null, then the current JVM's main JRE jar (rt.jar, or classes.jar on OS X) will be added. If this source has already been added, adding it again will do nothing (except possibly update its attached source location).
        Returns:
        Whether this source was added (e.g. it wasn't already loaded, or it has a new source path).
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        addClassFileSource(File), addCurrentJreClassFileSource(), getClassFileSources(), removeClassFileSource(LibraryInfo)
      • addCurrentJreClassFileSource

        public void addCurrentJreClassFileSource()
                                          throws java.io.IOException
        Adds the current JVM's rt.jar (or class.jar if on OS X) to the list of class file sources. If the application is running in a JDK, the associated source zip is also located and used.
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        addClassFileSource(LibraryInfo)
      • getCheckModifiedDatestamps

        public static boolean getCheckModifiedDatestamps()
        Returns whether the "last modified" time stamp on jars and class directories should be checked whenever completions are requested, and if the jar/directory has been modified since the last time, reload any cached class file data. This allows for code completion to update whenever dependencies are rebuilt, but has the side effect of increased file I/O. By default this option is enabled; if you somehow find the file I/O to be a bottleneck (perhaps accessing jars over a slow NFS mount), you can disable this option.
        Returns:
        Whether jars/directories are checked for modification since the last access, and clear any cached completion information if so.
        See Also:
        setCheckModifiedDatestamps(boolean)
      • getClassEntry

        public ClassFile getClassEntry​(java.lang.String className)
        Returns a class file's entry.
        Parameters:
        className - The class name.
        Returns:
        Its entry, or null if it cannot be found.
      • getClassesWithUnqualifiedName

        public java.util.List<ClassFile> getClassesWithUnqualifiedName​(java.lang.String name,
                                                                       java.util.List<ImportDeclaration> importDeclarations)
        Returns a list of all classes/interfaces/enums with a given (unqualified) name. There may be several, since the name is unqualified.
        Parameters:
        name - The unqualified name of a type declaration.
        importDeclarations - The imports of the compilation unit, if any.
        Returns:
        A list of type declarations with the given name, or null if there are none.
      • getClassesInPackage

        public java.util.List<ClassFile> getClassesInPackage​(java.lang.String pkgName,
                                                             boolean inPkg)
        Returns all classes in a package.
        Parameters:
        pkgName - A package name.
        inPkg - Not sure here
        Returns:
        A list of all classes in that package.
      • getClassFileSources

        public java.util.List<LibraryInfo> getClassFileSources()
        Returns the jars on the "build path".
        Returns:
        A list of LibraryInfos. Modifying a LibraryInfo in this list will have no effect on this completion provider; in order to do that, you must re-add the jar via addClassFileSource(LibraryInfo). If there are no jars on the "build path," this will be an empty list.
        See Also:
        addClassFileSource(LibraryInfo)
      • getSourceLocForClass

        public SourceLocation getSourceLocForClass​(java.lang.String className)
        Returns the source location for a specific class.
        Parameters:
        className - The class.
        Returns:
        Its source location.
      • removeClassFileSource

        public boolean removeClassFileSource​(java.io.File jar)
        Removes a jar from the "build path". This is a convenience method for folks only adding and removing jar sources.
        Parameters:
        jar - The jar to remove.
        Returns:
        Whether the jar was removed. This will be false if the jar was not on the build path.
        See Also:
        removeClassFileSource(LibraryInfo), addClassFileSource(LibraryInfo), getClassFileSources()
      • setCheckModifiedDatestamps

        public static void setCheckModifiedDatestamps​(boolean check)
        Sets whether the "last modified" time stamp on jars and class directories should be checked whenever completions are requested, and if the jar/directory has been modified since the last time, reload any cached class file data. This allows for code completion to update whenever dependencies are rebuilt, but has the side effect of increased file I/O. By default this option is enabled; if you somehow find the file I/O to be a bottleneck (perhaps accessing jars over a slow NFS mount), you can disable this option.
        Parameters:
        check - Whether to check if any jars/directories have been modified since the last access, and clear any cached completion information if so.
        See Also:
        getCheckModifiedDatestamps()