File tree Expand file tree Collapse file tree
plugin-api/src/main/java/org/sonar/api/measures Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 */
2020package org .sonar .api .measures ;
2121
22+ import org .sonar .api .issue .impact .Severity ;
23+
2224/**
2325 * Integer values that map to severity levels used by severity-based metrics.
2426 * Severities increase in numeric value; a higher value means a worse severity.
@@ -43,4 +45,49 @@ public final class SeverityValues {
4345 private SeverityValues () {
4446 // constants only
4547 }
48+
49+ /**
50+ * Maps a rule severity string (see {@link org.sonar.api.rule.Severity}) to a {@link SeverityValues} integer.
51+ *
52+ * @throws IllegalArgumentException if the severity string is not recognised
53+ * @since 13.6
54+ */
55+ public static int fromRuleSeverity (String severity ) {
56+ switch (severity ) {
57+ case org .sonar .api .rule .Severity .INFO :
58+ return INFO ;
59+ case org .sonar .api .rule .Severity .MINOR :
60+ return LOW ;
61+ case org .sonar .api .rule .Severity .MAJOR :
62+ return MEDIUM ;
63+ case org .sonar .api .rule .Severity .CRITICAL :
64+ return HIGH ;
65+ case org .sonar .api .rule .Severity .BLOCKER :
66+ return BLOCKER ;
67+ default :
68+ throw new IllegalArgumentException ("Unknown rule severity: " + severity );
69+ }
70+ }
71+
72+ /**
73+ * Maps impact severity (see {@link org.sonar.api.issue.impact.Severity}) to a {@link SeverityValues} integer.
74+ *
75+ * @since 13.6
76+ */
77+ public static int fromImpactSeverity (Severity severity ) {
78+ switch (severity ) {
79+ case INFO :
80+ return INFO ;
81+ case LOW :
82+ return LOW ;
83+ case MEDIUM :
84+ return MEDIUM ;
85+ case HIGH :
86+ return HIGH ;
87+ case BLOCKER :
88+ return BLOCKER ;
89+ default :
90+ throw new IllegalArgumentException ("Unknown impact severity: " + severity );
91+ }
92+ }
4693}
You can’t perform that action at this time.
0 commit comments