AnnotationTypeFieldBuilder.java revision 3233:b5d08bc0d224
1/*
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package jdk.javadoc.internal.doclets.toolkit.builders;
27
28import java.util.*;
29
30import javax.lang.model.element.Element;
31import javax.lang.model.element.TypeElement;
32
33import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter;
34import jdk.javadoc.internal.doclets.toolkit.Configuration;
35import jdk.javadoc.internal.doclets.toolkit.Content;
36import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap;
37
38
39/**
40 * Builds documentation for annotation type fields.
41 *
42 *  <p><b>This is NOT part of any supported API.
43 *  If you write code that depends on this, you do so at your own risk.
44 *  This code and its internal interfaces are subject to change or
45 *  deletion without notice.</b>
46 *
47 * @author Bhavesh Patel
48 */
49public class AnnotationTypeFieldBuilder extends AbstractMemberBuilder {
50
51    /**
52     * The annotation type whose members are being documented.
53     */
54    protected TypeElement typeElement;
55
56    /**
57     * The visible members for the given class.
58     */
59    protected VisibleMemberMap visibleMemberMap;
60
61    /**
62     * The writer to output the member documentation.
63     */
64    protected AnnotationTypeFieldWriter writer;
65
66    /**
67     * The list of members being documented.
68     */
69    protected SortedSet<Element> members;
70
71    /**
72     * The index of the current member that is being documented at this point
73     * in time.
74     */
75    protected Element currentMember;
76
77    /**
78     * Construct a new AnnotationTypeFieldsBuilder.
79     *
80     * @param context  the build context.
81     * @param typeElement the class whose members are being documented.
82     * @param writer the doclet specific writer.
83     * @param memberType the type of member that is being documented.
84     */
85    protected AnnotationTypeFieldBuilder(Context context,
86            TypeElement typeElement,
87            AnnotationTypeFieldWriter writer,
88            VisibleMemberMap.Kind memberType) {
89        super(context);
90        this.typeElement = typeElement;
91        this.writer = writer;
92        this.visibleMemberMap = new VisibleMemberMap(typeElement, memberType, configuration);
93        this.members = this.visibleMemberMap.getMembersFor(typeElement);
94    }
95
96
97    /**
98     * Construct a new AnnotationTypeFieldBuilder.
99     *
100     * @param context  the build context.
101     * @param typeElement the class whose members are being documented.
102     * @param writer the doclet specific writer.
103     */
104    public static AnnotationTypeFieldBuilder getInstance(
105            Context context, TypeElement typeElement,
106            AnnotationTypeFieldWriter writer) {
107        return new AnnotationTypeFieldBuilder(context, typeElement,
108                    writer, VisibleMemberMap.Kind.ANNOTATION_TYPE_FIELDS);
109    }
110
111    /**
112     * {@inheritDoc}
113     */
114    @Override
115    public String getName() {
116        return "AnnotationTypeFieldDetails";
117    }
118
119    /**
120     * Returns a list of members that will be documented for the given class.
121     * This information can be used for doclet specific documentation
122     * generation.
123     *
124     * @param typeElement the TypeElement we want to check.
125     * @return a list of members that will be documented.
126     */
127    public SortedSet<Element> members(TypeElement typeElement) {
128        return visibleMemberMap.getMembersFor(typeElement);
129    }
130
131    /**
132     * Returns the visible member map for the members of this class.
133     *
134     * @return the visible member map for the members of this class.
135     */
136    public VisibleMemberMap getVisibleMemberMap() {
137        return visibleMemberMap;
138    }
139
140    /**
141     * summaryOrder.size()
142     */
143    @Override
144    public boolean hasMembersToDocument() {
145        return members.size() > 0;
146    }
147
148    /**
149     * Build the annotation type field documentation.
150     *
151     * @param node the XML element that specifies which components to document
152     * @param memberDetailsTree the content tree to which the documentation will be added
153     */
154    public void buildAnnotationTypeField(XMLNode node, Content memberDetailsTree) {
155        buildAnnotationTypeMember(node, memberDetailsTree);
156    }
157
158    /**
159     * Build the member documentation.
160     *
161     * @param node the XML element that specifies which components to document
162     * @param memberDetailsTree the content tree to which the documentation will be added
163     */
164    public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) {
165        if (writer == null) {
166            return;
167        }
168        if (!members.isEmpty()) {
169            writer.addAnnotationFieldDetailsMarker(memberDetailsTree);
170            for (Element element : members) {
171                currentMember = element;
172                Content detailsTree = writer.getMemberTreeHeader();
173                writer.addAnnotationDetailsTreeHeader(typeElement, detailsTree);
174                Content annotationDocTree = writer.getAnnotationDocTreeHeader(element, detailsTree);
175                buildChildren(node, annotationDocTree);
176                detailsTree.addContent(writer.getAnnotationDoc(
177                        annotationDocTree, currentMember == members.last()));
178                memberDetailsTree.addContent(writer.getAnnotationDetails(detailsTree));
179            }
180        }
181    }
182
183    /**
184     * Build the signature.
185     *
186     * @param node the XML element that specifies which components to document
187     * @param annotationDocTree the content tree to which the documentation will be added
188     */
189    public void buildSignature(XMLNode node, Content annotationDocTree) {
190        annotationDocTree.addContent(
191                writer.getSignature(currentMember));
192    }
193
194    /**
195     * Build the deprecation information.
196     *
197     * @param node the XML element that specifies which components to document
198     * @param annotationDocTree the content tree to which the documentation will be added
199     */
200    public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) {
201        writer.addDeprecated(currentMember, annotationDocTree);
202    }
203
204    /**
205     * Build the comments for the member.  Do nothing if
206     * {@link Configuration#nocomment} is set to true.
207     *
208     * @param node the XML element that specifies which components to document
209     * @param annotationDocTree the content tree to which the documentation will be added
210     */
211    public void buildMemberComments(XMLNode node, Content annotationDocTree) {
212        if(! configuration.nocomment){
213            writer.addComments(currentMember, annotationDocTree);
214        }
215    }
216
217    /**
218     * Build the tag information.
219     *
220     * @param node the XML element that specifies which components to document
221     * @param annotationDocTree the content tree to which the documentation will be added
222     */
223    public void buildTagInfo(XMLNode node, Content annotationDocTree) {
224        writer.addTags(currentMember, annotationDocTree);
225    }
226
227    /**
228     * Return the annotation type field writer for this builder.
229     *
230     * @return the annotation type field writer for this builder.
231     */
232    public AnnotationTypeFieldWriter getWriter() {
233        return writer;
234    }
235}
236