Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gissuebot/f062bb7342cfa09080d1 to your computer and use it in GitHub Desktop.
Save gissuebot/f062bb7342cfa09080d1 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 784, comment 0
From 97f9b99dd6a76bc4691b9f4fcc71a828005969c8 Mon Sep 17 00:00:00 2001
From: Tavian Barnes <tavianator@tavianator.com>
Date: Thu, 28 Nov 2013 20:00:36 -0500
Subject: [PATCH] Pass the current Stage into the overridden and overriding
modules in Modules.override().
---
core/src/com/google/inject/util/Modules.java | 4 ++--
.../com/google/inject/util/OverrideModuleTest.java | 22 +++++++++++++++++++++-
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/core/src/com/google/inject/util/Modules.java b/core/src/com/google/inject/util/Modules.java
index adb4ee4..c166b8e 100644
--- a/core/src/com/google/inject/util/Modules.java
+++ b/core/src/com/google/inject/util/Modules.java
@@ -171,7 +171,7 @@ public final class Modules {
@Override
public void configure() {
Binder baseBinder = binder();
- List<Element> baseElements = Elements.getElements(baseModules);
+ List<Element> baseElements = Elements.getElements(currentStage(), baseModules);
// If the sole element was a PrivateElements, we want to override
// the private elements within that -- so refocus our elements
@@ -191,7 +191,7 @@ public final class Modules {
final Binder binder = baseBinder.skipSources(this.getClass());
final LinkedHashSet<Element> elements = new LinkedHashSet<Element>(baseElements);
- final List<Element> overrideElements = Elements.getElements(overrides);
+ final List<Element> overrideElements = Elements.getElements(currentStage(), overrides);
final Set<Key<?>> overriddenKeys = Sets.newHashSet();
final Map<Class<? extends Annotation>, ScopeBinding> overridesScopeAnnotations =
diff --git a/core/test/com/google/inject/util/OverrideModuleTest.java b/core/test/com/google/inject/util/OverrideModuleTest.java
index 8de76aa..3b8e05b 100644
--- a/core/test/com/google/inject/util/OverrideModuleTest.java
+++ b/core/test/com/google/inject/util/OverrideModuleTest.java
@@ -37,6 +37,7 @@ import com.google.inject.Provider;
import com.google.inject.Provides;
import com.google.inject.Scope;
import com.google.inject.ScopeAnnotation;
+import com.google.inject.Stage;
import com.google.inject.name.Named;
import com.google.inject.util.Modules;
@@ -657,5 +658,24 @@ public class OverrideModuleTest extends TestCase {
return new Object();
}
}
-
+
+ public void testCorrectStage() {
+ final Stage stage = Stage.PRODUCTION;
+ Module module = Modules.override(new AbstractModule() {
+ @Override
+ protected void configure() {
+ if (currentStage() != Stage.PRODUCTION) {
+ addError("Wronge stage in overridden module:" + currentStage());
+ }
+ }
+ }).with(new AbstractModule() {
+ @Override
+ protected void configure() {
+ if (currentStage() != Stage.PRODUCTION) {
+ addError("Wronge stage in overriding module:" + currentStage());
+ }
+ }
+ });
+ Guice.createInjector(stage, module);
+ }
}
--
1.8.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment