use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class ClassComplexityCheck method visitNode.
@Override
public void visitNode(Tree tree) {
int size = context.getComplexityNodes(tree).size();
if (size > max) {
ClassTree classTree = (ClassTree) tree;
Tree report = classTree.simpleName() == null ? classTree.openBraceToken() : classTree.simpleName();
reportIssue(report, "The Cyclomatic Complexity of this class is " + size + " which is greater than " + max + " authorized.", ImmutableList.<JavaFileScannerContext.Location>of(), size - max);
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class SubClassStaticReferenceCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
ClassTree classTree = (ClassTree) tree;
Type classType = classTree.symbol().type();
List<Tree> members = classTree.members();
// JLS 12.4. Initialization of Classes and Interfaces:
// Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables)
// declared in the class.
checkStaticVariables(members, classType);
checkStaticInitializers(members, classType);
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class StaticFieldInitializationCheck method visitNode.
@Override
public void visitNode(Tree tree) {
switch(tree.kind()) {
case CLASS:
classWithSynchronizedMethod.push(hasSynchronizedMethod((ClassTree) tree));
break;
case STATIC_INITIALIZER:
withinStaticInitializer.push(true);
break;
case METHOD:
methodUsesLocks.push(false);
break;
case METHOD_INVOCATION:
if (locks.anyMatch((MethodInvocationTree) tree) && methodUsesLocks.size() != 1) {
methodUsesLocks.pop();
methodUsesLocks.push(true);
}
break;
case ASSIGNMENT:
AssignmentExpressionTree aet = (AssignmentExpressionTree) tree;
if (hasSemantic() && aet.variable().is(Tree.Kind.IDENTIFIER) && !isInSyncBlock() && !isInStaticInitializer() && !isUsingLock() && isInClassWithSynchronizedMethod()) {
IdentifierTree variable = (IdentifierTree) aet.variable();
if (isStaticNotVolatileObject(variable)) {
reportIssue(variable, "Synchronize this lazy initialization of '" + variable.name() + "'");
}
}
break;
default:
}
super.visitNode(tree);
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class RightCurlyBraceStartLineCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (tree.is(Tree.Kind.BLOCK, Tree.Kind.STATIC_INITIALIZER, Tree.Kind.INITIALIZER)) {
BlockTree blockTree = (BlockTree) tree;
checkBlockBody(blockTree.openBraceToken(), blockTree.closeBraceToken(), blockTree.body());
} else {
ClassTree classTree = (ClassTree) tree;
checkBlockBody(classTree.openBraceToken(), classTree.closeBraceToken(), classTree.members());
}
}
use of org.sonar.plugins.java.api.tree.ClassTree in project sonar-java by SonarSource.
the class UndocumentedApiCheck method isPublicApi.
private boolean isPublicApi(Tree tree) {
Tree currentParent = currentParents.peek();
if (tree.is(CLASS_KINDS)) {
classTrees.push((ClassTree) tree);
currentParents.push(tree);
} else if (tree.is(METHOD_KINDS)) {
currentParents.push(tree);
}
return PublicApiChecker.isPublicApi(currentParent, tree);
}
Aggregations