1 /*
   2  * Copyright (c) 1997, 2019, 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.formats.html;
  27 
  28 import javax.lang.model.element.Element;
  29 import javax.lang.model.element.ExecutableElement;
  30 import javax.lang.model.element.TypeElement;
  31 
  32 import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
  33 import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
  34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
  35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
  36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
  37 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
  38 import jdk.javadoc.internal.doclets.formats.html.markup.Table;
  39 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
  40 import jdk.javadoc.internal.doclets.toolkit.Content;
  41 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  42 import jdk.javadoc.internal.doclets.toolkit.PropertyWriter;
  43 
  44 /**
  45  * Writes property documentation in HTML format.
  46  *
  47  *  <p><b>This is NOT part of any supported API.
  48  *  If you write code that depends on this, you do so at your own risk.
  49  *  This code and its internal interfaces are subject to change or
  50  *  deletion without notice.</b>
  51  *
  52  * @author Robert Field
  53  * @author Atul M Dambalkar
  54  * @author Jamie Ho (rewrite)
  55  * @author Bhavesh Patel (Modified)
  56  */
  57 public class PropertyWriterImpl extends AbstractMemberWriter
  58     implements PropertyWriter, MemberSummaryWriter {
  59 
  60     public PropertyWriterImpl(SubWriterHolderWriter writer, TypeElement typeElement) {
  61         super(writer, typeElement);
  62     }
  63 
  64     /**
  65      * {@inheritDoc}
  66      */
  67     @Override
  68     public Content getMemberSummaryHeader(TypeElement typeElement, Content memberSummaryTree) {
  69         memberSummaryTree.add(MarkerComments.START_OF_PROPERTY_SUMMARY);
  70         Content memberTree = new ContentBuilder();
  71         writer.addSummaryHeader(this, typeElement, memberTree);
  72         return memberTree;
  73     }
  74 
  75     /**
  76      * {@inheritDoc}
  77      */
  78     @Override
  79     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  80         writer.addMemberTree(HtmlStyle.propertySummary, memberSummaryTree, memberTree);
  81     }
  82 
  83     /**
  84      * {@inheritDoc}
  85      */
  86     @Override
  87     public Content getPropertyDetailsTreeHeader(TypeElement typeElement,
  88             Content memberDetailsTree) {
  89         memberDetailsTree.add(MarkerComments.START_OF_PROPERTY_DETAILS);
  90         Content propertyDetailsTree = new ContentBuilder();
  91         Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
  92                 contents.propertyDetailsLabel);
  93         propertyDetailsTree.add(heading);
  94         propertyDetailsTree.add(links.createAnchor(SectionName.PROPERTY_DETAIL));
  95         return propertyDetailsTree;
  96     }
  97 
  98     /**
  99      * {@inheritDoc}
 100      */
 101     @Override
 102     public Content getPropertyDocTreeHeader(ExecutableElement property,
 103             Content propertyDetailsTree) {
 104         Content propertyDocTree = new ContentBuilder();
 105         Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING);
 106         heading.add(utils.getPropertyLabel(name(property)));
 107         propertyDocTree.add(heading);
 108         propertyDocTree.add(links.createAnchor(name(property)));
 109         return HtmlTree.SECTION(HtmlStyle.detail, propertyDocTree);
 110     }
 111 
 112     /**
 113      * {@inheritDoc}
 114      */
 115     @Override
 116     public Content getSignature(ExecutableElement property) {
 117         Content pre = new HtmlTree(HtmlTag.PRE);
 118         writer.addAnnotationInfo(property, pre);
 119         addModifiers(property, pre);
 120         Content propertylink = writer.getLink(new LinkInfoImpl(
 121                 configuration, LinkInfoImpl.Kind.MEMBER,
 122                 utils.getReturnType(property)));
 123         pre.add(propertylink);
 124         pre.add(" ");
 125         if (configuration.linksource) {
 126             Content propertyName = new StringContent(name(property));
 127             writer.addSrcLink(property, propertyName, pre);
 128         } else {
 129             addName(name(property), pre);
 130         }
 131         return pre;
 132     }
 133 
 134     /**
 135      * {@inheritDoc}
 136      */
 137     @Override
 138     public void addDeprecated(ExecutableElement property, Content propertyDocTree) {
 139     }
 140 
 141     /**
 142      * {@inheritDoc}
 143      */
 144     @Override
 145     public void addComments(ExecutableElement property, Content propertyDocTree) {
 146         TypeElement holder = (TypeElement)property.getEnclosingElement();
 147         if (!utils.getFullBody(property).isEmpty()) {
 148             if (holder.equals(typeElement) ||
 149                     (!utils.isPublic(holder) || utils.isLinkable(holder))) {
 150                 writer.addInlineComment(property, propertyDocTree);
 151             } else {
 152                 Content link =
 153                         writer.getDocLink(LinkInfoImpl.Kind.PROPERTY_COPY,
 154                         holder, property,
 155                         utils.isIncluded(holder)
 156                                 ? holder.getSimpleName() : holder.getQualifiedName(),
 157                             false);
 158                 Content codeLink = HtmlTree.CODE(link);
 159                 Content descfrmLabel = HtmlTree.SPAN(HtmlStyle.descfrmTypeLabel,
 160                         utils.isClass(holder)
 161                                 ? contents.descfrmClassLabel
 162                                 : contents.descfrmInterfaceLabel);
 163                 descfrmLabel.add(Entity.NO_BREAK_SPACE);
 164                 descfrmLabel.add(codeLink);
 165                 propertyDocTree.add(HtmlTree.DIV(HtmlStyle.block, descfrmLabel));
 166                 writer.addInlineComment(property, propertyDocTree);
 167             }
 168         }
 169     }
 170 
 171     /**
 172      * {@inheritDoc}
 173      */
 174     @Override
 175     public void addTags(ExecutableElement property, Content propertyDocTree) {
 176         writer.addTagsInfo(property, propertyDocTree);
 177     }
 178 
 179     /**
 180      * {@inheritDoc}
 181      */
 182     @Override
 183     public Content getPropertyDetails(Content propertyDetailsTreeHeader, Content propertyDetailsTree) {
 184         Content propertyDetails = new ContentBuilder(propertyDetailsTreeHeader, propertyDetailsTree);
 185         return getMemberTree(HtmlTree.SECTION(HtmlStyle.propertyDetails, propertyDetails));
 186     }
 187 
 188     /**
 189      * {@inheritDoc}
 190      */
 191     @Override
 192     public Content getPropertyDoc(Content propertyDocTree,
 193             boolean isLastContent) {
 194         return getMemberTree(propertyDocTree, isLastContent);
 195     }
 196 
 197     /**
 198      * {@inheritDoc}
 199      */
 200     @Override
 201     public void addSummaryLabel(Content memberTree) {
 202         Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
 203                 contents.propertySummaryLabel);
 204         memberTree.add(label);
 205     }
 206 
 207     /**
 208      * {@inheritDoc}
 209      */
 210     @Override
 211     public TableHeader getSummaryTableHeader(Element member) {
 212         return new TableHeader(contents.typeLabel, contents.propertyLabel,
 213                 contents.descriptionLabel);
 214     }
 215 
 216     /**
 217      * {@inheritDoc}
 218      */
 219     @Override
 220     protected Table createSummaryTable() {
 221         return new Table(HtmlStyle.memberSummary)
 222                 .setCaption(contents.properties)
 223                 .setHeader(getSummaryTableHeader(typeElement))
 224                 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast)
 225                 .setRowScopeColumn(1);
 226     }
 227 
 228     /**
 229      * {@inheritDoc}
 230      */
 231     @Override
 232     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
 233         memberTree.add(links.createAnchor(SectionName.PROPERTY_SUMMARY));
 234     }
 235 
 236     /**
 237      * {@inheritDoc}
 238      */
 239     @Override
 240     public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
 241         inheritedTree.add(links.createAnchor(
 242                 SectionName.PROPERTIES_INHERITANCE,
 243                 configuration.getClassName(typeElement)));
 244     }
 245 
 246     /**
 247      * {@inheritDoc}
 248      */
 249     @Override
 250     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 251         Content classLink = writer.getPreQualifiedClassLink(
 252                 LinkInfoImpl.Kind.MEMBER, typeElement, false);
 253         Content label;
 254         if (configuration.summarizeOverriddenMethods) {
 255             label = new StringContent(utils.isClass(typeElement)
 256                     ? resources.getText("doclet.Properties_Declared_In_Class")
 257                     : resources.getText("doclet.Properties_Declared_In_Interface"));
 258         } else {
 259             label = new StringContent(utils.isClass(typeElement)
 260                     ? resources.getText("doclet.Properties_Inherited_From_Class")
 261                     : resources.getText("doclet.Properties_Inherited_From_Interface"));
 262         }
 263         Content labelHeading = HtmlTree.HEADING(Headings.TypeDeclaration.INHERITED_SUMMARY_HEADING,
 264                 label);
 265         labelHeading.add(Entity.NO_BREAK_SPACE);
 266         labelHeading.add(classLink);
 267         inheritedTree.add(labelHeading);
 268     }
 269 
 270     /**
 271      * {@inheritDoc}
 272      */
 273     @Override
 274     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 275             Content tdSummary) {
 276         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 277                 writer.getDocLink(context, typeElement,
 278                 member,
 279                 utils.getPropertyLabel(name(member)),
 280                 false,
 281                 true));
 282 
 283         Content code = HtmlTree.CODE(memberLink);
 284         tdSummary.add(code);
 285     }
 286 
 287     /**
 288      * {@inheritDoc}
 289      */
 290     @Override
 291     protected void addInheritedSummaryLink(TypeElement typeElement, Element member, Content linksTree) {
 292         String mname = name(member);
 293         Content content = writer.getDocLink(LinkInfoImpl.Kind.MEMBER, typeElement, member,
 294                 utils.isProperty(mname) ? utils.getPropertyName(mname) : mname,
 295                 false, true);
 296         linksTree.add(content);
 297     }
 298 
 299     /**
 300      * {@inheritDoc}
 301      */
 302     @Override
 303     protected void addSummaryType(Element member, Content tdSummaryType) {
 304         addModifierAndType(member, utils.getReturnType((ExecutableElement)member), tdSummaryType);
 305     }
 306 
 307     /**
 308      * {@inheritDoc}
 309      */
 310     @Override
 311     protected Content getDeprecatedLink(Element member) {
 312         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member,
 313                 utils.getFullyQualifiedName(member));
 314     }
 315 
 316     @Override
 317     public Content getMemberTreeHeader(){
 318         return writer.getMemberTreeHeader();
 319     }
 320 }