diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java')
-rw-r--r-- | core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java | 195 |
1 files changed, 183 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java index 659cd168170..9cf1b487f4f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java @@ -4,8 +4,6 @@ package org.eclipse.cdt.internal.core.model; * (c) Copyright QNX Software Systems Ltd. 2002. * All Rights Reserved. */ -import java.util.ArrayList; -import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICElement; @@ -27,7 +25,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus * The elements related to the failure, or <code>null</code> * if no elements are involved. */ - protected List fElements = new ArrayList(); + protected ICElement[] fElements; + protected final static ICElement[] EmptyElement = new ICElement[] {}; /** * The path related to the failure, or <code>null</code> * if no path is involved. @@ -62,7 +61,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(int code) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - fElements.clear(); + fElements = CElement.NO_ELEMENTS; } /** @@ -71,8 +70,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(int code, ICElement[] elements) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - for(int i=0; i<elements.length; ++i) - fElements.add(elements[i]); + fElements = elements; fPath= null; } @@ -85,7 +83,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus public CModelStatus(int severity, int code, String string) { super(severity, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - fElements.clear(); + fElements = CElement.NO_ELEMENTS; fPath= null; fString = string; } @@ -95,7 +93,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(int code, Throwable throwable) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", throwable); //$NON-NLS-1$ - fElements.clear(); + fElements = CElement.NO_ELEMENTS; } /** @@ -103,7 +101,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(int code, IPath path) { super(ERROR, CCorePlugin.PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$ - fElements.clear(); + fElements = CElement.NO_ELEMENTS; fPath= path; } @@ -134,7 +132,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public CModelStatus(CoreException coreException) { super(ERROR, CCorePlugin.PLUGIN_ID, CORE_EXCEPTION, "CModelStatus", coreException); //$NON-NLS-1$ - //fElements= CElementInfo.fgEmptyChildren; + fElements= CElement.NO_ELEMENTS; } protected int getBits() { @@ -154,15 +152,188 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus * @see ICModelStatus */ public ICElement[] getElements() { - return (ICElement[])fElements.toArray(new ICElement[fElements.size()]); + return fElements; } /** * Returns the message that is relevant to the code of this status. */ public String getMessage() { - return CCorePlugin.getResourceString("CoreModel.CModelStatus.Error_in_CPlugin"); //$NON-NLS-1$ + Throwable exception = getException(); + if (exception == null) { + switch (getCode()) { + case CORE_EXCEPTION : + return CoreModelMessages.getFormattedString("status.coreException"); //$NON-NLS-1$ + + //case BUILDER_INITIALIZATION_ERROR: + // return Util.bind("build.initializationError"); //$NON-NLS-1$ + + //case BUILDER_SERIALIZATION_ERROR: + // return Util.bind("build.serializationError"); //$NON-NLS-1$ + + case DEVICE_PATH: + return CoreModelMessages.getFormattedString("status.cannotUseDeviceOnPath", getPath().toString()); //$NON-NLS-1$ + + //case DOM_EXCEPTION: + // return Util.bind("status.JDOMError"); //$NON-NLS-1$ + + case ELEMENT_DOES_NOT_EXIST: + return CoreModelMessages.getFormattedString("element.doesNotExist",((ICElement)fElements[0]).toString()); //$NON-NLS-1$ + + case EVALUATION_ERROR: + return CoreModelMessages.getFormattedString("status.evaluationError", fString); //$NON-NLS-1$ + + case INDEX_OUT_OF_BOUNDS: + return CoreModelMessages.getFormattedString("status.indexOutOfBounds"); //$NON-NLS-1$ + + case INVALID_CONTENTS: + return CoreModelMessages.getFormattedString("status.invalidContents"); //$NON-NLS-1$ + + case INVALID_DESTINATION: + return CoreModelMessages.getFormattedString("status.invalidDestination", ((ICElement)fElements[0]).toString()); //$NON-NLS-1$ + + case INVALID_ELEMENT_TYPES: + StringBuffer buff= new StringBuffer(CoreModelMessages.getFormattedString("operation.notSupported")); //$NON-NLS-1$ + for (int i= 0; i < fElements.length; i++) { + if (i > 0) { + buff.append(", "); //$NON-NLS-1$ + } + buff.append(((ICElement)fElements[i]).toString()); + } + return buff.toString(); + + case INVALID_NAME: + return CoreModelMessages.getFormattedString("status.invalidName", fString); //$NON-NLS-1$ + + //case INVALID_PACKAGE: + // return Util.bind("status.invalidPackage", string); //$NON-NLS-1$ + + case INVALID_PATH: + if (fString != null) { + return fString; + } else { + return CoreModelMessages.getFormattedString("status.invalidPath", getPath() == null ? "null" : getPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$ + } + + case INVALID_PROJECT: + return CoreModelMessages.getFormattedString("status.invalidProject", fString); //$NON-NLS-1$ + + case INVALID_RESOURCE: + return CoreModelMessages.getFormattedString("status.invalidResource", fString); //$NON-NLS-1$ + + case INVALID_RESOURCE_TYPE: + return CoreModelMessages.getFormattedString("status.invalidResourceType", fString); //$NON-NLS-1$ + + case INVALID_SIBLING: + if (fString != null) { + return CoreModelMessages.getFormattedString("status.invalidSibling", fString); //$NON-NLS-1$ + } else { + return CoreModelMessages.getFormattedString("status.invalidSibling", ((ICElement)fElements[0]).toString()); //$NON-NLS-1$ + } + + case IO_EXCEPTION: + return CoreModelMessages.getFormattedString("status.IOException"); //$NON-NLS-1$ + + case NAME_COLLISION: + StringBuffer sb = new StringBuffer(); + if (fElements != null && fElements.length > 0) { + ICElement element = fElements[0]; + sb.append(element.getElementName()).append(' '); + } + if (fString != null) { + return fString; + } else { + return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$ + } + + case NO_ELEMENTS_TO_PROCESS: + return CoreModelMessages.getFormattedString("operation.needElements"); //$NON-NLS-1$ + + case NULL_NAME: + return CoreModelMessages.getFormattedString("operation.needName"); //$NON-NLS-1$ + + case NULL_PATH: + return CoreModelMessages.getFormattedString("operation.needPath"); //$NON-NLS-1$ + + case NULL_STRING: + return CoreModelMessages.getFormattedString("operation.needString"); //$NON-NLS-1$ + + case PATH_OUTSIDE_PROJECT: + return CoreModelMessages.getFormattedString("operation.pathOutsideProject", new String[]{fString, ((ICElement)fElements[0]).toString()}); //$NON-NLS-1$ + + case READ_ONLY: + ICElement element = fElements[0]; + String name = element.getElementName(); + return CoreModelMessages.getFormattedString("status.readOnly", name); //$NON-NLS-1$ + + case RELATIVE_PATH: + return CoreModelMessages.getFormattedString("operation.needAbsolutePath", getPath().toString()); //$NON-NLS-1$ + + case TARGET_EXCEPTION: + return CoreModelMessages.getFormattedString("status.targetException"); //$NON-NLS-1$ + + case UPDATE_CONFLICT: + return CoreModelMessages.getFormattedString("status.updateConflict"); //$NON-NLS-1$ + + case NO_LOCAL_CONTENTS : + return CoreModelMessages.getFormattedString("status.noLocalContents", getPath().toString()); //$NON-NLS-1$ + + //case CP_CONTAINER_PATH_UNBOUND: + // element = (ICElement)fElements[0]; + //PathEContainerInitializer initializer = CoreModel.getPathEntryContainerInitializer(this.path.segment(0)); + //String description = null; + //if (initializer != null) description = initializer.getDescription(this.path, javaProject); + //if (description == null) description = path.makeRelative().toString(); + // return CoreModelMessages.getFormattedString("pathentry.unboundContainerPath", element.getElementName()); //$NON-NLS-1$ + + //case INVALID_CP_CONTAINER_ENTRY: + // element = (ICElement)fElements[0]; + //IPathEntryContainer container = null; + //description = null; + //try { + // container = CoreModel.getPathEntryContainer(path, javaProject); + //} catch(CModelException e){ + // project doesn't exist: ignore + //} + //if (container == null) { + // initializer = CoreModel.getPathEntryContainerInitializer(path.segment(0)); + // if (initializer != null) description = initializer.getDescription(path, javaProject); + //} else { + // description = container.getDescription(); + //} + //if (description == null) description = path.makeRelative().toString(); + // return CoreModelMessages.getFormattedString("pathentry.invalidContainer", element.getElementName()); //$NON-NLS-1$ + + case CP_VARIABLE_PATH_UNBOUND: + element = (ICElement)fElements[0]; + return CoreModelMessages.getFormattedString("pathentry.unboundVariablePath", + new String[] {getPath().makeRelative().toString(), element.getElementName()}); //$NON-NLS-1$ + + //case CLASSPATH_CYCLE: + // element = (ICElement)fElements[0]; + // return CoreModelMessages.getFormattedString("pathentry.cycle", element.getElementName()); //$NON-NLS-1$ + + //case DISABLED_CP_EXCLUSION_PATTERNS: + + //case DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS: + + //case INCOMPATIBLE_JDK_LEVEL: + } + if (fString != null) { + return fString; + } else { + return ""; // //$NON-NLS-1$ + } + } else { + String message = exception.getMessage(); + if (message != null) { + return message; + } else { + return exception.toString(); + } + } } + /** * @see IOperationStatus */ |