Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.1.0)

E13403-02

oracle.javatools.parser.java.v1
Class JavaUtilities

java.lang.Object
  extended by oracle.javatools.parser.java.v1.JavaUtilities

public final class JavaUtilities
extends java.lang.Object

The JavaUtilities class provides utility routines for parsing a Java file (buffer) using the Java Parser. All public routines in this class are declared static. To use this class, first get a parsed representation of your buffer by calling getParseTree().

Once you have the parsed representation, you can get other information, such as package name, import names, and so on from the parse tree using the other utility routines in this class.


Method Summary
static java.lang.String[] breakUpQualifiedName(java.lang.String name)
          Breaks up the name along '.' boundaries.
static java.lang.String[] convertListToArray(java.util.List list)
          Private utility routine which takes a List of Strings, and produces an array of Strings out of it.
static java.lang.String[] getAllImports(RootSymbol rootSymbol)
          Utility routine which gets all the import names from the parse tree, including both explicit imports (i.e., java.io.IOException) and multi imports (i.e., java.io.*).
static int getArrayDimension(TypeSymbol typeSymbol)
          Utility routine which gets the array dimension of the type represented by the given TypeSymbol structure.
static java.lang.String getClassName(ClassSymbol classSymbol)
          Utility routine which gets the class name of the class represented by the given ClassSymbol structure.
static java.lang.String[] getExplicitImports(RootSymbol rootSymbol)
          Utility routine which gets the explicit import names from the parse tree (i.e., java.io.IOException).
static RootSymbol getImportsParseTree(TextBuffer textBuffer)
           
static java.lang.String getMethodName(MethodSymbol methodSymbol)
          Utility routine which gets the method name of the method represented by the given MethodSymbol structure.
static java.lang.String[] getMultiImportPackages(RootSymbol rootSymbol)
          Utility routine which gets the multi-import package names from the parse tree (i.e., java.io).
static java.lang.String[] getMultiImports(RootSymbol rootSymbol)
          Utility routine which gets the multi-import names from the parse tree (i.e., java.io.*).
static java.lang.String getPackageName(RootSymbol rootSymbol)
          Utility routine which gets the package name of the buffer represented by the given parse tree generated by getParseTree().
static RootSymbol getParseTree(ReadTextBuffer textBuffer)
          Utility routine which gets a full parse tree for the given text buffer.
static RootSymbol getParseTree(ReadTextBuffer textBuffer, boolean fullDepth)
          Utility routine which gets a full parse tree for the given text buffer.
static java.lang.String getSymbolName(Nameable nameableSymbol)
          Utility routine which gets the name of the NameableSymbol represented by the given parsed structure.
static java.lang.String getSymbolName(NameSymbol nameSymbol)
          Utility routine which gets the name contained in a NameSymbol.
static int getSymbolNameLength(Nameable nameableSymbol)
           
static int getSymbolNameOffset(Nameable nameableSymbol)
           
static java.lang.String getTypeName(TypeSymbol typeSymbol)
          Utility routine which gets the type name of the type represented by the given TypeSymbol structure.
static java.lang.String getVariableName(VariableSymbol variableSymbol)
          Utility routine which gets the variable name of the variable represented by the given VariableSymbol structure.
static boolean inJavaSymbol(int offset, JavaSymbol javaSymbol)
          Private utility which checks whether the given offset is located in the given JavaSymbol.
static ExpressionSymbol parseExpression(ReadTextBuffer wholeBuffer, int startOffset, int endOffset, Scope scope)
          Same as above except that it copies the relevant part of the original buffer so that the ExpressionSymbol can have offsets into the original buffer.
static ExpressionSymbol parseExpression(java.lang.String target)
          Convenience routine for parsing an expression.
static MethodSymbol parseMethodDeclaration(java.lang.String target)
          Takes a string of the form "void method( int a, Object o )" and generates a MethodSymbol for it.
static java.lang.String trimWhitespace(java.lang.String name)
          Returns a new String with leading and trailing whitespace removed.
static java.lang.String trimWhitespace(java.lang.String name, int start)
          Given the following substring, returns a new String that has leading and trailing whitespace removed.
static java.lang.String trimWhitespace(java.lang.String name, int start, int end)
          Given the following substring, returns a new String that has leading and trailing whitespace removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getParseTree

public static RootSymbol getParseTree(ReadTextBuffer textBuffer)
Utility routine which gets a full parse tree for the given text buffer. Other static routines in this class will pull information out of the parse tree. The generated parse tree has no dependency on the text buffer. Note that this parse is an error-tolerant one automatically.

Parameters:
textBuffer - the text buffer to parse
Returns:
a parse tree for the given buffer, type RootSymbol

getParseTree

public static RootSymbol getParseTree(ReadTextBuffer textBuffer,
                                      boolean fullDepth)
Utility routine which gets a full parse tree for the given text buffer. Other static routines in this class will pull information out of the parse tree. The generated parse tree has no dependency on the text buffer. Note that this parse is an error-tolerant one automatically.

Parameters:
textBuffer - the text buffer to parse
fullDepth - whether to do a full depth parse (vs. members only)
Returns:
a parse tree for the given buffer, type RootSymbol

getImportsParseTree

public static RootSymbol getImportsParseTree(TextBuffer textBuffer)

parseExpression

public static ExpressionSymbol parseExpression(java.lang.String target)
Convenience routine for parsing an expression. Does a no-tolerance parse of an expression using the String parameter as the input buffer.


parseExpression

public static ExpressionSymbol parseExpression(ReadTextBuffer wholeBuffer,
                                               int startOffset,
                                               int endOffset,
                                               Scope scope)
Same as above except that it copies the relevant part of the original buffer so that the ExpressionSymbol can have offsets into the original buffer.


parseMethodDeclaration

public static MethodSymbol parseMethodDeclaration(java.lang.String target)
Takes a string of the form "void method( int a, Object o )" and generates a MethodSymbol for it. There isn't a whole lot of intelligence to this. It simply creates the string "class name { $target { } )", parses it, and returns the first method from the first class in the result. If there are any parse errors, this will return null.


getExplicitImports

public static java.lang.String[] getExplicitImports(RootSymbol rootSymbol)
Utility routine which gets the explicit import names from the parse tree (i.e., java.io.IOException).

Parameters:
rootSymbol - the parse tree generated by getParseTree()
Returns:
the list of multi-imports only

getMultiImports

public static java.lang.String[] getMultiImports(RootSymbol rootSymbol)
Utility routine which gets the multi-import names from the parse tree (i.e., java.io.*).

Parameters:
rootSymbol - the parse tree generated by getParseTree()
Returns:
the list of multi-imports only

getMultiImportPackages

public static java.lang.String[] getMultiImportPackages(RootSymbol rootSymbol)
Utility routine which gets the multi-import package names from the parse tree (i.e., java.io).

Parameters:
rootSymbol - the parse tree generated by getParseTree()
Returns:
the list of multi-import packages only

getAllImports

public static java.lang.String[] getAllImports(RootSymbol rootSymbol)
Utility routine which gets all the import names from the parse tree, including both explicit imports (i.e., java.io.IOException) and multi imports (i.e., java.io.*).

Parameters:
rootSymbol - the parse tree generated by getParseTree()
Returns:
the list of all imports

getPackageName

public static java.lang.String getPackageName(RootSymbol rootSymbol)
Utility routine which gets the package name of the buffer represented by the given parse tree generated by getParseTree().

Parameters:
rootSymbol - the parse tree generated by getParseTree()
Returns:
the name of the package, or an empty String if there is no package or if there was no parse tree

getClassName

public static java.lang.String getClassName(ClassSymbol classSymbol)
Utility routine which gets the class name of the class represented by the given ClassSymbol structure.

Parameters:
classSymbol - the class structure in the parse tree representing the class in question
Returns:
the name of the class, or an empty String if none was found (anonymous class?)

getMethodName

public static java.lang.String getMethodName(MethodSymbol methodSymbol)
Utility routine which gets the method name of the method represented by the given MethodSymbol structure.

Parameters:
methodSymbol - the method structure in the parse tree representing the method in question
Returns:
the name of the method

getVariableName

public static java.lang.String getVariableName(VariableSymbol variableSymbol)
Utility routine which gets the variable name of the variable represented by the given VariableSymbol structure.

Parameters:
variableSymbol - the variable structure in the parse tree representing the variable in question
Returns:
the name of the variable

getTypeName

public static java.lang.String getTypeName(TypeSymbol typeSymbol)
Utility routine which gets the type name of the type represented by the given TypeSymbol structure.

Parameters:
typeSymbol - the type structure in the parse tree representing the type in question
Returns:
the name of the type

getSymbolNameOffset

public static int getSymbolNameOffset(Nameable nameableSymbol)

getSymbolNameLength

public static int getSymbolNameLength(Nameable nameableSymbol)

getSymbolName

public static java.lang.String getSymbolName(Nameable nameableSymbol)
Utility routine which gets the name of the NameableSymbol represented by the given parsed structure.

Parameters:
nameableSymbol - an instance of a JavaSymbol that is a Nameable, such as a ClassSymbol or MethodSymbol
Returns:
the name of the symbol

getSymbolName

public static java.lang.String getSymbolName(NameSymbol nameSymbol)
Utility routine which gets the name contained in a NameSymbol.

Parameters:
nameSymbol - an instance of a NameSymbol
Returns:
the name of the symbol

getArrayDimension

public static int getArrayDimension(TypeSymbol typeSymbol)
Utility routine which gets the array dimension of the type represented by the given TypeSymbol structure.

Parameters:
typeSymbol - the type structure in the parse tree representing the type in question
Returns:
the array dimension (if any) of the type symbol

convertListToArray

public static java.lang.String[] convertListToArray(java.util.List list)
Private utility routine which takes a List of Strings, and produces an array of Strings out of it.

Parameters:
list - the input list of Strings
Returns:
an array of Strings from the list

inJavaSymbol

public static boolean inJavaSymbol(int offset,
                                   JavaSymbol javaSymbol)
Private utility which checks whether the given offset is located in the given JavaSymbol. It is considered to be in the JavaSymbol if it is anywhere from the start to the offset right after the symbol (i.e., end is treated as inclusive.)

Parameters:
offset - the offset to check
javaSymbol - the javaSymbol to check
Returns:
whether the offset is contained in the java symbol

trimWhitespace

public static java.lang.String trimWhitespace(java.lang.String name,
                                              int start,
                                              int end)
Given the following substring, returns a new String that has leading and trailing whitespace removed.


trimWhitespace

public static java.lang.String trimWhitespace(java.lang.String name,
                                              int start)
Given the following substring, returns a new String that has leading and trailing whitespace removed.


trimWhitespace

public static java.lang.String trimWhitespace(java.lang.String name)
Returns a new String with leading and trailing whitespace removed.


breakUpQualifiedName

public static java.lang.String[] breakUpQualifiedName(java.lang.String name)
Breaks up the name along '.' boundaries. Leading and trailing whitespace is trimmed off each name before returning.


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.1.0)

E13403-02

Copyright © 1997, 2009, Oracle. All rights reserved.