use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternDSLPattern method buildPattern.
@Override
protected void buildPattern(DeclarationSpec declarationSpec, List<PatternConstraintParseResult> patternConstraintParseResults) {
MethodCallExpr patternExpression = createPatternExpression(pattern, declarationSpec);
List<Expression> exprs = new ArrayList<>();
context.pushExprPointer(exprs::add);
buildConstraints(pattern, patternType, patternConstraintParseResults);
context.popExprPointer();
List<Expression> additionalPatterns = new ArrayList<>();
for (Expression expr : exprs) {
Optional<Expression> rootScope = findRootNodeViaScope(expr);
if (rootScope.isPresent() && ((MethodCallExpr) rootScope.get()).getNameAsString().equals(PATTERN_CALL)) {
additionalPatterns.add(expr);
} else {
MethodCallExpr currentExpr = (MethodCallExpr) expr;
MethodCallExpr lastMethodInChain = findLastMethodInChain(currentExpr);
if (!NO_OP_EXPR.equals(lastMethodInChain.getNameAsString())) {
lastMethodInChain.setScope(patternExpression);
patternExpression = currentExpr;
}
}
}
if (pattern.isQuery()) {
patternExpression = new MethodCallExpr(patternExpression, PASSIVE_CALL);
}
context.addExpression(addWatchToPattern(patternExpression));
additionalPatterns.forEach(context::addExpression);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternDSLPattern method createPatternExpression.
private MethodCallExpr createPatternExpression(PatternDescr pattern, DeclarationSpec declarationSpec) {
MethodCallExpr dslExpr = createDslTopLevelMethod(PATTERN_CALL);
dslExpr.addArgument(context.getVarExpr(pattern.getIdentifier()));
if (context.isQuery()) {
Optional<Expression> declarationSource = declarationSpec.getDeclarationSource();
declarationSource.ifPresent(dslExpr::addArgument);
}
return dslExpr;
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FlowDSLQueryGenerator method queryNameClassArg.
private void queryNameClassArg(ClassOrInterfaceDeclaration clazz) {
MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
query1.addParameter(STRINGLITERAL, "name");
BlockStmt stmts = new BlockStmt();
NodeList<Type> typeArguments = nodeList();
NodeList<TypeParameter> typeParameters = nodeList();
NodeList<Expression> arguments = nodeList();
ClassOrInterfaceType queryCallViewItemImpl = queryDefImpl();
ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
objCreationExpr.setDiamondOperator();
stmts.addStatement(new ReturnStmt(objCreationExpr));
objCreationExpr.addArgument(new NameExpr(VIEWBUILDER));
objCreationExpr.addArgument("name");
rangeArity().forEach(i -> {
String genericTypeName = stringWithIndex("T", i);
String type = stringWithIndex("type", i);
String name = stringWithIndexInside(i);
typeArguments.add(parseType(genericTypeName));
arguments.add(new NameExpr(type));
arguments.add(new NameExpr(name));
String classGenericType = genericType(genericTypeName);
Type genericType = parseType(classGenericType);
query1.addParameter(genericType, type);
query1.addParameter(stringType(), name);
typeParameters.add(new TypeParameter(genericTypeName));
});
query1.setTypeParameters(typeParameters);
query1.setBody(stmts);
ClassOrInterfaceType type = queryDef();
type.setTypeArguments(typeArguments);
query1.setType(type);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FlowDSLQueryGenerator method queryPkgNameClassArg.
private void queryPkgNameClassArg(ClassOrInterfaceDeclaration clazz) {
MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
query1.addParameter(STRINGLITERAL, "pkg");
query1.addParameter(STRINGLITERAL, "name");
BlockStmt stmts = new BlockStmt();
NodeList<Type> typeArguments = nodeList();
NodeList<TypeParameter> typeParameters = nodeList();
NodeList<Expression> arguments = nodeList();
ClassOrInterfaceType queryCallViewItemImpl = queryDefImpl();
ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
objCreationExpr.setDiamondOperator();
stmts.addStatement(new ReturnStmt(objCreationExpr));
objCreationExpr.addArgument(new NameExpr(VIEWBUILDER));
objCreationExpr.addArgument("pkg");
objCreationExpr.addArgument("name");
rangeArity().forEach(i -> {
String genericTypeName = stringWithIndex("T", i);
String type = stringWithIndex("type", i);
String name = stringWithIndexInside(i);
typeArguments.add(parseType(genericTypeName));
arguments.add(new NameExpr(type));
arguments.add(new NameExpr(name));
String classGenericType = genericType(genericTypeName);
Type genericType = parseType(classGenericType);
query1.addParameter(genericType, type);
query1.addParameter(stringType(), name);
typeParameters.add(new TypeParameter(genericTypeName));
});
query1.setTypeParameters(typeParameters);
query1.setBody(stmts);
ClassOrInterfaceType type = queryDef();
type.setTypeArguments(typeArguments);
query1.setType(type);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class QueryDefImplGenerator method generateEquals.
private void generateEquals(ClassOrInterfaceDeclaration clazz) {
String template = " @Override\n" + " public boolean isEqualTo( ModelComponent other ) {\n" + " if ( this == other ) return true;\n" + " if ( !(other instanceof DEF_IMPL_TYPE) ) return false;\n" + "\n" + " DEF_IMPL_TYPE that = (DEF_IMPL_TYPE) other;\n" + "\n" + " return EQUALS_CALL;\n" + " }";
BodyDeclaration<?> parse = parseBodyDeclaration(template);
Expression andExpr = new BooleanLiteralExpr(true);
for (int i : rangeArity().toArray()) {
String argWithIndex = argIndex(i);
Expression e = parseExpression(String.format("ModelComponent.areEqualInModel( %s, that.%s )", argWithIndex, argWithIndex));
andExpr = new BinaryExpr(andExpr, e, BinaryExpr.Operator.AND);
}
final Expression finalAndExpr = andExpr;
parse.findAll(ClassOrInterfaceType.class, n -> n.toString().equals("DEF_IMPL_TYPE")).forEach(s -> s.replace(parseType("Query" + arity + "DefImpl")));
parse.findAll(NameExpr.class, n -> n.toString().equals("EQUALS_CALL")).forEach(s -> s.replace(finalAndExpr));
clazz.addMember(parse);
}
Aggregations