openrewrite / openrewrite/rewrite

Support IntelliJ `@Contract` annotation for `Expression#getSideEffects()`

Open
#2,744 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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 (via EmptyBlockVisitor)
  • SimplifyConstantIfBranchExecution (via EmptyBlockVisitor)
  • InstanceOfPatternMatch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.