net.jbock.common.SafeElements Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbock-compiler Show documentation
Show all versions of jbock-compiler Show documentation
jbock annotation processor
package net.jbock.common;
import io.jbock.simple.Inject;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import java.util.Optional;
/**
* A wrapper around {@link Elements} where none of the methods can return {@code null}.
*/
public class SafeElements {
private final Elements elements;
@Inject
public SafeElements(ProcessingEnvironment processingEnvironment) {
this.elements = processingEnvironment.getElementUtils();
}
public Optional getTypeElement(String name) {
return Optional.ofNullable(elements.getTypeElement(name));
}
}