001/*** 002 * ASM: a very small and fast Java bytecode manipulation framework 003 * Copyright (c) 2000-2011 INRIA, France Telecom 004 * All rights reserved. 005 * 006 * Redistribution and use in source and binary forms, with or without 007 * modification, are permitted provided that the following conditions 008 * are met: 009 * 1. Redistributions of source code must retain the above copyright 010 * notice, this list of conditions and the following disclaimer. 011 * 2. Redistributions in binary form must reproduce the above copyright 012 * notice, this list of conditions and the following disclaimer in the 013 * documentation and/or other materials provided with the distribution. 014 * 3. Neither the name of the copyright holders nor the names of its 015 * contributors may be used to endorse or promote products derived from 016 * this software without specific prior written permission. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 028 * THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030 031package org.springframework.asm; 032 033/** 034 * A visitor to visit a Java module. The methods of this class must be called in 035 * the following order: <tt>visitVersion</tt> | <tt>visitMainClass</tt> | 036 * <tt>visitTargetPlatform</tt> | ( <tt>visitConcealedPackage</tt> | <tt>visitRequire</tt> | 037 * <tt>visitExport</tt> | <tt>visitUse</tt> | <tt>visitProvide</tt> )* <tt>visitEnd</tt>. 038 * 039 * @author Remi Forax 040 */ 041public abstract class ModuleVisitor { 042 /** 043 * The ASM API version implemented by this visitor. The value of this field 044 * must be {@link Opcodes#ASM6}. 045 */ 046 protected final int api; 047 048 /** 049 * The module visitor to which this visitor must delegate method calls. May 050 * be null. 051 */ 052 protected ModuleVisitor mv; 053 054 055 public ModuleVisitor(final int api) { 056 this(api, null); 057 } 058 059 /** 060 * Constructs a new {@link MethodVisitor}. 061 * 062 * @param api 063 * the ASM API version implemented by this visitor. Must be {@link Opcodes#ASM6}. 064 * @param mv 065 * the method visitor to which this visitor must delegate method 066 * calls. May be null. 067 */ 068 public ModuleVisitor(final int api, final ModuleVisitor mv) { 069 if (api != Opcodes.ASM6) { 070 throw new IllegalArgumentException(); 071 } 072 this.api = api; 073 this.mv = mv; 074 } 075 076 /** 077 * Visit the main class of the current module. 078 * 079 * @param mainClass the main class of the current module. 080 */ 081 public void visitMainClass(String mainClass) { 082 if (mv != null) { 083 mv.visitMainClass(mainClass); 084 } 085 } 086 087 /** 088 * Visit a concealed package of the current module. 089 * 090 * @param packaze name of a concealed package 091 */ 092 public void visitPackage(String packaze) { 093 if (mv != null) { 094 mv.visitPackage(packaze); 095 } 096 } 097 098 /** 099 * Visits a dependence of the current module. 100 * 101 * @param module the module name of the dependence 102 * @param access the access flag of the dependence among 103 * ACC_TRANSITIVE, ACC_STATIC_PHASE, ACC_SYNTHETIC 104 * and ACC_MANDATED. 105 * @param version the module version at compile time or null. 106 */ 107 public void visitRequire(String module, int access, String version) { 108 if (mv != null) { 109 mv.visitRequire(module, access, version); 110 } 111 } 112 113 /** 114 * Visit an exported package of the current module. 115 * 116 * @param packaze the name of the exported package. 117 * @param access the access flag of the exported package, 118 * valid values are among {@code ACC_SYNTHETIC} and 119 * {@code ACC_MANDATED}. 120 * @param modules names of the modules that can access to 121 * the public classes of the exported package or 122 * <tt>null</tt>. 123 */ 124 public void visitExport(String packaze, int access, String... modules) { 125 if (mv != null) { 126 mv.visitExport(packaze, access, modules); 127 } 128 } 129 130 /** 131 * Visit an open package of the current module. 132 * 133 * @param packaze the name of the opened package. 134 * @param access the access flag of the opened package, 135 * valid values are among {@code ACC_SYNTHETIC} and 136 * {@code ACC_MANDATED}. 137 * @param modules names of the modules that can use deep 138 * reflection to the classes of the open package or 139 * <tt>null</tt>. 140 */ 141 public void visitOpen(String packaze, int access, String... modules) { 142 if (mv != null) { 143 mv.visitOpen(packaze, access, modules); 144 } 145 } 146 147 /** 148 * Visit a service used by the current module. 149 * The name must be the name of an interface or an 150 * abstract class. 151 * 152 * @param service the internal name of the service. 153 */ 154 public void visitUse(String service) { 155 if (mv != null) { 156 mv.visitUse(service); 157 } 158 } 159 160 /** 161 * Visit an implementation of a service. 162 * 163 * @param service the internal name of the service 164 * @param providers the internal names of the implementations 165 * of the service (there is at least one provider). 166 */ 167 public void visitProvide(String service, String... providers) { 168 if (mv != null) { 169 mv.visitProvide(service, providers); 170 } 171 } 172 173 public void visitEnd() { 174 if (mv != null) { 175 mv.visitEnd(); 176 } 177 } 178}