Multiple factory methods for the same class
I'm trying to convert a project that was using Dagger 2 to Lightsaber, but I can't figure out how I can create Factory classes that allow multiple combinations of arguments for a single class.
For example, I'd like to do something like this:
@Factory
public abstract static class AnalogHIDButtonTriggerFactory {
public abstract AnalogHIDButtonTrigger create(
XJoystick joystick,
int axisNumber,
@Named("analogMinThreshold") double analogMinThreshold,
@Named("analogMaxThreshold") double analogMaxThreshold);
public final AnalogHIDButtonTrigger create(XJoystick joystick, AnalogHIDDescription desc) {
return create(joystick, desc.axisNumber, desc.analogMinThreshold, desc.analogMaxThreshold);
}
}
@Factory.Inject
public AnalogHIDButtonTrigger(
@Factory.Parameter XJoystick joystick,
@Factory.Parameter int axisNumber,
@Factory.Parameter @Named("analogMinThreshold") double analogMinThreshold,
@Factory.Parameter @Named("analogMaxThreshold") double analogMaxThreshold) {
this(new AnalogHIDButtonConfiguration(joystick, axisNumber, analogMinThreshold, analogMaxThreshold));
}
This results in a compilation error:
Class xbot.common.controls.sensors.buttons.AnalogHIDButtonTrigger contains a @Factory.Parameter not provided by factory xbot.common.controls.sensors.buttons.AnalogHIDButtonTrigger$AnalogHIDButtonTriggerFactory: Dependency(type=int, qualifier=null)
Class xbot.common.controls.sensors.buttons.AnalogHIDButtonTrigger contains a @Factory.Parameter not provided by factory xbot.common.controls.sensors.buttons.AnalogHIDButtonTrigger$AnalogHIDButtonTriggerFactory: Dependency(type=double, qualifier=AnnotationMirror{type = Ljavax/inject/Named;, values = {value=analogMinThreshold}, visible = true})
Class xbot.common.controls.sensors.buttons.AnalogHIDButtonTrigger contains a @Factory.Parameter not provided by factory xbot.common.controls.sensors.buttons.AnalogHIDButtonTrigger$AnalogHIDButtonTriggerFactory: Dependency(type=double, qualifier=AnnotationMirror{type = Ljavax/inject/Named;, values = {value=analogMaxThreshold}, visible = true})
I assume this will also fail because the factory is not an interface. The same error occurs if I convert the factory to an interface with a default implementation for the second method.
Is there a way to tell Lightsaber to ignore the second interface method and only generate code for the first one?
Hi, thanks for the issue. This looks like a bug, and there is no way to override this behaviour at the moment. As you've mentioned this will not work with abstract classes, but should work when we fix this with default interface methods in Java.