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

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

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

Class.getModule介绍

暂无

代码示例

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

  1. /**
  2. * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}.
  3. * It is obtained by using {@code neighbor}.
  4. *
  5. * @param neighbor a class belonging to the same package that the loaded
  6. * class belogns to.
  7. * @param bcode the bytecode.
  8. * @since 3.24
  9. */
  10. public static Class<?> toClass(Class<?> neighbor, byte[] bcode)
  11. throws CannotCompileException
  12. {
  13. try {
  14. DefineClassHelper.class.getModule().addReads(neighbor.getModule());
  15. Lookup lookup = MethodHandles.lookup();
  16. Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup);
  17. return prvlookup.defineClass(bcode);
  18. } catch (IllegalAccessException | IllegalArgumentException e) {
  19. throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName()
  20. + " has no permission to define the class");
  21. }
  22. }

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

  1. /**
  2. * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}.
  3. * It is obtained by using {@code neighbor}.
  4. *
  5. * @param neighbor a class belonging to the same package that the loaded
  6. * class belogns to.
  7. * @param bcode the bytecode.
  8. * @since 3.24
  9. */
  10. public static Class<?> toClass(Class<?> neighbor, byte[] bcode)
  11. throws CannotCompileException
  12. {
  13. try {
  14. DefineClassHelper.class.getModule().addReads(neighbor.getModule());
  15. Lookup lookup = MethodHandles.lookup();
  16. Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup);
  17. return prvlookup.defineClass(bcode);
  18. } catch (IllegalAccessException | IllegalArgumentException e) {
  19. throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName()
  20. + " has no permission to define the class");
  21. }
  22. }

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

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

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

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

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

  1. @Override
  2. protected Lookup computeValue(Class<?> type) {
  3. if ( !getClass().getModule().canRead( type.getModule() ) ) {
  4. getClass().getModule().addReads( type.getModule() );
  5. }
  6. packageOpener.openPackageIfNeeded(
  7. type.getModule(), type.getPackageName(), FieldValueReaderImpl.class.getModule()
  8. );
  9. try {
  10. return MethodHandles.privateLookupIn( type, MethodHandles.lookup() );
  11. }
  12. catch (IllegalAccessException e) {
  13. throw new RuntimeException( e );
  14. }
  15. }
  16. };

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

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

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

  1. @Nullable
  2. @Override
  3. public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
  4. Module usingModule = beanClass.getModule();
  5. for (Field field : beanClass.getDeclaredFields()) {
  6. if (field.isAnnotationPresent(ModuleServiceReference.class)) {
  7. Class<?> injectionType = field.getType();
  8. if(injectionType.isAssignableFrom(List.class)) {
  9. registerServiceListFactoryBean(usingModule, field);
  10. } else {
  11. registerServiceFactoryBean(usingModule, field);
  12. }
  13. }
  14. }
  15. return null;
  16. }

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

  1. private void buildRef(MetadataItem.Reference reference, StringBuilder builder) {
  2. builder.append(reference.serviceClass().getModule().getName());
  3. builder.append(COLON);
  4. builder.append(reference.serviceClass().getName());
  5. builder.append(SEMI_COLON);
  6. builder.append(reference.setterMethodName());
  7. builder.append(SEMI_COLON);
  8. builder.append(reference.isList());
  9. builder.append(SEMI_COLON);
  10. builder.append(reference.isOptional());
  11. }

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

  1. public static Module getModule(Class cls) {
  2. if (JAVA_NINE) {
  3. return new Module9(cls.getModule());
  4. }
  5. return new ModuleDummy();
  6. }

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

  1. public StaticContentBuilderImpl(
  2. @Message InjectionPoint injectionPoint,
  3. Provider<HttpContext> httpContextProv,
  4. ResourceKit resourceKit) {
  5. this.httpContextProv = httpContextProv;
  6. this.resourceKit = resourceKit;
  7. if (injectionPoint != null) {
  8. String moduleName = injectionPoint.getTargetClass().getModule().getName();
  9. if (moduleName!=null) {
  10. String contentRootPkg = moduleName.replace('.', '/') + "/" + DEFAULT_RESOURCES_DIR;
  11. this.resourcesRoot = contentRootPkg;
  12. } else {
  13. throw new RuntimeException("Unnamed module for injection point: "+injectionPoint);
  14. }
  15. }
  16. log.debug("Initial content root: " + resourcesRoot);
  17. }

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

  1. /**
  2. * Creates a module info.
  3. *
  4. * @param hook the module hook
  5. */
  6. public ModuleInfo(ModuleHook hook) {
  7. this.hook = hook;
  8. this.urlPath = hook.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
  9. this.module = hook.getClass().getModule();
  10. if (module == null || !module.isNamed()) {
  11. throw new TentackleRuntimeException(hook.getClass() + " does not belong to a named module");
  12. }
  13. requiredModuleNames = new HashSet<>();
  14. for (ModuleDescriptor.Requires req : module.getDescriptor().requires()) {
  15. requiredModuleNames.add(req.name());
  16. }
  17. }

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

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

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

  1. /**
  2. * Loads a class file by {@code java.lang.invoke.MethodHandles.Lookup}.
  3. * It is obtained by using {@code neighbor}.
  4. *
  5. * @param neighbor a class belonging to the same package that the loaded
  6. * class belogns to.
  7. * @param bcode the bytecode.
  8. * @since 3.24
  9. */
  10. public static Class<?> toClass(Class<?> neighbor, byte[] bcode)
  11. throws CannotCompileException
  12. {
  13. try {
  14. DefineClassHelper.class.getModule().addReads(neighbor.getModule());
  15. Lookup lookup = MethodHandles.lookup();
  16. Lookup prvlookup = MethodHandles.privateLookupIn(neighbor, lookup);
  17. return prvlookup.defineClass(bcode);
  18. } catch (IllegalAccessException | IllegalArgumentException e) {
  19. throw new CannotCompileException(e.getMessage() + ": " + neighbor.getName()
  20. + " has no permission to define the class");
  21. }
  22. }

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

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

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

  1. protected ServiceLocator(Class<?> caller, Class<S> service, ClassLoader classLoader, Predicate<Class<? extends S>> classFilter) {
  2. if (caller == null) {
  3. throw new ServiceConfigurationError("Caller class is null");
  4. }
  5. this.caller = caller;
  6. if (service == null) {
  7. throw new ServiceConfigurationError("Service class is null");
  8. }
  9. this.service = service;
  10. Module callerModule = caller.getModule();
  11. if (!callerModule.canUse(service)) {
  12. throw new ServiceConfigurationError("Module '" + callerModule + "' does not declare 'uses' for class " + service.getName());
  13. }
  14. if (classLoader != null) {
  15. this.classLoader = classLoader;
  16. } else {
  17. this.classLoader = ClassLoader.getSystemClassLoader();
  18. }
  19. this.classFilter = classFilter;
  20. this.acc = (System.getSecurityManager() != null)
  21. ? AccessController.getContext()
  22. : null;
  23. }

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

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

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

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

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

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

相关文章

Class类方法