}
private final static Pattern EMPTY_BODY = Pattern.compile("(\\{(\\s*\\})?)?");
public void makeFinalFieldsConstructor(final MutableConstructorDeclaration it) {
MutableTypeDeclaration _declaringType = it.getDeclaringType();
ArrayList<TypeReference> _finalFieldsConstructorArgumentTypes = this.getFinalFieldsConstructorArgumentTypes(_declaringType);
boolean _isEmpty = _finalFieldsConstructorArgumentTypes.isEmpty();
if (_isEmpty) {
Type _findTypeGlobally = this.context.findTypeGlobally(FinalFieldsConstructor.class);
final AnnotationReference anno = it.findAnnotation(_findTypeGlobally);
StringConcatenation _builder = new StringConcatenation();
_builder.append("There are no final fields, this annotation has no effect");
this.context.addWarning(anno, _builder.toString());
return;
}
MutableTypeDeclaration _declaringType_1 = it.getDeclaringType();
boolean _hasFinalFieldsConstructor = this.hasFinalFieldsConstructor(_declaringType_1);
if (_hasFinalFieldsConstructor) {
MutableTypeDeclaration _declaringType_2 = it.getDeclaringType();
String _constructorAlreadyExistsMessage = this.getConstructorAlreadyExistsMessage(_declaringType_2);
this.context.addError(it, _constructorAlreadyExistsMessage);
return;
}
Iterable<? extends MutableParameterDeclaration> _parameters = it.getParameters();
boolean _isEmpty_1 = IterableExtensions.isEmpty(_parameters);
boolean _not = (!_isEmpty_1);
if (_not) {
this.context.addError(it, "Parameter list must be empty");
}
boolean _and = false;
Expression _body = it.getBody();
boolean _tripleNotEquals = (_body != null);
if (!_tripleNotEquals) {
_and = false;
} else {
Expression _body_1 = it.getBody();
String _string = _body_1.toString();
Matcher _matcher = FinalFieldsConstructorProcessor.Util.EMPTY_BODY.matcher(_string);
boolean _matches = _matcher.matches();
boolean _not_1 = (!_matches);
_and = _not_1;
}
if (_and) {
this.context.addError(it, "Body must be empty");
}
Iterable<? extends ResolvedParameter> _elvis = null;
MutableTypeDeclaration _declaringType_3 = it.getDeclaringType();
ResolvedConstructor _superConstructor = this.getSuperConstructor(_declaringType_3);
Iterable<? extends ResolvedParameter> _resolvedParameters = null;
if (_superConstructor!=null) {
_resolvedParameters=_superConstructor.getResolvedParameters();
}
if (_resolvedParameters != null) {
_elvis = _resolvedParameters;
} else {
_elvis = Collections.<ResolvedParameter>unmodifiableList(CollectionLiterals.<ResolvedParameter>newArrayList());
}
final Iterable<? extends ResolvedParameter> superParameters = _elvis;
final Procedure1<ResolvedParameter> _function = new Procedure1<ResolvedParameter>() {
public void apply(final ResolvedParameter p) {
ParameterDeclaration _declaration = p.getDeclaration();
String _simpleName = _declaration.getSimpleName();
TypeReference _resolvedType = p.getResolvedType();
it.addParameter(_simpleName, _resolvedType);
}
};
IterableExtensions.forEach(superParameters, _function);
final HashMap<MutableFieldDeclaration, MutableParameterDeclaration> fieldToParameter = CollectionLiterals.<MutableFieldDeclaration, MutableParameterDeclaration>newHashMap();
MutableTypeDeclaration _declaringType_4 = it.getDeclaringType();
Iterable<? extends MutableFieldDeclaration> _finalFields = this.getFinalFields(_declaringType_4);
final Procedure1<MutableFieldDeclaration> _function_1 = new Procedure1<MutableFieldDeclaration>() {
public void apply(final MutableFieldDeclaration p) {
p.markAsInitializedBy(it);
String _simpleName = p.getSimpleName();
TypeReference _type = p.getType();
TypeReference _orObject = Util.this.orObject(_type);
final MutableParameterDeclaration param = it.addParameter(_simpleName, _orObject);
fieldToParameter.put(p, param);
}
};
IterableExtensions.forEach(_finalFields, _function_1);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("super(");
final Function1<ResolvedParameter, String> _function = new Function1<ResolvedParameter, String>() {
public String apply(final ResolvedParameter it) {
ParameterDeclaration _declaration = it.getDeclaration();
return _declaration.getSimpleName();
}
};
String _join = IterableExtensions.join(superParameters, ", ", _function);
_builder.append(_join, "");
_builder.append(");");
_builder.newLineIfNotEmpty();
{
MutableTypeDeclaration _declaringType = it.getDeclaringType();
Iterable<? extends MutableFieldDeclaration> _finalFields = Util.this.getFinalFields(_declaringType);
for(final MutableFieldDeclaration arg : _finalFields) {
_builder.append("this.");
String _simpleName = arg.getSimpleName();
_builder.append(_simpleName, "");