From c652cc16dc510f2d5977def90592fe55543d8a11 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 19 Mar 2015 22:37:00 +0300 Subject: [PATCH] Classified usages as type parameters correctly. #KT-7047 fixed --- .../kotlin/idea/findUsages/UsageTypeUtils.kt | 5 ++--- .../findClassUsages/kotlinClassAllUsages.1.kt | 6 ++++++ .../kotlinClassAllUsages.results.txt | 18 +++++++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/UsageTypeUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/UsageTypeUtils.kt index a53551c73d3..3023196322e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/UsageTypeUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/UsageTypeUtils.kt @@ -64,6 +64,8 @@ public object UsageTypeUtils { } fun getClassUsageType(): UsageTypeEnum? { + if (refExpr.getNonStrictParentOfType() != null) return TYPE_PARAMETER + val property = refExpr.getNonStrictParentOfType() if (property != null) { when { @@ -97,9 +99,6 @@ public object UsageTypeUtils { refExpr.getParentOfTypeAndBranch(){ getTypeReference() } != null -> TYPE_DEFINITION - refExpr.getNonStrictParentOfType() != null -> - TYPE_PARAMETER - refExpr.getParentOfTypeAndBranch(){ getTypeReference() } != null -> VALUE_PARAMETER_TYPE diff --git a/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.1.kt b/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.1.kt index f7966c82a47..d3ac6710b19 100644 --- a/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.1.kt +++ b/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.1.kt @@ -29,6 +29,12 @@ object ClientObject: Server() { } +class Servers: Iterator { + +} + +fun Iterator.f(p: Iterator): Iterator = this + fun Client.bar(s: Server = Server.NAME) { foo(s) } diff --git a/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.results.txt b/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.results.txt index 382678767ba..13ac33d5bc0 100644 --- a/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.results.txt +++ b/idea/testData/findUsages/kotlin/findClassUsages/kotlinClassAllUsages.results.txt @@ -1,18 +1,22 @@ Class/object property type (6: 21) var nextServer: Server? = new Server() -Companion object (32: 28) fun Client.bar(s: Server = Server.NAME) { +Companion object (38: 28) fun Client.bar(s: Server = Server.NAME) { Companion object (5: 29) class Client(name: String = Server.NAME): Server() { Companion object (7: 16) val name = Server.NAME Function return types (14: 26) fun getNextServer(): Server? { -Function return types (40: 21) fun Any.asServer(): Server? { +Function return types (46: 21) fun Any.asServer(): Server? { Local variable declaration (10: 21) val server: Server = s -Parameter type (32: 19) fun Client.bar(s: Server = Server.NAME) { +Parameter type (38: 19) fun Client.bar(s: Server = Server.NAME) { Parameter type (9: 16) fun foo(s: Server) { Super type qualifier (19: 15) super.work() Supertype (23: 23) companion object: Server() { Supertype (28: 22) object ClientObject: Server() { Supertype (5: 43) class Client(name: String = Server.NAME): Server() { -Target type of 'is' operation (42: 12) is Server -> println("Server!") -Target type of 'is' operation (44: 24) return if (this is Server) this: Server else this as? Server -Usage in cast target type (44: 38) return if (this is Server) this: Server else this as? Server -Usage in cast target type (44: 59) return if (this is Server) this: Server else this as? Server +Target type of 'is' operation (48: 12) is Server -> println("Server!") +Target type of 'is' operation (50: 24) return if (this is Server) this: Server else this as? Server +Type parameter (32: 25) class Servers: Iterator { +Type parameter (36: 14) fun Iterator.f(p: Iterator): Iterator = this +Type parameter (36: 36) fun Iterator.f(p: Iterator): Iterator = this +Type parameter (36: 55) fun Iterator.f(p: Iterator): Iterator = this +Usage in cast target type (50: 38) return if (this is Server) this: Server else this as? Server +Usage in cast target type (50: 59) return if (this is Server) this: Server else this as? Server Usage in import (3: 15) import server.Server