Skip to content

A mix of naming strategy #389

@dmlloyd

Description

@dmlloyd

Issue description

We have a mix of naming strategies for mutator methods, due to the original intent of extending the classfile API rather than hiding it (and thus more or less imitating its idioms).

In some cases, thing.withXxx will modify thing by adding or changing one of its properties. In other cases, thing.withXxx returns a new Thing with the added or changed property.

I propose that we adopt this mutator naming strategy:

  • Methods which change something should be called setSomething(newSomething) (like fc.setAccess(PUBLIC)
  • Methods which add something to an existing object should be called addXxxx(xc -> { ... }) (like zc.addField(fc -> { ... })
  • Methods which remove something from an existing object should be called removeSomething(something) (like fc.removeModifier(TRANSIENT))
  • Methods which return a new thing with the transformed property should be Thing newThing = thing.with(newProperty); (like Gizmo#withOutput and probably the solution for Gizmo2: consider the default flags for classes and members #222 as well)

WDYT?

Metadata

Metadata

Assignees

Labels

2.xIssue applies to Gizmo 2.x

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions