Repository: kythe/kythe
Pull request #4753 (2020-11-12 20:45:06)

build: add more ErrorProne checks


Patch:
diff --git a/kythe/java/com/google/devtools/kythe/analyzers/base/KytheEntrySets.java b/kythe/java/com/google/devtools/kythe/analyzers/base/KytheEntrySets.java
index acb65ca51..0ac320c95 100644
--- a/kythe/java/com/google/devtools/kythe/analyzers/base/KytheEntrySets.java
+++ b/kythe/java/com/google/devtools/kythe/analyzers/base/KytheEntrySets.java
@@ -88,6 +88,18 @@ public class KytheEntrySets {
     return statistics;
   }
 
+  /**
+   * Returns a {@link NodeBuilder} with the given kind and added signature salts for each {@link
+   * EntrySet} dependency.
+   */
+  public NodeBuilder newNode(NodeKind kind, Iterable<VName> dependencies) {
+    NodeBuilder builder = newNode(kind);
+    for (VName d : dependencies) {
+      builder.addSignatureSalt(d);
+    }
+    return builder;
+  }
+
   /**
    * Returns a new {@link NodeBuilder} with the given node kind set.
    *
@@ -243,18 +255,6 @@ public class KytheEntrySets {
             .setProperty("text/encoding", encoding.name()));
   }
 
-  /**
-   * Returns a {@link NodeBuilder} with the given kind and added signature salts for each {@link
-   * EntrySet} dependency.
-   */
-  public NodeBuilder newNode(NodeKind kind, Iterable<VName> dependencies) {
-    NodeBuilder builder = newNode(kind);
-    for (VName d : dependencies) {
-      builder.addSignatureSalt(d);
-    }
-    return builder;
-  }
-
   /** Emits an edge of the given kind from {@code source} to {@code target}. */
   public void emitEdge(EntrySet source, EdgeKind kind, EntrySet target) {
     Preconditions.checkNotNull(source, "source EntrySet must be non-null");
diff --git a/kythe/java/com/google/devtools/kythe/analyzers/java/JavaEntrySets.java b/kythe/java/com/google/devtools/kythe/analyzers/java/JavaEntrySets.java
index d00eb1914..a2cba04c8 100644
--- a/kythe/java/com/google/devtools/kythe/analyzers/java/JavaEntrySets.java
+++ b/kythe/java/com/google/devtools/kythe/analyzers/java/JavaEntrySets.java
@@ -75,6 +75,10 @@ public class JavaEntrySets extends KytheEntrySets {
     this.config = config;
   }
 
+  Map<Symbol, VName> getSymbolNodes() {
+    return Collections.unmodifiableMap(symbolNodes);
+  }
+
   /**
    * Returns a node for the given {@link Symbol} and its signature. A new node is created and
    * emitted if necessary. If non-null, msBuilder will be used to generate a signature.
@@ -103,10 +107,6 @@ public class JavaEntrySets extends KytheEntrySets {
                     .map(sig -> getNode(signatureGenerator, s, sig, null, null))));
   }
 
-  Map<Symbol, VName> getSymbolNodes() {
-    return Collections.unmodifiableMap(symbolNodes);
-  }
-
   /**
    * Returns a node for the given {@link Symbol} and its signature. A new node is created and
    * emitted if necessary.
diff --git a/kythe/java/com/google/devtools/kythe/extractors/java/SystemExploder.java b/kythe/java/com/google/devtools/kythe/extractors/java/SystemExploder.java
index ad295ce2f..d8b50b8a6 100644
--- a/kythe/java/com/google/devtools/kythe/extractors/java/SystemExploder.java
+++ b/kythe/java/com/google/devtools/kythe/extractors/java/SystemExploder.java
@@ -47,15 +47,6 @@ final class SystemExploder {
     copySystemModules(systemDir, Paths.get(outputDir));
   }
 
-  // Returns a stream of paths from the specified --system directory, beginning with the appropriate
-  // modules subdirectory.
-  public static ImmutableList<Path> walkSystemModules(String systemDir) throws IOException {
-    StandardJavaFileManager fileManager =
-        ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
-    fileManager.handleOption("--system", Iterators.singletonIterator(systemDir));
-    return walkSystemModules(wrap(fileManager));
-  }
-
   // In order to work around the lack of the required JDK9 methods in google3, wrap
   // StandardJavaFileManagers before use (for now).
   private static ForwardingStandardJavaFileManager wrap(StandardJavaFileManager fileManager) {
@@ -65,6 +56,15 @@ final class SystemExploder {
     return new ForwardingStandardJavaFileManager(fileManager) {};
   }
 
+  // Returns a stream of paths from the specified --system directory, beginning with the appropriate
+  // modules subdirectory.
+  public static ImmutableList<Path> walkSystemModules(String systemDir) throws IOException {
+    StandardJavaFileManager fileManager =
+        ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
+    fileManager.handleOption("--system", Iterators.singletonIterator(systemDir));
+    return walkSystemModules(wrap(fileManager));
+  }
+
   private static ImmutableList<Path> walkSystemModules(
       ForwardingStandardJavaFileManager fileManager) throws IOException {
     JavaFileManager.Location systemLocation = StandardLocation.valueOf("SYSTEM_MODULES");
diff --git a/kythe/java/com/google/devtools/kythe/extractors/shared/ExtractorUtils.java b/kythe/java/com/google/devtools/kythe/extractors/shared/ExtractorUtils.java
index 9a4005fd2..45f883b06 100644
--- a/kythe/java/com/google/devtools/kythe/extractors/shared/ExtractorUtils.java
+++ b/kythe/java/com/google/devtools/kythe/extractors/shared/ExtractorUtils.java
@@ -81,6 +81,13 @@ public class ExtractorUtils {
     return createFileData(path, getContentDigest(content), content);
   }
 
+  private static FileData createFileData(String path, String digest, byte[] content) {
+    return FileData.newBuilder()
+        .setContent(ByteString.copyFrom(content))
+        .setInfo(FileInfo.newBuilder().setDigest(digest).setPath(path))
+        .build();
+  }
+
   public static List<FileData> processRequiredInputs(Iterable<String> files)
       throws ExtractionException {
     final SettableFuture<ExtractionException> exception = SettableFuture.create();
@@ -117,14 +124,14 @@ public class ExtractorUtils {
     return result;
   }
 
-  public static ImmutableList<FileInput> toFileInputs(Iterable<FileData> fileDatas) {
-    return toFileInputs(FileVNames.staticCorpus(""), p -> p, fileDatas);
-  }
-
   public static Function<String, String> makeRelativizer(final Path rootDir) {
     return p -> tryMakeRelative(rootDir, Paths.get(p));
   }
 
+  public static ImmutableList<FileInput> toFileInputs(Iterable<FileData> fileDatas) {
+    return toFileInputs(FileVNames.staticCorpus(""), p -> p, fileDatas);
+  }
+
   public static ImmutableList<FileInput> toFileInputs(
       FileVNames fileVNames, Function<String, String> relativize, Iterable<FileData> fileDatas) {
     return Streams.stream(fileDatas)
@@ -190,11 +197,4 @@ public class ExtractorUtils {
     existingCompilationUnit = builder.build();
     return existingCompilationUnit;
   }
-
-  private static FileData createFileData(String path, String digest, byte[] content) {
-    return FileData.newBuilder()
-        .setContent(ByteString.copyFrom(content))
-        .setInfo(FileInfo.newBuilder().setDigest(digest).setPath(path))
-        .build();
-  }
 }
diff --git a/kythe/java/com/google/devtools/kythe/platform/java/filemanager/CompilationUnitBasedJavaFileStore.java b/kythe/java/com/google/devtools/kythe/platform/java/filemanager/CompilationUnitBasedJavaFileStore.java
index 8aacb8b3c..841115fb0 100644
--- a/kythe/java/com/google/devtools/kythe/platform/java/filemanager/CompilationUnitBasedJavaFileStore.java
+++ b/kythe/java/com/google/devtools/kythe/platform/java/filemanager/CompilationUnitBasedJavaFileStore.java
@@ -40,6 +40,15 @@ public class CompilationUnitBasedJavaFileStore implements JavaFileStore {
     fileTree = new CompilationUnitFileTree(unit.getRequiredInputList());
   }
 
+  @Override
+  public CustomJavaFileObject findByPath(String path, Kind kind) {
+    String digest = fileTree.lookup(path);
+    if (digest != null) {
+      return new CustomJavaFileObject(contentProvider, path, digest, null, kind, encoding);
+    }
+    return null;
+  }
+
   @Override
   public CustomJavaFileObject find(String className, Kind kind, Set<String> pathPrefixes) {
     Path file = Paths.get(className.replace('.', '/') + kind.extension);
@@ -56,15 +65,6 @@ public class CompilationUnitBasedJavaFileStore implements JavaFileStore {
     return null;
   }
 
-  @Override
-  public CustomJavaFileObject findByPath(String path, Kind kind) {
-    String digest = fileTree.lookup(path);
-    if (digest != null) {
-      return new CustomJavaFileObject(contentProvider, path, digest, null, kind, encoding);
-    }
-    return null;
-  }
-
   @Override
   public CustomFileObject find(String packageName, String relativeName, Set<String> pathPrefixes) {
     String packagePath = packageName.replace('.', '/');
diff --git a/kythe/java/com/google/devtools/kythe/platform/java/filemanager/JavaFileStoreBasedFileManager.java b/kythe/java/com/google/devtools/kythe/platform/java/filemanager/JavaFileStoreBasedFileManager.java
index 4f5cf52ca..d68a7272f 100644
--- a/kythe/java/com/google/devtools/kythe/platform/java/filemanager/JavaFileStoreBasedFileManager.java
+++ b/kythe/java/com/google/devtools/kythe/platform/java/filemanager/JavaFileStoreBasedFileManager.java
@@ -152,11 +152,6 @@ public class JavaFileStoreBasedFileManager extends ForwardingStandardJavaFileMan
     return javaFileObjects;
   }
 
-  @Override
-  public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
-    return getJavaFileObjectsFromFiles(Arrays.asList(files));
-  }
-
   @Override
   public FileObject getFileForInput(Location location, String packageName, String relativeName)
       throws IOException {
@@ -172,15 +167,20 @@ public class JavaFileStoreBasedFileManager extends ForwardingStandardJavaFileMan
     return getJavaFileObjectsFromFiles(Iterables.transform(names, File::new));
   }
 
+  @Override
+  public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
+      @SuppressWarnings("IterablePathParameter") Iterable<? extends Path> paths) {
+    return getJavaFileObjectsFromFiles(Iterables.transform(paths, Path::toFile));
+  }
+
   @Override
   public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
     return getJavaFileObjectsFromStrings(Arrays.asList(names));
   }
 
   @Override
-  public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
-      @SuppressWarnings("IterablePathParameter") Iterable<? extends Path> paths) {
-    return getJavaFileObjectsFromFiles(Iterables.transform(paths, Path::toFile));
+  public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
+    return getJavaFileObjectsFromFiles(Arrays.asList(files));
   }
 
   @Override
diff --git a/kythe/java/com/google/devtools/kythe/platform/java/helpers/JCTreeScanner.java b/kythe/java/com/google/devtools/kythe/platform/java/helpers/JCTreeScanner.java
index 05405954e..e27a10406 100644
--- a/kythe/java/com/google/devtools/kythe/platform/java/helpers/JCTreeScanner.java
+++ b/kythe/java/com/google/devtools/kythe/platform/java/helpers/JCTreeScanner.java
@@ -175,10 +175,6 @@ public class JCTreeScanner<R, P> implements TreeVisitor<R, P> {
     }
   }
 
-  public R scanAll(P p, JCTree tree, JCTree... others) {
-    return scan(Lists.asList(tree, others), p);
-  }
-
   public R scan(Iterable<? extends JCTree> trees, P p) {
     R r = null;
     if (trees != null) {
@@ -191,6 +187,10 @@ public class JCTreeScanner<R, P> implements TreeVisitor<R, P> {
     return r;
   }
 
+  public R scanAll(P p, JCTree tree, JCTree... others) {
+    return scan(Lists.asList(tree, others), p);
+  }
+
   public R reduce(R r1, R r2) {
     return r1;
   }
diff --git a/kythe/java/com/google/devtools/kythe/platform/java/helpers/SignatureGenerator.java b/kythe/java/com/google/devtools/kythe/platform/java/helpers/SignatureGenerator.java
index bcb446653..0cb6578ed 100644
--- a/kythe/java/com/google/devtools/kythe/platform/java/helpers/SignatureGenerator.java
+++ b/kythe/java/com/google/devtools/kythe/platform/java/helpers/SignatureGenerator.java
@@ -257,6 +257,21 @@ public class SignatureGenerator
     return null;
   }
 
+  @Override
+  public Void visitType(Type t, StringBuilder sbout) {
+    if (!visitedTypes.containsKey(t)) {
+      StringBuilder sb = new StringBuilder();
+      if (t.isPrimitive()) {
+        sb.append(t.tsym.name);
+      } else if (t.getKind() == TypeKind.VOID) {
+        sb.append(t.tsym.name);
+      }
+      visitedTypes.put(t, sb.toString());
+    }
+    sbout.append(visitedTypes.get(t));
+    return null;
+  }
+
   @Override
   public Void visitVariable(VariableElement e, StringBuilder sbout) {
     if (!visitedElements.containsKey(e)) {
@@ -444,21 +459,6 @@ public class SignatureGenerator
     return null;
   }
 
-  @Override
-  public Void visitType(Type t, StringBuilder sbout) {
-    if (!visitedTypes.containsKey(t)) {
-      StringBuilder sb = new StringBuilder();
-      if (t.isPrimitive()) {
-        sb.append(t.tsym.name);
-      } else if (t.getKind() == TypeKind.VOID) {
-        sb.append(t.tsym.name);
-      }
-      visitedTypes.put(t, sb.toString());
-    }
-    sbout.append(visitedTypes.get(t));
-    return null;
-  }
-
   @Override
   public Void visitTypeVar(TypeVar t, StringBuilder sbout) {
     if (boundedVars.contains((TypeVar) t.stripMetadata())) {
@@ -583,18 +583,6 @@ public class SignatureGenerator
       return toString();
     }
 
-    private void addSignature(ClassSymbol symbol) {
-      this.assembleSig(symbol.type);
-    }
-
-    private void addSignature(MethodSymbol symbol) {
-      addSignature((ClassSymbol) symbol.owner);
-      append('.');
-      append(symbol.name);
-      append(':');
-      assembleSig(symbol.type);
-    }
-
     /**
      * Generates full variable signature (both fields & variables).
      *
@@ -626,6 +614,18 @@ public class SignatureGenerator
       return toString();
     }
 
+    private void addSignature(ClassSymbol symbol) {
+      this.assembleSig(symbol.type);
+    }
+
+    private void addSignature(MethodSymbol symbol) {
+      addSignature((ClassSymbol) symbol.owner);
+      append('.');
+      append(symbol.name);
+      append(':');
+      assembleSig(symbol.type);
+    }
+
     private final StringBuilder sb = new StringBuilder();
 
     SigGen(Types types) {
diff --git a/kythe/java/com/google/devtools/kythe/util/DeleteRecursively.java b/kythe/java/com/google/devtools/kythe/util/DeleteRecursively.java
index 52f4c6456..5e5198d1c 100644
--- a/kythe/java/com/google/devtools/kythe/util/DeleteRecursively.java
+++ b/kythe/java/com/google/devtools/kythe/util/DeleteRecursively.java
@@ -29,11 +29,6 @@ public class DeleteRecursively extends SimpleFileVisitor<Path> {
 
   private DeleteRecursively() {}
 
-  /** Deletes {@code path}, and if a {@code path} is a directory, all contained files. */
-  public static void delete(Path path) throws IOException {
-    Files.walkFileTree(path, INSTANCE);
-  }
-
   @Override
   public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
     return delete(dir, exc);
@@ -43,6 +38,10 @@ public class DeleteRecursively extends SimpleFileVisitor<Path> {
   public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
     return delete(file, null);
   }
+  /** Deletes {@code path}, and if a {@code path} is a directory, all contained files. */
+  public static void delete(Path path) throws IOException {
+    Files.walkFileTree(path, INSTANCE);
+  }
 
   private static FileVisitResult delete(Path p, IOException exc) throws IOException {
     if (exc != null) {
diff --git a/tools/javacopts.bazelrc b/tools/javacopts.bazelrc
index 3f25e1819..3326e0ae7 100644
--- a/tools/javacopts.bazelrc
+++ b/tools/javacopts.bazelrc
@@ -35,6 +35,7 @@ build --javacopt="-Xep:ComplexBooleanConstant"
 build --javacopt="-Xep:DateChecker"
 build --javacopt="-Xep:DateFormatConstant"
 build --javacopt="-Xep:DefaultCharset"
+build --javacopt="-Xep:DepAnn"
 build --javacopt="-Xep:DescribeMatch"
 build --javacopt="-Xep:DoNotCallSuggester"
 build --javacopt="-Xep:DoNotClaimAnnotations"
@@ -158,6 +159,7 @@ build --javacopt="-Xep:TypeParameterUnusedInFormals"
 build --javacopt="-Xep:URLEqualsHashCode"
 build --javacopt="-Xep:UndefinedEquals"
 build --javacopt="-Xep:UnescapedEntity"
+build --javacopt="-Xep:UngroupedOverloads"
 build --javacopt="-Xep:UnnecessaryAnonymousClass"
 build --javacopt="-Xep:UnnecessaryDefaultInEnumSwitch"
 build --javacopt="-Xep:UnnecessaryLambda"


Test patch:
diff --git a/kythe/javatests/com/google/devtools/kythe/analyzers/java/testdata/pkg/Deprecation.java b/kythe/javatests/com/google/devtools/kythe/analyzers/java/testdata/pkg/Deprecation.java
index d6583c33a..2215139b2 100644
--- a/kythe/javatests/com/google/devtools/kythe/analyzers/java/testdata/pkg/Deprecation.java
+++ b/kythe/javatests/com/google/devtools/kythe/analyzers/java/testdata/pkg/Deprecation.java
@@ -9,7 +9,7 @@ package pkg;
  * @author this is an author tag, not the {@code @deprecated} tag.
  */
 @Deprecated
-@SuppressWarnings({"MissingSummary", "ClassCanBeStatic", "EmptyBlockTag"})
+@SuppressWarnings({"MissingSummary", "ClassCanBeStatic", "EmptyBlockTag", "DepAnn"})
 public class Deprecation {
   //- DeprecationClass.tag/deprecated "this class is obsolete; prefer {@link Comments}"