From a35c03b255dac26885347b0c5afed10a8ff6b1cc Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 10 Jan 2014 15:08:32 +0100 Subject: [PATCH] Fix some quality flaws --- .../org/sonar/api/rule/RuleDefinitions.java | 19 +++++++++---------- .../sonar/api/rule/RuleDefinitionsTest.java | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java index 8b9f47082ae..f8113ddcbe1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java @@ -42,7 +42,7 @@ public interface RuleDefinitions extends ServerExtension { /** * Instantiated by core but not by plugins. */ - public static class Context { + static class Context { private final Map newRepositories = Maps.newHashMap(); private final ListMultimap extendedRepositories = ArrayListMultimap.create(); @@ -86,7 +86,7 @@ public interface RuleDefinitions extends ServerExtension { } } - public static interface ExtendedRepository { + static interface ExtendedRepository { String key(); NewRule newRule(String ruleKey); @@ -97,7 +97,7 @@ public interface RuleDefinitions extends ServerExtension { List getRules(); } - public static class NewRepository implements ExtendedRepository { + static class NewRepository implements ExtendedRepository { private final String key; private String language; private String name; @@ -170,12 +170,11 @@ public interface RuleDefinitions extends ServerExtension { } } - public static class NewRule { + static class NewRule { private final String repoKey, key; private String name, htmlDescription, metadata, defaultSeverity = Severity.MAJOR; private final Set tags = Sets.newHashSet(); private final Map params = Maps.newHashMap(); - // TODO cardinality ? or template boolean ? public NewRule(String repoKey, String key) { this.repoKey = repoKey; @@ -192,7 +191,7 @@ public interface RuleDefinitions extends ServerExtension { public NewRule setName(String s) { if (StringUtils.isBlank(s)) { - throw new IllegalArgumentException("Name of rule " + this + " is blank"); + throw new IllegalArgumentException(String.format("Name of rule %s is blank", this)); } this.name = s; return this; @@ -204,7 +203,7 @@ public interface RuleDefinitions extends ServerExtension { public NewRule setDefaultSeverity(String s) { if (!Severity.ALL.contains(s)) { - throw new IllegalArgumentException("Default severity of rule " + this + " is not correct: " + s); + throw new IllegalArgumentException(String.format("Default severity of rule %s is not correct: %s", this, s)); } this.defaultSeverity = s; return this; @@ -217,7 +216,7 @@ public interface RuleDefinitions extends ServerExtension { public NewRule setHtmlDescription(String s) { if (StringUtils.isBlank(s)) { - throw new IllegalArgumentException("HTML description of rule " + this + " is blank"); + throw new IllegalArgumentException(String.format("HTML description of rule %s is blank", this)); } this.htmlDescription = s; return this; @@ -225,7 +224,7 @@ public interface RuleDefinitions extends ServerExtension { public NewParam newParam(String paramKey) { if (params.containsKey(paramKey)) { - throw new IllegalArgumentException("The parameter '" + key + "' is declared several times on the rule " + this); + throw new IllegalArgumentException(String.format("The parameter '%s' is declared several times on the rule %s", paramKey, this)); } NewParam param = new NewParam(this, paramKey); params.put(paramKey, param); @@ -308,7 +307,7 @@ public interface RuleDefinitions extends ServerExtension { } } - public static class NewParam { + static class NewParam { private final NewRule rule; private final String key; private String name, description, defaultValue; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleDefinitionsTest.java index 8c8fb960663..1783a0e367f 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleDefinitionsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rule/RuleDefinitionsTest.java @@ -173,7 +173,7 @@ public class RuleDefinitionsTest { rule.newParam("level"); fail(); } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("The parameter 'NPE' is declared several times on the rule [repository=findbugs, key=NPE]"); + assertThat(e).hasMessage("The parameter 'level' is declared several times on the rule [repository=findbugs, key=NPE]"); } } -- 2.39.5