Skip to content

Gizmo2: consider the default flags for classes and members #222

@mkouba

Description

@mkouba

I agree that the defaults should just follow the JLS. But in Gizmo1 the defaults differ. For example, the MethodCreator produces public methods by default, fields are private (unless declared on an interface), etc. In some cases, it's more convenient. By the way, even in Gizmo2 the generated class is public by default, and not package private.

I wonder if we should stick with the same rules to ease the migration, or maybe introduce something like "default flag profiles"?

public interface AccessFlagProfile {
    public Collection<AccessFlag> methodFlags();
}

public class PublicFinalMethods implements AccessFlagProfile {
   public Collection<AccessFlag> methodFlags() {
      return List.of(AccessFlag.PUBLIC, AccessFlag.FINAL);
   }
}

g.class_(ClassDesc.of("org.acme.Foo"), cc -> {
   cc.withAccessFlagProfile(new PublicFinalMethods()); // all methods will be "public final" by default
}

And have some predefined profiles... like GIZMO1.

Maybe I'm wrong. I'm just throwing ideas...

Metadata

Metadata

Assignees

Labels

2.xIssue applies to Gizmo 2.xquestionFurther information is requested

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions