forked from phoedos/pmd
StringBuffer -> StringBuilder switchovers, refactoring
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7337 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -60,7 +60,7 @@ public class AvoidDuplicateLiteralsRule extends AbstractJavaRule {
|
||||
|
||||
public Set<String> parse(String s) {
|
||||
Set<String> result = new HashSet<String>();
|
||||
StringBuffer currentToken = new StringBuffer();
|
||||
StringBuilder currentToken = new StringBuilder();
|
||||
boolean inEscapeMode = false;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (inEscapeMode) {
|
||||
@ -74,7 +74,7 @@ public class AvoidDuplicateLiteralsRule extends AbstractJavaRule {
|
||||
}
|
||||
if (s.charAt(i) == delimiter) {
|
||||
result.add(currentToken.toString());
|
||||
currentToken = new StringBuffer();
|
||||
currentToken = new StringBuilder();
|
||||
} else {
|
||||
currentToken.append(s.charAt(i));
|
||||
}
|
||||
@ -128,21 +128,30 @@ public class AvoidDuplicateLiteralsRule extends AbstractJavaRule {
|
||||
|
||||
super.visit(node, data);
|
||||
|
||||
int threshold = getProperty(THRESHOLD_DESCRIPTOR);
|
||||
for (String key : literals.keySet()) {
|
||||
List<ASTLiteral> occurrences = literals.get(key);
|
||||
if (occurrences.size() >= threshold) {
|
||||
Object[] args = new Object[] { key, Integer.valueOf(occurrences.size()),
|
||||
Integer.valueOf(occurrences.get(0).getBeginLine()) };
|
||||
addViolation(data, occurrences.get(0), args);
|
||||
}
|
||||
}
|
||||
processResults(data);
|
||||
|
||||
minLength = 2 + getProperty(MINIMUM_LENGTH_DESCRIPTOR);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private void processResults(Object data) {
|
||||
|
||||
int threshold = getProperty(THRESHOLD_DESCRIPTOR);
|
||||
|
||||
for (Map.Entry<String, List<ASTLiteral>> entry : literals.entrySet()) {
|
||||
List<ASTLiteral> occurrences = entry.getValue();
|
||||
if (occurrences.size() >= threshold) {
|
||||
Object[] args = new Object[] {
|
||||
entry.getKey(),
|
||||
Integer.valueOf(occurrences.size()),
|
||||
Integer.valueOf(occurrences.get(0).getBeginLine())
|
||||
};
|
||||
addViolation(data, occurrences.get(0), args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTLiteral node, Object data) {
|
||||
if (!node.isStringLiteral()) {
|
||||
|
Reference in New Issue
Block a user