org.mvel2.util
Class ParseTools

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

public class ParseTools
extends Object


Nested Class Summary
static class ParseTools.WithStatementPair
           
 
Field Summary
static Class[] EMPTY_CLS_ARR
           
static Object[] EMPTY_OBJ_ARR
           
static String[] EMPTY_STR_ARR
           
 
Constructor Summary
ParseTools()
           
 
Method Summary
static int __resolveType(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 Class boxPrimitive(Class cls)
           
static 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(String name)
           
static boolean containsCheck(Object compareTo, Object compareTest)
           
static Class createClass(String className, ParserContext pCtx)
           
static int createClassSignatureHash(Class declaring, Class[] sig)
           
static char[] createShortFormOperativeAssignment(String name, char[] statement, int operation)
           
static String createStringTrimmed(char[] s)
           
static String createStringTrimmed(char[] s, int start, int length)
           
static Method determineActualTargetMethod(Method method)
           
static boolean endsWith(char[] c, char[] test)
           
static int find(char[] c, char find)
           
static int findAbsoluteLast(char[] array)
           
static Class findClass(VariableResolverFactory factory, String name, ParserContext ctx)
           
static ClassImportResolverFactory findClassImportResolverFactory(VariableResolverFactory factory)
           
static int findLast(char[] c, char find)
           
static Class getBaseComponentType(Class cls)
           
static Method getBestCandidate(Class[] arguments, String method, Class decl, Method[] methods, boolean requireExact)
           
static Method getBestCandidate(Object[] arguments, String method, Class decl, Method[] methods, boolean requireExact)
           
static Constructor getBestConstructorCandidate(Class[] arguments, Class cls, boolean requireExact)
           
static Constructor getBestConstructorCandidate(Object[] args, Class cls, boolean requireExact)
           
static Constructor[] getConstructors(Class cls)
           
static FileWriter getDebugFileWriter()
           
static Method getExactMatch(String name, Class[] args, Class returnType, Class cls)
           
static Class getSubComponentType(Class cls)
           
static Method getWidenedTarget(Method method)
           
static int handleEscapeSequence(char[] escapeStr, int pos)
          Replace escape sequences and return trim required.
static Object handleNumericConversion(char[] val)
           
static String handleStringEscapes(char[] input)
           
static boolean isDigit(int c)
           
static boolean isIdentifierPart(int c)
           
static boolean isJunct(char c)
           
static boolean isNotValidNameorLabel(String name)
          Check if the specfied string represents a valid name of label.
static boolean isNumber(char[] val)
           
static boolean isNumber(Object val)
           
static boolean isNumber(String val)
           
static boolean isNumeric(Object val)
           
static boolean isNumericallyCoercible(Class target, Class parm)
           
static boolean isPrimitiveWrapper(Class clazz)
           
static boolean isReservedWord(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(File file)
           
static char[] loadFromFile(File file, String encoding)
           
static Object narrowType(BigDecimal result, int returnTarget)
           
static int nextNonBlank(char[] expr, int cursor)
           
static int numericTest(char[] val)
           
static int opLookup(char c)
           
static Serializable optimizeTree(CompiledExpression compiled)
           
static String[] parseMethodOrConstructor(char[] parm)
           
static String[] parseParameterDefList(char[] parm, int offset, int length)
           
static String[] parseParameterList(char[] parm, int offset, int length)
           
static void parseWithExpressions(String nestParm, char[] block, int begin, int ending, Object ctx, VariableResolverFactory factory)
           
static char[] readIn(InputStream inStream, String encoding)
           
static String repeatChar(char c, int times)
           
static int resolveType(Class cls)
           
static int resolveType(Object o)
           
static int scoreInterface(Class parm, Class arg)
           
static float similarity(String s1, String s2)
           
static int skipWhitespace(char[] expr, int cursor, ParserContext pCtx)
           
static char[] subArray(char[] expr, int start, int end)
           
static Serializable subCompileExpression(char[] expression)
           
static Serializable subCompileExpression(char[] expression, ParserContext ctx)
           
static Serializable subCompileExpression(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 Class unboxPrimitive(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 String[] EMPTY_STR_ARR

EMPTY_OBJ_ARR

public static final Object[] EMPTY_OBJ_ARR

EMPTY_CLS_ARR

public static final Class[] EMPTY_CLS_ARR
Constructor Detail

ParseTools

public ParseTools()
Method Detail

parseMethodOrConstructor

public static String[] parseMethodOrConstructor(char[] parm)

parseParameterDefList

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

parseParameterList

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

getBestCandidate

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

getBestCandidate

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

scoreInterface

public static int scoreInterface(Class parm,
                                 Class arg)

getExactMatch

public static Method getExactMatch(String name,
                                   Class[] args,
                                   Class returnType,
                                   Class cls)

getWidenedTarget

public static Method getWidenedTarget(Method method)

getBestConstructorCandidate

public static Constructor getBestConstructorCandidate(Object[] args,
                                                      Class cls,
                                                      boolean requireExact)

getBestConstructorCandidate

public static Constructor getBestConstructorCandidate(Class[] arguments,
                                                      Class cls,
                                                      boolean requireExact)

createClass

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

getConstructors

public static Constructor[] getConstructors(Class cls)

captureContructorAndResidual

public static String[] captureContructorAndResidual(char[] cs)

boxPrimitive

public static Class boxPrimitive(Class cls)

unboxPrimitive

public static Class unboxPrimitive(Class cls)

containsCheck

public static boolean containsCheck(Object compareTo,
                                    Object compareTest)

createClassSignatureHash

public static int createClassSignatureHash(Class declaring,
                                           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(String name,
                                                        char[] statement,
                                                        int operation)

findClassImportResolverFactory

public static ClassImportResolverFactory findClassImportResolverFactory(VariableResolverFactory factory)

findClass

public static Class findClass(VariableResolverFactory factory,
                              String name,
                              ParserContext ctx)
                       throws ClassNotFoundException
Throws:
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(Object o)

resolveType

public static int resolveType(Class cls)

__resolveType

public static int __resolveType(Class cls)

isNumericallyCoercible

public static boolean isNumericallyCoercible(Class target,
                                             Class parm)

narrowType

public static Object narrowType(BigDecimal result,
                                int returnTarget)

determineActualTargetMethod

public static Method determineActualTargetMethod(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 String handleStringEscapes(char[] input)

captureStringLiteral

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

parseWithExpressions

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

handleNumericConversion

public static Object handleNumericConversion(char[] val)

isNumeric

public static boolean isNumeric(Object val)

numericTest

public static int numericTest(char[] val)

isNumber

public static boolean isNumber(Object val)

isNumber

public static boolean isNumber(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 String createStringTrimmed(char[] s)

createStringTrimmed

public static 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(String s1,
                               String s2)

findAbsoluteLast

public static int findAbsoluteLast(char[] array)

getBaseComponentType

public static Class getBaseComponentType(Class cls)

getSubComponentType

public static Class getSubComponentType(Class cls)

isJunct

public static boolean isJunct(char c)

opLookup

public static int opLookup(char c)

isReservedWord

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

Parameters:
name - -
Returns:
-

isNotValidNameorLabel

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

Parameters:
name - -
Returns:
-

checkNameSafety

public static void checkNameSafety(String name)

getDebugFileWriter

public static FileWriter getDebugFileWriter()
                                     throws IOException
Throws:
IOException

isPrimitiveWrapper

public static boolean isPrimitiveWrapper(Class clazz)

subCompileExpression

public static Serializable subCompileExpression(char[] expression)

subCompileExpression

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

subCompileExpression

public static Serializable subCompileExpression(String expression,
                                                ParserContext ctx)

optimizeTree

public static Serializable optimizeTree(CompiledExpression compiled)

isWhitespace

public static boolean isWhitespace(char c)

repeatChar

public static String repeatChar(char c,
                                int times)

loadFromFile

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

loadFromFile

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

readIn

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


Copyright © 2011. All Rights Reserved.