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 * @version $Id: FieldOrMethod.java 1481383 2013-05-11 17:34:32Z dbrosius $ 34 * @since 6.0 35 */ 36 public abstract class NameSignatureInstruction extends CPInstruction { 37 NameSignatureInstruction()38 public NameSignatureInstruction() { 39 super(); 40 } 41 NameSignatureInstruction(final short opcode, final int index)42 public NameSignatureInstruction(final short opcode, final int index) { 43 super(opcode, index); 44 } 45 getNameAndType(final ConstantPoolGen cpg)46 public ConstantNameAndType getNameAndType(final ConstantPoolGen cpg) { 47 final ConstantPool cp = cpg.getConstantPool(); 48 final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex()); 49 return (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex()); 50 } 51 /** @return signature of referenced method/field. 52 */ getSignature(final ConstantPoolGen cpg)53 public String getSignature(final ConstantPoolGen cpg) { 54 final ConstantPool cp = cpg.getConstantPool(); 55 final ConstantNameAndType cnat = getNameAndType(cpg); 56 return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); 57 } 58 59 /** @return name of referenced method/field. 60 */ getName(final ConstantPoolGen cpg)61 public String getName(final ConstantPoolGen cpg) { 62 final ConstantPool cp = cpg.getConstantPool(); 63 final ConstantNameAndType cnat = getNameAndType(cpg); 64 return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); 65 } 66 67 } 68