protected final ProcessingEnvironment processing() { return StaticEnvironment.processing(); }
protected final ProcessingEnvironment processing() { return StaticEnvironment.processing(); }
private static Filer getFiler() { return StaticEnvironment.processing().getFiler(); }
private static Messager getMessager() { return StaticEnvironment.processing().getMessager(); }
private TypeElement loadTypeElement(String input) { try { return StaticEnvironment.processing() .getElementUtils() .getTypeElement(input); } catch (Exception ex) { // if type element cannot be loaded for some reason return null; } }
void complete() { try { writeFile(); } catch (Exception ex) { StaticEnvironment.processing().getMessager().printMessage( Diagnostic.Kind.MANDATORY_WARNING, "Cannot write service files: " + key + ex.toString()); } }
@Override public String apply(Object input) { return StaticEnvironment.processing().getElementUtils().getConstantExpression(input); }
@Override public ImmutableSet<String> get() { List<String> extensions = Lists.newArrayList(); // best effort to read it from compilation classpath if (StaticEnvironment.isInitialized()) { try { String lines = getClasspathResourceText( StaticEnvironment.processing().getFiler(), resource); extensions.addAll(RESOURCE_SPLITTER.splitToList(lines)); } catch (RuntimeException | IOException cannotReadCompilationClasspath) { // we ignore this as we did or best effort // and there are no plans to halt whole compilation } } ClassLoader classLoader = ExtensionLoader.class.getClassLoader(); try { Enumeration<URL> resources = classLoader.getResources(resource); while (resources.hasMoreElements()) { URL nextElement = resources.nextElement(); String lines = Resources.toString(nextElement, StandardCharsets.UTF_8); extensions.addAll(RESOURCE_SPLITTER.splitToList(lines)); } } catch (RuntimeException | IOException cannotReadAnnotationProcessingClasspath) { // we ignore this as we did or best effort // and there are no plans to halt whole compilation } return FluentIterable.from(extensions).toSet(); } });
public boolean isJava8() { SourceVersion sourceVersion = StaticEnvironment.processing().getSourceVersion(); return sourceVersion.compareTo(SourceVersion.RELEASE_7) > 0; }
@Override @Nullable public Invokable invoke(Invokation invokation, Object... parameters) { Messager messager = StaticEnvironment.processing().getMessager(); String message = CharMatcher.whitespace().trimFrom(parameters[parameters.length - 1].toString()); Element element = (Element) Iterators.find( Iterators.forArray(parameters), Predicates.instanceOf(Element.class), null); if (element != null) { messager.printMessage(Diagnostic.Kind.ERROR, message, element); } else { messager.printMessage(Diagnostic.Kind.ERROR, message); } return null; } };