openrewrite / openrewrite/rewrite
Support IntelliJ `@Contract` annotation for `Expression#getSideEffects()`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 571
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
The MethodInvocation#getSideEffects() implementation currently always returns a list containing itself, even though the called method may not have any side effects. For this and other purposes IntelliJ has its @Contract annotation and using its external annotations feature they have annotated the JDK classes: https://github.com/JetBrains/intellij-community/tree/master/java/jdkAnnotations
OpenRewrite could load and use these external annotations when assessing whether a method invocation of a JDK method has side effects or not.
Note: Currently Expression#getSideEffects() is used by the following recipes:
EmptyBlock(viaEmptyBlockVisitor)SimplifyConstantIfBranchExecution(viaEmptyBlockVisitor)InstanceOfPatternMatch
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Expression#getSideEffects() and the MethodInvocation#getSideEffects() implementation, then review how EmptyBlock, SimplifyConstantIfBranchExecution, and InstanceOfPatternMatch use the result. Compare the desired behavior with IntelliJ’s @Contract and external-annotation documentation. Done means JDK method invocations use those annotations when assessing side effects without breaking the listed recipes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100