use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class MethodTreeImplTest method override_without_annotation_should_be_detected.
@Test
public void override_without_annotation_should_be_detected() {
CompilationUnitTree cut = createTree("interface T { int m(); } class A implements T { int m(){return 0;}}");
ClassTree interfaze = (ClassTree) cut.types().get(0);
MethodTreeImpl methodInterface = (MethodTreeImpl) interfaze.members().get(0);
ClassTree clazz = (ClassTree) cut.types().get(1);
MethodTreeImpl methodClazz = (MethodTreeImpl) clazz.members().get(0);
assertThat(methodInterface.isOverriding()).isFalse();
assertThat(methodClazz.isOverriding()).isTrue();
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class AnonymousClassShouldBeLambdaCheck method visitNewClass.
@Override
public void visitNewClass(NewClassTree tree) {
super.visitNewClass(tree);
ClassTree classBody = tree.classBody();
if (classBody != null) {
TypeTree identifier = tree.identifier();
if (!useThisIdentifier(classBody) && !enumConstants.contains(identifier) && isSAM(classBody)) {
context.reportIssue(this, identifier, "Make this anonymous inner class a lambda" + context.getJavaVersion().java8CompatibilityMessage());
}
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ChildClassShadowFieldCheck method visitNode.
@Override
public void visitNode(Tree tree) {
TypeTree superClass = ((ClassTree) tree).superClass();
if (superClass != null) {
Symbol.TypeSymbol superclassSymbol = superClass.symbolType().symbol();
((ClassTree) tree).members().stream().filter(m -> m.is(Kind.VARIABLE)).map(VariableTree.class::cast).map(VariableTree::simpleName).forEach(fieldSimpleName -> {
if (!IGNORED_FIELDS.contains(fieldSimpleName.name())) {
checkForIssue(superclassSymbol, fieldSimpleName);
}
});
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ClassFieldCountCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
long fieldCount = classTree.members().stream().filter(member -> member.is(Tree.Kind.VARIABLE) && shouldBeCounted((VariableTree) member)).count();
if (fieldCount > threshold) {
String message = String.format("Refactor this class so it has no more than %d %sfields, rather than the %d it currently has.", threshold, countNonPublicFields ? "" : "public ", fieldCount);
reportIssue(reportOnClassTree(classTree), message);
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ReassignmentFinderTest method classTree.
private ClassTree classTree(String classBody) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(classBody);
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ClassTree) compilationUnitTree.types().get(0);
}
Aggregations