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

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

本文整理了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

/**
 * Given a Factory Name return the generic type parameters of the factory (The actual repository class, and its properties class)o
 */
public static Type[] getEnvironmentRepositoryFactoryTypeParams(ConfigurableListableBeanFactory beanFactory, String factoryName) {
  MethodMetadata methodMetadata = (MethodMetadata) beanFactory.getBeanDefinition(factoryName).getSource();
  Class<?> factoryClass = null;
  try {
    factoryClass = Class.forName(methodMetadata.getReturnTypeName());
  } catch (ClassNotFoundException e) {
    throw new IllegalStateException(e);
  }
  Optional<AnnotatedType> annotatedFactoryType = Arrays.stream(factoryClass.getAnnotatedInterfaces())
      .filter(i -> {
        ParameterizedType parameterizedType = (ParameterizedType) i.getType();
        return parameterizedType.getRawType().equals(EnvironmentRepositoryFactory.class);
      }).findFirst();
  ParameterizedType factoryParameterizedType = (ParameterizedType) annotatedFactoryType
      .orElse(factoryClass.getAnnotatedSuperclass()).getType();
  return factoryParameterizedType.getActualTypeArguments();
}

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

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

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

@Retention(RetentionPolicy.RUNTIME)
public @interface X {
  String[] value();
}

@X({"a", "b", "c"})
interface AnInterface {}

public static class TestClass implements AnInterface {}

public static void main(String[] args) {
  // annotations are not inherited, empty array
  System.out.println(Arrays.toString(TestClass.class.getAnnotations()));

  // check if TestClass is annotated with X and get X.value()
  Arrays.stream(TestClass.class.getAnnotatedInterfaces())
      .filter(type -> type.getType().equals(AnInterface.class))
      .map(type -> (Class<AnInterface>) type.getType())
      .findFirst()
      .ifPresent(anInterface -> {
        String[] value = anInterface.getAnnotation(X.class).value();
        System.out.println(Arrays.toString(value));
      });
}

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

private static void determineValueExtractorDefinitions(List<AnnotatedType> valueExtractorDefinitions, Class<?> extractorImplementationType) {
  if ( !ValueExtractor.class.isAssignableFrom( extractorImplementationType ) ) {
    return;
  }
  Class<?> superClass = extractorImplementationType.getSuperclass();
  if ( superClass != null && !Object.class.equals( superClass ) ) {
    determineValueExtractorDefinitions( valueExtractorDefinitions, superClass );
  }
  for ( Class<?> implementedInterface : extractorImplementationType.getInterfaces() ) {
    if ( !ValueExtractor.class.equals( implementedInterface ) ) {
      determineValueExtractorDefinitions( valueExtractorDefinitions, implementedInterface );
    }
  }
  for ( AnnotatedType annotatedInterface : extractorImplementationType.getAnnotatedInterfaces() ) {
    if ( ValueExtractor.class.equals( ReflectionHelper.getClassFromType( annotatedInterface.getType() ) ) ) {
      valueExtractorDefinitions.add( annotatedInterface );
    }
  }
}

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

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

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

private void hierarchy(Consumer<ContainerElementKey> sink) {
  final TypeVariable<?> var;
  if (typeArgumentIndex == null) {
    var = null;
  } else {
    var = containerClass.getTypeParameters()[typeArgumentIndex.intValue()];
  }
  final Lazy<Set<ContainerElementKey>> round = new Lazy<>(LinkedHashSet::new);
  Stream
    .concat(Stream.of(containerClass.getAnnotatedSuperclass()),
      Stream.of(containerClass.getAnnotatedInterfaces()))
    .filter(AnnotatedParameterizedType.class::isInstance).map(AnnotatedParameterizedType.class::cast)
    .forEach(t -> {
      final AnnotatedType[] args = ((AnnotatedParameterizedType) t).getAnnotatedActualTypeArguments();
      for (int i = 0; i < args.length; i++) {
        final Type boundArgumentType = args[i].getType();
        if (boundArgumentType instanceof Class<?> || boundArgumentType.equals(var)) {
          round.get().add(new ContainerElementKey(t, Integer.valueOf(i)));
        }
      }
    });
  round.optional().ifPresent(s -> {
    s.forEach(sink);
    // recurse:
    s.forEach(k -> k.hierarchy(sink));
  });
}

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

private void hierarchy(Consumer<ContainerElementKey> sink) {
  final TypeVariable<?> var;
  if (typeArgumentIndex == null) {
    var = null;
  } else {
    var = containerClass.getTypeParameters()[typeArgumentIndex.intValue()];
  }
  final Lazy<Set<ContainerElementKey>> round = new Lazy<>(LinkedHashSet::new);
  Stream
    .concat(Stream.of(containerClass.getAnnotatedSuperclass()),
      Stream.of(containerClass.getAnnotatedInterfaces()))
    .filter(AnnotatedParameterizedType.class::isInstance).map(AnnotatedParameterizedType.class::cast)
    .forEach(t -> {
      final AnnotatedType[] args = ((AnnotatedParameterizedType) t).getAnnotatedActualTypeArguments();
      for (int i = 0; i < args.length; i++) {
        final Type boundArgumentType = args[i].getType();
        if (boundArgumentType instanceof Class<?> || boundArgumentType.equals(var)) {
          round.get().add(new ContainerElementKey(t, Integer.valueOf(i)));
        }
      }
    });
  round.optional().ifPresent(s -> {
    s.forEach(sink);
    // recurse:
    s.forEach(k -> k.hierarchy(sink));
  });
}

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

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

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

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

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

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

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

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

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

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

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

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

相关文章

Class类方法