arXiv:2504.10412cs.AIcs.LG2025-04被引 7

用图神经网络分析代码结构,自动优化可维护性。

AI-Driven Code Refactoring: Using Graph Neural Networks to Enhance Software Maintainability

  • 将代码转为抽象语法树,用图神经网络识别重构点
  • 降低35%复杂度、33%耦合度,准确率达92%
  • 适合希望自动化提升代码质量的开发团队

本研究探索图神经网络(GNNs)作为代码重构的变革性工具,利用抽象语法树(ASTs)提升软件可维护性。基于来自CodeSearchNet的200万代码片段及自建的7.5万文件GitHub Python语料库,对比GNN与基于规则的SonarQube和决策树方法。评估指标包括环路复杂度(目标低于10)、耦合度(目标低于5)和重构精度。GNN达到92%准确率,使复杂度降低35%,耦合度下降33%,优于SonarQube(78%,16%)和决策树(85%,25%)。预处理修复了60%的语法错误。柱状图、表格和AST可视化清晰呈现结果。该方法为构建更清洁代码库提供了可扩展的AI路径,对软件工程至关重要。

原文摘要 · Abstract (English)

This study explores Graph Neural Networks (GNNs) as a transformative tool for code refactoring, using abstract syntax trees (ASTs) to boost software maintainability. It analyzes a dataset of 2 million snippets from CodeSearchNet and a custom 75000-file GitHub Python corpus, comparing GNNs against rule-based SonarQube and decision trees. Metrics include cyclomatic complexity (target below 10), coupling (target below 5), and refactoring precision. GNNs achieve 92% accuracy, reducing complexity by 35% and coupling by 33%, outperforming SonarQube (78%, 16%) and decision trees (85%, 25%). Preprocessing fixed 60% of syntax errors. Bar graphs, tables, and AST visuals clarify results. This offers a scalable AI-driven path to cleaner codebases, which is crucial for software engineering.

代码重构图神经网络可维护性

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。