1/*
2 * Copyright (c) 2003, 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 javax.lang.model.element.TypeElement;
29
30import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter;
31import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
32import jdk.javadoc.internal.doclets.toolkit.Content;
33import jdk.javadoc.internal.doclets.toolkit.DocletException;
34import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap;
35
36
37/**
38 * Builds documentation for optional annotation type members.
39 *
40 *  <p><b>This is NOT part of any supported API.
41 *  If you write code that depends on this, you do so at your own risk.
42 *  This code and its internal interfaces are subject to change or
43 *  deletion without notice.</b>
44 *
45 * @author Jamie Ho
46 * @author Bhavesh Patel (Modified)
47 */
48public class AnnotationTypeOptionalMemberBuilder extends AnnotationTypeRequiredMemberBuilder {
49
50    /**
51     * Construct a new AnnotationTypeMemberBuilder.
52     *
53     * @param context  the build context.
54     * @param typeElement the class whose members are being documented.
55     * @param writer the doclet specific writer.
56     */
57    private AnnotationTypeOptionalMemberBuilder(Context context,
58            TypeElement typeElement,
59            AnnotationTypeOptionalMemberWriter writer) {
60        super(context, typeElement, writer,
61                VisibleMemberMap.Kind.ANNOTATION_TYPE_MEMBER_OPTIONAL);
62    }
63
64
65    /**
66     * Construct a new AnnotationTypeMemberBuilder.
67     *
68     * @param context  the build context.
69     * @param typeElement the class whose members are being documented.
70     * @param writer the doclet specific writer.
71     * @return the new AnnotationTypeMemberBuilder
72     */
73    public static AnnotationTypeOptionalMemberBuilder getInstance(
74            Context context, TypeElement typeElement,
75            AnnotationTypeOptionalMemberWriter writer) {
76        return new AnnotationTypeOptionalMemberBuilder(context,
77                typeElement, writer);
78    }
79
80    /**
81     * {@inheritDoc}
82     */
83    @Override
84    public String getName() {
85        return "AnnotationTypeOptionalMemberDetails";
86    }
87
88    /**
89     * Build the annotation type optional member documentation.
90     *
91     * @param node the XML element that specifies which components to document
92     * @param memberDetailsTree the content tree to which the documentation will be added
93     * @throws DocletException if there is a problem while building the documentation
94     */
95    public void buildAnnotationTypeOptionalMember(XMLNode node, Content memberDetailsTree)
96                throws DocletException {
97        buildAnnotationTypeMember(node, memberDetailsTree);
98    }
99
100    /**
101     * Build the default value for this optional member.
102     *
103     * @param node the XML element that specifies which components to document
104     * @param annotationDocTree the content tree to which the documentation will be added
105     */
106    public void buildDefaultValueInfo(XMLNode node, Content annotationDocTree) {
107        ((AnnotationTypeOptionalMemberWriter) writer).addDefaultValueInfo(currentMember,
108                annotationDocTree);
109    }
110
111    /**
112     * {@inheritDoc}
113     */
114    @Override
115    public AnnotationTypeRequiredMemberWriter getWriter() {
116        return writer;
117    }
118}
119