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

jshell tool: make all IMPORTS.jsh generated at build time

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 10
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b33

      Description

      Like this, but at in the make --


          // Compute all SE imports
          private class AllImports {

              ModuleFinder finder = ModuleFinder.ofSystem();

              Set<ModuleDescriptor> seModules() {
                  Set<ModuleDescriptor> closure = new HashSet<>();
                  moduleClosure(finder.find("java.se"), closure);
                  return closure;
              }

              void moduleClosure(Optional<ModuleReference> omr, Set<ModuleDescriptor> closure) {
                  if (omr.isPresent()) {
                      ModuleDescriptor mdesc = omr.get().descriptor();
                      if (closure.add(mdesc)) {
                          for (ModuleDescriptor.Requires req : mdesc.requires()) {
                              if (!req.modifiers().contains(ModuleDescriptor.Requires.Modifier.STATIC)) {
                                  moduleClosure(finder.find(req.name()), closure);
                              }
                          }
                      }
                  }
              }
              
              Set<String> packages() {
                  return seModules().stream().flatMap(md -> md.exports().stream())
                      .filter(e -> !e.isQualified()).map(Object::toString).collect(Collectors.toSet());
              }

              String imports() {
                  Set<String> si = packages();
                  String[] ai = si.toArray(new String[si.size()]);
                  Arrays.sort(ai);
                  return Arrays.stream(ai)
                          .map(p -> String.format("import %s.*;\n", p))
                          .collect(Collectors.joining());
              }
          }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rfield Robert Field
                Reporter:
                rfield Robert Field
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: