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

2005-06-25 Alain Magloire

Fix PR 91069: BinaryRunner search improvements from Chris Wiebe.
	* model/org/eclipse/cdt/internal/core/model/BinaryRunner.java
This commit is contained in:
Alain Magloire 2005-06-25 19:33:42 +00:00
parent 939eb01a27
commit 59725982d0
3 changed files with 75 additions and 29 deletions

View file

@ -1,3 +1,7 @@
2005-06-25 Alain Magloire
Fix PR 91069: BinaryRunner search improvements from Chris Wiebe.
* model/org/eclipse/cdt/internal/core/model/BinaryRunner.java
2005-06-25 Alain Magloire
Fix PR 98788: Dealing with templates
* model/org/eclipse/cdt/core/model/ICElement.java

View file

@ -14,18 +14,25 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
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.ICProject;
import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.jobs.Job;
public class BinaryRunner {
@ -50,15 +57,21 @@ public class BinaryRunner {
if (cproject == null || monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
try {
monitor.beginTask(getName(), IProgressMonitor.UNKNOWN);
BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer();
ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer();
vlib.removeChildren();
vbin.removeChildren();
cproject.getProject().accept(new Visitor(BinaryRunner.this, monitor));
cproject.getProject().accept(new Visitor(monitor), IContainer.INCLUDE_PHANTOMS);
fireEvents(cproject, vbin);
fireEvents(cproject, vlib);
monitor.done();
} catch (CoreException e) {
return e.getStatus();
}
@ -108,42 +121,73 @@ public class BinaryRunner {
}
}
void addChildIfBinary(IFile file) {
CModelManager factory = CModelManager.getDefault();
// Attempt to speed things up by rejecting up front
// Things we know should not be Binary files.
if (!CoreModel.isTranslationUnit(file)) {
IBinaryFile bin = factory.createBinaryFile(file);
if (bin != null) {
// Create the file will add it to the {Archive,Binary}Containery.
factory.create(file, bin, null);
}
}
}
class Visitor implements IResourceVisitor {
private BinaryRunner vRunner;
private class Visitor implements IResourceProxyVisitor {
private IProgressMonitor vMonitor;
private IProject project;
private IOutputEntry[] entries = new IOutputEntry[0];
private IContentType textContentType;
public Visitor(BinaryRunner r, IProgressMonitor monitor) {
vRunner = r;
public Visitor(IProgressMonitor monitor) {
vMonitor = monitor;
this.project = cproject.getProject();
try {
entries = cproject.getOutputEntries();
} catch (CModelException e) {
}
IContentTypeManager mgr = Platform.getContentTypeManager();
textContentType = mgr.getContentType("org.eclipse.core.runtime.text"); //$NON-NLS-1$
}
public boolean visit(IResource res) throws CoreException {
public boolean visit(IResourceProxy proxy) throws CoreException {
if (vMonitor.isCanceled()) {
return false;
}
if (cproject.isOnOutputEntry(res)) {
if (res instanceof IFile) {
if (vRunner != null) {
vRunner.addChildIfBinary((IFile) res);
vMonitor.worked(1);
// Attempt to speed things up by rejecting up front
// Things we know should not be Binary files.
// check if it's a file resource
// and bail out early
if (proxy.getType() != IResource.FILE) {
return true;
}
// check against known content types
String name = proxy.getName();
IContentType contentType = CCorePlugin.getContentType(project, name);
if (contentType != null && textContentType != null) {
if (contentType != null && contentType.isKindOf(textContentType)) {
return true;
} else if (textContentType.isAssociatedWith(name)) {
return true;
}
}
// we have a candidate
IPath path = proxy.requestFullPath();
if (path != null) {
for (int i = 0; i < entries.length; ++i) {
if (isOnOutputEntry(entries[i], path)) {
IFile file = (IFile) proxy.requestResource();
CModelManager factory = CModelManager.getDefault();
IBinaryFile bin = factory.createBinaryFile(file);
if (bin != null) {
// Create the file will add it to the {Archive,Binary}Containery.
factory.create(file, bin, cproject);
return true;
}
}
return false;
}
}
return true;
}
private boolean isOnOutputEntry(IOutputEntry entry, IPath path) {
if (entry.getPath().isPrefixOf(path) && !CoreModelUtil.isExcluded(path, entry.fullExclusionPatternChars())) {
return true;
}
return false;
}
}
}

View file

@ -102,10 +102,8 @@ public class ContentTypeProcessor {
for (int i = 0; i < members.length; ++i) {
if (members[i] instanceof IFile) {
IFile file = (IFile) members[i];
//if (contentType.isAssociatedWith(file.getName(), context)) {
IContentType cType = CCorePlugin.getContentType(file.getProject(), file.getName());
if (cType != null && cType.equals(contentType)) {
// if (CoreModel.isValidTranslationUnitName(file.getProject(), file.getName())) {
ICElement newElement = CoreModel.getDefault().create(file);
if (newElement != null) {
elementAdded(newElement, celement);