Compare commits

...

1 Commits

Author SHA1 Message Date
Kirill Shmakov
a7f85dbf75 WIP: State 2020-04-27 16:50:29 +03:00
6 changed files with 92 additions and 38 deletions

View File

@@ -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 @@ abstract class AbstractResolverForProject<M : ModuleInfo>(
override fun descriptorForModule(moduleInfo: M): ModuleDescriptorImpl {
checkModuleIsCorrect(moduleInfo)
return doGetDescriptorForModule(moduleInfo)
val result = doGetDescriptorForModule(moduleInfo)
return result
}
override fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>): Nothing {

View File

@@ -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 @@ class ExpectedActualDeclarationChecker(
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 } }
)
}
}

View File

@@ -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 @@ enum class LanguageFeature(
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

View File

@@ -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 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
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 {

View File

@@ -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 @@ internal class ProjectResolutionFacade(
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 {

View File

@@ -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 @@ class IdeaModuleStructureOracle : ModuleStructureOracle {
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) {