Commit 7a55a60c authored by ekuleshov's avatar ekuleshov

refactored bco modes support

parent fb6df06d
......@@ -44,30 +44,30 @@ BCOPreferencePage.showAsmifierCodeTip=Show ASMifier code
BCOPreferencePage.showOnlySelectedTip=Show bytecode for selected element only
BCOPreferencePage.linkViewToEditorTip=Link bytecode view to editor
action.hide_locals.text=Hide local variables
action.hide_locals.toolTipText=Hide local variables (if available in bytecode)
action.hide_locals.image=icons/hide_locals.gif
action.showVariables.text=Show local variables
action.showVariables.toolTipText=Show local variables (if available in bytecode)
action.showVariables.image=icons/hide_locals.gif
action.hide_line_info.text=Hide line info
action.hide_line_info.toolTipText=Hide line info (if available in bytecode)
action.hide_line_info.image=icons/hide_line_info.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.toggle_asmifier_mode.text=Toggle ASMifier mode on/off
action.toggle_asmifier_mode.toolTipText=Switch between true bytecode and ASMifier java code view
action.toggle_asmifier_mode.image=icons/asm.gif
action.showASMifierCode.text=Toggle ASMifier mode on/off
action.showASMifierCode.toolTipText=Show ASMified code
action.showASMifierCode.image=icons/asm.gif
action.show_verifier.text=Show bytecode analyzer pane
action.show_verifier.toolTipText=Shows the symbolic state of the execution stack frame at selected bytecode instruction
action.show_verifier.image=icons/verify.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.show_raw_mode.text=Show "raw" bytecode
action.show_raw_mode.toolTipText=Hide any additional help
action.show_raw_mode.image=icons/raw_mode.gif
action.showRawBytecode.text=Show "raw" bytecode
action.showRawBytecode.toolTipText=Show bytecode as is
action.showRawBytecode.image=icons/raw_mode.gif
action.show_selected_only.text=Show current element only
action.show_selected_only.toolTipText=Show bytecode for current field/method only
action.show_selected_only.image=icons/selected_only.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.link_with_editor.text=Link with editor
action.link_with_editor.toolTipText=Link With Editor
action.link_with_editor.image=icons/link_with_editor.gif
\ No newline at end of file
action.linkViewToEditor.text=Link with editor
action.linkViewToEditor.toolTipText=Link With Editor
action.linkViewToEditor.image=icons/link_with_editor.gif
......@@ -3,6 +3,7 @@ package de.loskutov.bco.asm;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import org.objectweb.asm.AnnotationVisitor;
......@@ -16,6 +17,8 @@ import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.ASMifierClassVisitor;
import org.objectweb.asm.util.AbstractVisitor;
import de.loskutov.bco.preferences.BCOConstants;
/**
* @author Eric Bruneton
*/
......@@ -45,6 +48,31 @@ public class DecompilerClassVisitor extends ClassAdapter {
this.methods = new ArrayList();
}
public static DecompiledClass getDecompiledClass(final InputStream is,
final String field, final String method, final BitSet modes, final ClassLoader cl)
throws IOException {
ClassReader cr = new ClassReader(is);
ClassVisitor cv;
if (modes.get(BCOConstants.F_SHOW_ASMIFIER_CODE)) {
cv = new ASMifierClassVisitor(null) {
public void visitEnd() {
text.add("cw.visitEnd();\n\n");
text.add("return cw.toByteArray();\n");
text.add("}\n");
text.add("}\n");
}
};
} else {
cv = new CommentedClassVisitor(!modes.get(BCOConstants.F_SHOW_RAW_BYTECODE));
}
DecompilerClassVisitor dcv = new DecompilerClassVisitor(
cv, field, method, modes.get(BCOConstants.F_SHOW_ANALYZER));
cr.accept(dcv, false);
return dcv.getResult(cl);
}
public static DecompiledClass getDecompiledClass(final InputStream is,
final String field, final String method, final boolean raw,
final boolean asmify, final boolean verify, final ClassLoader cl)
......
......@@ -21,14 +21,12 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IReusableEditor;
import de.loskutov.bco.BytecodeOutlinePlugin;
import de.loskutov.bco.preferences.BCOConstants;
import de.loskutov.bco.ui.actions.DefaultToggleAction;
......@@ -58,41 +56,34 @@ public class BytecodeCompare extends CompareEditorInput {
super(new CompareConfiguration());
this.left = left;
this.right = right;
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore();
boolean toggleAsmifierMode = store.getBoolean(BCOConstants.SHOW_ASMIFIER_CODE);
toggleAsmifierModeAction = new DefaultToggleAction(
DefaultToggleAction.TOGGLE_ASMIFIER, toggleAsmifierMode);
toggleAsmifierModeAction.addPropertyChangeListener(new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
if(IAction.CHECKED.equals(event.getProperty())){
toggleASMifierMode(Boolean.TRUE == event.getNewValue());
toggleAsmifierModeAction = new DefaultToggleAction(BCOConstants.SHOW_ASMIFIER_CODE,
new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
if(IAction.CHECKED.equals(event.getProperty())){
toggleASMifierMode(Boolean.TRUE == event.getNewValue());
}
}
}
});
boolean hideLineInfo = !store.getBoolean(BCOConstants.SHOW_LINE_INFO);
hideLineInfoAction = new DefaultToggleAction(
DefaultToggleAction.HIDE_LINE_INFO, hideLineInfo);
hideLineInfoAction.addPropertyChangeListener(new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
if(IAction.CHECKED.equals(event.getProperty())){
// TODO add custom behavoir
// toggleASMifierMode(Boolean.TRUE == event.getNewValue());
});
hideLineInfoAction = new DefaultToggleAction(BCOConstants.SHOW_LINE_INFO, new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
if(IAction.CHECKED.equals(event.getProperty())){
// TODO add custom behavoir
// toggleASMifierMode(Boolean.TRUE == event.getNewValue());
}
}
}
});
boolean hideLocals = !store.getBoolean(BCOConstants.SHOW_VARIABLES);
hideLocalsAction = new DefaultToggleAction(
DefaultToggleAction.HIDE_LOCALS, hideLocals);
hideLocalsAction.addPropertyChangeListener(new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
if(IAction.CHECKED.equals(event.getProperty())){
// TODO add custom behavoir
// toggleASMifierMode(Boolean.TRUE == event.getNewValue());
});
hideLocalsAction = new DefaultToggleAction(BCOConstants.SHOW_VARIABLES,
new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
if(IAction.CHECKED.equals(event.getProperty())){
// TODO add custom behavoir
// toggleASMifierMode(Boolean.TRUE == event.getNewValue());
}
}
}
});
});
}
/** @see CompareEditorInput#prepareInput(IProgressMonitor) */
......
......@@ -59,4 +59,15 @@ public interface BCOConstants {
*/
String SHOW_ANALYZER = "showAnalyzer";
int F_LINK_VIEW_TO_EDITOR = 0;
int F_SHOW_ONLY_SELECTED_ELEMENT = 1;
int F_SHOW_ASMIFIER_CODE = 2;
int F_SHOW_RAW_BYTECODE = 3;
int F_SHOW_LINE_INFO = 4;
int F_SHOW_VARIABLES = 5;
int F_RECALCULATE_STACKMAP = 6;
int F_EXPAND_STACKMAP = 7;
int F_SHOW_ANALYZER = 8;
}
......@@ -9,6 +9,8 @@
package de.loskutov.bco.ui.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import de.loskutov.bco.BytecodeOutlinePlugin;
......@@ -22,33 +24,21 @@ import de.loskutov.bco.BytecodeOutlinePlugin;
* @author Andrei
*/
public class DefaultToggleAction extends Action {
/** Action id for toggle asmifier mode on/off */
public static final String TOGGLE_ASMIFIER = "toggle_asmifier_mode";
/** Action id for hide/show line info */
public static final String HIDE_LINE_INFO = "hide_line_info";
/** Action id for hide/show local variables */
public static final String HIDE_LOCALS = "hide_locals";
/** Action id for hide/show verifier */
public static final String SHOW_VERIFIER = "show_verifier";
/** Action id for hide/show raw bytecode */
public static final String SHOW_RAW_BYTECODE = "show_raw_mode";
/** Action id for show selected element only */
public static final String SHOW_SELECTED_ONLY = "show_selected_only";
/** Action id for link with editor mode on/off */
public static final String LINK_WITH_EDITOR = "link_with_editor";
/**
* used to get text from props file
*/
private static final String ACTION = "action";
private boolean checked;
private boolean isChecked;
public DefaultToggleAction(String id, boolean isChecked){
public DefaultToggleAction(String id, IPropertyChangeListener listener) {
super();
checked = isChecked;
// to init internal "value" attribute in Action class to proper start value
setChecked(checked);
setId(id);
init();
addPropertyChangeListener(listener);
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore();
isChecked = store.getBoolean(id);
setChecked(isChecked);
}
private void init(){
......@@ -69,7 +59,7 @@ public class DefaultToggleAction extends Action {
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
checked = !checked;
setChecked(checked);
isChecked = !isChecked;
setChecked(isChecked);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment