aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar juliexxia <juliexxia@google.com>2018-01-04 19:45:04 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-04 19:47:00 -0800
commit9e63684a58025d98bfe2f180d56ba7ece69545ae (patch)
tree295cbf9b37ddfa86a216e9131bb2db525875741d /src/main/java
parentbbebe815a2580904f095583364770f5f6bf71dbb (diff)
Automated rollback of commit 86b4532769c22cca2ed7068a60f3326beaad34af.
*** Reason for rollback *** Probably breaking //javatests/com/google/devtools/build/lib:Query2Tests *** Original change description *** Restructure how universeScope is used when testing configured query to mimick impending changes to the configured query interface (CL/179872445) which will pull build targets out of the query expression. Fill in testTopLevelTransitions on the way! PiperOrigin-RevId: 180880350
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java
index 9ba285ee29..b202bc326e 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryParser.java
@@ -45,7 +45,7 @@ import java.util.Map;
* | SET '(' WORD * ')'
* </pre>
*/
-public final class QueryParser {
+final class QueryParser {
private Lexer.Token token; // current lookahead token
private final List<Lexer.Token> tokens;
@@ -56,26 +56,23 @@ public final class QueryParser {
* Scan and parse the specified query expression.
*/
static QueryExpression parse(String query, QueryEnvironment<?> env) throws QueryException {
- HashMap<String, QueryFunction> functions = new HashMap<>();
- for (QueryFunction queryFunction : env.getFunctions()) {
- functions.put(queryFunction.getName(), queryFunction);
- }
- return parse(query, functions);
- }
-
- public static QueryExpression parse(String query, HashMap<String, QueryFunction> functions)
- throws QueryException {
- QueryParser parser = new QueryParser(Lexer.scan(query), functions);
+ QueryParser parser = new QueryParser(Lexer.scan(query), env);
QueryExpression expr = parser.parseExpression();
if (parser.token.kind != TokenKind.EOF) {
throw new QueryException("unexpected token '" + parser.token
- + "' after query expression '" + expr + "'");
+ + "' after query expression '" + expr + "'");
}
return expr;
}
- public QueryParser(List<Lexer.Token> tokens, HashMap<String, QueryFunction> functions) {
- this.functions = functions;
+ private QueryParser(List<Lexer.Token> tokens, QueryEnvironment<?> env) {
+ // TODO(bazel-team): We only need QueryEnvironment#getFunctions, consider refactoring users of
+ // QueryParser#parse to instead just pass in the set of functions to make testing, among other
+ // things, simpler.
+ this.functions = new HashMap<>();
+ for (QueryFunction queryFunction : env.getFunctions()) {
+ this.functions.put(queryFunction.getName(), queryFunction);
+ }
this.tokens = tokens;
this.tokenIterator = tokens.iterator();
nextToken();