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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
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;
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;
27 * @see IJavaModelStatus
30 public class JavaModelStatus extends Status implements IJavaModelStatus, IJavaModelStatusConstants, IResourceStatus {
33 * The elements related to the failure, or <code>null</code>
34 * if no elements are involved.
36 protected IJavaElement[] fElements = new IJavaElement[0];
38 * The path related to the failure, or <code>null</code>
39 * if no path is involved.
41 protected IPath fPath;
43 * The <code>String</code> related to the failure, or <code>null</code>
44 * if no <code>String</code> is involved.
46 protected String fString;
50 protected final static IStatus[] fgEmptyChildren = new IStatus[] {};
51 protected IStatus[] fChildren= fgEmptyChildren;
56 public static final IJavaModelStatus VERIFIED_OK = new JavaModelStatus(OK);
59 * Constructs an Java model status with no corresponding elements.
61 public JavaModelStatus() {
62 // no code for an multi-status
63 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, 0, "JavaModelStatus", null); //$NON-NLS-1$
66 * Constructs an Java model status with no corresponding elements.
68 public JavaModelStatus(int code) {
69 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
70 fElements= JavaElementInfo.fgEmptyChildren;
73 // * Constructs an Java model status with the given corresponding
76 // public JavaModelStatus(int code, IJavaElement[] elements) {
77 // super(ERROR, JavaCore.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
78 // fElements= elements;
82 * Constructs an Java model status with no corresponding elements.
84 // public JavaModelStatus(int code, String string) {
85 // super(ERROR, JavaCore.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
86 // fElements= JavaElementInfo.fgEmptyChildren;
91 // * Constructs an Java model status with no corresponding elements.
93 public JavaModelStatus(int code, Throwable throwable) {
94 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, code, "JavaModelStatus", throwable); //$NON-NLS-1$
95 fElements= JavaElementInfo.fgEmptyChildren;
98 // * Constructs an Java model status with no corresponding elements.
100 // public JavaModelStatus(int code, IPath path) {
101 // super(ERROR, JavaCore.PLUGIN_ID, code, "JavaModelStatus", null); //$NON-NLS-1$
102 // fElements= JavaElementInfo.fgEmptyChildren;
106 * Constructs an Java model status with the given corresponding
109 // public JavaModelStatus(int code, IJavaElement element) {
110 // this(code, new IJavaElement[]{element});
113 // * Constructs an Java model status with the given corresponding
114 // * element and string
116 // public JavaModelStatus(int code, IJavaElement element, String string) {
117 // this(code, new IJavaElement[]{element});
121 * Constructs an Java model status with no corresponding elements.
123 public JavaModelStatus(CoreException coreException) {
124 super(ERROR, PHPeclipsePlugin.PLUGIN_ID, CORE_EXCEPTION, "JavaModelStatus", coreException); //$NON-NLS-1$
125 fElements= JavaElementInfo.fgEmptyChildren;
127 protected int getBits() {
128 int severity = 1 << (getCode() % 100 / 33);
129 int category = 1 << ((getCode() / 100) + 3);
130 return severity | category;
135 public IStatus[] getChildren() {
139 * @see IJavaModelStatus
141 public IJavaElement[] getElements() {
145 * Returns the message that is relevant to the code of this status.
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$
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++) {
174 // buff.append(", "); //$NON-NLS-1$
176 // buff.append(fElements[0].getElementName());
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$
203 // return Util.bind("status.nameCollision"); //$NON-NLS-1$
204 // case NO_ELEMENTS_TO_PROCESS:
205 // return Util.bind("operation.needElements"); //$NON-NLS-1$
207 // return Util.bind("operation.needName"); //$NON-NLS-1$
209 // return Util.bind("operation.needPath"); //$NON-NLS-1$
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$
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$
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$
230 // return getString();
232 // return getException().getMessage();
236 * @see IJavaModelStatus#getPath()
238 public IPath getPath() {
242 * @see IStatus#getSeverity()
244 public int getSeverity() {
245 if (fChildren == fgEmptyChildren) return super.getSeverity();
247 for (int i = 0, max = fChildren.length; i < max; i++) {
248 int childrenSeverity = fChildren[i].getSeverity();
249 if (childrenSeverity > severity) {
250 severity = childrenSeverity;
256 * @see IJavaModelStatus#getString()
258 public String getString() {
262 * @see IJavaModelStatus#isDoesNotExist()
264 public boolean isDoesNotExist() {
265 return getCode() == ELEMENT_DOES_NOT_EXIST;
268 * @see IStatus#isMultiStatus()
270 public boolean isMultiStatus() {
271 return fChildren != fgEmptyChildren;
274 * @see IStatus#isOK()
276 public boolean isOK() {
277 return getCode() == OK;
280 * @see IStatus#matches(int)
282 public boolean matches(int mask) {
283 if (! isMultiStatus()) {
284 return matches(this, mask);
286 for (int i = 0, max = fChildren.length; i < max; i++) {
287 if (matches((JavaModelStatus) fChildren[i], mask))
294 * Helper for matches(int).
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);
303 * Creates and returns a new <code>IJavaModelStatus</code> that is a
304 * a multi-status status.
306 * @see IStatus#isMultiStatus()
308 public static IJavaModelStatus newMultiStatus(IJavaModelStatus[] children) {
309 JavaModelStatus jms = new JavaModelStatus();
310 jms.fChildren = children;
314 * Returns a printable representation of this exception for debugging
317 public String toString() {
318 if (this == VERIFIED_OK){
319 return "JavaModelStatus[OK]"; //$NON-NLS-1$
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();