1 /*
2  * Copyright (c) 2003, 2018, 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 
26 package jdk.javadoc.internal.doclets.toolkit.builders;
27 
28 import javax.lang.model.element.TypeElement;
29 
30 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter;
31 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
32 import jdk.javadoc.internal.doclets.toolkit.Content;
33 import jdk.javadoc.internal.doclets.toolkit.DocletException;
34 
35 import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberTable.Kind.*;
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  */
48 public 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      */
AnnotationTypeOptionalMemberBuilder(Context context, TypeElement typeElement, AnnotationTypeOptionalMemberWriter writer)57     private AnnotationTypeOptionalMemberBuilder(Context context,
58             TypeElement typeElement,
59             AnnotationTypeOptionalMemberWriter writer) {
60         super(context, typeElement, writer, ANNOTATION_TYPE_MEMBER_OPTIONAL);
61     }
62 
63 
64     /**
65      * Construct a new AnnotationTypeMemberBuilder.
66      *
67      * @param context  the build context.
68      * @param typeElement the class whose members are being documented.
69      * @param writer the doclet specific writer.
70      * @return the new AnnotationTypeMemberBuilder
71      */
getInstance( Context context, TypeElement typeElement, AnnotationTypeOptionalMemberWriter writer)72     public static AnnotationTypeOptionalMemberBuilder getInstance(
73             Context context, TypeElement typeElement,
74             AnnotationTypeOptionalMemberWriter writer) {
75         return new AnnotationTypeOptionalMemberBuilder(context,
76                 typeElement, writer);
77     }
78 
79     /**
80      * {@inheritDoc}
81      */
82     @Override
build(Content contentTree)83     public void build(Content contentTree) throws DocletException {
84         buildAnnotationTypeOptionalMember(contentTree);
85     }
86 
87     /**
88      * Build the annotation type optional member documentation.
89      *
90      * @param memberDetailsTree the content tree to which the documentation will be added
91      * @throws DocletException if there is a problem while building the documentation
92      */
buildAnnotationTypeOptionalMember(Content memberDetailsTree)93     protected void buildAnnotationTypeOptionalMember(Content memberDetailsTree)
94                 throws DocletException {
95         buildAnnotationTypeMember(memberDetailsTree);
96     }
97 
98     @Override
buildAnnotationTypeMemberChildren(Content annotationDocTree)99     protected void buildAnnotationTypeMemberChildren(Content annotationDocTree) {
100         super.buildAnnotationTypeMemberChildren(annotationDocTree);
101         buildDefaultValueInfo(annotationDocTree);
102     }
103 
104     /**
105      * Build the default value for this optional member.
106      *
107      * @param annotationDocTree the content tree to which the documentation will be added
108      */
buildDefaultValueInfo(Content annotationDocTree)109     protected void buildDefaultValueInfo(Content annotationDocTree) {
110         ((AnnotationTypeOptionalMemberWriter) writer).addDefaultValueInfo(currentMember,
111                 annotationDocTree);
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
getWriter()118     public AnnotationTypeRequiredMemberWriter getWriter() {
119         return writer;
120     }
121 }
122