java.lang.Object
org.aspectj.org.eclipse.jdt.internal.compiler.util.Util
All Implemented Interfaces:
SuffixConstants

public class Util extends Object implements SuffixConstants
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    Character constant indicating an array type in a signature.
    static final char
    Character constant indicating the primitive type boolean in a signature.
    static final char
    Character constant indicating the primitive type byte in a signature.
    static final char
    Character constant indicating a capture of a wildcard type in a signature.
    static final char
    Character constant indicating the primitive type char in a signature.
    static final char
    Character constant indicating the colon in a signature.
    static final char
    Character constant indicating the dollar in a signature.
    static final char
    Character constant indicating the dot in a signature.
    static final char
    Character constant indicating the primitive type double in a signature.
    static final char
    Character constant indicating an exception in a signature.
    static final char
    Character constant indicating a bound wildcard type argument in a signature with extends clause.
    static final char
    Character constant indicating the primitive type float in a signature.
    static final char
    Character constant indicating the end of a generic type list in a signature.
    static final char
    Character constant indicating the start of a formal type parameter (or type argument) list in a signature.
    static final char
    Character constant indicating the primitive type int in a signature.
    static final char
    Character constant indicating the primitive type long in a signature.
    static final char
    Character constant indicating the end of a named type in a signature.
    static final char
    Character constant indicating the end of a parameter type list in a signature.
    static final char
    Character constant indicating the start of a parameter type list in a signature.
    static final char
    Character constant indicating the start of a resolved, named type in a signature.
    static final char
    Character constant indicating the semicolon in a signature.
    static final char
    Character constant indicating the primitive type short in a signature.
    static final char
    Character constant indicating an unbound wildcard type argument in a signature.
    static final char
    Character constant indicating a bound wildcard type argument in a signature with super clause.
    static final char
    Character constant indicating the start of a resolved type variable in a signature.
    static final char
    Character constant indicating the start of an unresolved, named type in a signature.
    static final char
    Character constant indicating result type void in a signature.
    static final String
     
    static final int[]
     
    static final String
     
    static final int
     
    static final String
     
    static final String
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    appendEscapedChar(StringBuilder buffer, char c, boolean stringLiteral)
     
    static final int
    Returns the kind of archive this file is.
    static String
    buildAllDirectoriesInto(String outputPath, String relativeFileName)
    Build all the directories and subdirectories corresponding to the packages names into the directory specified in parameters.
    static char[]
    bytesToChar(byte[] bytes, String encoding)
    Returns the given bytes as a char array using a given encoding (null means platform default).
     
     
    static void
     
    static void
     
    static int
    computeOuterMostVisibility(TypeDeclaration typeDeclaration, int visibility)
    Returns the outer most enclosing type's visibility for the given TypeDeclaration and visibility based on compiler options.
    static boolean
     
    static String
    Returns a one line summary for an exception (extracted from its stacktrace: name + first frame)
    static byte[]
    Returns the contents of the given file as a byte array.
    static char[]
    getFileCharContent(File file, String encoding)
    Returns the contents of the given file as a char array.
    static byte[]
    Returns the given input stream's contents as a byte array.
    static char[]
    Returns the given input stream's contents as a character array.
    static File
     
    static long
    getJDKLevel(File javaHome)
     
    static int
    getLineNumber(int position, int[] lineEnds, int g, int d)
     
    static int
    getParameterCount(char[] methodSignature)
     
     
    static byte[]
    Returns the contents of the given zip entry as a byte array.
    static int
    hashCode(Object[] array)
     
    static final boolean
     
    static final boolean
    isClassFileName(char[] name)
    Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
    static final boolean
    Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
    static final boolean
    isExcluded(char[] path, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean isFolderPath)
     
    static final boolean
    isJavaFileName(char[] name)
    Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
    static final boolean
    Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
    static final boolean
    isJrt(String name)
    Returns true iff str.toLowerCase().endsWith("jrt-fs.jar") implementation is not creating extra strings.
    static final boolean
    Returns whether the given name is potentially a zip archive file name (it has a file extension and it is not ".java" nor ".class")
    static byte[]
    readNBytes(InputStream input, int byteLength)
    Returns the given input stream's first bytes as array.
    static void
    recordNestedType(ClassFile classFile, TypeBinding typeBinding)
     
    static void
    reverseQuickSort(char[][] list, int left, int right)
     
    static void
    reverseQuickSort(char[][] list, int left, int right, int[] result)
     
    static int
    scanArrayTypeSignature(char[] string, int start)
    Scans the given string for an array type signature starting at the given index and returns the index of the last character.
    static int
    scanBaseTypeSignature(char[] string, int start)
    Scans the given string for a base type signature starting at the given index and returns the index of the last character.
    static int
    scanCaptureTypeSignature(char[] string, int start)
    Scans the given string for a capture of a wildcard type signature starting at the given index and returns the index of the last character.
    static int
    scanClassTypeSignature(char[] string, int start)
    Scans the given string for a class type signature starting at the given index and returns the index of the last character.
    static int
    scanIdentifier(char[] string, int start)
    Scans the given string for an identifier starting at the given index and returns the index of the last character.
    static int
    scanTypeArgumentSignature(char[] string, int start)
    Scans the given string for a type argument signature starting at the given index and returns the index of the last character.
    static int
    scanTypeArgumentSignatures(char[] string, int start)
    Scans the given string for a list of type argument signatures starting at the given index and returns the index of the last character.
    static int
    scanTypeBoundSignature(char[] string, int start)
    Scans the given string for a type bound signature starting at the given index and returns the index of the last character.
    static int
    scanTypeSignature(char[] string, int start)
    Scans the given string for a type signature starting at the given index and returns the index of the last character.
    static int
    scanTypeVariableSignature(char[] string, int start)
    Scans the given string for a type variable signature starting at the given index and returns the index of the last character.
    static final int
    searchColumnNumber(int[] startLineIndexes, int lineNumber, int position)
    INTERNAL USE-ONLY Search the column number corresponding to a specific position
    static Boolean
    toBoolean(boolean bool)
    Converts a boolean value into Boolean.
    static String
    toString(Object[] objects)
    Converts an array of Objects into String.
    static String
    toString(Object[] objects, Util.Displayable renderer)
    Converts an array of Objects into String.
    static void
    writeToDisk(boolean generatePackagesStructure, String outputPath, String relativeFileName, ClassFile classFile)
    outputPath is formed like: c:\temp\ the last character is a file separator relativeFileName is formed like: java\lang\String.class

    Methods inherited from class java.lang.Object

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

    • C_BOOLEAN

      public static final char C_BOOLEAN
      Character constant indicating the primitive type boolean in a signature. Value is 'Z'.
      See Also:
    • C_BYTE

      public static final char C_BYTE
      Character constant indicating the primitive type byte in a signature. Value is 'B'.
      See Also:
    • C_CHAR

      public static final char C_CHAR
      Character constant indicating the primitive type char in a signature. Value is 'C'.
      See Also:
    • C_DOUBLE

      public static final char C_DOUBLE
      Character constant indicating the primitive type double in a signature. Value is 'D'.
      See Also:
    • C_FLOAT

      public static final char C_FLOAT
      Character constant indicating the primitive type float in a signature. Value is 'F'.
      See Also:
    • C_INT

      public static final char C_INT
      Character constant indicating the primitive type int in a signature. Value is 'I'.
      See Also:
    • C_SEMICOLON

      public static final char C_SEMICOLON
      Character constant indicating the semicolon in a signature. Value is ';'.
      See Also:
    • C_COLON

      public static final char C_COLON
      Character constant indicating the colon in a signature. Value is ':'.
      Since:
      3.0
      See Also:
    • C_LONG

      public static final char C_LONG
      Character constant indicating the primitive type long in a signature. Value is 'J'.
      See Also:
    • C_SHORT

      public static final char C_SHORT
      Character constant indicating the primitive type short in a signature. Value is 'S'.
      See Also:
    • C_VOID

      public static final char C_VOID
      Character constant indicating result type void in a signature. Value is 'V'.
      See Also:
    • C_TYPE_VARIABLE

      public static final char C_TYPE_VARIABLE
      Character constant indicating the start of a resolved type variable in a signature. Value is 'T'.
      Since:
      3.0
      See Also:
    • C_STAR

      public static final char C_STAR
      Character constant indicating an unbound wildcard type argument in a signature. Value is '*'.
      Since:
      3.0
      See Also:
    • C_EXCEPTION_START

      public static final char C_EXCEPTION_START
      Character constant indicating an exception in a signature. Value is '^'.
      Since:
      3.1
      See Also:
    • C_EXTENDS

      public static final char C_EXTENDS
      Character constant indicating a bound wildcard type argument in a signature with extends clause. Value is '+'.
      Since:
      3.1
      See Also:
    • C_SUPER

      public static final char C_SUPER
      Character constant indicating a bound wildcard type argument in a signature with super clause. Value is '-'.
      Since:
      3.1
      See Also:
    • C_DOT

      public static final char C_DOT
      Character constant indicating the dot in a signature. Value is '.'.
      See Also:
    • C_DOLLAR

      public static final char C_DOLLAR
      Character constant indicating the dollar in a signature. Value is '$'.
      See Also:
    • C_ARRAY

      public static final char C_ARRAY
      Character constant indicating an array type in a signature. Value is '['.
      See Also:
    • C_RESOLVED

      public static final char C_RESOLVED
      Character constant indicating the start of a resolved, named type in a signature. Value is 'L'.
      See Also:
    • C_UNRESOLVED

      public static final char C_UNRESOLVED
      Character constant indicating the start of an unresolved, named type in a signature. Value is 'Q'.
      See Also:
    • C_NAME_END

      public static final char C_NAME_END
      Character constant indicating the end of a named type in a signature. Value is ';'.
      See Also:
    • C_PARAM_START

      public static final char C_PARAM_START
      Character constant indicating the start of a parameter type list in a signature. Value is '('.
      See Also:
    • C_PARAM_END

      public static final char C_PARAM_END
      Character constant indicating the end of a parameter type list in a signature. Value is ')'.
      See Also:
    • C_GENERIC_START

      public static final char C_GENERIC_START
      Character constant indicating the start of a formal type parameter (or type argument) list in a signature. Value is '<'.
      Since:
      3.0
      See Also:
    • C_GENERIC_END

      public static final char C_GENERIC_END
      Character constant indicating the end of a generic type list in a signature. Value is '>'.
      Since:
      3.0
      See Also:
    • C_CAPTURE

      public static final char C_CAPTURE
      Character constant indicating a capture of a wildcard type in a signature. Value is '!'.
      Since:
      3.1
      See Also:
    • UTF_8

      public static final String UTF_8
      See Also:
    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
    • EMPTY_STRING

      public static final String EMPTY_STRING
    • COMMA_SEPARATOR

      public static final String COMMA_SEPARATOR
      Since:
      3.14
    • EMPTY_INT_ARRAY

      public static final int[] EMPTY_INT_ARRAY
    • ZIP_FILE

      public static final int ZIP_FILE
      See Also:
    • JMOD_FILE

      public static final int JMOD_FILE
      See Also:
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • buildAllDirectoriesInto

      public static String buildAllDirectoriesInto(String outputPath, String relativeFileName) throws IOException
      Build all the directories and subdirectories corresponding to the packages names into the directory specified in parameters. outputPath is formed like: c:\temp\ the last character is a file separator relativeFileName is formed like: java\lang\String.class *
      Parameters:
      outputPath - java.lang.String
      relativeFileName - java.lang.String
      Returns:
      java.lang.String
      Throws:
      IOException
    • bytesToChar

      public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException
      Returns the given bytes as a char array using a given encoding (null means platform default).
      Throws:
      IOException
    • computeOuterMostVisibility

      public static int computeOuterMostVisibility(TypeDeclaration typeDeclaration, int visibility)
      Returns the outer most enclosing type's visibility for the given TypeDeclaration and visibility based on compiler options.
    • getFileByteContent

      public static byte[] getFileByteContent(File file) throws IOException
      Returns the contents of the given file as a byte array.
      Throws:
      IOException - if a problem occured reading the file.
    • getFileCharContent

      public static char[] getFileCharContent(File file, String encoding) throws IOException
      Returns the contents of the given file as a char array. When encoding is null, then the platform default one is used
      Throws:
      IOException - if a problem occured reading the file.
    • getInputStreamAsByteArray

      public static byte[] getInputStreamAsByteArray(InputStream input) throws IOException
      Returns the given input stream's contents as a byte array. All bytes in the stream are returned. Note this doesn't close the stream.
      Throws:
      IOException - if a problem occurred reading the stream.
    • readNBytes

      public static byte[] readNBytes(InputStream input, int byteLength) throws IOException
      Returns the given input stream's first bytes as array. Note this doesn't close the stream.
      Throws:
      IOException - if a problem occurred reading the stream.
    • getInputStreamAsCharArray

      public static char[] getInputStreamAsCharArray(InputStream stream, String encoding) throws IOException
      Returns the given input stream's contents as a character array. Note this doesn't close the stream.
      Throws:
      IOException - if a problem occured reading the stream.
    • getExceptionSummary

      public static String getExceptionSummary(Throwable exception)
      Returns a one line summary for an exception (extracted from its stacktrace: name + first frame)
      Returns:
      one line summary for an exception
    • getStackTrace

      public static CharSequence getStackTrace(Throwable exception)
    • getLineNumber

      public static int getLineNumber(int position, int[] lineEnds, int g, int d)
    • getZipEntryByteContent

      public static byte[] getZipEntryByteContent(ZipEntry ze, ZipFile zip) throws IOException
      Returns the contents of the given zip entry as a byte array.
      Throws:
      IOException - if a problem occurred reading the zip entry.
    • hashCode

      public static int hashCode(Object[] array)
    • isPotentialZipArchive

      public static final boolean isPotentialZipArchive(String name)
      Returns whether the given name is potentially a zip archive file name (it has a file extension and it is not ".java" nor ".class")
    • archiveFormat

      public static final int archiveFormat(String name)
      Returns the kind of archive this file is. The format is one of #ZIP_FILE or JMOD_FILE
    • isClassFileName

      public static final boolean isClassFileName(char[] name)
      Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
    • isClassFileName

      public static final boolean isClassFileName(String name)
      Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
    • isExcluded

      public static final boolean isExcluded(char[] path, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean isFolderPath)
    • isJavaFileName

      public static final boolean isJavaFileName(char[] name)
      Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
    • isJavaFileName

      public static final boolean isJavaFileName(String name)
      Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
    • isAjFileName

      public static final boolean isAjFileName(String name)
    • isJrt

      public static final boolean isJrt(String name)
      Returns true iff str.toLowerCase().endsWith("jrt-fs.jar") implementation is not creating extra strings.
    • reverseQuickSort

      public static void reverseQuickSort(char[][] list, int left, int right)
    • reverseQuickSort

      public static void reverseQuickSort(char[][] list, int left, int right, int[] result)
    • searchColumnNumber

      public static final int searchColumnNumber(int[] startLineIndexes, int lineNumber, int position)
      INTERNAL USE-ONLY Search the column number corresponding to a specific position
    • toBoolean

      public static Boolean toBoolean(boolean bool)
      Converts a boolean value into Boolean.
      Parameters:
      bool - The boolean to convert
      Returns:
      The corresponding Boolean object (TRUE or FALSE).
    • toString

      public static String toString(Object[] objects)
      Converts an array of Objects into String.
    • toString

      public static String toString(Object[] objects, Util.Displayable renderer)
      Converts an array of Objects into String.
    • writeToDisk

      public static void writeToDisk(boolean generatePackagesStructure, String outputPath, String relativeFileName, ClassFile classFile) throws IOException
      outputPath is formed like: c:\temp\ the last character is a file separator relativeFileName is formed like: java\lang\String.class
      Parameters:
      generatePackagesStructure - a flag to know if the packages structure has to be generated.
      outputPath - the given output directory
      relativeFileName - the given relative file name
      classFile - the given classFile to write
      Throws:
      IOException
    • recordNestedType

      public static void recordNestedType(ClassFile classFile, TypeBinding typeBinding)
    • getJavaHome

      public static File getJavaHome()
    • collectVMBootclasspath

      public static void collectVMBootclasspath(List<FileSystem.Classpath> bootclasspaths, File javaHome)
    • collectRunningVMBootclasspath

      public static void collectRunningVMBootclasspath(List<FileSystem.Classpath> bootclasspaths)
    • getJDKLevel

      public static long getJDKLevel(File javaHome)
    • collectFilesNames

      public static List<FileSystem.Classpath> collectFilesNames()
    • collectPlatformLibraries

      public static List<FileSystem.Classpath> collectPlatformLibraries(File javaHome)
    • getParameterCount

      public static int getParameterCount(char[] methodSignature)
    • scanTypeSignature

      public static int scanTypeSignature(char[] string, int start)
      Scans the given string for a type signature starting at the given index and returns the index of the last character.
       TypeSignature:
        |  BaseTypeSignature
        |  ArrayTypeSignature
        |  ClassTypeSignature
        |  TypeVariableSignature
       
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a type signature
    • scanBaseTypeSignature

      public static int scanBaseTypeSignature(char[] string, int start)
      Scans the given string for a base type signature starting at the given index and returns the index of the last character.
       BaseTypeSignature:
           B | C | D | F | I
         | J | S | V | Z
       
      Note that although the base type "V" is only allowed in method return types, there is no syntactic ambiguity. This method will accept them anywhere without complaint.
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a base type signature
    • scanArrayTypeSignature

      public static int scanArrayTypeSignature(char[] string, int start)
      Scans the given string for an array type signature starting at the given index and returns the index of the last character.
       ArrayTypeSignature:
           [ TypeSignature
       
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not an array type signature
    • scanCaptureTypeSignature

      public static int scanCaptureTypeSignature(char[] string, int start)
      Scans the given string for a capture of a wildcard type signature starting at the given index and returns the index of the last character.
       CaptureTypeSignature:
           ! TypeBoundSignature
       
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a capture type signature
    • scanTypeVariableSignature

      public static int scanTypeVariableSignature(char[] string, int start)
      Scans the given string for a type variable signature starting at the given index and returns the index of the last character.
       TypeVariableSignature:
           T Identifier ;
       
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a type variable signature
    • scanIdentifier

      public static int scanIdentifier(char[] string, int start)
      Scans the given string for an identifier starting at the given index and returns the index of the last character. Stop characters are: ";", ":", "<", ">", "/", ".".
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not an identifier
    • scanClassTypeSignature

      public static int scanClassTypeSignature(char[] string, int start)
      Scans the given string for a class type signature starting at the given index and returns the index of the last character.
       ClassTypeSignature:
           { L | Q } Identifier
                 { { / | . Identifier [ < TypeArgumentSignature* > ] }
                 ;
       
      Note that although all "/"-identifiers most come before "."-identifiers, there is no syntactic ambiguity. This method will accept them without complaint.
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a class type signature
    • scanTypeBoundSignature

      public static int scanTypeBoundSignature(char[] string, int start)
      Scans the given string for a type bound signature starting at the given index and returns the index of the last character.
       TypeBoundSignature:
           [-+] TypeSignature ;
           *
       
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a type variable signature
    • scanTypeArgumentSignatures

      public static int scanTypeArgumentSignatures(char[] string, int start)
      Scans the given string for a list of type argument signatures starting at the given index and returns the index of the last character.
       TypeArgumentSignatures:
           < TypeArgumentSignature* >
       
      Note that although there is supposed to be at least one type argument, there is no syntactic ambiguity if there are none. This method will accept zero type argument signatures without complaint.
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a list of type arguments signatures
    • scanTypeArgumentSignature

      public static int scanTypeArgumentSignature(char[] string, int start)
      Scans the given string for a type argument signature starting at the given index and returns the index of the last character.
       TypeArgumentSignature:
           *
        |  + TypeSignature
        |  - TypeSignature
        |  TypeSignature
       
      Note that although base types are not allowed in type arguments, there is no syntactic ambiguity. This method will accept them without complaint.
      Parameters:
      string - the signature string
      start - the 0-based character index of the first character
      Returns:
      the 0-based character index of the last character
      Throws:
      IllegalArgumentException - if this is not a type argument signature
    • effectivelyEqual

      public static boolean effectivelyEqual(Object[] one, Object[] two)
    • appendEscapedChar

      public static void appendEscapedChar(StringBuilder buffer, char c, boolean stringLiteral)