Permalink
Browse files

Issue #3908: SummaryJavadoc need special processing of inheritDoc tag

  • Loading branch information...
sagarshah94 committed Mar 17, 2017
1 parent f26c614 commit 0206db22c55dc674c030611805b6100a77960cec
@@ -77,10 +77,16 @@
* This regexp is used to convert multiline javadoc to single line without stars.
*/
private static final Pattern JAVADOC_MULTILINE_TO_SINGLELINE_PATTERN =
Pattern.compile("\n[ ]+(\\*)|^[ ]+(\\*)");
Pattern.compile("\n[ ]+(\\*)|^[ ]+(\\*)");
/**
* This regexp is used to find occurence of first character of asteric.
*/
private static final Pattern FIRST_CHARACTER_ASTERIC_PATTERN =
Pattern.compile("^\\*");
/** Period literal. */
private static final String PERIOD = ".";
/** Inherit doc literal. */
private static final String INHERIT_DOC_LITERAL = "{@inheritDoc}";
/**
* Regular expression for forbidden summary fragments.
@@ -135,7 +141,10 @@ public void visitJavadocToken(DetailNode ast) {
String firstSentence = getFirstSentence(ast);
final int endOfSentence = firstSentence.lastIndexOf(period);
if (endOfSentence == -1) {
if (!firstSentence.trim().startsWith("{@inheritDoc}")) {
if (!firstSentence.trim().startsWith(INHERIT_DOC_LITERAL)
&& !FIRST_CHARACTER_ASTERIC_PATTERN.matcher(firstSentence.trim())
.replaceFirst("").trim().startsWith(INHERIT_DOC_LITERAL)
&& !isValidInheritDocAfterRemovingAsteric(firstSentence)) {
log(ast.getLineNumber(), MSG_SUMMARY_FIRST_SENTENCE);
}
}
@@ -147,6 +156,33 @@ public void visitJavadocToken(DetailNode ast) {
}
}
/**
* Finds if inheritDoc is placed properly in java doc.
* @param firstSentence first sentence of java doc.
* @return true if inheritDoc is valid or fasle.
*/
private static boolean isValidInheritDocAfterRemovingAsteric(String firstSentence) {
boolean result = false;
final int begin = firstSentence.indexOf(INHERIT_DOC_LITERAL);
if (begin == -1) {
result = false;
}
else {
final StringBuilder innerContent = new StringBuilder();
final int end = firstSentence.indexOf("<EOF>");
for (int index = 0; index < end; index++) {
if (firstSentence.charAt(index) != '*' && firstSentence.charAt(index) != ' '
&& firstSentence.charAt(index) != '\n') {
innerContent.append(firstSentence.charAt(index));
}
}
if (innerContent.toString().trim().equals(INHERIT_DOC_LITERAL)) {
result = true;
}
}
return result;
}
/**
* Finds and returns first sentence.
* @param ast Javadoc root node.
@@ -76,6 +76,7 @@ public void testIncorrect() throws Exception {
"69: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
"83: " + getCheckMessage(MSG_SUMMARY_JAVADOC),
"103: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
"116: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
};
verify(checkConfig, getPath("InputIncorrectSummaryJavaDoc.java"), expected);
}
@@ -106,6 +107,7 @@ public void testDefaultConfiguration() throws Exception {
"37: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
"69: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
"103: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
"116: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
};
createChecker(checkConfig);
@@ -32,6 +32,22 @@ void foo6() {}
/** {@inheritDoc} */
void foo7() {}
/**
* {@inheritDoc} */
void foo8() {}
/**
* {@inheritDoc}
*/
void foo9() {}
/**
*
*
* {@inheritDoc}
*/
void foo10() {}
/**
* <a href="mailto:vlad@htmlbook.ru"/>
*/
@@ -112,5 +112,10 @@ void foo5() {}
* An especially short bit of Javadoc.
*/
void foo6() {}
/**
* mm{@inheritDoc}
*/
void foo7() {}
};
}

0 comments on commit 0206db2

Please sign in to comment.