src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/PropertyBuilder.java

changeset 1606
ccbe7ffdd867
parent 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/PropertyBuilder.java	Sun Feb 24 11:36:58 2013 -0800
     1.3 @@ -0,0 +1,228 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.doclets.internal.toolkit.builders;
    1.30 +
    1.31 +import java.util.*;
    1.32 +
    1.33 +import com.sun.tools.doclets.internal.toolkit.util.*;
    1.34 +import com.sun.tools.doclets.internal.toolkit.*;
    1.35 +import com.sun.javadoc.*;
    1.36 +
    1.37 +/**
    1.38 + * Builds documentation for a property.
    1.39 + *
    1.40 + *  <p><b>This is NOT part of any supported API.
    1.41 + *  If you write code that depends on this, you do so at your own risk.
    1.42 + *  This code and its internal interfaces are subject to change or
    1.43 + *  deletion without notice.</b>
    1.44 + *
    1.45 + * @author Jamie Ho
    1.46 + * @author Bhavesh Patel (Modified)
    1.47 + * @since 1.7
    1.48 + */
    1.49 +public class PropertyBuilder extends AbstractMemberBuilder {
    1.50 +
    1.51 +    /**
    1.52 +     * The class whose properties are being documented.
    1.53 +     */
    1.54 +    private final ClassDoc classDoc;
    1.55 +
    1.56 +    /**
    1.57 +     * The visible properties for the given class.
    1.58 +     */
    1.59 +    private final VisibleMemberMap visibleMemberMap;
    1.60 +
    1.61 +    /**
    1.62 +     * The writer to output the property documentation.
    1.63 +     */
    1.64 +    private final PropertyWriter writer;
    1.65 +
    1.66 +    /**
    1.67 +     * The list of properties being documented.
    1.68 +     */
    1.69 +    private final List<ProgramElementDoc> properties;
    1.70 +
    1.71 +    /**
    1.72 +     * The index of the current property that is being documented at this point
    1.73 +     * in time.
    1.74 +     */
    1.75 +    private int currentPropertyIndex;
    1.76 +
    1.77 +    /**
    1.78 +     * Construct a new PropertyBuilder.
    1.79 +     *
    1.80 +     * @param context  the build context.
    1.81 +     * @param classDoc the class whoses members are being documented.
    1.82 +     * @param writer the doclet specific writer.
    1.83 +     */
    1.84 +    private PropertyBuilder(Context context,
    1.85 +            ClassDoc classDoc,
    1.86 +            PropertyWriter writer) {
    1.87 +        super(context);
    1.88 +        this.classDoc = classDoc;
    1.89 +        this.writer = writer;
    1.90 +        visibleMemberMap =
    1.91 +                new VisibleMemberMap(
    1.92 +                classDoc,
    1.93 +                VisibleMemberMap.PROPERTIES,
    1.94 +                configuration);
    1.95 +        properties =
    1.96 +                new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc));
    1.97 +        if (configuration.getMemberComparator() != null) {
    1.98 +            Collections.sort(properties, configuration.getMemberComparator());
    1.99 +        }
   1.100 +    }
   1.101 +
   1.102 +    /**
   1.103 +     * Construct a new PropertyBuilder.
   1.104 +     *
   1.105 +     * @param context  the build context.
   1.106 +     * @param classDoc the class whoses members are being documented.
   1.107 +     * @param writer the doclet specific writer.
   1.108 +     */
   1.109 +    public static PropertyBuilder getInstance(Context context,
   1.110 +            ClassDoc classDoc,
   1.111 +            PropertyWriter writer) {
   1.112 +        return new PropertyBuilder(context, classDoc, writer);
   1.113 +    }
   1.114 +
   1.115 +    /**
   1.116 +     * {@inheritDoc}
   1.117 +     */
   1.118 +    public String getName() {
   1.119 +        return "PropertyDetails";
   1.120 +    }
   1.121 +
   1.122 +    /**
   1.123 +     * Returns a list of properties that will be documented for the given class.
   1.124 +     * This information can be used for doclet specific documentation
   1.125 +     * generation.
   1.126 +     *
   1.127 +     * @param classDoc the {@link ClassDoc} we want to check.
   1.128 +     * @return a list of properties that will be documented.
   1.129 +     */
   1.130 +    public List<ProgramElementDoc> members(ClassDoc classDoc) {
   1.131 +        return visibleMemberMap.getMembersFor(classDoc);
   1.132 +    }
   1.133 +
   1.134 +    /**
   1.135 +     * Returns the visible member map for the properties of this class.
   1.136 +     *
   1.137 +     * @return the visible member map for the properties of this class.
   1.138 +     */
   1.139 +    public VisibleMemberMap getVisibleMemberMap() {
   1.140 +        return visibleMemberMap;
   1.141 +    }
   1.142 +
   1.143 +    /**
   1.144 +     * summaryOrder.size()
   1.145 +     */
   1.146 +    public boolean hasMembersToDocument() {
   1.147 +        return properties.size() > 0;
   1.148 +    }
   1.149 +
   1.150 +    /**
   1.151 +     * Build the property documentation.
   1.152 +     *
   1.153 +     * @param node the XML element that specifies which components to document
   1.154 +     * @param memberDetailsTree the content tree to which the documentation will be added
   1.155 +     */
   1.156 +    public void buildPropertyDoc(XMLNode node, Content memberDetailsTree) {
   1.157 +        if (writer == null) {
   1.158 +            return;
   1.159 +        }
   1.160 +        int size = properties.size();
   1.161 +        if (size > 0) {
   1.162 +            Content propertyDetailsTree = writer.getPropertyDetailsTreeHeader(
   1.163 +                    classDoc, memberDetailsTree);
   1.164 +            for (currentPropertyIndex = 0; currentPropertyIndex < size;
   1.165 +                    currentPropertyIndex++) {
   1.166 +                Content propertyDocTree = writer.getPropertyDocTreeHeader(
   1.167 +                        (MethodDoc) properties.get(currentPropertyIndex),
   1.168 +                        propertyDetailsTree);
   1.169 +                buildChildren(node, propertyDocTree);
   1.170 +                propertyDetailsTree.addContent(writer.getPropertyDoc(
   1.171 +                        propertyDocTree, (currentPropertyIndex == size - 1)));
   1.172 +            }
   1.173 +            memberDetailsTree.addContent(
   1.174 +                    writer.getPropertyDetails(propertyDetailsTree));
   1.175 +        }
   1.176 +    }
   1.177 +
   1.178 +    /**
   1.179 +     * Build the signature.
   1.180 +     *
   1.181 +     * @param node the XML element that specifies which components to document
   1.182 +     * @param propertyDocTree the content tree to which the documentation will be added
   1.183 +     */
   1.184 +    public void buildSignature(XMLNode node, Content propertyDocTree) {
   1.185 +        propertyDocTree.addContent(
   1.186 +                writer.getSignature((MethodDoc) properties.get(currentPropertyIndex)));
   1.187 +    }
   1.188 +
   1.189 +    /**
   1.190 +     * Build the deprecation information.
   1.191 +     *
   1.192 +     * @param node the XML element that specifies which components to document
   1.193 +     * @param propertyDocTree the content tree to which the documentation will be added
   1.194 +     */
   1.195 +    public void buildDeprecationInfo(XMLNode node, Content propertyDocTree) {
   1.196 +        writer.addDeprecated(
   1.197 +                (MethodDoc) properties.get(currentPropertyIndex), propertyDocTree);
   1.198 +    }
   1.199 +
   1.200 +    /**
   1.201 +     * Build the comments for the property.  Do nothing if
   1.202 +     * {@link Configuration#nocomment} is set to true.
   1.203 +     *
   1.204 +     * @param node the XML element that specifies which components to document
   1.205 +     * @param propertyDocTree the content tree to which the documentation will be added
   1.206 +     */
   1.207 +    public void buildPropertyComments(XMLNode node, Content propertyDocTree) {
   1.208 +        if (!configuration.nocomment) {
   1.209 +            writer.addComments((MethodDoc) properties.get(currentPropertyIndex), propertyDocTree);
   1.210 +        }
   1.211 +    }
   1.212 +
   1.213 +    /**
   1.214 +     * Build the tag information.
   1.215 +     *
   1.216 +     * @param node the XML element that specifies which components to document
   1.217 +     * @param propertyDocTree the content tree to which the documentation will be added
   1.218 +     */
   1.219 +    public void buildTagInfo(XMLNode node, Content propertyDocTree) {
   1.220 +        writer.addTags((MethodDoc) properties.get(currentPropertyIndex), propertyDocTree);
   1.221 +    }
   1.222 +
   1.223 +    /**
   1.224 +     * Return the property writer for this builder.
   1.225 +     *
   1.226 +     * @return the property writer for this builder.
   1.227 +     */
   1.228 +    public PropertyWriter getWriter() {
   1.229 +        return writer;
   1.230 +    }
   1.231 +}

mercurial