aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-04-05 17:40:57 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-04-05 17:41:10 +0200
commitdedeee7c09f52d0b78302471de2660043ee5c27d (patch)
tree4dff043751c0a07fd619617cf6a0b419e29ec278 /plugins
parentcc59d04173789942e8c1c1abc704037dcf78db60 (diff)
downloadsonarqube-dedeee7c09f52d0b78302471de2660043ee5c27d.tar.gz
sonarqube-dedeee7c09f52d0b78302471de2660043ee5c27d.zip
Fix some quality flaws
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java15
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CommentDensityDecorator.java8
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java9
3 files changed, 14 insertions, 18 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java
index 5faddcff821..bd1fee2b1e7 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java
@@ -49,9 +49,11 @@ public final class AlertUtils {
} else if (alertLevel.equals(Metric.Level.WARN)) {
valueToEval = alert.getValueWarning();
+
} else {
throw new IllegalStateException(alertLevel.toString());
}
+
if (StringUtils.isEmpty(valueToEval)) {
return false;
}
@@ -60,13 +62,12 @@ public final class AlertUtils {
Comparable metricValue = getMeasureValue(alert.getMetric(), measure);
int comparison = metricValue.compareTo(criteriaValue);
- if (alert.isNotEqualsOperator() && comparison == 0 ||
- alert.isGreaterOperator() && comparison != 1 ||
- alert.isSmallerOperator() && comparison != -1 ||
- alert.isEqualsOperator() && comparison != 0) {
- return false;
- }
- return true;
+ return !(// NOSONAR complexity of this boolean expression is under control
+ (alert.isNotEqualsOperator() && comparison == 0) ||
+ (alert.isGreaterOperator() && comparison != 1) ||
+ (alert.isSmallerOperator() && comparison != -1) ||
+ (alert.isEqualsOperator() && comparison != 0)
+ );
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CommentDensityDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CommentDensityDecorator.java
index 7688f293a2d..fb1f3ef69a1 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CommentDensityDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CommentDensityDecorator.java
@@ -61,11 +61,9 @@ public class CommentDensityDecorator implements Decorator {
Measure ncloc = context.getMeasure(CoreMetrics.NCLOC);
Measure comments = context.getMeasure(CoreMetrics.COMMENT_LINES);
- if (MeasureUtils.hasValue(ncloc) && MeasureUtils.hasValue(comments)) {
- if (comments.getValue() + ncloc.getValue() > 0) {
- double val = 100.0 * (comments.getValue() / (comments.getValue() + ncloc.getValue()));
- context.saveMeasure(new Measure(CoreMetrics.COMMENT_LINES_DENSITY, val));
- }
+ if (MeasureUtils.hasValue(ncloc) && MeasureUtils.hasValue(comments) && (comments.getValue() + ncloc.getValue()) > 0) {
+ double val = 100.0 * (comments.getValue() / (comments.getValue() + ncloc.getValue()));
+ context.saveMeasure(new Measure(CoreMetrics.COMMENT_LINES_DENSITY, val));
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java
index e74d012f075..b1fab180258 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/VersionEventsSensor.java
@@ -50,12 +50,9 @@ public class VersionEventsSensor implements Sensor {
String snapshotVersionToDelete = (version.endsWith(SNAPSHOT_SUFFIX) ? "" : version + SNAPSHOT_SUFFIX);
for (Iterator<Event> it = context.getEvents(project).iterator(); it.hasNext();) {
Event event = it.next();
- if (event.isVersionCategory()) {
- if (version.equals(event.getName()) || snapshotVersionToDelete.equals(event.getName())) {
- it.remove();
- context.deleteEvent(event);
- event = null;
- }
+ if (event.isVersionCategory() && (version.equals(event.getName()) || snapshotVersionToDelete.equals(event.getName()))) {
+ it.remove();
+ context.deleteEvent(event);
}
}
}