org.eclipse.jdt.internal.compiler.util
Class Util

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

public class Util
extends Object
implements SuffixConstants


Nested Class Summary
static interface Util.Displayable
           
 
Field Summary
static char C_ARRAY
          Character constant indicating an array type in a signature.
static char C_BOOLEAN
          Character constant indicating the primitive type boolean in a signature.
static char C_BYTE
          Character constant indicating the primitive type byte in a signature.
static char C_CAPTURE
          Character constant indicating a capture of a wildcard type in a signature.
static char C_CHAR
          Character constant indicating the primitive type char in a signature.
static char C_COLON
          Character constant indicating the colon in a signature.
static char C_DOLLAR
          Character constant indicating the dollar in a signature.
static char C_DOT
          Character constant indicating the dot in a signature.
static char C_DOUBLE
          Character constant indicating the primitive type double in a signature.
static char C_EXCEPTION_START
          Character constant indicating an exception in a signature.
static char C_EXTENDS
          Character constant indicating a bound wildcard type argument in a signature with extends clause.
static char C_FLOAT
          Character constant indicating the primitive type float in a signature.
static char C_GENERIC_END
          Character constant indicating the end of a generic type list in a signature.
static char C_GENERIC_START
          Character constant indicating the start of a formal type parameter (or type argument) list in a signature.
static char C_INT
          Character constant indicating the primitive type int in a signature.
static char C_LONG
          Character constant indicating the primitive type long in a signature.
static char C_NAME_END
          Character constant indicating the end of a named type in a signature.
static char C_PARAM_END
          Character constant indicating the end of a parameter type list in a signature.
static char C_PARAM_START
          Character constant indicating the start of a parameter type list in a signature.
static char C_RESOLVED
          Character constant indicating the start of a resolved, named type in a signature.
static char C_SEMICOLON
          Character constant indicating the semicolon in a signature.
static char C_SHORT
          Character constant indicating the primitive type short in a signature.
static char C_STAR
          Character constant indicating an unbound wildcard type argument in a signature.
static char C_SUPER
          Character constant indicating a bound wildcard type argument in a signature with super clause.
static char C_TYPE_VARIABLE
          Character constant indicating the start of a resolved type variable in a signature.
static char C_UNRESOLVED
          Character constant indicating the start of an unresolved, named type in a signature.
static char C_VOID
          Character constant indicating result type void in a signature.
static int[] EMPTY_INT_ARRAY
           
static String EMPTY_STRING
           
static String LINE_SEPARATOR
           
static String UTF_8
           
 
Fields inherited from interface org.eclipse.jdt.internal.compiler.util.SuffixConstants
EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVA
 
Constructor Summary
Util()
           
 
Method Summary
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 collectRunningVMBootclasspath(List bootclasspaths)
           
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 String getExceptionSummary(Throwable exception)
          Returns a one line summary for an exception (extracted from its stacktrace: name + first frame)
static byte[] getFileByteContent(File file)
          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[] getInputStreamAsByteArray(InputStream stream, int length)
          Returns the given input stream's contents as a byte array.
static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding)
          Returns the given input stream's contents as a character array.
static File getJavaHome()
           
static int getLineNumber(int position, int[] lineEnds, int g, int d)
           
static int getParameterCount(char[] methodSignature)
           
static byte[] getZipEntryByteContent(ZipEntry ze, ZipFile zip)
          Returns the contents of the given zip entry as a byte array.
static int hashCode(Object[] array)
           
static boolean isClassFileName(char[] name)
          Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
static boolean isClassFileName(String name)
          Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
static boolean isExcluded(char[] path, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean isFolderPath)
           
static boolean isJavaFileName(char[] name)
          Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
static boolean isJavaFileName(String name)
          Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
static 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")
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 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 Detail

C_BOOLEAN

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

See Also:
Constant Field Values

C_BYTE

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

See Also:
Constant Field Values

C_CHAR

public static final char C_CHAR
Character constant indicating the primitive type char in a signature. Value is 'C'.

See Also:
Constant Field Values

C_DOUBLE

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

See Also:
Constant Field Values

C_FLOAT

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

See Also:
Constant Field Values

C_INT

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

See Also:
Constant Field Values

C_SEMICOLON

public static final char C_SEMICOLON
Character constant indicating the semicolon in a signature. Value is ';'.

See Also:
Constant Field Values

C_COLON

public static final char C_COLON
Character constant indicating the colon in a signature. Value is ':'.

Since:
3.0
See Also:
Constant Field Values

C_LONG

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

See Also:
Constant Field Values

C_SHORT

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

See Also:
Constant Field Values

C_VOID

public static final char C_VOID
Character constant indicating result type void in a signature. Value is 'V'.

See Also:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

C_DOT

public static final char C_DOT
Character constant indicating the dot in a signature. Value is '.'.

See Also:
Constant Field Values

C_DOLLAR

public static final char C_DOLLAR
Character constant indicating the dollar in a signature. Value is '$'.

See Also:
Constant Field Values

C_ARRAY

public static final char C_ARRAY
Character constant indicating an array type in a signature. Value is '['.

See Also:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

UTF_8

public static final String UTF_8
See Also:
Constant Field Values

LINE_SEPARATOR

public static final String LINE_SEPARATOR

EMPTY_STRING

public static final String EMPTY_STRING

EMPTY_INT_ARRAY

public static final int[] EMPTY_INT_ARRAY
Constructor Detail

Util

public Util()
Method Detail

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 stream,
                                               int length)
                                        throws IOException
Returns the given input stream's contents as a byte array. If a length is specified (i.e. if length != -1), only length bytes are returned. Otherwise all bytes in the stream are returned. Note this doesn't close the stream.

Throws:
IOException - if a problem occured reading the stream.

getInputStreamAsCharArray

public static char[] getInputStreamAsCharArray(InputStream stream,
                                               int length,
                                               String encoding)
                                        throws IOException
Returns the given input stream's contents as a character array. If a length is specified (i.e. if length != -1), this represents the number of bytes in the stream. 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)

Parameters:
exception -
Returns:
one line summary for an 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 occured 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")


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.


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()

collectRunningVMBootclasspath

public static void collectRunningVMBootclasspath(List bootclasspaths)

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


Copyright © 2012. All Rights Reserved.