Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accommodate archive files in Default Binary File Editor #414

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2011 QNX Software Systems and others.
* Copyright (c) 2000, 2023 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,6 +11,7 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
* John Dallaway - Adapt for IBinaryFile (#413)
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;

Expand Down Expand Up @@ -88,7 +89,7 @@ public boolean computeChildren(OpenableInfo info, IResource res) {

@Override
public <T> T getAdapter(Class<T> adapter) {
if (IBinaryArchive.class.equals(adapter)) {
if (adapter.isAssignableFrom(IBinaryArchive.class)) {
return adapter.cast(getBinaryArchive());
}
return super.getAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 QNX Software Systems and others.
* Copyright (c) 2000, 2023 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,6 +12,7 @@
* QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
* John Dallaway - Adapt for IBinaryFile (#413)
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;

Expand Down Expand Up @@ -214,7 +215,7 @@ protected IBinaryObject getBinaryObject() {

@Override
public <T> T getAdapter(Class<T> adapter) {
if (IBinaryObject.class.equals(adapter)) {
if (adapter.isAssignableFrom(IBinaryObject.class)) {
return adapter.cast(getBinaryObject());
}
return super.getAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2015 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2023 Wind River Systems, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,6 +10,7 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* John Dallaway - support both IArchive and IBinary as input (#413)
*******************************************************************************/

package org.eclipse.cdt.internal.ui.editor;
Expand All @@ -19,6 +20,7 @@

import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.resources.FileStorage;
Expand Down Expand Up @@ -60,15 +62,15 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
* A storage editor input for binary files.
*/
public static class BinaryFileEditorInput extends PlatformObject implements IStorageEditorInput {
private final IBinary fBinary;
private final ICElement fBinary;
private IStorage fStorage;

/**
* Create an editor input from the given binary.
*
* @param binary
*/
public BinaryFileEditorInput(IBinary binary) {
public BinaryFileEditorInput(ICElement binary) {
fBinary = binary;
}

Expand Down Expand Up @@ -120,11 +122,11 @@ public String getToolTipText() {
@Override
public IStorage getStorage() throws CoreException {
if (fStorage == null) {
IBinaryParser.IBinaryObject object = fBinary.getAdapter(IBinaryParser.IBinaryObject.class);
if (object != null) {
IGnuToolFactory factory = object.getBinaryParser().getAdapter(IGnuToolFactory.class);
IBinaryParser.IBinaryFile file = fBinary.getAdapter(IBinaryParser.IBinaryFile.class);
if (file != null) {
IGnuToolFactory factory = file.getBinaryParser().getAdapter(IGnuToolFactory.class);
if (factory != null) {
Objdump objdump = factory.getObjdump(object.getPath());
Objdump objdump = factory.getObjdump(file.getPath());
if (objdump != null) {
try {
// limit editor to X MB, if more - users should use objdump in command
Expand All @@ -139,7 +141,7 @@ public IStorage getStorage() throws CoreException {
System.arraycopy(message.getBytes(), 0, output, limitBytes - message.length(),
message.length());
}
fStorage = new FileStorage(new ByteArrayInputStream(output), object.getPath());
fStorage = new FileStorage(new ByteArrayInputStream(output), file.getPath());
} catch (IOException exc) {
CUIPlugin.log(exc);
}
Expand Down Expand Up @@ -172,8 +174,8 @@ protected IDocument createDocument(Object element) throws CoreException {
IFile file = ResourceUtil.getFile(element);
if (file != null) {
ICElement cElement = CoreModel.getDefault().create(file);
if (cElement instanceof IBinary) {
element = new BinaryFileEditorInput((IBinary) cElement);
if (cElement instanceof IArchive || cElement instanceof IBinary) {
element = new BinaryFileEditorInput(cElement);
}
}
return super.createDocument(element);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 QNX Software Systems and others.
* Copyright (c) 2000, 2023 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@
* Anton Leherbauer (Wind River Systems)
* Ed Swartz (Nokia)
* Alexander Fedorov (ArSysOp) - Bug 561993 - Remove dependency to com.ibm.icu from CDT UI
* John Dallaway - Support both IArchive and IBinary storage requests (#413)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.util;

Expand All @@ -36,6 +37,7 @@
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
Expand Down Expand Up @@ -751,15 +753,18 @@ private static String appendModifierString(String modifierString, int modifier)
new String[] { modifierString, newModifierString });
}

public static IStorage getStorage(IBinary bin) {
public static IStorage getStorage(ICElement element) {
IStorage store = null;
try {
IBuffer buffer = bin.getBuffer();
if (buffer != null) {
store = new FileStorage(new ByteArrayInputStream(buffer.getContents().getBytes()), bin.getPath());
if (element instanceof IOpenable openable) {
try {
IBuffer buffer = openable.getBuffer();
if (buffer != null) {
store = new FileStorage(new ByteArrayInputStream(buffer.getContents().getBytes()),
element.getPath());
}
} catch (CModelException e) {
// nothing;
}
} catch (CModelException e) {
// nothing;
}
return store;
}
Expand Down