01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.jci.classes;
19:
20: import org.objectweb.asm.ClassWriter;
21: import org.objectweb.asm.Label;
22: import org.objectweb.asm.MethodVisitor;
23: import org.objectweb.asm.Opcodes;
24:
25: public class ExtendedDump implements Opcodes {
26:
27: public static byte[] dump() throws Exception {
28:
29: ClassWriter cw = new ClassWriter(true);
30: MethodVisitor mv;
31:
32: cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Extended", null,
33: "jci/Simple", null);
34:
35: cw.visitSource("Extended.java", null);
36:
37: {
38: mv = cw
39: .visitMethod(ACC_PUBLIC, "<init>", "()V", null,
40: null);
41: mv.visitCode();
42: Label l0 = new Label();
43: mv.visitLabel(l0);
44: mv.visitLineNumber(3, l0);
45: mv.visitVarInsn(ALOAD, 0);
46: mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "<init>",
47: "()V");
48: mv.visitInsn(RETURN);
49: Label l1 = new Label();
50: mv.visitLabel(l1);
51: mv.visitLocalVariable("this", "Ljci/Extended;", null, l0,
52: l1, 0);
53: mv.visitMaxs(1, 1);
54: mv.visitEnd();
55: }
56: {
57: mv = cw.visitMethod(ACC_PUBLIC, "toString",
58: "()Ljava/lang/String;", null, null);
59: mv.visitCode();
60: Label l0 = new Label();
61: mv.visitLabel(l0);
62: mv.visitLineNumber(6, l0);
63: mv.visitTypeInsn(NEW, "java/lang/StringBuffer");
64: mv.visitInsn(DUP);
65: mv.visitLdcInsn("Extended:");
66: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer",
67: "<init>", "(Ljava/lang/String;)V");
68: mv.visitVarInsn(ALOAD, 0);
69: mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "toString",
70: "()Ljava/lang/String;");
71: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer",
72: "append",
73: "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
74: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer",
75: "toString", "()Ljava/lang/String;");
76: mv.visitInsn(ARETURN);
77: Label l1 = new Label();
78: mv.visitLabel(l1);
79: mv.visitLocalVariable("this", "Ljci/Extended;", null, l0,
80: l1, 0);
81: mv.visitMaxs(3, 1);
82: mv.visitEnd();
83: }
84: cw.visitEnd();
85:
86: return cw.toByteArray();
87: }
88: }
|