org.antlr.v4.runtime.BailErrorStrategy Java Examples
The following examples show how to use
org.antlr.v4.runtime.BailErrorStrategy.
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: Pql2Compiler.java From incubator-pinot with Apache License 2.0 | 6 votes |
public static AstNode buildAst(String expression) { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); lexer.removeErrorListeners(); lexer.addErrorListener(ERROR_LISTENER); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(ERROR_LISTENER); // Parse ParseTree parseTree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); Pql2AstListener listener = new Pql2AstListener(expression); walker.walk(listener, parseTree); AstNode rootNode = listener.getRootNode(); return rootNode; }
Example #2
Source File: LogInstruction.java From onedev with MIT License | 6 votes |
public static InstructionContext parse(String instructionString) { CharStream is = CharStreams.fromString(instructionString); LogInstructionLexer lexer = new LogInstructionLexer(is); lexer.removeErrorListeners(); lexer.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new RuntimeException("Malformed log instruction"); } }); CommonTokenStream tokens = new CommonTokenStream(lexer); LogInstructionParser parser = new LogInstructionParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); return parser.instruction(); }
Example #3
Source File: EnumParseListenerTest.java From protostuff-compiler with Apache License 2.0 | 6 votes |
private Enum parseEnumBlock(String input) { CharStream stream = CharStreams.fromString(input); ProtoLexer lexer = new ProtoLexer(stream); lexer.removeErrorListeners(); lexer.addErrorListener(TestUtils.ERROR_LISTENER); CommonTokenStream tokenStream = new CommonTokenStream(lexer); ProtoParser parser = new ProtoParser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.addErrorListener(TestUtils.ERROR_LISTENER); ProtoContext context = new ProtoContext("test.proto"); Proto proto = new Proto(); context.push(proto); EnumParseListener enumParseListener = new EnumParseListener(tokenStream, context); OptionParseListener optionParseListener = new OptionParseListener(tokenStream, context); parser.addParseListener(enumParseListener); parser.addParseListener(optionParseListener); parser.enumBlock(); return proto.getEnums().get(0); }
Example #4
Source File: ParserModule.java From protostuff-compiler with Apache License 2.0 | 6 votes |
@Override protected void configure() { bind(Importer.class).to(ImporterImpl.class); bind(FileDescriptorLoader.class).to(FileDescriptorLoaderImpl.class); bind(ANTLRErrorListener.class).to(ParseErrorLogger.class); bind(ANTLRErrorStrategy.class).to(BailErrorStrategy.class); bind(ProtoContext.class) .annotatedWith(Names.named(DESCRIPTOR_PROTO)) .toProvider(DefaultDescriptorProtoProvider.class); Multibinder<ProtoContextPostProcessor> postProcessors = Multibinder .newSetBinder(binder(), ProtoContextPostProcessor.class); postProcessors.addBinding().to(ImportsPostProcessor.class); postProcessors.addBinding().to(TypeRegistratorPostProcessor.class); postProcessors.addBinding().to(TypeResolverPostProcessor.class); postProcessors.addBinding().to(ExtensionRegistratorPostProcessor.class); postProcessors.addBinding().to(OptionsPostProcessor.class); postProcessors.addBinding().to(UserTypeValidationPostProcessor.class); install(new FactoryModuleBuilder() .implement(FileReader.class, MultiPathFileReader.class) .build(FileReaderFactory.class)); }
Example #5
Source File: FishParserFactory.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
static FishParser.ScriptContext parse(CharStream cs) { FishLexer lexer = new FishLexer(cs); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.setTokenSource(lexer); FishParser parser = new FishParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); FishParser.ScriptContext script = parser.script(); return script; }
Example #6
Source File: Pql2Compiler.java From incubator-pinot with Apache License 2.0 | 5 votes |
public AstNode parseToAstNode(String expression) { CharStream charStream = new ANTLRInputStream(expression); PQL2Lexer lexer = new PQL2Lexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); PQL2Parser parser = new PQL2Parser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); // Parse Pql2AstListener listener = new Pql2AstListener(expression); new ParseTreeWalker().walk(listener, parser.expression()); return listener.getRootNode(); }
Example #7
Source File: TestSQLAnalyzer.java From tajo with Apache License 2.0 | 5 votes |
private static Expr parseExpr(String sql) { ANTLRInputStream input = new ANTLRInputStream(sql); SQLLexer lexer = new SQLLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); SQLParser parser = new SQLParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); parser.setBuildParseTree(true); SQLAnalyzer visitor = new SQLAnalyzer(); SQLParser.Value_expressionContext context = parser.value_expression(); return visitor.visitValue_expression(context); }
Example #8
Source File: ForceUtils.java From datacollector with Apache License 2.0 | 5 votes |
public static SOQLParser.StatementContext getStatementContext(String query) { SOQLLexer lexer = new SOQLLexer(new ANTLRInputStream(query)); CommonTokenStream tokens = new CommonTokenStream(lexer); SOQLParser parser = new SOQLParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); return parser.statement(); }
Example #9
Source File: JsonPathCompiler.java From JsonSurfer with MIT License | 5 votes |
public static JsonPath compile(String path) { JsonPathLexer lexer = new JsonPathLexer(CharStreams.fromString(path)); CommonTokenStream tokens = new CommonTokenStream(lexer); JsonPathParser parser = new JsonPathParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); JsonPathParser.PathContext tree = parser.path(); JsonPathCompiler compiler = new JsonPathCompiler(); compiler.visit(tree); return compiler.pathBuilder.build(); }
Example #10
Source File: FormulaParser.java From LogicNG with Apache License 2.0 | 5 votes |
/** * Sets the internal lexer and the parser. * @param lexer the lexer * @param parser the parser */ void setLexerAndParser(final Lexer lexer, final ParserWithFormula parser) { this.lexer = lexer; this.parser = parser; this.parser.setFormulaFactory(this.f); this.lexer.removeErrorListeners(); this.parser.removeErrorListeners(); this.parser.setErrorHandler(new BailErrorStrategy()); }
Example #11
Source File: CoreQueryParser.java From heroic with Apache License 2.0 | 5 votes |
private QueryListener parse(Function<HeroicQueryParser, ParserRuleContext> op, String input) { final HeroicQueryLexer lexer = new HeroicQueryLexer(new ANTLRInputStream(input)); final CommonTokenStream tokens = new CommonTokenStream(lexer); final HeroicQueryParser parser = new HeroicQueryParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); final ParserRuleContext context; try { context = op.apply(parser); } catch (final ParseCancellationException e) { if (!(e.getCause() instanceof RecognitionException)) { throw e; } throw toParseException((RecognitionException) e.getCause()); } final QueryListener listener = new QueryListener(); ParseTreeWalker.DEFAULT.walk(listener, context); final Token last = lexer.getToken(); if (last.getType() != Token.EOF) { throw new ParseException( String.format("garbage at end of string: '%s'", last.getText()), null, last.getLine(), last.getCharPositionInLine()); } return listener; }
Example #12
Source File: SQLParserExecutor.java From shardingsphere with Apache License 2.0 | 5 votes |
private ParseASTNode twoPhaseParse() { SQLParser sqlParser = SQLParserFactory.newInstance(databaseTypeName, sql); try { ((Parser) sqlParser).setErrorHandler(new BailErrorStrategy()); ((Parser) sqlParser).getInterpreter().setPredictionMode(PredictionMode.SLL); return (ParseASTNode) sqlParser.parse(); } catch (final ParseCancellationException ex) { ((Parser) sqlParser).reset(); ((Parser) sqlParser).setErrorHandler(new DefaultErrorStrategy()); ((Parser) sqlParser).getInterpreter().setPredictionMode(PredictionMode.LL); return (ParseASTNode) sqlParser.parse(); } }
Example #13
Source File: IndexRQL.java From indexr with Apache License 2.0 | 5 votes |
private static ParseTree parseSQL(String sql) { CharStream charStream = new ANTLRInputStream(sql); RQLLexer lexer = new RQLLexer(charStream); lexer.setTokenFactory(new CommonTokenFactory(true)); TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer); RQLParser parser = new RQLParser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); return parser.root(); }
Example #14
Source File: ExprGenerator.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
public static Operator gen(GeneratorContext ctx, Planner cursorMeta, String expr) { CharStream cs = new ANTLRInputStream(expr); MysqlLexer lexer = new MysqlLexer(cs); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.setTokenSource(lexer); MysqlParser parser = new MysqlParser(tokens); parser.setErrorHandler(new BailErrorStrategy()); MysqlParser.ExprContext rule = parser.expr(); return gen(ctx, cursorMeta, rule); }
Example #15
Source File: GrammarParserInterpreter.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** Derive a new parser from an old one that has knowledge of the grammar. * The Grammar object is used to correctly compute outer alternative * numbers for parse tree nodes. A parser of the same type is created * for subclasses of {@link ParserInterpreter}. */ public static ParserInterpreter deriveTempParserInterpreter(Grammar g, Parser originalParser, TokenStream tokens) { ParserInterpreter parser; if (originalParser instanceof ParserInterpreter) { Class<? extends ParserInterpreter> c = originalParser.getClass().asSubclass(ParserInterpreter.class); try { Constructor<? extends ParserInterpreter> ctor = c.getConstructor(Grammar.class, ATN.class, TokenStream.class); parser = ctor.newInstance(g, originalParser.getATN(), originalParser.getTokenStream()); } catch (Exception e) { throw new IllegalArgumentException("can't create parser to match incoming "+originalParser.getClass().getSimpleName(), e); } } else { // must've been a generated parser char[] serializedAtn = ATNSerializer.getSerializedAsChars(originalParser.getATN()); ATN deserialized = new ATNDeserializer().deserialize(serializedAtn); parser = new ParserInterpreter(originalParser.getGrammarFileName(), originalParser.getVocabulary(), Arrays.asList(originalParser.getRuleNames()), deserialized, tokens); } parser.setInputStream(tokens); // Make sure that we don't get any error messages from using this temporary parser parser.setErrorHandler(new BailErrorStrategy()); parser.removeErrorListeners(); parser.removeParseListeners(); parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION); return parser; }
Example #16
Source File: CollectdTags.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Map<String, Any2<String, Number>> parse(String pattern) { class DescriptiveErrorListener extends BaseErrorListener { public List<String> errors = new ArrayList<>(); @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg)); } } final DescriptiveErrorListener error_listener = new DescriptiveErrorListener(); final CollectdTagsLexer lexer = new CollectdTagsLexer(new ANTLRInputStream(pattern)); lexer.removeErrorListeners(); lexer.addErrorListener(error_listener); final CollectdTagsParser parser = new CollectdTagsParser(new UnbufferedTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(error_listener); parser.setErrorHandler(new BailErrorStrategy()); final CollectdTagsParser.ExprContext result = parser.expr(); if (result.exception != null) throw new IllegalArgumentException("errors during parsing: " + pattern, result.exception); else if (!error_listener.errors.isEmpty()) throw new IllegalArgumentException("syntax errors during parsing:\n" + String.join("\n", error_listener.errors.stream().map(s -> " " + s).collect(Collectors.toList()))); return result.result; }
Example #17
Source File: StringTemplate.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static StringTemplate fromString(String pattern) { class DescriptiveErrorListener extends BaseErrorListener { public List<String> errors = new ArrayList<>(); @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg)); } } final DescriptiveErrorListener error_listener = new DescriptiveErrorListener(); final StringSubstitutionLexer lexer = new StringSubstitutionLexer(CharStreams.fromString(pattern)); lexer.removeErrorListeners(); lexer.addErrorListener(error_listener); final StringSubstitutionParser parser = new StringSubstitutionParser(new UnbufferedTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(error_listener); parser.setErrorHandler(new BailErrorStrategy()); final StringSubstitutionParser.ExprContext result = parser.expr(); if (result.exception != null) throw new IllegalArgumentException("errors during parsing: " + pattern, result.exception); else if (!error_listener.errors.isEmpty()) throw new IllegalArgumentException("syntax errors during parsing:\n" + String.join("\n", error_listener.errors.stream().map(s -> " " + s).collect(Collectors.toList()))); return result.s; }
Example #18
Source File: Interpolative.java From onedev with MIT License | 5 votes |
public static Interpolative parse(String interpolativeString) { CharStream is = CharStreams.fromString(interpolativeString); InterpolativeLexer lexer = new InterpolativeLexer(is); lexer.removeErrorListeners(); lexer.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new RuntimeException("Malformed interpolative: " + interpolativeString); } }); CommonTokenStream tokens = new CommonTokenStream(lexer); InterpolativeParser parser = new InterpolativeParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); List<Segment> segments = new ArrayList<>(); for (SegmentContext segment: parser.interpolative().segment()) { if (segment.Literal() != null) segments.add(new Segment(Type.LITERAL, segment.Literal().getText())); else segments.add(new Segment(Type.VARIABLE, FenceAware.unfence(segment.Variable().getText()))); } return new Interpolative(segments); }
Example #19
Source File: PatternSet.java From onedev with MIT License | 5 votes |
public static PatternSet parse(@Nullable String patternSetString) { Set<String> includes = new HashSet<>(); Set<String> excludes = new HashSet<>(); if (patternSetString != null) { CharStream is = CharStreams.fromString(patternSetString); PatternSetLexer lexer = new PatternSetLexer(is); lexer.removeErrorListeners(); lexer.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new RuntimeException("Malformed pattern set"); } }); CommonTokenStream tokens = new CommonTokenStream(lexer); PatternSetParser parser = new PatternSetParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); PatternsContext patternsContext = parser.patterns(); for (PatternContext pattern: patternsContext.pattern()) { String value; if (pattern.Quoted() != null) value = FenceAware.unfence(pattern.Quoted().getText()); else value = pattern.NQuoted().getText(); value = StringUtils.unescape(value); if (pattern.Excluded() != null) excludes.add(value); else includes.add(value); } } return new PatternSet(includes, excludes); }
Example #20
Source File: UserMatch.java From onedev with MIT License | 5 votes |
public static UserMatch parse(@Nullable String userMatchString) { List<UserMatchCriteria> criterias = new ArrayList<>(); List<UserMatchCriteria> exceptCriterias = new ArrayList<>(); if (userMatchString != null) { CharStream is = CharStreams.fromString(userMatchString); UserMatchLexer lexer = new UserMatchLexer(is); lexer.removeErrorListeners(); lexer.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new RuntimeException("Malformed user match"); } }); CommonTokenStream tokens = new CommonTokenStream(lexer); UserMatchParser parser = new UserMatchParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); UserMatchContext userMatchContext = parser.userMatch(); for (CriteriaContext criteriaContext: userMatchContext.criteria()) criterias.add(getUserMatchCriteria(criteriaContext)); for (ExceptCriteriaContext exceptCriteriaContext: userMatchContext.exceptCriteria()) { exceptCriterias.add(getUserMatchCriteria(exceptCriteriaContext.criteria())); } } return new UserMatch(criterias, exceptCriterias); }
Example #21
Source File: ParseHelper.java From graphicsfuzz with Apache License 2.0 | 5 votes |
private static Translation_unitContext tryFastParse( InputStream inputStream, ParseTreeListener listener) throws IOException { GLSLParser parser = getParser(inputStream, listener); parser.setErrorHandler(new BailErrorStrategy()); parser.getInterpreter().setPredictionMode(PredictionMode.SLL); Translation_unitContext result = parser.translation_unit(); parser.getInterpreter().clearDFA(); return result; }
Example #22
Source File: Parser.java From graql with GNU Affero General Public License v3.0 | 4 votes |
private <CONTEXT extends ParserRuleContext, RETURN> RETURN parseQuery( String queryString, Function<GraqlParser, CONTEXT> parserMethod, Function<CONTEXT, RETURN> visitor ) { if (queryString == null || queryString.isEmpty()) { throw GraqlException.create("Query String is NULL or Empty"); } ErrorListener errorListener = ErrorListener.of(queryString); CharStream charStream = CharStreams.fromString(queryString); GraqlLexer lexer = new GraqlLexer(charStream); lexer.removeErrorListeners(); lexer.addErrorListener(errorListener); CommonTokenStream tokens = new CommonTokenStream(lexer); GraqlParser parser = new GraqlParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(errorListener); // BailErrorStrategy + SLL is a very fast parsing strategy for queries // that are expected to be correct. However, it may not be able to // provide detailed/useful error message, if at all. parser.setErrorHandler(new BailErrorStrategy()); parser.getInterpreter().setPredictionMode(PredictionMode.SLL); CONTEXT queryContext; try { queryContext = parserMethod.apply(parser); } catch (ParseCancellationException e) { // We parse the query one more time, with "strict strategy" : // DefaultErrorStrategy + LL_EXACT_AMBIG_DETECTION // This was not set to default parsing strategy, but it is useful // to produce detailed/useful error message parser.setErrorHandler(new DefaultErrorStrategy()); parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION); queryContext = parserMethod.apply(parser); throw GraqlException.create(errorListener.toString()); } return visitor.apply(queryContext); }
Example #23
Source File: DSLParserWrapper.java From SPADE with GNU General Public License v3.0 | 4 votes |
private ParseProgram fromCharStream(CharStream input) { DSLLexer lexer = new DSLLexer(input); DSLParser parser = new DSLParser(new CommonTokenStream(lexer)); parser.setErrorHandler(new BailErrorStrategy()); return parser.program().r; }
Example #24
Source File: ReviewRequirement.java From onedev with MIT License | 4 votes |
public static ReviewRequirement parse(@Nullable String requirementString, boolean validate) { List<User> users = new ArrayList<>(); Map<Group, Integer> groups = new LinkedHashMap<>(); if (requirementString != null) { CharStream is = CharStreams.fromString(requirementString); ReviewRequirementLexer lexer = new ReviewRequirementLexer(is); lexer.removeErrorListeners(); lexer.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new RuntimeException("Malformed review requirement"); } }); CommonTokenStream tokens = new CommonTokenStream(lexer); ReviewRequirementParser parser = new ReviewRequirementParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); RequirementContext requirementContext = parser.requirement(); for (CriteriaContext criteria: requirementContext.criteria()) { if (criteria.userCriteria() != null) { String userName = getValue(criteria.userCriteria().Value()); User user = OneDev.getInstance(UserManager.class).findByName(userName); if (user != null) { if (!users.contains(user)) users.add(user); else if (validate) throw new OneException("User '" + userName + "' is included multiple times"); } else if (validate) { throw new OneException("Unable to find user '" + userName + "'"); } } else if (criteria.groupCriteria() != null) { String groupName = getValue(criteria.groupCriteria().Value()); Group group = OneDev.getInstance(GroupManager.class).find(groupName); if (group != null) { if (!groups.containsKey(group)) { CountContext count = criteria.groupCriteria().count(); if (count != null) { if (count.DIGIT() != null) groups.put(group, Integer.parseInt(count.DIGIT().getText())); else groups.put(group, 0); } else { groups.put(group, 1); } } else if (validate) { throw new OneException("Group '" + groupName + "' is included multiple times"); } } else if (validate) { throw new OneException("Unable to find group '" + groupName + "'"); } } } } return new ReviewRequirement(users, groups); }
Example #25
Source File: CommitQuery.java From onedev with MIT License | 4 votes |
public static CommitQuery parse(Project project, @Nullable String queryString) { List<CommitCriteria> criterias = new ArrayList<>(); if (queryString != null) { CharStream is = CharStreams.fromString(queryString); CommitQueryLexer lexer = new CommitQueryLexer(is); lexer.removeErrorListeners(); lexer.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new RuntimeException("Malformed commit query", e); } }); CommonTokenStream tokens = new CommonTokenStream(lexer); CommitQueryParser parser = new CommitQueryParser(tokens); parser.removeErrorListeners(); parser.setErrorHandler(new BailErrorStrategy()); List<String> authorValues = new ArrayList<>(); List<String> committerValues = new ArrayList<>(); List<String> beforeValues = new ArrayList<>(); List<String> afterValues = new ArrayList<>(); List<String> pathValues = new ArrayList<>(); List<String> messageValues = new ArrayList<>(); List<Revision> revisions = new ArrayList<>(); for (CriteriaContext criteria: parser.query().criteria()) { if (criteria.authorCriteria() != null) { if (criteria.authorCriteria().AuthoredByMe() != null) authorValues.add(null); else authorValues.add(getValue(criteria.authorCriteria().Value())); } else if (criteria.committerCriteria() != null) { if (criteria.committerCriteria().CommittedByMe() != null) committerValues.add(null); else committerValues.add(getValue(criteria.committerCriteria().Value())); } else if (criteria.messageCriteria() != null) { messageValues.add(getValue(criteria.messageCriteria().Value())); } else if (criteria.pathCriteria() != null) { pathValues.add(getValue(criteria.pathCriteria().Value())); } else if (criteria.beforeCriteria() != null) { beforeValues.add(getValue(criteria.beforeCriteria().Value())); } else if (criteria.afterCriteria() != null) { afterValues.add(getValue(criteria.afterCriteria().Value())); } else if (criteria.revisionCriteria() != null) { String value; Revision.Scope scope; if (criteria.revisionCriteria().DefaultBranch() != null) value = project.getDefaultBranch(); else value = getValue(criteria.revisionCriteria().Value()); if (criteria.revisionCriteria().BUILD() != null) { String numberStr = value; if (numberStr.startsWith("#")) numberStr = numberStr.substring(1); if (NumberUtils.isDigits(numberStr)) { Build build = OneDev.getInstance(BuildManager.class).find(project, Long.parseLong(numberStr)); if (build == null) throw new OneException("Unable to find build: " + value); else value = build.getCommitHash(); } else { throw new OneException("Invalid build number: " + numberStr); } } if (criteria.revisionCriteria().SINCE() != null) scope = Revision.Scope.SINCE; else if (criteria.revisionCriteria().UNTIL() != null) scope = Revision.Scope.UNTIL; else scope = null; revisions.add(new Revision(value, scope, criteria.revisionCriteria().getText())); } } if (!authorValues.isEmpty()) criterias.add(new AuthorCriteria(authorValues)); if (!committerValues.isEmpty()) criterias.add(new CommitterCriteria(committerValues)); if (!pathValues.isEmpty()) criterias.add(new PathCriteria(pathValues)); if (!messageValues.isEmpty()) criterias.add(new MessageCriteria(messageValues)); if (!beforeValues.isEmpty()) criterias.add(new BeforeCriteria(beforeValues)); if (!afterValues.isEmpty()) criterias.add(new AfterCriteria(afterValues)); if (!revisions.isEmpty()) criterias.add(new RevisionCriteria(revisions)); } return new CommitQuery(criterias); }