From f1a808c7bcb16a93c7aa8933e6368f03c2114316 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 4 Mar 2011 14:01:28 +0300 Subject: [PATCH] public fields replaced by getters in order enumerator api --- .../roots/OrderEnumeratorSettings.java | 39 +----- .../roots/impl/ModuleOrderEnumerator.java | 2 +- .../roots/impl/ModulesOrderEnumerator.java | 2 +- .../roots/impl/OrderEnumeratorBase.java | 122 ++++++++++++------ .../roots/impl/OrderRootsEnumeratorImpl.java | 4 +- .../roots/impl/ProjectOrderEnumerator.java | 4 +- .../MavenOrderEnumeratorHandler.java | 8 +- 7 files changed, 94 insertions(+), 87 deletions(-) diff --git a/platform/lang-api/src/com/intellij/openapi/roots/OrderEnumeratorSettings.java b/platform/lang-api/src/com/intellij/openapi/roots/OrderEnumeratorSettings.java index c60a07adb619..15f38d43fd55 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/OrderEnumeratorSettings.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/OrderEnumeratorSettings.java @@ -15,39 +15,8 @@ */ package com.intellij.openapi.roots; -public class OrderEnumeratorSettings { - public boolean productionOnly; - public boolean compileOnly; - public boolean runtimeOnly; - public boolean withoutJdk; - public boolean withoutLibraries; - public boolean withoutDepModules; - public boolean withoutModuleSourceEntries; - public boolean recursively; - public boolean recursivelyExportedOnly; - public boolean exportedOnly; - - public int getFlags() { - int flags = 0; - if (productionOnly) flags |= 1; - flags <<= 1; - if (compileOnly) flags |= 1; - flags <<= 1; - if (runtimeOnly) flags |= 1; - flags <<= 1; - if (withoutJdk) flags |= 1; - flags <<= 1; - if (withoutLibraries) flags |= 1; - flags <<= 1; - if (withoutDepModules) flags |= 1; - flags <<= 1; - if (withoutModuleSourceEntries) flags |= 1; - flags <<= 1; - if (recursively) flags |= 1; - flags <<= 1; - if (recursivelyExportedOnly) flags |= 1; - flags <<= 1; - if (exportedOnly) flags |= 1; - return flags; - } +public interface OrderEnumeratorSettings { + boolean isProductionOnly(); + boolean isCompileOnly(); + boolean isRuntimeOnly(); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleOrderEnumerator.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleOrderEnumerator.java index 1cdbf463cc55..4129b5aa54fd 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleOrderEnumerator.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModuleOrderEnumerator.java @@ -40,7 +40,7 @@ public class ModuleOrderEnumerator extends OrderEnumeratorBase { @Override public void forEach(@NotNull Processor processor) { - processEntries(myRootModel, processor, mySettings.recursively ? new THashSet() : null, true); + processEntries(myRootModel, processor, myRecursively ? new THashSet() : null, true); } @Override 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 index 92c1170904f8..e3476457aa38 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModulesOrderEnumerator.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ModulesOrderEnumerator.java @@ -45,7 +45,7 @@ public class ModulesOrderEnumerator extends OrderEnumeratorBase { @Override public void forEach(@NotNull Processor processor) { - mySettings.recursivelyExportedOnly = false; + myRecursivelyExportedOnly = false; final THashSet processed = new THashSet(); for (Module module : myModules) { 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 24856dbbf45c..5a22cc1f7a22 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 @@ -36,10 +36,18 @@ import java.util.*; /** * @author nik */ -abstract class OrderEnumeratorBase extends OrderEnumerator { +abstract class OrderEnumeratorBase extends OrderEnumerator implements OrderEnumeratorSettings { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.OrderEnumeratorBase"); - - protected final OrderEnumeratorSettings mySettings = new OrderEnumeratorSettings(); + private boolean myProductionOnly; + private boolean myCompileOnly; + private boolean myRuntimeOnly; + private boolean myWithoutJdk; + private boolean myWithoutLibraries; + protected boolean myWithoutDepModules; + private boolean myWithoutModuleSourceEntries; + protected boolean myRecursively; + protected boolean myRecursivelyExportedOnly; + private boolean myExportedOnly; private Condition myCondition; private final List myCustomHandlers; protected ModulesProvider myModulesProvider; @@ -59,66 +67,61 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { this.myCustomHandlers = customHandlers == null ? Collections.emptyList() : customHandlers; } - @NotNull - public OrderEnumeratorSettings getSettings() { - return mySettings; - } - @Override public OrderEnumerator productionOnly() { - mySettings.productionOnly = true; + myProductionOnly = true; return this; } @Override public OrderEnumerator compileOnly() { - mySettings.compileOnly = true; + myCompileOnly = true; return this; } @Override public OrderEnumerator runtimeOnly() { - mySettings.runtimeOnly = true; + myRuntimeOnly = true; return this; } @Override public OrderEnumerator withoutSdk() { - mySettings.withoutJdk = true; + myWithoutJdk = true; return this; } @Override public OrderEnumerator withoutLibraries() { - mySettings.withoutLibraries = true; + myWithoutLibraries = true; return this; } @Override public OrderEnumerator withoutDepModules() { - mySettings.withoutDepModules = true; + myWithoutDepModules = true; return this; } @Override public OrderEnumerator withoutModuleSourceEntries() { - mySettings.withoutModuleSourceEntries = true; + myWithoutModuleSourceEntries = true; return this; } @Override public OrderEnumerator recursively() { - mySettings.recursively = true; + myRecursively = true; return this; } @Override public OrderEnumerator exportedOnly() { - if (mySettings.recursively) { - mySettings.recursivelyExportedOnly = true; + if (myRecursively) { + myRecursivelyExportedOnly = true; } else { - mySettings.exportedOnly = true; + myExportedOnly = true; } return this; } @@ -135,10 +138,6 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { return this; } - public int getFlags() { - return mySettings.getFlags(); - } - @Override public OrderRootsEnumerator classes() { return new OrderRootsEnumeratorImpl(this, OrderRootType.CLASSES); @@ -173,6 +172,30 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { return myCache; } + public int getFlags() { + int flags = 0; + if (myProductionOnly) flags |= 1; + flags <<= 1; + if (myCompileOnly) flags |= 1; + flags <<= 1; + if (myRuntimeOnly) flags |= 1; + flags <<= 1; + if (myWithoutJdk) flags |= 1; + flags <<= 1; + if (myWithoutLibraries) flags |= 1; + flags <<= 1; + if (myWithoutDepModules) flags |= 1; + flags <<= 1; + if (myWithoutModuleSourceEntries) flags |= 1; + flags <<= 1; + if (myRecursively) flags |= 1; + flags <<= 1; + if (myRecursivelyExportedOnly) flags |= 1; + flags <<= 1; + if (myExportedOnly) flags |= 1; + return flags; + } + protected void processEntries(final ModuleRootModel rootModel, Processor processor, Set processed, boolean firstLevel) { @@ -181,17 +204,17 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { for (OrderEntry entry : rootModel.getOrderEntries()) { if (myCondition != null && !myCondition.value(entry)) continue; - if (mySettings.withoutJdk && entry instanceof JdkOrderEntry) continue; - if (mySettings.withoutLibraries && entry instanceof LibraryOrderEntry) continue; - if (mySettings.withoutDepModules) { - if (!mySettings.recursively && entry instanceof ModuleOrderEntry) continue; + if (myWithoutJdk && entry instanceof JdkOrderEntry) continue; + if (myWithoutLibraries && entry instanceof LibraryOrderEntry) continue; + if (myWithoutDepModules) { + if (!myRecursively && entry instanceof ModuleOrderEntry) continue; if (entry instanceof ModuleSourceOrderEntry && !isRootModuleModel(((ModuleSourceOrderEntry)entry).getRootModel())) continue; } - if (mySettings.withoutModuleSourceEntries && entry instanceof ModuleSourceOrderEntry) continue; + if (myWithoutModuleSourceEntries && entry instanceof ModuleSourceOrderEntry) continue; OrderEnumerationHandler.AddDependencyType shouldAdd = OrderEnumerationHandler.AddDependencyType.DEFAULT; for (OrderEnumerationHandler handler : myCustomHandlers) { - shouldAdd = handler.shouldAddDependency(entry, mySettings); + shouldAdd = handler.shouldAddDependency(entry, this); if (shouldAdd != OrderEnumerationHandler.AddDependencyType.DEFAULT) break; } if (shouldAdd == OrderEnumerationHandler.AddDependencyType.DO_NOT_ADD) continue; @@ -202,12 +225,12 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { ExportableOrderEntry exportableEntry = (ExportableOrderEntry)entry; if (shouldAdd == OrderEnumerationHandler.AddDependencyType.DEFAULT) { final DependencyScope scope = exportableEntry.getScope(); - if (mySettings.compileOnly && !scope.isForProductionCompile() && !scope.isForTestCompile()) continue; - if (mySettings.runtimeOnly && !scope.isForProductionRuntime() && !scope.isForTestRuntime()) continue; - if (mySettings.productionOnly) { + if (myCompileOnly && !scope.isForProductionCompile() && !scope.isForTestCompile()) continue; + if (myRuntimeOnly && !scope.isForProductionRuntime() && !scope.isForTestRuntime()) continue; + if (myProductionOnly) { if (!scope.isForProductionCompile() && !scope.isForProductionRuntime() - || mySettings.compileOnly && !scope.isForProductionCompile() - || mySettings.runtimeOnly && !scope.isForProductionRuntime()) { + || myCompileOnly && !scope.isForProductionCompile() + || myRuntimeOnly && !scope.isForProductionRuntime()) { continue; } } @@ -215,11 +238,11 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { exported = exportableEntry.isExported(); } if (!exported) { - if (mySettings.exportedOnly) continue; - if (mySettings.recursivelyExportedOnly && !firstLevel) continue; + if (myExportedOnly) continue; + if (myRecursivelyExportedOnly && !firstLevel) continue; } - if (mySettings.recursively && entry instanceof ModuleOrderEntry) { + if (myRecursively && entry instanceof ModuleOrderEntry) { ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry)entry; final Module module = moduleOrderEntry.getModule(); if (module != null) { @@ -238,7 +261,7 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { } } - if (mySettings.withoutDepModules && entry instanceof ModuleOrderEntry) continue; + if (myWithoutDepModules && entry instanceof ModuleOrderEntry) continue; if (!processor.process(entry)) { return; } @@ -286,7 +309,7 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { for (OrderEnumerationHandler handler : myCustomHandlers) { final List urls = new ArrayList(); final boolean added = - handler.addCustomOutput(forModule, orderEntryRootModel, type, mySettings, urls); + handler.addCustomOutput(forModule, orderEntryRootModel, type, this, urls); for (String url : urls) { ContainerUtil.addIfNotNull(VirtualFileManager.getInstance().findFileByUrl(url), result); } @@ -299,7 +322,7 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { boolean addCustomOutputUrls(Module forModule, ModuleRootModel orderEntryRootModel, OrderRootType type, Collection result) { for (OrderEnumerationHandler handler : myCustomHandlers) { - if (handler.addCustomOutput(forModule, orderEntryRootModel, type, mySettings, result)) { + if (handler.addCustomOutput(forModule, orderEntryRootModel, type, this, result)) { return true; } } @@ -309,7 +332,7 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { void addAdditionalRoots(Module forModule, Collection result) { final List urls = new ArrayList(); for (OrderEnumerationHandler handler : myCustomHandlers) { - handler.addAdditionalRoots(forModule, mySettings, urls); + handler.addAdditionalRoots(forModule, this, urls); } for (String url : urls) { ContainerUtil.addIfNotNull(VirtualFileManager.getInstance().findFileByUrl(url), result); @@ -318,10 +341,25 @@ abstract class OrderEnumeratorBase extends OrderEnumerator { void addAdditionalRootsUrls(Module forModule, Collection result) { for (OrderEnumerationHandler handler : myCustomHandlers) { - handler.addAdditionalRoots(forModule, mySettings, result); + handler.addAdditionalRoots(forModule, this, result); } } + @Override + public boolean isRuntimeOnly() { + return myRuntimeOnly; + } + + @Override + public boolean isCompileOnly() { + return myCompileOnly; + } + + @Override + public boolean isProductionOnly() { + return myProductionOnly; + } + public boolean isRootModuleModel(@NotNull ModuleRootModel rootModel) { return false; } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderRootsEnumeratorImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderRootsEnumeratorImpl.java index 390e3db7b094..c1f2dce222aa 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderRootsEnumeratorImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderRootsEnumeratorImpl.java @@ -208,7 +208,7 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator { } private void collectModuleRoots(OrderRootType type, ModuleRootModel rootModel, Collection result) { - final boolean productionOnly = myOrderEnumerator.getSettings().productionOnly; + final boolean productionOnly = myOrderEnumerator.isProductionOnly(); if (type.equals(OrderRootType.SOURCES)) { Collections.addAll(result, rootModel.getSourceRoots(!productionOnly)); } @@ -228,7 +228,7 @@ public class OrderRootsEnumeratorImpl implements OrderRootsEnumerator { } private void collectModuleRootsUrls(OrderRootType type, ModuleRootModel rootModel, Collection result) { - final boolean productionOnly = myOrderEnumerator.getSettings().productionOnly; + final boolean productionOnly = myOrderEnumerator.isProductionOnly(); if (type.equals(OrderRootType.SOURCES)) { Collections.addAll(result, rootModel.getSourceRootUrls(!productionOnly)); } 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 f676d3af0876..05fc05413a96 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 @@ -45,8 +45,8 @@ public class ProjectOrderEnumerator extends OrderEnumeratorBase { @Override public void forEach(@NotNull final Processor processor) { - mySettings.recursively = false; - mySettings.withoutDepModules = true; + myRecursively = false; + myWithoutDepModules = true; final THashSet processed = new THashSet(); processRootModules(new Processor() { @Override diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenOrderEnumeratorHandler.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenOrderEnumeratorHandler.java index 5d73dd11725d..a59b777e6c06 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenOrderEnumeratorHandler.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenOrderEnumeratorHandler.java @@ -78,11 +78,11 @@ public class MavenOrderEnumeratorHandler extends OrderEnumerationHandler { } private boolean shouldAddArtifact(MavenArtifact artifact, OrderEnumeratorSettings settings) { - if (settings.productionOnly) { + if (settings.isProductionOnly()) { String scope = artifact.getScope(); if (scope != null) { - if (settings.compileOnly && MavenConstants.SCOPE_RUNTIME.endsWith(scope)) return false; - if (settings.runtimeOnly && MavenConstants.SCOPE_PROVIDEED.equals(scope)) return false; + if (settings.isCompileOnly() && MavenConstants.SCOPE_RUNTIME.endsWith(scope)) return false; + if (settings.isRuntimeOnly() && MavenConstants.SCOPE_PROVIDEED.equals(scope)) return false; if (MavenConstants.SCOPE_TEST.equals(scope)) return false; } } @@ -142,7 +142,7 @@ public class MavenOrderEnumeratorHandler extends OrderEnumerationHandler { public void addAdditionalRoots(@NotNull Module forModule, @NotNull OrderEnumeratorSettings settings, @NotNull Collection urls) { - if (settings.productionOnly) return; + if (settings.isProductionOnly()) return; MavenProject project = MavenProjectsManager.getInstance(forModule.getProject()).findProject(forModule); if (project == null) return;