langtools/test/tools/javadoc/lib/OldToolTester.java
author jjg
Fri, 12 Aug 2016 17:45:31 -0700
changeset 40316 20b50a99fe8d
parent 5520 langtools/test/tools/javadoc/lib/Tester.java@86e4b9a9da40
permissions -rw-r--r--
8052398: Uniqify test framework class names Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
40316
20b50a99fe8d 8052398: Uniqify test framework class names
jjg
parents: 5520
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2985
diff changeset
    21
 * questions.
10
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
40316
20b50a99fe8d 8052398: Uniqify test framework class names
jjg
parents: 5520
diff changeset
    36
public class OldToolTester {
10
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
        "-sourcepath", TEST_SRC,
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    private final File outputFile = new File(TEST_CLASSES, "testrun.out");
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    private final File expectedOutputFile = new File(TEST_SRC, "expected.out");
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
//  private final File bootstrapMarkerFile = new File("bootstrap");
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    // True if we should "set expectations" by writing the expected output file
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    // rather than reading it and comparing.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
//  private final boolean bootstrap = bootstrapMarkerFile.isFile();
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    private String docletName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    private String[] args;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    private Writer out = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * Individual tests can extend this to create generics-aware doclets.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    public static abstract class Doclet extends com.sun.javadoc.Doclet {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        public static LanguageVersion languageVersion() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
            return LanguageVersion.JAVA_1_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
40316
20b50a99fe8d 8052398: Uniqify test framework class names
jjg
parents: 5520
diff changeset
    68
    public OldToolTester(String docletName) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        this(docletName, new String[0]);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
40316
20b50a99fe8d 8052398: Uniqify test framework class names
jjg
parents: 5520
diff changeset
    72
    public OldToolTester(String docletName, String... additionalArgs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        this.docletName = docletName;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        int len = DEFAULT_ARGS.length + additionalArgs.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        args = new String[len];
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        System.arraycopy(DEFAULT_ARGS, 0, args, 0, DEFAULT_ARGS.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        System.arraycopy(additionalArgs, 0, args, DEFAULT_ARGS.length,
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
                         additionalArgs.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
            out = new BufferedWriter(new FileWriter(outputFile));
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        } catch (IOException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            throw new Error("Could not open output file " + outputFile);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    public void run() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            if (com.sun.tools.javadoc.Main.execute("javadoc",
1475
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    91
                                                   docletName,
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    92
                                                   getClass().getClassLoader(),
19c0851667ca 6748541: javadoc should be reusable
jjg
parents: 10
diff changeset
    93
                                                   args) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                throw new Error("Javadoc errors encountered.");
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            System.out.println("--> Output written to " + outputFile);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
            out.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        }
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
     * Compare output of test run to expected output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * Throw an Error if they don't match.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    public void verify() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        BufferedReader thisRun =
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            new BufferedReader(new FileReader(outputFile));
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        BufferedReader expected =
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            new BufferedReader(new FileReader(expectedOutputFile));
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        for (int lineNum = 1; true; lineNum++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            String line1 = thisRun.readLine();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
            String line2 = expected.readLine();
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
            if (line1 == null && line2 == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                return;         // EOF with all lines matching
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
            if (line1 == null || !line1.equals(line2)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                throw new Error(outputFile + ":" + lineNum +
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                                ": output doesn't match");
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
            }
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
    public void println(Object o) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        prln(0, o);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    public void println() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        prln();
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    public void printPackage(PackageDoc p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        prPackage(0, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public void printClass(ClassDoc cd) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        if (cd.isAnnotationType())
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            printAnnotationType((AnnotationTypeDoc)cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            prClass(0, cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    public void printAnnotationType(AnnotationTypeDoc at) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        prAnnotationType(0, at);
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    public void printField(FieldDoc f) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        prField(0, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    public void printParameter(Parameter p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        prParameter(0, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    public void printMethod(MethodDoc m) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        prln(0, "method " + m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        prMethod(0, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public void printAnnotationTypeElement(AnnotationTypeElementDoc e)
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        prln(0, "element " + e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        prMethod(0, e);
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public void printConstructor(ConstructorDoc c) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        prln(0, "constructor " + c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        prExecutable(0, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    private void prPackage(int off, PackageDoc p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        prln(off, "package " + p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        prAnnotations(off + 2, p.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    private void prClass(int off, ClassDoc cd) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        prln(off,
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
             (cd.isInterface() ? "interface" : cd.isEnum() ? "enum" : "class")
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
             + " " + cd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        prln(off + 2, "name: " + cd.simpleTypeName() + " / " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
             cd.typeName() + " / " + cd.qualifiedTypeName());
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        prAnnotations(off + 2, cd.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        prLabel(off + 2, "type parameters");
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        for (Type t : cd.typeParameters())
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        prParamTags(off + 2, cd.typeParamTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        prLabel(off + 2, "nested in");
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        prln(off + 4, cd.containingClass());
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        prLabel(off + 2, "superclass");
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
        prln(off + 4, cd.superclassType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        prLabel(off + 2, "interfaces");
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        Type[] ts = cd.interfaceTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        Arrays.sort(ts);
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        for (Type t : ts)
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        prLabel(off + 2, "enum constants");
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        for (FieldDoc f : cd.enumConstants())
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            prln(off + 4, f.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        prLabel(off + 2, "fields");
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        for (FieldDoc f : cd.fields())
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            prln(off + 4, f.type() + " " + f.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        prLabel(off + 2, "constructors");
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        for (ConstructorDoc c : cd.constructors())
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            prln(off + 4, c.name() + c.flatSignature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        prLabel(off + 2, "methods");
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        for (MethodDoc m : cd.methods())
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            prln(off + 4, typeUseString(m.returnType()) + " " +
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                          m.name() + m.flatSignature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    private void prAnnotationType(int off, AnnotationTypeDoc at)
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        prln(off, "@interface " + at);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
        prAnnotations(off + 2, at.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        prLabel(off + 2, "elements");
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        for (AnnotationTypeElementDoc e : at.elements()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            String def = (e.defaultValue() == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                                ? ""
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                                : " default " + e.defaultValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            prln(off + 4, typeUseString(e.returnType()) + " " + e.name() +
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                          e.flatSignature() + def);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    private void prField(int off, FieldDoc f) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        prln(off, "field " + typeUseString(f.type()) + " " + f.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        prAnnotations(off + 2, f.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    private void prParameter(int off, Parameter p) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        prln(off, "parameter " + p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        prAnnotations(off + 2, p.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    private void prMethod(int off, MethodDoc m) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        prExecutable(off, m);
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        prLabel(off + 2, "returns");
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        prln(off + 4, typeUseString(m.returnType()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        prLabel(off + 2, "overridden type");
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        prln(off + 4, m.overriddenType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    private void prExecutable(int off, ExecutableMemberDoc m)
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
        if (!m.isAnnotationTypeElement()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            prln(off + 2, "signature: " + m.flatSignature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
            prln(off + 2, "           " + m.signature());
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        prAnnotations(off + 2, m.annotations());
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        prParamTags(off + 2, m.typeParamTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
        prParamTags(off + 2, m.paramTags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        prLabel(off + 2, "type parameters");
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        for (Type t : m.typeParameters())
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        prLabel(off + 2, "throws");
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        Type[] ts = m.thrownExceptionTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        Arrays.sort(ts);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        for (Type t : ts)
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            prln(off + 4, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    private void prAnnotations(int off, AnnotationDesc[] as)
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                                                        throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        prLabel(off, "annotations");
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        for (AnnotationDesc a : as)
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
            prln(off + 2, a.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    private void prParamTags(int off, ParamTag tags[]) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        for (ParamTag tag : tags)
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            prParamTag(off, tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    private void prParamTag(int off, ParamTag tag) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        String name = tag.parameterName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        if (tag.isTypeParameter()) name = "<" + name + ">";
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        prln(off, "@param " + name + " " + tag.parameterComment());
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    private String typeUseString(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        return (t instanceof ClassDoc || t instanceof TypeVariable)
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                ? t.typeName()
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
                : t.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    // Labels queued for possible printing.  Innermost is first in list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    List<Line> labels = new ArrayList<Line>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    // Print label if its section is nonempty.
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    void prLabel(int off, String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        while (!labels.isEmpty() && labels.get(0).off >= off)
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            labels.remove(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        labels.add(0, new Line(off, s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    // Print queued labels with offsets less than "off".
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
    void popLabels(int off) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        while (!labels.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            Line label = labels.remove(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            if (label.off < off)
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                prln(label.off, label.o + ":");
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    // Print "o" at given offset.
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
    void pr(int off, Object o) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        popLabels(off);
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        for (int i = 0; i < off; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
            out.write(' ');
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        if (o != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            out.write(o.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
    // Print "o" (if non-null) at given offset, then newline.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    void prln(int off, Object o) throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        if (o != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            pr(off, o);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            prln();
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    // Print newline.
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
    void prln() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        out.write('\n');        // don't want platform-dependent separator
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    static class Line {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        int off;
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        Object o;
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        Line(int off, Object o) { this.off = off; this.o = o; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
}