From 9417a1336e33e7036fa4da3cad6b9ec7c925121e Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 14 Nov 2021 21:50:53 +0100 Subject: [PATCH] extract method `getSeverity` --- .../analysis/parser/CodeCheckerParser.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java index 432050ee2..e9a540c79 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/CodeCheckerParser.java @@ -34,25 +34,30 @@ public CodeCheckerParser() { @Override protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) { - Severity priority; - if (matcher.group("severity").contains("CRITICAL")) { - priority = Severity.ERROR; - } - else if (matcher.group("severity").contains("HIGH")) { - priority = Severity.WARNING_HIGH; - } - else if (matcher.group("severity").contains("MEDIUM")) { - priority = Severity.WARNING_NORMAL; - } - else { - priority = Severity.WARNING_LOW; - } + Severity severity = getSeverity(matcher.group("severity")); return builder.setFileName(matcher.group("path")) - .setSeverity(priority) + .setSeverity(severity) .setLineStart(matcher.group("line")) .setColumnStart(matcher.group("column")) .setCategory(matcher.group("category")) .setMessage(matcher.group("message")) .buildOptional(); } + + private Severity getSeverity(final String severityText) { + Severity severity; + if (severityText.contains("CRITICAL")) { + severity = Severity.ERROR; + } + else if (severityText.contains("HIGH")) { + severity = Severity.WARNING_HIGH; + } + else if (severityText.contains("MEDIUM")) { + severity = Severity.WARNING_NORMAL; + } + else { + severity = Severity.WARNING_LOW; + } + return severity; + } }