Home | History | Annotate | Download | only in smalidea
      1 /*
      2  * Copyright 2014, Google Inc.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions are
      7  * met:
      8  *
      9  *     * Redistributions of source code must retain the above copyright
     10  * notice, this list of conditions and the following disclaimer.
     11  *     * Redistributions in binary form must reproduce the above
     12  * copyright notice, this list of conditions and the following disclaimer
     13  * in the documentation and/or other materials provided with the
     14  * distribution.
     15  *     * Neither the name of Google Inc. nor the names of its
     16  * contributors may be used to endorse or promote products derived from
     17  * this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 package org.jf.smalidea;
     33 
     34 import com.google.common.collect.Maps;
     35 import com.intellij.openapi.editor.colors.TextAttributesKey;
     36 import com.intellij.psi.tree.IElementType;
     37 import com.intellij.psi.tree.TokenSet;
     38 import org.jf.smali.smaliParser;
     39 
     40 import java.lang.reflect.Field;
     41 import java.util.Map;
     42 
     43 public class SmaliTokens {
     44     private static final IElementType[] ELEMENT_TYPES;
     45 
     46     public static IElementType getElementType(int tokenType) {
     47         return ELEMENT_TYPES[tokenType];
     48     }
     49 
     50     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ACCESS_SPEC;
     51     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ANNOTATION_DIRECTIVE;
     52     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ANNOTATION_VISIBILITY;
     53     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ARRAY_DATA_DIRECTIVE;
     54     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ARRAY_TYPE_PREFIX;
     55     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ARROW;
     56     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType BOOL_LITERAL;
     57     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType BYTE_LITERAL;
     58     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CATCH_DIRECTIVE;
     59     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CATCHALL_DIRECTIVE;
     60     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CHAR_LITERAL;
     61     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CLASS_DESCRIPTOR;
     62     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CLASS_DIRECTIVE;
     63     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CLOSE_BRACE;
     64     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType CLOSE_PAREN;
     65     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType COLON;
     66     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType COMMA;
     67     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType DOTDOT;
     68     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType DOUBLE_LITERAL;
     69     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType DOUBLE_LITERAL_OR_ID;
     70     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_ANNOTATION_DIRECTIVE;
     71     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_ARRAY_DATA_DIRECTIVE;
     72     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_FIELD_DIRECTIVE;
     73     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_LOCAL_DIRECTIVE;
     74     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_METHOD_DIRECTIVE;
     75     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_PACKED_SWITCH_DIRECTIVE;
     76     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_PARAMETER_DIRECTIVE;
     77     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_SPARSE_SWITCH_DIRECTIVE;
     78     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType END_SUBANNOTATION_DIRECTIVE;
     79     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType ENUM_DIRECTIVE;
     80     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType EPILOGUE_DIRECTIVE;
     81     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType EQUAL;
     82     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType FIELD_DIRECTIVE;
     83     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType FIELD_OFFSET;
     84     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType FLOAT_LITERAL;
     85     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType FLOAT_LITERAL_OR_ID;
     86     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType IMPLEMENTS_DIRECTIVE;
     87     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INLINE_INDEX;
     88     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT10t;
     89     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT10x;
     90     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT10x_ODEX;
     91     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT11n;
     92     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT11x;
     93     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT12x;
     94     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT12x_OR_ID;
     95     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT20bc;
     96     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT20t;
     97     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21c_FIELD;
     98     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21c_FIELD_ODEX;
     99     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21c_STRING;
    100     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21c_TYPE;
    101     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21ih;
    102     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21lh;
    103     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21s;
    104     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT21t;
    105     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22b;
    106     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22c_FIELD;
    107     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22c_FIELD_ODEX;
    108     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22c_TYPE;
    109     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22cs_FIELD;
    110     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22s;
    111     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22s_OR_ID;
    112     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22t;
    113     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT22x;
    114     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT23x;
    115     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT30t;
    116     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT31c;
    117     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT31i;
    118     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT31i_OR_ID;
    119     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT31t;
    120     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT32x;
    121     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT35c_METHOD;
    122     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT35c_METHOD_ODEX;
    123     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT35c_TYPE;
    124     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT35mi_METHOD;
    125     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT35ms_METHOD;
    126     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT3rc_METHOD;
    127     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT3rc_METHOD_ODEX;
    128     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT3rc_TYPE;
    129     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT3rmi_METHOD;
    130     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT3rms_METHOD;
    131     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType INSTRUCTION_FORMAT51l;
    132     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType LINE_COMMENT;
    133     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType LINE_DIRECTIVE;
    134     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType LOCAL_DIRECTIVE;
    135     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType LOCALS_DIRECTIVE;
    136     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType LONG_LITERAL;
    137     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType METHOD_DIRECTIVE;
    138     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType MEMBER_NAME;
    139     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType NEGATIVE_INTEGER_LITERAL;
    140     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType NULL_LITERAL;
    141     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType OPEN_BRACE;
    142     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType OPEN_PAREN;
    143     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType PACKED_SWITCH_DIRECTIVE;
    144     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType PARAM_LIST_OR_ID_PRIMITIVE_TYPE;
    145     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType PARAMETER_DIRECTIVE;
    146     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType POSITIVE_INTEGER_LITERAL;
    147     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType PRIMITIVE_TYPE;
    148     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType PROLOGUE_DIRECTIVE;
    149     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType REGISTER;
    150     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType REGISTERS_DIRECTIVE;
    151     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType RESTART_LOCAL_DIRECTIVE;
    152     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType SHORT_LITERAL;
    153     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType SIMPLE_NAME;
    154     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType SOURCE_DIRECTIVE;
    155     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType SPARSE_SWITCH_DIRECTIVE;
    156     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType STRING_LITERAL;
    157     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType SUBANNOTATION_DIRECTIVE;
    158     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType SUPER_DIRECTIVE;
    159     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType VERIFICATION_ERROR_TYPE;
    160     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType VOID_TYPE;
    161     @SuppressWarnings({"UnusedDeclaration"}) public static IElementType VTABLE_INDEX;
    162 
    163     public static final TokenSet INSTRUCTION_TOKENS;
    164 
    165     static {
    166         Map<String, TextAttributesKey> tokenColors = Maps.newHashMap();
    167 
    168         tokenColors.put("ACCESS_SPEC", SmaliHighlightingColors.ACCESS);
    169         tokenColors.put("ANNOTATION_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    170         tokenColors.put("ANNOTATION_VISIBILITY", SmaliHighlightingColors.ACCESS);
    171         tokenColors.put("ARRAY_DATA_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    172         tokenColors.put("ARRAY_TYPE_PREFIX", SmaliHighlightingColors.TYPE);
    173         tokenColors.put("ARROW", SmaliHighlightingColors.ARROW);
    174         tokenColors.put("BOOL_LITERAL", SmaliHighlightingColors.LITERAL);
    175         tokenColors.put("BYTE_LITERAL", SmaliHighlightingColors.NUMBER);
    176         tokenColors.put("CATCH_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    177         tokenColors.put("CATCHALL_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    178         tokenColors.put("CHAR_LITERAL", SmaliHighlightingColors.STRING);
    179         tokenColors.put("CLASS_DESCRIPTOR", SmaliHighlightingColors.TYPE);
    180         tokenColors.put("CLASS_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    181         tokenColors.put("CLOSE_BRACE", SmaliHighlightingColors.BRACES);
    182         tokenColors.put("CLOSE_PAREN", SmaliHighlightingColors.PARENS);
    183         tokenColors.put("COLON", SmaliHighlightingColors.COLON);
    184         tokenColors.put("COMMA", SmaliHighlightingColors.COMMA);
    185         tokenColors.put("DOTDOT", SmaliHighlightingColors.DOTDOT);
    186         tokenColors.put("DOUBLE_LITERAL", SmaliHighlightingColors.NUMBER);
    187         tokenColors.put("DOUBLE_LITERAL_OR_ID", SmaliHighlightingColors.NUMBER);
    188         tokenColors.put("END_ANNOTATION_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    189         tokenColors.put("END_ARRAY_DATA_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    190         tokenColors.put("END_FIELD_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    191         tokenColors.put("END_LOCAL_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    192         tokenColors.put("END_METHOD_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    193         tokenColors.put("END_PACKED_SWITCH_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    194         tokenColors.put("END_PARAMETER_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    195         tokenColors.put("END_SPARSE_SWITCH_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    196         tokenColors.put("END_SUBANNOTATION_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    197         tokenColors.put("ENUM_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    198         tokenColors.put("EPILOGUE_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    199         tokenColors.put("EQUAL", SmaliHighlightingColors.EQUAL);
    200         tokenColors.put("FIELD_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    201         tokenColors.put("FIELD_OFFSET", SmaliHighlightingColors.ODEX_REFERENCE);
    202         tokenColors.put("FLOAT_LITERAL", SmaliHighlightingColors.NUMBER);
    203         tokenColors.put("FLOAT_LITERAL_OR_ID", SmaliHighlightingColors.NUMBER);
    204         tokenColors.put("IMPLEMENTS_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    205         tokenColors.put("INLINE_INDEX", SmaliHighlightingColors.ODEX_REFERENCE);
    206         tokenColors.put("INSTRUCTION_FORMAT10t", SmaliHighlightingColors.INSTRUCTION);
    207         tokenColors.put("INSTRUCTION_FORMAT10x", SmaliHighlightingColors.INSTRUCTION);
    208         tokenColors.put("INSTRUCTION_FORMAT10x_ODEX", SmaliHighlightingColors.INSTRUCTION);
    209         tokenColors.put("INSTRUCTION_FORMAT11n", SmaliHighlightingColors.INSTRUCTION);
    210         tokenColors.put("INSTRUCTION_FORMAT11x", SmaliHighlightingColors.INSTRUCTION);
    211         tokenColors.put("INSTRUCTION_FORMAT12x", SmaliHighlightingColors.INSTRUCTION);
    212         tokenColors.put("INSTRUCTION_FORMAT12x_OR_ID", SmaliHighlightingColors.INSTRUCTION);
    213         tokenColors.put("INSTRUCTION_FORMAT20bc", SmaliHighlightingColors.INSTRUCTION);
    214         tokenColors.put("INSTRUCTION_FORMAT20t", SmaliHighlightingColors.INSTRUCTION);
    215         tokenColors.put("INSTRUCTION_FORMAT21c_FIELD", SmaliHighlightingColors.INSTRUCTION);
    216         tokenColors.put("INSTRUCTION_FORMAT21c_FIELD_ODEX", SmaliHighlightingColors.INSTRUCTION);
    217         tokenColors.put("INSTRUCTION_FORMAT21c_STRING", SmaliHighlightingColors.INSTRUCTION);
    218         tokenColors.put("INSTRUCTION_FORMAT21c_TYPE", SmaliHighlightingColors.INSTRUCTION);
    219         tokenColors.put("INSTRUCTION_FORMAT21ih", SmaliHighlightingColors.INSTRUCTION);
    220         tokenColors.put("INSTRUCTION_FORMAT21lh", SmaliHighlightingColors.INSTRUCTION);
    221         tokenColors.put("INSTRUCTION_FORMAT21s", SmaliHighlightingColors.INSTRUCTION);
    222         tokenColors.put("INSTRUCTION_FORMAT21t", SmaliHighlightingColors.INSTRUCTION);
    223         tokenColors.put("INSTRUCTION_FORMAT22b", SmaliHighlightingColors.INSTRUCTION);
    224         tokenColors.put("INSTRUCTION_FORMAT22c_FIELD", SmaliHighlightingColors.INSTRUCTION);
    225         tokenColors.put("INSTRUCTION_FORMAT22c_FIELD_ODEX", SmaliHighlightingColors.INSTRUCTION);
    226         tokenColors.put("INSTRUCTION_FORMAT22c_TYPE", SmaliHighlightingColors.INSTRUCTION);
    227         tokenColors.put("INSTRUCTION_FORMAT22cs_FIELD", SmaliHighlightingColors.INSTRUCTION);
    228         tokenColors.put("INSTRUCTION_FORMAT22s", SmaliHighlightingColors.INSTRUCTION);
    229         tokenColors.put("INSTRUCTION_FORMAT22s_OR_ID", SmaliHighlightingColors.INSTRUCTION);
    230         tokenColors.put("INSTRUCTION_FORMAT22t", SmaliHighlightingColors.INSTRUCTION);
    231         tokenColors.put("INSTRUCTION_FORMAT22x", SmaliHighlightingColors.INSTRUCTION);
    232         tokenColors.put("INSTRUCTION_FORMAT23x", SmaliHighlightingColors.INSTRUCTION);
    233         tokenColors.put("INSTRUCTION_FORMAT30t", SmaliHighlightingColors.INSTRUCTION);
    234         tokenColors.put("INSTRUCTION_FORMAT31c", SmaliHighlightingColors.INSTRUCTION);
    235         tokenColors.put("INSTRUCTION_FORMAT31i", SmaliHighlightingColors.INSTRUCTION);
    236         tokenColors.put("INSTRUCTION_FORMAT31i_OR_ID", SmaliHighlightingColors.INSTRUCTION);
    237         tokenColors.put("INSTRUCTION_FORMAT31t", SmaliHighlightingColors.INSTRUCTION);
    238         tokenColors.put("INSTRUCTION_FORMAT32x", SmaliHighlightingColors.INSTRUCTION);
    239         tokenColors.put("INSTRUCTION_FORMAT35c_METHOD", SmaliHighlightingColors.INSTRUCTION);
    240         tokenColors.put("INSTRUCTION_FORMAT35c_METHOD_ODEX", SmaliHighlightingColors.INSTRUCTION);
    241         tokenColors.put("INSTRUCTION_FORMAT35c_TYPE", SmaliHighlightingColors.INSTRUCTION);
    242         tokenColors.put("INSTRUCTION_FORMAT35mi_METHOD", SmaliHighlightingColors.INSTRUCTION);
    243         tokenColors.put("INSTRUCTION_FORMAT35ms_METHOD", SmaliHighlightingColors.INSTRUCTION);
    244         tokenColors.put("INSTRUCTION_FORMAT3rc_METHOD", SmaliHighlightingColors.INSTRUCTION);
    245         tokenColors.put("INSTRUCTION_FORMAT3rc_METHOD_ODEX", SmaliHighlightingColors.INSTRUCTION);
    246         tokenColors.put("INSTRUCTION_FORMAT3rc_TYPE", SmaliHighlightingColors.INSTRUCTION);
    247         tokenColors.put("INSTRUCTION_FORMAT3rmi_METHOD", SmaliHighlightingColors.INSTRUCTION);
    248         tokenColors.put("INSTRUCTION_FORMAT3rms_METHOD", SmaliHighlightingColors.INSTRUCTION);
    249         tokenColors.put("INSTRUCTION_FORMAT51l", SmaliHighlightingColors.INSTRUCTION);
    250         tokenColors.put("LINE_COMMENT", SmaliHighlightingColors.COMMENT);
    251         tokenColors.put("LINE_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    252         tokenColors.put("LOCAL_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    253         tokenColors.put("LOCALS_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    254         tokenColors.put("LONG_LITERAL", SmaliHighlightingColors.NUMBER);
    255         tokenColors.put("MEMBER_NAME", SmaliHighlightingColors.IDENTIFIER);
    256         tokenColors.put("METHOD_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    257         tokenColors.put("NEGATIVE_INTEGER_LITERAL", SmaliHighlightingColors.NUMBER);
    258         tokenColors.put("NULL_LITERAL", SmaliHighlightingColors.LITERAL);
    259         tokenColors.put("OPEN_BRACE", SmaliHighlightingColors.BRACES);
    260         tokenColors.put("OPEN_PAREN", SmaliHighlightingColors.PARENS);
    261         tokenColors.put("PACKED_SWITCH_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    262         tokenColors.put("PARAM_LIST_OR_ID_PRIMITIVE_TYPE", SmaliHighlightingColors.TYPE);
    263         tokenColors.put("PARAMETER_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    264         tokenColors.put("POSITIVE_INTEGER_LITERAL", SmaliHighlightingColors.NUMBER);
    265         tokenColors.put("PRIMITIVE_TYPE", SmaliHighlightingColors.TYPE);
    266         tokenColors.put("PROLOGUE_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    267         tokenColors.put("REGISTER", SmaliHighlightingColors.REGISTER);
    268         tokenColors.put("REGISTERS_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    269         tokenColors.put("RESTART_LOCAL_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    270         tokenColors.put("SHORT_LITERAL", SmaliHighlightingColors.NUMBER);
    271         tokenColors.put("SIMPLE_NAME", SmaliHighlightingColors.IDENTIFIER);
    272         tokenColors.put("SOURCE_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    273         tokenColors.put("SPARSE_SWITCH_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    274         tokenColors.put("STRING_LITERAL", SmaliHighlightingColors.STRING);
    275         tokenColors.put("SUBANNOTATION_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    276         tokenColors.put("SUPER_DIRECTIVE", SmaliHighlightingColors.DIRECTIVE);
    277         tokenColors.put("VERIFICATION_ERROR_TYPE", SmaliHighlightingColors.VERIFICATION_ERROR_TYPE);
    278         tokenColors.put("VOID_TYPE", SmaliHighlightingColors.TYPE);
    279         tokenColors.put("VTABLE_INDEX", SmaliHighlightingColors.ODEX_REFERENCE);
    280 
    281         int tokenCount = smaliParser.tokenNames.length;
    282         ELEMENT_TYPES = new IElementType[tokenCount];
    283 
    284         for (int tokenId=0; tokenId<tokenCount; tokenId++) {
    285             String tokenName = smaliParser.tokenNames[tokenId];
    286             Field field;
    287 
    288             try {
    289                 field = SmaliTokens.class.getField(tokenName);
    290             } catch (NoSuchFieldException ex) {
    291                 continue;
    292             }
    293 
    294             TextAttributesKey textAttributesKey = tokenColors.get(tokenName);
    295 
    296             if (textAttributesKey == null) {
    297                 throw new RuntimeException("No color attribute for token " + tokenName);
    298             }
    299 
    300             SmaliLexicalElementType elementType = new SmaliLexicalElementType(tokenId, tokenName, textAttributesKey);
    301             ELEMENT_TYPES[tokenId] = elementType;
    302 
    303             try {
    304                 field.set(null, elementType);
    305             } catch (IllegalAccessException ex) {
    306                 throw new RuntimeException(ex);
    307             }
    308         }
    309 
    310         INSTRUCTION_TOKENS = TokenSet.create(
    311                 INSTRUCTION_FORMAT10t,
    312                 INSTRUCTION_FORMAT10x,
    313                 INSTRUCTION_FORMAT10x_ODEX,
    314                 INSTRUCTION_FORMAT11n,
    315                 INSTRUCTION_FORMAT11x,
    316                 INSTRUCTION_FORMAT12x_OR_ID,
    317                 INSTRUCTION_FORMAT12x,
    318                 INSTRUCTION_FORMAT20bc,
    319                 INSTRUCTION_FORMAT20t,
    320                 INSTRUCTION_FORMAT21c_FIELD,
    321                 INSTRUCTION_FORMAT21c_FIELD_ODEX,
    322                 INSTRUCTION_FORMAT21c_STRING,
    323                 INSTRUCTION_FORMAT21c_TYPE,
    324                 INSTRUCTION_FORMAT21ih,
    325                 INSTRUCTION_FORMAT21lh,
    326                 INSTRUCTION_FORMAT21s,
    327                 INSTRUCTION_FORMAT21t,
    328                 INSTRUCTION_FORMAT22b,
    329                 INSTRUCTION_FORMAT22c_FIELD,
    330                 INSTRUCTION_FORMAT22c_FIELD_ODEX,
    331                 INSTRUCTION_FORMAT22c_TYPE,
    332                 INSTRUCTION_FORMAT22cs_FIELD,
    333                 INSTRUCTION_FORMAT22s_OR_ID,
    334                 INSTRUCTION_FORMAT22s,
    335                 INSTRUCTION_FORMAT22t,
    336                 INSTRUCTION_FORMAT22x,
    337                 INSTRUCTION_FORMAT23x,
    338                 INSTRUCTION_FORMAT30t,
    339                 INSTRUCTION_FORMAT31c,
    340                 INSTRUCTION_FORMAT31i_OR_ID,
    341                 INSTRUCTION_FORMAT31i,
    342                 INSTRUCTION_FORMAT31t,
    343                 INSTRUCTION_FORMAT32x,
    344                 INSTRUCTION_FORMAT35c_METHOD,
    345                 INSTRUCTION_FORMAT35c_METHOD_ODEX,
    346                 INSTRUCTION_FORMAT35c_TYPE,
    347                 INSTRUCTION_FORMAT35mi_METHOD,
    348                 INSTRUCTION_FORMAT35ms_METHOD,
    349                 INSTRUCTION_FORMAT3rc_METHOD,
    350                 INSTRUCTION_FORMAT3rc_METHOD_ODEX,
    351                 INSTRUCTION_FORMAT3rc_TYPE,
    352                 INSTRUCTION_FORMAT3rmi_METHOD,
    353                 INSTRUCTION_FORMAT3rms_METHOD,
    354                 INSTRUCTION_FORMAT51l,
    355                 ARRAY_DATA_DIRECTIVE,
    356                 PACKED_SWITCH_DIRECTIVE,
    357                 SPARSE_SWITCH_DIRECTIVE
    358         );
    359     }
    360 }
    361