Class JarReader


  • class JarReader
    extends java.lang.Object
    Reads entries from a source of class files, such as a jar or a "bin/" directory. This class acts as an intermediary between a raw LibraryInfo and the higher level Java completion classes. It caches information about classes and refreshes that cache when appropriate.
    Version:
    1.0
    • Field Detail

      • info

        private LibraryInfo info
        Information about the jar or directory we're reading classes from.
      • lastModified

        private long lastModified
    • Constructor Detail

      • JarReader

        JarReader​(LibraryInfo info)
           throws java.io.IOException
        Constructor.
        Parameters:
        info - The jar file to read from. This cannot be null.
        Throws:
        java.io.IOException - If an IO error occurs reading from the jar file.
    • Method Detail

      • addCompletions

        public void addCompletions​(org.fife.ui.autocomplete.CompletionProvider provider,
                                   java.lang.String[] pkgNames,
                                   java.util.Set<org.fife.ui.autocomplete.Completion> addTo)
        Gets the completions in this jar that match a given string.
        Parameters:
        provider - The parent completion provider.
        pkgNames - The text to match, split into tokens around the '.' character. This should be (the start of) a fully-qualified class, interface, or enum name.
        addTo - The list to add completion choices to.
      • checkLastModified

        private void checkLastModified()
        Checks whether the jar or class file directory has been modified since the last use of this reader. If it has, then any cached ClassFiles are cleared, in case any classes have been updated.
      • containsClass

        public boolean containsClass​(java.lang.String className)
      • containsPackage

        public boolean containsPackage​(java.lang.String pkgName)
      • getClassEntry

        public ClassFile getClassEntry​(java.lang.String[] items)
      • getClassesInPackage

        public void getClassesInPackage​(java.util.List<ClassFile> addTo,
                                        java.lang.String[] pkgs,
                                        boolean inPkg)
      • getClassesWithNamesStartingWith

        public java.util.List<ClassFile> getClassesWithNamesStartingWith​(java.lang.String prefix)
        Looks through all classes in this jar or directory, trying to find any whose unqualified names start with a given prefix.
        Parameters:
        prefix - The prefix of the class names. Case is ignored on this parameter.
        Returns:
        A list of ClassFiles representing classes in this jar or directory whose unqualified names start with the prefix. This will never be null, but may of course be empty.
      • getLibraryInfo

        public LibraryInfo getLibraryInfo()
        Returns the physical file on disk.

        Modifying the returned object will not have any effect on code completion; e.g. changing the source location will not have any effect.

        Returns:
        The info.
      • loadCompletions

        private void loadCompletions()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object