Class LibraryInfo

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<LibraryInfo>
    Direct Known Subclasses:
    ClasspathLibraryInfo, DirLibraryInfo, JarLibraryInfo

    public abstract class LibraryInfo
    extends java.lang.Object
    implements java.lang.Comparable<LibraryInfo>, java.lang.Cloneable
    Information about a jar, compiled class folder, or other source of classes to add to the "build path" for Java completion. Instances of this class are added to a JarManager for each library that should be on the build path.

    This class also keeps track of an optional source location, such as a zip file or source folder. If defined, this location is used to find the .java source corresponding to the library's classes, which is used to display Javadoc comments during code completion.

    Version:
    1.0
    See Also:
    DirLibraryInfo, JarLibraryInfo, ClasspathLibraryInfo
    • Field Detail

      • sourceLoc

        private SourceLocation sourceLoc
        The location of the source files corresponding to this library. This may be null.
    • Constructor Detail

      • LibraryInfo

        public LibraryInfo()
    • Method Detail

      • bulkClassFileCreationStart

        public abstract void bulkClassFileCreationStart()
                                                 throws java.io.IOException
        Readies this library for many class files being fetched via createClassFileBulk(String). After calling this method, the actual class file fetching should be done in a try/finally block that ensures a call to bulkClassFileCreationEnd(); e.g.
         libInfo.bulkClassFileCreationStart();
         try {
            String entryName = ...;
            ClassFile cf = createClassFileBulk(entryName);
            ...
         } finally {
            libInfo.bulkClassFileCreationEnd();
         }
         
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        bulkClassFileCreationEnd(), createClassFileBulk(String)
      • clone

        public java.lang.Object clone()
        Returns a deep copy of this library.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A deep copy.
      • createClassFile

        public abstract ClassFile createClassFile​(java.lang.String entryName)
                                           throws java.io.IOException
        Returns the class file information for the specified class. Instances of JarReader can call this method to lazily load information on individual classes and shove it into their package maps.

        If many class files will be fetched at a time, you should prefer using bulkClassFileCreationStart() and createClassFileBulk(String) over this method, for performance reasons.

        Parameters:
        entryName - The fully qualified name of the class file.
        Returns:
        The class file, or null if it isn't found in this library.
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        createClassFileBulk(String)
      • createClassFileBulk

        public abstract ClassFile createClassFileBulk​(java.lang.String entryName)
                                               throws java.io.IOException
        Returns the class file information for the specified class. Instances of JarReader can call this method to lazily load information on individual classes and shove it into their package maps.

        This method should be used when multiple classes will be fetched from this library at the same time. It should only be called after a call to bulkClassFileCreationStart(). If only a single class file is being fetched, it is simpler to call createClassFile(String).

        Parameters:
        entryName - The fully qualified name of the class file.
        Returns:
        The class file, or null if it isn't found in this library.
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        createClassFile(String)
      • createPackageMap

        public abstract PackageMapNode createPackageMap()
                                                 throws java.io.IOException
        Creates and returns a map of maps representing the hierarchical package structure in this library.
        Returns:
        The package structure in this library.
        Throws:
        java.io.IOException - If an IO error occurs.
      • equals

        public boolean equals​(java.lang.Object o)
        Two LibraryInfos are considered equal if they represent the same class file location. Source attachment is irrelevant.
        Overrides:
        equals in class java.lang.Object
        Returns:
        Whether the specified instance represents the same class source as this one.
      • getJreJarInfo

        public static LibraryInfo getJreJarInfo​(java.io.File jreHome)
        Returns information on the "main" jar for a JRE. This will be rt.jar everywhere except OS X, where it will be classes.jar. The associated source zip/jar file is also checked for.
        Parameters:
        jreHome - The location of the JRE.
        Returns:
        The information, or null if there is not a JRE in the specified directory.
        See Also:
        getMainJreJarInfo()
      • getLastModified

        public abstract long getLastModified()
        Returns the time this library was last modified. For jar files, this would be the modified date of the file. For directories, this would be the time a file in the directory was most recently modified. This information is used to determine whether callers should clear their cached package map information and load it anew.

        This API may change in the future.

        Returns:
        The last time this library was modified.
      • getLocationAsString

        public abstract java.lang.String getLocationAsString()
        Returns the location of this library, as a string. If this library is contained in a single jar file, this will be the full path to that jar. If it is a directory containing classes, it will be the full path of the directory. Otherwise, this value will be null.
        Returns:
        The location of this library.
      • getMainJreJarInfo

        public static LibraryInfo getMainJreJarInfo()
        Returns information on the JRE running this application. This will be rt.jar everywhere except OS X, where it will be classes.jar. The associated source zip/jar file is also checked for.
        Returns:
        The information, or null if an error occurs.
        See Also:
        getJreJarInfo(File)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • hashCodeImpl

        public abstract int hashCodeImpl()
        Subclasses should override this method since equals(Object) is overridden. Instances of LibraryInfo aren't typically stored in maps, so the hash value isn't necessarily important to RSTALanguageSupport.
        Returns:
        The hash code for this library.
      • setSourceLocation

        public void setSourceLocation​(SourceLocation sourceLoc)
        Sets the location of the source corresponding to this library.
        Parameters:
        sourceLoc - The source location. This may be null.
        See Also:
        getSourceLocation()