@@ -99,26 +99,32 @@ static boolean isSetter(J.MethodDeclaration method) {
9999 return false ;
100100 }
101101 J .Assignment assignment = (J .Assignment ) method .getBody ().getStatements ().get (0 );
102- J .FieldAccess fieldAccess = (J .FieldAccess ) assignment .getVariable ();
103- if (!method .getSimpleName ().equals (deriveSetterMethodName (fieldAccess ))) {
102+ J .FieldAccess assignedField = (J .FieldAccess ) assignment .getVariable ();
103+ if (!method .getSimpleName ().equals (deriveSetterMethodName (assignedField ))) {
104104 return false ;
105105 }
106106
107107 // Check argument is assigned to field
108108 J .VariableDeclarations variableDeclarations = (J .VariableDeclarations ) method .getParameters ().get (0 );
109109 J .VariableDeclarations .NamedVariable param = variableDeclarations .getVariables ().get (0 );
110- JavaType paramType = param .getType ();
111- String paramName = param .getName ().toString ();
112110
111+ // type of parameter and field have to match
112+ if (!param .getType ().equals (assignedField .getType ())) {
113+ return false ;
114+ }
113115
114- return
115- // assigned value is exactly the parameter
116- assignment .getAssignment ().toString ().equals (paramName ) // type of parameter and field have to match
117- &&
118-
119- // type of parameter and field have to match
120- param .getType ().equals (fieldAccess .getType ());
116+ // Check field is declared on method type
117+ JavaType .FullyQualified declaringType = method .getMethodType ().getDeclaringType ();
118+ if (assignedField .getTarget () instanceof J .Identifier ) {
119+ J .Identifier target = (J .Identifier ) assignedField .getTarget ();
120+ return target .getFieldType () != null && declaringType == target .getFieldType ().getOwner ();
121+ } else if (assignedField .getTarget () instanceof J .FieldAccess ) {
122+ Expression target = ((J .FieldAccess ) assignedField .getTarget ()).getTarget ();
123+ return target instanceof J .Identifier && ((J .Identifier ) target ).getFieldType () != null &&
124+ declaringType == ((J .Identifier ) target ).getFieldType ().getOwner ();
125+ }
121126
127+ return false ;
122128 }
123129
124130 private static String deriveSetterMethodName (J .FieldAccess fieldAccess ) {
0 commit comments