From c17d871ba5cab13fddc917fa37120b74705ec55c Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 28 May 2004 20:25:11 +0000 Subject: [PATCH] CModelstatus class was incomplete and never returned anything usefull as an error. --- .../cdt/internal/core/model/CElement.java | 1 + .../cdt/internal/core/model/CModelStatus.java | 195 ++++++++++++++++-- .../core/model/CoreModelMessages.java | 71 +++++++ .../core/model/CoreModelMessages.properties | 70 +++++++ 4 files changed, 325 insertions(+), 12 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java index 35ed80075d9..9fcef63b005 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java @@ -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; 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 null * 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 null * 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 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 */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java new file mode 100644 index 00000000000..26e9d3d8884 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java @@ -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); + } + +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties new file mode 100644 index 00000000000..35239de6b92 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties @@ -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. +