Home | History | Annotate | Download | only in file
      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.CstBaseMethodRef;
     20 
     21 /**
     22  * Representation of a method reference inside a Dalvik file.
     23  */
     24 public final class MethodIdItem extends MemberIdItem {
     25     /**
     26      * Constructs an instance.
     27      *
     28      * @param method {@code non-null;} the constant for the method
     29      */
     30     public MethodIdItem(CstBaseMethodRef method) {
     31         super(method);
     32     }
     33 
     34     /** {@inheritDoc} */
     35     @Override
     36     public ItemType itemType() {
     37         return ItemType.TYPE_METHOD_ID_ITEM;
     38     }
     39 
     40     /** {@inheritDoc} */
     41     @Override
     42     public void addContents(DexFile file) {
     43         super.addContents(file);
     44 
     45         ProtoIdsSection protoIds = file.getProtoIds();
     46         protoIds.intern(getMethodRef().getPrototype());
     47     }
     48 
     49     /**
     50      * Gets the method constant.
     51      *
     52      * @return {@code non-null;} the constant
     53      */
     54     public CstBaseMethodRef getMethodRef() {
     55         return (CstBaseMethodRef) getRef();
     56     }
     57 
     58     /** {@inheritDoc} */
     59     @Override
     60     protected int getTypoidIdx(DexFile file) {
     61         ProtoIdsSection protoIds = file.getProtoIds();
     62         return protoIds.indexOf(getMethodRef().getPrototype());
     63     }
     64 
     65     /** {@inheritDoc} */
     66     @Override
     67     protected String getTypoidName() {
     68         return "proto_idx";
     69     }
     70 }
     71