Search in sources :

Example 1 with ActionParser

use of com.sonar.sslr.api.typed.ActionParser 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 2 with ActionParser

use of com.sonar.sslr.api.typed.ActionParser in project sonar-java by SonarSource.

the class PublicApiCheckerTest method setUp.

@Before
public void setUp() {
    ActionParser p = JavaParser.createParser();
    cut = (CompilationUnitTree) p.parse(new File("src/test/files/ast/PublicApi.java"));
}
Also used : ActionParser(com.sonar.sslr.api.typed.ActionParser) File(java.io.File) Before(org.junit.Before)

Aggregations

ActionParser (com.sonar.sslr.api.typed.ActionParser)2 File (java.io.File)1 Before (org.junit.Before)1 Test (org.junit.Test)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 LexerlessGrammarBuilder (org.sonar.sslr.grammar.LexerlessGrammarBuilder)1