use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class BadConstantNameCheck method visitNode.
@Override
public void visitNode(Tree tree) {
ClassTree classTree = (ClassTree) tree;
for (Tree member : classTree.members()) {
if (member.is(Tree.Kind.VARIABLE) && hasSemantic()) {
VariableTree variableTree = (VariableTree) member;
Type symbolType = variableTree.type().symbolType();
if (isConstantType(symbolType) && (classTree.is(Tree.Kind.INTERFACE, Tree.Kind.ANNOTATION_TYPE) || isStaticFinal(variableTree))) {
checkName(variableTree);
}
} else if (member.is(Tree.Kind.ENUM_CONSTANT)) {
checkName((VariableTree) member);
}
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class BadTestClassNameCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
IdentifierTree simpleName = classTree.simpleName();
if (hasInvalidName(simpleName) && hasTestMethod(classTree.members())) {
reportIssue(simpleName, "Rename class \"" + simpleName + "\" to match the regular expression: '" + format + "'");
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class SerializableContract method hasSpecialHandlingSerializationMethods.
public static boolean hasSpecialHandlingSerializationMethods(ClassTree classTree) {
boolean hasWriteObject = false;
boolean hasReadObject = false;
String classFullyQualifiedName = classTree.symbol().type().fullyQualifiedName();
for (Tree member : classTree.members()) {
MethodMatcher writeObjectMatcher = writeObjectMatcher(classFullyQualifiedName);
MethodMatcher readObjectMatcher = readObjectMatcher(classFullyQualifiedName);
if (member.is(Tree.Kind.METHOD)) {
MethodTree methodTree = (MethodTree) member;
if (ModifiersUtils.hasModifier(methodTree.modifiers(), Modifier.PRIVATE)) {
hasWriteObject |= writeObjectMatcher.matches(methodTree) && methodThrows(methodTree, "java.io.IOException");
hasReadObject |= readObjectMatcher.matches(methodTree) && methodThrows(methodTree, "java.io.IOException", "java.lang.ClassNotFoundException");
}
}
}
return hasReadObject && hasWriteObject;
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class MethodNameSameAsClassCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
super.visitClass(tree);
IdentifierTree classSimpleName = tree.simpleName();
if (classSimpleName == null) {
return;
}
String className = classSimpleName.name();
for (Tree member : tree.members()) {
if (member.is(Tree.Kind.METHOD)) {
IdentifierTree simpleName = ((MethodTree) member).simpleName();
if (className.equals(simpleName.name())) {
context.reportIssue(this, simpleName, "Rename this method to prevent any misunderstanding or make it a constructor.");
}
}
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class JavaPropertiesHelperTest method firstExpression.
private ExpressionTree firstExpression(String code) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse("class A { " + code + "}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
ClassTree firstType = (ClassTree) compilationUnitTree.types().get(0);
StatementTree firstStatement = ((MethodTree) firstType.members().get(0)).block().body().get(0);
return ((ExpressionStatementTree) firstStatement).expression();
}
Aggregations