1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Implementation of the IOutputEntry

This commit is contained in:
Alain Magloire 2004-03-22 03:20:50 +00:00
parent 90ef8946ae
commit b8a6e4e9f5
9 changed files with 186 additions and 133 deletions

View file

@ -672,6 +672,7 @@ public class CoreModel implements ICDescriptorListener {
* @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent)
*/
public void descriptorChanged(CDescriptorEvent event) {
pathEntryManager.descriptorChanged(event);
manager.descriptorChanged(event);
}

View file

@ -9,74 +9,45 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IOutputEntry;
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.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
public class BinaryRunner {
IProject project;
ICProject cproject;
Thread runner;
ArchiveContainer vlib;
BinaryContainer vbin;
public BinaryRunner(IProject prj) {
project = prj;
cproject = CModelManager.getDefault().create(project);
}
public void start() {
runner = new Thread(new Runnable() {
public void run() {
ICProject cproject = CModelManager.getDefault().create(project);
if (cproject == null || Thread.currentThread().isInterrupted()) {
return;
}
IOutputEntry[] outs = null;
try {
outs = cproject.getOutputEntries();
} catch (CModelException e) {
outs = new IOutputEntry[0];
}
vbin = (BinaryContainer)cproject.getBinaryContainer();
vlib = (ArchiveContainer)cproject.getArchiveContainer();
vlib.removeChildren();
vbin.removeChildren();
IPath projectPath = project.getFullPath();
for (int i = 0; i < outs.length; i++) {
IPath path = outs[i].getPath();
if (projectPath.equals(path)) {
try {
project.accept(new Visitor(BinaryRunner.this));
} catch (CoreException e) {
//e.printStackTrace();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
}
break; // We are done.
} else if (projectPath.isPrefixOf(path)) {
path = path.removeFirstSegments(projectPath.segmentCount());
IResource res =project.findMember(path);
if (res != null) {
try {
res.accept(new Visitor(BinaryRunner.this));
} catch (CoreException e) {
//e.printStackTrace();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
}
}
}
try {
project.accept(new Visitor(BinaryRunner.this));
} catch (CoreException e) {
//e.printStackTrace();
} catch (Exception e) {
// What is wrong ?
e.printStackTrace();
}
if (!Thread.currentThread().isInterrupted()) {
fireEvents(cproject, vbin);
@ -165,6 +136,9 @@ public class BinaryRunner {
if (Thread.currentThread().isInterrupted()) {
return false;
}
if (!cproject.isOnOutputEntry(res)) {
return false;
}
if (res instanceof IFile) {
runner.addChildIfBinary((IFile)res);
return false;

View file

@ -189,7 +189,6 @@ public class CContainer extends Openable implements ICContainer {
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
ArrayList vChildren = new ArrayList();
ArrayList notChildren = new ArrayList();
try {
IResource[] resources = null;
if (res instanceof IContainer) {
@ -202,39 +201,9 @@ public class CContainer extends Openable implements ICContainer {
ICProject cproject = getCProject();
for (int i = 0; i < resources.length; i++) {
// Check for Valid C Element only.
ICElement celement = null;
switch (resources[i].getType()) {
case IResource.FILE :
{
IFile file = (IFile) resources[i];
if (factory.isTranslationUnit(file)) {
celement = new TranslationUnit(this, file);
} else if (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();
vlib.addChild(celement);
} else {
celement = new Binary(this, file, (IBinaryObject)bin);
if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
vbin.addChild(celement);
}
}
}
}
break;
}
case IResource.FOLDER :
celement = new CContainer(this, (IFolder) resources[i]);
break;
}
ICElement celement = computeChild(resources[i], cproject);
if (celement != null) {
vChildren.add(celement);
} else {
notChildren.add(resources[i]);
}
}
}
@ -247,8 +216,42 @@ public class CContainer extends Openable implements ICContainer {
ICElement[] children = new ICElement[vChildren.size()];
vChildren.toArray(children);
info.setChildren(children);
((CContainerInfo) getElementInfo()).setNonCResources(notChildren.toArray());
if (info instanceof CContainerInfo) {
((CContainerInfo) info).setNonCResources(null);
}
return true;
}
protected ICElement computeChild(IResource resource, ICProject cproject) {
ICElement celement = null;
switch (resource.getType()) {
case IResource.FILE :
{
IFile file = (IFile) resource;
if (factory.isTranslationUnit(file)) {
celement = new TranslationUnit(this, file);
} else if (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();
vlib.addChild(celement);
} else {
celement = new Binary(this, file, (IBinaryObject)bin);
if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
vbin.addChild(celement);
}
}
}
}
break;
}
case IResource.FOLDER :
celement = new CContainer(this, (IFolder) resource);
break;
}
return celement;
}
}

View file

@ -13,9 +13,12 @@ package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.core.resources.IContainer;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/**
*/
@ -40,6 +43,7 @@ public class CContainerInfo extends OpenableInfo {
ArrayList notChildren = new ArrayList();
ICElement parent = getElement();
ICProject cproject = parent.getCProject();
try {
IResource[] resources = null;
if (res instanceof IContainer) {
@ -47,16 +51,34 @@ public class CContainerInfo extends OpenableInfo {
resources = container.members(false);
}
IPathEntry[] entries = cproject.getResolvedPathEntries();
if (resources != null) {
CModelManager factory = CModelManager.getDefault();
ICElement[] children = getChildren();
for (int i = 0; i < resources.length; i++) {
boolean found = false;
for (int j = 0; j < children.length; j++) {
IResource r = children[j].getResource();
if (r != null && r.equals(resources[i])){
found = true;
break;
// Check if the folder is not itself a sourceEntry.
if (resources[i].getType() == IResource.FOLDER) {
IPath fullPath = resources[i].getFullPath();
for (int k = 0; k < entries.length; k++) {
IPathEntry entry = entries[k];
if (entry.getEntryKind() == IPathEntry.CDT_SOURCE) {
IPath sourcePath = entry.getPath();
if (fullPath.equals(sourcePath)) {
found = true;
break;
}
}
}
}
// Check the children for a match
if (!found) {
for (int j = 0; j < children.length; j++) {
IResource r = children[j].getResource();
if (r != null && r.equals(resources[i])){
found = true;
break;
}
}
}
if (!found) {

View file

@ -248,13 +248,14 @@ 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];
IPath rootPath = root.getPath();
if (root.isOnSourceEntry(file)) {
IPath rootPath = root.getPath();
IPath resourcePath = file.getFullPath();
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount());
String fileName = path.lastSegment();
@ -282,23 +283,25 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
}
}
checkIfBinary = true;
}
break;
}
}
// try in the outputEntry
if (celement == null && cproject.isOnOutputEntry(file)) {
// try in the outputEntry and save in the container
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);
ICElement archive = new Archive(vlib, file, (IBinaryArchive)bin);
vlib.addChild(archive);
} else {
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
celement = new Binary(vbin, file, (IBinaryObject)bin);
IBinary binary = new Binary(vbin, file, (IBinaryObject)bin);
if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
vbin.addChild(celement);
vbin.addChild(binary);
}
}
}

View file

@ -13,8 +13,6 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@ -59,57 +57,19 @@ public class DeltaProcessor {
}
CModelManager manager = CModelManager.getDefault();
ICElement celement = manager.create(resource, null);
if (celement == null) {
// Probably it was deleted, find it
IResource resParent = resource.getParent();
ICElement parent = null;
// the sourceRoot == Project
if (resParent instanceof IProject) {
ICProject cpj = manager.create((IProject)resParent);
if (cpj != null) {
try {
ISourceRoot[] roots = cpj.getAllSourceRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].isOnSourceEntry(resource)) {
parent = roots[i];
break;
}
}
} catch (CModelException e) {
//
}
}
}
if (parent == null) {
parent = manager.create(resParent, null);
}
if (parent instanceof IParent) {
ICElement[] children;
if (manager.peekAtInfo(parent) != null ) {
children = ((CElement)parent).getElementInfo().getChildren();
for (int i = 0; i < children.length; i++) {
IResource res = children[i].getResource();
if (res != null && res.equals(resource)) {
celement = children[i];
break;
}
}
}
}
}
// BUG 36424:
// The Binary may only be visible in the BinaryContainers
if (celement == null) {
ICElement[] children;
ICProject cproj = manager.create(resource.getProject());
if (cproj != null && manager.peekAtInfo(cproj) != null) {
if (cproj != null && cproj.isOpen()) {
IBinaryContainer bin = cproj.getBinaryContainer();
if (manager.peekAtInfo(bin) != null) {
if (bin.isOpen()) {
children = ((CElement)bin).getElementInfo().getChildren();
for (int i = 0; i < children.length; i++) {
IResource res = children[i].getResource();
if (res != null && res.equals(resource)) {
if (resource.equals(res)) {
celement = children[i];
break;
}
@ -122,13 +82,13 @@ public class DeltaProcessor {
if (celement == null) {
ICElement[] children;
ICProject cproj = manager.create(resource.getProject());
if (cproj != null && manager.peekAtInfo(cproj) != null) {
if (cproj != null && cproj.isOpen()) {
IArchiveContainer ar = cproj.getArchiveContainer();
if (manager.peekAtInfo(ar) != null) {
if (ar.isOpen()) {
children = ((CElement)ar).getElementInfo().getChildren();
for (int i = 0; i < children.length; i++) {
IResource res = children[i].getResource();
if (res != null && res.equals(resource)) {
if (resource.equals(res)) {
celement = children[i];
break;
}

View file

@ -301,4 +301,25 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo()
*/
protected CElementInfo createElementInfo() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {
if (o instanceof Openable) {
IResource otherRes = ((Openable)o).getResource();
IResource res = this.getResource();
if (otherRes != null && res != null) {
return otherRes.equals(res);
}
}
return super.equals(o);
}
}

View file

@ -16,7 +16,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CDescriptorEvent;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICDescriptorListener;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
@ -55,7 +57,7 @@ import org.w3c.dom.NodeList;
* @author alain
*
*/
public class PathEntryManager {
public class PathEntryManager implements ICDescriptorListener {
static String CONTAINER_INITIALIZER_EXTPOINT_ID = "pathEntryContainerInitializer"; //$NON-NLS-1$
static String PATH_ENTRY = "pathentry"; //$NON-NLS-1$
static String PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$
@ -717,4 +719,29 @@ public class PathEntryManager {
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent)
*/
public void descriptorChanged(CDescriptorEvent event) {
int flags = event.getFlags();
if ((flags & CDescriptorEvent.EXTENSION_CHANGED) != 0) {
ICDescriptor cdesc = event.getDescriptor();
if (cdesc != null) {
CModelManager manager = CModelManager.getDefault();
ICProject cproject = manager.create(cdesc.getProject());
try {
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);
resolvedMap.remove(cproject);
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
for (int i = 0; i < deltas.length; i++) {
manager.registerCModelDelta(deltas[i]);
}
manager.fire(ElementChangedEvent.POST_CHANGE);
} catch (CModelException e) {
}
}
}
}
}

View file

@ -11,11 +11,16 @@
package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/**
@ -32,14 +37,51 @@ public class SourceRoot extends CContainer implements ISourceRoot {
public SourceRoot(ICElement parent, IResource res, ISourceEntry entry) {
super(parent, res);
sourceEntry = entry;
IPath path = getPath();
IPath cpath = getParent().getPath();
IPath p = path.removeFirstSegments(cpath.segmentCount());
setElementName(p.toString());
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CContainer#computeChildren(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.resources.IResource)
*/
protected boolean computeChildren(OpenableInfo info, IResource res)
throws CModelException {
return super.computeChildren(info, res);
protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException {
ArrayList vChildren = new ArrayList();
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();
for (int i = 0; i < resources.length; i++) {
// Check for Valid C Element only.
ICElement celement = null;
if (isOnSourceEntry(resources[i].getFullPath())) {
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);
}
ICElement[] children = new ICElement[vChildren.size()];
vChildren.toArray(children);
info.setChildren(children);
if (info instanceof CContainerInfo) {
((CContainerInfo) info).setNonCResources(null);
}
return true;
}
public ISourceEntry getSourceEntry() {