aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-11-18 09:08:40 -0600
committersonartech <sonartech@sonarsource.com>2021-11-18 20:03:33 +0000
commit9f7a5068bb26f2760332c6e0bacec424e2edd47a (patch)
tree51ff128c6f77d1d15db5abe7960a90c74ee3d783 /sonar-plugin-api/src
parenteda9dff59cc60209b15b69ef4aa4c18885c0c744 (diff)
downloadsonarqube-9f7a5068bb26f2760332c6e0bacec424e2edd47a.tar.gz
sonarqube-9f7a5068bb26f2760332c6e0bacec424e2edd47a.zip
Improve code quality
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java26
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/text/CsvWriter.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rules/RulePriorityTest.java12
4 files changed, 19 insertions, 24 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 360488d1085..36672205968 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
@@ -109,7 +109,7 @@ public class Checks<C> {
}
public Checks<C> addAnnotatedChecks(Object... checkClassesOrObjects) {
- return addAnnotatedChecks((Iterable) Arrays.asList(checkClassesOrObjects));
+ return addAnnotatedChecks(Arrays.asList(checkClassesOrObjects));
}
public Checks<C> addAnnotatedChecks(Iterable checkClassesOrObjects) {
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 88986262343..52596910143 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
@@ -44,8 +44,18 @@ import org.sonar.api.utils.log.Loggers;
@ServerSide
@ComputeEngineSide
public final class AnnotationRuleParser {
-
private static final Logger LOG = Loggers.get(AnnotationRuleParser.class);
+ private static final Map<Class<?>, PropertyType> TYPE_FOR_CLASS_MAP = new HashMap<>();
+ private static final Function<Class<?>, PropertyType> TYPE_FOR_CLASS = type -> TYPE_FOR_CLASS_MAP.getOrDefault(type, PropertyType.STRING);
+
+ static {
+ TYPE_FOR_CLASS_MAP.put(Integer.class, PropertyType.INTEGER);
+ TYPE_FOR_CLASS_MAP.put(int.class, PropertyType.INTEGER);
+ TYPE_FOR_CLASS_MAP.put(Float.class, PropertyType.FLOAT);
+ TYPE_FOR_CLASS_MAP.put(float.class, PropertyType.FLOAT);
+ TYPE_FOR_CLASS_MAP.put(Boolean.class, PropertyType.BOOLEAN);
+ TYPE_FOR_CLASS_MAP.put(boolean.class, PropertyType.BOOLEAN);
+ }
public List<Rule> parse(String repositoryKey, Collection<Class> annotatedClasses) {
List<Rule> rules = new ArrayList<>();
@@ -101,20 +111,6 @@ public final class AnnotationRuleParser {
}
}
- private static final Map<Class<?>, PropertyType> TYPE_FOR_CLASS_MAP = new HashMap<>();
-
- static {
- TYPE_FOR_CLASS_MAP.put(Integer.class, PropertyType.INTEGER);
- TYPE_FOR_CLASS_MAP.put(int.class, PropertyType.INTEGER);
- TYPE_FOR_CLASS_MAP.put(Float.class, PropertyType.FLOAT);
- TYPE_FOR_CLASS_MAP.put(float.class, PropertyType.FLOAT);
- TYPE_FOR_CLASS_MAP.put(Boolean.class, PropertyType.BOOLEAN);
- TYPE_FOR_CLASS_MAP.put(boolean.class, PropertyType.BOOLEAN);
-
- }
-
- private static final Function<Class<?>, PropertyType> TYPE_FOR_CLASS = type -> TYPE_FOR_CLASS_MAP.getOrDefault(type, PropertyType.STRING);
-
static PropertyType guessType(Class<?> type) {
return TYPE_FOR_CLASS.apply(type);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/CsvWriter.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/CsvWriter.java
index 919681d2422..97a4c677ced 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/CsvWriter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/text/CsvWriter.java
@@ -28,10 +28,9 @@ import java.io.Writer;
* @since 4.2
*/
public class CsvWriter {
-
- private final Writer writer;
private static final String VALUE_SEPARATOR = ",";
private static final String LINE_SEPARATOR = "\r\n";
+ private final Writer writer;
private CsvWriter(Writer writer) {
this.writer = writer;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RulePriorityTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RulePriorityTest.java
index 8d4e9451af6..602053cf8b4 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RulePriorityTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RulePriorityTest.java
@@ -28,12 +28,12 @@ public class RulePriorityTest {
@Test
public void testValueOfString() {
- assertThat(RulePriority.INFO).isEqualTo(RulePriority.valueOfString("info"));
- assertThat(RulePriority.MAJOR).isEqualTo(RulePriority.valueOfString("MAJOR"));
- assertThat(RulePriority.MAJOR).isEqualTo(RulePriority.valueOfString("ERROR"));
- assertThat(RulePriority.INFO).isEqualTo(RulePriority.valueOfString("WARNING"));
- assertThat(RulePriority.MAJOR).isEqualTo(RulePriority.valueOfString("ErRor"));
- assertThat(RulePriority.INFO).isEqualTo(RulePriority.valueOfString("WaRnInG"));
+ assertThat(RulePriority.valueOfString("info")).isEqualTo(RulePriority.INFO);
+ assertThat(RulePriority.valueOfString("MAJOR")).isEqualTo(RulePriority.MAJOR);
+ assertThat(RulePriority.valueOfString("ERROR")).isEqualTo(RulePriority.MAJOR);
+ assertThat(RulePriority.valueOfString("WARNING")).isEqualTo(RulePriority.INFO);
+ assertThat(RulePriority.valueOfString("ErRor")).isEqualTo(RulePriority.MAJOR);
+ assertThat(RulePriority.valueOfString("WaRnInG")).isEqualTo(RulePriority.INFO);
}
@Test(expected = IllegalArgumentException.class)