mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Include Browser: Incorporating changes to index (IndexFileLocation)
This commit is contained in:
parent
6155014aab
commit
9840f921ae
6 changed files with 89 additions and 35 deletions
|
@ -17,6 +17,8 @@ import org.eclipse.core.resources.IResource;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
|
@ -175,5 +177,39 @@ public class CModelUtil {
|
|||
return tu;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translation unit for the location given or <code>null</code>.
|
||||
* @throws CModelException
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnitForLocation(IIndexFileLocation ifl, ICProject preferredProject) throws CModelException {
|
||||
String fullPath= ifl.getFullPath();
|
||||
if (fullPath != null) {
|
||||
IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath);
|
||||
if (file instanceof IFile) {
|
||||
return findTranslationUnit((IFile) file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||
if (location != null) {
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ITranslationUnit tu= null;
|
||||
if (preferredProject != null) {
|
||||
tu= coreModel.createTranslationUnitFrom(preferredProject, location);
|
||||
}
|
||||
if (tu == null) {
|
||||
ICProject[] projects= coreModel.getCModel().getCProjects();
|
||||
for (int i = 0; i < projects.length && tu == null; i++) {
|
||||
ICProject project = projects[i];
|
||||
if (!project.equals(preferredProject)) {
|
||||
tu= coreModel.createTranslationUnitFrom(project, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tu;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,15 +105,21 @@ public class IBContentProvider extends AsyncTreeContentProvider {
|
|||
for (int i = 0; i < includes.length; i++) {
|
||||
IIndexInclude include = includes[i];
|
||||
try {
|
||||
IPath includesPath = IndexLocationFactory.getAbsolutePath(include.getIncludesLocation());
|
||||
IIndexFileLocation includesPath= include.getIncludesLocation();
|
||||
if (fComputeIncludedBy) {
|
||||
directiveFile= targetFile= new IBFile(tu.getCProject(), IndexLocationFactory.getAbsolutePath(include.getIncludesLocation()));
|
||||
directiveFile= targetFile= new IBFile(tu.getCProject(), include.getIncludedByLocation());
|
||||
}
|
||||
else {
|
||||
targetFile= new IBFile(tu.getCProject(), includesPath);
|
||||
}
|
||||
IPath fullPath= IndexLocationFactory.getPath(includesPath);
|
||||
String name= "???"; //$NON-NLS-1$
|
||||
if (fullPath != null && fullPath.segmentCount() > 0) {
|
||||
name= fullPath.lastSegment();
|
||||
}
|
||||
|
||||
IBNode newnode= new IBNode(node, targetFile, directiveFile,
|
||||
includesPath.lastSegment(), include.getNameOffset(),
|
||||
name, include.getNameOffset(),
|
||||
include.getNameLength(),
|
||||
include.getIncludedBy().getTimestamp());
|
||||
newnode.setIsActiveCode(true);
|
||||
|
|
|
@ -21,6 +21,9 @@ import org.eclipse.jface.viewers.TreeViewer;
|
|||
import org.eclipse.swt.dnd.*;
|
||||
import org.eclipse.ui.part.ResourceTransfer;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
|
||||
public class IBDragSourceListener implements DragSourceListener {
|
||||
|
||||
private TreeViewer fTreeViewer;
|
||||
|
@ -65,9 +68,9 @@ public class IBDragSourceListener implements DragSourceListener {
|
|||
ArrayList files= new ArrayList(fSelectedNodes.size());
|
||||
for (Iterator iter = fSelectedNodes.iterator(); iter.hasNext();) {
|
||||
IBNode node = (IBNode) iter.next();
|
||||
IFile file= (IFile) node.getAdapter(IFile.class);
|
||||
if (file != null) {
|
||||
IPath location= file.getLocation();
|
||||
IIndexFileLocation ifl= (IIndexFileLocation) node.getAdapter(IIndexFileLocation.class);
|
||||
if (ifl != null) {
|
||||
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||
if (location != null) {
|
||||
files.add(location.toOSString());
|
||||
}
|
||||
|
|
|
@ -13,8 +13,10 @@ package org.eclipse.cdt.internal.ui.includebrowser;
|
|||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
@ -24,26 +26,20 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
|||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||
|
||||
public class IBFile {
|
||||
public IPath fLocation;
|
||||
public IIndexFileLocation fLocation;
|
||||
public ITranslationUnit fTU= null;
|
||||
|
||||
public IBFile(ITranslationUnit tu) {
|
||||
fTU= tu;
|
||||
IResource r= fTU.getResource();
|
||||
if (r != null) {
|
||||
fLocation= r.getLocation();
|
||||
}
|
||||
else {
|
||||
fLocation= fTU.getPath();
|
||||
}
|
||||
fLocation= IndexLocationFactory.getIFL(tu);
|
||||
}
|
||||
|
||||
public IBFile(ICProject preferredProject, IPath location) throws CModelException {
|
||||
public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException {
|
||||
fLocation= location;
|
||||
fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||
}
|
||||
|
||||
public IPath getLocation() {
|
||||
public IIndexFileLocation getLocation() {
|
||||
return fLocation;
|
||||
}
|
||||
|
||||
|
@ -65,10 +61,13 @@ public class IBFile {
|
|||
}
|
||||
|
||||
public IFile getResource() {
|
||||
if (fTU != null) {
|
||||
IResource r= fTU.getResource();
|
||||
if (r instanceof IFile) {
|
||||
return (IFile) r;
|
||||
if (fLocation != null) {
|
||||
String fullPath= fLocation.getFullPath();
|
||||
if (fullPath != null) {
|
||||
IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath);
|
||||
if (file instanceof IFile) {
|
||||
return (IFile) file;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||
|
@ -63,9 +65,9 @@ public class IBNode implements IAdaptable {
|
|||
hashCode+= fDirectiveName.hashCode();
|
||||
}
|
||||
else if (fRepresentedFile != null) {
|
||||
IPath path= fRepresentedFile.getLocation();
|
||||
if (path != null) {
|
||||
hashCode+= path.hashCode();
|
||||
IIndexFileLocation ifl= fRepresentedFile.getLocation();
|
||||
if (ifl != null) {
|
||||
hashCode+= ifl.hashCode();
|
||||
}
|
||||
}
|
||||
return hashCode;
|
||||
|
@ -89,14 +91,14 @@ public class IBNode implements IAdaptable {
|
|||
CoreUtility.safeEquals(fDirectiveName, rhs.fDirectiveName));
|
||||
}
|
||||
|
||||
private boolean computeIsRecursive(IBNode parent, IPath path) {
|
||||
if (parent == null || path == null) {
|
||||
private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) {
|
||||
if (parent == null || ifl == null) {
|
||||
return false;
|
||||
}
|
||||
if (path.equals(parent.getRepresentedFile().getLocation())) {
|
||||
if (ifl.equals(parent.getRepresentedFile().getLocation())) {
|
||||
return true;
|
||||
}
|
||||
return computeIsRecursive(parent.fParent, path);
|
||||
return computeIsRecursive(parent.fParent, ifl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,6 +173,9 @@ public class IBNode implements IAdaptable {
|
|||
if (adapter.isAssignableFrom(IFile.class)) {
|
||||
return fRepresentedFile.getResource();
|
||||
}
|
||||
if (adapter.isAssignableFrom(IIndexFileLocation.class)) {
|
||||
return fRepresentedFile.getLocation();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -183,11 +188,11 @@ public class IBNode implements IAdaptable {
|
|||
if (fRepresentedFile == null) {
|
||||
return null;
|
||||
}
|
||||
IFile file= fRepresentedFile.getResource();
|
||||
if (file != null) {
|
||||
return file.getFullPath();
|
||||
IIndexFileLocation ifl= fRepresentedFile.getLocation();
|
||||
if (ifl != null) {
|
||||
return IndexLocationFactory.getPath(ifl);
|
||||
}
|
||||
return fRepresentedFile.getLocation();
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
|
|
|
@ -69,6 +69,8 @@ import org.eclipse.ui.part.ShowInContext;
|
|||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
@ -684,9 +686,12 @@ public class IBViewPart extends ViewPart
|
|||
EditorOpener.open(page, f, region, timestamp);
|
||||
}
|
||||
else {
|
||||
IPath location= ibf.getLocation();
|
||||
if (location != null) {
|
||||
EditorOpener.openExternalFile(page, location, region, timestamp);
|
||||
IIndexFileLocation ifl = ibf.getLocation();
|
||||
if (ifl != null) {
|
||||
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||
if (location != null) {
|
||||
EditorOpener.openExternalFile(page, location, region, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue