Uppsats

Integrating Static Analysis and LLMs to Refactor ComplexMethods

Kandidat-uppsats

Mittuniversitetet/Institutionen för kommunikation, kvalitetsteknik och informationssystem (2023-)

Publicerad: 2025

Språk: Engelska

Sammanfattning

Code complexity significantly affects the readability andmaintainability of large-scale software systems. Refactoringis a common practice to address this, and recentadvancements in Large Language Models (LLMs) showpromise for automating the process. However, purely LLMbased refactoring often introduces errors or fails to addressspecific complexity issues. To mitigate such problems,hybrid approaches that combine static analysis with LLMshave been proposed, yet their effectiveness for complexityfocused refactoring remains underexplored. This studyevaluates PMD-LLM-Refactor, a hybrid approach integratingstatic complexity analysis with LLM-driven refactoring,specifically targeting method-level code complexity. Weempirically compared it against an LLM-only baseline usingthree models (DeepSeek-R1 Distill Qwen 32B, Gemini 2.0Flash, Llama 4 Maverick) across 45 methods from five opensource Java projects. The comparison evaluated fourstructural complexity metrics (Cyclomatic, Cognitive, NPath,and Method Length) and verified functional correctnessthrough existing unit tests. The hybrid approachoutperformed the LLM-only baseline, yielding more effectiverefactorings, a higher average complexity reduction acrossall metrics (58.8% vs. 51.7%), and lower variability. However,no statistically significant performance difference wasobserved among the three LLMs within the hybridconfiguration. The findings suggest that combining staticanalysis with LLMs improves the precision, consistency, andoverall effectiveness of automated method-level refactoringto reduce code complexity. The structured guidance enablesLLMs to perform more targeted transformations while alsomitigating common failure modes such as syntax errors andhallucinated code.

Information

Lärosäte / institution
Mittuniversitetet/Institutionen för kommunikation, kvalitetsteknik och informationssystem (2023-)
Publiceringsdatum
2025
Uppsatstyp
Kandidat-uppsats
Språk
Engelska

Utforska vidare

Liknande uppsatser

Uppsatser med liknande ämnen och nyckelord.