TargetSelector { public static @Nullable TargetSelector parse(String value, MplSource source, MplCompilerContext context) { checkNotNull(value, "value == null!"); checkNotNull(source, "source == null!"); checkNotNull(context, "context == null!"); ANTLRInputStream input = new ANTLRInputStream(value); TargetSelectorLexer lexer = new TargetSelectorLexer(input); TokenStream tokens = new CommonTokenStream(lexer); TargetSelectorParser parser = new TargetSelectorParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object token, int line, int charPositionInLine, String message, RecognitionException cause) { context.addError(new CompilerException(source, message)); } }); SelectorContext ctx = parser.selector(); if (context.getErrors().isEmpty()) { TargetSelectorListenerImpl listener = new TargetSelectorListenerImpl(); new ParseTreeWalker().walk(listener, ctx); return listener.getResult(); } return null; } @GenerateMplPojoBuilder  TargetSelector(TargetSelectorType type, Map<String, String> arguments); static @Nullable TargetSelector parse(String value, MplSource source,
      MplCompilerContext context); TargetSelectorType getType(); Map<String, String> getArguments(); @Override String toString();  }
@Test public void test_parse__Value_cannot_contain_a_comma() { String value = "@e[name=bl,ub]"; TargetSelector actual = parse(value); assertThat(actual).isNull(); assertThat(lastContext.getErrors()).hasSize(1); CompilerException error = lastContext.getErrors().iterator().next(); assertThat(error.getSource()).isSameAs(lastSource); }
@Test public void test_parse__Value_cannot_contain_a_space() { String value = "@e[name=bl ub]"; TargetSelector actual = parse(value); assertThat(actual).isNull(); assertThat(lastContext.getErrors()).hasSize(1); CompilerException error = lastContext.getErrors().iterator().next(); assertThat(error.getSource()).isSameAs(lastSource); }
@Test public void test_parse__Value_cannot_contain_a_tab() { String value = "@e[name=bl\tub]"; TargetSelector actual = parse(value); assertThat(actual).isNull(); assertThat(lastContext.getErrors()).hasSize(1); CompilerException error = lastContext.getErrors().iterator().next(); assertThat(error.getSource()).isSameAs(lastSource); }
@Test public void test_parse__Value_cannot_contain_a_carriage_return() { String value = "@e[name=bl\rub]"; TargetSelector actual = parse(value); assertThat(actual).isNull(); assertThat(lastContext.getErrors()).hasSize(1); CompilerException error = lastContext.getErrors().iterator().next(); assertThat(error.getSource()).isSameAs(lastSource); }
@Test public void test_parse__Value_cannot_contain_a_new_line() { String value = "@e[name=bl\nub]"; TargetSelector actual = parse(value); assertThat(actual).isNull(); assertThat(lastContext.getErrors()).hasSize(1); CompilerException error = lastContext.getErrors().iterator().next(); assertThat(error.getSource()).isSameAs(lastSource); }