diff --git a/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties b/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties index 31bf6257290..2e0b5d31d78 100644 --- a/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties +++ b/idea/idea-analysis/resources/org/jetbrains/kotlin/idea/KotlinBundle.properties @@ -82,7 +82,9 @@ options.kotlin.attribute.descriptor.var=Properties and Variables//Var (mutable v options.kotlin.attribute.descriptor.local.variable=Properties and Variables//Local variable or value options.kotlin.attribute.descriptor.captured.variable=Properties and Variables//Variables and values captured in a closure options.kotlin.attribute.descriptor.instance.property=Properties and Variables//Instance property +options.kotlin.attribute.descriptor.instance.property.custom.property.declaration=Properties and Variables//Instance property with custom property declarations options.kotlin.attribute.descriptor.package.property=Properties and Variables//Package-level property +options.kotlin.attribute.descriptor.package.property.custom.property.declaration=Properties and Variables//Package-level property with custom property declarations options.kotlin.attribute.descriptor.field=Properties and Variables//Backing field variable options.kotlin.attribute.descriptor.extension.property=Properties and Variables//Extension property options.kotlin.attribute.descriptor.synthetic.extension.property=Properties and Variables//Synthetic extension property diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java index a4852155d79..697e802145d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java @@ -75,6 +75,8 @@ public class KotlinHighlightingColors { public static final TextAttributesKey SYNTHETIC_EXTENSION_PROPERTY = createTextAttributesKey("KOTLIN_SYNTHETIC_EXTENSION_PROPERTY", EXTENSION_PROPERTY); public static final TextAttributesKey DYNAMIC_PROPERTY_CALL = createTextAttributesKey("KOTLIN_DYNAMIC_PROPERTY_CALL"); public static final TextAttributesKey ANDROID_EXTENSIONS_PROPERTY_CALL = createTextAttributesKey("KOTLIN_ANDROID_EXTENSIONS_PROPERTY_CALL"); + public static final TextAttributesKey INSTANCE_PROPERTY_CUSTOM_PROPERTY_DECLARATION = createTextAttributesKey("KOTLIN_INSTANCE_PROPERTY_CUSTOM_PROPERTY_DECLARATION", INSTANCE_PROPERTY); + public static final TextAttributesKey PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION = createTextAttributesKey("KOTLIN_PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION", PACKAGE_PROPERTY); // functions public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = createTextAttributesKey("KOTLIN_CLOSURE_DEFAULT_PARAMETER"); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt index be7f1e9510d..86f6c85a864 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingUtil.kt @@ -18,6 +18,8 @@ package org.jetbrains.kotlin.idea.highlighter import com.intellij.psi.PsiElement import com.intellij.psi.PsiManager +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.idea.caches.project.NotUnderContentRootModuleInfo import org.jetbrains.kotlin.idea.caches.project.getModuleInfo import org.jetbrains.kotlin.idea.core.script.IdeScriptReportSink @@ -79,4 +81,17 @@ object KotlinHighlightingUtil { return ProjectRootsUtil.isInProjectSource(ktFile, includeScriptsOutsideSourceRoots = true) } + + fun hasCustomPropertyDeclaration(descriptor: PropertyDescriptor): Boolean { + var hasCustomPropertyDeclaration = false + if (!hasExtensionReceiverParameter(descriptor)) { + if (descriptor.getter?.isDefault == false || descriptor.setter?.isDefault == false) + hasCustomPropertyDeclaration = true + } + return hasCustomPropertyDeclaration + } + + fun hasExtensionReceiverParameter(descriptor: PropertyDescriptor): Boolean { + return descriptor.extensionReceiverParameter != null + } } \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/PropertiesHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/PropertiesHighlightingVisitor.kt index 2e01c33e421..d027ce0adf8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/PropertiesHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/PropertiesHighlightingVisitor.kt @@ -97,14 +97,20 @@ internal class PropertiesHighlightingVisitor(holder: AnnotationHolder, bindingCo // The property is set in VariablesHighlightingVisitor null - descriptor.extensionReceiverParameter != null -> + KotlinHighlightingUtil.hasExtensionReceiverParameter(descriptor) -> if (descriptor.isSynthesized) SYNTHETIC_EXTENSION_PROPERTY else EXTENSION_PROPERTY DescriptorUtils.isStaticDeclaration(descriptor) -> - PACKAGE_PROPERTY + if(KotlinHighlightingUtil.hasCustomPropertyDeclaration(descriptor)) + PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION + else + PACKAGE_PROPERTY else -> - INSTANCE_PROPERTY + if (KotlinHighlightingUtil.hasCustomPropertyDeclaration(descriptor)) + INSTANCE_PROPERTY_CUSTOM_PROPERTY_DECLARATION + else + INSTANCE_PROPERTY } } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt index 58c1c0b4dbd..1a8e9e8c8a2 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt @@ -20,6 +20,7 @@ import com.intellij.lang.annotation.AnnotationHolder import com.intellij.psi.PsiElement import com.intellij.psi.PsiNameIdentifierOwner import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor @@ -29,6 +30,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext.* +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver @@ -166,6 +168,15 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon if (descriptor is ValueParameterDescriptor) { highlightName(elementToHighlight, PARAMETER) } + + if (descriptor is PropertyDescriptor && KotlinHighlightingUtil.hasCustomPropertyDeclaration(descriptor)) { + val isStaticDeclaration = DescriptorUtils.isStaticDeclaration(descriptor) + highlightName(elementToHighlight, + if (isStaticDeclaration) + PACKAGE_PROPERTY_CUSTOM_PROPERTY_DECLARATION + else + INSTANCE_PROPERTY_CUSTOM_PROPERTY_DECLARATION) + } } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt index 953818b1cab..aad655c9183 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt @@ -78,10 +78,14 @@ fun Int?.bar() { } } -var globalCounter : Int = 5 - get = field +var globalCounter : Int = 5 + get() = field abstract class Abstract { + val bar get() = 1 + fun test() { + bar + } } object Obj @@ -159,6 +163,8 @@ var globalCountermy = 0 +var my = 0 get() = field set(arg) { field = arg + 1 } fun foo(): Int { - val field = my + val field = my return field } \ No newline at end of file diff --git a/idea/testData/highlighter/PropertiesWithPropertyDeclarations.kt b/idea/testData/highlighter/PropertiesWithPropertyDeclarations.kt new file mode 100644 index 00000000000..6ca1caaf544 --- /dev/null +++ b/idea/testData/highlighter/PropertiesWithPropertyDeclarations.kt @@ -0,0 +1,42 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + +val packageSize = 0 +val packageSizeGetter +get() = packageSize * 2 + +var packageSizeSetter = 5 +set(value) { + field = value * 2 +} + +var packageSizeBean = 5 +get() = packageSize * 2 +set(value) { + field = value * 2 +} + + +class test() { + // no highlighting check + val size = 0 + + val classSize = 0 + + val classSizeGetter + get() = classSize * 2 + + var classSizeSetter = 5 + set(value) { + field = value * 2 + } + + var classSizeBean = 5 + get() = classSize * 2 + set(value) { + field = value * 2 + } + + fun callCustomPD() { + classSizeBean = 30 + } +} diff --git a/idea/testData/highlighter/Suspend.kt b/idea/testData/highlighter/Suspend.kt new file mode 100644 index 00000000000..58678a21a5b --- /dev/null +++ b/idea/testData/highlighter/Suspend.kt @@ -0,0 +1,15 @@ + +suspend fun letsDoSuspendLambda(block: suspend () -> Unit) { + val res : suspend (Int) -> Int = { it + 1 }; + letsDoSomething { block } + res(5) + block() +} + +suspend fun letsDoSomething(block: suspend () -> Unit) { + doSomething() + block() +} + +suspend fun doSomething() { +} \ No newline at end of file diff --git a/idea/testData/highlighter/Variables.kt b/idea/testData/highlighter/Variables.kt index e091289a96e..0b5ba7192b2 100644 --- a/idea/testData/highlighter/Variables.kt +++ b/idea/testData/highlighter/Variables.kt @@ -7,7 +7,7 @@ val Int.y : Int = 1 +val y : Int = 1 get() { return 5.sq + field + x } @@ -17,13 +17,13 @@ class Foo( b : String, var c : String ) { - init { + init { b } fun f(p : Int = a) {} - var v : Int + var v : Int get() { return 1; } diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java index 9cb8d864267..c8549278878 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java @@ -143,6 +143,11 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest { runTest("idea/testData/highlighter/VariablesAsFunctions.kt"); } + @TestMetadata("PropertiesWithPropertyDeclarations.kt") + public void testPropertiesWithPropertyDeclarations() throws Exception { + runTest("idea/testData/highlighter/PropertiesWithPropertyDeclarations.kt"); + } + @TestMetadata("idea/testData/highlighter/deprecated") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)