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:
parent
939eb01a27
commit
59725982d0
3 changed files with 75 additions and 29 deletions
|
@ -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
|
2005-06-25 Alain Magloire
|
||||||
Fix PR 98788: Dealing with templates
|
Fix PR 98788: Dealing with templates
|
||||||
* model/org/eclipse/cdt/core/model/ICElement.java
|
* model/org/eclipse/cdt/core/model/ICElement.java
|
||||||
|
|
|
@ -14,18 +14,25 @@ package org.eclipse.cdt.internal.core.model;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||||
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.CoreModelUtil;
|
||||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
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.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
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.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
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;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
|
||||||
public class BinaryRunner {
|
public class BinaryRunner {
|
||||||
|
@ -50,15 +57,21 @@ public class BinaryRunner {
|
||||||
if (cproject == null || monitor.isCanceled()) {
|
if (cproject == null || monitor.isCanceled()) {
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
monitor.beginTask(getName(), IProgressMonitor.UNKNOWN);
|
||||||
|
|
||||||
BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer();
|
BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer();
|
||||||
ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer();
|
ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer();
|
||||||
|
|
||||||
vlib.removeChildren();
|
vlib.removeChildren();
|
||||||
vbin.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, vbin);
|
||||||
fireEvents(cproject, vlib);
|
fireEvents(cproject, vlib);
|
||||||
|
|
||||||
|
monitor.done();
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getStatus();
|
return e.getStatus();
|
||||||
}
|
}
|
||||||
|
@ -108,42 +121,73 @@ public class BinaryRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addChildIfBinary(IFile file) {
|
private class Visitor implements IResourceProxyVisitor {
|
||||||
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 IProgressMonitor vMonitor;
|
private IProgressMonitor vMonitor;
|
||||||
|
private IProject project;
|
||||||
|
private IOutputEntry[] entries = new IOutputEntry[0];
|
||||||
|
private IContentType textContentType;
|
||||||
|
|
||||||
public Visitor(BinaryRunner r, IProgressMonitor monitor) {
|
public Visitor(IProgressMonitor monitor) {
|
||||||
vRunner = r;
|
|
||||||
vMonitor = 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()) {
|
if (vMonitor.isCanceled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (cproject.isOnOutputEntry(res)) {
|
vMonitor.worked(1);
|
||||||
if (res instanceof IFile) {
|
|
||||||
if (vRunner != null) {
|
// Attempt to speed things up by rejecting up front
|
||||||
vRunner.addChildIfBinary((IFile) res);
|
// 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;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
// 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 true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOnOutputEntry(IOutputEntry entry, IPath path) {
|
||||||
|
if (entry.getPath().isPrefixOf(path) && !CoreModelUtil.isExcluded(path, entry.fullExclusionPatternChars())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -102,10 +102,8 @@ public class ContentTypeProcessor {
|
||||||
for (int i = 0; i < members.length; ++i) {
|
for (int i = 0; i < members.length; ++i) {
|
||||||
if (members[i] instanceof IFile) {
|
if (members[i] instanceof IFile) {
|
||||||
IFile file = (IFile) members[i];
|
IFile file = (IFile) members[i];
|
||||||
//if (contentType.isAssociatedWith(file.getName(), context)) {
|
|
||||||
IContentType cType = CCorePlugin.getContentType(file.getProject(), file.getName());
|
IContentType cType = CCorePlugin.getContentType(file.getProject(), file.getName());
|
||||||
if (cType != null && cType.equals(contentType)) {
|
if (cType != null && cType.equals(contentType)) {
|
||||||
// if (CoreModel.isValidTranslationUnitName(file.getProject(), file.getName())) {
|
|
||||||
ICElement newElement = CoreModel.getDefault().create(file);
|
ICElement newElement = CoreModel.getDefault().create(file);
|
||||||
if (newElement != null) {
|
if (newElement != null) {
|
||||||
elementAdded(newElement, celement);
|
elementAdded(newElement, celement);
|
||||||
|
|
Loading…
Add table
Reference in a new issue