< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Module.java

Print this page




  41     static final String JDK_UNSUPPORTED = "jdk.unsupported";
  42 
  43     static final boolean DEBUG = Boolean.getBoolean("jdeps.debug");
  44     static void trace(String fmt, Object... args) {
  45         trace(DEBUG, fmt, args);
  46     }
  47 
  48     static void trace(boolean traceOn, String fmt, Object... args) {
  49         if (traceOn) {
  50             System.err.format(fmt, args);
  51         }
  52     }
  53 
  54     private final ModuleDescriptor descriptor;
  55     private final Map<String, Set<String>> exports;
  56     private final Map<String, Set<String>> opens;
  57     private final boolean isSystem;
  58     private final URI location;
  59 
  60     protected Module(String name) {




  61         super(name);
  62         this.descriptor = null;
  63         this.location = null;
  64         this.exports = Collections.emptyMap();
  65         this.opens = Collections.emptyMap();
  66         this.isSystem = true;
  67     }
  68 
  69     private Module(String name,
  70                    URI location,
  71                    ModuleDescriptor descriptor,
  72                    Map<String, Set<String>> exports,
  73                    Map<String, Set<String>> opens,
  74                    boolean isSystem,
  75                    ClassFileReader reader) {
  76         super(name, location, reader);
  77         this.descriptor = descriptor;
  78         this.location = location;
  79         this.exports = Collections.unmodifiableMap(exports);
  80         this.opens = Collections.unmodifiableMap(opens);
  81         this.isSystem = isSystem;
  82     }
  83 
  84     /**
  85      * Returns module name
  86      */
  87     public String name() {
  88         return descriptor != null ? descriptor.name() : getName();
  89     }
  90 
  91     public boolean isNamed() {
  92         return true;
  93     }
  94 
  95     public boolean isAutomatic() {
  96         return descriptor.isAutomatic();
  97     }
  98 
  99     public Module getModule() {
 100         return this;
 101     }
 102 
 103     public ModuleDescriptor descriptor() {
 104         return descriptor;
 105     }
 106 
 107     public URI location() {
 108         return location;
 109     }
 110 
 111     public boolean isJDK() {
 112         String mn = name();
 113         return isSystem &&
 114             (mn.startsWith("java.") || mn.startsWith("jdk.") || mn.startsWith("javafx."));
 115     }
 116 


 215             Map<String, Set<String>> opens = new HashMap<>();
 216 
 217             if (descriptor.isAutomatic()) {
 218                 // ModuleDescriptor::exports and opens returns an empty set
 219                 descriptor.packages().forEach(pn -> exports.put(pn, Collections.emptySet()));
 220                 descriptor.packages().forEach(pn -> opens.put(pn, Collections.emptySet()));
 221             } else {
 222                 descriptor.exports().stream()
 223                           .forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
 224                                                  .addAll(exp.targets()));
 225                 descriptor.opens().stream()
 226                     .forEach(exp -> opens.computeIfAbsent(exp.source(), _k -> new HashSet<>())
 227                         .addAll(exp.targets()));
 228             }
 229             return new Module(name, location, descriptor, exports, opens, isSystem, reader);
 230         }
 231     }
 232 
 233     private static class UnnamedModule extends Module {
 234         private UnnamedModule() {
 235             super("unnamed", null, null,
 236                   Collections.emptyMap(), Collections.emptyMap(),
 237                   false, null);
 238         }
 239 
 240         @Override
 241         public String name() {
 242             return "unnamed";
 243         }
 244 
 245         @Override
 246         public boolean isNamed() {
 247             return false;
 248         }
 249 
 250         @Override
 251         public boolean isAutomatic() {
 252             return false;
 253         }
 254 
 255         @Override
 256         public boolean isExported(String pn) {
 257             return true;
 258         }
 259     }
 260 
 261     /**
 262      * A normal module has a module-info.class
 263      */
 264     private static class NormalModule extends Module {
 265         private final ModuleDescriptor md;
 266 
 267         /**
 268          * Converts the given automatic module to a normal module.
 269          *
 270          * Replace this module's dependences with the given requires and also
 271          * declare service providers, if specified in META-INF/services configuration file
 272          */
 273         private NormalModule(Module m, Map<String, Boolean> requires) {
 274             super(m.name(), m.location, m.descriptor, m.exports, m.opens, m.isSystem, m.reader());
 275 




  41     static final String JDK_UNSUPPORTED = "jdk.unsupported";
  42 
  43     static final boolean DEBUG = Boolean.getBoolean("jdeps.debug");
  44     static void trace(String fmt, Object... args) {
  45         trace(DEBUG, fmt, args);
  46     }
  47 
  48     static void trace(boolean traceOn, String fmt, Object... args) {
  49         if (traceOn) {
  50             System.err.format(fmt, args);
  51         }
  52     }
  53 
  54     private final ModuleDescriptor descriptor;
  55     private final Map<String, Set<String>> exports;
  56     private final Map<String, Set<String>> opens;
  57     private final boolean isSystem;
  58     private final URI location;
  59 
  60     protected Module(String name) {
  61         this(name, null, false);
  62     }
  63 
  64     protected Module(String name, ModuleDescriptor descriptor, boolean isSystem) {
  65         super(name);
  66         this.descriptor = descriptor;
  67         this.location = null;
  68         this.exports = Collections.emptyMap();
  69         this.opens = Collections.emptyMap();
  70         this.isSystem = isSystem;
  71     }
  72 
  73     private Module(String name,
  74                    URI location,
  75                    ModuleDescriptor descriptor,
  76                    Map<String, Set<String>> exports,
  77                    Map<String, Set<String>> opens,
  78                    boolean isSystem,
  79                    ClassFileReader reader) {
  80         super(name, location, reader);
  81         this.descriptor = descriptor;
  82         this.location = location;
  83         this.exports = Collections.unmodifiableMap(exports);
  84         this.opens = Collections.unmodifiableMap(opens);
  85         this.isSystem = isSystem;
  86     }
  87 
  88     /**
  89      * Returns module name
  90      */
  91     public String name() {
  92         return descriptor != null ? descriptor.name() : getName();
  93     }
  94 
  95     public boolean isNamed() {
  96         return descriptor != null;
  97     }
  98 
  99     public boolean isAutomatic() {
 100         return descriptor != null && descriptor.isAutomatic();
 101     }
 102 
 103     public Module getModule() {
 104         return this;
 105     }
 106 
 107     public ModuleDescriptor descriptor() {
 108         return descriptor;
 109     }
 110 
 111     public URI location() {
 112         return location;
 113     }
 114 
 115     public boolean isJDK() {
 116         String mn = name();
 117         return isSystem &&
 118             (mn.startsWith("java.") || mn.startsWith("jdk.") || mn.startsWith("javafx."));
 119     }
 120 


 219             Map<String, Set<String>> opens = new HashMap<>();
 220 
 221             if (descriptor.isAutomatic()) {
 222                 // ModuleDescriptor::exports and opens returns an empty set
 223                 descriptor.packages().forEach(pn -> exports.put(pn, Collections.emptySet()));
 224                 descriptor.packages().forEach(pn -> opens.put(pn, Collections.emptySet()));
 225             } else {
 226                 descriptor.exports().stream()
 227                           .forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
 228                                                  .addAll(exp.targets()));
 229                 descriptor.opens().stream()
 230                     .forEach(exp -> opens.computeIfAbsent(exp.source(), _k -> new HashSet<>())
 231                         .addAll(exp.targets()));
 232             }
 233             return new Module(name, location, descriptor, exports, opens, isSystem, reader);
 234         }
 235     }
 236 
 237     private static class UnnamedModule extends Module {
 238         private UnnamedModule() {
 239             super("unnamed", null, false);


 240         }
 241 
 242         @Override
 243         public String name() {
 244             return "unnamed";
 245         }
 246 
 247         @Override










 248         public boolean isExported(String pn) {
 249             return true;
 250         }
 251     }
 252 
 253     /**
 254      * A normal module has a module-info.class
 255      */
 256     private static class NormalModule extends Module {
 257         private final ModuleDescriptor md;
 258 
 259         /**
 260          * Converts the given automatic module to a normal module.
 261          *
 262          * Replace this module's dependences with the given requires and also
 263          * declare service providers, if specified in META-INF/services configuration file
 264          */
 265         private NormalModule(Module m, Map<String, Boolean> requires) {
 266             super(m.name(), m.location, m.descriptor, m.exports, m.opens, m.isSystem, m.reader());
 267 


< prev index next >