Java Code Examples for com.google.javascript.rhino.Node#getLength()

The following examples show how to use com.google.javascript.rhino.Node#getLength() . 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: SourceExtractor.java    From clutz with MIT License 6 votes vote down vote up
/**
 * Gets the original literal code for a node or <code>null</code>.
 *
 * @param node The node to process.
 * @return The literal code for the node or <code>null</code> if it could not be determined.
 * @throws IOException Thrown if there was a problem loading the source file.
 */
@Nullable
public String getSource(Node node) throws IOException {
  String code = getFullFileSource(node);
  if (code == null) {
    return null;
  }

  int offset = node.getSourceOffset();
  int length = node.getLength();

  if (offset < 0) {
    return null;
  }

  return code.substring(offset, offset + length);
}