From 5041f00fea81f063430f933322e8cbf6976b0791 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 24 Dec 2014 18:19:38 +0300 Subject: [PATCH] Do not wrap empty scope and fix kotlinSourceAndClassFiles() --- .../stubindex/JetSourceFilterScope.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java b/idea/idea-analysis/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java index 5459f46f577..fac219cf931 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/stubindex/JetSourceFilterScope.java @@ -29,26 +29,38 @@ import org.jetbrains.jet.plugin.util.ProjectRootsUtil; public class JetSourceFilterScope extends DelegatingGlobalSearchScope { @NotNull public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate, @NotNull Project project) { - if (delegate instanceof JetSourceFilterScope) { - return delegate; - } - return new JetSourceFilterScope(delegate, true, true, project); + return create(delegate, true, true, project); } @NotNull public static GlobalSearchScope kotlinSourceAndClassFiles(@NotNull GlobalSearchScope delegate, @NotNull Project project) { - if (delegate instanceof JetSourceFilterScope) { - delegate = ((JetSourceFilterScope) delegate).myBaseScope; - } - return new JetSourceFilterScope(delegate, false, true, project); + return create(delegate, false, true, project); } @NotNull public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate, @NotNull Project project) { + return create(delegate, false, false, project); + } + + @NotNull + private static GlobalSearchScope create( + @NotNull GlobalSearchScope delegate, + boolean includeLibrarySourceFiles, + boolean includeClassFiles, + @NotNull Project project + ) { + if (delegate == GlobalSearchScope.EMPTY_SCOPE) return delegate; + if (delegate instanceof JetSourceFilterScope) { - delegate = ((JetSourceFilterScope) delegate).myBaseScope; + JetSourceFilterScope wrappedDelegate = (JetSourceFilterScope) delegate; + + boolean doIncludeLibrarySourceFiles = wrappedDelegate.includeLibrarySourceFiles && includeLibrarySourceFiles; + boolean doIncludeClassFiles = wrappedDelegate.includeClassFiles && includeClassFiles; + + return new JetSourceFilterScope(wrappedDelegate.myBaseScope, doIncludeLibrarySourceFiles, doIncludeClassFiles, project); } - return new JetSourceFilterScope(delegate, false, false, project); + + return new JetSourceFilterScope(delegate, includeLibrarySourceFiles, includeClassFiles, project); } private final ProjectFileIndex index; @@ -72,6 +84,11 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope { this.isJsProject = JsProjectDetector.isJsProject(project); } + @Override + public Project getProject() { + return project; + } + @Override public boolean contains(@NotNull VirtualFile file) { if (!super.contains(file)) {