Search in sources :

Example 6 with UnaryExpressionTree

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

the class LiteralUtils method intLiteralValue.

@CheckForNull
public static Integer intLiteralValue(ExpressionTree expression) {
    if (expression.is(Tree.Kind.INT_LITERAL)) {
        return intLiteralValue((LiteralTree) expression);
    }
    if (expression.is(Tree.Kind.UNARY_MINUS, Tree.Kind.UNARY_PLUS)) {
        UnaryExpressionTree unaryExp = (UnaryExpressionTree) expression;
        Integer subExpressionIntValue = intLiteralValue(unaryExp.expression());
        return expression.is(Tree.Kind.UNARY_MINUS) ? minus(subExpressionIntValue) : subExpressionIntValue;
    }
    return null;
}
Also used : UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) CheckForNull(javax.annotation.CheckForNull)

Example 7 with UnaryExpressionTree

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

the class IncrementDecrementInSubExpressionCheck method visitExpressionStatement.

@Override
public void visitExpressionStatement(ExpressionStatementTree tree) {
    ExpressionTree expressionTree = tree.expression();
    if (isIncrementOrDecrement(expressionTree)) {
        UnaryExpressionTree unaryExpressionTree = (UnaryExpressionTree) expressionTree;
        expressionTree = unaryExpressionTree.expression();
    }
    scan(expressionTree);
}
Also used : UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree)

Example 8 with UnaryExpressionTree

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

the class DoublePrefixOperatorCheck method visitNode.

@Override
public void visitNode(Tree tree) {
    UnaryExpressionTree exprTree = (UnaryExpressionTree) tree;
    if (alreadyReported(exprTree)) {
        return;
    }
    ExpressionTree expr = ExpressionUtils.skipParentheses(exprTree.expression());
    if (exprTree.is(expr.kind())) {
        UnaryExpressionTree child = (UnaryExpressionTree) expr;
        if (child.is(Tree.Kind.BITWISE_COMPLEMENT) && !ExpressionUtils.skipParentheses(child.expression()).is(Tree.Kind.BITWISE_COMPLEMENT)) {
            return;
        }
        prefixSet.add(child);
        reportIssue(exprTree.operatorToken(), child.operatorToken(), "Remove multiple operator prefixes.");
    }
}
Also used : UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree)

Aggregations

UnaryExpressionTree (org.sonar.plugins.java.api.tree.UnaryExpressionTree)8 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)5 CheckForNull (javax.annotation.CheckForNull)2 Test (org.junit.Test)2 ExpressionStatementTree (org.sonar.plugins.java.api.tree.ExpressionStatementTree)2 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)1 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)1 MethodInvocationTree (org.sonar.plugins.java.api.tree.MethodInvocationTree)1 ReturnStatementTree (org.sonar.plugins.java.api.tree.ReturnStatementTree)1