FieldId.java revision 23abc2fe89ec3713645d64bdb74415a9090084f4
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.dexmaker; 18 19import com.android.dx.rop.cst.CstFieldRef; 20import com.android.dx.rop.cst.CstNat; 21import com.android.dx.rop.cst.CstString; 22 23/** 24 * Identifies a field. 25 */ 26public final class FieldId<D, V> { 27 final TypeId<D> declaringType; 28 final TypeId<V> type; 29 final String name; 30 31 /** cached converted state */ 32 final CstNat nat; 33 final CstFieldRef constant; 34 35 FieldId(TypeId<D> declaringType, TypeId<V> type, String name) { 36 if (declaringType == null || type == null || name == null) { 37 throw new NullPointerException(); 38 } 39 this.declaringType = declaringType; 40 this.type = type; 41 this.name = name; 42 this.nat = new CstNat(new CstString(name), new CstString(type.name)); 43 this.constant = new CstFieldRef(declaringType.constant, nat); 44 } 45 46 public TypeId<D> getDeclaringType() { 47 return declaringType; 48 } 49 50 public TypeId<V> getType() { 51 return type; 52 } 53 54 public String getName() { 55 return name; 56 } 57 58 @Override public boolean equals(Object o) { 59 return o instanceof FieldId 60 && ((FieldId<?, ?>) o).declaringType.equals(declaringType) 61 && ((FieldId<?, ?>) o).name.equals(name); 62 } 63 64 @Override public int hashCode() { 65 return declaringType.hashCode() + 37 * name.hashCode(); 66 } 67 68 @Override public String toString() { 69 return declaringType + "." + name; 70 } 71} 72