Change AnalyzerFacade#createSetup to accept a list of synthetic files and a scope for physical source files
Make DeclarationProviderFactory a project service
This commit is contained in:
@@ -152,8 +152,6 @@ public class JetCoreEnvironment {
|
||||
|
||||
applicationEnvironment.getApplication().registerService(OperationModeProvider.class, new CompilerModeProvider());
|
||||
applicationEnvironment.getApplication().registerService(KotlinBinaryClassCache.class, new KotlinBinaryClassCache());
|
||||
applicationEnvironment.getApplication().registerService(DeclarationProviderFactoryService.class,
|
||||
new CliDeclarationProviderFactoryService());
|
||||
|
||||
return applicationEnvironment;
|
||||
}
|
||||
@@ -219,6 +217,7 @@ public class JetCoreEnvironment {
|
||||
configuration.getList(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY));
|
||||
|
||||
project.registerService(VirtualFileFinder.class, new CliVirtualFileFinder(classPath));
|
||||
project.registerService(DeclarationProviderFactoryService.class, new CliDeclarationProviderFactoryService(sourceFiles));
|
||||
}
|
||||
|
||||
public CompilerConfiguration getConfiguration() {
|
||||
|
||||
+26
-10
@@ -19,7 +19,11 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
@@ -47,6 +51,7 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
@@ -80,8 +85,12 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JvmSetup createSetup(@NotNull Project fileProject, @NotNull Collection<JetFile> files) {
|
||||
return createSetup(fileProject, files, new BindingTraceContext(), true);
|
||||
public JvmSetup createSetup(
|
||||
@NotNull Project fileProject,
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope
|
||||
) {
|
||||
return createSetup(fileProject, syntheticFiles, filesScope, new BindingTraceContext(), true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -91,20 +100,27 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
@NotNull BindingTrace trace,
|
||||
boolean addBuiltIns
|
||||
) {
|
||||
|
||||
return createSetup(project, files, trace, addBuiltIns).getLazyResolveSession();
|
||||
List<VirtualFile> virtualFiles = KotlinPackage.map(files, new Function1<JetFile, VirtualFile>() {
|
||||
@Override
|
||||
public VirtualFile invoke(JetFile file) {
|
||||
return file.getVirtualFile();
|
||||
}
|
||||
});
|
||||
return createSetup(project, Collections.<JetFile>emptyList(),
|
||||
GlobalSearchScope.filesScope(project, virtualFiles), trace, addBuiltIns).getLazyResolveSession();
|
||||
}
|
||||
|
||||
private static JvmSetup createSetup(
|
||||
Project project,
|
||||
Collection<JetFile> files,
|
||||
BindingTrace trace,
|
||||
public static JvmSetup createSetup(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope,
|
||||
@NotNull BindingTrace trace,
|
||||
boolean addBuiltIns
|
||||
) {
|
||||
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
||||
|
||||
DeclarationProviderFactory declarationProviderFactory =
|
||||
DeclarationProviderFactoryService.createDeclarationProviderFactory(project, globalContext.getStorageManager(), files);
|
||||
DeclarationProviderFactory declarationProviderFactory = DeclarationProviderFactoryService.object$
|
||||
.createDeclarationProviderFactory(project, globalContext.getStorageManager(), syntheticFiles, filesScope);
|
||||
|
||||
InjectorForLazyResolveWithJava resolveWithJava = new InjectorForLazyResolveWithJava(
|
||||
project,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.analyzer;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
@@ -48,6 +49,7 @@ public interface AnalyzerFacade {
|
||||
@NotNull
|
||||
Setup createSetup(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope
|
||||
);
|
||||
}
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.lazy.declarations;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public final class CliDeclarationProviderFactoryService extends DeclarationProviderFactoryService {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationProviderFactory create(
|
||||
@NotNull Project project, @NotNull StorageManager storageManager, @NotNull Collection<JetFile> files
|
||||
) {
|
||||
return new FileBasedDeclarationProviderFactory(storageManager, files);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.lazy.declarations
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.kotlin.util.sure
|
||||
import java.util.ArrayList
|
||||
|
||||
public class CliDeclarationProviderFactoryService(private val sourceFiles: Collection<JetFile>) : DeclarationProviderFactoryService() {
|
||||
|
||||
override fun create(
|
||||
project: Project,
|
||||
storageManager: StorageManager,
|
||||
syntheticFiles: Collection<JetFile>,
|
||||
filesScope: GlobalSearchScope
|
||||
): DeclarationProviderFactory {
|
||||
val allFiles = ArrayList<JetFile>()
|
||||
sourceFiles.filterTo(allFiles) {
|
||||
val vFile = it.getVirtualFile().sure("Source files should be physical files")
|
||||
filesScope.contains(vFile)
|
||||
}
|
||||
allFiles addAll syntheticFiles
|
||||
return FileBasedDeclarationProviderFactory(storageManager, allFiles)
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.lazy.declarations;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class DeclarationProviderFactoryService {
|
||||
@NotNull
|
||||
public abstract DeclarationProviderFactory create(
|
||||
@NotNull Project project,
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull Collection<JetFile> files
|
||||
);
|
||||
|
||||
@NotNull
|
||||
public static DeclarationProviderFactory createDeclarationProviderFactory(
|
||||
@NotNull Project project,
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull Collection<JetFile> files
|
||||
) {
|
||||
return ServiceManager.getService(DeclarationProviderFactoryService.class).create(project, storageManager, files);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.lazy.declarations
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.kotlin.util.sure
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import java.util.HashSet
|
||||
|
||||
public abstract class DeclarationProviderFactoryService {
|
||||
|
||||
public abstract fun create(
|
||||
project: Project,
|
||||
storageManager: StorageManager,
|
||||
syntheticFiles: Collection<JetFile>,
|
||||
filesScope: GlobalSearchScope
|
||||
): DeclarationProviderFactory
|
||||
|
||||
class object {
|
||||
|
||||
public fun createDeclarationProviderFactory(
|
||||
project: Project,
|
||||
storageManager: StorageManager,
|
||||
syntheticFiles: Collection<JetFile>,
|
||||
filesScope: GlobalSearchScope
|
||||
): DeclarationProviderFactory {
|
||||
return ServiceManager.getService(project, javaClass<DeclarationProviderFactoryService>())!!
|
||||
.create(project, storageManager, syntheticFiles, SyntheticFilesFilteringScope(syntheticFiles, filesScope))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class SyntheticFilesFilteringScope(syntheticFiles: Collection<JetFile>, baseScope: GlobalSearchScope) :
|
||||
DelegatingGlobalSearchScope(baseScope) {
|
||||
val originals = syntheticFiles.map {
|
||||
it.getOriginalFile().getVirtualFile()
|
||||
}.filterNotNullTo(HashSet<VirtualFile>())
|
||||
|
||||
override fun contains(file: VirtualFile): Boolean {
|
||||
if (file in originals) return false
|
||||
|
||||
return super.contains(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
@@ -68,7 +69,8 @@ public class LazyResolveTestUtil {
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(project);
|
||||
BindingTrace sharedTrace = support.getTrace();
|
||||
|
||||
ResolveSession lazyResolveSession = AnalyzerFacadeForJVM.createLazyResolveSession(project, files, sharedTrace, addBuiltIns);
|
||||
ResolveSession lazyResolveSession = AnalyzerFacadeForJVM.createSetup(project, files, GlobalSearchScope.EMPTY_SCOPE,
|
||||
sharedTrace, addBuiltIns).getLazyResolveSession();
|
||||
support.setModule((ModuleDescriptorImpl)lazyResolveSession.getModuleDescriptor());
|
||||
|
||||
return lazyResolveSession;
|
||||
|
||||
@@ -119,9 +119,6 @@
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"
|
||||
serviceImplementation="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"/>
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.stubindex.resolve.PluginDeclarationProviderFactoryService"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
||||
|
||||
@@ -158,6 +155,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.debugger.evaluate.KotlinEvaluateExpressionCache"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.debugger.evaluate.KotlinEvaluateExpressionCache"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.stubindex.resolve.PluginDeclarationProviderFactoryService"/>
|
||||
|
||||
<errorHandler implementation="org.jetbrains.jet.plugin.reporter.KotlinReportSubmitter"/>
|
||||
|
||||
<internalFileTemplate name="Kotlin File"/>
|
||||
|
||||
@@ -26,15 +26,12 @@ import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeProvider
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatform.*
|
||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
|
||||
import org.jetbrains.jet.plugin.project.TargetPlatformDetector
|
||||
import java.util.HashSet
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade
|
||||
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||
|
||||
@@ -67,11 +64,9 @@ class KotlinCacheService(val project: Project) {
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, javaClass<KotlinCacheService>())!!
|
||||
}
|
||||
|
||||
private fun globalResolveSessionProvider(platform: TargetPlatform, syntheticFile: JetFile? = null) = {
|
||||
val allFiles = JetFilesProvider.getInstance(project).allInScope(GlobalSearchScope.allScope(project))
|
||||
|
||||
val files = if (syntheticFile == null) allFiles else collectFilesForSyntheticFile(allFiles, syntheticFile)
|
||||
val setup = AnalyzerFacadeProvider.getAnalyzerFacade(platform).createSetup(project, files)
|
||||
private fun globalResolveSessionProvider(platform: TargetPlatform, syntheticFiles: Collection<JetFile> = listOf()) = {
|
||||
val setup = AnalyzerFacadeProvider.getAnalyzerFacade(platform)
|
||||
.createSetup(project, syntheticFiles, GlobalSearchScope.allScope(project))
|
||||
val resolveSessionForBodies = ResolveSessionForBodies(project, setup.getLazyResolveSession())
|
||||
CachedValueProvider.Result.create(
|
||||
SessionAndSetup(
|
||||
@@ -84,21 +79,6 @@ class KotlinCacheService(val project: Project) {
|
||||
)
|
||||
}
|
||||
|
||||
private fun collectFilesForSyntheticFile(allFiles: Collection<JetFile>, syntheticFile: JetFile): Collection<JetFile> {
|
||||
val files = HashSet(allFiles)
|
||||
|
||||
// Add requested file to the list of files for searching declarations
|
||||
files.add(syntheticFile)
|
||||
|
||||
val originalFile = syntheticFile.getOriginalFile()
|
||||
if (syntheticFile != originalFile) {
|
||||
// Given file can be a non-physical copy of the file in list (completion case). Remove the prototype file.
|
||||
files.remove(originalFile)
|
||||
}
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
private val globalCachesPerPlatform = mapOf(
|
||||
JVM to KotlinResolveCache(project, globalResolveSessionProvider(JVM)),
|
||||
JS to KotlinResolveCache(project, globalResolveSessionProvider(JS))
|
||||
@@ -110,7 +90,7 @@ class KotlinCacheService(val project: Project) {
|
||||
project,
|
||||
globalResolveSessionProvider(
|
||||
TargetPlatformDetector.getPlatform(file!!),
|
||||
file
|
||||
listOf(file)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -152,7 +132,11 @@ class KotlinCacheService(val project: Project) {
|
||||
if (virtualFile == null) {
|
||||
return false
|
||||
}
|
||||
return virtualFile in JetSourceFilterScope.kotlinSources(GlobalSearchScope.allScope(project))
|
||||
return virtualFile in kotlinSourcesInProjectScope()
|
||||
}
|
||||
|
||||
private fun kotlinSourcesInProjectScope(): GlobalSearchScope {
|
||||
return JetSourceFilterScope.kotlinSources(GlobalSearchScope.allScope(project))
|
||||
}
|
||||
|
||||
public fun <T> get(extension: CacheExtension<T>): T {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.plugin.project;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -33,7 +34,7 @@ public enum JSAnalyzerFacadeForIDEA implements AnalyzerFacade {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Setup createSetup(@NotNull Project project, @NotNull Collection<JetFile> files) {
|
||||
return new BasicSetup(AnalyzerFacadeForJS.getLazyResolveSession(files, new IDEAConfig(project)));
|
||||
public Setup createSetup(@NotNull Project project, @NotNull Collection<JetFile> syntheticFiles, @NotNull GlobalSearchScope filesScope) {
|
||||
return new BasicSetup(AnalyzerFacadeForJS.getLazyResolveSession(syntheticFiles, filesScope, new IDEAConfig(project)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
@@ -32,8 +33,8 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.MainFunctionDetector;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
import org.jetbrains.jet.plugin.MainFunctionDetector;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeProvider;
|
||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||
|
||||
@@ -83,7 +84,9 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
|
||||
if (psiFile instanceof JetFile) {
|
||||
JetFile jetFile = (JetFile) psiFile;
|
||||
AnalyzerFacade facade = AnalyzerFacadeProvider.getAnalyzerFacadeForFile(jetFile);
|
||||
ResolveSession resolveSession = facade.createSetup(jetFile.getProject(), Collections.singleton(jetFile)).getLazyResolveSession();
|
||||
ResolveSession resolveSession =
|
||||
facade.createSetup(jetFile.getProject(), Collections.<JetFile>emptyList(), GlobalSearchScope.fileScope(jetFile))
|
||||
.getLazyResolveSession();
|
||||
MainFunctionDetector mainFunctionDetector = new MainFunctionDetector(resolveSession);
|
||||
if (mainFunctionDetector.hasMain(jetFile.getDeclarations())) {
|
||||
return jetFile;
|
||||
|
||||
+8
-16
@@ -17,29 +17,21 @@
|
||||
package org.jetbrains.jet.plugin.stubindex.resolve
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Condition
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||
import org.jetbrains.jet.storage.StorageManager
|
||||
import org.jetbrains.jet.plugin.search.allScope
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||
|
||||
public class PluginDeclarationProviderFactoryService : DeclarationProviderFactoryService() {
|
||||
|
||||
override fun create(project: Project, storageManager: StorageManager, files: Collection<JetFile>): DeclarationProviderFactory {
|
||||
val indexedSourcesScope = JetSourceFilterScope.kotlinSourcesAndLibraries(project.allScope())
|
||||
val nonIndexedFiles = files.filter {
|
||||
file ->
|
||||
!file.isPhysical() || !indexedSourcesScope.contains(file.getVirtualFile()!!)
|
||||
}
|
||||
val physicalFilesScope = GlobalSearchScope.filesScope(project, files.filter { it.isPhysical() }.map { it.getVirtualFile()!! })
|
||||
val indexedFilesScope = indexedSourcesScope.intersectWith(physicalFilesScope)
|
||||
|
||||
return PluginDeclarationProviderFactory(project, indexedFilesScope, storageManager, nonIndexedFiles)
|
||||
override fun create(
|
||||
project: Project,
|
||||
storageManager: StorageManager,
|
||||
syntheticFiles: Collection<JetFile>,
|
||||
filesScope: GlobalSearchScope
|
||||
): DeclarationProviderFactory {
|
||||
return PluginDeclarationProviderFactory(project, JetSourceFilterScope.kotlinSources(filesScope), storageManager, syntheticFiles)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
@@ -36,6 +37,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
@@ -43,8 +45,6 @@ import org.jetbrains.k2js.config.Config;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService.createDeclarationProviderFactory;
|
||||
|
||||
public final class AnalyzerFacadeForJS {
|
||||
public static final List<ImportPath> DEFAULT_IMPORTS = ImmutableList.of(
|
||||
new ImportPath("js.*"),
|
||||
@@ -130,11 +130,20 @@ public final class AnalyzerFacadeForJS {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolveSession getLazyResolveSession(Collection<JetFile> files, Config config) {
|
||||
public static ResolveSession getLazyResolveSession(
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope,
|
||||
@NotNull Config config
|
||||
) {
|
||||
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
||||
DeclarationProviderFactory declarationProviderFactory =
|
||||
createDeclarationProviderFactory(config.getProject(), globalContext.getStorageManager(),
|
||||
Config.withJsLibAdded(files, config));
|
||||
DeclarationProviderFactory declarationProviderFactory = DeclarationProviderFactoryService.object$
|
||||
.createDeclarationProviderFactory(
|
||||
config.getProject(),
|
||||
globalContext.getStorageManager(),
|
||||
//TODO: lib files are not really synthetic
|
||||
Config.withJsLibAdded(syntheticFiles, config),
|
||||
filesScope
|
||||
);
|
||||
ModuleDescriptorImpl module = createJsModule("<lazy module>");
|
||||
module.addFragmentProvider(DependencyKind.BUILT_INS, KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user