Thu, 18 Sep 2008 18:39:44 -0700
6744408: Extra ouput is appearing in stderr
Reviewed-by: bpatel
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javadoc; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | |
duke@1 | 30 | import java.io.InputStream; |
duke@1 | 31 | import java.io.IOException; |
duke@1 | 32 | import java.text.CollationKey; |
duke@1 | 33 | import com.sun.tools.javac.util.Position; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * abstract base class of all Doc classes. Doc item's are representations |
duke@1 | 37 | * of java language constructs (class, package, method,...) which have |
duke@1 | 38 | * comments and have been processed by this run of javadoc. All Doc items |
duke@1 | 39 | * are unique, that is, they are == comparable. |
duke@1 | 40 | * |
duke@1 | 41 | * @since 1.2 |
duke@1 | 42 | * @author Robert Field |
duke@1 | 43 | * @author Atul M Dambalkar |
duke@1 | 44 | * @author Neal Gafter (rewrite) |
duke@1 | 45 | */ |
duke@1 | 46 | abstract class DocImpl implements Doc, Comparable<Object> { |
duke@1 | 47 | |
duke@1 | 48 | /** |
duke@1 | 49 | * Doc environment |
duke@1 | 50 | */ |
duke@1 | 51 | protected final DocEnv env; //### Rename this everywhere to 'docenv' ? |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * The complex comment object, lazily initialized. |
duke@1 | 55 | */ |
duke@1 | 56 | private Comment comment; |
duke@1 | 57 | |
duke@1 | 58 | /** |
duke@1 | 59 | * The cached sort key, to take care of Natural Language Text sorting. |
duke@1 | 60 | */ |
duke@1 | 61 | private CollationKey collationkey = null; |
duke@1 | 62 | |
duke@1 | 63 | /** |
duke@1 | 64 | * Raw documentation string. |
duke@1 | 65 | */ |
duke@1 | 66 | protected String documentation; // Accessed in PackageDocImpl, RootDocImpl |
duke@1 | 67 | |
duke@1 | 68 | /** |
duke@1 | 69 | * Cached first sentence. |
duke@1 | 70 | */ |
duke@1 | 71 | private Tag[] firstSentence; |
duke@1 | 72 | |
duke@1 | 73 | /** |
duke@1 | 74 | * Cached inline tags. |
duke@1 | 75 | */ |
duke@1 | 76 | private Tag[] inlineTags; |
duke@1 | 77 | |
duke@1 | 78 | /** |
duke@1 | 79 | * Constructor. |
duke@1 | 80 | */ |
duke@1 | 81 | DocImpl(DocEnv env, String documentation) { |
duke@1 | 82 | this.documentation = documentation; |
duke@1 | 83 | this.env = env; |
duke@1 | 84 | } |
duke@1 | 85 | |
duke@1 | 86 | /** |
duke@1 | 87 | * So subclasses have the option to do lazy initialization of |
duke@1 | 88 | * "documentation" string. |
duke@1 | 89 | */ |
duke@1 | 90 | String documentation() { |
duke@1 | 91 | if (documentation == null) documentation = ""; |
duke@1 | 92 | return documentation; |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | /** |
duke@1 | 96 | * For lazy initialization of comment. |
duke@1 | 97 | */ |
duke@1 | 98 | Comment comment() { |
duke@1 | 99 | if (comment == null) { |
duke@1 | 100 | comment = new Comment(this, documentation()); |
duke@1 | 101 | } |
duke@1 | 102 | return comment; |
duke@1 | 103 | } |
duke@1 | 104 | |
duke@1 | 105 | /** |
duke@1 | 106 | * Return the text of the comment for this doc item. |
duke@1 | 107 | * TagImpls have been removed. |
duke@1 | 108 | */ |
duke@1 | 109 | public String commentText() { |
duke@1 | 110 | return comment().commentText(); |
duke@1 | 111 | } |
duke@1 | 112 | |
duke@1 | 113 | /** |
duke@1 | 114 | * Return all tags in this Doc item. |
duke@1 | 115 | * |
duke@1 | 116 | * @return an array of TagImpl containing all tags on this Doc item. |
duke@1 | 117 | */ |
duke@1 | 118 | public Tag[] tags() { |
duke@1 | 119 | return comment().tags(); |
duke@1 | 120 | } |
duke@1 | 121 | |
duke@1 | 122 | /** |
duke@1 | 123 | * Return tags of the specified kind in this Doc item. |
duke@1 | 124 | * |
duke@1 | 125 | * @param tagname name of the tag kind to search for. |
duke@1 | 126 | * @return an array of TagImpl containing all tags whose 'kind()' |
duke@1 | 127 | * matches 'tagname'. |
duke@1 | 128 | */ |
duke@1 | 129 | public Tag[] tags(String tagname) { |
duke@1 | 130 | return comment().tags(tagname); |
duke@1 | 131 | } |
duke@1 | 132 | |
duke@1 | 133 | /** |
duke@1 | 134 | * Return the see also tags in this Doc item. |
duke@1 | 135 | * |
duke@1 | 136 | * @return an array of SeeTag containing all @see tags. |
duke@1 | 137 | */ |
duke@1 | 138 | public SeeTag[] seeTags() { |
duke@1 | 139 | return comment().seeTags(); |
duke@1 | 140 | } |
duke@1 | 141 | |
duke@1 | 142 | public Tag[] inlineTags() { |
duke@1 | 143 | if (inlineTags == null) { |
duke@1 | 144 | inlineTags = Comment.getInlineTags(this, commentText()); |
duke@1 | 145 | } |
duke@1 | 146 | return inlineTags; |
duke@1 | 147 | } |
duke@1 | 148 | |
duke@1 | 149 | public Tag[] firstSentenceTags() { |
duke@1 | 150 | if (firstSentence == null) { |
duke@1 | 151 | //Parse all sentences first to avoid duplicate warnings. |
duke@1 | 152 | inlineTags(); |
duke@1 | 153 | try { |
duke@1 | 154 | env.setSilent(true); |
duke@1 | 155 | firstSentence = Comment.firstSentenceTags(this, commentText()); |
duke@1 | 156 | } finally { |
duke@1 | 157 | env.setSilent(false); |
duke@1 | 158 | } |
duke@1 | 159 | } |
duke@1 | 160 | return firstSentence; |
duke@1 | 161 | } |
duke@1 | 162 | |
duke@1 | 163 | /** |
duke@1 | 164 | * Utility for subclasses which read HTML documentation files. |
duke@1 | 165 | */ |
duke@1 | 166 | String readHTMLDocumentation(InputStream input, String filename) throws IOException { |
duke@1 | 167 | int filesize = input.available(); |
duke@1 | 168 | byte[] filecontents = new byte[filesize]; |
duke@1 | 169 | input.read(filecontents, 0, filesize); |
duke@1 | 170 | input.close(); |
duke@1 | 171 | String encoding = env.getEncoding(); |
duke@1 | 172 | String rawDoc = (encoding!=null) |
duke@1 | 173 | ? new String(filecontents, encoding) |
duke@1 | 174 | : new String(filecontents); |
duke@1 | 175 | String upper = null; |
duke@1 | 176 | int bodyIdx = rawDoc.indexOf("<body"); |
duke@1 | 177 | if (bodyIdx == -1) { |
duke@1 | 178 | bodyIdx = rawDoc.indexOf("<BODY"); |
duke@1 | 179 | if (bodyIdx == -1) { |
duke@1 | 180 | upper = rawDoc.toUpperCase(); |
duke@1 | 181 | bodyIdx = upper.indexOf("<BODY"); |
duke@1 | 182 | if (bodyIdx == -1) { |
duke@1 | 183 | env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), |
duke@1 | 184 | "javadoc.Body_missing_from_html_file"); |
duke@1 | 185 | return ""; |
duke@1 | 186 | } |
duke@1 | 187 | } |
duke@1 | 188 | } |
duke@1 | 189 | bodyIdx = rawDoc.indexOf('>', bodyIdx); |
duke@1 | 190 | if (bodyIdx == -1) { |
duke@1 | 191 | env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), |
duke@1 | 192 | "javadoc.Body_missing_from_html_file"); |
duke@1 | 193 | return ""; |
duke@1 | 194 | } |
duke@1 | 195 | ++bodyIdx; |
duke@1 | 196 | int endIdx = rawDoc.indexOf("</body", bodyIdx); |
duke@1 | 197 | if (endIdx == -1) { |
duke@1 | 198 | endIdx = rawDoc.indexOf("</BODY", bodyIdx); |
duke@1 | 199 | if (endIdx == -1) { |
duke@1 | 200 | if (upper == null) { |
duke@1 | 201 | upper = rawDoc.toUpperCase(); |
duke@1 | 202 | } |
duke@1 | 203 | endIdx = upper.indexOf("</BODY", bodyIdx); |
duke@1 | 204 | if (endIdx == -1) { |
duke@1 | 205 | env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), |
duke@1 | 206 | "javadoc.End_body_missing_from_html_file"); |
duke@1 | 207 | return ""; |
duke@1 | 208 | } |
duke@1 | 209 | } |
duke@1 | 210 | } |
duke@1 | 211 | return rawDoc.substring(bodyIdx, endIdx); |
duke@1 | 212 | } |
duke@1 | 213 | |
duke@1 | 214 | /** |
duke@1 | 215 | * Return the full unprocessed text of the comment. Tags |
duke@1 | 216 | * are included as text. Used mainly for store and retrieve |
duke@1 | 217 | * operations like internalization. |
duke@1 | 218 | */ |
duke@1 | 219 | public String getRawCommentText() { |
duke@1 | 220 | return documentation(); |
duke@1 | 221 | } |
duke@1 | 222 | |
duke@1 | 223 | /** |
duke@1 | 224 | * Set the full unprocessed text of the comment. Tags |
duke@1 | 225 | * are included as text. Used mainly for store and retrieve |
duke@1 | 226 | * operations like internalization. |
duke@1 | 227 | */ |
duke@1 | 228 | public void setRawCommentText(String rawDocumentation) { |
duke@1 | 229 | documentation = rawDocumentation; |
duke@1 | 230 | comment = null; |
duke@1 | 231 | } |
duke@1 | 232 | |
duke@1 | 233 | /** |
duke@1 | 234 | * return a key for sorting. |
duke@1 | 235 | */ |
duke@1 | 236 | CollationKey key() { |
duke@1 | 237 | if (collationkey == null) { |
duke@1 | 238 | collationkey = generateKey(); |
duke@1 | 239 | } |
duke@1 | 240 | return collationkey; |
duke@1 | 241 | } |
duke@1 | 242 | |
duke@1 | 243 | /** |
duke@1 | 244 | * Generate a key for sorting. |
duke@1 | 245 | * <p> |
duke@1 | 246 | * Default is name(). |
duke@1 | 247 | */ |
duke@1 | 248 | CollationKey generateKey() { |
duke@1 | 249 | String k = name(); |
duke@1 | 250 | // System.out.println("COLLATION KEY FOR " + this + " is \"" + k + "\""); |
duke@1 | 251 | return env.doclocale.collator.getCollationKey(k); |
duke@1 | 252 | } |
duke@1 | 253 | |
duke@1 | 254 | /** |
duke@1 | 255 | * Returns a string representation of this Doc item. |
duke@1 | 256 | */ |
duke@1 | 257 | public String toString() { |
duke@1 | 258 | return qualifiedName(); |
duke@1 | 259 | } |
duke@1 | 260 | |
duke@1 | 261 | /** |
duke@1 | 262 | * Returns the name of this Doc item. |
duke@1 | 263 | * |
duke@1 | 264 | * @return the name |
duke@1 | 265 | */ |
duke@1 | 266 | public abstract String name(); |
duke@1 | 267 | |
duke@1 | 268 | /** |
duke@1 | 269 | * Returns the qualified name of this Doc item. |
duke@1 | 270 | * |
duke@1 | 271 | * @return the name |
duke@1 | 272 | */ |
duke@1 | 273 | public abstract String qualifiedName(); |
duke@1 | 274 | |
duke@1 | 275 | /** |
duke@1 | 276 | * Compares this Object with the specified Object for order. Returns a |
duke@1 | 277 | * negative integer, zero, or a positive integer as this Object is less |
duke@1 | 278 | * than, equal to, or greater than the given Object. |
duke@1 | 279 | * <p> |
duke@1 | 280 | * Included so that Doc item are java.lang.Comparable. |
duke@1 | 281 | * |
duke@1 | 282 | * @param o the <code>Object</code> to be compared. |
duke@1 | 283 | * @return a negative integer, zero, or a positive integer as this Object |
duke@1 | 284 | * is less than, equal to, or greater than the given Object. |
duke@1 | 285 | * @exception ClassCastException the specified Object's type prevents it |
duke@1 | 286 | * from being compared to this Object. |
duke@1 | 287 | */ |
duke@1 | 288 | public int compareTo(Object obj) { |
duke@1 | 289 | // System.out.println("COMPARE \"" + this + "\" to \"" + obj + "\" = " + key().compareTo(((DocImpl)obj).key())); |
duke@1 | 290 | return key().compareTo(((DocImpl)obj).key()); |
duke@1 | 291 | } |
duke@1 | 292 | |
duke@1 | 293 | /** |
duke@1 | 294 | * Is this Doc item a field? False until overridden. |
duke@1 | 295 | * |
duke@1 | 296 | * @return true if it represents a field |
duke@1 | 297 | */ |
duke@1 | 298 | public boolean isField() { |
duke@1 | 299 | return false; |
duke@1 | 300 | } |
duke@1 | 301 | |
duke@1 | 302 | /** |
duke@1 | 303 | * Is this Doc item an enum constant? False until overridden. |
duke@1 | 304 | * |
duke@1 | 305 | * @return true if it represents an enum constant |
duke@1 | 306 | */ |
duke@1 | 307 | public boolean isEnumConstant() { |
duke@1 | 308 | return false; |
duke@1 | 309 | } |
duke@1 | 310 | |
duke@1 | 311 | /** |
duke@1 | 312 | * Is this Doc item a constructor? False until overridden. |
duke@1 | 313 | * |
duke@1 | 314 | * @return true if it represents a constructor |
duke@1 | 315 | */ |
duke@1 | 316 | public boolean isConstructor() { |
duke@1 | 317 | return false; |
duke@1 | 318 | } |
duke@1 | 319 | |
duke@1 | 320 | /** |
duke@1 | 321 | * Is this Doc item a method (but not a constructor or annotation |
duke@1 | 322 | * type element)? |
duke@1 | 323 | * False until overridden. |
duke@1 | 324 | * |
duke@1 | 325 | * @return true if it represents a method |
duke@1 | 326 | */ |
duke@1 | 327 | public boolean isMethod() { |
duke@1 | 328 | return false; |
duke@1 | 329 | } |
duke@1 | 330 | |
duke@1 | 331 | /** |
duke@1 | 332 | * Is this Doc item an annotation type element? |
duke@1 | 333 | * False until overridden. |
duke@1 | 334 | * |
duke@1 | 335 | * @return true if it represents an annotation type element |
duke@1 | 336 | */ |
duke@1 | 337 | public boolean isAnnotationTypeElement() { |
duke@1 | 338 | return false; |
duke@1 | 339 | } |
duke@1 | 340 | |
duke@1 | 341 | /** |
duke@1 | 342 | * Is this Doc item a interface (but not an annotation type)? |
duke@1 | 343 | * False until overridden. |
duke@1 | 344 | * |
duke@1 | 345 | * @return true if it represents a interface |
duke@1 | 346 | */ |
duke@1 | 347 | public boolean isInterface() { |
duke@1 | 348 | return false; |
duke@1 | 349 | } |
duke@1 | 350 | |
duke@1 | 351 | /** |
duke@1 | 352 | * Is this Doc item a exception class? False until overridden. |
duke@1 | 353 | * |
duke@1 | 354 | * @return true if it represents a exception |
duke@1 | 355 | */ |
duke@1 | 356 | public boolean isException() { |
duke@1 | 357 | return false; |
duke@1 | 358 | } |
duke@1 | 359 | |
duke@1 | 360 | /** |
duke@1 | 361 | * Is this Doc item a error class? False until overridden. |
duke@1 | 362 | * |
duke@1 | 363 | * @return true if it represents a error |
duke@1 | 364 | */ |
duke@1 | 365 | public boolean isError() { |
duke@1 | 366 | return false; |
duke@1 | 367 | } |
duke@1 | 368 | |
duke@1 | 369 | /** |
duke@1 | 370 | * Is this Doc item an enum type? False until overridden. |
duke@1 | 371 | * |
duke@1 | 372 | * @return true if it represents an enum type |
duke@1 | 373 | */ |
duke@1 | 374 | public boolean isEnum() { |
duke@1 | 375 | return false; |
duke@1 | 376 | } |
duke@1 | 377 | |
duke@1 | 378 | /** |
duke@1 | 379 | * Is this Doc item an annotation type? False until overridden. |
duke@1 | 380 | * |
duke@1 | 381 | * @return true if it represents an annotation type |
duke@1 | 382 | */ |
duke@1 | 383 | public boolean isAnnotationType() { |
duke@1 | 384 | return false; |
duke@1 | 385 | } |
duke@1 | 386 | |
duke@1 | 387 | /** |
duke@1 | 388 | * Is this Doc item an ordinary class (i.e. not an interface, |
duke@1 | 389 | * annotation type, enumeration, exception, or error)? |
duke@1 | 390 | * False until overridden. |
duke@1 | 391 | * |
duke@1 | 392 | * @return true if it represents an ordinary class |
duke@1 | 393 | */ |
duke@1 | 394 | public boolean isOrdinaryClass() { |
duke@1 | 395 | return false; |
duke@1 | 396 | } |
duke@1 | 397 | |
duke@1 | 398 | /** |
duke@1 | 399 | * Is this Doc item a class |
duke@1 | 400 | * (and not an interface or annotation type)? |
duke@1 | 401 | * This includes ordinary classes, enums, errors and exceptions. |
duke@1 | 402 | * False until overridden. |
duke@1 | 403 | * |
duke@1 | 404 | * @return true if it represents a class |
duke@1 | 405 | */ |
duke@1 | 406 | public boolean isClass() { |
duke@1 | 407 | return false; |
duke@1 | 408 | } |
duke@1 | 409 | |
duke@1 | 410 | /** |
duke@1 | 411 | * return true if this Doc is include in the active set. |
duke@1 | 412 | */ |
duke@1 | 413 | public abstract boolean isIncluded(); |
duke@1 | 414 | |
duke@1 | 415 | /** |
duke@1 | 416 | * Return the source position of the entity, or null if |
duke@1 | 417 | * no position is available. |
duke@1 | 418 | */ |
duke@1 | 419 | public SourcePosition position() { return null; } |
duke@1 | 420 | } |