Example usage for javax.lang.model.element TypeElement getAnnotationsByType

List of usage examples for javax.lang.model.element TypeElement getAnnotationsByType

Introduction

In this page you can find the example usage for javax.lang.model.element TypeElement getAnnotationsByType.

Prototype

<A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType);

Source Link

Document

Returns annotations that are associated with this construct.

Usage

From source file:org.lambdamatic.mongodb.apt.template.MetadataTemplateContext.java

/**
 * Full constructor/*from w ww. j  a v a  2s . co  m*/
 * 
 * @param domainElement the {@link TypeElement} to work on.
 * @param templateFieldBuildFunction the {@link Function} used to generate a single
 *        {@link TemplateField} from a given relevant {@link VariableElement} in the given
 *        {@link TypeElement}.
 * @param templateMethodsBuildFunction the {@link Function} used to generate zero or more
 *        {@link TemplateMethods} from a given relevant {@link VariableElement} in the given
 *        {@link TypeElement}.
 * 
 */
private MetadataTemplateContext(final TypeElement domainElement,
        final BaseAnnotationProcessor annotationProcessor,
        final BiFunction<VariableElement, ProcessingEnvironment, TemplateField> templateFieldBuildFunction,
        final Function<DeclaredType, String> simpleClassNameBuilder, final String templateFileName) {
    super((DeclaredType) domainElement.asType(), annotationProcessor);
    this.domainTypeFields = domainElement.getEnclosedElements().stream()
            .filter(e -> e.getKind() == ElementKind.FIELD)
            .filter(e -> e.getAnnotation(TransientField.class) == null).map(e -> (VariableElement) e)
            .collect(Collectors.toList());
    this.templateFields = this.domainTypeFields.stream().map(f -> {
        return templateFieldBuildFunction.apply(f, annotationProcessor.getProcessingEnvironment());
    }).collect(Collectors.toList());
    this.simpleClassName = simpleClassNameBuilder.apply(this.domainType);
    this.fullyQualifiedClassName = getPackageName() + '.' + this.simpleClassName;
    this.templateFileName = templateFileName;
    this.annotations = Stream.of(domainElement.getAnnotationsByType(EmbeddedDocument.class))
            .map(a -> TemplateAnnotation.Builder.type(EmbeddedDocument.class).build())
            .collect(Collectors.toList());
}