aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-11-23 18:52:32 +0000
committerGodin <mandrikov@gmail.com>2010-11-23 18:52:32 +0000
commit9f8394b46a01f7ddac672afddd546ed6e82ccd7e (patch)
tree7645d0433f864c383f0509725000469724bcd81e /plugins
parentbb2cd28550c5c33d82473c7b8fb5fdadea80976f (diff)
downloadsonarqube-9f8394b46a01f7ddac672afddd546ed6e82ccd7e.tar.gz
sonarqube-9f8394b46a01f7ddac672afddd546ed6e82ccd7e.zip
SONAR-1845, SONAR-1931: Create a new Squid rules to check class and method complexity
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/MethodComplexityCheck.java44
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java48
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java47
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/ClassComplexityCheck.java (renamed from plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/ClassComplexityCheck.java)38
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/DITCheck.java (renamed from plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/bytecode/check/DITCheck.java)10
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/MethodComplexityCheck.java31
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/SquidCheck.java12
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/visitor/SquidVisitor.java28
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java22
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidRuleRepository.java12
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java (renamed from plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ClassComplexityCheckTest.java)6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java (renamed from plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/DITCheckTest.java)6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java (renamed from plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/MethodComplexityCheckTest.java)6
13 files changed, 214 insertions, 96 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/MethodComplexityCheck.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/MethodComplexityCheck.java
deleted file mode 100644
index 425c1dc6d59..00000000000
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/MethodComplexityCheck.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.sonar.java.ast.check;
-
-import org.sonar.check.IsoCategory;
-import org.sonar.check.Rule;
-import org.sonar.check.RuleProperty;
-import org.sonar.java.ast.visitor.MethodVisitor;
-import org.sonar.squid.api.CheckMessage;
-import org.sonar.squid.api.SourceCode;
-import org.sonar.squid.api.SourceFile;
-import org.sonar.squid.measures.Metric;
-
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
-
-import java.util.List;
-
-@Rule(key = "MethodComplexityCheck", name = "MethodComplexityCheck", isoCategory = IsoCategory.Maintainability)
-public class MethodComplexityCheck extends JavaAstCheck {
-
- @RuleProperty(description = "Threshold.")
- private Integer threshold;
-
- @Override
- public List<Integer> getWantedTokens() {
- return MethodVisitor.wantedTokens;
- }
-
- @Override
- public void leaveToken(DetailAST ast) {
- SourceCode currentResource = peekSourceCode();
- int complexity = currentResource.getInt(Metric.COMPLEXITY) + currentResource.getInt(Metric.BRANCHES) + 1;
- if (complexity > threshold) {
- CheckMessage message = new CheckMessage(this, "Method complexity exceeds " + threshold + ".");
- message.setLine(ast.getLineNo());
- message.setCost(complexity - threshold);
- SourceFile sourceFile = currentResource.getParent(SourceFile.class);
- sourceFile.log(message);
- }
- }
-
- public void setThreshold(int threshold) {
- this.threshold = threshold;
- }
-
-}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java
new file mode 100644
index 00000000000..deb6535ff27
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidScanner.java
@@ -0,0 +1,48 @@
+package org.sonar.java.squid;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.sonar.java.squid.check.SquidCheck;
+import org.sonar.java.squid.visitor.SquidVisitor;
+import org.sonar.squid.api.CodeScanner;
+import org.sonar.squid.api.CodeVisitor;
+import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.indexer.QueryByType;
+import org.sonar.squid.indexer.SquidIndex;
+
+public class SquidScanner extends CodeScanner<CodeVisitor> {
+
+ private SquidIndex indexer;
+
+ public SquidScanner(SquidIndex indexer) {
+ this.indexer = indexer;
+ }
+
+ public void scan() {
+ Collection<SourceCode> classes = indexer.search(new QueryByType(SourceClass.class));
+ notifySquidVisitors(classes);
+ }
+
+ private void notifySquidVisitors(Collection<SourceCode> classes) {
+ SquidVisitor[] visitorArray = getVisitors().toArray(new SquidVisitor[getVisitors().size()]);
+ for (SourceCode sourceClass : classes) {
+ SquidVisitorNotifier visitorNotifier = new SquidVisitorNotifier((SourceClass) sourceClass, visitorArray);
+ visitorNotifier.notifyVisitors(indexer);
+ }
+ }
+
+ @Override
+ public Collection<Class<? extends CodeVisitor>> getVisitorClasses() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void accept(CodeVisitor visitor) {
+ if (visitor instanceof SquidCheck) {
+ super.accept(visitor);
+ }
+ }
+
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java
new file mode 100644
index 00000000000..740db3c7a7d
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java
@@ -0,0 +1,47 @@
+package org.sonar.java.squid;
+
+import org.sonar.java.squid.visitor.SquidVisitor;
+import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.api.SourceMethod;
+import org.sonar.squid.indexer.SquidIndex;
+
+public class SquidVisitorNotifier {
+
+ private final SourceClass sourceClass;
+ private final SquidVisitor[] squidVisitors;
+
+ public SquidVisitorNotifier(SourceClass sourceClass, SquidVisitor[] squidVisitors) {
+ this.sourceClass = sourceClass;
+ this.squidVisitors = new SquidVisitor[squidVisitors.length];
+ System.arraycopy(squidVisitors, 0, this.squidVisitors, 0, squidVisitors.length);
+ }
+
+ public void notifyVisitors(SquidIndex indexer) {
+ for (SquidVisitor visitor : squidVisitors) {
+ visitor.setSquidIndex(indexer);
+ }
+ callVisitClass();
+ callVisitMethod();
+ }
+
+ private void callVisitClass() {
+ for (SquidVisitor visitor : squidVisitors) {
+ visitor.visitClass(sourceClass);
+ }
+ }
+
+ private void callVisitMethod() {
+ if (sourceClass.getChildren() == null) { // TODO Most probably SourceCode#hasChildren() shouldn't be protected
+ return;
+ }
+ for (SourceCode sourceCode : sourceClass.getChildren()) {
+ if (sourceCode instanceof SourceMethod) {
+ SourceMethod sourceMethod = (SourceMethod) sourceCode;
+ for (SquidVisitor visitor : squidVisitors) {
+ visitor.visitMethod(sourceMethod);
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/ClassComplexityCheck.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/ClassComplexityCheck.java
index 4a724126561..c529996cd19 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/check/ClassComplexityCheck.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/ClassComplexityCheck.java
@@ -18,54 +18,30 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.java.ast.check;
+package org.sonar.java.squid.check;
import org.sonar.check.IsoCategory;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
-import org.sonar.java.ast.visitor.ClassVisitor;
import org.sonar.squid.api.CheckMessage;
-import org.sonar.squid.api.SourceCode;
-import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.api.SourceClass;
import org.sonar.squid.measures.Metric;
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
-
-import java.util.List;
-
@Rule(key = "ClassComplexityCheck", name = "ClassComplexityCheck", isoCategory = IsoCategory.Maintainability)
-public class ClassComplexityCheck extends JavaAstCheck {
+public class ClassComplexityCheck extends SquidCheck {
@RuleProperty(description = "Threshold.")
private Integer threshold;
@Override
- public List<Integer> getWantedTokens() {
- return ClassVisitor.wantedTokens;
- }
-
- @Override
- public void leaveToken(DetailAST ast) {
- SourceCode currentResource = peekSourceCode();
- int complexity = calculateComplexity(currentResource);
+ public void visitClass(SourceClass sourceClass) {
+ int complexity = sourceClass.getInt(Metric.COMPLEXITY);
if (complexity > threshold) {
CheckMessage message = new CheckMessage(this, "Class complexity exceeds " + threshold + ".");
- message.setLine(ast.getLineNo());
+ message.setLine(sourceClass.getStartAtLine());
message.setCost(complexity - threshold);
- SourceFile sourceFile = currentResource.getParent(SourceFile.class);
- sourceFile.log(message);
- }
- }
-
- private int calculateComplexity(SourceCode sourceCode) {
- int result = 0;
- if (sourceCode.getChildren() != null) {
- for (SourceCode child : sourceCode.getChildren()) {
- result += calculateComplexity(child);
- }
+ getSourceFile(sourceClass).log(message);
}
- result += sourceCode.getInt(Metric.COMPLEXITY);
- return result;
}
public void setThreshold(int threshold) {
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/bytecode/check/DITCheck.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/DITCheck.java
index 0b88ee55da1..d202f591ab1 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/bytecode/check/DITCheck.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/DITCheck.java
@@ -1,10 +1,9 @@
-package org.sonar.java.bytecode.check;
+package org.sonar.java.squid.check;
import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
-import org.sonar.java.bytecode.asm.AsmClass;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceClass;
import org.sonar.squid.measures.Metric;
@@ -16,21 +15,20 @@ import org.sonar.squid.measures.Metric;
+ "can lead to very complex and unmaintainable source code.</p>"
+ "<p>Most of the time a too deep inheritance tree is due to bad object oriented design which has led to systematically use "
+ "'inheritance' when 'composition' would suit better.</p>")
-public class DITCheck extends BytecodeCheck {
+public class DITCheck extends SquidCheck {
@RuleProperty(description = "Maximum depth of the inheritance tree.", defaultValue = "5")
private Integer max;
@Override
- public void visitClass(AsmClass asmClass) {
- SourceClass sourceClass = getSourceClass(asmClass);
+ public void visitClass(SourceClass sourceClass) {
int dit = sourceClass.getInt(Metric.DIT);
if (dit > max) {
CheckMessage message = new CheckMessage(this, "This class has " + dit
+ " parents which makes it complex to understand and to maintain.");
message.setLine(sourceClass.getStartAtLine());
message.setCost(dit - max);
- getSourceFile(asmClass).log(message);
+ getSourceFile(sourceClass).log(message);
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/MethodComplexityCheck.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/MethodComplexityCheck.java
new file mode 100644
index 00000000000..27361d34deb
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/MethodComplexityCheck.java
@@ -0,0 +1,31 @@
+package org.sonar.java.squid.check;
+
+import org.sonar.check.IsoCategory;
+import org.sonar.check.Rule;
+import org.sonar.check.RuleProperty;
+import org.sonar.squid.api.CheckMessage;
+import org.sonar.squid.api.SourceMethod;
+import org.sonar.squid.measures.Metric;
+
+@Rule(key = "MethodComplexityCheck", name = "MethodComplexityCheck", isoCategory = IsoCategory.Maintainability)
+public class MethodComplexityCheck extends SquidCheck {
+
+ @RuleProperty(description = "Threshold.")
+ private Integer threshold;
+
+ @Override
+ public void visitMethod(SourceMethod sourceMethod) {
+ int complexity = sourceMethod.getInt(Metric.COMPLEXITY);
+ if (complexity > threshold) {
+ CheckMessage message = new CheckMessage(this, "Method complexity exceeds " + threshold + ".");
+ message.setLine(sourceMethod.getStartAtLine());
+ message.setCost(complexity - threshold);
+ getSourceFile(sourceMethod).log(message);
+ }
+ }
+
+ public void setThreshold(int threshold) {
+ this.threshold = threshold;
+ }
+
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/SquidCheck.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/SquidCheck.java
new file mode 100644
index 00000000000..fe28095de4a
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/SquidCheck.java
@@ -0,0 +1,12 @@
+package org.sonar.java.squid.check;
+
+import org.sonar.java.squid.visitor.SquidVisitor;
+import org.sonar.squid.api.CodeCheck;
+
+public class SquidCheck extends SquidVisitor implements CodeCheck {
+
+ public String getKey() {
+ return getClass().getSimpleName();
+ }
+
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/visitor/SquidVisitor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/visitor/SquidVisitor.java
new file mode 100644
index 00000000000..f50d4f21c21
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/visitor/SquidVisitor.java
@@ -0,0 +1,28 @@
+package org.sonar.java.squid.visitor;
+
+import org.sonar.squid.api.CodeVisitor;
+import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceCode;
+import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.api.SourceMethod;
+import org.sonar.squid.indexer.SquidIndex;
+
+public class SquidVisitor implements CodeVisitor {
+
+ SquidIndex index;
+
+ public void visitClass(SourceClass sourceClass) {
+ }
+
+ public void visitMethod(SourceMethod sourceMethod) {
+ }
+
+ protected final SourceFile getSourceFile(SourceCode sourceCode) {
+ return sourceCode.getParent(SourceFile.class);
+ }
+
+ public void setSquidIndex(SquidIndex index) {
+ this.index = index;
+ }
+
+}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
index bab76dee513..bbc1bb31777 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
@@ -19,6 +19,11 @@
*/
package org.sonar.plugins.squid;
+import java.io.File;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.checks.CheckFactory;
@@ -29,6 +34,7 @@ import org.sonar.api.utils.TimeProfiler;
import org.sonar.java.ast.JavaAstScanner;
import org.sonar.java.bytecode.BytecodeScanner;
import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
import org.sonar.plugins.squid.bridges.Bridge;
import org.sonar.plugins.squid.bridges.BridgeFactory;
import org.sonar.plugins.squid.bridges.ResourceIndex;
@@ -40,11 +46,6 @@ import org.sonar.squid.api.SourcePackage;
import org.sonar.squid.indexer.QueryByType;
import org.sonar.squid.measures.Metric;
-import java.io.File;
-import java.nio.charset.Charset;
-import java.util.Collection;
-import java.util.List;
-
public final class SquidExecutor {
private Squid squid;
@@ -52,7 +53,8 @@ public final class SquidExecutor {
private boolean bytecodeScanned = false;
private CheckFactory checkFactory;
- public SquidExecutor(boolean analyzePropertyAccessors, String fieldNamesToExcludeFromLcom4Computation, CheckFactory checkFactory, Charset sourcesCharset) {
+ public SquidExecutor(boolean analyzePropertyAccessors, String fieldNamesToExcludeFromLcom4Computation, CheckFactory checkFactory,
+ Charset sourcesCharset) {
JavaSquidConfiguration conf = createJavaSquidConfiguration(analyzePropertyAccessors, fieldNamesToExcludeFromLcom4Computation,
sourcesCharset);
squid = new Squid(conf);
@@ -87,6 +89,7 @@ public final class SquidExecutor {
scanBytecode(bytecodeFilesOrDirectories);
}
squid.decorateSourceCodeTreeWith(Metric.values());
+ scanSquidIndex();
}
public void save(Project project, SensorContext context, NoSonarFilter noSonarFilter) {
@@ -153,6 +156,13 @@ public final class SquidExecutor {
}
}
+ void scanSquidIndex() {
+ TimeProfiler profiler = new TimeProfiler(getClass()).start("Java Squid scan");
+ SquidScanner squidScanner = squid.register(SquidScanner.class);
+ squidScanner.scan();
+ profiler.stop();
+ }
+
boolean isSourceScanned() {
return sourceScanned;
}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidRuleRepository.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidRuleRepository.java
index 9c4ae500f29..3b47ff28e18 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidRuleRepository.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidRuleRepository.java
@@ -28,15 +28,15 @@ import org.sonar.api.rules.AnnotationRuleParser;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleRepository;
import org.sonar.java.ast.check.BreakCheck;
-import org.sonar.java.ast.check.ClassComplexityCheck;
import org.sonar.java.ast.check.ContinueCheck;
-import org.sonar.java.ast.check.MethodComplexityCheck;
import org.sonar.java.ast.check.UndocumentedApiCheck;
import org.sonar.java.bytecode.check.ArchitectureCheck;
import org.sonar.java.bytecode.check.CallToDeprecatedMethodCheck;
-import org.sonar.java.bytecode.check.DITCheck;
import org.sonar.java.bytecode.check.UnusedPrivateMethodCheck;
import org.sonar.java.bytecode.check.UnusedProtectedMethodCheck;
+import org.sonar.java.squid.check.ClassComplexityCheck;
+import org.sonar.java.squid.check.DITCheck;
+import org.sonar.java.squid.check.MethodComplexityCheck;
public final class SquidRuleRepository extends RuleRepository {
private AnnotationRuleParser ruleParser;
@@ -56,8 +56,10 @@ public final class SquidRuleRepository extends RuleRepository {
return Arrays.asList(
// Bytecode checks
(Class) CallToDeprecatedMethodCheck.class, UnusedPrivateMethodCheck.class, UnusedProtectedMethodCheck.class,
- ArchitectureCheck.class, DITCheck.class,
+ ArchitectureCheck.class,
// AST checks
- UndocumentedApiCheck.class, ContinueCheck.class, BreakCheck.class, ClassComplexityCheck.class, MethodComplexityCheck.class);
+ UndocumentedApiCheck.class, ContinueCheck.class, BreakCheck.class, ClassComplexityCheck.class, MethodComplexityCheck.class,
+ // Squid checks
+ DITCheck.class);
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ClassComplexityCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java
index 39692969332..24f7f02f261 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ClassComplexityCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.java.ast.check;
+package org.sonar.java.squid.check;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -28,9 +28,11 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.java.ast.JavaAstScanner;
import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
import org.sonar.squid.Squid;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.measures.Metric;
public class ClassComplexityCheckTest {
@@ -45,6 +47,8 @@ public class ClassComplexityCheckTest {
JavaAstScanner scanner = squid.register(JavaAstScanner.class);
scanner.scanFile(getFile("/metrics/branches/NoBranches.java"));
scanner.scanFile(getFile("/metrics/branches/ComplexBranches.java"));
+ squid.decorateSourceCodeTreeWith(Metric.values());
+ squid.register(SquidScanner.class).scan();
}
@Test
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/DITCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java
index bbe16d51117..51e9a215704 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/DITCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java
@@ -1,4 +1,4 @@
-package org.sonar.java.bytecode.check;
+package org.sonar.java.squid.check;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -9,6 +9,7 @@ import org.junit.Test;
import org.sonar.java.ast.JavaAstScanner;
import org.sonar.java.bytecode.BytecodeScanner;
import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
import org.sonar.squid.Squid;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
@@ -20,11 +21,12 @@ public class DITCheckTest {
@BeforeClass
public static void setup() {
squid = new Squid(new JavaSquidConfiguration());
- squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/src"));
DITCheck check = new DITCheck();
check.setMax(1);
squid.registerVisitor(check);
+ squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/src"));
squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/bin"));
+ squid.register(SquidScanner.class).scan();
}
@Test
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/MethodComplexityCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java
index 5f8a73396bd..5533ca8e18d 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/MethodComplexityCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java
@@ -1,4 +1,4 @@
-package org.sonar.java.ast.check;
+package org.sonar.java.squid.check;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -8,9 +8,11 @@ import org.junit.Before;
import org.junit.Test;
import org.sonar.java.ast.JavaAstScanner;
import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.java.squid.SquidScanner;
import org.sonar.squid.Squid;
import org.sonar.squid.api.CheckMessage;
import org.sonar.squid.api.SourceFile;
+import org.sonar.squid.measures.Metric;
public class MethodComplexityCheckTest {
private Squid squid;
@@ -23,6 +25,8 @@ public class MethodComplexityCheckTest {
squid.registerVisitor(check);
JavaAstScanner scanner = squid.register(JavaAstScanner.class);
scanner.scanFile(getFile("/metrics/branches/ComplexBranches.java"));
+ squid.decorateSourceCodeTreeWith(Metric.values());
+ squid.register(SquidScanner.class).scan();
}
@Test