• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.dexgen.dex.file;
18 
19 import com.android.dexgen.rop.cst.CstFieldRef;
20 
21 /**
22  * Representation of a field reference inside a Dalvik file.
23  */
24 public final class FieldIdItem extends MemberIdItem {
25     /**
26      * Constructs an instance.
27      *
28      * @param field {@code non-null;} the constant for the field
29      */
FieldIdItem(CstFieldRef field)30     public FieldIdItem(CstFieldRef field) {
31         super(field);
32     }
33 
34     /** {@inheritDoc} */
35     @Override
itemType()36     public ItemType itemType() {
37         return ItemType.TYPE_FIELD_ID_ITEM;
38     }
39 
40     /** {@inheritDoc} */
41     @Override
addContents(DexFile file)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 {@code non-null;} the constant
53      */
getFieldRef()54     public CstFieldRef getFieldRef() {
55         return (CstFieldRef) getRef();
56     }
57 
58     /** {@inheritDoc} */
59     @Override
getTypoidIdx(DexFile file)60     protected int getTypoidIdx(DexFile file) {
61         TypeIdsSection typeIds = file.getTypeIds();
62         return typeIds.indexOf(getFieldRef().getType());
63     }
64 
65     /** {@inheritDoc} */
66     @Override
getTypoidName()67     protected String getTypoidName() {
68         return "type_idx";
69     }
70 }
71