Search in sources :

Example 16 with ExpressionTree

use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.

the class MethodInvocationTreeImpl method firstToken.

@Override
public SyntaxToken firstToken() {
    if (typeArguments() != null && methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
        ExpressionTree expression = ((MemberSelectExpressionTree) methodSelect).expression();
        SyntaxToken firstToken = expression.firstToken();
        if (firstToken != null) {
            return firstToken;
        }
    }
    return super.firstToken();
}
Also used : MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)

Example 17 with ExpressionTree

use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.

the class MemberSelectExpressionTreeImpl method completeWithExpression.

public MemberSelectExpressionTreeImpl completeWithExpression(ExpressionTree expression) {
    Preconditions.checkState(this.expression == null);
    ExpressionTree result = expression;
    if (nestedDimensions != null) {
        nestedDimensions.setLastChildType((TypeTree) expression);
        result = nestedDimensions;
    }
    this.expression = result;
    return this;
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)

Example 18 with ExpressionTree

use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.

the class AbsOnNegativeCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
        MethodInvocationTree methodTree = (MethodInvocationTree) tree;
        if (MATH_ABS_METHODS.anyMatch(methodTree)) {
            ExpressionTree firstArgument = methodTree.arguments().get(0);
            checkForIssue(firstArgument);
        }
    } else {
        ExpressionTree operand = ((UnaryExpressionTree) tree).expression();
        checkForIssue(operand);
    }
}
Also used : UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree)

Example 19 with ExpressionTree

use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.

the class CastArithmeticOperandCheck method visitAssignmentExpression.

@Override
public void visitAssignmentExpression(AssignmentExpressionTree aet) {
    if (aet.is(Tree.Kind.ASSIGNMENT)) {
        Type varType = aet.symbolType();
        ExpressionTree expr = aet.expression();
        checkExpression(varType, expr);
    }
    super.visitAssignmentExpression(aet);
}
Also used : Type(org.sonar.plugins.java.api.semantic.Type) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree)

Example 20 with ExpressionTree

use of org.sonar.plugins.java.api.tree.ExpressionTree in project sonar-java by SonarSource.

the class CastArithmeticOperandCheck method checkIntegerDivisionInsideFloatingPointExpression.

private boolean checkIntegerDivisionInsideFloatingPointExpression(BinaryExpressionTree integerDivision) {
    Tree parent = integerDivision.parent();
    while (parent instanceof ExpressionTree) {
        ExpressionTree expressionTree = (ExpressionTree) parent;
        if (isFloatingPoint(expressionTree.symbolType())) {
            context.reportIssue(this, integerDivision, "Cast one of the operands of this integer division to a \"double\".");
            return false;
        }
        parent = expressionTree.parent();
    }
    return true;
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) Tree(org.sonar.plugins.java.api.tree.Tree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) ReturnStatementTree(org.sonar.plugins.java.api.tree.ReturnStatementTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree)

Aggregations

ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)189 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)88 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)80 BinaryExpressionTree (org.sonar.plugins.java.api.tree.BinaryExpressionTree)66 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)50 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)44 UnaryExpressionTree (org.sonar.plugins.java.api.tree.UnaryExpressionTree)35 Symbol (org.sonar.plugins.java.api.semantic.Symbol)31 ArrayAccessExpressionTree (org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree)30 ConditionalExpressionTree (org.sonar.plugins.java.api.tree.ConditionalExpressionTree)30 Test (org.junit.Test)25 LambdaExpressionTree (org.sonar.plugins.java.api.tree.LambdaExpressionTree)24 ReturnStatementTree (org.sonar.plugins.java.api.tree.ReturnStatementTree)24 VariableTree (org.sonar.plugins.java.api.tree.VariableTree)23 Type (org.sonar.plugins.java.api.semantic.Type)21 ExpressionStatementTree (org.sonar.plugins.java.api.tree.ExpressionStatementTree)20 Tree (org.sonar.plugins.java.api.tree.Tree)20 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)17 StatementTree (org.sonar.plugins.java.api.tree.StatementTree)14 IfStatementTree (org.sonar.plugins.java.api.tree.IfStatementTree)13