add support for classes with packages #KT-65909 fixed
Merge-request: KT-MR-14623 Merged-by: Artem Olkov <artem.olkov@jetbrains.com>
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
|
||||
package org.jetbrains.sir.passes
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.calls.KtCall
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.sir.*
|
||||
import org.jetbrains.kotlin.sir.builder.buildEnum
|
||||
import org.jetbrains.kotlin.sir.builder.buildModule
|
||||
@@ -57,14 +59,7 @@ public class SirInflatePackagesPass : SirModulePass {
|
||||
for (declaration in module.declarations) {
|
||||
val origin = declaration.origin as? KotlinSource
|
||||
if (origin != null) {
|
||||
// FIXME: for now we assume everything before the last dot is a package name.
|
||||
// This should change as we add type declarations into the mix
|
||||
val path = (origin.symbol as? KtCallableSymbol)
|
||||
?.callableIdIfNonLocal?.packageName
|
||||
?.pathSegments()
|
||||
?.map { it.toString() }
|
||||
?: emptyList()
|
||||
data.root.getOrCreate(path).elements.add(declaration)
|
||||
data.root.getOrCreate(origin.getPackagePath()).elements.add(declaration)
|
||||
continue
|
||||
}
|
||||
declarations += declaration
|
||||
@@ -89,4 +84,20 @@ public class SirInflatePackagesPass : SirModulePass {
|
||||
private fun SirDeclarationContainer.fixParents() = declarations
|
||||
.onEach { it.parent = this }
|
||||
.filterIsInstance<SirDeclarationContainer>()
|
||||
.forEach(SirDeclarationContainer::fixParents)
|
||||
.forEach(SirDeclarationContainer::fixParents)
|
||||
|
||||
private fun KotlinSource.getPackagePath(): List<String> {
|
||||
val fqName = when (symbol) {
|
||||
is KtCallableSymbol -> {
|
||||
symbol.callableIdIfNonLocal?.packageName
|
||||
}
|
||||
is KtClassOrObjectSymbol -> {
|
||||
symbol.classIdIfNonLocal?.packageFqName
|
||||
}
|
||||
else ->
|
||||
TODO("encountered unknown origin: $symbol. This exception should be reworked during KT-65980")
|
||||
}
|
||||
return fqName?.pathSegments()
|
||||
?.map { it.toString() }
|
||||
?: TODO("encountered empty FqName on source: ${this}. This exception should be reworked during KT-65980")
|
||||
}
|
||||
|
||||
@@ -204,7 +204,6 @@ context(KtAnalysisSession)
|
||||
private fun KtNamedClassOrObjectSymbol.isConsumableBySirBuilder(): Boolean =
|
||||
classKind == KtClassKind.CLASS
|
||||
&& (superTypes.count() == 1 && superTypes.first().isAny) // Every class has Any as a superclass
|
||||
&& classIdIfNonLocal?.packageFqName?.isRoot != false
|
||||
&& !isData
|
||||
&& !isInline
|
||||
&& modality == Modality.FINAL
|
||||
|
||||
+13
@@ -1,5 +1,18 @@
|
||||
import KotlinBridges
|
||||
import KotlinRuntime
|
||||
|
||||
public enum namespace {
|
||||
public enum deeper {
|
||||
public class NAMESPACED_CLASS {
|
||||
}
|
||||
public class Foo {
|
||||
}
|
||||
}
|
||||
public class NAMESPACED_CLASS {
|
||||
}
|
||||
public class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
public class Foo {
|
||||
}
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package namespace.deeper
|
||||
|
||||
class NAMESPACED_CLASS
|
||||
|
||||
class Foo {
|
||||
class INSIDE_CLASS // this should be ignored currently
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package namespace
|
||||
|
||||
class NAMESPACED_CLASS
|
||||
|
||||
class Foo {
|
||||
class INSIDE_CLASS // this should be ignored currently
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
|
||||
class Foo {
|
||||
class INSIDE_CLASS // this should be ignored currently
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
package namespace
|
||||
|
||||
class NAMESPACED_CLASS
|
||||
Reference in New Issue
Block a user