diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java index 606c92b859..36c6e99c2f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/MatchCollector.java @@ -27,8 +27,9 @@ class MatchCollector { public void collect(List marks) { // first get a pairwise collection of all maximal matches - for (int i = 0; i < marks.size() - 1; i++) { - int skipped = 0; + int skipped; + for (int i = 0; i < marks.size() - 1; i += skipped + 1) { + skipped = 0; TokenEntry mark1 = marks.get(i); for (int j = i + 1; j < marks.size(); j++) { TokenEntry mark2 = marks.get(j); @@ -55,8 +56,6 @@ class MatchCollector { } reportMatch(mark1, mark2, dupes); } - - i += skipped; } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/MatchAlgorithmTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/MatchAlgorithmTest.java index 8ba14d640d..5e2afca9b2 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/MatchAlgorithmTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/MatchAlgorithmTest.java @@ -37,15 +37,15 @@ class MatchAlgorithmTest { } private static String getMultipleRepetitionsCode() { - return "var x = [\n" + - " 1, 1, 1, 1, 1, 1, 1, 1,\n" + - " 0, 0, 0, 0, 0, 0, 0, 0,\n" + - " 2, 2, 2, 2, 2, 2, 2, 2,\n" + - " 0, 0, 0, 0, 0, 0, 0, 0,\n" + - " 3, 3, 3, 3, 3, 3, 3, 3,\n" + - " 0, 0, 0, 0, 0, 0, 0, 0,\n" + - " 4, 4, 4, 4, 4, 4, 4, 4\n" + - "];"; + return "var x = [\n" + + " 1, 1, 1, 1, 1, 1, 1, 1,\n" + + " 0, 0, 0, 0, 0, 0, 0, 0,\n" + + " 2, 2, 2, 2, 2, 2, 2, 2,\n" + + " 0, 0, 0, 0, 0, 0, 0, 0,\n" + + " 3, 3, 3, 3, 3, 3, 3, 3,\n" + + " 0, 0, 0, 0, 0, 0, 0, 0,\n" + + " 4, 4, 4, 4, 4, 4, 4, 4\n" + + "];"; } @Test diff --git a/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java b/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java index 635613908e..2faef10bc5 100644 --- a/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java +++ b/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java @@ -1,7 +1,10 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.lang.cpp.cpd; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.Path; import java.nio.file.Paths; @@ -11,7 +14,6 @@ import org.junit.jupiter.api.Test; import net.sourceforge.pmd.cpd.CPDConfiguration; import net.sourceforge.pmd.cpd.CpdAnalysis; -import net.sourceforge.pmd.cpd.Match; import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.cpp.CppLanguageModule;