1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

The PathEntryManager was returning the array instead

of making a copy.  Potentially clients could have
	modified the contents.

	* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
	* model/org/eclipse/cdt/internal/core/model/IMacroEntry.java
	* src/org/eclipse/cdt/core/resources/ScannerProvider.java
This commit is contained in:
Alain Magloire 2004-06-21 22:02:25 +00:00
parent 8102e0ee93
commit 43bd85438e
4 changed files with 88 additions and 28 deletions

View file

@ -1,3 +1,13 @@
2004-06-21 Alain Magloire
The PathEntryManager was returning the array instead
of making a copy. Potentially clients could have
modified the contents.
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
* model/org/eclipse/cdt/internal/core/model/IMacroEntry.java
* src/org/eclipse/cdt/core/resources/ScannerProvider.java
2004-06-21 Hoda Amer 2004-06-21 Hoda Amer
Fix for PR 67696: [I18N] - New Class Wizard does not take project encoding into account when creating files Fix for PR 67696: [I18N] - New Class Wizard does not take project encoding into account when creating files
Now the encoding is taken into consideration when committing a working copy contents to a file. Now the encoding is taken into consideration when committing a working copy contents to a file.

View file

@ -35,6 +35,11 @@ public interface IMacroEntry extends IPathEntry {
*/ */
IPath[] getExclusionPatterns(); IPath[] getExclusionPatterns();
/**
* Returns a char based representation of the exclusions patterns full path.
*/
public char[][] fullExclusionPatternChars();
/** /**
* Return the base path. * Return the base path.
* @return * @return

View file

@ -148,13 +148,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
} }
public IPathEntry[] getResolvedPathEntries(ICProject cproject, boolean generateMarkers) throws CModelException { public IPathEntry[] getResolvedPathEntries(ICProject cproject, boolean generateMarkers) throws CModelException {
IPathEntry[] entries = (IPathEntry[])resolvedMap.get(cproject); ArrayList listEntries = (ArrayList)resolvedMap.get(cproject);
if (entries == null) { IPathEntry[] resolvedEntries;
if (listEntries == null) {
IPath projectPath = cproject.getPath(); IPath projectPath = cproject.getPath();
entries = getRawPathEntries(cproject); IPathEntry[] rawEntries = getRawPathEntries(cproject);
ArrayList list = new ArrayList(); listEntries = new ArrayList();
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < rawEntries.length; i++) {
IPathEntry entry = entries[i]; IPathEntry entry = rawEntries[i];
// Expand the containers. // Expand the containers.
if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) {
IContainerEntry centry = (IContainerEntry) entry; IContainerEntry centry = (IContainerEntry) entry;
@ -164,7 +165,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (containerEntries != null) { if (containerEntries != null) {
for (int j = 0; j < containerEntries.length; j++) { for (int j = 0; j < containerEntries.length; j++) {
IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]); IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]);
list.add(newEntry); listEntries.add(newEntry);
} }
} }
} }
@ -172,15 +173,15 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
IPathEntry clone = cloneEntry(projectPath, entry); IPathEntry clone = cloneEntry(projectPath, entry);
IPathEntry e = getExpandedPathEntry(clone, cproject); IPathEntry e = getExpandedPathEntry(clone, cproject);
if (e != null) { if (e != null) {
list.add(e); listEntries.add(e);
} }
} }
} }
entries = new IPathEntry[list.size()]; listEntries.trimToSize();
list.toArray(entries); resolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
if (generateMarkers) { if (generateMarkers) {
final ICProject finalCProject = cproject; final ICProject finalCProject = cproject;
final IPathEntry[] finalEntries = entries; final IPathEntry[] finalEntries = resolvedEntries;
Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$ Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
@ -203,9 +204,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}; };
markerTask.schedule(); markerTask.schedule();
} }
resolvedMap.put(cproject, entries); resolvedMap.put(cproject, listEntries);
} else {
resolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
} }
return entries; return resolvedEntries;
} }
private IPathEntry getExpandedPathEntry(IPathEntry entry, ICProject cproject) throws CModelException { private IPathEntry getExpandedPathEntry(IPathEntry entry, ICProject cproject) throws CModelException {
@ -387,7 +390,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException {
try { try {
IPathEntry[] oldResolvedEntries = (IPathEntry[]) resolvedMap.get(cproject); IPathEntry[] oldResolvedEntries = null;
ArrayList listEntries = (ArrayList)resolvedMap.get(cproject);
if (listEntries != null) {
oldResolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
}
SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, oldResolvedEntries, newEntries); SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, oldResolvedEntries, newEntries);
CModelManager.getDefault().runOperation(op, monitor); CModelManager.getDefault().runOperation(op, monitor);
} catch (CoreException e) { } catch (CoreException e) {
@ -482,7 +489,12 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
continue; continue;
} }
remaining++; remaining++;
oldResolvedEntries[i] = (IPathEntry[]) resolvedMap.remove(affectedProject); ArrayList listEntries = (ArrayList) resolvedMap.remove(affectedProject);
if (listEntries != null) {
oldResolvedEntries[i] = (IPathEntry[]) listEntries.toArray(NO_PATHENTRIES);
} else {
oldResolvedEntries[i] = null;
}
containerPut(affectedProject, containerPath, newContainer); containerPut(affectedProject, containerPath, newContainer);
} }
// Nothing change. // Nothing change.
@ -1014,7 +1026,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (project.isAccessible()) { if (project.isAccessible()) {
try { try {
// Clear the old cache entries. // Clear the old cache entries.
IPathEntry[] oldResolvedEntries = (IPathEntry[])resolvedMap.remove(cproject); IPathEntry[] oldResolvedEntries = null;
ArrayList listEntries = (ArrayList) resolvedMap.remove(cproject);
if (listEntries != null) {
oldResolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
}
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject); IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries); ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
if (deltas.length > 0) { if (deltas.length > 0) {

View file

@ -18,6 +18,7 @@ import java.util.Map;
import org.eclipse.cdt.core.AbstractCExtension; import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta; import org.eclipse.cdt.core.model.ICElementDelta;
@ -89,6 +90,31 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP
if (cproject != null) { if (cproject != null) {
IPathEntry[] entries = cproject.getResolvedPathEntries(); IPathEntry[] entries = cproject.getResolvedPathEntries();
// First deal with the exclusion any entry that
// excludes the file should not be part of the list.
for (int k = 0; k < entries.length; k++) {
switch (entries[k].getEntryKind()) {
case IPathEntry.CDT_INCLUDE:
IIncludeEntry incEntry = (IIncludeEntry)entries[k];
if (CoreModelUtil.isExcluded(resPath, incEntry.fullExclusionPatternChars())) {
entries[k] = null;
}
break;
case IPathEntry.CDT_MACRO:
IMacroEntry macEntry = (IMacroEntry)entries[k];
if (CoreModelUtil.isExcluded(resPath, macEntry.fullExclusionPatternChars())) {
entries[k] = null;
}
break;
case IPathEntry.CDT_PROJECT:
// do nothing.
break;
default:
// not interrested in the other types.
entries[k] = null;
}
}
// We need to reorder the include/macros: // We need to reorder the include/macros:
// includes the closest match to the resource will come first // includes the closest match to the resource will come first
// /project/src/file.c --> /usr/local/include // /project/src/file.c --> /usr/local/include
@ -101,23 +127,26 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP
// /project/src --> NDEBUG=0 // /project/src --> NDEBUG=0
// //
// We will use NDEBUG=1 only // We will use NDEBUG=1 only
int count = resPath.segmentCount(); int count = resPath.segmentCount();
ArrayList includeList = new ArrayList(); ArrayList includeList = new ArrayList();
Map symbolMap = new HashMap(); Map symbolMap = new HashMap();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
IPath newPath = resPath.removeLastSegments(i); IPath newPath = resPath.removeLastSegments(i);
for (int j = 0; j < entries.length; j++) { for (int j = 0; j < entries.length; j++) {
IPathEntry entry = entries[j]; if (entries[j] != null) {
IPath otherPath = entry.getPath(); IPathEntry entry = entries[j];
if (newPath.equals(otherPath)) { IPath otherPath = entry.getPath();
if (entry.getEntryKind() == IPathEntry.CDT_INCLUDE) { if (newPath.equals(otherPath)) {
IIncludeEntry include = (IIncludeEntry)entry; if (entry.getEntryKind() == IPathEntry.CDT_INCLUDE) {
includeList.add(include.getFullIncludePath().toOSString()); IIncludeEntry include = (IIncludeEntry)entry;
} else if (entry.getEntryKind() == IPathEntry.CDT_MACRO) { includeList.add(include.getFullIncludePath().toOSString());
IMacroEntry macro = (IMacroEntry)entry; } else if (entry.getEntryKind() == IPathEntry.CDT_MACRO) {
String key = macro.getMacroName(); IMacroEntry macro = (IMacroEntry)entry;
if (!symbolMap.containsKey(key)) { String key = macro.getMacroName();
symbolMap.put(key, macro.getMacroValue()); if (!symbolMap.containsKey(key)) {
symbolMap.put(key, macro.getMacroValue());
}
} }
} }
} }
@ -127,7 +156,7 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP
// Add the Project contributions last. // Add the Project contributions last.
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
IPathEntry entry = entries[i]; IPathEntry entry = entries[i];
if (entry.getEntryKind() == IPathEntry.CDT_PROJECT) { if (entry != null && entry.getEntryKind() == IPathEntry.CDT_PROJECT) {
IResource res = resource.getWorkspace().getRoot().findMember(entry.getPath()); IResource res = resource.getWorkspace().getRoot().findMember(entry.getPath());
if (res != null && res.getType() == IResource.PROJECT) { if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res); ICProject refCProject = CoreModel.getDefault().create((IProject)res);