use of org.drools.javaparser.ast.expr.StringLiteralExpr in project drools by kiegroup.
the class ConstraintParser method getEqualityExpression.
private static Expression getEqualityExpression(TypedExpression left, TypedExpression right, BinaryExpr.Operator operator) {
if (isAnyOperandBigDecimal(left, right)) {
return compareBigDecimal(operator, left, right);
}
if (isPrimitiveExpression(right.getExpression())) {
if (left.getType() != String.class) {
return new BinaryExpr(left.getExpression(), right.getExpression(), operator == BinaryExpr.Operator.EQUALS ? BinaryExpr.Operator.EQUALS : BinaryExpr.Operator.NOT_EQUALS);
} else if (right.getExpression() instanceof LiteralExpr) {
right.setExpression(new StringLiteralExpr(right.getExpression().toString()));
}
}
if (left.getType() == String.class && right.getType() == Object.class) {
right.setExpression(new MethodCallExpr(right.getExpression(), "toString"));
}
MethodCallExpr methodCallExpr = new MethodCallExpr(null, "org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals");
methodCallExpr.addArgument(left.getExpression());
// don't create NodeList with static method because missing "parent for child" would null and NPE
methodCallExpr.addArgument(right.getExpression());
return operator == BinaryExpr.Operator.EQUALS ? methodCallExpr : new UnaryExpr(methodCallExpr, UnaryExpr.Operator.LOGICAL_COMPLEMENT);
}
use of org.drools.javaparser.ast.expr.StringLiteralExpr in project drools by kiegroup.
the class FlowExpressionBuilder method buildExpressionWithIndexing.
public Expression buildExpressionWithIndexing(DrlxParseSuccess drlxParseResult) {
String exprId = drlxParseResult.getExprId();
MethodCallExpr exprDSL = new MethodCallExpr(null, EXPR_CALL);
if (exprId != null && !"".equals(exprId)) {
exprDSL.addArgument(new StringLiteralExpr(exprId));
}
exprDSL = buildExpression(drlxParseResult, exprDSL);
exprDSL = buildIndexedBy(drlxParseResult, exprDSL);
exprDSL = buildReactOn(drlxParseResult, exprDSL);
return exprDSL;
}
use of org.drools.javaparser.ast.expr.StringLiteralExpr in project drools by kiegroup.
the class PatternExpressionBuilder method buildExpressionWithIndexing.
@Override
public Expression buildExpressionWithIndexing(DrlxParseSuccess drlxParseResult) {
String exprId = drlxParseResult.getExprId();
MethodCallExpr exprDSL = new MethodCallExpr(null, EXPR_CALL);
if (exprId != null && !"".equals(exprId)) {
exprDSL.addArgument(new StringLiteralExpr(exprId));
}
exprDSL = buildExpression(drlxParseResult, exprDSL);
MethodCallExpr finalExprDSL = exprDSL;
Optional<MethodCallExpr> indexedByExpr = buildIndexedBy(drlxParseResult);
indexedByExpr.ifPresent(finalExprDSL::addArgument);
final Optional<MethodCallExpr> reactOnDSL = buildReactOn(drlxParseResult);
reactOnDSL.ifPresent(finalExprDSL::addArgument);
return exprDSL;
}
use of org.drools.javaparser.ast.expr.StringLiteralExpr in project drools by kiegroup.
the class PackageModel method addGlobalField.
private static void addGlobalField(ClassOrInterfaceDeclaration classDeclaration, String packageName, String globalName, Class<?> globalClass) {
ClassOrInterfaceType varType = JavaParser.parseClassOrInterfaceType(Global.class.getCanonicalName());
varType.setTypeArguments(DrlxParseUtil.classToReferenceType(globalClass));
Type declType = DrlxParseUtil.classToReferenceType(globalClass);
MethodCallExpr declarationOfCall = new MethodCallExpr(null, "globalOf");
declarationOfCall.addArgument(new ClassExpr(declType));
declarationOfCall.addArgument(new StringLiteralExpr(packageName));
declarationOfCall.addArgument(new StringLiteralExpr(globalName));
FieldDeclaration field = classDeclaration.addField(varType, toVar(globalName), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
field.getVariables().get(0).setInitializer(declarationOfCall);
}
use of org.drools.javaparser.ast.expr.StringLiteralExpr in project drools by kiegroup.
the class Consequence method executeScriptCall.
private MethodCallExpr executeScriptCall(RuleDescr ruleDescr, MethodCallExpr onCall) {
MethodCallExpr executeCall = new MethodCallExpr(onCall, EXECUTESCRIPT_CALL);
executeCall.addArgument(new StringLiteralExpr("mvel"));
ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr();
objectCreationExpr.setType(StringBuilder.class.getCanonicalName());
Expression mvelSB = objectCreationExpr;
for (String i : packageModel.getImports()) {
if (i.equals(packageModel.getName() + ".*")) {
// skip same-package star import.
continue;
}
MethodCallExpr appendCall = new MethodCallExpr(mvelSB, "append");
StringLiteralExpr importAsStringLiteral = new StringLiteralExpr();
// use the setter method in order for the string literal be properly escaped.
importAsStringLiteral.setString("import " + i + ";\n");
appendCall.addArgument(importAsStringLiteral);
mvelSB = appendCall;
}
StringLiteralExpr mvelScriptBodyStringLiteral = new StringLiteralExpr();
// use the setter method in order for the string literal be properly escaped.
mvelScriptBodyStringLiteral.setString(ruleDescr.getConsequence().toString());
MethodCallExpr appendCall = new MethodCallExpr(mvelSB, "append");
appendCall.addArgument(mvelScriptBodyStringLiteral);
executeCall.addArgument(new MethodCallExpr(appendCall, "toString"));
return executeCall;
}
Aggregations