mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-19 15:05:36 +02:00
Accommodate archive files in Default Binary File Editor
This commit is contained in:
parent
0a8734fb12
commit
d4c444eaeb
4 changed files with 31 additions and 22 deletions
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -88,7 +89,7 @@ public class Archive extends Openable implements IArchive {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -214,7 +215,7 @@ public class Binary extends Openable implements IBinary {
|
|||
|
||||
@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);
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -19,6 +20,7 @@ import java.io.IOException;
|
|||
|
||||
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;
|
||||
|
@ -60,7 +62,7 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -68,7 +70,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
|||
*
|
||||
* @param binary
|
||||
*/
|
||||
public BinaryFileEditorInput(IBinary binary) {
|
||||
public BinaryFileEditorInput(ICElement binary) {
|
||||
fBinary = binary;
|
||||
}
|
||||
|
||||
|
@ -120,11 +122,11 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
|||
@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
|
||||
|
@ -139,7 +141,7 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
|||
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);
|
||||
}
|
||||
|
@ -172,8 +174,8 @@ public class DefaultBinaryFileEditor extends AbstractTextEditor implements IReso
|
|||
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);
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -36,6 +37,7 @@ import org.eclipse.cdt.core.model.IBuffer;
|
|||
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;
|
||||
|
@ -751,16 +753,19 @@ public class EditorUtility {
|
|||
new String[] { modifierString, newModifierString });
|
||||
}
|
||||
|
||||
public static IStorage getStorage(IBinary bin) {
|
||||
public static IStorage getStorage(ICElement element) {
|
||||
IStorage store = null;
|
||||
if (element instanceof IOpenable openable) {
|
||||
try {
|
||||
IBuffer buffer = bin.getBuffer();
|
||||
IBuffer buffer = openable.getBuffer();
|
||||
if (buffer != null) {
|
||||
store = new FileStorage(new ByteArrayInputStream(buffer.getContents().getBytes()), bin.getPath());
|
||||
store = new FileStorage(new ByteArrayInputStream(buffer.getContents().getBytes()),
|
||||
element.getPath());
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
// nothing;
|
||||
}
|
||||
}
|
||||
return store;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue