use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class OpensDirectiveTreeImplTest method simple_opens.
@Test
public void simple_opens() {
OpensDirectiveTree exports = moduleDirective("opens foo;");
assertThat(exports.kind()).isEqualTo(Tree.Kind.OPENS_DIRECTIVE);
assertThat(exports.directiveKeyword().text()).isEqualTo("opens");
assertThat(((IdentifierTree) exports.packageName()).name()).isEqualTo("foo");
assertThat(exports.toKeyword()).isNull();
assertThat(exports.moduleNames()).isEmpty();
assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class RequiresDirectiveTreeImplTest method transitive_as_name.
@Test
public void transitive_as_name() {
RequiresDirectiveTree requires = requireDirective("requires transitive;");
assertThat(requires.kind()).isEqualTo(Tree.Kind.REQUIRES_DIRECTIVE);
assertThat(requires.directiveKeyword().text()).isEqualTo("requires");
assertThat(requires.modifiers()).isEmpty();
assertThat(requires.moduleName().stream().map(IdentifierTree::name)).containsExactly("transitive");
assertThat(requires.semicolonToken().text()).isEqualTo(";");
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class RequiresDirectiveTreeImplTest method transitive_as_name_with_static.
@Test
public void transitive_as_name_with_static() {
RequiresDirectiveTree requires = requireDirective("requires static transitive;");
assertThat(requires.kind()).isEqualTo(Tree.Kind.REQUIRES_DIRECTIVE);
assertThat(requires.directiveKeyword().text()).isEqualTo("requires");
assertThat(requires.modifiers()).hasSize(1);
assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.STATIC)).isTrue();
assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.TRANSITIVE)).isFalse();
assertThat(requires.moduleName().stream().map(IdentifierTree::name)).containsExactly("transitive");
assertThat(requires.semicolonToken().text()).isEqualTo(";");
}
use of org.sonar.plugins.java.api.tree.IdentifierTree in project sonar-java by SonarSource.
the class RequiresDirectiveTreeImplTest method requires.
@Test
public void requires() {
RequiresDirectiveTree requires = requireDirective("requires static transitive foo.bar;");
assertThat(requires.kind()).isEqualTo(Tree.Kind.REQUIRES_DIRECTIVE);
assertThat(requires.directiveKeyword().text()).isEqualTo("requires");
assertThat(requires.modifiers()).hasSize(2);
assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.STATIC)).isTrue();
assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.TRANSITIVE)).isTrue();
ModuleNameTree moduleName = requires.moduleName();
assertThat(moduleName).hasSize(2);
assertThat(moduleName.stream().map(IdentifierTree::name)).containsExactly("foo", "bar");
assertThat(moduleName.separators()).hasSize(1);
assertThat(requires.semicolonToken().text()).isEqualTo(";");
}
use of org.sonar.plugins.java.api.tree.IdentifierTree 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();
}
}
Aggregations