From 2bc063b2300336f78b16a8c3109ca48b8a9031f4 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 23 Mar 2018 13:35:29 +0300 Subject: [PATCH] FIR: implement default star importing scope --- .../transformers/FirTypeResolveTransformer.kt | 3 +- ...pe.kt => FirAbstractStarImportingScope.kt} | 6 ++-- .../impl/FirDefaultStarImportingScope.kt | 30 +++++++++++++++++++ .../impl/FirExplicitStarImportingScope.kt | 14 +++++++++ .../testData/fir/resolve/builtins/lists.kt | 3 -- compiler/testData/fir/resolve/enum.txt | 6 ++-- compiler/testData/fir/resolve/simpleClass.kt | 2 -- 7 files changed, 52 insertions(+), 12 deletions(-) rename compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/{FirStarImportingScope.kt => FirAbstractStarImportingScope.kt} (84%) create mode 100644 compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt create mode 100644 compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt index a678b85c72b..b43920d83b5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTypeResolveTransformer.kt @@ -38,7 +38,8 @@ open class FirTypeResolveTransformer : FirTransformer() { // from high priority to low priority FirExplicitImportingScope(file.imports), FirSelfImportingScope(file.packageFqName, file.session), - FirStarImportingScope(file.imports, file.session) + FirExplicitStarImportingScope(file.imports, file.session), + FirDefaultStarImportingScope(file.session) ) ) packageFqName = file.packageFqName diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStarImportingScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt similarity index 84% rename from compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStarImportingScope.kt rename to compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt index a6c09a8e19b..1ed9d2a8c1c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStarImportingScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractStarImportingScope.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.fir.scopes.impl import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirImport import org.jetbrains.kotlin.fir.declarations.FirResolvedImport import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider import org.jetbrains.kotlin.fir.scopes.FirPosition @@ -15,9 +14,9 @@ import org.jetbrains.kotlin.fir.symbols.ConeSymbol import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name -class FirStarImportingScope(imports: List, val session: FirSession) : FirScope { +abstract class FirAbstractStarImportingScope(val session: FirSession) : FirScope { - private val starImports = imports.filterIsInstance().filter { it.isAllUnder } + protected abstract val starImports: List override fun processClassifiersByName( name: Name, @@ -39,4 +38,5 @@ class FirStarImportingScope(imports: List, val session: FirSession) : } return true } + } \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt new file mode 100644 index 00000000000..ab5b859b8a8 --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDefaultStarImportingScope.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.fir.scopes.impl + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.impl.FirImportImpl +import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedPackageStarImport +import org.jetbrains.kotlin.name.FqName + +class FirDefaultStarImportingScope(session: FirSession) : FirAbstractStarImportingScope(session) { + // TODO: move relevant code in TargetPlatform from compiler:frontend and use here + override val starImports = listOf( + "kotlin", + "kotlin.annotation", + "kotlin.collections", + "kotlin.ranges", + "kotlin.sequences", + "kotlin.text", + "kotlin.io" + ).map { + val fqName = FqName(it) + FirResolvedPackageStarImport( + FirImportImpl(session, null, fqName, isAllUnder = true, aliasName = null), + fqName + ) + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt new file mode 100644 index 00000000000..fbfa4dc4f9f --- /dev/null +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirExplicitStarImportingScope.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.fir.scopes.impl + +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirImport +import org.jetbrains.kotlin.fir.declarations.FirResolvedImport + +class FirExplicitStarImportingScope(imports: List, session: FirSession) : FirAbstractStarImportingScope(session) { + override val starImports = imports.filterIsInstance().filter { it.isAllUnder } +} \ No newline at end of file diff --git a/compiler/testData/fir/resolve/builtins/lists.kt b/compiler/testData/fir/resolve/builtins/lists.kt index 1dd3753ddc4..7bc9fcf408e 100644 --- a/compiler/testData/fir/resolve/builtins/lists.kt +++ b/compiler/testData/fir/resolve/builtins/lists.kt @@ -1,6 +1,3 @@ -import kotlin.* -import kotlin.collections.* - abstract class MyStringList : List abstract class MyMutableStringList : MutableList diff --git a/compiler/testData/fir/resolve/enum.txt b/compiler/testData/fir/resolve/enum.txt index bc2b76e785a..7e16808cb6d 100644 --- a/compiler/testData/fir/resolve/enum.txt +++ b/compiler/testData/fir/resolve/enum.txt @@ -9,19 +9,19 @@ FILE: enum.kt public? constructor(x: R/Some/) public? final enum entry FIRST() : R/SomeEnum/ { - public? open? override function check(y: R/Some/): R/error: Symbol not found/ { + public? open? override function check(y: R/Some/): R/kotlin/Boolean/ { STUB } } public? final enum entry SECOND() : R/SomeEnum/ { - public? open? override function check(y: R/Some/): R/error: Symbol not found/ { + public? open? override function check(y: R/Some/): R/kotlin/Boolean/ { STUB } } - public? abstract function check(y: R/Some/): R/error: Symbol not found/ + public? abstract function check(y: R/Some/): R/kotlin/Boolean/ } diff --git a/compiler/testData/fir/resolve/simpleClass.kt b/compiler/testData/fir/resolve/simpleClass.kt index 09e2961bfe7..851f3c6f289 100644 --- a/compiler/testData/fir/resolve/simpleClass.kt +++ b/compiler/testData/fir/resolve/simpleClass.kt @@ -1,5 +1,3 @@ -import kotlin.* - interface SomeInterface { fun foo(x: Int, y: String): String