• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.visitor.*;
25 
26 /**
27  * This Constant represents a ref constant in the constant pool.
28  *
29  * @author Eric Lafortune
30  */
31 public abstract class RefConstant extends Constant
32 {
33     public int u2classIndex;
34     public int u2nameAndTypeIndex;
35 
36     /**
37      * An extra field pointing to the referenced Clazz object.
38      * This field is typically filled out by the <code>{@link
39      * proguard.classfile.util.ClassReferenceInitializer
40      * ClassReferenceInitializer}</code>.
41      */
42     public Clazz referencedClass;
43 
44     /**
45      * An extra field optionally pointing to the referenced Member object.
46      * This field is typically filled out by the <code>{@link
47      * proguard.classfile.util.ClassReferenceInitializer
48      * ClassReferenceInitializer}</code>.
49      */
50     public Member referencedMember;
51 
52 
RefConstant()53     protected RefConstant()
54     {
55     }
56 
57 
58     /**
59      * Returns the class index.
60      */
getClassIndex()61     public int getClassIndex()
62     {
63         return u2classIndex;
64     }
65 
66     /**
67      * Returns the name-and-type index.
68      */
getNameAndTypeIndex()69     public int getNameAndTypeIndex()
70     {
71         return u2nameAndTypeIndex;
72     }
73 
74     /**
75      * Sets the name-and-type index.
76      */
setNameAndTypeIndex(int index)77     public void setNameAndTypeIndex(int index)
78     {
79         u2nameAndTypeIndex = index;
80     }
81 
82     /**
83      * Returns the class name.
84      */
getClassName(Clazz clazz)85     public String getClassName(Clazz clazz)
86     {
87         return clazz.getClassName(u2classIndex);
88     }
89 
90     /**
91      * Returns the method/field name.
92      */
getName(Clazz clazz)93     public String getName(Clazz clazz)
94     {
95         return clazz.getName(u2nameAndTypeIndex);
96     }
97 
98     /**
99      * Returns the type.
100      */
getType(Clazz clazz)101     public String getType(Clazz clazz)
102     {
103         return clazz.getType(u2nameAndTypeIndex);
104     }
105 
106 
107     /**
108      * Lets the referenced class accept the given visitor.
109      */
referencedClassAccept(ClassVisitor classVisitor)110     public void referencedClassAccept(ClassVisitor classVisitor)
111     {
112         if (referencedClass != null)
113         {
114             referencedClass.accept(classVisitor);
115         }
116     }
117 
118 
119     /**
120      * Lets the referenced class member accept the given visitor.
121      */
referencedMemberAccept(MemberVisitor memberVisitor)122     public void referencedMemberAccept(MemberVisitor memberVisitor)
123     {
124         if (referencedMember != null)
125         {
126             referencedMember.accept(referencedClass,
127                                     memberVisitor);
128         }
129     }
130 }
131