duke@1: /* ohair@554: * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.builders; duke@1: duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.javadoc.*; duke@1: import java.io.*; duke@1: import java.util.*; duke@1: import java.lang.reflect.*; duke@1: duke@1: /** duke@1: * Builds the summary for a given annotation type. duke@1: * duke@1: * This code is not part of an API. duke@1: * It is implementation that is subject to change. duke@1: * Do not use it as an API duke@1: * duke@1: * @author Jamie Ho duke@1: * @since 1.5 duke@1: */ duke@1: public class AnnotationTypeBuilder extends AbstractBuilder { duke@1: duke@1: /** duke@1: * The root element of the annotation type XML is {@value}. duke@1: */ duke@1: public static final String ROOT = "AnnotationTypeDoc"; duke@1: duke@1: /** duke@1: * The annotation type being documented. duke@1: */ duke@1: private AnnotationTypeDoc annotationTypeDoc; duke@1: duke@1: /** duke@1: * The doclet specific writer. duke@1: */ duke@1: private AnnotationTypeWriter writer; duke@1: duke@1: /** duke@1: * Construct a new ClassBuilder. duke@1: * duke@1: * @param configuration the current configuration of the duke@1: * doclet. duke@1: */ duke@1: private AnnotationTypeBuilder(Configuration configuration) { duke@1: super(configuration); duke@1: } duke@1: duke@1: /** duke@1: * Construct a new ClassBuilder. duke@1: * duke@1: * @param configuration the current configuration of the doclet. duke@1: * @param annotationTypeDoc the class being documented. duke@1: * @param writer the doclet specific writer. duke@1: */ duke@1: public static AnnotationTypeBuilder getInstance(Configuration configuration, duke@1: AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer) duke@1: throws Exception { duke@1: AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration); duke@1: builder.configuration = configuration; duke@1: builder.annotationTypeDoc = annotationTypeDoc; duke@1: builder.writer = writer; duke@1: if(containingPackagesSeen == null) { jjg@74: containingPackagesSeen = new HashSet(); duke@1: } duke@1: return builder; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ mcimadamore@184: public void invokeMethod(String methodName, Class[] paramClasses, duke@1: Object[] params) duke@1: throws Exception { duke@1: if (DEBUG) { duke@1: configuration.root.printError("DEBUG: " + this.getClass().getName() duke@1: + "." + methodName); duke@1: } duke@1: Method method = this.getClass().getMethod(methodName, paramClasses); duke@1: method.invoke(this, params); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public void build() throws IOException { duke@1: build(LayoutParser.getInstance(configuration).parseXML(ROOT)); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public String getName() { duke@1: return ROOT; duke@1: } duke@1: duke@1: /** duke@1: * Handles the <AnnotationTypeDoc> tag. duke@1: * duke@1: * @param elements the XML elements that specify how to document a class. duke@1: */ mcimadamore@184: public void buildAnnotationTypeDoc(List elements) throws Exception { duke@1: build(elements); duke@1: writer.close(); duke@1: copyDocFiles(); duke@1: } duke@1: duke@1: duke@1: /** duke@1: * Copy the doc files for the current ClassDoc if necessary. duke@1: */ duke@1: private void copyDocFiles() { duke@1: PackageDoc containingPackage = annotationTypeDoc.containingPackage(); duke@1: if((configuration.packages == null || duke@1: Arrays.binarySearch(configuration.packages, duke@1: containingPackage) < 0) && duke@1: ! containingPackagesSeen.contains(containingPackage.name())){ duke@1: //Only copy doc files dir if the containing package is not duke@1: //documented AND if we have not documented a class from the same duke@1: //package already. Otherwise, we are making duplicate copies. duke@1: Util.copyDocFiles(configuration, duke@1: Util.getPackageSourcePath(configuration, duke@1: annotationTypeDoc.containingPackage()) + duke@1: DirectoryManager.getDirectoryPath( duke@1: annotationTypeDoc.containingPackage()) duke@1: + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true); duke@1: containingPackagesSeen.add(containingPackage.name()); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Build the header of the page. duke@1: */ duke@1: public void buildAnnotationTypeHeader() { duke@1: writer.writeHeader(configuration.getText("doclet.AnnotationType") + duke@1: " " + annotationTypeDoc.name()); duke@1: } duke@1: duke@1: /** duke@1: * If this class is deprecated, print the appropriate information. duke@1: */ duke@1: public void buildDeprecationInfo () { duke@1: writer.writeAnnotationTypeDeprecationInfo(); duke@1: } duke@1: duke@1: /** duke@1: * Build the signature of the current annotation type. duke@1: */ duke@1: public void buildAnnotationTypeSignature() { duke@1: StringBuffer modifiers = new StringBuffer( duke@1: annotationTypeDoc.modifiers() + " "); duke@1: writer.writeAnnotationTypeSignature( duke@1: Util.replaceText( duke@1: modifiers.toString(), "interface", "@interface")); duke@1: } duke@1: duke@1: /** duke@1: * Build the class description. duke@1: */ duke@1: public void buildAnnotationTypeDescription() { duke@1: writer.writeAnnotationTypeDescription(); duke@1: } duke@1: duke@1: /** duke@1: * Build the tag information for the current class. duke@1: */ duke@1: public void buildAnnotationTypeTagInfo() { duke@1: writer.writeAnnotationTypeTagInfo(); duke@1: } duke@1: duke@1: /** duke@1: * Build the contents of the page. duke@1: * duke@1: * @param elements the XML elements that specify how a member summary is duke@1: * documented. duke@1: */ mcimadamore@184: public void buildMemberSummary(List elements) throws Exception { duke@1: configuration.getBuilderFactory(). duke@1: getMemberSummaryBuilder(writer).build(elements); duke@1: writer.completeMemberSummaryBuild(); duke@1: } duke@1: duke@1: /** duke@1: * Build the annotation type optional member documentation. duke@1: * duke@1: * @param elements the XML elements that specify how a annotation type duke@1: * members are documented. duke@1: */ mcimadamore@184: public void buildAnnotationTypeOptionalMemberDetails(List elements) duke@1: throws Exception { duke@1: configuration.getBuilderFactory(). duke@1: getAnnotationTypeOptionalMemberBuilder(writer).build(elements); duke@1: } duke@1: duke@1: /** duke@1: * Build the annotation type required member documentation. duke@1: * duke@1: * @param elements the XML elements that specify how a annotation type duke@1: * members are documented. duke@1: */ mcimadamore@184: public void buildAnnotationTypeRequiredMemberDetails(List elements) duke@1: throws Exception { duke@1: configuration.getBuilderFactory(). duke@1: getAnnotationTypeRequiredMemberBuilder(writer).build(elements); duke@1: } duke@1: duke@1: duke@1: /** duke@1: * Build the footer of the page. duke@1: */ duke@1: public void buildAnnotationTypeFooter() { duke@1: writer.writeFooter(); duke@1: } duke@1: }