Skip to content

Commit 742f4bc

Browse files
committedJan 27, 2019
For #1004: Enforce since tag in inner classes
1 parent 93f22f1 commit 742f4bc

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed
 

‎qulice-checkstyle/src/main/java/com/qulice/checkstyle/JavadocTagsCheck.java

+13-19
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@
6363
*
6464
* @see <a href="http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html">Keywords substitution in Subversion</a>
6565
* @since 0.3
66-
* @todo #743:30min Nested classes should have since tag. Implement check to
67-
* validate if nested classes javadoc have a valid since tag. After the
68-
* implementation add JavadocTagsCheck to checks.xml and ChecksTest (removed
69-
* because now the test fails).
7066
*/
7167
public final class JavadocTagsCheck extends AbstractCheck {
7268

@@ -111,21 +107,19 @@ public void init() {
111107

112108
@Override
113109
public void visitToken(final DetailAST ast) {
114-
if (ast.getParent() == null) {
115-
final String[] lines = this.getLines();
116-
final int start = ast.getLineNo();
117-
final int cstart = JavadocTagsCheck.findCommentStart(lines, start);
118-
final int cend = JavadocTagsCheck.findCommentEnd(lines, start);
119-
if (cend > cstart && cstart >= 0) {
120-
for (final String tag : this.prohibited) {
121-
this.findProhibited(lines, start, cstart, cend, tag);
122-
}
123-
for (final String tag : this.tags.keySet()) {
124-
this.matchTagFormat(lines, cstart, cend, tag);
125-
}
126-
} else {
127-
this.log(0, "Problem finding class/interface comment");
110+
final String[] lines = this.getLines();
111+
final int start = ast.getLineNo();
112+
final int cstart = JavadocTagsCheck.findCommentStart(lines, start);
113+
final int cend = JavadocTagsCheck.findCommentEnd(lines, start);
114+
if (cend > cstart && cstart >= 0) {
115+
for (final String tag : this.prohibited) {
116+
this.findProhibited(lines, start, cstart, cend, tag);
117+
}
118+
for (final String tag : this.tags.keySet()) {
119+
this.matchTagFormat(lines, cstart, cend, tag);
128120
}
121+
} else {
122+
this.log(0, "Problem finding class/interface comment");
129123
}
130124
}
131125

@@ -252,7 +246,7 @@ private List<Integer> findTagLineNum(final String[] lines, final int start,
252246
for (int pos = start; pos <= end; pos += 1) {
253247
final String line = lines[pos];
254248
if (line.contains(String.format("@%s ", tag))) {
255-
if (!line.startsWith(prefix)) {
249+
if (!line.trim().startsWith(prefix.trim())) {
256250
this.log(
257251
start + pos + 1,
258252
"Line with ''@{0}'' does not start with a ''{1}''",

‎qulice-checkstyle/src/main/resources/com/qulice/checkstyle/checks.xml

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
<module name="com.qulice.checkstyle.FinalSemicolonInTryWithResourcesCheck"/>
419419
<module name="com.qulice.checkstyle.JavadocEmptyLineCheck"/>
420420
<module name="com.qulice.checkstyle.DiamondOperatorCheck"/>
421+
<module name="com.qulice.checkstyle.JavadocTagsCheck"/>
421422
</module>
422423

423424
<!--

‎qulice-checkstyle/src/test/java/com/qulice/checkstyle/ChecksTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public final class ChecksTest {
7979
"NonStaticMethodCheck",
8080
"ConstantUsageCheck",
8181
"JavadocEmptyLineCheck",
82+
"JavadocTagsCheck",
8283
};
8384

8485
/**

‎qulice-checkstyle/src/test/resources/com/qulice/checkstyle/ValidAbbreviationAsWordInName.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final String UPPERCASE() {
2424

2525
/**
2626
* ValidInnerHtml example class having the abbreviation in camelcase.
27+
* @since 1.0
2728
*/
2829
public class ValidInnerHtml {
2930
}

‎qulice-checkstyle/src/test/resources/com/qulice/checkstyle/ValidAbbreviationAsWordInNameIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class ValidAbbreviationAsWordInNameIT {
1111
/**
1212
* Valid name on inner class, because the IT abbreviation is allowed.
13+
* @since 1.0
1314
*/
1415
class ValidInnerIT {
1516
}

‎qulice-checkstyle/src/test/resources/com/qulice/checkstyle/ValidDiamondsUsage.java

+2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public static void innerClassUsage() {
3535

3636
/**
3737
* Simple interface, used as wrapper.
38+
* @since 1.0
3839
*/
3940
interface SimpleInterface {
4041

4142
/**
4243
* Inner class with generic parameter.
4344
* @param <E> generic parameter
45+
* @since 1.0
4446
*/
4547
final class InnerClass<E> implements SimpleInterface {
4648

0 commit comments

Comments
 (0)
Please sign in to comment.