]> source.dussan.org Git - sonarqube.git/commitdiff
Make SquidVisitor interface instead of class
authorGodin <mandrikov@gmail.com>
Tue, 23 Nov 2010 20:49:38 +0000 (20:49 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 23 Nov 2010 20:49:38 +0000 (20:49 +0000)
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/SquidVisitorNotifier.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/ClassComplexityCheck.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/DITCheck.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/MethodComplexityCheck.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/check/SquidCheck.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/squid/visitor/SquidVisitor.java

index 740db3c7a7dab64d0256be7a025984965ccfd41f..98ef164fca4bd9dd789e1ce0b653c6ecd5fd0c8d 100644 (file)
@@ -18,9 +18,6 @@ public class SquidVisitorNotifier {
   }
 
   public void notifyVisitors(SquidIndex indexer) {
-    for (SquidVisitor visitor : squidVisitors) {
-      visitor.setSquidIndex(indexer);
-    }
     callVisitClass();
     callVisitMethod();
   }
index 50892d7fe20657770535b6112fe0ece2f5c25852..de909df1e1150b82b5c00dff54be1393207f349a 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.check.Rule;
 import org.sonar.check.RuleProperty;
 import org.sonar.squid.api.CheckMessage;
 import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceFile;
 import org.sonar.squid.measures.Metric;
 
 @Rule(key = "ClassCyclomaticComplexity", name = "Avoid too complex class", isoCategory = IsoCategory.Maintainability,
@@ -50,7 +51,7 @@ public class ClassComplexityCheck extends SquidCheck {
           + max + " authorized.");
       message.setLine(sourceClass.getStartAtLine());
       message.setCost(complexity - max);
-      getSourceFile(sourceClass).log(message);
+      sourceClass.getParent(SourceFile.class).log(message);
     }
   }
 
index be0c2bd6f40227ac2bc376d5d1dfc38384ecc16e..3db6a3dcdf429415cda7a44012f99e11d9064d40 100644 (file)
@@ -6,6 +6,7 @@ import org.sonar.check.Rule;
 import org.sonar.check.RuleProperty;
 import org.sonar.squid.api.CheckMessage;
 import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceFile;
 import org.sonar.squid.measures.Metric;
 
 @Rule(key = "MaximumInheritanceDepth", name = "Avoid too deep inheritance tree", isoCategory = IsoCategory.Maintainability,
@@ -27,7 +28,7 @@ public class DITCheck extends SquidCheck {
       CheckMessage message = new CheckMessage(this, "This class has " + dit + " parents which is greater than " + max + " authorized.");
       message.setLine(sourceClass.getStartAtLine());
       message.setCost(dit - max);
-      getSourceFile(sourceClass).log(message);
+      sourceClass.getParent(SourceFile.class).log(message);
     }
   }
 
index 8e527e8a3027ffde44eee78fcd07decaae26055a..7c0810a3872e9a571949535f140058d6807e7546 100644 (file)
@@ -5,6 +5,7 @@ import org.sonar.check.Priority;
 import org.sonar.check.Rule;
 import org.sonar.check.RuleProperty;
 import org.sonar.squid.api.CheckMessage;
+import org.sonar.squid.api.SourceFile;
 import org.sonar.squid.api.SourceMethod;
 import org.sonar.squid.measures.Metric;
 
@@ -30,7 +31,7 @@ public class MethodComplexityCheck extends SquidCheck {
           + max + " authorized.");
       message.setLine(sourceMethod.getStartAtLine());
       message.setCost(complexity - max);
-      getSourceFile(sourceMethod).log(message);
+      sourceMethod.getParent(SourceFile.class).log(message);
     }
   }
 
index fe28095de4ab413c8c88be3c0dd64cb81f99a1f9..c2fe6ef2572e1b9a57a4ce0674fffecbd9cca05b 100644 (file)
@@ -2,11 +2,19 @@ package org.sonar.java.squid.check;
 
 import org.sonar.java.squid.visitor.SquidVisitor;
 import org.sonar.squid.api.CodeCheck;
+import org.sonar.squid.api.SourceClass;
+import org.sonar.squid.api.SourceMethod;
 
-public class SquidCheck extends SquidVisitor implements CodeCheck {
+public class SquidCheck implements SquidVisitor, CodeCheck {
 
   public String getKey() {
     return getClass().getSimpleName();
   }
 
+  public void visitClass(SourceClass sourceClass) {
+  }
+
+  public void visitMethod(SourceMethod sourceMethod) {
+  }
+
 }
index f50d4f21c21bfc45d18f690f65fa274ad4877304..802626d59fcd7e10e8831c12929200149c980947 100644 (file)
@@ -2,27 +2,12 @@ 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 {
+public interface SquidVisitor extends CodeVisitor {
 
-  SquidIndex index;
+  void visitClass(SourceClass sourceClass);
 
-  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;
-  }
+  void visitMethod(SourceMethod sourceMethod);
 
 }