langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AnnotationTypeBuilder.java
author ohair
Tue, 25 May 2010 15:54:51 -0700
changeset 5520 86e4b9a9da40
parent 1789 7ac8c0815000
child 5855 00d9c252e60c
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
     2
 * Copyright (c) 2003, 2008, 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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1789
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.builders;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.doclets.internal.toolkit.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.doclets.internal.toolkit.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.javadoc.*;
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 java.lang.reflect.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Builds the summary for a given annotation type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * This code is not part of an API.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * It is implementation that is subject to change.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * Do not use it as an API
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Jamie Ho
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
public class AnnotationTypeBuilder extends AbstractBuilder {
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
     * The root element of the annotation type XML is {@value}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    public static final String ROOT = "AnnotationTypeDoc";
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
     * The annotation type being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    private AnnotationTypeDoc annotationTypeDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     * The doclet specific writer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    private AnnotationTypeWriter writer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * Construct a new ClassBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * @param configuration the current configuration of the
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     *                      doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private AnnotationTypeBuilder(Configuration configuration) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        super(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     * Construct a new ClassBuilder.
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     * @param configuration     the current configuration of the doclet.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @param annotationTypeDoc the class being documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * @param writer            the doclet specific writer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    public static AnnotationTypeBuilder getInstance(Configuration configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer)
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        builder.configuration = configuration;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        builder.annotationTypeDoc = annotationTypeDoc;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        builder.writer = writer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        if(containingPackagesSeen == null) {
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
    87
            containingPackagesSeen = new HashSet<String>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        return builder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
    95
    public void invokeMethod(String methodName, Class<?>[] paramClasses,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
            Object[] params)
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        if (DEBUG) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
            configuration.root.printError("DEBUG: " + this.getClass().getName()
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                + "." + methodName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        Method method = this.getClass().getMethod(methodName, paramClasses);
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        method.invoke(this, params);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public void build() throws IOException {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        build(LayoutParser.getInstance(configuration).parseXML(ROOT));
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public String getName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return ROOT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
      * Handles the &lt;AnnotationTypeDoc> tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
      *
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
      * @param elements the XML elements that specify how to document a class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
      */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   125
     public void buildAnnotationTypeDoc(List<?> elements) throws Exception {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        writer.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        copyDocFiles();
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
      * Copy the doc files for the current ClassDoc if necessary.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
      */
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     private void copyDocFiles() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        PackageDoc containingPackage = annotationTypeDoc.containingPackage();
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        if((configuration.packages == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                Arrays.binarySearch(configuration.packages,
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
                                    containingPackage) < 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
           ! containingPackagesSeen.contains(containingPackage.name())){
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
            //Only copy doc files dir if the containing package is not
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            //documented AND if we have not documented a class from the same
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
            //package already. Otherwise, we are making duplicate copies.
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
            Util.copyDocFiles(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                Util.getPackageSourcePath(configuration,
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
                    annotationTypeDoc.containingPackage()) +
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                DirectoryManager.getDirectoryPath(
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                    annotationTypeDoc.containingPackage())
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                    + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
            containingPackagesSeen.add(containingPackage.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * Build the header of the page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    public void buildAnnotationTypeHeader() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        writer.writeHeader(configuration.getText("doclet.AnnotationType") +
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
            " " + annotationTypeDoc.name());
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * If this class is deprecated, print the appropriate information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public void buildDeprecationInfo () {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        writer.writeAnnotationTypeDeprecationInfo();
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Build the signature of the current annotation type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public void buildAnnotationTypeSignature() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        StringBuffer modifiers = new StringBuffer(
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            annotationTypeDoc.modifiers() + " ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
        writer.writeAnnotationTypeSignature(
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
            Util.replaceText(
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                modifiers.toString(), "interface", "@interface"));
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * Build the class description.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public void buildAnnotationTypeDescription() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
       writer.writeAnnotationTypeDescription();
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     * Build the tag information for the current class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public void buildAnnotationTypeTagInfo() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
       writer.writeAnnotationTypeTagInfo();
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * Build the contents of the page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * @param elements the XML elements that specify how a member summary is
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     *                 documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   200
    public void buildMemberSummary(List<?> elements) throws Exception {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        configuration.getBuilderFactory().
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
            getMemberSummaryBuilder(writer).build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        writer.completeMemberSummaryBuild();
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * Build the annotation type optional member documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * @param elements the XML elements that specify how a annotation type
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     *                 members are documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   212
    public void buildAnnotationTypeOptionalMemberDetails(List<?> elements)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        configuration.getBuilderFactory().
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
            getAnnotationTypeOptionalMemberBuilder(writer).build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * Build the annotation type required member documentation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     * @param elements the XML elements that specify how a annotation type
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     *                 members are documented.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     */
1789
7ac8c0815000 6765045: Remove rawtypes warnings from langtools
mcimadamore
parents: 1264
diff changeset
   224
    public void buildAnnotationTypeRequiredMemberDetails(List<?> elements)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    throws Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        configuration.getBuilderFactory().
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            getAnnotationTypeRequiredMemberBuilder(writer).build(elements);
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * Build the footer of the page.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    public void buildAnnotationTypeFooter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        writer.writeFooter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
}