Highlight dynamic calls in the editor
This commit is contained in:
@@ -159,9 +159,11 @@ options.kotlin.attribute.descriptor.package.property=Package-level property
|
||||
options.kotlin.attribute.descriptor.property.with.backing=Property with backing field
|
||||
options.kotlin.attribute.descriptor.backing.field.access=Backing field access
|
||||
options.kotlin.attribute.descriptor.extension.property=Extension property
|
||||
options.kotlin.attribute.descriptor.dynamic.property=Dynamic property
|
||||
options.kotlin.attribute.descriptor.it=Function literal default parameter
|
||||
options.kotlin.attribute.descriptor.fun=Function declaration
|
||||
options.kotlin.attribute.descriptor.fun.call=Function call
|
||||
options.kotlin.attribute.descriptor.dynamic.fun.call=Dynamic function call
|
||||
options.kotlin.attribute.descriptor.package.fun.call=Package-level function call
|
||||
options.kotlin.attribute.descriptor.extension.fun.call=Extension function call
|
||||
options.kotlin.attribute.descriptor.constructor.call=Constructor call
|
||||
|
||||
+8
-6
@@ -19,16 +19,14 @@ package org.jetbrains.jet.plugin.highlighter;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TasksPackage;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -69,8 +67,12 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
||||
JetExpression callee = expression.getCalleeExpression();
|
||||
ResolvedCall<?> resolvedCall = CallUtilPackage.getResolvedCall(expression, bindingContext);
|
||||
if (callee instanceof JetReferenceExpression && resolvedCall != null) {
|
||||
DeclarationDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor();
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
CallableDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
if (TasksPackage.isDynamic(calleeDescriptor)) {
|
||||
JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.DYNAMIC_FUNCTION_CALL);
|
||||
}
|
||||
else if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
JetPsiChecker.highlightName(holder, callee, containedInFunctionClassOrSubclass(calleeDescriptor)
|
||||
? JetHighlightingColors.VARIABLE_AS_FUNCTION_CALL
|
||||
: JetHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL);
|
||||
|
||||
@@ -66,6 +66,7 @@ public class JetHighlightingColors {
|
||||
public static final TextAttributesKey PROPERTY_WITH_BACKING_FIELD = createTextAttributesKey("KOTLIN_PROPERTY_WITH_BACKING_FIELD");
|
||||
public static final TextAttributesKey BACKING_FIELD_ACCESS = createTextAttributesKey("KOTLIN_BACKING_FIELD_ACCESS");
|
||||
public static final TextAttributesKey EXTENSION_PROPERTY = createTextAttributesKey("KOTLIN_EXTENSION_PROPERTY");
|
||||
public static final TextAttributesKey DYNAMIC_PROPERTY_CALL = createTextAttributesKey("KOTLIN_DYNAMIC_PROPERTY_CALL");
|
||||
|
||||
// functions
|
||||
public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = createTextAttributesKey("KOTLIN_CLOSURE_DEFAULT_PARAMETER");
|
||||
@@ -74,6 +75,7 @@ public class JetHighlightingColors {
|
||||
public static final TextAttributesKey PACKAGE_FUNCTION_CALL = createTextAttributesKey("KOTLIN_PACKAGE_FUNCTION_CALL", CodeInsightColors.STATIC_METHOD_ATTRIBUTES);
|
||||
public static final TextAttributesKey EXTENSION_FUNCTION_CALL = createTextAttributesKey("KOTLIN_EXTENSION_FUNCTION_CALL");
|
||||
public static final TextAttributesKey CONSTRUCTOR_CALL = createTextAttributesKey("KOTLIN_CONSTRUCTOR", CodeInsightColors.CONSTRUCTOR_CALL_ATTRIBUTES);
|
||||
public static final TextAttributesKey DYNAMIC_FUNCTION_CALL = createTextAttributesKey("KOTLIN_DYNAMIC_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");
|
||||
|
||||
|
||||
+6
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetThisExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TasksPackage;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
@@ -82,6 +83,11 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
@NotNull PropertyDescriptor descriptor,
|
||||
boolean withBackingField
|
||||
) {
|
||||
if (TasksPackage.isDynamic(descriptor)) {
|
||||
JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.DYNAMIC_PROPERTY_CALL);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isStatic = DescriptorUtils.isStaticDeclaration(descriptor);
|
||||
JetPsiChecker.highlightName(
|
||||
holder, elementToHighlight,
|
||||
|
||||
+5
@@ -81,6 +81,11 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
super.visitClass(klass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDynamicType(@NotNull JetDynamicType type) {
|
||||
// Do nothing: 'dynamic' is highlighted as a keyword
|
||||
}
|
||||
|
||||
private void highlightName(@NotNull PsiElement whatToHighlight, @NotNull TextAttributesKey textAttributesKey) {
|
||||
JetPsiChecker.highlightName(holder, whatToHighlight, textAttributesKey);
|
||||
}
|
||||
|
||||
+7
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TasksPackage;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.expressions.CaptureKind;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
@@ -87,6 +88,12 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof VariableDescriptor) {
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
|
||||
|
||||
if (TasksPackage.isDynamic(variableDescriptor)) {
|
||||
JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.DYNAMIC_PROPERTY_CALL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (variableDescriptor.isVar()) {
|
||||
JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.MUTABLE_VARIABLE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user