Remove the SeparatorFinder interface and inline its only implementation.

Let's not create abstractions when we don't need them.

RELNOTES: None.
PiperOrigin-RevId: 303733672
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/DeclarationAssembler.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/DeclarationAssembler.java
index 2cea656..0b38335 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/DeclarationAssembler.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/DeclarationAssembler.java
@@ -31,18 +31,10 @@
  */
 public class DeclarationAssembler {
   private final DeclarationConsumer declarationConsumer;
-  private final SeparatorFinder separatorFinder;
 
-  /**
-   * @param declarationConsumer delegate declaration consumer for actual processing / parsing
-   * @param separatorFinder callback used to determine if two fragments should be separate
-   *     declarations (in the Ninja case, if the new line starts with a space, it should be treated
-   *     as a part of the previous declaration, i.e. the separator is longer then one symbol).
-   */
-  public DeclarationAssembler(
-      DeclarationConsumer declarationConsumer, SeparatorFinder separatorFinder) {
+  /** @param declarationConsumer delegate declaration consumer for actual processing / parsing */
+  public DeclarationAssembler(DeclarationConsumer declarationConsumer) {
     this.declarationConsumer = declarationConsumer;
-    this.separatorFinder = separatorFinder;
   }
 
   /**
@@ -113,7 +105,8 @@
     int previousEnd = 0;
     for (Range<Integer> range : interestingRanges) {
       int idx =
-          separatorFinder.findNextSeparator(merged, range.lowerEndpoint(), range.upperEndpoint());
+          NinjaSeparatorFinder.findNextSeparator(
+              merged, range.lowerEndpoint(), range.upperEndpoint());
       if (idx >= 0) {
         // There should always be a previous fragment, as we are checking non-intersecting ranges,
         // starting from the connection point between first and second fragments.
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/FileFragmentSplitter.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/FileFragmentSplitter.java
index d782abc..6db928e 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/FileFragmentSplitter.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/FileFragmentSplitter.java
@@ -30,18 +30,14 @@
 public class FileFragmentSplitter implements Callable<List<FileFragment>> {
   private final FileFragment fileFragment;
   private final DeclarationConsumer consumer;
-  private final SeparatorFinder separatorFinder;
 
   /**
    * @param fileFragment {@link FileFragment}, fragment of which should be splitted
    * @param consumer declaration consumer
-   * @param separatorFinder finds declaration separators
    */
-  public FileFragmentSplitter(
-      FileFragment fileFragment, DeclarationConsumer consumer, SeparatorFinder separatorFinder) {
+  public FileFragmentSplitter(FileFragment fileFragment, DeclarationConsumer consumer) {
     this.fileFragment = fileFragment;
     this.consumer = consumer;
-    this.separatorFinder = separatorFinder;
   }
 
   /**
@@ -55,7 +51,7 @@
     List<FileFragment> fragments = Lists.newArrayList();
     int start = 0;
     while (true) {
-      int end = separatorFinder.findNextSeparator(fileFragment, start, -1);
+      int end = NinjaSeparatorFinder.findNextSeparator(fileFragment, start, -1);
       if (end < 0) {
         break;
       }
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/NinjaSeparatorFinder.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/NinjaSeparatorFinder.java
index 2d11ce4..af88b14 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/NinjaSeparatorFinder.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/NinjaSeparatorFinder.java
@@ -18,7 +18,7 @@
 import com.google.common.base.Preconditions;
 
 /**
- * Implementation of {@link SeparatorFinder} for Ninja files.
+ * Finds the border between two different Ninja declarations.
  *
  * <p>The Ninja declaration consists of several text lines; if the line is a part of the previous
  * declaration, it starts with some amount of spaces or tabs. If the line is the beginning of the
@@ -28,9 +28,7 @@
  * <p>We support '\r\n' separators in Ninja files and throw {@link IncorrectSeparatorException} in
  * case an incorrect separator '\r' is used.
  */
-public class NinjaSeparatorFinder implements SeparatorFinder {
-  public static final NinjaSeparatorFinder INSTANCE = new NinjaSeparatorFinder();
-
+public class NinjaSeparatorFinder {
   private static final byte DOLLAR_BYTE = '$';
   private static final byte LINEFEED_BYTE = '\r';
   private static final byte NEWLINE_BYTE = '\n';
@@ -39,8 +37,7 @@
 
   private NinjaSeparatorFinder() {}
 
-  @Override
-  public int findNextSeparator(FileFragment fragment, int startingFrom, int untilExcluded)
+  public static int findNextSeparator(FileFragment fragment, int startingFrom, int untilExcluded)
       throws IncorrectSeparatorException {
     Preconditions.checkState(startingFrom < fragment.length());
     Preconditions.checkState(untilExcluded < 0 || untilExcluded <= fragment.length());
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/ParallelFileProcessing.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/ParallelFileProcessing.java
index dd9da72..f18d0ab 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/ParallelFileProcessing.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/ParallelFileProcessing.java
@@ -25,26 +25,23 @@
 
 /**
  * Parallel file processing implementation. See comment to {@link #processFile(ReadableByteChannel,
- * BlockParameters, Supplier, ListeningExecutorService, SeparatorFinder)}.
+ * BlockParameters, Supplier, ListeningExecutorService)}.
  */
 public class ParallelFileProcessing {
   private final ReadableByteChannel channel;
   private final BlockParameters parameters;
   private final Supplier<DeclarationConsumer> tokenConsumerFactory;
   private final ListeningExecutorService executorService;
-  private final SeparatorFinder predicate;
 
   private ParallelFileProcessing(
       ReadableByteChannel channel,
       BlockParameters parameters,
       Supplier<DeclarationConsumer> tokenConsumerFactory,
-      ListeningExecutorService executorService,
-      SeparatorFinder predicate) {
+      ListeningExecutorService executorService) {
     this.channel = channel;
     this.parameters = parameters;
     this.tokenConsumerFactory = tokenConsumerFactory;
     this.executorService = executorService;
-    this.predicate = predicate;
   }
 
   /**
@@ -89,11 +86,9 @@
       ReadableByteChannel channel,
       BlockParameters parameters,
       Supplier<DeclarationConsumer> tokenConsumerFactory,
-      ListeningExecutorService executorService,
-      SeparatorFinder predicate)
+      ListeningExecutorService executorService)
       throws GenericParsingException, IOException, InterruptedException {
-    new ParallelFileProcessing(
-            channel, parameters, tokenConsumerFactory, executorService, predicate)
+    new ParallelFileProcessing(channel, parameters, tokenConsumerFactory, executorService)
         .processFileImpl();
   }
 
@@ -102,8 +97,7 @@
       // Return immediately, if the file is empty.
       return;
     }
-    DeclarationAssembler assembler =
-        new DeclarationAssembler(tokenConsumerFactory.get(), predicate);
+    DeclarationAssembler assembler = new DeclarationAssembler(tokenConsumerFactory.get());
 
     CollectingListFuture<List<FileFragment>, GenericParsingException> future =
         new CollectingListFuture<>(GenericParsingException.class);
@@ -151,7 +145,7 @@
       }
       DeclarationConsumer consumer = tokenConsumerFactory.get();
       FileFragment fragment = new FileFragment(bb, offset, from, to);
-      FileFragmentSplitter tokenizer = new FileFragmentSplitter(fragment, consumer, predicate);
+      FileFragmentSplitter tokenizer = new FileFragmentSplitter(fragment, consumer);
       future.add(executorService.submit(tokenizer));
       from = to;
     }
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/SeparatorFinder.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/SeparatorFinder.java
deleted file mode 100644
index e95e241..0000000
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/file/SeparatorFinder.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2019 The Bazel Authors. All rights reserved.
-//
-// 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.devtools.build.lib.bazel.rules.ninja.file;
-
-/** Interface for determining where the byte sequence should be split into parts. */
-public interface SeparatorFinder {
-
-  /**
-   * Returns the index of the end of the next separator (separator can be of two symbols, \r\n), or
-   * -1 if the fragment does not contain any separators.
-   *
-   * @param fragment fragment to search in
-   * @param startingFrom index to start search from
-   * @param untilExcluded index to stop search before (excluded from search).
-   * @throws IncorrectSeparatorException if the incorrect separator value (\r) is used
-   */
-  int findNextSeparator(FileFragment fragment, int startingFrom, int untilExcluded)
-      throws IncorrectSeparatorException;
-}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/pipeline/NinjaPipeline.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/pipeline/NinjaPipeline.java
index d45aaf6..14397ed 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/pipeline/NinjaPipeline.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/ninja/pipeline/NinjaPipeline.java
@@ -26,7 +26,6 @@
 import com.google.devtools.build.lib.bazel.rules.ninja.file.CollectingListFuture;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.FileFragment;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.GenericParsingException;
-import com.google.devtools.build.lib.bazel.rules.ninja.file.NinjaSeparatorFinder;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.ParallelFileProcessing;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.ParallelFileProcessing.BlockParameters;
 import com.google.devtools.build.lib.bazel.rules.ninja.lexer.NinjaLexer;
@@ -215,8 +214,7 @@
                   pieces.add(parseResult);
                   return new NinjaParser(NinjaPipeline.this, parseResult, path.getBaseName());
                 },
-                service,
-                NinjaSeparatorFinder.INSTANCE);
+                service);
             return NinjaFileParseResult.merge(pieces);
           }
         });
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/DeclarationAssemblerTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/DeclarationAssemblerTest.java
index f345b7d..40610e2 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/DeclarationAssemblerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/DeclarationAssemblerTest.java
@@ -24,7 +24,6 @@
 import com.google.devtools.build.lib.bazel.rules.ninja.file.DeclarationAssembler;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.FileFragment;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.GenericParsingException;
-import com.google.devtools.build.lib.bazel.rules.ninja.file.NinjaSeparatorFinder;
 import com.google.devtools.build.lib.util.Pair;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -73,8 +72,7 @@
             fragment -> {
               offsetStringPairList.add(
                   new Pair<>(fragment.getFragmentOffset(), fragment.toString()));
-            },
-            NinjaSeparatorFinder.INSTANCE);
+            });
 
     assembler.wrapUp(
         Lists.newArrayList(
@@ -98,8 +96,7 @@
             fragment -> {
               list.add(fragment.toString());
               assertThat(fragment.getFileOffset()).isAnyOf(0L, (long) chars1.length);
-            },
-            NinjaSeparatorFinder.INSTANCE);
+            });
 
     assembler.wrapUp(
         Lists.newArrayList(
@@ -118,8 +115,7 @@
             fragment -> {
               list.add(fragment.toString());
               assertThat(fragment.getFileOffset()).isEqualTo(0);
-            },
-            NinjaSeparatorFinder.INSTANCE);
+            });
 
     byte[] chars = s.getBytes(StandardCharsets.ISO_8859_1);
     ByteBuffer bytes = ByteBuffer.wrap(chars);
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/FileFragmentSplitterTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/FileFragmentSplitterTest.java
index 885debd..41d08c3 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/FileFragmentSplitterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/FileFragmentSplitterTest.java
@@ -23,7 +23,6 @@
 import com.google.devtools.build.lib.bazel.rules.ninja.file.DeclarationConsumer;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.FileFragment;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.FileFragmentSplitter;
-import com.google.devtools.build.lib.bazel.rules.ninja.file.NinjaSeparatorFinder;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
@@ -50,8 +49,7 @@
     byte[] chars = String.join("\n", list).getBytes(StandardCharsets.ISO_8859_1);
     ByteBuffer buffer = ByteBuffer.wrap(chars);
     FileFragment fragment = new FileFragment(buffer, offsetValue, 0, chars.length);
-    FileFragmentSplitter tokenizer =
-        new FileFragmentSplitter(fragment, consumer, NinjaSeparatorFinder.INSTANCE);
+    FileFragmentSplitter tokenizer = new FileFragmentSplitter(fragment, consumer);
     List<FileFragment> edges = tokenizer.call();
     assertThat(result).containsExactly("two\n");
     assertThat(
@@ -73,8 +71,7 @@
     DeclarationConsumer consumer = fragment -> result.add(fragment.toString());
 
     FileFragment fragment = new FileFragment(bytes, 0, 0, chars.length);
-    FileFragmentSplitter tokenizer =
-        new FileFragmentSplitter(fragment, consumer, NinjaSeparatorFinder.INSTANCE);
+    FileFragmentSplitter tokenizer = new FileFragmentSplitter(fragment, consumer);
     List<FileFragment> edges = tokenizer.call();
     assertThat(result).containsExactly("two\n\ttwo-detail\n");
     assertThat(
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/NinjaSeparatorFinderTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/NinjaSeparatorFinderTest.java
index ab1efd6..207408e 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/NinjaSeparatorFinderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/NinjaSeparatorFinderTest.java
@@ -64,14 +64,14 @@
     FileFragment fragment = new FileFragment(buffer, 0, 0, buffer.limit());
     assertThrows(
         IncorrectSeparatorException.class,
-        () -> NinjaSeparatorFinder.INSTANCE.findNextSeparator(fragment, 0, -1));
+        () -> NinjaSeparatorFinder.findNextSeparator(fragment, 0, -1));
   }
 
   private static void doTestIsSeparator(String s, int expected) throws IncorrectSeparatorException {
     byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
     ByteBuffer buffer = ByteBuffer.wrap(bytes);
     FileFragment fragment = new FileFragment(buffer, 0, 0, buffer.limit());
-    int result = NinjaSeparatorFinder.INSTANCE.findNextSeparator(fragment, 0, -1);
+    int result = NinjaSeparatorFinder.findNextSeparator(fragment, 0, -1);
     assertThat(result).isEqualTo(expected);
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/ParallelFileProcessingTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/ParallelFileProcessingTest.java
index b1cb73f..7a3c755 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/ParallelFileProcessingTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/ninja/ParallelFileProcessingTest.java
@@ -27,7 +27,6 @@
 import com.google.devtools.build.lib.bazel.rules.ninja.file.DeclarationConsumer;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.FileFragment;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.GenericParsingException;
-import com.google.devtools.build.lib.bazel.rules.ninja.file.NinjaSeparatorFinder;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.ParallelFileProcessing;
 import com.google.devtools.build.lib.bazel.rules.ninja.file.ParallelFileProcessing.BlockParameters;
 import com.google.devtools.build.lib.concurrent.ExecutorUtil;
@@ -143,8 +142,7 @@
           channel,
           parameters != null ? parameters : new BlockParameters(file.length()),
           factory,
-          service,
-          NinjaSeparatorFinder.INSTANCE);
+          service);
     } finally {
       ExecutorUtil.interruptibleShutdown(service);
     }