Search in sources :

Example 1 with AssignmentExpressionTreeImpl

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

the class TreeFactory method assignmentExpression.

// End of statements
// Expressions
public ExpressionTree assignmentExpression(ExpressionTree expression, Optional<List<OperatorAndOperand>> operatorAndOperands) {
    if (!operatorAndOperands.isPresent()) {
        return expression;
    }
    ExpressionTree result = null;
    InternalSyntaxToken lastOperator = null;
    for (OperatorAndOperand operatorAndOperand : Lists.reverse(operatorAndOperands.get())) {
        if (lastOperator == null) {
            result = operatorAndOperand.operand();
        } else {
            result = new AssignmentExpressionTreeImpl(kindMaps.getAssignmentOperator((JavaPunctuator) lastOperator.getGrammarRuleKey()), operatorAndOperand.operand(), lastOperator, result);
        }
        lastOperator = operatorAndOperand.operator();
    }
    result = new AssignmentExpressionTreeImpl(kindMaps.getAssignmentOperator((JavaPunctuator) lastOperator.getGrammarRuleKey()), expression, lastOperator, result);
    return result;
}
Also used : ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) AssignmentExpressionTreeImpl(org.sonar.java.model.expression.AssignmentExpressionTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Aggregations

InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)1 AssignmentExpressionTreeImpl (org.sonar.java.model.expression.AssignmentExpressionTreeImpl)1 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)1