Package org.mvel2.util
Class ParseTools
- java.lang.Object
-
- org.mvel2.util.ParseTools
-
public class ParseTools extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.Class,java.lang.ref.WeakReference<java.lang.reflect.Constructor[]>>
CLASS_CONSTRUCTOR_CACHE
private static java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.Class>>>
CLASS_RESOLVER_CACHE
private static java.util.Map<java.lang.reflect.Constructor,java.lang.ref.WeakReference<java.lang.Class[]>>
CONSTRUCTOR_PARMS_CACHE
static java.lang.Class[]
EMPTY_CLS_ARR
static java.lang.Object[]
EMPTY_OBJ_ARR
private static java.util.Map<java.lang.Class,java.lang.Integer>
typeCodes
private static java.util.HashMap<java.lang.Class,java.lang.Integer>
typeResolveMap
-
Constructor Summary
Constructors Constructor Description ParseTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
__resolveType(java.lang.Class cls)
private static java.io.Serializable
_optimizeTree(CompiledExpression compiled)
static int
balancedCapture(char[] chars, int start, char type)
This is an important aspect of the core parser tools.static int
balancedCapture(char[] chars, int start, int end, char type)
static int
balancedCaptureWithLineAccounting(char[] chars, int start, int end, char type, ParserContext pCtx)
static java.lang.Class<?>
boxPrimitive(java.lang.Class cls)
static java.lang.String[]
captureContructorAndResidual(char[] cs, int start, int offset)
static int
captureStringLiteral(char type, char[] expr, int cursor, int end)
static int
captureToEOS(char[] expr, int cursor, int end, ParserContext pCtx)
static int
captureToNextTokenJunction(char[] expr, int cursor, int end, ParserContext pCtx)
static void
checkNameSafety(java.lang.String name)
private static int
comparePrecision(java.lang.Class<?> numeric1, java.lang.Class<?> numeric2)
static boolean
containsCheck(java.lang.Object compareTo, java.lang.Object compareTest)
private static boolean
containsCheckOnBooleanArray(boolean[] array, java.lang.Boolean compareTest)
private static boolean
containsCheckOnByteArray(byte[] array, java.lang.Byte compareTest)
private static boolean
containsCheckOnCharArray(char[] array, java.lang.Character compareTest)
private static boolean
containsCheckOnDoubleArray(double[] array, java.lang.Double compareTest)
private static boolean
containsCheckOnFloatArray(float[] array, java.lang.Float compareTest)
private static boolean
containsCheckOnIntArray(int[] array, java.lang.Integer compareTest)
private static boolean
containsCheckOnLongArray(long[] array, java.lang.Long compareTest)
private static boolean
containsCheckOnPrimitveArray(java.lang.Object primitiveArray, java.lang.Object compareTest)
private static boolean
containsCheckOnShortArray(short[] array, java.lang.Short compareTest)
static java.lang.Class
createClass(java.lang.String className, ParserContext pCtx)
static char[]
createShortFormOperativeAssignment(java.lang.String name, char[] statement, int start, int offset, int operation)
static java.lang.String
createStringTrimmed(char[] s)
static java.lang.String
createStringTrimmed(char[] s, int start, int length)
private static java.lang.reflect.Method
determineActualTargetMethod(java.lang.Class clazz, java.lang.reflect.Method method)
static java.lang.reflect.Method
determineActualTargetMethod(java.lang.reflect.Method method)
static boolean
endsWith(char[] c, int start, int offset, char[] test)
static int
find(char[] c, int start, int offset, char find)
static int
findAbsoluteLast(char[] array)
static java.lang.Class
findClass(VariableResolverFactory factory, java.lang.String name, ParserContext pCtx)
static ClassImportResolverFactory
findClassImportResolverFactory(VariableResolverFactory factory, ParserContext pCtx)
static java.lang.Class
findInnerClass(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.ClassNotFoundException cnfe)
static int
findLast(char[] c, int start, int offset, char find)
static java.lang.Class
forNameWithInner(java.lang.String className, java.lang.ClassLoader classLoader)
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.Class[] arguments, java.lang.String method, java.lang.Class decl, java.lang.reflect.Method[] methods, boolean requireExact, boolean classTarget)
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)
private static java.lang.Class[]
getConstructors(java.lang.reflect.Constructor cns)
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)
private static int
getMethodScore(java.lang.Class[] arguments, boolean requireExact, java.lang.Class<?>[] parmTypes, boolean varArgs)
static java.lang.Class
getSubComponentType(java.lang.Class cls)
static java.lang.reflect.Method
getWidenedTarget(java.lang.Class cls, java.lang.reflect.Method method)
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, int start, int offset)
static java.lang.String
handleStringEscapes(char[] input)
private static boolean
isArgsNumberNotCompatible(java.lang.Class[] arguments, java.lang.Class<?>[] parmTypes, boolean isVarArgs)
static boolean
isArrayType(char[] array, int start, int end)
static boolean
isDigit(int c)
static boolean
isIdentifierPart(int c)
static boolean
isJunct(char c)
private static boolean
isMorePreciseForBigDecimal(java.lang.reflect.Method newCandidate, java.lang.reflect.Method oldCandidate, java.lang.Class[] arguments)
private static boolean
isMoreSpecialized(java.lang.reflect.Method newCandidate, java.lang.reflect.Method oldCandidate)
static boolean
isNotValidNameorLabel(java.lang.String name)
Check if the specfied string represents a valid name of label.static boolean
isNumber(char[] val, int start, int offset)
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)
private static boolean
isPrimitiveSubtype(java.lang.Class argument, java.lang.Class<?> actualParamType)
static boolean
isPrimitiveWrapper(java.lang.Class clazz)
static boolean
isPropertyOnly(char[] array, int start, int end)
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, int start, int offset)
static int
opLookup(char c)
static java.io.Serializable
optimizeTree(CompiledExpression compiled)
static java.util.List<char[]>
parseMethodOrConstructor(char[] parm)
static java.lang.String[]
parseParameterDefList(char[] parm, int offset, int length)
static java.util.List<char[]>
parseParameterList(char[] parm, int offset, int length)
static void
parseWithExpressions(java.lang.String nestParm, char[] block, int start, int offset, 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.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)
static char[]
subArray(char[] expr, int start, int end)
static java.io.Serializable
subCompileExpression(char[] expression)
static java.io.Serializable
subCompileExpression(char[] expression, int start, int offset, ParserContext ctx)
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 char[]
subsetTrimmed(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 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)
-
-
-
Field Detail
-
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_PARMS_CACHE
private static final java.util.Map<java.lang.reflect.Constructor,java.lang.ref.WeakReference<java.lang.Class[]>> CONSTRUCTOR_PARMS_CACHE
-
CLASS_RESOLVER_CACHE
private static final java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.Class>>> CLASS_RESOLVER_CACHE
-
CLASS_CONSTRUCTOR_CACHE
private static final java.util.Map<java.lang.Class,java.lang.ref.WeakReference<java.lang.reflect.Constructor[]>> CLASS_CONSTRUCTOR_CACHE
-
typeResolveMap
private static final java.util.HashMap<java.lang.Class,java.lang.Integer> typeResolveMap
-
typeCodes
private static final java.util.Map<java.lang.Class,java.lang.Integer> typeCodes
-
-
Method Detail
-
parseMethodOrConstructor
public static java.util.List<char[]> parseMethodOrConstructor(char[] parm)
-
parseParameterDefList
public static java.lang.String[] parseParameterDefList(char[] parm, int offset, int length)
-
parseParameterList
public static java.util.List<char[]> 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)
-
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, boolean classTarget)
-
isArgsNumberNotCompatible
private static boolean isArgsNumberNotCompatible(java.lang.Class[] arguments, java.lang.Class<?>[] parmTypes, boolean isVarArgs)
-
isMoreSpecialized
private static boolean isMoreSpecialized(java.lang.reflect.Method newCandidate, java.lang.reflect.Method oldCandidate)
-
isMorePreciseForBigDecimal
private static boolean isMorePreciseForBigDecimal(java.lang.reflect.Method newCandidate, java.lang.reflect.Method oldCandidate, java.lang.Class[] arguments)
-
comparePrecision
private static int comparePrecision(java.lang.Class<?> numeric1, java.lang.Class<?> numeric2)
-
getMethodScore
private static int getMethodScore(java.lang.Class[] arguments, boolean requireExact, java.lang.Class<?>[] parmTypes, boolean varArgs)
-
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)
-
getWidenedTarget
public static java.lang.reflect.Method getWidenedTarget(java.lang.Class cls, java.lang.reflect.Method method)
-
getConstructors
private static java.lang.Class[] getConstructors(java.lang.reflect.Constructor cns)
-
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, int start, int offset)
-
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)
-
containsCheckOnPrimitveArray
private static boolean containsCheckOnPrimitveArray(java.lang.Object primitiveArray, java.lang.Object compareTest)
-
containsCheckOnBooleanArray
private static boolean containsCheckOnBooleanArray(boolean[] array, java.lang.Boolean compareTest)
-
containsCheckOnIntArray
private static boolean containsCheckOnIntArray(int[] array, java.lang.Integer compareTest)
-
containsCheckOnLongArray
private static boolean containsCheckOnLongArray(long[] array, java.lang.Long compareTest)
-
containsCheckOnDoubleArray
private static boolean containsCheckOnDoubleArray(double[] array, java.lang.Double compareTest)
-
containsCheckOnFloatArray
private static boolean containsCheckOnFloatArray(float[] array, java.lang.Float compareTest)
-
containsCheckOnCharArray
private static boolean containsCheckOnCharArray(char[] array, java.lang.Character compareTest)
-
containsCheckOnShortArray
private static boolean containsCheckOnShortArray(short[] array, java.lang.Short compareTest)
-
containsCheckOnByteArray
private static boolean containsCheckOnByteArray(byte[] array, java.lang.Byte compareTest)
-
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 start, int offset, int operation)
-
findClassImportResolverFactory
public static ClassImportResolverFactory findClassImportResolverFactory(VariableResolverFactory factory, ParserContext pCtx)
-
findClass
public static java.lang.Class findClass(VariableResolverFactory factory, java.lang.String name, ParserContext pCtx) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
subsetTrimmed
public static char[] subsetTrimmed(char[] array, int start, int length)
-
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)
-
isPrimitiveSubtype
private static boolean isPrimitiveSubtype(java.lang.Class argument, java.lang.Class<?> actualParamType)
-
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)
-
determineActualTargetMethod
private static java.lang.reflect.Method determineActualTargetMethod(java.lang.Class clazz, java.lang.reflect.Method method)
-
captureToNextTokenJunction
public static int captureToNextTokenJunction(char[] expr, int cursor, int end, ParserContext pCtx)
-
nextNonBlank
public static int nextNonBlank(char[] expr, int cursor)
-
skipWhitespace
public static int skipWhitespace(char[] expr, int cursor)
-
isStatementNotManuallyTerminated
public static boolean isStatementNotManuallyTerminated(char[] expr, int cursor)
-
captureToEOS
public static int captureToEOS(char[] expr, int cursor, int end, 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:
expr
- -start
- -pos
- - current position- Returns:
- new position.
-
trimRight
public static int trimRight(char[] expr, int pos)
From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.- Parameters:
expr
- -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:
- -
-
balancedCapture
public static int balancedCapture(char[] chars, int start, int end, char type)
-
balancedCaptureWithLineAccounting
public static int balancedCaptureWithLineAccounting(char[] chars, int start, int end, 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 end)
-
parseWithExpressions
public static void parseWithExpressions(java.lang.String nestParm, char[] block, int start, int offset, java.lang.Object ctx, VariableResolverFactory factory)
-
handleNumericConversion
public static java.lang.Object handleNumericConversion(char[] val, int start, int offset)
-
isNumeric
public static boolean isNumeric(java.lang.Object val)
-
numericTest
public static int numericTest(char[] val, int start, int offset)
-
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, int start, int offset)
-
find
public static int find(char[] c, int start, int offset, char find)
-
findLast
public static int findLast(char[] c, int start, int offset, 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, int start, int offset, 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:
- -
-
isPropertyOnly
public static boolean isPropertyOnly(char[] array, int start, int end)
-
isArrayType
public static boolean isArrayType(char[] array, int start, int end)
-
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(char[] expression, int start, int offset, ParserContext ctx)
-
subCompileExpression
public static java.io.Serializable subCompileExpression(java.lang.String expression, ParserContext ctx)
-
optimizeTree
public static java.io.Serializable optimizeTree(CompiledExpression compiled)
-
_optimizeTree
private 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
-
forNameWithInner
public static java.lang.Class forNameWithInner(java.lang.String className, java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
findInnerClass
public static java.lang.Class findInnerClass(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.ClassNotFoundException cnfe) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
-