Search in sources :

Example 11 with BlockStmt

use of org.drools.javaparser.ast.stmt.BlockStmt in project drools by kiegroup.

the class POJOGenerator method generateHashCodeMethod.

private static MethodDeclaration generateHashCodeMethod(List<Statement> hashCodeFieldStatement) {
    final Statement header = parseStatement("int result = super.hashCode();");
    NodeList<Statement> hashCodeStatements = nodeList(header);
    hashCodeStatements.addAll(hashCodeFieldStatement);
    hashCodeStatements.add(parseStatement("return result;"));
    final Type returnType = JavaParser.parseType(int.class.getSimpleName());
    final MethodDeclaration equals = new MethodDeclaration(EnumSet.of(Modifier.PUBLIC), returnType, HASH_CODE);
    equals.addAnnotation("Override");
    equals.setBody(new BlockStmt(hashCodeStatements));
    return equals;
}
Also used : ClassOrInterfaceType(org.drools.javaparser.ast.type.ClassOrInterfaceType) PrimitiveType(org.drools.javaparser.ast.type.PrimitiveType) Type(org.drools.javaparser.ast.type.Type) JavaParser.parseStatement(org.drools.javaparser.JavaParser.parseStatement) Statement(org.drools.javaparser.ast.stmt.Statement) MethodDeclaration(org.drools.javaparser.ast.body.MethodDeclaration) BlockStmt(org.drools.javaparser.ast.stmt.BlockStmt)

Example 12 with BlockStmt

use of org.drools.javaparser.ast.stmt.BlockStmt in project drools by kiegroup.

the class POJOGenerator method generateEqualsMethod.

private static MethodDeclaration generateEqualsMethod(String generatedClassName, List<Statement> equalsFieldStatement) {
    NodeList<Statement> equalsStatements = nodeList(referenceEquals, classCheckEquals);
    equalsStatements.add(classCastStatement(generatedClassName));
    equalsStatements.add(parseStatement("if ( !super.equals( o ) ) return false;"));
    equalsStatements.addAll(equalsFieldStatement);
    equalsStatements.add(parseStatement("return true;"));
    final Type returnType = JavaParser.parseType(boolean.class.getSimpleName());
    final MethodDeclaration equals = new MethodDeclaration(EnumSet.of(Modifier.PUBLIC), returnType, EQUALS);
    equals.addParameter(Object.class, "o");
    equals.addAnnotation("Override");
    equals.setBody(new BlockStmt(equalsStatements));
    return equals;
}
Also used : ClassOrInterfaceType(org.drools.javaparser.ast.type.ClassOrInterfaceType) PrimitiveType(org.drools.javaparser.ast.type.PrimitiveType) Type(org.drools.javaparser.ast.type.Type) JavaParser.parseStatement(org.drools.javaparser.JavaParser.parseStatement) Statement(org.drools.javaparser.ast.stmt.Statement) MethodDeclaration(org.drools.javaparser.ast.body.MethodDeclaration) BlockStmt(org.drools.javaparser.ast.stmt.BlockStmt)

Example 13 with BlockStmt

use of org.drools.javaparser.ast.stmt.BlockStmt in project drools by kiegroup.

the class NamedConsequenceVisitor method onDSL.

private MethodCallExpr onDSL(NamedConsequenceDescr namedConsequence) {
    String namedConsequenceString = context.getNamedConsequences().get(namedConsequence.getName());
    BlockStmt ruleVariablesBlock = new BlockStmt();
    createVariables(context.getKbuilder(), ruleVariablesBlock, packageModel, context);
    return new Consequence(context).createCall(null, namedConsequenceString, ruleVariablesBlock, namedConsequence.isBreaking());
}
Also used : BlockStmt(org.drools.javaparser.ast.stmt.BlockStmt) Consequence(org.drools.modelcompiler.builder.generator.Consequence)

Aggregations

BlockStmt (org.drools.javaparser.ast.stmt.BlockStmt)13 MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)9 Statement (org.drools.javaparser.ast.stmt.Statement)9 MethodDeclaration (org.drools.javaparser.ast.body.MethodDeclaration)8 NameExpr (org.drools.javaparser.ast.expr.NameExpr)8 ClassOrInterfaceType (org.drools.javaparser.ast.type.ClassOrInterfaceType)8 AssignExpr (org.drools.javaparser.ast.expr.AssignExpr)6 Expression (org.drools.javaparser.ast.expr.Expression)6 VariableDeclarationExpr (org.drools.javaparser.ast.expr.VariableDeclarationExpr)6 Type (org.drools.javaparser.ast.type.Type)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 List (java.util.List)5 JavaParser (org.drools.javaparser.JavaParser)5 Modifier (org.drools.javaparser.ast.Modifier)5 ClassExpr (org.drools.javaparser.ast.expr.ClassExpr)5 StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)5 PackageModel (org.drools.modelcompiler.builder.PackageModel)5 Collectors.toList (java.util.stream.Collectors.toList)4 JavaParser.parseExpression (org.drools.javaparser.JavaParser.parseExpression)4