Package org.drools.mvel.parser
Class MvelParser
java.lang.Object
org.drools.mvel.parser.MvelParser
Parse Java source code and creates Abstract Syntax Trees.
- Author:
- JĂșlio Vilmar Gesser
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiate the parser with default configuration.MvelParser(com.github.javaparser.ParserConfiguration configuration) Instantiate the parser.MvelParser(com.github.javaparser.ParserConfiguration configuration, boolean optionalSemicolon) -
Method Summary
Modifier and TypeMethodDescriptioncom.github.javaparser.ParserConfigurationGet the non-static configuration for this parser.static com.github.javaparser.ParserConfigurationGet the configuration for the static parse...static com.github.javaparser.ast.expr.Expressionparse(InputStream in) Parses the Java code contained in theInputStreamand returns aExpressionthat represents it.
Note: Uses UTF-8 encodingstatic com.github.javaparser.ast.expr.Expressionparse(InputStream in, Charset encoding) Parses the Java code contained in theInputStreamand returns aExpressionthat represents it.static com.github.javaparser.ast.expr.ExpressionParses Java code from a Reader and returns aExpressionthat represents it.static com.github.javaparser.ast.expr.ExpressionParses the Java code contained in code and returns aExpressionthat represents it.<N extends com.github.javaparser.ast.Node>
com.github.javaparser.ParseResult<N>parse(ParseStart<N> start, Provider provider) Parses source code.static com.github.javaparser.ast.stmt.BlockStmtparseBlock(String blockStatement) Parses the Java block contained in aStringand returns aBlockStmtthat represents it.static com.github.javaparser.ast.type.ClassOrInterfaceTypeParses a Java class or interface type name and returns aClassOrInterfaceTypethat represents it.static com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmtparseExplicitConstructorInvocationStmt(String statement) Parses the this(...) and super(...) statements that may occur at the start of a constructor.static <T extends com.github.javaparser.ast.expr.Expression>
TparseExpression(String expression) Parses the Java expression contained in aStringand returns aExpressionthat represents it.static com.github.javaparser.ast.expr.NameParses a qualified name (one that can have "."s in it) and returns it as a Name.static com.github.javaparser.ast.expr.ExpressionparseResource(ClassLoader classLoader, String path, Charset encoding) Parses the Java code contained in a resource and returns aExpressionthat represents it.static com.github.javaparser.ast.expr.ExpressionparseResource(String path) Parses the Java code contained in a resource and returns aExpressionthat represents it.
Note: Uses UTF-8 encodingstatic com.github.javaparser.ast.expr.ExpressionparseResource(String path, Charset encoding) Parses the Java code contained in a resource and returns aExpressionthat represents it.static com.github.javaparser.ast.expr.SimpleNameparseSimpleName(String name) Parses a simple name (one that can NOT have "."s in it) and returns it as a SimpleName.static com.github.javaparser.ast.type.TypeParses a Java type name and returns aTypethat represents it.static voidsetStaticConfiguration(com.github.javaparser.ParserConfiguration staticConfiguration) Set the configuration for the static parse...
-
Constructor Details
-
MvelParser
public MvelParser()Instantiate the parser with default configuration. Note that parsing can also be done with the static methods on this class. Creating an instance will reduce setup time between parsing files. -
MvelParser
public MvelParser(com.github.javaparser.ParserConfiguration configuration) Instantiate the parser. Note that parsing can also be done with the static methods on this class. Creating an instance will reduce setup time between parsing files. -
MvelParser
public MvelParser(com.github.javaparser.ParserConfiguration configuration, boolean optionalSemicolon)
-
-
Method Details
-
getStaticConfiguration
public static com.github.javaparser.ParserConfiguration getStaticConfiguration()Get the configuration for the static parse... methods. This is a STATIC field, so modifying it will directly change how all static parse... methods work! -
setStaticConfiguration
public static void setStaticConfiguration(com.github.javaparser.ParserConfiguration staticConfiguration) Set the configuration for the static parse... methods. This is a STATIC field, so modifying it will directly change how all static parse... methods work! -
getParserConfiguration
public com.github.javaparser.ParserConfiguration getParserConfiguration()Get the non-static configuration for this parser.- Returns:
- The non-static configuration for this parser.
-
parse
public <N extends com.github.javaparser.ast.Node> com.github.javaparser.ParseResult<N> parse(ParseStart<N> start, Provider provider) Parses source code. It takes the source code from a Provider. The start indicates what can be found in the source code (compilation unit, block, import...)- Type Parameters:
N- the subclass of Node that is the result of parsing in the start.- Parameters:
start- refer to the constants in ParseStart to see what can be parsed.provider- refer to Providers to see how you can read source. The provider will be closed after parsing.- Returns:
- the parse result, a collection of encountered problems, and some extra data.
-
parse
Parses the Java code contained in theInputStreamand returns aExpressionthat represents it.- Parameters:
in-InputStreamcontaining Java source code. It will be closed after parsing.encoding- encoding of the source code- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parse
Parses the Java code contained in theInputStreamand returns aExpressionthat represents it.
Note: Uses UTF-8 encoding- Parameters:
in-InputStreamcontaining Java source code. It will be closed after parsing.- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseResource
public static com.github.javaparser.ast.expr.Expression parseResource(String path) throws IOException Parses the Java code contained in a resource and returns aExpressionthat represents it.
Note: Uses UTF-8 encoding- Parameters:
path- path to a resource containing Java source code. As resource is accessed through a class loader, a leading "/" is not allowed in pathToResource- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errorsIOException- the path could not be accessed
-
parseResource
public static com.github.javaparser.ast.expr.Expression parseResource(String path, Charset encoding) throws IOException Parses the Java code contained in a resource and returns aExpressionthat represents it.- Parameters:
path- path to a resource containing Java source code. As resource is accessed through a class loader, a leading "/" is not allowed in pathToResourceencoding- encoding of the source code- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errorsIOException- the path could not be accessed
-
parseResource
public static com.github.javaparser.ast.expr.Expression parseResource(ClassLoader classLoader, String path, Charset encoding) throws IOException Parses the Java code contained in a resource and returns aExpressionthat represents it.- Parameters:
classLoader- the classLoader that is asked to load the resourcepath- path to a resource containing Java source code. As resource is accessed through a class loader, a leading "/" is not allowed in pathToResource- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errorsIOException- the path could not be accessed
-
parse
Parses Java code from a Reader and returns aExpressionthat represents it.- Parameters:
reader- the reader containing Java source code. It will be closed after parsing.- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parse
Parses the Java code contained in code and returns aExpressionthat represents it.- Parameters:
code- Java source code- Returns:
- Expression representing the Java source code
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseBlock
Parses the Java block contained in aStringand returns aBlockStmtthat represents it.- Parameters:
blockStatement-Stringcontaining Java block code- Returns:
- BlockStmt representing the Java block
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseExpression
public static <T extends com.github.javaparser.ast.expr.Expression> T parseExpression(String expression) Parses the Java expression contained in aStringand returns aExpressionthat represents it.- Parameters:
expression-Stringcontaining Java expression- Returns:
- Expression representing the Java expression
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseClassOrInterfaceType
public static com.github.javaparser.ast.type.ClassOrInterfaceType parseClassOrInterfaceType(String type) Parses a Java class or interface type name and returns aClassOrInterfaceTypethat represents it.- Parameters:
type- the type name like a.b.c.X or Y- Returns:
- ClassOrInterfaceType representing the type
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseType
Parses a Java type name and returns aTypethat represents it.- Parameters:
type- the type name like a.b.c.X, Y, or int- Returns:
- ClassOrInterfaceType representing the type
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseExplicitConstructorInvocationStmt
public static com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(String statement) Parses the this(...) and super(...) statements that may occur at the start of a constructor.- Parameters:
statement- a statement like super("hello");- Returns:
- the AST for the statement.
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseName
Parses a qualified name (one that can have "."s in it) and returns it as a Name.- Parameters:
qualifiedName- a name like "com.laamella.parameter_source"- Returns:
- the AST for the name
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-
parseSimpleName
Parses a simple name (one that can NOT have "."s in it) and returns it as a SimpleName.- Parameters:
name- a name like "parameter_source"- Returns:
- the AST for the name
- Throws:
com.github.javaparser.ParseProblemException- if the source code has parser errors
-