use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class PatternDSLQueryGenerator method queryFirstMethod.
private void queryFirstMethod(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 = queryDefImplType();
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 = argNameWithIndex(i);
typeArguments.add(parseType(genericTypeName));
arguments.add(new NameExpr(type));
arguments.add(new NameExpr(name));
String classGenericType = genericType("Class", genericTypeName);
Type genericType = parseType(classGenericType);
query1.addParameter(genericType, type);
query1.addParameter(parseType(STRINGLITERAL), name);
typeParameters.add(new TypeParameter(genericTypeName));
});
query1.setTypeParameters(typeParameters);
query1.setBody(stmts);
ClassOrInterfaceType type = queryDefType();
type.setTypeArguments(typeArguments);
query1.setType(type);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class PatternDSLQueryGenerator method querySecondMethod.
private void querySecondMethod(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 = queryDefImplType();
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 = argNameWithIndex(i);
typeArguments.add(parseType(genericTypeName));
arguments.add(new NameExpr(type));
arguments.add(new NameExpr(name));
String classGenericType = genericType("Class", genericTypeName);
Type genericType = parseType(classGenericType);
query1.addParameter(genericType, type);
query1.addParameter(parseType(STRINGLITERAL), name);
typeParameters.add(new TypeParameter(genericTypeName));
});
query1.setTypeParameters(typeParameters);
query1.setBody(stmts);
ClassOrInterfaceType type = queryDefType();
type.setTypeArguments(typeArguments);
query1.setType(type);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class PatternDSLQueryGenerator method queryFirstMethodOnlyClass.
private void queryFirstMethodOnlyClass(ClassOrInterfaceDeclaration clazz) {
MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
addNameParameter(query1);
BlockStmt stmts = new BlockStmt();
NodeList<Type> typeArguments = nodeList();
NodeList<TypeParameter> typeParameters = nodeList();
NodeList<Expression> arguments = nodeList();
ClassOrInterfaceType queryCallViewItemImpl = queryDefImplType();
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);
typeArguments.add(parseType(genericTypeName));
arguments.add(new NameExpr(type));
String classGenericType = genericType(CLASS, genericTypeName);
Type genericType = parseType(classGenericType);
query1.addParameter(genericType, type);
typeParameters.add(new TypeParameter(genericTypeName));
});
query1.setTypeParameters(typeParameters);
query1.setBody(stmts);
ClassOrInterfaceType type = queryDefType();
type.setTypeArguments(typeArguments);
query1.setType(type);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class PatternDSLQueryGenerator method querySecondMethodOnlyClass.
private void querySecondMethodOnlyClass(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 = queryDefImplType();
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);
typeArguments.add(parseType(genericTypeName));
arguments.add(new NameExpr(type));
String classGenericType = genericType(CLASS, genericTypeName);
Type genericType = parseType(classGenericType);
query1.addParameter(genericType, type);
typeParameters.add(new TypeParameter(genericTypeName));
});
query1.setTypeParameters(typeParameters);
query1.setBody(stmts);
ClassOrInterfaceType type = queryDefType();
type.setTypeArguments(typeArguments);
query1.setType(type);
}
use of com.github.javaparser.ast.expr.ObjectCreationExpr in project drools by kiegroup.
the class MaterializedLambdaPredicate method createPredicateInformationMethod.
private void createPredicateInformationMethod(EnumDeclaration classDeclaration) {
MethodDeclaration methodDeclaration = classDeclaration.addMethod("predicateInformation", Modifier.Keyword.PUBLIC);
methodDeclaration.addAnnotation("Override");
ClassOrInterfaceType predicateInformationType = toClassOrInterfaceType(PredicateInformation.class);
methodDeclaration.setType(predicateInformationType);
BlockStmt block = new BlockStmt();
NameExpr infoExpr = new NameExpr("info");
VariableDeclarationExpr infoVar = new VariableDeclarationExpr(toClassOrInterfaceType(PredicateInformation.class), "info");
NodeList<Expression> newPredicateInformationArguments = NodeList.nodeList(toStringLiteral(StringEscapeUtils.escapeJava(predicateInformation.getStringConstraint())));
ObjectCreationExpr newPredicateInformation = new ObjectCreationExpr(null, predicateInformationType, newPredicateInformationArguments);
block.addStatement(new AssignExpr(infoVar, newPredicateInformation, AssignExpr.Operator.ASSIGN));
int i = 0;
NodeList<Expression> addRuleNamesArguments = null;
for (PredicateInformation.RuleDef ruleDef : predicateInformation.getRuleDefs()) {
if (i++ % 125 == 0) {
addRuleNamesArguments = NodeList.nodeList();
block.addStatement(new MethodCallExpr(infoExpr, "addRuleNames", addRuleNamesArguments));
}
addRuleNamesArguments.add(toStringLiteral(ruleDef.getRuleName()));
addRuleNamesArguments.add(toStringLiteral(ruleDef.getFileName()));
}
if (predicateInformation.isMoreThanMaxRuleDefs()) {
block.addStatement(new MethodCallExpr(infoExpr, "setMoreThanMaxRuleDefs", NodeList.nodeList(new BooleanLiteralExpr(true))));
}
block.addStatement(new ReturnStmt(infoExpr));
methodDeclaration.setBody(block);
}
Aggregations