Properties with custom property declarations highlighting rule.
Added support for package and class-level properties with custom PD. Java syntethic extensions are ignored from this rule. #KT-30806 Fixed
This commit is contained in:
@@ -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
|
||||
|
||||
+2
@@ -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");
|
||||
|
||||
+15
@@ -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
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user