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

项目:moduletools    文件:Main.java   
private static Builder toBuilder(ModuleDescriptor descriptor) {
  String name = descriptor.name();
  Set<Modifier> modifiers = descriptor.isAutomatic()? Set.of(Modifier.AUTOMATIC):
    descriptor.isOpen()? Set.of(Modifier.OPEN): Set.of();
  Builder builder = ModuleDescriptor.newModule(name, modifiers);

  descriptor.requires().forEach(builder::requires);
  descriptor.exports().forEach(builder::exports);
  descriptor.opens().forEach(builder::opens);

  HashSet<String> packages = new HashSet<>(descriptor.packages());
  descriptor.exports().forEach(export -> packages.remove(export.source()));
  descriptor.opens().forEach(open -> packages.remove(open.source()));
  builder.packages(packages);

  descriptor.uses().forEach(builder::uses);
  descriptor.provides().forEach(builder::provides);

  return builder;
}
项目:openjdk-jdk10    文件:ScriptLoader.java   
private Module createModule(final String moduleName) {
    final Module structMod = context.getStructLoader().getModule();
    final ModuleDescriptor.Builder builder =
        ModuleDescriptor.newModule(moduleName, Set.of(Modifier.SYNTHETIC))
                .requires("java.logging")
                .requires(NASHORN_MODULE.getName())
                .requires(structMod.getName())
                .packages(Set.of(SCRIPTS_PKG));

    if (Context.javaSqlFound) {
        builder.requires("java.sql");
    }

    if (Context.javaSqlRowsetFound) {
        builder.requires("java.sql.rowset");
    }

    final ModuleDescriptor descriptor = builder.build();

    final Module mod = Context.createModuleTrusted(structMod.getLayer(), descriptor, this);
    loadModuleManipulator();
    return mod;
}
项目:pro    文件:ModuleFixerPlugin.java   
private static Path generateModuleInfo(ModuleReference ref,
                                       Set<String> requires, Set<String> exports, Set<String> uses, Map<String, Set<String>> provides,
                                       Path moduleDependencyFixerPath) throws IOException {
  String moduleName = ref.descriptor().name();

  //System.out.println(moduleName);
  //System.out.println("requires: " + requires);
  //System.out.println("exports: " + exports);
  //System.out.println("uses: " + uses);
  //System.out.println("provides: " + provides);

  Path modulePatchPath = moduleDependencyFixerPath.resolve(moduleName);
  Files.createDirectories(modulePatchPath);

  ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(moduleName, Set.of(Modifier.OPEN));
  ref.descriptor().version().ifPresent(version -> builder.version(version.toString()));
  requires.forEach(builder::requires);
  exports.forEach(export -> builder.exports(export.replace('/', '.')));
  uses.forEach(use -> builder.uses(use.replace('/', '.')));
  provides.forEach((service, providers) -> builder.provides(service, new ArrayList<>(providers)));

  Path generatedModuleInfoPath = modulePatchPath.resolve("module-info.class");
  Files.write(generatedModuleInfoPath, ModuleHelper.moduleDescriptorToBinary(builder.build()));
  return generatedModuleInfoPath;
}
项目:openjdk-jdk10    文件:StructureLoader.java   
private Module createModule(final String moduleName) {
    final ModuleDescriptor descriptor =
        ModuleDescriptor.newModule(moduleName, Set.of(Modifier.SYNTHETIC))
                        .requires(NASHORN_MODULE.getName())
                        .packages(Set.of(SCRIPTS_PKG))
                        .build();

    final Module mod = Context.createModuleTrusted(descriptor, this);
    loadModuleManipulator();
    return mod;
}
项目:pro    文件:ModuleHelper.java   
private static Set<Requires.Modifier> requireModifiers(int modifiers) {
  return Map.of(
      ACC_MANDATED, Requires.Modifier.MANDATED,
      ACC_SYNTHETIC, Requires.Modifier.SYNTHETIC,
      ACC_TRANSITIVE, Requires.Modifier.TRANSITIVE,
      ACC_STATIC_PHASE, Requires.Modifier.STATIC)
    .entrySet()
    .stream()
    .map(entry -> (modifiers & entry.getKey()) != 0? entry.getValue(): null)
    .filter(Objects::nonNull)
    .collect(Collectors.toSet());
}
项目:pro    文件:ModuleHelper.java   
private static ModuleDescriptor createModuleDescriptor(ModuleNode moduleNode, Path moduleInfoPath) {
  Set<Modifier> modifiers = (moduleNode.access & ACC_OPEN) != 0? Set.of(Modifier.OPEN): Set.of();
  ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(moduleNode.name, modifiers);

  moduleNode.requires.forEach(require -> builder.requires(requireModifiers(require.access), require.module));
  moduleNode.exports.forEach(export -> {
    if (export.modules.isEmpty()) {
      builder.exports(export.packaze);
    } else {
      builder.exports(export.packaze, export.modules.stream().collect(toSet()));
    }
  });
  moduleNode.opens.forEach(open -> {
    if (open.modules.isEmpty()) {
      builder.opens(open.packaze);
    } else {
      builder.opens(open.packaze, open.modules.stream().collect(toSet()));
    }
  });
  moduleNode.uses.forEach(builder::uses);
  moduleNode.provides.forEach(provide -> builder.provides(provide.service, provide.providers));

  Path moduleDirectory = moduleInfoPath.getParent();
  Set<String> javaPackages = findJavaPackages(moduleDirectory);
  javaPackages.removeAll(moduleNode.exports.stream().map(export -> export.packaze).collect(Collectors.toList()));
  javaPackages.removeAll(moduleNode.opens.stream().map(export -> export.packaze).collect(Collectors.toList()));
  builder.packages(javaPackages);

  ModuleDescriptor descriptor = builder.build();
  //System.out.println(descriptor.name() + " " + descriptor.packages());

  return descriptor;
}
项目:pro    文件:ModuleHelper.java   
private static Set<Requires.Modifier> mergeRequiresModifiers(Set<Requires.Modifier> s1, Set<Requires.Modifier> s2) {
  boolean transitive = s1.contains(Requires.Modifier.TRANSITIVE) || s2.contains(Requires.Modifier.TRANSITIVE);
  boolean staticz = s1.contains(Requires.Modifier.STATIC) && s2.contains(Requires.Modifier.STATIC);
  return Stream.of(
        Optional.of(Requires.Modifier.TRANSITIVE).filter(__ -> transitive),
        Optional.of(Requires.Modifier.STATIC).filter(__ -> staticz)
      ).flatMap(Optional::stream).collect(Collectors.toSet());
}
项目:pro    文件:ModuleHelper.java   
private static int modifierToInt(Requires.Modifier modifier) {
  switch(modifier) {
  case MANDATED:
    return ACC_MANDATED;
  case SYNTHETIC:
    return ACC_SYNTHETIC;
  case STATIC:
    return ACC_STATIC_PHASE;
  case TRANSITIVE:
    return ACC_TRANSITIVE;
  default:
    throw new IllegalStateException("unknown modifier " + modifier);
  }
}
项目:pro    文件:ModuleHelper.java   
private static int modifierToInt(Exports.Modifier modifier) {
  switch(modifier) {
  case MANDATED:
    return ACC_MANDATED;
  case SYNTHETIC:
    return ACC_SYNTHETIC;
  default:
    throw new IllegalStateException("unknown modifier " + modifier);
  }
}
项目: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);
  }
}
项目: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();
}