void buildCompareTo() throws SourceException {
JMethod compareToMethod = valueClass.method(JMod.PUBLIC | JMod.FINAL, types._int, "compareTo");
compareToMethod.annotate(Override.class);
VariableNameSource nameSource = new VariableNameSource();
AbstractJClass usedValueClassType = valueClass.narrow(valueClass.typeParams());
JVar that = compareToMethod.param(JMod.FINAL, usedValueClassType, nameSource.get("that"));
AbstractJClass visitorType = visitorInterface.narrowed(usedValueClassType, types._Integer, types._RuntimeException);
JDefinedClass anonymousClass1 = valueClass.owner().anonymousClass(visitorType);
JMethod[] methods = visitorInterface.methods().toArray(new JMethod[visitorInterface.methods().size()]);
for (int interfaceMethodIndex1 = 0; interfaceMethodIndex1 < methods.length; interfaceMethodIndex1++) {
JMethod interfaceMethod1 = methods[interfaceMethodIndex1];
JMethod visitorMethod1 = anonymousClass1.method(interfaceMethod1.mods().getValue() & ~JMod.ABSTRACT, types._Integer, interfaceMethod1.name());
visitorMethod1.annotate(Override.class);
visitorMethod1.annotate(Nonnull.class);
VariableNameSource nameSource1 = nameSource.forBlock();
List<JVar> arguments1 = new ArrayList<JVar>();
JVar varArgument1 = null;
for (JVar param1: interfaceMethod1.params()) {
AbstractJType argumentType = visitorInterface.substituteSpecialType(param1.type(), usedValueClassType, types._Integer, types._RuntimeException);
JVar argument1 = visitorMethod1.param(param1.mods().getValue() | JMod.FINAL, argumentType, nameSource1.get(param1.name()));
arguments1.add(argument1);
}
JVar param1 = interfaceMethod1.listVarParam();
if (param1 != null) {
AbstractJType argumentType = visitorInterface.substituteSpecialType(param1.type().elementType(), usedValueClassType, types._Integer, types._RuntimeException);
JVar argument1 = visitorMethod1.varParam(param1.mods().getValue() | JMod.FINAL, argumentType, nameSource1.get(param1.name()));
varArgument1 = argument1;
}
JDefinedClass anonymousClass2 = valueClass.owner().anonymousClass(visitorType);
for (int interfaceMethodIndex2 = 0; interfaceMethodIndex2 < methods.length; interfaceMethodIndex2++) {
JMethod interfaceMethod2 = methods[interfaceMethodIndex2];
JMethod visitorMethod2 = anonymousClass2.method(interfaceMethod2.mods().getValue() & ~JMod.ABSTRACT, types._Integer, interfaceMethod2.name());
visitorMethod2.annotate(Override.class);
visitorMethod2.annotate(Nonnull.class);
VariableNameSource nameSource2 = nameSource1.forBlock();
List<JVar> arguments2 = new ArrayList<JVar>();
JVar varArgument2 = null;
for (JVar param2: interfaceMethod2.params()) {
AbstractJType argumentType = visitorInterface.substituteSpecialType(param2.type(), usedValueClassType, types._Integer, types._RuntimeException);
JVar argument2 = visitorMethod2.param(param2.mods().getValue(), argumentType, nameSource2.get(param2.name()));
arguments2.add(argument2);
}
JVar param2 = interfaceMethod2.listVarParam();
if (param2 != null) {
AbstractJType argumentType = visitorInterface.substituteSpecialType(param2.type().elementType(), usedValueClassType, types._Integer, types._RuntimeException);
JVar argument2 = visitorMethod2.varParam(param2.mods().getValue(), argumentType, nameSource2.get(param2.name()));
varArgument2 = argument2;
}
if (!interfaceMethod1.name().equals(interfaceMethod2.name())) {
int result = (interfaceMethodIndex1 < interfaceMethodIndex2 ? -1 : (interfaceMethodIndex1 == interfaceMethodIndex2 ? 0 : 1));
visitorMethod2.body()._return(JExpr.lit(result));
} else {
if (!interfaceMethod1.params().isEmpty() || interfaceMethod1.hasVarArgs()) {
CompareToMethod compareToMethodModel = new CompareToMethod(types, visitorMethod2.body(), nameSource2);
CompareToMethod.Body body = compareToMethodModel.createBody();
for (int i = 0; i < interfaceMethod1.params().size(); i++) {
JVar argument1 = arguments1.get(i);
JVar argument2 = arguments2.get(i);
JVar param = interfaceMethod1.params().get(i);
if (isNullable(param))
body.appendNullableValue(argument1.type(), argument1, argument2);
else
body.appendNotNullValue(argument1.type(), argument1, argument2);
}
if (varArgument1 != null) {
JVar param = interfaceMethod1.listVarParam();
if (isNullable(param))
body.appendNullableValue(varArgument1.type(), varArgument1, varArgument2);
else
body.appendNotNullValue(varArgument1.type(), varArgument1, varArgument2);
}