Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@InjectAnnotation with custom immutable annotation not recognized #912

Open
m0rtalis opened this issue Feb 5, 2019 · 1 comment
Open

Comments

@m0rtalis
Copy link

m0rtalis commented Feb 5, 2019

The @InjectAnnotation is not considered when a custom immutable annotation is annotated with it.
As Example

InjectAnnotation:

@InjectAnnotation(type = PersistenceConstructor.class, target = InjectAnnotation.Where.CONSTRUCTOR)
// @Inherited // This has no effect
public @interface PersistenceConstructorInjected {
}

Custom immutable annotation:

@Value.Style(strictBuilder = true, of = "new", allParameters = true)
@PersistenceConstructorInjected
public @interface MyImmutable {
}

Abstract class

@MyImmutable
public abstract class SomeClass{
  public abstract String getValue();
}

Generated immutable:

@Generated(from = "SomeClass", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableSomeClass extends SomeClass {
  private final String value;

  /**
   * Construct a new immutable {@code SomeClass} instance.
   * @param value The value for the {@code value} attribute
   */
  public ImmutableSomeClass(String value) {
    this.value = Objects.requireNonNull(value, "value");
  }

  private ImmutableSomeClass(ImmutableSomeClass original, String value) {
    this.value = value;
  }

  /**
   * @return The value of the {@code value} attribute
   */
  @Override
  public String getValue() {
    return value;
  }
  // Some other stuff
}

I would expect the constructor public ImmutableSomeClass(String value) {..} to be annotated with @PersistenceConstructor. But this only happens if SomeClass is annotated with @PersistenceConstructorInjected.

Is this not supported or am I doing something wrong?

@elucash
Copy link
Member

elucash commented Mar 15, 2019

thank you for raising this! sorry for the very late response. IIRC annotation injection does not work as a meta-annotation and not quite like a style annotation. But to save some typing it can be placed on a enclosing package (using package-info.java etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants