diff options
8 files changed, 35 insertions, 54 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java index 23deec29c54..ed58246c723 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java @@ -19,7 +19,6 @@ */ package org.sonar.api.batch.rule; -import com.google.common.collect.Maps; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Collection; @@ -122,7 +121,7 @@ public class Checks<C> { } public Checks<C> addAnnotatedChecks(Iterable checkClassesOrObjects) { - Map<String, Object> checksByEngineKey = Maps.newHashMap(); + Map<String, Object> checksByEngineKey = new HashMap<>(); for (Object checkClassesOrObject : checkClassesOrObjects) { String engineKey = annotatedEngineKey(checkClassesOrObject); if (engineKey != null) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java index 4935e7b5e1a..c99f2ab7de6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java @@ -19,9 +19,9 @@ */ package org.sonar.api.batch.sensor.coverage.internal; -import com.google.common.collect.Maps; import java.util.Collections; import java.util.SortedMap; +import java.util.TreeMap; import javax.annotation.Nullable; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.coverage.CoverageType; @@ -29,8 +29,8 @@ import org.sonar.api.batch.sensor.coverage.NewCoverage; import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.internal.SensorStorage; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; public class DefaultCoverage extends DefaultStorable implements NewCoverage { @@ -39,9 +39,9 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage { private int totalCoveredLines = 0; private int totalConditions = 0; private int totalCoveredConditions = 0; - private SortedMap<Integer, Integer> hitsByLine = Maps.newTreeMap(); - private SortedMap<Integer, Integer> conditionsByLine = Maps.newTreeMap(); - private SortedMap<Integer, Integer> coveredConditionsByLine = Maps.newTreeMap(); + private SortedMap<Integer, Integer> hitsByLine = new TreeMap<>(); + private SortedMap<Integer, Integer> conditionsByLine = new TreeMap<>(); + private SortedMap<Integer, Integer> coveredConditionsByLine = new TreeMap<>(); public DefaultCoverage() { super(); @@ -63,8 +63,7 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage { @Override public NewCoverage ofType(CoverageType type) { - checkNotNull(type, "type can't be null"); - this.type = type; + this.type = requireNonNull(type, "type can't be null"); return this; } @@ -92,7 +91,7 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage { } private void validateFile() { - checkNotNull(inputFile, "Call onFile() first"); + requireNonNull(inputFile, "Call onFile() first"); } @Override diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java index ef22f7d0ccf..78a4d700151 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java @@ -32,6 +32,8 @@ import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.Settings; import org.sonar.duplications.internal.pmd.TokensLine; +import static java.util.Objects.requireNonNull; + public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { private final Settings settings; @@ -51,8 +53,7 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { @Override public DefaultCpdTokens onFile(InputFile inputFile) { - Preconditions.checkNotNull(inputFile, "file can't be null"); - this.inputFile = inputFile; + this.inputFile = requireNonNull(inputFile, "file can't be null"); String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); for (PathPattern cpdExclusion : PathPattern.create(cpdExclusions)) { if (cpdExclusion.match(inputFile)) { @@ -80,8 +81,8 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { @Override public DefaultCpdTokens addToken(TextRange range, String image) { - Preconditions.checkNotNull(range, "Range should not be null"); - Preconditions.checkNotNull(image, "Image should not be null"); + requireNonNull(range, "Range should not be null"); + requireNonNull(image, "Image should not be null"); checkInputFileNotNull(); if (excluded) { return this; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java index 49d59135d82..74df633c2d5 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisError.java @@ -19,6 +19,7 @@ */ package org.sonar.api.batch.sensor.error.internal; +import com.google.common.base.Preconditions; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.TextPointer; import org.sonar.api.batch.sensor.error.AnalysisError; @@ -26,7 +27,7 @@ import org.sonar.api.batch.sensor.error.NewAnalysisError; import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.internal.SensorStorage; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; public class DefaultAnalysisError extends DefaultStorable implements NewAnalysisError, AnalysisError { private InputFile inputFile; @@ -79,7 +80,7 @@ public class DefaultAnalysisError extends DefaultStorable implements NewAnalysis @Override protected void doSave() { - Preconditions.checkNotNull(this.inputFile, "inputFile is mandatory on AnalysisError"); + requireNonNull(this.inputFile, "inputFile is mandatory on AnalysisError"); storage.store(this); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java index 29f35e69391..01f5ca27149 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java @@ -32,6 +32,8 @@ import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.internal.SensorStorage; +import static java.util.Objects.requireNonNull; + public class DefaultHighlighting extends DefaultStorable implements NewHighlighting { private final List<SyntaxHighlightingRule> syntaxHighlightingRules; @@ -64,7 +66,7 @@ public class DefaultHighlighting extends DefaultStorable implements NewHighlight @Override public DefaultHighlighting onFile(InputFile inputFile) { - Preconditions.checkNotNull(inputFile, "file can't be null"); + requireNonNull(inputFile, "file can't be null"); this.inputFile = (DefaultInputFile) inputFile; return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index 641776f2813..fda7d880565 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -34,7 +34,9 @@ import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.issue.NewIssueLocation; import org.sonar.api.rule.RuleKey; +import static com.google.common.base.Preconditions.checkState; import static java.lang.String.format; +import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { @@ -85,7 +87,7 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { @Override public DefaultIssue at(NewIssueLocation primaryLocation) { Preconditions.checkArgument(primaryLocation != null, "Cannot use a location that is null"); - Preconditions.checkState(this.primaryLocation == null, "at() already called"); + checkState(this.primaryLocation == null, "at() already called"); this.primaryLocation = (DefaultIssueLocation) primaryLocation; Preconditions.checkArgument(this.primaryLocation.inputComponent() != null, "Cannot use a location with no input component"); return this; @@ -141,8 +143,8 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { @Override public void doSave() { - Preconditions.checkNotNull(this.ruleKey, "ruleKey is mandatory on issue"); - Preconditions.checkState(primaryLocation != null, "Primary location is mandatory on every issue"); + requireNonNull(this.ruleKey, "ruleKey is mandatory on issue"); + checkState(primaryLocation != null, "Primary location is mandatory on every issue"); storage.store(this); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java index 4dbb0ae8650..23b669f0700 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueLocation.java @@ -27,6 +27,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.issue.IssueLocation; import org.sonar.api.batch.sensor.issue.NewIssueLocation; +import static java.util.Objects.requireNonNull; + public class DefaultIssueLocation implements NewIssueLocation, IssueLocation { private InputComponent component; @@ -53,7 +55,7 @@ public class DefaultIssueLocation implements NewIssueLocation, IssueLocation { @Override public DefaultIssueLocation message(String message) { - Preconditions.checkNotNull(message, "Message can't be null"); + requireNonNull(message, "Message can't be null"); this.message = StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_MAX_SIZE); return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java index 8f3d1ffb775..0b6d54e93b7 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestMeasureComputerDefinition.java @@ -19,20 +19,15 @@ */ package org.sonar.api.ce.measure.test; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; -import java.util.Arrays; import java.util.List; import java.util.Set; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import org.sonar.api.ce.measure.MeasureComputer; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Arrays.asList; import static java.util.Objects.requireNonNull; public class TestMeasureComputerDefinition implements MeasureComputer.MeasureComputerDefinition { @@ -79,16 +74,20 @@ public class TestMeasureComputerDefinition implements MeasureComputer.MeasureCom return new TestMeasureComputerDefinition(this); } - private static String[] validateInputMetricKeys(@Nullable String[] inputMetrics) { + private static String[] validateInputMetricKeys(String[] inputMetrics) { requireNonNull(inputMetrics, "Input metrics cannot be null"); checkNotNull(inputMetrics); return inputMetrics; } - private static String[] validateOutputMetricKeys(@Nullable String[] outputMetrics) { + private static String[] validateOutputMetricKeys(String[] outputMetrics) { requireNonNull(outputMetrics, "Output metrics cannot be null"); checkArgument(outputMetrics.length > 0, "At least one output metric must be defined"); - FluentIterable.from(CoreMetrics.getMetrics()).transform(MetricToKey.INSTANCE).filter(new MatchMetricKey(outputMetrics)).size(); + + List<String> outputMetricKeys = asList(outputMetrics); + CoreMetrics.getMetrics().stream() + .map(Metric::getKey) + .forEach(metricKey -> checkArgument(!outputMetricKeys.contains(metricKey), "Core metrics are not allowed")); checkNotNull(outputMetrics); return outputMetrics; } @@ -99,28 +98,4 @@ public class TestMeasureComputerDefinition implements MeasureComputer.MeasureCom } } } - - private enum MetricToKey implements Function<Metric, String> { - INSTANCE; - - @Override - public String apply(@Nonnull Metric input) { - return input.getKey(); - } - } - - private static class MatchMetricKey implements Predicate<String> { - - private final List<String> metrics; - - public MatchMetricKey(String[] metrics) { - this.metrics = Arrays.asList(metrics); - } - - @Override - public boolean apply(@Nonnull String metric) { - checkArgument(!metrics.contains(metric), "Core metrics are not allowed"); - return true; - } - } } |