use of org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method applySelectors.
private static ExpressionTree applySelectors(ExpressionTree primary, Optional<List<Tuple<Optional<InternalSyntaxToken>, ExpressionTree>>> selectors) {
ExpressionTree result = primary;
if (selectors.isPresent()) {
for (Tuple<Optional<InternalSyntaxToken>, ExpressionTree> tuple : selectors.get()) {
Optional<InternalSyntaxToken> dotTokenOptional = tuple.first();
ExpressionTree selector = tuple.second();
if (dotTokenOptional.isPresent()) {
InternalSyntaxToken dotToken = dotTokenOptional.get();
if (selector.is(Kind.IDENTIFIER)) {
IdentifierTreeImpl identifier = (IdentifierTreeImpl) selector;
result = new MemberSelectExpressionTreeImpl(result, dotToken, identifier);
} else {
MethodInvocationTreeImpl methodInvocation = (MethodInvocationTreeImpl) selector;
IdentifierTreeImpl identifier = (IdentifierTreeImpl) methodInvocation.methodSelect();
MemberSelectExpressionTreeImpl memberSelect = new MemberSelectExpressionTreeImpl(result, dotToken, identifier);
result = new MethodInvocationTreeImpl(memberSelect, methodInvocation.typeArguments(), (ArgumentListTreeImpl) methodInvocation.arguments());
}
} else if (selector.is(Kind.NEW_CLASS)) {
NewClassTreeImpl newClass = (NewClassTreeImpl) selector;
result = newClass.completeWithEnclosingExpression(result);
} else if (selector.is(Kind.ARRAY_ACCESS_EXPRESSION)) {
ArrayAccessExpressionTreeImpl arrayAccess = (ArrayAccessExpressionTreeImpl) selector;
result = arrayAccess.complete(result);
} else if (selector.is(Kind.MEMBER_SELECT)) {
MemberSelectExpressionTreeImpl memberSelect = (MemberSelectExpressionTreeImpl) selector;
result = memberSelect.completeWithExpression(result);
} else {
throw new IllegalStateException();
}
}
}
return result;
}
use of org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl 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());
}
Aggregations