if (variable == null || !variable.isParameter()) {
return null;
}
final MemberReferenceExpression memberReference = (MemberReferenceExpression) left;
final MemberReference member = memberReference.getUserData(Keys.MEMBER_REFERENCE);
if (member instanceof FieldReference &&
memberReference.getTarget() instanceof ThisReferenceExpression) {
final FieldDefinition resolvedField = ((FieldReference) member).resolve();
if (resolvedField != null && resolvedField.isSynthetic()) {
final ParameterDefinition parameter = variable.getOriginalParameter();
int parameterIndex = parameter.getPosition();
if (parameter.getMethod().getParameters().size() > _originalArguments.size()) {
parameterIndex -= (parameter.getMethod().getParameters().size() - _originalArguments.size());
}
if (parameterIndex >= 0 && parameterIndex < _originalArguments.size()) {
final Expression argument = _originalArguments.get(parameterIndex);
if (argument == null) {
return null;
}
_nodesToRemove.add(argument);
if (argument instanceof ThisReferenceExpression) {
//
// Don't replace outer class references; they will be rewritten later.
//
markConstructorParameterForRemoval(node, parameter);
return null;
}
_parametersToRemove.add(parameter);
final String fullName = member.getFullName();
if (!hasSideEffects(argument)) {
_replacements.put(fullName, argument);
}
else {
context.getForcedVisibleMembers().add(resolvedField);
_initializers.put(fullName, argument);
}
if (node.getParent() instanceof ExpressionStatement) {
_nodesToRemove.add(node.getParent());
}
markConstructorParameterForRemoval(node, parameter);
}
}
else if (_baseConstructorCalled &&
resolvedField != null &&
context.getCurrentMethod().isConstructor() &&
(!context.getCurrentMethod().isSynthetic() ||
context.getSettings().getShowSyntheticMembers())) {
final MemberReferenceExpression leftMemberReference = (MemberReferenceExpression) left;
final MemberReference leftMember = leftMemberReference.getUserData(Keys.MEMBER_REFERENCE);
final Variable rightVariable = right.getUserData(Keys.VARIABLE);
if (rightVariable.isParameter()) {
final ParameterDefinition parameter = variable.getOriginalParameter();
final int parameterIndex = parameter.getPosition();
if (parameterIndex >= 0 && parameterIndex < _originalArguments.size()) {
final Expression argument = _originalArguments.get(parameterIndex);
if (parameterIndex == 0 &&
argument instanceof ThisReferenceExpression &&
isLocalOrAnonymous(context.getCurrentType())) {
//
// Don't replace outer class references; they will be rewritten later.
//
return null;
}
final FieldDefinition resolvedTargetField = ((FieldReference) leftMember).resolve();
if (resolvedTargetField != null && !resolvedTargetField.isSynthetic()) {
_parametersToRemove.add(parameter);
_initializers.put(resolvedTargetField.getFullName(), argument);
if (node.getParent() instanceof ExpressionStatement) {
_nodesToRemove.add(node.getParent());
}
}
}
}
}
}
}
else if (_baseConstructorCalled && right instanceof MemberReferenceExpression) {
final MemberReferenceExpression leftMemberReference = (MemberReferenceExpression) left;
final MemberReference leftMember = leftMemberReference.getUserData(Keys.MEMBER_REFERENCE);
final MemberReferenceExpression rightMemberReference = (MemberReferenceExpression) right;
final MemberReference rightMember = right.getUserData(Keys.MEMBER_REFERENCE);
if (rightMember instanceof FieldReference &&
rightMemberReference.getTarget() instanceof ThisReferenceExpression) {
final FieldDefinition resolvedTargetField = ((FieldReference) leftMember).resolve();
final FieldDefinition resolvedSourceField = ((FieldReference) rightMember).resolve();
if (resolvedSourceField != null &&
resolvedTargetField != null &&
resolvedSourceField.isSynthetic() &&
!resolvedTargetField.isSynthetic()) {
final Expression initializer = _replacements.get(rightMember.getFullName());
if (initializer != null) {
_initializers.put(resolvedTargetField.getFullName(), initializer);
if (node.getParent() instanceof ExpressionStatement) {