// Path: src/main/java/com/google/testing/compile/JavaFileObjects.java
// static ByteSource asByteSource(final JavaFileObject javaFileObject) {
//   return new ByteSource() {
//     @Override public InputStream openStream() throws IOException {
//       return javaFileObject.openInputStream();
//     }
//   };
// }


import static com.google.common.base.Preconditions.checkState;
import static com.google.testing.compile.JavaFileObjects.asByteSource;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;
import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.MANDATORY_WARNING;
import static javax.tools.Diagnostic.Kind.NOTE;
import static javax.tools.Diagnostic.Kind.WARNING;
import static javax.tools.JavaFileObject.Kind.CLASS;
import static javax.tools.StandardLocation.SOURCE_OUTPUT;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.util.Optional;
import java.util.stream.Collector;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;
    StringBuilder message = new StringBuilder("Compilation produced the following diagnostics:\n");
    diagnostics.forEach(diagnostic -> message.append(diagnostic).append('\n'));
    return message.toString();
  }

  /** Returns a description of the source file generated by this compilation. */
  String describeGeneratedSourceFiles() {
    ImmutableList<JavaFileObject> generatedSourceFiles =
        generatedFiles
            .stream()
            .filter(generatedFile -> generatedFile.getKind().equals(JavaFileObject.Kind.SOURCE))
            .collect(toImmutableList());
    if (generatedSourceFiles.isEmpty()) {
      return "No files were generated.\n";
    } else {
      StringBuilder message = new StringBuilder("Generated Source Files\n======================\n");
      for (JavaFileObject generatedFile : generatedSourceFiles) {
        message.append(describeGeneratedFile(generatedFile));
      }
      return message.toString();
    }
  }

  /** Returns a description of the contents of a given generated file. */
  private String describeGeneratedFile(JavaFileObject generatedFile) {
    try {
      StringBuilder entry = new StringBuilder("\n").append(generatedFile.getName()).append(":\n");
      if (generatedFile.getKind().equals(CLASS)) {
        entry.append(
            String.format(
// Path: src/main/java/com/google/testing/compile/JavaFileObjects.java
// static ByteSource asByteSource(final JavaFileObject javaFileObject) {
//   return new ByteSource() {
//     @Override public InputStream openStream() throws IOException {
//       return javaFileObject.openInputStream();
//     }
//   };
// }


// Path: src/main/java/com/google/testing/compile/Compilation.java
import static com.google.common.base.Preconditions.checkState;
import static com.google.testing.compile.JavaFileObjects.asByteSource;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;
import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.MANDATORY_WARNING;
import static javax.tools.Diagnostic.Kind.NOTE;
import static javax.tools.Diagnostic.Kind.WARNING;
import static javax.tools.JavaFileObject.Kind.CLASS;
import static javax.tools.StandardLocation.SOURCE_OUTPUT;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.util.Optional;
import java.util.stream.Collector;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;

    StringBuilder message = new StringBuilder("Compilation produced the following diagnostics:\n");
    diagnostics.forEach(diagnostic -> message.append(diagnostic).append('\n'));
    return message.toString();
  }

  /** Returns a description of the source file generated by this compilation. */
  String describeGeneratedSourceFiles() {
    ImmutableList<JavaFileObject> generatedSourceFiles =
        generatedFiles
            .stream()
            .filter(generatedFile -> generatedFile.getKind().equals(JavaFileObject.Kind.SOURCE))
            .collect(toImmutableList());
    if (generatedSourceFiles.isEmpty()) {
      return "No files were generated.\n";
    } else {
      StringBuilder message = new StringBuilder("Generated Source Files\n======================\n");
      for (JavaFileObject generatedFile : generatedSourceFiles) {
        message.append(describeGeneratedFile(generatedFile));
      }
      return message.toString();
    }
  }

  /** Returns a description of the contents of a given generated file. */
  private String describeGeneratedFile(JavaFileObject generatedFile) {
    try {
      StringBuilder entry = new StringBuilder("\n").append(generatedFile.getName()).append(":\n");
      if (generatedFile.getKind().equals(CLASS)) {
        entry.append(
            String.format(
                "  [generated class file (%d bytes)]", asByteSource(generatedFile).size()));