Minor, improve some usages of function type utilities
Re change in FunctionsHighlightingVisitor: KBI#isFunctionOrExtensionFunctionType already takes care of supertypes, no need to do additional loop
This commit is contained in:
+7
-26
@@ -28,8 +28,6 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||||
import org.jetbrains.kotlin.types.KotlinType;
|
|
||||||
import org.jetbrains.kotlin.types.TypeUtils;
|
|
||||||
|
|
||||||
public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||||
public FunctionsHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) {
|
public FunctionsHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) {
|
||||||
@@ -73,9 +71,13 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
|||||||
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL);
|
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL);
|
||||||
}
|
}
|
||||||
else if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
else if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
NameHighlighter.highlightName(holder, callee, containedInFunctionClassOrSubclass(calleeDescriptor)
|
DeclarationDescriptor container = calleeDescriptor.getContainingDeclaration();
|
||||||
? KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL
|
boolean containedInFunctionClassOrSubclass =
|
||||||
: KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL);
|
container instanceof ClassDescriptor &&
|
||||||
|
KotlinBuiltIns.isFunctionOrExtensionFunctionType(((ClassDescriptor) container).getDefaultType());
|
||||||
|
NameHighlighter.highlightName(holder, callee, containedInFunctionClassOrSubclass
|
||||||
|
? KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL
|
||||||
|
: KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (calleeDescriptor instanceof ConstructorDescriptor) {
|
if (calleeDescriptor instanceof ConstructorDescriptor) {
|
||||||
@@ -96,25 +98,4 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
|||||||
|
|
||||||
super.visitCallExpression(expression);
|
super.visitCallExpression(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean containedInFunctionClassOrSubclass(DeclarationDescriptor calleeDescriptor) {
|
|
||||||
DeclarationDescriptor parent = calleeDescriptor.getContainingDeclaration();
|
|
||||||
if (!(parent instanceof ClassDescriptor)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
KotlinType defaultType = ((ClassDescriptor) parent).getDefaultType();
|
|
||||||
|
|
||||||
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(defaultType)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (KotlinType supertype : TypeUtils.getAllSupertypes(defaultType)) {
|
|
||||||
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(supertype)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -39,13 +39,13 @@ object CreateFunctionFromCallableReferenceActionFactory : CreateCallableMemberFr
|
|||||||
val context = resolutionFacade.analyze(element, BodyResolveMode.PARTIAL)
|
val context = resolutionFacade.analyze(element, BodyResolveMode.PARTIAL)
|
||||||
return element
|
return element
|
||||||
.guessTypes(context, resolutionFacade.moduleDescriptor)
|
.guessTypes(context, resolutionFacade.moduleDescriptor)
|
||||||
.filter { KotlinBuiltIns.isExactFunctionType(it) || KotlinBuiltIns.isExactExtensionFunctionType(it) }
|
.filter(KotlinBuiltIns::isExactFunctionOrExtensionFunctionType)
|
||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
val expectedReceiverType = KotlinBuiltIns.getReceiverType(it)
|
val expectedReceiverType = KotlinBuiltIns.getReceiverType(it)
|
||||||
val actualReceiverTypeRef = element.typeReference
|
val actualReceiverTypeRef = element.typeReference
|
||||||
val receiverTypeInfo = actualReceiverTypeRef?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo.Empty
|
val receiverTypeInfo = actualReceiverTypeRef?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo.Empty
|
||||||
val returnTypeInfo = TypeInfo(KotlinBuiltIns.getReturnTypeFromFunctionType(it), Variance.OUT_VARIANCE)
|
val returnTypeInfo = TypeInfo(KotlinBuiltIns.getReturnTypeFromFunctionType(it), Variance.OUT_VARIANCE)
|
||||||
val containers = element.getExtractionContainers(includeAll = true).ifEmpty { return@mapNotNull null }
|
val containers = element.getExtractionContainers(includeAll = true).ifEmpty { return@mapNotNull null }
|
||||||
val parameterInfos = SmartList<ParameterInfo>().apply {
|
val parameterInfos = SmartList<ParameterInfo>().apply {
|
||||||
if (actualReceiverTypeRef == null && expectedReceiverType != null) {
|
if (actualReceiverTypeRef == null && expectedReceiverType != null) {
|
||||||
add(ParameterInfo(TypeInfo(expectedReceiverType, Variance.IN_VARIANCE)))
|
add(ParameterInfo(TypeInfo(expectedReceiverType, Variance.IN_VARIANCE)))
|
||||||
|
|||||||
Reference in New Issue
Block a user