// 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/TreeDiffer.java
// static TreeDifference diffCompilationUnits(
//     CompilationUnitTree expected, CompilationUnitTree actual) {
//   return createDiff(checkNotNull(expected), checkNotNull(actual), TreeFilter.KEEP_ALL);
// }
// 
// Path: src/main/java/com/google/testing/compile/TreeDiffer.java
// static TreeDifference matchCompilationUnits(
//     CompilationUnitTree pattern,
//     Trees patternTrees,
//     CompilationUnitTree actual,
//     Trees actualTrees) {
//   checkNotNull(pattern);
//   checkNotNull(actual);
//   return createDiff(
//       pattern, actual, new MatchExpectedTreesFilter(pattern, patternTrees, actual, actualTrees));
// }
// 
// Path: src/main/java/com/google/testing/compile/Parser.java
// static final class ParseResult {
//   private final ImmutableListMultimap<Diagnostic.Kind, Diagnostic<? extends JavaFileObject>>
//       diagnostics;
//   private final ImmutableList<? extends CompilationUnitTree> compilationUnits;
//   private final Trees trees;
// 
//   ParseResult(
//       ImmutableListMultimap<Diagnostic.Kind, Diagnostic<? extends JavaFileObject>> diagnostics,
//       Iterable<? extends CompilationUnitTree> compilationUnits,
//       Trees trees) {
//     this.trees = trees;
//     this.compilationUnits = ImmutableList.copyOf(compilationUnits);
//     this.diagnostics = diagnostics;
//   }
// 
//   ImmutableListMultimap<Diagnostic.Kind, Diagnostic<? extends JavaFileObject>>
//       diagnosticsByKind() {
//     return diagnostics;
//   }
// 
//   ImmutableList<? extends CompilationUnitTree> compilationUnits() {
//     return compilationUnits;
//   }
// 
//   Trees trees() {
//     return trees;
//   }
// }


import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Fact.fact;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaFileObjects.asByteSource;
import static com.google.testing.compile.TreeDiffer.diffCompilationUnits;
import static com.google.testing.compile.TreeDiffer.matchCompilationUnits;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteSource;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.testing.compile.Parser.ParseResult;
import com.sun.source.tree.CompilationUnitTree;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.function.BiFunction;
import javax.tools.JavaFileObject;
import org.checkerframework.checker.nullness.qual.Nullable;
/*
 * Copyright (C) 2016 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.testing.compile;



/** Assertions about {@link JavaFileObject}s. */
public final class JavaFileObjectSubject extends Subject {

  private static final Subject.Factory<JavaFileObjectSubject, JavaFileObject> FACTORY =
      new JavaFileObjectSubjectFactory();

  /** Returns a {@link Subject.Factory} for {@link JavaFileObjectSubject}s. */
  public static Subject.Factory<JavaFileObjectSubject, JavaFileObject> javaFileObjects() {
    return FACTORY;
  }

  /** Starts making assertions about a {@link JavaFileObject}. */
  public static JavaFileObjectSubject assertThat(JavaFileObject actual) {
    return assertAbout(FACTORY).that(actual);
  }

  private final JavaFileObject actual;

  JavaFileObjectSubject(FailureMetadata failureMetadata, JavaFileObject actual) {
    super(failureMetadata, actual);
    this.actual = actual;
  }

  @Override
  protected String actualCustomStringRepresentation() {
    return actual.toUri().getPath();
  }

  /**
   * If {@code other} is a {@link JavaFileObject}, tests that their contents are equal. Otherwise
   * uses {@link Object#equals(Object)}.
   */
  @Override
  public void isEqualTo(@Nullable Object other) {
    if (!(other instanceof JavaFileObject)) {
      super.isEqualTo(other);
      return;
    }

    JavaFileObject otherFile = (JavaFileObject) other;
    try {
// 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/TreeDiffer.java
// static TreeDifference diffCompilationUnits(
//     CompilationUnitTree expected, CompilationUnitTree actual) {
//   return createDiff(checkNotNull(expected), checkNotNull(actual), TreeFilter.KEEP_ALL);
// }
// 
// Path: src/main/java/com/google/testing/compile/TreeDiffer.java
// static TreeDifference matchCompilationUnits(
//     CompilationUnitTree pattern,
//     Trees patternTrees,
//     CompilationUnitTree actual,
//     Trees actualTrees) {
//   checkNotNull(pattern);
//   checkNotNull(actual);
//   return createDiff(
//       pattern, actual, new MatchExpectedTreesFilter(pattern, patternTrees, actual, actualTrees));
// }
// 
// Path: src/main/java/com/google/testing/compile/Parser.java
// static final class ParseResult {
//   private final ImmutableListMultimap<Diagnostic.Kind, Diagnostic<? extends JavaFileObject>>
//       diagnostics;
//   private final ImmutableList<? extends CompilationUnitTree> compilationUnits;
//   private final Trees trees;
// 
//   ParseResult(
//       ImmutableListMultimap<Diagnostic.Kind, Diagnostic<? extends JavaFileObject>> diagnostics,
//       Iterable<? extends CompilationUnitTree> compilationUnits,
//       Trees trees) {
//     this.trees = trees;
//     this.compilationUnits = ImmutableList.copyOf(compilationUnits);
//     this.diagnostics = diagnostics;
//   }
// 
//   ImmutableListMultimap<Diagnostic.Kind, Diagnostic<? extends JavaFileObject>>
//       diagnosticsByKind() {
//     return diagnostics;
//   }
// 
//   ImmutableList<? extends CompilationUnitTree> compilationUnits() {
//     return compilationUnits;
//   }
// 
//   Trees trees() {
//     return trees;
//   }
// }


// Path: src/main/java/com/google/testing/compile/JavaFileObjectSubject.java
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Fact.fact;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.testing.compile.JavaFileObjects.asByteSource;
import static com.google.testing.compile.TreeDiffer.diffCompilationUnits;
import static com.google.testing.compile.TreeDiffer.matchCompilationUnits;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteSource;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import com.google.testing.compile.Parser.ParseResult;
import com.sun.source.tree.CompilationUnitTree;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.function.BiFunction;
import javax.tools.JavaFileObject;
import org.checkerframework.checker.nullness.qual.Nullable;

/*
 * Copyright (C) 2016 Google, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.testing.compile;



/** Assertions about {@link JavaFileObject}s. */
public final class JavaFileObjectSubject extends Subject {

  private static final Subject.Factory<JavaFileObjectSubject, JavaFileObject> FACTORY =
      new JavaFileObjectSubjectFactory();

  /** Returns a {@link Subject.Factory} for {@link JavaFileObjectSubject}s. */
  public static Subject.Factory<JavaFileObjectSubject, JavaFileObject> javaFileObjects() {
    return FACTORY;
  }

  /** Starts making assertions about a {@link JavaFileObject}. */
  public static JavaFileObjectSubject assertThat(JavaFileObject actual) {
    return assertAbout(FACTORY).that(actual);
  }

  private final JavaFileObject actual;

  JavaFileObjectSubject(FailureMetadata failureMetadata, JavaFileObject actual) {
    super(failureMetadata, actual);
    this.actual = actual;
  }

  @Override
  protected String actualCustomStringRepresentation() {
    return actual.toUri().getPath();
  }

  /**
   * If {@code other} is a {@link JavaFileObject}, tests that their contents are equal. Otherwise
   * uses {@link Object#equals(Object)}.
   */
  @Override
  public void isEqualTo(@Nullable Object other) {
    if (!(other instanceof JavaFileObject)) {
      super.isEqualTo(other);
      return;
    }

    JavaFileObject otherFile = (JavaFileObject) other;
    try {
      if (!asByteSource(actual).contentEquals(asByteSource(otherFile))) {