Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (56 sloc) 2.05 KB
/**
* Copyright (C) 2014 41concepts Aps
*
* This is a helper template group file that is responsible for generating the equals method.
**/
method_equals_Object(clazz, method) ::= <<
<@javadoc><JavaDocMethod(method)><@end><@annotations><method.annotations:annotationLine()><@end><\\>
<declare_method(clazz, method)>
{
<@preamble><@end>
<@sameinstancecheck>
if (this == <first(method.parameters).name>)
return true;
<@end>
<@nullcheck>
if (<first(method.parameters).name> == null)
return false;
<@end>
<@supercheck>
<if(!method.declaringType.rootObject)>
if (!super.equals(obj))
return false;
<endif>
<@end>
<@typecheck>
if (getClass() != <first(method.parameters).name>.getClass())
return false;
<@end>
<if(clazz.anyMembers)>
@SuppressWarnings("unchecked")
<clazz.prototypicalName> <uniqueVariableName(clazz,"other")> = (<clazz.prototypicalName>) <first(method.parameters).name>;
<endif>
<@postamble><@end>
return <@returnvalue><if(clazz.anyMembers)>(<clazz.members:{m | <(equalsTemplateNamesByTypeCategory.(m.type.typeCategory))(clazz, m.name, m.type)>}; wrap, anchor, separator=" && ">)<else>true<endif><@end>;
}
>>
equalsTemplateNamesByTypeCategory ::= [ "PRIMITIVE": "equals_primitive", "ARRAY": "equals_array", default: "equals_object"]
equals_primitive(clazz, var, type) ::= <%
<if(type.primitiveFloat)>
(Float.floatToIntBits(<var>) == Float.floatToIntBits(<uniqueVariableName(clazz,"other")>.<var>))
<elseif(type.primitiveDouble)>
(Double.doubleToLongBits(<var>) == Double.doubleToLongBits(<uniqueVariableName(clazz,"other")>.<var>))
<else>
(<var> == <uniqueVariableName(clazz,"other")>.<var>)
<endif>
%>
equals_array(clazz, var, type) ::= <%
<if(type.multiDimensionalArray)>
<clazz.helperTypes.javaUtilArrays.name>.deepEquals(<var>, <uniqueVariableName(clazz,"other")>.<var>)
<else>
<clazz.helperTypes.javaUtilArrays.name>.equals(<var>, <uniqueVariableName(clazz,"other")>.<var>)
<endif>
%>
equals_object(clazz, var, type) ::= <%
<clazz.helperTypes.javaUtilObjects.name>.equals(<var>, <uniqueVariableName(clazz,"other")>.<var>)
%>