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

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

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

/**
 * 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

Class<?> c = o.getClass();
 AnnotatedType type = c.getAnnotatedSuperclass();
 System.out.println(Arrays.toString(type.getAnnotations()));

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

import java.lang.annotation.*;

public class AnnotationTest {

  @Target(ElementType.TYPE_USE)
  @Retention(RetentionPolicy.RUNTIME)
  @interface First { }

  @Target(ElementType.TYPE_USE)
  @Retention(RetentionPolicy.RUNTIME)
  @interface Second { }

  class A { }

  class B extends @First @Second A { }

  public static void main(String[] args) {
    Annotation[] anns = B.class.getAnnotatedSuperclass().getAnnotations();
    System.out.printf("There are %d annotations on B's use of its superclass.%n", anns.length);
    for (Annotation a : anns)
      System.out.println(a.annotationType().getName());
  }
}

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

public TO getTo() throws Exception{
  if (to == null) {
   try{
     to = ((Class<TO>)((ParameterizedType)this.getClass().
           getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
   }catch(ClassCastException cce){
     cce.printStackTrace();
     to = ((Class<TO>)((ParameterizedType)(((Class<TO>)
         this.getClass().getAnnotatedSuperclass().getType()).getGenericSuperclass()))
           .getActualTypeArguments()[0]).newInstance();
   }   
  }
  return to;
 }

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

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

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

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

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

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

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

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

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

public TO getTo() throws Exception {
  if(to == null) {
    try {
      to = ((Class<TO>) ((ParameterizedType) this.getClass().getGenericSuperclass())
          .getActualTypeArguments()[0]).newInstance();
    } catch(ClassCastException cce) {
      cce.printStackTrace();
      to = ((Class<TO>) ((ParameterizedType) (((Class<TO>) this.getClass()
          .getAnnotatedSuperclass().getType()).getGenericSuperclass()))
              .getActualTypeArguments()[0]).newInstance();
    }
  }
  return to;
}

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

private AnnotatedType extractType() {
  AnnotatedType t = getClass().getAnnotatedSuperclass();
  if (!(t instanceof AnnotatedParameterizedType)) {
    throw new RuntimeException("Invalid TypeToken; must specify type parameters");
  }
  AnnotatedParameterizedType pt = (AnnotatedParameterizedType) t;
  if (((ParameterizedType) pt.getType()).getRawType() != TypeToken.class) {
    throw new RuntimeException("Invalid TypeToken; must directly extend TypeToken");
  }
  return pt.getAnnotatedActualTypeArguments()[0];
}

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

/**
  * Gets the POJO Rules to be used by the RuleBook via reflection of the specified package.
  * @return  a List of POJO Rules
  */
 protected List<Class<?>> getPojoRules() {
  Reflections reflections = new Reflections(_package);

  List<Class<?>> rules = reflections
    .getTypesAnnotatedWith(com.deliveredtechnologies.rulebook.annotation.Rule.class).stream()
    .filter(rule -> rule.getAnnotatedSuperclass() != null) // Include classes only, exclude interfaces, etc.
    .filter(rule -> _subPkgMatch.test(rule.getPackage().getName()))
    .collect(Collectors.toList());

  rules.sort(comparingInt(aClass ->
    getAnnotation(com.deliveredtechnologies.rulebook.annotation.Rule.class, aClass).order()));

  return rules;
 }
}

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

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

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

AnnotatedType superClass = clazz.getAnnotatedSuperclass();

相关文章

Class类方法