Skip to content

Emods ijmodified#155

Open
glelouet wants to merge 6 commits into
phax:masterfrom
glelouet:emods_ijmodified
Open

Emods ijmodified#155
glelouet wants to merge 6 commits into
phax:masterfrom
glelouet:emods_ijmodified

Conversation

@glelouet
Copy link
Copy Markdown
Contributor

@glelouet glelouet commented Jun 5, 2026

step forward in the effort to add modern-ish (come on, enumset are soo 2000 ) code. No removal, just adding simpler methods to do the same thing.

  1. added the IJModified interface in modifiers/. Allows to access the Emods with add, remove, list methods
  2. sameish methods implemented in JMods (except addEmods requires allowed set)
  3. AbstractJClassContainer extends IJModified
  4. JDefined class implements it by delegating to its jmods, checking for interface/class allowed emods
  5. JDirectClass implements it by doing nothing
  6. JVar implements IJModified
  7. JFieldVar overrides the addemods to use allowed fields emods instead ; and to return JFieldVar instead of a JVar :P
  8. JMethod implements IJModified

The new addEmod method automatically discards invalid modifiers (like public for a local variable) and removes the ones excluded by those added :

Typically calling

jmethod.addEmods(EMod.PUBLIC,  EMod.SEALED, EMod.PROTECTED)

Will result in the jmethod having PROTECTED modifier, with PRIVATE and PUBLIC removed if they were present ; the addition of SEALED is discarded, other existing modifiers are kept.

side note : final and volatile should also be in the list of mutual exclusion. The code style wrecks if I add them so I opt out (I added them, then realized there was too many changes so reverted the project and did it again. Took me 1h to try to fix it, before I gave up).
This means a variable should be removed volatile when set to final (which has no effect since vars can't be volatile ) ; and same for a field (which allows both, so effect)

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

Successfully merging this pull request may close these issues.

1 participant