📄 asmcontenthandler.java
字号:
stack);
} else if (type.equals("APPEND")) {
getCodeVisitor().visitFrame(Opcodes.F_APPEND,
nLocal,
local,
0,
null);
} else if (type.equals("CHOP")) {
getCodeVisitor().visitFrame(Opcodes.F_CHOP,
Integer.parseInt(count),
null,
0,
null);
} else if (type.equals("SAME")) {
getCodeVisitor().visitFrame(Opcodes.F_SAME, 0, null, 0, null);
} else if (type.equals("SAME1")) {
getCodeVisitor().visitFrame(Opcodes.F_SAME1,
0,
null,
nStack,
stack);
}
}
}
private final class FrameTypeRule extends Rule {
public void begin(final String name, final Attributes attrs) {
List types = (List) ((HashMap) peek()).get(name);
String type = attrs.getValue("type");
if ("uninitialized".equals(type)) {
types.add(getLabel(attrs.getValue("label")));
} else {
Integer t = (Integer) TYPES.get(type);
if (t == null) {
types.add(type);
} else {
types.add(t);
}
}
}
}
/**
* LabelRule
*/
private final class LabelRule extends Rule {
public final void begin(final String name, final Attributes attrs) {
getCodeVisitor().visitLabel(getLabel(attrs.getValue("name")));
}
}
/**
* TryCatchRule
*/
private final class TryCatchRule extends Rule {
public final void begin(final String name, final Attributes attrs) {
Label start = getLabel(attrs.getValue("start"));
Label end = getLabel(attrs.getValue("end"));
Label handler = getLabel(attrs.getValue("handler"));
String type = attrs.getValue("type");
getCodeVisitor().visitTryCatchBlock(start, end, handler, type);
}
}
/**
* LineNumberRule
*/
private final class LineNumberRule extends Rule {
public final void begin(final String name, final Attributes attrs) {
int line = Integer.parseInt(attrs.getValue("line"));
Label start = getLabel(attrs.getValue("start"));
getCodeVisitor().visitLineNumber(line, start);
}
}
/**
* LocalVarRule
*/
private final class LocalVarRule extends Rule {
public final void begin(final String element, final Attributes attrs) {
String name = attrs.getValue("name");
String desc = attrs.getValue("desc");
String signature = attrs.getValue("signature");
Label start = getLabel(attrs.getValue("start"));
Label end = getLabel(attrs.getValue("end"));
int var = Integer.parseInt(attrs.getValue("var"));
getCodeVisitor().visitLocalVariable(name,
desc,
signature,
start,
end,
var);
}
}
/**
* OpcodesRule
*/
private final class OpcodesRule extends Rule {
// public boolean match( String match, String element) {
// return match.startsWith( path) && OPCODES.containsKey( element);
// }
public final void begin(final String element, final Attributes attrs)
throws SAXException
{
Opcode o = (Opcode) OPCODES.get(element);
if (o == null) {
throw new SAXException("Invalid element: " + element + " at "
+ match);
}
switch (o.type) {
case OpcodeGroup.INSN:
getCodeVisitor().visitInsn(o.opcode);
break;
case OpcodeGroup.INSN_FIELD:
getCodeVisitor().visitFieldInsn(o.opcode,
attrs.getValue("owner"),
attrs.getValue("name"),
attrs.getValue("desc"));
break;
case OpcodeGroup.INSN_INT:
getCodeVisitor().visitIntInsn(o.opcode,
Integer.parseInt(attrs.getValue("value")));
break;
case OpcodeGroup.INSN_JUMP:
getCodeVisitor().visitJumpInsn(o.opcode,
getLabel(attrs.getValue("label")));
break;
case OpcodeGroup.INSN_METHOD:
getCodeVisitor().visitMethodInsn(o.opcode,
attrs.getValue("owner"),
attrs.getValue("name"),
attrs.getValue("desc"));
break;
case OpcodeGroup.INSN_TYPE:
getCodeVisitor().visitTypeInsn(o.opcode,
attrs.getValue("desc"));
break;
case OpcodeGroup.INSN_VAR:
getCodeVisitor().visitVarInsn(o.opcode,
Integer.parseInt(attrs.getValue("var")));
break;
case OpcodeGroup.INSN_IINC:
getCodeVisitor().visitIincInsn(Integer.parseInt(attrs.getValue("var")),
Integer.parseInt(attrs.getValue("inc")));
break;
case OpcodeGroup.INSN_LDC:
getCodeVisitor().visitLdcInsn(getValue(attrs.getValue("desc"),
attrs.getValue("cst")));
break;
case OpcodeGroup.INSN_MULTIANEWARRAY:
getCodeVisitor().visitMultiANewArrayInsn(attrs.getValue("desc"),
Integer.parseInt(attrs.getValue("dims")));
break;
default:
throw new Error("Internal error");
}
}
}
/**
* MaxRule
*/
private final class MaxRule extends Rule {
public final void begin(final String element, final Attributes attrs) {
int maxStack = Integer.parseInt(attrs.getValue("maxStack"));
int maxLocals = Integer.parseInt(attrs.getValue("maxLocals"));
getCodeVisitor().visitMaxs(maxStack, maxLocals);
}
}
private final class AnnotationRule extends Rule {
public void begin(final String name, final Attributes attrs) {
String desc = attrs.getValue("desc");
boolean visible = Boolean.valueOf(attrs.getValue("visible"))
.booleanValue();
Object v = peek();
if (v instanceof ClassVisitor) {
push(((ClassVisitor) v).visitAnnotation(desc, visible));
} else if (v instanceof FieldVisitor) {
push(((FieldVisitor) v).visitAnnotation(desc, visible));
} else if (v instanceof MethodVisitor) {
push(((MethodVisitor) v).visitAnnotation(desc, visible));
}
}
public void end(final String name) {
AnnotationVisitor av = (AnnotationVisitor) pop();
if (av != null) {
av.visitEnd();
}
}
}
private final class AnnotationParameterRule extends Rule {
public void begin(final String name, final Attributes attrs) {
int parameter = Integer.parseInt(attrs.getValue("parameter"));
String desc = attrs.getValue("desc");
boolean visible = Boolean.valueOf(attrs.getValue("visible"))
.booleanValue();
push(((MethodVisitor) peek()).visitParameterAnnotation(parameter,
desc,
visible));
}
public void end(final String name) {
AnnotationVisitor av = (AnnotationVisitor) pop();
if (av != null) {
av.visitEnd();
}
}
}
private final class AnnotationValueRule extends Rule {
public void begin(final String nm, final Attributes attrs)
throws SAXException
{
AnnotationVisitor av = (AnnotationVisitor) peek();
if (av != null) {
av.visit(attrs.getValue("name"),
getValue(attrs.getValue("desc"),
attrs.getValue("value")));
}
}
}
private final class AnnotationValueEnumRule extends Rule {
public void begin(final String nm, final Attributes attrs) {
AnnotationVisitor av = (AnnotationVisitor) peek();
if (av != null) {
av.visitEnum(attrs.getValue("name"),
attrs.getValue("desc"),
attrs.getValue("value"));
}
}
}
private final class AnnotationValueAnnotationRule extends Rule {
public void begin(final String nm, final Attributes attrs) {
AnnotationVisitor av = (AnnotationVisitor) peek();
push(av == null ? null : av.visitAnnotation(attrs.getValue("name"),
attrs.getValue("desc")));
}
public void end(final String name) {
AnnotationVisitor av = (AnnotationVisitor) pop();
if (av != null) {
av.visitEnd();
}
}
}
private final class AnnotationValueArrayRule extends Rule {
public void begin(final String nm, final Attributes attrs) {
AnnotationVisitor av = (AnnotationVisitor) peek();
push(av == null ? null : av.visitArray(attrs.getValue("name")));
}
public void end(final String name) {
AnnotationVisitor av = (AnnotationVisitor) pop();
if (av != null) {
av.visitEnd();
}
}
}
private final class AnnotationDefaultRule extends Rule {
public void begin(final String nm, final Attributes attrs) {
MethodVisitor av = (MethodVisitor) peek();
push(av == null ? null : av.visitAnnotationDefault());
}
public void end(final String name) {
AnnotationVisitor av = (AnnotationVisitor) pop();
if (av != null) {
av.visitEnd();
}
}
}
/**
* Opcode
*/
private final static class Opcode {
public int opcode;
public int type;
public Opcode(final int opcode, final int type) {
this.opcode = opcode;
this.type = type;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -