diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index d2207a7ac84..4be55c90633 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -290,7 +290,7 @@ - + diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt index 9973ee92441..bb0d7aa1dd3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt @@ -14,175 +14,141 @@ * limitations under the License. */ -package org.jetbrains.kotlin.idea.highlighter; +package org.jetbrains.kotlin.idea.highlighter -import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.fileTypes.SyntaxHighlighter; -import com.intellij.openapi.options.OptionsBundle; -import com.intellij.openapi.options.colors.AttributesDescriptor; -import com.intellij.openapi.options.colors.ColorDescriptor; -import com.intellij.openapi.options.colors.ColorSettingsPage; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.JetBundle; -import org.jetbrains.kotlin.idea.JetIcons; -import org.jetbrains.kotlin.idea.JetLanguage; +import com.intellij.openapi.editor.colors.TextAttributesKey +import com.intellij.openapi.fileTypes.SyntaxHighlighter +import com.intellij.openapi.options.OptionsBundle +import com.intellij.openapi.options.colors.AttributesDescriptor +import com.intellij.openapi.options.colors.ColorDescriptor +import com.intellij.openapi.options.colors.ColorSettingsPage +import org.jetbrains.kotlin.idea.JetBundle +import org.jetbrains.kotlin.idea.JetIcons +import org.jetbrains.kotlin.idea.JetLanguage -import javax.swing.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; +import javax.swing.* +import java.lang.reflect.Field +import java.lang.reflect.Modifier +import java.util.HashMap -public class JetColorSettingsPage implements ColorSettingsPage { - @Override - public Icon getIcon() { - return JetIcons.SMALL_LOGO; - } +public class KotlinColorSettingsPage : ColorSettingsPage { + override fun getIcon() = JetIcons.SMALL_LOGO + override fun getHighlighter(): SyntaxHighlighter = JetHighlighter() - @NotNull - @Override - public SyntaxHighlighter getHighlighter() { - return new JetHighlighter(); - } + override fun getDemoText(): String { + return """/* Block comment */ +package hello +import kotlin.util.* // line comment - @NotNull - @Override - public String getDemoText() { - return "/* Block comment */\n" + - "package hello\n" + - "import kotlin.util.* // line comment\n" + - "\n" + - "/**\n" + - " * Doc comment here for `SomeClass`\n" + - " * @see Iterator#next()\n" + - " */\n" + - "@deprecated(\"Deprecated class\")\n" + - "public class MyClass<out T : Iterable<T>>(var prop1 : Int) {\n" + - " fun foo(nullable : String?, r : Runnable, f : () -> Int, fl : FunctionLike, dyn: dynamic) {\n" + - " println(\"length\\nis ${nullable?.length} \\e\")\n" + - " val ints = java.util.ArrayList(2)\n" + - " ints[0] = 102 + f() + fl()\n" + - " val myFun = { -> \"\" };\n" + - " var ref = ints.size()\n" + - " if (!ints.empty) {\n" + - " ints.forEach {\n" + - " if (it == null) return\n" + - " println(it + ref)\n" + - " }\n" + - " }\n" + - " dyn.dynamicCall()\n" + - " dyn.dynamicProp = 5\n" + - " }\n" + - "}\n" + - "\n" + - "var globalCounter : Int = 5\n" + - " get() {\n" + - " return $globalCounter\n" + - " }\n" + - "\n" + - "public abstract class Abstract {\n" + - "}\n" + - "\n" + - "object Obj\n" + - "\n" + - "enum class E { A }\n" + - " Bad character: \\n\n"; - } - - @Override - public Map getAdditionalHighlightingTagToDescriptorMap() { - Map map = new HashMap(); - for (Field field : JetHighlightingColors.class.getFields()) { - if (Modifier.isStatic(field.getModifiers())) { - try { - map.put(field.getName(), (TextAttributesKey) field.get(null)); - } - catch (IllegalAccessException e) { - assert false; - } - } +/** + * Doc comment here for `SomeClass` + * @see Iterator#next() + */ +@deprecated("Deprecated class") +public class MyClass<out T : Iterable<T>>(var prop1 : Int) + fun foo(nullable : String?, r : Runnable, f : () -> Int, fl : FunctionLike, dyn: dynamic) { + println("length\nis ${"$"}{nullable?.length} \e") + val ints = java.util.ArrayList(2) + ints[0] = 102 + f() + fl() + val myFun = { -> "" }; + var ref = ints.size() + if (!ints.empty) { + ints.forEach { + if (it == null) return + println(it + ref) + } } - return map; - } - - @NotNull - @Override - public AttributesDescriptor[] getAttributeDescriptors() { - return new AttributesDescriptor[]{ - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.keyword"), JetHighlightingColors.KEYWORD), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.builtin.annotation"), JetHighlightingColors.BUILTIN_ANNOTATION), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.number"), JetHighlightingColors.NUMBER), - - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.string.escape"), JetHighlightingColors.STRING_ESCAPE), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string"), JetHighlightingColors.INVALID_STRING_ESCAPE), - - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.operator.sign"), JetHighlightingColors.OPERATOR_SIGN), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parentheses"), JetHighlightingColors.PARENTHESIS), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.braces"), JetHighlightingColors.BRACES), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.closure.braces"), JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.arrow"), JetHighlightingColors.ARROW), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.brackets"), JetHighlightingColors.BRACKETS), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.comma"), JetHighlightingColors.COMMA), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.semicolon"), JetHighlightingColors.SEMICOLON), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.dot"), JetHighlightingColors.DOT), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.safe.access"), JetHighlightingColors.SAFE_ACCESS), - - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.line.comment"), JetHighlightingColors.LINE_COMMENT), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.block.comment"), JetHighlightingColors.BLOCK_COMMENT), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.kdoc.comment"), JetHighlightingColors.DOC_COMMENT), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.kdoc.tag"), JetHighlightingColors.KDOC_TAG), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.kdoc.value"), JetHighlightingColors.KDOC_LINK), - - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.class"), JetHighlightingColors.CLASS), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), JetHighlightingColors.TYPE_PARAMETER), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS), - new AttributesDescriptor("Interface", JetHighlightingColors.TRAIT), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.annotation"), JetHighlightingColors.ANNOTATION), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.object"), JetHighlightingColors.OBJECT), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.enumEntry"), JetHighlightingColors.ENUM_ENTRY), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.var"), JetHighlightingColors.MUTABLE_VARIABLE), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.local.variable"), JetHighlightingColors.LOCAL_VARIABLE), - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parameter"), JetHighlightingColors.PARAMETER), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.captured.variable"), JetHighlightingColors.WRAPPED_INTO_REF), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.instance.property"), JetHighlightingColors.INSTANCE_PROPERTY), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.package.property"), JetHighlightingColors.PACKAGE_PROPERTY), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.property.with.backing"), JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.backing.field.access"), JetHighlightingColors.BACKING_FIELD_ACCESS), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.extension.property"), JetHighlightingColors.EXTENSION_PROPERTY), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.dynamic.property"), JetHighlightingColors.DYNAMIC_PROPERTY_CALL), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.it"), JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.fun"), JetHighlightingColors.FUNCTION_DECLARATION), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.fun.call"), JetHighlightingColors.FUNCTION_CALL), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.dynamic.fun.call"), JetHighlightingColors.DYNAMIC_FUNCTION_CALL), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.package.fun.call"), JetHighlightingColors.PACKAGE_FUNCTION_CALL), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.extension.fun.call"), JetHighlightingColors.EXTENSION_FUNCTION_CALL), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.constructor.call"), JetHighlightingColors.CONSTRUCTOR_CALL), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.variable.as.function.call"), JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL), - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.variable.as.function.like.call"), JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL), - - new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.smart.cast"), JetHighlightingColors.SMART_CAST_VALUE), - - new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.label"), JetHighlightingColors.LABEL), - }; - } - - @NotNull - @Override - public ColorDescriptor[] getColorDescriptors() { - return ColorDescriptor.EMPTY_ARRAY; - } - - @NotNull - @Override - public String getDisplayName() { - return JetLanguage.NAME; + dyn.dynamicCall() + dyn.dynamicProp = 5 } } + +var globalCounter : Int = 5 + get() { + return ${"$"}globalCounter + } + +public abstract class Abstract { +} + +object Obj + +enum class E { A } + Bad character: \n +""" + } + + override fun getAdditionalHighlightingTagToDescriptorMap(): Map { + val map = HashMap() + for (field in javaClass().getFields()) { + if (Modifier.isStatic(field.getModifiers())) { + try { + map.put(field.getName(), field.get(null) as TextAttributesKey) + } + catch (e: IllegalAccessException) { + assert(false) + } + + } + } + return map + } + + override fun getAttributeDescriptors(): Array { + fun String.to(key: TextAttributesKey) = AttributesDescriptor(this, key) + + return arrayOf(OptionsBundle.message("options.java.attribute.descriptor.keyword") to JetHighlightingColors.KEYWORD, + JetBundle.message("options.kotlin.attribute.descriptor.builtin.annotation") to JetHighlightingColors.BUILTIN_ANNOTATION, + OptionsBundle.message("options.java.attribute.descriptor.number") to JetHighlightingColors.NUMBER, + OptionsBundle.message("options.java.attribute.descriptor.string") to JetHighlightingColors.STRING, + JetBundle.message("options.kotlin.attribute.descriptor.string.escape") to JetHighlightingColors.STRING_ESCAPE, + OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string") to JetHighlightingColors.INVALID_STRING_ESCAPE, + OptionsBundle.message("options.java.attribute.descriptor.operator.sign") to JetHighlightingColors.OPERATOR_SIGN, + OptionsBundle.message("options.java.attribute.descriptor.parentheses") to JetHighlightingColors.PARENTHESIS, + OptionsBundle.message("options.java.attribute.descriptor.braces") to JetHighlightingColors.BRACES, + JetBundle.message("options.kotlin.attribute.descriptor.closure.braces") to JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW, + JetBundle.message("options.kotlin.attribute.descriptor.arrow") to JetHighlightingColors.ARROW, + OptionsBundle.message("options.java.attribute.descriptor.brackets") to JetHighlightingColors.BRACKETS, + OptionsBundle.message("options.java.attribute.descriptor.comma") to JetHighlightingColors.COMMA, + OptionsBundle.message("options.java.attribute.descriptor.semicolon") to JetHighlightingColors.SEMICOLON, + OptionsBundle.message("options.java.attribute.descriptor.dot") to JetHighlightingColors.DOT, + JetBundle.message("options.kotlin.attribute.descriptor.safe.access") to JetHighlightingColors.SAFE_ACCESS, + OptionsBundle.message("options.java.attribute.descriptor.line.comment") to JetHighlightingColors.LINE_COMMENT, + OptionsBundle.message("options.java.attribute.descriptor.block.comment") to JetHighlightingColors.BLOCK_COMMENT, + JetBundle.message("options.kotlin.attribute.descriptor.kdoc.comment") to JetHighlightingColors.DOC_COMMENT, + JetBundle.message("options.kotlin.attribute.descriptor.kdoc.tag") to JetHighlightingColors.KDOC_TAG, + JetBundle.message("options.kotlin.attribute.descriptor.kdoc.value") to JetHighlightingColors.KDOC_LINK, + OptionsBundle.message("options.java.attribute.descriptor.class") to JetHighlightingColors.CLASS, + OptionsBundle.message("options.java.attribute.descriptor.type.parameter") to JetHighlightingColors.TYPE_PARAMETER, + OptionsBundle.message("options.java.attribute.descriptor.abstract.class") to JetHighlightingColors.ABSTRACT_CLASS, + "Interface" to JetHighlightingColors.TRAIT, + JetBundle.message("options.kotlin.attribute.descriptor.annotation") to JetHighlightingColors.ANNOTATION, + JetBundle.message("options.kotlin.attribute.descriptor.object") to JetHighlightingColors.OBJECT, + JetBundle.message("options.kotlin.attribute.descriptor.enumEntry") to JetHighlightingColors.ENUM_ENTRY, + JetBundle.message("options.kotlin.attribute.descriptor.var") to JetHighlightingColors.MUTABLE_VARIABLE, + JetBundle.message("options.kotlin.attribute.descriptor.local.variable") to JetHighlightingColors.LOCAL_VARIABLE, + OptionsBundle.message("options.java.attribute.descriptor.parameter") to JetHighlightingColors.PARAMETER, + JetBundle.message("options.kotlin.attribute.descriptor.captured.variable") to JetHighlightingColors.WRAPPED_INTO_REF, + JetBundle.message("options.kotlin.attribute.descriptor.instance.property") to JetHighlightingColors.INSTANCE_PROPERTY, + JetBundle.message("options.kotlin.attribute.descriptor.package.property") to JetHighlightingColors.PACKAGE_PROPERTY, + JetBundle.message("options.kotlin.attribute.descriptor.property.with.backing") to JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD, + JetBundle.message("options.kotlin.attribute.descriptor.backing.field.access") to JetHighlightingColors.BACKING_FIELD_ACCESS, + JetBundle.message("options.kotlin.attribute.descriptor.extension.property") to JetHighlightingColors.EXTENSION_PROPERTY, + JetBundle.message("options.kotlin.attribute.descriptor.dynamic.property") to JetHighlightingColors.DYNAMIC_PROPERTY_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.it") to JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER, + JetBundle.message("options.kotlin.attribute.descriptor.fun") to JetHighlightingColors.FUNCTION_DECLARATION, + JetBundle.message("options.kotlin.attribute.descriptor.fun.call") to JetHighlightingColors.FUNCTION_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.dynamic.fun.call") to JetHighlightingColors.DYNAMIC_FUNCTION_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.package.fun.call") to JetHighlightingColors.PACKAGE_FUNCTION_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.extension.fun.call") to JetHighlightingColors.EXTENSION_FUNCTION_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.constructor.call") to JetHighlightingColors.CONSTRUCTOR_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.variable.as.function.call") to JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL, + JetBundle.message("options.kotlin.attribute.descriptor.variable.as.function.like.call") to JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL, + OptionsBundle.message("options.java.attribute.descriptor.bad.character") to JetHighlightingColors.BAD_CHARACTER, + JetBundle.message("options.kotlin.attribute.descriptor.smart.cast") to JetHighlightingColors.SMART_CAST_VALUE, + JetBundle.message("options.kotlin.attribute.descriptor.label") to JetHighlightingColors.LABEL) + } + + override fun getColorDescriptors(): Array = ColorDescriptor.EMPTY_ARRAY + override fun getDisplayName(): String = JetLanguage.NAME +}