changeset 1996:f050c714b556

8008367: Sub-packages missing from Profiles javadoc Reviewed-by: bpatel
author jjg
date Fri, 30 Aug 2013 16:27:08 -0700
parents 7a2fe98cb0e6
children b25e387481dc
files src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java
diffstat 1 files changed, 38 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Fri Aug 30 16:16:28 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Fri Aug 30 16:27:08 2013 -0700
@@ -383,35 +383,44 @@
         DocErrorReporter reporter);
 
     private void initProfiles() throws IOException {
+        if (profilespath.isEmpty())
+            return;
+
         profiles = Profiles.read(new File(profilespath));
-        // Generate profiles documentation only is profilespath is set and if
-        // profiles is not null and profiles count is 1 or more.
-        showProfiles = (!profilespath.isEmpty() && profiles != null &&
-                profiles.getProfileCount() > 0);
-    }
 
-    private void initProfilePackages() throws IOException {
+        // Group the packages to be documented by the lowest profile (if any)
+        // in which each appears
+        Map<Profile, List<PackageDoc>> interimResults =
+                new EnumMap<Profile, List<PackageDoc>>(Profile.class);
+        for (Profile p: Profile.values())
+            interimResults.put(p, new ArrayList<PackageDoc>());
+
+        for (PackageDoc pkg: packages) {
+            // the getProfile method takes a type name, not a package name,
+            // but isn't particularly fussy about the simple name -- so just use *
+            int i = profiles.getProfile(pkg.name().replace(".", "/") + "/*");
+            Profile p = Profile.lookup(i);
+            if (p != null) {
+                List<PackageDoc> pkgs = interimResults.get(p);
+                pkgs.add(pkg);
+            }
+        }
+
+        // Build the profilePackages structure used by the doclet
         profilePackages = new HashMap<String,PackageDoc[]>();
-        ArrayList<PackageDoc> results;
-        Map<String,PackageDoc> packageIndex = new HashMap<String,PackageDoc>();
-        for (int i = 0; i < packages.length; i++) {
-            PackageDoc pkg = packages[i];
-            packageIndex.put(pkg.name(), pkg);
+        List<PackageDoc> prev = Collections.<PackageDoc>emptyList();
+        for (Map.Entry<Profile,List<PackageDoc>> e: interimResults.entrySet()) {
+            Profile p = e.getKey();
+            List<PackageDoc> pkgs =  e.getValue();
+            pkgs.addAll(prev); // each profile contains all lower profiles
+            Collections.sort(pkgs);
+            profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()]));
+            prev = pkgs;
         }
-        for (int i = 1; i < profiles.getProfileCount(); i++) {
-            Set<String> profPkgs = profiles.getPackages(i);
-            results = new ArrayList<PackageDoc>();
-            for (String packageName : profPkgs) {
-                packageName = packageName.replace("/", ".");
-                PackageDoc profPkg = packageIndex.get(packageName);
-                if (profPkg != null) {
-                    results.add(profPkg);
-                }
-            }
-            Collections.sort(results);
-            PackageDoc[] profilePkgs = results.toArray(new PackageDoc[]{});
-            profilePackages.put(Profile.lookup(i).name, profilePkgs);
-        }
+
+        // Generate profiles documentation if any profile contains any
+        // of the packages to be documented.
+        showProfiles = !prev.isEmpty();
     }
 
     private void initPackageArray() {
@@ -534,13 +543,10 @@
     public void setOptions() throws Fault {
         initPackageArray();
         setOptions(root.options());
-        if (!profilespath.isEmpty()) {
-            try {
-                initProfiles();
-                initProfilePackages();
-            } catch (Exception e) {
-                throw new DocletAbortException(e);
-            }
+        try {
+            initProfiles();
+        } catch (Exception e) {
+            throw new DocletAbortException(e);
         }
         setSpecificDocletOptions(root.options());
     }