NameAndTypeConstant.java revision b72c5c2e5482cf10117b2b25f642f7616b2326c3
1/* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21package proguard.classfile.constant; 22 23import proguard.classfile.*; 24import proguard.classfile.constant.visitor.ConstantVisitor; 25 26/** 27 * This Constant represents a name and type constant in the constant pool. 28 * 29 * @author Eric Lafortune 30 */ 31public class NameAndTypeConstant extends Constant 32{ 33 public int u2nameIndex; 34 public int u2descriptorIndex; 35 36 37 /** 38 * Creates an uninitialized NameAndTypeConstant. 39 */ 40 public NameAndTypeConstant() 41 { 42 } 43 44 45 /** 46 * Creates a new NameAndTypeConstant with the given name and type indices. 47 * @param u2nameIndex the index of the name in the constant pool. 48 * @param u2descriptorIndex the index of the descriptor in the constant 49 * pool. 50 */ 51 public NameAndTypeConstant(int u2nameIndex, 52 int u2descriptorIndex) 53 { 54 this.u2nameIndex = u2nameIndex; 55 this.u2descriptorIndex = u2descriptorIndex; 56 } 57 58 59 /** 60 * Returns the name index. 61 */ 62 protected int getNameIndex() 63 { 64 return u2nameIndex; 65 } 66 67 /** 68 * Sets the name index. 69 */ 70 protected void setNameIndex(int index) 71 { 72 u2nameIndex = index; 73 } 74 75 /** 76 * Returns the descriptor index. 77 */ 78 protected int getDescriptorIndex() 79 { 80 return u2descriptorIndex; 81 } 82 83 /** 84 * Sets the descriptor index. 85 */ 86 protected void setDescriptorIndex(int index) 87 { 88 u2descriptorIndex = index; 89 } 90 91 /** 92 * Returns the name. 93 */ 94 public String getName(Clazz clazz) 95 { 96 return clazz.getString(u2nameIndex); 97 } 98 99 /** 100 * Returns the type. 101 */ 102 public String getType(Clazz clazz) 103 { 104 return clazz.getString(u2descriptorIndex); 105 } 106 107 108 // Implementations for Constant. 109 110 public int getTag() 111 { 112 return ClassConstants.CONSTANT_NameAndType; 113 } 114 115 public void accept(Clazz clazz, ConstantVisitor constantVisitor) 116 { 117 constantVisitor.visitNameAndTypeConstant(clazz, this); 118 } 119} 120