001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.jci.classes;
019
020 import org.objectweb.asm.ClassWriter;
021 import org.objectweb.asm.Label;
022 import org.objectweb.asm.MethodVisitor;
023 import org.objectweb.asm.Opcodes;
024
025
026 public class ExtendedDump implements Opcodes {
027
028 public static byte[] dump() throws Exception {
029
030 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
031 MethodVisitor mv;
032
033 cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Extended", null, "jci/Simple", null);
034
035 cw.visitSource("Extended.java", null);
036
037 {
038 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
039 mv.visitCode();
040 Label l0 = new Label();
041 mv.visitLabel(l0);
042 mv.visitLineNumber(3, l0);
043 mv.visitVarInsn(ALOAD, 0);
044 mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "<init>", "()V");
045 mv.visitInsn(RETURN);
046 Label l1 = new Label();
047 mv.visitLabel(l1);
048 mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
049 mv.visitMaxs(1, 1);
050 mv.visitEnd();
051 }
052 {
053 mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
054 mv.visitCode();
055 Label l0 = new Label();
056 mv.visitLabel(l0);
057 mv.visitLineNumber(6, l0);
058 mv.visitTypeInsn(NEW, "java/lang/StringBuffer");
059 mv.visitInsn(DUP);
060 mv.visitLdcInsn("Extended:");
061 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer", "<init>", "(Ljava/lang/String;)V");
062 mv.visitVarInsn(ALOAD, 0);
063 mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "toString", "()Ljava/lang/String;");
064 mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
065 mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;");
066 mv.visitInsn(ARETURN);
067 Label l1 = new Label();
068 mv.visitLabel(l1);
069 mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
070 mv.visitMaxs(3, 1);
071 mv.visitEnd();
072 }
073 cw.visitEnd();
074
075 return cw.toByteArray();
076 }
077 }