Skip to content

Implied qualifier name for constructor paramters takes [suffix] type name into account #144

@rbygrave

Description

@rbygrave

Scenario

For implied names for constructor parameters if we have a variable name that has a suffix that matches the type. In the example below otherPEmailer has the suffix of the type PEmailer.

In the case like:

  public Foo(PEmailer otherPEmailer) {
    ...
  }

Currently the implied name for this is !otherPEmailer

The expected implied name should be !other

It should be !other to make the constructor implied name consistent with the implied name that occurs when concrete @Singleton implement an interface or abstract type and have a similar naming convention.

That is, according to the TCK tests if we have an interface PEmailer and we have a @Singleton implementation called OtherPEmailer that does not have an explicit name it gets an implicit name of other (due to the type name having a suffix of the interface type.

Test case

@Singleton
public class UseNamedPEmailer {
  ...
  public UseNamedPEmailer(@Named("Other") PEmailer emailer, PEmailer other, PEmailer otherPEmailer) {
    ...
  }
 ...

The 3 constructor parameters are expected to have qualifier names of:

  1. Other - because it has this explicitly stated
  2. !other - implied name with no 'type suffix match'
  3. !other - because otherPEmailer has the type suffix PEmailer

The expected generated injection code is:

  /**
   * Create and register UseNamedPEmailer.
   */
  public static void build(Builder builder) {
    if (builder.isAddBeanFor(UseNamedPEmailer.class)) {
      UseNamedPEmailer bean = new UseNamedPEmailer(builder.get(PEmailer.class,"other"), builder.get(PEmailer.class,"!other"), builder.get(PEmailer.class,"!other"));
      builder.register(bean);
    }
  }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions