Java Code Examples for com.google.debugging.sourcemap.FilePosition#getLine()

The following examples show how to use com.google.debugging.sourcemap.FilePosition#getLine() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_34_CodePrinter_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts the given position by normalizing it against the insertion
 * or removal of a newline at the given line and character position.
 *
 * @param position The existing position before the newline was inserted.
 * @param lineIndex The index of the line at which the newline was inserted.
 * @param characterPosition The position on the line at which the newline
 *     was inserted.
 * @param insertion True if a newline was inserted, false if a newline was
 *     removed.
 *
 * @return The normalized position.
 * @throws IllegalStateException if an attempt to reverse a line cut is
 *     made on a previous line rather than the current line.
 */
private FilePosition convertPosition(FilePosition position, int lineIndex,
                                 int characterPosition, boolean insertion) {
  int originalLine = position.getLine();
  int originalChar = position.getColumn();
  if (insertion) {
    if (originalLine == lineIndex && originalChar >= characterPosition) {
      // If the position falls on the line itself, then normalize it
      // if it falls at or after the place the newline was inserted.
      return new FilePosition(
          originalLine + 1, originalChar - characterPosition);
    } else {
      return position;
    }
  } else {
    if (originalLine == lineIndex) {
      return new FilePosition(
          originalLine - 1, originalChar + characterPosition);
    } else if (originalLine > lineIndex) {
        // Not supported, can only undo a cut on the most recent line. To
        // do this on a previous lines would require reevaluating the cut
        // positions on all subsequent lines.
        throw new IllegalStateException(
            "Cannot undo line cut on a previous line.");
    } else {
      return position;
    }
  }
}
 
Example 2
Source File: Closure_34_CodePrinter_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Converts the given position by normalizing it against the insertion
 * or removal of a newline at the given line and character position.
 *
 * @param position The existing position before the newline was inserted.
 * @param lineIndex The index of the line at which the newline was inserted.
 * @param characterPosition The position on the line at which the newline
 *     was inserted.
 * @param insertion True if a newline was inserted, false if a newline was
 *     removed.
 *
 * @return The normalized position.
 * @throws IllegalStateException if an attempt to reverse a line cut is
 *     made on a previous line rather than the current line.
 */
private FilePosition convertPosition(FilePosition position, int lineIndex,
                                 int characterPosition, boolean insertion) {
  int originalLine = position.getLine();
  int originalChar = position.getColumn();
  if (insertion) {
    if (originalLine == lineIndex && originalChar >= characterPosition) {
      // If the position falls on the line itself, then normalize it
      // if it falls at or after the place the newline was inserted.
      return new FilePosition(
          originalLine + 1, originalChar - characterPosition);
    } else {
      return position;
    }
  } else {
    if (originalLine == lineIndex) {
      return new FilePosition(
          originalLine - 1, originalChar + characterPosition);
    } else if (originalLine > lineIndex) {
        // Not supported, can only undo a cut on the most recent line. To
        // do this on a previous lines would require reevaluating the cut
        // positions on all subsequent lines.
        throw new IllegalStateException(
            "Cannot undo line cut on a previous line.");
    } else {
      return position;
    }
  }
}
 
Example 3
Source File: CodePrinter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts the given position by normalizing it against the insertion
 * or removal of a newline at the given line and character position.
 *
 * @param position The existing position before the newline was inserted.
 * @param lineIndex The index of the line at which the newline was inserted.
 * @param characterPosition The position on the line at which the newline
 *     was inserted.
 * @param insertion True if a newline was inserted, false if a newline was
 *     removed.
 *
 * @return The normalized position.
 * @throws IllegalStateException if an attempt to reverse a line cut is
 *     made on a previous line rather than the current line.
 */
private FilePosition convertPosition(FilePosition position, int lineIndex,
                                 int characterPosition, boolean insertion) {
  int originalLine = position.getLine();
  int originalChar = position.getColumn();
  if (insertion) {
    if (originalLine == lineIndex && originalChar >= characterPosition) {
      // If the position falls on the line itself, then normalize it
      // if it falls at or after the place the newline was inserted.
      return new FilePosition(
          originalLine + 1, originalChar - characterPosition);
    } else {
      return position;
    }
  } else {
    if (originalLine == lineIndex) {
      return new FilePosition(
          originalLine - 1, originalChar + characterPosition);
    } else if (originalLine > lineIndex) {
        // Not supported, can only undo a cut on the most recent line. To
        // do this on a previous lines would require reevaluating the cut
        // positions on all subsequent lines.
        throw new IllegalStateException(
            "Cannot undo line cut on a previous line.");
    } else {
      return position;
    }
  }
}