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
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private Map
<String, CompiledExpression> private boolean
private List
<ErrorDetail> private Object
private boolean
private boolean
private boolean
private boolean
private LineLabel
private Type[]
private int
private int
private boolean
private ParserContext
private ParserConfiguration
private boolean
private Parser
private String
private Map
<String, LineMapper.LineLookup> private boolean
private boolean
protected boolean
-
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 TypeMethodDescriptionvoid
addError
(ErrorDetail errorDetail) void
Adds an import for the specified Class.void
Adds an import for a specified Class using an alias.void
Adds an import for a specified Method representing a static method import using an alias.void
addImport
(String name, MethodStub method) Adds a static import for the specifiedMethodStub
with an alias.void
void
addIndexedInput
(String variable) void
addIndexedInput
(String[] variables) void
addIndexedInputs
(Collection<String> variables) void
addIndexedLocals
(String[] variables) void
addIndexedLocals
(Collection<String> variables) void
void
void
void
addPackageImport
(String packageName) Adds a package import to a parse session.void
void
addVariable
(String name, Class type) void
addVariable
(String name, Class type, boolean failIfNewAssignment) void
addVariables
(Map<String, Class> variables) static ParserContext
create()
void
declareFunction
(Function function) getFunction
(String name) Get an import that has been declared, either in the parsed script or programaticallyString[]
Type[]
int
Get total number of lines declared in the current context.int
getLineFor
(String sourceName, int cursor) int
Get the current line offset.getProtoImport
(String name) getStaticImport
(String name) Get aMethodStub
which 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.boolean
boolean
hasFunction
(String name) boolean
Tests to see if the specified import exists.boolean
boolean
boolean
hasProtoImport
(String name) boolean
hasVarOrInput
(String name) Tests whether or not a variable or input exists in the current parser context.int
incrementLineCount
(int increment) Increments the current line count by the specified amountvoid
Initializes internal Maps.private void
void
initLineMapping
(String sourceName, char[] expr) private void
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
isLineMapped
(String sourceName) boolean
boolean
boolean
boolean
boolean
boolean
isVariableVisible
(String var) boolean
isVisitedLine
(String sourceName, int lineNumber) void
makeVisible
(String var) void
void
void
void
void
setAllowBootstrapBypass
(boolean allowBootstrapBypass) void
setBlockSymbols
(boolean blockSymbols) void
setCompiled
(boolean compiled) void
setDebugSymbols
(boolean debugSymbols) void
setErrorList
(List<ErrorDetail> errorList) void
setExecutableCodeReached
(boolean executableCodeReached) void
setFatalError
(boolean fatalError) void
setImports
(Map<String, Object> imports) void
setIndexAllocation
(boolean indexAllocation) void
void
setInterceptors
(Map<String, Interceptor> interceptors) setLastLineLabel
(LineLabel lastLineLabel) void
setLastTypeParameters
(Type[] lastTypeParameters) void
setLineAndOffset
(int lineCount, int lineOffset) Sets both the current line count and line offsetint
setLineCount
(int lineCount) Set the current number of lines in the current context.void
setLineOffset
(int lineOffset) Sets the current line offset.void
setRetainParserState
(boolean retainParserState) void
setRootParser
(Parser rootParser) void
setSourceFile
(String sourceFile) void
setStrictTypeEnforcement
(boolean strictTypeEnforcement) Enables strict type enforcement -void
setStrongTyping
(boolean strongTyping) Enables strong type enforcement.void
setVariables
(HashMap<String, Class> variables) int
variableIndexOf
(String name) void
withImport
(Class clazz) withIndexedVars
(String[] varNames) withInputs
(Map<String, Class> inputs)
-
Field Details
-
sourceFile
-
lineCount
private int lineCount -
lineOffset
private int lineOffset -
parent
-
parserConfiguration
-
evaluationContext
-
indexedInputs
-
indexedLocals
-
variableVisibility
-
variables
-
inputs
-
typeParameters
-
lastTypeParameters
-
globalFunctions
-
errorList
-
sourceLineLookups
-
visitedLines
-
lastLineLabel
-
rootParser
-
compiledExpressionCache
-
returnTypeCache
-
functionContext
private boolean functionContext -
compiled
private boolean compiled -
strictTypeEnforcement
private boolean strictTypeEnforcement -
strongTyping
private boolean strongTyping -
optimizationMode
private boolean optimizationMode -
fatalError
private boolean fatalError -
retainParserState
private boolean retainParserState -
debugSymbols
private boolean debugSymbols -
blockSymbols
private boolean blockSymbols -
executableCodeReached
private boolean executableCodeReached -
indexAllocation
private boolean indexAllocation -
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
-
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 aMethodStub
which 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 specifiedMethodStub
with 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
-
initVariableVisibility
private void initVariableVisibility() -
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() -
initIndexedVariables
private void initIndexedVariables() -
getIndexedInputs
-
addIndexedInput
-
addIndexedLocals
-
addIndexedLocals
-
addIndexedInput
-
addIndexedInputs
-
variableIndexOf
-
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
-