1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.classfile; 23 24 import java.io.DataInput; 25 import java.io.IOException; 26 27 import com.sun.org.apache.bcel.internal.Const; 28 29 /** 30 * This class is derived from the abstract {@link Constant} 31 * and represents a reference to a invoke dynamic. 32 * 33 * @see Constant 34 * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.10"> 35 * The CONSTANT_InvokeDynamic_info Structure in The Java Virtual Machine Specification</a> 36 * @since 6.0 37 */ 38 public final class ConstantInvokeDynamic extends ConstantCP { 39 40 /** 41 * Initialize from another object. 42 */ 43 public ConstantInvokeDynamic(final ConstantInvokeDynamic c) { 44 this(c.getBootstrapMethodAttrIndex(), c.getNameAndTypeIndex()); 45 } 46 47 48 /** 49 * Initialize instance from file data. 50 * 51 * @param file Input stream 52 * @throws IOException 53 */ 54 ConstantInvokeDynamic(final DataInput file) throws IOException { 55 this(file.readShort(), file.readShort()); 56 } 57 58 59 public ConstantInvokeDynamic(final int bootstrap_method_attr_index, final int name_and_type_index) { 60 super(Const.CONSTANT_InvokeDynamic, bootstrap_method_attr_index, name_and_type_index); 61 } 62 63 64 /** 65 * Called by objects that are traversing the nodes of the tree implicitly 66 * defined by the contents of a Java class. I.e., the hierarchy of methods, 67 * fields, attributes, etc. spawns a tree of objects. 68 * 69 * @param v Visitor object 70 */ 71 @Override 72 public void accept( final Visitor v ) { 73 v.visitConstantInvokeDynamic(this); 74 } 75 76 /** 77 * @return Reference (index) to bootstrap method this constant refers to. 78 * 79 * Note that this method is a functional duplicate of getClassIndex 80 * for use by ConstantInvokeDynamic. 81 * @since 6.0 82 */ 83 public final int getBootstrapMethodAttrIndex() { 84 return super.getClassIndex(); // AKA bootstrap_method_attr_index 85 } 86 87 /** 88 * @return String representation 89 */ 90 @Override 91 public final String toString() { 92 return super.toString().replace("class_index", "bootstrap_method_attr_index"); 93 } 94 }