]> source.dussan.org Git - sonarqube.git/commitdiff
Fix violations
authorFabrice Bellingard <bellingard@gmail.com>
Thu, 5 Apr 2012 07:41:23 +0000 (09:41 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Thu, 5 Apr 2012 07:42:06 +0000 (09:42 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/measures/AverageComplexityFormula.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/AverageFormula.java

index 297b7062a5f7afce8ce1972f09eae1343a0f7263..3a22d6567412d7e1fcb3c6ca6f68cef6da5d5718 100644 (file)
@@ -29,7 +29,6 @@ package org.sonar.api.measures;
 @Deprecated
 public class AverageComplexityFormula extends AverageFormula {
 
-  @Deprecated
   public AverageComplexityFormula(Metric byMetric) {
     super(CoreMetrics.COMPLEXITY, byMetric);
   }
index 7ed369837bfdea6718dfe93d8415ba73003d8b76..861c67daf0b97c63cfa3ccb7bc7a8a6800f06bcc 100644 (file)
@@ -62,31 +62,48 @@ public class AverageFormula implements Formula {
     if (!shouldDecorateResource(data, context)) {
       return null;
     }
+
+    Measure result = null;
     if (ResourceUtils.isFile(context.getResource())) {
-      Double byMeasure = MeasureUtils.getValue(data.getMeasure(byMetric), null);
-      Double mainMeasure = MeasureUtils.getValue(data.getMeasure(mainMetric), null);
-      if (mainMeasure != null && byMeasure != null && byMeasure > 0.0) {
-        return new Measure(context.getTargetMetric(), (mainMeasure / byMeasure));
-      }
+      result = calculateForFile(data, context);
     } else {
-      double totalByMeasure = 0;
-      double totalMainMeasure = 0;
-      boolean hasApplicableChildren = false;
-
-      for (FormulaData childrenData : data.getChildren()) {
-        Double childrenByMeasure = MeasureUtils.getValue(childrenData.getMeasure(byMetric), null);
-        Double childrenMainMeasure = MeasureUtils.getValue(childrenData.getMeasure(mainMetric), null);
-        if (childrenMainMeasure != null && childrenByMeasure != null && childrenByMeasure > 0.0) {
-          totalByMeasure += childrenByMeasure;
-          totalMainMeasure += childrenMainMeasure;
-          hasApplicableChildren = true;
-        }
-      }
-      if (hasApplicableChildren) {
-        return new Measure(context.getTargetMetric(), (totalMainMeasure / totalByMeasure));
+      result = calculateOnChildren(data, context);
+    }
+    return result;
+  }
+
+  private Measure calculateOnChildren(FormulaData data, FormulaContext context) {
+    Measure result = null;
+
+    double totalByMeasure = 0;
+    double totalMainMeasure = 0;
+    boolean hasApplicableChildren = false;
+
+    for (FormulaData childrenData : data.getChildren()) {
+      Double childrenByMeasure = MeasureUtils.getValue(childrenData.getMeasure(byMetric), null);
+      Double childrenMainMeasure = MeasureUtils.getValue(childrenData.getMeasure(mainMetric), null);
+      if (childrenMainMeasure != null && childrenByMeasure != null && childrenByMeasure > 0.0) {
+        totalByMeasure += childrenByMeasure;
+        totalMainMeasure += childrenMainMeasure;
+        hasApplicableChildren = true;
       }
     }
-    return null;
+    if (hasApplicableChildren) {
+      result = new Measure(context.getTargetMetric(), (totalMainMeasure / totalByMeasure));
+    }
+    return result;
+  }
+
+  private Measure calculateForFile(FormulaData data, FormulaContext context) {
+    Measure result = null;
+
+    Double byMeasure = MeasureUtils.getValue(data.getMeasure(byMetric), null);
+    Double mainMeasure = MeasureUtils.getValue(data.getMeasure(mainMetric), null);
+    if (mainMeasure != null && byMeasure != null && byMeasure > 0.0) {
+      result = new Measure(context.getTargetMetric(), (mainMeasure / byMeasure));
+    }
+
+    return result;
   }
 
   private boolean shouldDecorateResource(FormulaData data, FormulaContext context) {