Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonar.api.measures;

import org.sonar.api.issue.impact.Severity;

/**
* Integer values that map to severity levels used by severity-based metrics.
* Severities increase in numeric value; a higher value means a worse severity.
Expand All @@ -43,4 +45,49 @@ public final class SeverityValues {
private SeverityValues() {
// constants only
}

/**
* Maps a rule severity string (see {@link org.sonar.api.rule.Severity}) to a {@link SeverityValues} integer.
*
* @throws IllegalArgumentException if the severity string is not recognised
* @since 13.6
*/
public static int fromRuleSeverity(String severity) {
Comment thread
sonar-review-alpha[bot] marked this conversation as resolved.
switch (severity) {
case org.sonar.api.rule.Severity.INFO:
return INFO;
case org.sonar.api.rule.Severity.MINOR:
return LOW;
case org.sonar.api.rule.Severity.MAJOR:
return MEDIUM;
case org.sonar.api.rule.Severity.CRITICAL:
return HIGH;
case org.sonar.api.rule.Severity.BLOCKER:
return BLOCKER;
default:
throw new IllegalArgumentException("Unknown rule severity: " + severity);
}
}

/**
* Maps impact severity (see {@link org.sonar.api.issue.impact.Severity}) to a {@link SeverityValues} integer.
*
* @since 13.6
*/
public static int fromImpactSeverity(Severity severity) {
switch (severity) {
case INFO:
return INFO;
case LOW:
return LOW;
case MEDIUM:
return MEDIUM;
case HIGH:
return HIGH;
case BLOCKER:
return BLOCKER;
default:
throw new IllegalArgumentException("Unknown impact severity: " + severity);
}
}
}
Loading