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.
Author:
JĂșlio Vilmar Gesser
  • Constructor Summary

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    com.github.javaparser.ParserConfiguration
    Get the non-static configuration for this parser.
    static com.github.javaparser.ParserConfiguration
    Get the configuration for the static parse...
    static com.github.javaparser.ast.expr.Expression
    Parses the Java code contained in the InputStream and returns a Expression that represents it.
    Note: Uses UTF-8 encoding
    static com.github.javaparser.ast.expr.Expression
    parse(InputStream in, Charset encoding)
    Parses the Java code contained in the InputStream and returns a Expression that represents it.
    static com.github.javaparser.ast.expr.Expression
    parse(Reader reader)
    Parses Java code from a Reader and returns a Expression that represents it.
    static com.github.javaparser.ast.expr.Expression
    parse(String code)
    Parses the Java code contained in code and returns a Expression that 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.BlockStmt
    parseBlock(String blockStatement)
    Parses the Java block contained in a String and returns a BlockStmt that represents it.
    static com.github.javaparser.ast.type.ClassOrInterfaceType
    Parses a Java class or interface type name and returns a ClassOrInterfaceType that represents it.
    static com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt
    Parses the this(...) and super(...) statements that may occur at the start of a constructor.
    static <T extends com.github.javaparser.ast.expr.Expression>
    T
    parseExpression(String expression)
    Parses the Java expression contained in a String and returns a Expression that represents it.
    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.
    static com.github.javaparser.ast.expr.Expression
    parseResource(ClassLoader classLoader, String path, Charset encoding)
    Parses the Java code contained in a resource and returns a Expression that represents it.
    static com.github.javaparser.ast.expr.Expression
    Parses the Java code contained in a resource and returns a Expression that represents it.
    Note: Uses UTF-8 encoding
    static com.github.javaparser.ast.expr.Expression
    parseResource(String path, Charset encoding)
    Parses the Java code contained in a resource and returns a Expression that represents it.
    static com.github.javaparser.ast.expr.SimpleName
    Parses a simple name (one that can NOT have "."s in it) and returns it as a SimpleName.
    static com.github.javaparser.ast.type.Type
    Parses a Java type name and returns a Type that represents it.
    static void
    setStaticConfiguration(com.github.javaparser.ParserConfiguration staticConfiguration)
    Set the configuration for the static parse...

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static com.github.javaparser.ast.expr.Expression parse(InputStream in, Charset encoding)
      Parses the Java code contained in the InputStream and returns a Expression that represents it.
      Parameters:
      in - InputStream containing 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 the InputStream and returns a Expression that represents it.
      Note: Uses UTF-8 encoding
      Parameters:
      in - InputStream 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
    • parseResource

      public static com.github.javaparser.ast.expr.Expression parseResource(String path) throws IOException
      Parses the Java code contained in a resource and returns a Expression that 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 errors
      IOException - 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 a Expression that 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 pathToResource
      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
      IOException - 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 a Expression that represents it.
      Parameters:
      classLoader - the classLoader that is asked to load the resource
      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 errors
      IOException - 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 a Expression that 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 a Expression that 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 a String and returns a BlockStmt that represents it.
      Parameters:
      blockStatement - String containing 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 a String and returns a Expression that represents it.
      Parameters:
      expression - String containing 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 a ClassOrInterfaceType that 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 a Type that 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