Single Method Interfaces, AbstractFactories, constructor references and intellij findability
Hi all,
We are doing this pattern a ton lately:
public ConcreteThing implements Thing {
public ConcreteThing(String arg1, Long arg2, DependentClass arg3) {
// ...
}
}
Then I need an AbstractFactory:
public ThingCreator {
Thing makeIt(String arg1, Long arg2, DependentClass arg3);
}
So we have YET another class that needs to build "Thing"s on demand, so it needs a ThingCreator:
public IUseThings {
public IUseThings(ThingCreator factory) {
this.factory = factory;
}
private Thing makeAthing() {
return factory.makeIt(arg1, arg2, arg3);
}
}
Ok so in Java8 we can do this:
IUseThings usingThings = new IUseThings(ConcreteThing::new);
and dang that just seems SO slick! In Unit tests of IUseThings I can mock up ThingCreator and keep my tests nice and unit-y.
But findability in IntelliJ suffers quite a bit here! Show class hiearchy, goto-implementation, find usages all will show me who the CLIENTS of ThingCreator are (eg: IUseThings, and IUseThingsTest) but I can't find the "ConcreteThing::new" implementation. At least if i do find-usages on the ConcreteThing constructor it shows up.
I'm wondering if there is some way to make the findability better - do I have to resort to making stub factory classes?
Please sign in to leave a comment.
IDEA 13.1.3 EAP contains ability to find method references/lambdas by functional interfaces, hierarchy view, show definitions should also work. Please give it a try!
Thanks,
Anna