Share check "is file under source roots"
This commit is contained in:
@@ -47,7 +47,7 @@ class ModuleTypeCacheManager private (project: Project) {
|
||||
fun isGradleModule(module: Module) = getModuleType(module) == ModuleType.GRADLE
|
||||
|
||||
private fun getModuleType(module: Module): ModuleType? {
|
||||
return cachedValue?.getValue(module)
|
||||
return cachedValue.getValue(module)
|
||||
}
|
||||
|
||||
private class VfsModificationTracker(project: Project): SimpleModificationTracker() {
|
||||
|
||||
+13
-3
@@ -59,12 +59,22 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (index.isInSourceContent(file)) {
|
||||
return isInProjectSources(project, file, index, /* withClassesRoots */ true, includeLibraries);
|
||||
}
|
||||
|
||||
public static boolean isInProjectSources(
|
||||
@NotNull Project project,
|
||||
@NotNull VirtualFile file,
|
||||
@NotNull ProjectFileIndex fileIndex,
|
||||
boolean withClassesRoots,
|
||||
boolean withLibraries
|
||||
) {
|
||||
if (fileIndex.isInSourceContent(file)) {
|
||||
return !JetModuleTypeManager.getInstance().isKtFileInGradleProjectInWrongFolder(file, project);
|
||||
}
|
||||
|
||||
if (!includeLibraries) return false;
|
||||
if (!withLibraries) return false;
|
||||
|
||||
return index.isInLibraryClasses(file) || index.isInLibrarySource(file);
|
||||
return (withClassesRoots && fileIndex.isInLibraryClasses(file)) || fileIndex.isInLibrarySource(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,11 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.util
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.roots.ProjectFileIndex
|
||||
import com.intellij.openapi.util.Computable
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.jet.plugin.configuration.JetModuleTypeManager
|
||||
import kotlin.platform.platformStatic
|
||||
import org.jetbrains.jet.plugin.util.application.runReadAction
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||
|
||||
public object ProjectRootsUtil {
|
||||
platformStatic
|
||||
@@ -36,15 +32,9 @@ public object ProjectRootsUtil {
|
||||
val virtualFile = containingFile.getVirtualFile()
|
||||
if (virtualFile == null) return@runReadAction false
|
||||
|
||||
val index = ProjectFileIndex.SERVICE.getInstance(element.getProject())
|
||||
val isInSourceRoot = if (includeLibrarySources)
|
||||
index.isInSource(virtualFile)
|
||||
else
|
||||
index.isInSourceContent(virtualFile)
|
||||
|
||||
if (!isInSourceRoot) return@runReadAction false
|
||||
|
||||
return@runReadAction !JetModuleTypeManager.getInstance()!!.isKtFileInGradleProjectInWrongFolder(element)
|
||||
val project = element.getProject()
|
||||
val index = ProjectFileIndex.SERVICE.getInstance(project)
|
||||
return@runReadAction JetSourceFilterScope.isInProjectSources(project, virtualFile, index, false, includeLibrarySources)
|
||||
}!!
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user