1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 00:36:16 +02:00

Bug 193843 - Fix up handling of folders and binaries not in a source root but in an output entry.

This commit is contained in:
Doug Schaefer 2007-06-23 00:31:06 +00:00
parent edf59d635c
commit b5ad1a939e
5 changed files with 129 additions and 152 deletions

View file

@ -227,14 +227,11 @@ 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(); 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; boolean checkBinary = true;
if (sroot.isOnSourceEntry(res)) { if (sroot != null && sroot.isOnSourceEntry(res)) {
// Check for Valid C Element only. // 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) {
@ -263,7 +260,7 @@ public class CContainer extends Openable implements ICContainer {
break; break;
} }
case IResource.FOLDER: case IResource.FOLDER:
if (sroot.isOnSourceEntry(res) || cproject.isOnOutputEntry(res)) { if (sroot != null && sroot.isOnSourceEntry(res) || cproject.isOnOutputEntry(res)) {
celement = new CContainer(this, res); celement = new CContainer(this, res);
} }
break; break;

View file

@ -249,10 +249,6 @@ 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;
@ -260,33 +256,41 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (cproject == null) { if (cproject == null) {
cproject = create(folder.getProject()); cproject = create(folder.getProject());
} }
ICContainer celement = null;
IPath resourcePath = folder.getFullPath();
try { try {
ICElement[] children = cproject.getChildren(); ICElement[] children = cproject.getChildren();
for (int i = 0; i < children.length; ++i) { for (int i = 0; i < children.length; ++i) {
if (children[i] instanceof ICContainer) { if (children[i] instanceof ISourceRoot) {
ICContainer root = (ICContainer) children[i]; ISourceRoot root = (ISourceRoot)children[i];
IPath rootPath = root.getPath(); if (root.isOnSourceEntry(folder)) {
if (rootPath.equals(resourcePath)) { // Get the container
celement = root; IPath path = folder.getFullPath();
break; // We are done. path = path.removeFirstSegments(root.getPath().segmentCount());
} else if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(folder) || isInContainerOnOutputPath(root, folder)) {
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
String[] segments = path.segments(); String[] segments = path.segments();
ICContainer cfolder = root; ICContainer cfolder = root;
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]);
} }
celement = cfolder; return cfolder;
break; }
} else if (children[i] instanceof ICContainer) {
ICContainer root = (ICContainer)children[i];
IPath rootPath = root.getPath();
IPath path = folder.getFullPath();
if (rootPath.isPrefixOf(path) && cproject.isOnOutputEntry(folder)) {
path = path.removeFirstSegments(root.getPath().segmentCount());
String[] segments = path.segments();
ICContainer cfolder = root;
for (int j = 0; j < segments.length; ++j) {
cfolder = cfolder.getCContainer(segments[j]);
}
return cfolder;
} }
} }
} }
} catch (CModelException e) { } catch (CModelException e) {
// //
} }
return celement; return null;
} }
public ICElement create(IFile file, ICProject cproject) { public ICElement create(IFile file, ICProject cproject) {
@ -298,13 +302,13 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
ICElement celement = null; ICElement celement = null;
try { try {
ICElement[] children = cproject.getChildren(); // First look for TU's
for (int i = 0; i < children.length; ++i) {
if (children[i] instanceof ICContainer) {
ICContainer root = (ICContainer) children[i];
if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(file) || isInContainerOnOutputPath(root, file)) {
IPath rootPath = root.getPath();
IPath resourcePath = file.getFullPath(); IPath resourcePath = file.getFullPath();
ISourceRoot[] roots = cproject.getSourceRoots();
for (int i = 0; i < roots.length; ++i) {
ISourceRoot root = roots[i];
if (root.isOnSourceEntry(file)) {
IPath rootPath = root.getPath();
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
String fileName = path.lastSegment(); String fileName = path.lastSegment();
path = path.removeLastSegments(1); path = path.removeLastSegments(1);
@ -315,23 +319,19 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
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)) {
IBinaryFile bin = createBinaryFile(file);
if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) {
celement = new Archive(cfolder, file, (IBinaryArchive) bin);
ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer();
vlib.addChild(celement);
} else { } else {
celement = new Binary(cfolder, file, (IBinaryObject) bin); IBinaryFile bin = createBinaryFile(file);
BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer(); if (bin != null)
vbin.addChild(celement); celement = create(file, bin, cproject);
}
}
} }
break; break;
} }
} }
if (celement == null && cproject.isOnOutputEntry(file)) {
IBinaryFile bin = createBinaryFile(file);
if (bin != null)
celement = create(file, bin, cproject);
} }
} catch (CModelException e) { } catch (CModelException e) {
// //
@ -354,6 +354,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (cproject.isOnOutputEntry(file)) { if (cproject.isOnOutputEntry(file)) {
IPath resourcePath = file.getParent().getFullPath(); IPath resourcePath = file.getParent().getFullPath();
ICElement cfolder = cproject.findElement(resourcePath); ICElement cfolder = cproject.findElement(resourcePath);
// Check if folder is a source root and use that instead
ISourceRoot sourceRoot = cproject.findSourceRoot(resourcePath);
if (sourceRoot != null)
cfolder = sourceRoot;
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
celement = new Archive(cfolder, file, (IBinaryArchive)bin); celement = new Archive(cfolder, file, (IBinaryArchive)bin);

View file

@ -620,39 +620,36 @@ public class CProject extends Openable implements ICProject {
return new ArrayList(0); return new ArrayList(0);
} }
/** protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
* Add any output paths which don't overlay paths already in the list. List sourceRoots = computeSourceRoots();
*/ List children = new ArrayList(sourceRoots.size());
private List addOutputOnlyRoots(List sourceRoots) { children.addAll(sourceRoots);
IResource[] resources;
ArrayList result = new ArrayList(sourceRoots.size()); // Now look for output folders
try { try {
resources = getProject().members(); IResource[] resources = getProject().members();
for (int i = 0; i < resources.length; i++) { for (int i = 0; i < resources.length; i++) {
if (resources[i].getType() == IResource.FOLDER) { IResource child = resources[i];
if (child.getType() == IResource.FOLDER) {
boolean found = false; boolean found = false;
for (int j = 0; j < sourceRoots.size(); j++) { for (Iterator iter = sourceRoots.iterator(); iter.hasNext();) {
if (((ICElement) sourceRoots.get(j)).getResource().getProjectRelativePath().isPrefixOf(resources[i].getProjectRelativePath())) { ISourceRoot sourceRoot = (ISourceRoot)iter.next();
if (sourceRoot.isOnSourceEntry(child)) {
found = true; found = true;
break; break;
} }
} }
if (!found) {
result.add(new CContainer(this, resources[i])); // Not in source folder, check if it's a container on output entry
} if (!found && isOnOutputEntry(child))
children.add(new CContainer(this, child));
} }
} }
} catch (CoreException e) { } catch (CoreException e) {
// ignore // ignore
} }
result.addAll(sourceRoots);
return result;
}
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { info.setChildren(children);
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);

View file

@ -12,10 +12,10 @@
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
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.IArchiveContainer; import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -23,16 +23,10 @@ import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ILibraryReference; import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.cdt.core.model.IOutputEntry; import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/** /**
* Info for ICProject. * Info for ICProject.
@ -78,72 +72,58 @@ class CProjectInfo extends OpenableInfo {
if (nonCResources != null) if (nonCResources != null)
return nonCResources; return nonCResources;
// determine if src == project List notChildren = new ArrayList();
boolean srcIsProject = false;
ICSourceEntry[] entries = null;
ICProject cproject = getElement().getCProject();
IProject project = cproject.getProject();
IPath projectPath = project.getFullPath();
char[][] exclusionPatterns = null;
ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false);
if (des != null) {
ICConfigurationDescription cfg = des.getDefaultSettingConfiguration();
if (cfg != null) {
entries = cfg.getResolvedSourceEntries();
}
}
if (entries != null) {
for (int i = 0; i < entries.length; i++) {
ICSourceEntry entry = entries[i];
if (projectPath.equals(entry.getFullPath())) {
srcIsProject = true;
exclusionPatterns = entry.fullExclusionPatternChars();
break;
}
}
}
ArrayList notChildren = new ArrayList();
try { try {
IResource[] resources = null;
if (res instanceof IContainer) { if (res instanceof IContainer) {
IContainer container = (IContainer)res; ICProject cproject = getElement().getCProject();
resources = container.members(false); ISourceRoot[] sourceRoots = cproject.getSourceRoots();
} IResource[] resources = ((IContainer)res).members();
if (resources != null) { for (int i = 0; i < resources.length; ++i) {
for (int i = 0; i < resources.length; i++) { IResource child = resources[i];
IResource member = resources[i];
switch(member.getType()) { // Check if under source root
case IResource.FILE: { boolean found = false;
String filename = member.getName(); for (int j = 0; j < sourceRoots.length; ++j)
if (srcIsProject) { if (sourceRoots[j].isOnSourceEntry(child)) {
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) found = true;
&& !CoreModelUtil.isExcluded(member, exclusionPatterns)) {
continue;
} else if (!CoreModelUtil.isExcluded(member, exclusionPatterns)) {
if (cproject.isOnOutputEntry(member) && CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
continue;
}
}
}
break; break;
} }
case IResource.FOLDER: {
if (srcIsProject && !CoreModelUtil.isExcluded(member, exclusionPatterns)) { if (found) {
switch (child.getType()) {
case IResource.FILE:
// Must be a translation unit or binary
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), child.getName())
|| CModelManager.getDefault().createBinaryFile((IFile)child) != null)
continue;
break;
case IResource.FOLDER:
// All folders are good
continue;
}
} else if (cproject.isOnOutputEntry(child)) {
switch (child.getType()) {
case IResource.FILE:
if (CModelManager.getDefault().createBinaryFile((IFile)child) != null)
continue;
break;
case IResource.FOLDER:
// All folders are good here too
continue; continue;
} }
} }
}
notChildren.add(member); // It's a non C resource
notChildren.add(child);
} }
} }
} catch (CModelException e) {
// this can't be good.
} catch (CoreException e) { } catch (CoreException e) {
//System.out.println (e); // this neither
//CPlugin.log (e);
//e.printStackTrace();
} }
setNonCResources(notChildren.toArray()); setNonCResources(notChildren.toArray());
return nonCResources; return nonCResources;
} }

View file

@ -329,19 +329,16 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
return NO_CHILDREN; return NO_CHILDREN;
List list= new ArrayList(); List list= new ArrayList();
ISourceRoot[] roots = cproject.getSourceRoots(); ICElement[] children = cproject.getChildren();
// filter out source roots that correspond to projects and for (int i= 0; i < children.length; i++) {
// replace them with the package fragments directly ICElement child = children[i];
for (int i= 0; i < roots.length; i++) { if (child instanceof ISourceRoot && child.getResource().getType() == IResource.PROJECT) {
ISourceRoot root= roots[i]; // Was a source root at the project, get the children of this element
if (isProjectSourceRoot(root)) { ICElement[] c2 = ((ISourceRoot)child).getChildren();
Object[] children= root.getChildren(); for (int k = 0; k < c2.length; ++k)
for (int k= 0; k < children.length; k++) { list.add(c2[k]);
list.add(children[k]); } else
} list.add(child);
} else {
list.add(root);
}
} }
Object[] objects = list.toArray(); Object[] objects = list.toArray();