01: package org.drools.compiler;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.commons.jci.problems.CompilationProblem;
20: import org.drools.lang.descr.FunctionDescr;
21:
22: public class FunctionError extends DroolsError {
23: final private FunctionDescr functionDescr;
24: final private Object object;
25: final private String message;
26: private int[] errorLines;
27:
28: public FunctionError(final FunctionDescr functionDescr,
29: final Object object, final String message) {
30: super ();
31: this .functionDescr = functionDescr;
32: this .object = object;
33: this .message = createMessage(message);
34: }
35:
36: public FunctionDescr getFunctionDescr() {
37: return this .functionDescr;
38: }
39:
40: public Object getObject() {
41: return this .object;
42: }
43:
44: public int[] getErrorLines() {
45: return errorLines;
46: }
47:
48: public String getMessage() {
49: return this .message;
50: }
51:
52: public String toString() {
53: return this .message;
54: }
55:
56: private String createMessage(String message) {
57: StringBuffer detail = new StringBuffer();
58: if (object instanceof CompilationProblem[]) {
59: CompilationProblem[] cp = (CompilationProblem[]) object;
60: this .errorLines = new int[cp.length];
61: for (int i = 0; i < cp.length; i++) {
62: this .errorLines[i] = cp[i].getStartLine()
63: - this .functionDescr.getOffset()
64: + this .getFunctionDescr().getLine() - 1;
65: detail.append(this .functionDescr.getName());
66: detail.append(" (line:");
67: detail.append(this .errorLines[i]);
68: detail.append("): ");
69: detail.append(cp[i].getMessage());
70: detail.append("\n");
71: }
72: } else {
73: this .errorLines = new int[0];
74: }
75: return "[ " + functionDescr.getName() + " : " + message + "\n"
76: + detail.toString() + " ]";
77: }
78:
79: }
|