1917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul/* 2917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Copyright (C) 2008 The Android Open Source Project 3917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * 4917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Licensed under the Apache License, Version 2.0 (the "License"); 5917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * you may not use this file except in compliance with the License. 6917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * You may obtain a copy of the License at 7917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * 8917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * http://www.apache.org/licenses/LICENSE-2.0 9917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * 10917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Unless required by applicable law or agreed to in writing, software 11917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * distributed under the License is distributed on an "AS IS" BASIS, 12917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * See the License for the specific language governing permissions and 14917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * limitations under the License. 15917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul */ 16917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 17917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgulpackage com.android.dexgen.dex.file; 18917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 19917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgulimport com.android.dexgen.util.ToHuman; 20917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 21917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul/** 22917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Enumeration of all the top-level item types. 23917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul */ 24917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgulpublic enum ItemType implements ToHuman { 25917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_HEADER_ITEM( 0x0000, "header_item"), 26917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_STRING_ID_ITEM( 0x0001, "string_id_item"), 27917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_TYPE_ID_ITEM( 0x0002, "type_id_item"), 28917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_PROTO_ID_ITEM( 0x0003, "proto_id_item"), 29917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_FIELD_ID_ITEM( 0x0004, "field_id_item"), 30917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_METHOD_ID_ITEM( 0x0005, "method_id_item"), 31917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_CLASS_DEF_ITEM( 0x0006, "class_def_item"), 32917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_MAP_LIST( 0x1000, "map_list"), 33917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_TYPE_LIST( 0x1001, "type_list"), 34917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_ANNOTATION_SET_REF_LIST( 0x1002, "annotation_set_ref_list"), 35917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_ANNOTATION_SET_ITEM( 0x1003, "annotation_set_item"), 36917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_CLASS_DATA_ITEM( 0x2000, "class_data_item"), 37917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_CODE_ITEM( 0x2001, "code_item"), 38917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_STRING_DATA_ITEM( 0x2002, "string_data_item"), 39917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_DEBUG_INFO_ITEM( 0x2003, "debug_info_item"), 40917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_ANNOTATION_ITEM( 0x2004, "annotation_item"), 41917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_ENCODED_ARRAY_ITEM( 0x2005, "encoded_array_item"), 42917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_ANNOTATIONS_DIRECTORY_ITEM(0x2006, "annotations_directory_item"), 43917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_MAP_ITEM( -1, "map_item"), 44917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_TYPE_ITEM( -1, "type_item"), 45917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_EXCEPTION_HANDLER_ITEM( -1, "exception_handler_item"), 46917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul TYPE_ANNOTATION_SET_REF_ITEM( -1, "annotation_set_ref_item"); 47917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 48917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** value when represented in a {@link MapItem} */ 49917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul private final int mapValue; 50917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 51917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** {@code non-null;} name of the type */ 52917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul private final String typeName; 53917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 54917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** {@code non-null;} the short human name */ 55917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul private final String humanName; 56917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 57917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** 58917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Constructs an instance. 59917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * 60917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * @param mapValue value when represented in a {@link MapItem} 61917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * @param typeName {@code non-null;} name of the type 62917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul */ 63917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul private ItemType(int mapValue, String typeName) { 64917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul this.mapValue = mapValue; 65917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul this.typeName = typeName; 66917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 67917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul // Make the human name. 68917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul String human = typeName; 69917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul if (human.endsWith("_item")) { 70917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul human = human.substring(0, human.length() - 5); 71917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul } 72917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul this.humanName = human.replace('_', ' '); 73917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul } 74917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 75917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** 76917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Gets the map value. 77917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * 78917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * @return the map value 79917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul */ 80917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul public int getMapValue() { 81917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul return mapValue; 82917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul } 83917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 84917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** 85917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * Gets the type name. 86917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * 87917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul * @return {@code non-null;} the type name 88917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul */ 89917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul public String getTypeName() { 90917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul return typeName; 91917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul } 92917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul 93917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul /** {@inheritDoc} */ 94917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul public String toHuman() { 95917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul return humanName; 96917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul } 97917cb222329ee8c035c3ffaf947e4265761b9367Piotr Gurgul} 98