From e0f8a9bbeb1fac476fb81db9dc4e8682ffe71c99 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 24 Aug 2004 18:29:51 +0000 Subject: [PATCH] 2004-08-24 Alain Magloire Fix for PR 72078 * model/org/eclipse/cdt/internal/core/model/CModelStatus.java * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java --- core/org.eclipse.cdt.core/ChangeLog | 6 + .../cdt/internal/core/model/CModelStatus.java | 54 ++++++--- .../internal/core/model/PathEntryManager.java | 114 ++++++++++++++++-- 3 files changed, 142 insertions(+), 32 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index a1d7522e076..d9822da028e 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,9 @@ +2004-08-24 Alain Magloire + + Fix for PR 72078 + * model/org/eclipse/cdt/internal/core/model/CModelStatus.java + * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java + 2004-08-23 Chris Wiebe fix for 68210 - add missing cpp header names 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 9b225342016..f63be8a170c 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 @@ -169,6 +169,16 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus */ public String getMessage() { Throwable exception = getException(); + if (isMultiStatus()) { + StringBuffer sb = new StringBuffer(); + IStatus[] children = getChildren(); + if (children != null && children.length > 0) { + for (int i = 0; i < children.length; ++i) { + sb.append(children[i].getMessage()).append(','); + } + } + return sb.toString(); + } if (exception == null) { switch (getCode()) { case CORE_EXCEPTION : @@ -212,9 +222,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus 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$ } + return CoreModelMessages.getFormattedString("status.invalidPath", getPath() == null ? "null" : getPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$ case INVALID_PROJECT: return CoreModelMessages.getFormattedString("status.invalidProject", getString()); //$NON-NLS-1$ @@ -228,9 +237,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus case INVALID_SIBLING: if (fString != null) { return CoreModelMessages.getFormattedString("status.invalidSibling", getString()); //$NON-NLS-1$ - } else { - return CoreModelMessages.getFormattedString("status.invalidSibling", getFirstElementName()); //$NON-NLS-1$ } + return CoreModelMessages.getFormattedString("status.invalidSibling", getFirstElementName()); //$NON-NLS-1$ case IO_EXCEPTION: return CoreModelMessages.getFormattedString("status.IOException"); //$NON-NLS-1$ @@ -243,9 +251,8 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus } if (fString != null) { return fString; - } else { - return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$ } + 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$ @@ -289,14 +296,12 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus } return getString(); - } else { - String message = exception.getMessage(); - if (message != null) { - return message; - } else { - return exception.toString(); - } } + String message = exception.getMessage(); + if (message != null) { + return message; + } + return exception.toString(); } /** @@ -368,13 +373,12 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus public boolean matches(int mask) { if (! isMultiStatus()) { return matches(this, mask); - } else { - for (int i = 0, max = fChildren.length; i < max; i++) { - if (matches((CModelStatus) fChildren[i], mask)) - return true; - } - return false; } + for (int i = 0, max = fChildren.length; i < max; i++) { + if (matches((CModelStatus) fChildren[i], mask)) + return true; + } + return false; } /** @@ -399,6 +403,18 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus return jms; } + /** + * Creates and returns a new ICModelStatus that is a + * a multi-status status. + * + * @see IStatus#.isMultiStatus() + */ + public static ICModelStatus newMultiStatus(int code, ICModelStatus[] children) { + CModelStatus jms = new CModelStatus(code); + jms.fChildren = children; + return jms; + } + /** * Returns a printable representation of this exception for debugging * purposes. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index c638d629ed5..d1364bc08cf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -12,8 +12,10 @@ package org.eclipse.cdt.internal.core.model; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; +import java.util.List; import java.util.Map; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.ICDescriptor; @@ -176,7 +178,25 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange } } listEntries.trimToSize(); + resolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); + + // Check for duplication in the sources + List dups = checkForSourceDuplication(resolvedEntries); + if (dups.size() > 0) { + List newList = new ArrayList(Arrays.asList(resolvedEntries)); + newList.removeAll(dups); + resolvedEntries = (IPathEntry[]) newList.toArray(new IPathEntry[newList.size()]); + } + + // Check for duplication in the outputs + dups = checkForOutputDuplication(resolvedEntries); + if (dups.size() > 0) { + List newList = new ArrayList(Arrays.asList(resolvedEntries)); + newList.removeAll(dups); + resolvedEntries = (IPathEntry[]) newList.toArray(new IPathEntry[newList.size()]); + } + if (generateMarkers) { final ICProject finalCProject = cproject; final IPathEntry[] finalEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); @@ -197,7 +217,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange createPathEntryProblemMarker(project, status); } } - return CModelStatus.OK_STATUS; + return Status.OK_STATUS; } }; markerTask.schedule(); @@ -1161,6 +1181,30 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange } } + // check duplication of sources + List dups = checkForSourceDuplication(entries); + if (dups.size() > 0) { + ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()]; + for (int i = 0; i < dups.size(); ++i) { + StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$ + errMesg.append(':').append(dups.get(i).toString()); + cmodelStatus[i] = new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); + } + return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus); + } + + // check duplication of Outputs + dups = checkForOutputDuplication(entries); + if (dups.size() > 0) { + ICModelStatus[] cmodelStatus = new ICModelStatus[dups.size()]; + for (int i = 0; i < dups.size(); ++i) { + StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$ + errMesg.append(':').append(dups.get(i).toString()); + cmodelStatus[i] = new CModelStatus(ICModelStatusConstants.NAME_COLLISION, errMesg.toString()); + } + return CModelStatus.newMultiStatus(ICModelStatusConstants.INVALID_PATHENTRY, cmodelStatus); + } + // allow nesting source entries in each other as long as the outer entry excludes the inner one for (int i = 0; i < entries.length; i++) { IPathEntry entry = entries[i]; @@ -1187,17 +1231,15 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ errMesg.append(':').append(entry.toString()); return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); + } else if (otherKind == IPathEntry.CDT_SOURCE) { + exclusionPattern += '/'; + StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ + errMesg.append(':').append(entry.toString()); + return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); } else { - if (otherKind == IPathEntry.CDT_SOURCE) { - exclusionPattern += '/'; - StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ - errMesg.append(':').append(entry.toString()); - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); - } else { - StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ - errMesg.append(':').append(entry.toString()); - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); //$NON-NLS-1$ - } + StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ + errMesg.append(':').append(entry.toString()); + return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); //$NON-NLS-1$ } } } @@ -1336,6 +1378,52 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange return false; } + private List checkForSourceDuplication(IPathEntry[] pathEntries) { + List duplicate = new ArrayList(pathEntries.length); + for (int i = 0; i < pathEntries.length; ++i) { + if (pathEntries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { + ISourceEntry sourceEntry = (ISourceEntry)pathEntries[i]; + for (int j = 0; j < pathEntries.length; ++j) { + if (pathEntries[j].getEntryKind() == IPathEntry.CDT_SOURCE) { + ISourceEntry otherSource = (ISourceEntry)pathEntries[j]; + if (!sourceEntry.equals(otherSource)) { + if (!duplicate.contains(sourceEntry)) { + if (sourceEntry.getPath().equals(otherSource.getPath())) { + // duplication of sources + duplicate.add(otherSource); + } + } + } + } + } + } + } + return duplicate; + } + + private List checkForOutputDuplication(IPathEntry[] pathEntries) { + List duplicate = new ArrayList(pathEntries.length); + for (int i = 0; i < pathEntries.length; ++i) { + if (pathEntries[i].getEntryKind() == IPathEntry.CDT_OUTPUT) { + IOutputEntry outputEntry = (IOutputEntry)pathEntries[i]; + for (int j = 0; j < pathEntries.length; ++j) { + if (pathEntries[j].getEntryKind() == IPathEntry.CDT_OUTPUT) { + IOutputEntry otherOutput = (IOutputEntry)pathEntries[j]; + if (!outputEntry.equals(otherOutput)) { + if (!duplicate.contains(outputEntry)) { + if (outputEntry.getPath().equals(otherOutput.getPath())) { + // duplication of outputs + duplicate.add(otherOutput); + } + } + } + } + } + } + } + return duplicate; + } + /** * Record a new marker denoting a classpath problem */ @@ -1351,7 +1439,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange case ICModelStatusConstants.INVALID_PATH: severity = IMarker.SEVERITY_WARNING; break; - + default: severity = IMarker.SEVERITY_ERROR; break; @@ -1367,7 +1455,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange ICModelMarker.PATHENTRY_FILE_FORMAT, }, new Object[] { - status.getString(), + status.getMessage(), new Integer(severity), "pathentry",//$NON-NLS-1$ "false",//$NON-NLS-1$