use of org.sonar.plugins.java.api.tree.AssertStatementTree in project sonar-java by SonarSource.
the class AssertsOnParametersOfPublicMethodCheck method checkUsage.
private void checkUsage(IdentifierTree parameterUsage, MethodTree methodTree) {
Tree parameterParent = parameterUsage.parent();
while (!parameterParent.equals(methodTree) && !assertReported.contains(parameterParent)) {
if (parameterParent.is(Tree.Kind.ASSERT_STATEMENT)) {
assertReported.add((AssertStatementTree) parameterParent);
reportIssue(parameterParent, "Replace this assert with a proper check.");
return;
}
parameterParent = parameterParent.parent();
}
}
use of org.sonar.plugins.java.api.tree.AssertStatementTree in project sonar-java by SonarSource.
the class JavaTreeModelTest method assert_statement.
/**
* 14.10. The assert Statement
*/
@Test
public void assert_statement() {
AssertStatementTree tree = (AssertStatementTree) firstMethodFirstStatement("class T { void m() { assert true; } }");
assertThat(tree.is(Tree.Kind.ASSERT_STATEMENT)).isTrue();
assertThat(tree.assertKeyword().text()).isEqualTo("assert");
assertThat(tree.condition()).isNotNull();
assertThat(tree.colonToken()).isNull();
assertThat(tree.detail()).isNull();
assertThat(tree.semicolonToken().text()).isEqualTo(";");
assertThatChildrenIteratorHasSize(tree, 3);
tree = (AssertStatementTree) firstMethodFirstStatement("class T { void m() { assert true : \"detail\"; } }");
assertThat(tree.is(Tree.Kind.ASSERT_STATEMENT)).isTrue();
assertThat(tree.assertKeyword().text()).isEqualTo("assert");
assertThat(tree.condition()).isNotNull();
assertThat(tree.colonToken().text()).isEqualTo(":");
assertThat(tree.detail()).isNotNull();
assertThat(tree.semicolonToken().text()).isEqualTo(";");
assertThatChildrenIteratorHasSize(tree, 5);
}
Aggregations