pmd: fix #1073 Hard coded violation messages CommentSize

This commit is contained in:
Andreas Dangel
2013-03-10 09:48:11 +01:00
parent a1b1e3f31c
commit adcbdc204f
4 changed files with 19 additions and 14 deletions

View File

@ -2,6 +2,7 @@
Fixed bug 1064: Exception running PrematureDeclaration Fixed bug 1064: Exception running PrematureDeclaration
Fixed bug 1068: CPD fails on broken symbolic links Fixed bug 1068: CPD fails on broken symbolic links
Fixed bug 1073: Hard coded violation messages CommentSize
Fixed bug 1074: rule priority doesn't work on group definitions Fixed bug 1074: rule priority doesn't work on group definitions

View File

@ -108,19 +108,19 @@ public class CommentContentRule extends AbstractCommentRule {
return foundWords; return foundWords;
} }
private static String errorMsgFor(List<String> badWords) { private String errorMsgFor(List<String> badWords) {
StringBuilder msg = new StringBuilder(this.getMessage()).append(": ");
if (badWords.size() == 1 ) { if (badWords.size() == 1 ) {
return "Invalid term: '" + badWords.get(0) + '\''; msg.append("Invalid term: '").append(badWords.get(0)).append('\'');
} } else {
msg.append("Invalid terms: '");
StringBuilder sb = new StringBuilder("Invalid terms: '"); msg.append(badWords.get(0));
sb.append(badWords.get(0));
for (int i=1; i<badWords.size(); i++) { for (int i=1; i<badWords.size(); i++) {
sb.append("', '").append(badWords.get(i)); msg.append("', '").append(badWords.get(i));
} }
sb.append('\''); msg.append('\'');
return sb.toString(); }
return msg.toString();
} }
@Override @Override

View File

@ -78,14 +78,18 @@ public class CommentSizeRule extends AbstractCommentRule {
for (Comment comment : cUnit.getComments()) { for (Comment comment : cUnit.getComments()) {
if (hasTooManyLines(comment)) { if (hasTooManyLines(comment)) {
addViolationWithMessage(data, cUnit, "Too many lines", comment.getBeginLine(), comment.getEndLine()); addViolationWithMessage(data, cUnit,
this.getMessage() + ": Too many lines",
comment.getBeginLine(), comment.getEndLine());
} }
List<Integer> lineNumbers = overLengthLineIndicesIn(comment); List<Integer> lineNumbers = overLengthLineIndicesIn(comment);
if (lineNumbers.isEmpty()) continue; if (lineNumbers.isEmpty()) continue;
for (Integer lineNum : lineNumbers) { for (Integer lineNum : lineNumbers) {
addViolationWithMessage(data, cUnit, "Line too long", lineNum, lineNum); addViolationWithMessage(data, cUnit,
this.getMessage() + ": Line too long",
lineNum, lineNum);
} }
} }

View File

@ -62,7 +62,7 @@ Determines whether the dimensions of non-header comments found are within the sp
<rule name="CommentContent" <rule name="CommentContent"
since="5.0" since="5.0"
message="Invalid words or phrases found." message="Invalid words or phrases found"
class="net.sourceforge.pmd.lang.java.rule.comments.CommentContentRule" class="net.sourceforge.pmd.lang.java.rule.comments.CommentContentRule"
externalInfoUrl="${pmd.website.baseurl}/rules/java/comments.html#CommentContent"> externalInfoUrl="${pmd.website.baseurl}/rules/java/comments.html#CommentContent">
<description> <description>