forked from jenkinsci/analysis-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavacParser.java
76 lines (63 loc) · 2.73 KB
/
JavacParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package edu.hm.hafner.analysis.parser;
import java.util.Optional;
import java.util.regex.Matcher;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.ParsingException;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.util.LookaheadStream;
import static edu.hm.hafner.analysis.Categories.*;
/**
* A parser for the javac compiler warnings.
*
* @author Ullrich Hafner
*/
public class JavacParser extends LookaheadParser {
private static final long serialVersionUID = 7199325311690082782L;
private static final String ERRORPRONE_URL_PATTERN = "\\s+\\(see https?://\\S+\\s*\\)";
private static final String JAVAC_WARNING_PATTERN
= "^(?:\\S+\\s+)?" // optional preceding arbitrary number of characters that are not a
// whitespace followed by whitespace. This can be used for timestamps.
+ "(?:(?:\\[(WARNING|ERROR)\\]|w:)\\s+)" // optional [WARNING] or [ERROR] or w:
+ "([^\\[\\(]*):\\s*" // group 1: filename
+ "[\\[\\(]" // [ or (
+ "(\\d+)[.,;]*" // group 2: line number
+ "\\s?(\\d+)?" // group 3: optional column
+ "[\\]\\)]\\s*" // ] or )
+ ":?" // optional :
+ "(?:\\[(\\w+)\\])?" // group 4: optional category
+ "\\s*(.*)$"; // group 5: message
/**
* Creates a new instance of {@link JavacParser}.
*/
public JavacParser() {
super(JAVAC_WARNING_PATTERN);
}
@Override
protected boolean isLineInteresting(final String line) {
return line.contains("[") || line.contains("w:");
}
@Override
protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStream lookahead,
final IssueBuilder builder) throws ParsingException {
if (lookahead.hasNext(ERRORPRONE_URL_PATTERN)) {
return Optional.empty();
}
String type = matcher.group(1);
if ("ERROR".equals(type)) {
builder.setSeverity(Severity.ERROR);
}
else {
builder.setSeverity(Severity.WARNING_NORMAL);
}
String message = matcher.group(6);
String category = guessCategoryIfEmpty(matcher.group(5), message);
return builder.setFileName(matcher.group(2))
.setLineStart(matcher.group(3))
.setColumnStart(matcher.group(4))
.setCategory(category)
.setMessage(message)
.buildOptional();
}
}