check_api/src/main/java/com/google/errorprone/fixes/AppliedFix.java
@Nullable
    public AppliedFix apply(Fix suggestedFix) {
      // We apply the replacements in ascending order here. Descending is simpler, since applying a
      // replacement can't change the index for future replacements, but it leads to quadratic
      // copying behavior as we constantly shift the tail of the file around in our StringBuilder.
      ImmutableSet<Replacement> replacements =
          ascending(suggestedFix.getReplacements(endPositions));
      if (replacements.isEmpty()) {
        return null;
      }

      StringBuilder replaced = new StringBuilder();
      int positionInOriginal = 0;
      for (Replacement repl : replacements) {
        checkArgument(
            repl.endPosition() <= source.length(),
            "End [%s] should not exceed source length [%s]",
            repl.endPosition(),
            source.length());

        // Write the unmodified content leading up to this change
        replaced.append(source, positionInOriginal, repl.startPosition());
        // And the modified content for this change
        replaced.append(repl.replaceWith());
        // Then skip everything from source between start and end
        positionInOriginal = repl.endPosition();
      }
      // Flush out any remaining content after the final change
      replaced.append(source, positionInOriginal, source.length());

      // Find the changed line containing the first edit
      String snippet = firstEditedLine(replaced, Iterables.get(replacements, 0));
      if (snippet.isEmpty()) {
        return new AppliedFix("to remove this line", /* isRemoveLine= */ true);
      }
      return new AppliedFix(snippet, /* isRemoveLine= */ false);
    }
/**
     * Applies the suggestedFix to the source. Returns null if applying the fix results in no change
     * to the source, or a change only to imports.
     */
Applies the suggestedFix to the source. Returns null if applying the fix results in no change
to the source, or a change only to imports.
Applies the suggestedFix to the source . Returns null if applying the fix results in no change to the source or a change only to imports .
@Nullable
    public AppliedFix apply(Fix suggestedFix) {
      ImmutableSet<Replacement> replacements =
          ascending(suggestedFix.getReplacements(endPositions));
      if (replacements.isEmpty()) {
        return null;
      }
      StringBuilder replaced = new StringBuilder();
      int positionInOriginal = 0;
      for (Replacement repl : replacements) {
        checkArgument(
            repl.endPosition() <= source.length(),
            "End [%s] should not exceed source length [%s]",
            repl.endPosition(),
            source.length());
        replaced.append(source, positionInOriginal, repl.startPosition());
        replaced.append(repl.replaceWith());
        positionInOriginal = repl.endPosition();
      }
      replaced.append(source, positionInOriginal, source.length());
      String snippet = firstEditedLine(replaced, Iterables.get(replacements, 0));
      if (snippet.isEmpty()) {
        return new AppliedFix("to remove this line", /* isRemoveLine= */ true);
      }
      return new AppliedFix(snippet, /* isRemoveLine= */ false);
    }
@ Nullable public AppliedFix apply ( Fix suggestedFix ) { ImmutableSet < Replacement > replacements = ascending ( suggestedFix . getReplacements ( endPositions ) ) ; if ( replacements . isEmpty ( ) ) { return null ; } StringBuilder replaced = new StringBuilder ( ) ; int positionInOriginal = 0 ; for ( Replacement repl : replacements ) { checkArgument ( repl . endPosition ( ) <= source . length ( ) , "End [%s] should not exceed source length [%s]" , repl . endPosition ( ) , source . length ( ) ) ; replaced . append ( source , positionInOriginal , repl . startPosition ( ) ) ; replaced . append ( repl . replaceWith ( ) ) ; positionInOriginal = repl . endPosition ( ) ; } replaced . append ( source , positionInOriginal , source . length ( ) ) ; String snippet = firstEditedLine ( replaced , Iterables . get ( replacements , 0 ) ) ; if ( snippet . isEmpty ( ) ) { return new AppliedFix ( "to remove this line" , /* isRemoveLine= */ true ) ; } return new AppliedFix ( snippet , /* isRemoveLine= */ false ) ; }
Applies the suggestedFix to the source.
Applies the suggestedFix to the source .
// We apply the replacements in ascending order here. Descending is simpler, since applying a // replacement can't change the index for future replacements, but it leads to quadratic // copying behavior as we constantly shift the tail of the file around in our StringBuilder. // Write the unmodified content leading up to this change // And the modified content for this change // Then skip everything from source between start and end // Flush out any remaining content after the final change // Find the changed line containing the first edit