Home | History | Annotate | Download | only in file
      1 /*
      2  * Copyright (C) 2008 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.dx.dex.file;
     18 
     19 import com.android.dx.util.ToHuman;
     20 
     21 /**
     22  * Enumeration of all the top-level item types.
     23  */
     24 public enum ItemType implements ToHuman {
     25     TYPE_HEADER_ITEM(               0x0000, "header_item"),
     26     TYPE_STRING_ID_ITEM(            0x0001, "string_id_item"),
     27     TYPE_TYPE_ID_ITEM(              0x0002, "type_id_item"),
     28     TYPE_PROTO_ID_ITEM(             0x0003, "proto_id_item"),
     29     TYPE_FIELD_ID_ITEM(             0x0004, "field_id_item"),
     30     TYPE_METHOD_ID_ITEM(            0x0005, "method_id_item"),
     31     TYPE_CLASS_DEF_ITEM(            0x0006, "class_def_item"),
     32     TYPE_MAP_LIST(                  0x1000, "map_list"),
     33     TYPE_TYPE_LIST(                 0x1001, "type_list"),
     34     TYPE_ANNOTATION_SET_REF_LIST(   0x1002, "annotation_set_ref_list"),
     35     TYPE_ANNOTATION_SET_ITEM(       0x1003, "annotation_set_item"),
     36     TYPE_CLASS_DATA_ITEM(           0x2000, "class_data_item"),
     37     TYPE_CODE_ITEM(                 0x2001, "code_item"),
     38     TYPE_STRING_DATA_ITEM(          0x2002, "string_data_item"),
     39     TYPE_DEBUG_INFO_ITEM(           0x2003, "debug_info_item"),
     40     TYPE_ANNOTATION_ITEM(           0x2004, "annotation_item"),
     41     TYPE_ENCODED_ARRAY_ITEM(        0x2005, "encoded_array_item"),
     42     TYPE_ANNOTATIONS_DIRECTORY_ITEM(0x2006, "annotations_directory_item"),
     43     TYPE_MAP_ITEM(                  -1,     "map_item"),
     44     TYPE_TYPE_ITEM(                 -1,     "type_item"),
     45     TYPE_EXCEPTION_HANDLER_ITEM(    -1,     "exception_handler_item"),
     46     TYPE_ANNOTATION_SET_REF_ITEM(   -1,     "annotation_set_ref_item");
     47 
     48     /** value when represented in a {@link MapItem} */
     49     private final int mapValue;
     50 
     51     /** {@code non-null;} name of the type */
     52     private final String typeName;
     53 
     54     /** {@code non-null;} the short human name */
     55     private final String humanName;
     56 
     57     /**
     58      * Constructs an instance.
     59      *
     60      * @param mapValue value when represented in a {@link MapItem}
     61      * @param typeName {@code non-null;} name of the type
     62      */
     63     private ItemType(int mapValue, String typeName) {
     64         this.mapValue = mapValue;
     65         this.typeName = typeName;
     66 
     67         // Make the human name.
     68         String human = typeName;
     69         if (human.endsWith("_item")) {
     70             human = human.substring(0, human.length() - 5);
     71         }
     72         this.humanName = human.replace('_', ' ');
     73     }
     74 
     75     /**
     76      * Gets the map value.
     77      *
     78      * @return the map value
     79      */
     80     public int getMapValue() {
     81         return mapValue;
     82     }
     83 
     84     /**
     85      * Gets the type name.
     86      *
     87      * @return {@code non-null;} the type name
     88      */
     89     public String getTypeName() {
     90         return typeName;
     91     }
     92 
     93     /** {@inheritDoc} */
     94     public String toHuman() {
     95         return humanName;
     96     }
     97 }
     98