Commit de88d4d6 authored by andrei's avatar andrei

Fix for not working editor<-> view synchronization with disabled line info

parent 4a7ec716
package de.loskutov.bco.asm;
import java.util.BitSet;
import org.objectweb.asm.Label;
import org.objectweb.asm.Type;
import org.objectweb.asm.util.TraceAnnotationVisitor;
......@@ -7,6 +9,8 @@ import org.objectweb.asm.util.TraceClassVisitor;
import org.objectweb.asm.util.TraceFieldVisitor;
import org.objectweb.asm.util.TraceMethodVisitor;
import de.loskutov.bco.preferences.BCOConstants;
/**
* @author Eric Bruneton
*/
......@@ -14,10 +18,18 @@ import org.objectweb.asm.util.TraceMethodVisitor;
public class CommentedClassVisitor extends TraceClassVisitor {
protected boolean raw;
protected BitSet modes;
protected boolean showLines;
protected boolean showLocals;
protected boolean showStackMap;
public CommentedClassVisitor(final boolean raw) {
public CommentedClassVisitor(final BitSet modes) {
super(null);
this.raw = raw;
this.modes = modes;
raw = !modes.get(BCOConstants.F_SHOW_RAW_BYTECODE);
showLines = modes.get(BCOConstants.F_SHOW_LINE_INFO);
showLocals = modes.get(BCOConstants.F_SHOW_VARIABLES);
showStackMap = modes.get(BCOConstants.F_SHOW_STACKMAP);
}
public void visitEnd() {
......@@ -184,6 +196,12 @@ public class CommentedClassVisitor extends TraceClassVisitor {
return null;
}
public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
if(showStackMap) {
super.visitFrame(type, nLocal, local, nStack, stack);
}
}
public void visitMethodInsn (
final int opcode,
final String owner,
......@@ -230,18 +248,20 @@ public class CommentedClassVisitor extends TraceClassVisitor {
public void visitLocalVariable(final String name, final String desc,
final String signature, final Label start, final Label end,
final int index) {
if (raw) {
if (showLocals) {
super.visitLocalVariable(
name, desc, signature, start, end, index);
}
}
public void visitLineNumber(final int line, final Label start) {
super.visitLineNumber(line, start);
if (showLines) {
super.visitLineNumber(line, start);
}
}
public void visitMaxs(final int maxStack, final int maxLocals) {
if (raw) {
if (showLocals) {
super.visitMaxs(maxStack, maxLocals);
}
}
......
package de.loskutov.bco.asm;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
......@@ -50,9 +51,12 @@ public class DecompiledMethod {
private int errorInsn;
private final BitSet modes;
public DecompiledMethod(final String owner, final List inputText,
final Map lineNumbers, final List localVariables,
final MethodNode meth, final ClassLoader cl) {
final MethodNode meth, final ClassLoader cl, BitSet modes) {
this.modes = modes;
this.text = new ArrayList();
this.localVariables = localVariables;
this.sourceLines = new HashMap();
......
......@@ -12,8 +12,6 @@ import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.ASMifierClassVisitor;
......@@ -70,44 +68,11 @@ public class DecompilerClassVisitor extends ClassAdapter {
};
} else {
cv = new CommentedClassVisitor(!modes.get(BCOConstants.F_SHOW_RAW_BYTECODE));
cv = new CommentedClassVisitor(modes);
}
DecompilerClassVisitor dcv = new DecompilerClassVisitor(
cv, field, method, modes);
cr.accept(new ClassAdapter(dcv) {
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
return mv==null ? null : new MethodAdapter(mv) {
public void visitLocalVariable(String name1, String desc1, String signature1, Label start, Label end, int index) {
if(modes.get(BCOConstants.F_SHOW_VARIABLES)) {
super.visitLocalVariable(name1, desc1, signature1, start, end, index);
}
}
public void visitMaxs(int maxStack, int maxLocals) {
if(modes.get(BCOConstants.F_SHOW_VARIABLES)) {
super.visitMaxs(maxStack, maxLocals);
}
}
public void visitLineNumber(int line, Label start) {
if(modes.get(BCOConstants.F_SHOW_LINE_INFO)) {
super.visitLineNumber(line, start);
}
}
public void visitLabel(Label label) {
super.visitLabel(label);
}
public void visitFrame(int type, int nLocal,
Object[] local, int nStack, Object[] stack) {
if (modes.get(BCOConstants.F_SHOW_STACKMAP)) {
super.visitFrame(
type, nLocal, local, nStack, stack);
}
}
};
}
}, crFlags);
cr.accept(dcv, crFlags);
return dcv.getResult(cl);
}
......@@ -225,7 +190,7 @@ public class DecompilerClassVisitor extends ClassAdapter {
int size = text.size();
MethodVisitor mv = cv.visitMethod(
access, name1, desc, signature, exceptions);
mv = new DecompilerMethodVisitor(this.name, meth, mv);
mv = new DecompilerMethodVisitor(this.name, meth, mv, modes);
methods.add(mv);
for (int i = size; i < text.size(); ++i) {
if (text.get(i) instanceof List) {
......
package de.loskutov.bco.asm;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -33,10 +34,13 @@ public class DecompilerMethodVisitor extends MethodAdapter {
private List localVariables;
private final BitSet modes;
public DecompilerMethodVisitor(final String owner, final MethodNode meth,
final MethodVisitor mv) {
final MethodVisitor mv, BitSet modes) {
super(mv);
this.owner = owner;
this.modes = modes;
this.text = ((AbstractVisitor) mv).getText();
this.meth = meth;
this.lineNumbers = new HashMap();
......@@ -45,7 +49,7 @@ public class DecompilerMethodVisitor extends MethodAdapter {
public DecompiledMethod getResult(final ClassLoader cl) {
return new DecompiledMethod(
owner, text, lineNumbers, localVariables, meth, cl);
owner, text, lineNumbers, localVariables, meth, cl, modes);
}
public void visitInsn(final int opcode) {
......
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