KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > doctorj > TypeDocAnalyzer


1 package org.incava.doctorj;
2
3 import java.util.List JavaDoc;
4 import java.util.Map JavaDoc;
5 import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
6 import net.sourceforge.pmd.ast.SimpleNode;
7 import net.sourceforge.pmd.ast.Token;
8 import org.incava.analysis.Report;
9 import org.incava.java.ClassUtil;
10 import org.incava.java.SimpleNodeUtil;
11 import org.incava.javadoc.*;
12
13
14 /**
15  * Analyzes Javadoc and code for a type, which is a class (concrete or abstract)
16  * or an interface.
17  */

18 public abstract class TypeDocAnalyzer extends ItemDocAnalyzer
19 {
20     /**
21      * The message for an author without a name.
22      */

23     public final static String JavaDoc MSG_AUTHOR_WITHOUT_NAME = "@author without name text";
24
25     /**
26      * The message for a version without associated text.
27      */

28     public final static String JavaDoc MSG_VERSION_WITHOUT_TEXT = "@version without text";
29
30     /**
31      * The message for a serial field without a description.
32      */

33     public final static String JavaDoc MSG_SERIAL_WITHOUT_TEXT = "@serial without field description";
34
35     /**
36      * The node to which this type applies.
37      */

38     private ASTClassOrInterfaceDeclaration _decl;
39     
40     /**
41      * Creates an analyzer, but does not yet run.
42      */

43     public TypeDocAnalyzer(Report r, ASTClassOrInterfaceDeclaration decl)
44     {
45         super(r, decl);
46         
47         _decl = decl;
48     }
49
50     /**
51      * Checks the Javadoc against that expected by a type.
52      */

53     protected void checkJavadoc(JavadocNode javadoc)
54     {
55         super.checkJavadoc(javadoc);
56
57         if (javadoc != null && isCheckable(getEnclosingNode(), CHKLVL_TAG_CONTENT)) {
58             JavadocTaggedNode[] taggedComments = javadoc.getTaggedComments();
59             for (int ti = 0; ti < taggedComments.length; ++ti) {
60                 JavadocTaggedNode jtn = taggedComments[ti];
61                 JavadocTag tag = jtn.getTag();
62                 
63                 if (tag.text.equals(JavadocTags.AUTHOR)) {
64                     checkForTagDescription(jtn, MSG_AUTHOR_WITHOUT_NAME);
65                 }
66                 else if (tag.text.equals(JavadocTags.VERSION)) {
67                     checkForTagDescription(jtn, MSG_VERSION_WITHOUT_TEXT);
68                 }
69                 else if (tag.text.equals(JavadocTags.SERIAL)) {
70                     checkForTagDescription(jtn, MSG_SERIAL_WITHOUT_TEXT);
71                 }
72             }
73         }
74     }
75
76     /**
77      * Adds a violation, for something that is not documented.
78      */

79     protected void addUndocumentedViolation(String JavaDoc desc)
80     {
81         Token nameTk = ClassUtil.getName(_decl);
82         addViolation(desc, nameTk);
83     }
84
85     protected SimpleNode getEnclosingNode()
86     {
87         return SimpleNodeUtil.getParent(_decl);
88     }
89
90 }
91
Popular Tags