Package org.drools.mvel.parser
Class MvelParser
- java.lang.Object
-
- org.drools.mvel.parser.MvelParser
-
public final class MvelParser extends Object
Parse Java source code and creates Abstract Syntax Trees.
-
-
Constructor Summary
Constructors Constructor Description MvelParser()Instantiate the parser with default configuration.MvelParser(com.github.javaparser.ParserConfiguration configuration)Instantiate the parser.MvelParser(com.github.javaparser.ParserConfiguration configuration, boolean optionalSemicolon)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.github.javaparser.ParserConfigurationgetParserConfiguration()Get the non-static configuration for this parser.static com.github.javaparser.ParserConfigurationgetStaticConfiguration()Get the configuration for the static parse... methods.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.Expressionparse(Reader reader)Parses Java code from a Reader and returns aExpressionthat represents it.static com.github.javaparser.ast.expr.Expressionparse(String code)Parses 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.ClassOrInterfaceTypeparseClassOrInterfaceType(String type)Parses 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.NameparseName(String qualifiedName)Parses a qualified name (one that can have "."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 "."static com.github.javaparser.ast.type.TypeparseType(String type)Parses a Java type name and returns aTypethat represents it.static voidsetStaticConfiguration(com.github.javaparser.ParserConfiguration staticConfiguration)Set the configuration for the static parse... methods.
-
-
-
Constructor Detail
-
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 Detail
-
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
public static com.github.javaparser.ast.expr.Expression parse(InputStream in, Charset encoding)
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
public static com.github.javaparser.ast.expr.Expression parse(InputStream in)
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
public static com.github.javaparser.ast.expr.Expression parse(Reader reader)
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
public static com.github.javaparser.ast.expr.Expression parse(String code)
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
public static com.github.javaparser.ast.stmt.BlockStmt parseBlock(String blockStatement)
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
public static com.github.javaparser.ast.type.Type parseType(String type)
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
public static com.github.javaparser.ast.expr.Name parseName(String qualifiedName)
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
public static com.github.javaparser.ast.expr.SimpleName parseSimpleName(String name)
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
-
-