public class ParserContext extends Object implements 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 |
---|---|
protected boolean |
variablesEscape |
Constructor and Description |
---|
ParserContext() |
ParserContext(boolean debugSymbols) |
ParserContext(Map<String,Object> imports,
Map<String,Interceptor> interceptors,
String sourceFile) |
ParserContext(Parser rootParser) |
ParserContext(ParserConfiguration parserConfiguration) |
ParserContext(ParserConfiguration parserConfiguration,
ParserContext parent,
boolean functionContext) |
Modifier and Type | Method and Description |
---|---|
void |
addError(ErrorDetail errorDetail) |
void |
addImport(Class cls)
Adds an import for the specified Class.
|
void |
addImport(Proto proto) |
void |
addImport(String name,
Class cls)
Adds an import for a specified Class using an alias.
|
void |
addImport(String name,
Method method)
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 specified
MethodStub with an alias. |
void |
addIndexedInput(String variable) |
void |
addIndexedInput(String[] variables) |
void |
addIndexedInputs(Collection<String> variables) |
void |
addIndexedLocals(Collection<String> variables) |
void |
addIndexedLocals(String[] variables) |
void |
addInput(String name,
Class type) |
void |
addInput(String name,
Class type,
Class[] typeParameters) |
void |
addInputs(Map<String,Class> inputs) |
void |
addPackageImport(String packageName)
Adds a package import to a parse session.
|
void |
addTypeParameters(Map<String,Map<String,Type>> typeParameters) |
void |
addTypeParameters(String name,
Class type) |
void |
addVariable(String name,
Class type) |
void |
addVariable(String name,
Class type,
boolean failIfNewAssignment) |
void |
addVariables(Map<String,Class> variables) |
static ParserContext |
create() |
ParserContext |
createColoringSubcontext() |
ParserContext |
createSubcontext() |
void |
declareFunction(Function function) |
ClassLoader |
getClassLoader() |
List<ErrorDetail> |
getErrorList() |
Function |
getFunction(String name) |
Map |
getFunctions() |
Class |
getImport(String name)
Get an import that has been declared, either in the parsed script or programatically
|
Map<String,Object> |
getImports() |
ArrayList<String> |
getIndexedInputs() |
String[] |
getIndexedVarNames() |
Map<String,Class> |
getInputs() |
Map<String,Interceptor> |
getInterceptors() |
LineLabel |
getLastLineLabel() |
Type[] |
getLastTypeParameters() |
int |
getLineCount()
Get total number of lines declared in the current context.
|
int |
getLineFor(String sourceName,
int cursor) |
int |
getLineOffset()
Get the current line offset.
|
ParserConfiguration |
getParserConfiguration() |
Proto |
getProtoImport(String name) |
Parser |
getRootParser() |
String |
getSourceFile() |
MethodStub |
getStaticImport(String name)
Get a
MethodStub which wraps a static method import. |
Object |
getStaticOrClassImport(String name)
Returns either an instance of Class or
MethodStub (whichever matches). |
Map<String,Type> |
getTypeParameters(String name) |
Type[] |
getTypeParametersAsArray(String name) |
HashMap<String,Class> |
getVariables() |
Set<String> |
getVariableScope() |
Class |
getVarOrInputType(String name)
Return the variable or input type froom the current parser context.
|
Class |
getVarOrInputTypeOrNull(String name) |
boolean |
hasFunction() |
boolean |
hasFunction(String name) |
boolean |
hasImport(String name)
Tests to see if the specified import exists.
|
boolean |
hasImports() |
boolean |
hasIndexedInputs() |
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 amount
|
void |
initializeTables()
Initializes internal Maps.
|
void |
initLineMapping(String sourceName,
char[] expr) |
boolean |
isAllowBootstrapBypass() |
boolean |
isBlockSymbols() |
boolean |
isCompiled() |
boolean |
isDebugSymbols() |
boolean |
isExecutableCodeReached() |
boolean |
isFatalError() |
boolean |
isFunctionContext() |
boolean |
isIndexAllocation() |
boolean |
isLineMapped(String sourceName) |
boolean |
isOptimizerNotified() |
boolean |
isRetainParserState() |
boolean |
isStrictTypeEnforcement() |
boolean |
isStrongTyping() |
boolean |
isVariablesEscape() |
boolean |
isVariableVisible(String var) |
boolean |
isVisitedLine(String sourceName,
int lineNumber) |
void |
makeVisible(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(List<ErrorDetail> errorList) |
void |
setExecutableCodeReached(boolean executableCodeReached) |
void |
setFatalError(boolean fatalError) |
void |
setImports(Map<String,Object> imports) |
void |
setIndexAllocation(boolean indexAllocation) |
void |
setInputs(Map<String,Class> inputs) |
void |
setInterceptors(Map<String,Interceptor> interceptors) |
LineLabel |
setLastLineLabel(LineLabel lastLineLabel) |
void |
setLastTypeParameters(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(String sourceFile) |
void |
setStrictTypeEnforcement(boolean strictTypeEnforcement)
Enables strict type enforcement -
|
void |
setStrongTyping(boolean strongTyping)
Enables strong type enforcement.
|
void |
setVariables(HashMap<String,Class> variables) |
ParserContext |
stronglyTyped() |
int |
variableIndexOf(String name) |
void |
visitLine(String sourceName,
int lineNumber) |
ParserContext |
withImport(Class clazz) |
ParserContext |
withIndexedVars(String[] varNames) |
ParserContext |
withInput(String name,
Class type) |
ParserContext |
withInputs(Map<String,Class> inputs) |
ParserContext |
withTypeParameter(String name,
Class type) |
ParserContext |
withTypeParameters(Map<String,Map<String,Type>> typeParameters) |
public ParserContext()
public ParserContext(boolean debugSymbols)
public ParserContext(Parser rootParser)
public ParserContext(ParserConfiguration parserConfiguration)
public ParserContext(ParserConfiguration parserConfiguration, ParserContext parent, boolean functionContext)
public ParserContext createSubcontext()
public ParserContext createColoringSubcontext()
public boolean hasVarOrInput(String name)
name
- The name of the identifier.public Class getVarOrInputType(String name)
name
- The name of the identifierpublic 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 Class getImport(String name)
name
- The name identifier for the imported class (ie. "HashMap")public MethodStub getStaticImport(String name)
MethodStub
which wraps a static method import.name
- The name identifierMethodStub
public Object getStaticOrClassImport(String name)
MethodStub
(whichever matches).name
- The name identifier.MethodStub
public void addPackageImport(String packageName)
packageName
- A fully qualified package (eg. java.util.concurrent).public boolean hasImport(String name)
name
- A name identifierpublic boolean hasProtoImport(String name)
public void addImport(Class cls)
cls
- The instance of the Class which represents the imported class.public void addImport(Proto proto)
public void addImport(String name, 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(String name, 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(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 processTables()
public List<ErrorDetail> getErrorList()
public void setErrorList(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 String getSourceFile()
public void setSourceFile(String sourceFile)
public Map<String,Interceptor> getInterceptors()
public void setInterceptors(Map<String,Interceptor> interceptors)
public void pushVariableScope()
public void popVariableScope()
public void makeVisible(String var)
public boolean isVariableVisible(String var)
public boolean isCompiled()
public void setCompiled(boolean compiled)
public boolean isDebugSymbols()
public void setDebugSymbols(boolean debugSymbols)
public boolean isLineMapped(String sourceName)
public void initLineMapping(String sourceName, char[] expr)
public int getLineFor(String sourceName, int cursor)
public boolean isVisitedLine(String sourceName, int lineNumber)
public void visitLine(String sourceName, int lineNumber)
public LineLabel getLastLineLabel()
public boolean hasImports()
public void declareFunction(Function function)
public Map getFunctions()
public boolean hasFunction(String name)
public boolean hasFunction()
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()
public void addIndexedInput(String[] variables)
public void addIndexedLocals(String[] variables)
public void addIndexedLocals(Collection<String> variables)
public void addIndexedInput(String variable)
public void addIndexedInputs(Collection<String> variables)
public int variableIndexOf(String name)
public boolean hasIndexedInputs()
public boolean isIndexAllocation()
public void setIndexAllocation(boolean indexAllocation)
public boolean isFunctionContext()
public ParserConfiguration getParserConfiguration()
public ClassLoader getClassLoader()
public Type[] getLastTypeParameters()
public void setLastTypeParameters(Type[] lastTypeParameters)
public boolean isAllowBootstrapBypass()
public void setAllowBootstrapBypass(boolean allowBootstrapBypass)
public String[] getIndexedVarNames()
public static ParserContext create()
public ParserContext stronglyTyped()
public ParserContext withInput(String name, Class type)
public ParserContext withInputs(Map<String,Class> inputs)
public ParserContext withTypeParameter(String name, Class type)
public ParserContext withTypeParameters(Map<String,Map<String,Type>> typeParameters)
public ParserContext withImport(Class clazz)
public ParserContext withIndexedVars(String[] varNames)
Copyright © 2018. All rights reserved.