diff options
author | Francois-Rene Rideau <tunes@google.com> | 2015-03-02 17:12:45 +0000 |
---|---|---|
committer | Ulf Adams <ulfjack@google.com> | 2015-03-05 14:16:48 +0000 |
commit | edf7bdb0e4e62c75a8ac889ebfc01519af1c20e4 (patch) | |
tree | ff155146938646c17371763edd3808373d85e9c8 /src/main/java/com/google | |
parent | 39fc88c22c09312882e84e73756801cb71c2e440 (diff) |
Publish a static ASTNode setLocation
--
MOS_MIGRATED_REVID=87519507
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java | 6 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Parser.java | 11 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java b/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java index 81ca5847b3..2fa492ee99 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ASTNode.java @@ -37,6 +37,12 @@ public abstract class ASTNode implements Serializable { 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. diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java index 93d6a06a05..b8fb203351 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java @@ -330,16 +330,13 @@ class Parser { } // 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. |