ValExtractor: Reliable Automated Local Variable Extraction in Code Refactoring
-
Abstract
Extracting local variable is a well-known and widely used refactoring technique designed to enhance code readability by replacing complex expressions with simpler variable references. Although most integrated development environments (IDEs) provide tool support for such refactoring, these tools often result in semantic errors due to a lack of in-depth analysis. To overcome these limitations, we present ValExtractor, a novel and reliable approach for reliable automated variable extraction. The key challenge involves accurately and efficiently identifying the side effects of extracted expressions and their potential interactions with the surrounding context, without resorting to time-consuming dynamic execution. ValExtractor employs lightweight static source code analysis to validate the side effects of selected expressions and determine which instances of the expressions can be extracted together without altering program semantics or introducing new potential exceptions. Our evaluation demonstrates that mainstream refactoring engines, such as those in Eclipse and IntelliJ IDEA, frequently generate incorrect variable extractions, whereas ValExtractor successfully avoids these errors. The algorithm and its implementation have been integrated into Eclipse, serving over 3 million global Eclipse users.
-
-