code: protected void buildIndexMap(RootDoc root)  {
          PackageDoc[] packages = root.specifiedPackages();
          ClassDoc[] classes = root.classes();
          if (!classesOnly) {
              if (packages.length == 0) {
                  Set<PackageDoc> set = new HashSet<>();
                  for (ClassDoc aClass : classes) {
                      PackageDoc pd = aClass.containingPackage();
                      if (pd != null && pd.name().length() > 0) {
                          set.add(pd);
                      }
                  }
                  adjustIndexMap(set.toArray(packages));
              } else {
                  adjustIndexMap(packages);
              }
          }
          adjustIndexMap(classes);
          if (!classesOnly) {
              for (ClassDoc aClass : classes) {
                  if (shouldAddToIndexMap(aClass)) {
                      putMembersInIndexMap(aClass);
                  }
              }
          }
          sortIndexMap();
      }
docs: Get all the members in all the Packages and all the Classes
  given on the command line. Form separate list of those members depending
  upon their names.
  
  @param root Root of the documemt.