Minor: add another mode to JetSourceFilterScope

This commit is contained in:
Pavel V. Talanov
2014-12-02 18:48:16 +03:00
parent 79ce7135a4
commit 5676b0bf7c
2 changed files with 23 additions and 9 deletions
@@ -31,7 +31,15 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
if (delegate instanceof JetSourceFilterScope) { if (delegate instanceof JetSourceFilterScope) {
return delegate; return delegate;
} }
return new JetSourceFilterScope(delegate, true, project); return new JetSourceFilterScope(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);
} }
@NotNull @NotNull
@@ -39,18 +47,25 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
if (delegate instanceof JetSourceFilterScope) { if (delegate instanceof JetSourceFilterScope) {
delegate = ((JetSourceFilterScope) delegate).myBaseScope; delegate = ((JetSourceFilterScope) delegate).myBaseScope;
} }
return new JetSourceFilterScope(delegate, false, project); return new JetSourceFilterScope(delegate, false, false, project);
} }
private final ProjectFileIndex index; private final ProjectFileIndex index;
private final Project project; private final Project project;
private final boolean includeLibraries; private final boolean includeLibrarySourceFiles;
private final boolean includeClassFiles;
private JetSourceFilterScope(@NotNull GlobalSearchScope delegate, boolean includeLibraries, @NotNull Project project) { private JetSourceFilterScope(
@NotNull GlobalSearchScope delegate,
boolean includeLibrarySourceFiles,
boolean includeClassFiles,
@NotNull Project project
) {
super(delegate); super(delegate);
this.index = ProjectRootManager.getInstance(project).getFileIndex(); this.index = ProjectRootManager.getInstance(project).getFileIndex();
this.project = project; this.project = project;
this.includeLibraries = includeLibraries; this.includeLibrarySourceFiles = includeLibrarySourceFiles;
this.includeClassFiles = includeClassFiles;
} }
@Override @Override
@@ -59,6 +74,6 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
return false; return false;
} }
return ProjectRootsUtil.isInSources(project, file, /* includeTestSources */ includeLibraries, /* withLibraryClassesRoots */ true, index); return ProjectRootsUtil.isInSources(project, file, includeLibrarySourceFiles, includeClassFiles, index);
} }
} }
@@ -36,9 +36,8 @@ public object ProjectRootsUtil {
return !JetModuleTypeManager.getInstance()!!.isKtFileInGradleProjectInWrongFolder(file, project) return !JetModuleTypeManager.getInstance()!!.isKtFileInGradleProjectInWrongFolder(file, project)
} }
if (!includeLibrarySources) return false return (withLibraryClassesRoots && fileIndex.isInLibraryClasses(file))
|| (includeLibrarySources && fileIndex.isInLibrarySource(file))
return (withLibraryClassesRoots && fileIndex.isInLibraryClasses(file)) || fileIndex.isInLibrarySource(file)
} }
platformStatic platformStatic