diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-03 08:37:43 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-07-03 11:23:41 +0200 |
commit | 854f1e5cd9acdad37fc041f7966aa85f39c8523f (patch) | |
tree | 36b7f6d145912f98abdbda28b84e5389a2356ebb /sonar-batch/src | |
parent | 7f218017d505877feb4415b0568dde3fb8492172 (diff) | |
download | sonarqube-854f1e5cd9acdad37fc041f7966aa85f39c8523f.tar.gz sonarqube-854f1e5cd9acdad37fc041f7966aa85f39c8523f.zip |
Fix quality flaws
Diffstat (limited to 'sonar-batch/src')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java | 24 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java | 33 |
2 files changed, 31 insertions, 26 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java index 27a64a9e21f..2e41b0401fa 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java @@ -21,6 +21,9 @@ package org.sonar.batch.report; import com.google.common.base.Function; import com.google.common.collect.Iterables; +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.Nonnull; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.measures.CoreMetrics; @@ -33,9 +36,6 @@ import org.sonar.batch.protocol.output.BatchReport.Coverage.Builder; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.scan.measure.MeasureCache; -import java.util.LinkedHashMap; -import java.util.Map; - public class CoveragePublisher implements ReportPublisherStep { private final BatchComponentCache resourceCache; @@ -91,12 +91,7 @@ public class CoveragePublisher implements ReportPublisherStep { } }); - writer.writeComponentCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), new Function<Coverage.Builder, Coverage>() { - @Override - public Coverage apply(Builder input) { - return input.build(); - } - })); + writer.writeComponentCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), BuildCoverage.INSTANCE)); } } @@ -123,8 +118,17 @@ public class CoveragePublisher implements ReportPublisherStep { } } - static interface MeasureOperation { + interface MeasureOperation { void apply(String value, Coverage.Builder builder); } + private enum BuildCoverage implements Function<Coverage.Builder, Coverage>{ + INSTANCE; + + @Override + public Coverage apply(@Nonnull Builder input) { + return input.build(); + } + } + } diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java index 4ddfe03452e..1d90a8ce3ff 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java @@ -23,6 +23,7 @@ import com.google.common.base.Function; import com.google.common.collect.Iterables; import java.util.Map; import java.util.Set; +import javax.annotation.Nonnull; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; @@ -193,22 +194,7 @@ public class DefaultSensorStorage implements SensorStorage { BatchReportWriter writer = reportPublisher.getWriter(); DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile(); writer.writeComponentSyntaxHighlighting(resourceCache.get(inputFile).batchId(), - Iterables.transform(highlighting.getSyntaxHighlightingRuleSet(), new Function<SyntaxHighlightingRule, BatchReport.SyntaxHighlighting>() { - private BatchReport.SyntaxHighlighting.Builder builder = BatchReport.SyntaxHighlighting.newBuilder(); - private Range.Builder rangeBuilder = Range.newBuilder(); - - @Override - public BatchReport.SyntaxHighlighting apply(SyntaxHighlightingRule input) { - builder.setRange(rangeBuilder.setStartLine(input.range().start().line()) - .setStartOffset(input.range().start().lineOffset()) - .setEndLine(input.range().end().line()) - .setEndOffset(input.range().end().lineOffset()) - .build()); - builder.setType(BatchReportUtils.toProtocolType(input.getTextType())); - return builder.build(); - } - - })); + Iterables.transform(highlighting.getSyntaxHighlightingRuleSet(), new BuildSyntaxHighlighting())); } public void store(DefaultInputFile inputFile, Map<Symbol, Set<TextRange>> referencesBySymbol) { @@ -259,6 +245,21 @@ public class DefaultSensorStorage implements SensorStorage { sonarIndex.addMeasure(file, new org.sonar.api.measures.Measure(type.coveredConditionsByLine()).setData(KeyValueFormat.format(defaultCoverage.coveredConditionsByLine()))); sonarIndex.addMeasure(file, new org.sonar.api.measures.Measure(type.conditionsByLine()).setData(KeyValueFormat.format(defaultCoverage.conditionsByLine()))); } + } + private static class BuildSyntaxHighlighting implements Function<SyntaxHighlightingRule, BatchReport.SyntaxHighlighting> { + private BatchReport.SyntaxHighlighting.Builder builder = BatchReport.SyntaxHighlighting.newBuilder(); + private Range.Builder rangeBuilder = Range.newBuilder(); + + @Override + public BatchReport.SyntaxHighlighting apply(@Nonnull SyntaxHighlightingRule input) { + builder.setRange(rangeBuilder.setStartLine(input.range().start().line()) + .setStartOffset(input.range().start().lineOffset()) + .setEndLine(input.range().end().line()) + .setEndOffset(input.range().end().lineOffset()) + .build()); + builder.setType(BatchReportUtils.toProtocolType(input.getTextType())); + return builder.build(); + } } } |