RefactoringMiner icon indicating copy to clipboard operation
RefactoringMiner copied to clipboard

Missing Inline Variable refactoring

Open onewhl opened this issue 4 years ago • 1 comments

Hello! I noticed that RefactoringMiner doesn't detect Inline Variable refactoring at the following code changes:

Before:

public String getName() {
        String name = "A";
        return name;
}

After:

public String getName() {
        return "A";
 }   

RefactoringMiner version: 2.0.3

onewhl avatar Feb 04 '21 11:02 onewhl

In this case String name = "A"; is matched with return "A"; instead of return name; -> return "A"; + Inline Variable String name = "A";

A similar scenario for Extract Variable holds in case https://github.com/javaparser/javaparser/commit/427dd53b9ebedcb0bdb687007eb0faf2de734df4#diff-d4545a64b742a6d7b072135d10643c1d309ecaa62daa9450ba05dc68985543aaR477 where final VariableDeclarator variableDeclarator = (VariableDeclarator)type.getParentNode().get(); is matched with Node parent = type.getParentNode().get(); instead of final VariableDeclarator variableDeclarator = (VariableDeclarator)type.getParentNode().get(); -> final VariableDeclarator variableDeclarator = (VariableDeclarator) parent; + Extract Variable Node parent = type.getParentNode().get();

tsantalis avatar Aug 01 '22 14:08 tsantalis

@onewhl This old issue is fixed.

Screenshot from 2023-08-01 17-01-37

Screenshot from 2023-08-01 08-22-07

tsantalis avatar Aug 01 '23 21:08 tsantalis