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

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

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

Class.isAnnotationPresent介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create a new {@link AnnotationTypeFilter} for the given annotation type.
 * @param annotationType the annotation type to match
 * @param considerMetaAnnotations whether to also match on meta-annotations
 * @param considerInterfaces whether to also match interfaces
 */
public AnnotationTypeFilter(
    Class<? extends Annotation> annotationType, boolean considerMetaAnnotations, boolean considerInterfaces) {
  super(annotationType.isAnnotationPresent(Inherited.class), considerInterfaces);
  this.annotationType = annotationType;
  this.considerMetaAnnotations = considerMetaAnnotations;
}

代码示例来源:origin: apache/incubator-dubbo

private static <T> boolean withExtensionAnnotation(Class<T> type) {
  return type.isAnnotationPresent(SPI.class);
}

代码示例来源:origin: apache/incubator-dubbo

private static <T> boolean withExtensionAnnotation(Class<T> type) {
  return type.isAnnotationPresent(SPI.class);
}

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

/** Returns true if the supplied class includes an annotation of the given type. */
static public boolean isAnnotationPresent (Class c, Class<? extends java.lang.annotation.Annotation> annotationType) {
  return c.isAnnotationPresent(annotationType);
}

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

/** Returns true if the supplied class includes an annotation of the given type. */
static public boolean isAnnotationPresent (Class c, Class<? extends java.lang.annotation.Annotation> annotationType) {
  return c.isAnnotationPresent(annotationType);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Checks whether the given annotation type is a recognized qualifier type.
 */
protected boolean isQualifier(Class<? extends Annotation> annotationType) {
  for (Class<? extends Annotation> qualifierType : this.qualifierTypes) {
    if (annotationType.equals(qualifierType) || annotationType.isAnnotationPresent(qualifierType)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: apache/incubator-dubbo

private static boolean hasConstraintParameter(Method method) {
  Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  if (parameterAnnotations != null && parameterAnnotations.length > 0) {
    for (Annotation[] annotations : parameterAnnotations) {
      for (Annotation annotation : annotations) {
        if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
          return true;
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: apache/incubator-dubbo

private static boolean hasConstraintParameter(Method method) {
  Annotation[][] parameterAnnotations = method.getParameterAnnotations();
  if (parameterAnnotations != null && parameterAnnotations.length > 0) {
    for (Annotation[] annotations : parameterAnnotations) {
      for (Annotation annotation : annotations) {
        if (annotation.annotationType().isAnnotationPresent(Constraint.class)) {
          return true;
        }
      }
    }
  }
  return false;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) {
  return (clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class)) &&
      canRead(mediaType);
}

代码示例来源:origin: square/retrofit

private static Set<? extends Annotation> jsonAnnotations(Annotation[] annotations) {
  Set<Annotation> result = null;
  for (Annotation annotation : annotations) {
   if (annotation.annotationType().isAnnotationPresent(JsonQualifier.class)) {
    if (result == null) result = new LinkedHashSet<>();
    result.add(annotation);
   }
  }
  return result != null ? unmodifiableSet(result) : Collections.<Annotation>emptySet();
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
  if (super.canEncode(elementType, mimeType)) {
    Class<?> outputClass = elementType.toClass();
    return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
        outputClass.isAnnotationPresent(XmlType.class));
  }
  else {
    return false;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
  Class<?> outputClass = elementType.toClass();
  return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
      outputClass.isAnnotationPresent(XmlType.class)) && super.canDecode(elementType, mimeType);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public boolean matches(Class<?> clazz) {
  return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(clazz, this.annotationType) :
      clazz.isAnnotationPresent(this.annotationType));
}

代码示例来源:origin: square/retrofit

@Override public @Nullable Converter<ResponseBody, ?> responseBodyConverter(
  Type type, Annotation[] annotations, Retrofit retrofit) {
 if (type instanceof Class && ((Class<?>) type).isAnnotationPresent(XmlRootElement.class)) {
  return new JaxbResponseConverter<>(contextForType((Class<?>) type), (Class<?>) type);
 }
 return null;
}

代码示例来源:origin: square/retrofit

@Override public @Nullable Converter<?, RequestBody> requestBodyConverter(Type type,
  Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
 if (type instanceof Class && ((Class<?>) type).isAnnotationPresent(XmlRootElement.class)) {
  return new JaxbRequestConverter<>(contextForType((Class<?>) type), (Class<?>) type);
 }
 return null;
}

代码示例来源:origin: alibaba/fastjson

public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
  return FastJsonHttpMessageConverter.class.isAssignableFrom(converterType)
      &&
      (returnType.getContainingClass().isAnnotationPresent(ResponseJSONP.class) || returnType.hasMethodAnnotation(ResponseJSONP.class));
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public <T> T getExtension(Class<T> type, String name) {
  if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
    ExtensionLoader<T> loader = ExtensionLoader.getExtensionLoader(type);
    if (!loader.getSupportedExtensions().isEmpty()) {
      return loader.getAdaptiveExtension();
    }
  }
  return null;
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public <T> T getExtension(Class<T> type, String name) {
  if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
    ExtensionLoader<T> loader = ExtensionLoader.getExtensionLoader(type);
    if (!loader.getSupportedExtensions().isEmpty()) {
      return loader.getAdaptiveExtension();
    }
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

private Object unmarshal(List<XMLEvent> events, Class<?> outputClass) {
  try {
    Unmarshaller unmarshaller = initUnmarshaller(outputClass);
    XMLEventReader eventReader = StaxUtils.createXMLEventReader(events);
    if (outputClass.isAnnotationPresent(XmlRootElement.class)) {
      return unmarshaller.unmarshal(eventReader);
    }
    else {
      JAXBElement<?> jaxbElement = unmarshaller.unmarshal(eventReader, outputClass);
      return jaxbElement.getValue();
    }
  }
  catch (UnmarshalException ex) {
    throw new DecodingException("Could not unmarshal XML to " + outputClass, ex);
  }
  catch (JAXBException ex) {
    throw new CodecException("Invalid JAXB configuration", ex);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
  if (isLogEnabled()) {
    String[] beanNames = beanFactory.getBeanDefinitionNames();
    for (String beanName : beanNames) {
      String nameToLookup = beanName;
      if (beanFactory.isFactoryBean(beanName)) {
        nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
      }
      Class<?> beanType = beanFactory.getType(nameToLookup);
      if (beanType != null) {
        Class<?> userClass = ClassUtils.getUserClass(beanType);
        if (userClass.isAnnotationPresent(Deprecated.class)) {
          BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
          logDeprecatedBean(beanName, beanType, beanDefinition);
        }
      }
    }
  }
}

相关文章

Class类方法