summaryrefslogtreecommitdiff
path: root/platform/indexing-impl/src/com/intellij/openapi
diff options
context:
space:
mode:
Diffstat (limited to 'platform/indexing-impl/src/com/intellij/openapi')
-rw-r--r--platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryScope.java4
-rw-r--r--platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleScopeProviderImpl.java (renamed from platform/indexing-impl/src/com/intellij/openapi/module/impl/ModuleScopeProviderImpl.java)28
-rw-r--r--platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java7
-rw-r--r--platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsScope.java79
-rw-r--r--platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsTestScope.java40
5 files changed, 110 insertions, 48 deletions
diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryScope.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryScope.java
index 2dcbf3558292..f78b69704db3 100644
--- a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryScope.java
+++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/LibraryScope.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -20,6 +20,7 @@ import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.util.PathUtil;
+import org.jetbrains.annotations.NotNull;
/**
* @author nik
@@ -32,6 +33,7 @@ public class LibraryScope extends LibraryScopeBase {
myLibrary = library;
}
+ @NotNull
@Override
public String getDisplayName() {
String name = myLibrary.getName();
diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/ModuleScopeProviderImpl.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleScopeProviderImpl.java
index 052c73022d53..2e7c581f0976 100644
--- a/platform/indexing-impl/src/com/intellij/openapi/module/impl/ModuleScopeProviderImpl.java
+++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleScopeProviderImpl.java
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.intellij.openapi.module.impl;
+package com.intellij.openapi.module.impl.scopes;
import com.intellij.openapi.module.Module;
-import com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope;
-import com.intellij.openapi.module.impl.scopes.ModuleWithDependentsScope;
+import com.intellij.openapi.module.impl.ModuleScopeProvider;
import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.util.containers.ConcurrentIntObjectMap;
import com.intellij.util.containers.StripedLockIntObjectConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
@@ -27,16 +27,15 @@ import org.jetbrains.annotations.NotNull;
*/
public class ModuleScopeProviderImpl implements ModuleScopeProvider {
private final Module myModule;
- private final StripedLockIntObjectConcurrentHashMap<GlobalSearchScope> myScopeCache = new StripedLockIntObjectConcurrentHashMap<GlobalSearchScope>();
- private GlobalSearchScope myModuleWithDependentsScope;
- private GlobalSearchScope myModuleTestsWithDependentsScope;
+ private final ConcurrentIntObjectMap<GlobalSearchScope> myScopeCache = new StripedLockIntObjectConcurrentHashMap<GlobalSearchScope>();
+ private ModuleWithDependentsTestScope myModuleTestsWithDependentsScope;
public ModuleScopeProviderImpl(@NotNull Module module) {
myModule = module;
}
@NotNull
- public GlobalSearchScope getCachedScope(@ModuleWithDependenciesScope.ScopeConstant int options) {
+ private GlobalSearchScope getCachedScope(@ModuleWithDependenciesScope.ScopeConstant int options) {
GlobalSearchScope scope = myScopeCache.get(options);
if (scope == null) {
scope = new ModuleWithDependenciesScope(myModule, options);
@@ -45,7 +44,6 @@ public class ModuleScopeProviderImpl implements ModuleScopeProvider {
return scope;
}
-
@Override
@NotNull
public GlobalSearchScope getModuleScope() {
@@ -93,19 +91,15 @@ public class ModuleScopeProviderImpl implements ModuleScopeProvider {
@Override
@NotNull
public GlobalSearchScope getModuleWithDependentsScope() {
- GlobalSearchScope scope = myModuleWithDependentsScope;
- if (scope == null) {
- myModuleWithDependentsScope = scope = new ModuleWithDependentsScope(myModule, false);
- }
- return scope;
+ return getModuleTestsWithDependentsScope().getBaseScope();
}
@Override
@NotNull
- public GlobalSearchScope getModuleTestsWithDependentsScope() {
- GlobalSearchScope scope = myModuleTestsWithDependentsScope;
+ public ModuleWithDependentsTestScope getModuleTestsWithDependentsScope() {
+ ModuleWithDependentsTestScope scope = myModuleTestsWithDependentsScope;
if (scope == null) {
- myModuleTestsWithDependentsScope = scope = new ModuleWithDependentsScope(myModule, true);
+ myModuleTestsWithDependentsScope = scope = new ModuleWithDependentsTestScope(myModule);
}
return scope;
}
@@ -120,8 +114,6 @@ public class ModuleScopeProviderImpl implements ModuleScopeProvider {
@Override
public void clearCache() {
myScopeCache.clear();
- myModuleWithDependentsScope = null;
myModuleTestsWithDependentsScope = null;
}
-
}
diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java
index 477a04f1d549..05b0ef34be7e 100644
--- a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java
+++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependenciesScope.java
@@ -34,7 +34,6 @@ import org.jetbrains.annotations.TestOnly;
import java.util.*;
public class ModuleWithDependenciesScope extends GlobalSearchScope {
-
public static final int COMPILE = 0x01;
public static final int LIBRARIES = 0x02;
public static final int MODULES = 0x04;
@@ -59,10 +58,10 @@ public class ModuleWithDependenciesScope extends GlobalSearchScope {
myModule = module;
myOptions = options;
- myProjectFileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
+ myProjectFileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
OrderEnumerator en = ModuleRootManager.getInstance(module).orderEntries();
- /*if (myIncludeOtherModules) */en.recursively();
+ en.recursively();
if (hasOption(COMPILE)) {
en.exportedOnly().compileOnly();
@@ -117,6 +116,7 @@ public class ModuleWithDependenciesScope extends GlobalSearchScope {
}
}
+ @NotNull
public Module getModule() {
return myModule;
}
@@ -125,6 +125,7 @@ public class ModuleWithDependenciesScope extends GlobalSearchScope {
return (myOptions & option) != 0;
}
+ @NotNull
@Override
public String getDisplayName() {
return hasOption(COMPILE) ? PsiBundle.message("search.scope.module", myModule.getName())
diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsScope.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsScope.java
index 367ebd2a4f05..0a575acdc550 100644
--- a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsScope.java
+++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsScope.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-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.
@@ -17,82 +17,112 @@ package com.intellij.openapi.module.impl.scopes;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.ProjectScope;
+import com.intellij.psi.util.CachedValueProvider;
+import com.intellij.psi.util.CachedValuesManager;
+import com.intellij.util.containers.MultiMap;
import com.intellij.util.containers.Queue;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.Set;
/**
* @author max
*/
-public class ModuleWithDependentsScope extends GlobalSearchScope {
+class ModuleWithDependentsScope extends GlobalSearchScope {
private final Module myModule;
- private final boolean myOnlyTests;
private final ProjectFileIndex myProjectFileIndex;
private final Set<Module> myModules;
private final GlobalSearchScope myProjectScope;
- public ModuleWithDependentsScope(Module module, boolean onlyTests) {
+ ModuleWithDependentsScope(@NotNull Module module) {
super(module.getProject());
myModule = module;
- myOnlyTests = onlyTests;
- myProjectFileIndex = ProjectRootManager.getInstance(myModule.getProject()).getFileIndex();
- myProjectScope = ProjectScope.getProjectScope(myModule.getProject());
+ myProjectFileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
+ myProjectScope = ProjectScope.getProjectScope(module.getProject());
myModules = new THashSet<Module>();
- myModules.add(myModule);
+ myModules.add(module);
fillModules();
}
private void fillModules() {
+ ModuleIndex index = getModuleIndex(myModule.getProject());
+
Queue<Module> walkingQueue = new Queue<Module>(10);
walkingQueue.addLast(myModule);
- Module[] allModules = ModuleManager.getInstance(myModule.getProject()).getModules();
- Set<Module> processed = new THashSet<Module>();
-
while (!walkingQueue.isEmpty()) {
Module current = walkingQueue.pullFirst();
- processed.add(current);
- for (Module dependent : allModules) {
- for (OrderEntry orderEntry : ModuleRootManager.getInstance(dependent).getOrderEntries()) {
- if (orderEntry instanceof ModuleOrderEntry && current.equals(((ModuleOrderEntry)orderEntry).getModule())) {
- myModules.add(dependent);
- if (!processed.contains(dependent) && ((ModuleOrderEntry)orderEntry).isExported()) {
- walkingQueue.addLast(dependent);
- }
- }
+ myModules.addAll(index.plainUsages.get(current));
+ for (Module dependent : index.exportingUsages.get(current)) {
+ if (myModules.add(dependent)) {
+ walkingQueue.addLast(dependent);
}
}
}
}
+ private static class ModuleIndex {
+ final MultiMap<Module, Module> plainUsages = MultiMap.create();
+ final MultiMap<Module, Module> exportingUsages = MultiMap.create();
+ }
+ private static ModuleIndex getModuleIndex(final Project project) {
+ return CachedValuesManager.getManager(project).getCachedValue(project, new CachedValueProvider<ModuleIndex>() {
+ @Nullable
+ @Override
+ public Result<ModuleIndex> compute() {
+ ModuleIndex index = new ModuleIndex();
+ for (Module module : ModuleManager.getInstance(project).getModules()) {
+ for (OrderEntry orderEntry : ModuleRootManager.getInstance(module).getOrderEntries()) {
+ if (orderEntry instanceof ModuleOrderEntry) {
+ Module referenced = ((ModuleOrderEntry)orderEntry).getModule();
+ if (referenced != null) {
+ MultiMap<Module, Module> map = ((ModuleOrderEntry)orderEntry).isExported() ? index.exportingUsages : index.plainUsages;
+ map.putValue(referenced, module);
+ }
+ }
+ }
+ }
+ return Result.create(index, ProjectRootManager.getInstance(project));
+ }
+ });
+ }
+
+ @Override
public boolean contains(@NotNull VirtualFile file) {
+ return contains(file, false);
+ }
+
+ boolean contains(@NotNull VirtualFile file, boolean myOnlyTests) {
Module moduleOfFile = myProjectFileIndex.getModuleForFile(file);
- if (moduleOfFile == null) return false;
- if (!myModules.contains(moduleOfFile)) return false;
+ if (moduleOfFile == null || !myModules.contains(moduleOfFile)) return false;
if (myOnlyTests && !myProjectFileIndex.isInTestSourceContent(file)) return false;
return myProjectScope.contains(file);
}
+ @Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
return 0;
}
+ @Override
public boolean isSearchInModuleContent(@NotNull Module aModule) {
return myModules.contains(aModule);
}
+ @Override
public boolean isSearchInLibraries() {
return false;
}
@@ -108,10 +138,7 @@ public class ModuleWithDependentsScope extends GlobalSearchScope {
final ModuleWithDependentsScope moduleWithDependentsScope = (ModuleWithDependentsScope)o;
- if (myOnlyTests != moduleWithDependentsScope.myOnlyTests) return false;
- if (!myModule.equals(moduleWithDependentsScope.myModule)) return false;
-
- return true;
+ return myModule.equals(moduleWithDependentsScope.myModule);
}
public int hashCode() {
diff --git a/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsTestScope.java b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsTestScope.java
new file mode 100644
index 000000000000..f9ec689a40ab
--- /dev/null
+++ b/platform/indexing-impl/src/com/intellij/openapi/module/impl/scopes/ModuleWithDependentsTestScope.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2000-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 com.intellij.openapi.module.impl.scopes;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.search.DelegatingGlobalSearchScope;
+import org.jetbrains.annotations.NotNull;
+
+// Tests only (module plus dependencies) scope
+// Delegates to ModuleWithDependentsScope with extra flag testOnly to reduce memory for holding modules and CPU for traversing dependencies.
+class ModuleWithDependentsTestScope extends DelegatingGlobalSearchScope {
+ ModuleWithDependentsTestScope(@NotNull Module module) {
+ // the additional equality argument allows to distinguish ModuleWithDependentsTestScope from ModuleWithDependentsScope
+ super(new ModuleWithDependentsScope(module), true);
+ }
+
+ @Override
+ public boolean contains(@NotNull VirtualFile file) {
+ return getBaseScope().contains(file, true);
+ }
+
+ @NotNull
+ ModuleWithDependentsScope getBaseScope() {
+ return (ModuleWithDependentsScope)myBaseScope;
+ }
+}