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