Search in sources :

Example 11 with MethodDeclaration

use of org.drools.javaparser.ast.body.MethodDeclaration 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)

Aggregations

MethodDeclaration (org.drools.javaparser.ast.body.MethodDeclaration)11 BlockStmt (org.drools.javaparser.ast.stmt.BlockStmt)8 MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)6 Type (org.drools.javaparser.ast.type.Type)6 NameExpr (org.drools.javaparser.ast.expr.NameExpr)5 Statement (org.drools.javaparser.ast.stmt.Statement)5 ClassOrInterfaceType (org.drools.javaparser.ast.type.ClassOrInterfaceType)5 ArrayList (java.util.ArrayList)4 JavaParser.parseStatement (org.drools.javaparser.JavaParser.parseStatement)4 PrimitiveType (org.drools.javaparser.ast.type.PrimitiveType)4 List (java.util.List)3 Optional (java.util.Optional)3 Modifier (org.drools.javaparser.ast.Modifier)3 ClassOrInterfaceDeclaration (org.drools.javaparser.ast.body.ClassOrInterfaceDeclaration)3 AssignExpr (org.drools.javaparser.ast.expr.AssignExpr)3 Expression (org.drools.javaparser.ast.expr.Expression)3 FieldAccessExpr (org.drools.javaparser.ast.expr.FieldAccessExpr)3 StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)3 VariableDeclarationExpr (org.drools.javaparser.ast.expr.VariableDeclarationExpr)3 ReturnStmt (org.drools.javaparser.ast.stmt.ReturnStmt)3