/** * Determine whether the given {@code Class} is a Kotlin type * (with Kotlin metadata present on it). */ public static boolean isKotlinType(Class<?> clazz) { return (kotlinMetadata != null && clazz.getDeclaredAnnotation(kotlinMetadata) != null); }
/** * Determine whether the given {@code Class} is a Kotlin type * (with Kotlin metadata present on it). */ public static boolean isKotlinType(Class<?> clazz) { return (kotlinMetadata != null && clazz.getDeclaredAnnotation(kotlinMetadata) != null); }
public static io.swagger.v3.oas.annotations.media.Schema getSchemaDeclaredAnnotation(Class<?> cls) { if (cls == null) { return null; } io.swagger.v3.oas.annotations.media.Schema mp = null; io.swagger.v3.oas.annotations.media.ArraySchema as = cls.getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.ArraySchema.class); if (as != null) { mp = as.schema(); } else { mp = cls.getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); } return mp; }
/** * Gets declared annotation for a class. * * @param <T> Type of annotation to return. * @param cls Class to get annotation from. * @param annCls Annotation to get. * @return Instance of annotation, or {@code null} if not found. */ @Nullable public static <T extends Annotation> T getDeclaredAnnotation(Class<?> cls, Class<T> annCls) { if (cls == Object.class) return null; return cls.getDeclaredAnnotation(annCls); }
/** * Returns true if the annotation exists. */ private boolean isDeclaredAnnotationPresent(Class<? extends Annotation> annotationClass) { if (annotationClass == null) { throw new NullPointerException("annotationClass == null"); } return getDeclaredAnnotation(annotationClass) != null; }
private String groupPrefix() { return SslPolicyConfig.class.getDeclaredAnnotation( Group.class ).value(); }
/** * Determine whether an annotation of the specified {@code annotationType} * is declared locally (i.e. <em>directly present</em>) on the supplied * {@code clazz}. * <p>The supplied {@link Class} may represent any type. * <p>Meta-annotations will <em>not</em> be searched. * <p>Note: This method does <strong>not</strong> determine if the annotation * is {@linkplain java.lang.annotation.Inherited inherited}. For greater * clarity regarding inherited annotations, consider using * {@link #isAnnotationInherited(Class, Class)} instead. * @param annotationType the annotation type to look for * @param clazz the class to check for the annotation on * @return {@code true} if an annotation of the specified {@code annotationType} * is <em>directly present</em> * @see java.lang.Class#getDeclaredAnnotations() * @see java.lang.Class#getDeclaredAnnotation(Class) * @see #isAnnotationInherited(Class, Class) */ public static boolean isAnnotationDeclaredLocally(Class<? extends Annotation> annotationType, Class<?> clazz) { try { return (clazz.getDeclaredAnnotation(annotationType) != null); } catch (Throwable ex) { handleIntrospectionFailure(clazz, ex); return false; } }
private RateLimiter getRateLimiterAnnotation(ProceedingJoinPoint proceedingJoinPoint) { RateLimiter rateLimiter = null; Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(RateLimiter.class)) { rateLimiter = targetClass.getAnnotation(RateLimiter.class); if (rateLimiter == null) { rateLimiter = targetClass.getDeclaredAnnotation(RateLimiter.class); } if (rateLimiter == null) { logger.debug("TargetClass has no declared annotation 'RateLimiter'"); } } return rateLimiter; }
@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
@Override public <A extends Annotation> A getAnnotation(Class<A> annotationType) { if (annotationType == null) { throw new NullPointerException("annotationType == null"); } A annotation = getDeclaredAnnotation(annotationType); if (annotation != null) { return annotation; } if (annotationType.isAnnotationPresent(Inherited.class)) { for (Class<?> sup = getSuperclass(); sup != null; sup = sup.getSuperclass()) { annotation = sup.getDeclaredAnnotation(annotationType); if (annotation != null) { return annotation; } } } return null; }
public static io.swagger.v3.oas.annotations.media.Schema getSchemaDeclaredAnnotation(Annotated a) { if (a == null) { return null; } io.swagger.v3.oas.annotations.media.ArraySchema arraySchema = a.getRawType().getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.ArraySchema.class); if (arraySchema != null) { return arraySchema.schema(); } else { return a.getRawType().getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); } }
private CircuitBreaker getBackendMonitoredAnnotation(ProceedingJoinPoint proceedingJoinPoint) { if (logger.isDebugEnabled()) { logger.debug("circuitBreaker parameter is null"); } CircuitBreaker circuitBreaker = null; Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(CircuitBreaker.class)) { circuitBreaker = targetClass.getAnnotation(CircuitBreaker.class); if (circuitBreaker == null) { if (logger.isDebugEnabled()) { logger.debug("TargetClass has no annotation 'CircuitBreaker'"); } circuitBreaker = targetClass.getDeclaredAnnotation(CircuitBreaker.class); if (circuitBreaker == null) { if (logger.isDebugEnabled()) { logger.debug("TargetClass has no declared annotation 'CircuitBreaker'"); } } } } return circuitBreaker; }
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, Set<Annotation> visited) { try { A annotation = clazz.getDeclaredAnnotation(annotationType); if (annotation != null) { return annotation;
/** * Determine whether an annotation of the specified {@code annotationType} * is declared locally (i.e. <em>directly present</em>) on the supplied * {@code clazz}. * <p>The supplied {@link Class} may represent any type. * <p>Meta-annotations will <em>not</em> be searched. * <p>Note: This method does <strong>not</strong> determine if the annotation * is {@linkplain java.lang.annotation.Inherited inherited}. For greater * clarity regarding inherited annotations, consider using * {@link #isAnnotationInherited(Class, Class)} instead. * @param annotationType the annotation type to look for * @param clazz the class to check for the annotation on * @return {@code true} if an annotation of the specified {@code annotationType} * is <em>directly present</em> * @see java.lang.Class#getDeclaredAnnotations() * @see java.lang.Class#getDeclaredAnnotation(Class) * @see #isAnnotationInherited(Class, Class) */ public static boolean isAnnotationDeclaredLocally(Class<? extends Annotation> annotationType, Class<?> clazz) { try { return (clazz.getDeclaredAnnotation(annotationType) != null); } catch (Throwable ex) { handleIntrospectionFailure(clazz, ex); return false; } }
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, Set<Annotation> visited) { try { A annotation = clazz.getDeclaredAnnotation(annotationType); if (annotation != null) { return annotation;
public static void validate(Class<? extends WorkItemHandler> handlerClass, WorkItem workItem) throws Exception { Wid handlerWidAnnotation = handlerClass.getDeclaredAnnotation(Wid.class); if (workItem == null || handlerWidAnnotation == null || handlerWidAnnotation.parameters() == null || handlerWidAnnotation.parameters().length < 1) { // nothing to validate return; } for (WidParameter handlerWidParameter : handlerWidAnnotation.parameters()) { if (handlerWidParameter.name() != null && handlerWidParameter.required()) { if (workItem.getParameter(handlerWidParameter.name()) == null) { logger.error("Workitem declares following required parameter which does not exist: " + handlerWidParameter.name()); throw new IllegalArgumentException("Workitem declares following required parameter which does not exist: " + handlerWidParameter.name()); } } } } }
WechatAddonConfig wechatAddonConfig = addonClass.getDeclaredAnnotation(WechatAddonConfig.class); if (wechatAddonConfig == null) { continue;
protected Discriminator resolveDiscriminator(JavaType type, ModelConverterContext context) { io.swagger.v3.oas.annotations.media.Schema declaredSchemaAnnotation = AnnotationsUtils.getSchemaDeclaredAnnotation(type.getRawClass()); String disc = (declaredSchemaAnnotation == null) ? "" : declaredSchemaAnnotation.discriminatorProperty(); if (disc.isEmpty()) { // longer method would involve AnnotationIntrospector.findTypeResolver(...) but: JsonTypeInfo typeInfo = type.getRawClass().getDeclaredAnnotation(JsonTypeInfo.class); if (typeInfo != null) { disc = typeInfo.property(); } } if (!disc.isEmpty()) { Discriminator discriminator = new Discriminator() .propertyName(disc); if (declaredSchemaAnnotation != null) { DiscriminatorMapping mappings[] = declaredSchemaAnnotation.discriminatorMapping(); if (mappings != null && mappings.length > 0) { for (DiscriminatorMapping mapping : mappings) { if (!mapping.value().isEmpty() && !mapping.schema().equals(Void.class)) { discriminator.mapping(mapping.value(), constructRef(context.resolve(new AnnotatedType().type(mapping.schema())).getName())); } } } } return discriminator; } return null; }
public static Annotation mergeSchemaAnnotations( Annotation[] ctxAnnotations, JavaType type) { io.swagger.v3.oas.annotations.media.Schema tS = type.getRawClass().getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.Schema.class); if (!hasSchemaAnnotation(tS)) { tS = null; io.swagger.v3.oas.annotations.media.ArraySchema tA = type.getRawClass().getDeclaredAnnotation(io.swagger.v3.oas.annotations.media.ArraySchema.class); if (!hasArrayAnnotation(tA)) { tA = null;
/** * Finds the first class in a class hierarchy that is annotated with {@link ArtifactClassLoaderRunnerConfig}. * <p/> * Annotated class is searched by levels, in a Breadth-first search (BFS) way. Starting from the class received as a parameter, * first the class is checked and return if annotated. Otherwise interface directly implemented by the class will be added to * review and finally its super class. * <p/> * Implemented interfaces have priority over class hierarchy as base classes can be imported from other modules with different * runner configurations. * * @param testClass class of the test begin executed by the test runner. * @return the first class found in the hierarchy that is annotated, null if no class in the hierarchy is annotated. */ public static Class findConfiguredClass(Class<?> testClass) { Deque<Class> classesToReview = new LinkedList<>(); classesToReview.push(testClass); while (!classesToReview.isEmpty()) { Class currentClass = classesToReview.pop(); if (currentClass.getDeclaredAnnotation(ArtifactClassLoaderRunnerConfig.class) != null) { LOGGER.info("Reading test runner configuration for test '{}' from '{}'", testClass.getName(), currentClass.getName()); return currentClass; } addAll(classesToReview, currentClass.getInterfaces()); if (currentClass.getSuperclass() != null && currentClass.getSuperclass() != Object.class) { classesToReview.add(currentClass.getSuperclass()); } } return null; }