1 /* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2014 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 */ 21 package proguard.classfile.constant; 22 23 import proguard.classfile.*; 24 import proguard.classfile.constant.visitor.ConstantVisitor; 25 import proguard.classfile.visitor.ClassVisitor; 26 27 /** 28 * This Constant represents a class constant in the constant pool. 29 * 30 * @author Eric Lafortune 31 */ 32 public class ClassConstant extends Constant 33 { 34 public int u2nameIndex; 35 36 /** 37 * An extra field pointing to the referenced Clazz object. 38 * This field is filled out by the <code>{@link 39 * proguard.classfile.util.ClassReferenceInitializer ClassReferenceInitializer}</code>. 40 */ 41 public Clazz referencedClass; 42 43 /** 44 * An extra field pointing to the java.lang.Class Clazz object. 45 * This field is typically filled out by the <code>{@link 46 * proguard.classfile.util.ClassReferenceInitializer 47 * ClassReferenceInitializer}</code>.. 48 */ 49 public Clazz javaLangClassClass; 50 51 52 /** 53 * Creates an uninitialized ClassConstant. 54 */ ClassConstant()55 public ClassConstant() 56 { 57 } 58 59 60 /** 61 * Creates a new ClassConstant with the given name index. 62 * @param u2nameIndex the index of the name in the constant pool. 63 * @param referencedClass the referenced class. 64 */ ClassConstant(int u2nameIndex, Clazz referencedClass)65 public ClassConstant(int u2nameIndex, 66 Clazz referencedClass) 67 { 68 this.u2nameIndex = u2nameIndex; 69 this.referencedClass = referencedClass; 70 } 71 72 73 /** 74 * Returns the name. 75 */ getName(Clazz clazz)76 public String getName(Clazz clazz) 77 { 78 return clazz.getString(u2nameIndex); 79 } 80 81 82 // Implementations for Constant. 83 getTag()84 public int getTag() 85 { 86 return ClassConstants.CONSTANT_Class; 87 } 88 accept(Clazz clazz, ConstantVisitor constantVisitor)89 public void accept(Clazz clazz, ConstantVisitor constantVisitor) 90 { 91 constantVisitor.visitClassConstant(clazz, this); 92 } 93 94 95 /** 96 * Lets the referenced class accept the given visitor. 97 */ referencedClassAccept(ClassVisitor classVisitor)98 public void referencedClassAccept(ClassVisitor classVisitor) 99 { 100 if (referencedClass != null) 101 { 102 referencedClass.accept(classVisitor); 103 } 104 } 105 } 106