use of org.sonar.plugins.java.api.tree.TypeTree in project sonar-java by SonarSource.
the class JunitMethodDeclarationCheck method visitMethod.
private void visitMethod(MethodTree methodTree) {
String name = methodTree.simpleName().name();
TypeTree returnType = methodTree.returnType();
if (JUNIT_SETUP.equals(name) || JUNIT_TEARDOWN.equals(name)) {
checkSetupTearDownSignature(methodTree);
} else if (JUNIT_SUITE.equals(name)) {
checkSuiteSignature(methodTree);
} else if ((returnType != null && returnType.symbolType().isSubtypeOf("junit.framework.Test")) || areVerySimilarStrings(JUNIT_SUITE, name)) {
addIssueForMethodBadName(methodTree, JUNIT_SUITE, name);
} else if (areVerySimilarStrings(JUNIT_SETUP, name)) {
addIssueForMethodBadName(methodTree, JUNIT_SETUP, name);
} else if (areVerySimilarStrings(JUNIT_TEARDOWN, name)) {
addIssueForMethodBadName(methodTree, JUNIT_TEARDOWN, name);
}
}
use of org.sonar.plugins.java.api.tree.TypeTree in project sonar-java by SonarSource.
the class EqualsNotOverriddenInSubclassCheck method parentClassImplementsEquals.
private static boolean parentClassImplementsEquals(ClassTree tree) {
TypeTree superClass = tree.superClass();
if (superClass != null) {
Type superClassType = superClass.symbolType();
while (superClassType.symbol().isTypeSymbol() && !superClassType.is("java.lang.Object")) {
Symbol.TypeSymbol superClassSymbol = superClassType.symbol();
if (hasNotFinalEqualsMethod(superClassSymbol)) {
return true;
}
superClassType = superClassSymbol.superClass();
}
}
return false;
}
use of org.sonar.plugins.java.api.tree.TypeTree in project sonar-java by SonarSource.
the class DisallowedClassCheck method visitClass.
@Override
public void visitClass(ClassTree classTree) {
TypeTree superClass = classTree.superClass();
if (superClass != null) {
String superClassTypeName = superClass.symbolType().fullyQualifiedName();
checkIfDisallowed(superClassTypeName, superClass);
}
super.visitClass(classTree);
}
use of org.sonar.plugins.java.api.tree.TypeTree in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest method provides_with_modules.
@Test
public void provides_with_modules() {
ProvidesDirectiveTree exports = providesDirective("provides org.MyInterface with com.MyInterface, MyInterface2;");
assertThat(exports.kind()).isEqualTo(Tree.Kind.PROVIDES_DIRECTIVE);
assertThat(exports.directiveKeyword().text()).isEqualTo("provides");
TypeTree typeName = exports.typeName();
assertThat(typeName.is(Tree.Kind.MEMBER_SELECT)).isTrue();
MemberSelectExpressionTree mset = (MemberSelectExpressionTree) typeName;
assertThat(((IdentifierTree) mset.expression()).name()).isEqualTo("org");
assertThat(mset.identifier().name()).isEqualTo("MyInterface");
assertThat(exports.withKeyword().text()).isEqualTo("with");
ListTree<TypeTree> typeNames = exports.typeNames();
assertThat(typeNames).hasSize(2);
assertThat(((MemberSelectExpressionTree) typeNames.get(0)).identifier().name()).isEqualTo("MyInterface");
assertThat(typeNames.separators()).hasSize(1);
assertThat(typeNames.separators().iterator().next().text()).isEqualTo(",");
assertThat(((IdentifierTree) typeNames.get(1)).name()).isEqualTo("MyInterface2");
assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
use of org.sonar.plugins.java.api.tree.TypeTree in project sonar-java by SonarSource.
the class UsesDirectiveTreeImplTest method simple_uses.
@Test
public void simple_uses() {
UsesDirectiveTree exports = moduleDirective("uses foo.MyInterface;");
assertThat(exports.kind()).isEqualTo(Tree.Kind.USES_DIRECTIVE);
assertThat(exports.directiveKeyword().text()).isEqualTo("uses");
TypeTree typeName = exports.typeName();
assertThat(typeName.is(Tree.Kind.MEMBER_SELECT)).isTrue();
assertThat(((MemberSelectExpressionTree) typeName).identifier().name()).isEqualTo("MyInterface");
assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
Aggregations