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