1 package org.incava.doctorj; 2 3 import java.util.Iterator ; 4 import java.util.List ; 5 import net.sourceforge.pmd.ast.*; 6 import org.incava.analysis.Report; 7 import org.incava.java.*; 8 import org.incava.javadoc.*; 9 10 11 14 public class MethodDocAnalyzer extends FunctionDocAnalyzer 15 { 16 public final static String MSG_RETURN_WITHOUT_DESCRIPTION = "@return without description."; 17 18 public final static String MSG_RETURN_FOR_VOID_METHOD = "@return for method returning void"; 19 20 public final static String MSG_RETURN_TYPE_USED = "@return refers to method return type"; 21 22 private ASTMethodDeclaration _method; 23 24 public MethodDocAnalyzer(Report r, ASTMethodDeclaration method) 25 { 26 super(r, method); 27 28 _method = method; 29 } 30 31 public String getItemType() 32 { 33 return "method"; 34 } 35 36 39 protected SimpleNode getEnclosingNode() 40 { 41 return SimpleNodeUtil.getParent(_method); 42 } 43 44 protected void checkJavadoc(JavadocNode javadoc) 45 { 46 tr.Ace.log("javadoc: " + javadoc); 47 48 super.checkJavadoc(javadoc); 49 50 if (javadoc != null) { 51 JavadocTaggedNode[] taggedComments = javadoc.getTaggedComments(); 52 for (int ti = 0; ti < taggedComments.length; ++ti) { 53 JavadocTaggedNode jtn = taggedComments[ti]; 54 JavadocTag tag = jtn.getTag(); 55 tr.Ace.log("checking tag: " + tag); 56 57 if (tag.text.equals(JavadocTags.RETURN)) { 58 ASTResultType resType = (ASTResultType)SimpleNodeUtil.findChild(_method, ASTResultType.class); 59 Token resTkn = resType.getFirstToken(); 60 61 if (resTkn.kind == JavaParserConstants.VOID) { 62 addViolation(MSG_RETURN_FOR_VOID_METHOD, tag.start, tag.end); 63 } 64 else { 65 JavadocElement tgt = jtn.getTarget(); 66 if (tgt == null) { 67 if (isCheckable(getEnclosingNode(), CHKLVL_TAG_CONTENT)) { 68 addViolation(MSG_RETURN_WITHOUT_DESCRIPTION, tag.start, tag.end); 69 } 70 } 71 else { 72 String text = tgt.text; 73 tr.Ace.log("text: '" + text + "'"); 74 if (text.equals(resTkn.image)) { 75 addViolation(MSG_RETURN_TYPE_USED, tgt.start, tgt.end); 76 } 77 } 78 } 79 } 80 } 81 } 82 } 83 84 87 protected ASTFormalParameters getParameterList() 88 { 89 return MethodUtil.getParameters(_method); 90 } 91 92 95 protected List getValidTags() 96 { 97 return JavadocTags.getValidMethodTags(); 98 } 99 100 104 protected void addUndocumentedViolation(String desc) 105 { 106 Token nameTk = MethodUtil.getName(_method); 107 addViolation(desc, nameTk); 108 } 109 110 } 111 | Popular Tags |