src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AbstractBuilder.java

Wed, 18 Sep 2013 17:13:26 -0700

author
bpatel
date
Wed, 18 Sep 2013 17:13:26 -0700
changeset 2035
a2a5ad0853ed
parent 1985
0e6577980181
child 2071
2c24a04ebfb4
permissions
-rw-r--r--

8015249: javadoc fails to document static final fields in annotation types
Reviewed-by: jjg

duke@1 1 /*
jjg@1985 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.builders;
duke@1 27
duke@1 28 import java.io.*;
duke@1 29 import java.lang.reflect.*;
duke@1 30 import java.util.*;
duke@1 31
jjg@1357 32 import com.sun.tools.doclets.internal.toolkit.*;
jjg@1357 33 import com.sun.tools.doclets.internal.toolkit.util.*;
jjg@1357 34
duke@1 35 /**
duke@1 36 * The superclass for all builders. A builder is a class that provides
duke@1 37 * the structure and content of API documentation. A builder is completely
duke@1 38 * doclet independent which means that any doclet can use builders to
duke@1 39 * construct documentation, as long as it impelements the appropriate
duke@1 40 * writer interfaces. For example, if a doclet wanted to use
duke@1 41 * {@link ConstantsSummaryBuilder} to build a constant summary, all it has to
duke@1 42 * do is implement the ConstantsSummaryWriter interface and pass it to the
duke@1 43 * builder using a WriterFactory.
duke@1 44 *
jjg@1359 45 * <p><b>This is NOT part of any supported API.
jjg@1359 46 * If you write code that depends on this, you do so at your own risk.
jjg@1359 47 * This code and its internal interfaces are subject to change or
jjg@1359 48 * deletion without notice.</b>
duke@1 49 *
duke@1 50 * @author Jamie Ho
duke@1 51 * @since 1.5
duke@1 52 */
duke@1 53
duke@1 54 public abstract class AbstractBuilder {
jjg@1410 55 public static class Context {
jjg@1410 56 /**
jjg@1410 57 * The configuration used in this run of the doclet.
jjg@1410 58 */
jjg@1410 59 final Configuration configuration;
jjg@1410 60
jjg@1410 61 /**
jjg@1410 62 * Keep track of which packages we have seen for
jjg@1410 63 * efficiency purposes. We don't want to copy the
jjg@1410 64 * doc files multiple times for a single package.
jjg@1410 65 */
jjg@1410 66 final Set<String> containingPackagesSeen;
jjg@1410 67
jjg@1410 68 /**
jjg@1410 69 * Shared parser for the builder XML file
jjg@1410 70 */
jjg@1410 71 final LayoutParser layoutParser;
jjg@1410 72
jjg@1410 73 Context(Configuration configuration,
jjg@1410 74 Set<String> containingPackagesSeen,
jjg@1410 75 LayoutParser layoutParser) {
jjg@1410 76 this.configuration = configuration;
jjg@1410 77 this.containingPackagesSeen = containingPackagesSeen;
jjg@1410 78 this.layoutParser = layoutParser;
jjg@1410 79 }
jjg@1410 80 }
duke@1 81
duke@1 82 /**
duke@1 83 * The configuration used in this run of the doclet.
duke@1 84 */
jjg@1410 85 protected final Configuration configuration;
duke@1 86
duke@1 87 /**
duke@1 88 * Keep track of which packages we have seen for
duke@1 89 * efficiency purposes. We don't want to copy the
duke@1 90 * doc files multiple times for a single package.
duke@1 91 */
jjg@1410 92 protected final Set<String> containingPackagesSeen;
jjg@1410 93
jjg@1410 94 protected final LayoutParser layoutParser;
duke@1 95
duke@1 96 /**
duke@1 97 * True if we want to print debug output.
duke@1 98 */
duke@1 99 protected static final boolean DEBUG = false;
duke@1 100
duke@1 101 /**
duke@1 102 * Construct a Builder.
duke@1 103 * @param configuration the configuration used in this run
duke@1 104 * of the doclet.
duke@1 105 */
jjg@1410 106 public AbstractBuilder(Context c) {
jjg@1410 107 this.configuration = c.configuration;
jjg@1410 108 this.containingPackagesSeen = c.containingPackagesSeen;
jjg@1410 109 this.layoutParser = c.layoutParser;
duke@1 110 }
duke@1 111
duke@1 112 /**
duke@1 113 * Return the name of this builder.
duke@1 114 *
duke@1 115 * @return the name of the builder.
duke@1 116 */
duke@1 117 public abstract String getName();
duke@1 118
duke@1 119 /**
duke@1 120 * Build the documentation.
duke@1 121 *
duke@1 122 * @throws IOException there was a problem writing the output.
duke@1 123 */
duke@1 124 public abstract void build() throws IOException;
duke@1 125
duke@1 126 /**
jjg@589 127 * Build the documentation, as specified by the given XML element.
duke@1 128 *
jjg@589 129 * @param node the XML element that specifies which component to document.
bpatel@766 130 * @param contentTree content tree to which the documentation will be added
duke@1 131 */
bpatel@766 132 protected void build(XMLNode node, Content contentTree) {
jjg@589 133 String component = node.name;
jjg@589 134 try {
jjg@589 135 invokeMethod("build" + component,
bpatel@766 136 new Class<?>[]{XMLNode.class, Content.class},
bpatel@766 137 new Object[]{node, contentTree});
jjg@589 138 } catch (NoSuchMethodException e) {
jjg@589 139 e.printStackTrace();
jjg@589 140 configuration.root.printError("Unknown element: " + component);
jjg@1985 141 throw new DocletAbortException(e);
jjg@589 142 } catch (InvocationTargetException e) {
jjg@589 143 e.getCause().printStackTrace();
jjg@589 144 } catch (Exception e) {
jjg@589 145 e.printStackTrace();
jjg@589 146 configuration.root.printError("Exception " +
bpatel@766 147 e.getClass().getName() +
bpatel@766 148 " thrown while processing element: " + component);
jjg@1985 149 throw new DocletAbortException(e);
duke@1 150 }
duke@1 151 }
duke@1 152
duke@1 153 /**
jjg@589 154 * Build the documentation, as specified by the children of the given XML element.
jjg@589 155 *
jjg@589 156 * @param node the XML element that specifies which components to document.
bpatel@766 157 * @param contentTree content tree to which the documentation will be added
jjg@589 158 */
bpatel@766 159 protected void buildChildren(XMLNode node, Content contentTree) {
bpatel@766 160 for (XMLNode child : node.children)
bpatel@766 161 build(child, contentTree);
jjg@589 162 }
jjg@589 163
jjg@589 164 /**
duke@1 165 * Given the name and parameters, invoke the method in the builder. This
duke@1 166 * method is required to invoke the appropriate build method as instructed
duke@1 167 * by the builder XML file.
duke@1 168 *
duke@1 169 * @param methodName the name of the method that we would like to invoke.
duke@1 170 * @param paramClasses the types for each parameter.
duke@1 171 * @param params the parameters of the method.
duke@1 172 */
jjg@589 173 protected void invokeMethod(String methodName, Class<?>[] paramClasses,
duke@1 174 Object[] params)
jjg@589 175 throws Exception {
jjg@589 176 if (DEBUG) {
bpatel@766 177 configuration.root.printError("DEBUG: " + this.getClass().getName() + "." + methodName);
jjg@589 178 }
jjg@589 179 Method method = this.getClass().getMethod(methodName, paramClasses);
jjg@589 180 method.invoke(this, params);
jjg@589 181 }
duke@1 182 }

mercurial