diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index a218abbaf93..b2b47a99751 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -90,6 +90,7 @@ options.jet.attribute.descriptor.fun.call=Function call options.jet.attribute.descriptor.namespace.fun.call=Package-level function call options.jet.attribute.descriptor.extension.fun.call=Extension function call options.jet.attribute.descriptor.constructor.call=Constructor call +options.jet.attribute.descriptor.variable.as.function.call=Variable as function call options.jet.attribute.descriptor.auto.casted=Smart-cast value options.jet.attribute.descriptor.label=Label change.to.function.invocation=Change to function invocation diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java index d89e246f485..7cef1d665a1 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/FunctionsHighlightingVisitor.java @@ -72,6 +72,15 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.EXTENSION_FUNCTION_CALL); } } + else if (calleeDescriptor instanceof VariableDescriptor) { + String kind = calleeDescriptor instanceof ValueParameterDescriptor + ? "parameter" + : calleeDescriptor instanceof PropertyDescriptor + ? "property" + : "variable"; + holder.createInfoAnnotation(callee, "Calling " + kind + " as function").setTextAttributes( + JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL); + } } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 9bd425eb310..a9aeb393626 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -61,7 +61,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { " fun foo(nullable : String?, r : Runnable, f : () -> Int) {\n" + " println(\"length\\nis ${nullable?.length} \\e\")\n" + " val ints = java.util.ArrayList(2)\n" + - " ints[0] = 102 + f()\n" + + " ints[0] = 102 + f()\n" + " val myFun = { -> \"\" }; var ref = ints.size()\n" + " if (!ints.empty) {\n" + " ints.forEach @lit {\n" + @@ -154,6 +154,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.namespace.fun.call"), JetHighlightingColors.NAMESPACE_FUNCTION_CALL), new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.extension.fun.call"), JetHighlightingColors.EXTENSION_FUNCTION_CALL), new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.constructor.call"), JetHighlightingColors.CONSTRUCTOR_CALL), + new AttributesDescriptor(JetBundle.message("options.jet.attribute.descriptor.variable.as.function.call"), JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 3b4ca3e9d0e..be7b6c33a97 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -236,6 +236,11 @@ public class JetHighlightingColors { CodeInsightColors.CONSTRUCTOR_CALL_ATTRIBUTES.getDefaultAttributes() ); + public static final TextAttributesKey VARIABLE_AS_FUNCTION_CALL = TextAttributesKey.createTextAttributesKey( + "KOTLIN_VARIABLE_AS_FUNCTION", + new TextAttributes(null, new Color(0xdbffdb), null, null, Font.PLAIN) + ); + public static final TextAttributesKey BAD_CHARACTER = TextAttributesKey.createTextAttributesKey( "KOTLIN_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER.getDefaultAttributes() diff --git a/idea/testData/checker/infos/VariableAsFunction.kt b/idea/testData/checker/infos/VariableAsFunction.kt new file mode 100644 index 00000000000..129e3656184 --- /dev/null +++ b/idea/testData/checker/infos/VariableAsFunction.kt @@ -0,0 +1,19 @@ +class FunctionLike { + fun invoke() { + } +} + +val property = {} + +fun foo(param: (Int) -> Int, functionLike: FunctionLike) { + param(1) + functionLike() + + val v1 = param + var v2 = param + + v1(1) + v2(1) + + property() +} \ No newline at end of file diff --git a/idea/testData/highlighter/VariablesAsFunctions.kt b/idea/testData/highlighter/VariablesAsFunctions.kt index 356c031cdab..3a133d4a695 100644 --- a/idea/testData/highlighter/VariablesAsFunctions.kt +++ b/idea/testData/highlighter/VariablesAsFunctions.kt @@ -6,7 +6,7 @@ val Int.foo(a : () -> Unit) { - a() - global() - 1.ext() + a() + global() + 1.ext() } \ No newline at end of file diff --git a/idea/testData/highlighter/deprecated/Invoke.kt b/idea/testData/highlighter/deprecated/Invoke.kt index 8680a3b9e69..16c156c7714 100644 --- a/idea/testData/highlighter/deprecated/Invoke.kt +++ b/idea/testData/highlighter/deprecated/Invoke.kt @@ -5,5 +5,5 @@ deprecated("Use A instead") fun MyRunnable.invoke() { fun test() { val m = MyRunnable() - m() + m() } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java b/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java index 8b6895fc371..b99ed04b0b4 100644 --- a/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/checkers/JetPsiCheckerTestGenerated.java @@ -414,6 +414,11 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest { doTestWithInfos("idea/testData/checker/infos/PropertiesWithBackingFields.kt"); } + @TestMetadata("VariableAsFunction.kt") + public void testVariableAsFunction() throws Exception { + doTestWithInfos("idea/testData/checker/infos/VariableAsFunction.kt"); + } + @TestMetadata("WrapIntoRef.kt") public void testWrapIntoRef() throws Exception { doTestWithInfos("idea/testData/checker/infos/WrapIntoRef.kt");