com.google.debugging.sourcemap.FilePosition Java Examples

The following examples show how to use com.google.debugging.sourcemap.FilePosition. 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 6 votes vote down vote up
/**
 * Starts the source mapping for the given
 * node at the current position.
 */
@Override
void startSourceMapping(Node node) {
  Preconditions.checkState(sourceMapDetailLevel != null);
  Preconditions.checkState(node != null);
  if (createSrcMap
      && node.getSourceFileName() != null
      && node.getLineno() > 0
      && sourceMapDetailLevel.apply(node)) {
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();
    Preconditions.checkState(line >= 0);
    Mapping mapping = new Mapping();
    mapping.node = node;
    mapping.start = new FilePosition(line, index);
    mappings.push(mapping);
    allMappings.add(mapping);
  }
}
 
Example #2
Source File: Closure_34_CodePrinter_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Starts the source mapping for the given
 * node at the current position.
 */
@Override
void startSourceMapping(Node node) {
  Preconditions.checkState(sourceMapDetailLevel != null);
  Preconditions.checkState(node != null);
  if (createSrcMap
      && node.getSourceFileName() != null
      && node.getLineno() > 0
      && sourceMapDetailLevel.apply(node)) {
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();
    Preconditions.checkState(line >= 0);
    Mapping mapping = new Mapping();
    mapping.node = node;
    mapping.start = new FilePosition(line, index);
    mappings.push(mapping);
    allMappings.add(mapping);
  }
}
 
Example #3
Source File: CodePrinter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Starts the source mapping for the given
 * node at the current position.
 */
@Override
void startSourceMapping(Node node) {
  Preconditions.checkState(sourceMapDetailLevel != null);
  Preconditions.checkState(node != null);
  if (createSrcMap
      && node.getSourceFileName() != null
      && node.getLineno() > 0
      && sourceMapDetailLevel.apply(node)) {
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();
    Preconditions.checkState(line >= 0);
    Mapping mapping = new Mapping();
    mapping.node = node;
    mapping.start = new FilePosition(line, index);
    mappings.push(mapping);
    allMappings.add(mapping);
  }
}
 
Example #4
Source File: Closure_34_CodePrinter_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Finishes the source mapping for the given
 * node at the current position.
 */
@Override
void endSourceMapping(Node node) {
  if (createSrcMap && !mappings.isEmpty() && mappings.peek().node == node) {
    Mapping mapping = mappings.pop();
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();
    Preconditions.checkState(line >= 0);
    mapping.end = new FilePosition(line, index);
  }
}
 
Example #5
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 #6
Source File: Closure_34_CodePrinter_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Finishes the source mapping for the given
 * node at the current position.
 */
@Override
void endSourceMapping(Node node) {
  if (createSrcMap && !mappings.isEmpty() && mappings.peek().node == node) {
    Mapping mapping = mappings.pop();
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();
    Preconditions.checkState(line >= 0);
    mapping.end = new FilePosition(line, index);
  }
}
 
Example #7
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 #8
Source File: Closure_47_SourceMap_t.java    From coming with MIT License 5 votes vote down vote up
public void addMapping(
    Node node,
    FilePosition outputStartPosition,
    FilePosition outputEndPosition) {
  String sourceFile = node.getSourceFileName();

  // If the node does not have an associated source file or
  // its line number is -1, then the node does not have sufficient
  // information for a mapping to be useful.
  if (sourceFile == null || node.getLineno() < 0) {
    return;
  }

  sourceFile = fixupSourceLocation(sourceFile);

  String originalName = (String) node.getProp(Node.ORIGINALNAME_PROP);

  // Strangely, Rhino source lines are one based but columns are
  // zero based.
  // We don't change this for the v1 or v2 source maps but for
  // v3 we make them both 0 based.
  int lineBaseOffset = 1;
  if (generator instanceof SourceMapGeneratorV1
      || generator instanceof SourceMapGeneratorV2) {
    lineBaseOffset = 0;
  }

  generator.addMapping(
      sourceFile, originalName,
      new FilePosition(node.getLineno() - lineBaseOffset, node.getCharno()),
      outputStartPosition, outputEndPosition);
}
 
Example #9
Source File: Closure_47_SourceMap_s.java    From coming with MIT License 5 votes vote down vote up
public void addMapping(
    Node node,
    FilePosition outputStartPosition,
    FilePosition outputEndPosition) {
  String sourceFile = node.getSourceFileName();

  // If the node does not have an associated source file or
  // its line number is -1, then the node does not have sufficient
  // information for a mapping to be useful.
  if (sourceFile == null || node.getLineno() < 0) {
    return;
  }

  sourceFile = fixupSourceLocation(sourceFile);

  String originalName = (String) node.getProp(Node.ORIGINALNAME_PROP);

  // Strangely, Rhino source lines are one based but columns are
  // zero based.
  // We don't change this for the v1 or v2 source maps but for
  // v3 we make them both 0 based.

  generator.addMapping(
      sourceFile, originalName,
      new FilePosition(node.getLineno(), node.getCharno()),
      outputStartPosition, outputEndPosition);
}
 
Example #10
Source File: SourceMap.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void addMapping(
    Node node,
    FilePosition outputStartPosition,
    FilePosition outputEndPosition) {
  String sourceFile = node.getSourceFileName();

  // If the node does not have an associated source file or
  // its line number is -1, then the node does not have sufficient
  // information for a mapping to be useful.
  if (sourceFile == null || node.getLineno() < 0) {
    return;
  }

  sourceFile = fixupSourceLocation(sourceFile);

  String originalName = (String) node.getProp(Node.ORIGINALNAME_PROP);

  // Strangely, Rhino source lines are one based but columns are
  // zero based.
  // We don't change this for the v1 or v2 source maps but for
  // v3 we make them both 0 based.
  int lineBaseOffset = 1;
  if (generator instanceof SourceMapGeneratorV1
      || generator instanceof SourceMapGeneratorV2) {
    lineBaseOffset = 0;
  }

  generator.addMapping(
      sourceFile, originalName,
      new FilePosition(node.getLineno() - lineBaseOffset, node.getCharno()),
      outputStartPosition, outputEndPosition);
}
 
Example #11
Source File: CodePrinter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Finishes the source mapping for the given
 * node at the current position.
 */
@Override
void endSourceMapping(Node node) {
  if (createSrcMap && !mappings.isEmpty() && mappings.peek().node == node) {
    Mapping mapping = mappings.pop();
    int line = getCurrentLineIndex();
    int index = getCurrentCharIndex();
    Preconditions.checkState(line >= 0);
    mapping.end = new FilePosition(line, index);
  }
}
 
Example #12
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;
    }
  }
}
 
Example #13
Source File: DefaultGssSourceMapGenerator.java    From closure-stylesheets with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the source mapping for the given node at the current position.
 * This is intended to be called before the node is written to the buffer.
 *
 * @param node the {@link CssNode} to be processed
 * @param startLine the first character's line number once it starts writing output
 * @param startCharIndex the first character's character index once it starts writing output
 */
@Override
public void startSourceMapping(CssNode node, int startLine, int startCharIndex) {
  Preconditions.checkState(node != null);
  Preconditions.checkState(startLine >= 0);
  Preconditions.checkState(startCharIndex >= 0);
  if (node.getSourceCodeLocation() != null
      && detailLevelPredicate.apply(node)) {
    Mapping mapping = new Mapping();
    mapping.node = node;
    mapping.start = new FilePosition(startLine, startCharIndex);
    mappings.push(mapping);
    allMappings.add(mapping);
  }
}
 
Example #14
Source File: DefaultGssSourceMapGenerator.java    From closure-stylesheets with Apache License 2.0 5 votes vote down vote up
/**
 * Finishes the source mapping for the given node at the current position.
 * This is intended to be called immediately after the whole node is written to the buffer.
 *
 * @param node the {@link CssNode} to be processed
 * @param endLine the last character's line number when it ends writing output
 * @param endCharIndex the last character's character index when it ends writing output
 */
@Override
public void endSourceMapping(CssNode node, int endLine, int endCharIndex) {
  Preconditions.checkState(node != null);
  Preconditions.checkState(endLine >= 0);
  // -1 when a node contributes no content at the start of the buffer,
  // as when a CssImportBlockNode is encountered, and there is no
  // copyright comment.
  Preconditions.checkState(endCharIndex >= -1);
  endCharIndex++; //
  if (!mappings.isEmpty() && mappings.peek().node == node) {
    Mapping mapping = mappings.pop();
    mapping.end = new FilePosition(endLine, endCharIndex);
  }
}
 
Example #15
Source File: DefaultGssSourceMapGenerator.java    From closure-stylesheets with Apache License 2.0 5 votes vote down vote up
CompleteMapping(Mapping mapping) {
  CssNode node = mapping.node;
  this.sourceFile = getSourceFileName(node);
  this.inputStart = new FilePosition(
      getStartLineno(node), getStartCharIndex(node));
  this.outputStart = mapping.start;
  this.outputEnd = mapping.end;
}
 
Example #16
Source File: SourceMapGeneratorStage.java    From j2cl with Apache License 2.0 2 votes vote down vote up
/**
 * Converts a j2cl File Position to a JsCompiler sourcemap File Position.
 *
 * @param j2clFilePosition
 * @return JsCompiler sourcemap File Position
 */
private static FilePosition toFilePosition(com.google.j2cl.common.FilePosition j2clFilePosition) {
  return new FilePosition(j2clFilePosition.getLine(), j2clFilePosition.getColumn());
}