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
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.

View file

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

View file

@ -148,13 +148,14 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
}
public IPathEntry[] getResolvedPathEntries(ICProject cproject, boolean generateMarkers) throws CModelException {
IPathEntry[] entries = (IPathEntry[])resolvedMap.get(cproject);
if (entries == null) {
ArrayList listEntries = (ArrayList)resolvedMap.get(cproject);
IPathEntry[] resolvedEntries;
if (listEntries == null) {
IPath projectPath = cproject.getPath();
entries = getRawPathEntries(cproject);
ArrayList list = new ArrayList();
for (int i = 0; i < entries.length; i++) {
IPathEntry entry = entries[i];
IPathEntry[] rawEntries = getRawPathEntries(cproject);
listEntries = new ArrayList();
for (int i = 0; i < rawEntries.length; i++) {
IPathEntry entry = rawEntries[i];
// Expand the containers.
if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) {
IContainerEntry centry = (IContainerEntry) entry;
@ -164,7 +165,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (containerEntries != null) {
for (int j = 0; j < containerEntries.length; 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 e = getExpandedPathEntry(clone, cproject);
if (e != null) {
list.add(e);
listEntries.add(e);
}
}
}
entries = new IPathEntry[list.size()];
list.toArray(entries);
listEntries.trimToSize();
resolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES);
if (generateMarkers) {
final ICProject finalCProject = cproject;
final IPathEntry[] finalEntries = entries;
final IPathEntry[] finalEntries = resolvedEntries;
Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$
/* (non-Javadoc)
* @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();
}
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 {
@ -387,7 +390,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException {
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);
CModelManager.getDefault().runOperation(op, monitor);
} catch (CoreException e) {
@ -482,7 +489,12 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
continue;
}
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);
}
// Nothing change.
@ -1014,7 +1026,11 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
if (project.isAccessible()) {
try {
// 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);
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
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.model.CModelException;
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.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
@ -89,6 +90,31 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP
if (cproject != null) {
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:
// includes the closest match to the resource will come first
// /project/src/file.c --> /usr/local/include
@ -101,23 +127,26 @@ public class ScannerProvider extends AbstractCExtension implements IScannerInfoP
// /project/src --> NDEBUG=0
//
// We will use NDEBUG=1 only
int count = resPath.segmentCount();
ArrayList includeList = new ArrayList();
Map symbolMap = new HashMap();
for (int i = 0; i < count; i++) {
IPath newPath = resPath.removeLastSegments(i);
for (int j = 0; j < entries.length; j++) {
IPathEntry entry = entries[j];
IPath otherPath = entry.getPath();
if (newPath.equals(otherPath)) {
if (entry.getEntryKind() == IPathEntry.CDT_INCLUDE) {
IIncludeEntry include = (IIncludeEntry)entry;
includeList.add(include.getFullIncludePath().toOSString());
} else if (entry.getEntryKind() == IPathEntry.CDT_MACRO) {
IMacroEntry macro = (IMacroEntry)entry;
String key = macro.getMacroName();
if (!symbolMap.containsKey(key)) {
symbolMap.put(key, macro.getMacroValue());
if (entries[j] != null) {
IPathEntry entry = entries[j];
IPath otherPath = entry.getPath();
if (newPath.equals(otherPath)) {
if (entry.getEntryKind() == IPathEntry.CDT_INCLUDE) {
IIncludeEntry include = (IIncludeEntry)entry;
includeList.add(include.getFullIncludePath().toOSString());
} else if (entry.getEntryKind() == IPathEntry.CDT_MACRO) {
IMacroEntry macro = (IMacroEntry)entry;
String key = macro.getMacroName();
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.
for (int i = 0; i < entries.length; 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());
if (res != null && res.getType() == IResource.PROJECT) {
ICProject refCProject = CoreModel.getDefault().create((IProject)res);