diff options
Diffstat (limited to 'sonar-plugin-api')
7 files changed, 34 insertions, 40 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java index 2f62eb28f2c..c025818612f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java @@ -54,9 +54,7 @@ public final class PropertyDefinitions { private final Map<String, String> deprecatedKeys = new HashMap<>(); public PropertyDefinitions(Object... components) { - if (components != null) { - addComponents(Arrays.asList(components)); - } + addComponents(Arrays.asList(components)); } public PropertyDefinitions(Collection<PropertyDefinition> components) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java index 9700220b47f..04732b9fae5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java @@ -135,7 +135,7 @@ public class Measure<G extends Serializable> implements Serializable { * @param metric the metric * @param level the alert level */ - public Measure(Metric metric, Metric.Level level) { + public Measure(Metric metric, @Nullable Metric.Level level) { this.metric = metric; this.metricKey = metric.getKey(); if (level != null) { @@ -308,7 +308,7 @@ public class Measure<G extends Serializable> implements Serializable { * @param i the value * @return the measure object instance */ - public Measure<G> setIntValue(Integer i) { + public Measure<G> setIntValue(@Nullable Integer i) { if (i == null) { this.value = null; } else { @@ -361,7 +361,7 @@ public class Measure<G extends Serializable> implements Serializable { * @param level the alert level * @return the measure object instance */ - public Measure<G> setData(Metric.Level level) { + public Measure<G> setData(@Nullable Metric.Level level) { if (level == null) { this.data = null; } else { 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 9542220d04e..4626a6221e5 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 @@ -45,7 +45,7 @@ public final class MeasureUtils { * @return true if all measures numeric values */ public static boolean haveValues(Measure... measures) { - if (measures == null || measures.length == 0) { + if (measures.length == 0) { return false; } for (Measure measure : measures) { @@ -78,11 +78,11 @@ public final class MeasureUtils { return defaultValue; } - public static Double getVariation(Measure measure, int periodIndex) { + public static Double getVariation(@Nullable Measure measure, int periodIndex) { return getVariation(measure, periodIndex, null); } - public static Double getVariation(Measure measure, int periodIndex, @Nullable Double defaultValue) { + public static Double getVariation(@Nullable Measure measure, int periodIndex, @Nullable Double defaultValue) { Double result = null; if (measure != null) { result = measure.getVariation(periodIndex); @@ -90,11 +90,11 @@ public final class MeasureUtils { return result != null ? result : defaultValue; } - public static Long getVariationAsLong(Measure measure, int periodIndex) { + public static Long getVariationAsLong(@Nullable Measure measure, int periodIndex) { return getVariationAsLong(measure, periodIndex, null); } - public static Long getVariationAsLong(Measure measure, int periodIndex, @Nullable Long defaultValue) { + public static Long getVariationAsLong(@Nullable Measure measure, int periodIndex, @Nullable Long defaultValue) { Double result = null; if (measure != null) { result = measure.getVariation(periodIndex); @@ -108,7 +108,7 @@ public final class MeasureUtils { * @param measure the measure * @return whether the measure has a value */ - public static boolean hasValue(Measure measure) { + public static boolean hasValue(@Nullable Measure measure) { return measure != null && measure.getValue() != null; } @@ -118,7 +118,7 @@ public final class MeasureUtils { * @param measure the measure * @return whether the measure has a data field */ - public static boolean hasData(Measure measure) { + public static boolean hasData(@Nullable Measure measure) { return measure != null && StringUtils.isNotBlank(measure.getData()); } @@ -129,7 +129,7 @@ public final class MeasureUtils { * @param measures the series of measures * @return the sum of the measure series */ - public static Double sum(boolean zeroIfNone, Collection<Measure> measures) { + public static Double sum(boolean zeroIfNone, @Nullable Collection<Measure> measures) { if (measures != null) { return sum(zeroIfNone, measures.toArray(new Measure[measures.size()])); } @@ -144,9 +144,6 @@ public final class MeasureUtils { * @return the sum of the measure series */ public static Double sum(boolean zeroIfNone, Measure... measures) { - if (measures == null) { - return zeroIfNone(zeroIfNone); - } Double sum = 0d; boolean hasValue = false; for (Measure measure : measures) { @@ -170,7 +167,7 @@ public final class MeasureUtils { * @param measures the series of measures * @return the sum of the variations for the measure series */ - public static Double sumOnVariation(boolean zeroIfNone, int variationIndex, Collection<Measure> measures) { + public static Double sumOnVariation(boolean zeroIfNone, int variationIndex, @Nullable Collection<Measure> measures) { if (measures == null) { return zeroIfNone(zeroIfNone); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java index c576b34d88d..309f3c51d14 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java @@ -20,6 +20,7 @@ package org.sonar.api.measures; import java.util.Collection; +import javax.annotation.Nullable; /** * @since 1.10 @@ -28,6 +29,6 @@ import java.util.Collection; @Deprecated public interface MeasuresFilter<M> { - M filter(Collection<Measure> measures); + M filter(@Nullable Collection<Measure> measures); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java index 5c8883e91a6..3b83842d8ac 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java @@ -144,11 +144,12 @@ public final class KeyValueFormat { } public abstract static class Converter<T> { - abstract String format(T type); + abstract String format(@Nullable T type); @CheckForNull abstract T parse(String s); + String escape(String s) { if (s.contains(FIELD_SEPARATOR) || s.contains(PAIR_SEPARATOR)) { return new StringBuilder() @@ -167,8 +168,8 @@ public final class KeyValueFormat { } @Override - String format(String s) { - return escape(s); + String format(@Nullable String s) { + return s == null ? "" : escape(s); } @Override @@ -188,8 +189,8 @@ public final class KeyValueFormat { } @Override - String format(Object o) { - return escape(o.toString()); + String format(@Nullable Object o) { + return o == null ? "" : escape(o.toString()); } @Override @@ -209,7 +210,7 @@ public final class KeyValueFormat { } @Override - String format(Integer s) { + String format(@Nullable Integer s) { return s == null ? "" : String.valueOf(s); } @@ -230,7 +231,7 @@ public final class KeyValueFormat { } @Override - String format(RulePriority s) { + String format(@Nullable RulePriority s) { return s == null ? "" : s.toString(); } @@ -251,7 +252,7 @@ public final class KeyValueFormat { } @Override - String format(Double d) { + String format(@Nullable Double d) { return d == null ? "" : String.valueOf(d); } @@ -273,7 +274,7 @@ public final class KeyValueFormat { } @Override - String format(Date d) { + String format(@Nullable Date d) { return d == null ? "" : dateFormat.format(d); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java index 48b28e33421..41484e56d31 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/WildcardPattern.java @@ -22,6 +22,7 @@ package org.sonar.api.utils; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; /** @@ -169,7 +170,7 @@ public class WildcardPattern { * * @see #create(String, String) */ - public static WildcardPattern[] create(String[] patterns) { + public static WildcardPattern[] create(@Nullable String[] patterns) { if (patterns == null) { return new WildcardPattern[0]; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/dag/DirectAcyclicGraph.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/dag/DirectAcyclicGraph.java index 338f2962b76..2a6b75e57dc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/dag/DirectAcyclicGraph.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/dag/DirectAcyclicGraph.java @@ -37,15 +37,13 @@ public class DirectAcyclicGraph { private Map<Object, Node> registeredObjects = new HashMap<>(); private List<Node> nodes = new ArrayList<>(); - public DirectAcyclicGraph(final Object... objects) { - if (objects != null) { - for (Object object : objects) { - add(object); - } + public DirectAcyclicGraph(Object... objects) { + for (Object object : objects) { + add(object); } } - public Node add(final Object object, final Object... dependencies) { + public Node add(Object object, Object... dependencies) { Node node = registeredObjects.get(object); if (node == null) { node = new Node(object); @@ -53,11 +51,9 @@ public class DirectAcyclicGraph { registeredObjects.put(object, node); } - if (dependencies != null) { - for (Object dependency : dependencies) { - Node depNode = add(dependency); - node.addDependency(depNode); - } + for (Object dependency : dependencies) { + Node depNode = add(dependency); + node.addDependency(depNode); } return node; } |