/** Returns a description of the why the compilation failed. */ String describeFailureDiagnostics() { ImmutableList<Diagnostic<? extends JavaFileObject>> diagnostics = diagnostics(); if (diagnostics.isEmpty()) { return "Compilation produced no diagnostics.\n"; } StringBuilder message = new StringBuilder("Compilation produced the following diagnostics:\n"); diagnostics.forEach(diagnostic -> message.append(diagnostic).append('\n')); return message.toString(); }
ImmutableList<Diagnostic<? extends JavaFileObject>> diagnosticsOfKind(Kind kind, Kind... more) { ImmutableSet<Kind> kinds = Sets.immutableEnumSet(kind, more); return diagnostics() .stream() .filter(diagnostic -> kinds.contains(diagnostic.getKind())) .collect(toImmutableList()); }
ImmutableList<Diagnostic<? extends JavaFileObject>> diagnosticsOfKind(Kind kind, Kind... more) { ImmutableSet<Kind> kinds = Sets.immutableEnumSet(kind, more); return diagnostics() .stream() .filter(diagnostic -> kinds.contains(diagnostic.getKind())) .collect(toImmutableList()); }
public static List<Diagnostic<? extends JavaFileObject>> getActualDiagnostics(Compiler compiler, Class<?> clazz) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { List<? extends Processor> processors = createProcessors(clazz); if (processors.isEmpty()) { throw new IllegalArgumentException( "Did you forget to annotate " + clazz.getSimpleName() + " with @UseProcessor?"); } Compilation compilation = compiler.withProcessors(processors).compile(getSourceFile(clazz)); List<Diagnostic<? extends JavaFileObject>> diagnostics = new ArrayList<>(compilation.diagnostics()); diagnostics.sort(ACTUAL_DIAGNOSTIC_LINE_ORDER); return diagnostics; } }
public List<ExpectedDiagnostic<?>> getExpectedDiagnostics(Compilation compilation) { List<ExpectedDiagnostic<?>> expectations = new ArrayList<>(); List<Diagnostic<? extends JavaFileObject>> diagnostics = new ArrayList<>(compilation.diagnostics()); diagnostics.sort(ActualDiagnostics.ACTUAL_DIAGNOSTIC_LINE_ORDER);