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 SimpleDump implements Opcodes {
26:
27: public static byte[] dump(final String to) throws Exception {
28:
29: ClassWriter cw = new ClassWriter(true);
30: MethodVisitor mv;
31:
32: cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Simple", null,
33: "java/lang/Object", null);
34:
35: cw.visitSource("Simple.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, "java/lang/Object",
47: "<init>", "()V");
48: mv.visitInsn(RETURN);
49: Label l1 = new Label();
50: mv.visitLabel(l1);
51: mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1,
52: 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.visitLdcInsn(to);
64: mv.visitInsn(ARETURN);
65: Label l1 = new Label();
66: mv.visitLabel(l1);
67: mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1,
68: 0);
69: mv.visitMaxs(1, 1);
70: mv.visitEnd();
71: }
72: cw.visitEnd();
73:
74: return cw.toByteArray();
75: }
76: }
|