Changed GhsMultiParser to use Lookahead Parser
@@ -2,25 +2,32 @@ package edu.hm.hafner.analysis.parser;
import java.util.Optional;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
-import edu.hm.hafner.analysis.RegexpLineParser;
+import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.Severity;
+import edu.hm.hafner.util.LookaheadStream;
/**
* A parser for the GHS Multi compiler warnings.
*
* @author Joseph Boulos
*/
-public class GhsMultiParser extends RegexpLineParser {
+public class GhsMultiParser extends LookaheadParser {
private static final long serialVersionUID = 8149238560432255036L;
+ // Regex Pattern to match start of Warning / Error
+ // Groups are used to identify FileName, StartLine, Type, Category, Start of message
private static final String GHS_MULTI_WARNING_PATTERN =
- //"(?:\\.|[A-Z]:)(.*)\"\\,\\s*line\\s*(\\d+):\\s*(warning|error)\\s*([^:]+):\\s*(?m)([^\\^]*)\\s*\\^";
- "(?:\\.|[A-Z]:)(.*)\"\\,\\s*line\\s*(\\d+):\\s*(warning|error)\\s*([^:]+):";
+ "(?:\\.|[A-Z]:)(.*)\"\\,\\s*line\\s*(\\d+):\\s*(warning|error)\\s*([^:]+):\\s*(?m)([^\\^]*)";
+
+ // Regex Pattern to match the ending of the Warning / Error Message
+ private static final Pattern MESSAGE_END_PATTERN = Pattern.compile("\\s*\\^");
+
/**
* Creates a new instance of {@link GhsMultiParser}.
@@ -30,25 +37,28 @@ public class GhsMultiParser extends RegexpLineParser {
}
@Override
- protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder) {
+ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead, final IssueBuilder builder) {
String type = StringUtils.capitalize(matcher.group(3));
- return builder.setFileName(matcher.group(1))
- .setLineStart(matcher.group(2))
- .setCategory(matcher.group(4))
- .setMessage("TODO: Gather all lines untill ^ Symbol")
- .setSeverity(mapPriority(type))
- .buildOptional();
- }
+ StringBuilder messageBuilder = new StringBuilder(matcher.group(5));
+ messageBuilder.append("\n");
- private Severity mapPriority(final String type) {
- Severity priority;
- if ("warning".equalsIgnoreCase(type)) {
- priority = Severity.WARNING_NORMAL;
+ boolean messageEndFound = false;
+ while (!messageEndFound && lookahead.hasNext()) {
+ String messageLine = lookahead.next();
+ Matcher messageEndMatcher = MESSAGE_END_PATTERN.matcher(messageLine);
+ if (messageEndMatcher.matches()) {
+ messageEndFound = true;
}
else {
- priority = Severity.WARNING_HIGH;
+ messageBuilder.append(messageLine).append("\n");
+ }
}
- return priority;
+ return builder.setFileName(matcher.group(1))
+ .setLineStart(matcher.group(2))
+ .setCategory(matcher.group(4))
+ .setMessage(messageBuilder.toString())
+ .setSeverity(Severity.guessFromString(type))
+ .buildOptional();
}
}
