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;
}
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);
}
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.");
}
}
Aggregations