Skip to content

Commit

Permalink
Publish a static ASTNode setLocation
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=87519507
  • Loading branch information
fare authored and ulfjack committed Mar 5, 2015
1 parent 39fc88c commit edf7bdb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public Location getLocation() {
return location;
}

/** @return the same node with its location set, in a slightly more fluent style */
public static <NODE extends ASTNode> NODE setLocation(Location location, NODE node) {
node.setLocation(location);
return node;
}

/**
* Print the syntax node in a form useful for debugging. The output is not
* precisely specified, and should not be used by pretty-printing routines.
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/google/devtools/build/lib/syntax/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,13 @@ private Ident makeErrorExpression(int start, int end) {
}

// Convenience wrapper around ASTNode.setLocation that returns the node.
private <NODE extends ASTNode> NODE
setLocation(NODE node, int startOffset, int endOffset) {
node.setLocation(lexer.createLocation(startOffset, endOffset));
return node;
private <NODE extends ASTNode> NODE setLocation(NODE node, Location location) {
return ASTNode.<NODE>setLocation(location, node);
}

// Another convenience wrapper method around ASTNode.setLocation
private <NODE extends ASTNode> NODE setLocation(NODE node, Location location) {
node.setLocation(location);
return node;
private <NODE extends ASTNode> NODE setLocation(NODE node, int startOffset, int endOffset) {
return setLocation(node, lexer.createLocation(startOffset, endOffset));
}

// Convenience method that uses end offset from the last node.
Expand Down

0 comments on commit edf7bdb

Please sign in to comment.