Search in sources :

Example 11 with LexerlessGrammarBuilder

use of org.sonar.sslr.grammar.LexerlessGrammarBuilder in project sonar-java by SonarSource.

the class EnumDeclarationTest method ok.

@Test
public void ok() {
    LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
    assertThat(b, JavaLexer.ENUM_DECLARATION).matches("enum identifier implements Foo, Bar<Integer> {}");
}
Also used : LexerlessGrammarBuilder(org.sonar.sslr.grammar.LexerlessGrammarBuilder) Test(org.junit.Test)

Example 12 with LexerlessGrammarBuilder

use of org.sonar.sslr.grammar.LexerlessGrammarBuilder in project sonar-java by SonarSource.

the class EnumConstantTest method test_annotation.

@Test
public void test_annotation() {
    LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
    ActionParser<Tree> parser = new ActionParser<>(StandardCharsets.UTF_8, b, JavaGrammar.class, new TreeFactory(), new JavaNodeBuilder(), JavaLexer.ENUM_CONSTANT);
    EnumConstantTreeImpl node = (EnumConstantTreeImpl) parser.parse("@Foo CONSTANT");
    assertThat(node.modifiers().size()).isEqualTo(1);
    assertThat(((IdentifierTree) ((AnnotationTreeImpl) node.modifiers().get(0)).annotationType()).identifierToken().text()).isEqualTo("Foo");
}
Also used : AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) ActionParser(com.sonar.sslr.api.typed.ActionParser) TreeFactory(org.sonar.java.ast.parser.TreeFactory) LexerlessGrammarBuilder(org.sonar.sslr.grammar.LexerlessGrammarBuilder) JavaNodeBuilder(org.sonar.java.ast.parser.JavaNodeBuilder) Tree(org.sonar.plugins.java.api.tree.Tree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) EnumConstantTreeImpl(org.sonar.java.model.declaration.EnumConstantTreeImpl) Test(org.junit.Test)

Example 13 with LexerlessGrammarBuilder

use of org.sonar.sslr.grammar.LexerlessGrammarBuilder in project sonar-java by SonarSource.

the class EnumConstantTest method ok.

@Test
public void ok() {
    LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
    assertThat(b, JavaLexer.ENUM_CONSTANT).matches("identifier").matches("identifier,").matches("@Foo identifier").matches("@Foo identifier()").matches("@Foo identifier {}").matches("@Foo identifier() {}");
}
Also used : LexerlessGrammarBuilder(org.sonar.sslr.grammar.LexerlessGrammarBuilder) Test(org.junit.Test)

Example 14 with LexerlessGrammarBuilder

use of org.sonar.sslr.grammar.LexerlessGrammarBuilder in project sonar-java by SonarSource.

the class LocalVariableDeclarationStatementTest method ok.

@Test
public void ok() {
    LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
    assertThat(b, JavaLexer.LOCAL_VARIABLE_DECLARATION_STATEMENT).matches("final int a ;").matches("@Foo List<Integer> a, b ;").matches("int a;");
}
Also used : LexerlessGrammarBuilder(org.sonar.sslr.grammar.LexerlessGrammarBuilder) Test(org.junit.Test)

Example 15 with LexerlessGrammarBuilder

use of org.sonar.sslr.grammar.LexerlessGrammarBuilder in project sonar-java by SonarSource.

the class BlockTest method ok.

@Test
public void ok() {
    LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
    assertThat(b, JavaLexer.BLOCK).matches("{ ; }").matches("{ int a; foo(); }");
}
Also used : LexerlessGrammarBuilder(org.sonar.sslr.grammar.LexerlessGrammarBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 LexerlessGrammarBuilder (org.sonar.sslr.grammar.LexerlessGrammarBuilder)22 ActionParser (com.sonar.sslr.api.typed.ActionParser)1 JavaNodeBuilder (org.sonar.java.ast.parser.JavaNodeBuilder)1 TreeFactory (org.sonar.java.ast.parser.TreeFactory)1 AnnotationTreeImpl (org.sonar.java.model.declaration.AnnotationTreeImpl)1 EnumConstantTreeImpl (org.sonar.java.model.declaration.EnumConstantTreeImpl)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1 Tree (org.sonar.plugins.java.api.tree.Tree)1