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);
Constructor and Description |
---|
ParserContext() |
ParserContext(boolean debugSymbols) |
ParserContext(Map<String,Object> imports,
Map<String,Interceptor> interceptors,
String sourceFile) |
ParserContext(Object rootParser) |
ParserContext(ParserConfiguration parserConfiguration) |
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 |
addIndexedVariable(String variable) |
void |
addIndexedVariables(Collection<String> variables) |
void |
addIndexedVariables(String[] variables) |
void |
addInput(String name,
Class type) |
void |
addInput(String name,
Class type,
Class[] typeParameters) |
void |
addInputs(Map<String,Class> inputs) |
void |
addKnownLine(int lineNumber) |
void |
addKnownLine(String sourceName,
int lineNumber) |
void |
addPackageImport(String packageName)
Adds a package import to a parse session.
|
void |
addTypeParameters(Map<String,Map<String,Class>> 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 |
createSubcontext() |
void |
declareFunction(Function function) |
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> |
getIndexedVariables() |
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 |
getLineOffset()
Get the current line offset.
|
ParserConfiguration |
getParserConfiguration() |
Proto |
getProtoImport(String name) |
Object |
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,Class> |
getTypeParameters(String name) |
Type[] |
getTypeParametersAsArray(String name) |
HashMap<String,Class> |
getVariables() |
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 |
hasIndexedVariables() |
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.
|
boolean |
isAllowBootstrapBypass() |
boolean |
isBlockSymbols() |
boolean |
isCompiled() |
boolean |
isDebugSymbols() |
boolean |
isExecutableCodeReached() |
boolean |
isFatalError() |
boolean |
isIndexAllocation() |
boolean |
isKnownLine(String sourceName,
int lineNumber) |
boolean |
isRetainParserState() |
boolean |
isStrictTypeEnforcement() |
boolean |
isStrongTyping() |
void |
processTables() |
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(short lineOffset)
Sets the current line offset.
|
void |
setRetainParserState(boolean retainParserState) |
void |
setRootParser(Object 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) |
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,Class>> typeParameters) |
public ParserContext()
public ParserContext(boolean debugSymbols)
public ParserContext(Object rootParser)
public ParserContext(ParserConfiguration parserConfiguration)
public ParserContext createSubcontext()
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(short 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 Object getRootParser()
public void setRootParser(Object rootParser)
public String getSourceFile()
public void setSourceFile(String sourceFile)
public Map<String,Interceptor> getInterceptors()
public void setInterceptors(Map<String,Interceptor> interceptors)
public boolean isCompiled()
public void setCompiled(boolean compiled)
public boolean isDebugSymbols()
public void setDebugSymbols(boolean debugSymbols)
public boolean isKnownLine(String sourceName, int lineNumber)
public void addKnownLine(String sourceName, int lineNumber)
public void addKnownLine(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 isExecutableCodeReached()
public void setExecutableCodeReached(boolean executableCodeReached)
public void addIndexedVariables(String[] variables)
public void addIndexedVariable(String variable)
public void addIndexedVariables(Collection<String> variables)
public int variableIndexOf(String name)
public boolean hasIndexedVariables()
public boolean isIndexAllocation()
public void setIndexAllocation(boolean indexAllocation)
public ParserConfiguration getParserConfiguration()
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,Class>> typeParameters)
public ParserContext withImport(Class clazz)
public ParserContext withIndexedVars(String[] varNames)
Copyright © 2013. All rights reserved.