rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

InlineOneTimeUsageVariable

Open Pankraz76 opened this issue 1 year ago • 1 comments

Please complete the InlineVariable function where it stops. While this is the intended behavior, it also misaligns the true indentation

make new one: InlineOneTimeUsagesVariable

BEFORE

class A {
    public int calculateArea() {
        int length = 1;
        int width = 2;
        int area = length + width; // Area calculation
        return area;
    }
}

InlineOneTimeUsageVariable / InlineAllVariable

class A {
    public int calculateAreaImproved() {
        return 1 + 2; // Length and width inlined
    }
}

InlineVariable this is actually more something like InlineImmediateVariable

class A {
    public int calculateArea() {
        int length = 1;
        int width = 2;
        return length + width; // Area calculation
    }
}

Code Examples

Here are some examples demonstrating these principles:

const calculateArea = () => {
    const length = 1; 
    const width = 2; 
    const area = length + width; 
    return area; 
};
// here is where the InlineVariable stops which is the intend but also kind of stupid
const calculateAreaWithParams = () => {
    const length = 1; 
    const width = 2; 
    return length + width; 
};

const calculateAreaInline = () => {
    return 1 + 2; 
};

Pankraz76 avatar Oct 14 '24 05:10 Pankraz76

  • https://github.com/openrewrite/rewrite-static-analysis/pull/367

Pankraz76 avatar Oct 14 '24 14:10 Pankraz76

Partly this has already been achieved through

  • https://github.com/openrewrite/rewrite-static-analysis/pull/647

I don't see us extending this to inline just any variable that's used once, as readability would suffer. With that we can close this issue.

timtebeek avatar Jul 26 '25 17:07 timtebeek