-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve to aliases instead of underlying types (#74)
Resolve to aliases instead of underlying types The original implementations skipped intermediate aliases and made them transparent and non-observable. Another solution is KSType.alias which points to the aliasing type and is less intuitive.
- Loading branch information
Showing
6 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
plugins/ksp/src/org/jetbrains/kotlin/ksp/processor/TypeAliasProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.ksp.processor | ||
|
||
import org.jetbrains.kotlin.ksp.processing.Resolver | ||
import org.jetbrains.kotlin.ksp.symbol.* | ||
|
||
open class TypeAliasProcessor : AbstractTestProcessor() { | ||
val results = mutableListOf<String>() | ||
val typeCollector = TypeCollector() | ||
val types = mutableListOf<KSType>() | ||
|
||
override fun process(resolver: Resolver) { | ||
val files = resolver.getAllFiles() | ||
|
||
files.forEach { | ||
it.accept(typeCollector, types) | ||
} | ||
|
||
val sortedTypes = types.sortedBy { it.declaration.simpleName.asString() } | ||
|
||
for (i in sortedTypes) { | ||
val r = mutableListOf<String>() | ||
var a: KSType? = i | ||
do { | ||
r.add(a!!.declaration.simpleName.asString()) | ||
a = (a.declaration as? KSTypeAlias)?.type?.resolve() | ||
} while (a != null) | ||
results.add(r.joinToString(" = ")) | ||
} | ||
|
||
for (i in types) { | ||
for (j in types) { | ||
assert(i == j) | ||
} | ||
} | ||
} | ||
|
||
override fun toResult(): List<String> { | ||
return results | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// WITH_RUNTIME | ||
// TEST PROCESSOR: TypeAliasProcessor | ||
// EXPECTED: | ||
// A = String | ||
// B = String | ||
// C = A = String | ||
// String | ||
// END | ||
|
||
typealias A = String | ||
typealias B = String | ||
typealias C = A | ||
val a: A = "" | ||
val b: B = "" | ||
val c: C = "" | ||
val d: String = "" |