View Javadoc

    1   package net.sourceforge.pmd.lang.java.ast;
    2
    3   import java.util.ArrayList;
    4   import java.util.Collection;
    5   import java.util.Map;
    6
    7   import net.sourceforge.pmd.lang.ast.AbstractNode;
    8   import net.sourceforge.pmd.lang.ast.Node;
    9   import net.sourceforge.pmd.lang.java.javadoc.JavadocTag;
    10
    11  public abstract class Comment extends AbstractNode {
    12
    13      protected Comment(Token t) {
    14      	super(-1, t.beginLine, t.endLine, t.beginColumn, t.endColumn);
    15
    16          setImage(t.image);
    17          if (t.image.startsWith("/**")) {
    18              findJavadocs(t.image);
    19          }
    20      }
    21
    22      public String toString() {
    23      	return getImage();
    24      }
    25
    26      private void findJavadocs(String commentText) {
    27
    28      	Collection<JavadocElement> kids = new ArrayList<JavadocElement>();
    29
    30      	Map<String, Integer> tags = CommentUtil.javadocTagsIn(commentText);
    31      	for (Map.Entry<String, Integer> entry : tags.entrySet()) {
    32      		JavadocTag tag = JavadocTag.tagFor(entry.getKey());
    33      		if (tag == null) continue;
    34      		kids.add(
    35      			new JavadocElement(
    36      				getBeginLine(), getBeginLine(),	// TODO valid?
    37      				entry.getValue() + 1, entry.getValue() + tag.label.length() + 1 ,tag
    38      				)
    39      			);
    40      	}
    41
    42      	children = kids.toArray(new Node[kids.size()]);
    43      }
    44
    45  }