Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 4, 2016
2 parents 8410aff + 4adbdd6 commit 6589ee4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -114,23 +116,25 @@ public void visitToken(final DetailAST ast) {
*/
private void matchTagFormat(final String[] lines, final int start,
final int end, final String tag) {
final int line = this.findTagLineNum(lines, start, end, tag);
if (line == -1) {
final List<Integer> found = this.findTagLineNum(lines, start, end, tag);
if (found.isEmpty()) {
this.log(
start + 1,
"Missing ''@{0}'' tag in class/interface comment",
tag
);
return;
}
final String text = this.getTagText(lines[line]);
if (!this.tags.get(tag).matcher(text).matches()) {
this.log(
line + 1,
"Tag text ''{0}'' does not match the pattern ''{1}''",
text,
this.tags.get(tag).toString()
);
for (final Integer item : found) {
final String text = this.getTagText(lines[item]);
if (!this.tags.get(tag).matcher(text).matches()) {
this.log(
item + 1,
"Tag text ''{0}'' does not match the pattern ''{1}''",
text,
this.tags.get(tag).toString()
);
}
}
}

Expand All @@ -154,10 +158,10 @@ private String getTagText(final String line) {
* @return Line number with found tag or -1 otherwise.
* @checkstyle ParameterNumber (3 lines)
*/
private int findTagLineNum(final String[] lines, final int start,
private List<Integer> findTagLineNum(final String[] lines, final int start,
final int end, final String tag) {
final String prefix = String.format(" * @%s ", tag);
int found = -1;
final List<Integer> found = new ArrayList<Integer>(1);
for (int pos = start; pos <= end; pos += 1) {
final String line = lines[pos];
if (line.contains(String.format("@%s ", tag))) {
Expand All @@ -168,11 +172,9 @@ private int findTagLineNum(final String[] lines, final int start,
tag,
prefix
);
found = -1;
break;
}
found = pos;
break;
found.add(pos);
}
}
return found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,22 @@ public void main() {
* @author John Smith - incorrect format of author
* @version 1.1 - incorrect format
*/
public final class Foo {
public final class InvalidAuthor {
}

/**
* @author First Author (first@author.com)
* @author second author has incorrect format
* @author Third Author (third@author.com)
* @version $Id$
*/
public final class TwoValidAndOneInvalidAuthor {
}

/**
* @author first author has incorrect format
* @author second author has incorrect format
* @version $Id$
*/
public final class TwoInvalidAuthors {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/**
* @author Yegor Bugayenko (yegor@tpc2.com)
* @author Some Name (some@name.com)
* @version $Id$
*/
public final class Invalid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
6:Missing '@version' tag in class/interface comment
15:Tag text 'John Smith - incorrect format of author' does not match the pattern '^([A-Z](\.|[a-z]+) )+\([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\)$'
16:Tag text '1.1 - incorrect format' does not match the pattern '^\$Id.*\$$'
23:Tag text 'second author has incorrect format' does not match the pattern '^([A-Z](\.|[a-z]+) )+\([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\)$'
31:Tag text 'first author has incorrect format' does not match the pattern '^([A-Z](\.|[a-z]+) )+\([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\)$'
32:Tag text 'second author has incorrect format' does not match the pattern '^([A-Z](\.|[a-z]+) )+\([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\)$'

0 comments on commit 6589ee4

Please sign in to comment.