deleted: export="true"
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / JavaModelStatus.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.IJavaModelStatus;
15 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
16 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17
18 import org.eclipse.core.resources.IResourceStatus;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 //import net.sourceforge.phpdt.core.IPackageFragment;
24 //import net.sourceforge.phpdt.core.JavaCore;
25
26 /**
27  * @see IJavaModelStatus
28  */
29
30 public class JavaModelStatus extends Status implements IJavaModelStatus, IJavaModelStatusConstants, IResourceStatus {
31
32         /**
33          * The elements related to the failure, or <code>null</code>
34          * if no elements are involved.
35          */
36         protected IJavaElement[] fElements = new IJavaElement[0];
37         /**
38          * The path related to the failure, or <code>null</code>
39          * if no path is involved.
40          */
41         protected IPath fPath;
42         /**
43          * The <code>String</code> related to the failure, or <code>null</code>
44          * if no <code>String</code> is involved.
45          */
46         protected String fString;
47         /**
48          * Empty children
49          */
50         protected final static IStatus[] fgEmptyChildren = new IStatus[] {};
51         protected IStatus[] fChildren= fgEmptyChildren;
52
53         /**
54          * Singleton OK object
55          */
56         public static final IJavaModelStatus VERIFIED_OK = new JavaModelStatus(OK);
57
58         /**
59          * Constructs an Java model status with no corresponding elements.
60          */
61         public JavaModelStatus() {
62                 // no code for an multi-status
63                 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, 0, "JavaModelStatus", null); //$NON-NLS-1$
64         }
65         /**
66          * Constructs an Java model status with no corresponding elements.
67          */
68         public JavaModelStatus(int code) {
69                 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
70                 fElements= JavaElementInfo.fgEmptyChildren;
71         }
72 //      /**
73 //       * Constructs an Java model status with the given corresponding
74 //       * elements.
75 //       */
76 //      public JavaModelStatus(int code, IJavaElement[] elements) {
77 //              super(ERROR, JavaCore.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
78 //              fElements= elements;
79 //              fPath= null;
80 //      }
81         /**
82          * Constructs an Java model status with no corresponding elements.
83          */
84 //      public JavaModelStatus(int code, String string) {
85 //              super(ERROR, JavaCore.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
86 //              fElements= JavaElementInfo.fgEmptyChildren;
87 //              fPath= null;
88 //              fString = string;
89 //      }
90 //      /**
91 //       * Constructs an Java model status with no corresponding elements.
92 //       */
93         public JavaModelStatus(int code, Throwable throwable) {
94                 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, code, "JavaModelStatus", throwable); //$NON-NLS-1$
95                 fElements= JavaElementInfo.fgEmptyChildren;
96         }
97 //      /**
98 //       * Constructs an Java model status with no corresponding elements.
99 //       */
100 //      public JavaModelStatus(int code, IPath path) {
101 //              super(ERROR, JavaCore.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
102 //              fElements= JavaElementInfo.fgEmptyChildren;
103 //              fPath= path;
104 //      }
105         /**
106          * Constructs an Java model status with the given corresponding
107          * element.
108          */
109 //      public JavaModelStatus(int code, IJavaElement element) {
110 //              this(code, new IJavaElement[]{element});
111 //      }
112 //      /**
113 //       * Constructs an Java model status with the given corresponding
114 //       * element and string
115 //       */
116 //      public JavaModelStatus(int code, IJavaElement element, String string) {
117 //              this(code, new IJavaElement[]{element});
118 //              fString= string;
119 //      }
120         /**
121          * Constructs an Java model status with no corresponding elements.
122          */
123         public JavaModelStatus(CoreException coreException) {
124                 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, CORE_EXCEPTION, "JavaModelStatus", coreException); //$NON-NLS-1$
125                 fElements= JavaElementInfo.fgEmptyChildren;
126         }
127         protected int getBits() {
128                 int severity = 1 << (getCode() % 100 / 33);
129                 int category = 1 << ((getCode() / 100) + 3);
130                 return severity | category;
131         }
132         /**
133          * @see IStatus
134          */
135         public IStatus[] getChildren() {
136                 return fChildren;
137         }
138         /**
139          * @see IJavaModelStatus
140          */
141         public IJavaElement[] getElements() {
142                 return fElements;
143         }
144         /**
145          * Returns the message that is relevant to the code of this status.
146          */
147 //      public String getMessage() {
148 //              if (getException() == null) {
149 //                      switch (getCode()) {
150 //                              case CORE_EXCEPTION :
151 //                                      return Util.bind("status.coreException"); //$NON-NLS-1$
152 //                              case BUILDER_INITIALIZATION_ERROR:
153 //                                      return Util.bind("build.initializationError"); //$NON-NLS-1$
154 //                              case BUILDER_SERIALIZATION_ERROR:
155 //                                      return Util.bind("build.serializationError"); //$NON-NLS-1$
156 //                              case DEVICE_PATH:
157 //                                      return Util.bind("status.cannotUseDeviceOnPath", getPath().toString()); //$NON-NLS-1$
158 //                              case DOM_EXCEPTION:
159 //                                      return Util.bind("status.JDOMError"); //$NON-NLS-1$
160 //                              case ELEMENT_DOES_NOT_EXIST:
161 //                                      return Util.bind("element.doesNotExist",fElements[0].getElementName()); //$NON-NLS-1$
162 //                              case EVALUATION_ERROR:
163 //                                      return Util.bind("status.evaluationError", getString()); //$NON-NLS-1$
164 //                              case INDEX_OUT_OF_BOUNDS:
165 //                                      return Util.bind("status.indexOutOfBounds"); //$NON-NLS-1$
166 //                              case INVALID_CONTENTS:
167 //                                      return Util.bind("status.invalidContents"); //$NON-NLS-1$
168 //                              case INVALID_DESTINATION:
169 //                                      return Util.bind("status.invalidDestination", fElements[0].getElementName()); //$NON-NLS-1$
170 //                              case INVALID_ELEMENT_TYPES:
171 //                                      StringBuffer buff= new StringBuffer(Util.bind("operation.notSupported")); //$NON-NLS-1$
172 //                                      for (int i= 0; i < fElements.length; i++) {
173 //                                              if (i > 0) {
174 //                                                      buff.append(", "); //$NON-NLS-1$
175 //                                              }
176 //                                              buff.append(fElements[0].getElementName());
177 //                                      }
178 //                                      return buff.toString();
179 //                              case INVALID_NAME:
180 //                                      return Util.bind("status.invalidName", getString()); //$NON-NLS-1$
181 //                              case INVALID_PACKAGE:
182 //                                      return Util.bind("status.invalidPackage", getString()); //$NON-NLS-1$
183 //                              case INVALID_PATH:
184 //                                      return Util.bind("status.invalidPath", getPath() == null ? "null" : getPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
185 //                              case INVALID_PROJECT:
186 //                                      return Util.bind("status.invalidProject", getString()); //$NON-NLS-1$
187 //                              case INVALID_RESOURCE:
188 //                                      return Util.bind("status.invalidResource", getString()); //$NON-NLS-1$
189 //                              case INVALID_RESOURCE_TYPE:
190 //                                      return Util.bind("status.invalidResourceType", getString()); //$NON-NLS-1$
191 //                              case INVALID_SIBLING:
192 //                                      return Util.bind("status.invalidSibling", fElements[0].getElementName()); //$NON-NLS-1$
193 //                              case IO_EXCEPTION:
194 //                                      return Util.bind("status.IOException"); //$NON-NLS-1$
195 //                              case NAME_COLLISION:
196 //                                      if (fElements != null && fElements.length > 0) {
197 //                                              IJavaElement element = fElements[0];
198 //                                              String name = element.getElementName();
199 //                                              if (element instanceof IPackageFragment && name.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
200 //                                                      return Util.bind("operation.cannotRenameDefaultPackage"); //$NON-NLS-1$
201 //                                              }
202 //                                      }
203 //                                      return Util.bind("status.nameCollision"); //$NON-NLS-1$
204 //                              case NO_ELEMENTS_TO_PROCESS:
205 //                                      return Util.bind("operation.needElements"); //$NON-NLS-1$
206 //                              case NULL_NAME:
207 //                                      return Util.bind("operation.needName"); //$NON-NLS-1$
208 //                              case NULL_PATH:
209 //                                      return Util.bind("operation.needPath"); //$NON-NLS-1$
210 //                              case NULL_STRING:
211 //                                      return Util.bind("operation.needString"); //$NON-NLS-1$
212 //                              case PATH_OUTSIDE_PROJECT:
213 //                                      return Util.bind("operation.pathOutsideProject", getString(), fElements[0].getElementName()); //$NON-NLS-1$
214 //                              case READ_ONLY:
215 //                                      IJavaElement element = fElements[0];
216 //                                      String name = element.getElementName();
217 //                                      if (element instanceof IPackageFragment && name.equals(IPackageFragment.DEFAULT_PACKAGE_NAME)) {
218 //                                              return Util.bind("status.defaultPackageReadOnly"); //$NON-NLS-1$
219 //                                      }
220 //                                      return  Util.bind("status.readOnly", name); //$NON-NLS-1$
221 //                              case RELATIVE_PATH:
222 //                                      return Util.bind("operation.needAbsolutePath", getPath().toString()); //$NON-NLS-1$
223 //                              case TARGET_EXCEPTION:
224 //                                      return Util.bind("status.targetException"); //$NON-NLS-1$
225 //                              case UPDATE_CONFLICT:
226 //                                      return Util.bind("status.updateConflict"); //$NON-NLS-1$
227 //                              case NO_LOCAL_CONTENTS :
228 //                                      return Util.bind("status.noLocalContents", getPath().toString()); //$NON-NLS-1$
229 //                      }
230 //                      return getString();
231 //              } else {
232 //                      return getException().getMessage();
233 //              }
234 //      }
235         /**
236          * @see IJavaModelStatus#getPath()
237          */
238         public IPath getPath() {
239                 return fPath;
240         }
241         /**
242          * @see IStatus#getSeverity()
243          */
244         public int getSeverity() {
245                 if (fChildren == fgEmptyChildren) return super.getSeverity();
246                 int severity = -1;
247                 for (int i = 0, max = fChildren.length; i < max; i++) {
248                         int childrenSeverity = fChildren[i].getSeverity();
249                         if (childrenSeverity > severity) {
250                                 severity = childrenSeverity;
251                         }
252                 }
253                 return severity;
254         }
255         /**
256          * @see IJavaModelStatus#getString()
257          */
258         public String getString() {
259                 return fString;
260         }
261         /**
262          * @see IJavaModelStatus#isDoesNotExist()
263          */
264         public boolean isDoesNotExist() {
265                 return getCode() == ELEMENT_DOES_NOT_EXIST;
266         }
267         /**
268          * @see IStatus#isMultiStatus()
269          */
270         public boolean isMultiStatus() {
271                 return fChildren != fgEmptyChildren;
272         }
273         /**
274          * @see IStatus#isOK()
275          */
276         public boolean isOK() {
277                 return getCode() == OK;
278         }
279         /**
280          * @see IStatus#matches(int)
281          */
282         public boolean matches(int mask) {
283                 if (! isMultiStatus()) {
284                         return matches(this, mask);
285                 } else {
286                         for (int i = 0, max = fChildren.length; i < max; i++) {
287                                 if (matches((JavaModelStatus) fChildren[i], mask))
288                                         return true;
289                         }
290                         return false;
291                 }
292         }
293         /**
294          * Helper for matches(int).
295          */
296         protected boolean matches(JavaModelStatus status, int mask) {
297                 int severityMask = mask & 0x7;
298                 int categoryMask = mask & ~0x7;
299                 int bits = status.getBits();
300                 return ((severityMask == 0) || (bits & severityMask) != 0) && ((categoryMask == 0) || (bits & categoryMask) != 0);
301         }
302         /**
303          * Creates and returns a new <code>IJavaModelStatus</code> that is a
304          * a multi-status status.
305          *
306          * @see IStatus#isMultiStatus()
307          */
308         public static IJavaModelStatus newMultiStatus(IJavaModelStatus[] children) {
309                 JavaModelStatus jms = new JavaModelStatus();
310                 jms.fChildren = children;
311                 return jms;
312         }
313         /**
314          * Returns a printable representation of this exception for debugging
315          * purposes.
316          */
317         public String toString() {
318                 if (this == VERIFIED_OK){
319                         return "JavaModelStatus[OK]"; //$NON-NLS-1$
320                 }
321                 StringBuffer buffer = new StringBuffer();
322                 buffer.append("Java Model Status ["); //$NON-NLS-1$
323                 buffer.append(getMessage());
324                 buffer.append("]"); //$NON-NLS-1$
325                 return buffer.toString();
326         }
327 }