1 22 package org.aspectj.tools.ajdoc; 23 24 import com.sun.javadoc.Doc; 25 import com.sun.javadoc.ParamTag; 26 import com.sun.javadoc.SeeTag; 27 import com.sun.javadoc.SerialFieldTag; 28 import com.sun.javadoc.Tag; 29 import com.sun.javadoc.ThrowsTag; 30 31 import java.util.ArrayList ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Locale ; 35 36 public class Comment { 37 38 39 private String commentText; 40 41 42 private String rawCommentText; 43 44 45 private List tags; 46 47 48 private Doc doc; 49 50 51 private Locale loc; 52 53 54 private ErrPrinter err; 55 56 public Comment(Doc doc, String formalComment) { 57 this(doc, formalComment, ErrPrinter.instance); 58 } 59 60 public Comment(Doc doc, String formalComment, ErrPrinter err) { 61 this(doc, formalComment, err, Locale.US); 62 } 63 64 public Comment(Doc doc, String formalComment, ErrPrinter err, Locale loc) { 65 this.rawCommentText = Util.rawCommentText(formalComment); 66 this.commentText = Util.commentText(rawCommentText); 67 this.doc = doc; 68 this.err = err; 69 this.loc = loc; 70 } 71 72 77 public String commentText() { 78 return commentText; 79 } 80 81 86 public String getRawCommentText() { 87 return rawCommentText; 88 } 89 90 95 public void setCommentText(String commentText) { 96 this.commentText = commentText; 97 } 98 99 104 public String rawCommentText() { 105 return rawCommentText; 106 } 107 108 113 public void setRawCommentText(String rawCommentText) { 114 this.rawCommentText = rawCommentText; 115 } 116 117 122 public List getTags() { 123 if (tags == null) { 124 tags = findTags(); 125 } 126 return tags; 127 } 128 129 134 public void setDoc(Doc doc) { 135 this.doc = doc; 136 } 137 138 143 public Doc doc() { 144 return doc; 145 } 146 147 152 public void setLocale(Locale loc) { 153 this.loc = loc; 154 } 155 156 161 public Locale locale() { 162 return loc; 163 } 164 165 170 public void setErr(ErrPrinter err) { 171 this.err = err; 172 } 173 174 179 public ErrPrinter err() { 180 return err; 181 } 182 183 190 public void init(Doc doc, Locale loc, ErrPrinter err) { 191 setDoc(doc); 192 setLocale(loc); 193 setErr(err); 194 } 195 196 201 public Tag[] inlineTags() { 202 return Util.inlineTags(doc(), 203 commentText(), 204 locale(), 205 err()); 206 } 207 208 215 public Tag[] tags(String type) { 216 type = type.startsWith("@") ? type : "@"+type; 217 List result = new ArrayList (); 218 Tag tag; 219 for (Iterator i = getTags().iterator(); i.hasNext();) { 220 if ((tag = (Tag)i.next()).kind().equals(type)) { 221 result.add(tag); 222 } 223 } 224 return (Tag[])result.toArray(new Tag[result.size()]); 225 } 226 227 234 public ParamTag[] paramTags() { 235 List result = new ArrayList (); 236 Tag tag; 237 for (Iterator i = getTags().iterator(); i.hasNext();) { 238 if ((tag = (Tag)i.next()) instanceof ParamTag) { 239 result.add((ParamTag)tag); 240 } 241 } 242 return (ParamTag[])result.toArray(new ParamTag[result.size()]); 243 } 244 245 251 public SeeTag[] seeTags() { 252 List result = new ArrayList (); 253 Tag tag; 254 for (Iterator i = getTags().iterator(); i.hasNext();) { 255 if ((tag = (Tag)i.next()) instanceof SeeTag) { 256 result.add((SeeTag)tag); 257 } 258 } 259 return (SeeTag[])result.toArray(new SeeTag[result.size()]); 260 } 261 262 268 public SerialFieldTag[] serialFieldTags() { 269 List result = new ArrayList (); 270 Tag tag; 271 for (Iterator i = getTags().iterator(); i.hasNext();) { 272 if ((tag = (Tag)i.next()) instanceof SerialFieldTag) { 273 result.add((SerialFieldTag)tag); 274 } 275 } 276 return (SerialFieldTag[])result.toArray 277 (new SerialFieldTag[result.size()]); 278 } 279 280 287 public ThrowsTag[] throwsTags() { 288 List result = new ArrayList (); 289 Tag tag; 290 for (Iterator i = getTags().iterator(); i.hasNext();) { 291 if ((tag = (Tag)i.next()) instanceof ThrowsTag) { 292 result.add((ThrowsTag)tag); 293 } 294 } 295 return (ThrowsTag[])result.toArray 296 (new ThrowsTag[result.size()]); 297 } 298 299 305 public Tag[] tags() { 306 return (Tag[])getTags().toArray 307 (new Tag[getTags().size()]); 308 } 309 310 317 public Tag[] firstSentenceTags() { 318 return Util.firstSentenceTags(doc(), 319 commentText(), 320 locale(), 321 err()); 322 } 323 324 330 private List findTags() { 331 return Util.findTags(doc(), 332 rawCommentText(), 333 locale(), 334 err()); 335 } 336 } 337 | Popular Tags |