Search in sources :

Example 1 with ArrayDimensionTreeImpl

use of org.sonar.java.model.ArrayDimensionTreeImpl 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 ArrayDimensionTreeImpl

use of org.sonar.java.model.ArrayDimensionTreeImpl 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Optional (com.sonar.sslr.api.typed.Optional)2 ArrayDimensionTreeImpl (org.sonar.java.model.ArrayDimensionTreeImpl)2 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)2 AnnotationTreeImpl (org.sonar.java.model.declaration.AnnotationTreeImpl)2 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)2 ArrayAccessExpressionTreeImpl (org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl)1 NewArrayTreeImpl (org.sonar.java.model.expression.NewArrayTreeImpl)1