src/share/classes/jdk/internal/org/objectweb/asm/util/ASMifier.java
Print this page
*** 28,38 ****
* However, the following notice accompanied the original version of this
* file:
*
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000-2011 INRIA, France Telecom
- * Copyright (c) 2011 Google
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
--- 28,37 ----
*** 68,77 ****
--- 67,77 ----
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.Handle;
import jdk.internal.org.objectweb.asm.Label;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.Type;
+ import jdk.internal.org.objectweb.asm.TypePath;
/**
* A {@link Printer} that prints the ASM code to generate the classes if visits.
*
* @author Eric Bruneton
*** 113,132 ****
* Constructs a new {@link ASMifier}. <i>Subclasses must not use this
* constructor</i>. Instead, they must use the
* {@link #ASMifier(int, String, int)} version.
*/
public ASMifier() {
! this(Opcodes.ASM4, "cw", 0);
}
/**
* Constructs a new {@link ASMifier}.
*
! * @param api the ASM API version implemented by this class. Must be one of
! * {@link Opcodes#ASM4}.
! * @param name the name of the visitor variable in the produced code.
! * @param id identifier of the annotation visitor variable in the produced
* code.
*/
protected ASMifier(final int api, final String name, final int id) {
super(api);
this.name = name;
--- 113,135 ----
* Constructs a new {@link ASMifier}. <i>Subclasses must not use this
* constructor</i>. Instead, they must use the
* {@link #ASMifier(int, String, int)} version.
*/
public ASMifier() {
! this(Opcodes.ASM5, "cw", 0);
}
/**
* Constructs a new {@link ASMifier}.
*
! * @param api
! * the ASM API version implemented by this class. Must be one of
! * {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
! * @param name
! * the name of the visitor variable in the produced code.
! * @param id
! * identifier of the annotation visitor variable in the produced
* code.
*/
protected ASMifier(final int api, final String name, final int id) {
super(api);
this.name = name;
*** 133,149 ****
this.id = id;
}
/**
* Prints the ASM source code to generate the given class to the standard
! * output. <p> Usage: ASMifier [-debug] <binary
! * class name or class file name>
*
! * @param args the command line arguments.
*
! * @throws Exception if the class cannot be found, or if an IO exception
! * occurs.
*/
public static void main(final String[] args) throws Exception {
int i = 0;
int flags = ClassReader.SKIP_DEBUG;
--- 136,154 ----
this.id = id;
}
/**
* Prints the ASM source code to generate the given class to the standard
! * output.
! * <p>
! * Usage: ASMifier [-debug] <binary class name or class file name>
*
! * @param args
! * the command line arguments.
*
! * @throws Exception
! * if the class cannot be found, or if an IO exception occurs.
*/
public static void main(final String[] args) throws Exception {
int i = 0;
int flags = ClassReader.SKIP_DEBUG;
*** 157,197 ****
if (args.length != 2) {
ok = false;
}
}
if (!ok) {
! System.err.println("Prints the ASM code to generate the given class.");
System.err.println("Usage: ASMifier [-debug] "
+ "<fully qualified class name or class file name>");
return;
}
ClassReader cr;
if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1
! || args[i].indexOf('/') > -1)
! {
cr = new ClassReader(new FileInputStream(args[i]));
} else {
cr = new ClassReader(args[i]);
}
! cr.accept(new TraceClassVisitor(null,
! new ASMifier(),
! new PrintWriter(System.out)), flags);
}
// ------------------------------------------------------------------------
// Classes
// ------------------------------------------------------------------------
@Override
! public void visit(
! final int version,
! final int access,
! final String name,
! final String signature,
! final String superName,
! final String[] interfaces)
! {
String simpleName;
int n = name.lastIndexOf('/');
if (n == -1) {
simpleName = name;
} else {
--- 162,196 ----
if (args.length != 2) {
ok = false;
}
}
if (!ok) {
! System.err
! .println("Prints the ASM code to generate the given class.");
System.err.println("Usage: ASMifier [-debug] "
+ "<fully qualified class name or class file name>");
return;
}
ClassReader cr;
if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1
! || args[i].indexOf('/') > -1) {
cr = new ClassReader(new FileInputStream(args[i]));
} else {
cr = new ClassReader(args[i]);
}
! cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
! System.out)), flags);
}
// ------------------------------------------------------------------------
// Classes
// ------------------------------------------------------------------------
@Override
! public void visit(final int version, final int access, final String name,
! final String signature, final String superName,
! final String[] interfaces) {
String simpleName;
int n = name.lastIndexOf('/');
if (n == -1) {
simpleName = name;
} else {
*** 270,284 ****
buf.append(");\n\n");
text.add(buf.toString());
}
@Override
! public void visitOuterClass(
! final String owner,
! final String name,
! final String desc)
! {
buf.setLength(0);
buf.append("cw.visitOuterClass(");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
--- 269,280 ----
buf.append(");\n\n");
text.add(buf.toString());
}
@Override
! public void visitOuterClass(final String owner, final String name,
! final String desc) {
buf.setLength(0);
buf.append("cw.visitOuterClass(");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
*** 287,315 ****
buf.append(");\n\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitClassAnnotation(
! final String desc,
! final boolean visible)
! {
return visitAnnotation(desc, visible);
}
@Override
public void visitClassAttribute(final Attribute attr) {
visitAttribute(attr);
}
@Override
! public void visitInnerClass(
! final String name,
! final String outerName,
! final String innerName,
! final int access)
! {
buf.setLength(0);
buf.append("cw.visitInnerClass(");
appendConstant(name);
buf.append(", ");
appendConstant(outerName);
--- 283,311 ----
buf.append(");\n\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitClassAnnotation(final String desc,
! final boolean visible) {
return visitAnnotation(desc, visible);
}
@Override
+ public ASMifier visitClassTypeAnnotation(final int typeRef,
+ final TypePath typePath, final String desc, final boolean visible) {
+ return visitTypeAnnotation(typeRef, typePath, desc, visible);
+ }
+
+ @Override
public void visitClassAttribute(final Attribute attr) {
visitAttribute(attr);
}
@Override
! public void visitInnerClass(final String name, final String outerName,
! final String innerName, final int access) {
buf.setLength(0);
buf.append("cw.visitInnerClass(");
appendConstant(name);
buf.append(", ");
appendConstant(outerName);
*** 320,336 ****
buf.append(");\n\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitField(
! final int access,
! final String name,
! final String desc,
! final String signature,
! final Object value)
! {
buf.setLength(0);
buf.append("{\n");
buf.append("fv = cw.visitField(");
appendAccess(access | ACCESS_FIELD);
buf.append(", ");
--- 316,327 ----
buf.append(");\n\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitField(final int access, final String name,
! final String desc, final String signature, final Object value) {
buf.setLength(0);
buf.append("{\n");
buf.append("fv = cw.visitField(");
appendAccess(access | ACCESS_FIELD);
buf.append(", ");
*** 348,364 ****
text.add("}\n");
return a;
}
@Override
! public ASMifier visitMethod(
! final int access,
! final String name,
! final String desc,
! final String signature,
! final String[] exceptions)
! {
buf.setLength(0);
buf.append("{\n");
buf.append("mv = cw.visitMethod(");
appendAccess(access);
buf.append(", ");
--- 339,350 ----
text.add("}\n");
return a;
}
@Override
! public ASMifier visitMethod(final int access, final String name,
! final String desc, final String signature, final String[] exceptions) {
buf.setLength(0);
buf.append("{\n");
buf.append("mv = cw.visitMethod(");
appendAccess(access);
buf.append(", ");
*** 408,422 ****
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitEnum(
! final String name,
! final String desc,
! final String value)
! {
buf.setLength(0);
buf.append("av").append(id).append(".visitEnum(");
appendConstant(buf, name);
buf.append(", ");
appendConstant(buf, desc);
--- 394,405 ----
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitEnum(final String name, final String desc,
! final String value) {
buf.setLength(0);
buf.append("av").append(id).append(".visitEnum(");
appendConstant(buf, name);
buf.append(", ");
appendConstant(buf, desc);
*** 425,438 ****
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitAnnotation(
! final String name,
! final String desc)
! {
buf.setLength(0);
buf.append("{\n");
buf.append("AnnotationVisitor av").append(id + 1).append(" = av");
buf.append(id).append(".visitAnnotation(");
appendConstant(buf, name);
--- 408,418 ----
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitAnnotation(final String name, final String desc) {
buf.setLength(0);
buf.append("{\n");
buf.append("AnnotationVisitor av").append(id + 1).append(" = av");
buf.append(id).append(".visitAnnotation(");
appendConstant(buf, name);
*** 471,488 ****
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
@Override
! public ASMifier visitFieldAnnotation(
! final String desc,
! final boolean visible)
! {
return visitAnnotation(desc, visible);
}
@Override
public void visitFieldAttribute(final Attribute attr) {
visitAttribute(attr);
}
@Override
--- 451,472 ----
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
@Override
! public ASMifier visitFieldAnnotation(final String desc,
! final boolean visible) {
return visitAnnotation(desc, visible);
}
@Override
+ public ASMifier visitFieldTypeAnnotation(final int typeRef,
+ final TypePath typePath, final String desc, final boolean visible) {
+ return visitTypeAnnotation(typeRef, typePath, desc, visible);
+ }
+
+ @Override
public void visitFieldAttribute(final Attribute attr) {
visitAttribute(attr);
}
@Override
*** 495,535 ****
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
@Override
public ASMifier visitAnnotationDefault() {
buf.setLength(0);
! buf.append("{\n")
! .append("av0 = ")
! .append(name)
.append(".visitAnnotationDefault();\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
text.add(a.getText());
text.add("}\n");
return a;
}
@Override
! public ASMifier visitMethodAnnotation(
! final String desc,
! final boolean visible)
! {
return visitAnnotation(desc, visible);
}
@Override
! public ASMifier visitParameterAnnotation(
! final int parameter,
! final String desc,
! final boolean visible)
! {
buf.setLength(0);
! buf.append("{\n")
! .append("av0 = ").append(name).append(".visitParameterAnnotation(")
! .append(parameter)
.append(", ");
appendConstant(desc);
buf.append(", ").append(visible).append(");\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
--- 479,526 ----
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
@Override
+ public void visitParameter(String parameterName, int access) {
+ buf.setLength(0);
+ buf.append(name).append(".visitParameter(").append(parameterName)
+ .append(", ");
+ appendAccess(access);
+ text.add(buf.append(");\n").toString());
+ }
+
+ @Override
public ASMifier visitAnnotationDefault() {
buf.setLength(0);
! buf.append("{\n").append("av0 = ").append(name)
.append(".visitAnnotationDefault();\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
text.add(a.getText());
text.add("}\n");
return a;
}
@Override
! public ASMifier visitMethodAnnotation(final String desc,
! final boolean visible) {
return visitAnnotation(desc, visible);
}
@Override
! public ASMifier visitMethodTypeAnnotation(final int typeRef,
! final TypePath typePath, final String desc, final boolean visible) {
! return visitTypeAnnotation(typeRef, typePath, desc, visible);
! }
!
! @Override
! public ASMifier visitParameterAnnotation(final int parameter,
! final String desc, final boolean visible) {
buf.setLength(0);
! buf.append("{\n").append("av0 = ").append(name)
! .append(".visitParameterAnnotation(").append(parameter)
.append(", ");
appendConstant(desc);
buf.append(", ").append(visible).append(");\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
*** 547,563 ****
public void visitCode() {
text.add(name + ".visitCode();\n");
}
@Override
! public void visitFrame(
! final int type,
! final int nLocal,
! final Object[] local,
! final int nStack,
! final Object[] stack)
! {
buf.setLength(0);
switch (type) {
case Opcodes.F_NEW:
case Opcodes.F_FULL:
declareFrameTypes(nLocal, local);
--- 538,549 ----
public void visitCode() {
text.add(name + ".visitCode();\n");
}
@Override
! public void visitFrame(final int type, final int nLocal,
! final Object[] local, final int nStack, final Object[] stack) {
buf.setLength(0);
switch (type) {
case Opcodes.F_NEW:
case Opcodes.F_FULL:
declareFrameTypes(nLocal, local);
*** 574,599 ****
buf.append('}');
break;
case Opcodes.F_APPEND:
declareFrameTypes(nLocal, local);
buf.append(name).append(".visitFrame(Opcodes.F_APPEND,")
! .append(nLocal)
! .append(", new Object[] {");
appendFrameTypes(nLocal, local);
buf.append("}, 0, null");
break;
case Opcodes.F_CHOP:
buf.append(name).append(".visitFrame(Opcodes.F_CHOP,")
! .append(nLocal)
! .append(", null, 0, null");
break;
case Opcodes.F_SAME:
! buf.append(name).append(".visitFrame(Opcodes.F_SAME, 0, null, 0, null");
break;
case Opcodes.F_SAME1:
declareFrameTypes(1, stack);
! buf.append(name).append(".visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {");
appendFrameTypes(1, stack);
buf.append('}');
break;
}
buf.append(");\n");
--- 560,585 ----
buf.append('}');
break;
case Opcodes.F_APPEND:
declareFrameTypes(nLocal, local);
buf.append(name).append(".visitFrame(Opcodes.F_APPEND,")
! .append(nLocal).append(", new Object[] {");
appendFrameTypes(nLocal, local);
buf.append("}, 0, null");
break;
case Opcodes.F_CHOP:
buf.append(name).append(".visitFrame(Opcodes.F_CHOP,")
! .append(nLocal).append(", null, 0, null");
break;
case Opcodes.F_SAME:
! buf.append(name).append(
! ".visitFrame(Opcodes.F_SAME, 0, null, 0, null");
break;
case Opcodes.F_SAME1:
declareFrameTypes(1, stack);
! buf.append(name).append(
! ".visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {");
appendFrameTypes(1, stack);
buf.append('}');
break;
}
buf.append(");\n");
*** 601,611 ****
}
@Override
public void visitInsn(final int opcode) {
buf.setLength(0);
! buf.append(name).append(".visitInsn(").append(OPCODES[opcode]).append(");\n");
text.add(buf.toString());
}
@Override
public void visitIntInsn(final int opcode, final int operand) {
--- 587,598 ----
}
@Override
public void visitInsn(final int opcode) {
buf.setLength(0);
! buf.append(name).append(".visitInsn(").append(OPCODES[opcode])
! .append(");\n");
text.add(buf.toString());
}
@Override
public void visitIntInsn(final int opcode, final int operand) {
*** 612,658 ****
buf.setLength(0);
buf.append(name)
.append(".visitIntInsn(")
.append(OPCODES[opcode])
.append(", ")
! .append(opcode == Opcodes.NEWARRAY
! ? TYPES[operand]
! : Integer.toString(operand))
! .append(");\n");
text.add(buf.toString());
}
@Override
public void visitVarInsn(final int opcode, final int var) {
buf.setLength(0);
! buf.append(name)
! .append(".visitVarInsn(")
! .append(OPCODES[opcode])
! .append(", ")
! .append(var)
! .append(");\n");
text.add(buf.toString());
}
@Override
public void visitTypeInsn(final int opcode, final String type) {
buf.setLength(0);
! buf.append(name).append(".visitTypeInsn(").append(OPCODES[opcode]).append(", ");
appendConstant(type);
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitFieldInsn(
! final int opcode,
! final String owner,
! final String name,
! final String desc)
! {
buf.setLength(0);
! buf.append(this.name).append(".visitFieldInsn(").append(OPCODES[opcode]).append(", ");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
--- 599,637 ----
buf.setLength(0);
buf.append(name)
.append(".visitIntInsn(")
.append(OPCODES[opcode])
.append(", ")
! .append(opcode == Opcodes.NEWARRAY ? TYPES[operand] : Integer
! .toString(operand)).append(");\n");
text.add(buf.toString());
}
@Override
public void visitVarInsn(final int opcode, final int var) {
buf.setLength(0);
! buf.append(name).append(".visitVarInsn(").append(OPCODES[opcode])
! .append(", ").append(var).append(");\n");
text.add(buf.toString());
}
@Override
public void visitTypeInsn(final int opcode, final String type) {
buf.setLength(0);
! buf.append(name).append(".visitTypeInsn(").append(OPCODES[opcode])
! .append(", ");
appendConstant(type);
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitFieldInsn(final int opcode, final String owner,
! final String name, final String desc) {
buf.setLength(0);
! buf.append(this.name).append(".visitFieldInsn(")
! .append(OPCODES[opcode]).append(", ");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
*** 659,676 ****
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitMethodInsn(
! final int opcode,
! final String owner,
! final String name,
! final String desc)
! {
buf.setLength(0);
! buf.append(this.name).append(".visitMethodInsn(").append(OPCODES[opcode]).append(", ");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
--- 638,652 ----
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitMethodInsn(final int opcode, final String owner,
! final String name, final String desc) {
buf.setLength(0);
! buf.append(this.name).append(".visitMethodInsn(")
! .append(OPCODES[opcode]).append(", ");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
*** 677,692 ****
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitInvokeDynamicInsn(
! String name,
! String desc,
! Handle bsm,
! Object... bsmArgs)
! {
buf.setLength(0);
buf.append(this.name).append(".visitInvokeDynamicInsn(");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
--- 653,664 ----
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
! Object... bsmArgs) {
buf.setLength(0);
buf.append(this.name).append(".visitInvokeDynamicInsn(");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
*** 705,715 ****
@Override
public void visitJumpInsn(final int opcode, final Label label) {
buf.setLength(0);
declareLabel(label);
! buf.append(name).append(".visitJumpInsn(").append(OPCODES[opcode]).append(", ");
appendLabel(label);
buf.append(");\n");
text.add(buf.toString());
}
--- 677,688 ----
@Override
public void visitJumpInsn(final int opcode, final Label label) {
buf.setLength(0);
declareLabel(label);
! buf.append(name).append(".visitJumpInsn(").append(OPCODES[opcode])
! .append(", ");
appendLabel(label);
buf.append(");\n");
text.add(buf.toString());
}
*** 733,770 ****
}
@Override
public void visitIincInsn(final int var, final int increment) {
buf.setLength(0);
! buf.append(name)
! .append(".visitIincInsn(")
! .append(var)
! .append(", ")
! .append(increment)
! .append(");\n");
text.add(buf.toString());
}
@Override
! public void visitTableSwitchInsn(
! final int min,
! final int max,
! final Label dflt,
! final Label... labels)
! {
buf.setLength(0);
for (int i = 0; i < labels.length; ++i) {
declareLabel(labels[i]);
}
declareLabel(dflt);
! buf.append(name)
! .append(".visitTableSwitchInsn(")
! .append(min)
! .append(", ")
! .append(max)
! .append(", ");
appendLabel(dflt);
buf.append(", new Label[] {");
for (int i = 0; i < labels.length; ++i) {
buf.append(i == 0 ? " " : ", ");
appendLabel(labels[i]);
--- 706,731 ----
}
@Override
public void visitIincInsn(final int var, final int increment) {
buf.setLength(0);
! buf.append(name).append(".visitIincInsn(").append(var).append(", ")
! .append(increment).append(");\n");
text.add(buf.toString());
}
@Override
! public void visitTableSwitchInsn(final int min, final int max,
! final Label dflt, final Label... labels) {
buf.setLength(0);
for (int i = 0; i < labels.length; ++i) {
declareLabel(labels[i]);
}
declareLabel(dflt);
! buf.append(name).append(".visitTableSwitchInsn(").append(min)
! .append(", ").append(max).append(", ");
appendLabel(dflt);
buf.append(", new Label[] {");
for (int i = 0; i < labels.length; ++i) {
buf.append(i == 0 ? " " : ", ");
appendLabel(labels[i]);
*** 772,786 ****
buf.append(" });\n");
text.add(buf.toString());
}
@Override
! public void visitLookupSwitchInsn(
! final Label dflt,
! final int[] keys,
! final Label[] labels)
! {
buf.setLength(0);
for (int i = 0; i < labels.length; ++i) {
declareLabel(labels[i]);
}
declareLabel(dflt);
--- 733,744 ----
buf.append(" });\n");
text.add(buf.toString());
}
@Override
! public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
! final Label[] labels) {
buf.setLength(0);
for (int i = 0; i < labels.length; ++i) {
declareLabel(labels[i]);
}
declareLabel(dflt);
*** 808,823 ****
buf.append(", ").append(dims).append(");\n");
text.add(buf.toString());
}
@Override
! public void visitTryCatchBlock(
! final Label start,
! final Label end,
! final Label handler,
! final String type)
! {
buf.setLength(0);
declareLabel(start);
declareLabel(end);
declareLabel(handler);
buf.append(name).append(".visitTryCatchBlock(");
--- 766,784 ----
buf.append(", ").append(dims).append(");\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitInsnAnnotation(final int typeRef,
! final TypePath typePath, final String desc, final boolean visible) {
! return visitTypeAnnotation("visitInsnAnnotation", typeRef, typePath,
! desc, visible);
! }
!
! @Override
! public void visitTryCatchBlock(final Label start, final Label end,
! final Label handler, final String type) {
buf.setLength(0);
declareLabel(start);
declareLabel(end);
declareLabel(handler);
buf.append(name).append(".visitTryCatchBlock(");
*** 831,848 ****
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public void visitLocalVariable(
! final String name,
! final String desc,
! final String signature,
! final Label start,
! final Label end,
! final int index)
! {
buf.setLength(0);
buf.append(this.name).append(".visitLocalVariable(");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
--- 792,811 ----
buf.append(");\n");
text.add(buf.toString());
}
@Override
! public ASMifier visitTryCatchAnnotation(final int typeRef,
! final TypePath typePath, final String desc, final boolean visible) {
! return visitTypeAnnotation("visitTryCatchAnnotation", typeRef,
! typePath, desc, visible);
! }
!
! @Override
! public void visitLocalVariable(final String name, final String desc,
! final String signature, final Label start, final Label end,
! final int index) {
buf.setLength(0);
buf.append(this.name).append(".visitLocalVariable(");
appendConstant(name);
buf.append(", ");
appendConstant(desc);
*** 855,864 ****
--- 818,860 ----
buf.append(", ").append(index).append(");\n");
text.add(buf.toString());
}
@Override
+ public Printer visitLocalVariableAnnotation(int typeRef, TypePath typePath,
+ Label[] start, Label[] end, int[] index, String desc,
+ boolean visible) {
+ buf.setLength(0);
+ buf.append("{\n").append("av0 = ").append(name)
+ .append(".visitLocalVariableAnnotation(");
+ buf.append(typeRef);
+ buf.append(", TypePath.fromString(\"").append(typePath).append("\"), ");
+ buf.append("new Label[] {");
+ for (int i = 0; i < start.length; ++i) {
+ buf.append(i == 0 ? " " : ", ");
+ appendLabel(start[i]);
+ }
+ buf.append(" }, new Label[] {");
+ for (int i = 0; i < end.length; ++i) {
+ buf.append(i == 0 ? " " : ", ");
+ appendLabel(end[i]);
+ }
+ buf.append(" }, new int[] {");
+ for (int i = 0; i < index.length; ++i) {
+ buf.append(i == 0 ? " " : ", ").append(index[i]);
+ }
+ buf.append(" }, ");
+ appendConstant(desc);
+ buf.append(", ").append(visible).append(");\n");
+ text.add(buf.toString());
+ ASMifier a = createASMifier("av", 0);
+ text.add(a.getText());
+ text.add("}\n");
+ return a;
+ }
+
+ @Override
public void visitLineNumber(final int line, final Label start) {
buf.setLength(0);
buf.append(name).append(".visitLineNumber(").append(line).append(", ");
appendLabel(start);
buf.append(");\n");
*** 866,881 ****
}
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
buf.setLength(0);
! buf.append(name)
! .append(".visitMaxs(")
! .append(maxStack)
! .append(", ")
! .append(maxLocals)
! .append(");\n");
text.add(buf.toString());
}
@Override
public void visitMethodEnd() {
--- 862,873 ----
}
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
buf.setLength(0);
! buf.append(name).append(".visitMaxs(").append(maxStack).append(", ")
! .append(maxLocals).append(");\n");
text.add(buf.toString());
}
@Override
public void visitMethodEnd() {
*** 886,903 ****
// ------------------------------------------------------------------------
// Common methods
// ------------------------------------------------------------------------
! public ASMifier visitAnnotation(
! final String desc,
! final boolean visible)
! {
buf.setLength(0);
! buf.append("{\n")
! .append("av0 = ")
! .append(name)
.append(".visitAnnotation(");
appendConstant(desc);
buf.append(", ").append(visible).append(");\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
--- 878,890 ----
// ------------------------------------------------------------------------
// Common methods
// ------------------------------------------------------------------------
! public ASMifier visitAnnotation(final String desc, final boolean visible) {
buf.setLength(0);
! buf.append("{\n").append("av0 = ").append(name)
.append(".visitAnnotation(");
appendConstant(desc);
buf.append(", ").append(visible).append(");\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
*** 904,913 ****
--- 891,922 ----
text.add(a.getText());
text.add("}\n");
return a;
}
+ public ASMifier visitTypeAnnotation(final int typeRef,
+ final TypePath typePath, final String desc, final boolean visible) {
+ return visitTypeAnnotation("visitTypeAnnotation", typeRef, typePath,
+ desc, visible);
+ }
+
+ public ASMifier visitTypeAnnotation(final String method, final int typeRef,
+ final TypePath typePath, final String desc, final boolean visible) {
+ buf.setLength(0);
+ buf.append("{\n").append("av0 = ").append(name).append(".")
+ .append(method).append("(");
+ buf.append(typeRef);
+ buf.append(", TypePath.fromString(\"").append(typePath).append("\"), ");
+ appendConstant(desc);
+ buf.append(", ").append(visible).append(");\n");
+ text.add(buf.toString());
+ ASMifier a = createASMifier("av", 0);
+ text.add(a.getText());
+ text.add("}\n");
+ return a;
+ }
+
public void visitAttribute(final Attribute attr) {
buf.setLength(0);
buf.append("// ATTRIBUTE ").append(attr.type).append('\n');
if (attr instanceof ASMifiable) {
if (labelNames == null) {
*** 924,941 ****
// ------------------------------------------------------------------------
// Utility methods
// ------------------------------------------------------------------------
protected ASMifier createASMifier(final String name, final int id) {
! return new ASMifier(Opcodes.ASM4, name, id);
}
/**
! * Appends a string representation of the given access modifiers to {@link
! * #buf buf}.
*
! * @param access some access modifiers.
*/
void appendAccess(final int access) {
boolean first = true;
if ((access & Opcodes.ACC_PUBLIC) != 0) {
buf.append("ACC_PUBLIC");
--- 933,951 ----
// ------------------------------------------------------------------------
// Utility methods
// ------------------------------------------------------------------------
protected ASMifier createASMifier(final String name, final int id) {
! return new ASMifier(Opcodes.ASM5, name, id);
}
/**
! * Appends a string representation of the given access modifiers to
! * {@link #buf buf}.
*
! * @param access
! * some access modifiers.
*/
void appendAccess(final int access) {
boolean first = true;
if ((access & Opcodes.ACC_PUBLIC) != 0) {
buf.append("ACC_PUBLIC");
*** 973,1039 ****
buf.append("ACC_SUPER");
}
first = false;
}
if ((access & Opcodes.ACC_VOLATILE) != 0
! && (access & ACCESS_FIELD) != 0)
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_VOLATILE");
first = false;
}
if ((access & Opcodes.ACC_BRIDGE) != 0 && (access & ACCESS_CLASS) == 0
! && (access & ACCESS_FIELD) == 0)
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_BRIDGE");
first = false;
}
if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0
! && (access & ACCESS_FIELD) == 0)
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_VARARGS");
first = false;
}
if ((access & Opcodes.ACC_TRANSIENT) != 0
! && (access & ACCESS_FIELD) != 0)
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_TRANSIENT");
first = false;
}
if ((access & Opcodes.ACC_NATIVE) != 0 && (access & ACCESS_CLASS) == 0
! && (access & ACCESS_FIELD) == 0)
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_NATIVE");
first = false;
}
if ((access & Opcodes.ACC_ENUM) != 0
&& ((access & ACCESS_CLASS) != 0
! || (access & ACCESS_FIELD) != 0 || (access & ACCESS_INNER) != 0))
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_ENUM");
first = false;
}
if ((access & Opcodes.ACC_ANNOTATION) != 0
! && ((access & ACCESS_CLASS) != 0 || (access & ACCESS_INNER) != 0))
! {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_ANNOTATION");
first = false;
--- 983,1042 ----
buf.append("ACC_SUPER");
}
first = false;
}
if ((access & Opcodes.ACC_VOLATILE) != 0
! && (access & ACCESS_FIELD) != 0) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_VOLATILE");
first = false;
}
if ((access & Opcodes.ACC_BRIDGE) != 0 && (access & ACCESS_CLASS) == 0
! && (access & ACCESS_FIELD) == 0) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_BRIDGE");
first = false;
}
if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0
! && (access & ACCESS_FIELD) == 0) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_VARARGS");
first = false;
}
if ((access & Opcodes.ACC_TRANSIENT) != 0
! && (access & ACCESS_FIELD) != 0) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_TRANSIENT");
first = false;
}
if ((access & Opcodes.ACC_NATIVE) != 0 && (access & ACCESS_CLASS) == 0
! && (access & ACCESS_FIELD) == 0) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_NATIVE");
first = false;
}
if ((access & Opcodes.ACC_ENUM) != 0
&& ((access & ACCESS_CLASS) != 0
! || (access & ACCESS_FIELD) != 0 || (access & ACCESS_INNER) != 0)) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_ENUM");
first = false;
}
if ((access & Opcodes.ACC_ANNOTATION) != 0
! && ((access & ACCESS_CLASS) != 0 || (access & ACCESS_INNER) != 0)) {
if (!first) {
buf.append(" + ");
}
buf.append("ACC_ANNOTATION");
first = false;
*** 1080,1090 ****
/**
* Appends a string representation of the given constant to the given
* buffer.
*
! * @param cst an {@link Integer}, {@link Float}, {@link Long},
* {@link Double} or {@link String} object. May be <tt>null</tt>.
*/
protected void appendConstant(final Object cst) {
appendConstant(buf, cst);
}
--- 1083,1094 ----
/**
* Appends a string representation of the given constant to the given
* buffer.
*
! * @param cst
! * an {@link Integer}, {@link Float}, {@link Long},
* {@link Double} or {@link String} object. May be <tt>null</tt>.
*/
protected void appendConstant(final Object cst) {
appendConstant(buf, cst);
}
*** 1091,1102 ****
/**
* Appends a string representation of the given constant to the given
* buffer.
*
! * @param buf a string buffer.
! * @param cst an {@link Integer}, {@link Float}, {@link Long},
* {@link Double} or {@link String} object. May be <tt>null</tt>.
*/
static void appendConstant(final StringBuffer buf, final Object cst) {
if (cst == null) {
buf.append("null");
--- 1095,1108 ----
/**
* Appends a string representation of the given constant to the given
* buffer.
*
! * @param buf
! * a string buffer.
! * @param cst
! * an {@link Integer}, {@link Float}, {@link Long},
* {@link Double} or {@link String} object. May be <tt>null</tt>.
*/
static void appendConstant(final StringBuffer buf, final Object cst) {
if (cst == null) {
buf.append("null");
*** 1107,1124 ****
buf.append(((Type) cst).getDescriptor());
buf.append("\")");
} else if (cst instanceof Handle) {
buf.append("new Handle(");
Handle h = (Handle) cst;
! buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()]).append(", \"");
buf.append(h.getOwner()).append("\", \"");
buf.append(h.getName()).append("\", \"");
buf.append(h.getDesc()).append("\")");
} else if (cst instanceof Byte) {
buf.append("new Byte((byte)").append(cst).append(')');
} else if (cst instanceof Boolean) {
! buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE" : "Boolean.FALSE");
} else if (cst instanceof Short) {
buf.append("new Short((short)").append(cst).append(')');
} else if (cst instanceof Character) {
int c = ((Character) cst).charValue();
buf.append("new Character((char)").append(c).append(')');
--- 1113,1132 ----
buf.append(((Type) cst).getDescriptor());
buf.append("\")");
} else if (cst instanceof Handle) {
buf.append("new Handle(");
Handle h = (Handle) cst;
! buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()])
! .append(", \"");
buf.append(h.getOwner()).append("\", \"");
buf.append(h.getName()).append("\", \"");
buf.append(h.getDesc()).append("\")");
} else if (cst instanceof Byte) {
buf.append("new Byte((byte)").append(cst).append(')');
} else if (cst instanceof Boolean) {
! buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE"
! : "Boolean.FALSE");
} else if (cst instanceof Short) {
buf.append("new Short((short)").append(cst).append(')');
} else if (cst instanceof Character) {
int c = ((Character) cst).charValue();
buf.append("new Character((char)").append(c).append(')');
*** 1153,1164 ****
buf.append('}');
} else if (cst instanceof char[]) {
char[] v = (char[]) cst;
buf.append("new char[] {");
for (int i = 0; i < v.length; i++) {
! buf.append(i == 0 ? "" : ",")
! .append("(char)")
.append((int) v[i]);
}
buf.append('}');
} else if (cst instanceof int[]) {
int[] v = (int[]) cst;
--- 1161,1171 ----
buf.append('}');
} else if (cst instanceof char[]) {
char[] v = (char[]) cst;
buf.append("new char[] {");
for (int i = 0; i < v.length; i++) {
! buf.append(i == 0 ? "" : ",").append("(char)")
.append((int) v[i]);
}
buf.append('}');
} else if (cst instanceof int[]) {
int[] v = (int[]) cst;
*** 1239,1249 ****
/**
* Appends a declaration of the given label to {@link #buf buf}. This
* declaration is of the form "Label lXXX = new Label();". Does nothing if
* the given label has already been declared.
*
! * @param l a label.
*/
protected void declareLabel(final Label l) {
if (labelNames == null) {
labelNames = new HashMap<Label, String>();
}
--- 1246,1257 ----
/**
* Appends a declaration of the given label to {@link #buf buf}. This
* declaration is of the form "Label lXXX = new Label();". Does nothing if
* the given label has already been declared.
*
! * @param l
! * a label.
*/
protected void declareLabel(final Label l) {
if (labelNames == null) {
labelNames = new HashMap<Label, String>();
}
*** 1255,1268 ****
}
}
/**
* Appends the name of the given label to {@link #buf buf}. The given label
! * <i>must</i> already have a name. One way to ensure this is to always
! * call {@link #declareLabel declared} before calling this method.
*
! * @param l a label.
*/
protected void appendLabel(final Label l) {
buf.append(labelNames.get(l));
}
}
--- 1263,1277 ----
}
}
/**
* Appends the name of the given label to {@link #buf buf}. The given label
! * <i>must</i> already have a name. One way to ensure this is to always call
! * {@link #declareLabel declared} before calling this method.
*
! * @param l
! * a label.
*/
protected void appendLabel(final Label l) {
buf.append(labelNames.get(l));
}
}