protected final Set<TypeElement> annotations() { return StaticEnvironment.annotations(); } }
private static Files getFiles() { return StaticEnvironment.getInstance(Files.class, FilesSupplier.INSTANCE); }
protected final ProcessingEnvironment processing() { return StaticEnvironment.processing(); }
@Override public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) { try { StaticEnvironment.init(annotations, round, processingEnv); if (!round.processingOver() && !round.errorRaised()) { process(); } StaticEnvironment.shutdown(); } catch (Exception ex) { processingEnv.getMessager() .printMessage(Diagnostic.Kind.ERROR, getClass().getName() + " threw " + Throwables.getStackTraceAsString(ex)); } return false; } }
@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(); } });
static ProcessingEnvironment processing() { return state().processing; }
protected final RoundEnvironment round() { return StaticEnvironment.round(); }
static RoundEnvironment round() { return state().round; }
protected final RoundEnvironment round() { return StaticEnvironment.round(); }
protected final ProcessingEnvironment processing() { return StaticEnvironment.processing(); }
static Set<TypeElement> annotations() { return state().annotations; }
protected final Set<TypeElement> annotations() { return StaticEnvironment.annotations(); }
private static Filer getFiler() { return StaticEnvironment.processing().getFiler(); }
static void shutdown() throws Exception { state().shutdown(); }
private static Messager getMessager() { return StaticEnvironment.processing().getMessager(); }
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) { ClassToInstanceMap<Completable> components = state().components; @Nullable T instance = components.getInstance(type); if (instance == null) { instance = supplier.get(); components.putInstance(type, instance); } return instance; }
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); }
public boolean isJava8() { SourceVersion sourceVersion = StaticEnvironment.processing().getSourceVersion(); return sourceVersion.compareTo(SourceVersion.RELEASE_7) > 0; }