Skip to content

Commit

Permalink
Update snapshot tests with new implementation relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Jul 18, 2023
1 parent 1924867 commit e1d754c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package snapshots
class Class constructor(private var banana: Int, apple: String) :
// ^^^^^ definition semanticdb maven . . snapshots/Class#
// documentation ```kt\npublic final class Class : kotlin.Throwable\n```
// relationship is_reference is_implementation semanticdb maven . . kotlin/Throwable#
// ^^^^^^^^^^^ definition semanticdb maven . . snapshots/Class#`<init>`().
// documentation ```kt\npublic constructor Class(banana: kotlin.Int, apple: kotlin.String)\n```
// ^^^^^^ definition semanticdb maven . . snapshots/Class#`<init>`().(banana)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class DocstringSuperclass
class Docstrings : DocstringSuperclass(), Serializable {
// ^^^^^^^^^^ definition semanticdb maven . . snapshots/Docstrings#
// documentation ```kt\npublic final class Docstrings : snapshots.DocstringSuperclass, java.io.Serializable\n```\n\n----\n\n Example class docstring.
// relationship is_reference is_implementation semanticdb maven . . snapshots/DocstringSuperclass#
// ^^^^^^^^^^ definition semanticdb maven . . snapshots/Docstrings#`<init>`().
// documentation ```kt\npublic constructor Docstrings()\n```\n\n----\n\n Example class docstring.
// ^^^^^^^^^^^^^^^^^^^ reference semanticdb maven . . snapshots/DocstringSuperclass#`<init>`().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ package snapshots
class Overrides : AutoCloseable {
// ^^^^^^^^^ definition semanticdb maven . . snapshots/Overrides#
// documentation ```kt\npublic final class Overrides : java.lang.AutoCloseable\n```
// relationship is_reference is_implementation semanticdb maven jdk 8 java/lang/AutoCloseable#
// ^^^^^^^^^ definition semanticdb maven . . snapshots/Overrides#`<init>`().
// documentation ```kt\npublic constructor Overrides()\n```
// ^^^^^^^^^^^^^ reference semanticdb maven jdk 8 java/lang/AutoCloseable#
override fun close() {
// ^^^^^ definition semanticdb maven . . snapshots/Overrides#close().
// documentation ```kt\npublic open fun close()\n```
// relationship is_reference is_implementation semanticdb maven jdk 8 java/lang/AutoCloseable#close().
TODO("Not yet implemented")
// ^^^^ reference semanticdb maven . . kotlin/StandardKt#TODO(+1).
}
Expand All @@ -32,6 +34,7 @@ interface Animal {
open class Bird : Animal {
// ^^^^ definition semanticdb maven . . snapshots/Bird#
// documentation ```kt\npublic open class Bird : snapshots.Animal\n```
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#
// ^^^^ definition semanticdb maven . . snapshots/Bird#`<init>`().
// documentation ```kt\npublic constructor Bird()\n```
// ^^^^^^ reference semanticdb maven . . snapshots/Animal#
Expand All @@ -46,13 +49,16 @@ open class Bird : Animal {
override fun sound(): String {
// ^^^^^ definition semanticdb maven . . snapshots/Bird#sound().
// documentation ```kt\npublic open fun sound(): kotlin.String\n```
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#sound().
// ^^^^^^ reference semanticdb maven . . kotlin/String#
return "tweet"
}
}
class Seagull : Bird() {
// ^^^^^^^ definition semanticdb maven . . snapshots/Seagull#
// documentation ```kt\npublic final class Seagull : snapshots.Bird\n```
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#
// relationship is_reference is_implementation semanticdb maven . . snapshots/Bird#
// ^^^^^^^ definition semanticdb maven . . snapshots/Seagull#`<init>`().
// documentation ```kt\npublic constructor Seagull()\n```
// ^^^^ reference semanticdb maven . . snapshots/Bird#`<init>`().
Expand All @@ -66,6 +72,8 @@ class Seagull : Bird() {
override fun sound(): String {
// ^^^^^ definition semanticdb maven . . snapshots/Seagull#sound().
// documentation ```kt\npublic open fun sound(): kotlin.String\n```
// relationship is_reference is_implementation semanticdb maven . . snapshots/Animal#sound().
// relationship is_reference is_implementation semanticdb maven . . snapshots/Bird#sound().
// ^^^^^^ reference semanticdb maven . . kotlin/String#
return "squawk"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import org.jetbrains.kotlin.backend.common.serialization.metadata.findKDocString
import org.jetbrains.kotlin.com.intellij.lang.java.JavaLanguage
import org.jetbrains.kotlin.com.intellij.navigation.NavigationItem
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc.fqnString
import org.jetbrains.kotlin.psi.KtConstructor
Expand Down Expand Up @@ -55,6 +52,27 @@ class SemanticdbTextDocumentBuilder(
if (role == Role.DEFINITION) symbols.add(symbolInformation(symbol, descriptor, element))
}

private val isIgnoredSuperClass = setOf("kotlin.Any", "java.lang.Object", "java.io.Serializable")

private fun functionDescriptorOverrides(descriptor: FunctionDescriptor): Iterable<String> {
val result = mutableListOf<String>()
val isVisited = mutableSetOf<FunctionDescriptor>()
val queue = ArrayDeque<FunctionDescriptor>()
queue.add(descriptor)
while (!queue.isEmpty()) {
val current = queue.removeFirst()
if (current in isVisited) {
continue
}

isVisited.add(current)
val directOverrides = current.overriddenDescriptors.flatMap { cache[it] }.map { it.toString() }
result.addAll(directOverrides)
queue.addAll(current.overriddenDescriptors)
}
return result
}

private fun symbolInformation(
symbol: Symbol,
descriptor: DeclarationDescriptor,
Expand All @@ -68,20 +86,20 @@ class SemanticdbTextDocumentBuilder(
// first is the class itself
.drop(1)
.filter {
it.fqnString != "kotlin.Any" && it.fqnString != "java.lang.Object"
it.fqnString !in isIgnoredSuperClass
}
.flatMap { cache[it] }
.map { it.toString() }
.asIterable()
is SimpleFunctionDescriptor ->
descriptor.overriddenDescriptors.flatMap { cache[it] }.map { it.toString() }
functionDescriptorOverrides(descriptor)
else -> emptyList<String>().asIterable()
}
return SymbolInformation {
this.symbol = symbol.toString()
this.displayName = displayName(element)
this.documentation = semanticdbDocumentation(descriptor)
// this.addAllOverriddenSymbols(supers)
this.addAllOverriddenSymbols(supers)
this.language =
when (element.language) {
is KotlinLanguage -> Semanticdb.Language.KOTLIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fun main() {

ScipJava.main(arrayOf(
"index-semanticdb",
"--no-emit-inverse-relationships",
"--cwd",
sourceroot.toString(),
"--output",
Expand Down

0 comments on commit e1d754c

Please sign in to comment.