1 /* 2 * ProGuard -- shrinking, optimization, obfuscation, and preverification 3 * of Java bytecode. 4 * 5 * Copyright (c) 2002-2014 Eric Lafortune (eric (at) 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.evaluation.value; 22 23 import proguard.classfile.Clazz; 24 25 /** 26 * This TypedReferenceValue represents a reference value that is identified by a 27 * unique ID. 28 * 29 * @author Eric Lafortune 30 */ 31 class IdentifiedReferenceValue extends TypedReferenceValue 32 { 33 private final ValueFactory valuefactory; 34 private final int id; 35 36 37 /** 38 * Creates a new reference value with the given ID. 39 */ 40 public IdentifiedReferenceValue(String type, 41 Clazz referencedClass, 42 boolean mayBeNull, 43 ValueFactory valuefactory, 44 int id) 45 { 46 super(type, referencedClass, mayBeNull); 47 48 this.valuefactory = valuefactory; 49 this.id = id; 50 } 51 52 53 // Implementations of binary methods of ReferenceValue. 54 55 public ReferenceValue generalize(ReferenceValue other) 56 { 57 return other.generalize(this); 58 } 59 60 61 public int equal(ReferenceValue other) 62 { 63 return other.equal(this); 64 } 65 66 67 // Implementations of binary ReferenceValue methods with 68 // IdentifiedReferenceValue arguments. 69 70 // public ReferenceValue generalize(IdentifiedReferenceValue other) 71 // { 72 // return generalize((TypedReferenceValue)other); 73 // } 74 75 76 public int equal(IdentifiedReferenceValue other) 77 { 78 return this.equals(other) ? ALWAYS : 79 this.equal((TypedReferenceValue)other); 80 } 81 82 83 // // Implementations of binary ReferenceValue methods with 84 // // ArrayReferenceValue arguments. 85 // 86 // public ReferenceValue generalize(ArrayReferenceValue other) 87 // { 88 // return generalize((TypedReferenceValue)other); 89 // } 90 // 91 // 92 // public int equal(ArrayReferenceValue other) 93 // { 94 // return equal((TypedReferenceValue)other); 95 // } 96 // 97 // 98 // // Implementations of binary ReferenceValue methods with 99 // // IdentifiedArrayReferenceValue arguments. 100 // 101 // public ReferenceValue generalize(IdentifiedArrayReferenceValue other) 102 // { 103 // return generalize((ArrayReferenceValue)other); 104 // } 105 // 106 // 107 // public int equal(IdentifiedArrayReferenceValue other) 108 // { 109 // return equal((ArrayReferenceValue)other); 110 // } 111 // 112 // 113 // // Implementations of binary ReferenceValue methods with 114 // // DetailedArrayReferenceValue arguments. 115 // 116 // public ReferenceValue generalize(DetailedArrayReferenceValue other) 117 // { 118 // return generalize((IdentifiedArrayReferenceValue)other); 119 // } 120 // 121 // 122 // public int equal(DetailedArrayReferenceValue other) 123 // { 124 // return equal((IdentifiedArrayReferenceValue)other); 125 // } 126 127 128 // Implementations for Value. 129 130 public boolean isSpecific() 131 { 132 return true; 133 } 134 135 136 // Implementations for Object. 137 138 public boolean equals(Object object) 139 { 140 return this == object || 141 super.equals(object) && 142 this.valuefactory.equals(((IdentifiedReferenceValue)object).valuefactory) && 143 this.id == ((IdentifiedReferenceValue)object).id; 144 } 145 146 147 public int hashCode() 148 { 149 return super.hashCode() ^ 150 valuefactory.hashCode() ^ 151 id; 152 } 153 154 155 public String toString() 156 { 157 return super.toString()+'#'+id; 158 } 159 }