Package org.mvel2
Class ParserContext
java.lang.Object
org.mvel2.ParserContext
- All Implemented Interfaces:
Serializable
The ParserContext is the main environment object used for sharing state throughout the entire
parser/compileShared process.
The ParserContext is used to configure the parser/compiler. For example:
ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true); // turn on strong typing.
Serializable comp = MVEL.compileExpression("foo.bar", parserContext);
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionParserContext(boolean debugSymbols) ParserContext(Map<String, Object> imports, Map<String, Interceptor> interceptors, String sourceFile) ParserContext(Parser rootParser) ParserContext(ParserConfiguration parserConfiguration) ParserContext(ParserConfiguration parserConfiguration, Object evaluationContext) ParserContext(ParserConfiguration parserConfiguration, ParserContext parent, boolean functionContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddError(ErrorDetail errorDetail) voidAdds an import for the specified Class.voidAdds an import for a specified Class using an alias.voidAdds an import for a specified Method representing a static method import using an alias.voidaddImport(String name, MethodStub method) Adds a static import for the specifiedMethodStubwith an alias.voidvoidaddIndexedInput(String variable) voidaddIndexedInput(String[] variables) voidaddIndexedInputs(Collection<String> variables) voidaddIndexedLocals(String[] variables) voidaddIndexedLocals(Collection<String> variables) voidvoidvoidvoidaddLocalDeclaration(String variable) voidaddPackageImport(String packageName) Adds a package import to a parse session.voidvoidaddVariable(String name, Class type) voidaddVariable(String name, Class type, boolean failIfNewAssignment) voidaddVariables(Map<String, Class> variables) static ParserContextcreate()voiddeclareFunction(Function function) static voidstatic SandboxedParserConfigurationgetFunction(String name) Get an import that has been declared, either in the parsed script or programaticallyString[]Type[]intGet total number of lines declared in the current context.intgetLineFor(String sourceName, int cursor) intGet the current line offset.getLiteral(String property) getProtoImport(String name) getStaticImport(String name) Get aMethodStubwhich wraps a static method import.getStaticOrClassImport(String name) Returns either an instance of Class orMethodStub(whichever matches).getTypeParameters(String name) Type[]getVarOrInputType(String name) Return the variable or input type froom the current parser context.booleanbooleanhasFunction(String name) booleanTests to see if the specified import exists.booleanbooleanbooleanhasLiteral(String property) booleanhasLocalDeclaration(String name) booleanhasProtoImport(String name) booleanhasVarOrInput(String name) Tests whether or not a variable or input exists in the current parser context.intincrementLineCount(int increment) Increments the current line count by the specified amountvoidInitializes internal Maps.voidinitLineMapping(String sourceName, char[] expr) booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanisLineMapped(String sourceName) booleanisMethodAllowed(Method method) booleanbooleanbooleanbooleanbooleanbooleanisVariableVisible(String var) booleanisVisitedLine(String sourceName, int lineNumber) voidmakeVisible(String var) voidvoidvoidvoidvoidsetAllowBootstrapBypass(boolean allowBootstrapBypass) voidsetBlockSymbols(boolean blockSymbols) voidsetCompiled(boolean compiled) voidsetDebugSymbols(boolean debugSymbols) voidsetErrorList(List<ErrorDetail> errorList) voidsetExecutableCodeReached(boolean executableCodeReached) voidsetFatalError(boolean fatalError) voidsetImports(Map<String, Object> imports) voidsetIndexAllocation(boolean indexAllocation) voidvoidsetInterceptors(Map<String, Interceptor> interceptors) setLastLineLabel(LineLabel lastLineLabel) voidsetLastTypeParameters(Type[] lastTypeParameters) voidsetLineAndOffset(int lineCount, int lineOffset) Sets both the current line count and line offsetintsetLineCount(int lineCount) Set the current number of lines in the current context.voidsetLineOffset(int lineOffset) Sets the current line offset.voidsetLiterals(Map<String, Object> literals) voidsetRetainParserState(boolean retainParserState) voidsetRootParser(Parser rootParser) voidsetSourceFile(String sourceFile) voidsetStrictTypeEnforcement(boolean strictTypeEnforcement) Enables strict type enforcement -voidsetStrongTyping(boolean strongTyping) Enables strong type enforcement.voidsetVariables(HashMap<String, Class> variables) intvariableIndexOf(String name) voidwithImport(Class clazz) withIndexedVars(String[] varNames) withInputs(Map<String, Class> inputs)
-
Field Details
-
variablesEscape
protected boolean variablesEscape
-
-
Constructor Details
-
ParserContext
public ParserContext() -
ParserContext
public ParserContext(boolean debugSymbols) -
ParserContext
-
ParserContext
-
ParserContext
-
ParserContext
public ParserContext(ParserConfiguration parserConfiguration, ParserContext parent, boolean functionContext) -
ParserContext
-
-
Method Details
-
enableSandboxedMode
-
disableSandboxedMode
public static void disableSandboxedMode() -
createSubcontext
-
createColoringSubcontext
-
hasVarOrInput
Tests whether or not a variable or input exists in the current parser context.- Parameters:
name- The name of the identifier.- Returns:
- boolean
-
getVarOrInputType
Return the variable or input type froom the current parser context. Returns Object.class if the type cannot be determined.- Parameters:
name- The name of the identifier- Returns:
- boolean
-
getVarOrInputTypeOrNull
-
getLineCount
public int getLineCount()Get total number of lines declared in the current context.- Returns:
- int of lines
-
setLineCount
public int setLineCount(int lineCount) Set the current number of lines in the current context. (Generally only used by the compiler)- Parameters:
lineCount- The number of lines- Returns:
- int of lines
-
incrementLineCount
public int incrementLineCount(int increment) Increments the current line count by the specified amount- Parameters:
increment- The number of lines to increment- Returns:
- int of lines
-
getLineOffset
public int getLineOffset()Get the current line offset. This measures the number of cursor positions back to the beginning of the line.- Returns:
- int offset
-
setLineOffset
public void setLineOffset(int lineOffset) Sets the current line offset. (Generally only used by the compiler)- Parameters:
lineOffset- The offset amount
-
setLineAndOffset
public void setLineAndOffset(int lineCount, int lineOffset) Sets both the current line count and line offset- Parameters:
lineCount- The line countlineOffset- The line offset
-
getImport
Get an import that has been declared, either in the parsed script or programatically- Parameters:
name- The name identifier for the imported class (ie. "HashMap")- Returns:
- An instance of Class denoting the imported class.
-
getStaticImport
Get aMethodStubwhich wraps a static method import.- Parameters:
name- The name identifier- Returns:
- An instance of
MethodStub
-
getStaticOrClassImport
Returns either an instance of Class orMethodStub(whichever matches).- Parameters:
name- The name identifier.- Returns:
- An instance of Class or
MethodStub
-
addPackageImport
Adds a package import to a parse session.- Parameters:
packageName- A fully qualified package (eg. java.util.concurrent).
-
hasImport
Tests to see if the specified import exists.- Parameters:
name- A name identifier- Returns:
- boolean
-
hasProtoImport
-
getProtoImport
-
addImport
Adds an import for the specified Class.- Parameters:
cls- The instance of the Class which represents the imported class.
-
addImport
-
addImport
Adds an import for a specified Class using an alias. For example:
... doing this would allow an MVEL script to be written as such:parserContext.addImport("sys", System.class);sys.currentTimeMillis();- Parameters:
name- The alias to usecls- The instance of the Class which represents the imported class.
-
addImport
Adds an import for a specified Method representing a static method import using an alias. For example:
... doing this allows the System.currentTimeMillis() method to be executed in a script simply by writing time().parserContext.addImport("time", MVEL.getStaticMethod(System.class, "currentTimeMillis", new Class[0]));- Parameters:
name- The alias to usemethod- The instance of Method which represents the static import.
-
addImport
Adds a static import for the specifiedMethodStubwith an alias.- Parameters:
name- The alias to usemethod- The instance of Method which represents the static import.- See Also:
-
initializeTables
public void initializeTables()Initializes internal Maps. Called by the compiler. -
addVariable
-
addVariable
-
addVariables
-
addInput
-
addInput
-
addInputs
-
processTables
public void processTables() -
getInputs
-
setInputs
-
getErrorList
-
setErrorList
-
addError
-
isFatalError
public boolean isFatalError() -
setFatalError
public void setFatalError(boolean fatalError) -
isStrictTypeEnforcement
public boolean isStrictTypeEnforcement() -
setStrictTypeEnforcement
public void setStrictTypeEnforcement(boolean strictTypeEnforcement) Enables strict type enforcement -- Parameters:
strictTypeEnforcement- -
-
isStrongTyping
public boolean isStrongTyping() -
setStrongTyping
public void setStrongTyping(boolean strongTyping) Enables strong type enforcement.- Parameters:
strongTyping- -
-
isRetainParserState
public boolean isRetainParserState() -
setRetainParserState
public void setRetainParserState(boolean retainParserState) -
getRootParser
-
setRootParser
-
getSourceFile
-
setSourceFile
-
getInterceptors
-
setInterceptors
-
getImports
-
setImports
-
pushVariableScope
public void pushVariableScope() -
popVariableScope
public void popVariableScope() -
makeVisible
-
getVariableScope
-
isVariableVisible
-
getVariables
-
setVariables
-
isCompiled
public boolean isCompiled() -
setCompiled
public void setCompiled(boolean compiled) -
isDebugSymbols
public boolean isDebugSymbols() -
setDebugSymbols
public void setDebugSymbols(boolean debugSymbols) -
isLineMapped
-
initLineMapping
-
getLineFor
-
isVisitedLine
-
visitLine
-
getLastLineLabel
-
setLastLineLabel
-
hasImports
public boolean hasImports() -
declareFunction
-
getFunction
-
getFunctions
-
hasFunction
-
hasFunction
public boolean hasFunction() -
addTypeParameters
-
getTypeParameters
-
getTypeParametersAsArray
-
isBlockSymbols
public boolean isBlockSymbols() -
setBlockSymbols
public void setBlockSymbols(boolean blockSymbols) -
isVariablesEscape
public boolean isVariablesEscape() -
isExecutableCodeReached
public boolean isExecutableCodeReached() -
setExecutableCodeReached
public void setExecutableCodeReached(boolean executableCodeReached) -
optimizationNotify
public void optimizationNotify() -
isOptimizerNotified
public boolean isOptimizerNotified() -
hasLiteral
-
getLiteral
-
setLiterals
-
getIndexedInputs
-
addIndexedInput
-
addIndexedLocals
-
addLocalDeclaration
-
addIndexedLocals
-
addIndexedInput
-
addIndexedInputs
-
variableIndexOf
-
hasLocalDeclaration
-
getEvaluationContext
-
hasIndexedInputs
public boolean hasIndexedInputs() -
isIndexAllocation
public boolean isIndexAllocation() -
setIndexAllocation
public void setIndexAllocation(boolean indexAllocation) -
isFunctionContext
public boolean isFunctionContext() -
getParserConfiguration
-
getClassLoader
-
getLastTypeParameters
-
setLastTypeParameters
-
isAllowBootstrapBypass
public boolean isAllowBootstrapBypass() -
setAllowBootstrapBypass
public void setAllowBootstrapBypass(boolean allowBootstrapBypass) -
getIndexedVarNames
-
getCompiledExpressionCache
-
getReturnTypeCache
-
create
-
stronglyTyped
-
withInput
-
withInputs
-
withTypeParameters
-
withImport
-
withIndexedVars
-
isMethodAllowed
-