Search in sources :

Example 1 with AnnotationTreeImpl

use of org.sonar.java.model.declaration.AnnotationTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newArrayCreatorWithInitializer.

public NewArrayTreeImpl newArrayCreatorWithInitializer(InternalSyntaxToken openBracketToken, InternalSyntaxToken closeBracketToken, Optional<List<Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>>>> dimensions, NewArrayTreeImpl partial) {
    ImmutableList.Builder<ArrayDimensionTree> dDimensionsBuilder = ImmutableList.builder();
    dDimensionsBuilder.add(new ArrayDimensionTreeImpl(openBracketToken, null, closeBracketToken));
    if (dimensions.isPresent()) {
        for (Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>> dim : dimensions.get()) {
            List<AnnotationTreeImpl> annotations = dim.first().or(ImmutableList.<AnnotationTreeImpl>of());
            Tuple<InternalSyntaxToken, InternalSyntaxToken> brackets = dim.second();
            dDimensionsBuilder.add(new ArrayDimensionTreeImpl(annotations, brackets.first(), null, brackets.second()));
        }
    }
    return partial.completeDimensions(dDimensionsBuilder.build());
}
Also used : AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) Optional(com.sonar.sslr.api.typed.Optional) ImmutableList(com.google.common.collect.ImmutableList) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) ArrayDimensionTreeImpl(org.sonar.java.model.ArrayDimensionTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 2 with AnnotationTreeImpl

use of org.sonar.java.model.declaration.AnnotationTreeImpl 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 3 with AnnotationTreeImpl

use of org.sonar.java.model.declaration.AnnotationTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newArrayTypeTreeWithAnnotations.

private static ArrayTypeTreeImpl newArrayTypeTreeWithAnnotations(TypeTree type, Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>> dim) {
    List<AnnotationTreeImpl> annotations = dim.first().or(ImmutableList.<AnnotationTreeImpl>of());
    InternalSyntaxToken openBracketToken = dim.second().first();
    InternalSyntaxToken closeBracketToken = dim.second().second();
    return new ArrayTypeTreeImpl(type, annotations, openBracketToken, closeBracketToken);
}
Also used : AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 4 with AnnotationTreeImpl

use of org.sonar.java.model.declaration.AnnotationTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newArrayCreatorWithDimension.

public NewArrayTreeImpl newArrayCreatorWithDimension(InternalSyntaxToken openBracketToken, ExpressionTree expression, InternalSyntaxToken closeBracketToken, Optional<List<ArrayAccessExpressionTreeImpl>> arrayAccesses, Optional<List<Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>>>> dims) {
    ImmutableList.Builder<ArrayDimensionTree> dimensions = ImmutableList.builder();
    dimensions.add(new ArrayDimensionTreeImpl(openBracketToken, expression, closeBracketToken));
    if (arrayAccesses.isPresent()) {
        for (ArrayAccessExpressionTreeImpl arrayAccess : arrayAccesses.get()) {
            dimensions.add(arrayAccess.dimension());
        }
    }
    if (dims.isPresent()) {
        for (Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>> dim : dims.get()) {
            Tuple<InternalSyntaxToken, InternalSyntaxToken> brackets = dim.second();
            List<AnnotationTreeImpl> annotations = dim.first().or(ImmutableList.<AnnotationTreeImpl>of());
            dimensions.add(new ArrayDimensionTreeImpl(annotations, brackets.first(), null, brackets.second()));
        }
    }
    return new NewArrayTreeImpl(dimensions.build(), InitializerListTreeImpl.emptyList());
}
Also used : NewArrayTreeImpl(org.sonar.java.model.expression.NewArrayTreeImpl) Optional(com.sonar.sslr.api.typed.Optional) ImmutableList(com.google.common.collect.ImmutableList) ArrayDimensionTreeImpl(org.sonar.java.model.ArrayDimensionTreeImpl) AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) ArrayAccessExpressionTreeImpl(org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Example 5 with AnnotationTreeImpl

use of org.sonar.java.model.declaration.AnnotationTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newArrayTypeTree.

@CheckForNull
private static ArrayTypeTreeImpl newArrayTypeTree(Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> dims) {
    ArrayTypeTreeImpl result = null;
    if (dims.isPresent()) {
        for (Tuple<InternalSyntaxToken, InternalSyntaxToken> dim : dims.get()) {
            InternalSyntaxToken openBracketToken = dim.first();
            InternalSyntaxToken closeBracketToken = dim.second();
            result = new ArrayTypeTreeImpl(result, ImmutableList.<AnnotationTreeImpl>of(), openBracketToken, closeBracketToken);
        }
    }
    return result;
}
Also used : AnnotationTreeImpl(org.sonar.java.model.declaration.AnnotationTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) CheckForNull(javax.annotation.CheckForNull)

Aggregations

AnnotationTreeImpl (org.sonar.java.model.declaration.AnnotationTreeImpl)5 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)4 ImmutableList (com.google.common.collect.ImmutableList)2 Optional (com.sonar.sslr.api.typed.Optional)2 ArrayDimensionTreeImpl (org.sonar.java.model.ArrayDimensionTreeImpl)2 ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)2 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)2 ActionParser (com.sonar.sslr.api.typed.ActionParser)1 CheckForNull (javax.annotation.CheckForNull)1 Test (org.junit.Test)1 JavaNodeBuilder (org.sonar.java.ast.parser.JavaNodeBuilder)1 TreeFactory (org.sonar.java.ast.parser.TreeFactory)1 EnumConstantTreeImpl (org.sonar.java.model.declaration.EnumConstantTreeImpl)1 ArrayAccessExpressionTreeImpl (org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl)1 NewArrayTreeImpl (org.sonar.java.model.expression.NewArrayTreeImpl)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