Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / problem / DefaultProblem.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.problem;
12
13 import net.sourceforge.phpdt.core.compiler.IProblem;
14 //import net.sourceforge.phpdt.internal.compiler.util.Util;
15
16 public class DefaultProblem implements ProblemSeverities, IProblem {
17         private char[] fileName;
18
19         private int id;
20
21         private int startPosition, endPosition, line;
22
23         private int severity;
24
25         private String[] arguments;
26
27         private String message;
28
29         public DefaultProblem(char[] originatingFileName, String message, int id,
30                         String[] stringArguments, int severity, int startPosition,
31                         int endPosition, int line) {
32                 this.fileName = originatingFileName;
33                 this.message = message;
34                 this.id = id;
35                 this.arguments = stringArguments;
36                 this.severity = severity;
37                 this.startPosition = startPosition;
38                 this.endPosition = endPosition;
39                 this.line = line;
40         }
41
42 //      public String errorReportSource(char[] unitSource) {
43 //              // extra from the source the innacurate token
44 //              // and "highlight" it using some underneath ^^^^^
45 //              // put some context around too.
46 //              // this code assumes that the font used in the console is fixed size
47 //              // sanity .....
48 //              if ((startPosition > endPosition)
49 //                              || ((startPosition < 0) && (endPosition < 0)))
50 //                      return Util.bind("problem.noSourceInformation"); //$NON-NLS-1$
51 //              StringBuffer errorBuffer = new StringBuffer(" "); //$NON-NLS-1$
52 //              errorBuffer.append(Util.bind("problem.atLine", String.valueOf(line))); //$NON-NLS-1$
53 //              errorBuffer.append("\n\t"); //$NON-NLS-1$
54 //              char c;
55 //              final char SPACE = '\u0020';
56 //              final char MARK = '^';
57 //              final char TAB = '\t';
58 //              // the next code tries to underline the token.....
59 //              // it assumes (for a good display) that token source does not
60 //              // contain any \r \n. This is false on statements !
61 //              // (the code still works but the display is not optimal !)
62 //              // expand to line limits
63 //              int length = unitSource.length, begin, end;
64 //              for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) {
65 //                      if ((c = unitSource[begin - 1]) == '\n' || c == '\r')
66 //                              break;
67 //              }
68 //              for (end = endPosition >= length ? length - 1 : endPosition; end + 1 < length; end++) {
69 //                      if ((c = unitSource[end + 1]) == '\r' || c == '\n')
70 //                              break;
71 //              }
72 //              // trim left and right spaces/tabs
73 //              while ((c = unitSource[begin]) == ' ' || c == '\t')
74 //                      begin++;
75 //              // while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO
76 //              // (philippe) should also trim right, but all tests are to be updated
77 //              // copy source
78 //              errorBuffer.append(unitSource, begin, end - begin + 1);
79 //              errorBuffer.append("\n\t"); //$NON-NLS-1$
80 //              // compute underline
81 //              for (int i = begin; i < startPosition; i++) {
82 //                      errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE);
83 //              }
84 //              for (int i = startPosition; i <= (endPosition >= length ? length - 1
85 //                              : endPosition); i++) {
86 //                      errorBuffer.append(MARK);
87 //              }
88 //              return errorBuffer.toString();
89 //      }
90
91         // public String errorReportSource(ITextEditor textEditor){
92         // //ICompilationUnit compilationUnit) {
93         // //extra from the source the innacurate token
94         // //and "highlight" it using some underneath ^^^^^
95         // //put some context around too.
96         //
97         // //this code assumes that the font used in the console is fixed size
98         //
99         // //sanity .....
100         // if ((startPosition > endPosition)
101         // || ((startPosition <= 0) && (endPosition <= 0)))
102         // return ProjectPrefUtil.bind("problem.noSourceInformation"); //$NON-NLS-1$
103         //
104         // final char SPACE = '\u0020';
105         // final char MARK = '^';
106         // final char TAB = '\t';
107         // // char[] source = compilationUnit.getContents();
108         // char[] source =
109         // textEditor.getDocumentProvider().getDocument(null).get().toCharArray();
110         // //the next code tries to underline the token.....
111         // //it assumes (for a good display) that token source does not
112         // //contain any \r \n. This is false on statements !
113         // //(the code still works but the display is not optimal !)
114         //
115         // //compute the how-much-char we are displaying around the inaccurate
116         // token
117         // int begin = startPosition >= source.length ? source.length - 1 :
118         // startPosition;
119         // int relativeStart = 0;
120         // int end = endPosition >= source.length ? source.length - 1 :
121         // endPosition;
122         // int relativeEnd = 0;
123         // label : for (relativeStart = 0;; relativeStart++) {
124         // if (begin == 0)
125         // break label;
126         // if ((source[begin - 1] == '\n') || (source[begin - 1] == '\r'))
127         // break label;
128         // begin--;
129         // }
130         // label : for (relativeEnd = 0;; relativeEnd++) {
131         // if ((end + 1) >= source.length)
132         // break label;
133         // if ((source[end + 1] == '\r') || (source[end + 1] == '\n')) {
134         // break label;
135         // }
136         // end++;
137         // }
138         // //extract the message form the source
139         // char[] extract = new char[end - begin + 1];
140         // System.arraycopy(source, begin, extract, 0, extract.length);
141         // char c;
142         // //remove all SPACE and TAB that begin the error message...
143         // int trimLeftIndex = 0;
144         // while (((c = extract[trimLeftIndex++]) == TAB) || (c == SPACE)) {
145         // };
146         // System.arraycopy(
147         // extract,
148         // trimLeftIndex - 1,
149         // extract = new char[extract.length - trimLeftIndex + 1],
150         // 0,
151         // extract.length);
152         // relativeStart -= trimLeftIndex;
153         // //buffer spaces and tabs in order to reach the error position
154         // int pos = 0;
155         // char[] underneath = new char[extract.length]; // can't be bigger
156         // for (int i = 0; i <= relativeStart; i++) {
157         // if (extract[i] == TAB) {
158         // underneath[pos++] = TAB;
159         // } else {
160         // underneath[pos++] = SPACE;
161         // }
162         // }
163         // //mark the error position
164         // for (int i = startPosition;
165         // i <= (endPosition >= source.length ? source.length - 1 : endPosition);
166         // i++)
167         // underneath[pos++] = MARK;
168         // //resize underneathto remove 'null' chars
169         // System.arraycopy(underneath, 0, underneath = new char[pos], 0, pos);
170         //
171         // return " " + ProjectPrefUtil.bind("problem.atLine", String.valueOf(line))
172         // //$NON-NLS-2$ //$NON-NLS-1$
173         // + "\n\t" + new String(extract) + "\n\t" + new String(underneath);
174         // //$NON-NLS-2$ //$NON-NLS-1$
175         // }
176         /**
177          * Answer back the original arguments recorded into the problem.
178          * 
179          * @return java.lang.String[]
180          */
181         public String[] getArguments() {
182                 return arguments;
183         }
184
185         /**
186          * Answer the type of problem.
187          * 
188          * @see net.sourceforge.phpdt.core.compiler.IProblem#getID()
189          * @return int
190          */
191         public int getID() {
192                 return id;
193         }
194
195         /**
196          * Answer a localized, human-readable message string which describes the
197          * problem.
198          * 
199          * @return java.lang.String
200          */
201         public String getMessage() {
202                 return message;
203         }
204
205         /**
206          * Answer the file name in which the problem was found.
207          * 
208          * @return char[]
209          */
210         public char[] getOriginatingFileName() {
211                 return fileName;
212         }
213
214         /**
215          * Answer the end position of the problem (inclusive), or -1 if unknown.
216          * 
217          * @return int
218          */
219         public int getSourceEnd() {
220                 return endPosition;
221         }
222
223         /**
224          * Answer the line number in source where the problem begins.
225          * 
226          * @return int
227          */
228         public int getSourceLineNumber() {
229                 return line;
230         }
231
232         /**
233          * Answer the start position of the problem (inclusive), or -1 if unknown.
234          * 
235          * @return int
236          */
237         public int getSourceStart() {
238                 return startPosition;
239         }
240
241         /*
242          * Helper method: checks the severity to see if the Error bit is set.
243          * @return boolean
244          */
245         public boolean isError() {
246                 return (severity & ProblemSeverities.Error) != 0;
247         }
248
249         /*
250          * Helper method: checks the severity to see if the Error bit is not set.
251          * @return boolean
252          */
253         public boolean isWarning() {
254                 return (severity & ProblemSeverities.Error) == 0;
255         }
256
257         /**
258          * Set the end position of the problem (inclusive), or -1 if unknown.
259          * 
260          * Used for shifting problem positions.
261          * 
262          * @param sourceEnd
263          *            the new value of the sourceEnd of the receiver
264          */
265         public void setSourceEnd(int sourceEnd) {
266                 endPosition = sourceEnd;
267         }
268
269         /**
270          * Set the line number in source where the problem begins.
271          * 
272          * @param lineNumber
273          *            the new value of the line number of the receiver
274          */
275         public void setSourceLineNumber(int lineNumber) {
276                 line = lineNumber;
277         }
278
279         /**
280          * Set the start position of the problem (inclusive), or -1 if unknown.
281          * 
282          * Used for shifting problem positions.
283          * 
284          * @param sourceStart
285          *            the new value of the source start position of the receiver
286          */
287         public void setSourceStart(int sourceStart) {
288                 startPosition = sourceStart;
289         }
290
291         public String toString() {
292                 String s = "Pb(" + (id & IgnoreCategoriesMask) + ") "; //$NON-NLS-1$ //$NON-NLS-2$
293                 if (message != null) {
294                         s += message;
295                 } else {
296                         if (arguments != null)
297                                 for (int i = 0; i < arguments.length; i++)
298                                         s += " " + arguments[i]; //$NON-NLS-1$
299                 }
300                 return s;
301         }
302 }