Highlighting variable called as function.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class JetColorSettingsPage implements ColorSettingsPage {
|
||||
" fun <FUNCTION_DECLARATION>foo</FUNCTION_DECLARATION>(<PARAMETER>nullable</PARAMETER> : String?, <PARAMETER>r</PARAMETER> : <TRAIT>Runnable</TRAIT>, <PARAMETER>f</PARAMETER> : () -> Int) {\n" +
|
||||
" <FUNCTION_CALL><NAMESPACE_FUNCTION_CALL>println</NAMESPACE_FUNCTION_CALL></FUNCTION_CALL>(\"length\\nis ${<PARAMETER>nullable</PARAMETER><SAFE_ACCESS>?.</SAFE_ACCESS><INSTANCE_PROPERTY>length</INSTANCE_PROPERTY>} <INVALID_STRING_ESCAPE><STRING_ESCAPE>\\e</STRING_ESCAPE></INVALID_STRING_ESCAPE>\")\n" +
|
||||
" val <LOCAL_VARIABLE>ints</LOCAL_VARIABLE> = java.util.<CONSTRUCTOR_CALL>ArrayList</CONSTRUCTOR_CALL><Int?>(2)\n" +
|
||||
" <LOCAL_VARIABLE>ints</LOCAL_VARIABLE>[0] = 102 + <PARAMETER>f</PARAMETER>()\n" +
|
||||
" <LOCAL_VARIABLE>ints</LOCAL_VARIABLE>[0] = 102 + <PARAMETER><VARIABLE_AS_FUNCTION_CALL>f</VARIABLE_AS_FUNCTION_CALL></PARAMETER>()\n" +
|
||||
" val <LOCAL_VARIABLE>myFun</LOCAL_VARIABLE> = <FUNCTION_LITERAL_BRACES_AND_ARROW>{</FUNCTION_LITERAL_BRACES_AND_ARROW> <FUNCTION_LITERAL_BRACES_AND_ARROW>-></FUNCTION_LITERAL_BRACES_AND_ARROW> \"\" <FUNCTION_LITERAL_BRACES_AND_ARROW>}</FUNCTION_LITERAL_BRACES_AND_ARROW>; var <LOCAL_VARIABLE><MUTABLE_VARIABLE><WRAPPED_INTO_REF>ref</WRAPPED_INTO_REF></MUTABLE_VARIABLE></LOCAL_VARIABLE> = <LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<FUNCTION_CALL>size</FUNCTION_CALL>()\n" +
|
||||
" if (!<LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<EXTENSION_PROPERTY><NAMESPACE_PROPERTY>empty</NAMESPACE_PROPERTY></EXTENSION_PROPERTY>) {\n" +
|
||||
" <LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<EXTENSION_FUNCTION_CALL><NAMESPACE_FUNCTION_CALL><FUNCTION_CALL>forEach</FUNCTION_CALL></NAMESPACE_FUNCTION_CALL></EXTENSION_FUNCTION_CALL> @lit <FUNCTION_LITERAL_BRACES_AND_ARROW>{</FUNCTION_LITERAL_BRACES_AND_ARROW>\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),
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
class FunctionLike {
|
||||
fun invoke() {
|
||||
}
|
||||
}
|
||||
|
||||
val <info>property</info> = {}
|
||||
|
||||
fun foo(param: (Int) -> Int, functionLike: FunctionLike) {
|
||||
<info descr="Calling parameter as function">param</info>(1)
|
||||
<info descr="Calling parameter as function">functionLike</info>()
|
||||
|
||||
val v1 = param
|
||||
var v2 = param
|
||||
|
||||
<info descr="Calling variable as function">v1</info>(1)
|
||||
<info descr="Calling variable as function">v2</info>(1)
|
||||
|
||||
<info descr="Calling property as function">property</info>()
|
||||
}
|
||||
@@ -6,7 +6,7 @@ val <info textAttributesKey="KOTLIN_CLASS">Int</info>.<info textAttributesKey="K
|
||||
}
|
||||
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>(<info textAttributesKey="KOTLIN_PARAMETER">a</info> : () -> <info textAttributesKey="KOTLIN_CLASS">Unit</info>) {
|
||||
<info textAttributesKey="KOTLIN_PARAMETER">a</info>()
|
||||
<info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_MUTABLE_VARIABLE">global</info></info>()
|
||||
1.<info textAttributesKey="KOTLIN_EXTENSION_PROPERTY"><info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY">ext</info></info>()
|
||||
<info textAttributesKey="KOTLIN_PARAMETER"><info textAttributesKey="KOTLIN_VARIABLE_AS_FUNCTION">a</info></info>()
|
||||
<info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_MUTABLE_VARIABLE"><info textAttributesKey="KOTLIN_VARIABLE_AS_FUNCTION">global</info></info></info>()
|
||||
1.<info textAttributesKey="KOTLIN_EXTENSION_PROPERTY"><info textAttributesKey="KOTLIN_NAMESPACE_PROPERTY"><info textAttributesKey="KOTLIN_VARIABLE_AS_FUNCTION">ext</info></info></info>()
|
||||
}
|
||||
@@ -5,5 +5,5 @@ deprecated("Use A instead") fun MyRunnable.invoke() {
|
||||
|
||||
fun test() {
|
||||
val m = MyRunnable()
|
||||
<info descr="'fun invoke()' is deprecated. Use A instead">m()</info>
|
||||
<info descr="'fun invoke()' is deprecated. Use A instead"><info>m</info>()</info>
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user