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.commons.compiler.LocatedException;
22 import org.codehaus.commons.compiler.Location;
23
24
25
26
27
28
29 public final class JaninoCompilationProblem implements CompilationProblem {
30
31 private final Location location;
32 private final String fileName;
33 private final String message;
34 private final boolean error;
35
36 public JaninoCompilationProblem(final LocatedException pLocatedException) {
37 this(pLocatedException.getLocation(), pLocatedException.getMessage(), true);
38 }
39
40 public JaninoCompilationProblem(final Location pLocation, final String pMessage, final boolean pError) {
41 this(pLocation.getFileName(), pLocation, pMessage, pError);
42 }
43
44 public JaninoCompilationProblem(final String pFilename, final String pMessage, final boolean pError) {
45 this(pFilename, null, pMessage, pError);
46 }
47
48 public JaninoCompilationProblem(final String pFilename, final Location pLocation, final String pMessage, final boolean pError) {
49 location = pLocation;
50 fileName = pFilename;
51 message = pMessage;
52 error = pError;
53 }
54
55 public boolean isError() {
56 return error;
57 }
58
59 public String getFileName() {
60 return fileName;
61 }
62
63 public int getStartLine() {
64 if (location == null) {
65 return 0;
66 }
67 return location.getLineNumber();
68 }
69
70 public int getStartColumn() {
71 if (location == null) {
72 return 0;
73 }
74 return location.getColumnNumber();
75 }
76
77 public int getEndLine() {
78 return getStartLine();
79 }
80
81 public int getEndColumn() {
82 return getStartColumn();
83 }
84
85 public String getMessage() {
86 return message;
87 }
88
89 @Override
90 public String toString() {
91 final StringBuilder sb = new StringBuilder();
92 sb.append(getFileName()).append(" (");
93 sb.append(getStartLine());
94 sb.append(":");
95 sb.append(getStartColumn());
96 sb.append(") : ");
97 sb.append(getMessage());
98 return sb.toString();
99 }
100
101 }