< prev index next >

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

Print this page

        

@@ -25,11 +25,10 @@
 
 package jdk.javadoc.internal.doclets.formats.html;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Locale;
 import java.util.Map;

@@ -196,18 +195,10 @@
     protected String winTitle;
 
     protected Script mainBodyScript;
 
     /**
-     * A table of the anchors used for at-index and related tags,
-     * so that they can be made unique by appending a suitable suffix.
-     * (Ideally, javadoc should be tracking all id's generated in a file
-     * to avoid generating duplicates.)
-     */
-    Map<String, Integer> indexAnchorTable = new HashMap<>();
-
-    /**
      * Constructor to construct the HtmlStandardWriter object.
      *
      * @param configuration the configuration for this doclet
      * @param path the file to be generated.
      */

@@ -1722,90 +1713,135 @@
      * @param packageElement the package to write annotations for.
      * @param htmltree the documentation tree to which the annotation info will be
      *        added
      */
     public void addAnnotationInfo(PackageElement packageElement, Content htmltree) {
-        addAnnotationInfo(packageElement.getAnnotationMirrors(), htmltree);
+        addAnnotationInfo(packageElement, packageElement.getAnnotationMirrors(), htmltree);
+    }
+
+    /**
+     * Add the annotation types of the executable receiver.
+     *
+     * @param method the executable to write the receiver annotations for.
+     * @param descList a list of annotation mirrors.
+     * @param htmltree the documentation tree to which the annotation info will be
+     *        added
+     */
+    public void addReceiverAnnotationInfo(ExecutableElement method, List<AnnotationMirror> descList,
+            Content htmltree) {
+        addAnnotationInfo(0, method, descList, false, htmltree);
     }
 
     /*
      * this is a hack to delay dealing with Annotations in the writers, the assumption
      * is that all necessary checks have been made to get here.
      */
     public void addReceiverAnnotationInfo(ExecutableElement method, TypeMirror rcvrTypeMirror,
             List<? extends AnnotationMirror> annotationMirrors, Content htmltree) {
         TypeMirror rcvrType = method.getReceiverType();
         List<? extends AnnotationMirror> annotationMirrors1 = rcvrType.getAnnotationMirrors();
-        htmltree.add(getAnnotationInfo(annotationMirrors1, false));
+        addAnnotationInfo(0, method, annotationMirrors1, false, htmltree);
     }
 
     /**
      * Adds the annotation types for the given element.
      *
      * @param element the package to write annotations for
      * @param htmltree the content tree to which the annotation types will be added
      */
     public void addAnnotationInfo(Element element, Content htmltree) {
-        addAnnotationInfo(element.getAnnotationMirrors(), htmltree);
+        addAnnotationInfo(element, element.getAnnotationMirrors(), htmltree);
     }
 
     /**
      * Add the annotatation types for the given element and parameter.
      *
+     * @param indent the number of spaces to indent the parameters.
+     * @param element the element to write annotations for.
      * @param param the parameter to write annotations for.
      * @param tree the content tree to which the annotation types will be added
      */
-    public boolean addAnnotationInfo(VariableElement param, Content tree) {
-        Content annotaionInfo = getAnnotationInfo(param.getAnnotationMirrors(), false);
-        if (annotaionInfo.isEmpty()) {
-            return false;
-        }
-        tree.add(annotaionInfo);
-        return true;
+    public boolean addAnnotationInfo(int indent, Element element, VariableElement param,
+            Content tree) {
+        return addAnnotationInfo(indent, element, param.getAnnotationMirrors(), false, tree);
     }
 
     /**
      * Adds the annotatation types for the given Element.
      *
+     * @param element the element to write annotations for.
      * @param descList a list of annotation mirrors.
      * @param htmltree the documentation tree to which the annotation info will be
      *        added
      */
-    private void addAnnotationInfo(List<? extends AnnotationMirror> descList, Content htmltree) {
-        htmltree.add(getAnnotationInfo(descList, true));
+    private void addAnnotationInfo(Element element, List<? extends AnnotationMirror> descList,
+            Content htmltree) {
+        addAnnotationInfo(0, element, descList, true, htmltree);
     }
 
     /**
-     * Return a content tree containing the annotation types for the given element.
+     * Adds the annotation types for the given element.
      *
+     * @param indent the number of extra spaces to indent the annotations.
+     * @param element the element to write annotations for.
      * @param descList a list of annotation mirrors.
-     * @return the documentation tree containing the annotation info.
+     * @param htmltree the documentation tree to which the annotation info will be
+     *        added
      */
-    Content getAnnotationInfo(List<? extends AnnotationMirror> descList, boolean lineBreak) {
-        List<Content> annotations = getAnnotations(descList, lineBreak);
+    private boolean addAnnotationInfo(int indent, Element element,
+            List<? extends AnnotationMirror> descList, boolean lineBreak, Content htmltree) {
+        List<Content> annotations = getAnnotations(indent, descList, lineBreak);
         String sep = "";
-        ContentBuilder builder = new ContentBuilder();
+        if (annotations.isEmpty()) {
+            return false;
+        }
         for (Content annotation: annotations) {
-            builder.add(sep);
-            builder.add(annotation);
+            htmltree.add(sep);
+            htmltree.add(annotation);
             if (!lineBreak) {
                 sep = " ";
             }
         }
-        return builder;
+        return true;
+    }
+
+   /**
+     * Return the string representations of the annotation types for
+     * the given doc.
+     *
+     * @param indent the number of extra spaces to indent the annotations.
+     * @param descList a list of annotation mirrors.
+     * @param linkBreak if true, add new line between each member value.
+     * @return a list of strings representing the annotations being
+     *         documented.
+     */
+    private List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList, boolean linkBreak) {
+        return getAnnotations(indent, descList, linkBreak, true);
+    }
+
+    private List<Content> getAnnotations(int indent, AnnotationMirror amirror, boolean linkBreak) {
+        List<AnnotationMirror> descList = new ArrayList<>();
+        descList.add(amirror);
+        return getAnnotations(indent, descList, linkBreak, true);
     }
 
     /**
      * Return the string representations of the annotation types for
      * the given doc.
      *
+     * A {@code null} {@code elementType} indicates that all the
+     * annotations should be returned without any filtering.
+     *
+     * @param indent the number of extra spaces to indent the annotations.
      * @param descList a list of annotation mirrors.
      * @param linkBreak if true, add new line between each member value.
+     * @param isJava5DeclarationLocation
      * @return a list of strings representing the annotations being
      *         documented.
      */
-    public List<Content> getAnnotations(List<? extends AnnotationMirror> descList, boolean linkBreak) {
+    public List<Content> getAnnotations(int indent, List<? extends AnnotationMirror> descList,
+            boolean linkBreak, boolean isJava5DeclarationLocation) {
         List<Content> results = new ArrayList<>();
         ContentBuilder annotation;
         for (AnnotationMirror aDesc : descList) {
             TypeElement annotationElement = (TypeElement)aDesc.getAnnotationType().asElement();
             // If an annotation is not documented, do not add it to the list. If

@@ -1815,10 +1851,15 @@
             // but its container is documented, it will be added to the list.
             if (!utils.isDocumentedAnnotation(annotationElement) &&
                 (!isAnnotationDocumented && !isContainerDocumented)) {
                 continue;
             }
+            /* TODO: check logic here to correctly handle declaration
+             * and type annotations.
+            if  (utils.isDeclarationAnnotation(annotationElement, isJava5DeclarationLocation)) {
+                continue;
+            }*/
             annotation = new ContentBuilder();
             isAnnotationDocumented = false;
             LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
                                                      LinkInfoImpl.Kind.ANNOTATION, annotationElement);
             Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = aDesc.getElementValues();

@@ -1857,11 +1898,13 @@
                     List<AnnotationValue> annotationTypeValues = new ArrayList<>();
                     for (AnnotationValue a :  pairs.values()) {
                         new SimpleAnnotationValueVisitor9<Void, List<AnnotationValue>>() {
                             @Override
                             public Void visitArray(List<? extends AnnotationValue> vals, List<AnnotationValue> annotationTypeValues) {
-                               annotationTypeValues.addAll(vals);
+                               for (AnnotationValue av : vals) {
+                                   annotationTypeValues.add(av);
+                               }
                                return null;
                             }
                         }.visit(a, annotationTypeValues);
                     }
                     String sep = "";

@@ -1872,15 +1915,17 @@
                     }
                 }
                 // If the container has 1 or more value defined and if the
                 // repeatable type annotation is not documented, print the container.
                 else {
-                    addAnnotations(annotationElement, linkInfo, annotation, pairs, false);
+                    addAnnotations(annotationElement, linkInfo, annotation, pairs,
+                                   indent, false);
                 }
             }
             else {
-                addAnnotations(annotationElement, linkInfo, annotation, pairs, linkBreak);
+                addAnnotations(annotationElement, linkInfo, annotation, pairs,
+                               indent, linkBreak);
             }
             annotation.add(linkBreak ? DocletConstants.NL : "");
             results.add(annotation);
         }
         return results;

@@ -1891,16 +1936,17 @@
      *
      * @param annotationDoc the annotation being documented
      * @param linkInfo the information about the link
      * @param annotation the annotation string to which the annotation will be added
      * @param map annotation type element to annotation value pairs
+     * @param indent the number of extra spaces to indent the annotations.
      * @param linkBreak if true, add new line between each member value
      */
     private void addAnnotations(TypeElement annotationDoc, LinkInfoImpl linkInfo,
                                 ContentBuilder annotation,
                                 Map<? extends ExecutableElement, ? extends AnnotationValue> map,
-                                boolean linkBreak) {
+                                int indent, boolean linkBreak) {
         linkInfo.label = new StringContent("@");
         linkInfo.label.add(annotationDoc.getSimpleName());
         annotation.add(getLink(linkInfo));
         if (!map.isEmpty()) {
             annotation.add("(");

@@ -1913,11 +1959,11 @@
                 } else {
                     annotation.add(",");
                     if (linkBreak) {
                         annotation.add(DocletConstants.NL);
                         int spaces = annotationDoc.getSimpleName().length() + 2;
-                        for (int k = 0; k < (spaces); k++) {
+                        for (int k = 0; k < (spaces + indent); k++) {
                             annotation.add(" ");
                         }
                     }
                 }
                 String simpleName = element.getSimpleName().toString();

@@ -2026,11 +2072,11 @@
                     }
                 }.visit(t);
             }
             @Override
             public Content visitAnnotation(AnnotationMirror a, Void p) {
-                List<Content> list = getAnnotations(List.of(a), false);
+                List<Content> list = getAnnotations(0, a, false);
                 ContentBuilder buf = new ContentBuilder();
                 for (Content c : list) {
                     buf.add(c);
                 }
                 return buf;
< prev index next >