You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DocletProxy.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This file is part of the debugger and core tools for the AspectJ(tm)
  4. * programming language; see http://aspectj.org
  5. *
  6. * The contents of this file are subject to the Mozilla Public License
  7. * Version 1.1 (the "License"); you may not use this file except in
  8. * compliance with the License. You may obtain a copy of the License at
  9. * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is AspectJ.
  17. *
  18. * The Initial Developer of the Original Code is Xerox Corporation. Portions
  19. * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
  20. * All Rights Reserved.
  21. */
  22. package org.aspectj.tools.ajdoc;
  23. import org.aspectj.tools.doclets.standard.AbstractStandard;
  24. import org.aspectj.tools.doclets.standard.Standard;
  25. import com.sun.javadoc.DocErrorReporter;
  26. import com.sun.javadoc.RootDoc;
  27. import java.io.IOException;
  28. import java.util.List;
  29. /**
  30. */
  31. public interface DocletProxy {
  32. public static final DocletProxy STANDARD
  33. = JavadocStandardProxy.SINGLETON;
  34. public static final DocletProxy DEFAULT
  35. = StandardProxy.SINGLETON;
  36. public int optionLength(String arg);
  37. public boolean start(RootDoc root)
  38. throws IOException;
  39. public boolean validOptions(List options, DocErrorReporter handler)
  40. throws IOException;
  41. }
  42. /**
  43. * This proxy delegates to Standard singleton,
  44. * but delays alerts about it being unavailable until first use
  45. */
  46. class StandardProxy implements DocletProxy {
  47. public static final DocletProxy SINGLETON = new StandardProxy();
  48. private StandardProxy() { }
  49. /** check and delegate to standard */
  50. public int optionLength(String arg) {
  51. return Standard.optionLength(arg);
  52. }
  53. /** check and delegate to standard */
  54. public boolean validOptions(List options, DocErrorReporter handler)
  55. throws IOException {
  56. return AbstractStandard.validOptions(docletOptions(options), handler);
  57. }
  58. // todo: validate that this is the expected format for doclet options
  59. protected String[][] docletOptions(List options) {
  60. if ((null == options) || (1 > options.size())) {
  61. return new String[][]{};
  62. }
  63. Object[] ra = options.toArray();
  64. String[] strs = new String[ra.length];
  65. for (int i = 0; i < ra.length; i++) {
  66. strs[i] = (null == ra[i] ? null : ra[i].toString());
  67. }
  68. return new String[][] {strs};
  69. }
  70. /** check and delegate to standard */
  71. public boolean start(RootDoc root) throws IOException {
  72. return Standard.start(root);
  73. }
  74. } // StandardProxy
  75. /**
  76. * This proxy delegates to javadoc Standard singleton.
  77. */
  78. class JavadocStandardProxy implements DocletProxy {
  79. public static final DocletProxy SINGLETON = new JavadocStandardProxy();
  80. private JavadocStandardProxy() { }
  81. /** check and delegate to standard */
  82. public int optionLength(String arg) {
  83. return com.sun.tools.doclets.standard.Standard.optionLength(arg);
  84. }
  85. /** check and delegate to standard */
  86. public boolean validOptions(List options, DocErrorReporter handler)
  87. throws IOException {
  88. return com.sun.tools.doclets.standard.Standard.validOptions(docletOptions(options), handler);
  89. }
  90. // todo: validate that this is the expected format for doclet options
  91. protected String[][] docletOptions(List options) {
  92. if ((null == options) || (1 > options.size())) {
  93. return new String[][]{};
  94. }
  95. Object[] ra = options.toArray();
  96. String[] strs = new String[ra.length];
  97. for (int i = 0; i < ra.length; i++) {
  98. strs[i] = (null == ra[i] ? null : ra[i].toString());
  99. }
  100. return new String[][] {strs};
  101. }
  102. /** check and delegate to standard */
  103. public boolean start(RootDoc root) throws IOException {
  104. return com.sun.tools.doclets.standard.Standard.start(root);
  105. }
  106. } // JavadocStandardProxy
  107. /** Wrap a Throwable as a RuntimeException
  108. * This will render stack trace as the delegate stack trace,
  109. * notwithstanding any call to fillInStackTrace.
  110. class ExceptionWrapper extends RuntimeException {
  111. Throwable delegate;
  112. public ExceptionWrapper(Throwable t) {
  113. delegate = (null == t ? new Error("null") : t);
  114. }
  115. public void printStackTrace() {
  116. delegate.printStackTrace();
  117. }
  118. public void printStackTrace(PrintStream stream) {
  119. delegate.printStackTrace(stream);
  120. }
  121. public void printStackTrace(PrintWriter stream) {
  122. delegate.printStackTrace(stream);
  123. }
  124. public String getMessage() {
  125. return delegate.getMessage();
  126. }
  127. public String getLocalizedMessage() {
  128. return delegate.getLocalizedMessage();
  129. }
  130. public Throwable fillInStackTrace() {
  131. return delegate.fillInStackTrace();
  132. }
  133. }
  134. */