From 7369bbb86369e52f351f56dbeddd3fca444ed21e Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 6 Aug 2010 09:35:21 +0400 Subject: [PATCH] added OrderEnumerator for collection of modules --- .../openapi/roots/ProjectRootManager.java | 11 +++++ .../roots/impl/ModulesOrderEnumerator.java | 46 +++++++++++++++++++ .../roots/impl/OrderEnumeratorBase.java | 4 +- .../roots/impl/ProjectOrderEnumerator.java | 6 +-- .../roots/impl/ProjectRootManagerImpl.java | 7 +++ .../stubs/StubProjectRootManagerEx.java | 1 + 6 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/openapi/roots/impl/ModulesOrderEnumerator.java diff --git a/platform/lang-api/src/com/intellij/openapi/roots/ProjectRootManager.java b/platform/lang-api/src/com/intellij/openapi/roots/ProjectRootManager.java index 03e5af546b16..61349d15b38f 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/ProjectRootManager.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/ProjectRootManager.java @@ -17,6 +17,7 @@ package com.intellij.openapi.roots; import com.intellij.openapi.Disposable; import com.intellij.openapi.module.ModifiableModuleModel; +import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.util.ModificationTracker; @@ -24,6 +25,8 @@ import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; + /** * Allows to query and modify the list of root directories belonging to a project. */ @@ -84,6 +87,14 @@ public abstract class ProjectRootManager implements ModificationTracker { @NotNull public abstract OrderEnumerator orderEntries(); + /** + * Creates new enumerator instance to process dependencies of several modules in the project. Caching is not supported for this enumerator + * @param modules modules to process + * @return new enumerator instance + */ + @NotNull + public abstract OrderEnumerator orderEntries(@NotNull Collection modules); + /** * Unlike getContentRoots(), this includes the project base dir. Is this really necessary? * TODO: remove this method? diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModulesOrderEnumerator.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModulesOrderEnumerator.java new file mode 100644 index 000000000000..d283dc060b3f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModulesOrderEnumerator.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2010 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.roots.impl; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.OrderEntry; +import com.intellij.util.Processor; +import gnu.trove.THashSet; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * @author nik + */ +public class ModulesOrderEnumerator extends OrderEnumeratorBase { + private Collection myModules; + + public ModulesOrderEnumerator(@NotNull Project project, @NotNull Collection modules) { + super(null, project, null); + myModules = modules; + } + + @Override + public void forEach(@NotNull Processor processor) { + myRecursivelyExportedOnly = false; + final THashSet processed = new THashSet(); + for (Module module : myModules) { + processEntries(getRootModel(module), processor, processed, true); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEnumeratorBase.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEnumeratorBase.java index 3fbfd6589f7c..b8441447d3cb 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEnumeratorBase.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEnumeratorBase.java @@ -48,11 +48,11 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { protected boolean myWithoutDepModules; private boolean myWithoutThisModuleContent; protected boolean myRecursively; - private boolean myRecursivelyExportedOnly; + protected boolean myRecursivelyExportedOnly; private boolean myExportedOnly; private Condition myCondition; private List myCustomHandlers; - private ModulesProvider myModulesProvider; + protected ModulesProvider myModulesProvider; private OrderRootsCache myCache; public OrderEnumeratorBase(@Nullable Module module, @NotNull Project project, @Nullable OrderRootsCache cache) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectOrderEnumerator.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectOrderEnumerator.java index f2039ecbb206..9957f4e2c43d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectOrderEnumerator.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectOrderEnumerator.java @@ -18,7 +18,6 @@ package com.intellij.openapi.roots.impl; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.OrderEntry; import com.intellij.util.Processor; import gnu.trove.THashSet; @@ -40,8 +39,9 @@ public class ProjectOrderEnumerator extends OrderEnumeratorBase { myRecursively = false; myWithoutDepModules = true; final THashSet processed = new THashSet(); - for (Module module : ModuleManager.getInstance(myProject).getSortedModules()) { - processEntries(ModuleRootManager.getInstance(module), processor, processed, true); + final Module[] modules = myModulesProvider != null ? myModulesProvider.getModules() : ModuleManager.getInstance(myProject).getSortedModules(); + for (Module module : modules) { + processEntries(getRootModel(module), processor, processed, true); } } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java index 1034ec9e6e20..188a0619ffe4 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerImpl.java @@ -305,11 +305,18 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj return VfsUtil.toVirtualFileArray(result); } + @NotNull @Override public OrderEnumerator orderEntries() { return new ProjectOrderEnumerator(myProject, myRootsCache); } + @NotNull + @Override + public OrderEnumerator orderEntries(@NotNull Collection modules) { + return new ModulesOrderEnumerator(myProject, modules); + } + public VirtualFile[] getContentRootsFromAllModules() { List result = new ArrayList(); final Module[] modules = getModuleManager().getSortedModules(); diff --git a/platform/lvcs-impl/testSrc/com/intellij/history/integration/stubs/StubProjectRootManagerEx.java b/platform/lvcs-impl/testSrc/com/intellij/history/integration/stubs/StubProjectRootManagerEx.java index 121e907cca40..eff9da4b3abb 100644 --- a/platform/lvcs-impl/testSrc/com/intellij/history/integration/stubs/StubProjectRootManagerEx.java +++ b/platform/lvcs-impl/testSrc/com/intellij/history/integration/stubs/StubProjectRootManagerEx.java @@ -97,6 +97,7 @@ public abstract class StubProjectRootManagerEx extends ProjectRootManagerEx { throw new UnsupportedOperationException(); } + @NotNull @Override public OrderEnumerator orderEntries() { throw new UnsupportedOperationException("'orderEntries' not implemented in " + getClass().getName());