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());
}
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");
}
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);
}
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());
}
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;
}
Aggregations