Class JarManager

java.lang.Object
org.fife.rsta.ac.java.JarManager

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

    • classFileSources

      private 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 Details

    • JarManager

      public JarManager()
      Constructor.
  • Method Details

    • addCompletions

      public void addCompletions(org.fife.ui.autocomplete.CompletionProvider p, String text, 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(File jarFile) throws 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:
      IOException - If an IO error occurs.
      See Also:
    • addClassFileSource

      public boolean addClassFileSource(LibraryInfo info) throws 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:
      IOException - If an IO error occurs.
      See Also:
    • addCurrentJreClassFileSource

      public void addCurrentJreClassFileSource() throws 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:
      IOException - If an IO error occurs.
      See Also:
    • clearClassFileSources

      public void clearClassFileSources()
      Removes all class file sources from the "build path".
      See Also:
    • 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:
    • getClassEntry

      public ClassFile getClassEntry(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 List<ClassFile> getClassesWithUnqualifiedName(String name, 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 List<ClassFile> getClassesInPackage(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 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:
    • getSourceLocForClass

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

      public boolean removeClassFileSource(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

      public boolean removeClassFileSource(LibraryInfo toRemove)
      Removes a class file source from the "build path".
      Parameters:
      toRemove - The source to remove.
      Returns:
      Whether source jar was removed. This will be false if the source was not on the build path.
      See Also:
    • 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: