| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * https://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package org.apache.bcel.generic; |
| |
| import org.apache.bcel.classfile.ConstantCP; |
| import org.apache.bcel.classfile.ConstantNameAndType; |
| import org.apache.bcel.classfile.ConstantPool; |
| import org.apache.bcel.classfile.ConstantUtf8; |
| |
| /** |
| * Super class for FieldOrMethod and INVOKEDYNAMIC, since they both have names and signatures |
| * |
| * @since 6.0 |
| */ |
| public abstract class NameSignatureInstruction extends CPInstruction { |
| |
| /** |
| * Constructs a NameSignatureInstruction. |
| */ |
| public NameSignatureInstruction() { |
| } |
| |
| /** |
| * Constructs a NameSignatureInstruction. |
| * |
| * @param opcode the opcode. |
| * @param index index into constant pool. |
| */ |
| public NameSignatureInstruction(final short opcode, final int index) { |
| super(opcode, index); |
| } |
| |
| /** |
| * Gets the name of the referenced method or field. |
| * |
| * @param cpg constant pool generator. |
| * @return name of referenced method/field. |
| */ |
| public String getName(final ConstantPoolGen cpg) { |
| final ConstantPool cp = cpg.getConstantPool(); |
| final ConstantNameAndType cnat = getNameAndType(cpg); |
| return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes(); |
| } |
| |
| /** |
| * Gets the name and type constant. |
| * |
| * @param cpg constant pool generator. |
| * @return the name and type constant. |
| */ |
| public ConstantNameAndType getNameAndType(final ConstantPoolGen cpg) { |
| final ConstantPool cp = cpg.getConstantPool(); |
| final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex()); |
| return (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex()); |
| } |
| |
| /** |
| * Gets the signature of the referenced method or field. |
| * |
| * @param cpg constant pool generator. |
| * @return signature of referenced method/field. |
| */ |
| public String getSignature(final ConstantPoolGen cpg) { |
| final ConstantPool cp = cpg.getConstantPool(); |
| final ConstantNameAndType cnat = getNameAndType(cpg); |
| return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes(); |
| } |
| |
| } |