Skip to content

Multiple factory methods for the same class #27

Description

@stephenjust

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions