Skip to content

Commit

Permalink
Merge pull request #365 from Netflix/useToolStageForElementVisitors
Browse files Browse the repository at this point in the history
always use Stage.TOOL when using ElementVisitors for inspection of bi…
  • Loading branch information
twicksell authored May 15, 2017
2 parents 375dc4e + 3682f28 commit 75e5594
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.slf4j.LoggerFactory;

import com.google.inject.Module;
import com.google.inject.Stage;
import com.google.inject.spi.Element;
import com.google.inject.spi.Elements;
import com.netflix.governator.spi.ModuleListTransformer;
Expand All @@ -15,7 +16,7 @@ public class BindingLoggingModuleTransformer implements ModuleListTransformer {

@Override
public List<Module> transform(List<Module> modules) {
for (Element binding : Elements.getElements(modules)) {
for (Element binding : Elements.getElements(Stage.TOOL, modules)) {
LOG.debug("Binding : {}", binding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public InjectorBuilder map(ModuleTransformer transformer) {
*/
public InjectorBuilder filter(ElementVisitor<Boolean> predicate) {
List<Element> elements = new ArrayList<Element>();
for (Element element : Elements.getElements(module)) {
for (Element element : Elements.getElements(Stage.TOOL, module)) {
if (element.acceptVisitor(predicate)) {
elements.add(element);
}
Expand All @@ -192,7 +192,7 @@ public InjectorBuilder stripStaticInjections() {
* @return Return all elements in the managed module
*/
public List<Element> getElements() {
return Elements.getElements(module);
return Elements.getElements(Stage.TOOL, module);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.inject.Module;
import com.google.inject.Stage;
import com.google.inject.spi.DefaultElementVisitor;
import com.google.inject.spi.Element;
import com.google.inject.spi.Elements;
Expand All @@ -16,7 +17,7 @@ public class StripStaticInjections implements ModuleTransformer {
@Override
public Collection<Module> call(Collection<Module> modules) {
final List<Element> noStatics = Lists.newArrayList();
for(Element element : Elements.getElements(modules)) {
for(Element element : Elements.getElements(Stage.TOOL, modules)) {
element.acceptVisitor(new DefaultElementVisitor<Void>() {
@Override
public Void visit(StaticInjectionRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.slf4j.LoggerFactory;

import com.google.inject.Module;
import com.google.inject.Stage;
import com.google.inject.spi.DefaultElementVisitor;
import com.google.inject.spi.Element;
import com.google.inject.spi.Elements;
Expand All @@ -17,7 +18,7 @@ public class WarnAboutStaticInjections implements ModuleTransformer {

@Override
public Collection<Module> call(Collection<Module> modules) {
for(Element element : Elements.getElements(modules)) {
for(Element element : Elements.getElements(Stage.TOOL, modules)) {
element.acceptVisitor(new DefaultElementVisitor<Void>() {
@Override
public Void visit(StaticInjectionRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Stage;
import com.google.inject.TypeLiteral;
import com.google.inject.binder.AnnotatedBindingBuilder;
import com.google.inject.binder.LinkedBindingBuilder;
Expand Down Expand Up @@ -59,7 +60,7 @@ public AnnotationBasedTestInjectorManager(Class<?> classUnderTest, Class<? exten
this.mockHandler = createMockHandlerForTestClass(classUnderTest, defaultMockHandlerClass);
inspectModulesForTestClass(classUnderTest);
inspectMocksForTestClass(classUnderTest);
inspectSpiesForTargetKeys(Elements.getElements(modulesForTestClass));
inspectSpiesForTargetKeys(Elements.getElements(Stage.TOOL, modulesForTestClass));
overrideModules.add(new ArchaiusTestConfigOverrideModule(classLevelOverrides, methodLevelOverrides));
}

Expand Down

0 comments on commit 75e5594

Please sign in to comment.