diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java index feb502bb3b0..907a2d1b3d7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IBinary.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2024 QNX Software Systems and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,9 +11,12 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Markus Schorn (Wind River Systems) + * John Dallaway - Support external binary files (#630) *******************************************************************************/ package org.eclipse.cdt.core.model; +import org.eclipse.core.runtime.IPath; + /** * Represents a Binary file, for example an ELF executable. * An ELF parser will inspect the binary. @@ -57,4 +60,11 @@ public interface IBinary extends ICElement, IParent, IOpenable { public boolean showInBinaryContainer(); //public IAddressFactory getAddressFactory(); + /** + * Returns the absolute path of the location of this binary. May be {@code null}, + * in case the location does not exist. + * @return an absolute path to the location, or {@code null} + * @since 8.4 + */ + public IPath getLocation(); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java index e47f3c52d5c..b50054750f3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java @@ -28,6 +28,7 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.util.MementoTokenizer; +import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; @@ -94,12 +95,12 @@ public boolean computeChildren(OpenableInfo info, IResource res) { } IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(objPath); if (file == null) { // if object path is external to the workspace - // fallback to legacy behaviour - // TODO: support external paths in Binary class as we do in TranslationUnit - objPath = ar.getPath().append(objPath.lastSegment()); + Binary binary = new Binary(this, URIUtil.toURI(objPath), obj); + info.addChild(binary); + } else { + Binary binary = new Binary(this, objPath, obj); + info.addChild(binary); } - Binary binary = new Binary(this, objPath, obj); - info.addChild(binary); } return true; } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java index 934357178e4..4512034abd6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java @@ -14,6 +14,7 @@ * Anton Leherbauer (Wind River Systems) * John Dallaway - Adapt for IBinaryFile (#413) * John Dallaway - Support source file lookup from relative path (#652) + * John Dallaway - Add initial support for external paths (#630) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -21,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.net.URI; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -43,10 +45,15 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.resources.ResourceLookup; import org.eclipse.cdt.internal.core.util.MementoTokenizer; +import org.eclipse.cdt.utils.UNCPathConverter; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileInfo; +import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; @@ -66,6 +73,7 @@ public class Binary extends Openable implements IBinary { private long fLastModification; + private URI location; private IBinaryObject binaryObject; private boolean showInBinaryContainer; @@ -75,6 +83,13 @@ public Binary(ICElement parent, IFile file, IBinaryObject bin) { showInBinaryContainer = determineShowInBinaryContainer(bin); } + public Binary(ICElement parent, URI uri, IBinaryObject bin) { + super(parent, (IResource) null, uri.toString(), ICElement.C_BINARY); + location = uri; + binaryObject = bin; + showInBinaryContainer = determineShowInBinaryContainer(bin); + } + private boolean determineShowInBinaryContainer(IBinaryObject bin) { BinaryFilePresentation presentation = bin.getAdapter(BinaryFilePresentation.class); if (presentation != null) { @@ -284,7 +299,7 @@ boolean computeChildren(OpenableInfo info, IResource res) throws CModelException // information. If not, fall back on information from the binary parser. boolean showSourceFiles = Platform.getPreferencesService().getBoolean(CCorePlugin.PLUGIN_ID, CCorePreferenceConstants.SHOW_SOURCE_FILES_IN_BINARIES, false, null); - if (!showSourceFiles || !addSourceFiles(info, res, obj, hash)) { + if (!showSourceFiles || (res == null) || !addSourceFiles(info, res, obj, hash)) { ISymbol[] symbols = obj.getSymbols(); for (ISymbol symbol : symbols) { switch (symbol.getType()) { @@ -528,7 +543,63 @@ public boolean exists() { IResource res = getResource(); if (res != null) return res.exists(); - return super.exists(); + if (location != null) { + try { + IFileStore fileStore = EFS.getStore(location); + IFileInfo info = fileStore.fetchInfo(); + return info.exists(); + } catch (CoreException e) { + CCorePlugin.log(e); + } + + } + return false; + } + + @Override + public IPath getLocation() { + if (location == null) { + IFile file = getFile(); + if (file != null) { + return file.getLocation(); + } else { + return null; + } + } + return UNCPathConverter.toPath(location); + } + + @Override + public URI getLocationURI() { + if (location == null) { + IFile file = getFile(); + if (file != null) { + location = file.getLocationURI(); + } else { + return null; + } + } + return location; + } + + @Override + public IPath getPath() { + if (getFile() != null) { + return super.getPath(); + } + IPath path = getLocation(); + if (path != null) { + return path; + } + return super.getPath(); + } + + public IFile getFile() { + IResource res = super.getResource(); + if (res instanceof IFile) { + return (IFile) res; + } + return null; } @Override diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 2e208202e37..0bec04bd47e 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2003, 2023 IBM Corporation, QNX Software Systems, and others. +# Copyright (c) 2003, 2024 IBM Corporation, QNX Software Systems, and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -656,6 +656,8 @@ ShiftRightAction.label= &Shift Right ShiftLeftAction.label= S&hift Left # Decorators +binaryFileDecorator.label = C/C++ Binary Files +binaryFileDecorator.description = Decorates C/C++ executable, object, core and shared library files. indexedFilesDecorator.label = C/C++ Indexed Files indexedFilesDecorator.description = Decorates files indexed by C/C++ Indexer. translationUnitDecorator.label = C/C++ Translation Units diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index dbd37475e31..383e2203cc0 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4445,6 +4445,17 @@ + + %binaryFileDecorator.description + + + +