Skip to content

Commit

Permalink
assistedinject: Skip static methods on interfaces.
Browse files Browse the repository at this point in the history
This fixes google/guice#937.
  • Loading branch information
tavianator committed Jul 6, 2015
1 parent 20f35c0 commit 6c6d041
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
ImmutableMap.Builder<Method, AssistData> assistDataBuilder = ImmutableMap.builder();
// TODO: also grab methods from superinterfaces
for (Method method : factoryRawType.getMethods()) {
// Skip static methods
if (Modifier.isStatic(method.getModifiers())) {
continue;
}

// Skip default methods that java8 may have created.
if (isDefault(method) && (method.isBridge() || method.isSynthetic())) {
// Even synthetic default methods need the return type validation...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public void testAssistedInjection() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(Factory.class));
}
});
Factory factory = injector.getInstance(Factory.class);
assertEquals(1, factory.create(1).i);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Thing create(int i);

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
static Factory getDefault() {
return Thing::new;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@Inject
Thing(@Assisted int i) {
this.i = i;
}

0 comments on commit 6c6d041

Please sign in to comment.