org.mvel2.util
Class ParseTools

java.lang.Object
  extended by org.mvel2.util.ParseTools

public class ParseTools
extends java.lang.Object


Nested Class Summary
static class ParseTools.WithStatementPair
           
 
Field Summary
static java.lang.Class[] EMPTY_CLS_ARR
           
static java.lang.Object[] EMPTY_OBJ_ARR
           
static java.lang.String[] EMPTY_STR_ARR
           
 
Constructor Summary
ParseTools()
           
 
Method Summary
static int __resolveType(java.lang.Class cls)
           
static int balancedCapture(char[] chars, int start, char type)
          This is an important aspect of the core parser tools.
static int balancedCaptureWithLineAccounting(char[] chars, int start, char type, ParserContext pCtx)
           
static java.lang.Class boxPrimitive(java.lang.Class cls)
           
static java.lang.String[] captureContructorAndResidual(char[] cs)
           
static int captureStringLiteral(char type, char[] expr, int cursor, int length)
           
static int captureToEOS(char[] expr, int cursor, ParserContext pCtx)
           
static int captureToNextTokenJunction(char[] expr, int cursor, ParserContext pCtx)
           
static void checkNameSafety(java.lang.String name)
           
static boolean containsCheck(java.lang.Object compareTo, java.lang.Object compareTest)
           
static java.lang.Class createClass(java.lang.String className, ParserContext pCtx)
           
static int createClassSignatureHash(java.lang.Class declaring, java.lang.Class[] sig)
           
static char[] createShortFormOperativeAssignment(java.lang.String name, char[] statement, int operation)
           
static java.lang.String createStringTrimmed(char[] s)
           
static java.lang.String createStringTrimmed(char[] s, int start, int length)
           
static java.lang.reflect.Method determineActualTargetMethod(java.lang.reflect.Method method)
           
static boolean endsWith(char[] c, char[] test)
           
static int find(char[] c, char find)
           
static int findAbsoluteLast(char[] array)
           
static java.lang.Class findClass(VariableResolverFactory factory, java.lang.String name, ParserContext ctx)
           
static ClassImportResolverFactory findClassImportResolverFactory(VariableResolverFactory factory)
           
static int findLast(char[] c, char find)
           
static java.lang.Class getBaseComponentType(java.lang.Class cls)
           
static java.lang.reflect.Method getBestCandidate(java.lang.Class[] arguments, java.lang.String method, java.lang.Class decl, java.lang.reflect.Method[] methods, boolean requireExact)
           
static java.lang.reflect.Method getBestCandidate(java.lang.Object[] arguments, java.lang.String method, java.lang.Class decl, java.lang.reflect.Method[] methods, boolean requireExact)
           
static java.lang.reflect.Constructor getBestConstructorCandidate(java.lang.Class[] arguments, java.lang.Class cls, boolean requireExact)
           
static java.lang.reflect.Constructor getBestConstructorCandidate(java.lang.Object[] args, java.lang.Class cls, boolean requireExact)
           
static java.lang.reflect.Constructor[] getConstructors(java.lang.Class cls)
           
static java.io.FileWriter getDebugFileWriter()
           
static java.lang.reflect.Method getExactMatch(java.lang.String name, java.lang.Class[] args, java.lang.Class returnType, java.lang.Class cls)
           
static java.lang.Class getSubComponentType(java.lang.Class cls)
           
static java.lang.reflect.Method getWidenedTarget(java.lang.reflect.Method method)
           
static int handleEscapeSequence(char[] escapeStr, int pos)
          Replace escape sequences and return trim required.
static java.lang.Object handleNumericConversion(char[] val)
           
static java.lang.String handleStringEscapes(char[] input)
           
static boolean isDigit(int c)
           
static boolean isIdentifierPart(int c)
           
static boolean isJunct(char c)
           
static boolean isNotValidNameorLabel(java.lang.String name)
          Check if the specfied string represents a valid name of label.
static boolean isNumber(char[] val)
           
static boolean isNumber(java.lang.Object val)
           
static boolean isNumber(java.lang.String val)
           
static boolean isNumeric(java.lang.Object val)
           
static boolean isNumericallyCoercible(java.lang.Class target, java.lang.Class parm)
           
static boolean isPrimitiveWrapper(java.lang.Class clazz)
           
static boolean isReservedWord(java.lang.String name)
          Check if the specified string is a reserved word in the parser.
static boolean isStatementNotManuallyTerminated(char[] expr, int cursor)
           
static boolean isWhitespace(char c)
           
static char[] loadFromFile(java.io.File file)
           
static char[] loadFromFile(java.io.File file, java.lang.String encoding)
           
static java.lang.Object narrowType(java.math.BigDecimal result, int returnTarget)
           
static int nextNonBlank(char[] expr, int cursor)
           
static int numericTest(char[] val)
           
static int opLookup(char c)
           
static java.io.Serializable optimizeTree(CompiledExpression compiled)
           
static java.lang.String[] parseMethodOrConstructor(char[] parm)
           
static java.lang.String[] parseParameterDefList(char[] parm, int offset, int length)
           
static java.lang.String[] parseParameterList(char[] parm, int offset, int length)
           
static void parseWithExpressions(java.lang.String nestParm, char[] block, int begin, int ending, java.lang.Object ctx, VariableResolverFactory factory)
           
static char[] readIn(java.io.InputStream inStream, java.lang.String encoding)
           
static java.lang.String repeatChar(char c, int times)
           
static int resolveType(java.lang.Class cls)
           
static int resolveType(java.lang.Object o)
           
static int scoreInterface(java.lang.Class parm, java.lang.Class arg)
           
static float similarity(java.lang.String s1, java.lang.String s2)
           
static int skipWhitespace(char[] expr, int cursor, ParserContext pCtx)
           
static char[] subArray(char[] expr, int start, int end)
           
static java.io.Serializable subCompileExpression(char[] expression)
           
static java.io.Serializable subCompileExpression(char[] expression, ParserContext ctx)
           
static java.io.Serializable subCompileExpression(java.lang.String expression, ParserContext ctx)
           
static char[] subset(char[] array, int start)
           
static char[] subset(char[] array, int start, int length)
           
static int trimLeft(char[] expr, int start, int pos)
          From the specified cursor position, trim out any whitespace between the current position and the end of the last non-whitespace character.
static int trimRight(char[] expr, int start, int pos)
          From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.
static java.lang.Class unboxPrimitive(java.lang.Class cls)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STR_ARR

public static final java.lang.String[] EMPTY_STR_ARR

EMPTY_OBJ_ARR

public static final java.lang.Object[] EMPTY_OBJ_ARR

EMPTY_CLS_ARR

public static final java.lang.Class[] EMPTY_CLS_ARR
Constructor Detail

ParseTools

public ParseTools()
Method Detail

parseMethodOrConstructor

public static java.lang.String[] parseMethodOrConstructor(char[] parm)

parseParameterDefList

public static java.lang.String[] parseParameterDefList(char[] parm,
                                                       int offset,
                                                       int length)

parseParameterList

public static java.lang.String[] parseParameterList(char[] parm,
                                                    int offset,
                                                    int length)

getBestCandidate

public static java.lang.reflect.Method getBestCandidate(java.lang.Object[] arguments,
                                                        java.lang.String method,
                                                        java.lang.Class decl,
                                                        java.lang.reflect.Method[] methods,
                                                        boolean requireExact)

getBestCandidate

public static java.lang.reflect.Method getBestCandidate(java.lang.Class[] arguments,
                                                        java.lang.String method,
                                                        java.lang.Class decl,
                                                        java.lang.reflect.Method[] methods,
                                                        boolean requireExact)

scoreInterface

public static int scoreInterface(java.lang.Class parm,
                                 java.lang.Class arg)

getExactMatch

public static java.lang.reflect.Method getExactMatch(java.lang.String name,
                                                     java.lang.Class[] args,
                                                     java.lang.Class returnType,
                                                     java.lang.Class cls)

getWidenedTarget

public static java.lang.reflect.Method getWidenedTarget(java.lang.reflect.Method method)

getBestConstructorCandidate

public static java.lang.reflect.Constructor getBestConstructorCandidate(java.lang.Object[] args,
                                                                        java.lang.Class cls,
                                                                        boolean requireExact)

getBestConstructorCandidate

public static java.lang.reflect.Constructor getBestConstructorCandidate(java.lang.Class[] arguments,
                                                                        java.lang.Class cls,
                                                                        boolean requireExact)

createClass

public static java.lang.Class createClass(java.lang.String className,
                                          ParserContext pCtx)
                                   throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getConstructors

public static java.lang.reflect.Constructor[] getConstructors(java.lang.Class cls)

captureContructorAndResidual

public static java.lang.String[] captureContructorAndResidual(char[] cs)

boxPrimitive

public static java.lang.Class boxPrimitive(java.lang.Class cls)

unboxPrimitive

public static java.lang.Class unboxPrimitive(java.lang.Class cls)

containsCheck

public static boolean containsCheck(java.lang.Object compareTo,
                                    java.lang.Object compareTest)

createClassSignatureHash

public static int createClassSignatureHash(java.lang.Class declaring,
                                           java.lang.Class[] sig)

handleEscapeSequence

public static int handleEscapeSequence(char[] escapeStr,
                                       int pos)
Replace escape sequences and return trim required.

Parameters:
escapeStr - -
pos - -
Returns:
-

createShortFormOperativeAssignment

public static char[] createShortFormOperativeAssignment(java.lang.String name,
                                                        char[] statement,
                                                        int operation)

findClassImportResolverFactory

public static ClassImportResolverFactory findClassImportResolverFactory(VariableResolverFactory factory)

findClass

public static java.lang.Class findClass(VariableResolverFactory factory,
                                        java.lang.String name,
                                        ParserContext ctx)
                                 throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

subset

public static char[] subset(char[] array,
                            int start,
                            int length)

subset

public static char[] subset(char[] array,
                            int start)

resolveType

public static int resolveType(java.lang.Object o)

resolveType

public static int resolveType(java.lang.Class cls)

__resolveType

public static int __resolveType(java.lang.Class cls)

isNumericallyCoercible

public static boolean isNumericallyCoercible(java.lang.Class target,
                                             java.lang.Class parm)

narrowType

public static java.lang.Object narrowType(java.math.BigDecimal result,
                                          int returnTarget)

determineActualTargetMethod

public static java.lang.reflect.Method determineActualTargetMethod(java.lang.reflect.Method method)

captureToNextTokenJunction

public static int captureToNextTokenJunction(char[] expr,
                                             int cursor,
                                             ParserContext pCtx)

nextNonBlank

public static int nextNonBlank(char[] expr,
                               int cursor)

skipWhitespace

public static int skipWhitespace(char[] expr,
                                 int cursor,
                                 ParserContext pCtx)

isStatementNotManuallyTerminated

public static boolean isStatementNotManuallyTerminated(char[] expr,
                                                       int cursor)

captureToEOS

public static int captureToEOS(char[] expr,
                               int cursor,
                               ParserContext pCtx)

trimLeft

public static int trimLeft(char[] expr,
                           int start,
                           int pos)
From the specified cursor position, trim out any whitespace between the current position and the end of the last non-whitespace character.

Parameters:
pos - - current position
Returns:
new position.

trimRight

public static int trimRight(char[] expr,
                            int start,
                            int pos)
From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.

Parameters:
pos - -
Returns:
-

subArray

public static char[] subArray(char[] expr,
                              int start,
                              int end)

balancedCapture

public static int balancedCapture(char[] chars,
                                  int start,
                                  char type)
This is an important aspect of the core parser tools. This method is used throughout the core parser and sub-lexical parsers to capture a balanced capture between opening and terminating tokens such as: ( [ { ' "

For example: ((foo + bar + (bar - foo)) * 20;

If a balanced capture is performed from position 2, we get "(foo + bar + (bar - foo))" back.
If a balanced capture is performed from position 15, we get "(bar - foo)" back.
Etc.

Parameters:
chars - -
start - -
type - -
Returns:
-

balancedCaptureWithLineAccounting

public static int balancedCaptureWithLineAccounting(char[] chars,
                                                    int start,
                                                    char type,
                                                    ParserContext pCtx)

handleStringEscapes

public static java.lang.String handleStringEscapes(char[] input)

captureStringLiteral

public static int captureStringLiteral(char type,
                                       char[] expr,
                                       int cursor,
                                       int length)

parseWithExpressions

public static void parseWithExpressions(java.lang.String nestParm,
                                        char[] block,
                                        int begin,
                                        int ending,
                                        java.lang.Object ctx,
                                        VariableResolverFactory factory)

handleNumericConversion

public static java.lang.Object handleNumericConversion(char[] val)

isNumeric

public static boolean isNumeric(java.lang.Object val)

numericTest

public static int numericTest(char[] val)

isNumber

public static boolean isNumber(java.lang.Object val)

isNumber

public static boolean isNumber(java.lang.String val)

isNumber

public static boolean isNumber(char[] val)

find

public static int find(char[] c,
                       char find)

findLast

public static int findLast(char[] c,
                           char find)

createStringTrimmed

public static java.lang.String createStringTrimmed(char[] s)

createStringTrimmed

public static java.lang.String createStringTrimmed(char[] s,
                                                   int start,
                                                   int length)

endsWith

public static boolean endsWith(char[] c,
                               char[] test)

isIdentifierPart

public static boolean isIdentifierPart(int c)

isDigit

public static boolean isDigit(int c)

similarity

public static float similarity(java.lang.String s1,
                               java.lang.String s2)

findAbsoluteLast

public static int findAbsoluteLast(char[] array)

getBaseComponentType

public static java.lang.Class getBaseComponentType(java.lang.Class cls)

getSubComponentType

public static java.lang.Class getSubComponentType(java.lang.Class cls)

isJunct

public static boolean isJunct(char c)

opLookup

public static int opLookup(char c)

isReservedWord

public static boolean isReservedWord(java.lang.String name)
Check if the specified string is a reserved word in the parser.

Parameters:
name - -
Returns:
-

isNotValidNameorLabel

public static boolean isNotValidNameorLabel(java.lang.String name)
Check if the specfied string represents a valid name of label.

Parameters:
name - -
Returns:
-

checkNameSafety

public static void checkNameSafety(java.lang.String name)

getDebugFileWriter

public static java.io.FileWriter getDebugFileWriter()
                                             throws java.io.IOException
Throws:
java.io.IOException

isPrimitiveWrapper

public static boolean isPrimitiveWrapper(java.lang.Class clazz)

subCompileExpression

public static java.io.Serializable subCompileExpression(char[] expression)

subCompileExpression

public static java.io.Serializable subCompileExpression(char[] expression,
                                                        ParserContext ctx)

subCompileExpression

public static java.io.Serializable subCompileExpression(java.lang.String expression,
                                                        ParserContext ctx)

optimizeTree

public static java.io.Serializable optimizeTree(CompiledExpression compiled)

isWhitespace

public static boolean isWhitespace(char c)

repeatChar

public static java.lang.String repeatChar(char c,
                                          int times)

loadFromFile

public static char[] loadFromFile(java.io.File file)
                           throws java.io.IOException
Throws:
java.io.IOException

loadFromFile

public static char[] loadFromFile(java.io.File file,
                                  java.lang.String encoding)
                           throws java.io.IOException
Throws:
java.io.IOException

readIn

public static char[] readIn(java.io.InputStream inStream,
                            java.lang.String encoding)
                     throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2011. All Rights Reserved.