openrewrite / openrewrite/rewrite-static-analysis

Recipe: `static` member should be accessed via `class` reference instead of `instance` reference

Open
#74 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

Before :

class Hello(){

       public static String world = "WORLD";
        public static void helloWorld(){

        }

        public void main(String[] args){
            Hello hello = new Hello();
            hello.helloWorld();
           String world = hello.world;
        }
    }

After :

class Hello(){


        public static void helloWorld(){

        }

        public void main(String[] args){
            Hello.helloWorld();
           String world = Hello.world;
        }
    }

In this example, the instance is not needed after this rewrite, but I am not sure if we want to include that as part of this recipe or just delegate it to RemoveUnusedLocalVariables

org.openrewrite.java.ChangeMethodTargetToStatic is similar to this, but it needs configuration and it does not seem to be the same

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 by comparing the proposed behavior with org.openrewrite.java.ChangeMethodTargetToStatic and read RemoveUnusedLocalVariables at rewrite-java/src/main/java/org/openrewrite/java/cleanup/RemoveUnusedLocalVariables.java. Define the recipe's scope for replacing instance references to static methods and fields, including whether removing the now-unused instance is part of the work. Done means the agreed rewrite behavior is represented as a new static-analysis recipe.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.