当前位置: 首页>>代码示例>>Java>>正文


Java Requires类代码示例

本文整理汇总了Java中java.lang.module.ModuleDescriptor.Requires的典型用法代码示例。如果您正苦于以下问题:Java Requires类的具体用法?Java Requires怎么用?Java Requires使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Requires类属于java.lang.module.ModuleDescriptor包,在下文中一共展示了Requires类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newRequires

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Returns a {@link Requires} for a dependence on a module with the given
 * (and possibly empty) set of modifiers, and optionally the version
 * recorded at compile time.
 */
public static Requires newRequires(Set<Requires.Modifier> mods,
                                   String mn,
                                   String compiledVersion)
{
    Version version = null;
    if (compiledVersion != null) {
        // use the cached version if the same version string
        Version ver = cachedVersion;
        if (ver != null && compiledVersion.equals(ver.toString())) {
            version = ver;
        } else {
            version = Version.parse(compiledVersion);
        }
    }
    return JLMA.newRequires(mods, mn, version);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Builder.java

示例2: dedups

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:SystemModulesPlugin.java

示例3: testRequiresStatic2

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Basic test of "requires static":
 *     m1 requires static m2
 *     m2
 *     resolve m1
 */
public void testRequiresStatic2() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires(Set.of(Requires.Modifier.STATIC), "m2")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf = resolve(finder, "m1");

    assertTrue(cf.modules().size() == 1);

    ResolvedModule m1 = cf.findModule("m1").get();
    assertTrue(m1.reads().size() == 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ConfigurationTest.java

示例4: testRequiresStatic3

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Basic test of "requires static":
 *     m1 requires static m2
 *     m2
 *     resolve m1, m2
 */
public void testRequiresStatic3() {
    ModuleDescriptor descriptor1 = newBuilder("m1")
            .requires(Set.of(Requires.Modifier.STATIC), "m2")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .build();

    ModuleFinder finder = ModuleUtils.finderOf(descriptor1, descriptor2);

    Configuration cf = resolve(finder, "m1", "m2");

    assertTrue(cf.modules().size() == 2);

    ResolvedModule m1 = cf.findModule("m1").get();
    ResolvedModule m2 = cf.findModule("m2").get();

    assertTrue(m1.reads().size() == 1);
    assertTrue(m1.reads().contains(m2));

    assertTrue(m2.reads().size() == 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ConfigurationTest.java

示例5: testReadModuleWithSameNameAsSelf

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Basic test to detect reading a module with the same name as itself
 *
 * The test consists of three configurations:
 * - Configuration cf1: m1, m2 requires transitive m1
 * - Configuration cf2: m1 requires m2
 */
@Test(expectedExceptions = { ResolutionException.class })
public void testReadModuleWithSameNameAsSelf() {
    ModuleDescriptor descriptor1_v1 = newBuilder("m1")
            .build();

    ModuleDescriptor descriptor2 = newBuilder("m2")
            .requires(Set.of(Requires.Modifier.TRANSITIVE), "m1")
            .build();

    ModuleDescriptor descriptor1_v2 = newBuilder("m1")
            .requires("m2")
            .build();

    ModuleFinder finder1 = ModuleUtils.finderOf(descriptor1_v1, descriptor2);
    Configuration cf1 = resolve(finder1, "m2");
    assertTrue(cf1.modules().size() == 2);

    // resolve should throw ResolutionException
    ModuleFinder finder2 = ModuleUtils.finderOf(descriptor1_v2);
    resolve(cf1, finder2, "m1");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ConfigurationTest.java

示例6: testUnparseableCompiledVersion

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Basic test for requiring a module with an unparseable version recorded
 * at compile version.
 */
@Test(dataProvider = "unparseableVersions")
public void testUnparseableCompiledVersion(String vs1, String vs2) {
    Requires r1 = newRequires("m", vs1);
    Requires r2 = newRequires("m", vs2);

    if (vs1 != null && !isParsableVersion(vs1)) {
        assertFalse(r1.compiledVersion().isPresent());
        assertTrue(r1.rawCompiledVersion().isPresent());
        assertEquals(r1.rawCompiledVersion().get(), vs1);
    }

    if (vs2 != null && !isParsableVersion(vs2)) {
        assertFalse(r2.compiledVersion().isPresent());
        assertTrue(r2.rawCompiledVersion().isPresent());
        assertEquals(r2.rawCompiledVersion().get(), vs2);
    }

    assertFalse(r1.equals(r2));
    assertFalse(r2.equals(r1));
    assertTrue(r1.compareTo(r2) == -1);
    assertTrue(r2.compareTo(r1) == 1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ModuleDescriptorTest.java

示例7: testAutomaticModule

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
public void testAutomaticModule() {
    ModuleDescriptor descriptor = ModuleDescriptor.newAutomaticModule("foo")
            .packages(Set.of("p"))
            .provides("p.Service", List.of("q.ServiceImpl"))
            .build();

    // modifiers
    assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC));
    assertTrue(descriptor.isAutomatic());

    // requires
    assertTrue(descriptor.requires().size() == 1);
    Set<String> names = descriptor.requires()
            .stream()
            .map(Requires::name)
            .collect(Collectors.toSet());
    assertEquals(names, Set.of("java.base"));

    // packages
    assertEquals(descriptor.packages(), Set.of("p", "q"));
    assertTrue(descriptor.exports().isEmpty());
    assertTrue(descriptor.opens().isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ModuleDescriptorTest.java

示例8: printModuleInfo

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
private void printModuleInfo(PrintWriter writer, ModuleDescriptor descriptor) {
    writer.format("module %s {%n", descriptor.name());

    Map<String, Module> modules = configuration.getModules();
    // first print the JDK modules
    descriptor.requires().stream()
              .filter(req -> !req.name().equals("java.base"))   // implicit requires
              .sorted(Comparator.comparing(Requires::name))
              .forEach(req -> writer.format("    requires %s;%n", req));

    descriptor.exports().stream()
              .peek(exp -> {
                  if (exp.targets().size() > 0)
                      throw new InternalError(descriptor.name() + " qualified exports: " + exp);
              })
              .sorted(Comparator.comparing(Exports::source))
              .forEach(exp -> writer.format("    exports %s;%n", exp.source()));

    descriptor.provides().values().stream()
                .sorted(Comparator.comparing(Provides::service))
                .forEach(p -> p.providers().stream()
                    .sorted()
                    .forEach(impl -> writer.format("    provides %s with %s;%n", p.service(), impl)));

    writer.println("}");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:27,代码来源:ModuleInfoBuilder.java

示例9: newModuleDescriptor

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Returns a new {@code ModuleDescriptor} instance.
 */
ModuleDescriptor newModuleDescriptor(String name,
                                     boolean automatic,
                                     boolean synthetic,
                                     Set<Requires> requires,
                                     Set<String> uses,
                                     Set<Exports> exports,
                                     Map<String, Provides> provides,
                                     Version version,
                                     String mainClass,
                                     String osName,
                                     String osArch,
                                     String osVersion,
                                     Set<String> conceals,
                                     Set<String> packages,
                                     ModuleHashes hashes);
 
开发者ID:campolake,项目名称:openjdk9,代码行数:19,代码来源:JavaLangModuleAccess.java

示例10: getClassReaderInDependencies

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * Lookup the class in this pool and the required pools. NB: static module
 * readability can be different at execution time.
 *
 * @param binaryName The class to lookup.
 * @return The reader or null if not found
 */
@Override
public ClassReader getClassReaderInDependencies(String binaryName) {
    Objects.requireNonNull(binaryName);
    ClassReader reader = getClassReader(binaryName);
    if (reader == null) {
        for (Requires requires : descriptor.requires()) {
            AsmModulePool pool = pools.getModulePool(requires.name());
            reader = pool.getExportedClassReader(moduleName, binaryName);
            if (reader != null) {
                break;
            }
        }
    }
    return reader;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:23,代码来源:AsmPoolImpl.java

示例11: requireModifiers

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
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());
}
 
开发者ID:forax,项目名称:moduletools,代码行数:13,代码来源:ModuleHelper.java

示例12: modifierToInt

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
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);
  }
}
 
开发者ID:forax,项目名称:moduletools,代码行数:15,代码来源:ModuleHelper.java

示例13: printModuleDescriptor

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
public void printModuleDescriptor(Module module) {
    if (!module.isNamed())
        return;

    writer.format("%s%s%n", module.name(), module.isAutomatic() ? " automatic" : "");
    writer.format(" [%s]%n", module.location());
    module.descriptor().requires()
            .stream()
            .sorted(Comparator.comparing(Requires::name))
            .forEach(req -> writer.format("   requires %s%n", req));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JdepsWriter.java

示例14: printModuleInfo

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
private void printModuleInfo(PrintWriter writer, ModuleDescriptor md) {
    writer.format("%smodule %s {%n", open ? "open " : "", md.name());

    Map<String, Module> modules = configuration.getModules();

    // first print requires
    Set<Requires> reqs = md.requires().stream()
        .filter(req -> !req.name().equals("java.base") && req.modifiers().isEmpty())
        .collect(Collectors.toSet());
    reqs.stream()
        .sorted(Comparator.comparing(Requires::name))
        .forEach(req -> writer.format("    requires %s;%n",
                                      toString(req.modifiers(), req.name())));
    if (!reqs.isEmpty()) {
        writer.println();
    }

    // requires transitive
    reqs = md.requires().stream()
             .filter(req -> !req.name().equals("java.base") && !req.modifiers().isEmpty())
             .collect(Collectors.toSet());
    reqs.stream()
        .sorted(Comparator.comparing(Requires::name))
        .forEach(req -> writer.format("    requires %s;%n",
                                      toString(req.modifiers(), req.name())));
    if (!reqs.isEmpty()) {
        writer.println();
    }

    if (!open) {
        md.exports().stream()
          .peek(exp -> {
              if (exp.isQualified())
                  throw new InternalError(md.name() + " qualified exports: " + exp);
              })
          .sorted(Comparator.comparing(Exports::source))
          .forEach(exp -> writer.format("    exports %s;%n", exp.source()));

        if (!md.exports().isEmpty()) {
            writer.println();
        }
    }

    md.provides().stream()
      .sorted(Comparator.comparing(Provides::service))
      .map(p -> p.providers().stream()
                 .map(impl -> "        " + impl.replace('$', '.'))
                 .collect(joining(",\n",
                                  String.format("    provides %s with%n",
                                                p.service().replace('$', '.')),
                                  ";")))
                 .forEach(writer::println);

    if (!md.provides().isEmpty()) {
        writer.println();
    }
    writer.println("}");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:ModuleInfoBuilder.java

示例15: newModuleDescriptor

import java.lang.module.ModuleDescriptor.Requires; //导入依赖的package包/类
/**
 * 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);
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:JavaLangModuleAccess.java


注:本文中的java.lang.module.ModuleDescriptor.Requires类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。