Search in sources :

Example 1 with PrimitiveType

use of org.drools.javaparser.ast.type.PrimitiveType in project drools by kiegroup.

the class POJOGenerator method generateEqualsForField.

private static Statement generateEqualsForField(MethodDeclaration getter, String fieldName) {
    Type type = getter.getType();
    Statement statement;
    if (type instanceof ClassOrInterfaceType) {
        statement = parseStatement(" if( __fieldName != null ? !__fieldName.equals(that.__fieldName) : that.__fieldName != null) { return false; }");
    } else if (type instanceof PrimitiveType) {
        statement = parseStatement(" if( __fieldName != that.__fieldName) { return false; }");
    } else {
        throw new RuntimeException("Unknown type");
    }
    return replaceFieldName(statement, fieldName);
}
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) PrimitiveType(org.drools.javaparser.ast.type.PrimitiveType) ClassOrInterfaceType(org.drools.javaparser.ast.type.ClassOrInterfaceType)

Aggregations

JavaParser.parseStatement (org.drools.javaparser.JavaParser.parseStatement)1 Statement (org.drools.javaparser.ast.stmt.Statement)1 ClassOrInterfaceType (org.drools.javaparser.ast.type.ClassOrInterfaceType)1 PrimitiveType (org.drools.javaparser.ast.type.PrimitiveType)1 Type (org.drools.javaparser.ast.type.Type)1