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.generic; 23 24 import com.sun.org.apache.bcel.internal.classfile.ConstantCP; 25 import com.sun.org.apache.bcel.internal.classfile.ConstantNameAndType; 26 import com.sun.org.apache.bcel.internal.classfile.ConstantPool; 27 import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; 28 29 /** 30 * Super class for FieldOrMethod and INVOKEDYNAMIC, since they both have 31 * names and signatures 32 * 33 * @since 6.0 34 */ 35 public abstract class NameSignatureInstruction extends CPInstruction { 36 NameSignatureInstruction()37 public NameSignatureInstruction() { 38 super(); 39 } 40 NameSignatureInstruction(final short opcode, final int index)41 public NameSignatureInstruction(final short opcode, final int index) { 42 super(opcode, index); 43 } 44 getNameAndType(final ConstantPoolGen cpg)45 public ConstantNameAndType getNameAndType(final ConstantPoolGen cpg) { 46 final ConstantPool cp = cpg.getConstantPool(); 47 final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex()); 48 return (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex()); 49 } 50 /** @return signature of referenced method/field. 51 */ getSignature(final ConstantPoolGen cpg)52 public String getSignature(final ConstantPoolGen cpg) { 53 final ConstantPool cp = cpg.getConstantPool(); 54 final ConstantNameAndType cnat = getNameAndType(cpg); 55 return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); 56 } 57 58 /** @return name of referenced method/field. 59 */ getName(final ConstantPoolGen cpg)60 public String getName(final ConstantPoolGen cpg) { 61 final ConstantPool cp = cpg.getConstantPool(); 62 final ConstantNameAndType cnat = getNameAndType(cpg); 63 return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); 64 } 65 66 } 67