/** * Sets the value member to the given type object. * * @param name The name of the member * @param type The type * @return This builder */ public AnnotationValueBuilder<T> member(String name, @Nullable Class<?> type) { if (type != null) { values.put(name, new AnnotationClassValue<>(type)); } return this; }
addConverter(AnnotationClassValue.class, Class.class, (object, targetType, context) -> object.getType()); addConverter(AnnotationClassValue[].class, Class.class, (object, targetType, context) -> { if (object.length > 0) { final AnnotationClassValue o = object[0]; if (o != null) { return o.getType(); for (AnnotationClassValue<?> annotationClassValue : object) { if (annotationClassValue != null) { final Optional<? extends Class<?>> type = annotationClassValue.getType(); if (type.isPresent()) { classes.add(type.get());
/** * Registers a annotation type. * * @param annotationClassValue the annotation class value */ @SuppressWarnings("unchecked") private static void registerAnnotationType(AnnotationClassValue<?> annotationClassValue) { final String name = annotationClassValue.getName(); if (!ANNOTATION_TYPES.containsKey(name)) { annotationClassValue.getType().ifPresent((Consumer<Class<?>>) aClass -> { if (Annotation.class.isAssignableFrom(aClass)) { ANNOTATION_TYPES.put(name, (Class<? extends Annotation>) aClass); } }); } }
/** * Registers default values for the given annotation and values. * * @param annotation The annotation * @param defaultValues The default values */ static void registerDefaultValues(AnnotationClassValue<?> annotation, Map<String, Object> defaultValues) { registerDefaultValues(annotation.getName(), defaultValues); registerAnnotationType(annotation); }
/** * Registers a annotation type. * * @param annotationClassValue the annotation class value */ @SuppressWarnings("unchecked") private static void registerAnnotationType(AnnotationClassValue<?> annotationClassValue) { final String name = annotationClassValue.getName(); if (!ANNOTATION_TYPES.containsKey(name)) { annotationClassValue.getType().ifPresent((Consumer<Class<?>>) aClass -> { if (Annotation.class.isAssignableFrom(aClass)) { ANNOTATION_TYPES.put(name, (Class<? extends Annotation>) aClass); } }); } }
/** * Registers default values for the given annotation and values. * * @param annotation The annotation * @param defaultValues The default values */ static void registerDefaultValues(AnnotationClassValue<?> annotation, Map<String, Object> defaultValues) { registerDefaultValues(annotation.getName(), defaultValues); registerAnnotationType(annotation); }
private boolean matchesPresenceOfClasses(ConditionContext context, AnnotationValue<Requires> requirements, String attr) { if (requirements.contains(attr)) { Optional<AnnotationClassValue[]> classNames = requirements.get(attr, AnnotationClassValue[].class); if (classNames.isPresent()) { AnnotationClassValue[] classValues = classNames.get(); for (AnnotationClassValue classValue : classValues) { if (!classValue.getType().isPresent()) { context.fail("Class [" + classValue.getName() + "] is not present"); if (ClassLoadingReporter.isReportingEnabled()) { for (AnnotationClassValue cv : classValues) { ClassLoadingReporter.reportMissing(cv.getName()); } reportMissingClass(context); } return false; } } } } return true; }
/** * Sets the value member to the given type objects. * * @param name The name of the member * @param types The type[] * @return This builder */ public AnnotationValueBuilder<T> member(String name, @Nullable Class<?>... types) { if (types != null) { AnnotationClassValue[] classValues = new AnnotationClassValue[types.length]; for (int i = 0; i < types.length; i++) { Class<?> type = types[i]; classValues[i] = new AnnotationClassValue<>(type); } values.put(name, classValues); } return this; }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final AnnotationValueBuilder<?> builder = AnnotationValue.builder("io.micronaut.spring.tx.annotation.Transactional"); annotation.getValue(String.class).ifPresent(s -> { builder.value(s); builder.member("transactionManager", s); }); Stream.of("propagation", "isolation", "transactionManager") .forEach(member -> annotation.get(member, String.class).ifPresent(s -> builder.member(member, s))); Stream.of("rollbackForClassName", "noRollbackForClassName") .forEach(member -> annotation.get(member, String[].class).ifPresent(s -> builder.member(member, s))); Stream.of("rollbackFor", "noRollbackFor") .forEach(member -> annotation.get(member, AnnotationClassValue[].class).ifPresent(classValues -> { String[] names = new String[classValues.length]; for (int i = 0; i < classValues.length; i++) { AnnotationClassValue classValue = classValues[i]; names[i] = classValue.getName(); } builder.member(member, names); })); annotation.get("timeout", Integer.class).ifPresent(integer -> builder.member("timeout", integer)); annotation.get("readOnly", Boolean.class).ifPresent(bool -> builder.member("readOnly", bool)); return Collections.singletonList(builder.build()); } }
private boolean matchesPresenceOfClasses(ConditionContext context, AnnotationValue<Requires> requirements, String attr) { if (requirements.contains(attr)) { Optional<AnnotationClassValue[]> classNames = requirements.get(attr, AnnotationClassValue[].class); if (classNames.isPresent()) { AnnotationClassValue[] classValues = classNames.get(); for (AnnotationClassValue classValue : classValues) { if (!classValue.getType().isPresent()) { context.fail("Class [" + classValue.getName() + "] is not present"); if (ClassLoadingReporter.isReportingEnabled()) { for (AnnotationClassValue cv : classValues) { ClassLoadingReporter.reportMissing(cv.getName()); } reportMissingClass(context); } return false; } } } } return true; }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder(Requires.class) .member("missingBeans", new AnnotationClassValue<>(EmbeddedServer.class)) .build() ); }
Map<String, GeneratorAdapter> loadTypeMethods, AnnotationClassValue acv) { final String typeName = acv.getName(); final String desc = getMethodDescriptor(AnnotationClassValue.class, Collections.emptyList()); final GeneratorAdapter loadTypeGeneratorMethod = loadTypeMethods.computeIfAbsent(typeName, type -> {
private boolean matchesPresenceOfEntities(ConditionContext context, AnnotationValue<Requires> annotationValue) { if (annotationValue.contains("entities")) { Optional<AnnotationClassValue[]> classNames = annotationValue.get("entities", AnnotationClassValue[].class); if (classNames.isPresent()) { BeanContext beanContext = context.getBeanContext(); if (beanContext instanceof ApplicationContext) { ApplicationContext applicationContext = (ApplicationContext) beanContext; final AnnotationClassValue[] classValues = classNames.get(); for (AnnotationClassValue<?> classValue : classValues) { final Optional<? extends Class<?>> entityType = classValue.getType(); if (!entityType.isPresent()) { context.fail("Annotation type [" + classValue.getName() + "] not present on classpath"); return false; } else { Environment environment = applicationContext.getEnvironment(); Class annotationType = entityType.get(); if (!environment.scan(annotationType).findFirst().isPresent()) { context.fail("No entities found in packages [" + String.join(", ", environment.getPackages()) + "] for annotation: " + annotationType); return false; } } } } } } return true; }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { return Collections.singletonList( AnnotationValue.builder(Requires.class) .member("beans", new AnnotationClassValue<>(EmbeddedServer.class)) .build() ); }
Map<String, GeneratorAdapter> loadTypeMethods, AnnotationClassValue acv) { final String typeName = acv.getName(); final String desc = getMethodDescriptor(AnnotationClassValue.class, Collections.emptyList()); final GeneratorAdapter loadTypeGeneratorMethod = loadTypeMethods.computeIfAbsent(typeName, type -> {
private boolean matchesPresenceOfEntities(ConditionContext context, AnnotationValue<Requires> annotationValue) { if (annotationValue.contains("entities")) { Optional<AnnotationClassValue[]> classNames = annotationValue.get("entities", AnnotationClassValue[].class); if (classNames.isPresent()) { BeanContext beanContext = context.getBeanContext(); if (beanContext instanceof ApplicationContext) { ApplicationContext applicationContext = (ApplicationContext) beanContext; final AnnotationClassValue[] classValues = classNames.get(); for (AnnotationClassValue<?> classValue : classValues) { final Optional<? extends Class<?>> entityType = classValue.getType(); if (!entityType.isPresent()) { context.fail("Annotation type [" + classValue.getName() + "] not present on classpath"); return false; } else { Environment environment = applicationContext.getEnvironment(); Class annotationType = entityType.get(); if (!environment.scan(annotationType).findFirst().isPresent()) { context.fail("No entities found in packages [" + String.join(", ", environment.getPackages()) + "] for annotation: " + annotationType); return false; } } } } } } return true; }
@Override protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) { final AnnotationClassValue annotationClassValue = annotation.getValue(AnnotationClassValue.class).orElseGet(() -> annotation.get("type", String.class).map(AnnotationClassValue::new).orElse(null) ); if (annotationClassValue != null) { return Arrays.asList( AnnotationValue.builder(Requires.class) .member("condition", new AnnotationClassValue<>( "io.micronaut.spring.boot.condition.RequiresSingleCandidateCondition" )) .build(), AnnotationValue.builder("io.micronaut.spring.boot.condition.RequiresSingleCandidate") .member("value", annotationClassValue) .build() ); } return Collections.emptyList(); }
if (value instanceof AnnotationClassValue) { AnnotationClassValue acv = (AnnotationClassValue) value; return environment.convert(acv.getType().orElse(acv.getName()), conversionContext); } else if (value instanceof CharSequence) { PropertyPlaceholderResolver placeholderResolver = environment.getPlaceholderResolver();
staticInit.visitLabel(new Label()); invokeLoadClassValueMethod(owningType, classWriter, staticInit, loadTypeMethods, new AnnotationClassValue(annotationName)); final Map<String, Object> value = entry.getValue(); pushAnnotationAttributes(owningType, classWriter, staticInit, value, loadTypeMethods);
if (value instanceof AnnotationClassValue) { AnnotationClassValue acv = (AnnotationClassValue) value; return environment.convert(acv.getType().orElse(acv.getName()), conversionContext); } else if (value instanceof CharSequence) { PropertyPlaceholderResolver placeholderResolver = environment.getPlaceholderResolver();