Search in sources :

Example 21 with ExpressionTree

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

the class AssignmentInSubExpressionCheck method skipChainedAssignments.

private ExpressionTree skipChainedAssignments(ExpressionTree expressionTree) {
    ExpressionTree tree = ExpressionUtils.skipParentheses(expressionTree);
    while (tree instanceof AssignmentExpressionTree) {
        AssignmentExpressionTree assignmentExpressionTree = (AssignmentExpressionTree) tree;
        scan(assignmentExpressionTree.variable());
        tree = ExpressionUtils.skipParentheses(assignmentExpressionTree.expression());
    }
    return tree;
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) LambdaExpressionTree(org.sonar.plugins.java.api.tree.LambdaExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree)

Example 22 with ExpressionTree

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

the class AssignmentInSubExpressionCheck method visitVariable.

@Override
public void visitVariable(VariableTree tree) {
    ExpressionTree initializer = tree.initializer();
    if (initializer != null) {
        ExpressionTree expressionTree = skipChainedAssignments(initializer);
        scan(expressionTree);
    }
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) LambdaExpressionTree(org.sonar.plugins.java.api.tree.LambdaExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree)

Example 23 with ExpressionTree

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

the class AvoidDESCheck method onMethodInvocationFound.

@Override
protected void onMethodInvocationFound(MethodInvocationTree mit) {
    ExpressionTree firstArg = mit.arguments().get(0);
    ExpressionTree defaultPropertyValue = JavaPropertiesHelper.retrievedPropertyDefaultValue(firstArg);
    if (defaultPropertyValue == null) {
        defaultPropertyValue = firstArg;
    }
    if (defaultPropertyValue.is(Tree.Kind.STRING_LITERAL)) {
        checkIssue(firstArg, (LiteralTree) defaultPropertyValue);
    }
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree)

Example 24 with ExpressionTree

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

the class SyntaxTreeDebug method argumentsString.

private static String argumentsString(Arguments syntaxNode) {
    StringBuilder buffer = new StringBuilder();
    boolean first = true;
    for (ExpressionTree expressionTree : syntaxNode) {
        if (first) {
            first = false;
        } else {
            buffer.append(',');
        }
        buffer.append(toString(expressionTree));
    }
    return buffer.toString();
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree) ConditionalExpressionTree(org.sonar.plugins.java.api.tree.ConditionalExpressionTree) ArrayAccessExpressionTree(org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree)

Example 25 with ExpressionTree

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

the class SyntaxTreeDebug method newInstanceString.

private static String newInstanceString(NewClassTree syntaxNode) {
    StringBuilder buffer = new StringBuilder("new ");
    buffer.append(syntaxNode.identifier().toString());
    buffer.append('(');
    boolean first = true;
    for (ExpressionTree argument : syntaxNode.arguments()) {
        if (first) {
            first = false;
        } else {
            buffer.append(',');
        }
        buffer.append(toString(argument));
    }
    buffer.append(')');
    return buffer.toString();
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree) ConditionalExpressionTree(org.sonar.plugins.java.api.tree.ConditionalExpressionTree) ArrayAccessExpressionTree(org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree)

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