Source Code Expansion for Automated Refactoring

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Manually transforming source code without changing its semantics is challenging, and automated tools face difficulties in correctly refactoring code due to its context-dependent nature, often resulting in errors and over-complicated implementations.

Innovation Solution

An automated programming tool that expands source code by inserting typecasts, fully-qualifying identifiers, and enclosing expressions in parentheses to ensure correct parsing, followed by refactoring and subsequent reduction of expanded code to maintain original coding preferences.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If automated refactoring tools are used to transform source code, then productivity is improved, but reliability deteriorates due to context-dependent errors

Engineering Contradiction:
Improverefactoring efficiencyVSAvoidrefactoring correctness
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The patent applies preliminary action by expanding the source code before refactoring. The expansion phase adds necessary type information, fully-qualified identifiers, and parentheses around expressions before the refactoring operation is performed. This preliminary expansion ensures that the refactoring tool has complete context information to perform transformations correctly, thereby improving reliability while maintaining productivity.

Inventive Principle:
Principle #10Preliminary action

2Reliability

If source code is expanded with typecasts and fully-qualified identifiers to improve refactoring accuracy, then reliability is improved, but device complexity increases

Engineering Contradiction:
Improverefactoring correctnessVSAvoidcode expansion complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent segments the refactoring process into distinct phases: an expansion phase that adds type information and qualifiers, a refactoring phase that performs the transformation, and a reduction phase that removes unnecessary expansions. This segmentation allows each phase to focus on specific tasks, managing complexity systematically while improving overall reliability.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The expanded source code acts as an intermediary representation between the original code and the refactored code. By introducing typecasts, fully-qualified identifiers, and parentheses as intermediary elements, the system creates a bridge that enables accurate refactoring while keeping the original code intact. The intermediary expansion layer absorbs the complexity of context-dependent transformations.

Inventive Principle:
Principle #24Intermediary (Mediator)

3Ease of operation

If simple replace-all operations are used for variable renaming, then ease of operation is improved, but reliability deteriorates due to incorrect variable substitution

Engineering Contradiction:
Improverefactoring simplicityVSAvoidvariable substitution correctness
Core Design Contradiction:
Ease of operationVSReliability

Solution Approach 1:

Before performing simple replace-all operations, the system performs preliminary expansion to add fully-qualified identifiers and type information to variable declarations. This preliminary action provides the refactoring tool with unambiguous context about which variables should be renamed and which should not, allowing simple replacement operations to become reliable.

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS9182980B2Expansion and reduction of source code for code refactoring
Publication Date: 2015.11.10 MICROSOFT TECHNOLOGY LICENSING LLC
  • US9182980B2 patent drawing
  • US9182980B2 patent drawing
  • US9182980B2 patent drawing

AI summary

An automated programming tool can receive program source code and can expand portions of the program source code to make to make identifiers explicit, insert sets of parenthesis and so on. Expansions can be kept track of so that reductions after refactoring can be confined to altered portions of the program source code.