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