| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons.doclet; |
| 34 | | | |
| 35 | | | import java.io.File; |
| 36 | | | import java.io.FileOutputStream; |
| 37 | | | import java.io.IOException; |
| 38 | | | import java.io.OutputStreamWriter; |
| 39 | | | import java.io.Writer; |
| 40 | | | import java.util.Arrays; |
| 41 | | | import java.util.HashMap; |
| 42 | | | import java.util.HashSet; |
| 43 | | | import java.util.Iterator; |
| 44 | | | import java.util.Map; |
| 45 | | | import java.util.Set; |
| 46 | | | import java.util.logging.Level; |
| 47 | | | import java.util.logging.Logger; |
| 48 | | | |
| 49 | | | import org.jcoderz.commons.ArgumentMalformedException; |
| 50 | | | import org.jcoderz.commons.util.ArraysUtil; |
| 51 | | | import org.jcoderz.commons.util.IoUtil; |
| 52 | | | import org.jcoderz.commons.util.StringUtil; |
| 53 | | | import org.jcoderz.commons.util.XmlUtil; |
| 54 | | | |
| 55 | | | import com.sun.javadoc.ClassDoc; |
| 56 | | | import com.sun.javadoc.ConstructorDoc; |
| 57 | | | import com.sun.javadoc.Doc; |
| 58 | | | import com.sun.javadoc.DocErrorReporter; |
| 59 | | | import com.sun.javadoc.Doclet; |
| 60 | | | import com.sun.javadoc.ExecutableMemberDoc; |
| 61 | | | import com.sun.javadoc.FieldDoc; |
| 62 | | | import com.sun.javadoc.MemberDoc; |
| 63 | | | import com.sun.javadoc.MethodDoc; |
| 64 | | | import com.sun.javadoc.PackageDoc; |
| 65 | | | import com.sun.javadoc.ParamTag; |
| 66 | | | import com.sun.javadoc.Parameter; |
| 67 | | | import com.sun.javadoc.ProgramElementDoc; |
| 68 | | | import com.sun.javadoc.RootDoc; |
| 69 | | | import com.sun.javadoc.SeeTag; |
| 70 | | | import com.sun.javadoc.SourcePosition; |
| 71 | | | import com.sun.javadoc.Tag; |
| 72 | | | import com.sun.javadoc.ThrowsTag; |
| 73 | | | |
| 74 | | | |
| 75 | | | |
| 76 | | | |
| 77 | | | @author |
| 78 | | | |
| 79 | | | public class XmlDoclet |
| 80 | | | extends Doclet |
| 81 | | | { |
| 82 | | | |
| 83 | 0 | | private static final String CLASSNAME = XmlDoclet.class.getName(); |
| 84 | | | |
| 85 | | | |
| 86 | 0 | | private static final Logger logger = Logger.getLogger(CLASSNAME); |
| 87 | | | |
| 88 | | | |
| 89 | 0 | | private static XmlDocletConfig sConfig = new XmlDocletConfig(); |
| 90 | | | |
| 91 | | | |
| 92 | | | private final XmlDocletConfig mConfig; |
| 93 | | | |
| 94 | | | |
| 95 | 0 | | private Writer mOut = null; |
| 96 | | | |
| 97 | | | private RootDoc mRootDoc; |
| 98 | | | |
| 99 | | | |
| 100 | | | |
| 101 | | | @param |
| 102 | | | |
| 103 | | | public XmlDoclet (XmlDocletConfig config) |
| 104 | 0 | | { |
| 105 | | | try |
| 106 | | | { |
| 107 | 0 | | mConfig = (XmlDocletConfig) config.clone(); |
| 108 | | | } |
| 109 | 0 | | catch (CloneNotSupportedException e) |
| 110 | | | { |
| 111 | 0 | (1) | throw new RuntimeException("Clone must be supported by config.", e); |
| 112 | 0 | | } |
| 113 | 0 | | } |
| 114 | | | |
| 115 | | | {@inheritDoc} |
| 116 | | (2) | public static boolean start (RootDoc root) |
| 117 | | | { |
| 118 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 119 | | | { |
| 120 | 0 | | logger.entering(CLASSNAME, "start(RootDoc)", root); |
| 121 | | | } |
| 122 | 0 | | boolean result = true; |
| 123 | | | try |
| 124 | | | { |
| 125 | 0 | | final XmlDoclet handler = new XmlDoclet(sConfig); |
| 126 | 0 | | handler.handle(root); |
| 127 | | | } |
| 128 | 0 | | catch (Exception ex) |
| 129 | | | { |
| 130 | | (3) | |
| 131 | 0 | | result = false; |
| 132 | 0 | | root.printError(ex.getMessage()); |
| 133 | 0 | (4) | throw new RuntimeException("Internal processing error.", ex); |
| 134 | 0 | | } |
| 135 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 136 | | | { |
| 137 | 0 | | logger.exiting(CLASSNAME, "start(RootDoc)", Boolean.valueOf(result)); |
| 138 | | | } |
| 139 | 0 | | return result; |
| 140 | | | } |
| 141 | | | |
| 142 | | | @see |
| 143 | | (5)(6) | public static int optionLength (String option) |
| 144 | | | { |
| 145 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 146 | | | { |
| 147 | 0 | | logger.entering(CLASSNAME, "optionLength(String)", option); |
| 148 | | | } |
| 149 | 0 | | final int result = sConfig.optionLength(option); |
| 150 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 151 | | | { |
| 152 | 0 | | logger.exiting(CLASSNAME, "optionLength(String)", |
| 153 | | | new Integer(result)); |
| 154 | | | } |
| 155 | 0 | | return result; |
| 156 | | | } |
| 157 | | | |
| 158 | | (7) | public static boolean validOptions (String[][] arguments, |
| 159 | | | DocErrorReporter reporter) |
| 160 | | | { |
| 161 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 162 | | | { |
| 163 | 0 | | logger.entering(CLASSNAME, |
| 164 | | | "validOptions(String[][], DocErrorReporter)", |
| 165 | | | new Object[] {ArraysUtil.toString(arguments), reporter}); |
| 166 | | | } |
| 167 | 0 | | boolean result = true; |
| 168 | 0 | | final Iterator i = Arrays.asList(arguments).iterator(); |
| 169 | 0 | | while (i.hasNext()) |
| 170 | | | { |
| 171 | 0 | | final String[] arg = (String[]) i.next(); |
| 172 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 173 | | | { |
| 174 | 0 | | logger.finest("About to parse argument: " |
| 175 | | | + ArraysUtil.toString(arg)); |
| 176 | | | } |
| 177 | 0 | | final String[] options = new String[arg.length - 1]; |
| 178 | 0 | | System.arraycopy(arg, 1, options, 0, options.length); |
| 179 | | | try |
| 180 | | | { |
| 181 | 0 | | sConfig.parseOption(arg[0], options); |
| 182 | | | } |
| 183 | 0 | | catch (ArgumentMalformedException ex) |
| 184 | | | { |
| 185 | 0 | | reporter.printError(ex.getMessage()); |
| 186 | 0 | | result = false; |
| 187 | 0 | | } |
| 188 | 0 | | } |
| 189 | 0 | | if (logger.isLoggable(Level.FINER)) |
| 190 | | | { |
| 191 | 0 | | logger.exiting(CLASSNAME, |
| 192 | | | "validOptions(String[][], DocErrorReporter)", |
| 193 | | | Boolean.valueOf(result)); |
| 194 | | | } |
| 195 | 0 | | return result; |
| 196 | | | } |
| 197 | | | |
| 198 | | | |
| 199 | | | private void handle (RootDoc root) |
| 200 | | | throws IOException |
| 201 | | | { |
| 202 | | | |
| 203 | 0 | | FileOutputStream streamOut = null; |
| 204 | 0 | | mRootDoc = root; |
| 205 | | | try |
| 206 | | | { |
| 207 | 0 | | streamOut = new FileOutputStream( |
| 208 | | | new File(mConfig.getOutputDirectory(), "javadoc.xml"), false); |
| 209 | | | |
| 210 | 0 | | mOut = new OutputStreamWriter(streamOut, "utf-8"); |
| 211 | | | |
| 212 | 0 | | mOut.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 213 | 0 | | mOut.write("<javadoc>\n"); |
| 214 | | | |
| 215 | 0 | | final Set handledPackages = new HashSet(); |
| 216 | | | |
| 217 | 0 | | final PackageDoc[] packages = root.specifiedPackages(); |
| 218 | 0 | | for (int i = 0; i < packages.length; ++i) |
| 219 | | | { |
| 220 | 0 | | generatePackageElement(packages[i]); |
| 221 | 0 | | handledPackages.add(packages[i].name()); |
| 222 | | | } |
| 223 | 0 | | final ClassDoc[] classes = root.specifiedClasses(); |
| 224 | 0 | | for (int i = 0; i < classes.length; ++i) |
| 225 | | | { |
| 226 | 0 | | if (!handledPackages.contains( |
| 227 | | | classes[i].containingPackage().name())) |
| 228 | | | { |
| 229 | 0 | | generatePackageElement(classes[i].containingPackage()); |
| 230 | 0 | | handledPackages.add(classes[i].containingPackage().name()); |
| 231 | | | } |
| 232 | | | } |
| 233 | 0 | | mOut.write("</javadoc>"); |
| 234 | | | |
| 235 | | | |
| 236 | | | } |
| 237 | | | finally |
| 238 | | | { |
| 239 | 0 | | IoUtil.close(mOut); |
| 240 | 0 | | IoUtil.close(streamOut); |
| 241 | 0 | | mOut = null; |
| 242 | 0 | | } |
| 243 | 0 | | } |
| 244 | | | |
| 245 | | | private void generatePackageElement (PackageDoc pkg) |
| 246 | | | throws IOException |
| 247 | | | { |
| 248 | 0 | | mOut.write("<package"); |
| 249 | 0 | | generateDocHeader(pkg); |
| 250 | 0 | | mOut.write(">"); |
| 251 | 0 | | generateDocBody(pkg); |
| 252 | 0 | | final ClassDoc[] classes = pkg.allClasses(); |
| 253 | 0 | | for (int i = 0; i < classes.length; ++i) |
| 254 | | | { |
| 255 | 0 | | generateClassElement(classes[i]); |
| 256 | | | } |
| 257 | 0 | | mOut.write("</package>"); |
| 258 | 0 | | } |
| 259 | | | |
| 260 | | | private void generateClassElement (ClassDoc cd) |
| 261 | | | throws IOException |
| 262 | | | { |
| 263 | 0 | | mOut.write("<class"); |
| 264 | 0 | | generateClassHeader(cd); |
| 265 | 0 | | mOut.write(">\n"); |
| 266 | 0 | | generateClassBody(cd); |
| 267 | 0 | | mOut.write("</class>\n"); |
| 268 | 0 | | } |
| 269 | | | |
| 270 | | | private void generateClassBody (ClassDoc cd) |
| 271 | | | throws IOException |
| 272 | | | { |
| 273 | 0 | | generateProgramElementBody(cd); |
| 274 | | | |
| 275 | | | |
| 276 | 0 | | final ClassDoc[] interfaces = cd.interfaces(); |
| 277 | 0 | | for (int i = 0; i < interfaces.length; ++i) |
| 278 | | | { |
| 279 | 0 | | mOut.write("<interface"); |
| 280 | 0 | (8) | addAttribute("name", interfaces[i].qualifiedName()); |
| 281 | 0 | | mOut.write("/>\n"); |
| 282 | | | } |
| 283 | | | |
| 284 | | | |
| 285 | 0 | | final ClassDoc[] innerClass = cd.innerClasses(); |
| 286 | 0 | | for (int i = 0; i < innerClass.length; ++i) |
| 287 | | | { |
| 288 | 0 | | mOut.write("<inner"); |
| 289 | 0 | | addAttribute("name", innerClass[i].qualifiedName()); |
| 290 | 0 | | mOut.write("/>\n"); |
| 291 | | | } |
| 292 | | | |
| 293 | | | |
| 294 | | | |
| 295 | 0 | | final FieldDoc[] fields = cd.fields(); |
| 296 | 0 | | for (int i = 0; i < fields.length; ++i) |
| 297 | | | { |
| 298 | 0 | | final FieldDoc field = fields[i]; |
| 299 | 0 | | generateFieldHeader(field); |
| 300 | 0 | | generateFieldBody(field); |
| 301 | 0 | | mOut.write("</field>\n"); |
| 302 | | | } |
| 303 | | | |
| 304 | | | |
| 305 | 0 | | final ConstructorDoc[] constructors = cd.constructors(); |
| 306 | 0 | | for (int i = 0; i < constructors.length; ++i) |
| 307 | | | { |
| 308 | 0 | | final ConstructorDoc constructor = constructors[i]; |
| 309 | 0 | | generateConstructorHeader(constructor); |
| 310 | 0 | | generateConstructorBody(constructor); |
| 311 | 0 | | mOut.write("</constructor>\n"); |
| 312 | | | } |
| 313 | | | |
| 314 | | | |
| 315 | 0 | | final MethodDoc[] methods = cd.methods(); |
| 316 | 0 | | for (int i = 0; i < methods.length; ++i) |
| 317 | | | { |
| 318 | 0 | | final MethodDoc method = methods[i]; |
| 319 | 0 | | generateMethodHeader(method); |
| 320 | 0 | | generateMethodBody(method); |
| 321 | 0 | | mOut.write("</method>\n"); |
| 322 | | | } |
| 323 | 0 | | } |
| 324 | | | |
| 325 | | | private void generateMethodHeader (MethodDoc method) |
| 326 | | | throws IOException |
| 327 | | | { |
| 328 | 0 | | mOut.write("<method"); |
| 329 | | | |
| 330 | 0 | | addAttribute("abstract", method.isAbstract()); |
| 331 | 0 | | if (method.overriddenClass() != null) |
| 332 | | | { |
| 333 | 0 | | addAttribute("overridden-class", |
| 334 | | | method.overriddenClass().qualifiedName()); |
| 335 | | | } |
| 336 | | | |
| 337 | 0 | | if (method.overriddenMethod() != null) |
| 338 | | | { |
| 339 | 0 | | addAttribute("overridden-method", |
| 340 | | | method.overriddenMethod().qualifiedName()); |
| 341 | | | } |
| 342 | | | |
| 343 | 0 | | generateExecutableMemberHeader(method); |
| 344 | 0 | | mOut.write(">\n"); |
| 345 | 0 | | } |
| 346 | | | |
| 347 | | | private void generateMethodBody (MethodDoc method) |
| 348 | | | throws IOException |
| 349 | | | { |
| 350 | 0 | (9) | if (method.returnType() != null |
| 351 | | | && !method.returnType().qualifiedTypeName().equals("void")) |
| 352 | | | { |
| 353 | 0 | | mOut.write("<return"); |
| 354 | 0 | (10) | addAttribute("type", |
| 355 | | | method.returnType().qualifiedTypeName() |
| 356 | | | + method.returnType().dimension()); |
| 357 | 0 | | mOut.write(">"); |
| 358 | 0 | | final Tag[] returnTag = method.tags("return"); |
| 359 | 0 | | if (returnTag != null && returnTag.length > 0) |
| 360 | | | { |
| 361 | 0 | | generatedTagedTextElement(returnTag[0].inlineTags()); |
| 362 | | | } |
| 363 | 0 | | mOut.write("</return>\n"); |
| 364 | | | } |
| 365 | 0 | | generateExecutableMemberDocBody(method); |
| 366 | 0 | | } |
| 367 | | | |
| 368 | | | private void generatedTagedTextElement (final Tag[] tags) |
| 369 | | | throws IOException |
| 370 | | | { |
| 371 | 0 | | mOut.write("<doc>"); |
| 372 | 0 | | generateTagedDoc(tags); |
| 373 | 0 | | mOut.write("</doc>\n"); |
| 374 | 0 | | } |
| 375 | | | |
| 376 | | | private void generateConstructorBody (ConstructorDoc constructor) |
| 377 | | | throws IOException |
| 378 | | | { |
| 379 | 0 | | generateExecutableMemberDocBody(constructor); |
| 380 | 0 | | } |
| 381 | | | |
| 382 | | (11) | private void generateExecutableMemberDocBody ( |
| 383 | | | ExecutableMemberDoc executableMemberDoc) |
| 384 | | | throws IOException |
| 385 | | | { |
| 386 | 0 | | generateMemberBody(executableMemberDoc); |
| 387 | | | |
| 388 | | | |
| 389 | 0 | | final ParamTag[] tags = executableMemberDoc.paramTags(); |
| 390 | 0 | | final Map parameterTags = new HashMap(); |
| 391 | 0 | | for (int i = 0; i < tags.length; ++i) |
| 392 | | | { |
| 393 | 0 | | if (parameterTags.containsKey(tags[i].parameterName())) |
| 394 | | | { |
| 395 | 0 | | warn(tags[i].position(), |
| 396 | | | "Duplicate parameter ignored. " + tags[i], |
| 397 | | | executableMemberDoc); |
| 398 | | | } |
| 399 | | | else |
| 400 | | | { |
| 401 | | | |
| 402 | 0 | | parameterTags.put(tags[i].parameterName(), tags[i]); |
| 403 | | | } |
| 404 | | | } |
| 405 | | | |
| 406 | 0 | | final Parameter[] parameters = executableMemberDoc.parameters(); |
| 407 | 0 | | for (int i = 0; i < parameters.length; ++i) |
| 408 | | | { |
| 409 | 0 | | final ParamTag parameterTag |
| 410 | | | = (ParamTag) parameterTags.get(parameters[i].name()); |
| 411 | | | |
| 412 | | | |
| 413 | | | |
| 414 | | | |
| 415 | | | |
| 416 | 0 | | generateParameterHeader(parameters[i], parameterTag); |
| 417 | 0 | | generateParameterBody(parameters[i], parameterTag); |
| 418 | 0 | | mOut.write("</parameter>\n"); |
| 419 | 0 | | parameterTags.remove(parameters[i].name()); |
| 420 | | | } |
| 421 | | | |
| 422 | 0 | | if (!parameterTags.isEmpty()) |
| 423 | | | { |
| 424 | 0 | | warn(executableMemberDoc.position(), |
| 425 | | | "Unused parameter tags: " + parameterTags, executableMemberDoc); |
| 426 | | | } |
| 427 | | | |
| 428 | | | |
| 429 | 0 | | final ThrowsTag[] tTags = executableMemberDoc.throwsTags(); |
| 430 | 0 | | final Map throwsTags = new HashMap(); |
| 431 | 0 | | for (int i = 0; i < tTags.length; ++i) |
| 432 | | | { |
| 433 | 0 | | if (throwsTags.containsKey(tTags[i].exceptionName())) |
| 434 | | | { |
| 435 | 0 | | warn(tTags[i].position(), |
| 436 | | | "Duplicate throws Tags ignored." + tTags[i].exceptionName(), |
| 437 | | | executableMemberDoc); |
| 438 | | | } |
| 439 | | | else |
| 440 | | | { |
| 441 | 0 | | throwsTags.put(tTags[i].exceptionName(), tTags[i]); |
| 442 | | | } |
| 443 | | | } |
| 444 | | | |
| 445 | 0 | | final ClassDoc[] exceptions = executableMemberDoc.thrownExceptions(); |
| 446 | 0 | | for (int i = 0; i < exceptions.length; ++i) |
| 447 | | | { |
| 448 | 0 | | ThrowsTag exceptionTag |
| 449 | | | = (ThrowsTag) throwsTags.remove(exceptions[i].qualifiedName()); |
| 450 | 0 | | if (exceptionTag == null) |
| 451 | | | { |
| 452 | 0 | | exceptionTag = (ThrowsTag) throwsTags.remove(exceptions[i].name()); |
| 453 | | | } |
| 454 | 0 | (12) | if (exceptionTag == null) |
| 455 | | | { |
| 456 | | | |
| 457 | | | |
| 458 | | | |
| 459 | | | } |
| 460 | 0 | | generateThrowsHeader(exceptions[i], exceptionTag); |
| 461 | 0 | | generateThrowsBody(exceptions[i], exceptionTag); |
| 462 | 0 | | mOut.write("</throws>\n"); |
| 463 | | | } |
| 464 | | | |
| 465 | 0 | | if (!throwsTags.isEmpty()) |
| 466 | | | { |
| 467 | 0 | | warn(executableMemberDoc.position(), |
| 468 | | | "Unused throws tags: " + throwsTags, executableMemberDoc); |
| 469 | | | } |
| 470 | 0 | | } |
| 471 | | | |
| 472 | | | private void generateMemberBody (MemberDoc member) |
| 473 | | | throws IOException |
| 474 | | | { |
| 475 | 0 | | generateProgramElementBody(member); |
| 476 | 0 | | } |
| 477 | | | |
| 478 | | | private void generateProgramElementBody (ProgramElementDoc programElement) |
| 479 | | | throws IOException |
| 480 | | | { |
| 481 | 0 | | generateDocBody(programElement); |
| 482 | 0 | | } |
| 483 | | | |
| 484 | | | private void generateThrowsHeader (ClassDoc parameter, |
| 485 | | | ThrowsTag exceptionTag) |
| 486 | | | throws IOException |
| 487 | | | { |
| 488 | 0 | | mOut.write("<throws"); |
| 489 | 0 | | addAttribute("type", parameter.qualifiedName()); |
| 490 | 0 | | generateTagHeader(exceptionTag); |
| 491 | 0 | | mOut.write(">"); |
| 492 | 0 | | } |
| 493 | | | |
| 494 | | | private void generateThrowsBody (ClassDoc parameter, |
| 495 | | | ThrowsTag exceptionTag) |
| 496 | | | throws IOException |
| 497 | | | { |
| 498 | 0 | | if (exceptionTag != null) |
| 499 | | | { |
| 500 | 0 | | generateTagBody(exceptionTag); |
| 501 | | | } |
| 502 | 0 | | } |
| 503 | | | |
| 504 | | | private void generateParameterBody (Parameter parameter, |
| 505 | | | ParamTag parameterTag) |
| 506 | | | throws IOException |
| 507 | | | { |
| 508 | 0 | | if (parameterTag != null) |
| 509 | | | { |
| 510 | 0 | | generateTagBody(parameterTag); |
| 511 | | | } |
| 512 | 0 | | } |
| 513 | | | |
| 514 | | | private void generateParameterHeader (Parameter parameter, |
| 515 | | | ParamTag parameterTag) |
| 516 | | | throws IOException |
| 517 | | | { |
| 518 | 0 | | mOut.write("<parameter"); |
| 519 | 0 | | addAttribute("name", parameter.name()); |
| 520 | 0 | | addAttribute("type", |
| 521 | | | parameter.type().qualifiedTypeName() |
| 522 | | | + parameter.type().dimension()); |
| 523 | 0 | | mOut.write(">"); |
| 524 | 0 | | } |
| 525 | | | |
| 526 | | | private void generateConstructorHeader (ConstructorDoc cd) |
| 527 | | | throws IOException |
| 528 | | | { |
| 529 | 0 | | mOut.write("<constructor"); |
| 530 | 0 | | generateExecutableMemberHeader(cd); |
| 531 | 0 | | mOut.write(">"); |
| 532 | 0 | | } |
| 533 | | | |
| 534 | | | private void generateExecutableMemberHeader (ExecutableMemberDoc emd) |
| 535 | | | throws IOException |
| 536 | | | { |
| 537 | 0 | | addAttribute("flat-signature", emd.flatSignature()); |
| 538 | 0 | | addAttribute("signature", emd.signature()); |
| 539 | 0 | | addAttribute("native", emd.isNative()); |
| 540 | 0 | | addAttribute("synchronized", emd.isSynchronized()); |
| 541 | 0 | | generateMemberHeader(emd); |
| 542 | 0 | | } |
| 543 | | | |
| 544 | | | private void generateMemberHeader (MemberDoc md) |
| 545 | | | throws IOException |
| 546 | | | { |
| 547 | 0 | | addAttribute("synthetic", md.isSynthetic()); |
| 548 | 0 | | generateProgramElementHeader(md); |
| 549 | 0 | | } |
| 550 | | | |
| 551 | | | private void generateFieldBody (FieldDoc fd) |
| 552 | | | throws IOException |
| 553 | | | { |
| 554 | 0 | | generateMemberBody(fd); |
| 555 | | (13) | |
| 556 | 0 | | } |
| 557 | | | |
| 558 | | | private void generateFieldHeader (FieldDoc cd) |
| 559 | | | throws IOException |
| 560 | | | { |
| 561 | 0 | | mOut.write("<field"); |
| 562 | 0 | | addAttribute("type", |
| 563 | | | cd.type().qualifiedTypeName() + cd.type().dimension()); |
| 564 | | | |
| 565 | 0 | | final String constant = cd.constantValueExpression(); |
| 566 | 0 | | if (constant != null) |
| 567 | | | { |
| 568 | 0 | | addAttribute("constant", true); |
| 569 | 0 | | addAttribute("value", constant); |
| 570 | | | } |
| 571 | 0 | | addAttribute("volatile", cd.isVolatile()); |
| 572 | 0 | | addAttribute("transient", cd.isTransient()); |
| 573 | 0 | | generateMemberHeader(cd); |
| 574 | 0 | | mOut.write(">"); |
| 575 | 0 | | } |
| 576 | | | |
| 577 | | | private void generateDocBody (Doc doc) |
| 578 | | | throws IOException |
| 579 | | | { |
| 580 | 0 | | mOut.write("<doc>"); |
| 581 | 0 | | generateTagedDoc(doc.inlineTags()); |
| 582 | 0 | | mOut.write("</doc>"); |
| 583 | | | |
| 584 | 0 | | final Tag[] tags = doc.tags(); |
| 585 | 0 | | for (int i = 0; i < tags.length; i++) |
| 586 | | | { |
| 587 | 0 | | final Tag tag = tags[i]; |
| 588 | | | |
| 589 | 0 | (14) | if (!tag.kind().equals("@param") |
| 590 | | | && !tag.kind().equals("@return") |
| 591 | | | && !tag.kind().equals("@throws")) |
| 592 | | | { |
| 593 | 0 | | generateTagElement(tag); |
| 594 | | | } |
| 595 | | | } |
| 596 | 0 | | } |
| 597 | | | |
| 598 | | | private void generateTagHeader (Tag tag) |
| 599 | | | throws IOException |
| 600 | | | { |
| 601 | 0 | | if (tag != null) |
| 602 | | | { |
| 603 | 0 | | if (tag.position() != null) |
| 604 | | | { |
| 605 | 0 | | generateSourcePositionHeader(tag.position()); |
| 606 | | | } |
| 607 | 0 | | addAttribute("name", tag.name()); |
| 608 | | | |
| 609 | 0 | | if (tag instanceof SeeTag) |
| 610 | | | { |
| 611 | 0 | | final SeeTag seeTag = (SeeTag) tag; |
| 612 | 0 | | addAttribute("label", seeTag.label()); |
| 613 | 0 | | addAttribute("referenced-class", seeTag.referencedClassName()); |
| 614 | 0 | | addAttribute("referenced-member", seeTag.referencedMemberName()); |
| 615 | 0 | | if (seeTag.referencedPackage() != null) |
| 616 | | | { |
| 617 | 0 | | addAttribute("referenced-package", |
| 618 | | | seeTag.referencedPackage().name()); |
| 619 | | | } |
| 620 | 0 | | } |
| 621 | | | else |
| 622 | | | { |
| 623 | 0 | | addAttribute("kind", tag.kind()); |
| 624 | | | } |
| 625 | | | } |
| 626 | 0 | | } |
| 627 | | | |
| 628 | | | private void generateTagElement (Tag tag) |
| 629 | | | throws IOException |
| 630 | | | { |
| 631 | 0 | | if (tag instanceof SeeTag) |
| 632 | | | { |
| 633 | 0 | | generateSeeElement((SeeTag) tag); |
| 634 | | | } |
| 635 | 0 | | else if (tag != null) |
| 636 | | | { |
| 637 | 0 | | mOut.write("<tag"); |
| 638 | 0 | | generateTagHeader(tag); |
| 639 | 0 | | mOut.write(">"); |
| 640 | 0 | | generateTagBody(tag); |
| 641 | 0 | | mOut.write("</tag>"); |
| 642 | | | } |
| 643 | 0 | | } |
| 644 | | | |
| 645 | | | private void generateTagBody (Tag tag) |
| 646 | | | throws IOException |
| 647 | | | { |
| 648 | 0 | | mOut.write("<doc>"); |
| 649 | 0 | | generateTagedDoc(tag.inlineTags()); |
| 650 | 0 | | mOut.write("</doc>"); |
| 651 | 0 | | } |
| 652 | | | |
| 653 | | | private void generateTagedDoc (Tag[] tags) |
| 654 | | | throws IOException |
| 655 | | | { |
| 656 | | | |
| 657 | 0 | | final StringBuffer data = new StringBuffer(); |
| 658 | 0 | | for (int i = 0; i < tags.length; i++) |
| 659 | | | { |
| 660 | 0 | | final Tag inlineTag = tags[i]; |
| 661 | 0 | | if (inlineTag instanceof SeeTag) |
| 662 | | | { |
| 663 | 0 | | data.append("<a id='SEE_TAG_"); |
| 664 | 0 | | data.append(Integer.toString(i)); |
| 665 | 0 | (15) | data.append("'></a>"); |
| 666 | | | } |
| 667 | | | else |
| 668 | | | { |
| 669 | 0 | | data.append(inlineTag.text()); |
| 670 | | | } |
| 671 | | | } |
| 672 | 0 | | final String input = data.toString(); |
| 673 | | | final String clean; |
| 674 | 0 | | if (input.indexOf('<') != -1 || input.indexOf('&') != -1) |
| 675 | | | { |
| 676 | 0 | | final HtmlCleaner cleaner = new HtmlCleaner(); |
| 677 | 0 | | clean = cleaner.clean(data); |
| 678 | 0 | | final String warnings = cleaner.getWarnings(); |
| 679 | 0 | | if (!StringUtil.isEmptyOrNull(warnings)) |
| 680 | | | { |
| 681 | 0 | | mRootDoc.printWarning("Input:" + input); |
| 682 | 0 | | mRootDoc.printWarning("Clean:" + clean); |
| 683 | 0 | | if (cleaner.hasErrors()) |
| 684 | | | { |
| 685 | 0 | (16) | mRootDoc.printWarning(tags[0].position(), warnings); |
| 686 | | | |
| 687 | | | } |
| 688 | | | else |
| 689 | | | { |
| 690 | 0 | | mRootDoc.printWarning(tags[0].position(), warnings); |
| 691 | | | } |
| 692 | | | } |
| 693 | 0 | | } |
| 694 | | | else |
| 695 | | | { |
| 696 | 0 | | clean = input; |
| 697 | | | } |
| 698 | 0 | | data.setLength(0); |
| 699 | 0 | | data.append(clean); |
| 700 | | | |
| 701 | | | |
| 702 | | | int pos; |
| 703 | 0 | | while ((pos = data.indexOf("<a id='SEE_TAG_")) != -1) |
| 704 | | | { |
| 705 | 0 | | mOut.write(data.substring(0, pos)); |
| 706 | 0 | | final int i = Integer.parseInt(data.substring(pos |
| 707 | | | + "<a id='SEE_TAG_".length(), data.indexOf("'></a>", pos))); |
| 708 | 0 | | generateSeeElement((SeeTag) tags[i]); |
| 709 | 0 | | data.delete(0, data.indexOf("'></a>", pos) + "'></a>".length()); |
| 710 | 0 | | } |
| 711 | 0 | | mOut.write(data.toString()); |
| 712 | 0 | | } |
| 713 | | | |
| 714 | | | private void generateSeeElement (SeeTag tag) |
| 715 | | | throws IOException |
| 716 | | | { |
| 717 | 0 | | mOut.write("<see "); |
| 718 | 0 | | generateTagHeader(tag); |
| 719 | 0 | | mOut.write(">"); |
| 720 | | | final String label; |
| 721 | 0 | | if (!StringUtil.isNullOrEmpty(tag.label())) |
| 722 | | | { |
| 723 | 0 | | label = tag.label(); |
| 724 | | | } |
| 725 | 0 | | else if (tag.referencedClassName() != null |
| 726 | | | && tag.referencedMemberName() != null) |
| 727 | | | { |
| 728 | 0 | | label = tag.referencedClassName() + "#" + tag.referencedMemberName(); |
| 729 | | | } |
| 730 | 0 | | else if (tag.referencedClassName() != null) |
| 731 | | | { |
| 732 | 0 | | label = tag.referencedClassName(); |
| 733 | | | } |
| 734 | 0 | | else if (tag.referencedPackage() != null) |
| 735 | | | { |
| 736 | 0 | | label = tag.referencedPackage().name(); |
| 737 | | | } |
| 738 | 0 | | else if (tag.referencedMemberName() != null) |
| 739 | | | { |
| 740 | 0 | | label = tag.referencedMemberName(); |
| 741 | | | } |
| 742 | | | else |
| 743 | | | { |
| 744 | 0 | | label = ""; |
| 745 | | | } |
| 746 | 0 | | mOut.write(XmlUtil.escape(label)); |
| 747 | 0 | | mOut.write("</see>"); |
| 748 | 0 | | } |
| 749 | | | |
| 750 | | | private void generateSourcePositionHeader (SourcePosition position) |
| 751 | | | throws IOException |
| 752 | | | { |
| 753 | 0 | | if (position.file() != null) |
| 754 | | | { |
| 755 | 0 | | addAttribute("file", position.file().getPath()); |
| 756 | | | } |
| 757 | 0 | | addAttribute("line", position.line()); |
| 758 | 0 | | addAttribute("column", position.column()); |
| 759 | 0 | | } |
| 760 | | | |
| 761 | | | private void generateClassHeader (ClassDoc cd) |
| 762 | | | throws IOException |
| 763 | | | { |
| 764 | 0 | | generateProgramElementHeader(cd); |
| 765 | 0 | | addAttribute("abstract", cd.isAbstract()); |
| 766 | 0 | | addAttribute("externalizable", cd.isExternalizable()); |
| 767 | 0 | | addAttribute("serializable", cd.isSerializable()); |
| 768 | 0 | | if (cd.superclass() != null) |
| 769 | | | { |
| 770 | 0 | | addAttribute("superclass", cd.superclass().qualifiedName()); |
| 771 | | | } |
| 772 | 0 | | } |
| 773 | | | |
| 774 | | | private void generateProgramElementHeader (ProgramElementDoc pe) |
| 775 | | | throws IOException |
| 776 | | | { |
| 777 | 0 | | addAttribute("qualified-name", pe.qualifiedName()); |
| 778 | | | |
| 779 | 0 | | if (pe.containingClass() != null) |
| 780 | | | { |
| 781 | 0 | | addAttribute("containing-class", |
| 782 | | | pe.containingClass().qualifiedName()); |
| 783 | | | } |
| 784 | | | |
| 785 | | | final String visibility; |
| 786 | 0 | | if (pe.isPrivate()) |
| 787 | | | { |
| 788 | 0 | | visibility = "private"; |
| 789 | | | } |
| 790 | 0 | | else if (pe.isProtected()) |
| 791 | | | { |
| 792 | 0 | | visibility = "protected"; |
| 793 | | | } |
| 794 | 0 | | else if (pe.isPackagePrivate()) |
| 795 | | | { |
| 796 | 0 | | visibility = "package private"; |
| 797 | | | } |
| 798 | 0 | | else if (pe.isPublic()) |
| 799 | | | { |
| 800 | 0 | | visibility = "public"; |
| 801 | | | } |
| 802 | | | else |
| 803 | | | { |
| 804 | 0 | | throw new RuntimeException("Could not detect access right " + pe); |
| 805 | | | } |
| 806 | 0 | | addAttribute("visibility", visibility); |
| 807 | 0 | | addAttribute("static", pe.isStatic()); |
| 808 | 0 | | addAttribute("final", pe.isFinal()); |
| 809 | 0 | | addAttribute("modifiers", pe.modifiers()); |
| 810 | 0 | | addAttribute("modifier-specifier", |
| 811 | | | String.valueOf(pe.modifierSpecifier())); |
| 812 | | | |
| 813 | 0 | | generateDocHeader(pe); |
| 814 | 0 | | } |
| 815 | | | |
| 816 | | | private void generateDocHeader (Doc doc) |
| 817 | | | throws IOException |
| 818 | | | { |
| 819 | 0 | | addAttribute("name", doc.name()); |
| 820 | 0 | | addAttribute("exception", doc.isException()); |
| 821 | 0 | | addAttribute("error", doc.isError()); |
| 822 | 0 | | addAttribute("ordinary-class", doc.isOrdinaryClass()); |
| 823 | 0 | | if (doc.position() != null) |
| 824 | | | { |
| 825 | 0 | | generateSourcePositionHeader(doc.position()); |
| 826 | | | } |
| 827 | 0 | | if (doc.isInterface()) |
| 828 | | | { |
| 829 | 0 | | addAttribute("type", "interface"); |
| 830 | | | } |
| 831 | 0 | | else if (doc.isClass()) |
| 832 | | | { |
| 833 | 0 | | addAttribute("type", "class"); |
| 834 | | | } |
| 835 | 0 | | } |
| 836 | | | |
| 837 | | | private void addAttribute (String name, boolean value) |
| 838 | | | throws IOException |
| 839 | | | { |
| 840 | 0 | | if (value) |
| 841 | | | { |
| 842 | 0 | | mOut.write(" "); |
| 843 | 0 | | mOut.write(name); |
| 844 | 0 | | mOut.write("='"); |
| 845 | 0 | | mOut.write(name); |
| 846 | 0 | | mOut.write("'"); |
| 847 | | | } |
| 848 | 0 | | } |
| 849 | | | |
| 850 | | | private void addAttribute (String name, int value) |
| 851 | | | throws IOException |
| 852 | | | { |
| 853 | 0 | | addAttribute(name, Integer.toString(value)); |
| 854 | 0 | | } |
| 855 | | | |
| 856 | | | private void addAttribute (String name, String value) |
| 857 | | | throws IOException |
| 858 | | | { |
| 859 | 0 | | if (!StringUtil.isEmptyOrNull(value)) |
| 860 | | | { |
| 861 | 0 | | mOut.write(" "); |
| 862 | 0 | | mOut.write(name); |
| 863 | 0 | | mOut.write("='"); |
| 864 | 0 | | mOut.write(XmlUtil.attributeEscape(value)); |
| 865 | 0 | | mOut.write("'"); |
| 866 | | | } |
| 867 | 0 | | } |
| 868 | | | |
| 869 | | | private void warn (SourcePosition pos, String string, Object parameter) |
| 870 | | | { |
| 871 | 0 | | mRootDoc.printWarning(pos, string + " at " + parameter); |
| 872 | 0 | | } |
| 873 | | | |
| 874 | | | } |