Long Method Autofix Engine for Accurate Code Refactoring

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing software development tools struggle to accurately and efficiently identify and refactor long methods in code, leading to inefficiencies and increased maintenance costs due to false positives and the inability to automate the refactoring process.

Innovation Solution

A system and methodology using a long method autofix engine that employs machine learning and natural language processing to automatically identify and prioritize overlong code segments, applying block and variable-based extraction algorithms to split them into smaller, semantically equivalent methods.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Ease of manufacture

If existing IDE refactoring tools use a single line count threshold to identify long methods, then the identification process is simple, but the results contain numerous false positives and are non-actionable

Engineering Contradiction:
Improvesimplicity of identification processVSAvoidaccuracy of long method identification
Core Design Contradiction:
Ease of manufactureVSMeasurement precision

Solution Approach 1:

The patent changes the identification parameters from a single line count threshold to multiple dimensions including effective line count (excluding blanks and comments), cyclomatic complexity, and nesting depth. This multi-parameter approach allows for more precise identification of truly problematic long methods while filtering out false positives.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The patent implements dynamic threshold adjustment based on method characteristics. Instead of using a fixed threshold, the system adapts the threshold based on the method's complexity, nesting level, and other metrics, allowing the identification criteria to change dynamically according to the specific context of each method.

Inventive Principle:
Principle #15Dynamics

2Manufacturing precision

If developers manually extract code segments to fix long methods, then the refactoring can be precise, but the process requires considerable time and effort

Engineering Contradiction:
Improveprecision of code extractionVSAvoidtime required for refactoring
Core Design Contradiction:
Manufacturing precisionVSLoss of time

Solution Approach 1:

The patent enables the system to automatically perform the refactoring process without human intervention. The automated extraction service analyzes the code, identifies extractable segments, creates new methods, and updates references automatically, allowing the system to service itself rather than requiring manual developer effort.

Inventive Principle:
Principle #25Self-service

Solution Approach 2:

The patent performs preliminary analysis to pre-identify extractable code segments and their optimal extraction points before the actual refactoring occurs. By preparing extraction candidates in advance and analyzing dependencies beforehand, the system reduces the time required for the actual refactoring execution.

Inventive Principle:
Principle #10Preliminary action

3Reliability

If existing tools flag all methods exceeding a threshold as overlong, then the identification is comprehensive, but the large number of results makes them non-actionable

Engineering Contradiction:
Improvecompleteness of identificationVSAvoidactionability of results
Core Design Contradiction:
ReliabilityVSEase of operation

Solution Approach 1:

The patent applies different identification criteria and thresholds to different contexts and locations in the codebase. Instead of treating all methods uniformly, the system considers local factors such as class size, method position, and surrounding code structure to determine whether a method should be flagged, making the results more actionable by focusing on truly problematic cases.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent intentionally applies stricter identification criteria than a simple threshold would suggest, potentially missing some edge cases, but this ensures that only the most clearly problematic long methods are flagged. This partial action approach prioritizes precision over completeness, making the results more actionable.

Inventive Principle:
Principle #16Partial or excessive action

4Productivity

If automated refactoring tools are implemented, then productivity increases, but the device complexity increases

Engineering Contradiction:
Improverefactoring speedVSAvoidcomplexity of refactoring system
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The patent divides the complex refactoring system into separate modular services: an identification service that detects long methods, an extraction service that performs the actual refactoring, and a reference update service that maintains code consistency. This segmentation allows each component to be developed and maintained independently, managing overall system complexity while maintaining high productivity.

Inventive Principle:
Principle #1Segmentation

Data Source

PatentUS12481486B2Long method autofix engine
Publication Date: 2025.11.25 DEVFACTORY INNOVATIONS FZ LLC
  • US12481486B2 patent drawing
  • US12481486B2 patent drawing
  • US12481486B2 patent drawing

AI summary

A method and apparatus are disclosed for eliminating overlong source code segments (e.g., methods) by evaluating input source code segments for a plurality of predetermined code metric values to identify a first long code segment based on predetermined code metric values for output and storage in a codefix issue queue, applying multiple extraction algorithms to the first long code segment to generate a second code segment that is semantically equivalent to and shorter than the first long code segment; and then generating a fixed codegraph representation of the software program using the second code segment to replace the first long code segment.