1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * This file is available under and governed by the GNU General Public
  27  * License version 2 only, as published by the Free Software Foundation.
  28  * However, the following notice accompanied the original version of this
  29  * file:
  30  *
  31  * ASM: a very small and fast Java bytecode manipulation framework
  32  * Copyright (c) 2000-2011 INRIA, France Telecom
  33  * All rights reserved.
  34  *
  35  * Redistribution and use in source and binary forms, with or without
  36  * modification, are permitted provided that the following conditions
  37  * are met:
  38  * 1. Redistributions of source code must retain the above copyright
  39  *    notice, this list of conditions and the following disclaimer.
  40  * 2. Redistributions in binary form must reproduce the above copyright
  41  *    notice, this list of conditions and the following disclaimer in the
  42  *    documentation and/or other materials provided with the distribution.
  43  * 3. Neither the name of the copyright holders nor the names of its
  44  *    contributors may be used to endorse or promote products derived from
  45  *    this software without specific prior written permission.
  46  *
  47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm;
  60 
  61 /**
  62  * A visitor to visit a Java module. The methods of this class must be called in
  63  * the following order: <tt>visitMainClass</tt> | ( <tt>visitPackage</tt> |
  64  * <tt>visitRequire</tt> | <tt>visitExport</tt> | <tt>visitOpen</tt> |
  65  * <tt>visitUse</tt> | <tt>visitProvide</tt> )* <tt>visitEnd</tt>.
  66  *
  67  * The methods {@link #visitRequire(String, int, String)}, {@link #visitExport(String, int, String...)},
  68  * {@link #visitOpen(String, int, String...)} and {@link #visitPackage(String)}
  69  * take as parameter a package name or a module name. Unlike the other names which are internal names
  70  * (names separated by slash), module and package names are qualified names (names separated by dot).
  71  *
  72  * @author Remi Forax
  73  */
  74 public abstract class ModuleVisitor {
  75     /**
  76      * The ASM API version implemented by this visitor. The value of this field
  77      * must be {@link Opcodes#ASM6}.
  78      */
  79     protected final int api;
  80 
  81     /**
  82      * The module visitor to which this visitor must delegate method calls. May
  83      * be null.
  84      */
  85     protected ModuleVisitor mv;
  86 
  87     /**
  88      * Constructs a new {@link ModuleVisitor}.
  89      *
  90      * @param api
  91      *            the ASM API version implemented by this visitor. Must be {@link Opcodes#ASM6}.
  92      */
  93     public ModuleVisitor(final int api) {
  94         this(api, null);
  95     }
  96 
  97     /**
  98      * Constructs a new {@link ModuleVisitor}.
  99      *
 100      * @param api
 101      *            the ASM API version implemented by this visitor. Must be {@link Opcodes#ASM6}.
 102      * @param mv
 103      *            the module visitor to which this visitor must delegate method
 104      *            calls. May be null.
 105      */
 106     public ModuleVisitor(final int api, final ModuleVisitor mv) {
 107         if (api != Opcodes.ASM6) {
 108             throw new IllegalArgumentException();
 109         }
 110         this.api = api;
 111         this.mv = mv;
 112     }
 113 
 114     /**
 115      * Visit the main class of the current module.
 116      *
 117      * @param mainClass the internal name of the main class of the current module.
 118      */
 119     public void visitMainClass(String mainClass) {
 120         if (mv != null) {
 121             mv.visitMainClass(mainClass);
 122         }
 123     }
 124 
 125     /**
 126      * Visit a package of the current module.
 127      *
 128      * @param packaze the qualified name of a package.
 129      */
 130     public void visitPackage(String packaze) {
 131         if (mv != null) {
 132             mv.visitPackage(packaze);
 133         }
 134     }
 135 
 136     /**
 137      * Visits a dependence of the current module.
 138      *
 139      * @param module the qualified name of the dependence.
 140      * @param access the access flag of the dependence among
 141      *        ACC_TRANSITIVE, ACC_STATIC_PHASE, ACC_SYNTHETIC
 142      *        and ACC_MANDATED.
 143      * @param version the module version at compile time or null.
 144      */
 145     public void visitRequire(String module, int access, String version) {
 146         if (mv != null) {
 147             mv.visitRequire(module, access, version);
 148         }
 149     }
 150 
 151     /**
 152      * Visit an exported package of the current module.
 153      *
 154      * @param packaze the qualified name of the exported package.
 155      * @param access the access flag of the exported package,
 156      *        valid values are among {@code ACC_SYNTHETIC} and
 157      *        {@code ACC_MANDATED}.
 158      * @param modules the qualified names of the modules that can access to
 159      *        the public classes of the exported package or
 160      *        <tt>null</tt>.
 161      */
 162     public void visitExport(String packaze, int access, String... modules) {
 163         if (mv != null) {
 164             mv.visitExport(packaze, access, modules);
 165         }
 166     }
 167 
 168     /**
 169      * Visit an open package of the current module.
 170      *
 171      * @param packaze the qualified name of the opened package.
 172      * @param access the access flag of the opened package,
 173      *        valid values are among {@code ACC_SYNTHETIC} and
 174      *        {@code ACC_MANDATED}.
 175      * @param modules the qualified names of the modules that can use deep
 176      *        reflection to the classes of the open package or
 177      *        <tt>null</tt>.
 178      */
 179     public void visitOpen(String packaze, int access, String... modules) {
 180         if (mv != null) {
 181             mv.visitOpen(packaze, access, modules);
 182         }
 183     }
 184 
 185     /**
 186      * Visit a service used by the current module.
 187      * The name must be the internal name of an interface or a class.
 188      *
 189      * @param service the internal name of the service.
 190      */
 191     public void visitUse(String service) {
 192         if (mv != null) {
 193             mv.visitUse(service);
 194         }
 195     }
 196 
 197     /**
 198      * Visit an implementation of a service.
 199      *
 200      * @param service the internal name of the service
 201      * @param providers the internal names of the implementations
 202      *        of the service (there is at least one provider).
 203      */
 204     public void visitProvide(String service, String... providers) {
 205         if (mv != null) {
 206             mv.visitProvide(service, providers);
 207         }
 208     }
 209 
 210     /**
 211      * Visits the end of the module. This method, which is the last one to be
 212      * called, is used to inform the visitor that everything have been visited.
 213      */
 214     public void visitEnd() {
 215         if (mv != null) {
 216             mv.visitEnd();
 217         }
 218     }
 219 }