use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method annotationIdentifier.
public TypeTree annotationIdentifier(InternalSyntaxToken firstIdentifier, Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> rests) {
List<InternalSyntaxToken> children = Lists.newArrayList();
children.add(firstIdentifier);
if (rests.isPresent()) {
for (Tuple<InternalSyntaxToken, InternalSyntaxToken> rest : rests.get()) {
children.add(rest.first());
children.add(rest.second());
}
}
JavaTree result = null;
InternalSyntaxToken dotToken = null;
for (InternalSyntaxToken child : children) {
if (!child.getGrammarRuleKey().equals(JavaTokenType.IDENTIFIER)) {
dotToken = child;
} else {
InternalSyntaxToken identifierToken = child;
if (result == null) {
result = new IdentifierTreeImpl(identifierToken);
} else {
IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
result = new MemberSelectExpressionTreeImpl((ExpressionTree) result, dotToken, identifier);
}
}
}
return (TypeTree) result;
}
use of org.sonar.java.model.expression.IdentifierTreeImpl 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.IdentifierTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newAnnotatedParameterizedIdentifier.
public ExpressionTree newAnnotatedParameterizedIdentifier(Optional<List<AnnotationTreeImpl>> annotations, InternalSyntaxToken identifierToken, Optional<TypeArgumentListTreeImpl> typeArguments) {
List<AnnotationTree> annotationList = ImmutableList.copyOf(annotations.or(ImmutableList.of()));
ExpressionTree result = new IdentifierTreeImpl(identifierToken);
if (typeArguments.isPresent()) {
result = new ParameterizedTypeTreeImpl((TypeTree) result, typeArguments.get()).complete(annotationList);
} else {
result = ((IdentifierTreeImpl) result).complete(annotationList);
}
return result;
}
use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newVariableDeclaratorId.
public VariableTreeImpl newVariableDeclaratorId(InternalSyntaxToken identifierToken, Optional<List<Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>>>> dims) {
IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
ArrayTypeTreeImpl nestedDimensions = newArrayTypeTreeWithAnnotations(dims);
return new VariableTreeImpl(identifier, nestedDimensions);
}
use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method completeVariableDeclarator.
public VariableTreeImpl completeVariableDeclarator(InternalSyntaxToken identifierToken, Optional<List<Tuple<Optional<List<AnnotationTreeImpl>>, Tuple<InternalSyntaxToken, InternalSyntaxToken>>>> dimensions, Optional<VariableTreeImpl> partial) {
IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
ArrayTypeTreeImpl nestedDimensions = newArrayTypeTreeWithAnnotations(dimensions);
if (partial.isPresent()) {
return partial.get().completeIdentifierAndDims(identifier, nestedDimensions);
} else {
return new VariableTreeImpl(identifier, nestedDimensions);
}
}
Aggregations