Java 类java.lang.module.ModuleDescriptor.Opens 实例源码

项目:openjdk-jdk10    文件:SecurityManager.java   
/**
 * Returns the non-exported packages of the specified module.
 */
private static Set<String> nonExportedPkgs(ModuleDescriptor md) {
    // start with all packages in the module
    Set<String> pkgs = new HashSet<>(md.packages());

    // remove the non-qualified exported packages
    md.exports().stream()
                .filter(p -> !p.isQualified())
                .map(Exports::source)
                .forEach(pkgs::remove);

    // remove the non-qualified open packages
    md.opens().stream()
              .filter(p -> !p.isQualified())
              .map(Opens::source)
              .forEach(pkgs::remove);

    return pkgs;
}
项目:openjdk-jdk10    文件:SystemModulesPlugin.java   
/**
 * Validates if exported and open packages are present
 */
void validatePackages() {
    Set<String> nonExistPackages = new TreeSet<>();
    descriptor.exports().stream()
        .map(Exports::source)
        .filter(pn -> !packages.contains(pn))
        .forEach(nonExistPackages::add);

    descriptor.opens().stream()
        .map(Opens::source)
        .filter(pn -> !packages.contains(pn))
        .forEach(nonExistPackages::add);

    if (!nonExistPackages.isEmpty()) {
        throw new PluginException("Packages that are exported or open in "
            + descriptor.name() + " are not present: " + nonExistPackages);
    }
}
项目:openjdk-jdk10    文件:SystemModulesPlugin.java   
private void dedups(ModuleDescriptor md) {
    // exports
    for (Exports e : md.exports()) {
        dedupSetBuilder.stringSet(e.targets());
        dedupSetBuilder.exportsModifiers(e.modifiers());
    }

    // opens
    for (Opens opens : md.opens()) {
        dedupSetBuilder.stringSet(opens.targets());
        dedupSetBuilder.opensModifiers(opens.modifiers());
    }

    // requires
    for (Requires r : md.requires()) {
        dedupSetBuilder.requiresModifiers(r.modifiers());
    }

    // uses
    dedupSetBuilder.stringSet(md.uses());
}
项目:openjdk-jdk10    文件:SystemModulesPlugin.java   
void newOpens(Set<Opens.Modifier> ms, String pn, Set<String> targets) {
    int modifiersSetIndex = dedupSetBuilder.indexOfOpensModifiers(ms);
    if (!targets.isEmpty()) {
        int stringSetIndex = dedupSetBuilder.indexOfStringSet(targets);
        mv.visitVarInsn(ALOAD, modifiersSetIndex);
        mv.visitLdcInsn(pn);
        mv.visitVarInsn(ALOAD, stringSetIndex);
        mv.visitMethodInsn(INVOKESTATIC, MODULE_DESCRIPTOR_BUILDER,
            "newOpens", OPENS_MODIFIER_SET_STRING_SET_SIG, false);
    } else {
        mv.visitVarInsn(ALOAD, modifiersSetIndex);
        mv.visitLdcInsn(pn);
        mv.visitMethodInsn(INVOKESTATIC, MODULE_DESCRIPTOR_BUILDER,
            "newOpens", OPENS_MODIFIER_SET_STRING_SIG, false);
    }
}
项目:openjdk-jdk10    文件:JmodTask.java   
private void validatePackages(ModuleDescriptor descriptor, Set<String> packages) {
    Set<String> nonExistPackages = new TreeSet<>();
    descriptor.exports().stream()
        .map(Exports::source)
        .filter(pn -> !packages.contains(pn))
        .forEach(nonExistPackages::add);

    descriptor.opens().stream()
        .map(Opens::source)
        .filter(pn -> !packages.contains(pn))
        .forEach(nonExistPackages::add);

    if (!nonExistPackages.isEmpty()) {
        throw new CommandException("err.missing.export.or.open.packages",
            descriptor.name(), nonExistPackages);
    }
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensToTargets() {
    Set<String> targets = new HashSet<>();
    targets.add("bar");
    targets.add("gus");
    Opens o = ModuleDescriptor.newModule("foo")
            .opens("p", targets)
            .build()
            .opens()
            .iterator()
            .next();
    assertEquals(o, o);
    assertTrue(o.modifiers().isEmpty());
    assertEquals(o.source(), "p");
    assertTrue(o.isQualified());
    assertTrue(o.targets().size() == 2);
    assertTrue(o.targets().contains("bar"));
    assertTrue(o.targets().contains("gus"));
}
项目:moduletools    文件:ModuleHelper.java   
private static int modifierToInt(Opens.Modifier modifier) {
  switch(modifier) {
  case MANDATED:
    return ACC_MANDATED;
  case SYNTHETIC:
    return ACC_SYNTHETIC;
  default:
    throw new IllegalStateException("unknown modifier " + modifier);
  }
}
项目:openjdk-jdk10    文件:JavaLangModuleAccess.java   
/**
 * Returns a new {@code ModuleDescriptor} instance.
 */
ModuleDescriptor newModuleDescriptor(String name,
                                     Version version,
                                     Set<ModuleDescriptor.Modifier> ms,
                                     Set<Requires> requires,
                                     Set<Exports> exports,
                                     Set<Opens> opens,
                                     Set<String> uses,
                                     Set<Provides> provides,
                                     Set<String> packages,
                                     String mainClass,
                                     int hashCode);
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
private Opens opens(Set<Opens.Modifier> mods, String pn) {
    return ModuleDescriptor.newModule("foo")
            .opens(mods, pn)
            .build()
            .opens()
            .iterator()
            .next();
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
private Opens opens(Set<Opens.Modifier> mods, String pn, String target) {
    return ModuleDescriptor.newModule("foo")
            .opens(mods, pn, Set.of(target))
            .build()
            .opens()
            .iterator()
            .next();
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensToAll() {
    Opens o = opens("p");
    assertEquals(o, o);
    assertTrue(o.modifiers().isEmpty());
    assertEquals(o.source(), "p");
    assertFalse(o.isQualified());
    assertTrue(o.targets().isEmpty());
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensToTarget() {
    Opens o = opens("p", "bar");
    assertEquals(o, o);
    assertTrue(o.modifiers().isEmpty());
    assertEquals(o.source(), "p");
    assertTrue(o.isQualified());
    assertTrue(o.targets().size() == 1);
    assertTrue(o.targets().contains("bar"));
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensCompare() {
    Opens o1 = opens("p");
    Opens o2 = opens("p");
    assertEquals(o1, o2);
    assertTrue(o1.hashCode() == o2.hashCode());
    assertTrue(o1.compareTo(o2) == 0);
    assertTrue(o2.compareTo(o1) == 0);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensCompareWithSameModifiers() {
    Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p");
    Opens o2 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p");
    assertEquals(o1, o2);
    assertTrue(o1.hashCode() == o2.hashCode());
    assertTrue(o1.compareTo(o2) == 0);
    assertTrue(o2.compareTo(o1) == 0);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensCompareWithDifferentModifiers() {
    Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p");
    Opens o2 = opens("p");
    assertNotEquals(o1, o2);
    assertTrue(o1.compareTo(o2) == 1);
    assertTrue(o2.compareTo(o1) == -1);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensCompareWithSameTargets() {
    Opens o1 = opens("p", "x");
    Opens o2 = opens("p", "x");
    assertEquals(o1, o2);
    assertTrue(o1.hashCode() == o2.hashCode());
    assertTrue(o1.compareTo(o2) == 0);
    assertTrue(o2.compareTo(o1) == 0);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensCompareWithDifferentTargets() {
    Opens o1 = opens("p", "y");
    Opens o2 = opens("p", "x");
    assertNotEquals(o1, o2);
    assertTrue(o1.compareTo(o2) == 1);
    assertTrue(o2.compareTo(o1) == -1);
}
项目:pro    文件:ModuleHelper.java   
private static int modifierToInt(Opens.Modifier modifier) {
  switch(modifier) {
  case MANDATED:
    return ACC_MANDATED;
  case SYNTHETIC:
    return ACC_SYNTHETIC;
  default:
    throw new IllegalStateException("unknown modifier " + modifier);
  }
}
项目:openjdk-jdk10    文件:Builder.java   
/**
 * Returns an {@link Opens} for a qualified opens, with
 * the given (and possibly empty) set of modifiers,
 * to a set of target modules.
 */
public static Opens newOpens(Set<Opens.Modifier> ms,
                             String pn,
                             Set<String> targets) {
    return JLMA.newOpens(ms, pn, targets);
}
项目:openjdk-jdk10    文件:SystemModulesPlugin.java   
void opensModifiers(Set<Opens.Modifier> mods) {
    opensModifiersSets.computeIfAbsent(mods, s ->
                    new EnumSetBuilder<>(s, OPENS_MODIFIER_CLASSNAME,
                            enumSetVar, localVarSupplier)
    ).increment();
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
private Opens opens(String pn) {
    return opens(Set.of(), pn);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
private Opens opens(String pn, String target) {
    return opens(Set.of(), pn, target);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
public void testOpensOpens() {
    Opens o1 = opens("p");
    ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").opens(o1).build();
    Opens o2 = descriptor.opens().iterator().next();
    assertEquals(o1, o2);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
@Test(expectedExceptions = IllegalStateException.class)
public void testOpensWithDuplicate1() {
    Opens o = opens("p");
    ModuleDescriptor.newModule("foo").opens(o).opens(o);
}
项目:openjdk-jdk10    文件:ModuleDescriptorTest.java   
@Test(expectedExceptions = NullPointerException.class )
public void testOpensWithNullExports() {
    ModuleDescriptor.newModule("foo").opens((Opens) null);
}
项目:pro    文件:ModuleHelper.java   
public static ModuleDescriptor mergeModuleDescriptor(ModuleDescriptor sourceModule, ModuleDescriptor testModule) {
  boolean open = sourceModule.isOpen() || testModule.isOpen();

  Set<Modifier> moduleModifiers = open? Set.of(Modifier.OPEN): Set.of();
  Builder builder = ModuleDescriptor.newModule(testModule.name(), moduleModifiers);

  HashMap<String, Set<Requires.Modifier>> requires = merge(ModuleDescriptor::requires,
      Requires::name, Requires::modifiers, ModuleHelper::mergeRequiresModifiers, sourceModule, testModule);
  HashMap<String, Set<String>> exports = merge(ModuleDescriptor::exports,
      Exports::source, Exports::targets, ModuleHelper::mergeRestrictions, sourceModule, testModule);
  HashMap<String, Boolean> packages = merge(ModuleDescriptor::packages,
      x -> x, x -> true, (_1, _2) -> true, sourceModule, testModule);
  HashMap<String, Set<String>> opens = merge(ModuleDescriptor::opens,
      Opens::source, Opens::targets, ModuleHelper::mergeRestrictions, sourceModule, testModule);
  HashMap<String, Boolean> uses = merge(ModuleDescriptor::uses,
      x -> x, x -> true, (_1, _2) -> true, sourceModule, testModule);
  HashMap<String, Set<String>> provides = merge(ModuleDescriptor::provides,
      Provides::service, p -> new HashSet<>(p.providers()), ModuleHelper::mergeAll, sourceModule, testModule);

  requires.forEach((name, modifiers) -> builder.requires(modifiers, name));
  exports.forEach((source, target) -> {
    if (target.isEmpty()) {
      builder.exports(Set.of(), source);
    } else {
      builder.exports(source, target);
    }
  });
  packages.keySet().removeAll(exports.keySet());
  builder.packages(packages.keySet());
  opens.forEach((source, target) -> {
    if (target.isEmpty()) {
      builder.opens(Set.of(), source);
    } else {
      builder.opens(source, target);
    }
  });
  uses.keySet().forEach(builder::uses);
  provides.forEach((service, providers) -> builder.provides(service, providers.stream().collect(toList())));

  return builder.build();
}
项目:openjdk-jdk10    文件:Builder.java   
/**
 * Returns an {@link Opens} for an unqualified open with a given set of
 * modifiers.
 */
public static Opens newOpens(Set<Opens.Modifier> ms, String pn) {
    return JLMA.newOpens(ms, pn);
}
项目:openjdk-jdk10    文件:JavaLangModuleAccess.java   
/**
 * Returns an unqualified {@code ModuleDescriptor.Opens}
 * of the given modifiers and package name source.
 */
Opens newOpens(Set<Opens.Modifier> ms, String source);
项目:openjdk-jdk10    文件:JavaLangModuleAccess.java   
/**
 * Returns a qualified {@code ModuleDescriptor.Opens}
 * of the given modifiers, package name source and targets.
 */
Opens newOpens(Set<Opens.Modifier> ms, String source, Set<String> targets);
项目:openjdk-jdk10    文件:SystemModulesPlugin.java   
/**
 * Retrieve the index to the given set of Opens.Modifier.
 * Emit code to generate it when EnumSetBuilder::build is called.
 */
int indexOfOpensModifiers(Set<Opens.Modifier> mods) {
    return opensModifiersSets.get(mods).build();
}