java.lang.Class.getModule()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(351)

本文整理了Java中java.lang.Class.getModule()方法的一些代码示例,展示了Class.getModule()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getModule()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getModule

Class.getModule介绍

暂无

代码示例

代码示例来源:origin: scouter-project/scouter

/**
 * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}.
 * It is obtained by using {@code neighbor}.
 *
 * @param neighbor  a class belonging to the same package that the loaded
 *                  class belogns to.
 * @param bcode     the bytecode.
 * @since 3.24
 */
public static Class<?> toClass(Class<?> neighbor, byte[] bcode)
  throws CannotCompileException
{
  try {
    DefineClassHelper.class.getModule().addReads(neighbor.getModule());
    Lookup lookup = MethodHandles.lookup();
    Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup);
    return prvlookup.defineClass(bcode);
  } catch (IllegalAccessException | IllegalArgumentException e) {
    throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName()
                     + " has no permission to define the class");
  }
}

代码示例来源:origin: org.javassist/javassist

/**
 * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}.
 * It is obtained by using {@code neighbor}.
 *
 * @param neighbor  a class belonging to the same package that the loaded
 *                  class belogns to.
 * @param bcode     the bytecode.
 * @since 3.24
 */
public static Class<?> toClass(Class<?> neighbor, byte[] bcode)
  throws CannotCompileException
{
  try {
    DefineClassHelper.class.getModule().addReads(neighbor.getModule());
    Lookup lookup = MethodHandles.lookup();
    Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup);
    return prvlookup.defineClass(bcode);
  } catch (IllegalAccessException | IllegalArgumentException e) {
    throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName()
                     + " has no permission to define the class");
  }
}

代码示例来源:origin: org.eclipse.jetty/jetty-alpn-java-client

@Override
public boolean appliesTo(SSLEngine sslEngine)
{
  Module module = sslEngine.getClass().getModule();
  return module!=null && "java.base".equals(module.getName());
}

代码示例来源:origin: org.eclipse.jetty/jetty-alpn-java-server

@Override
public boolean appliesTo(SSLEngine sslEngine)
{
  Module module = sslEngine.getClass().getModule();
  return module!=null && "java.base".equals(module.getName());
}

代码示例来源:origin: hibernate/hibernate-demos

@Override
  protected Lookup computeValue(Class<?> type) {
    if ( !getClass().getModule().canRead( type.getModule() ) ) {
      getClass().getModule().addReads( type.getModule() );
    }
    packageOpener.openPackageIfNeeded(
        type.getModule(), type.getPackageName(), FieldValueReaderImpl.class.getModule()
    );
    try {
      return MethodHandles.privateLookupIn( type, MethodHandles.lookup() );
    }
    catch (IllegalAccessException e) {
      throw new RuntimeException( e );
    }
  }
};

代码示例来源:origin: io.github.tomdw.java.modules.spring/java-modules-context-boot

private static Module getCallerModule() {
  return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE)
      .walk(stackFrameStream -> stackFrameStream
          .map(StackWalker.StackFrame::getDeclaringClass)
          .map(Class::getModule)
          .filter(module -> module != ModuleContextRegistry.class.getModule())
          .findFirst()
          .orElseThrow(() -> new UnsupportedOperationException("Can only get an application context for a Module annotated with @ModuleContext")));
}

代码示例来源:origin: io.github.tomdw.java.modules.spring/java-modules-context-boot

@Nullable
@Override
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
  Module usingModule = beanClass.getModule();
  for (Field field : beanClass.getDeclaredFields()) {
    if (field.isAnnotationPresent(ModuleServiceReference.class)) {
      Class<?> injectionType = field.getType();
      if(injectionType.isAssignableFrom(List.class)) {
        registerServiceListFactoryBean(usingModule, field);
      } else {
        registerServiceFactoryBean(usingModule, field);
      }
    }
  }
  return null;
}

代码示例来源:origin: io.github.udaychandra/common

private void buildRef(MetadataItem.Reference reference, StringBuilder builder) {
  builder.append(reference.serviceClass().getModule().getName());
  builder.append(COLON);
  builder.append(reference.serviceClass().getName());
  builder.append(SEMI_COLON);
  builder.append(reference.setterMethodName());
  builder.append(SEMI_COLON);
  builder.append(reference.isList());
  builder.append(SEMI_COLON);
  builder.append(reference.isOptional());
}

代码示例来源:origin: com.headius/modulator

public static Module getModule(Class cls) {
  if (JAVA_NINE) {
    return new Module9(cls.getModule());
  }
  return new ModuleDummy();
}

代码示例来源:origin: net.colesico.framework/colesico-webstatic

public StaticContentBuilderImpl(
    @Message InjectionPoint injectionPoint,
    Provider<HttpContext> httpContextProv,
    ResourceKit resourceKit) {
  this.httpContextProv = httpContextProv;
  this.resourceKit = resourceKit;
  if (injectionPoint != null) {
    String moduleName = injectionPoint.getTargetClass().getModule().getName();
    if (moduleName!=null) {
      String contentRootPkg = moduleName.replace('.', '/') + "/" + DEFAULT_RESOURCES_DIR;
      this.resourcesRoot = contentRootPkg;
    } else {
      throw new RuntimeException("Unnamed module for injection point: "+injectionPoint);
    }
  }
  log.debug("Initial content root: " + resourcesRoot);
}

代码示例来源:origin: org.tentackle/tentackle-common

/**
 * Creates a module info.
 *
 * @param hook the module hook
 */
public ModuleInfo(ModuleHook hook) {
 this.hook = hook;
 this.urlPath = hook.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
 this.module = hook.getClass().getModule();
 if (module == null || !module.isNamed()) {
  throw new TentackleRuntimeException(hook.getClass() + " does not belong to a named module");
 }
 requiredModuleNames = new HashSet<>();
 for (ModuleDescriptor.Requires req : module.getDescriptor().requires()) {
  requiredModuleNames.add(req.name());
 }
}

代码示例来源:origin: io.github.udaychandra.susel/susel

throws IOException, SuselMetadataNullException {
var module = serviceProvider.getModule();
var metadata = perModuleMetadataCache.get(module);
    var properties = new Properties();
    try (InputStream inStream = serviceProvider.getModule().getResourceAsStream(SUSEL_METADATA_RESOURCE_PATH)) {
      properties.load(inStream);
    } catch (NullPointerException ex) {

代码示例来源:origin: io.github.scouter-project/scouter-agent-java

/**
 * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}.
 * It is obtained by using {@code neighbor}.
 *
 * @param neighbor  a class belonging to the same package that the loaded
 *                  class belogns to.
 * @param bcode     the bytecode.
 * @since 3.24
 */
public static Class<?> toClass(Class<?> neighbor, byte[] bcode)
  throws CannotCompileException
{
  try {
    DefineClassHelper.class.getModule().addReads(neighbor.getModule());
    Lookup lookup = MethodHandles.lookup();
    Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup);
    return prvlookup.defineClass(bcode);
  } catch (IllegalAccessException | IllegalArgumentException e) {
    throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName()
                     + " has no permission to define the class");
  }
}

代码示例来源:origin: io.github.udaychandra/susel

throws IOException, SuselMetadataNullException {
var module = serviceProvider.getModule();
var metadata = perModuleMetadataCache.get(module);
    var properties = new Properties();
    try (InputStream inStream = serviceProvider.getModule().getResourceAsStream(SUSEL_METADATA_RESOURCE_PATH)) {
      properties.load(inStream);
    } catch (NullPointerException ex) {

代码示例来源:origin: net.colesico.framework/colesico-ioc

protected ServiceLocator(Class<?> caller, Class<S> service, ClassLoader classLoader, Predicate<Class<? extends S>> classFilter) {
  if (caller == null) {
    throw new ServiceConfigurationError("Caller class is null");
  }
  this.caller = caller;
  if (service == null) {
    throw new ServiceConfigurationError("Service class is null");
  }
  this.service = service;
  Module callerModule = caller.getModule();
  if (!callerModule.canUse(service)) {
    throw new ServiceConfigurationError("Module '" + callerModule + "' does not declare 'uses' for class " + service.getName());
  }
  if (classLoader != null) {
    this.classLoader = classLoader;
  } else {
    this.classLoader = ClassLoader.getSystemClassLoader();
  }
  this.classFilter = classFilter;
  this.acc = (System.getSecurityManager() != null)
      ? AccessController.getContext()
      : null;
}

代码示例来源:origin: io.github.tomdw.java.modules.spring/java-modules-context-boot

public static <SERVICETYPE> SERVICETYPE retrieveInstanceFromContext(Class<SERVICETYPE> serviceClass) {
  LOGGER.log(INFO, "Providing instance of " + serviceClass.getSimpleName() + " from module " + serviceClass.getModule().getName());
  GenericApplicationContext context = get();
  if (!context.isActive()) {
    LOGGER.log(INFO, "Lazy starting ApplicationContext for module " + serviceClass.getModule().getName());
    context.refresh();
  }
  return context.getBean(serviceClass);
}

代码示例来源:origin: bytemanproject/byteman

extraReads.add(AccessEnabler.class.getModule());

代码示例来源:origin: bytemanproject/byteman

extraReads.add(AccessEnabler.class.getModule());

相关文章

Class类方法