diff options
author | David Gageot <david@gageot.net> | 2012-10-05 10:58:44 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-10-05 12:46:08 +0200 |
commit | 3b491638221796e517421d401d23b16e1589eabc (patch) | |
tree | 780309ee3863454d6d4777b83cd3673a5710bf63 /sonar-plugin-api/src | |
parent | 0e4035176cadd517927a03abc6f41c4bdd5e1105 (diff) | |
download | sonarqube-3b491638221796e517421d401d23b16e1589eabc.tar.gz sonarqube-3b491638221796e517421d401d23b16e1589eabc.zip |
Fix violations
Diffstat (limited to 'sonar-plugin-api/src')
5 files changed, 175 insertions, 155 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 6025d79bd44..c829cd4ac17 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -19,6 +19,7 @@ */ package org.sonar.api.config; +import com.google.common.collect.ImmutableList; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -27,6 +28,8 @@ import org.sonar.api.PropertyType; import javax.annotation.Nullable; +import java.util.List; + /** * @since 3.0 */ @@ -56,19 +59,19 @@ public final class PropertyDefinition { } } - private String key; - private String defaultValue; - private String name; - private PropertyType type = PropertyType.STRING; - private String[] options; - private String description; - private String category; - private boolean onProject = false; - private boolean onModule = false; - private boolean isGlobal = true; - private boolean multiValues; - private String propertySetKey; - private PropertyFieldDefinition[] fields; + private final String key; + private final String defaultValue; + private final String name; + private final PropertyType type; + private final String[] options; + private final String description; + private final String category; + private final boolean onProject; + private final boolean onModule; + private final boolean isGlobal; + private final boolean multiValues; + private final String propertySetKey; + private final List<PropertyFieldDefinition> fields; private PropertyDefinition(Property annotation) { this.key = annotation.key(); @@ -82,8 +85,24 @@ public final class PropertyDefinition { this.type = fixType(annotation.key(), annotation.type()); this.options = annotation.options(); this.multiValues = annotation.multiValues(); - propertySetKey = annotation.propertySetKey(); - this.fields = PropertyFieldDefinition.create(annotation.fields()); + this.propertySetKey = annotation.propertySetKey(); + this.fields = ImmutableList.copyOf(PropertyFieldDefinition.create(annotation.fields())); + } + + private PropertyDefinition(String key, PropertyType type, String[] options) { + this.key = key; + this.name = null; + this.defaultValue = null; + this.description = null; + this.isGlobal = true; + this.onProject = false; + this.onModule = false; + this.category = null; + this.type = type; + this.options = options; + this.multiValues = false; + this.propertySetKey = null; + this.fields = null; } private static PropertyType fixType(String key, PropertyType type) { @@ -99,12 +118,6 @@ public final class PropertyDefinition { return type; } - private PropertyDefinition(String key, PropertyType type, String[] options) { - this.key = key; - this.type = type; - this.options = options; - } - public static PropertyDefinition create(Property annotation) { return new PropertyDefinition(annotation); } @@ -199,7 +212,7 @@ public final class PropertyDefinition { /** * @since 3.3 */ - public PropertyFieldDefinition[] getFields() { + public List<PropertyFieldDefinition> getFields() { return fields; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java index dfa4171792a..05fbea9cf7e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java @@ -47,12 +47,12 @@ public final class PropertyFieldDefinition { this.options = annotation.options(); } - public static PropertyFieldDefinition[] create(PropertyField[] fields) { + public static List<PropertyFieldDefinition> create(PropertyField[] fields) { List<PropertyFieldDefinition> definitions = Lists.newArrayList(); for (PropertyField field : fields) { definitions.add(new PropertyFieldDefinition(field)); } - return definitions.toArray(new PropertyFieldDefinition[definitions.size()]); + return definitions; } public String getKey() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java index 7e3adbf5073..fd65fb460a0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java @@ -973,13 +973,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_COVERAGE = new Metric.Builder(OVERALL_COVERAGE_KEY, "Overall coverage", Metric.ValueType.PERCENT) - .setDescription("Overall test coverage") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .create(); + .setDescription("Overall test coverage") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .create(); /** * @since 3.3 @@ -990,14 +990,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_COVERAGE = new Metric.Builder(NEW_OVERALL_COVERAGE_KEY, "Overall new coverage", Metric.ValueType.PERCENT) - .setDescription("Overall coverage of new/changed code") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Overall coverage of new/changed code") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1008,14 +1008,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_LINES_TO_COVER = new Metric.Builder(OVERALL_LINES_TO_COVER_KEY, "Overall lines to cover", Metric.ValueType.INT) - .setDescription("Overall lines to cover by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setDomain(DOMAIN_OVERALL_TESTS) - .setQualitative(false) - .setFormula(new SumChildValuesFormula(false)) - .setHidden(true) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Overall lines to cover by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setDomain(DOMAIN_OVERALL_TESTS) + .setQualitative(false) + .setFormula(new SumChildValuesFormula(false)) + .setHidden(true) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1026,13 +1026,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_LINES_TO_COVER = new Metric.Builder(NEW_OVERALL_LINES_TO_COVER_KEY, "Overall new lines to cover", Metric.ValueType.INT) - .setDescription("New lines to cover by all tests") - .setDirection(Metric.DIRECTION_WORST) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New lines to cover by all tests") + .setDirection(Metric.DIRECTION_WORST) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1043,12 +1043,12 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_UNCOVERED_LINES = new Metric.Builder(OVERALL_UNCOVERED_LINES_KEY, "Overall uncovered lines", Metric.ValueType.INT) - .setDescription("Uncovered lines by all tests") - .setDirection(Metric.DIRECTION_WORST) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .create(); + .setDescription("Uncovered lines by all tests") + .setDirection(Metric.DIRECTION_WORST) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .create(); /** * @since 3.3 @@ -1059,13 +1059,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_UNCOVERED_LINES = new Metric.Builder(NEW_OVERALL_UNCOVERED_LINES_KEY, "Overall new lines uncovered", Metric.ValueType.INT) - .setDescription("New lines that are not covered by any tests") - .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setBestValue(0.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New lines that are not covered by any tests") + .setDirection(Metric.DIRECTION_WORST) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setBestValue(0.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1076,11 +1076,11 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_LINE_COVERAGE = new Metric.Builder(OVERALL_LINE_COVERAGE_KEY, "Overall line coverage", Metric.ValueType.PERCENT) - .setDescription("Line coverage by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .create(); + .setDescription("Line coverage by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .create(); /** * @since 3.3 @@ -1091,14 +1091,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_LINE_COVERAGE = new Metric.Builder(NEW_OVERALL_LINE_COVERAGE_KEY, "Overall new line coverage", Metric.ValueType.PERCENT) - .setDescription("Line coverage of added/changed code by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setWorstValue(0.0) - .setBestValue(100.0) - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Line coverage of added/changed code by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setWorstValue(0.0) + .setBestValue(100.0) + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1109,12 +1109,12 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_COVERAGE_LINE_HITS_DATA = new Metric.Builder(OVERALL_COVERAGE_LINE_HITS_DATA_KEY, "Overall coverage hits by line", Metric.ValueType.DATA) - .setDescription("Coverage hits by all tests and by line") - .setDirection(Metric.DIRECTION_NONE) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Coverage hits by all tests and by line") + .setDirection(Metric.DIRECTION_NONE) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1125,14 +1125,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(OVERALL_CONDITIONS_TO_COVER_KEY, "Overall branches to cover", Metric.ValueType.INT) - .setDescription("Branches to cover by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setHidden(true) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Branches to cover by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setHidden(true) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1143,11 +1143,11 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(NEW_OVERALL_CONDITIONS_TO_COVER_KEY, "Overall new branches to cover", Metric.ValueType.INT) - .setDescription("New branches to cover by all tests") - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New branches to cover by all tests") + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1158,11 +1158,11 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall uncovered branches", Metric.ValueType.INT) - .setDescription("Uncovered branches by all tests") - .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .create(); + .setDescription("Uncovered branches by all tests") + .setDirection(Metric.DIRECTION_WORST) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .create(); /** * @since 3.3 @@ -1173,13 +1173,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall new branches uncovered", Metric.ValueType.INT) - .setDescription("New branches that are not covered by any test") - .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setBestValue(0.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New branches that are not covered by any test") + .setDirection(Metric.DIRECTION_WORST) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setBestValue(0.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1190,13 +1190,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_BRANCH_COVERAGE = new Metric.Builder(OVERALL_BRANCH_COVERAGE_KEY, "Overall branch coverage", Metric.ValueType.PERCENT) - .setDescription("Branch coverage by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .create(); + .setDescription("Branch coverage by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .create(); /** * @since 3.3 @@ -1207,14 +1207,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_BRANCH_COVERAGE = new Metric.Builder(NEW_OVERALL_BRANCH_COVERAGE_KEY, "Overall new branch coverage", Metric.ValueType.PERCENT) - .setDescription("Branch coverage of new/changed code by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Branch coverage of new/changed code by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1225,10 +1225,10 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_CONDITIONS_BY_LINE_KEY, "Overall branches by line", Metric.ValueType.DATA) - .setDescription("Overall branches by all tests and by line") - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Overall branches by all tests and by line") + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1238,12 +1238,12 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final Metric OVERALL_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, "Overall covered branches by line", Metric.ValueType.DATA) - .setDescription("Overall covered branches by all tests and by line") - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); - + public static final Metric OVERALL_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, "Overall covered branches by line", + Metric.ValueType.DATA) + .setDescription("Overall covered branches by all tests and by line") + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); // -------------------------------------------------------------------------------------------------------------------- // diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index ce4bdbc814e..134a0b4f6ad 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -20,6 +20,9 @@ package org.sonar.api.rules; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -93,15 +96,19 @@ public final class AnnotationRuleParser implements ServerComponent { } } + private static final Function<Class<?>, PropertyType> TYPE_FOR_CLASS = Functions.forMap( + ImmutableMap.<Class<?>, PropertyType> builder() + .put(Integer.class, PropertyType.INTEGER) + .put(int.class, PropertyType.INTEGER) + .put(Float.class, PropertyType.FLOAT) + .put(float.class, PropertyType.FLOAT) + .put(Boolean.class, PropertyType.BOOLEAN) + .put(boolean.class, PropertyType.BOOLEAN) + .build(), + PropertyType.STRING); + @VisibleForTesting static PropertyType guessType(Class<?> type) { - if ((type == Integer.class) || (type == int.class)) { - return PropertyType.INTEGER; - } else if ((type == Float.class) || (type == float.class)) { - return PropertyType.FLOAT; - } else if ((type == Boolean.class) || (type == boolean.class)) { - return PropertyType.BOOLEAN; - } - return PropertyType.STRING; + return TYPE_FOR_CLASS.apply(type); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java index bc76fcd7507..a0b2295f98b 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java @@ -94,17 +94,17 @@ public class PropertyDefinitionTest { PropertyDefinition def = PropertyDefinition.create(prop); assertThat(def.getFields()).hasSize(2); - assertThat(def.getFields()[0].getKey()).isEqualTo("first"); - assertThat(def.getFields()[0].getName()).isEqualTo("First"); - assertThat(def.getFields()[0].getDescription()).isEqualTo("Description"); - assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING); - assertThat(def.getFields()[0].getOptions()).containsOnly("A", "B"); - assertThat(def.getFields()[0].getIndicativeSize()).isEqualTo(20); - assertThat(def.getFields()[1].getKey()).isEqualTo("second"); - assertThat(def.getFields()[1].getName()).isEqualTo("Second"); - assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER); - assertThat(def.getFields()[1].getOptions()).isEmpty(); - assertThat(def.getFields()[1].getIndicativeSize()).isEqualTo(5); + assertThat(def.getFields().get(0).getKey()).isEqualTo("first"); + assertThat(def.getFields().get(0).getName()).isEqualTo("First"); + assertThat(def.getFields().get(0).getDescription()).isEqualTo("Description"); + assertThat(def.getFields().get(0).getType()).isEqualTo(PropertyType.STRING); + assertThat(def.getFields().get(0).getOptions()).containsOnly("A", "B"); + assertThat(def.getFields().get(0).getIndicativeSize()).isEqualTo(20); + assertThat(def.getFields().get(1).getKey()).isEqualTo("second"); + assertThat(def.getFields().get(1).getName()).isEqualTo("Second"); + assertThat(def.getFields().get(1).getType()).isEqualTo(PropertyType.INTEGER); + assertThat(def.getFields().get(1).getOptions()).isEmpty(); + assertThat(def.getFields().get(1).getIndicativeSize()).isEqualTo(5); } @Properties(@Property(key = "hello", name = "Hello")) |