br.com.objectos.code.AnnotationMirrorWrapper Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.code;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
/**
* @author [email protected] (Marcio Endo)
*/
class AnnotationMirrorWrapper {
private final ProcessingEnvironmentWrapper processingEnv;
private final AnnotationMirror annotation;
public AnnotationMirrorWrapper(ProcessingEnvironmentWrapper processingEnv, AnnotationMirror annotation) {
this.processingEnv = processingEnv;
this.annotation = annotation;
}
public static Stream wrapAll(ProcessingEnvironmentWrapper processingEnv, Element element) {
return element.getAnnotationMirrors()
.stream()
.map(annotation -> {
DeclaredType type = annotation.getAnnotationType();
if (TypeKind.ERROR.equals(type.getKind())) {
throw new CodeGenerationIncompleteException();
}
return annotation;
})
.map(mirror -> AnnotationMirrorWrapper.wrapperOf(processingEnv, mirror));
}
public static List wrapAllAndList(ProcessingEnvironmentWrapper processingEnv, Element element) {
return wrapAll(processingEnv, element)
.map(AnnotationMirrorWrapper::toAnnotationInfo)
.collect(Collectors.toList());
}
public static AnnotationMirrorWrapper wrapperOf(
ProcessingEnvironmentWrapper processingEnv, AnnotationMirror annotation) {
return new AnnotationMirrorWrapper(processingEnv, annotation);
}
AnnotationInfo toAnnotationInfo() {
DeclaredType annotationType = annotation.getAnnotationType();
Element element = annotationType.asElement();
return new AnnotationInfoAnnotationMirror(
processingEnv,
annotation,
packageInfo(element),
accessInfo(element),
name(element));
}
private AccessInfo accessInfo(Element element) {
return Apt.accessInfoOf(element);
}
private PackageInfo packageInfo(Element element) {
return Apt.packageInfoOf(processingEnv, element);
}
private String name(Element element) {
return element.getSimpleName().toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy