Drop JsProjectDetector

It leads to undesired behaviour
    such as returning library source when only binaries are queried
It is redundant since js libraries do not include kotlin source files
    (real binary format is used for this purpose for along time now)
This commit is contained in:
Pavel V. Talanov
2017-10-17 14:41:43 +03:00
parent 6551ee5403
commit 2af0bf4c71
4 changed files with 5 additions and 53 deletions
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2015 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.
*/
package org.jetbrains.kotlin.idea.caches.resolve
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootModificationTracker
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.CachedValuesManager
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.js.resolve.JsPlatform
//TODO: this should go away to support cross-platform projects
object JsProjectDetector {
@JvmStatic
fun isJsProject(project: Project): Boolean {
return CachedValuesManager.getManager(project).getCachedValue(project) {
val result = ModuleManager.getInstance(project).modules.any { TargetPlatformDetector.getPlatform(it) == JsPlatform }
CachedValueProvider.Result(result, ProjectRootModificationTracker.getInstance(project))
}
}
}
@@ -35,16 +35,13 @@ class KotlinSourceFilterScope private constructor(
private val index = ProjectRootManager.getInstance(project).fileIndex
//NOTE: avoid recomputing in potentially bottleneck 'contains' method
private val isJsProjectRef = Ref<Boolean?>(null)
override fun getProject() = project
override fun contains(file: VirtualFile): Boolean {
if (!super.contains(file)) return false
return ProjectRootsUtil.isInContent(
project, file, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, includeScriptDependencies, index, isJsProjectRef
project, file, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, includeScriptDependencies, index
)
}
@@ -28,15 +28,14 @@ import com.intellij.openapi.roots.FileIndex
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.util.Ref
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFileSystemItem
import org.jetbrains.kotlin.idea.KotlinModuleFileType
import org.jetbrains.kotlin.idea.caches.resolve.JsProjectDetector
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInFileType
import org.jetbrains.kotlin.idea.decompiler.js.KotlinJavaScriptMetaFileType
import org.jetbrains.kotlin.idea.util.application.runReadAction
abstract class KotlinBinaryExtension(val fileType: FileType) {
@@ -53,6 +52,7 @@ abstract class KotlinBinaryExtension(val fileType: FileType) {
class JavaClassBinary: KotlinBinaryExtension(JavaClassFileType.INSTANCE)
class KotlinBuiltInBinary: KotlinBinaryExtension(KotlinBuiltInFileType)
class KotlinModuleBinary: KotlinBinaryExtension(KotlinModuleFileType.INSTANCE)
class KotlinJsMetaBinary: KotlinBinaryExtension(KotlinJavaScriptMetaFileType)
fun FileType.isKotlinBinary(): Boolean = this in KotlinBinaryExtension.kotlinBinaries
@@ -69,8 +69,7 @@ object ProjectRootsUtil {
@JvmStatic fun isInContent(project: Project, file: VirtualFile, includeProjectSource: Boolean,
includeLibrarySource: Boolean, includeLibraryClasses: Boolean,
includeScriptDependencies: Boolean,
fileIndex: ProjectFileIndex = ProjectFileIndex.SERVICE.getInstance(project),
isJsProjectRef: Ref<Boolean?>? = null): Boolean {
fileIndex: ProjectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)): Boolean {
if (includeProjectSource && fileIndex.isInSourceContentWithoutInjected(file)) return true
@@ -92,15 +91,6 @@ object ProjectRootsUtil {
if (scriptConfigurationManager?.getAllLibrarySourcesScope()?.contains(file) == true) return true
}
if ((includeLibraryClasses && fileIndex.isInLibraryClasses(file)) ||
(includeLibrarySource && fileIndex.isInLibrarySource(file))) {
//NOTE: avoid computing isJsProject if redundant
val isJsProject = isJsProjectRef?.get() ?: JsProjectDetector.isJsProject(project)
isJsProjectRef?.set(isJsProject)
return isJsProject
}
return false
}
+1
View File
@@ -2726,6 +2726,7 @@
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.JavaClassBinary"/>
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinBuiltInBinary"/>
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinModuleBinary"/>
<binaryExtension implementation="org.jetbrains.kotlin.idea.util.KotlinJsMetaBinary"/>
</extensions>
</idea-plugin>