Commit f6cf50ec authored by andrei's avatar andrei

1) addes status line with some class/selection info

2) fixed "whole class selection" bug if current java element is null
3) added key listener to bytecode dump
parent 97729732
package de.loskutov.bco.asm;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Eric Bruneton
......@@ -10,13 +12,24 @@ import java.util.List;
public class DecompiledClass {
private List text;
/**
* key is string, value is string
*/
private Map classAttributesMap = new HashMap();
private String value;
public DecompiledClass(final List text) {
this.text = text;
}
public void setAttribute(String key, String value){
classAttributesMap.put(key, value);
}
public String getAttribute(String key){
return (String)classAttributesMap.get(key);
}
public String getText() {
if (value == null) {
StringBuffer buf = new StringBuffer();
......@@ -49,6 +62,24 @@ public class DecompiledClass {
return (String[][]) lines.toArray(new String[lines.size()][]);
}
public int getBytecodeOffest(final int decompiledLine) {
int currentDecompiledLine = 0;
for (int i = 0; i < text.size(); ++i) {
Object o = text.get(i);
if (o instanceof DecompiledMethod) {
DecompiledMethod m = (DecompiledMethod) o;
Integer offset = m.getBytecodeOffset(decompiledLine - currentDecompiledLine);
if(offset != null){
return offset.intValue();
}
currentDecompiledLine += m.getLineCount();
} else {
currentDecompiledLine++;
}
}
return -1;
}
public int getSourceLine(final int decompiledLine) {
int currentDecompiledLine = 0;
for (int i = 0; i < text.size(); ++i) {
......
......@@ -297,7 +297,7 @@ public class DecompiledMethod {
* second is the operands stack content. "null" value could be returned too.
*/
public String[] getFrame(final int decompiledLine, final boolean useQualifiedNames) {
Integer insn = (Integer) insns.get(new Integer(decompiledLine));
Integer insn = getBytecodeOffset(decompiledLine);
if (error != null && insn != null && insn.intValue() == errorInsn) {
return new String [] {error,error};
}
......@@ -339,8 +339,17 @@ public class DecompiledMethod {
return null;
}
/**
* @param decompiledLine
* @return
*/
public Integer getBytecodeOffset(final int decompiledLine) {
Integer insn = (Integer) insns.get(new Integer(decompiledLine));
return insn;
}
public String[][][] getFrameTables(final int decompiledLine, boolean useQualifiedNames) {
Integer insn = (Integer) insns.get(new Integer(decompiledLine));
Integer insn = getBytecodeOffset(decompiledLine);
if (error != null && insn != null && insn.intValue() == errorInsn) {
return null;
}
......
......@@ -34,6 +34,8 @@ public class DecompilerClassVisitor extends ClassAdapter {
private AnnotationVisitor dummyAnnVisitor;
private String javaVersion;
public DecompilerClassVisitor(final ClassVisitor cv, final String field,
final String method, final boolean verify) {
super(cv);
......@@ -51,7 +53,6 @@ public class DecompilerClassVisitor extends ClassAdapter {
ClassVisitor cv;
if (asmify) {
cv = new ASMifierClassVisitor(null) {
public void visitEnd() {
text.add("cw.visitEnd();\n\n");
text.add("return cw.toByteArray();\n");
......@@ -59,12 +60,14 @@ public class DecompilerClassVisitor extends ClassAdapter {
text.add("}\n");
}
};
} else {
cv = new CommentedClassVisitor(raw);
}
DecompilerClassVisitor dcv = new DecompilerClassVisitor(
cv, field, method, verify);
cr.accept(dcv, false);
return dcv.getResult(cl);
}
......@@ -74,7 +77,9 @@ public class DecompilerClassVisitor extends ClassAdapter {
while (text.size() > 0 && text.get(0).equals("\n")) {
text.remove(0);
}
return new DecompiledClass(text);
DecompiledClass dc = new DecompiledClass(text);
dc.setAttribute("java.version", javaVersion);
return dc;
}
private void formatText(final List input, StringBuffer line, final List result,
......@@ -110,6 +115,13 @@ public class DecompilerClassVisitor extends ClassAdapter {
.visit(version, access, name1, signature, superName, interfaces);
}
this.name = name1;
int major = version & 0xFFFF;
//int minor = version >>> 16;
// 1.1 is 45, 1.2 is 46 etc.
int javaV = major % 44;
if (javaV > 0 && javaV < 10) {
javaVersion = "1." + javaV; //$NON-NLS-1$
}
}
public void visitSource(final String source, final String debug) {
......@@ -192,10 +204,10 @@ public class DecompilerClassVisitor extends ClassAdapter {
private AnnotationVisitor getDummyAnnotationVisitor(){
if (dummyAnnVisitor == null) {
dummyAnnVisitor = new AnnotationVisitor() {
public void visit(String n, Object value) {
public void visit(String n, Object value) {
/* empty */
}
public void visitEnum(String n, String desc, String value) {
public void visitEnum(String n, String desc, String value) {
/* empty */
}
public AnnotationVisitor visitAnnotation(String n, String desc) {
......@@ -204,7 +216,7 @@ public class DecompilerClassVisitor extends ClassAdapter {
public AnnotationVisitor visitArray(String n) {
return this;
}
public void visitEnd() {
public void visitEnd() {
/* empty*/
}
};
......
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