Skip to content

Commit

Permalink
SONARJAVA-1272 Restore complexity api breaking change and deprecate s…
Browse files Browse the repository at this point in the history
…ome methods

From JavaFileScannerContext deprecate:
* int getComplexity(Tree tree)
* int getMethodComplexity(ClassTree enclosingClass, MethodTree methodTree)
* void addNoSonarLines(Set<Integer> lines)
  • Loading branch information
mpaladin committed Oct 6, 2015
1 parent 3414687 commit 4d4390c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public List<Tree.Kind> nodesToVisit() {

@Override
public void visitNode(Tree tree) {
List<Tree> complexity = context.getComplexity(tree);
List<Tree> complexity = context.getComplexityNodes(tree);
int size = complexity.size();
if (size > max) {
List<JavaFileScannerContext.Location> flow = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<Tree.Kind> nodesToVisit() {
@Override
public void visitNode(Tree tree) {
MethodTree methodTree = (MethodTree) tree;
List<Tree> complexity = context.getComplexity(methodTree);
List<Tree> complexity = context.getComplexityNodes(methodTree);
int size = complexity.size();
if (size > max) {
List<JavaFileScannerContext.Location> flow = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions java-squid/src/main/java/org/sonar/java/Measurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void scanFile(JavaFileScannerContext context) {
context.addNoSonarLines(commentLinesVisitor.noSonarLines());
super.scanFile(context);
//leave file.
int fileComplexity = context.getComplexity(context.getTree()).size();
int fileComplexity = context.getComplexityNodes(context.getTree()).size();
saveMetricOnFile(CoreMetrics.CLASSES, classes);
saveMetricOnFile(CoreMetrics.FUNCTIONS, methods);
saveMetricOnFile(CoreMetrics.ACCESSORS, accessors);
Expand Down Expand Up @@ -145,7 +145,7 @@ public void visitNode(Tree tree) {
accessors++;
} else {
methods++;
int methodComplexity = context.getMethodComplexity(classTrees.peek(), methodTree).size();
int methodComplexity = context.getMethodComplexityNodes(classTrees.peek(), methodTree).size();
methodComplexityDistribution.add(methodComplexity);
complexityInMethods += methodComplexity;
}
Expand Down
14 changes: 12 additions & 2 deletions java-squid/src/main/java/org/sonar/java/model/VisitorsBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,22 @@ public File getFile() {
}

@Override
public List<Tree> getComplexity(Tree tree) {
public int getComplexity(Tree tree) {
return getComplexityNodes(tree).size();
}

@Override
public int getMethodComplexity(ClassTree enclosingClass, MethodTree methodTree) {
return getMethodComplexityNodes(enclosingClass, methodTree).size();
}

@Override
public List<Tree> getComplexityNodes(Tree tree) {
return complexityVisitor.scan(tree);
}

@Override
public List<Tree> getMethodComplexity(ClassTree enclosingClass, MethodTree methodTree) {
public List<Tree> getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree) {
return complexityVisitor.scan(enclosingClass, methodTree);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,26 @@ public interface JavaFileScannerContext {

File getFile();

List<Tree> getComplexity(Tree tree);

List<Tree> getMethodComplexity(ClassTree enclosingClass, MethodTree methodTree);

/**
* @deprecated As of release 3.6, replaced by {@link #getComplexityNodes(Tree)}
*/
@Deprecated
int getComplexity(Tree tree);

/**
* @deprecated As of release 3.6, replaced by {@link #getMethodComplexityNodes(ClassTree, MethodTree)}
*/
@Deprecated
int getMethodComplexity(ClassTree enclosingClass, MethodTree methodTree);

List<Tree> getComplexityNodes(Tree tree);

List<Tree> getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree);

/**
* @deprecated As of release 3.6, this method was not intended on a public interface
*/
@Deprecated
void addNoSonarLines(Set<Integer> lines);

void reportIssue(JavaCheck javaCheck, Tree tree, String message);
Expand Down

0 comments on commit 4d4390c

Please sign in to comment.