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.groovy.control.messages.ExceptionMessage;
22 import org.codehaus.groovy.control.messages.Message;
23 import org.codehaus.groovy.control.messages.SimpleMessage;
24 import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
25 import org.codehaus.groovy.syntax.SyntaxException;
26
27
28
29
30
31
32 public final class GroovyCompilationProblem implements CompilationProblem {
33
34 private final String fileName;
35 private final String message;
36 private final boolean error;
37 private final int startLine;
38 private final int startColumn;
39 private final int endLine;
40 private final int endColumn;
41
42 public GroovyCompilationProblem(final Message pMessage) {
43 if (pMessage instanceof SimpleMessage) {
44 error = false;
45 } else {
46 error = true;
47 }
48 if (pMessage instanceof SyntaxErrorMessage) {
49 SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)pMessage;
50 SyntaxException syntaxException = syntaxErrorMessage.getCause();
51 message = syntaxException.getMessage();
52 fileName = syntaxException.getSourceLocator();
53
54 startLine = syntaxException.getStartLine();
55 startColumn = syntaxException.getStartColumn();
56 endLine = syntaxException.getLine();
57 endColumn = syntaxException.getEndColumn();
58 } else {
59 fileName = "";
60 startLine = 0;
61 startColumn = 0;
62 endLine = 0;
63 endColumn = 0;
64 if (pMessage instanceof ExceptionMessage) {
65 message = ((ExceptionMessage)pMessage).getCause().getMessage();
66 } else if (pMessage instanceof SimpleMessage) {
67 message = ((SimpleMessage)pMessage).getMessage();
68 } else {
69 message = pMessage.toString();
70 }
71 }
72 }
73
74 public boolean isError() {
75 return error;
76 }
77
78 public String getFileName() {
79 return fileName;
80 }
81
82 public int getStartLine() {
83 return startLine;
84 }
85
86 public int getStartColumn() {
87 return startColumn;
88 }
89
90 public int getEndLine() {
91 return endLine;
92 }
93
94 public int getEndColumn() {
95 return endColumn;
96 }
97
98 public String getMessage() {
99 return message;
100 }
101
102 @Override
103 public String toString() {
104 return getMessage();
105 }
106
107 }