use of org.sonar.plugins.java.api.tree.NewClassTree in project sonar-java by SonarSource.
the class ImmediateReverseBoxingCheck method visitNode.
@Override
public void visitNode(Tree tree) {
if (!hasSemantic()) {
return;
}
if (tree.is(Tree.Kind.METHOD_INVOCATION)) {
visitMethodInvocationTree((MethodInvocationTree) tree);
} else if (tree.is(Tree.Kind.VARIABLE)) {
VariableTree variableTree = (VariableTree) tree;
ExpressionTree initializer = variableTree.initializer();
if (initializer != null) {
checkExpression(initializer, variableTree.type().symbolType());
}
} else if (tree.is(Tree.Kind.ASSIGNMENT)) {
AssignmentExpressionTree assignmentTree = (AssignmentExpressionTree) tree;
checkExpression(assignmentTree.expression(), assignmentTree.symbolType());
} else {
NewClassTree newClassTree = (NewClassTree) tree;
Symbol.TypeSymbol classSymbol = wrapperClassSymbol(newClassTree);
if (classSymbol != null) {
ExpressionTree arg0 = newClassTree.arguments().get(0);
checkForUnboxing(arg0);
checkForUselessUnboxing(newClassTree.symbolType(), newClassTree.identifier(), arg0);
}
}
}
use of org.sonar.plugins.java.api.tree.NewClassTree in project sonar-java by SonarSource.
the class ImmediateReverseBoxingCheck method checkForBoxing.
private void checkForBoxing(ExpressionTree expression) {
if (expression.is(Tree.Kind.NEW_CLASS)) {
NewClassTree newClassTree = (NewClassTree) expression;
Symbol.TypeSymbol classSymbol = wrapperClassSymbol(newClassTree);
if (classSymbol != null) {
ExpressionTree boxingArg = newClassTree.arguments().get(0);
if (boxingArg.symbolType().isPrimitive()) {
addBoxingIssue(newClassTree, classSymbol, boxingArg);
}
}
} else if (expression.is(Tree.Kind.METHOD_INVOCATION)) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expression;
if (isValueOfInvocation(methodInvocationTree)) {
ExpressionTree boxingArg = methodInvocationTree.arguments().get(0);
addBoxingIssue(expression, methodInvocationTree.symbol().owner(), boxingArg);
}
}
}
use of org.sonar.plugins.java.api.tree.NewClassTree in project sonar-java by SonarSource.
the class Measurer method visitNode.
@Override
public void visitNode(Tree tree) {
if (isClassTree(tree)) {
classes++;
classTrees.push((ClassTree) tree);
}
if (tree.is(Tree.Kind.NEW_CLASS) && ((NewClassTree) tree).classBody() != null) {
classes--;
}
if (tree.is(Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR) && classTrees.peek().simpleName() != null) {
// don't count methods in anonymous classes.
MethodTree methodTree = (MethodTree) tree;
methods++;
int methodComplexity = context.getComplexityNodes(methodTree).size();
methodComplexityDistribution.add(methodComplexity);
complexityInMethods += methodComplexity;
}
}
Aggregations