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);
}
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);
}
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);
}
Aggregations