|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mvel2.ParserContext
public class ParserContext
The ParserContext is the main enviroment object used for sharing state throughout the entire
parser/compile 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);
Constructor Summary | |
---|---|
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(java.lang.Object rootParser)
|
|
ParserContext(ParserConfiguration parserConfiguration)
|
Method Summary | |
---|---|
void |
addError(ErrorDetail errorDetail)
|
void |
addImport(java.lang.Class cls)
Adds an import for the specified Class. |
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 |
addIndexedVariable(java.lang.String variable)
|
void |
addIndexedVariables(java.util.Collection<java.lang.String> variables)
|
void |
addIndexedVariables(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 |
addKnownLine(int lineNumber)
|
void |
addKnownLine(java.lang.String sourceName,
int lineNumber)
|
void |
addPackageImport(java.lang.String packageName)
Adds a package import to a parse session. |
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)
|
void |
declareFunction(Function function)
|
java.util.List<ErrorDetail> |
getErrorList()
|
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> |
getIndexedVariables()
|
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 |
getLineOffset()
Get the current line offset. |
ParserConfiguration |
getParserConfiguration()
|
java.lang.Object |
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.Class> |
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.lang.Class |
getVarOrInputType(java.lang.String name)
Return the variable or input type froom the current parser context. |
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 |
hasIndexedVariables()
|
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. |
boolean |
isAllowBootstrapBypass()
|
boolean |
isBlockSymbols()
|
boolean |
isCompiled()
|
boolean |
isDebugSymbols()
|
boolean |
isExecutableCodeReached()
|
boolean |
isFatalError()
|
boolean |
isIndexAllocation()
|
boolean |
isKnownLine(java.lang.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(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(short lineOffset)
Sets the current line offset. |
void |
setRetainParserState(boolean retainParserState)
|
void |
setRootParser(java.lang.Object 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)
|
int |
variableIndexOf(java.lang.String name)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ParserContext()
public ParserContext(boolean debugSymbols)
public ParserContext(java.lang.Object rootParser)
public ParserContext(ParserConfiguration parserConfiguration)
public ParserContext(java.util.Map<java.lang.String,java.lang.Object> imports, java.util.Map<java.lang.String,Interceptor> interceptors, java.lang.String sourceFile)
Method Detail |
---|
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 identifier
public int getLineCount()
public int setLineCount(int lineCount)
lineCount
- The number of lines
public int incrementLineCount(int increment)
increment
- The number of lines to increment
public int getLineOffset()
public void setLineOffset(short 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 identifier
MethodStub
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 identifier
public void addImport(java.lang.Class cls)
cls
- The instance of the Class which represents the imported class.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 java.lang.Object getRootParser()
public void setRootParser(java.lang.Object 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)
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 isKnownLine(java.lang.String sourceName, int lineNumber)
public void addKnownLine(java.lang.String sourceName, int lineNumber)
public void addKnownLine(int lineNumber)
public LineLabel getLastLineLabel()
public LineLabel setLastLineLabel(LineLabel lastLineLabel)
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 java.util.Map<java.lang.String,java.lang.Class> 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 isExecutableCodeReached()
public void setExecutableCodeReached(boolean executableCodeReached)
public java.util.ArrayList<java.lang.String> getIndexedVariables()
public void addIndexedVariables(java.lang.String[] variables)
public void addIndexedVariable(java.lang.String variable)
public void addIndexedVariables(java.util.Collection<java.lang.String> variables)
public int variableIndexOf(java.lang.String name)
public boolean hasIndexedVariables()
public boolean isIndexAllocation()
public void setIndexAllocation(boolean indexAllocation)
public ParserConfiguration getParserConfiguration()
public java.lang.reflect.Type[] getLastTypeParameters()
public void setLastTypeParameters(java.lang.reflect.Type[] lastTypeParameters)
public boolean isAllowBootstrapBypass()
public void setAllowBootstrapBypass(boolean allowBootstrapBypass)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |