30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Collections;
33 import java.util.Deque;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Map.Entry;
39 import java.util.Objects;
40 import java.util.Optional;
41 import java.util.Set;
42 import java.util.stream.Collectors;
43 import java.util.stream.Stream;
44
45 import jdk.internal.module.ModuleReferenceImpl;
46 import jdk.internal.module.ModuleTarget;
47
48 /**
49 * A configuration that is the result of <a href="package-summary.html#resolution">
50 * resolution</a> or resolution with <a href="#service-binding">service binding</a>.
51 *
52 * <p> A configuration encapsulates the <em>readability graph</em> that is the
53 * output of resolution. A readability graph is a directed graph whose vertices
54 * are of type {@link ResolvedModule} and the edges represent the readability
55 * amongst the modules. {@code Configuration} defines the {@link #modules()
56 * modules()} method to get the set of resolved modules in the graph. {@code
57 * ResolvedModule} defines the {@link ResolvedModule#reads() reads()} method to
58 * get the set of modules that a resolved module reads. The modules that are
59 * read may be in the same configuration or may be in {@link #parents() parent}
60 * configurations. </p>
61 *
62 * <p> Configuration defines the {@link #resolve(ModuleFinder,List,ModuleFinder,Collection)
63 * resolve} method to resolve a collection of root modules, and the {@link
64 * #resolveAndBind(ModuleFinder,List,ModuleFinder,Collection) resolveAndBind}
65 * method to do resolution with service binding. There are instance and
66 * static variants of both methods. The instance methods create a configuration
67 * with the receiver as the parent configuration. The static methods are for
68 * more advanced cases where there can be more than one parent configuration. </p>
69 *
70 * <p> Each {@link java.lang.ModuleLayer layer} of modules in the Java virtual
503 * @return A possibly-empty unmodifiable list of this parent configurations
504 */
505 public List<Configuration> parents() {
506 return parents;
507 }
508
509
510 /**
511 * Returns an immutable set of the resolved modules in this configuration.
512 *
513 * @return A possibly-empty unmodifiable set of the resolved modules
514 * in this configuration
515 */
516 public Set<ResolvedModule> modules() {
517 return modules;
518 }
519
520
521 /**
522 * Finds a resolved module in this configuration, or if not in this
523 * configuration, the {@linkplain #parents parent} configurations.
524 * Finding a module in parent configurations is equivalent to invoking
525 * {@code findModule} on each parent, in search order, until the module
526 * is found or all parents have been searched. In a <em>tree of
527 * configurations</em> then this is equivalent to a depth-first search.
528 *
529 * @param name
530 * The module name of the resolved module to find
531 *
532 * @return The resolved module with the given name or an empty {@code
533 * Optional} if there isn't a module with this name in this
534 * configuration or any parent configurations
535 */
536 public Optional<ResolvedModule> findModule(String name) {
537 Objects.requireNonNull(name);
538 ResolvedModule m = nameToModule.get(name);
539 if (m != null)
540 return Optional.of(m);
541
542 if (!parents.isEmpty()) {
543 return configurations()
|
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Collections;
33 import java.util.Deque;
34 import java.util.HashMap;
35 import java.util.HashSet;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Map.Entry;
39 import java.util.Objects;
40 import java.util.Optional;
41 import java.util.Set;
42 import java.util.stream.Collectors;
43 import java.util.stream.Stream;
44
45 import jdk.internal.module.ModuleReferenceImpl;
46 import jdk.internal.module.ModuleTarget;
47
48 /**
49 * A configuration that is the result of <a href="package-summary.html#resolution">
50 * resolution</a> or resolution with
51 * <a href="{@docRoot}/java/lang/Configuration#service-binding">service binding</a>.
52 *
53 * <p> A configuration encapsulates the <em>readability graph</em> that is the
54 * output of resolution. A readability graph is a directed graph whose vertices
55 * are of type {@link ResolvedModule} and the edges represent the readability
56 * amongst the modules. {@code Configuration} defines the {@link #modules()
57 * modules()} method to get the set of resolved modules in the graph. {@code
58 * ResolvedModule} defines the {@link ResolvedModule#reads() reads()} method to
59 * get the set of modules that a resolved module reads. The modules that are
60 * read may be in the same configuration or may be in {@link #parents() parent}
61 * configurations. </p>
62 *
63 * <p> Configuration defines the {@link #resolve(ModuleFinder,List,ModuleFinder,Collection)
64 * resolve} method to resolve a collection of root modules, and the {@link
65 * #resolveAndBind(ModuleFinder,List,ModuleFinder,Collection) resolveAndBind}
66 * method to do resolution with service binding. There are instance and
67 * static variants of both methods. The instance methods create a configuration
68 * with the receiver as the parent configuration. The static methods are for
69 * more advanced cases where there can be more than one parent configuration. </p>
70 *
71 * <p> Each {@link java.lang.ModuleLayer layer} of modules in the Java virtual
504 * @return A possibly-empty unmodifiable list of this parent configurations
505 */
506 public List<Configuration> parents() {
507 return parents;
508 }
509
510
511 /**
512 * Returns an immutable set of the resolved modules in this configuration.
513 *
514 * @return A possibly-empty unmodifiable set of the resolved modules
515 * in this configuration
516 */
517 public Set<ResolvedModule> modules() {
518 return modules;
519 }
520
521
522 /**
523 * Finds a resolved module in this configuration, or if not in this
524 * configuration, the {@linkplain #parents() parent} configurations.
525 * Finding a module in parent configurations is equivalent to invoking
526 * {@code findModule} on each parent, in search order, until the module
527 * is found or all parents have been searched. In a <em>tree of
528 * configurations</em> then this is equivalent to a depth-first search.
529 *
530 * @param name
531 * The module name of the resolved module to find
532 *
533 * @return The resolved module with the given name or an empty {@code
534 * Optional} if there isn't a module with this name in this
535 * configuration or any parent configurations
536 */
537 public Optional<ResolvedModule> findModule(String name) {
538 Objects.requireNonNull(name);
539 ResolvedModule m = nameToModule.get(name);
540 if (m != null)
541 return Optional.of(m);
542
543 if (!parents.isEmpty()) {
544 return configurations()
|