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_CACHEprivate static java.util.Map<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.ref.WeakReference<java.lang.Class>>>CLASS_RESOLVER_CACHEprivate static java.util.Map<java.lang.reflect.Constructor,java.lang.ref.WeakReference<java.lang.Class[]>>CONSTRUCTOR_PARMS_CACHEstatic java.lang.Class[]EMPTY_CLS_ARRstatic java.lang.Object[]EMPTY_OBJ_ARRprivate static java.util.Map<java.lang.Class,java.lang.Integer>typeCodesprivate 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 intbalancedCapture(char[] chars, int start, char type)This is an important aspect of the core parser tools.static intbalancedCapture(char[] chars, int start, int end, char type)static intbalancedCaptureWithLineAccounting(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 intcaptureStringLiteral(char type, char[] expr, int cursor, int end)static intcaptureToEOS(char[] expr, int cursor, int end, ParserContext pCtx)static intcaptureToNextTokenJunction(char[] expr, int cursor, int end, ParserContext pCtx)static voidcheckNameSafety(java.lang.String name)private static intcomparePrecision(java.lang.Class<?> numeric1, java.lang.Class<?> numeric2)static booleancontainsCheck(java.lang.Object compareTo, java.lang.Object compareTest)private static booleancontainsCheckOnBooleanArray(boolean[] array, java.lang.Boolean compareTest)private static booleancontainsCheckOnByteArray(byte[] array, java.lang.Byte compareTest)private static booleancontainsCheckOnCharArray(char[] array, java.lang.Character compareTest)private static booleancontainsCheckOnDoubleArray(double[] array, java.lang.Double compareTest)private static booleancontainsCheckOnFloatArray(float[] array, java.lang.Float compareTest)private static booleancontainsCheckOnIntArray(int[] array, java.lang.Integer compareTest)private static booleancontainsCheckOnLongArray(long[] array, java.lang.Long compareTest)private static booleancontainsCheckOnPrimitveArray(java.lang.Object primitiveArray, java.lang.Object compareTest)private static booleancontainsCheckOnShortArray(short[] array, java.lang.Short compareTest)static java.lang.ClasscreateClass(java.lang.String className, ParserContext pCtx)static char[]createShortFormOperativeAssignment(java.lang.String name, char[] statement, int start, int offset, int operation)static java.lang.StringcreateStringTrimmed(char[] s)static java.lang.StringcreateStringTrimmed(char[] s, int start, int length)private static java.lang.reflect.MethoddetermineActualTargetMethod(java.lang.Class clazz, java.lang.reflect.Method method)static java.lang.reflect.MethoddetermineActualTargetMethod(java.lang.reflect.Method method)static booleanendsWith(char[] c, int start, int offset, char[] test)static intfind(char[] c, int start, int offset, char find)static intfindAbsoluteLast(char[] array)static java.lang.ClassfindClass(VariableResolverFactory factory, java.lang.String name, ParserContext pCtx)static ClassImportResolverFactoryfindClassImportResolverFactory(VariableResolverFactory factory, ParserContext pCtx)static java.lang.ClassfindInnerClass(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.ClassNotFoundException cnfe)static intfindLast(char[] c, int start, int offset, char find)static java.lang.ClassforNameWithInner(java.lang.String className, java.lang.ClassLoader classLoader)static java.lang.ClassgetBaseComponentType(java.lang.Class cls)static java.lang.reflect.MethodgetBestCandidate(java.lang.Class[] arguments, java.lang.String method, java.lang.Class decl, java.lang.reflect.Method[] methods, boolean requireExact)static java.lang.reflect.MethodgetBestCandidate(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.MethodgetBestCandidate(java.lang.Object[] arguments, java.lang.String method, java.lang.Class decl, java.lang.reflect.Method[] methods, boolean requireExact)static java.lang.reflect.ConstructorgetBestConstructorCandidate(java.lang.Class[] arguments, java.lang.Class cls, boolean requireExact)static java.lang.reflect.ConstructorgetBestConstructorCandidate(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.FileWritergetDebugFileWriter()static java.lang.reflect.MethodgetExactMatch(java.lang.String name, java.lang.Class[] args, java.lang.Class returnType, java.lang.Class cls)private static intgetMethodScore(java.lang.Class[] arguments, boolean requireExact, java.lang.Class<?>[] parmTypes, boolean varArgs)static java.lang.ClassgetSubComponentType(java.lang.Class cls)static java.lang.reflect.MethodgetWidenedTarget(java.lang.Class cls, java.lang.reflect.Method method)static java.lang.reflect.MethodgetWidenedTarget(java.lang.reflect.Method method)static inthandleEscapeSequence(char[] escapeStr, int pos)Replace escape sequences and return trim required.static java.lang.ObjecthandleNumericConversion(char[] val, int start, int offset)static java.lang.StringhandleStringEscapes(char[] input)private static booleanisArgsNumberNotCompatible(java.lang.Class[] arguments, java.lang.Class<?>[] parmTypes, boolean isVarArgs)static booleanisArrayType(char[] array, int start, int end)static booleanisDigit(int c)static booleanisIdentifierPart(int c)static booleanisJunct(char c)private static booleanisMorePreciseForBigDecimal(java.lang.reflect.Executable newCandidate, java.lang.reflect.Executable oldCandidate, java.lang.Class[] arguments)private static booleanisMoreSpecialized(java.lang.reflect.Method newCandidate, java.lang.reflect.Method oldCandidate)static booleanisNotValidNameorLabel(java.lang.String name)Check if the specfied string represents a valid name of label.static booleanisNumber(char[] val, int start, int offset)static booleanisNumber(java.lang.Object val)static booleanisNumber(java.lang.String val)static booleanisNumeric(java.lang.Object val)static booleanisNumericallyCoercible(java.lang.Class target, java.lang.Class parm)private static booleanisPrimitiveSubtype(java.lang.Class argument, java.lang.Class<?> actualParamType)static booleanisPrimitiveWrapper(java.lang.Class clazz)static booleanisPropertyOnly(char[] array, int start, int end)static booleanisReservedWord(java.lang.String name)Check if the specified string is a reserved word in the parser.static booleanisStatementNotManuallyTerminated(char[] expr, int cursor)static booleanisWhitespace(char c)static char[]loadFromFile(java.io.File file)static char[]loadFromFile(java.io.File file, java.lang.String encoding)static java.lang.ObjectnarrowType(java.math.BigDecimal result, int returnTarget)static intnextNonBlank(char[] expr, int cursor)static intnumericTest(char[] val, int start, int offset)static intopLookup(char c)static java.io.SerializableoptimizeTree(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 voidparseWithExpressions(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.StringrepeatChar(char c, int times)static intresolveType(java.lang.Object o)static intscoreInterface(java.lang.Class<?> parm, java.lang.Class<?> arg)static floatsimilarity(java.lang.String s1, java.lang.String s2)private static intskipStringEscape(int cur)static intskipWhitespace(char[] expr, int cursor)static char[]subArray(char[] expr, int start, int end)static java.io.SerializablesubCompileExpression(char[] expression)static java.io.SerializablesubCompileExpression(char[] expression, int start, int offset, ParserContext ctx)static java.io.SerializablesubCompileExpression(char[] expression, ParserContext ctx)static java.io.SerializablesubCompileExpression(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 inttrimLeft(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 inttrimRight(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.ClassunboxPrimitive(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.Executable newCandidate, java.lang.reflect.Executable 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
-
skipStringEscape
private static int skipStringEscape(int cur)
-
-