allowedTypes = new HashSet<>();
+ allowedTypes.add(JavadocTokenTypes.TEXT);
+ allowedTypes.add(JavadocTokenTypes.JAVADOC_INLINE_TAG);
+ allowedTypes.add(JavadocTokenTypes.WS);
+ boolean flag = true;
+ final StringBuilder result = new StringBuilder();
+ for (DetailNode child : ast.getChildren()) {
+ if (allowedTypes.contains(child.getType())) {
+ result.append(child.getText());
+ }
+ else if (child.getType() == JavadocTokenTypes.HTML_ELEMENT) {
+ if (result.toString().trim().isEmpty()) {
+ log(ast.getLineNumber(), MSG_SUMMARY_JAVADOC_MISSING);
+ flag = false;
+ }
+ result.append(child.getText());
+ }
+ else if (child.getType() == JavadocTokenTypes.JAVADOC_TAG) {
+ if (result.toString().trim().isEmpty()) {
+ log(ast.getLineNumber(), MSG_SUMMARY_JAVADOC_MISSING);
+ }
+ flag = false;
+ }
+
+ if (!flag) {
+ break;
}
}
+ final String textSentence = result.toString().replace('*', ' ').trim();
+ if (flag && !textSentence.isEmpty()
+ && !period.isEmpty()
+ && !String.valueOf(textSentence.charAt(textSentence.length() - 1)).equals(period)
+ && !textSentence.equals(INHERIT_DOC)) {
+ log(ast.getLineNumber(), MSG_SUMMARY_FIRST_SENTENCE);
+ }
+
+ return flag;
}
+
/**
* Finds and returns first sentence.
* @param ast Javadoc root node.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages.properties
index 500995843bd..746debe946f 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages.properties
@@ -30,6 +30,7 @@ non.empty.atclause=At-clause should have a non-empty description.
tag.continuation.indent=Line continuation have incorrect indentation level, expected level should be {0}.
summary.javaDoc=Forbidden summary fragment.
+summary.javaDoc.missing=Summary javadoc is missing.
summary.first.sentence=First sentence of Javadoc is incomplete (period is missing) or not present.
at.clause.order=At-clauses have to appear in the order ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_de.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_de.properties
index 11f9b16cc4c..03d4a8dc6ab 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_de.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_de.properties
@@ -30,6 +30,7 @@ non.empty.atclause=@-Klausel sollte eine nicht-leere Beschreibung haben.
tag.continuation.indent=Forsetzung der Zeile hat falsche Einrückungstiefe (erwartet: {0}).
summary.javaDoc=Verbotener Ausdruck im ersten Javadoc-Satz.
+summary.javaDoc.missing=Zusammenfassung javadoc fehlt.
summary.first.sentence=Erster Javadoc-Satz ist unvollständig (Punkt fehlt) oder nicht vorhanden.
at.clause.order=@-Klauseln müssen in der folgenden Reihenfolge erscheinen: ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_es.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_es.properties
index 7ed59685c2a..5e6cbf7214d 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_es.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_es.properties
@@ -30,6 +30,7 @@ non.empty.atclause = Al cláusula debe tener una descripción que no esté vací
tag.continuation.indent = Línea continuación tiene nivel de sangría incorrecta, nivel esperado debería ser {0}
summary.javaDoc = Resumen fragmento Prohibida.
+summary.javaDoc.missing=Resumen javadoc falta.
summary.first.sentence = Primera frase del Javadoc es incompleta (período de falta) o no está presente.
at.clause.order = Al-cláusulas tienen que aparecer en el orden ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fi.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fi.properties
index 36eeeeb6a8b..2bfa7ee5f3b 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fi.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fi.properties
@@ -30,6 +30,7 @@ non.empty.atclause = At-lauseke tulisi olla ei-tyhjä kuvaus.
tag.continuation.indent = Jatkorivin on väärä sisennystason, odotettu taso olisi {0} .
summary.javaDoc = Kielletty yhteenveto fragmentti.
+summary.javaDoc.missing=Yhteenveto javadoc puuttuu.
summary.first.sentence = Ensimmäinen virke Javadoc on epätäydellinen (ajanjakso puuttuu) tai ole läsnä.
at.clause.order = At-lausekkeet tarvitse esiintyä järjestyksessä ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fr.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fr.properties
index 798b65c9a43..00eb3d00224 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fr.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_fr.properties
@@ -30,6 +30,7 @@ non.empty.atclause=La balise javadoc doit avoir une description non-vide.
tag.continuation.indent=La continuation de la ligne a un niveau d''indentation incorrect, le niveau attendu doit être {0}.
summary.javaDoc=Fragment de résumé interdit.
+summary.javaDoc.missing=Résumé javadoc est manquant.
summary.first.sentence=La première phrase de la javadoc est incomplète (le point est manquant) ou non présente.
at.clause.order=Les balises javadoc doivent apparaître dans l''ordre ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_ja.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_ja.properties
index ad33b1e5052..d4264a67b58 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_ja.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_ja.properties
@@ -30,6 +30,7 @@ non.empty.atclause = Javadoc タグには空でない説明文が必要です。
tag.continuation.indent = 行継続のインデントのレベルが間違っています。期待されるレベルは {0} です。
summary.javaDoc = 禁止された文言が概要に含まれています。
+summary.javaDoc.missing=要約javadocがありません。
summary.first.sentence = Javadoc の最初の文が不完全(ピリオドがない)か、または文がありません。
at.clause.order = Javadoc タグは ''{0}'' の順で並べてください。
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_pt.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_pt.properties
index 0a17a6821c1..79aa30fe371 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_pt.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_pt.properties
@@ -30,6 +30,7 @@ non.empty.atclause = Na cláusula deve ter uma descrição não-vazia.
tag.continuation.indent = Continuação de linha têm nível de recuo incorreto, nível esperado deve ser {0}
summary.javaDoc = Fragmento resumo Proibida.
+summary.javaDoc.missing=Sumário javadoc está ausente.
summary.first.sentence = Primeira frase do Javadoc está incompleta (período está faltando) ou não está presente.
at.clause.order = At-cláusulas têm de aparecer na ordem ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_tr.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_tr.properties
index 17021ad0039..e93674d93fd 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_tr.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_tr.properties
@@ -30,6 +30,7 @@ non.empty.atclause = At-fıkra boş olmayan bir tanım olması gerekir.
tag.continuation.indent = Çizgi devamı yanlış girinti düzeyine sahip, beklenen seviyede olmalıdır {0}
summary.javaDoc = Yasak özeti fragmanı.
+summary.javaDoc.missing=Özet javadoc eksik.
summary.first.sentence = Javadoc ilk cümlesi (dönem eksik) veya mevcut eksik.
at.clause.order = Cümlecikleri At-düzen 'görünmesi zorunda ''{0}''.
diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_zh.properties b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_zh.properties
index c7e36b4b08d..3b43fb0cc71 100644
--- a/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_zh.properties
+++ b/src/main/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/messages_zh.properties
@@ -30,6 +30,7 @@ non.empty.atclause=@标签应有非空说明。
tag.continuation.indent=Javadoc 缩进级别错误,应为 {0} 个缩进符。
summary.javaDoc=禁止出现的首行内容。
+summary.javaDoc.missing=缺少摘要javadoc。
summary.first.sentence=Javadoc 首句应以句号结尾。
at.clause.order=@标签应按以下顺序出现:''{0}''。
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheckTest.java
index 51f0e135972..3f2ec891c87 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/SummaryJavadocCheckTest.java
@@ -21,6 +21,7 @@
import static com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck.MSG_SUMMARY_FIRST_SENTENCE;
import static com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck.MSG_SUMMARY_JAVADOC;
+import static com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck.MSG_SUMMARY_JAVADOC_MISSING;
import static org.junit.Assert.assertArrayEquals;
import java.io.File;
@@ -69,13 +70,16 @@ public void testIncorrect() throws Exception {
checkConfig.addAttribute("forbiddenSummaryFragments",
"^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )");
final String[] expected = {
- "14: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ "14: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "32: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
"37: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
"47: " + getCheckMessage(MSG_SUMMARY_JAVADOC),
+ "53: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "58: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
"58: " + getCheckMessage(MSG_SUMMARY_JAVADOC),
- "69: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ "69: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
"83: " + getCheckMessage(MSG_SUMMARY_JAVADOC),
- "103: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ "103: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
};
verify(checkConfig, getPath("InputIncorrectSummaryJavaDoc.java"), expected);
}
@@ -102,13 +106,30 @@ public void testNoPeriod() throws Exception {
@Test
public void testDefaultConfiguration() throws Exception {
final String[] expected = {
- "14: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ "14: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "32: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
"37: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
- "69: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
- "103: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ "53: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "58: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "69: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "103: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
};
createChecker(checkConfig);
verify(checkConfig, getPath("InputIncorrectSummaryJavaDoc.java"), expected);
}
+
+ @Test
+ public void testPeriodAtEnd() throws Exception {
+ checkConfig.addAttribute("period", ".");
+ final String[] expected = {
+ "5: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ "10: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "17: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "24: " + getCheckMessage(MSG_SUMMARY_JAVADOC_MISSING),
+ "31: " + getCheckMessage(MSG_SUMMARY_FIRST_SENTENCE),
+ };
+
+ verify(checkConfig, getPath("InputPeriodAtEnd.java"), expected);
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputCorrectSummaryJavaDoc.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputCorrectSummaryJavaDoc.java
index 0c5a130e760..8c2c6b56236 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputCorrectSummaryJavaDoc.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputCorrectSummaryJavaDoc.java
@@ -16,10 +16,11 @@ class InputCorrectSummaryJavaDoc {
void foo3() {}
/**
+ * This is valid.
* @throws Exception if an error occurs.
*/
void foo4() throws Exception {}
-
+
/** An especially This method returns short bit of Javadoc. */
void foo5() {}
@@ -32,8 +33,10 @@ void foo6() {}
/** {@inheritDoc} */
void foo7() {}
- /**
- *
+ /**
+ * This is an example of
+ * valid java doc.
+ * .
*/
class InnerInputCorrectJavaDocParagraphCheck {
@@ -49,15 +52,16 @@ class InnerInputCorrectJavaDocParagraphCheck {
public static final byte NUL_2 = 0;
/**
- * Returns the customer ID. This method returns
+ * Returns the customer ID. This method returns.
*/
int getId() {return 666;}
-
+
/**
+ * This is valid.
* .
*/
void foo2() {}
-
+
/**
* As of JDK 1.1,
* replaced by {@link #setBounds(int,int,int,int)}. This method returns.
@@ -65,11 +69,12 @@ void foo2() {}
void foo3() {}
/**
+ * This is description.
* @throws Exception if an error occurs.
*/
void foo4() throws Exception {}
-
- /**
+
+ /**
* JAXB Provider Use Only: Provides partial default
* implementations for some of the javax.xml.bind interfaces.
*/
@@ -77,7 +82,7 @@ void foo5() {}
/**
* An especially short (int... A) bit of Javadoc. This
- * method returns
+ * method returns.
*/
void foo6() {}
}
@@ -108,10 +113,11 @@ void foo6() {}
void foo3() {}
/**
+ * This is valid.
* @throws Exception if an error occurs.
*/
void foo4() throws Exception {}
-
+
/** An especially short bit of Javadoc. */
void foo5() {}
@@ -129,15 +135,17 @@ void foo6() {}
* Some Javadoc. This method returns some javadoc. Some Javadoc.
*/
boolean emulated1() {return false;}
-
+
/**
+ * This is valid.
* @return Some Javadoc the customer ID.
*/
- int geId() {return 666;}
-
+ int geId() {return 666;}
+
/**
+ * This is valid.
* @return Sentence one. Sentence two.
*/
- String twoSentences() {return "Sentence one. Sentence two.";}
+ String twoSentences() {return "Sentence one. Sentence two.";}
};
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputIncorrectSummaryJavaDoc.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputIncorrectSummaryJavaDoc.java
index ffef6b00292..40436c8e283 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputIncorrectSummaryJavaDoc.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputIncorrectSummaryJavaDoc.java
@@ -5,17 +5,17 @@
* is a simple Javadoc. Some javadoc.
*/
class InputIncorrectSummaryJavaDoc {
-
+
/**
- * As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}
+ * As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}.
*/
void foo3() {}
-
+
/**
* @throws Exception if an error occurs
*/
void foo4() throws Exception {}
-
+
/** An especially short bit of Javadoc. */
void foo5() {}
@@ -29,8 +29,8 @@ void foo6() {}
*/
public static final byte NUL = 0;
- /**
- *
+ /**
+ *
*/
class InnerInputCorrectJavaDocParagraphCheck {
@@ -39,7 +39,7 @@ class InnerInputCorrectJavaDocParagraphCheck {
*/
public static final byte NUL = 0;
- /**
+ /**
* Some java@doc.
*/
public static final byte NUL_2 = 0;
@@ -49,7 +49,7 @@ class InnerInputCorrectJavaDocParagraphCheck {
* returns some javadoc. Some javadoc.
*/
boolean emulated() {return false;}
-
+
/**
*
*/
@@ -59,18 +59,18 @@ void foo2() {}
* @return the
* customer ID some javadoc.
*/
- int geId() {return 666;}
+ int geId() {return 666;}
/**
- * As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}
+ * As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}.
*/
void foo3() {}
-
+
/**
* @throws Exception if an error occurs
*/
void foo4() throws Exception {}
-
+
/** An especially short bit of Javadoc. */
void foo5() {}
@@ -94,17 +94,17 @@ void foo6() {}
* Some Javadoc.
*/
void emulated(String s) {}
-
+
/**
- * As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}
+ * As of JDK 1.1, replaced by {@link #setBounds(int,int,int,int)}.
*/
void foo3() {}
-
+
/**
* @throws Exception if an error occurs
*/
void foo4() throws Exception {}
-
+
/** An especially short bit of Javadoc. */
void foo5() {}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputPeriodAtEnd.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputPeriodAtEnd.java
new file mode 100644
index 00000000000..046e30b7d51
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/InputPeriodAtEnd.java
@@ -0,0 +1,50 @@
+package com.puppycrawl.tools.checkstyle.checks.javadoc;
+
+
+public class InputPeriodAtEnd {
+ /**
+ * JAXB 1.0 only default validation event handler
+ */
+ public static final byte NUL = 0;
+
+ /**
+ * @throws Exception if an error occurs.
+ */
+ public void foo1() throws Exception {
+
+ }
+
+ /**
+ * @return 1.
+ */
+ public int foo2(){
+ return 1;
+ }
+
+ /**
+ *
+ */
+ public void foo3() {
+
+ }
+
+ /**
+ * A {@code Foo. Foo}
+ */
+ public void foo(){
+
+ }
+ /**
+ * This is test
+ * Valid or invalid.
+ */
+ public void foo4(){
+
+ }
+ /**
+ * This is valid java doc.
+ */
+ public void foo5(){
+
+ }
+}
diff --git a/src/xdocs/config_javadoc.xml b/src/xdocs/config_javadoc.xml
index 26d536b4066..8ae8c8a42e8 100644
--- a/src/xdocs/config_javadoc.xml
+++ b/src/xdocs/config_javadoc.xml
@@ -1693,6 +1693,10 @@ public class TestClass {
summary.javaDoc
+
+
+ summary.javaDoc.missing
+
All messages can be customized if the default message doesn't suit you.