Implement structural grouping of Kotlin declaration usages

#KT-4742 Fixed
This commit is contained in:
Alexey Sedunov
2014-03-25 15:39:40 +04:00
parent 5d4527d7aa
commit cceb66d632
14 changed files with 248 additions and 14 deletions
@@ -0,0 +1,14 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetClass
// GROUPING_RULES: org.jetbrains.jet.plugin.findUsages.KotlinDeclarationGroupRuleProvider$KotlinDeclarationGroupingRule
// OPTIONS: usages, constructorUsages
package server
open class <caret>Server {
class object {
val NAME = "Server"
}
open fun work() {
println("Server")
}
}
@@ -0,0 +1,42 @@
package client
import server.Server
class Client(name: String = Server.NAME): Server() {
var nextServer: Server? = new Server()
val name = Server.NAME
fun foo(s: Server) {
val server: Server = s
println("Server: $server")
}
fun getNextServer(): Server? {
return nextServer
}
override fun work() {
super<Server>.work()
println("Client")
}
class object: Server() {
}
}
object ClientObject: Server() {
}
fun Client.bar(s: Server = Server.NAME) {
foo(s)
}
fun Client.hasNextServer(): Boolean {
return getNextServer() != null
}
fun Any.asServer(): Server? {
return if (this is Server) this as Server else null
}
@@ -0,0 +1,16 @@
Class/object property type (Client) (6: 21) var nextServer: Server? = new Server()
Function return types (Client) (14: 26) fun getNextServer(): Server? {
Function return types (asServer) (40: 21) fun Any.asServer(): Server? {
Local variable declaration (Client) (10: 21) val server: Server = s
Nested class/object (Client) (5: 29) class Client(name: String = Server.NAME): Server() {
Nested class/object (Client) (7: 16) val name = Server.NAME
Nested class/object (bar) (32: 28) fun Client.bar(s: Server = Server.NAME) {
Parameter type (Client) (9: 16) fun foo(s: Server) {
Parameter type (bar) (32: 19) fun Client.bar(s: Server = Server.NAME) {
Super type qualifier (Client) (19: 15) super<Server>.work()
Supertype (Client) (23: 19) class object: Server() {
Supertype (Client) (5: 43) class Client(name: String = Server.NAME): Server() {
Supertype (ClientObject) (28: 22) object ClientObject: Server() {
Target type of 'is' operation (asServer) (41: 24) return if (this is Server) this as Server else null
Usage in cast target type (asServer) (41: 40) return if (this is Server) this as Server else null
Usage in import (3: 15) import server.Server
@@ -0,0 +1,13 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
// GROUPING_RULES: org.jetbrains.jet.plugin.findUsages.KotlinDeclarationGroupRuleProvider$KotlinDeclarationGroupingRule
// OPTIONS: usages
package server;
public open class Server() {
open fun <caret>processRequest() = "foo"
}
public class ServerEx(): Server() {
override fun processRequest() = "foofoo"
}
@@ -0,0 +1,8 @@
import server.*;
class Client {
public fun foo() {
Server().processRequest()
ServerEx().processRequest()
}
}
@@ -0,0 +1,2 @@
Function call (Client) (5: 18) Server().processRequest()
Function call (Client) (6: 20) ServerEx().processRequest()
@@ -0,0 +1,20 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetProperty
// GROUPING_RULES: org.jetbrains.jet.plugin.findUsages.KotlinDeclarationGroupRuleProvider$KotlinDeclarationGroupingRule
// OPTIONS: usages
package server;
open class A<T> {
open var <caret>foo: T
}
open class B: A<String>() {
open var foo: String
get() {
println("get")
return super<A>.foo
}
set(value: String) {
println("set:" + value)
super<A>.foo = value
}
}
@@ -0,0 +1,13 @@
import server.*;
class Client {
public fun foo() {
val a = A<String>()
a.foo = "a"
println("a.foo = ${a.foo}")
val b = B()
b.foo = "b"
println("b.foo = ${b.foo}")
}
}
@@ -0,0 +1,6 @@
Value read (B) (14: 29) return super<A>.foo
Value read (Client) (11: 30) println("b.foo = ${b.foo}")
Value read (Client) (7: 30) println("a.foo = ${a.foo}")
Value write (B) (18: 22) super<A>.foo = value
Value write (Client) (10: 11) b.foo = "b"
Value write (Client) (6: 11) a.foo = "a"