mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
CModelstatus class was incomplete and never returned
anything usefull as an error.
This commit is contained in:
parent
eebe6d4aeb
commit
c17d871ba5
4 changed files with 325 additions and 12 deletions
|
@ -23,6 +23,7 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
|
||||
public abstract class CElement extends PlatformObject implements ICElement {
|
||||
|
||||
protected static final CElement[] NO_ELEMENTS = new CElement[0];
|
||||
protected int fType;
|
||||
|
||||
protected ICElement fParent;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2003, 2004 QNX Software Systems Ltd. and others. All
|
||||
* rights reserved. This program and the accompanying materials are made
|
||||
* available under the terms of the Common Public License v1.0 which
|
||||
* accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors: QNX Software Systems - Initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
/**
|
||||
* CoreModelMessages
|
||||
*
|
||||
*/
|
||||
public class CoreModelMessages {
|
||||
private static final String RESOURCE_BUNDLE= "org.eclipse.cdt.internal.core.model.CoreModelMessages"; //$NON-NLS-1$
|
||||
private static ResourceBundle fgResourceBundle;
|
||||
static {
|
||||
try {
|
||||
fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
||||
} catch (MissingResourceException x) {
|
||||
fgResourceBundle = null;
|
||||
}
|
||||
}
|
||||
|
||||
private CoreModelMessages() {
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return fgResourceBundle.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
} catch (NullPointerException e) {
|
||||
return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string from the resource bundle and formats it with the argument
|
||||
*
|
||||
* @param key the string used to get the bundle value, must not be null
|
||||
*/
|
||||
public static String getFormattedString(String key) {
|
||||
return getString(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a string from the resource bundle and formats it with the argument
|
||||
*
|
||||
* @param key the string used to get the bundle value, must not be null
|
||||
*/
|
||||
public static String getFormattedString(String key, Object arg) {
|
||||
return MessageFormat.format(getString(key), new Object[] { arg });
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string from the resource bundle and formats it with arguments
|
||||
*/
|
||||
public static String getFormattedString(String key, Object[] args) {
|
||||
return MessageFormat.format(getString(key), args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2000, 2004 IBM Corporation and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Common Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/cpl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# QNX Software Systems - Initial API and implementation
|
||||
###############################################################################
|
||||
|
||||
### CoreModel messages.
|
||||
|
||||
### Core model operations
|
||||
operation.needElements = Operation requires one or more elements.
|
||||
operation.needName = Operation requires a name.
|
||||
operation.needPath = Operation requires a path.
|
||||
operation.needAbsolutePath = Operation requires an absolute path. Relative path specified was: ''{0}''
|
||||
operation.needString = Operation requires a String.
|
||||
operation.notSupported = Operation not supported for specified element type(s):
|
||||
operation.cancelled = Operation cancelled.
|
||||
operation.nullContainer = Container cannot be null.
|
||||
operation.nullName = Name cannot be null.
|
||||
operation.copyElementProgress = Copying elements...
|
||||
operation.moveElementProgress = Moving elements...
|
||||
operation.renameElementProgress = Renaming elements...
|
||||
operation.copyResourceProgress = Copying resources...
|
||||
operation.moveResourceProgress = Moving resources...
|
||||
operation.renameResourceProgress = Renaming resources...
|
||||
operation.createUnitProgress = Creating a compilation unit...
|
||||
operation.createFieldProgress = Creating a field...
|
||||
operation.createImportsProgress = Creating imports...
|
||||
operation.createInitializerProgress = Creating an initializer...
|
||||
operation.createMethodProgress = Creating a method...
|
||||
operation.createPackageProgress = Creating a package declaration...
|
||||
operation.createPackageFragmentProgress = Creating package fragment(s)...
|
||||
operation.createTypeProgress = Creating a type...
|
||||
operation.deleteElementProgress = Deleting elements...
|
||||
operation.deleteResourceProgress = Deleting resources...
|
||||
operation.cannotRenameDefaultPackage = Default package cannot be renamed.
|
||||
operation.pathOutsideProject = Path ''{0}'' must denote location inside project {1}
|
||||
operation.sortelements = Sorting elements...
|
||||
|
||||
### working copy
|
||||
workingCopy.commit = Committing working copy...
|
||||
|
||||
### status
|
||||
status.cannotUseDeviceOnPath = Operation requires a path with no device. Path specified was: {0}
|
||||
status.coreException = Core exception.
|
||||
status.defaultPackageReadOnly = Default package is read-only.
|
||||
status.evaluationError = Evaluation error: {0}.
|
||||
status.JDOMError = JDOM error.
|
||||
status.IOException = I/O exception.
|
||||
status.indexOutOfBounds = Index out of bounds.
|
||||
status.invalidContents = Invalid contents specified.
|
||||
status.invalidDestination = Invalid destination: ''{0}''.
|
||||
status.invalidName = Invalid name specified: {0}.
|
||||
status.invalidPackage = Invalid package: {0}.
|
||||
status.invalidPath = Invalid path: ''{0}''.
|
||||
status.invalidProject = Invalid project: {0}.
|
||||
status.invalidResource = Invalid resource: {0}.
|
||||
status.invalidResourceType = Invalid resource type for {0}.
|
||||
status.invalidSibling = Invalid sibling: {0}.
|
||||
status.nameCollision = {0} already exists in target.
|
||||
status.noLocalContents = Cannot find local contents for resource: {0}
|
||||
status.OK = OK
|
||||
status.readOnly = {0} is read-only.
|
||||
status.targetException = Target exception.
|
||||
status.updateConflict = Update conflict.
|
||||
|
Loading…
Add table
Reference in a new issue