Search in sources :

Example 1 with JavaParser

use of org.drools.compiler.rule.builder.dialect.java.parser.JavaParser in project drools by kiegroup.

the class JavaExprAnalyzer method analyzeExpression.

// ------------------------------------------------------------
// Instance methods
// ------------------------------------------------------------
/**
 * Analyze an expression.
 *
 * @param expr
 *            The expression to analyze.
 * @param availableIdentifiers
 *            Total set of declarations available.
 *
 * @return The <code>Set</code> of declarations used by the expression.
 * @throws RecognitionException
 *             If an error occurs in the parser.
 */
@SuppressWarnings("unchecked")
public JavaAnalysisResult analyzeExpression(final String expr, final BoundIdentifiers availableIdentifiers) throws RecognitionException {
    final JavaParser parser = parse(expr);
    parser.conditionalOrExpression();
    JavaAnalysisResult result = new JavaAnalysisResult();
    result.setAnalyzedExpr(expr);
    result.setIdentifiers(new HashSet<String>(parser.getIdentifiers()));
    return analyze(result, availableIdentifiers);
}
Also used : JavaParser(org.drools.compiler.rule.builder.dialect.java.parser.JavaParser)

Example 2 with JavaParser

use of org.drools.compiler.rule.builder.dialect.java.parser.JavaParser in project drools by kiegroup.

the class JavaExprAnalyzer method analyzeBlock.

@SuppressWarnings("unchecked")
public JavaAnalysisResult analyzeBlock(final String expr, final BoundIdentifiers availableIdentifiers) throws RecognitionException {
    final JavaParser parser = parse("{" + expr + "}");
    parser.block();
    JavaAnalysisResult result = new JavaAnalysisResult();
    result.setAnalyzedExpr(expr);
    result.setIdentifiers(new HashSet<String>(parser.getIdentifiers()));
    result.setLocalVariables(new HashMap<String, JavaLocalDeclarationDescr>());
    if (parser.getRootBlockDescr().getInScopeLocalVars() != null) {
        for (JavaLocalDeclarationDescr descr : parser.getRootBlockDescr().getInScopeLocalVars()) {
            for (JavaLocalDeclarationDescr.IdentifierDescr ident : descr.getIdentifiers()) {
                result.addLocalVariable(ident.getIdentifier(), descr);
            }
        }
    }
    result.setBlockDescrs(parser.getRootBlockDescr());
    return analyze(result, availableIdentifiers);
}
Also used : JavaParser(org.drools.compiler.rule.builder.dialect.java.parser.JavaParser) JavaLocalDeclarationDescr(org.drools.compiler.rule.builder.dialect.java.parser.JavaLocalDeclarationDescr)

Example 3 with JavaParser

use of org.drools.compiler.rule.builder.dialect.java.parser.JavaParser in project drools by kiegroup.

the class JavaExprAnalyzer method parse.

private JavaParser parse(final String expr) {
    final CharStream charStream = new ANTLRStringStream(expr);
    final JavaLexer lexer = new JavaLexer(charStream);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    return new JavaParser(tokenStream);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) JavaParser(org.drools.compiler.rule.builder.dialect.java.parser.JavaParser) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) JavaLexer(org.drools.compiler.rule.builder.dialect.java.parser.JavaLexer) CharStream(org.antlr.runtime.CharStream)

Aggregations

JavaParser (org.drools.compiler.rule.builder.dialect.java.parser.JavaParser)3 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CharStream (org.antlr.runtime.CharStream)1 CommonTokenStream (org.antlr.runtime.CommonTokenStream)1 TokenStream (org.antlr.runtime.TokenStream)1 JavaLexer (org.drools.compiler.rule.builder.dialect.java.parser.JavaLexer)1 JavaLocalDeclarationDescr (org.drools.compiler.rule.builder.dialect.java.parser.JavaLocalDeclarationDescr)1