diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2019-12-09 09:34:43 -0600 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-12-10 20:46:09 +0100 |
commit | d1fd889554bccbb50122550899dbb66b90b04f78 (patch) | |
tree | 9cad838366292ee79b77ac3513403f7489b06355 /sonar-duplications | |
parent | f86a1094588e4e47b3abf612891af0431653cd0e (diff) | |
download | sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.tar.gz sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.zip |
Fix code quality issues and reduce dependency on Guava
Diffstat (limited to 'sonar-duplications')
8 files changed, 17 insertions, 28 deletions
diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java index bc7a20bdd16..e2adf71f69e 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java @@ -67,7 +67,7 @@ public class TokenEntry implements Comparable<TokenEntry> { i = TOKENS.size() + 1; TOKENS.put(image, i); } - this.identifier = i.intValue(); + this.identifier = i; this.tokenSrcID = tokenSrcID; this.beginLine = beginLine; this.index = tokenCount++; diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/ContainsInComparator.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/ContainsInComparator.java index efea70410c8..31b1481270c 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/ContainsInComparator.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/ContainsInComparator.java @@ -34,25 +34,17 @@ public final class ContainsInComparator implements Comparator<ClonePart> { /** * Defines order by resourceId. */ - public static final Comparator<ClonePart> RESOURCE_ID_COMPARATOR = new Comparator<ClonePart>() { - @Override - public int compare(ClonePart o1, ClonePart o2) { - return FastStringComparator.INSTANCE.compare(o1.getResourceId(), o2.getResourceId()); - } - }; + public static final Comparator<ClonePart> RESOURCE_ID_COMPARATOR = (o1, o2) -> FastStringComparator.INSTANCE.compare(o1.getResourceId(), o2.getResourceId()); /** * Defines order by resourceId and by unitStart. */ - public static final Comparator<ClonePart> CLONEPART_COMPARATOR = new Comparator<ClonePart>() { - @Override - public int compare(ClonePart o1, ClonePart o2) { - int c = RESOURCE_ID_COMPARATOR.compare(o1, o2); - if (c == 0) { - return o1.getUnitStart() - o2.getUnitStart(); - } - return c; + public static final Comparator<ClonePart> CLONEPART_COMPARATOR = (o1, o2) -> { + int c = RESOURCE_ID_COMPARATOR.compare(o1, o2); + if (c == 0) { + return o1.getUnitStart() - o2.getUnitStart(); } + return c; }; private final int l1; diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/statement/matcher/UptoTokenMatcher.java b/sonar-duplications/src/main/java/org/sonar/duplications/statement/matcher/UptoTokenMatcher.java index e8ccfb4018e..52d0fe18cd9 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/statement/matcher/UptoTokenMatcher.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/statement/matcher/UptoTokenMatcher.java @@ -19,6 +19,7 @@ */ package org.sonar.duplications.statement.matcher; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -41,9 +42,7 @@ public class UptoTokenMatcher extends TokenMatcher { // otherwise we will always try to consume everything, but will never succeed throw new IllegalArgumentException(); } - for (String uptoMatchToken : uptoMatchTokens) { - this.uptoMatchTokens.add(uptoMatchToken); - } + this.uptoMatchTokens.addAll(Arrays.asList(uptoMatchTokens)); } @Override diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java index e21de0e8756..f44d6c4b70c 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java @@ -19,6 +19,7 @@ */ package org.sonar.duplications.detector.original; +import java.util.Arrays; import org.junit.Test; import org.sonar.duplications.block.Block; @@ -40,9 +41,7 @@ public class BlocksGroupTest { public static BlocksGroup newBlocksGroup(Block... blocks) { BlocksGroup result = BlocksGroup.empty(); - for (Block block : blocks) { - result.blocks.add(block); - } + result.blocks.addAll(Arrays.asList(blocks)); return result; } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/DataUtilsTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/DataUtilsTest.java index 4825849122f..058161a8ee7 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/index/DataUtilsTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/index/DataUtilsTest.java @@ -63,7 +63,7 @@ public class DataUtilsTest { assertThat(DataUtils.binarySearch(sortable), is(2)); } - class SimpleSortable implements DataUtils.Sortable { + static class SimpleSortable implements DataUtils.Sortable { private final int[] a; private final int size; diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java index 43636a71f66..23e6c0e4603 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java @@ -20,7 +20,6 @@ package org.sonar.duplications.internal.pmd; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.List; @@ -42,7 +41,7 @@ public class TokenizerBridgeTest { @Before public void setUp() { Tokenizer tokenizer = new Tokenizer() { - public void tokenize(SourceCode tokens, Tokens tokenEntries) throws IOException { + public void tokenize(SourceCode tokens, Tokens tokenEntries) { tokenEntries.add(new TokenEntry("t1", "src", 1)); tokenEntries.add(new TokenEntry("t2", "src", 1)); tokenEntries.add(new TokenEntry("t3", "src", 2)); diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java index 75966a19091..8d8f8ab2010 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaDuplicationsFunctionalTest.java @@ -19,6 +19,7 @@ */ package org.sonar.duplications.java; +import java.util.Arrays; import java.util.Collection; import java.util.List; import org.junit.Test; @@ -33,7 +34,6 @@ import org.sonar.duplications.statement.Statement; import org.sonar.duplications.statement.StatementChunker; import org.sonar.duplications.token.TokenChunker; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.joining; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -149,7 +149,7 @@ public class JavaDuplicationsFunctionalTest { } private String source(String... lines) { - return asList(lines).stream().collect(joining("\n")); + return Arrays.stream(lines).collect(joining("\n")); } private static List<CloneGroup> detect2(String... fragments) { @@ -180,7 +180,7 @@ public class JavaDuplicationsFunctionalTest { private static BlockChunker BLOCK_CHUNKER = new BlockChunker(BLOCK_SIZE); private List<CloneGroup> detect(String... lines) { - String sourceCode = asList(lines).stream().collect(joining("\n")); + String sourceCode = Arrays.stream(lines).collect(joining("\n")); MemoryCloneIndex index = new MemoryCloneIndex(); List<Statement> statements = STATEMENT_CHUNKER.chunk(TOKEN_CHUNKER.chunk(sourceCode)); List<Block> blocks = BLOCK_CHUNKER.chunk("resourceId", statements); diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java index 9762da77fba..f11a6f90fff 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/statement/StatementTest.java @@ -37,7 +37,7 @@ public class StatementTest { @Test(expected = IllegalArgumentException.class) public void shouldNotAcceptEmpty() { - new Statement(new ArrayList<Token>()); + new Statement(new ArrayList<>()); } @Test |