Java Code Examples for java.lang.module.ModuleDescriptor.Requires#Modifier

The following examples show how to use java.lang.module.ModuleDescriptor.Requires#Modifier . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Builder.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: Builder.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: SystemModulesPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void newRequires(Set<Requires.Modifier> mods, String name, String compiledVersion) {
    int varIndex = dedupSetBuilder.indexOfRequiresModifiers(mods);
    mv.visitVarInsn(ALOAD, varIndex);
    mv.visitLdcInsn(name);
    if (compiledVersion != null) {
        mv.visitLdcInsn(compiledVersion);
        mv.visitMethodInsn(INVOKESTATIC, MODULE_DESCRIPTOR_BUILDER,
            "newRequires", REQUIRES_SET_STRING_STRING_SIG, false);
    } else {
        mv.visitMethodInsn(INVOKESTATIC, MODULE_DESCRIPTOR_BUILDER,
            "newRequires", REQUIRES_SET_STRING_SIG, false);
    }
}
 
Example 4
Source File: ModuleHelper.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example 5
Source File: ModuleHelper.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
private static Set<Requires.Modifier> mergeRequiresModifiers(Set<Requires.Modifier> s1, Set<Requires.Modifier> s2) {
  var transitive = s1.contains(Requires.Modifier.TRANSITIVE) || s2.contains(Requires.Modifier.TRANSITIVE);
  var 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());
}
 
Example 6
Source File: ModuleHelper.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
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);
  }
}
 
Example 7
Source File: Builder.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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)
{
    return newRequires(mods, mn, null);
}
 
Example 8
Source File: JavaLangModuleAccess.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Adds a dependence on a module with the given (possibly un-parsable)
 * version string.
 */
void requires(ModuleDescriptor.Builder builder,
              Set<Requires.Modifier> ms,
              String mn,
              String rawCompiledVersion);
 
Example 9
Source File: Builder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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)
{
    return newRequires(mods, mn, null);
}
 
Example 10
Source File: JavaLangModuleAccess.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds a dependence on a module with the given (possibly un-parsable)
 * version string.
 */
void requires(ModuleDescriptor.Builder builder,
              Set<Requires.Modifier> ms,
              String mn,
              String rawCompiledVersion);
 
Example 11
Source File: SystemModulesPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void requiresModifiers(Set<Requires.Modifier> mods) {
    requiresModifiersSets.computeIfAbsent(mods, s ->
        new EnumSetBuilder<>(s, REQUIRES_MODIFIER_CLASSNAME,
                             enumSetVar, localVarSupplier)
    ).increment();
}
 
Example 12
Source File: SystemModulesPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
int indexOfRequiresModifiers(Set<Requires.Modifier> mods) {
    return requiresModifiersSets.get(mods).build();
}
 
Example 13
Source File: JavaLangModuleAccess.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a {@code ModuleDescriptor.Requires} of the given modifiers
 * and module name.
 */
Requires newRequires(Set<Requires.Modifier> ms, String mn, Version v);
 
Example 14
Source File: JavaLangModuleAccess.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a {@code ModuleDescriptor.Requires} of the given modifiers
 * and module name.
 */
Requires newRequires(Set<Requires.Modifier> ms, String mn, Version v);