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;
}
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;
}
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());
}
Aggregations