1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jci.compilers;
19
20 import org.apache.commons.jci.problems.CompilationProblem;
21 import org.codehaus.janino.Location;
22 import org.codehaus.janino.Scanner.ScanException;
23 import org.codehaus.janino.Parser.ParseException;
24
25
26
27
28
29
30 public final class JaninoCompilationProblem implements CompilationProblem {
31
32 private final Location location;
33 private final String fileName;
34 private final String message;
35 private final boolean error;
36
37 public JaninoCompilationProblem(final ParseException pParseException) {
38 this(pParseException.getLocation(), pParseException.getMessage(), true);
39 }
40
41 public JaninoCompilationProblem(final ScanException pScanException) {
42 this(pScanException.getLocation(), pScanException.getMessage(), true);
43 }
44
45 public JaninoCompilationProblem(final Location pLocation, final String pMessage, final boolean pError) {
46 this(pLocation.getFileName(), pLocation, pMessage, pError);
47 }
48
49 public JaninoCompilationProblem(final String pFilename, final String pMessage, final boolean pError) {
50 this(pFilename, null, pMessage, pError);
51 }
52
53 public JaninoCompilationProblem(final String pFilename, final Location pLocation, final String pMessage, final boolean pError) {
54 location = pLocation;
55 fileName = pFilename;
56 message = pMessage;
57 error = pError;
58 }
59
60 public boolean isError() {
61 return error;
62 }
63
64 public String getFileName() {
65 return fileName;
66 }
67
68 public int getStartLine() {
69 if (location == null) {
70 return 0;
71 }
72 return location.getLineNumber();
73 }
74
75 public int getStartColumn() {
76 if (location == null) {
77 return 0;
78 }
79 return location.getColumnNumber();
80 }
81
82 public int getEndLine() {
83 return getStartLine();
84 }
85
86 public int getEndColumn() {
87 return getStartColumn();
88 }
89
90 public String getMessage() {
91 return message;
92 }
93
94 public String toString() {
95 final StringBuffer sb = new StringBuffer();
96 sb.append(getFileName()).append(" (");
97 sb.append(getStartLine());
98 sb.append(":");
99 sb.append(getStartColumn());
100 sb.append(") : ");
101 sb.append(getMessage());
102 return sb.toString();
103 }
104
105 }