src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/EnumConstantBuilder.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -21,18 +21,24 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package com.sun.tools.doclets.internal.toolkit.builders;
+package jdk.javadoc.internal.doclets.toolkit.builders;
 
 import java.util.*;
 
-import com.sun.javadoc.*;
-import com.sun.tools.doclets.internal.toolkit.*;
-import com.sun.tools.doclets.internal.toolkit.util.*;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
 
+import jdk.javadoc.internal.doclets.toolkit.Configuration;
+import jdk.javadoc.internal.doclets.toolkit.Content;
+import jdk.javadoc.internal.doclets.toolkit.EnumConstantWriter;
+import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap;
+
+
 /**
  * Builds documentation for a enum constants.
  *
  *  <p><b>This is NOT part of any supported API.
  *  If you write code that depends on this, you do so at your own risk.

@@ -46,11 +52,11 @@
 public class EnumConstantBuilder extends AbstractMemberBuilder {
 
     /**
      * The class whose enum constants are being documented.
      */
-    private final ClassDoc classDoc;
+    private final TypeElement typeElement;
 
     /**
      * The visible enum constantss for the given class.
      */
     private final VisibleMemberMap visibleMemberMap;

@@ -61,70 +67,68 @@
     private final EnumConstantWriter writer;
 
     /**
      * The list of enum constants being documented.
      */
-    private final List<ProgramElementDoc> enumConstants;
+    private final SortedSet<Element> enumConstants;
 
     /**
-     * The index of the current enum constant that is being documented at this point
+     * The current enum constant that is being documented at this point
      * in time.
      */
-    private int currentEnumConstantsIndex;
+    private VariableElement currentElement;
 
     /**
      * Construct a new EnumConstantsBuilder.
      *
      * @param context  the build context.
-     * @param classDoc the class whoses members are being documented.
+     * @param typeElement the class whose members are being documented.
      * @param writer the doclet specific writer.
      */
     private EnumConstantBuilder(Context context,
-            ClassDoc classDoc, EnumConstantWriter writer) {
+            TypeElement typeElement, EnumConstantWriter writer) {
         super(context);
-        this.classDoc = classDoc;
+        this.typeElement = typeElement;
         this.writer = writer;
         visibleMemberMap =
                 new VisibleMemberMap(
-                classDoc,
-                VisibleMemberMap.ENUM_CONSTANTS,
+                typeElement,
+                VisibleMemberMap.Kind.ENUM_CONSTANTS,
                 configuration);
-        enumConstants = new ArrayList<>(visibleMemberMap.getMembersFor(classDoc));
-        if (configuration.getMemberComparator() != null) {
-            Collections.sort(enumConstants, configuration.getMemberComparator());
+        enumConstants = visibleMemberMap.getMembersFor(typeElement);
         }
-    }
 
     /**
      * Construct a new EnumConstantsBuilder.
      *
      * @param context  the build context.
-     * @param classDoc the class whoses members are being documented.
+     * @param typeElement the class whoses members are being documented.
      * @param writer the doclet specific writer.
      */
     public static EnumConstantBuilder getInstance(Context context,
-            ClassDoc classDoc, EnumConstantWriter writer) {
-        return new EnumConstantBuilder(context, classDoc, writer);
+            TypeElement typeElement, EnumConstantWriter writer) {
+        return new EnumConstantBuilder(context, typeElement, writer);
     }
 
     /**
      * {@inheritDoc}
      */
+    @Override
     public String getName() {
         return "EnumConstantDetails";
     }
 
     /**
      * Returns a list of enum constants that will be documented for the given class.
      * This information can be used for doclet specific documentation
      * generation.
      *
-     * @param classDoc the {@link ClassDoc} we want to check.
+     * @param typeElement the {@link TypeElement} we want to check.
      * @return a list of enum constants that will be documented.
      */
-    public List<ProgramElementDoc> members(ClassDoc classDoc) {
-        return visibleMemberMap.getMembersFor(classDoc);
+    public SortedSet<Element> members(TypeElement typeElement) {
+        return visibleMemberMap.getMembersFor(typeElement);
     }
 
     /**
      * Returns the visible member map for the enum constants of this class.
      *

@@ -135,10 +139,11 @@
     }
 
     /**
      * summaryOrder.size()
      */
+    @Override
     public boolean hasMembersToDocument() {
         return enumConstants.size() > 0;
     }
 
     /**

@@ -149,22 +154,20 @@
      */
     public void buildEnumConstant(XMLNode node, Content memberDetailsTree) {
         if (writer == null) {
             return;
         }
-        int size = enumConstants.size();
-        if (size > 0) {
-            Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(
-                    classDoc, memberDetailsTree);
-            for (currentEnumConstantsIndex = 0; currentEnumConstantsIndex < size;
-                    currentEnumConstantsIndex++) {
-                Content enumConstantsTree = writer.getEnumConstantsTreeHeader(
-                        (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
+        if (!enumConstants.isEmpty()) {
+            Content enumConstantsDetailsTree = writer.getEnumConstantsDetailsTreeHeader(typeElement,
+                    memberDetailsTree);
+            for (Element element : enumConstants) {
+                currentElement = (VariableElement)element;
+                Content enumConstantsTree = writer.getEnumConstantsTreeHeader(currentElement,
                         enumConstantsDetailsTree);
                 buildChildren(node, enumConstantsTree);
                 enumConstantsDetailsTree.addContent(writer.getEnumConstants(
-                        enumConstantsTree, (currentEnumConstantsIndex == size - 1)));
+                        enumConstantsTree, currentElement.equals(enumConstants.last())));
             }
             memberDetailsTree.addContent(
                     writer.getEnumConstantsDetails(enumConstantsDetailsTree));
         }
     }

@@ -174,24 +177,21 @@
      *
      * @param node the XML element that specifies which components to document
      * @param enumConstantsTree the content tree to which the documentation will be added
      */
     public void buildSignature(XMLNode node, Content enumConstantsTree) {
-        enumConstantsTree.addContent(writer.getSignature(
-                (FieldDoc) enumConstants.get(currentEnumConstantsIndex)));
+        enumConstantsTree.addContent(writer.getSignature(currentElement));
     }
 
     /**
      * Build the deprecation information.
      *
      * @param node the XML element that specifies which components to document
      * @param enumConstantsTree the content tree to which the documentation will be added
      */
     public void buildDeprecationInfo(XMLNode node, Content enumConstantsTree) {
-        writer.addDeprecated(
-                (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
-                enumConstantsTree);
+        writer.addDeprecated(currentElement, enumConstantsTree);
     }
 
     /**
      * Build the comments for the enum constant.  Do nothing if
      * {@link Configuration#nocomment} is set to true.

@@ -199,13 +199,11 @@
      * @param node the XML element that specifies which components to document
      * @param enumConstantsTree the content tree to which the documentation will be added
      */
     public void buildEnumConstantComments(XMLNode node, Content enumConstantsTree) {
         if (!configuration.nocomment) {
-            writer.addComments(
-                    (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
-                    enumConstantsTree);
+            writer.addComments(currentElement, enumConstantsTree);
         }
     }
 
     /**
      * Build the tag information.

@@ -212,13 +210,11 @@
      *
      * @param node the XML element that specifies which components to document
      * @param enumConstantsTree the content tree to which the documentation will be added
      */
     public void buildTagInfo(XMLNode node, Content enumConstantsTree) {
-        writer.addTags(
-                (FieldDoc) enumConstants.get(currentEnumConstantsIndex),
-                enumConstantsTree);
+        writer.addTags(currentElement, enumConstantsTree);
     }
 
     /**
      * Return the enum constant writer for this builder.
      *