diff --git a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java index 00c3094..f0c2bae 100644 --- a/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java +++ b/src/main/java/fr/greencodeinitiative/java/checks/IncrementCheck.java @@ -20,6 +20,8 @@ import java.util.Collections; import java.util.List; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; import org.sonar.check.Rule; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.Tree; @@ -31,14 +33,17 @@ public class IncrementCheck extends IssuableSubscriptionVisitor { protected static final String MESSAGERULE = "Use ++i instead of i++"; + private static final Logger LOGGER = Loggers.get(IncrementCheck.class); @Override public List nodesToVisit() { return Collections.singletonList(Kind.POSTFIX_INCREMENT); } - @Override public void visitNode(Tree tree) { - reportIssue(tree, MESSAGERULE); + LOGGER.debug("Parent node is of Kind: " + tree.parent().toString()); + if (!tree.parent().is(Kind.ARGUMENTS)) { + reportIssue(tree, MESSAGERULE); + } } } diff --git a/src/test/files/IncrementCheck.java b/src/test/files/IncrementCheck.java index 6e7e6c2..26a7f9a 100644 --- a/src/test/files/IncrementCheck.java +++ b/src/test/files/IncrementCheck.java @@ -60,4 +60,10 @@ void foo51(int value) { System.out.println(i); } } + + // Compliant because maybe foo51 needs the incremented value + void foo6(int value) { + int i = 0; + foo51(i++); + } } \ No newline at end of file