-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ErrorReporter.java
171 lines (148 loc) · 5.22 KB
/
ErrorReporter.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package org.lflang;
import java.nio.file.Path;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.lflang.generator.Position;
/**
* Interface for reporting errors.
*
* @author Edward A. Lee <eal@berkeley.edu>
* @author Marten Lohstroh <marten@berkeley.edu>
* @author Christian Menard <christian.menard@tu-dresden.de>
*/
public interface ErrorReporter {
/**
* Report an error.
*
* @param message The error message.
* @return a string that describes the error.
*/
String reportError(String message);
/**
* Report a warning.
*
* @param message The warning message.
* @return a string that describes the warning.
*/
String reportWarning(String message);
/**
* Report an informational message.
*
* @param message The message to report
* @return a string that describes the error
*/
String reportInfo(String message);
/**
* Report an error on the specified parse tree object.
*
* @param object The parse tree object.
* @param message The error message.
* @return a string that describes the error.
*/
String reportError(EObject object, String message);
/**
* Report a warning on the specified parse tree object.
*
* @param object The parse tree object.
* @param message The error message.
* @return a string that describes the warning.
*/
String reportWarning(EObject object, String message);
/**
* Report an informational message on the specified parse tree object.
* @param object The parse tree object.
* @param message The inforomational message
* @return a string that describes the info
*/
String reportInfo(EObject object, String message);
/**
* Report an error at the specified line within a file.
*
* @param message The error message.
* @param line The one-based line number to report at.
* @param file The file to report at.
* @return a string that describes the error.
*/
String reportError(Path file, Integer line, String message);
/**
* Report a warning at the specified line within a file.
*
* @param message The error message.
* @param line The one-based line number to report at.
* @param file The file to report at.
* @return a string that describes the warning.
*/
String reportWarning(Path file, Integer line, String message);
/**
*
* @param file The file to report at.
* @param line The one-based line number to report at.
* @param message The error message.
* @return
*/
String reportInfo(Path file, Integer line, String message);
/**
* Report a message of severity {@code severity}.
* @param file The file to which the message pertains, or {@code null} if the file is unknown.
* @param severity the severity of the message
* @param message the message to send to the IDE
* @return a string that describes the diagnostic
*/
default String report(Path file, DiagnosticSeverity severity, String message) {
switch (severity) {
case Error:
return reportError(message);
case Warning:
case Hint:
case Information:
return reportInfo(message);
default:
return reportWarning(message);
}
}
/**
* Report a message of severity {@code severity} that
* pertains to line {@code line} of an LF source file.
* @param file The file to which the message pertains, or {@code null} if the file is unknown.
* @param severity the severity of the message
* @param message the message to send to the IDE
* @param line the one-based line number associated
* with the message
* @return a string that describes the diagnostic
*/
default String report(Path file, DiagnosticSeverity severity, String message, int line) {
switch (severity) {
case Error:
return reportError(file, line, message);
case Warning:
case Hint:
case Information:
return reportInfo(file, line, message);
default:
return reportWarning(file, line, message);
}
}
/**
* Report a message of severity {@code severity} that
* pertains to the range [{@code startPos}, {@code endPos})
* of an LF source file.
* @param file The file to which the message pertains, or {@code null} if the file is unknown.
* @param severity the severity of the message
* @param message the message to send to the IDE
* @param startPos the position of the first character
* of the range of interest
* @param endPos the position immediately AFTER the
* final character of the range of
* interest
* @return a string that describes the diagnostic
*/
default String report(Path file, DiagnosticSeverity severity, String message, Position startPos, Position endPos) {
return report(file, severity, message, startPos.getOneBasedLine());
}
/**
* Check if errors where reported.
*
* @return true if errors where reported
*/
boolean getErrorsOccurred();
}