io.micronaut.core.annotation.AnnotationValue Java Examples

The following examples show how to use io.micronaut.core.annotation.AnnotationValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappedEntityMapper.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
/**
 * The bean introspection configuration for a mapped entity.
 *
 * @return The entity
 */
public static AnnotationValue<Introspected> buildIntrospectionConfiguration() {
    final AnnotationValueBuilder<Introspected> builder = AnnotationValue.builder(Introspected.class)
            // don't bother with transients properties
            .member("excludedAnnotations", Transient.class)
            // following are indexed for fast lookups
            .member("indexed",
                    AnnotationValue.builder(Introspected.IndexedAnnotation.class)
                            .member("annotation", Id.class).build(),
                    AnnotationValue.builder(Introspected.IndexedAnnotation.class)
                            .member("annotation", Version.class).build(),
                    AnnotationValue.builder(Introspected.IndexedAnnotation.class)
                            .member("annotation", DateCreated.class).build(),
                    AnnotationValue.builder(Introspected.IndexedAnnotation.class)
                            .member("annotation", DateUpdated.class).build(),
                    AnnotationValue.builder(Introspected.IndexedAnnotation.class)
                            .member("annotation", MappedProperty.class)
                            .member("member", "value").build()
            );
    return builder.build();
}
 
Example #2
Source File: MappedEntityVisitor.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the configured data types.
 * @param element The element
 * @return The data types
 */
static Map<String, DataType> getConfiguredDataTypes(ClassElement element) {
    List<AnnotationValue<TypeDef>> typeDefinitions = element.getAnnotationValuesByType(TypeDef.class);
    Map<String, DataType> dataTypes = new HashMap<>(typeDefinitions.size());
    for (AnnotationValue<TypeDef> typeDefinition : typeDefinitions) {
        typeDefinition.enumValue("type", DataType.class).ifPresent(dataType -> {
            String[] values = typeDefinition.stringValues("classes");
            String[] names = typeDefinition.stringValues("names");
            String[] concated = ArrayUtils.concat(values, names);
            for (String s : concated) {
                dataTypes.put(s, dataType);
            }
        });
    }
    return dataTypes;
}
 
Example #3
Source File: ConditionalOnPropertyAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final String[] propertyNames = annotation.getValue(String[].class).orElseGet(() -> annotation.get("name", String[].class).orElse(null));
    if (propertyNames != null) {
        final String prefix = annotation.get("prefix", String.class).orElse(null);
        final boolean matchIfMissing = annotation.get("matchIfMissing", boolean.class).orElse(false);
        final String havingValue = annotation.get("havingValue", String.class).orElse(null);
        List<AnnotationValue<?>> annotationValues = new ArrayList<>(propertyNames.length);
        for (String propertyName : propertyNames) {
            if (prefix != null) {
                propertyName = prefix + "." + propertyName;
            }

            final AnnotationValueBuilder<Requires> builder = AnnotationValue.builder(Requires.class);
            builder.member(matchIfMissing ? "missingProperty" : "property", propertyName);
            if (havingValue != null) {
                builder.value(havingValue);
            }
            annotationValues.add(builder.build());

        }

        return annotationValues;
    }
    return Collections.emptyList();
}
 
Example #4
Source File: ConditionalOnSingleCandidateAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #5
Source File: TransactionalAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #6
Source File: ScheduledAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(Scheduled.class);
    annotation.get("cron", String.class).ifPresent(s -> builder.member("cron", s));

    // members that take numbers needed "ms" appending
    annotation.get("fixedDelay", String.class).ifPresent(s -> builder.member("fixedDelay", s + "ms"));
    annotation.get("fixedRate", String.class).ifPresent(s -> builder.member("fixedRate", s + "ms"));
    annotation.get("initialDelay", String.class).ifPresent(s -> builder.member("initialDelay", s + "ms"));

    annotation.get("fixedDelayString", String.class).ifPresent(s -> builder.member("fixedDelay", s));
    annotation.get("fixedRateString", String.class).ifPresent(s -> builder.member("fixedRate", s));
    annotation.get("initialDelayString", String.class).ifPresent(s -> builder.member("initialDelay", s));

    final AnnotationValue<?> scheduledAnn = builder
            .build();
    return Collections.singletonList(scheduledAnn);
}
 
Example #7
Source File: RequestMappingAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> annotations = new ArrayList<>();

    final String path = computePath(annotation);
    final Optional<HttpMethod> method = annotation.get("method", HttpMethod.class);

    annotations.add(newBuilder(method.orElse(null), annotation).value(path).build());

    final String[] consumes = annotation.get("consumes", String[].class).orElse(null);
    final String[] produces = annotation.get("produces", String[].class).orElse(null);

    if (ArrayUtils.isNotEmpty(consumes)) {
        annotations.add(AnnotationValue.builder(Consumes.class).member("value", consumes).build());
    }
    if (ArrayUtils.isNotEmpty(produces)) {
        annotations.add(AnnotationValue.builder(Produces.class).member("value", produces).build());
    }

    if (isHttpMethodMapping(method.orElse(null))) {
        annotations.add(AnnotationValue.builder(HttpMethodMapping.class).value(path).build());
    }
    return annotations;
}
 
Example #8
Source File: ColumnAnnotationMapper.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
public List<AnnotationValue<?>> map(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final String name = annotation.stringValue("name").orElse(null);
    final boolean nullable = annotation.booleanValue("nullable").orElse(false);
    AnnotationValue<MappedProperty> persistedAnnotationValue;
    List<AnnotationValue<?>> values = new ArrayList<>(2);
    if (name != null) {
        AnnotationValueBuilder<MappedProperty> builder = AnnotationValue.builder(MappedProperty.class)
                                                                        .value(name);
        annotation.stringValue("columnDefinition").ifPresent(s -> builder.member("definition", s));
        persistedAnnotationValue = builder
                .build();

        values.add(persistedAnnotationValue);
    } else {
        annotation.stringValue("columnDefinition").ifPresent(s ->
                values.add(AnnotationValue.builder(MappedProperty.class)
                                          .member("definition", s).build()));
    }

    if (nullable) {
        values.add(AnnotationValue.builder("javax.annotation.Nullable").build());
    }

    return values;
}
 
Example #9
Source File: BeanAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> newAnnotations = new ArrayList<>(3);
    final AnnotationValueBuilder<Bean> beanAnn = AnnotationValue.builder(Bean.class);

    final Optional<String> destroyMethod = annotation.get("destroyMethod", String.class);
    destroyMethod.ifPresent(s -> beanAnn.member("preDestroy", s));
    newAnnotations.add(beanAnn.build());
    newAnnotations.add(AnnotationValue.builder(DefaultScope.class)
            .value(Singleton.class)
            .build());
    final String beanName = annotation.getValue(String.class).orElse(annotation.get("name", String.class).orElse(null));

    if (StringUtils.isNotEmpty(beanName)) {
        newAnnotations.add(AnnotationValue.builder(Named.class).value(beanName).build());
    }

    return newAnnotations;
}
 
Example #10
Source File: TransactionalInterceptor.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
/**
 * @param executableMethod The method
 * @return The {@link TransactionAttribute}
 */
protected TransactionAttribute resolveTransactionDefinition(
        ExecutableMethod<Object, Object> executableMethod) {
    AnnotationValue<TransactionalAdvice> annotation = executableMethod.getAnnotation(TransactionalAdvice.class);

    if (annotation == null) {
        throw new IllegalStateException("No declared @Transactional annotation present");
    }

    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setName(executableMethod.getDeclaringType().getSimpleName() + "." + executableMethod.getMethodName());
    attribute.setReadOnly(annotation.isTrue("readOnly"));
    annotation.intValue("timeout").ifPresent(value -> attribute.setTimeout(Duration.ofSeconds(value)));
    final Class[] noRollbackFors = annotation.classValues("noRollbackFor");
    //noinspection unchecked
    attribute.setNoRollbackFor(noRollbackFors);
    annotation.enumValue("propagation", TransactionDefinition.Propagation.class)
            .ifPresent(attribute::setPropagationBehavior);
    annotation.enumValue("isolation", TransactionDefinition.Isolation.class)
            .ifPresent(attribute::setIsolationLevel);
    return attribute;
}
 
Example #11
Source File: ManyToOneMapper.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
public List<AnnotationValue<?>> map(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {

    final AnnotationValueBuilder<Relation> relationBuilder = AnnotationValue.builder(Relation.class)
            .value(Relation.Kind.MANY_TO_ONE);

    annotation.enumValue("cascade", Relation.Cascade.class).ifPresent(c ->
        relationBuilder.member("cascade", c)
    );

    AnnotationValue<Relation> ann = relationBuilder
            .build();
    boolean nullable = annotation.booleanValue("optional").orElse(true);
    if (nullable) {
        return Arrays.asList(
            AnnotationValue.builder("javax.annotation.Nullable").build(),
            ann
        );
    } else {
        return Collections.singletonList(ann);
    }
}
 
Example #12
Source File: GeneratedValueMapper.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
public List<AnnotationValue<?>> map(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    AnnotationValueBuilder<GeneratedValue> generatedValueBuilder = AnnotationValue.builder(GeneratedValue.class);
    annotation.stringValue("strategy").ifPresent(s -> {
        try {
            GeneratedValue.Type type = GeneratedValue.Type.valueOf(s);
            generatedValueBuilder.value(type);
        } catch (IllegalArgumentException e) {
            // not a compatible enum
        }
    });
    return Arrays.asList(
            generatedValueBuilder.build(),
            // include nullable for generated values, so they are excluded from null checks
            AnnotationValue.builder("javax.annotation.Nullable").build()
    );
}
 
Example #13
Source File: AbstractSqlRepositoryOperations.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
private <T> Map<String, Integer> buildSqlParameterBinding(AnnotationMetadata annotationMetadata) {
    AnnotationValue<DataMethod> annotation = annotationMetadata.getAnnotation(DataMethod.class);
    if (annotation == null) {
        return Collections.emptyMap();
    }
    String[] parameterData = annotationMetadata.stringValues(DataMethod.class, DataMethod.META_MEMBER_PARAMETER_BINDING_PATHS);
    Map<String, Integer> parameterValues;
    if (ArrayUtils.isNotEmpty(parameterData)) {
        parameterValues = new HashMap<>(parameterData.length);
        for (int i = 0; i < parameterData.length; i++) {
            String p = parameterData[i];
            parameterValues.put(p, i + 1);
        }
    } else {
        parameterValues = Collections.emptyMap();
    }
    return parameterValues;
}
 
Example #14
Source File: OneToOneMapper.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
public List<AnnotationValue<?>> map(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    AnnotationValueBuilder<Relation> builder = AnnotationValue.builder(Relation.class).value(Relation.Kind.ONE_TO_ONE);
    annotation.enumValue("cascade", Relation.Cascade.class).ifPresent(c ->
            builder.member("cascade", c)
    );
    annotation.stringValue("mappedBy").ifPresent(s -> builder.member("mappedBy", s));
    AnnotationValue<Relation> ann = builder.build();
    boolean nullable = annotation.booleanValue("optional").orElse(true);
    if (nullable) {
        return Arrays.asList(
                AnnotationValue.builder("javax.annotation.Nullable").build(),
                ann
        );
    } else {
        return Collections.singletonList(ann);
    }
}
 
Example #15
Source File: ConfigurationPropertiesAnnotationMapper.java    From micronaut-spring with Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    String prefix = annotation.get("prefix", String.class).orElseGet(() -> annotation.getValue(String.class).orElse(null));
    if (prefix != null) {
        prefix = NameUtils.hyphenate(prefix, true);
        return Arrays.asList(
                AnnotationValue.builder(ConfigurationReader.class)
                        .member("prefix", prefix)
                        .build(),
                AnnotationValue.builder(ConfigurationProperties.class)
                        .value(prefix)
                        .build()
        );
    } else {
        return Collections.emptyList();
    }
}
 
Example #16
Source File: AbstractQueryInterceptor.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the root entity or throws an exception if it not available.
 * @param context The context
 * @return The root entity type
 * @throws IllegalStateException If the root entity is unavailable
 */
@NonNull
protected Class<?> getRequiredRootEntity(MethodInvocationContext context) {
    Class aClass = context.classValue(PREDATOR_ANN_NAME, DataMethod.META_MEMBER_ROOT_ENTITY).orElse(null);
    if (aClass != null) {
        return aClass;
    } else {
        final AnnotationValue<Annotation> ann = context.getDeclaredAnnotation(PREDATOR_ANN_NAME);
        if (ann != null) {
            aClass = ann.classValue(DataMethod.META_MEMBER_ROOT_ENTITY).orElse(null);
            if (aClass != null) {
                return aClass;
            }
        }

        throw new IllegalStateException("No root entity present in method");
    }
}
 
Example #17
Source File: WebBindAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>();

    final String name = annotation.getValue(String.class).orElseGet(() -> annotation.get("name", String.class).orElse(null));
    final String defaultValue = annotation.get("defaultValue", String.class).orElse(null);
    final boolean required = annotation.get("required", boolean.class).orElse(true);

    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(annotationType());
    final AnnotationValueBuilder<Bindable> bindableBuilder = AnnotationValue.builder(Bindable.class);
    if (StringUtils.isNotEmpty(name)) {
        builder.value(name);
        bindableBuilder.value(name);
    }
    if (StringUtils.isNotEmpty(defaultValue)) {
        builder.member("defaultValue", name);
        bindableBuilder.member("defaultValue", defaultValue);
    }

    mappedAnnotations.add(builder.build());
    mappedAnnotations.add(bindableBuilder.build());
    if (!required) {
        mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build());
    }

    return mappedAnnotations;
}
 
Example #18
Source File: RequestBodyAnnotationMapping.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> mappedAnnotations = new ArrayList<>();
    final boolean required = annotation.get("required", boolean.class).orElse(true);
    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(Body.class);
    final AnnotationValueBuilder<Bindable> bindableBuilder = AnnotationValue.builder(Bindable.class);
    mappedAnnotations.add(builder.build());
    mappedAnnotations.add(bindableBuilder.build());
    if (!required) {
        mappedAnnotations.add(AnnotationValue.builder(Nullable.class).build());
    }
    return mappedAnnotations;
}
 
Example #19
Source File: MicronautLockConfigurationExtractor.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
Duration getLockAtMostFor(AnnotationValue<SchedulerLock> annotation) {
    return getValue(
        annotation,
        this.defaultLockAtMostFor,
        "lockAtMostFor"
    );
}
 
Example #20
Source File: RequestMappingAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new builder for the given http method.
 * @param httpMethod The method
 * @param annotation The annotation
 * @return The builder
 */
protected @Nonnull AnnotationValueBuilder<?> newBuilder(
        @Nullable HttpMethod httpMethod,
        AnnotationValue<Annotation> annotation) {

    if (httpMethod != null) {
        switch (httpMethod) {
            case TRACE:
                return AnnotationValue.builder(Trace.class);
            case DELETE:
                return AnnotationValue.builder(Delete.class);
            case GET:
                return AnnotationValue.builder(Get.class);
            case HEAD:
                return AnnotationValue.builder(Head.class);
            case POST:
                return AnnotationValue.builder(Post.class);
            case PUT:
                return AnnotationValue.builder(Put.class);
            case PATCH:
                return AnnotationValue.builder(Patch.class);
            case OPTIONS:
                return AnnotationValue.builder(Options.class);
            default:
                return AnnotationValue.builder("io.micronaut.http.annotation.UriMapping");
        }
    } else {
        return AnnotationValue.builder("io.micronaut.http.annotation.UriMapping");
    }
}
 
Example #21
Source File: ResponseStatusAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    try {
        final String code = annotation.getValue(String.class).orElse(annotation.get("code", String.class).orElse(null));
        final HttpStatus status = HttpStatus.valueOf(code);

        return Collections.singletonList(
                AnnotationValue.builder(Status.class).value(status).build()
        );
    } catch (IllegalArgumentException e) {
        // ignore
    }
    return Collections.emptyList();
}
 
Example #22
Source File: ExceptionHandlerAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final AnnotationValueBuilder<Error> builder = AnnotationValue.builder(Error.class);
    annotation.getValue(AnnotationClassValue.class).ifPresent(annotationClassValue -> builder.member("value", annotationClassValue));
    return Collections.singletonList(
            builder
                .build()
    );
}
 
Example #23
Source File: SelectorAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
public List<AnnotationValue<?>> map(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    return Collections.singletonList(
            AnnotationValue.builder("io.micronaut.management.endpoint.annotation.Selector").build()

    );
}
 
Example #24
Source File: ConditionalOnWebApplicationAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    return Collections.singletonList(
            AnnotationValue.builder(Requires.class)
                           .member("beans", new AnnotationClassValue<>(EmbeddedServer.class))
                           .build()
    );
}
 
Example #25
Source File: AbstractQueryInterceptor.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
private boolean isJoinFetch(AnnotationValue<Join> av) {
    if (!av.stringValue().isPresent()) {
        return false;
    }
    Optional<String> type = av.stringValue("type");
    return !type.isPresent() || type.get().contains("FETCH");
}
 
Example #26
Source File: EndpointAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final Optional<String> id = annotation.get("id", String.class);
    if (id.isPresent()) {
        final AnnotationValueBuilder<?> builder = AnnotationValue.builder("io.micronaut.management.endpoint.annotation.Endpoint");
        final Boolean enableByDefault = annotation.get("enableByDefault", boolean.class).orElse(true);
        builder.value(id.get());
        builder.member("id", id.get());
        builder.member("defaultEnabled", enableByDefault);
        return Collections.singletonList(builder.build());
    }

    return Collections.emptyList();
}
 
Example #27
Source File: ReadOperationAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final String[] produces = annotation.get("produces", String[].class).orElse(null);
    final AnnotationValue<?> readOp = AnnotationValue.builder("io.micronaut.management.endpoint.annotation." + operationName()).build();
    List<AnnotationValue<?>> annotationValues = new ArrayList<>(2);

    annotationValues.add(readOp);
    if (produces != null) {
        final AnnotationValue<Produces> producesAnn = AnnotationValue.builder(Produces.class).member("value", produces).build();
        annotationValues.add(producesAnn);
    }
    return annotationValues;
}
 
Example #28
Source File: ValueAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final Optional<String> value = annotation.getValue(String.class);
    if (value.isPresent()) {
        return Collections.singletonList(
                AnnotationValue.builder(Value.class)
                        .value(value.get())
                        .build()
        );
    }
    return Collections.emptyList();
}
 
Example #29
Source File: TableAnnotationMapper.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public List<AnnotationValue<?>> map(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final AnnotationValueBuilder<MappedEntity> builder = AnnotationValue.builder(MappedEntity.class);
    annotation.stringValue("name").ifPresent(builder::value);
    annotation.stringValue(SqlMembers.CATALOG).ifPresent(catalog -> builder.member(SqlMembers.CATALOG, catalog));
    annotation.stringValue(SqlMembers.SCHEMA).ifPresent(catalog -> builder.member(SqlMembers.SCHEMA, catalog));
    return Collections.singletonList(builder.build());
}
 
Example #30
Source File: ConditionalOnNotWebApplicationAnnotationMapper.java    From micronaut-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    return Collections.singletonList(
            AnnotationValue.builder(Requires.class)
                    .member("missingBeans", new AnnotationClassValue<>(EmbeddedServer.class))
                    .build()
    );
}