aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-07-10 11:30:57 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-07-10 11:31:30 +0200
commit118ae7d21966b15666b5d40e47f103c5d412ec70 (patch)
treeae1191e1d66de3321353e108828dcafb368fba18 /sonar-plugin-api/src/main
parent56251b15bc1b3d7f94537e89cdaf1d1128f68256 (diff)
downloadsonarqube-118ae7d21966b15666b5d40e47f103c5d412ec70.tar.gz
sonarqube-118ae7d21966b15666b5d40e47f103c5d412ec70.zip
Fix some quality flaws
Diffstat (limited to 'sonar-plugin-api/src/main')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java12
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java56
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java24
4 files changed, 62 insertions, 33 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java
index 81dad9e2759..9f77587903c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java
@@ -19,10 +19,12 @@
*/
package org.sonar.api.measures;
-import java.util.Collection;
-
import org.apache.commons.lang.StringUtils;
+import javax.annotation.Nullable;
+
+import java.util.Collection;
+
/**
* An utility class to manipulate measures
*
@@ -62,7 +64,7 @@ public final class MeasureUtils {
* @return <code>defaultValue</code> if measure is null or has no values.
*/
- public static Double getValue(Measure measure, Double defaultValue) {
+ public static Double getValue(Measure measure, @Nullable Double defaultValue) {
if (MeasureUtils.hasValue(measure)) {
return measure.getValue();
}
@@ -80,7 +82,7 @@ public final class MeasureUtils {
return getVariation(measure, periodIndex, null);
}
- public static Double getVariation(Measure measure, int periodIndex, Double defaultValue) {
+ public static Double getVariation(Measure measure, int periodIndex, @Nullable Double defaultValue) {
Double result = null;
if (measure != null) {
result = measure.getVariation(periodIndex);
@@ -92,7 +94,7 @@ public final class MeasureUtils {
return getVariationAsLong(measure, periodIndex, null);
}
- public static Long getVariationAsLong(Measure measure, int periodIndex, Long defaultValue) {
+ public static Long getVariationAsLong(Measure measure, int periodIndex, @Nullable Long defaultValue) {
Double result = null;
if (measure != null) {
result = measure.getVariation(periodIndex);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
index 58ba8bc9797..081bb09df62 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
@@ -26,6 +26,7 @@ import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
import org.sonar.api.batch.InstantiationStrategy;
+import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
@@ -211,7 +212,7 @@ public class Metric implements ServerExtension, BatchExtension {
* @deprecated since 2.7 use the {@link Builder} factory.
*/
@Deprecated
- public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain,
+ public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, @Nullable String domain,
boolean userManaged) {
this.key = key;
this.description = description;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
index efba225462c..cf33a84c0ff 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
@@ -25,6 +25,8 @@ import org.apache.commons.lang.builder.ToStringBuilder;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
+import javax.annotation.Nullable;
+
/**
* @since 1.10
*/
@@ -36,7 +38,7 @@ public class RuleMeasure extends Measure {
/**
* This constructor is for internal use only. Please use static methods createForXXX().
*/
- public RuleMeasure(Metric metric, Rule rule, RulePriority rulePriority, Integer ruleCategory) {
+ public RuleMeasure(Metric metric, @Nullable Rule rule, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) {
super(metric);
this.rule = rule;
this.rulePriority = rulePriority;
@@ -103,7 +105,7 @@ public class RuleMeasure extends Measure {
if (obj == null) {
return false;
}
- if (!(obj.getClass().equals(RuleMeasure.class))) {//NOSONAR should be refactored but kept in the current state
+ if (!(obj.getClass().equals(RuleMeasure.class))) {// NOSONAR should be refactored but kept in the current state
// for the moment.
return false;
}
@@ -112,10 +114,10 @@ public class RuleMeasure extends Measure {
}
RuleMeasure other = (RuleMeasure) obj;
return new EqualsBuilder()
- .append(getMetric(), other.getMetric())
- .append(personId, other.personId)
- .append(rule, other.rule)
- .isEquals();
+ .append(getMetric(), other.getMetric())
+ .append(personId, other.personId)
+ .append(rule, other.rule)
+ .isEquals();
}
@Override
@@ -126,34 +128,34 @@ public class RuleMeasure extends Measure {
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(getMetric())
- .append(personId)
- .append(rule)
- .toHashCode();
+ .append(getMetric())
+ .append(personId)
+ .append(rule)
+ .toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", getId())
- .append("metric", metric)
- .append("personId", personId)
- .append("rule", rule)
- .append("value", value)
- .append("data", data)
- .append("description", description)
- .append("alertStatus", alertStatus)
- .append("alertText", alertText)
- .append("tendency", tendency)
- .append("severity", rulePriority)
- .toString();
- }
-
- public static RuleMeasure createForRule(Metric metric, Rule rule, Double value) {
+ .append("id", getId())
+ .append("metric", metric)
+ .append("personId", personId)
+ .append("rule", rule)
+ .append("value", value)
+ .append("data", data)
+ .append("description", description)
+ .append("alertStatus", alertStatus)
+ .append("alertText", alertText)
+ .append("tendency", tendency)
+ .append("severity", rulePriority)
+ .toString();
+ }
+
+ public static RuleMeasure createForRule(Metric metric, Rule rule, @Nullable Double value) {
return new RuleMeasure(metric, rule, null, null).setValue(value);
}
- public static RuleMeasure createForPriority(Metric metric, RulePriority priority, Double value) {
+ public static RuleMeasure createForPriority(Metric metric, RulePriority priority, @Nullable Double value) {
return new RuleMeasure(metric, null, priority, null).setValue(value);
}
@@ -161,7 +163,7 @@ public class RuleMeasure extends Measure {
* @deprecated since 2.5. See SONAR-2007.
*/
@Deprecated
- public static RuleMeasure createForCategory(Metric metric, Integer category, Double value) {
+ public static RuleMeasure createForCategory(Metric metric, Integer category, @Nullable Double value) {
return new RuleMeasure(metric, null, null, category).setValue(value);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java
new file mode 100644
index 00000000000..6a66b2a2c1b
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.measures;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+