src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
changeset 47988 fb0b9913ff7e
parent 47453 b4beec6a0a25
child 48028 9e022f580a9d
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Wed Nov 29 15:01:16 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Wed Nov 29 15:27:47 2017 -0800
@@ -55,6 +55,8 @@
 import javax.lang.model.type.NoType;
 import javax.lang.model.type.PrimitiveType;
 import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.type.WildcardType;
 import javax.lang.model.util.ElementFilter;
 import javax.lang.model.util.ElementKindVisitor9;
 import javax.lang.model.util.Elements;
@@ -976,71 +978,40 @@
     }
 
     /**
-     * For the class return all implemented interfaces including the
-     * superinterfaces of the implementing interfaces, also iterate over for
-     * all the superclasses. For interface return all the extended interfaces
-     * as well as superinterfaces for those extended interfaces.
+     * Returns all the implemented super-interfaces of a given type,
+     * in the case of classes, include all the super-interfaces of
+     * the supertype. The super-interfaces are collected before the
+     * super-interfaces of the supertype.
      *
-     * @param  te the class to get the interfaces for
-     * @return List of all the required interfaces.
+     * @param  te the type element to get the super-interfaces for.
+     * @return the list of super-interfaces.
      */
     public Set<TypeMirror> getAllInterfaces(TypeElement te) {
         Set<TypeMirror> results = new LinkedHashSet<>();
-
-        List<? extends TypeMirror> interfaceTypes = te.getInterfaces();
-
-        for (TypeMirror interfaceType : interfaceTypes) {
-            TypeElement intfc = asTypeElement(interfaceType);
-
-            if (isPublic(intfc) || isLinkable(intfc)) {
-                results.add(interfaceType);
-                TypeElement klass = asTypeElement(interfaceType);
-                for (TypeMirror t : getAllInterfaces(klass)) {
-                    t = getDeclaredType(results, te, t);
-                    results.add(t);
-                }
-            }
-        }
-        // TypeMirror contains the modified TypeParameterElement's types represented
-        // in the local Class'es elements types. ex: Foo<E> implements Bar<V> and the
-        // class being considered is Foo then TypeParameters will be represented as <E>
-        // note that any conversion might revert back to the old signature. For this
-        // very reason we get the superType, and find its interfaces.
-        TypeMirror superType = getSuperType(te);
-        if (superType == getObjectType())
-            return results;
-        // Try walking the tree
-        addAllInterfaceTypes(results, te, superType,
-                configuration.workArounds.interfaceTypesOf(superType));
+        getAllInterfaces(te.asType(), results);
         return results;
     }
 
-    private void findAllInterfaceTypes(Set<TypeMirror> results, final TypeElement baseClass,
-            TypeMirror p) {
-        TypeMirror superType = getSuperType(asTypeElement(p));
-        if (superType == p) {
-            return;
-        }
-        addAllInterfaceTypes(results, baseClass, superType,
-                configuration.workArounds.interfaceTypesOf(superType));
-    }
-
-    private void addAllInterfaceTypes(Set<TypeMirror> results,
-            final TypeElement baseClass, TypeMirror type,
-            List<TypeMirror> interfaceTypes) {
-        for (TypeMirror interfaceType : interfaceTypes) {
-            TypeElement iElement = asTypeElement(interfaceType);
-            if (isPublic(iElement) && isLinkable(iElement)) {
-                interfaceType = getDeclaredType(results, baseClass, interfaceType);
-                results.add(interfaceType);
-                Set<TypeMirror> superInterfaces = getAllInterfaces(iElement);
-                for (TypeMirror superInterface : superInterfaces) {
-                    superInterface = getDeclaredType(results, baseClass, superInterface);
-                    results.add(superInterface);
-                }
+    private void getAllInterfaces(TypeMirror type, Set<TypeMirror> results) {
+        List<? extends TypeMirror> intfacs = typeUtils.directSupertypes(type);
+        TypeMirror superType = null;
+        for (TypeMirror intfac : intfacs) {
+            if (intfac == getObjectType())
+                continue;
+            TypeElement e = asTypeElement(intfac);
+            if (isInterface(e)) {
+                if (isPublic(e) || isLinkable(e))
+                    results.add(intfac);
+
+                getAllInterfaces(intfac, results);
+            } else {
+                // Save the supertype for later.
+                superType = intfac;
             }
         }
-        findAllInterfaceTypes(results, baseClass, type);
+        // Collect the super-interfaces of the supertype.
+        if (superType != null)
+            getAllInterfaces(superType, results);
     }
 
     /**
@@ -1154,22 +1125,6 @@
                 (isPublic(typeElem) || isProtected(typeElem)));
     }
 
-    List<TypeMirror> asErasureTypes(Collection<TypeElement> inList) {
-        List<TypeMirror> out = new ArrayList<>(inList.size());
-        inList.stream().forEach((te) -> {
-            out.add(typeUtils.erasure(te.asType()));
-        });
-        return out;
-    }
-
-    List<TypeMirror> asTypes(Collection<TypeElement> inList) {
-        List<TypeMirror> out = new ArrayList<>(inList.size());
-        inList.stream().forEach((te) -> {
-            out.add(te.asType());
-        });
-        return out;
-    }
-
     /**
      * Return this type as a {@code TypeElement} if it represents a class
      * interface or annotation.  Array dimensions are ignored.
@@ -1195,10 +1150,9 @@
             }
 
             @Override
-            public TypeElement visitTypeVariable(javax.lang.model.type.TypeVariable t, Void p) {
-               /*
-                * TODO: Check with JJG.
-                * if we have an annotated type @A $B T, then erasure returns a
+            public TypeElement visitTypeVariable(TypeVariable t, Void p) {
+               /* TODO, this may not be an optimimal fix.
+                * if we have an annotated type @DA T, then erasure returns a
                 * none, in this case we use asElement instead.
                 */
                 if (isAnnotated(t)) {
@@ -1208,7 +1162,7 @@
             }
 
             @Override
-            public TypeElement visitWildcard(javax.lang.model.type.WildcardType t, Void p) {
+            public TypeElement visitWildcard(WildcardType t, Void p) {
                 return visit(typeUtils.erasure(t));
             }