diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java index e87d5d69f6c..f4f7da9bee6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -202,28 +202,19 @@ public class CContainer extends Openable implements ICContainer { try { IResource[] resources = null; if (res instanceof IContainer) { - //System.out.println (" Resource: " + - // res.getFullPath().toOSString()); IContainer container = (IContainer) res; resources = container.members(false); } if (resources != null) { ICProject cproject = getCProject(); - ISourceRoot sroot = getSourceRoot(); 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); - if (celement != null) { - vChildren.add(celement); - } + ICElement celement = computeChild(resources[i], cproject); + if (celement != null) { + vChildren.add(celement); } } } } catch (CoreException e) { - //System.out.println (e); - //CPlugin.log (e); - //e.printStackTrace(); throw new CModelException(e); } info.setChildren(vChildren); @@ -235,23 +226,35 @@ public class CContainer extends Openable implements ICContainer { protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException { ICElement celement = null; + ISourceRoot sroot = getSourceRoot(); + if (sroot == null) { + return null; + } switch (res.getType()) { - case IResource.FILE : { + case IResource.FILE: { IFile file = (IFile) res; - String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName()); - if (id != null) { - celement = new TranslationUnit(this, file, id); - } else if (cproject.isOnOutputEntry(file)) { + boolean checkBinary = true; + if (sroot.isOnSourceEntry(res)) { + // Check for Valid C Element only. + String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName()); + if (id != null) { + celement = new TranslationUnit(this, file, id); + checkBinary = false; + } else { + checkBinary = true; + } + } + if (checkBinary && cproject.isOnOutputEntry(file)) { IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file); if (bin != null) { if (bin.getType() == IBinaryFile.ARCHIVE) { - celement = new Archive(this, file, (IBinaryArchive)bin); - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); + celement = new Archive(this, file, (IBinaryArchive) bin); + ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer(); vlib.addChild(celement); } else { - celement = new Binary(this, file, (IBinaryObject)bin); + celement = new Binary(this, file, (IBinaryObject) bin); if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); + BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer(); vbin.addChild(celement); } } @@ -259,8 +262,10 @@ public class CContainer extends Openable implements ICContainer { } break; } - case IResource.FOLDER : - celement = new CContainer(this, res); + case IResource.FOLDER: + if (sroot.isOnSourceEntry(res) || cproject.isOnOutputEntry(res)) { + celement = new CContainer(this, res); + } break; } return celement; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java index 2dbfef1535a..c2dba75999a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java @@ -68,7 +68,6 @@ public class CContainerInfo extends OpenableInfo { resources = container.members(false); } -// IPathEntry[] entries = cproject.getResolvedPathEntries(); ICSourceEntry[] entries = null; ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(cproject.getProject(), false); if(des != null){ @@ -85,21 +84,21 @@ public class CContainerInfo extends OpenableInfo { case IResource.FOLDER: { // Check if the folder is not itself a sourceEntry. IPath resourcePath = member.getFullPath(); - if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries)) { + if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries) + || cproject.isOnOutputEntry(member)) { continue; } break; } case IResource.FILE: { String filename = member.getName(); - if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) && - root.isOnSourceEntry(member)) { + if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) + && root.isOnSourceEntry(member)) { continue; } - if (root.isOnSourceEntry(member)) { - if (cproject.isOnOutputEntry(member) && CModelManager.getDefault().createBinaryFile((IFile)member) != null) { - continue; - } + if (cproject.isOnOutputEntry(member) + && CModelManager.getDefault().createBinaryFile((IFile) member) != null) { + continue; } break; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 0d0e73fc81e..7ca8613a4f1 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -249,6 +249,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe return cModel.getCProject(project); } + private boolean isInContainerOnOutputPath(ICContainer root, IResource resource) { + return (root.getPath().isPrefixOf(resource.getFullPath())); + } + public ICContainer create(IFolder folder, ICProject cproject) { if (folder == null) { return null; @@ -259,21 +263,24 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe ICContainer celement = null; IPath resourcePath = folder.getFullPath(); try { - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; ++i) { - ISourceRoot root = roots[i]; - IPath rootPath = root.getPath(); - if (rootPath.equals(resourcePath)) { - celement = root; - break; // We are done. - } else if (root.isOnSourceEntry(folder)) { - IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); - String[] segments = path.segments(); - ICContainer cfolder = root; - for (int j = 0; j < segments.length; j++) { - cfolder = cfolder.getCContainer(segments[j]); + ICElement[] children = cproject.getChildren(); + for (int i = 0; i < children.length; ++i) { + if (children[i] instanceof ICContainer) { + ICContainer root = (ICContainer) children[i]; + IPath rootPath = root.getPath(); + if (rootPath.equals(resourcePath)) { + celement = root; + break; // We are done. + } else if (root instanceof ISourceRoot && ((ISourceRoot)root).isOnSourceEntry(folder) || isInContainerOnOutputPath(root, folder)) { + IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); + String[] segments = path.segments(); + ICContainer cfolder = root; + for (int j = 0; j < segments.length; j++) { + cfolder = cfolder.getCContainer(segments[j]); + } + celement = cfolder; + break; } - celement = cfolder; } } } catch (CModelException e) { @@ -289,58 +296,40 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe if (cproject == null) { cproject = create(file.getProject()); } - boolean checkIfBinary = false; ICElement celement = null; try { - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; ++i) { - ISourceRoot root = roots[i]; - if (root.isOnSourceEntry(file)) { - IPath rootPath = root.getPath(); - IPath resourcePath = file.getFullPath(); - IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); - String fileName = path.lastSegment(); - 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 (CoreModel.isValidTranslationUnitName(cproject.getProject(), 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 { - celement = new Binary(cfolder, file, (IBinaryObject)bin); - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - vbin.addChild(celement); + ICElement[] children = cproject.getChildren(); + 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 path = resourcePath.removeFirstSegments(rootPath.segmentCount()); + String fileName = path.lastSegment(); + 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 (CoreModel.isValidTranslationUnitName(cproject.getProject(), 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 { + celement = new Binary(cfolder, file, (IBinaryObject) bin); + BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer(); + vbin.addChild(celement); + } } } - checkIfBinary = true; - } - 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); + break; } } } @@ -362,43 +351,16 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe } ICElement celement = null; try { - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; ++i) { - ISourceRoot root = roots[i]; - 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) { - celement = new Archive(cfolder, file, (IBinaryArchive)bin); - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - vlib.addChild(celement); - } else { - 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 (cproject.isOnOutputEntry(file)) { + IPath resourcePath = file.getParent().getFullPath(); + ICElement cfolder = cproject.findElement(resourcePath); if (bin.getType() == IBinaryFile.ARCHIVE) { ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - celement = new Archive(vlib, file, (IBinaryArchive)bin); + celement = new Archive(cfolder, file, (IBinaryArchive)bin); vlib.addChild(celement); } else { BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - celement = new Binary(vbin, file, (IBinaryObject)bin); + celement = new Binary(cfolder, file, (IBinaryObject)bin); vbin.addChild(celement); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java index a16c4fb28bd..8cd16bfc7b3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java @@ -156,10 +156,7 @@ public class CProject extends Openable implements ICProject { for (int i = 0; i < entries.length; i++) { if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) { IIncludeEntry entry = (IIncludeEntry) entries[i]; - IIncludeReference inc = new IncludeReference(this, entry); - if (inc != null) { - list.add(inc); - } + list.add(new IncludeReference(this, entry)); } } 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() */ public ISourceRoot[] getSourceRoots() throws CModelException { - Object[] children; - int length; - - children = getChildren(); - length = children.length; - ISourceRoot[] roots = new ISourceRoot[length]; - System.arraycopy(children, 0, roots, 0, length); - - return roots; + Object[] children = getChildren(); + ArrayList result = new ArrayList(children.length); + for (int i = 0; i < children.length; i++) { + if (children[i] instanceof ISourceRoot) { + result.add(children[i]); + } + } + return (ISourceRoot[]) result.toArray(new ISourceRoot[result.size()]); } /** @@ -588,7 +584,7 @@ public class CProject extends Openable implements ICProject { try { IResource res = getResource(); if (res != null && res.isAccessible()) { - validInfo = computeSourceRoots(info, res); + validInfo = computeChildren(info, res); } else { throw newNotPresentException(); } @@ -613,29 +609,57 @@ public class CProject extends Openable implements ICProject { if(entries != null){ ArrayList list = new ArrayList(entries.length); for (int i = 0; i < entries.length; i++) { -// if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { - ICSourceEntry sourceEntry = (ICSourceEntry)entries[i]; + ICSourceEntry sourceEntry = entries[i]; ISourceRoot root = getSourceRoot(sourceEntry); if (root != null) { list.add(root); } -// } } return list; } 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) { CProjectInfo pinfo = (CProjectInfo)info; pinfo.setNonCResources(null); } - return true; } - + /* * @see ICProject */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java index ae9f9d08ea9..b28cde4b7fa 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java @@ -85,31 +85,24 @@ class CProjectInfo extends OpenableInfo { IProject project = cproject.getProject(); IPath projectPath = project.getFullPath(); char[][] exclusionPatterns = null; -// try { -// entries = cproject.getResolvedPathEntries(); - ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); - if(des != null){ - ICConfigurationDescription cfg = des.getDefaultSettingConfiguration(); - if(cfg != null){ - entries = cfg.getResolvedSourceEntries(); + 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; } } - - if(entries != null){ - for (int i = 0; i < entries.length; i++) { -// if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { - ICSourceEntry entry = /*(ISourceEntry)*/entries[i]; - if (projectPath.equals(entry.getFullPath())) { - srcIsProject = true; - exclusionPatterns = entry.fullExclusionPatternChars(); - break; - } -// } - } - } -// } catch (CModelException e) { - // ignore -// } + } ArrayList notChildren = new ArrayList(); try {