Package org.mvel2.util
Class ParseTools
java.lang.Object
org.mvel2.util.ParseTools
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map
<Class, WeakReference<Constructor[]>> private static final Map
<ClassLoader, Map<String, WeakReference<Class>>> private static final Map
<Constructor, WeakReference<Class[]>> static final Class[]
static final Object[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
__resolveType
(Class cls) private static 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 Class
<?> boxPrimitive
(Class cls) static 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
(String name) private static int
comparePrecision
(Class<?> numeric1, Class<?> numeric2) static boolean
containsCheck
(Object compareTo, Object compareTest) private static boolean
containsCheckOnBooleanArray
(boolean[] array, Boolean compareTest) private static boolean
containsCheckOnByteArray
(byte[] array, Byte compareTest) private static boolean
containsCheckOnCharArray
(char[] array, Character compareTest) private static boolean
containsCheckOnDoubleArray
(double[] array, Double compareTest) private static boolean
containsCheckOnFloatArray
(float[] array, Float compareTest) private static boolean
containsCheckOnIntArray
(int[] array, Integer compareTest) private static boolean
containsCheckOnLongArray
(long[] array, Long compareTest) private static boolean
containsCheckOnPrimitveArray
(Object primitiveArray, Object compareTest) private static boolean
containsCheckOnShortArray
(short[] array, Short compareTest) static Class
createClass
(String className, ParserContext pCtx) static char[]
createShortFormOperativeAssignment
(String name, char[] statement, int start, int offset, int operation) static String
createStringTrimmed
(char[] s) static String
createStringTrimmed
(char[] s, int start, int length) private static Method
determineActualTargetMethod
(Class clazz, Method method) static Method
determineActualTargetMethod
(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 Class
findClass
(VariableResolverFactory factory, String name, ParserContext pCtx) static ClassImportResolverFactory
findClassImportResolverFactory
(VariableResolverFactory factory, ParserContext pCtx) static Class
findInnerClass
(String className, ClassLoader classLoader, ClassNotFoundException cnfe) static int
findLast
(char[] c, int start, int offset, char find) static Class
forNameWithInner
(String className, ClassLoader classLoader) static Class
static Method
getBestCandidate
(Class[] arguments, String method, Class decl, Method[] methods, boolean requireExact) static Method
getBestCandidate
(Class[] arguments, String method, Class decl, Method[] methods, boolean requireExact, boolean classTarget) 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) private static Class[]
static FileWriter
static Method
getExactMatch
(String name, Class[] args, Class returnType, Class cls) private static int
getMethodScore
(Class[] arguments, boolean requireExact, Class<?>[] parmTypes, boolean varArgs) static Class
getSubComponentType
(Class cls) static Method
getWidenedTarget
(Class cls, Method method) static Method
getWidenedTarget
(Method method) static int
handleEscapeSequence
(char[] escapeStr, int pos) Replace escape sequences and return trim required.static Object
handleNumericConversion
(char[] val, int start, int offset) static String
handleStringEscapes
(char[] input) private static boolean
isArgsNumberNotCompatible
(Class[] arguments, 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
(Executable newCandidate, Executable oldCandidate, Class[] arguments) private static boolean
isMoreSpecialized
(Method newCandidate, Method oldCandidate) static boolean
isNotValidNameorLabel
(String name) Check if the specfied string represents a valid name of label.static boolean
isNumber
(char[] val, int start, int offset) static boolean
static boolean
static boolean
static boolean
isNumericallyCoercible
(Class target, Class parm) private static boolean
isPrimitiveSubtype
(Class argument, Class<?> actualParamType) static boolean
isPrimitiveWrapper
(Class clazz) static boolean
isPropertyOnly
(char[] array, int start, int end) 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, int start, int offset) static int
opLookup
(char c) static Serializable
optimizeTree
(CompiledExpression compiled) static List
<char[]> parseMethodOrConstructor
(char[] parm) static String[]
parseParameterDefList
(char[] parm, int offset, int length) static List
<char[]> parseParameterList
(char[] parm, int offset, int length) static void
parseWithExpressions
(String nestParm, char[] block, int start, int offset, Object ctx, VariableResolverFactory factory) static char[]
readIn
(InputStream inStream, String encoding) static String
repeatChar
(char c, int times) static int
static int
scoreInterface
(Class<?> parm, Class<?> arg) static float
similarity
(String s1, String s2) private static int
skipStringEscape
(int cur) static int
skipWhitespace
(char[] expr, int cursor) static char[]
subArray
(char[] expr, int start, int end) static Serializable
subCompileExpression
(char[] expression) static Serializable
subCompileExpression
(char[] expression, int start, int offset, ParserContext ctx) 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 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 Class
unboxPrimitive
(Class cls)
-
Field Details
-
EMPTY_OBJ_ARR
-
EMPTY_CLS_ARR
-
CONSTRUCTOR_PARMS_CACHE
-
CLASS_RESOLVER_CACHE
-
CLASS_CONSTRUCTOR_CACHE
-
typeResolveMap
-
typeCodes
-
-
Constructor Details
-
ParseTools
public ParseTools()
-
-
Method Details
-
parseMethodOrConstructor
-
parseParameterDefList
-
parseParameterList
-
getBestCandidate
-
getBestCandidate
-
getBestCandidate
-
isArgsNumberNotCompatible
-
isMoreSpecialized
-
isMorePreciseForBigDecimal
private static boolean isMorePreciseForBigDecimal(Executable newCandidate, Executable oldCandidate, Class[] arguments) -
comparePrecision
-
getMethodScore
-
scoreInterface
-
getExactMatch
-
getWidenedTarget
-
getWidenedTarget
-
getConstructors
-
getBestConstructorCandidate
public static Constructor getBestConstructorCandidate(Object[] args, Class cls, boolean requireExact) -
getBestConstructorCandidate
public static Constructor getBestConstructorCandidate(Class[] arguments, Class cls, boolean requireExact) -
createClass
- Throws:
ClassNotFoundException
-
getConstructors
-
captureContructorAndResidual
-
boxPrimitive
-
unboxPrimitive
-
containsCheck
-
containsCheckOnPrimitveArray
-
containsCheckOnBooleanArray
-
containsCheckOnIntArray
-
containsCheckOnLongArray
-
containsCheckOnDoubleArray
-
containsCheckOnFloatArray
-
containsCheckOnCharArray
-
containsCheckOnShortArray
-
containsCheckOnByteArray
-
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 start, int offset, int operation) -
findClassImportResolverFactory
public static ClassImportResolverFactory findClassImportResolverFactory(VariableResolverFactory factory, ParserContext pCtx) -
findClass
public static Class findClass(VariableResolverFactory factory, String name, ParserContext pCtx) throws ClassNotFoundException - Throws:
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
-
__resolveType
-
isPrimitiveSubtype
-
isNumericallyCoercible
-
narrowType
-
determineActualTargetMethod
-
determineActualTargetMethod
-
captureToNextTokenJunction
-
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
-
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
-
captureStringLiteral
public static int captureStringLiteral(char type, char[] expr, int cursor, int end) -
parseWithExpressions
public static void parseWithExpressions(String nestParm, char[] block, int start, int offset, Object ctx, VariableResolverFactory factory) -
handleNumericConversion
-
isNumeric
-
numericTest
public static int numericTest(char[] val, int start, int offset) -
isNumber
-
isNumber
-
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
-
createStringTrimmed
-
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
-
findAbsoluteLast
public static int findAbsoluteLast(char[] array) -
getBaseComponentType
-
getSubComponentType
-
isJunct
public static boolean isJunct(char c) -
opLookup
public static int opLookup(char c) -
isReservedWord
Check if the specified string is a reserved word in the parser.- Parameters:
name
- -- Returns:
- -
-
isNotValidNameorLabel
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
-
getDebugFileWriter
- Throws:
IOException
-
isPrimitiveWrapper
-
subCompileExpression
-
subCompileExpression
-
subCompileExpression
public static Serializable subCompileExpression(char[] expression, int start, int offset, ParserContext ctx) -
subCompileExpression
-
optimizeTree
-
_optimizeTree
-
isWhitespace
public static boolean isWhitespace(char c) -
repeatChar
-
loadFromFile
- Throws:
IOException
-
loadFromFile
- Throws:
IOException
-
readIn
- Throws:
IOException
-
forNameWithInner
public static Class forNameWithInner(String className, ClassLoader classLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
findInnerClass
public static Class findInnerClass(String className, ClassLoader classLoader, ClassNotFoundException cnfe) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
skipStringEscape
private static int skipStringEscape(int cur)
-