1 // ASM: a very small and fast Java bytecode manipulation framework 2 // Copyright (c) 2000-2011 INRIA, France Telecom 3 // All rights reserved. 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions 7 // are met: 8 // 1. Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // 2. Redistributions in binary form must reproduce the above copyright 11 // notice, this list of conditions and the following disclaimer in the 12 // documentation and/or other materials provided with the distribution. 13 // 3. Neither the name of the copyright holders nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 // THE POSSIBILITY OF SUCH DAMAGE. 28 package org.objectweb.asm.util; 29 30 import org.objectweb.asm.ModuleVisitor; 31 import org.objectweb.asm.Opcodes; 32 33 /** 34 * A {@link ModuleVisitor} that prints the fields it visits with a {@link Printer}. 35 * 36 * @author Remi Forax 37 */ 38 public final class TraceModuleVisitor extends ModuleVisitor { 39 40 /** The printer to convert the visited module into text. */ 41 // DontCheck(MemberName): can't be renamed (for backward binary compatibility). 42 public final Printer p; 43 44 /** 45 * Constructs a new {@link TraceModuleVisitor}. 46 * 47 * @param printer the printer to convert the visited module into text. 48 */ TraceModuleVisitor(final Printer printer)49 public TraceModuleVisitor(final Printer printer) { 50 this(null, printer); 51 } 52 53 /** 54 * Constructs a new {@link TraceModuleVisitor}. 55 * 56 * @param moduleVisitor the module visitor to which to delegate calls. May be {@literal null}. 57 * @param printer the printer to convert the visited module into text. 58 */ TraceModuleVisitor(final ModuleVisitor moduleVisitor, final Printer printer)59 public TraceModuleVisitor(final ModuleVisitor moduleVisitor, final Printer printer) { 60 super(/* latest api = */ Opcodes.ASM9, moduleVisitor); 61 this.p = printer; 62 } 63 64 @Override visitMainClass(final String mainClass)65 public void visitMainClass(final String mainClass) { 66 p.visitMainClass(mainClass); 67 super.visitMainClass(mainClass); 68 } 69 70 @Override visitPackage(final String packaze)71 public void visitPackage(final String packaze) { 72 p.visitPackage(packaze); 73 super.visitPackage(packaze); 74 } 75 76 @Override visitRequire(final String module, final int access, final String version)77 public void visitRequire(final String module, final int access, final String version) { 78 p.visitRequire(module, access, version); 79 super.visitRequire(module, access, version); 80 } 81 82 @Override visitExport(final String packaze, final int access, final String... modules)83 public void visitExport(final String packaze, final int access, final String... modules) { 84 p.visitExport(packaze, access, modules); 85 super.visitExport(packaze, access, modules); 86 } 87 88 @Override visitOpen(final String packaze, final int access, final String... modules)89 public void visitOpen(final String packaze, final int access, final String... modules) { 90 p.visitOpen(packaze, access, modules); 91 super.visitOpen(packaze, access, modules); 92 } 93 94 @Override visitUse(final String use)95 public void visitUse(final String use) { 96 p.visitUse(use); 97 super.visitUse(use); 98 } 99 100 @Override visitProvide(final String service, final String... providers)101 public void visitProvide(final String service, final String... providers) { 102 p.visitProvide(service, providers); 103 super.visitProvide(service, providers); 104 } 105 106 @Override visitEnd()107 public void visitEnd() { 108 p.visitModuleEnd(); 109 super.visitEnd(); 110 } 111 } 112