001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This library is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This library is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this library; if not, write to the Free Software Foundation,
019: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.classfile.constant;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.constant.visitor.ConstantVisitor;
025:
026: /**
027: * This Constant represents a name and type constant in the constant pool.
028: *
029: * @author Eric Lafortune
030: */
031: public class NameAndTypeConstant extends Constant {
032: public int u2nameIndex;
033: public int u2descriptorIndex;
034:
035: /**
036: * Creates an uninitialized NameAndTypeConstant.
037: */
038: public NameAndTypeConstant() {
039: }
040:
041: /**
042: * Creates a new NameAndTypeConstant with the given name and type indices.
043: * @param u2nameIndex the index of the name in the constant pool.
044: * @param u2descriptorIndex the index of the descriptor in the constant
045: * pool.
046: */
047: public NameAndTypeConstant(int u2nameIndex, int u2descriptorIndex) {
048: this .u2nameIndex = u2nameIndex;
049: this .u2descriptorIndex = u2descriptorIndex;
050: }
051:
052: /**
053: * Returns the name index.
054: */
055: protected int getNameIndex() {
056: return u2nameIndex;
057: }
058:
059: /**
060: * Sets the name index.
061: */
062: protected void setNameIndex(int index) {
063: u2nameIndex = index;
064: }
065:
066: /**
067: * Returns the descriptor index.
068: */
069: protected int getDescriptorIndex() {
070: return u2descriptorIndex;
071: }
072:
073: /**
074: * Sets the descriptor index.
075: */
076: protected void setDescriptorIndex(int index) {
077: u2descriptorIndex = index;
078: }
079:
080: /**
081: * Returns the name.
082: */
083: public String getName(Clazz clazz) {
084: return clazz.getString(u2nameIndex);
085: }
086:
087: /**
088: * Returns the type.
089: */
090: public String getType(Clazz clazz) {
091: return clazz.getString(u2descriptorIndex);
092: }
093:
094: // Implementations for Constant.
095:
096: public int getTag() {
097: return ClassConstants.CONSTANT_NameAndType;
098: }
099:
100: public void accept(Clazz clazz, ConstantVisitor constantVisitor) {
101: constantVisitor.visitNameAndTypeConstant(clazz, this);
102: }
103: }
|