use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class AbstractExpressionBuilder method generateLambdaForTemporalConstraint.
protected Expression generateLambdaForTemporalConstraint(TypedExpression typedExpression, Class<?> patternType) {
Expression expr = typedExpression.getExpression();
Collection<String> usedDeclarations = DrlxParseUtil.collectUsedDeclarationsInExpression(expr);
boolean containsThis = usedDeclarations.contains(THIS_PLACEHOLDER);
if (containsThis) {
usedDeclarations.remove(THIS_PLACEHOLDER);
}
Expression generatedExpr = generateLambdaWithoutParameters(usedDeclarations, expr, !containsThis, Optional.ofNullable(patternType), context);
if (generatedExpr instanceof LambdaExpr) {
context.getPackageModel().registerLambdaReturnType((LambdaExpr) generatedExpr, typedExpression.getType());
}
return generatedExpr;
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternExpressionBuilder method buildExpressionWithIndexing.
@Override
public MethodCallExpr buildExpressionWithIndexing(DrlxParseSuccess drlxParseResult) {
if (drlxParseResult instanceof MultipleDrlxParseSuccess) {
MultipleDrlxParseSuccess multi = (MultipleDrlxParseSuccess) drlxParseResult;
MethodCallExpr exprDSL = new MethodCallExpr(null, multi.getOperator() == BinaryExpr.Operator.OR ? EXPR_OR_CALL : EXPR_AND_CALL);
for (DrlxParseSuccess child : multi.getResults()) {
MethodCallExpr childExpr = buildExpressionWithIndexing(child);
childExpr.setScope(exprDSL);
exprDSL = childExpr;
if (child instanceof SingleDrlxParseSuccess && child.getExprBinding() != null) {
SingleDrlxParseSuccess singleDrlxChild = (SingleDrlxParseSuccess) child;
context.addDeclaration(child.getExprBinding(), singleDrlxChild.getLeftExprRawClass());
Expression dslExpr = buildBinding(singleDrlxChild);
context.addExpression(dslExpr);
}
}
return new MethodCallExpr(exprDSL, multi.getOperator() == BinaryExpr.Operator.OR ? EXPR_END_OR_CALL : EXPR_END_AND_CALL);
}
return buildSingleExpressionWithIndexing((SingleDrlxParseSuccess) drlxParseResult);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternExpressionBuilder method buildBinding.
@Override
public MethodCallExpr buildBinding(SingleDrlxParseSuccess drlxParseResult) {
sortUsedDeclarations(drlxParseResult);
MethodCallExpr bindDSL = new MethodCallExpr(null, BIND_CALL);
String boundVar = drlxParseResult.hasUnificationVariable() ? drlxParseResult.getUnificationVariable() : drlxParseResult.getExprBinding();
bindDSL.addArgument(context.getVarExpr(boundVar));
final Expression constraintExpression = getBindingExpression(drlxParseResult);
drlxParseResult.getUsedDeclarationsOnLeft().forEach(d -> bindDSL.addArgument(context.getVar(d)));
bindDSL.addArgument(constraintExpression);
final Optional<MethodCallExpr> methodCallExpr = buildReactOn(drlxParseResult);
methodCallExpr.ifPresent(bindDSL::addArgument);
context.registerBindingExpression(boundVar, bindDSL);
return bindDSL;
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternExpressionBuilder method processExpression.
@Override
public void processExpression(SingleDrlxParseSuccess drlxParseResult) {
if (drlxParseResult.hasUnificationVariable()) {
Expression dslExpr = buildUnificationExpression(drlxParseResult);
context.addExpression(dslExpr);
} else if (drlxParseResult.isPredicate()) {
Expression dslExpr = buildExpressionWithIndexing(drlxParseResult);
context.addExpression(dslExpr);
}
if (drlxParseResult.getExprBinding() != null) {
Expression dslExpr = buildBinding(drlxParseResult);
context.addExpression(dslExpr);
}
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FlattenScope method transformFullyQualifiedInlineCastExpr.
public static Expression transformFullyQualifiedInlineCastExpr(TypeResolver typeResolver, FullyQualifiedInlineCastExpr fqInlineCastExpr) {
final Deque<String> expressionNamesWithoutType = new ArrayDeque<>();
String className = findClassName(fqInlineCastExpr.getName(), typeResolver, expressionNamesWithoutType);
Expression scope = fqInlineCastExpr.getScope();
if (scope instanceof FullyQualifiedInlineCastExpr) {
scope = transformFullyQualifiedInlineCastExpr(typeResolver, (FullyQualifiedInlineCastExpr) scope);
}
Expression expr = new InlineCastExpr(toClassOrInterfaceType(className), scope);
// last element is the one with the actual arguments and need a special case
if (!expressionNamesWithoutType.isEmpty()) {
String lastElement = expressionNamesWithoutType.removeLast();
// the others will be considered FieldAccessExpr
for (String s : expressionNamesWithoutType) {
expr = new FieldAccessExpr(expr, s);
}
if (fqInlineCastExpr.hasArguments()) {
expr = new MethodCallExpr(expr, lastElement, fqInlineCastExpr.getArguments());
} else {
expr = new FieldAccessExpr(expr, lastElement);
}
}
return expr;
}
Aggregations