Commit 4967c0ee authored by andrei's avatar andrei

SVN somehow managed to delete "de" directory!?!

parent 90b1ae21
/*****************************************************************************************
* Copyright (c) 2004 Andrei Loskutov. All rights reserved. This program and the
* accompanying materials are made available under the terms of the BSD License which
* accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php Contributor: Andrei Loskutov -
* initial API and implementation
****************************************************************************************/
package de.loskutov.bco;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The main plugin class to be used in the desktop.
*/
public class BytecodeOutlinePlugin extends AbstractUIPlugin {
//The shared instance.
private static BytecodeOutlinePlugin plugin;
//Resource bundle.
private ResourceBundle resourceBundle;
public static boolean DEBUG;
/**
* The constructor.
*/
public BytecodeOutlinePlugin() {
super();
if(plugin != null){
throw new IllegalStateException("Bytecode outline plugin is a singleton!");
}
plugin = this;
try {
resourceBundle = ResourceBundle
.getBundle("de.loskutov.bco.BytecodeOutlinePluginResources"); //$NON-NLS-1$
} catch (MissingResourceException x) {
resourceBundle = null;
}
}
/**
* This method is called upon plug-in activation
* @param context
* @throws Exception
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
DEBUG = isDebugging();
}
/**
* This method is called when the plug-in is stopped
* @param context
* @throws Exception
*/
@Override
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
/**
* Returns the shared instance.
* @return plugin
*/
public static BytecodeOutlinePlugin getDefault() {
return plugin;
}
/**
* Returns the string from the plugin's resource bundle, or 'key' if not found.
* @param key
* @return translation
*/
public static String getResourceString(String key) {
ResourceBundle bundle = BytecodeOutlinePlugin.getDefault()
.getResourceBundle();
try {
return (bundle != null)
? bundle.getString(key)
: key;
} catch (MissingResourceException e) {
return key;
}
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
/**
* Returns the workspace instance.
* @return shell object
*/
public static Shell getShell() {
return getDefault().getWorkbench().getActiveWorkbenchWindow()
.getShell();
}
/**
* @param messageID
* @param error
*/
public static void error(String messageID, Throwable error) {
Shell shell = getShell();
String message = getResourceString("BytecodeOutline.Error"); //$NON-NLS-1$
if (messageID != null) {
message = getResourceString(messageID);
}
if (error != null) {
message += " " + error.getMessage();
}
MessageDialog.openError(
shell, getResourceString("BytecodeOutline.Title"), //$NON-NLS-1$
message);
getDefault().getLog().log(
new Status(IStatus.ERROR, "BytecodeOutline", 0, message, error)); //$NON-NLS-1$
}
/**
* @param statusID one of IStatus. constants like IStatus.ERROR etc
* @param error
*/
public static void log(Throwable error, int statusID) {
String message = error.getMessage();
if(message == null){
message = error.toString();
}
getDefault().getLog()
.log(
new Status(
statusID,
"BytecodeOutline", 0, message, error)); //$NON-NLS-1$
}
}
BytecodeOutline.Title=Bytecode Outline
BytecodeOutline.Error=Error (Bytecode Outline)
BytecodeOutlineView.lvt.tooltip=LVT
BytecodeOutlineView.stack.tooltip=STACK
BytecodeOutlineView.lvt.header=Vars
BytecodeOutlineView.stack.header=Stack
BytecodeOutlineView.select_all.label=Select &All@Ctrl+A
BytecodeOutlineView.select_all.tooltip=Select All
BytecodeOutlineView.select_all.description=Select All
BytecodeOutlineView.copy.label=Copy
BytecodeOutlineView.copy.tooltip=Copy
BytecodeOutlineView.copy.description=Copy
BytecodeOutlineView.find_replace.label=&Find...@Ctrl+F
BytecodeOutlineView.find_replace.tooltip=Find in bytecode
BytecodeOutlineView.find_replace.description=Find in bytecode
BytecodeOutlineView.find_replace.image=
BytecodeOutlineView.toggle.vertical.label=&Vertical View Orientation
BytecodeOutlineView.toggle.horizontal.label=&Horizontal View Orientation
BytecodeOutlineView.toggle.automatic.label=&Automatic View Orientation
BytecodeReferenceView.empty.selection.text=<html><head><title>Bytecode reference</title></head><body bgcolor='#D3D3D3'>Please select any bytecode instruction in the bytecode outline view.</body></html>
BCOPreferencePage.description=Bytecode Outline View Settings
BCOPreferencePage.defaultsGroup=Outline
BCOPreferencePage.compareGroup=Compare
BCOPreferencePage.miscGroup=Misc...
BCOPreferencePage.showVariables=Show variables
BCOPreferencePage.showLineInfo=Show line info
BCOPreferencePage.showStackMap=Show stack map
BCOPreferencePage.expandStackMap=Expand stack map
BCOPreferencePage.recalculateStackMap=Recalculate stack map
BCOPreferencePage.showRawBytecode=Show internal types
BCOPreferencePage.showAnalyzer=Show analyzer pane
BCOPreferencePage.showAsmifierCode=Show ASMifier code
BCOPreferencePage.showOnlySelected=Show bytecode for selected element only
BCOPreferencePage.linkViewToEditor=Link Bytecode Outline view to editor
BCOPreferencePage.linkRefViewToEditor=Link Bytecode Reference view to editor
BCOPreferencePage.showHexValues=Show hex values for numeric constants
BCOPreferencePage.diffExpandStackMap=Expand stack map
BCOPreferencePage.diffShowStackMap=Show stack map
BCOPreferencePage.diffShowLineInfo=Show line info
BCOPreferencePage.diffShowVariables=Show variables
BCOPreferencePage.diffShowAsmifierCode=Show ASMifier code
action.showVariables.text=Show local variables
action.showVariables.toolTipText=Show local variables (if available in bytecode)
action.showVariables.image=icons/hide_locals.gif
action.showLineInfo.text=Show line info
action.showLineInfo.toolTipText=Show line info (if available in bytecode)
action.showLineInfo.image=icons/hide_line_info.gif
action.showStackmap.text=Show StackMap
action.showStackmap.toolTipText=Show StackMap info (if available in bytecode)
action.showStackmap.image=icons/stackmap.gif
action.expandStackmap.text=Expand StackMap
action.expandStackmap.toolTipText=Expand StackMap frames (if StackMap is available in bytecode)
action.expandStackmap.image=icons/stackmapexp.gif
action.showASMifierCode.text=Toggle ASMifier mode on/off
action.showASMifierCode.toolTipText=Show ASMified code
action.showASMifierCode.image=icons/asm.gif
action.showAnalyzer.text=Show bytecode analyzer pane
action.showAnalyzer.toolTipText=Show state of the execution stack frames
action.showAnalyzer.image=icons/verify.gif
action.showRawBytecode.text=Show readable bytecode
action.showRawBytecode.toolTipText=Show internal types
action.showRawBytecode.image=icons/raw_mode.gif
action.showOnlySelectedElement.text=Show current element only
action.showOnlySelectedElement.toolTipText=Show bytecode for current field/method only
action.showOnlySelectedElement.image=icons/selected_only.gif
action.linkViewToEditor.text=Link with editor
action.linkViewToEditor.toolTipText=Link With Editor
action.linkViewToEditor.image=icons/link_with_editor.gif
action.linkRefViewToEditor.text=Link with editor
action.linkRefViewToEditor.toolTipText=Link With Editor
action.linkRefViewToEditor.image=icons/link_with_editor.gif
action.showHexValues.text=Show values in hex format
action.showHexValues.toolTipText=Show numerical constant values in hex format
action.showHexValues.image=icons/hex_mode.gif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*******************************************************************************
* Copyright (c) 2011 Andrey Loskutov. All rights reserved. This program and the
* accompanying materials are made available under the terms of the BSD License which
* accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php Contributor: Andrey Loskutov -
* initial API and implementation
*******************************************************************************/
package de.loskutov.bco.asm;
public class DecompiledClassInfo {
/**
* Major.minor or ?
*/
public final String javaVersion;
public final int accessFlags;
public final int major;
public DecompiledClassInfo(String javaVersion, int accessFlags) {
this.javaVersion = javaVersion;
this.accessFlags = accessFlags;
major = javaVersion.startsWith("1.")? Integer.parseInt(javaVersion.substring(2)) : 0;
}
}
This diff is collapsed.
/*******************************************************************************
* Copyright (c) 2011 Eric Bruneton.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the BSD License
* which accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php
* Contributor: Eric Bruneton - initial API and implementation
* Contributor: Andrey Loskutov - fixes
*******************************************************************************/
package de.loskutov.bco.asm;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.util.Printer;
import org.objectweb.asm.util.TraceClassVisitor;
import de.loskutov.bco.preferences.BCOConstants;
/**
* @author Eric Bruneton
*/
public class DecompilerHelper {
public static DecompiledClass getDecompiledClass(final InputStream is,
DecompilerOptions options)
throws IOException, UnsupportedClassVersionError {
ClassReader cr = new ClassReader(is);
ClassNode cn = new ClassNode(Opcodes.ASM5);
int crFlags = 0;
if(options.modes.get(BCOConstants.F_EXPAND_STACKMAP)) {
crFlags |= ClassReader.EXPAND_FRAMES;
}
cr.accept(cn, crFlags);
ICommentedClassVisitor printer;
if (options.modes.get(BCOConstants.F_SHOW_ASMIFIER_CODE)) {
printer = new CommentedASMifierClassVisitor(cn, options);
} else {
printer = new CommentedClassVisitor(cn, options);
}
TraceClassVisitor dcv = new TraceClassVisitor(null, (Printer) printer, null);
cn.accept(dcv);
return getResult(printer, options, cn);
}
private static DecompiledClass getResult(ICommentedClassVisitor printer, DecompilerOptions options, ClassNode classNode) {
List<Object> classText = new ArrayList<Object>();
formatText(printer.getText(), new StringBuffer(), classText, options.cl);
while (classText.size() > 0 && classText.get(0).equals("\n")) {
classText.remove(0);
}
DecompiledClassInfo classInfo = printer.getClassInfo();
return new DecompiledClass(classText, classInfo, classNode);
}
private static void formatText(final List input, final StringBuffer line, final List<Object> result,
final ClassLoader cl) {
for (int i = 0; i < input.size(); ++i) {
Object o = input.get(i);
if (o instanceof List) {
formatText((List) o, line, result, cl);
} else if (o instanceof DecompiledMethod) {
result.add(o);
} else {
String s = o.toString();
int p;
do {
p = s.indexOf('\n');
if (p == -1) {
line.append(s);
} else {
result.add(line.toString() + s.substring(0, p + 1));
s = s.substring(p + 1);
line.setLength(0);
}
} while (p != -1);
}
}
}
}
/*******************************************************************************
* Copyright (c) 2011 Andrey Loskutov. All rights reserved. This program and the
* accompanying materials are made available under the terms of the BSD License which
* accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php Contributor: Andrey Loskutov -
* initial API and implementation
*******************************************************************************/
package de.loskutov.bco.asm;
import java.util.BitSet;
public class DecompilerOptions {
public final String fieldFilter;
public final String methodFilter;
public final BitSet modes;
public final ClassLoader cl;
public DecompilerOptions(final String fieldFilter, final String methodFilter,
final BitSet modes, final ClassLoader cl) {
this.fieldFilter = fieldFilter;
this.methodFilter = methodFilter;
this.modes = modes;
this.cl = cl;
}
}
/*******************************************************************************
* Copyright (c) 2011 Andrey Loskutov.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the BSD License
* which accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.bco.asm;
import java.util.List;
public interface ICommentedClassVisitor {
List getText();
DecompiledClassInfo getClassInfo();
}
package de.loskutov.bco.asm;
import org.objectweb.asm.tree.LabelNode;
/**
* @author Eric Bruneton
*/
public class Index {
public final LabelNode labelNode;
public final int insn;
public final int opcode;
public Index(final LabelNode label, final int insn, final int opcode) {
this.labelNode = label;
this.insn = insn;
this.opcode = opcode;
}
}
package de.loskutov.bco.asm;
/**
* @author Andrei
*/
public class LineRange {
public final int startLine;
public final int endLine;
public LineRange(int startLine, int endLine) {
super();
this.startLine = startLine;
this.endLine = endLine;
}
}
This diff is collapsed.
/*****************************************************************************************
* Copyright (c) 2011 Andrey Loskutov. All rights reserved. This program and the
* accompanying materials are made available under the terms of the BSD License which
* accompanies this distribution, and is available at
* http://www.opensource.org/licenses/bsd-license.php Contributor: Andrey Loskutov -
* initial API and implementation
****************************************************************************************/
package de.loskutov.bco.compare;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.BitSet;
import org.eclipse.compare.BufferedContent;
import org.eclipse.compare.CompareUI;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import de.loskutov.bco.BytecodeOutlinePlugin;
import de.loskutov.bco.asm.DecompiledClass;
import de.loskutov.bco.asm.DecompilerHelper;
import de.loskutov.bco.asm.DecompilerOptions;
import de.loskutov.bco.ui.JdtUtils;
/**
* @author Andrei
*/
public class TypedElement extends BufferedContent
implements
ITypedElement,
IStructureComparator {
private final String name;
private String type;
private final String methodName;
private final IJavaElement element;
/** used by Eclipse to recognize appropriated viewer */
public static final String TYPE_BYTECODE = "bytecode";
/** used by Eclipse to recognize appropriated viewer */
public static final String TYPE_ASM_IFIER = "java";
private final BitSet modes;
/**
* Constructor for TypedElement.
* @param name
* @param type
* @param element
* @param modes
*/
public TypedElement(String name, String methodName, String type, IJavaElement element, BitSet modes) {
super();
this.name = name;
this.methodName = methodName;
this.type = type;
this.element = element;
this.modes = modes;
}
/**
* @see org.eclipse.compare.ITypedElement#getName()
*/
@Override
public String getName() {
return name;
}
/**
* @see org.eclipse.compare.ITypedElement#getType()
*/
@Override
public String getType() {
return type;
}
/**
* @param type The type to set.
*/
protected void setType(String type) {
this.type = type;
}
/**
* @return name
*/
public String getElementName() {
return JdtUtils.getElementName(element);
}
@Override
public Image getImage() {
// default image for .class files
return CompareUI.getImage("class");
}
@Override
public Object[] getChildren() {
return new TypedElement[0];
}
@Override
protected InputStream createStream() throws CoreException {
InputStream stream = JdtUtils.createInputStream(element);
if (stream == null) {
throw new CoreException(new Status(
IStatus.ERROR, "de.loskutov.bco", -1,
"cannot get bytecode from class file", null));
}
DecompiledClass decompiledClass = null;
try {
decompiledClass = DecompilerHelper.getDecompiledClass(
stream, new DecompilerOptions(null, methodName, modes, null));
} catch (IOException e) {
throw new CoreException(new Status(
IStatus.ERROR, "de.loskutov.bco", -1,
"cannot get bytecode dump", e));
} catch (UnsupportedClassVersionError e){
throw new CoreException(new Status(
IStatus.ERROR, "de.loskutov.bco", -1,
"Error caused by attempt to load class compiled with Java version which"
+ " is not supported by current JVM", e));
} finally {
try {
stream.close();
} catch (IOException e) {
BytecodeOutlinePlugin.log(e, IStatus.WARNING);
}
}
final byte[] bytes = decompiledClass.getText().getBytes(Charset.forName("UTF-8"));
// use internal buffering to prevent multiple calls to this method
Display.getDefault().syncExec(new Runnable(){
@Override
public void run() {
setContent(bytes);
}
});
return new ByteArrayInputStream(bytes);
}
/**
*
* @param mode one of BCOConstants.F_* modes
* @param value
*/
public void setMode(int mode, boolean value){
modes.set(mode, value);
// force create new stream
discardBuffer();
}
}
package de.loskutov.bco.editors;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditorActionContributor;
import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathSupport;
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement;
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import de.loskutov.bco.BytecodeOutlinePlugin;
import de.loskutov.bco.preferences.BCOConstants;
/**
* Adds "Show Bytecode" action to tool/menu bars
* @author V. Grishchenko, Eugene Kuleshov, Andrei
*/
public class BytecodeActionBarContributor
extends
ClassFileEditorActionContributor {
BytecodeClassFileEditor editor;
protected ShowBytecodeAction refreshAction;
protected ToggleRawBytecodeAction toggleRawBytecodeAction;
private final AttachSourceAction attachAction;
public BytecodeActionBarContributor() {
super();
String symbolicName = BytecodeOutlinePlugin.getDefault().getBundle()
.getSymbolicName();
ImageDescriptor actionIcon = AbstractUIPlugin
.imageDescriptorFromPlugin(symbolicName, "icons/bytecodeview.gif");
refreshAction = new ShowBytecodeAction(actionIcon);
actionIcon = AbstractUIPlugin.imageDescriptorFromPlugin(
symbolicName, "icons/raw_mode.gif");
toggleRawBytecodeAction = new ToggleRawBytecodeAction(actionIcon);
actionIcon = AbstractUIPlugin.imageDescriptorFromPlugin(
symbolicName, "icons/source.gif");
attachAction = new AttachSourceAction(actionIcon);
}
@Override
public void contributeToToolBar(IToolBarManager toolBarManager) {
super.contributeToToolBar(toolBarManager);
toolBarManager.add(refreshAction);
toolBarManager.add(toggleRawBytecodeAction);
toolBarManager.add(attachAction);
// toolBarManager.add(new Separator(JadclipsePlugin.PID_JADCLIPSE));
// toolBarManager.appendToGroup(JadclipsePlugin.PID_JADCLIPSE, dAction);
}
@Override
public void contributeToMenu(IMenuManager menu) {
super.contributeToMenu(menu);
IMenuManager edit = menu
.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (edit != null) {
edit.add(refreshAction);
edit.add(toggleRawBytecodeAction);
edit.add(attachAction);
}
}
@Override