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.intellij.openapi.editor.colors.TextAttributesKey; 35 import com.intellij.openapi.fileTypes.SyntaxHighlighter; 36 import com.intellij.openapi.options.colors.AttributesDescriptor; 37 import com.intellij.openapi.options.colors.ColorDescriptor; 38 import com.intellij.openapi.options.colors.ColorSettingsPage; 39 import org.jetbrains.annotations.NotNull; 40 import org.jetbrains.annotations.Nullable; 41 42 import javax.swing.*; 43 import java.util.List; 44 import java.util.Map; 45 46 public class SmaliColorsPage implements ColorSettingsPage { 47 private static final AttributesDescriptor[] ATTRS; 48 49 static { 50 List<TextAttributesKey> keys = SmaliHighlightingColors.getAllKeys(); 51 52 ATTRS = new AttributesDescriptor[keys.size()]; 53 for (int i=0; i<keys.size(); i++) { 54 TextAttributesKey key = keys.get(i); 55 56 ATTRS[i] = new AttributesDescriptor(key.getExternalName(), key); 57 } 58 } 59 getIcon()60 @Nullable @Override public Icon getIcon() { 61 return SmaliIcons.SmaliIcon; 62 } 63 getHighlighter()64 @NotNull @Override public SyntaxHighlighter getHighlighter() { 65 return new SmaliHighlighter(); 66 } 67 getDemoText()68 @NotNull @Override public String getDemoText() { 69 return ".class public Lorg/jf/smalidea/ColorExample;\n" + 70 ".super Ljava/lang/Object;\n" + 71 ".source \"ColorExample.smali\"\n" + 72 "\n" + 73 ".field public exampleField:I = 1234\n" + 74 "\n" + 75 ".field public boolField:Z = true\n" + 76 "\n" + 77 "# This is an example comment\n" + 78 "\n" + 79 ".method public constructor <init>()V\n" + 80 " .registers 1\n" + 81 " invoke-direct {p0}, Ljava/lang/Object;-><init>()V\n" + 82 " return-void\n" + 83 ".end method\n" + 84 "\n" + 85 ".method public exampleMethod()V\n" + 86 " .registers 10\n" + 87 "\n" + 88 " const v0, 1234\n" + 89 " const-string v1, \"An Example String\"\n" + 90 "\n" + 91 " invoke-virtual {p0, v0, v1}, Lorg/jf/smalidea/ColorExample;->anotherMethod(ILjava/lang/String;)V\n" + 92 "\n" + 93 " move v2, v1\n" + 94 " move v1, v0\n" + 95 " move v0, p0\n" + 96 "\n" + 97 " invoke-virtual/range {v0 .. v2}, Lorg/jf/smalidea/ColorExample;->anotherMethod(ILjava/lang/String;)V\n" + 98 "\n" + 99 " return-void\n" + 100 ".end method\n" + 101 "\n" + 102 ".method public anotherMethod(ILjava/Lang/String;)V\n" + 103 " .registers 10\n" + 104 "\n" + 105 " # This is another example comment\n" + 106 "\n" + 107 " return-void\n" + 108 ".end method\n" + 109 "\n" + 110 ".method public odexInstructions()V\n" + 111 " .registers 10\n" + 112 " invoke-virtual {p0}, vtable@0x1b\n" + 113 "\n" + 114 " iget-quick p0, field@0x1\n" + 115 "\n" + 116 " execute-inline {p0}, inline@0xa\n" + 117 "\n" + 118 " throw-verification-error illegal-method-access, Lblah;->Blort()V\n" + 119 ".end method"; 120 } 121 getAttributeDescriptors()122 @NotNull @Override public AttributesDescriptor[] getAttributeDescriptors() { 123 return ATTRS; 124 } 125 getAdditionalHighlightingTagToDescriptorMap()126 @Nullable @Override public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() { 127 return null; 128 } 129 getColorDescriptors()130 @NotNull @Override public ColorDescriptor[] getColorDescriptors() { 131 return ColorDescriptor.EMPTY_ARRAY; 132 } 133 getDisplayName()134 @NotNull @Override public String getDisplayName() { 135 return "smali"; 136 } 137 } 138