Search in sources :

Example 6 with Optional

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

Optional (com.sonar.sslr.api.typed.Optional)6 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)3 ArrayDimensionTreeImpl (org.sonar.java.model.ArrayDimensionTreeImpl)2 AnnotationTreeImpl (org.sonar.java.model.declaration.AnnotationTreeImpl)2 ArrayAccessExpressionTreeImpl (org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl)2 IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)2 NewArrayTreeImpl (org.sonar.java.model.expression.NewArrayTreeImpl)2 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)2 TypeArgumentListTreeImpl (org.sonar.java.model.expression.TypeArgumentListTreeImpl)2 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)2 EnumConstantTreeImpl (org.sonar.java.model.declaration.EnumConstantTreeImpl)1 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)1 MemberSelectExpressionTreeImpl (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)1 MethodInvocationTreeImpl (org.sonar.java.model.expression.MethodInvocationTreeImpl)1 ModifierTree (org.sonar.plugins.java.api.tree.ModifierTree)1 SyntaxToken (org.sonar.plugins.java.api.tree.SyntaxToken)1