
br.com.objectos.way.code.AnnotationInfoAnnotationMirror Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2015 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.way.code;
import java.util.List;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import br.com.objectos.way.core.auto.AutoPojo;
import br.com.objectos.way.core.lang.Lazy;
import com.google.common.base.Function;
import com.google.common.base.Optional;
/**
* @author [email protected] (Marcio Endo)
*/
@AutoPojo
abstract class AnnotationInfoAnnotationMirror extends AnnotationInfo {
abstract ProcessingEnvironmentWrapper processingEnv();
abstract AnnotationMirror annotation();
@Override
abstract PackageInfo packageInfo();
@Override
abstract AccessInfo accessInfo();
@Override
abstract String name();
private final Lazy annotationValueInfoMap = new LazyAnnotationValueInfoMap();
private final Lazy> enclosingTypeInfo = new LazyEnclosingTypeInfo();
private final Lazy annotationInfoMap = new LazyAnnotationInfoMap();
AnnotationInfoAnnotationMirror() {
}
public static AnnotationInfoAnnotationMirrorBuilder builder() {
return new AnnotationInfoAnnotationMirrorBuilderPojo();
}
@Override
AnnotationValueInfoMap annotationValueInfoMap() {
return annotationValueInfoMap.get();
}
@Override
Optional enclosingTypeInfo() {
return enclosingTypeInfo.get();
}
@Override
public AnnotationInfoMap annotationInfoMap() {
return annotationInfoMap.get();
}
private Element element() {
DeclaredType annotationType = annotation().getAnnotationType();
return annotationType.asElement();
}
private class LazyAnnotationValueInfoMap extends Lazy {
@Override
protected AnnotationValueInfoMap compute() {
return AnnotationValueWrapper.wrapAll(processingEnv(), annotation())
.transform(AnnotationValueWrapperToAnnotationValueInfo.get())
.asMap(new Function, AnnotationValueInfoMap>() {
@Override
public AnnotationValueInfoMap apply(List input) {
return AnnotationValueInfoMap.mapOf(input);
}
});
}
}
private class LazyEnclosingTypeInfo extends Lazy> {
@Override
protected Optional compute() {
Optional res = Optional.absent();
Element enclosingElement = element().getEnclosingElement();
if (Apt.isType(enclosingElement)) {
TypeElement typeElement = TypeElement.class.cast(enclosingElement);
SimpleTypeInfo simpleTypeInfo = SimpleTypeInfoTypeElement.wrap(processingEnv(), typeElement);
res = Optional.of(simpleTypeInfo);
}
return res;
}
}
private class LazyAnnotationInfoMap extends Lazy {
@Override
protected AnnotationInfoMap compute() {
AnnotationInfoMap map = AnnotationInfoMap.emptyMap();
if (!packageInfo().isJavaLang() && !packageInfo().hasName("java.lang.annotation")) {
map = AnnotationMirrorWrapper.wrapAllAndMap(processingEnv(), element());
}
return map;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy