public class ParserContext
extends java.lang.Object
implements java.io.Serializable
ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true); // turn on strong typing.
Serializable comp = MVEL.compileExpression("foo.bar", parserContext);
Modifier and Type | Field and Description |
---|---|
private boolean |
blockSymbols |
private boolean |
compiled |
private java.util.Map<java.lang.String,CompiledExpression> |
compiledExpressionCache |
private boolean |
debugSymbols |
private java.util.List<ErrorDetail> |
errorList |
private java.lang.Object |
evaluationContext |
private boolean |
executableCodeReached |
private boolean |
fatalError |
private boolean |
functionContext |
private java.util.HashMap<java.lang.String,Function> |
globalFunctions |
private boolean |
indexAllocation |
private java.util.ArrayList<java.lang.String> |
indexedInputs |
private java.util.ArrayList<java.lang.String> |
indexedLocals |
private java.util.Map<java.lang.String,java.lang.Class> |
inputs |
private LineLabel |
lastLineLabel |
private java.lang.reflect.Type[] |
lastTypeParameters |
private int |
lineCount |
private int |
lineOffset |
private boolean |
optimizationMode |
private ParserContext |
parent |
private ParserConfiguration |
parserConfiguration |
private boolean |
retainParserState |
private java.util.Map<java.lang.String,java.lang.Class> |
returnTypeCache |
private Parser |
rootParser |
private java.lang.String |
sourceFile |
private java.util.Map<java.lang.String,LineMapper.LineLookup> |
sourceLineLookups |
private boolean |
strictTypeEnforcement |
private boolean |
strongTyping |
private java.util.HashMap<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Type>> |
typeParameters |
private java.util.HashMap<java.lang.String,java.lang.Class> |
variables |
protected boolean |
variablesEscape |
private java.util.ArrayList<java.util.Set<java.lang.String>> |
variableVisibility |
private java.util.Map<java.lang.String,java.util.Set<java.lang.Integer>> |
visitedLines |
Constructor and Description |
---|
ParserContext() |
ParserContext(boolean debugSymbols) |
ParserContext(java.util.Map<java.lang.String,java.lang.Object> imports,
java.util.Map<java.lang.String,Interceptor> interceptors,
java.lang.String sourceFile) |
ParserContext(Parser rootParser) |
ParserContext(ParserConfiguration parserConfiguration) |
ParserContext(ParserConfiguration parserConfiguration,
java.lang.Object evaluationContext) |
ParserContext(ParserConfiguration parserConfiguration,
ParserContext parent,
boolean functionContext) |
Modifier and Type | Method and Description |
---|---|
void |
addError(ErrorDetail errorDetail) |
void |
addImport(java.lang.Class cls)
Adds an import for the specified Class.
|
void |
addImport(Proto proto) |
void |
addImport(java.lang.String name,
java.lang.Class cls)
Adds an import for a specified Class using an alias.
|
void |
addImport(java.lang.String name,
java.lang.reflect.Method method)
Adds an import for a specified Method representing a static method import using an alias.
|
void |
addImport(java.lang.String name,
MethodStub method)
Adds a static import for the specified
MethodStub with an alias. |
void |
addIndexedInput(java.lang.String variable) |
void |
addIndexedInput(java.lang.String[] variables) |
void |
addIndexedInputs(java.util.Collection<java.lang.String> variables) |
void |
addIndexedLocals(java.util.Collection<java.lang.String> variables) |
void |
addIndexedLocals(java.lang.String[] variables) |
void |
addInput(java.lang.String name,
java.lang.Class type) |
void |
addInput(java.lang.String name,
java.lang.Class type,
java.lang.Class[] typeParameters) |
void |
addInputs(java.util.Map<java.lang.String,java.lang.Class> inputs) |
void |
addPackageImport(java.lang.String packageName)
Adds a package import to a parse session.
|
void |
addTypeParameters(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Type>> typeParameters) |
void |
addVariable(java.lang.String name,
java.lang.Class type) |
void |
addVariable(java.lang.String name,
java.lang.Class type,
boolean failIfNewAssignment) |
void |
addVariables(java.util.Map<java.lang.String,java.lang.Class> variables) |
static ParserContext |
create() |
ParserContext |
createColoringSubcontext() |
ParserContext |
createSubcontext() |
void |
declareFunction(Function function) |
java.lang.ClassLoader |
getClassLoader() |
java.util.Map<java.lang.String,CompiledExpression> |
getCompiledExpressionCache() |
java.util.List<ErrorDetail> |
getErrorList() |
java.lang.Object |
getEvaluationContext() |
Function |
getFunction(java.lang.String name) |
java.util.Map |
getFunctions() |
java.lang.Class |
getImport(java.lang.String name)
Get an import that has been declared, either in the parsed script or programatically
|
java.util.Map<java.lang.String,java.lang.Object> |
getImports() |
java.util.ArrayList<java.lang.String> |
getIndexedInputs() |
java.lang.String[] |
getIndexedVarNames() |
java.util.Map<java.lang.String,java.lang.Class> |
getInputs() |
java.util.Map<java.lang.String,Interceptor> |
getInterceptors() |
LineLabel |
getLastLineLabel() |
java.lang.reflect.Type[] |
getLastTypeParameters() |
int |
getLineCount()
Get total number of lines declared in the current context.
|
int |
getLineFor(java.lang.String sourceName,
int cursor) |
int |
getLineOffset()
Get the current line offset.
|
ParserConfiguration |
getParserConfiguration() |
Proto |
getProtoImport(java.lang.String name) |
java.util.Map<java.lang.String,java.lang.Class> |
getReturnTypeCache() |
Parser |
getRootParser() |
java.lang.String |
getSourceFile() |
MethodStub |
getStaticImport(java.lang.String name)
Get a
MethodStub which wraps a static method import. |
java.lang.Object |
getStaticOrClassImport(java.lang.String name)
Returns either an instance of Class or
MethodStub (whichever matches). |
java.util.Map<java.lang.String,java.lang.reflect.Type> |
getTypeParameters(java.lang.String name) |
java.lang.reflect.Type[] |
getTypeParametersAsArray(java.lang.String name) |
java.util.HashMap<java.lang.String,java.lang.Class> |
getVariables() |
java.util.Set<java.lang.String> |
getVariableScope() |
java.lang.Class |
getVarOrInputType(java.lang.String name)
Return the variable or input type froom the current parser context.
|
java.lang.Class |
getVarOrInputTypeOrNull(java.lang.String name) |
boolean |
hasFunction() |
boolean |
hasFunction(java.lang.String name) |
boolean |
hasImport(java.lang.String name)
Tests to see if the specified import exists.
|
boolean |
hasImports() |
boolean |
hasIndexedInputs() |
boolean |
hasProtoImport(java.lang.String name) |
boolean |
hasVarOrInput(java.lang.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 amount
|
void |
initializeTables()
Initializes internal Maps.
|
private void |
initIndexedVariables() |
void |
initLineMapping(java.lang.String sourceName,
char[] expr) |
private void |
initVariableVisibility() |
boolean |
isAllowBootstrapBypass() |
boolean |
isBlockSymbols() |
boolean |
isCompiled() |
boolean |
isDebugSymbols() |
boolean |
isExecutableCodeReached() |
boolean |
isFatalError() |
boolean |
isFunctionContext() |
boolean |
isIndexAllocation() |
boolean |
isLineMapped(java.lang.String sourceName) |
boolean |
isOptimizerNotified() |
boolean |
isRetainParserState() |
boolean |
isStrictTypeEnforcement() |
boolean |
isStrongTyping() |
boolean |
isVariablesEscape() |
boolean |
isVariableVisible(java.lang.String var) |
boolean |
isVisitedLine(java.lang.String sourceName,
int lineNumber) |
void |
makeVisible(java.lang.String var) |
void |
optimizationNotify() |
void |
popVariableScope() |
void |
processTables() |
void |
pushVariableScope() |
void |
setAllowBootstrapBypass(boolean allowBootstrapBypass) |
void |
setBlockSymbols(boolean blockSymbols) |
void |
setCompiled(boolean compiled) |
void |
setDebugSymbols(boolean debugSymbols) |
void |
setErrorList(java.util.List<ErrorDetail> errorList) |
void |
setExecutableCodeReached(boolean executableCodeReached) |
void |
setFatalError(boolean fatalError) |
void |
setImports(java.util.Map<java.lang.String,java.lang.Object> imports) |
void |
setIndexAllocation(boolean indexAllocation) |
void |
setInputs(java.util.Map<java.lang.String,java.lang.Class> inputs) |
void |
setInterceptors(java.util.Map<java.lang.String,Interceptor> interceptors) |
LineLabel |
setLastLineLabel(LineLabel lastLineLabel) |
void |
setLastTypeParameters(java.lang.reflect.Type[] lastTypeParameters) |
void |
setLineAndOffset(int lineCount,
int lineOffset)
Sets both the current line count and line offset
|
int |
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(java.lang.String sourceFile) |
void |
setStrictTypeEnforcement(boolean strictTypeEnforcement)
Enables strict type enforcement -
|
void |
setStrongTyping(boolean strongTyping)
Enables strong type enforcement.
|
void |
setVariables(java.util.HashMap<java.lang.String,java.lang.Class> variables) |
ParserContext |
stronglyTyped() |
int |
variableIndexOf(java.lang.String name) |
void |
visitLine(java.lang.String sourceName,
int lineNumber) |
ParserContext |
withImport(java.lang.Class clazz) |
ParserContext |
withIndexedVars(java.lang.String[] varNames) |
ParserContext |
withInput(java.lang.String name,
java.lang.Class type) |
ParserContext |
withInputs(java.util.Map<java.lang.String,java.lang.Class> inputs) |
ParserContext |
withTypeParameters(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Type>> typeParameters) |
private java.lang.String sourceFile
private int lineCount
private int lineOffset
private ParserContext parent
private ParserConfiguration parserConfiguration
private java.lang.Object evaluationContext
private java.util.ArrayList<java.lang.String> indexedInputs
private java.util.ArrayList<java.lang.String> indexedLocals
private java.util.ArrayList<java.util.Set<java.lang.String>> variableVisibility
private java.util.HashMap<java.lang.String,java.lang.Class> variables
private java.util.Map<java.lang.String,java.lang.Class> inputs
private transient java.util.HashMap<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Type>> typeParameters
private transient java.lang.reflect.Type[] lastTypeParameters
private java.util.HashMap<java.lang.String,Function> globalFunctions
private transient java.util.List<ErrorDetail> errorList
private transient java.util.Map<java.lang.String,LineMapper.LineLookup> sourceLineLookups
private transient java.util.Map<java.lang.String,java.util.Set<java.lang.Integer>> visitedLines
private LineLabel lastLineLabel
private transient Parser rootParser
private transient java.util.Map<java.lang.String,CompiledExpression> compiledExpressionCache
private transient java.util.Map<java.lang.String,java.lang.Class> returnTypeCache
private boolean functionContext
private boolean compiled
private boolean strictTypeEnforcement
private boolean strongTyping
private boolean optimizationMode
private boolean fatalError
private boolean retainParserState
private boolean debugSymbols
private boolean blockSymbols
private boolean executableCodeReached
private boolean indexAllocation
protected boolean variablesEscape
public ParserContext()
public ParserContext(boolean debugSymbols)
public ParserContext(Parser rootParser)
public ParserContext(ParserConfiguration parserConfiguration)
public ParserContext(ParserConfiguration parserConfiguration, java.lang.Object evaluationContext)
public ParserContext(ParserConfiguration parserConfiguration, ParserContext parent, boolean functionContext)
public ParserContext(java.util.Map<java.lang.String,java.lang.Object> imports, java.util.Map<java.lang.String,Interceptor> interceptors, java.lang.String sourceFile)
public ParserContext createSubcontext()
public ParserContext createColoringSubcontext()
public boolean hasVarOrInput(java.lang.String name)
name
- The name of the identifier.public java.lang.Class getVarOrInputType(java.lang.String name)
name
- The name of the identifierpublic java.lang.Class getVarOrInputTypeOrNull(java.lang.String name)
public int getLineCount()
public int setLineCount(int lineCount)
lineCount
- The number of linespublic int incrementLineCount(int increment)
increment
- The number of lines to incrementpublic int getLineOffset()
public void setLineOffset(int lineOffset)
lineOffset
- The offset amountpublic void setLineAndOffset(int lineCount, int lineOffset)
lineCount
- The line countlineOffset
- The line offsetpublic java.lang.Class getImport(java.lang.String name)
name
- The name identifier for the imported class (ie. "HashMap")public MethodStub getStaticImport(java.lang.String name)
MethodStub
which wraps a static method import.name
- The name identifierMethodStub
public java.lang.Object getStaticOrClassImport(java.lang.String name)
MethodStub
(whichever matches).name
- The name identifier.MethodStub
public void addPackageImport(java.lang.String packageName)
packageName
- A fully qualified package (eg. java.util.concurrent).public boolean hasImport(java.lang.String name)
name
- A name identifierpublic boolean hasProtoImport(java.lang.String name)
public Proto getProtoImport(java.lang.String name)
public void addImport(java.lang.Class cls)
cls
- The instance of the Class which represents the imported class.public void addImport(Proto proto)
public void addImport(java.lang.String name, java.lang.Class cls)
parserContext.addImport("sys", System.class);
... doing this would allow an MVEL script to be written as such:
sys.currentTimeMillis();
name
- The alias to usecls
- The instance of the Class which represents the imported class.public void addImport(java.lang.String name, java.lang.reflect.Method method)
parserContext.addImport("time", MVEL.getStaticMethod(System.class, "currentTimeMillis", new Class[0]));
... doing this allows the System.currentTimeMillis() method to be executed in a script simply by writing
time().name
- The alias to usemethod
- The instance of Method which represents the static import.public void addImport(java.lang.String name, MethodStub method)
MethodStub
with an alias.name
- The alias to usemethod
- The instance of Method which represents the static import.addImport(String, org.mvel2.util.MethodStub)
public void initializeTables()
public void addVariable(java.lang.String name, java.lang.Class type, boolean failIfNewAssignment)
public void addVariable(java.lang.String name, java.lang.Class type)
public void addVariables(java.util.Map<java.lang.String,java.lang.Class> variables)
public void addInput(java.lang.String name, java.lang.Class type)
public void addInput(java.lang.String name, java.lang.Class type, java.lang.Class[] typeParameters)
public void addInputs(java.util.Map<java.lang.String,java.lang.Class> inputs)
public void processTables()
public java.util.Map<java.lang.String,java.lang.Class> getInputs()
public void setInputs(java.util.Map<java.lang.String,java.lang.Class> inputs)
public java.util.List<ErrorDetail> getErrorList()
public void setErrorList(java.util.List<ErrorDetail> errorList)
public void addError(ErrorDetail errorDetail)
public boolean isFatalError()
public void setFatalError(boolean fatalError)
public boolean isStrictTypeEnforcement()
public void setStrictTypeEnforcement(boolean strictTypeEnforcement)
strictTypeEnforcement
- -public boolean isStrongTyping()
public void setStrongTyping(boolean strongTyping)
strongTyping
- -public boolean isRetainParserState()
public void setRetainParserState(boolean retainParserState)
public Parser getRootParser()
public void setRootParser(Parser rootParser)
public java.lang.String getSourceFile()
public void setSourceFile(java.lang.String sourceFile)
public java.util.Map<java.lang.String,Interceptor> getInterceptors()
public void setInterceptors(java.util.Map<java.lang.String,Interceptor> interceptors)
public java.util.Map<java.lang.String,java.lang.Object> getImports()
public void setImports(java.util.Map<java.lang.String,java.lang.Object> imports)
private void initVariableVisibility()
public void pushVariableScope()
public void popVariableScope()
public void makeVisible(java.lang.String var)
public java.util.Set<java.lang.String> getVariableScope()
public boolean isVariableVisible(java.lang.String var)
public java.util.HashMap<java.lang.String,java.lang.Class> getVariables()
public void setVariables(java.util.HashMap<java.lang.String,java.lang.Class> variables)
public boolean isCompiled()
public void setCompiled(boolean compiled)
public boolean isDebugSymbols()
public void setDebugSymbols(boolean debugSymbols)
public boolean isLineMapped(java.lang.String sourceName)
public void initLineMapping(java.lang.String sourceName, char[] expr)
public int getLineFor(java.lang.String sourceName, int cursor)
public boolean isVisitedLine(java.lang.String sourceName, int lineNumber)
public void visitLine(java.lang.String sourceName, int lineNumber)
public LineLabel getLastLineLabel()
public boolean hasImports()
public void declareFunction(Function function)
public Function getFunction(java.lang.String name)
public java.util.Map getFunctions()
public boolean hasFunction(java.lang.String name)
public boolean hasFunction()
public void addTypeParameters(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Type>> typeParameters)
public java.util.Map<java.lang.String,java.lang.reflect.Type> getTypeParameters(java.lang.String name)
public java.lang.reflect.Type[] getTypeParametersAsArray(java.lang.String name)
public boolean isBlockSymbols()
public void setBlockSymbols(boolean blockSymbols)
public boolean isVariablesEscape()
public boolean isExecutableCodeReached()
public void setExecutableCodeReached(boolean executableCodeReached)
public void optimizationNotify()
public boolean isOptimizerNotified()
private void initIndexedVariables()
public java.util.ArrayList<java.lang.String> getIndexedInputs()
public void addIndexedInput(java.lang.String[] variables)
public void addIndexedLocals(java.lang.String[] variables)
public void addIndexedLocals(java.util.Collection<java.lang.String> variables)
public void addIndexedInput(java.lang.String variable)
public void addIndexedInputs(java.util.Collection<java.lang.String> variables)
public int variableIndexOf(java.lang.String name)
public java.lang.Object getEvaluationContext()
public boolean hasIndexedInputs()
public boolean isIndexAllocation()
public void setIndexAllocation(boolean indexAllocation)
public boolean isFunctionContext()
public ParserConfiguration getParserConfiguration()
public java.lang.ClassLoader getClassLoader()
public java.lang.reflect.Type[] getLastTypeParameters()
public void setLastTypeParameters(java.lang.reflect.Type[] lastTypeParameters)
public boolean isAllowBootstrapBypass()
public void setAllowBootstrapBypass(boolean allowBootstrapBypass)
public java.lang.String[] getIndexedVarNames()
public java.util.Map<java.lang.String,CompiledExpression> getCompiledExpressionCache()
public java.util.Map<java.lang.String,java.lang.Class> getReturnTypeCache()
public static ParserContext create()
public ParserContext stronglyTyped()
public ParserContext withInput(java.lang.String name, java.lang.Class type)
public ParserContext withInputs(java.util.Map<java.lang.String,java.lang.Class> inputs)
public ParserContext withTypeParameters(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.reflect.Type>> typeParameters)
public ParserContext withImport(java.lang.Class clazz)
public ParserContext withIndexedVars(java.lang.String[] varNames)