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

implementation type not visible when using @Criteria and ImplementationVisibility.PACKAGE #1501

Open
rgatbert opened this issue Jan 15, 2024 · 0 comments

Comments

@rgatbert
Copy link

rgatbert commented Jan 15, 2024

src.zip

I use an own style annotation with the goal of using only interfaces and hiding the immutables implementation package private:

package com.sandbox.model;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.immutables.value.Value;
import org.immutables.value.Value.Style.ImplementationVisibility;

@Target({ ElementType.PACKAGE, ElementType.TYPE })
@Retention(RetentionPolicy.CLASS)

@Value.Style(
    allowedClasspathAnnotations = {
        java.lang.Override.class
    },
    depluralize = true,
    depluralizeDictionary = {
        "address:addresses",
        "axis:axes",
        "analysis:analyses",
        "child:children",
        "criterion:criteria",
        "focus:focuses",
        "index:indices",
        "index:indexes",
        "party:parties",
        "person:people",
        "radius:radiuses"
    },
    get = {
        "get*",
        "has*",
        "is*"
    },
    jacksonIntegration = true,
    jakarta = true,
    jdkOnly = true,
    optionalAcceptNullable = true,
    overshadowImplementation = true,
    typeAbstract = "",
    typeImmutable = "Immutable*",
    visibility = ImplementationVisibility.PACKAGE)
public @interface MyStyle {
}

I have a base class in a common package:

package com.sandbox.model.common;

import org.immutables.value.Value;

import com.sandbox.model.MyStyle;

@Value.Immutable
@MyStyle
public interface UserId {

  class Builder extends ImmutableUserId.Builder {
  }

  @Value.Parameter
  String getDomainName();

  @Value.Parameter
  String getDomainUserName();
}

And another class referencing this in a app package combined with @criteria:

package com.sandbox.model.app;

import org.immutables.criteria.Criteria;
import org.immutables.value.Value;

import com.sandbox.model.MyStyle;
import com.sandbox.model.common.UserId;

@Value.Immutable
@MyStyle
@Criteria
public interface User {

  class Builder extends ImmutableUser.Builder {
  }

  UserId getId();

  String getFullName();
}

When in User class @criteria is used, parts of the implementation will be generated with compile errors "the type ImmutableUserId is not visible" what is true. E.g.:

    public final User.Builder id(UserId id) {
      this.id = ImmutableUserId.copyOf(id);
      initBits &= ~INIT_BIT_ID;
      return (User.Builder) this;
    }

When I omit @criteria, this part is generated differently without compile error:

    public final User.Builder id(UserId id) {
      this.id = Objects.requireNonNull(id, "id");
      initBits &= ~INIT_BIT_ID;
      return (User.Builder) this;
    }

So there are some questions ahead:

  1. Is this a bug?
  2. Have I forgotten something?
  3. A way/workaround to use @criteria and hide all immutables implementations package private?
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

1 participant