check_api/src/main/java/com/google/errorprone/fixes/AppliedFix.java
private static String firstEditedLine(StringBuilder content, Replacement firstEdit) {
      // We subtract 1 here because we want to find the first newline *before* the edit, not one
      // at its beginning.
      int startOfFirstEditedLine = content.lastIndexOf("\n", firstEdit.startPosition() - 1);
      int endOfFirstEditedLine = content.indexOf("\n", firstEdit.startPosition());
      if (startOfFirstEditedLine == -1) {
        startOfFirstEditedLine = 0; // Change to start of file with no preceding newline
      }
      if (endOfFirstEditedLine == -1) {
        // Change to last line of file
        endOfFirstEditedLine = content.length();
      }
      String snippet = content.substring(startOfFirstEditedLine, endOfFirstEditedLine);
      snippet = snippet.trim();
      if (snippet.contains("//")) {
        snippet = snippet.substring(0, snippet.indexOf("//")).trim();
      }
      return snippet;
    }
/**
     * Finds the full text of the first line that's changed. In this case "line" means "bracketed by
     * \n characters". We don't handle \r\n specially, because the strings that javac provides to
     * Error Prone have already been transformed from platform line endings to newlines (and even if
     * it didn't, the dangling \r characters would be handled by a trim() call).
     */
Finds the full text of the first line that's changed. In this case "line" means "bracketed by
\n characters". We don't handle \r\n specially, because the strings that javac provides to
Error Prone have already been transformed from platform line endings to newlines (and even if
it didn't, the dangling \r characters would be handled by a trim() call).
Finds the full text of the first line that ' s changed . In this case " line " means " bracketed by \ n characters " . We don ' t handle \ r \ n specially because the strings that javac provides to Error Prone have already been transformed from platform line endings to newlines ( and even if it didn ' t the dangling \ r characters would be handled by a trim () call ) .
private static String firstEditedLine(StringBuilder content, Replacement firstEdit) {
      int startOfFirstEditedLine = content.lastIndexOf("\n", firstEdit.startPosition() - 1);
      int endOfFirstEditedLine = content.indexOf("\n", firstEdit.startPosition());
      if (startOfFirstEditedLine == -1) {
        startOfFirstEditedLine = 0; 
      }
      if (endOfFirstEditedLine == -1) {
        endOfFirstEditedLine = content.length();
      }
      String snippet = content.substring(startOfFirstEditedLine, endOfFirstEditedLine);
      snippet = snippet.trim();
      if (snippet.contains("//")) {
        snippet = snippet.substring(0, snippet.indexOf("//")).trim();
      }
      return snippet;
    }
private static String firstEditedLine ( StringBuilder content , Replacement firstEdit ) { int startOfFirstEditedLine = content . lastIndexOf ( "\n" , firstEdit . startPosition ( ) - 1 ) ; int endOfFirstEditedLine = content . indexOf ( "\n" , firstEdit . startPosition ( ) ) ; if ( startOfFirstEditedLine == - 1 ) { startOfFirstEditedLine = 0 ; } if ( endOfFirstEditedLine == - 1 ) { endOfFirstEditedLine = content . length ( ) ; } String snippet = content . substring ( startOfFirstEditedLine , endOfFirstEditedLine ) ; snippet = snippet . trim ( ) ; if ( snippet . contains ( "//" ) ) { snippet = snippet . substring ( 0 , snippet . indexOf ( "//" ) ) . trim ( ) ; } return snippet ; }
Finds the full text of the first line that's changed.
Finds the full text of the first line that ' s changed .
// We subtract 1 here because we want to find the first newline *before* the edit, not one // at its beginning. // Change to start of file with no preceding newline // Change to last line of file