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

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

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

Class.getAnnotatedInterfaces介绍

暂无

代码示例

代码示例来源:origin: spring-cloud/spring-cloud-config

  1. /**
  2. * Given a Factory Name return the generic type parameters of the factory (The actual repository class, and its properties class)o
  3. */
  4. public static Type[] getEnvironmentRepositoryFactoryTypeParams(ConfigurableListableBeanFactory beanFactory, String factoryName) {
  5. MethodMetadata methodMetadata = (MethodMetadata) beanFactory.getBeanDefinition(factoryName).getSource();
  6. Class<?> factoryClass = null;
  7. try {
  8. factoryClass = Class.forName(methodMetadata.getReturnTypeName());
  9. } catch (ClassNotFoundException e) {
  10. throw new IllegalStateException(e);
  11. }
  12. Optional<AnnotatedType> annotatedFactoryType = Arrays.stream(factoryClass.getAnnotatedInterfaces())
  13. .filter(i -> {
  14. ParameterizedType parameterizedType = (ParameterizedType) i.getType();
  15. return parameterizedType.getRawType().equals(EnvironmentRepositoryFactory.class);
  16. }).findFirst();
  17. ParameterizedType factoryParameterizedType = (ParameterizedType) annotatedFactoryType
  18. .orElse(factoryClass.getAnnotatedSuperclass()).getType();
  19. return factoryParameterizedType.getActualTypeArguments();
  20. }

代码示例来源:origin: stackoverflow.com

  1. for (AnnotatedType t : consumer.getClass().getAnnotatedInterfaces()) {
  2. annotation = t.getAnnotation(MyTypeAnnotation.class);
  3. if (annotation != null) {

代码示例来源:origin: stackoverflow.com

  1. @Retention(RetentionPolicy.RUNTIME)
  2. public @interface X {
  3. String[] value();
  4. }
  5. @X({"a", "b", "c"})
  6. interface AnInterface {}
  7. public static class TestClass implements AnInterface {}
  8. public static void main(String[] args) {
  9. // annotations are not inherited, empty array
  10. System.out.println(Arrays.toString(TestClass.class.getAnnotations()));
  11. // check if TestClass is annotated with X and get X.value()
  12. Arrays.stream(TestClass.class.getAnnotatedInterfaces())
  13. .filter(type -> type.getType().equals(AnInterface.class))
  14. .map(type -> (Class<AnInterface>) type.getType())
  15. .findFirst()
  16. .ifPresent(anInterface -> {
  17. String[] value = anInterface.getAnnotation(X.class).value();
  18. System.out.println(Arrays.toString(value));
  19. });
  20. }

代码示例来源:origin: org.hibernate.validator/hibernate-validator

  1. private static void determineValueExtractorDefinitions(List<AnnotatedType> valueExtractorDefinitions, Class<?> extractorImplementationType) {
  2. if ( !ValueExtractor.class.isAssignableFrom( extractorImplementationType ) ) {
  3. return;
  4. }
  5. Class<?> superClass = extractorImplementationType.getSuperclass();
  6. if ( superClass != null && !Object.class.equals( superClass ) ) {
  7. determineValueExtractorDefinitions( valueExtractorDefinitions, superClass );
  8. }
  9. for ( Class<?> implementedInterface : extractorImplementationType.getInterfaces() ) {
  10. if ( !ValueExtractor.class.equals( implementedInterface ) ) {
  11. determineValueExtractorDefinitions( valueExtractorDefinitions, implementedInterface );
  12. }
  13. }
  14. for ( AnnotatedType annotatedInterface : extractorImplementationType.getAnnotatedInterfaces() ) {
  15. if ( ValueExtractor.class.equals( ReflectionHelper.getClassFromType( annotatedInterface.getType() ) ) ) {
  16. valueExtractorDefinitions.add( annotatedInterface );
  17. }
  18. }
  19. }

代码示例来源:origin: funcatron/funcatron

  1. Arrays.stream(c.getAnnotatedInterfaces()).
  2. map(a -> a.getType()).
  3. filter(a -> a instanceof ParameterizedType).

代码示例来源:origin: org.apache.tomee.patch/bval-jsr

  1. private void hierarchy(Consumer<ContainerElementKey> sink) {
  2. final TypeVariable<?> var;
  3. if (typeArgumentIndex == null) {
  4. var = null;
  5. } else {
  6. var = containerClass.getTypeParameters()[typeArgumentIndex.intValue()];
  7. }
  8. final Lazy<Set<ContainerElementKey>> round = new Lazy<>(LinkedHashSet::new);
  9. Stream
  10. .concat(Stream.of(containerClass.getAnnotatedSuperclass()),
  11. Stream.of(containerClass.getAnnotatedInterfaces()))
  12. .filter(AnnotatedParameterizedType.class::isInstance).map(AnnotatedParameterizedType.class::cast)
  13. .forEach(t -> {
  14. final AnnotatedType[] args = ((AnnotatedParameterizedType) t).getAnnotatedActualTypeArguments();
  15. for (int i = 0; i < args.length; i++) {
  16. final Type boundArgumentType = args[i].getType();
  17. if (boundArgumentType instanceof Class<?> || boundArgumentType.equals(var)) {
  18. round.get().add(new ContainerElementKey(t, Integer.valueOf(i)));
  19. }
  20. }
  21. });
  22. round.optional().ifPresent(s -> {
  23. s.forEach(sink);
  24. // recurse:
  25. s.forEach(k -> k.hierarchy(sink));
  26. });
  27. }

代码示例来源:origin: org.apache.bval/bval-jsr

  1. private void hierarchy(Consumer<ContainerElementKey> sink) {
  2. final TypeVariable<?> var;
  3. if (typeArgumentIndex == null) {
  4. var = null;
  5. } else {
  6. var = containerClass.getTypeParameters()[typeArgumentIndex.intValue()];
  7. }
  8. final Lazy<Set<ContainerElementKey>> round = new Lazy<>(LinkedHashSet::new);
  9. Stream
  10. .concat(Stream.of(containerClass.getAnnotatedSuperclass()),
  11. Stream.of(containerClass.getAnnotatedInterfaces()))
  12. .filter(AnnotatedParameterizedType.class::isInstance).map(AnnotatedParameterizedType.class::cast)
  13. .forEach(t -> {
  14. final AnnotatedType[] args = ((AnnotatedParameterizedType) t).getAnnotatedActualTypeArguments();
  15. for (int i = 0; i < args.length; i++) {
  16. final Type boundArgumentType = args[i].getType();
  17. if (boundArgumentType instanceof Class<?> || boundArgumentType.equals(var)) {
  18. round.get().add(new ContainerElementKey(t, Integer.valueOf(i)));
  19. }
  20. }
  21. });
  22. round.optional().ifPresent(s -> {
  23. s.forEach(sink);
  24. // recurse:
  25. s.forEach(k -> k.hierarchy(sink));
  26. });
  27. }

代码示例来源:origin: org.apache.bval/bval-jsr

  1. final Lazy<Set<ContainerElementKey>> result = new Lazy<>(HashSet::new);
  2. Stream.of(extractorType.getAnnotatedInterfaces()).filter(AnnotatedParameterizedType.class::isInstance)
  3. .map(AnnotatedParameterizedType.class::cast)
  4. .filter(apt -> ValueExtractor.class.equals(((ParameterizedType) apt.getType()).getRawType()))

代码示例来源:origin: org.apache.tomee.patch/bval-jsr

  1. final Lazy<Set<ContainerElementKey>> result = new Lazy<>(HashSet::new);
  2. Stream.of(extractorType.getAnnotatedInterfaces()).filter(AnnotatedParameterizedType.class::isInstance)
  3. .map(AnnotatedParameterizedType.class::cast)
  4. .filter(apt -> ValueExtractor.class.equals(((ParameterizedType) apt.getType()).getRawType()))

代码示例来源:origin: org.eclipse.kapua/kapua-commons

  1. String serviceInterface = impementedClass[0].getAnnotatedInterfaces()[0].getType().getTypeName();
  2. String genericsList = serviceInterface.substring(serviceInterface.indexOf('<') + 1, serviceInterface.indexOf('>'));
  3. String[] entityClassesToScan = genericsList.replaceAll("\\,", "").split(" ");

代码示例来源:origin: eclipse/kapua

  1. String serviceInterface = impementedClass[0].getAnnotatedInterfaces()[0].getType().getTypeName();
  2. String genericsList = serviceInterface.substring(serviceInterface.indexOf('<') + 1, serviceInterface.indexOf('>'));
  3. String[] entityClassesToScan = genericsList.replaceAll("\\,", "").split(" ");

代码示例来源:origin: com.oracle.substratevm/svm

  1. allAnnotatedInterfaces = javaClass.getAnnotatedInterfaces();
  2. } catch (MalformedParameterizedTypeException | TypeNotPresentException | NoClassDefFoundError t) {

代码示例来源:origin: io.leangen.geantyref/geantyref

  1. AnnotatedType[] superInterfaces = clazz.getAnnotatedInterfaces();
  2. AnnotatedType superClass = clazz.getAnnotatedSuperclass();

相关文章

Class类方法