Commit ae105e1f authored by andrei's avatar andrei

Update to the ASM 4.0 RC2 API state

parent b38009ce
......@@ -2,15 +2,11 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bytecode Outline
Bundle-SymbolicName: de.loskutov.BytecodeOutline;singleton:=true
Bundle-Version: 2.3.1
Bundle-Version: 2.4.0
Bundle-ClassPath: .,
lib/asm-3.3.jar,
lib/asm-analysis-3.3.jar,
lib/asm-commons-3.3.jar,
lib/asm-tree-3.3.jar,
lib/asm-util-3.3.jar
lib/asm-debug-all-4.0_RC2.jar
Bundle-Activator: de.loskutov.bco.BytecodeOutlinePlugin
Bundle-Vendor: Andrei Loskutov
Bundle-Vendor: Andrey Loskutov
Require-Bundle: org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.core.runtime,
......
plugin.id=de.loskutov.BytecodeOutline
plugin.version=2.3.1
plugin.version=2.4.0
bin.includes = LICENSE.txt,\
README.txt,\
......@@ -9,13 +9,9 @@ bin.includes = LICENSE.txt,\
plugin.xml,\
.,\
about.html,\
lib/asm-3.3.jar,\
lib/asm-analysis-3.3.jar,\
lib/asm-commons-3.3.jar,\
lib/asm-tree-3.3.jar,\
lib/asm-util-3.3.jar,\
.project,\
.settings/
.settings/,\
lib/asm-debug-all-4.0_RC2.jar
jars.compile.order = .
source.. = src/,\
......
......@@ -11,11 +11,14 @@
<property name="plugin.jar" value="${plugin.id}_${plugin.version}.jar"/>
<property name="feature.jar" value="${plugin.id}.feature_${plugin.version}.jar"/>
<path id="saxon.classpath">
<fileset dir="${saxon.home}" includes="*.jar"/>
</path>
<target name="init">
<path id="classpath">
<fileset dir="lib" includes="*.jar"/>
<fileset dir="${eclipse.home}" includes="plugins/**/*.jar"/>
<fileset dir="${eclipse.home}" includes="plugins/**/*.jar"/>
</path>
</target>
......@@ -68,8 +71,8 @@
<include name="lib/*.jar"/>
</fileset>
<fileset dir="${out.build}">
<include name="**/*"/>
</fileset>
<include name="**/*"/>
</fileset>
<zipfileset dir="${out}/doc" includes="toc.xml,ref-*.html" prefix="doc"/>
</zip>
</target>
......@@ -96,9 +99,9 @@
<target name="xslt" depends="init">
<mkdir dir="${out}/doc"/>
<xslt basedir="." destdir="${out}/doc" includes="opcodes.xml"
<xslt basedir="." destdir="${out}/doc" includes="opcodes.xml" classpathref="saxon.classpath"
style="opcodes-doc.xsl" force="true">
<factory name="net.sf.saxon.TransformerFactoryImpl" />
<factory name="net.sf.saxon.TransformerFactoryImpl" />
</xslt>
</target>
......
/*******************************************************************************
* Copyright (c) 2004 Andrei Loskutov.
* 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: Andrei Loskutov - initial API and implementation
* Contributor: Andrey Loskutov - initial API and implementation
*******************************************************************************/
package de.loskutov.bco.asm;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.BitSet;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.util.ASMifierClassVisitor;
import org.objectweb.asm.util.ASMifierMethodVisitor;
import org.objectweb.asm.util.ASMifierVisitor;
import de.loskutov.bco.preferences.BCOConstants;
/**
* @author Andrei
*/
public class CommentedASMifierClassVisitor extends ASMifierClassVisitor {
public class CommentedASMifierClassVisitor extends ASMifierVisitor implements ICommentedClassVisitor {
protected BitSet modes;
protected boolean raw;
protected boolean showLines;
protected boolean showLocals;
protected boolean showStackMap;
private ASMifierClassVisitor classVisitor;
protected ASMifierMethodVisitor createASMifierMethodVisitor() {
return new ASMifierMethodVisitor() {
public void visitFrame(final int type, final int nLocal,
final Object[] local, final int nStack, final Object[] stack) {
if (showStackMap) {
super.visitFrame(type, nLocal, local, nStack, stack);
}
}
public void visitLineNumber(int line, Label start) {
if (showLines) {
super.visitLineNumber(line, start);
}
}
public void visitLocalVariable(String name, String desc,
String signature, Label start, Label end, int index) {
if (showLocals) {
super.visitLocalVariable(
name, desc, signature, start, end, index);
}
}
public void visitFrame(final int type, final int nLocal,
final Object[] local, final int nStack, final Object[] stack) {
if (showStackMap) {
super.visitFrame(type, nLocal, local, nStack, stack);
}
}
public void visitMaxs(int maxStack, int maxLocals) {
//if (showLocals) {
super.visitMaxs(maxStack, maxLocals);
//}
}
public void visitLineNumber(int line, Label start) {
if (showLines) {
super.visitLineNumber(line, start);
}
}
};
public void visitLocalVariable(String name1, String desc,
String signature, Label start, Label end, int index) {
if (showLocals) {
super.visitLocalVariable(
name1, desc, signature, start, end, index);
}
}
protected boolean showLines;
protected boolean showLocals;
protected boolean showStackMap;
public void visitMaxs(int maxStack, int maxLocals) {
//if (showLocals) {
super.visitMaxs(maxStack, maxLocals);
//}
}
public CommentedASMifierClassVisitor(final BitSet modes) {
super(null);
private CommentedASMifierClassVisitor(final BitSet modes, String name, int id) {
super(Opcodes.ASM4, name, id);
this.modes = modes;
raw = !modes.get(BCOConstants.F_SHOW_RAW_BYTECODE);
showLines = modes.get(BCOConstants.F_SHOW_LINE_INFO);
......@@ -70,10 +69,26 @@ public class CommentedASMifierClassVisitor extends ASMifierClassVisitor {
showStackMap = modes.get(BCOConstants.F_SHOW_STACKMAP);
}
public CommentedASMifierClassVisitor(final BitSet modes) {
this(modes, "cw", 0);
}
public void visitEnd() {
text.add("cw.visitEnd();\n\n");
text.add("return cw.toByteArray();\n");
text.add("}\n");
text.add("}\n");
}
}
\ No newline at end of file
public ClassVisitor getClassVisitor() {
if(classVisitor == null) {
// TODO ASM 4.0 transition: PrintWriter should be optional
classVisitor = new ASMifierClassVisitor(this, new PrintWriter(new StringWriter()));
}
return classVisitor;
}
protected ASMifierVisitor createASMifierVisitor(String name1, int id1) {
return new CommentedASMifierClassVisitor(modes, name1, id1);
}
}
......@@ -8,24 +8,23 @@ import java.util.List;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.AbstractVisitor;
import org.objectweb.asm.util.TraceAnnotationVisitor;
import org.objectweb.asm.util.TraceFieldVisitor;
import de.loskutov.bco.asm.CommentedClassVisitor.CommentedAnnotationVisitor;
import de.loskutov.bco.asm.CommentedClassVisitor.CommentedFieldVisitor;
import de.loskutov.bco.preferences.BCOConstants;
/**
* @author Eric Bruneton
*/
public class DecompilerClassVisitor extends ClassAdapter {
public class DecompilerClassVisitor extends ClassVisitor {
private final String fieldFilter;
......@@ -45,9 +44,12 @@ public class DecompilerClassVisitor extends ClassAdapter {
private final ClassNode classNode;
public DecompilerClassVisitor(final ClassVisitor cv, final String field,
private final ICommentedClassVisitor cv2;
public DecompilerClassVisitor(final ICommentedClassVisitor cv, final String field,
final String method, final BitSet modes) {
super(cv);
super(Opcodes.ASM4, cv.getClassVisitor());
cv2 = cv;
this.classNode = new ClassNode();
this.fieldFilter = field;
this.methodFilter = method;
......@@ -63,7 +65,7 @@ public class DecompilerClassVisitor extends ClassAdapter {
if(modes.get(BCOConstants.F_EXPAND_STACKMAP)) {
crFlags |= ClassReader.EXPAND_FRAMES;
}
ClassVisitor cv;
ICommentedClassVisitor cv;
if (modes.get(BCOConstants.F_SHOW_ASMIFIER_CODE)) {
cv = new CommentedASMifierClassVisitor(modes);
} else {
......@@ -77,7 +79,7 @@ public class DecompilerClassVisitor extends ClassAdapter {
public DecompiledClass getResult(final ClassLoader cl) {
List text = new ArrayList();
formatText(((AbstractVisitor) cv).getText(), new StringBuffer(), text, cl);
formatText(cv2.getText(), new StringBuffer(), text, cl);
while (text.size() > 0 && text.get(0).equals("\n")) {
text.remove(0);
}
......@@ -158,9 +160,9 @@ public class DecompilerClassVisitor extends ClassAdapter {
if (decompilingEntireClass()) {
AnnotationVisitor cav = classNode.visitAnnotation(desc, visible);
AnnotationVisitor av = super.visitAnnotation(desc, visible);
if(av instanceof CommentedAnnotationVisitor){
CommentedAnnotationVisitor visitor = (CommentedAnnotationVisitor) av;
visitor.setAnnotationVisitor(cav);
if(av instanceof TraceAnnotationVisitor){
TraceAnnotationVisitor visitor = (TraceAnnotationVisitor) av;
visitor.setNext(cav);
}
return av;
}
......@@ -192,9 +194,9 @@ public class DecompilerClassVisitor extends ClassAdapter {
}
FieldVisitor cfv = classNode.visitField(access, name1, desc, signature, value);
FieldVisitor fieldVisitor = super.visitField(access, name1, desc, signature, value);
if(fieldVisitor instanceof CommentedFieldVisitor){
CommentedFieldVisitor visitor = (CommentedFieldVisitor) fieldVisitor;
visitor.setFieldVisitor(cfv);
if(fieldVisitor instanceof TraceFieldVisitor){
TraceFieldVisitor visitor = (TraceFieldVisitor) fieldVisitor;
visitor.setNext(cfv);
}
return fieldVisitor;
}
......@@ -209,10 +211,11 @@ public class DecompilerClassVisitor extends ClassAdapter {
}
MethodNode meth = (MethodNode) classNode.visitMethod(
access, name1, desc, signature, exceptions);
List text = ((AbstractVisitor) cv).getText();
final List text = cv2.getText();
int size = text.size();
MethodVisitor mv = cv.visitMethod(
access, name1, desc, signature, exceptions);
mv = new DecompilerMethodVisitor(this.name, meth, mv, modes);
methods.add(mv);
for (int i = size; i < text.size(); ++i) {
......@@ -232,7 +235,7 @@ public class DecompilerClassVisitor extends ClassAdapter {
private AnnotationVisitor getDummyAnnotationVisitor(){
if (dummyAnnVisitor == null) {
dummyAnnVisitor = new AnnotationVisitor() {
dummyAnnVisitor = new AnnotationVisitor(Opcodes.ASM4) {
public void visit(String n, Object value) {
/* empty */
}
......
......@@ -8,20 +8,19 @@ import java.util.Map;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.AbstractVisitor;
import de.loskutov.bco.asm.CommentedClassVisitor.CommentedAnnotationVisitor;
import org.objectweb.asm.util.ASMifierMethodVisitor;
import org.objectweb.asm.util.TraceAnnotationVisitor;
import org.objectweb.asm.util.TraceMethodVisitor;
/**
* @author Eric Bruneton
*/
public class DecompilerMethodVisitor extends MethodAdapter {
public class DecompilerMethodVisitor extends MethodVisitor {
private final String owner;
......@@ -39,10 +38,15 @@ public class DecompilerMethodVisitor extends MethodAdapter {
public DecompilerMethodVisitor(final String owner, final MethodNode meth,
final MethodVisitor mv, BitSet modes) {
super(mv);
super(Opcodes.ASM4, mv);
this.owner = owner;
this.modes = modes;
this.text = ((AbstractVisitor) mv).getText();
// TODO ASM 4.0 transition: "tv" and "sv" fields are invisible for us in ASM 4.0 RC2
if(mv instanceof TraceMethodVisitor) {
this.text = ((TraceMethodVisitor)mv).tv.text;
} else {
this.text = ((ASMifierMethodVisitor)mv).sv.text;
}
this.meth = meth;
this.lineNumbers = new HashMap();
}
......@@ -54,9 +58,10 @@ public class DecompilerMethodVisitor extends MethodAdapter {
public AnnotationVisitor visitAnnotationDefault() {
AnnotationVisitor annVisitor = super.visitAnnotationDefault();
AnnotationVisitor visitor = meth.visitAnnotationDefault();
if (annVisitor instanceof CommentedAnnotationVisitor) {
CommentedAnnotationVisitor av = (CommentedAnnotationVisitor) annVisitor;
av.setAnnotationVisitor(visitor);
if (annVisitor instanceof TraceAnnotationVisitor) {
TraceAnnotationVisitor av = (TraceAnnotationVisitor) annVisitor;
// TODO ASM 4.0 transition: setNext() is invisible for us in ASM 4.0 RC2
av.setNext(visitor);
}
return annVisitor;
}
......@@ -64,9 +69,10 @@ public class DecompilerMethodVisitor extends MethodAdapter {
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
AnnotationVisitor annVisitor = super.visitAnnotation(desc, visible);
AnnotationVisitor visitor = meth.visitAnnotation(desc, visible);
if (annVisitor instanceof CommentedAnnotationVisitor) {
CommentedAnnotationVisitor av = (CommentedAnnotationVisitor) annVisitor;
av.setAnnotationVisitor(visitor);
if (annVisitor instanceof TraceAnnotationVisitor) {
TraceAnnotationVisitor av = (TraceAnnotationVisitor) annVisitor;
// TODO ASM 4.0 transition: setNext() is invisible for us in ASM 4.0 RC2
av.setNext(visitor);
}
return annVisitor;
}
......@@ -77,9 +83,10 @@ public class DecompilerMethodVisitor extends MethodAdapter {
parameter, desc, visible);
AnnotationVisitor visitor = meth.visitParameterAnnotation(
parameter, desc, visible);
if (annVisitor instanceof CommentedAnnotationVisitor) {
CommentedAnnotationVisitor av = (CommentedAnnotationVisitor) annVisitor;
av.setAnnotationVisitor(visitor);
if (annVisitor instanceof TraceAnnotationVisitor) {
TraceAnnotationVisitor av = (TraceAnnotationVisitor) annVisitor;
// TODO ASM 4.0 transition: setNext() is invisible for us in ASM 4.0 RC2
av.setNext(visitor);
}
return annVisitor;
}
......
package de.loskutov.bco.asm;
import java.util.List;
import org.objectweb.asm.ClassVisitor;
public interface ICommentedClassVisitor {
ClassVisitor getClassVisitor();
List getText();
}
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