use of org.sonar.java.model.expression.NewArrayTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newArrayInitializer.
public NewArrayTreeImpl newArrayInitializer(InternalSyntaxToken openBraceToken, Optional<InternalSyntaxToken> optionalComma, Optional<List<Tuple<ExpressionTree, Optional<InternalSyntaxToken>>>> rests, InternalSyntaxToken closeBraceToken) {
ImmutableList.Builder<ExpressionTree> initializers = ImmutableList.builder();
ImmutableList.Builder<SyntaxToken> separators = ImmutableList.builder();
if (optionalComma.isPresent()) {
separators.add(optionalComma.get());
}
if (rests.isPresent()) {
for (Tuple<ExpressionTree, Optional<InternalSyntaxToken>> rest : rests.get()) {
initializers.add(rest.first());
if (rest.second().isPresent()) {
separators.add(rest.second().get());
}
}
}
return new NewArrayTreeImpl(ImmutableList.<ArrayDimensionTree>of(), new InitializerListTreeImpl(initializers.build(), separators.build())).completeWithCurlyBraces(openBraceToken, closeBraceToken);
}
use of org.sonar.java.model.expression.NewArrayTreeImpl 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.expression.NewArrayTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newExpression.
public ExpressionTree newExpression(InternalSyntaxToken newToken, Optional<List<AnnotationTreeImpl>> annotations, ExpressionTree partial) {
TypeTree typeTree;
if (partial.is(Tree.Kind.NEW_CLASS)) {
NewClassTreeImpl newClassTree = (NewClassTreeImpl) partial;
newClassTree.completeWithNewKeyword(newToken);
typeTree = newClassTree.identifier();
} else {
NewArrayTreeImpl newArrayTree = (NewArrayTreeImpl) partial;
newArrayTree.completeWithNewKeyword(newToken);
typeTree = newArrayTree.type();
}
completeTypeTreeWithAnnotations(typeTree, annotations);
return partial;
}
Aggregations