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.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.IPath;
|
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.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
|
@ -175,5 +177,39 @@ public class CModelUtil {
|
||||||
return tu;
|
return tu;
|
||||||
}
|
}
|
||||||
return null;
|
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++) {
|
for (int i = 0; i < includes.length; i++) {
|
||||||
IIndexInclude include = includes[i];
|
IIndexInclude include = includes[i];
|
||||||
try {
|
try {
|
||||||
IPath includesPath = IndexLocationFactory.getAbsolutePath(include.getIncludesLocation());
|
IIndexFileLocation includesPath= include.getIncludesLocation();
|
||||||
if (fComputeIncludedBy) {
|
if (fComputeIncludedBy) {
|
||||||
directiveFile= targetFile= new IBFile(tu.getCProject(), IndexLocationFactory.getAbsolutePath(include.getIncludesLocation()));
|
directiveFile= targetFile= new IBFile(tu.getCProject(), include.getIncludedByLocation());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
targetFile= new IBFile(tu.getCProject(), includesPath);
|
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,
|
IBNode newnode= new IBNode(node, targetFile, directiveFile,
|
||||||
includesPath.lastSegment(), include.getNameOffset(),
|
name, include.getNameOffset(),
|
||||||
include.getNameLength(),
|
include.getNameLength(),
|
||||||
include.getIncludedBy().getTimestamp());
|
include.getIncludedBy().getTimestamp());
|
||||||
newnode.setIsActiveCode(true);
|
newnode.setIsActiveCode(true);
|
||||||
|
|
|
@ -21,6 +21,9 @@ import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.swt.dnd.*;
|
import org.eclipse.swt.dnd.*;
|
||||||
import org.eclipse.ui.part.ResourceTransfer;
|
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 {
|
public class IBDragSourceListener implements DragSourceListener {
|
||||||
|
|
||||||
private TreeViewer fTreeViewer;
|
private TreeViewer fTreeViewer;
|
||||||
|
@ -65,9 +68,9 @@ public class IBDragSourceListener implements DragSourceListener {
|
||||||
ArrayList files= new ArrayList(fSelectedNodes.size());
|
ArrayList files= new ArrayList(fSelectedNodes.size());
|
||||||
for (Iterator iter = fSelectedNodes.iterator(); iter.hasNext();) {
|
for (Iterator iter = fSelectedNodes.iterator(); iter.hasNext();) {
|
||||||
IBNode node = (IBNode) iter.next();
|
IBNode node = (IBNode) iter.next();
|
||||||
IFile file= (IFile) node.getAdapter(IFile.class);
|
IIndexFileLocation ifl= (IIndexFileLocation) node.getAdapter(IIndexFileLocation.class);
|
||||||
if (file != null) {
|
if (ifl != null) {
|
||||||
IPath location= file.getLocation();
|
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
files.add(location.toOSString());
|
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.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
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.CModelException;
|
||||||
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;
|
||||||
|
@ -24,26 +26,20 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||||
|
|
||||||
public class IBFile {
|
public class IBFile {
|
||||||
public IPath fLocation;
|
public IIndexFileLocation fLocation;
|
||||||
public ITranslationUnit fTU= null;
|
public ITranslationUnit fTU= null;
|
||||||
|
|
||||||
public IBFile(ITranslationUnit tu) {
|
public IBFile(ITranslationUnit tu) {
|
||||||
fTU= tu;
|
fTU= tu;
|
||||||
IResource r= fTU.getResource();
|
fLocation= IndexLocationFactory.getIFL(tu);
|
||||||
if (r != null) {
|
|
||||||
fLocation= r.getLocation();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fLocation= fTU.getPath();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBFile(ICProject preferredProject, IPath location) throws CModelException {
|
public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException {
|
||||||
fLocation= location;
|
fLocation= location;
|
||||||
fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPath getLocation() {
|
public IIndexFileLocation getLocation() {
|
||||||
return fLocation;
|
return fLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,10 +61,13 @@ public class IBFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFile getResource() {
|
public IFile getResource() {
|
||||||
if (fTU != null) {
|
if (fLocation != null) {
|
||||||
IResource r= fTU.getResource();
|
String fullPath= fLocation.getFullPath();
|
||||||
if (r instanceof IFile) {
|
if (fullPath != null) {
|
||||||
return (IFile) r;
|
IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath);
|
||||||
|
if (file instanceof IFile) {
|
||||||
|
return (IFile) file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IPath;
|
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.core.model.ITranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||||
|
@ -63,9 +65,9 @@ public class IBNode implements IAdaptable {
|
||||||
hashCode+= fDirectiveName.hashCode();
|
hashCode+= fDirectiveName.hashCode();
|
||||||
}
|
}
|
||||||
else if (fRepresentedFile != null) {
|
else if (fRepresentedFile != null) {
|
||||||
IPath path= fRepresentedFile.getLocation();
|
IIndexFileLocation ifl= fRepresentedFile.getLocation();
|
||||||
if (path != null) {
|
if (ifl != null) {
|
||||||
hashCode+= path.hashCode();
|
hashCode+= ifl.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hashCode;
|
return hashCode;
|
||||||
|
@ -89,14 +91,14 @@ public class IBNode implements IAdaptable {
|
||||||
CoreUtility.safeEquals(fDirectiveName, rhs.fDirectiveName));
|
CoreUtility.safeEquals(fDirectiveName, rhs.fDirectiveName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean computeIsRecursive(IBNode parent, IPath path) {
|
private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) {
|
||||||
if (parent == null || path == null) {
|
if (parent == null || ifl == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (path.equals(parent.getRepresentedFile().getLocation())) {
|
if (ifl.equals(parent.getRepresentedFile().getLocation())) {
|
||||||
return true;
|
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)) {
|
if (adapter.isAssignableFrom(IFile.class)) {
|
||||||
return fRepresentedFile.getResource();
|
return fRepresentedFile.getResource();
|
||||||
}
|
}
|
||||||
|
if (adapter.isAssignableFrom(IIndexFileLocation.class)) {
|
||||||
|
return fRepresentedFile.getLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -183,11 +188,11 @@ public class IBNode implements IAdaptable {
|
||||||
if (fRepresentedFile == null) {
|
if (fRepresentedFile == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
IFile file= fRepresentedFile.getResource();
|
IIndexFileLocation ifl= fRepresentedFile.getLocation();
|
||||||
if (file != null) {
|
if (ifl != null) {
|
||||||
return file.getFullPath();
|
return IndexLocationFactory.getPath(ifl);
|
||||||
}
|
}
|
||||||
return fRepresentedFile.getLocation();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimestamp() {
|
public long getTimestamp() {
|
||||||
|
|
|
@ -69,6 +69,8 @@ import org.eclipse.ui.part.ShowInContext;
|
||||||
import org.eclipse.ui.part.ViewPart;
|
import org.eclipse.ui.part.ViewPart;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
@ -684,9 +686,12 @@ public class IBViewPart extends ViewPart
|
||||||
EditorOpener.open(page, f, region, timestamp);
|
EditorOpener.open(page, f, region, timestamp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IPath location= ibf.getLocation();
|
IIndexFileLocation ifl = ibf.getLocation();
|
||||||
if (location != null) {
|
if (ifl != null) {
|
||||||
EditorOpener.openExternalFile(page, location, region, timestamp);
|
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||||
|
if (location != null) {
|
||||||
|
EditorOpener.openExternalFile(page, location, region, timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue