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

fixes problem with binaries showing up multiple time in project view.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=183825
This commit is contained in:
David Inglis 2007-06-14 20:19:22 +00:00
parent 81bcb26800
commit 0a9f69a04c
5 changed files with 153 additions and 170 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2005 QNX Software Systems and others. * Copyright (c) 2000, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -202,28 +202,19 @@ public class CContainer extends Openable implements ICContainer {
try { try {
IResource[] resources = null; IResource[] resources = null;
if (res instanceof IContainer) { if (res instanceof IContainer) {
//System.out.println (" Resource: " +
// res.getFullPath().toOSString());
IContainer container = (IContainer) res; IContainer container = (IContainer) res;
resources = container.members(false); resources = container.members(false);
} }
if (resources != null) { if (resources != null) {
ICProject cproject = getCProject(); ICProject cproject = getCProject();
ISourceRoot sroot = getSourceRoot();
for (int i = 0; i < resources.length; i++) { for (int i = 0; i < resources.length; i++) {
if (sroot.isOnSourceEntry(resources[i])) {
// Check for Valid C Element only.
ICElement celement = computeChild(resources[i], cproject); ICElement celement = computeChild(resources[i], cproject);
if (celement != null) { if (celement != null) {
vChildren.add(celement); vChildren.add(celement);
} }
} }
} }
}
} catch (CoreException e) { } catch (CoreException e) {
//System.out.println (e);
//CPlugin.log (e);
//e.printStackTrace();
throw new CModelException(e); throw new CModelException(e);
} }
info.setChildren(vChildren); info.setChildren(vChildren);
@ -235,13 +226,25 @@ public class CContainer extends Openable implements ICContainer {
protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException { protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException {
ICElement celement = null; ICElement celement = null;
ISourceRoot sroot = getSourceRoot();
if (sroot == null) {
return null;
}
switch (res.getType()) { switch (res.getType()) {
case IResource.FILE: { case IResource.FILE: {
IFile file = (IFile) res; IFile file = (IFile) res;
boolean checkBinary = true;
if (sroot.isOnSourceEntry(res)) {
// Check for Valid C Element only.
String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName()); String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
if (id != null) { if (id != null) {
celement = new TranslationUnit(this, file, id); celement = new TranslationUnit(this, file, id);
} else if (cproject.isOnOutputEntry(file)) { checkBinary = false;
} else {
checkBinary = true;
}
}
if (checkBinary && cproject.isOnOutputEntry(file)) {
IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file); IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file);
if (bin != null) { if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
@ -260,7 +263,9 @@ public class CContainer extends Openable implements ICContainer {
break; break;
} }
case IResource.FOLDER: case IResource.FOLDER:
if (sroot.isOnSourceEntry(res) || cproject.isOnOutputEntry(res)) {
celement = new CContainer(this, res); celement = new CContainer(this, res);
}
break; break;
} }
return celement; return celement;

View file

@ -68,7 +68,6 @@ public class CContainerInfo extends OpenableInfo {
resources = container.members(false); resources = container.members(false);
} }
// IPathEntry[] entries = cproject.getResolvedPathEntries();
ICSourceEntry[] entries = null; ICSourceEntry[] entries = null;
ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(cproject.getProject(), false); ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(cproject.getProject(), false);
if(des != null){ if(des != null){
@ -85,22 +84,22 @@ public class CContainerInfo extends OpenableInfo {
case IResource.FOLDER: { case IResource.FOLDER: {
// Check if the folder is not itself a sourceEntry. // Check if the folder is not itself a sourceEntry.
IPath resourcePath = member.getFullPath(); IPath resourcePath = member.getFullPath();
if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries)) { if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries)
|| cproject.isOnOutputEntry(member)) {
continue; continue;
} }
break; break;
} }
case IResource.FILE: { case IResource.FILE: {
String filename = member.getName(); String filename = member.getName();
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) && if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename)
root.isOnSourceEntry(member)) { && root.isOnSourceEntry(member)) {
continue; continue;
} }
if (root.isOnSourceEntry(member)) { if (cproject.isOnOutputEntry(member)
if (cproject.isOnOutputEntry(member) && CModelManager.getDefault().createBinaryFile((IFile)member) != null) { && CModelManager.getDefault().createBinaryFile((IFile) member) != null) {
continue; continue;
} }
}
break; break;
} }
} }

View file

@ -249,6 +249,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
return cModel.getCProject(project); return cModel.getCProject(project);
} }
private boolean isInContainerOnOutputPath(ICContainer root, IResource resource) {
return (root.getPath().isPrefixOf(resource.getFullPath()));
}
public ICContainer create(IFolder folder, ICProject cproject) { public ICContainer create(IFolder folder, ICProject cproject) {
if (folder == null) { if (folder == null) {
return null; return null;
@ -259,14 +263,15 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
ICContainer celement = null; ICContainer celement = null;
IPath resourcePath = folder.getFullPath(); IPath resourcePath = folder.getFullPath();
try { try {
ISourceRoot[] roots = cproject.getAllSourceRoots(); ICElement[] children = cproject.getChildren();
for (int i = 0; i < roots.length; ++i) { for (int i = 0; i < children.length; ++i) {
ISourceRoot root = roots[i]; if (children[i] instanceof ICContainer) {
ICContainer root = (ICContainer) children[i];
IPath rootPath = root.getPath(); IPath rootPath = root.getPath();
if (rootPath.equals(resourcePath)) { if (rootPath.equals(resourcePath)) {
celement = root; celement = root;
break; // We are done. break; // We are done.
} else if (root.isOnSourceEntry(folder)) { } else if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(folder) || isInContainerOnOutputPath(root, folder)) {
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
String[] segments = path.segments(); String[] segments = path.segments();
ICContainer cfolder = root; ICContainer cfolder = root;
@ -274,6 +279,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
cfolder = cfolder.getCContainer(segments[j]); cfolder = cfolder.getCContainer(segments[j]);
} }
celement = cfolder; celement = cfolder;
break;
}
} }
} }
} catch (CModelException e) { } catch (CModelException e) {
@ -289,13 +296,13 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (cproject == null) { if (cproject == null) {
cproject = create(file.getProject()); cproject = create(file.getProject());
} }
boolean checkIfBinary = false;
ICElement celement = null; ICElement celement = null;
try { try {
ISourceRoot[] roots = cproject.getAllSourceRoots(); ICElement[] children = cproject.getChildren();
for (int i = 0; i < roots.length; ++i) { for (int i = 0; i < children.length; ++i) {
ISourceRoot root = roots[i]; if (children[i] instanceof ICContainer) {
if (root.isOnSourceEntry(file)) { ICContainer root = (ICContainer) children[i];
if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(file) || isInContainerOnOutputPath(root, file)) {
IPath rootPath = root.getPath(); IPath rootPath = root.getPath();
IPath resourcePath = file.getFullPath(); IPath resourcePath = file.getFullPath();
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
@ -306,7 +313,6 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
for (int j = 0; j < segments.length; j++) { for (int j = 0; j < segments.length; j++) {
cfolder = cfolder.getCContainer(segments[j]); cfolder = cfolder.getCContainer(segments[j]);
} }
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) { if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) {
celement = cfolder.getTranslationUnit(fileName); celement = cfolder.getTranslationUnit(fileName);
} else if (cproject.isOnOutputEntry(file)) { } else if (cproject.isOnOutputEntry(file)) {
@ -322,27 +328,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
vbin.addChild(celement); vbin.addChild(celement);
} }
} }
checkIfBinary = true;
} }
break; break;
} }
} }
// try in the outputEntry and save in the container
// But do not create an ICElement since they are not in the Model per say
if (celement == null && !checkIfBinary && cproject.isOnOutputEntry(file)) {
IBinaryFile bin = createBinaryFile(file);
if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
celement = new Archive(vlib, file, (IBinaryArchive)bin);
vlib.addChild(celement);
} else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
celement = new Binary(vbin, file, (IBinaryObject)bin);
vbin.addChild(celement);
}
}
} }
} catch (CModelException e) { } catch (CModelException e) {
// //
@ -362,43 +351,16 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
ICElement celement = null; ICElement celement = null;
try { try {
ISourceRoot[] roots = cproject.getAllSourceRoots(); if (cproject.isOnOutputEntry(file)) {
for (int i = 0; i < roots.length; ++i) { IPath resourcePath = file.getParent().getFullPath();
ISourceRoot root = roots[i]; ICElement cfolder = cproject.findElement(resourcePath);
if (root.isOnSourceEntry(file)) {
IPath rootPath = root.getPath();
IPath resourcePath = file.getFullPath();
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
path = path.removeLastSegments(1);
String[] segments = path.segments();
ICContainer cfolder = root;
for (int j = 0; j < segments.length; j++) {
cfolder = cfolder.getCContainer(segments[j]);
}
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
celement = new Archive(cfolder, file, (IBinaryArchive)bin); celement = new Archive(cfolder, file, (IBinaryArchive)bin);
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
vlib.addChild(celement); vlib.addChild(celement);
} else { } else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
celement = new Binary(cfolder, file, (IBinaryObject)bin); celement = new Binary(cfolder, file, (IBinaryObject)bin);
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
vbin.addChild(celement);
}
break;
}
}
// try in the outputEntry and save in the container
// But do not create a ICElement since they are not in the Model per say
if (celement == null) {
if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
celement = new Archive(vlib, file, (IBinaryArchive)bin);
vlib.addChild(celement);
} else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
celement = new Binary(vbin, file, (IBinaryObject)bin);
vbin.addChild(celement); vbin.addChild(celement);
} }
} }

View file

@ -156,10 +156,7 @@ public class CProject extends Openable implements ICProject {
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) { if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
IIncludeEntry entry = (IIncludeEntry) entries[i]; IIncludeEntry entry = (IIncludeEntry) entries[i];
IIncludeReference inc = new IncludeReference(this, entry); list.add(new IncludeReference(this, entry));
if (inc != null) {
list.add(inc);
}
} }
} }
incRefs = (IIncludeReference[]) list.toArray(new IIncludeReference[0]); incRefs = (IIncludeReference[]) list.toArray(new IIncludeReference[0]);
@ -481,15 +478,14 @@ public class CProject extends Openable implements ICProject {
* @see org.eclipse.cdt.core.model.ICProject#getSourceRoots() * @see org.eclipse.cdt.core.model.ICProject#getSourceRoots()
*/ */
public ISourceRoot[] getSourceRoots() throws CModelException { public ISourceRoot[] getSourceRoots() throws CModelException {
Object[] children; Object[] children = getChildren();
int length; ArrayList result = new ArrayList(children.length);
for (int i = 0; i < children.length; i++) {
children = getChildren(); if (children[i] instanceof ISourceRoot) {
length = children.length; result.add(children[i]);
ISourceRoot[] roots = new ISourceRoot[length]; }
System.arraycopy(children, 0, roots, 0, length); }
return (ISourceRoot[]) result.toArray(new ISourceRoot[result.size()]);
return roots;
} }
/** /**
@ -588,7 +584,7 @@ public class CProject extends Openable implements ICProject {
try { try {
IResource res = getResource(); IResource res = getResource();
if (res != null && res.isAccessible()) { if (res != null && res.isAccessible()) {
validInfo = computeSourceRoots(info, res); validInfo = computeChildren(info, res);
} else { } else {
throw newNotPresentException(); throw newNotPresentException();
} }
@ -613,26 +609,54 @@ public class CProject extends Openable implements ICProject {
if(entries != null){ if(entries != null){
ArrayList list = new ArrayList(entries.length); ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
// if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { ICSourceEntry sourceEntry = entries[i];
ICSourceEntry sourceEntry = (ICSourceEntry)entries[i];
ISourceRoot root = getSourceRoot(sourceEntry); ISourceRoot root = getSourceRoot(sourceEntry);
if (root != null) { if (root != null) {
list.add(root); list.add(root);
} }
// }
} }
return list; return list;
} }
return new ArrayList(0); return new ArrayList(0);
} }
protected boolean computeSourceRoots(OpenableInfo info, IResource res) throws CModelException { /**
info.setChildren(computeSourceRoots()); * Add any output paths which don't overlay paths already in the list.
*/
private List addOutputOnlyRoots(List sourceRoots) {
IResource[] resources;
ArrayList result = new ArrayList(sourceRoots.size());
try {
resources = getProject().members();
for (int i = 0; i < resources.length; i++) {
if (resources[i].getType() == IResource.FOLDER) {
boolean found = false;
for (int j = 0; j < sourceRoots.size(); j++) {
if (((ICElement) sourceRoots.get(j)).getResource().getProjectRelativePath().isPrefixOf(resources[i].getProjectRelativePath())) {
found = true;
break;
}
}
if (!found) {
result.add(new CContainer(this, resources[i]));
}
}
}
} catch (CoreException e) {
// ignore
}
result.addAll(sourceRoots);
return result;
}
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
List list = computeSourceRoots();
list = addOutputOnlyRoots(list);
info.setChildren(list);
if (info instanceof CProjectInfo) { if (info instanceof CProjectInfo) {
CProjectInfo pinfo = (CProjectInfo)info; CProjectInfo pinfo = (CProjectInfo)info;
pinfo.setNonCResources(null); pinfo.setNonCResources(null);
} }
return true; return true;
} }

View file

@ -85,8 +85,6 @@ class CProjectInfo extends OpenableInfo {
IProject project = cproject.getProject(); IProject project = cproject.getProject();
IPath projectPath = project.getFullPath(); IPath projectPath = project.getFullPath();
char[][] exclusionPatterns = null; char[][] exclusionPatterns = null;
// try {
// entries = cproject.getResolvedPathEntries();
ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
if (des != null) { if (des != null) {
ICConfigurationDescription cfg = des.getDefaultSettingConfiguration(); ICConfigurationDescription cfg = des.getDefaultSettingConfiguration();
@ -97,19 +95,14 @@ class CProjectInfo extends OpenableInfo {
if (entries != null) { if (entries != null) {
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
// if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { ICSourceEntry entry = entries[i];
ICSourceEntry entry = /*(ISourceEntry)*/entries[i];
if (projectPath.equals(entry.getFullPath())) { if (projectPath.equals(entry.getFullPath())) {
srcIsProject = true; srcIsProject = true;
exclusionPatterns = entry.fullExclusionPatternChars(); exclusionPatterns = entry.fullExclusionPatternChars();
break; break;
} }
// }
} }
} }
// } catch (CModelException e) {
// ignore
// }
ArrayList notChildren = new ArrayList(); ArrayList notChildren = new ArrayList();
try { try {