1919 */
2020package org .sonar .java .checks ;
2121
22- import com .google .common .base .Joiner ;
2322import com .google .common .collect .ImmutableList ;
2423import com .google .common .collect .Lists ;
2524import org .apache .commons .lang .BooleanUtils ;
2928import org .sonar .java .model .ModifiersUtils ;
3029import org .sonar .java .model .declaration .MethodTreeImpl ;
3130import org .sonar .java .tag .Tag ;
31+ import org .sonar .plugins .java .api .JavaFileScannerContext ;
3232import org .sonar .plugins .java .api .tree .BlockTree ;
33+ import org .sonar .plugins .java .api .tree .IdentifierTree ;
3334import org .sonar .plugins .java .api .tree .MethodTree ;
3435import org .sonar .plugins .java .api .tree .Modifier ;
3536import org .sonar .plugins .java .api .tree .Tree ;
3839import org .sonar .squidbridge .annotations .SqaleConstantRemediation ;
3940import org .sonar .squidbridge .annotations .SqaleSubCharacteristic ;
4041
42+ import java .util .ArrayList ;
4143import java .util .List ;
4244
4345@ Rule (
@@ -59,14 +61,19 @@ public List<Tree.Kind> nodesToVisit() {
5961 public void visitNode (Tree tree ) {
6062 MethodTree methodTree = (MethodTree ) tree ;
6163 if (hasSemantic () && methodTree .block () != null && !isExcluded (methodTree )) {
62- List <String > unused = Lists .newArrayList ();
64+ List <IdentifierTree > unused = Lists .newArrayList ();
6365 for (VariableTree var : methodTree .parameters ()) {
6466 if (var .symbol ().usages ().isEmpty ()) {
65- unused .add (var .simpleName (). name () );
67+ unused .add (var .simpleName ());
6668 }
6769 }
6870 if (!unused .isEmpty ()) {
69- addIssue (methodTree , "Remove the unused method parameter(s) \" " + Joiner .on ("," ).join (unused ) + "\" ." );
71+ List <JavaFileScannerContext .Location > locations = new ArrayList <>();
72+ for (IdentifierTree identifier : unused .subList (1 , unused .size ())) {
73+ locations .add (new JavaFileScannerContext .Location ("Remove this unused method parameter " +identifier .name ()+"\" ." , identifier ));
74+ }
75+ IdentifierTree firstUnused = unused .get (0 );
76+ reportIssue (firstUnused , "Remove this unused method parameter \" " + firstUnused .name () + "\" ." , locations , null );
7077 }
7178 }
7279 }
0 commit comments