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
17package com.android.dx.dex.file;
18
19import com.android.dx.util.ToHuman;
20
21/**
22 * Enumeration of all the top-level item types.
23 */
24public 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_CALL_SITE_ID_ITEM(         0x0007, "call_site_id_item"),
33    TYPE_METHOD_HANDLE_ITEM(        0x0008, "method_handle_item"),
34    TYPE_MAP_LIST(                  0x1000, "map_list"),
35    TYPE_TYPE_LIST(                 0x1001, "type_list"),
36    TYPE_ANNOTATION_SET_REF_LIST(   0x1002, "annotation_set_ref_list"),
37    TYPE_ANNOTATION_SET_ITEM(       0x1003, "annotation_set_item"),
38    TYPE_CLASS_DATA_ITEM(           0x2000, "class_data_item"),
39    TYPE_CODE_ITEM(                 0x2001, "code_item"),
40    TYPE_STRING_DATA_ITEM(          0x2002, "string_data_item"),
41    TYPE_DEBUG_INFO_ITEM(           0x2003, "debug_info_item"),
42    TYPE_ANNOTATION_ITEM(           0x2004, "annotation_item"),
43    TYPE_ENCODED_ARRAY_ITEM(        0x2005, "encoded_array_item"),
44    TYPE_ANNOTATIONS_DIRECTORY_ITEM(0x2006, "annotations_directory_item"),
45    TYPE_MAP_ITEM(                  -1,     "map_item"),
46    TYPE_TYPE_ITEM(                 -1,     "type_item"),
47    TYPE_EXCEPTION_HANDLER_ITEM(    -1,     "exception_handler_item"),
48    TYPE_ANNOTATION_SET_REF_ITEM(   -1,     "annotation_set_ref_item");
49
50    /** value when represented in a {@link MapItem} */
51    private final int mapValue;
52
53    /** {@code non-null;} name of the type */
54    private final String typeName;
55
56    /** {@code non-null;} the short human name */
57    private final String humanName;
58
59    /**
60     * Constructs an instance.
61     *
62     * @param mapValue value when represented in a {@link MapItem}
63     * @param typeName {@code non-null;} name of the type
64     */
65    private ItemType(int mapValue, String typeName) {
66        this.mapValue = mapValue;
67        this.typeName = typeName;
68
69        // Make the human name.
70        String human = typeName;
71        if (human.endsWith("_item")) {
72            human = human.substring(0, human.length() - 5);
73        }
74        this.humanName = human.replace('_', ' ');
75    }
76
77    /**
78     * Gets the map value.
79     *
80     * @return the map value
81     */
82    public int getMapValue() {
83        return mapValue;
84    }
85
86    /**
87     * Gets the type name.
88     *
89     * @return {@code non-null;} the type name
90     */
91    public String getTypeName() {
92        return typeName;
93    }
94
95    /** {@inheritDoc} */
96    @Override
97    public String toHuman() {
98        return humanName;
99    }
100}
101