Refactor all ctor callsites of PathFragment to instead call a static 'create' method.

This paves the way for changing PathFragment to e.g. an abstract class with multiple subclasses. This way we can split out the windows-specific stuff into one of these concrete classes, making the code more readable and also saving memory (since the shallow heap size of the NonWindowsPathFragment subclass will hopefully be smaller than that of the current PathFragment).

This also lets us pursue gc churn optimizations. We can now do interning in PathFragment#create and can also get rid of unnecessary intermediate PathFragment allocations.

RELNOTES: None

PiperOrigin-RevId: 152145768
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java
index 89f961a..d23b527 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java
@@ -92,7 +92,7 @@
   public void testStartingAtBuildFile() throws Exception {
     scratch.file("a/b/c/BUILD");
     RecursivePkgValue value =
-        buildRecursivePkgValue(rootDirectory, new PathFragment("a/b/c/BUILD"));
+        buildRecursivePkgValue(rootDirectory, PathFragment.create("a/b/c/BUILD"));
     assertTrue(value.getPackages().isEmpty());
   }
 
@@ -106,11 +106,11 @@
     scratch.file(root2 + "/a/b/BUILD");
     setPackageCacheOptions("--package_path=" + "root1" + ":" + "root2");
 
-    RecursivePkgValue valueForRoot1 = buildRecursivePkgValue(root1, new PathFragment("a"));
+    RecursivePkgValue valueForRoot1 = buildRecursivePkgValue(root1, PathFragment.create("a"));
     String root1Pkg = Iterables.getOnlyElement(valueForRoot1.getPackages());
     assertEquals(root1Pkg, "a");
 
-    RecursivePkgValue valueForRoot2 = buildRecursivePkgValue(root2, new PathFragment("a"));
+    RecursivePkgValue valueForRoot2 = buildRecursivePkgValue(root2, PathFragment.create("a"));
     String root2Pkg = Iterables.getOnlyElement(valueForRoot2.getPackages());
     assertEquals(root2Pkg, "a/b");
   }
@@ -123,10 +123,10 @@
     scratch.file("a/c/BUILD");
 
     // When the top package is evaluated for recursive package values, and "a/b" is excluded,
-    PathFragment excludedPathFragment = new PathFragment("a/b");
+    PathFragment excludedPathFragment = PathFragment.create("a/b");
     SkyKey key =
         buildRecursivePkgKey(
-            rootDirectory, new PathFragment("a"), ImmutableSet.of(excludedPathFragment));
+            rootDirectory, PathFragment.create("a"), ImmutableSet.of(excludedPathFragment));
     EvaluationResult<RecursivePkgValue> evaluationResult = getEvaluationResult(key);
     RecursivePkgValue value = evaluationResult.get(key);
 
@@ -150,7 +150,7 @@
     assertTrue(
         exists(
             buildRecursivePkgKey(
-                rootDirectory, new PathFragment("a/c"), ImmutableSet.<PathFragment>of()),
+                rootDirectory, PathFragment.create("a/c"), ImmutableSet.<PathFragment>of()),
             graph));
   }
 
@@ -162,8 +162,8 @@
     scratch.file("a/b/d/BUILD");
 
     // When the top package is evaluated for recursive package values, and "a/b/c" is excluded,
-    ImmutableSet<PathFragment> excludedPaths = ImmutableSet.of(new PathFragment("a/b/c"));
-    SkyKey key = buildRecursivePkgKey(rootDirectory, new PathFragment("a"), excludedPaths);
+    ImmutableSet<PathFragment> excludedPaths = ImmutableSet.of(PathFragment.create("a/b/c"));
+    SkyKey key = buildRecursivePkgKey(rootDirectory, PathFragment.create("a"), excludedPaths);
     EvaluationResult<RecursivePkgValue> evaluationResult = getEvaluationResult(key);
     RecursivePkgValue value = evaluationResult.get(key);
 
@@ -178,6 +178,8 @@
     // "a/b/c" does live underneath "a/b".
     WalkableGraph graph = Preconditions.checkNotNull(evaluationResult.getWalkableGraph());
     assertTrue(
-        exists(buildRecursivePkgKey(rootDirectory, new PathFragment("a/b"), excludedPaths), graph));
+        exists(
+            buildRecursivePkgKey(rootDirectory, PathFragment.create("a/b"), excludedPaths),
+            graph));
   }
 }