if (_notEquals) {
context.addError(cls, "Inheritance does not play well with immutability");
}
cls.setFinal(true);
String _builderClassName = this.builderClassName(cls);
MutableClassDeclaration _findClass = context.findClass(_builderClassName);
final Procedure1<MutableClassDeclaration> _function = new Procedure1<MutableClassDeclaration>() {
public void apply(final MutableClassDeclaration it) {
it.setFinal(true);
final Procedure1<MutableMethodDeclaration> _function = new Procedure1<MutableMethodDeclaration>() {
public void apply(final MutableMethodDeclaration it) {
TypeReference _newTypeReference = context.newTypeReference(cls);
it.setReturnType(_newTypeReference);
final CompilationStrategy _function = new CompilationStrategy() {
public CharSequence compile(final CompilationStrategy.CompilationContext it) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("return new ");
String _simpleName = cls.getSimpleName();
_builder.append(_simpleName, "");
_builder.append("(");
Iterable<? extends MutableFieldDeclaration> _dataFields = ImmutableProcessor.this.dataFields(cls);
final Function1<MutableFieldDeclaration, String> _function = new Function1<MutableFieldDeclaration, String>() {
public String apply(final MutableFieldDeclaration it) {
return it.getSimpleName();
}
};
String _join = IterableExtensions.join(_dataFields, ",", _function);
_builder.append(_join, "");
_builder.append(");");
_builder.newLineIfNotEmpty();
return _builder;
}
};
it.setBody(_function);
}
};
it.addMethod("build", _function);
Iterable<? extends MutableFieldDeclaration> _dataFields = ImmutableProcessor.this.dataFields(cls);
final Procedure1<MutableFieldDeclaration> _function_1 = new Procedure1<MutableFieldDeclaration>() {
public void apply(final MutableFieldDeclaration field) {
String _simpleName = field.getSimpleName();
final Procedure1<MutableMethodDeclaration> _function = new Procedure1<MutableMethodDeclaration>() {
public void apply(final MutableMethodDeclaration it) {
String _simpleName = field.getSimpleName();
TypeReference _type = field.getType();
it.addParameter(_simpleName, _type);
String _builderClassName = ImmutableProcessor.this.builderClassName(cls);
TypeReference _newTypeReference = context.newTypeReference(_builderClassName);
it.setReturnType(_newTypeReference);
final CompilationStrategy _function = new CompilationStrategy() {
public CharSequence compile(final CompilationStrategy.CompilationContext it) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("this.");
String _simpleName = field.getSimpleName();
_builder.append(_simpleName, "");
_builder.append(" = ");
String _simpleName_1 = field.getSimpleName();
_builder.append(_simpleName_1, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("return this;");
_builder.newLine();
return _builder;
}
};
it.setBody(_function);
}
};
it.addMethod(_simpleName, _function);
String _simpleName_1 = field.getSimpleName();
final Procedure1<MutableFieldDeclaration> _function_1 = new Procedure1<MutableFieldDeclaration>() {
public void apply(final MutableFieldDeclaration it) {
TypeReference _type = field.getType();
it.setType(_type);
}
};
it.addField(_simpleName_1, _function_1);
}
};
IterableExtensions.forEach(_dataFields, _function_1);
}
};
final MutableClassDeclaration builder = ObjectExtensions.<MutableClassDeclaration>operator_doubleArrow(_findClass, _function);
final Procedure1<MutableMethodDeclaration> _function_1 = new Procedure1<MutableMethodDeclaration>() {
public void apply(final MutableMethodDeclaration it) {
it.setStatic(true);
TypeReference _newTypeReference = context.newTypeReference(cls);
it.setReturnType(_newTypeReference);