Run IntelliJ's "Pattern variable can be used" inspection on entire codebase.

This is a machine-generated CL.

Bazel does a lot of downcasting, much of it necessary due to the runtime-dynamic and configurable nature of the system. Using JEP394 to ergonomically downcast saves a line of distracting boilerplate which adds up with hundreds of downcasts.

#jdk21 #jep394

PiperOrigin-RevId: 625454340
Change-Id: I4f21253f855128df271a100ec19a578d5af1ec1c
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index 16296c6..42e0cd9 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -186,8 +186,7 @@
       if (rootInfo.type.isFile()) {
         return resultForFileRoot(traversal.root().asRootedPath(), rootInfo);
       }
-      if (rootInfo.type.isDirectory() && rootInfo.metadata instanceof TreeArtifactValue) {
-        TreeArtifactValue value = (TreeArtifactValue) rootInfo.metadata;
+      if (rootInfo.type.isDirectory() && rootInfo.metadata instanceof TreeArtifactValue value) {
         ImmutableList.Builder<RecursiveFilesystemTraversalValue> traversalValues =
             ImmutableList.builderWithExpectedSize(value.getChildValues().size());
         for (Map.Entry<TreeFileArtifact, FileArtifactValue> entry
@@ -457,19 +456,15 @@
   @VisibleForTesting
   static HasDigest withDigest(HasDigest fsVal, Path path, XattrProvider syscallCache)
       throws IOException {
-    if (fsVal instanceof FileStateValue) {
-      FileStateValue fsv = (FileStateValue) fsVal;
-      if (fsv instanceof RegularFileStateValueWithDigest) {
-        RegularFileStateValueWithDigest rfsv = (RegularFileStateValueWithDigest) fsv;
+    if (fsVal instanceof FileStateValue fsv) {
+      if (fsv instanceof RegularFileStateValueWithDigest rfsv) {
         return FileArtifactValue.createForVirtualActionInput(rfsv.getDigest(), rfsv.getSize());
-      } else if (fsv instanceof RegularFileStateValueWithContentsProxy) {
-        RegularFileStateValueWithContentsProxy rfsv = (RegularFileStateValueWithContentsProxy) fsv;
+      } else if (fsv instanceof RegularFileStateValueWithContentsProxy rfsv) {
         return FileArtifactValue.createForNormalFileUsingPath(path, rfsv.getSize(), syscallCache);
       }
 
       return new HasDigest.ByteStringDigest(fsv.getValueFingerprint());
-    } else if (fsVal instanceof FileArtifactValue) {
-      FileArtifactValue fav = ((FileArtifactValue) fsVal);
+    } else if (fsVal instanceof FileArtifactValue fav) {
       if (fav.getDigest() != null) {
         return fav;
       }
@@ -718,8 +713,7 @@
       if (value == null) {
         continue;
       }
-      if (key instanceof FileValue.Key) {
-        FileValue.Key fileKey = (FileValue.Key) key;
+      if (key instanceof FileValue.Key fileKey) {
         FileInfo fileInfo =
             toFileInfo((FileValue) value, env, fileKey.argument().asPath(), syscallCache);
         if (fileInfo != null) {