summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-09-05 16:32:19 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-09-05 16:32:19 +0200
commit159ffab2f099d6a6cf37dba91d83b74d40b07524 (patch)
treed6afef44609c6a5839de1f8d895d7253e9419623
parent52cdc38ac06e8c40858e26d97b53d02b8f2b5926 (diff)
parenta37e3ae9be1fe8f0b2701490be42511fff128f8d (diff)
downloadsonarqube-159ffab2f099d6a6cf37dba91d83b74d40b07524.tar.gz
sonarqube-159ffab2f099d6a6cf37dba91d83b74d40b07524.zip
Merge branch 'branch-3.2' of github.com:SonarSource/sonar into branch-3.2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java21
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java27
2 files changed, 30 insertions, 18 deletions
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 df43d139657..ce3bdfacae0 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
@@ -19,8 +19,6 @@
*/
package org.sonar.api.rules;
-import org.sonar.api.utils.SonarException;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
@@ -29,6 +27,8 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.PropertyType;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.AnnotationUtils;
+import org.sonar.api.utils.FieldUtils2;
+import org.sonar.api.utils.SonarException;
import org.sonar.check.Check;
import java.lang.reflect.Field;
@@ -72,13 +72,10 @@ public final class AnnotationRuleParser implements ServerComponent {
rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
rule.setCardinality(ruleAnnotation.cardinality());
- Field[] fields = clazz.getDeclaredFields();
- if (fields != null) {
- for (Field field : fields) {
- addRuleProperty(rule, field);
- }
+ List<Field> fields = FieldUtils2.getFields(clazz, true);
+ for (Field field : fields) {
+ addRuleProperty(rule, field);
}
-
return rule;
}
@@ -89,11 +86,9 @@ public final class AnnotationRuleParser implements ServerComponent {
rule.setDescription(checkAnnotation.description());
rule.setSeverity(RulePriority.fromCheckPriority(checkAnnotation.priority()));
- Field[] fields = clazz.getDeclaredFields();
- if (fields != null) {
- for (Field field : fields) {
- addCheckProperty(rule, field);
- }
+ List<Field> fields = FieldUtils2.getFields(clazz, true);
+ for (Field field : fields) {
+ addCheckProperty(rule, field);
}
return rule;
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java
index 2fa2b5c30de..74877514357 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java
@@ -19,11 +19,10 @@
*/
package org.sonar.api.rules;
-import org.sonar.api.utils.SonarException;
-
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.PropertyType;
+import org.sonar.api.utils.SonarException;
import org.sonar.check.IsoCategory;
import org.sonar.check.Priority;
@@ -116,6 +115,18 @@ public class AnnotationRuleParserTest {
}
@Test
+ public void overridden_rule() {
+ List<Rule> rules = parseAnnotatedClass(OverridingRule.class);
+ assertThat(rules).hasSize(1);
+ Rule rule = rules.get(0);
+ assertThat(rule.getKey()).isEqualTo("overriding_foo");
+ assertThat(rule.getName()).isEqualTo("Overriding Foo");
+ assertThat(rule.getDescription()).isNull();
+ assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR);
+ assertThat(rule.getParams()).hasSize(2);
+ }
+
+ @Test
public void supportDeprecatedAnnotations() {
List<Rule> rules = parseAnnotatedClass(Check.class);
assertThat(rules).hasSize(1);
@@ -141,19 +152,25 @@ public class AnnotationRuleParserTest {
@org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
static class RuleWithProperty {
@org.sonar.check.RuleProperty(description = "Ignore ?", defaultValue = "false")
- public String property;
+ private String property;
+ }
+
+ @org.sonar.check.Rule(key = "overriding_foo", name = "Overriding Foo")
+ static class OverridingRule extends RuleWithProperty {
+ @org.sonar.check.RuleProperty
+ private String additionalProperty;
}
@org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
static class RuleWithIntegerProperty {
@org.sonar.check.RuleProperty(description = "Max", defaultValue = "12")
- public Integer property;
+ private Integer property;
}
@org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)
static class RuleWithTextProperty {
@org.sonar.check.RuleProperty(description = "text", defaultValue = "Long text", type = "TEXT")
- public String property;
+ protected String property;
}
@org.sonar.check.Rule(key = "foo", name = "bar", description = "Foo Bar", priority = Priority.BLOCKER)