1/* 2 * Copyright (C) 2007 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.android.dx.dex.file; 18 19import com.android.dx.rop.cst.CstFieldRef; 20 21/** 22 * Representation of a field reference inside a Dalvik file. 23 */ 24public final class FieldIdItem extends MemberIdItem { 25 /** 26 * Constructs an instance. 27 * 28 * @param field non-null; the constant for the field 29 */ 30 public FieldIdItem(CstFieldRef field) { 31 super(field); 32 } 33 34 /** {@inheritDoc} */ 35 @Override 36 public ItemType itemType() { 37 return ItemType.TYPE_FIELD_ID_ITEM; 38 } 39 40 /** {@inheritDoc} */ 41 @Override 42 public void addContents(DexFile file) { 43 super.addContents(file); 44 45 TypeIdsSection typeIds = file.getTypeIds(); 46 typeIds.intern(getFieldRef().getType()); 47 } 48 49 /** 50 * Gets the field constant. 51 * 52 * @return non-null; the constant 53 */ 54 public CstFieldRef getFieldRef() { 55 return (CstFieldRef) getRef(); 56 } 57 58 /** {@inheritDoc} */ 59 @Override 60 protected int getTypoidIdx(DexFile file) { 61 TypeIdsSection typeIds = file.getTypeIds(); 62 return typeIds.indexOf(getFieldRef().getType()); 63 } 64 65 /** {@inheritDoc} */ 66 @Override 67 protected String getTypoidName() { 68 return "type_idx"; 69 } 70} 71