Search in sources :

Example 1 with MemberSelectExpressionTreeImpl

use of org.sonar.java.model.expression.MemberSelectExpressionTreeImpl 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;
}
Also used : ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl) JavaTree(org.sonar.java.model.JavaTree)

Example 2 with MemberSelectExpressionTreeImpl

use of org.sonar.java.model.expression.MemberSelectExpressionTreeImpl 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;
}
Also used : Optional(com.sonar.sslr.api.typed.Optional) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) NewClassTreeImpl(org.sonar.java.model.expression.NewClassTreeImpl) ArrayAccessExpressionTreeImpl(org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl) TypeArgumentListTreeImpl(org.sonar.java.model.expression.TypeArgumentListTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl) MethodInvocationTreeImpl(org.sonar.java.model.expression.MethodInvocationTreeImpl)

Example 3 with MemberSelectExpressionTreeImpl

use of org.sonar.java.model.expression.MemberSelectExpressionTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newDotClassSelector.

public ExpressionTree newDotClassSelector(Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> dimensions, InternalSyntaxToken dotToken, InternalSyntaxToken classToken) {
    IdentifierTreeImpl identifier = new IdentifierTreeImpl(classToken);
    ArrayTypeTreeImpl nestedDimensions = newArrayTypeTree(dimensions);
    return new MemberSelectExpressionTreeImpl(nestedDimensions, dotToken, identifier);
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)

Example 4 with MemberSelectExpressionTreeImpl

use of org.sonar.java.model.expression.MemberSelectExpressionTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method newImportDeclaration.

public ImportTreeImpl newImportDeclaration(InternalSyntaxToken importToken, Optional<InternalSyntaxToken> staticToken, ExpressionTree qualifiedIdentifier, Optional<Tuple<InternalSyntaxToken, InternalSyntaxToken>> dotStar, InternalSyntaxToken semicolonToken) {
    ExpressionTree target = qualifiedIdentifier;
    if (dotStar.isPresent()) {
        IdentifierTreeImpl identifier = new IdentifierTreeImpl(dotStar.get().second());
        InternalSyntaxToken dotToken = dotStar.get().first();
        target = new MemberSelectExpressionTreeImpl(qualifiedIdentifier, dotToken, identifier);
    }
    InternalSyntaxToken staticKeyword = staticToken.orNull();
    return new ImportTreeImpl(importToken, staticKeyword, target, semicolonToken);
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ImportTreeImpl(org.sonar.java.model.JavaTree.ImportTreeImpl) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)

Example 5 with MemberSelectExpressionTreeImpl

use of org.sonar.java.model.expression.MemberSelectExpressionTreeImpl in project sonar-java by SonarSource.

the class TreeFactory method basicClassExpression.

public ExpressionTree basicClassExpression(PrimitiveTypeTreeImpl basicType, Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> dimensions, InternalSyntaxToken dotToken, InternalSyntaxToken classToken) {
    // 15.8.2. Class Literals
    // int.class
    // int[].class
    IdentifierTreeImpl classIdentifier = new IdentifierTreeImpl(classToken);
    ArrayTypeTreeImpl nestedDimensions = newArrayTypeTree(dimensions);
    TypeTree typeTree = applyDim(basicType, nestedDimensions);
    return new MemberSelectExpressionTreeImpl((ExpressionTree) typeTree, dotToken, classIdentifier);
}
Also used : ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)

Aggregations

IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)5 MemberSelectExpressionTreeImpl (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)5 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)3 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)3 ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)2 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)2 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)2 Optional (com.sonar.sslr.api.typed.Optional)1 JavaTree (org.sonar.java.model.JavaTree)1 ImportTreeImpl (org.sonar.java.model.JavaTree.ImportTreeImpl)1 ArrayAccessExpressionTreeImpl (org.sonar.java.model.expression.ArrayAccessExpressionTreeImpl)1 MethodInvocationTreeImpl (org.sonar.java.model.expression.MethodInvocationTreeImpl)1 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)1 TypeArgumentListTreeImpl (org.sonar.java.model.expression.TypeArgumentListTreeImpl)1