< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java

Print this page




  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 java.util.ArrayList;
  29 import java.util.Collections;
  30 import java.util.HashMap;
  31 import java.util.LinkedList;
  32 import java.util.List;
  33 import java.util.ListIterator;
  34 import java.util.Locale;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import java.util.regex.Matcher;
  38 import java.util.regex.Pattern;
  39 
  40 import javax.lang.model.element.AnnotationMirror;
  41 import javax.lang.model.element.AnnotationValue;
  42 import javax.lang.model.element.Element;
  43 import javax.lang.model.element.ElementKind;
  44 import javax.lang.model.element.ExecutableElement;
  45 import javax.lang.model.element.ModuleElement;
  46 import javax.lang.model.element.Name;
  47 import javax.lang.model.element.PackageElement;
  48 import javax.lang.model.element.QualifiedNameable;
  49 import javax.lang.model.element.TypeElement;
  50 import javax.lang.model.element.VariableElement;


 181     /**
 182      * To check whether the repeated annotations is documented or not.
 183      */
 184     private boolean isAnnotationDocumented = false;
 185 
 186     /**
 187      * To check whether the container annotations is documented or not.
 188      */
 189     private boolean isContainerDocumented = false;
 190 
 191     HtmlTree fixedNavDiv = new HtmlTree(HtmlTag.DIV);
 192 
 193     /**
 194      * The window title of this file.
 195      */
 196     protected String winTitle;
 197 
 198     protected Script mainBodyScript;
 199 
 200     /**
 201      * A table of the anchors used for at-index and related tags,
 202      * so that they can be made unique by appending a suitable suffix.
 203      * (Ideally, javadoc should be tracking all id's generated in a file
 204      * to avoid generating duplicates.)
 205      */
 206     Map<String, Integer> indexAnchorTable = new HashMap<>();
 207 
 208     /**
 209      * Constructor to construct the HtmlStandardWriter object.
 210      *
 211      * @param configuration the configuration for this doclet
 212      * @param path the file to be generated.
 213      */
 214     public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path) {
 215         this.configuration = configuration;
 216         this.contents = configuration.contents;
 217         this.messages = configuration.messages;
 218         this.resources = configuration.resources;
 219         this.links = new Links(path);
 220         this.utils = configuration.utils;
 221         this.path = path;
 222         this.pathToRoot = path.parent().invert();
 223         this.filename = path.basename();
 224         this.docPaths = configuration.docPaths;
 225         this.mainBodyScript = new Script();
 226 
 227         messages.notice("doclet.Generating_0",
 228             DocFile.createFileForOutput(configuration, path).getPath());


1707         return text;
1708     }
1709 
1710     /**
1711      * According to
1712      * <cite>The Java&trade; Language Specification</cite>,
1713      * all the outer classes and static nested classes are core classes.
1714      */
1715     public boolean isCoreClass(TypeElement typeElement) {
1716         return utils.getEnclosingTypeElement(typeElement) == null || utils.isStatic(typeElement);
1717     }
1718 
1719     /**
1720      * Adds the annotation types for the given packageElement.
1721      *
1722      * @param packageElement the package to write annotations for.
1723      * @param htmltree the documentation tree to which the annotation info will be
1724      *        added
1725      */
1726     public void addAnnotationInfo(PackageElement packageElement, Content htmltree) {
1727         addAnnotationInfo(packageElement.getAnnotationMirrors(), htmltree);













1728     }
1729 
1730     /*
1731      * this is a hack to delay dealing with Annotations in the writers, the assumption
1732      * is that all necessary checks have been made to get here.
1733      */
1734     public void addReceiverAnnotationInfo(ExecutableElement method, TypeMirror rcvrTypeMirror,
1735             List<? extends AnnotationMirror> annotationMirrors, Content htmltree) {
1736         TypeMirror rcvrType = method.getReceiverType();
1737         List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors();
1738         htmltree.add(getAnnotationInfo(annotationMirrors1, false));
1739     }
1740 
1741     /**
1742      * Adds the annotation types for the given element.
1743      *
1744      * @param element the package to write annotations for
1745      * @param htmltree the content tree to which the annotation types will be added
1746      */
1747     public void addAnnotationInfo(Element element, Content htmltree) {
1748         addAnnotationInfo(element.getAnnotationMirrors(), htmltree);
1749     }
1750 
1751     /**
1752      * Add the annotatation types for the given element and parameter.
1753      *


1754      * @param param the parameter to write annotations for.
1755      * @param tree the content tree to which the annotation types will be added
1756      */
1757     public boolean addAnnotationInfo(VariableElement param, Content tree) {
1758         Content annotaionInfo = getAnnotationInfo(param.getAnnotationMirrors(), false);
1759         if (annotaionInfo.isEmpty()) {
1760             return false;
1761         }
1762         tree.add(annotaionInfo);
1763         return true;
1764     }
1765 
1766     /**
1767      * Adds the annotatation types for the given Element.
1768      *

1769      * @param descList a list of annotation mirrors.
1770      * @param htmltree the documentation tree to which the annotation info will be
1771      *        added
1772      */
1773     private void addAnnotationInfo(List<? extends AnnotationMirror> descList, Content htmltree) {
1774         htmltree.add(getAnnotationInfo(descList, true));

1775     }
1776 
1777     /**
1778      * Return a content tree containing the annotation types for the given element.
1779      *


1780      * @param descList a list of annotation mirrors.
1781      * @return the documentation tree containing the annotation info.

1782      */
1783     Content getAnnotationInfo(List<? extends AnnotationMirror> descList, boolean lineBreak) {
1784         List<Content> annotations = getAnnotations(descList, lineBreak);

1785         String sep = "";
1786         ContentBuilder builder = new ContentBuilder();


1787         for (Content annotation: annotations) {
1788             builder.add(sep);
1789             builder.add(annotation);
1790             if (!lineBreak) {
1791                 sep = " ";
1792             }
1793         }
1794         return builder;




















1795     }
1796 
1797     /**
1798      * Return the string representations of the annotation types for
1799      * the given doc.
1800      *




1801      * @param descList a list of annotation mirrors.
1802      * @param linkBreak if true, add new line between each member value.

1803      * @return a list of strings representing the annotations being
1804      *         documented.
1805      */
1806     public List<Content> getAnnotations(List<? extends AnnotationMirror> descList, boolean linkBreak) {

1807         List<Content> results = new ArrayList<>();
1808         ContentBuilder annotation;
1809         for (AnnotationMirror aDesc : descList) {
1810             TypeElement annotationElement = (TypeElement)aDesc.getAnnotationType().asElement();
1811             // If an annotation is not documented, do not add it to the list. If
1812             // the annotation is of a repeatable type, and if it is not documented
1813             // and also if its container annotation is not documented, do not add it
1814             // to the list. If an annotation of a repeatable type is not documented
1815             // but its container is documented, it will be added to the list.
1816             if (!utils.isDocumentedAnnotation(annotationElement) &&
1817                 (!isAnnotationDocumented && !isContainerDocumented)) {
1818                 continue;
1819             }





1820             annotation = new ContentBuilder();
1821             isAnnotationDocumented = false;
1822             LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
1823                                                      LinkInfoImpl.Kind.ANNOTATION, annotationElement);
1824             Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = aDesc.getElementValues();
1825             // If the annotation is synthesized, do not print the container.
1826             if (utils.configuration.workArounds.isSynthesized(aDesc)) {
1827                 for (ExecutableElement ee : pairs.keySet()) {
1828                     AnnotationValue annotationValue = pairs.get(ee);
1829                     List<AnnotationValue> annotationTypeValues = new ArrayList<>();
1830 
1831                     new SimpleAnnotationValueVisitor9<Void, List<AnnotationValue>>() {
1832                         @Override
1833                         public Void visitArray(List<? extends AnnotationValue> vals, List<AnnotationValue> p) {
1834                             p.addAll(vals);
1835                             return null;
1836                         }
1837 
1838                         @Override
1839                         protected Void defaultAction(Object o, List<AnnotationValue> p) {


1842                         }
1843                     }.visit(annotationValue, annotationTypeValues);
1844 
1845                     String sep = "";
1846                     for (AnnotationValue av : annotationTypeValues) {
1847                         annotation.add(sep);
1848                         annotation.add(annotationValueToContent(av));
1849                         sep = " ";
1850                     }
1851                 }
1852             } else if (isAnnotationArray(pairs)) {
1853                 // If the container has 1 or more value defined and if the
1854                 // repeatable type annotation is not documented, do not print
1855                 // the container.
1856                 if (pairs.size() == 1 && isAnnotationDocumented) {
1857                     List<AnnotationValue> annotationTypeValues = new ArrayList<>();
1858                     for (AnnotationValue a :  pairs.values()) {
1859                         new SimpleAnnotationValueVisitor9<Void, List<AnnotationValue>>() {
1860                             @Override
1861                             public Void visitArray(List<? extends AnnotationValue> vals, List<AnnotationValue> annotationTypeValues) {
1862                                annotationTypeValues.addAll(vals);


1863                                return null;
1864                             }
1865                         }.visit(a, annotationTypeValues);
1866                     }
1867                     String sep = "";
1868                     for (AnnotationValue av : annotationTypeValues) {
1869                         annotation.add(sep);
1870                         annotation.add(annotationValueToContent(av));
1871                         sep = " ";
1872                     }
1873                 }
1874                 // If the container has 1 or more value defined and if the
1875                 // repeatable type annotation is not documented, print the container.
1876                 else {
1877                     addAnnotations(annotationElement, linkInfo, annotation, pairs, false);

1878                 }
1879             }
1880             else {
1881                 addAnnotations(annotationElement, linkInfo, annotation, pairs, linkBreak);

1882             }
1883             annotation.add(linkBreak ? DocletConstants.NL : "");
1884             results.add(annotation);
1885         }
1886         return results;
1887     }
1888 
1889     /**
1890      * Add annotation to the annotation string.
1891      *
1892      * @param annotationDoc the annotation being documented
1893      * @param linkInfo the information about the link
1894      * @param annotation the annotation string to which the annotation will be added
1895      * @param map annotation type element to annotation value pairs

1896      * @param linkBreak if true, add new line between each member value
1897      */
1898     private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo,
1899                                 ContentBuilder annotation,
1900                                 Map<? extends ExecutableElement, ? extends AnnotationValue> map,
1901                                 boolean linkBreak) {
1902         linkInfo.label = new StringContent("@");
1903         linkInfo.label.add(annotationDoc.getSimpleName());
1904         annotation.add(getLink(linkInfo));
1905         if (!map.isEmpty()) {
1906             annotation.add("(");
1907             boolean isFirst = true;
1908             Set<? extends ExecutableElement> keys = map.keySet();
1909             boolean multipleValues = keys.size() > 1;
1910             for (ExecutableElement element : keys) {
1911                 if (isFirst) {
1912                     isFirst = false;
1913                 } else {
1914                     annotation.add(",");
1915                     if (linkBreak) {
1916                         annotation.add(DocletConstants.NL);
1917                         int spaces = annotationDoc.getSimpleName().length() + 2;
1918                         for (int k = 0; k < (spaces); k++) {
1919                             annotation.add(" ");
1920                         }
1921                     }
1922                 }
1923                 String simpleName = element.getSimpleName().toString();
1924                 if (multipleValues || !"value".equals(simpleName)) { // Omit "value=" where unnecessary
1925                     annotation.add(getDocLink(LinkInfoImpl.Kind.ANNOTATION,
1926                                                      element, simpleName, false));
1927                     annotation.add("=");
1928                 }
1929                 AnnotationValue annotationValue = map.get(element);
1930                 List<AnnotationValue> annotationTypeValues = new ArrayList<>();
1931                 new SimpleAnnotationValueVisitor9<Void, AnnotationValue>() {
1932                     @Override
1933                     public Void visitArray(List<? extends AnnotationValue> vals, AnnotationValue p) {
1934                         annotationTypeValues.addAll(vals);
1935                         return null;
1936                     }
1937                     @Override
1938                     protected Void defaultAction(Object o, AnnotationValue p) {


2011             public Content visitType(TypeMirror t, Void p) {
2012                 return new SimpleTypeVisitor9<Content, Void>() {
2013                     @Override
2014                     public Content visitDeclared(DeclaredType t, Void p) {
2015                         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
2016                                 LinkInfoImpl.Kind.ANNOTATION, t);
2017                         String name = utils.isIncluded(t.asElement())
2018                                 ? t.asElement().getSimpleName().toString()
2019                                 : utils.getFullyQualifiedName(t.asElement());
2020                         linkInfo.label = new StringContent(name + utils.getDimension(t) + ".class");
2021                         return getLink(linkInfo);
2022                     }
2023                     @Override
2024                     protected Content defaultAction(TypeMirror e, Void p) {
2025                         return new StringContent(t + utils.getDimension(t) + ".class");
2026                     }
2027                 }.visit(t);
2028             }
2029             @Override
2030             public Content visitAnnotation(AnnotationMirror a, Void p) {
2031                 List<Content> list = getAnnotations(List.of(a), false);
2032                 ContentBuilder buf = new ContentBuilder();
2033                 for (Content c : list) {
2034                     buf.add(c);
2035                 }
2036                 return buf;
2037             }
2038             @Override
2039             public Content visitEnumConstant(VariableElement c, Void p) {
2040                 return getDocLink(LinkInfoImpl.Kind.ANNOTATION,
2041                         c, c.getSimpleName(), false);
2042             }
2043             @Override
2044             public Content visitArray(List<? extends AnnotationValue> vals, Void p) {
2045                 ContentBuilder buf = new ContentBuilder();
2046                 String sep = "";
2047                 for (AnnotationValue av : vals) {
2048                     buf.add(sep);
2049                     buf.add(visit(av));
2050                     sep = " ";
2051                 }




  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 java.util.ArrayList;
  29 import java.util.Collections;

  30 import java.util.LinkedList;
  31 import java.util.List;
  32 import java.util.ListIterator;
  33 import java.util.Locale;
  34 import java.util.Map;
  35 import java.util.Set;
  36 import java.util.regex.Matcher;
  37 import java.util.regex.Pattern;
  38 
  39 import javax.lang.model.element.AnnotationMirror;
  40 import javax.lang.model.element.AnnotationValue;
  41 import javax.lang.model.element.Element;
  42 import javax.lang.model.element.ElementKind;
  43 import javax.lang.model.element.ExecutableElement;
  44 import javax.lang.model.element.ModuleElement;
  45 import javax.lang.model.element.Name;
  46 import javax.lang.model.element.PackageElement;
  47 import javax.lang.model.element.QualifiedNameable;
  48 import javax.lang.model.element.TypeElement;
  49 import javax.lang.model.element.VariableElement;


 180     /**
 181      * To check whether the repeated annotations is documented or not.
 182      */
 183     private boolean isAnnotationDocumented = false;
 184 
 185     /**
 186      * To check whether the container annotations is documented or not.
 187      */
 188     private boolean isContainerDocumented = false;
 189 
 190     HtmlTree fixedNavDiv = new HtmlTree(HtmlTag.DIV);
 191 
 192     /**
 193      * The window title of this file.
 194      */
 195     protected String winTitle;
 196 
 197     protected Script mainBodyScript;
 198 
 199     /**








 200      * Constructor to construct the HtmlStandardWriter object.
 201      *
 202      * @param configuration the configuration for this doclet
 203      * @param path the file to be generated.
 204      */
 205     public HtmlDocletWriter(HtmlConfiguration configuration, DocPath path) {
 206         this.configuration = configuration;
 207         this.contents = configuration.contents;
 208         this.messages = configuration.messages;
 209         this.resources = configuration.resources;
 210         this.links = new Links(path);
 211         this.utils = configuration.utils;
 212         this.path = path;
 213         this.pathToRoot = path.parent().invert();
 214         this.filename = path.basename();
 215         this.docPaths = configuration.docPaths;
 216         this.mainBodyScript = new Script();
 217 
 218         messages.notice("doclet.Generating_0",
 219             DocFile.createFileForOutput(configuration, path).getPath());


1698         return text;
1699     }
1700 
1701     /**
1702      * According to
1703      * <cite>The Java&trade; Language Specification</cite>,
1704      * all the outer classes and static nested classes are core classes.
1705      */
1706     public boolean isCoreClass(TypeElement typeElement) {
1707         return utils.getEnclosingTypeElement(typeElement) == null || utils.isStatic(typeElement);
1708     }
1709 
1710     /**
1711      * Adds the annotation types for the given packageElement.
1712      *
1713      * @param packageElement the package to write annotations for.
1714      * @param htmltree the documentation tree to which the annotation info will be
1715      *        added
1716      */
1717     public void addAnnotationInfo(PackageElement packageElement, Content htmltree) {
1718         addAnnotationInfo(packageElement, packageElement.getAnnotationMirrors(), htmltree);
1719     }
1720 
1721     /**
1722      * Add the annotation types of the executable receiver.
1723      *
1724      * @param method the executable to write the receiver annotations for.
1725      * @param descList a list of annotation mirrors.
1726      * @param htmltree the documentation tree to which the annotation info will be
1727      *        added
1728      */
1729     public void addReceiverAnnotationInfo(ExecutableElement method, List<AnnotationMirror> descList,
1730             Content htmltree) {
1731         addAnnotationInfo(0, method, descList, false, htmltree);
1732     }
1733 
1734     /*
1735      * this is a hack to delay dealing with Annotations in the writers, the assumption
1736      * is that all necessary checks have been made to get here.
1737      */
1738     public void addReceiverAnnotationInfo(ExecutableElement method, TypeMirror rcvrTypeMirror,
1739             List<? extends AnnotationMirror> annotationMirrors, Content htmltree) {
1740         TypeMirror rcvrType = method.getReceiverType();
1741         List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors();
1742         addAnnotationInfo(0, method, annotationMirrors1, false, htmltree);
1743     }
1744 
1745     /**
1746      * Adds the annotation types for the given element.
1747      *
1748      * @param element the package to write annotations for
1749      * @param htmltree the content tree to which the annotation types will be added
1750      */
1751     public void addAnnotationInfo(Element element, Content htmltree) {
1752         addAnnotationInfo(element, element.getAnnotationMirrors(), htmltree);
1753     }
1754 
1755     /**
1756      * Add the annotatation types for the given element and parameter.
1757      *
1758      * @param indent the number of spaces to indent the parameters.
1759      * @param element the element to write annotations for.
1760      * @param param the parameter to write annotations for.
1761      * @param tree the content tree to which the annotation types will be added
1762      */
1763     public boolean addAnnotationInfo(int indent, Element element, VariableElement param,
1764             Content tree) {
1765         return addAnnotationInfo(indent, element, param.getAnnotationMirrors(), false, tree);




1766     }
1767 
1768     /**
1769      * Adds the annotatation types for the given Element.
1770      *
1771      * @param element the element to write annotations for.
1772      * @param descList a list of annotation mirrors.
1773      * @param htmltree the documentation tree to which the annotation info will be
1774      *        added
1775      */
1776     private void addAnnotationInfo(Element element, List<? extends AnnotationMirror> descList,
1777             Content htmltree) {
1778         addAnnotationInfo(0, element, descList, true, htmltree);
1779     }
1780 
1781     /**
1782      * Adds the annotation types for the given element.
1783      *
1784      * @param indent the number of extra spaces to indent the annotations.
1785      * @param element the element to write annotations for.
1786      * @param descList a list of annotation mirrors.
1787      * @param htmltree the documentation tree to which the annotation info will be
1788      *        added
1789      */
1790     private boolean addAnnotationInfo(int indent, Element element,
1791             List<? extends AnnotationMirror> descList, boolean lineBreak, Content htmltree) {
1792         List<Content> annotations = getAnnotations(indent, descList, lineBreak);
1793         String sep = "";
1794         if (annotations.isEmpty()) {
1795             return false;
1796         }
1797         for (Content annotation: annotations) {
1798             htmltree.add(sep);
1799             htmltree.add(annotation);
1800             if (!lineBreak) {
1801                 sep = " ";
1802             }
1803         }
1804         return true;
1805     }
1806 
1807    /**
1808      * Return the string representations of the annotation types for
1809      * the given doc.
1810      *
1811      * @param indent the number of extra spaces to indent the annotations.
1812      * @param descList a list of annotation mirrors.
1813      * @param linkBreak if true, add new line between each member value.
1814      * @return a list of strings representing the annotations being
1815      *         documented.
1816      */
1817     private List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList, boolean linkBreak) {
1818         return getAnnotations(indent, descList, linkBreak, true);
1819     }
1820 
1821     private List<Content> getAnnotations(int indent, AnnotationMirror amirror, boolean linkBreak) {
1822         List<AnnotationMirror> descList = new ArrayList<>();
1823         descList.add(amirror);
1824         return getAnnotations(indent, descList, linkBreak, true);
1825     }
1826 
1827     /**
1828      * Return the string representations of the annotation types for
1829      * the given doc.
1830      *
1831      * A {@code null} {@code elementType} indicates that all the
1832      * annotations should be returned without any filtering.
1833      *
1834      * @param indent the number of extra spaces to indent the annotations.
1835      * @param descList a list of annotation mirrors.
1836      * @param linkBreak if true, add new line between each member value.
1837      * @param isJava5DeclarationLocation
1838      * @return a list of strings representing the annotations being
1839      *         documented.
1840      */
1841     public List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList,
1842             boolean linkBreak, boolean isJava5DeclarationLocation) {
1843         List<Content> results = new ArrayList<>();
1844         ContentBuilder annotation;
1845         for (AnnotationMirror aDesc : descList) {
1846             TypeElement annotationElement = (TypeElement)aDesc.getAnnotationType().asElement();
1847             // If an annotation is not documented, do not add it to the list. If
1848             // the annotation is of a repeatable type, and if it is not documented
1849             // and also if its container annotation is not documented, do not add it
1850             // to the list. If an annotation of a repeatable type is not documented
1851             // but its container is documented, it will be added to the list.
1852             if (!utils.isDocumentedAnnotation(annotationElement) &&
1853                 (!isAnnotationDocumented && !isContainerDocumented)) {
1854                 continue;
1855             }
1856             /* TODO: check logic here to correctly handle declaration
1857              * and type annotations.
1858             if  (utils.isDeclarationAnnotation(annotationElement, isJava5DeclarationLocation)) {
1859                 continue;
1860             }*/
1861             annotation = new ContentBuilder();
1862             isAnnotationDocumented = false;
1863             LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
1864                                                      LinkInfoImpl.Kind.ANNOTATION, annotationElement);
1865             Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = aDesc.getElementValues();
1866             // If the annotation is synthesized, do not print the container.
1867             if (utils.configuration.workArounds.isSynthesized(aDesc)) {
1868                 for (ExecutableElement ee : pairs.keySet()) {
1869                     AnnotationValue annotationValue = pairs.get(ee);
1870                     List<AnnotationValue> annotationTypeValues = new ArrayList<>();
1871 
1872                     new SimpleAnnotationValueVisitor9<Void, List<AnnotationValue>>() {
1873                         @Override
1874                         public Void visitArray(List<? extends AnnotationValue> vals, List<AnnotationValue> p) {
1875                             p.addAll(vals);
1876                             return null;
1877                         }
1878 
1879                         @Override
1880                         protected Void defaultAction(Object o, List<AnnotationValue> p) {


1883                         }
1884                     }.visit(annotationValue, annotationTypeValues);
1885 
1886                     String sep = "";
1887                     for (AnnotationValue av : annotationTypeValues) {
1888                         annotation.add(sep);
1889                         annotation.add(annotationValueToContent(av));
1890                         sep = " ";
1891                     }
1892                 }
1893             } else if (isAnnotationArray(pairs)) {
1894                 // If the container has 1 or more value defined and if the
1895                 // repeatable type annotation is not documented, do not print
1896                 // the container.
1897                 if (pairs.size() == 1 && isAnnotationDocumented) {
1898                     List<AnnotationValue> annotationTypeValues = new ArrayList<>();
1899                     for (AnnotationValue a :  pairs.values()) {
1900                         new SimpleAnnotationValueVisitor9<Void, List<AnnotationValue>>() {
1901                             @Override
1902                             public Void visitArray(List<? extends AnnotationValue> vals, List<AnnotationValue> annotationTypeValues) {
1903                                for (AnnotationValue av : vals) {
1904                                    annotationTypeValues.add(av);
1905                                }
1906                                return null;
1907                             }
1908                         }.visit(a, annotationTypeValues);
1909                     }
1910                     String sep = "";
1911                     for (AnnotationValue av : annotationTypeValues) {
1912                         annotation.add(sep);
1913                         annotation.add(annotationValueToContent(av));
1914                         sep = " ";
1915                     }
1916                 }
1917                 // If the container has 1 or more value defined and if the
1918                 // repeatable type annotation is not documented, print the container.
1919                 else {
1920                     addAnnotations(annotationElement, linkInfo, annotation, pairs,
1921                                    indent, false);
1922                 }
1923             }
1924             else {
1925                 addAnnotations(annotationElement, linkInfo, annotation, pairs,
1926                                indent, linkBreak);
1927             }
1928             annotation.add(linkBreak ? DocletConstants.NL : "");
1929             results.add(annotation);
1930         }
1931         return results;
1932     }
1933 
1934     /**
1935      * Add annotation to the annotation string.
1936      *
1937      * @param annotationDoc the annotation being documented
1938      * @param linkInfo the information about the link
1939      * @param annotation the annotation string to which the annotation will be added
1940      * @param map annotation type element to annotation value pairs
1941      * @param indent the number of extra spaces to indent the annotations.
1942      * @param linkBreak if true, add new line between each member value
1943      */
1944     private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo,
1945                                 ContentBuilder annotation,
1946                                 Map<? extends ExecutableElement, ? extends AnnotationValue> map,
1947                                 int indent, boolean linkBreak) {
1948         linkInfo.label = new StringContent("@");
1949         linkInfo.label.add(annotationDoc.getSimpleName());
1950         annotation.add(getLink(linkInfo));
1951         if (!map.isEmpty()) {
1952             annotation.add("(");
1953             boolean isFirst = true;
1954             Set<? extends ExecutableElement> keys = map.keySet();
1955             boolean multipleValues = keys.size() > 1;
1956             for (ExecutableElement element : keys) {
1957                 if (isFirst) {
1958                     isFirst = false;
1959                 } else {
1960                     annotation.add(",");
1961                     if (linkBreak) {
1962                         annotation.add(DocletConstants.NL);
1963                         int spaces = annotationDoc.getSimpleName().length() + 2;
1964                         for (int k = 0; k < (spaces + indent); k++) {
1965                             annotation.add(" ");
1966                         }
1967                     }
1968                 }
1969                 String simpleName = element.getSimpleName().toString();
1970                 if (multipleValues || !"value".equals(simpleName)) { // Omit "value=" where unnecessary
1971                     annotation.add(getDocLink(LinkInfoImpl.Kind.ANNOTATION,
1972                                                      element, simpleName, false));
1973                     annotation.add("=");
1974                 }
1975                 AnnotationValue annotationValue = map.get(element);
1976                 List<AnnotationValue> annotationTypeValues = new ArrayList<>();
1977                 new SimpleAnnotationValueVisitor9<Void, AnnotationValue>() {
1978                     @Override
1979                     public Void visitArray(List<? extends AnnotationValue> vals, AnnotationValue p) {
1980                         annotationTypeValues.addAll(vals);
1981                         return null;
1982                     }
1983                     @Override
1984                     protected Void defaultAction(Object o, AnnotationValue p) {


2057             public Content visitType(TypeMirror t, Void p) {
2058                 return new SimpleTypeVisitor9<Content, Void>() {
2059                     @Override
2060                     public Content visitDeclared(DeclaredType t, Void p) {
2061                         LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
2062                                 LinkInfoImpl.Kind.ANNOTATION, t);
2063                         String name = utils.isIncluded(t.asElement())
2064                                 ? t.asElement().getSimpleName().toString()
2065                                 : utils.getFullyQualifiedName(t.asElement());
2066                         linkInfo.label = new StringContent(name + utils.getDimension(t) + ".class");
2067                         return getLink(linkInfo);
2068                     }
2069                     @Override
2070                     protected Content defaultAction(TypeMirror e, Void p) {
2071                         return new StringContent(t + utils.getDimension(t) + ".class");
2072                     }
2073                 }.visit(t);
2074             }
2075             @Override
2076             public Content visitAnnotation(AnnotationMirror a, Void p) {
2077                 List<Content> list = getAnnotations(0, a, false);
2078                 ContentBuilder buf = new ContentBuilder();
2079                 for (Content c : list) {
2080                     buf.add(c);
2081                 }
2082                 return buf;
2083             }
2084             @Override
2085             public Content visitEnumConstant(VariableElement c, Void p) {
2086                 return getDocLink(LinkInfoImpl.Kind.ANNOTATION,
2087                         c, c.getSimpleName(), false);
2088             }
2089             @Override
2090             public Content visitArray(List<? extends AnnotationValue> vals, Void p) {
2091                 ContentBuilder buf = new ContentBuilder();
2092                 String sep = "";
2093                 for (AnnotationValue av : vals) {
2094                     buf.add(sep);
2095                     buf.add(visit(av));
2096                     sep = " ";
2097                 }


< prev index next >