langtools/test/tools/javadoc/lib/Tester.java
author jjg
Wed, 15 Oct 2008 08:07:59 -0700
changeset 1475 19c0851667ca
parent 10 06bc494ca11e
child 1652 1324f96f3883
permissions -rw-r--r--
6748541: javadoc should be reusable Reviewed-by: bpatel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * A utility used to invoke and test the javadoc tool.
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
public class Tester {
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
    protected final String TEST_SRC = System.getProperty("test.src", ".");
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
    protected final String TEST_CLASSES = System.getProperty("test.classes",
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
                                                             ".");
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    private final String DEFAULT_ARGS[] = {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        "-source", "1.5",
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        "-sourcepath", TEST_SRC,
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    private final File outputFile = new File(TEST_CLASSES, "testrun.out");
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    private final File expectedOutputFile = new File(TEST_SRC, "expected.out");
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
//  private final File bootstrapMarkerFile = new File("bootstrap");
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    // True if we should "set expectations" by writing the expected output file
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    // rather than reading it and comparing.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
//  private final boolean bootstrap = bootstrapMarkerFile.isFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    private String docletName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    private String[] args;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    private Writer out = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     * Individual tests can extend this to create generics-aware doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    public static abstract class Doclet extends com.sun.javadoc.Doclet {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
        public static LanguageVersion languageVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
            return LanguageVersion.JAVA_1_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public Tester(String docletName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        this(docletName, new String[0]);
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public Tester(String docletName, String... additionalArgs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        this.docletName = docletName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        int len = DEFAULT_ARGS.length + additionalArgs.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        args = new String[len];
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        System.arraycopy(DEFAULT_ARGS, 0, args, 0, DEFAULT_ARGS.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        System.arraycopy(additionalArgs, 0, args, DEFAULT_ARGS.length,
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                         additionalArgs.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            out = new BufferedWriter(new FileWriter(outputFile));
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            throw new Error("Could not open output file " + outputFile);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    public void run() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            if (com.sun.tools.javadoc.Main.execute("javadoc",
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    92
                                                   docletName,
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    93
                                                   getClass().getClassLoader(),
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    94
                                                   args) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
                throw new Error("Javadoc errors encountered.");
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
            System.out.println("--> Output written to " + outputFile);
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            out.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * Compare output of test run to expected output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     * Throw an Error if they don't match.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    public void verify() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        BufferedReader thisRun =
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            new BufferedReader(new FileReader(outputFile));
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        BufferedReader expected =
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
            new BufferedReader(new FileReader(expectedOutputFile));
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        for (int lineNum = 1; true; lineNum++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            String line1 = thisRun.readLine();
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            String line2 = expected.readLine();
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
            if (line1 == null && line2 == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                return;         // EOF with all lines matching
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            if (line1 == null || !line1.equals(line2)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                throw new Error(outputFile + ":" + lineNum +
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                                ": output doesn't match");
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public void println(Object o) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        prln(0, o);
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public void println() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        prln();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    public void printPackage(PackageDoc p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        prPackage(0, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    public void printClass(ClassDoc cd) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        if (cd.isAnnotationType())
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            printAnnotationType((AnnotationTypeDoc)cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            prClass(0, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    public void printAnnotationType(AnnotationTypeDoc at) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        prAnnotationType(0, at);
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    public void printField(FieldDoc f) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        prField(0, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    public void printParameter(Parameter p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        prParameter(0, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    public void printMethod(MethodDoc m) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        prln(0, "method " + m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        prMethod(0, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    public void printAnnotationTypeElement(AnnotationTypeElementDoc e)
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        prln(0, "element " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        prMethod(0, e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public void printConstructor(ConstructorDoc c) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        prln(0, "constructor " + c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        prExecutable(0, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    private void prPackage(int off, PackageDoc p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        prln(off, "package " + p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        prAnnotations(off + 2, p.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    private void prClass(int off, ClassDoc cd) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        prln(off,
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
             (cd.isInterface() ? "interface" : cd.isEnum() ? "enum" : "class")
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
             + " " + cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        prln(off + 2, "name: " + cd.simpleTypeName() + " / " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
             cd.typeName() + " / " + cd.qualifiedTypeName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        prAnnotations(off + 2, cd.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        prLabel(off + 2, "type parameters");
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        for (Type t : cd.typeParameters())
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        prParamTags(off + 2, cd.typeParamTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        prLabel(off + 2, "nested in");
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        prln(off + 4, cd.containingClass());
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        prLabel(off + 2, "superclass");
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        prln(off + 4, cd.superclassType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        prLabel(off + 2, "interfaces");
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        Type[] ts = cd.interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        Arrays.sort(ts);
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        for (Type t : ts)
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        prLabel(off + 2, "enum constants");
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        for (FieldDoc f : cd.enumConstants())
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
            prln(off + 4, f.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        prLabel(off + 2, "fields");
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        for (FieldDoc f : cd.fields())
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            prln(off + 4, f.type() + " " + f.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        prLabel(off + 2, "constructors");
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        for (ConstructorDoc c : cd.constructors())
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            prln(off + 4, c.name() + c.flatSignature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        prLabel(off + 2, "methods");
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        for (MethodDoc m : cd.methods())
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            prln(off + 4, typeUseString(m.returnType()) + " " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                          m.name() + m.flatSignature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    private void prAnnotationType(int off, AnnotationTypeDoc at)
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        prln(off, "@interface " + at);
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        prAnnotations(off + 2, at.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        prLabel(off + 2, "elements");
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        for (AnnotationTypeElementDoc e : at.elements()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            String def = (e.defaultValue() == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                                ? ""
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                                : " default " + e.defaultValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            prln(off + 4, typeUseString(e.returnType()) + " " + e.name() +
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                          e.flatSignature() + def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    private void prField(int off, FieldDoc f) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        prln(off, "field " + typeUseString(f.type()) + " " + f.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        prAnnotations(off + 2, f.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    private void prParameter(int off, Parameter p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        prln(off, "parameter " + p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        prAnnotations(off + 2, p.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
    private void prMethod(int off, MethodDoc m) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        prExecutable(off, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        prLabel(off + 2, "returns");
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        prln(off + 4, typeUseString(m.returnType()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        prLabel(off + 2, "overridden type");
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        prln(off + 4, m.overriddenType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    private void prExecutable(int off, ExecutableMemberDoc m)
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
        if (!m.isAnnotationTypeElement()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            prln(off + 2, "signature: " + m.flatSignature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            prln(off + 2, "           " + m.signature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        prAnnotations(off + 2, m.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        prParamTags(off + 2, m.typeParamTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        prParamTags(off + 2, m.paramTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        prLabel(off + 2, "type parameters");
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
        for (Type t : m.typeParameters())
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        prLabel(off + 2, "throws");
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        Type[] ts = m.thrownExceptionTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        Arrays.sort(ts);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        for (Type t : ts)
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    private void prAnnotations(int off, AnnotationDesc[] as)
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        prLabel(off, "annotations");
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        for (AnnotationDesc a : as)
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            prln(off + 2, a.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    private void prParamTags(int off, ParamTag tags[]) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        for (ParamTag tag : tags)
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
            prParamTag(off, tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    private void prParamTag(int off, ParamTag tag) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        String name = tag.parameterName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        if (tag.isTypeParameter()) name = "<" + name + ">";
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
        prln(off, "@param " + name + " " + tag.parameterComment());
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
    private String typeUseString(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        return (t instanceof ClassDoc || t instanceof TypeVariable)
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                ? t.typeName()
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
                : t.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    // Labels queued for possible printing.  Innermost is first in list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    List<Line> labels = new ArrayList<Line>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    // Print label if its section is nonempty.
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    void prLabel(int off, String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        while (!labels.isEmpty() && labels.get(0).off >= off)
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
            labels.remove(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        labels.add(0, new Line(off, s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    // Print queued labels with offsets less than "off".
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    void popLabels(int off) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        while (!labels.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            Line label = labels.remove(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            if (label.off < off)
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                prln(label.off, label.o + ":");
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    // Print "o" at given offset.
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    void pr(int off, Object o) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        popLabels(off);
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        for (int i = 0; i < off; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            out.write(' ');
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        if (o != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            out.write(o.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    // Print "o" (if non-null) at given offset, then newline.
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    void prln(int off, Object o) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        if (o != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            pr(off, o);
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            prln();
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    // Print newline.
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    void prln() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        out.write('\n');        // don't want platform-dependent separator
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    static class Line {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        int off;
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        Object o;
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        Line(int off, Object o) { this.off = off; this.o = o; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
}