}
public void notifyVisitors(SquidIndex indexer) {
- for (SquidVisitor visitor : squidVisitors) {
- visitor.setSquidIndex(indexer);
- }
callVisitClass();
callVisitMethod();
}
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,
+ max + " authorized.");
message.setLine(sourceClass.getStartAtLine());
message.setCost(complexity - max);
- getSourceFile(sourceClass).log(message);
+ sourceClass.getParent(SourceFile.class).log(message);
}
}
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,
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);
}
}
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;
+ max + " authorized.");
message.setLine(sourceMethod.getStartAtLine());
message.setCost(complexity - max);
- getSourceFile(sourceMethod).log(message);
+ sourceMethod.getParent(SourceFile.class).log(message);
}
}
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) {
+ }
+
}
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);
}