Skip to content

Very minor suggestion: don't generate private delegate field if it's not used #1519

Description

@rwalkerands

I'm using 1.2.0.Final.

I've got a case where I have a very simple mapper interface with a corresponding decorator class written in the "standard" style (i.e., with a constructor that takes a delegate parameter) where I get a generated ...Impl.java and a ...Impl_.java. The ...Impl.java file looks like this:

package au.org.ands.vocabs.registry.db.converter;

import javax.annotation.Generated;

@Generated(

    value = "org.mapstruct.ap.MappingProcessor",

    date = "2018-06-12T10:27:48+1000",

    comments = "version: 1.1.0.Final, compiler: Eclipse JDT (IDE) 1.3.110.v20180329-0935, environment: Java 1.8.0_144 (Oracle Corporation)"

)

public class SubscriptionDbSchemaMapperImpl extends SubscriptionDbSchemaMapperDecorator implements SubscriptionDbSchemaMapper {

    private final SubscriptionDbSchemaMapper delegate;

    public SubscriptionDbSchemaMapperImpl() {

        this( new SubscriptionDbSchemaMapperImpl_() );
    }

    private SubscriptionDbSchemaMapperImpl(SubscriptionDbSchemaMapperImpl_ delegate) {

        super( delegate );

        this.delegate = delegate;
    }
}

It works perfectly, but Eclipse gives me this warning for line 17 (the definition of the field delegate):

The value of the field SubscriptionDbSchemaMapperImpl.delegate is not used

Indeed, in this case it isn't.

(I have some other more "interesting" mapper interfaces that give a generated ...Impl.java file that has other methods that use delegate, and for which I therefore don't get a warning from Eclipse.)

So a very minor suggestion: don't generate the private field if it isn't needed.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions