aoqi@0: /*
aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0: *
aoqi@0: * This code is free software; you can redistribute it and/or modify it
aoqi@0: * under the terms of the GNU General Public License version 2 only, as
aoqi@0: * published by the Free Software Foundation. Oracle designates this
aoqi@0: * particular file as subject to the "Classpath" exception as provided
aoqi@0: * by Oracle in the LICENSE file that accompanied this code.
aoqi@0: *
aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0: * accompanied this code).
aoqi@0: *
aoqi@0: * You should have received a copy of the GNU General Public License version
aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0: *
aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0: * or visit www.oracle.com if you need additional information or have any
aoqi@0: * questions.
aoqi@0: */
aoqi@0:
aoqi@0: package com.sun.tools.doclets.internal.toolkit.builders;
aoqi@0:
aoqi@0: import java.util.*;
aoqi@0:
aoqi@0: import com.sun.javadoc.*;
aoqi@0: import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0:
aoqi@0: /**
aoqi@0: * Builds documentation for required annotation type members.
aoqi@0: *
aoqi@0: *
This is NOT part of any supported API.
aoqi@0: * If you write code that depends on this, you do so at your own risk.
aoqi@0: * This code and its internal interfaces are subject to change or
aoqi@0: * deletion without notice.
aoqi@0: *
aoqi@0: * @author Jamie Ho
aoqi@0: * @author Bhavesh Patel (Modified)
aoqi@0: * @since 1.5
aoqi@0: */
aoqi@0: public class AnnotationTypeRequiredMemberBuilder extends AbstractMemberBuilder {
aoqi@0:
aoqi@0: /**
aoqi@0: * The annotation type whose members are being documented.
aoqi@0: */
aoqi@0: protected ClassDoc classDoc;
aoqi@0:
aoqi@0: /**
aoqi@0: * The visible members for the given class.
aoqi@0: */
aoqi@0: protected VisibleMemberMap visibleMemberMap;
aoqi@0:
aoqi@0: /**
aoqi@0: * The writer to output the member documentation.
aoqi@0: */
aoqi@0: protected AnnotationTypeRequiredMemberWriter writer;
aoqi@0:
aoqi@0: /**
aoqi@0: * The list of members being documented.
aoqi@0: */
aoqi@0: protected List members;
aoqi@0:
aoqi@0: /**
aoqi@0: * The index of the current member that is being documented at this point
aoqi@0: * in time.
aoqi@0: */
aoqi@0: protected int currentMemberIndex;
aoqi@0:
aoqi@0: /**
aoqi@0: * Construct a new AnnotationTypeRequiredMemberBuilder.
aoqi@0: *
aoqi@0: * @param context the build context.
aoqi@0: * @param classDoc the class whose members are being documented.
aoqi@0: * @param writer the doclet specific writer.
aoqi@0: */
aoqi@0: protected AnnotationTypeRequiredMemberBuilder(Context context,
aoqi@0: ClassDoc classDoc,
aoqi@0: AnnotationTypeRequiredMemberWriter writer,
aoqi@0: int memberType) {
aoqi@0: super(context);
aoqi@0: this.classDoc = classDoc;
aoqi@0: this.writer = writer;
aoqi@0: this.visibleMemberMap = new VisibleMemberMap(classDoc, memberType,
aoqi@0: configuration);
aoqi@0: this.members = new ArrayList(
aoqi@0: this.visibleMemberMap.getMembersFor(classDoc));
aoqi@0: if (configuration.getMemberComparator() != null) {
aoqi@0: Collections.sort(this.members, configuration.getMemberComparator());
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0:
aoqi@0: /**
aoqi@0: * Construct a new AnnotationTypeMemberBuilder.
aoqi@0: *
aoqi@0: * @param context the build context.
aoqi@0: * @param classDoc the class whose members are being documented.
aoqi@0: * @param writer the doclet specific writer.
aoqi@0: */
aoqi@0: public static AnnotationTypeRequiredMemberBuilder getInstance(
aoqi@0: Context context, ClassDoc classDoc,
aoqi@0: AnnotationTypeRequiredMemberWriter writer) {
aoqi@0: return new AnnotationTypeRequiredMemberBuilder(context, classDoc,
aoqi@0: writer,
aoqi@0: VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * {@inheritDoc}
aoqi@0: */
aoqi@0: public String getName() {
aoqi@0: return "AnnotationTypeRequiredMemberDetails";
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Returns a list of members that will be documented for the given class.
aoqi@0: * This information can be used for doclet specific documentation
aoqi@0: * generation.
aoqi@0: *
aoqi@0: * @param classDoc the {@link ClassDoc} we want to check.
aoqi@0: * @return a list of members that will be documented.
aoqi@0: */
aoqi@0: public List members(ClassDoc classDoc) {
aoqi@0: return visibleMemberMap.getMembersFor(classDoc);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Returns the visible member map for the members of this class.
aoqi@0: *
aoqi@0: * @return the visible member map for the members of this class.
aoqi@0: */
aoqi@0: public VisibleMemberMap getVisibleMemberMap() {
aoqi@0: return visibleMemberMap;
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * summaryOrder.size()
aoqi@0: */
aoqi@0: public boolean hasMembersToDocument() {
aoqi@0: return members.size() > 0;
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Build the annotation type required member documentation.
aoqi@0: *
aoqi@0: * @param node the XML element that specifies which components to document
aoqi@0: * @param memberDetailsTree the content tree to which the documentation will be added
aoqi@0: */
aoqi@0: public void buildAnnotationTypeRequiredMember(XMLNode node, Content memberDetailsTree) {
aoqi@0: buildAnnotationTypeMember(node, memberDetailsTree);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Build the member documentation.
aoqi@0: *
aoqi@0: * @param node the XML element that specifies which components to document
aoqi@0: * @param memberDetailsTree the content tree to which the documentation will be added
aoqi@0: */
aoqi@0: public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) {
aoqi@0: if (writer == null) {
aoqi@0: return;
aoqi@0: }
aoqi@0: int size = members.size();
aoqi@0: if (size > 0) {
aoqi@0: writer.addAnnotationDetailsMarker(memberDetailsTree);
aoqi@0: for (currentMemberIndex = 0; currentMemberIndex < size;
aoqi@0: currentMemberIndex++) {
aoqi@0: Content detailsTree = writer.getMemberTreeHeader();
aoqi@0: writer.addAnnotationDetailsTreeHeader(classDoc, detailsTree);
aoqi@0: Content annotationDocTree = writer.getAnnotationDocTreeHeader(
aoqi@0: (MemberDoc) members.get(currentMemberIndex), detailsTree);
aoqi@0: buildChildren(node, annotationDocTree);
aoqi@0: detailsTree.addContent(writer.getAnnotationDoc(
aoqi@0: annotationDocTree, (currentMemberIndex == size - 1)));
aoqi@0: memberDetailsTree.addContent(writer.getAnnotationDetails(detailsTree));
aoqi@0: }
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Build the signature.
aoqi@0: *
aoqi@0: * @param node the XML element that specifies which components to document
aoqi@0: * @param annotationDocTree the content tree to which the documentation will be added
aoqi@0: */
aoqi@0: public void buildSignature(XMLNode node, Content annotationDocTree) {
aoqi@0: annotationDocTree.addContent(
aoqi@0: writer.getSignature((MemberDoc) members.get(currentMemberIndex)));
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Build the deprecation information.
aoqi@0: *
aoqi@0: * @param node the XML element that specifies which components to document
aoqi@0: * @param annotationDocTree the content tree to which the documentation will be added
aoqi@0: */
aoqi@0: public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) {
aoqi@0: writer.addDeprecated((MemberDoc) members.get(currentMemberIndex),
aoqi@0: annotationDocTree);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Build the comments for the member. Do nothing if
aoqi@0: * {@link Configuration#nocomment} is set to true.
aoqi@0: *
aoqi@0: * @param node the XML element that specifies which components to document
aoqi@0: * @param annotationDocTree the content tree to which the documentation will be added
aoqi@0: */
aoqi@0: public void buildMemberComments(XMLNode node, Content annotationDocTree) {
aoqi@0: if(! configuration.nocomment){
aoqi@0: writer.addComments((MemberDoc) members.get(currentMemberIndex),
aoqi@0: annotationDocTree);
aoqi@0: }
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Build the tag information.
aoqi@0: *
aoqi@0: * @param node the XML element that specifies which components to document
aoqi@0: * @param annotationDocTree the content tree to which the documentation will be added
aoqi@0: */
aoqi@0: public void buildTagInfo(XMLNode node, Content annotationDocTree) {
aoqi@0: writer.addTags((MemberDoc) members.get(currentMemberIndex),
aoqi@0: annotationDocTree);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Return the annotation type required member writer for this builder.
aoqi@0: *
aoqi@0: * @return the annotation type required member constant writer for this
aoqi@0: * builder.
aoqi@0: */
aoqi@0: public AnnotationTypeRequiredMemberWriter getWriter() {
aoqi@0: return writer;
aoqi@0: }
aoqi@0: }