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

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

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

Class.getAnnotatedSuperclass介绍

暂无

代码示例

代码示例来源: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. Class<?> c = o.getClass();
  2. AnnotatedType type = c.getAnnotatedSuperclass();
  3. System.out.println(Arrays.toString(type.getAnnotations()));

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

  1. import java.lang.annotation.*;
  2. public class AnnotationTest {
  3. @Target(ElementType.TYPE_USE)
  4. @Retention(RetentionPolicy.RUNTIME)
  5. @interface First { }
  6. @Target(ElementType.TYPE_USE)
  7. @Retention(RetentionPolicy.RUNTIME)
  8. @interface Second { }
  9. class A { }
  10. class B extends @First @Second A { }
  11. public static void main(String[] args) {
  12. Annotation[] anns = B.class.getAnnotatedSuperclass().getAnnotations();
  13. System.out.printf("There are %d annotations on B's use of its superclass.%n", anns.length);
  14. for (Annotation a : anns)
  15. System.out.println(a.annotationType().getName());
  16. }
  17. }

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

  1. public TO getTo() throws Exception{
  2. if (to == null) {
  3. try{
  4. to = ((Class<TO>)((ParameterizedType)this.getClass().
  5. getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
  6. }catch(ClassCastException cce){
  7. cce.printStackTrace();
  8. to = ((Class<TO>)((ParameterizedType)(((Class<TO>)
  9. this.getClass().getAnnotatedSuperclass().getType()).getGenericSuperclass()))
  10. .getActualTypeArguments()[0]).newInstance();
  11. }
  12. }
  13. return to;
  14. }

代码示例来源:origin: leangen/graphql-spqr

  1. private AnnotatedType getSourceType() {
  2. return GenericTypeReflector.getTypeParameter(getClass().getAnnotatedSuperclass(), AbstractTypeAdapter.class.getTypeParameters()[0]);
  3. }
  4. }

代码示例来源:origin: leangen/graphql-spqr

  1. private AnnotatedType getTypeArguments(int index) {
  2. return GenericTypeReflector.getTypeParameter(getClass().getAnnotatedSuperclass(), CachingMapper.class.getTypeParameters()[index]);
  3. }
  4. }

代码示例来源:origin: leangen/graphql-spqr

  1. public AbstractTypeSubstitutingMapper() {
  2. substituteType = GenericTypeReflector.getTypeParameter(getClass().getAnnotatedSuperclass(), AbstractTypeSubstitutingMapper.class.getTypeParameters()[0]);
  3. }

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

  1. List<?> token = new ArrayList<@NonNull String>() {};
  2. fullType("", token.getClass().getAnnotatedSuperclass());

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

  1. public TO getTo() throws Exception {
  2. if(to == null) {
  3. try {
  4. to = ((Class<TO>) ((ParameterizedType) this.getClass().getGenericSuperclass())
  5. .getActualTypeArguments()[0]).newInstance();
  6. } catch(ClassCastException cce) {
  7. cce.printStackTrace();
  8. to = ((Class<TO>) ((ParameterizedType) (((Class<TO>) this.getClass()
  9. .getAnnotatedSuperclass().getType()).getGenericSuperclass()))
  10. .getActualTypeArguments()[0]).newInstance();
  11. }
  12. }
  13. return to;
  14. }

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

  1. private AnnotatedType extractType() {
  2. AnnotatedType t = getClass().getAnnotatedSuperclass();
  3. if (!(t instanceof AnnotatedParameterizedType)) {
  4. throw new RuntimeException("Invalid TypeToken; must specify type parameters");
  5. }
  6. AnnotatedParameterizedType pt = (AnnotatedParameterizedType) t;
  7. if (((ParameterizedType) pt.getType()).getRawType() != TypeToken.class) {
  8. throw new RuntimeException("Invalid TypeToken; must directly extend TypeToken");
  9. }
  10. return pt.getAnnotatedActualTypeArguments()[0];
  11. }

代码示例来源:origin: rulebook-rules/rulebook

  1. /**
  2. * Gets the POJO Rules to be used by the RuleBook via reflection of the specified package.
  3. * @return a List of POJO Rules
  4. */
  5. protected List<Class<?>> getPojoRules() {
  6. Reflections reflections = new Reflections(_package);
  7. List<Class<?>> rules = reflections
  8. .getTypesAnnotatedWith(com.deliveredtechnologies.rulebook.annotation.Rule.class).stream()
  9. .filter(rule -> rule.getAnnotatedSuperclass() != null) // Include classes only, exclude interfaces, etc.
  10. .filter(rule -> _subPkgMatch.test(rule.getPackage().getName()))
  11. .collect(Collectors.toList());
  12. rules.sort(comparingInt(aClass ->
  13. getAnnotation(com.deliveredtechnologies.rulebook.annotation.Rule.class, aClass).order()));
  14. return rules;
  15. }
  16. }

代码示例来源: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: com.oracle.substratevm/svm

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

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

  1. AnnotatedType superClass = clazz.getAnnotatedSuperclass();

相关文章

Class类方法