WIP: State
diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AbstractResolverForProject.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AbstractResolverForProject.kt
index 93ed25dd..91e17a8 100644
--- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AbstractResolverForProject.kt
+++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AbstractResolverForProject.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * 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.
*/
@@ -119,7 +119,8 @@
override fun descriptorForModule(moduleInfo: M): ModuleDescriptorImpl {
checkModuleIsCorrect(moduleInfo)
- return doGetDescriptorForModule(moduleInfo)
+ val result = doGetDescriptorForModule(moduleInfo)
+ return result
}
override fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>): Nothing {
diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt
index 5e5d63f..5974003 100644
--- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt
+++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ExpectedActualDeclarationChecker.kt
@@ -1,17 +1,6 @@
/*
- * Copyright 2010-2017 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 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.resolve.checkers
@@ -69,12 +58,14 @@
val checkActual = !context.languageVersionSettings.getFlag(AnalysisFlags.multiPlatformDoNotCheckActual)
val allImplementedModules = moduleStructureOracle.findAllDependsOnPaths(descriptor.module).flatMap { it.nodes }.toHashSet()
+ val expLast = ExpectedActualResolver.findExpectedForActual(descriptor, allImplementedModules.last(), { it.name in allImplementedModules.map { m -> m.name } })
+ val expFist = ExpectedActualResolver.findExpectedForActual(descriptor, allImplementedModules.first(), { it.name in allImplementedModules.map { m -> m.name } })
checkActualDeclarationHasExpected(
declaration,
descriptor,
context.trace,
checkActual,
- moduleVisibilityFilter = { it in allImplementedModules }
+ moduleVisibilityFilter = { it.name in allImplementedModules.map { m -> m.name } }
)
}
}
diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt
index 8e4885e..cc558a6 100644
--- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt
+++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * 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.
*/
@@ -142,7 +142,7 @@
State.ENABLED_WITH_WARNING
),
- MultiPlatformProjects(sinceVersion = null, defaultState = State.DISABLED),
+ MultiPlatformProjects(sinceVersion = KOTLIN_1_3, defaultState = State.ENABLED),
NewInference(sinceVersion = KOTLIN_1_4),
// In the next block, features can be enabled only along with new inference
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt
index bb6de03..548cd86 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt
@@ -1,17 +1,6 @@
/*
- * Copyright 2010-2016 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 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.idea.caches.resolve
@@ -493,8 +482,10 @@
return ModuleResolutionFacadeImpl(projectFacade, moduleInfo)
}
- override fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade? =
- (moduleInfo as? IdeaModuleInfo)?.let { getResolutionFacadeByModuleInfo(it, platform) }
+ override fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade? {
+// if (moduleInfo is LibrarySourceInfo)
+ return (moduleInfo as? IdeaModuleInfo)?.let { getResolutionFacadeByModuleInfo(it, platform) }
+ }
private fun Collection<KtFile>.filterNotInProjectSource(moduleInfo: IdeaModuleInfo): Set<KtFile> {
return mapNotNull {
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ProjectResolutionFacade.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ProjectResolutionFacade.kt
index 09e936c..8459699 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ProjectResolutionFacade.kt
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/ProjectResolutionFacade.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * 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.
*/
@@ -135,7 +135,8 @@
cachedResolverForProject.resolverForModuleDescriptor(moduleDescriptor)
internal fun findModuleDescriptor(ideaModuleInfo: IdeaModuleInfo): ModuleDescriptor {
- return cachedResolverForProject.descriptorForModule(ideaModuleInfo)
+ val result = cachedResolverForProject.descriptorForModule(ideaModuleInfo)
+ return result
}
internal fun getAnalysisResultsForElements(elements: Collection<KtElement>): AnalysisResult {
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaModuleStructureOracle.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaModuleStructureOracle.kt
index 8b1a440f..65090fc 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaModuleStructureOracle.kt
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/IdeaModuleStructureOracle.kt
@@ -1,20 +1,67 @@
/*
- * Copyright 2010-2019 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.
+ * 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.idea.project
import com.intellij.openapi.module.Module
+import com.intellij.openapi.roots.OrderRootType
+import com.intellij.openapi.roots.libraries.Library
+import com.intellij.openapi.vfs.VirtualFile
+import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl
+import com.intellij.psi.PsiManager
import org.jetbrains.kotlin.analyzer.ModuleInfo
+import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.caches.project.*
-import org.jetbrains.kotlin.idea.caches.project.sourceType
import org.jetbrains.kotlin.idea.core.unwrapModuleSourceInfo
+import org.jetbrains.kotlin.name.Name
+import org.jetbrains.kotlin.platform.TargetPlatform
+import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.ModulePath
import org.jetbrains.kotlin.resolve.ModuleStructureOracle
import java.util.*
+fun findVirtualFile(file: VirtualDirectoryImpl): VirtualFile? {
+ for (child in file.children) {
+ if (child.url.endsWith(".kt")) {
+ return child
+ }
+
+ if (child is VirtualDirectoryImpl) {
+ val result = findVirtualFile(child)
+ if (result != null) {
+ return result
+ }
+ }
+ }
+
+ return null
+}
+
+fun findModuleDescriptors(
+ library: Library,
+ platform: TargetPlatform,
+ psiManager: PsiManager,
+ cacheService: KotlinCacheService
+): Map<Name, ModuleDescriptor> {
+ val descriptors = hashMapOf<Name, ModuleDescriptor>()
+
+ for (sources in listOf(*library.getFiles(OrderRootType.SOURCES))) {
+ if (sources !is VirtualDirectoryImpl) continue
+
+ val virtualFileForKt = findVirtualFile(sources) ?: continue
+ val fileViewProvider = psiManager.findViewProvider(virtualFileForKt)
+ val ktFile = fileViewProvider!!.getPsi(fileViewProvider.baseLanguage) as? KtFile ?: continue
+ val facade = cacheService.getResolutionFacade(listOf(ktFile), platform)
+
+ descriptors[facade.moduleDescriptor.name] = facade.moduleDescriptor
+ }
+
+ return descriptors
+}
+
class IdeaModuleStructureOracle : ModuleStructureOracle {
override fun hasImplementingModules(module: ModuleDescriptor): Boolean {
return module.implementingDescriptors.isNotEmpty()
@@ -42,6 +89,29 @@
override fun findAllDependsOnPaths(module: ModuleDescriptor): List<ModulePath> {
val currentPath: Stack<ModuleInfo> = Stack()
+ if (module.platform != null && module.getCapability(ModuleInfo.Capability) is LibrarySourceInfo) {
+ val librarySourceInfo = module.getCapability(ModuleInfo.Capability) as LibrarySourceInfo
+
+ val cacheService = KotlinCacheService.getInstance(librarySourceInfo.project)
+ val psiManager = PsiManager.getInstance(librarySourceInfo.project)
+
+ val descriptors = hashMapOf<Name, ModuleDescriptor>()
+
+ for ((name, descriptor) in findModuleDescriptors(librarySourceInfo.library, module.platform!!, psiManager, cacheService)) {
+ descriptors[name] = descriptor
+ }
+
+ for (moduleInfo in getModuleInfosFromIdeaModel(librarySourceInfo.project).filter { it.displayedName.contains("stdlib") }) {
+ if (moduleInfo is LibraryInfo) {
+ for ((name, descriptor) in findModuleDescriptors(moduleInfo.library, module.platform!!, psiManager, cacheService)) {
+ descriptors[name] = descriptor
+ }
+ }
+ }
+
+ return listOf(ModulePath(descriptors.map { it.value }.toList()))
+ }
+
return sequence<ModuleInfoPath> {
val root = module.moduleInfo
if (root != null) {