1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Allow Include Browser to work accross projects.

This commit is contained in:
Markus Schorn 2006-07-05 08:35:08 +00:00
parent 9cb27b5066
commit 8ea9103fcf
2 changed files with 53 additions and 23 deletions

View file

@ -101,11 +101,16 @@ public class IBContentProvider extends AsyncTreeContentProvider {
catch (CoreException e) { catch (CoreException e) {
CUIPlugin.getDefault().log(e.getStatus()); CUIPlugin.getDefault().log(e.getStatus());
} }
catch (InterruptedException e) {
CUIPlugin.getDefault().log(e);
}
} }
} }
return NO_CHILDREN; return NO_CHILDREN;
} }
public void setComputeIncludedBy(boolean value) { public void setComputeIncludedBy(boolean value) {
fComputeIncludedBy = value; fComputeIncludedBy = value;
} }

View file

@ -12,6 +12,11 @@
package org.eclipse.cdt.internal.ui.missingapi; package org.eclipse.cdt.internal.ui.missingapi;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -20,6 +25,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
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.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -29,7 +35,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude; import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
public class CIndexQueries { public class CIndexQueries {
public static class IPDOMInclude { public static class IPDOMInclude {
private PDOMInclude fInclude; private PDOMInclude fInclude;
public IPDOMInclude(PDOMInclude include) { public IPDOMInclude(PDOMInclude include) {
@ -75,27 +81,40 @@ public class CIndexQueries {
return null; return null;
} }
private CIndexQueries() {
}
public IPDOMInclude[] findIncludedBy(ITranslationUnit tu, IProgressMonitor pm) throws CoreException { public IPDOMInclude[] findIncludedBy(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
HashMap result= new HashMap();
LinkedList projects= new LinkedList(Arrays.asList(CoreModel.getDefault().getCModel().getCProjects()));
ICProject cproject= tu.getCProject(); ICProject cproject= tu.getCProject();
if (cproject != null) { if (cproject != null) {
projects.remove(cproject);
projects.addFirst(cproject);
}
for (Iterator iter = projects.iterator(); iter.hasNext();) {
cproject = (ICProject) iter.next();
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(cproject); PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(cproject);
if (pdom != null) { if (pdom != null) {
PDOMFile fileTarget= pdom.getFile(locationForTU(tu)); pdom.acquireReadLock();
if (fileTarget != null) { try {
ArrayList result= new ArrayList(); PDOMFile fileTarget= pdom.getFile(locationForTU(tu));
PDOMInclude include= fileTarget.getFirstIncludedBy(); if (fileTarget != null) {
while (include != null) { PDOMInclude include= fileTarget.getFirstIncludedBy();
result.add(new IPDOMInclude(include)); while (include != null) {
include= include.getNextInIncludedBy(); PDOMFile file= include.getIncludedBy();
String path= file.getFileName().getString();
result.put(path, new IPDOMInclude(include));
include= include.getNextInIncludedBy();
}
} }
return (IPDOMInclude[]) result.toArray(new IPDOMInclude[result.size()]); }
finally {
pdom.releaseReadLock();
} }
} }
} }
return EMPTY_INCLUDES; Collection includes= result.values();
return (IPDOMInclude[]) includes.toArray(new IPDOMInclude[includes.size()]);
} }
private IPath locationForTU(ITranslationUnit tu) { private IPath locationForTU(ITranslationUnit tu) {
@ -106,20 +125,26 @@ public class CIndexQueries {
return tu.getPath(); return tu.getPath();
} }
public IPDOMInclude[] findIncludesTo(ITranslationUnit tu, IProgressMonitor pm) throws CoreException { public IPDOMInclude[] findIncludesTo(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
ICProject cproject= tu.getCProject(); ICProject cproject= tu.getCProject();
if (cproject != null) { if (cproject != null) {
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(cproject); PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(cproject);
if (pdom != null) { if (pdom != null) {
PDOMFile fileTarget= pdom.getFile(locationForTU(tu)); pdom.acquireReadLock();
if (fileTarget != null) { try {
ArrayList result= new ArrayList(); PDOMFile fileTarget= pdom.getFile(locationForTU(tu));
PDOMInclude include= fileTarget.getFirstInclude(); if (fileTarget != null) {
while (include != null) { ArrayList result= new ArrayList();
result.add(new IPDOMInclude(include)); PDOMInclude include= fileTarget.getFirstInclude();
include= include.getNextInIncludes(); while (include != null) {
result.add(new IPDOMInclude(include));
include= include.getNextInIncludes();
}
return (IPDOMInclude[]) result.toArray(new IPDOMInclude[result.size()]);
} }
return (IPDOMInclude[]) result.toArray(new IPDOMInclude[result.size()]); }
finally {
pdom.releaseReadLock();
} }
} }
} }