use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method declaration.
@Test
public void declaration() throws Exception {
String code = newCode("int foo() {", " int a = 0;", " return a;", "}");
List<StatementTree> statements = methodBody(code);
ExpressionTree aDeclarationInitializer = initializerFromVariableDeclarationStatement(statements.get(0));
assertThatLastReassignmentsOfReturnedVariableIsEqualTo(statements, aDeclarationInitializer);
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method assignement_with_parenthesis.
@Test
public void assignement_with_parenthesis() throws Exception {
String code = newCode("int foo() {", " int a;", " a = 0;", " int b = ((a));", " return a;", "}");
List<StatementTree> statements = methodBody(code);
ExpressionTree aAssignmentExpression = assignementExpressionFromStatement(statements.get(1));
assertThatLastReassignmentsOfReturnedVariableIsEqualTo(statements, aAssignmentExpression);
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method last_assignement_on_same_line.
@Test
public void last_assignement_on_same_line() throws Exception {
String code = newCode("int foo() {", " int a;", " a = 0;", " a = 1; return a;", "}");
List<StatementTree> statements = methodBody(code);
ExpressionTree secondAssignment = assignementExpressionFromStatement(statements.get(2));
assertThatLastReassignmentsOfReturnedVariableIsEqualTo(statements, secondAssignment);
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method assignement_with_other_variable.
@Test
public void assignement_with_other_variable() throws Exception {
String code = newCode("int foo() {", " int a;", " int b;", " a = 0;", " b = 0;", " return a;", "}");
List<StatementTree> statements = methodBody(code);
ExpressionTree aAssignmentExpression = assignementExpressionFromStatement(statements.get(2));
assertThatLastReassignmentsOfReturnedVariableIsEqualTo(statements, aAssignmentExpression);
}
use of org.sonar.plugins.java.api.tree.StatementTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method last_assignement.
@Test
public void last_assignement() throws Exception {
String code = newCode("int foo() {", " int a;", " a = 0;", " a = 1;", " return a;", "}");
List<StatementTree> statements = methodBody(code);
ExpressionTree secondAssignment = assignementExpressionFromStatement(statements.get(2));
assertThatLastReassignmentsOfReturnedVariableIsEqualTo(statements, secondAssignment);
}
Aggregations