aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-duplications/src/main/java')
-rw-r--r--sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java9
-rw-r--r--sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java16
-rw-r--r--sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java5
-rw-r--r--sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java5
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java38
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/original/OriginalCloneDetectionAlgorithm.java17
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java4
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java16
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java4
9 files changed, 59 insertions, 55 deletions
diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java
index 06f0d48e801..8291e574d1e 100644
--- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java
+++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java
@@ -28,6 +28,11 @@ import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;
+/**
+ * <p>Not intended to be instantiated by clients.</p>
+ *
+ * @since 2.2
+ */
public class SourceCode {
public static final String EOL = System.getProperty("line.separator", "\n");
@@ -150,6 +155,10 @@ public class SourceCode {
return sb.toString();
}
+ /**
+ * Within Sonar Ecosystem - absolute path to file containing code,
+ * whereas in fact existence of such file not guaranteed - see {@link StringCodeLoader}.
+ */
public String getFileName() {
return cl.getFileName();
}
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 9878841cd8e..a615af964d3 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
@@ -28,11 +28,19 @@ import com.google.common.annotations.Beta;
import java.util.HashMap;
import java.util.Map;
+/**
+ * @since 2.2
+ */
public class TokenEntry implements Comparable<TokenEntry> {
private final static Map<String, Integer> TOKENS = new HashMap<String, Integer>();
private static int tokenCount = 0;
+ /**
+ * Shared instance of end-of-file token.
+ *
+ * <p>Not intended to be used by clients - {@link #getEOF()} should be used instead.</p>
+ */
public static final TokenEntry EOF = new TokenEntry();
private String tokenSrcID;
@@ -49,6 +57,11 @@ public class TokenEntry implements Comparable<TokenEntry> {
this.value = "";
}
+ /**
+ * @param image string representation of token
+ * @param tokenSrcID within Sonar Ecosystem - absolute path to file, otherwise current implementation of sonar-cpd-plugin will not work
+ * @param beginLine number of line
+ */
public TokenEntry(String image, String tokenSrcID, int beginLine) {
Integer i = TOKENS.get(image);
if (i == null) {
@@ -72,6 +85,9 @@ public class TokenEntry implements Comparable<TokenEntry> {
return value;
}
+ /**
+ * End-of-file token.
+ */
public static TokenEntry getEOF() {
tokenCount++;
return EOF;
diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
index 6df5eb70200..fb09a270257 100644
--- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
+++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java
@@ -25,6 +25,11 @@ package net.sourceforge.pmd.cpd;
import java.io.IOException;
+/**
+ * @since 2.2
+ */
public interface Tokenizer {
+
void tokenize(SourceCode tokens, Tokens tokenEntries) throws IOException;
+
}
diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java
index 09d33d14c38..1f63af26923 100644
--- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java
+++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java
@@ -29,6 +29,11 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+/**
+ * <p>Not intended to be instantiated by clients.</p>
+ *
+ * @since 2.2
+ */
public class Tokens {
private List<TokenEntry> tokens = new ArrayList<TokenEntry>();
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 fb98dd10732..1ccc79194ef 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
@@ -31,20 +31,20 @@ public final class Block implements CodeFragment {
private final String resourceId;
private final ByteArray blockHash;
private final int indexInFile;
- private final int firstLineNumber;
- private final int lastLineNumber;
+ private final int startLine;
+ private final int endLine;
/**
* Cache for hash code.
*/
private int hash;
- public Block(String resourceId, ByteArray blockHash, int indexInFile, int firstLineNumber, int lastLineNumber) {
+ public Block(String resourceId, ByteArray blockHash, int indexInFile, int startLine, int endLine) {
this.resourceId = resourceId;
this.blockHash = blockHash;
this.indexInFile = indexInFile;
- this.firstLineNumber = firstLineNumber;
- this.lastLineNumber = lastLineNumber;
+ this.startLine = startLine;
+ this.endLine = endLine;
}
public Block(int indexInFile, int firstLineNumber, int lastLineNumber, String resourceId, String hash) {
@@ -108,26 +108,12 @@ public final class Block implements CodeFragment {
this.endUnit = endUnit;
}
- /**
- * @deprecated in 2.14, use {@link #getStartLine()} instead
- */
- public int getFirstLineNumber() {
- return firstLineNumber;
- }
-
- /**
- * @deprecated in 2.14, use {@link #getEndLine()} instead
- */
- public int getLastLineNumber() {
- return lastLineNumber;
- }
-
public int getStartLine() {
- return firstLineNumber;
+ return startLine;
}
public int getEndLine() {
- return lastLineNumber;
+ return endLine;
}
@Override
@@ -139,8 +125,8 @@ public final class Block implements CodeFragment {
return resourceId.equals(other.resourceId)
&& blockHash.equals(other.blockHash)
&& indexInFile == other.indexInFile
- && firstLineNumber == other.firstLineNumber
- && lastLineNumber == other.lastLineNumber;
+ && startLine == other.startLine
+ && endLine == other.endLine;
}
@Override
@@ -150,8 +136,8 @@ public final class Block implements CodeFragment {
h = resourceId.hashCode();
h = 31 * h + blockHash.hashCode();
h = 31 * h + indexInFile;
- h = 31 * h + firstLineNumber;
- h = 31 * h + lastLineNumber;
+ h = 31 * h + startLine;
+ h = 31 * h + endLine;
hash = h;
}
return h;
@@ -159,7 +145,7 @@ public final class Block implements CodeFragment {
@Override
public String toString() {
- return "'" + resourceId + "'[" + indexInFile + "|" + firstLineNumber + "-" + lastLineNumber + "]:" + blockHash;
+ return "'" + resourceId + "'[" + indexInFile + "|" + startLine + "-" + endLine + "]:" + blockHash;
}
}
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 183d87b1ef7..bef9f4e80a4 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
@@ -19,19 +19,18 @@
*/
package org.sonar.duplications.detector.original;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
import org.sonar.duplications.index.CloneGroup;
import org.sonar.duplications.index.CloneIndex;
import org.sonar.duplications.index.ClonePart;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
/**
* Implementation of algorithm described in paper
@@ -210,8 +209,8 @@ public final class OriginalCloneDetectionAlgorithm {
Block lastBlock = pair[1];
ClonePart part = new ClonePart(firstBlock.getResourceId(),
firstBlock.getIndexInFile(),
- firstBlock.getFirstLineNumber(),
- lastBlock.getLastLineNumber());
+ firstBlock.getStartLine(),
+ lastBlock.getEndLine());
if (originResourceId.equals(part.getResourceId())) {
if (origin == null) {
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
index 1b9f5f8b164..6c05737240b 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/detector/suffixtree/DuplicationsCollector.java
@@ -89,8 +89,8 @@ public class DuplicationsCollector extends Search.Collector {
ClonePart part = new ClonePart(
firstBlock.getResourceId(),
firstBlock.getIndexInFile(),
- firstBlock.getFirstLineNumber(),
- lastBlock.getLastLineNumber());
+ firstBlock.getStartLine(),
+ lastBlock.getEndLine());
// TODO Godin: maybe use FastStringComparator here ?
if (originResourceId.equals(part.getResourceId())) { // part from origin
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java
index 36648b19d25..2fadac7621e 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java
@@ -48,22 +48,6 @@ public class ClonePart implements CodeFragment {
return startUnit;
}
- /**
- * @deprecated in 2.14, use {@link #getStartLine()} instead
- */
- @Deprecated
- public int getLineStart() {
- return startLine;
- }
-
- /**
- * @deprecated in 2.14, use {@link #getEndLine()} instead
- */
- @Deprecated
- public int getLineEnd() {
- return endLine;
- }
-
public int getStartLine() {
return startLine;
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java
index cb721a0cc78..a2d66e2f0b3 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/PackedMemoryCloneIndex.java
@@ -184,8 +184,8 @@ public class PackedMemoryCloneIndex extends AbstractCloneIndex {
blockData[offset++] = hash[i];
}
blockData[offset++] = block.getIndexInFile();
- blockData[offset++] = block.getFirstLineNumber();
- blockData[offset++] = block.getLastLineNumber();
+ blockData[offset++] = block.getStartLine();
+ blockData[offset++] = block.getEndLine();
blockData[offset++] = block.getStartUnit();
blockData[offset] = block.getEndUnit();