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 public class SimpleDump implements Opcodes { 026 027 public static byte[] dump( final String to ) throws Exception { 028 029 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 030 MethodVisitor mv; 031 032 cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Simple", null, "java/lang/Object", null); 033 034 cw.visitSource("Simple.java", null); 035 036 { 037 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 038 mv.visitCode(); 039 Label l0 = new Label(); 040 mv.visitLabel(l0); 041 mv.visitLineNumber(3, l0); 042 mv.visitVarInsn(ALOAD, 0); 043 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 044 mv.visitInsn(RETURN); 045 Label l1 = new Label(); 046 mv.visitLabel(l1); 047 mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0); 048 mv.visitMaxs(1, 1); 049 mv.visitEnd(); 050 } 051 { 052 mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); 053 mv.visitCode(); 054 Label l0 = new Label(); 055 mv.visitLabel(l0); 056 mv.visitLineNumber(6, l0); 057 mv.visitLdcInsn(to); 058 mv.visitInsn(ARETURN); 059 Label l1 = new Label(); 060 mv.visitLabel(l1); 061 mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0); 062 mv.visitMaxs(1, 1); 063 mv.visitEnd(); 064 } 065 cw.visitEnd(); 066 067 return cw.toByteArray(); 068 } 069 }