1 | package com.framsticks.framclipse.editors.configuration;
|
---|
2 |
|
---|
3 | import org.eclipse.core.resources.IMarker;
|
---|
4 | import org.eclipse.core.resources.IResource;
|
---|
5 | import org.eclipse.core.runtime.CoreException;
|
---|
6 |
|
---|
7 | import com.framsticks.framclipse.internal.parser.ParseException;
|
---|
8 | import com.framsticks.framclipse.internal.parser.TokenMgrError;
|
---|
9 |
|
---|
10 | public abstract class ErrorHandler<T extends Throwable> {
|
---|
11 |
|
---|
12 | public IMarker createMarker(IResource resource, T error) throws CoreException {
|
---|
13 | IMarker marker = resource.createMarker(IMarker.PROBLEM);
|
---|
14 | marker.setAttribute(IMarker.LINE_NUMBER, getLine(error));
|
---|
15 | marker.setAttribute(IMarker.MESSAGE, getMessage(error));
|
---|
16 | marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
|
---|
17 | marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
|
---|
18 | return marker;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public abstract int getLine(T error);
|
---|
22 |
|
---|
23 | public abstract String getMessage(T error);
|
---|
24 |
|
---|
25 | public static class ParseErrorHandler extends ErrorHandler<ParseException> {
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public int getLine(ParseException e) {
|
---|
29 | return e.currentToken.next.beginLine;
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public String getMessage(ParseException e) {
|
---|
34 | return e.getMessage();
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public static class TokenErrorHandler extends ErrorHandler<TokenMgrError> {
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public int getLine(TokenMgrError e) {
|
---|
42 | return 1;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public String getMessage(TokenMgrError e) {
|
---|
47 | return e.getMessage();
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | }
|
---|