langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
changeset 45771 e447c20c3ff9
parent 44385 f777a2822087
child 45864 ac6c2a3326d2
equal deleted inserted replaced
45743:51bca2b0d672 45771:e447c20c3ff9
  1680      */
  1680      */
  1681     public Comparator<Element> makeModuleComparator() {
  1681     public Comparator<Element> makeModuleComparator() {
  1682         return new Utils.ElementComparator<Element>() {
  1682         return new Utils.ElementComparator<Element>() {
  1683             @Override
  1683             @Override
  1684             public int compare(Element mod1, Element mod2) {
  1684             public int compare(Element mod1, Element mod2) {
  1685                 return compareNames(mod1, mod2);
  1685                 return compareFullyQualifiedNames(mod1, mod2);
  1686             }
  1686             }
  1687         };
  1687         };
  1688     }
  1688     }
  1689 
  1689 
  1690     /**
  1690     /**
  1770         };
  1770         };
  1771     }
  1771     }
  1772 
  1772 
  1773     /**
  1773     /**
  1774      * Returns a Comparator for index file presentations, and are sorted as follows.
  1774      * Returns a Comparator for index file presentations, and are sorted as follows.
  1775      *  If comparing modules then simply compare the simple names,
  1775      *  If comparing modules and packages then simply compare the qualified names, if comparing a module
  1776      *  comparing packages then simply compare the qualified names, if comparing a package with a
  1776      *  or a package with a type/member then compare the FullyQualifiedName of the module or a package
  1777      *  module/type/member then compare the FullyQualifiedName of the package
       
  1778      *  with the SimpleName of the entity, otherwise
  1777      *  with the SimpleName of the entity, otherwise
  1779      *  1. compare the ElementKind ex: Module, Package, Interface etc.
  1778      *  1. compare the ElementKind ex: Module, Package, Interface etc.
  1780      *  2a. if equal and if the type is of ExecutableElement(Constructor, Methods),
  1779      *  2a. if equal and if the type is of ExecutableElement(Constructor, Methods),
  1781      *      a case insensitive comparison of parameter the type signatures
  1780      *      a case insensitive comparison of parameter the type signatures
  1782      *  2b. if equal, case sensitive comparison of the type signatures
  1781      *  2b. if equal, case sensitive comparison of the type signatures
  1784      * @return a comparator for index file use
  1783      * @return a comparator for index file use
  1785      */
  1784      */
  1786     public Comparator<Element> makeIndexUseComparator() {
  1785     public Comparator<Element> makeIndexUseComparator() {
  1787         return new Utils.ElementComparator<Element>() {
  1786         return new Utils.ElementComparator<Element>() {
  1788             /**
  1787             /**
  1789              * Compare two given elements, if comparing two modules, return the
  1788              * Compare two given elements, if comparing two modules or two packages, return the
  1790              * comparison of SimpleName, if comparing two packages, return the
  1789              * comparison of FullyQualifiedName, if comparing a module or a package with a
  1791              * comparison of FullyQualifiedName, if comparing a package with a
  1790              * type/member then compare the FullyQualifiedName of the module or the package
  1792              * module/type/member then compare the FullyQualifiedName of the package
       
  1793              * with the SimpleName of the entity, then sort on the kinds, then on
  1791              * with the SimpleName of the entity, then sort on the kinds, then on
  1794              * the parameters only if the type is an ExecutableElement,
  1792              * the parameters only if the type is an ExecutableElement,
  1795              * the parameters are compared and finally the qualified names.
  1793              * the parameters are compared and finally the qualified names.
  1796              *
  1794              *
  1797              * @param e1 - an element.
  1795              * @param e1 - an element.
  1800              *         argument is less than, equal to, or greater than the second.
  1798              *         argument is less than, equal to, or greater than the second.
  1801              */
  1799              */
  1802             @Override
  1800             @Override
  1803             public int compare(Element e1, Element e2) {
  1801             public int compare(Element e1, Element e2) {
  1804                 int result = 0;
  1802                 int result = 0;
  1805                 if (isModule(e1) && isModule(e2)) {
  1803                 if ((isModule(e1) || isPackage(e1)) && (isModule(e2) || isPackage(e2))) {
  1806                     return compareNames(e1, e2);
  1804                     result = compareFullyQualifiedNames(e1, e2);
  1807                 }
  1805                     if (result != 0) {
  1808                 if (isPackage(e1) && isPackage(e2)) {
  1806                         return result;
  1809                     return compareFullyQualifiedNames(e1, e2);
  1807                     }
  1810                 }
  1808                     return compareElementTypeKinds(e1, e2);
  1811                 if (isPackage(e1) || isPackage(e2)) {
  1809                 }
  1812                     result = (isPackage(e1))
  1810                 if (isModule(e1) || isPackage(e1)) {
  1813                             ? compareStrings(getFullyQualifiedName(e1), getSimpleName(e2))
  1811                     result = compareStrings(getFullyQualifiedName(e1), getSimpleName(e2));
  1814                             : compareStrings(getSimpleName(e1), getFullyQualifiedName(e2));
  1812                 } else if (isModule(e2) || isPackage(e2)) {
       
  1813                     result = compareStrings(getSimpleName(e1), getFullyQualifiedName(e2));
  1815                 } else {
  1814                 } else {
  1816                     result = compareNames(e1, e2);
  1815                     result = compareNames(e1, e2);
  1817                 }
  1816                 }
  1818                 if (result != 0) {
  1817                 if (result != 0) {
  1819                     return result;
  1818                     return result;
  1913         return getFullyQualifiedName(e, true);
  1912         return getFullyQualifiedName(e, true);
  1914     }
  1913     }
  1915 
  1914 
  1916     public String getFullyQualifiedName(Element e, final boolean outer) {
  1915     public String getFullyQualifiedName(Element e, final boolean outer) {
  1917         return new SimpleElementVisitor9<String, Void>() {
  1916         return new SimpleElementVisitor9<String, Void>() {
       
  1917             @Override
       
  1918             public String visitModule(ModuleElement e, Void p) {
       
  1919                 return e.getQualifiedName().toString();
       
  1920             }
       
  1921 
  1918             @Override
  1922             @Override
  1919             public String visitPackage(PackageElement e, Void p) {
  1923             public String visitPackage(PackageElement e, Void p) {
  1920                 return e.getQualifiedName().toString();
  1924                 return e.getQualifiedName().toString();
  1921             }
  1925             }
  1922 
  1926 
  2525     private String getSimpleName0(Element e) {
  2529     private String getSimpleName0(Element e) {
  2526         if (snvisitor == null) {
  2530         if (snvisitor == null) {
  2527             snvisitor = new SimpleElementVisitor9<String, Void>() {
  2531             snvisitor = new SimpleElementVisitor9<String, Void>() {
  2528                 @Override
  2532                 @Override
  2529                 public String visitModule(ModuleElement e, Void p) {
  2533                 public String visitModule(ModuleElement e, Void p) {
  2530                     return e.getSimpleName().toString();
  2534                     return e.getQualifiedName().toString();  // temp fix for 8182736
  2531                 }
  2535                 }
  2532 
  2536 
  2533                 @Override
  2537                 @Override
  2534                 public String visitType(TypeElement e, Void p) {
  2538                 public String visitType(TypeElement e, Void p) {
  2535                     StringBuilder sb = new StringBuilder(e.getSimpleName());
  2539                     StringBuilder sb = new StringBuilder(e.getSimpleName());