duke@1: /*
jjg@1357: * Copyright (c) 2003, 2012, 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:
bpatel@766: import java.io.*;
bpatel@766: import java.util.*;
jjg@1357:
jjg@1357: import com.sun.javadoc.*;
jjg@1357: import com.sun.tools.doclets.internal.toolkit.*;
duke@1: import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1:
duke@1: /**
duke@1: * Builds the summary for a given annotation type.
duke@1: *
jjg@1359: *
This is NOT part of any supported API.
jjg@1359: * If you write code that depends on this, you do so at your own risk.
jjg@1359: * This code and its internal interfaces are subject to change or
jjg@1359: * deletion without notice.
duke@1: *
duke@1: * @author Jamie Ho
bpatel@766: * @author Bhavesh Patel (Modified)
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: /**
bpatel@766: * The content tree for the annotation documentation.
bpatel@766: */
bpatel@766: private Content contentTree;
bpatel@766:
bpatel@766: /**
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: */
duke@1: public void build() throws IOException {
bpatel@766: build(LayoutParser.getInstance(configuration).parseXML(ROOT), contentTree);
duke@1: }
duke@1:
duke@1: /**
duke@1: * {@inheritDoc}
duke@1: */
duke@1: public String getName() {
duke@1: return ROOT;
duke@1: }
duke@1:
bpatel@766: /**
bpatel@766: * Build the annotation type documentation.
duke@1: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param contentTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeDoc(XMLNode node, Content contentTree) throws Exception {
bpatel@766: contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") +
bpatel@766: " " + annotationTypeDoc.name());
bpatel@766: Content annotationContentTree = writer.getAnnotationContentHeader();
bpatel@766: buildChildren(node, annotationContentTree);
bpatel@766: contentTree.addContent(annotationContentTree);
bpatel@766: writer.addFooter(contentTree);
bpatel@766: writer.printDocument(contentTree);
bpatel@766: writer.close();
bpatel@766: copyDocFiles();
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,
jjg@1372: new File(Util.getPackageSourcePath(configuration, containingPackage),
jjg@1372: DocPath.forPackage(annotationTypeDoc).getPath()),
jjg@1372: DocPaths.DOC_FILES, true);
duke@1: containingPackagesSeen.add(containingPackage.name());
duke@1: }
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * Build the annotation information tree documentation.
bpatel@766: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationContentTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) {
bpatel@766: Content annotationInfoTree = writer.getAnnotationInfoTreeHeader();
bpatel@766: buildChildren(node, annotationInfoTree);
bpatel@766: annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree));
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * If this annotation is deprecated, build the appropriate information.
bpatel@766: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationInfoTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) {
bpatel@766: writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Build the signature of the current annotation type.
bpatel@766: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationInfoTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
jjg@1362: StringBuilder modifiers = new StringBuilder(
bpatel@766: annotationTypeDoc.modifiers() + " ");
bpatel@766: writer.addAnnotationTypeSignature(Util.replaceText(
bpatel@766: modifiers.toString(), "interface", "@interface"), annotationInfoTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * Build the annotation type description.
bpatel@766: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationInfoTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) {
bpatel@766: writer.addAnnotationTypeDescription(annotationInfoTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * Build the tag information for the current annotation type.
bpatel@766: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationInfoTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) {
bpatel@766: writer.addAnnotationTypeTagInfo(annotationInfoTree);
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * Build the member summary contents of the page.
duke@1: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationContentTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildMemberSummary(XMLNode node, Content annotationContentTree)
bpatel@766: throws Exception {
bpatel@766: Content memberSummaryTree = writer.getMemberTreeHeader();
duke@1: configuration.getBuilderFactory().
bpatel@766: getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
bpatel@766: annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
bpatel@766: }
bpatel@766:
bpatel@766: /**
bpatel@766: * Build the member details contents of the page.
bpatel@766: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param annotationContentTree the content tree to which the documentation will be added
bpatel@766: */
bpatel@766: public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
bpatel@766: Content memberDetailsTree = writer.getMemberTreeHeader();
bpatel@766: buildChildren(node, memberDetailsTree);
bpatel@766: if (memberDetailsTree.isValid()) {
bpatel@766: Content memberDetails = writer.getMemberTreeHeader();
bpatel@766: writer.addAnnotationDetailsMarker(memberDetails);
bpatel@766: memberDetails.addContent(writer.getMemberTree(memberDetailsTree));
bpatel@766: annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails));
bpatel@766: }
duke@1: }
duke@1:
duke@1: /**
duke@1: * Build the annotation type optional member documentation.
duke@1: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param memberDetailsTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree)
bpatel@766: throws Exception {
duke@1: configuration.getBuilderFactory().
bpatel@766: getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree);
duke@1: }
duke@1:
duke@1: /**
duke@1: * Build the annotation type required member documentation.
duke@1: *
bpatel@766: * @param node the XML element that specifies which components to document
bpatel@766: * @param memberDetailsTree the content tree to which the documentation will be added
duke@1: */
bpatel@766: public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree)
bpatel@766: throws Exception {
duke@1: configuration.getBuilderFactory().
bpatel@766: getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree);
duke@1: }
duke@1: }