Search in sources :

Example 1 with PROBLEM_BY_BEGIN_POSITION

use of com.github.javaparser.Problem.PROBLEM_BY_BEGIN_POSITION in project drools by kiegroup.

the class MvelParser method parse.

/**
 * 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...)
 *
 * @param start refer to the constants in ParseStart to see what can be parsed.
 * @param provider refer to Providers to see how you can read source. The provider will be closed after parsing.
 * @param <N> the subclass of Node that is the result of parsing in the start.
 * @return the parse result, a collection of encountered problems, and some extra data.
 */
public <N extends Node> ParseResult<N> parse(ParseStart<N> start, Provider provider) {
    assertNotNull(start);
    assertNotNull(provider);
    final GeneratedMvelParser parser = getParserForProvider(provider);
    try {
        N resultNode = start.parse(parser);
        ParseResult<N> result = new ParseResult<>(resultNode, parser.problems, parser.getCommentsCollection());
        configuration.getPostProcessors().forEach(postProcessor -> postProcessor.process(result, configuration));
        result.getProblems().sort(PROBLEM_BY_BEGIN_POSITION);
        return result;
    } catch (Exception e) {
        final String message = e.getMessage() == null ? "Unknown error" : e.getMessage();
        parser.problems.add(new Problem(message, null, e));
        return new ParseResult<>(null, parser.problems, parser.getCommentsCollection());
    } finally {
        try {
            provider.close();
        } catch (IOException e) {
        // Since we're done parsing and have our result, we don't care about any errors.
        }
    }
}
Also used : ParseResult(com.github.javaparser.ParseResult) Problem(com.github.javaparser.Problem) IOException(java.io.IOException) EXPRESSION(org.drools.mvel.parser.ParseStart.EXPRESSION) PROBLEM_BY_BEGIN_POSITION(com.github.javaparser.Problem.PROBLEM_BY_BEGIN_POSITION) IOException(java.io.IOException) ParseProblemException(com.github.javaparser.ParseProblemException)

Aggregations

ParseProblemException (com.github.javaparser.ParseProblemException)1 ParseResult (com.github.javaparser.ParseResult)1 Problem (com.github.javaparser.Problem)1 PROBLEM_BY_BEGIN_POSITION (com.github.javaparser.Problem.PROBLEM_BY_BEGIN_POSITION)1 IOException (java.io.IOException)1 EXPRESSION (org.drools.mvel.parser.ParseStart.EXPRESSION)1