View Javadoc
1   /*
2    * Copyright (c) 1997, 2013, 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 com.sun.tools.doclets.formats.html;
27  
28  import java.io.*;
29  
30  import com.sun.javadoc.*;
31  import com.sun.tools.doclets.formats.html.markup.*;
32  import com.sun.tools.doclets.internal.toolkit.*;
33  import com.sun.tools.doclets.internal.toolkit.util.*;
34  
35  /**
36   * Writes property documentation in HTML format.
37   *
38   *  <p><b>This is NOT part of any supported API.
39   *  If you write code that depends on this, you do so at your own risk.
40   *  This code and its internal interfaces are subject to change or
41   *  deletion without notice.</b>
42   *
43   * @author Robert Field
44   * @author Atul M Dambalkar
45   * @author Jamie Ho (rewrite)
46   * @author Bhavesh Patel (Modified)
47   */
48  public class PropertyWriterImpl extends AbstractMemberWriter
49      implements PropertyWriter, MemberSummaryWriter {
50  
51      public PropertyWriterImpl(SubWriterHolderWriter writer, ClassDoc classdoc) {
52          super(writer, classdoc);
53      }
54  
55      /**
56       * {@inheritDoc}
57       */
58      public Content getMemberSummaryHeader(ClassDoc classDoc,
59              Content memberSummaryTree) {
60          memberSummaryTree.addContent(HtmlConstants.START_OF_PROPERTY_SUMMARY);
61          Content memberTree = writer.getMemberTreeHeader();
62          writer.addSummaryHeader(this, classDoc, memberTree);
63          return memberTree;
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      public Content getPropertyDetailsTreeHeader(ClassDoc classDoc,
70              Content memberDetailsTree) {
71          memberDetailsTree.addContent(HtmlConstants.START_OF_PROPERTY_DETAILS);
72          Content propertyDetailsTree = writer.getMemberTreeHeader();
73          propertyDetailsTree.addContent(writer.getMarkerAnchor(
74                  SectionName.PROPERTY_DETAIL));
75          Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
76                  writer.propertyDetailsLabel);
77          propertyDetailsTree.addContent(heading);
78          return propertyDetailsTree;
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      public Content getPropertyDocTreeHeader(MethodDoc property,
85              Content propertyDetailsTree) {
86          propertyDetailsTree.addContent(
87                  writer.getMarkerAnchor(property.name()));
88          Content propertyDocTree = writer.getMemberTreeHeader();
89          Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
90          heading.addContent(property.name().substring(0, property.name().lastIndexOf("Property")));
91          propertyDocTree.addContent(heading);
92          return propertyDocTree;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public Content getSignature(MethodDoc property) {
99          Content pre = new HtmlTree(HtmlTag.PRE);
100         writer.addAnnotationInfo(property, pre);
101         addModifiers(property, pre);
102         Content propertylink = writer.getLink(new LinkInfoImpl(
103                 configuration, LinkInfoImpl.Kind.MEMBER,
104                 property.returnType()));
105         pre.addContent(propertylink);
106         pre.addContent(" ");
107         if (configuration.linksource) {
108             Content propertyName = new StringContent(property.name());
109             writer.addSrcLink(property, propertyName, pre);
110         } else {
111             addName(property.name(), pre);
112         }
113         return pre;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     public void addDeprecated(MethodDoc property, Content propertyDocTree) {
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     public void addComments(MethodDoc property, Content propertyDocTree) {
126         ClassDoc holder = property.containingClass();
127         if (property.inlineTags().length > 0) {
128             if (holder.equals(classdoc) ||
129                     (! (holder.isPublic() || Util.isLinkable(holder, configuration)))) {
130                 writer.addInlineComment(property, propertyDocTree);
131             } else {
132                 Content link =
133                         writer.getDocLink(LinkInfoImpl.Kind.PROPERTY_DOC_COPY,
134                         holder, property,
135                         holder.isIncluded() ?
136                             holder.typeName() : holder.qualifiedTypeName(),
137                             false);
138                 Content codeLink = HtmlTree.CODE(link);
139                 Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel, holder.isClass()?
140                    writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
141                 descfrmLabel.addContent(writer.getSpace());
142                 descfrmLabel.addContent(codeLink);
143                 propertyDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, descfrmLabel));
144                 writer.addInlineComment(property, propertyDocTree);
145             }
146         }
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     public void addTags(MethodDoc property, Content propertyDocTree) {
153         writer.addTagsInfo(property, propertyDocTree);
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     public Content getPropertyDetails(Content propertyDetailsTree) {
160         return getMemberTree(propertyDetailsTree);
161     }
162 
163     /**
164      * {@inheritDoc}
165      */
166     public Content getPropertyDoc(Content propertyDocTree,
167             boolean isLastContent) {
168         return getMemberTree(propertyDocTree, isLastContent);
169     }
170 
171     /**
172      * Close the writer.
173      */
174     public void close() throws IOException {
175         writer.close();
176     }
177 
178     public int getMemberKind() {
179         return VisibleMemberMap.PROPERTIES;
180     }
181 
182     /**
183      * {@inheritDoc}
184      */
185     public void addSummaryLabel(Content memberTree) {
186         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
187                 writer.getResource("doclet.Property_Summary"));
188         memberTree.addContent(label);
189     }
190 
191     /**
192      * {@inheritDoc}
193      */
194     public String getTableSummary() {
195         return configuration.getText("doclet.Member_Table_Summary",
196                 configuration.getText("doclet.Property_Summary"),
197                 configuration.getText("doclet.properties"));
198     }
199 
200     /**
201      * {@inheritDoc}
202      */
203     public Content getCaption() {
204         return configuration.getResource("doclet.Properties");
205     }
206 
207     /**
208      * {@inheritDoc}
209      */
210     public String[] getSummaryTableHeader(ProgramElementDoc member) {
211         String[] header = new String[] {
212             configuration.getText("doclet.Type"),
213             configuration.getText("doclet.0_and_1",
214                     configuration.getText("doclet.Property"),
215                     configuration.getText("doclet.Description"))
216         };
217         return header;
218     }
219 
220     /**
221      * {@inheritDoc}
222      */
223     public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
224         memberTree.addContent(writer.getMarkerAnchor(
225                 SectionName.PROPERTY_SUMMARY));
226     }
227 
228     /**
229      * {@inheritDoc}
230      */
231     public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
232         inheritedTree.addContent(writer.getMarkerAnchor(
233                 SectionName.PROPERTIES_INHERITANCE,
234                 configuration.getClassName(cd)));
235     }
236 
237     /**
238      * {@inheritDoc}
239      */
240     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
241         Content classLink = writer.getPreQualifiedClassLink(
242                 LinkInfoImpl.Kind.MEMBER, cd, false);
243         Content label = new StringContent(cd.isClass() ?
244             configuration.getText("doclet.Properties_Inherited_From_Class") :
245             configuration.getText("doclet.Properties_Inherited_From_Interface"));
246         Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING,
247                 label);
248         labelHeading.addContent(writer.getSpace());
249         labelHeading.addContent(classLink);
250         inheritedTree.addContent(labelHeading);
251     }
252 
253     /**
254      * {@inheritDoc}
255      */
256     protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
257             Content tdSummary) {
258         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
259                 writer.getDocLink(context, cd,
260                 (MemberDoc) member,
261                 member.name().substring(0, member.name().lastIndexOf("Property")),
262                 false,
263                 true));
264 
265         Content code = HtmlTree.CODE(memberLink);
266         tdSummary.addContent(code);
267     }
268 
269     /**
270      * {@inheritDoc}
271      */
272     protected void addInheritedSummaryLink(ClassDoc cd,
273             ProgramElementDoc member, Content linksTree) {
274         linksTree.addContent(
275                 writer.getDocLink(LinkInfoImpl.Kind.MEMBER, cd, (MemberDoc)member,
276                 ((member.name().lastIndexOf("Property") != -1) && configuration.javafx)
277                         ? member.name().substring(0, member.name().length() - "Property".length())
278                         : member.name(),
279                 false, true));
280     }
281 
282     /**
283      * {@inheritDoc}
284      */
285     protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
286         MethodDoc property = (MethodDoc)member;
287         addModifierAndType(property, property.returnType(), tdSummaryType);
288     }
289 
290     /**
291      * {@inheritDoc}
292      */
293     protected Content getDeprecatedLink(ProgramElementDoc member) {
294         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
295                 (MemberDoc) member, ((MethodDoc)member).qualifiedName());
296     }
297 
298     /**
299      * {@inheritDoc}
300      */
301     protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
302         if (link) {
303             if (cd == null) {
304                 return writer.getHyperLink(
305                 SectionName.PROPERTY_SUMMARY,
306                 writer.getResource("doclet.navProperty"));
307             } else {
308                 return writer.getHyperLink(
309                 SectionName.PROPERTIES_INHERITANCE,
310                 configuration.getClassName(cd), writer.getResource("doclet.navProperty"));
311             }
312         } else {
313             return writer.getResource("doclet.navProperty");
314         }
315     }
316 
317     /**
318      * {@inheritDoc}
319      */
320     protected void addNavDetailLink(boolean link, Content liNav) {
321         if (link) {
322             liNav.addContent(writer.getHyperLink(
323                     SectionName.PROPERTY_DETAIL,
324                     writer.getResource("doclet.navProperty")));
325         } else {
326             liNav.addContent(writer.getResource("doclet.navProperty"));
327         }
328     }
329 }