Suspend function calls highlighting added.

'If' highlighting fixed at settings sample area.

 #KT-27496 Fixed
This commit is contained in:
Vladimir Ilmov
2019-11-06 10:06:47 +03:00
committed by Vladimir Ilmov
parent 46423443e9
commit ab3f9586b3
7 changed files with 46 additions and 3 deletions
@@ -95,6 +95,7 @@ options.kotlin.attribute.descriptor.fun=Functions//Function declaration
options.kotlin.attribute.descriptor.fun.call=Functions//Function call
options.kotlin.attribute.descriptor.dynamic.fun.call=Functions//Dynamic function call
options.kotlin.attribute.descriptor.package.fun.call=Functions//Package-level function call
options.kotlin.attribute.descriptor.suspend.fun.call=Functions//Suspend function call
options.kotlin.attribute.descriptor.extension.fun.call=Functions//Extension function call
options.kotlin.attribute.descriptor.constructor.call=Functions//Constructor call
options.kotlin.attribute.descriptor.variable.as.function.call=Properties and Variables//Variable as function call
@@ -79,12 +79,13 @@ internal class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingCon
@Suppress("DEPRECATION")
val extensions = Extensions.getExtensions(HighlighterExtension.EP_NAME)
val key = extensions.firstNotNullResult { extension ->
extension.highlightCall(callee, resolvedCall)
} ?: when {
calleeDescriptor.fqNameOrNull() == KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME -> KEYWORD
calleeDescriptor.isDynamic() -> DYNAMIC_FUNCTION_CALL
calleeDescriptor is FunctionDescriptor && calleeDescriptor.isSuspend -> SUSPEND_FUNCTION_CALL
resolvedCall is VariableAsFunctionResolvedCall -> {
val container = calleeDescriptor.containingDeclaration
val containedInFunctionClassOrSubclass = container is ClassDescriptor && container.defaultType.isFunctionTypeOrSubtype
@@ -86,6 +86,7 @@ public class KotlinHighlightingColors {
public static final TextAttributesKey EXTENSION_FUNCTION_CALL = createTextAttributesKey("KOTLIN_EXTENSION_FUNCTION_CALL", DefaultLanguageHighlighterColors.STATIC_METHOD);
public static final TextAttributesKey CONSTRUCTOR_CALL = createTextAttributesKey("KOTLIN_CONSTRUCTOR", DefaultLanguageHighlighterColors.FUNCTION_CALL);
public static final TextAttributesKey DYNAMIC_FUNCTION_CALL = createTextAttributesKey("KOTLIN_DYNAMIC_FUNCTION_CALL");
public static final TextAttributesKey SUSPEND_FUNCTION_CALL = createTextAttributesKey("KOTLIN_SUSPEND_FUNCTION_CALL", KotlinHighlightingColors.FUNCTION_CALL);
public static final TextAttributesKey VARIABLE_AS_FUNCTION_CALL = createTextAttributesKey("KOTLIN_VARIABLE_AS_FUNCTION");
public static final TextAttributesKey VARIABLE_AS_FUNCTION_LIKE_CALL = createTextAttributesKey("KOTLIN_VARIABLE_AS_FUNCTION_LIKE");
@@ -113,6 +113,11 @@ public class PerformanceHighlightingTestGenerated extends AbstractPerformanceHig
runTest("idea/testData/highlighter/SmartCast.kt");
}
@TestMetadata("Suspend.kt")
public void testSuspend() throws Exception {
runTest("idea/testData/highlighter/Suspend.kt");
}
@TestMetadata("SyntheticExtensionProperty.kt")
public void testSyntheticExtensionProperty() throws Exception {
runTest("idea/testData/highlighter/SyntheticExtensionProperty.kt");
@@ -55,7 +55,7 @@ class KotlinColorSettingsPage : ColorSettingsPage, RainbowColorSettingsPage {
var <LOCAL_VARIABLE><MUTABLE_VARIABLE>ref</MUTABLE_VARIABLE></LOCAL_VARIABLE> = <LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<INSTANCE_PROPERTY>size</INSTANCE_PROPERTY>
ints.<EXTENSION_PROPERTY>lastIndex</EXTENSION_PROPERTY> + <PACKAGE_PROPERTY>globalCounter</PACKAGE_PROPERTY>
<LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<EXTENSION_FUNCTION_CALL>forEach</EXTENSION_FUNCTION_CALL> <LABEL>lit@</LABEL> <FUNCTION_LITERAL_BRACES_AND_ARROW>{</FUNCTION_LITERAL_BRACES_AND_ARROW>
if (<FUNCTION_LITERAL_DEFAULT_PARAMETER>it</FUNCTION_LITERAL_DEFAULT_PARAMETER> == null) return<LABEL>@lit</LABEL>
<KEYWORD>if</KEYWORD> (<FUNCTION_LITERAL_DEFAULT_PARAMETER>it</FUNCTION_LITERAL_DEFAULT_PARAMETER> == null) return<LABEL>@lit</LABEL>
<PACKAGE_FUNCTION_CALL>println</PACKAGE_FUNCTION_CALL>(<FUNCTION_LITERAL_DEFAULT_PARAMETER><SMART_CAST_VALUE>it</SMART_CAST_VALUE></FUNCTION_LITERAL_DEFAULT_PARAMETER> + <LOCAL_VARIABLE><MUTABLE_VARIABLE><WRAPPED_INTO_REF>ref</WRAPPED_INTO_REF></MUTABLE_VARIABLE></LOCAL_VARIABLE>)
<FUNCTION_LITERAL_BRACES_AND_ARROW>}</FUNCTION_LITERAL_BRACES_AND_ARROW>
dyn.<DYNAMIC_FUNCTION_CALL>dynamicCall</DYNAMIC_FUNCTION_CALL>()
@@ -70,7 +70,7 @@ class KotlinColorSettingsPage : ColorSettingsPage, RainbowColorSettingsPage {
}
fun Int?.bar() {
if (this != null) {
<KEYWORD>if</KEYWORD> (this != null) {
println(<NAMED_ARGUMENT>message =</NAMED_ARGUMENT> <SMART_CAST_RECEIVER>toString</SMART_CAST_RECEIVER>())
}
else {
@@ -98,6 +98,12 @@ var <PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION><MUTABLE_VARIABLE>globalCounte
<KEYWORD>typealias</KEYWORD> <TYPE_ALIAS>Predicate</TYPE_ALIAS><<TYPE_PARAMETER>T</TYPE_PARAMETER>> = (<TYPE_PARAMETER>T</TYPE_PARAMETER>) -> <CLASS>Boolean</CLASS>
<KEYWORD>fun</KEYWORD> <FUNCTION_DECLARATION>baz</FUNCTION_DECLARATION>(<PARAMETER>p</PARAMETER>: <TYPE_ALIAS>Predicate</TYPE_ALIAS><<CLASS>Int</CLASS>>) = <PARAMETER><VARIABLE_AS_FUNCTION_CALL>p</VARIABLE_AS_FUNCTION_CALL></PARAMETER>(<NUMBER>42</NUMBER>)
<KEYWORD>suspend</KEYWORD> <KEYWORD>fun</KEYWORD> <FUNCTION_DECLARATION>suspendCall</FUNCTION_DECLARATION>() =
<SUSPEND_FUNCTION_CALL>suspendFn</SUSPEND_FUNCTION_CALL>()
<KEYWORD>suspend</KEYWORD> <KEYWORD>fun</KEYWORD> <FUNCTION_DECLARATION>suspendFn</FUNCTION_DECLARATION>() {}
"""
}
@@ -175,6 +181,7 @@ var <PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION><MUTABLE_VARIABLE>globalCounte
KotlinBundle.message("options.kotlin.attribute.descriptor.fun") to KotlinHighlightingColors.FUNCTION_DECLARATION,
KotlinBundle.message("options.kotlin.attribute.descriptor.fun.call") to KotlinHighlightingColors.FUNCTION_CALL,
KotlinBundle.message("options.kotlin.attribute.descriptor.dynamic.fun.call") to KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL,
KotlinBundle.message("options.kotlin.attribute.descriptor.suspend.fun.call") to KotlinHighlightingColors.SUSPEND_FUNCTION_CALL,
KotlinBundle.message("options.kotlin.attribute.descriptor.package.fun.call") to KotlinHighlightingColors.PACKAGE_FUNCTION_CALL,
KotlinBundle.message("options.kotlin.attribute.descriptor.extension.fun.call") to KotlinHighlightingColors.EXTENSION_FUNCTION_CALL,
KotlinBundle.message("options.kotlin.attribute.descriptor.constructor.call") to KotlinHighlightingColors.CONSTRUCTOR_CALL,
+23
View File
@@ -0,0 +1,23 @@
// EXPECTED_DUPLICATED_HIGHLIGHTING
val <info textAttributesKey="KOTLIN_PACKAGE_PROPERTY">fnType</info> : <info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info> () -> <info textAttributesKey="KOTLIN_OBJECT">Unit</info> = {}
val <info textAttributesKey="KOTLIN_PACKAGE_PROPERTY">fnFnType</info>: () -> <info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info> () -> <info textAttributesKey="KOTLIN_OBJECT">Unit</info> = { -> {}}
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info> fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">inSuspend</info>(<info textAttributesKey="KOTLIN_PARAMETER">fn</info>: <info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info> () -> <info textAttributesKey="KOTLIN_OBJECT">Unit</info>) {
val <info textAttributesKey="KOTLIN_LOCAL_VARIABLE">res</info>: <info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info> (<info textAttributesKey="KOTLIN_CLASS">Int</info>) -> <info textAttributesKey="KOTLIN_CLASS">Int</info> = { <info textAttributesKey="KOTLIN_PARAMETER"><info textAttributesKey="KOTLIN_CLOSURE_DEFAULT_PARAMETER">it</info></info> + 1 };
<info textAttributesKey="KOTLIN_CONSTRUCTOR">T2</info>().<info textAttributesKey="KOTLIN_FUNCTION_CALL">nonSuspend</info>()
.<info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL">suspend1</info>(<info textAttributesKey="KOTLIN_PARAMETER">fn</info>)
.<info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL">suspend1</info> { }
.<info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL">suspend1</info> { <info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL"><info textAttributesKey="KOTLIN_LOCAL_VARIABLE">res</info></info>(5) }
<info textAttributesKey="KOTLIN_LOCAL_VARIABLE"><info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL">res</info></info>(5)
<info textAttributesKey="KOTLIN_PACKAGE_PROPERTY"><info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL">fnType</info></info>()
<info textAttributesKey="KOTLIN_PACKAGE_PROPERTY"><info textAttributesKey="KOTLIN_VARIABLE_AS_FUNCTION">fnFnType</info></info>().<info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL">invoke</info>()
}
class <info textAttributesKey="KOTLIN_CLASS">T2</info> {
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info> <info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">inline</info> fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">suspend1</info>(<info textAttributesKey="KOTLIN_PARAMETER">block</info>: <warning textAttributesKey="WARNING_ATTRIBUTES"><info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">suspend</info></warning> () -> <info textAttributesKey="KOTLIN_OBJECT">Unit</info>): <info textAttributesKey="KOTLIN_CLASS">T2</info> {
<info textAttributesKey="KOTLIN_SUSPEND_FUNCTION_CALL"><info textAttributesKey="KOTLIN_PARAMETER">block</info></info>()
return this
}
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">nonSuspend</info>() = this
}
@@ -113,6 +113,11 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
runTest("idea/testData/highlighter/SmartCast.kt");
}
@TestMetadata("Suspend.kt")
public void testSuspend() throws Exception {
runTest("idea/testData/highlighter/Suspend.kt");
}
@TestMetadata("SyntheticExtensionProperty.kt")
public void testSyntheticExtensionProperty() throws Exception {
runTest("idea/testData/highlighter/SyntheticExtensionProperty.kt");