Skip to content

Commit

Permalink
Process types in primary constructor at model phase
Browse files Browse the repository at this point in the history
this fixes #309
  • Loading branch information
Schahen committed Jun 17, 2020
1 parent 3a716fc commit ffe747f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export declare interface ReadableOptions {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// [test] resolveImportFromPrimaryConstructor.kt
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", "EXTERNAL_DELEGATION")

import kotlin.js.*
import kotlin.js.Json
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*

external open class MyRequest(options: ReadableOptions)

// ------------------------------------------------------------------------------------------
// [test] _stream.kt
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", "EXTERNAL_DELEGATION")

import kotlin.js.*
import kotlin.js.Json
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*

external interface ReadableOptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as stream from "./_stream";

declare class MyRequest {
constructor(options: stream.ReadableOptions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ interface ModelWithOwnerTypeLowering : ModelWithOwnerLowering {
override fun lowerClassModel(ownerContext: NodeOwner<ClassModel>, parentModule: ModuleModel): ClassModel {
val declaration = ownerContext.node
return declaration.copy(
primaryConstructor = declaration.primaryConstructor?.let { constructorModel ->
constructorModel.copy(parameters = constructorModel.parameters.map { lowerParameterModel(ownerContext.wrap(it)) })
},
members = declaration.members.mapNotNull { member -> lowerMemberModel(NodeOwner(member, ownerContext), parentModule) },
typeParameters = declaration.typeParameters.map { typeParameterModel -> lowerTypeParameterModel(ownerContext.wrap(typeParameterModel)) },
parentEntities = declaration.parentEntities.map { heritageClause ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ private fun NameEntity.normalize(): NameEntity? {
}
}

@OptIn(ExperimentalStdlibApi::class)
private fun ModuleModel.addImports(): ModuleModel {
val importContext = mutableMapOf<NameEntity, NameEntity>()
declarations.map { importContext[it.name] = name }

val nameVisitor = NameVisitor(name, importContext)
val nameVisitor = NameVisitor(name, buildMap<NameEntity, NameEntity> {
declarations.forEach {
this[it.name] = name
}
}.toMutableMap())

val moduleWithFqNames = nameVisitor.lowerRoot(this, NodeOwner(this, null))

return moduleWithFqNames.copy(
Expand Down

0 comments on commit ffe747f

Please sign in to comment.