aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-02-12 20:44:41 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-02-13 11:42:13 +0400
commite0589ad21f8cb45b38c9879a44f73ad6aafeb618 (patch)
treef890ab74bdb8b930b944edcf83ec5ba1c9568ac8 /sonar-duplications
parentc2cb97c242b64f0815d01ed5fa193fffadc97bca (diff)
downloadsonarqube-e0589ad21f8cb45b38c9879a44f73ad6aafeb618.tar.gz
sonarqube-e0589ad21f8cb45b38c9879a44f73ad6aafeb618.zip
Remove deprecated and unused code
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java12
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java2
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java59
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java65
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java56
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java37
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/detector/original/BlocksGroupTest.java12
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java102
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java19
9 files changed, 55 insertions, 309 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
index 822454db205..e618a3c1614 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
@@ -113,18 +113,6 @@ public final class Block implements CodeFragment {
this.endUnit = builder.endUnit;
}
- /**
- * @deprecated since 2.14 use {@link #builder()}
- */
- @Deprecated
- public Block(String resourceId, ByteArray blockHash, int indexInFile, int startLine, int endLine) {
- this.resourceId = resourceId;
- this.blockHash = blockHash;
- this.indexInFile = indexInFile;
- this.startLine = startLine;
- this.endLine = endLine;
- }
-
public String getHashHex() {
return getBlockHash().toString();
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
index afefdef5c07..84f3633f5f6 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java
@@ -147,7 +147,7 @@ public final class OriginalCloneDetectionAlgorithm {
// stored in a0. Clones are only reported, if tuples are lost in
// Line 12, as otherwise all current clones could be prolonged
// by one statement. Clone reporting matches tuples that, after
- // correction of the statement index, appear in both c(i) and a;
+ // correction of the statement index, appear in both c(i) and a,
// each matched pair corresponds to a single clone. Its location
// can be extracted from the filename and info fields.
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java
index cd7f520120b..64377a4955d 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex.java
@@ -19,66 +19,29 @@
*/
package org.sonar.duplications.index;
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Comparator;
-
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.TreeMultimap;
+import java.util.Collection;
public class MemoryCloneIndex implements CloneIndex {
- private final TreeMultimap<String, Block> filenameIndex;
- private final HashMultimap<ByteArray, Block> sequenceHashIndex;
-
- private static final class ValueComparator implements Comparator<Block>, Serializable {
-
- private static final long serialVersionUID = 6048010242032502222L;
-
- public int compare(Block o1, Block o2) {
- if (o2.getResourceId().equals(o1.getResourceId())) {
- return o1.getIndexInFile() - o2.getIndexInFile();
- }
- return o1.getResourceId().compareTo(o2.getResourceId());
- }
- }
-
- private static final class KeyComparator implements Comparator<String>, Serializable {
-
- private static final long serialVersionUID = 8705841881237170539L;
-
- public int compare(String o1, String o2) {
- return o1.compareTo(o2);
- }
- }
-
- public MemoryCloneIndex() {
- filenameIndex = TreeMultimap.create(new KeyComparator(), new ValueComparator());
- sequenceHashIndex = HashMultimap.create();
- }
-
- public Collection<String> getAllUniqueResourceId() {
- return filenameIndex.keySet();
- }
-
- public boolean containsResourceId(String resourceId) {
- return filenameIndex.containsKey(resourceId);
- }
+ private Multimap<String, Block> byResource = ArrayListMultimap.create();
+ private Multimap<ByteArray, Block> byHash = ArrayListMultimap.create();
- public Collection<Block> getByResourceId(String fileName) {
- return filenameIndex.get(fileName);
+ public Collection<Block> getByResourceId(String resourceId) {
+ return byResource.get(resourceId);
}
public Collection<Block> getBySequenceHash(ByteArray sequenceHash) {
- return sequenceHashIndex.get(sequenceHash);
+ return byHash.get(sequenceHash);
}
- public void insert(Block tuple) {
- filenameIndex.put(tuple.getResourceId(), tuple);
- sequenceHashIndex.put(tuple.getBlockHash(), tuple);
+ public void insert(Block block) {
+ byResource.put(block.getResourceId(), block);
+ byHash.put(block.getBlockHash(), block);
}
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java
deleted file mode 100644
index 324a5e120e3..00000000000
--- a/sonar-duplications/src/main/java/org/sonar/duplications/index/MemoryCloneIndex2.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.duplications.index;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.sonar.duplications.block.Block;
-import org.sonar.duplications.block.ByteArray;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-public class MemoryCloneIndex2 extends AbstractCloneIndex {
-
- private Map<String, List<Block>> byResource = Maps.newHashMap();
- private Map<ByteArray, List<Block>> byHash = Maps.newHashMap();
-
- public Collection<Block> getByResourceId(String resourceId) {
- return get(byResource, resourceId);
- }
-
- public Collection<Block> getBySequenceHash(ByteArray sequenceHash) {
- return get(byHash, sequenceHash);
- }
-
- public void insert(Block block) {
- put(byResource, block.getResourceId(), block);
- put(byHash, block.getBlockHash(), block);
- }
-
- private static <T> List<Block> get(Map<T, List<Block>> map, T key) {
- List<Block> blocks = map.get(key);
- return blocks != null ? blocks : Collections.EMPTY_LIST;
- }
-
- private static <T> void put(Map<T, List<Block>> map, T key, Block value) {
- List<Block> blocks = map.get(key);
- if (blocks == null) {
- blocks = Lists.newLinkedList();
- map.put(key, blocks);
- }
- blocks.add(value);
- }
-
-}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java
index fd86e55c699..71477b0c6eb 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/block/BlockTest.java
@@ -21,8 +21,9 @@ package org.sonar.duplications.block;
import org.junit.Test;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertThat;
public class BlockTest {
@@ -48,55 +49,4 @@ public class BlockTest {
assertThat(block.getEndUnit(), is(5));
}
- @Test
- public void fieldsTest() {
- String fileName = "someFile";
- int statementIndex = 4;
- ByteArray hash = new ByteArray(12345);
- Block tuple = new Block(fileName, hash, statementIndex, 0, 10);
- assertThat(tuple.getResourceId(), equalTo(fileName));
- assertThat(tuple.getIndexInFile(), equalTo(statementIndex));
- assertEquals(tuple.getBlockHash(), hash);
- }
-
- @Test
- public void tupleEqualsTest() {
- Block tuple1 = new Block("somefile", new ByteArray(123), 1, 1, 10);
- Block tuple2 = new Block("somefile", new ByteArray(123), 1, 1, 10);
- Block tupleArr = new Block("somefile", new ByteArray(333), 1, 1, 10);
- Block tupleIndex = new Block("somefile", new ByteArray(123), 2, 1, 10);
- Block tupleName = new Block("other", new ByteArray(123), 1, 1, 10);
-
- assertTrue(tuple1.equals(tuple2));
- assertThat(tuple1.toString(), is(tuple2.toString()));
-
- assertFalse(tuple1.equals(tupleArr));
- assertThat(tuple1.toString(), not(equalTo(tupleArr.toString())));
-
- assertFalse(tuple1.equals(tupleIndex));
- assertThat(tuple1.toString(), not(equalTo(tupleIndex.toString())));
-
- assertFalse(tuple1.equals(tupleName));
- assertThat(tuple1.toString(), not(equalTo(tupleName.toString())));
- }
-
- @Test
- public void hashCodeTest() {
- String[] files = {"file1", "file2"};
- int[] unitIndexes = {1, 2};
- ByteArray[] arrays = {new ByteArray(123), new ByteArray(321)};
-
- // fileName is in hashCode()
- int defaultTupleHashCode = new Block(files[0], arrays[0], unitIndexes[0], 1, 10).hashCode();
- int fileNameTupleHashCode = new Block(files[1], arrays[0], unitIndexes[0], 1, 10).hashCode();
- assertThat(defaultTupleHashCode, not(equalTo(fileNameTupleHashCode)));
-
- // statementIndex is in hashCode()
- int indexTupleHashCode = new Block(files[0], arrays[0], unitIndexes[1], 1, 10).hashCode();
- assertThat(defaultTupleHashCode, not(equalTo(indexTupleHashCode)));
-
- // sequenceHash is in hashCode()
- int sequenceHashTupleHashCode = new Block(files[0], arrays[1], unitIndexes[0], 1, 10).hashCode();
- assertThat(defaultTupleHashCode, not(equalTo(sequenceHashTupleHashCode)));
- }
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
index 3ce2f6a70f9..7a216b12c95 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/detector/DetectorTestCase.java
@@ -19,18 +19,7 @@
*/
package org.sonar.duplications.detector;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
-
-import java.util.*;
-
+import com.google.common.collect.Lists;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.duplications.block.Block;
@@ -41,7 +30,13 @@ import org.sonar.duplications.index.ClonePart;
import org.sonar.duplications.index.MemoryCloneIndex;
import org.sonar.duplications.junit.TestNamePrinter;
-import com.google.common.collect.Lists;
+import java.util.*;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.*;
+import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
public abstract class DetectorTestCase {
@@ -55,7 +50,12 @@ public abstract class DetectorTestCase {
* so we can simply use index and hash.
*/
protected static Block newBlock(String resourceId, ByteArray hash, int index) {
- return new Block(resourceId, hash, index, index, index + LINES_PER_BLOCK);
+ return Block.builder()
+ .setResourceId(resourceId)
+ .setBlockHash(hash)
+ .setIndexInFile(index)
+ .setLines(index, index + LINES_PER_BLOCK)
+ .build();
}
protected static ClonePart newClonePart(String resourceId, int unitStart, int cloneUnitLength) {
@@ -390,10 +390,13 @@ public abstract class DetectorTestCase {
@Test
public void same_lines_but_different_indexes() {
CloneIndex cloneIndex = createIndex();
+ Block.Builder block = Block.builder()
+ .setResourceId("a")
+ .setLines(0, 1);
List<Block> fileBlocks = Arrays.asList(
- new Block("a", new ByteArray("1".getBytes()), 0, 0, 1),
- new Block("a", new ByteArray("2".getBytes()), 1, 0, 1),
- new Block("a", new ByteArray("1".getBytes()), 2, 0, 1));
+ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(),
+ block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(),
+ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build());
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
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 536456c7a2d..e2476d41146 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,19 +19,23 @@
*/
package org.sonar.duplications.detector.original;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
import org.junit.Test;
import org.sonar.duplications.block.Block;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
public class BlocksGroupTest {
/**
* {@link BlocksGroup} uses only resourceId and index from block, thus we can simplify testing.
*/
private static Block newBlock(String resourceId, int indexInFile) {
- return new Block(resourceId, null, indexInFile, indexInFile, indexInFile);
+ return Block.builder()
+ .setResourceId(resourceId)
+ .setIndexInFile(indexInFile)
+ .setLines(indexInFile, indexInFile)
+ .build();
}
public static BlocksGroup newBlocksGroup(Block... blocks) {
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java
deleted file mode 100644
index a2996cf5da7..00000000000
--- a/sonar-duplications/src/test/java/org/sonar/duplications/index/MemoryCloneIndexTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.duplications.index;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.duplications.block.Block;
-import org.sonar.duplications.block.ByteArray;
-
-public class MemoryCloneIndexTest {
-
- private CloneIndex cloneIndex;
-
- @Before
- public void initialize() {
- cloneIndex = new MemoryCloneIndex();
- }
-
- @Test
- public void byFileName() {
- Block tuple1 = new Block("a", new ByteArray(0), 0, 0, 10);
- Block tuple2 = new Block("a", new ByteArray(0), 1, 10, 20);
-
- assertThat(cloneIndex.getByResourceId("a").size(), is(0));
-
- cloneIndex.insert(tuple1);
- assertThat(cloneIndex.getByResourceId("a").size(), is(1));
-
- cloneIndex.insert(tuple2);
- assertThat(cloneIndex.getByResourceId("a").size(), is(2));
- }
-
- @Test
- public void bySequenceHash() {
- Block tuple1 = new Block("a", new ByteArray(0), 0, 0, 5);
- Block tuple2 = new Block("a", new ByteArray(0), 1, 1, 6);
-
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(0));
-
- cloneIndex.insert(tuple1);
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(1));
-
- cloneIndex.insert(tuple2);
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(2));
- }
-
- @Test
- public void insertSame() {
- Block tuple = new Block("a", new ByteArray(0), 0, 0, 5);
- Block tupleSame = new Block("a", new ByteArray(0), 0, 0, 5);
-
- assertThat(cloneIndex.getByResourceId("a").size(), is(0));
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(0));
-
- cloneIndex.insert(tuple);
- assertThat(cloneIndex.getByResourceId("a").size(), is(1));
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(1));
-
- cloneIndex.insert(tupleSame);
- assertThat(cloneIndex.getByResourceId("a").size(), is(1));
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(0)).size(), is(1));
- }
-
- @Test
- public void testSorted() {
- for (int i = 0; i < 10; i++) {
- cloneIndex.insert(new Block("a", new ByteArray(1), 10 - i, i, i + 5));
- }
- assertThat(cloneIndex.getByResourceId("a").size(), is(10));
- assertThat(cloneIndex.getBySequenceHash(new ByteArray(1)).size(), is(10));
-
- Collection<Block> set = cloneIndex.getByResourceId("a");
- int prevStatementIndex = 0;
- for (Block tuple : set) {
- assertTrue(tuple.getIndexInFile() > prevStatementIndex);
- prevStatementIndex = tuple.getIndexInFile();
- }
- }
-}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java
index c47a2be3cfe..e99c3b42b4a 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/index/PackedMemoryCloneIndexTest.java
@@ -19,17 +19,17 @@
*/
package org.sonar.duplications.index;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertThat;
-
-import java.util.Collection;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
+import java.util.Collection;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
public class PackedMemoryCloneIndexTest {
private PackedMemoryCloneIndex index;
@@ -110,7 +110,12 @@ public class PackedMemoryCloneIndexTest {
}
private static Block newBlock(String resourceId, long hash) {
- return new Block(resourceId, new ByteArray(hash), 1, 1, 1);
+ return Block.builder()
+ .setResourceId(resourceId)
+ .setBlockHash(new ByteArray(hash))
+ .setIndexInFile(1)
+ .setLines(1, 2)
+ .build();
}
}