Class Util


  • public final class Util
    extends java.lang.Object
    Utility methods for Java completion.
    Version:
    1.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Util()
      Private constructor to prevent instantiation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void appendDocCommentTail​(java.lang.StringBuilder sb, java.lang.StringBuilder tail)  
      private static void appendLinkTagText​(java.lang.StringBuilder appendTo, java.lang.String linkContent)
      Appends HTML representing a "link" or "linkplain" Javadoc element to a string buffer.
      static java.lang.String docCommentToHtml​(java.lang.String dc)
      Converts a Java documentation comment to HTML.
      private static java.lang.StringBuilder fixDocComment​(java.lang.StringBuilder text)  
      private static java.lang.String fixLinkText​(java.lang.String text)
      Tidies up a link's display text for use in a <a> tag.
      private static java.lang.String forXML​(java.lang.String aText)  
      static CompilationUnit getCompilationUnitFromDisk​(SourceLocation loc, ClassFile cf)
      Used by MemberCompletion.Data implementations to get an AST from a source file in a SourceLocation.
      static java.lang.String getUnqualified​(java.lang.String clazz)
      Returns the "unqualified" version of a (possibly) fully-qualified class name.
      private static int indexOf​(char ch, java.lang.CharSequence sb, int offs)
      Returns the next location of a single character in a character sequence.
      static boolean isFullyQualified​(java.lang.String str)
      Returns whether the specified string is "fully qualified," that is, whether it contains a '.' character.
      private static boolean isInPreBlock​(java.lang.String line, boolean prevValue)
      Returns whether this line ends in the middle of a pre-block.
      private static java.lang.String possiblyStripDocCommentTail​(java.lang.String str)
      Removes the tail end of a documentation comment from a string, if it exists.
      static java.lang.String[] splitOnChar​(java.lang.String str, int ch)
      A faster way to split on a single char than String#split(), since we'll be doing this in a tight loop possibly thousands of times (rt.jar).
      • Methods inherited from class java.lang.Object

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

      • DOC_COMMENT_LINE_HEADER

        static final java.util.regex.Pattern DOC_COMMENT_LINE_HEADER
        Optional leading text for doc comment lines (except the first line) that should be removed if it exists.
      • LINK_TAG_MEMBER_PATTERN

        static final java.util.regex.Pattern LINK_TAG_MEMBER_PATTERN
        Pattern matching a link in a "@link" tag. This should match the following:
        • ClassName
        • fully.qualified.ClassName
        • #method
        • #method(int, int)
        • String#method
        • String#method(params)
        • fully.qualified.ClassName#method
        • fully.qualified.ClassName#method(params)
        Hyperlinks ("<a href=...") are not matched and should be handled separately.
      • lastCUClassFileParam

        private static ClassFile lastCUClassFileParam
    • Constructor Detail

      • Util

        private Util()
        Private constructor to prevent instantiation.
    • Method Detail

      • appendDocCommentTail

        private static void appendDocCommentTail​(java.lang.StringBuilder sb,
                                                 java.lang.StringBuilder tail)
      • appendLinkTagText

        private static void appendLinkTagText​(java.lang.StringBuilder appendTo,
                                              java.lang.String linkContent)
        Appends HTML representing a "link" or "linkplain" Javadoc element to a string buffer.

        For some information on this format, see http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#see.

        Parameters:
        appendTo - The buffer to append to.
        linkContent - The content of a "link", "linkplain" or "see" item.
      • docCommentToHtml

        public static java.lang.String docCommentToHtml​(java.lang.String dc)
        Converts a Java documentation comment to HTML.
         This is a
         pre block
         
        Parameters:
        dc - The documentation comment.
        Returns:
        An HTML version of the comment.
      • forXML

        private static java.lang.String forXML​(java.lang.String aText)
      • fixDocComment

        private static java.lang.StringBuilder fixDocComment​(java.lang.StringBuilder text)
      • fixLinkText

        private static java.lang.String fixLinkText​(java.lang.String text)
        Tidies up a link's display text for use in a <a> tag.
        Parameters:
        text - The text (a class, method, or field signature).
        Returns:
        The display value for the signature.
      • getCompilationUnitFromDisk

        public static CompilationUnit getCompilationUnitFromDisk​(SourceLocation loc,
                                                                 ClassFile cf)
        Used by MemberCompletion.Data implementations to get an AST from a source file in a SourceLocation. Classes should prefer this method over calling into the location directly since this method caches the most recent result for performance.
        Parameters:
        loc - A directory or zip/jar file.
        cf - The ClassFile representing the source grab from the location.
        Returns:
        The compilation unit, or null if it is not found or an IO error occurs.
      • getUnqualified

        public static java.lang.String getUnqualified​(java.lang.String clazz)
        Returns the "unqualified" version of a (possibly) fully-qualified class name.
        Parameters:
        clazz - The class name.
        Returns:
        The unqualified version of the name.
      • indexOf

        private static int indexOf​(char ch,
                                   java.lang.CharSequence sb,
                                   int offs)
        Returns the next location of a single character in a character sequence. This method is here because StringBuilder doesn't get this method added to it until Java 1.5.
        Parameters:
        ch - The character to look for.
        sb - The character sequence.
        offs - The offset at which to start looking.
        Returns:
        The next location of the character, or -1 if it is not found.
      • isFullyQualified

        public static boolean isFullyQualified​(java.lang.String str)
        Returns whether the specified string is "fully qualified," that is, whether it contains a '.' character.
        Parameters:
        str - The string to check.
        Returns:
        Whether the string is fully qualified.
        See Also:
        getUnqualified(String)
      • isInPreBlock

        private static boolean isInPreBlock​(java.lang.String line,
                                            boolean prevValue)
        Returns whether this line ends in the middle of a pre-block.
        Parameters:
        line - The line's contents.
        prevValue - Whether this line started in a pre-block.
        Returns:
        Whether the line ends in a pre-block.
      • possiblyStripDocCommentTail

        private static java.lang.String possiblyStripDocCommentTail​(java.lang.String str)
        Removes the tail end of a documentation comment from a string, if it exists.
        Parameters:
        str - The string.
        Returns:
        The string, possibly with the documentation comment tail removed.
      • splitOnChar

        public static java.lang.String[] splitOnChar​(java.lang.String str,
                                                     int ch)
        A faster way to split on a single char than String#split(), since we'll be doing this in a tight loop possibly thousands of times (rt.jar). This is also fundamentally different from String.split(String)), in the case where str ends with ch - this method will return an empty item at the end of the returned array, while String#split() will not.
        Parameters:
        str - The string to split.
        ch - The char to split on.
        Returns:
        The string, split on the character (e.g. '/' or '.').