public static StatementChunker build() { return StatementChunker.builder() .ignore(from("import"), to(";")) .ignore(from("package"), to(";")) .statement(new BridgeWithExceptionTokenMatcher("{", "}", ";")) .ignore(token("}")) .ignore(token("{")) .ignore(token(";")) .statement(from("@"), anyToken(), opt(bridge("(", ")"))) .statement(from("do")) .statement(from("if"), bridge("(", ")")) .statement(from("else"), token("if"), bridge("(", ")")) .statement(from("else")) .statement(from("for"), bridge("(", ")")) .statement(from("while"), bridge("(", ")")) .statement(from("try"), bridge("(", ")")) .statement(from("case"), to(";", "{", "}"), forgetLastToken()) .statement(from("default"), to(";", "{", "}"), forgetLastToken()) .statement(to(";", "{", "}"), forgetLastToken()) .build(); }
@Test public void shouldCreateMatchers() { assertThat(TokenMatcherFactory.anyToken(), instanceOf(AnyTokenMatcher.class)); assertThat(TokenMatcherFactory.bridge("(", ")"), instanceOf(BridgeTokenMatcher.class)); assertThat(TokenMatcherFactory.forgetLastToken(), instanceOf(ForgetLastTokenMatcher.class)); assertThat(TokenMatcherFactory.from("if"), instanceOf(ExactTokenMatcher.class)); assertThat(TokenMatcherFactory.opt(mock(TokenMatcher.class)), instanceOf(OptTokenMatcher.class)); assertThat(TokenMatcherFactory.to(";"), instanceOf(UptoTokenMatcher.class)); assertThat(TokenMatcherFactory.token(";"), instanceOf(ExactTokenMatcher.class)); }
public static StatementChunker build() { return StatementChunker.builder() .ignore(from("import"), to(";")) .ignore(from("package"), to(";")) .statement(new BridgeWithExceptionTokenMatcher("{", "}", ";")) .ignore(token("}")) .ignore(token("{")) .ignore(token(";")) .statement(from("@"), anyToken(), opt(bridge("(", ")"))) .statement(from("do")) .statement(from("if"), bridge("(", ")")) .statement(from("else"), token("if"), bridge("(", ")")) .statement(from("else")) .statement(from("for"), bridge("(", ")")) .statement(from("while"), bridge("(", ")")) .statement(from("try"), bridge("(", ")")) .statement(from("case"), to(";", "{", "}"), forgetLastToken()) .statement(from("default"), to(";", "{", "}"), forgetLastToken()) .statement(to(";", "{", "}"), forgetLastToken()) .build(); }