[PiranhaJava] Does not remove Java enum constants with fields matching flag value
See original GitHub issueSo let’s say I have an enum with some code like this:
public enum TestExperimentName {
STALE_FLAG("stale.flag"),
OTHER_FLAG("other.flag");
private final String key;
TestExperimentName(final String key) {
this.key = key;
}
}
Running Piranha with -XepOpt:Piranha:FlagName=stale.flag
won’t remove the STALE_FLAG
constant from the enum (and therefore will also not remove downstream usages).
I have been working on a fix for this, as my organization uses feature flags in this way. Still waiting on legal approval before I can share any code with y’all, however. And AFAIK, it will require its own pass and my current implementation has its own BugChecker implementation.
Would love to know if the maintainers of the Piranha project believe this is out of scope or not for Piranha. While I’d rather contribute to this back upstream to the project, I can see it being arguably made to be in its own project to be run prior to running Piranha, as it is a use case quite possibly specific to my organization’s needs.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Hmm… I suppose if we can do a look up for every enum’s String field values or constructor when Piranha encounters that enum being used, it would be possible to do in one pass. Let me see what kind of tools I can use from Error Prone to traverse the AST and I’ll get back to y’all with a PR with a new option in the
properties.json
for this. And it looks like legal just approved me for code sharing 😃Really appreciate the replies @lazaroclapp and @mkr-plse !
+1. Let us add it as part of the same EP pass (if necessary, under an option). Some locations to consider updating: