br.com.objectos.code.PackageInfoPackageElement 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.Stream;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import br.com.objectos.core.util.ImmutableList;
import br.com.objectos.lazy.Lazy;
/**
* @author [email protected] (Marcio Endo)
*/
class PackageInfoPackageElement extends PackageInfo {
private static final PackageInfo NULL = new Null();
private final ProcessingEnvironmentWrapper processingEnv;
private final PackageElement element;
private final Lazy> annotationInfoList = new LazyAnnotationInfoList();
private PackageInfoPackageElement(ProcessingEnvironmentWrapper processingEnv, PackageElement element) {
this.processingEnv = processingEnv;
this.element = element;
}
public static PackageInfo wrap(ProcessingEnvironmentWrapper processingEnv, PackageElement element) {
return element == null
? NULL
: new PackageInfoPackageElement(processingEnv, element);
}
@Override
public List annotationInfoList() {
return annotationInfoList.get();
}
@Override
public Stream declaredTypeInfoStream() {
return element.getEnclosedElements()
.stream()
.filter(el -> Util.isTypeInfoKind(el))
.map(TypeElement.class::cast)
.map(el -> TypeInfoTypeElement.wrap(processingEnv, el));
}
@Override
public PackageInfo parentPackageInfo() {
PackageElement element = processingEnv.getPackageElement(parentName());
return new PackageInfoPackageElement(processingEnv, element);
}
@Override
String name() {
return element.getQualifiedName().toString();
}
private class LazyAnnotationInfoList extends Lazy> {
@Override
protected List compute() {
return AnnotationMirrorWrapper.wrapAllAndList(processingEnv, element);
}
}
private static class Null extends PackageInfo {
@Override
public List annotationInfoList() {
return ImmutableList.of();
}
@Override
public Stream declaredTypeInfoStream() {
return Stream.of();
}
@Override
String name() {
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy