Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4672021

stddoclet: Combine near-duplicate methods for getting package path: getPackagePath, getDirectoryPath

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: tools

      Description

      I notice we have a method SourceToHTMLConverter called getPackagePath that is
      nearly identical in function to one DirectoryManager called getDirectoryPath.
      It looks like the first method always ends in a slash while the other
      doesn't. They could still be reduced to a single method.

      I'd favor the first implementation, which has fewer lines, uses methods
      designed specifically for this task, and it has a better
      name. It should be using StringBuffer rather than String,
      and should be located in DirectoryManager.

      We need to decide whether the method should keep the trailing slash or not.

          /**
           * Get the package path
           * @param pd the package to get the path for.
           * @return a path for the package
           */
          public static String getPackagePath(PackageDoc pd) {
              if (pd == null) {
                  return "";
              }
              StringTokenizer st = new StringTokenizer(pd.name(), ".");
              String result = "";
              while (st.hasMoreTokens()) {
                  result += st.nextToken() + File.separator;
              }
              return result;
          }


           public static String getDirectoryPath(PackageDoc pd) {
              if (pd == null) {
                  return "";
              }
              String name = pd.name();
              StringBuffer pathstr = new StringBuffer();
              for (int i = 0; i < name.length(); i++) {
                  char ch = name.charAt(i);
                  if (ch == '.') {
                      pathstr.append(fileseparator);
                  } else {
                      pathstr.append(ch);
                  }
              }
              return pathstr.toString();
          }

        Attachments

          Activity

            People

            Assignee:
            bpatel Bhavesh Patel (Inactive)
            Reporter:
            dkramersunw Douglas Kramer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: