Code generation tools are essential to help developers in the software development process. Existing tools often disconnect with the working context, i.e., the code repository, causing the generated code to be not similar to human developers. In this paper, we propose a novel code generation framework, dubbed \textbf{$A^3$}-CodGen, to harness information within the code repository to generate code with fewer logical errors, code redundancy, and library-related compatibility issues. We identify three categories of representative information for the code repository: local-aware information from current code file, global-aware information from other code files, and third-party-library information. Results demonstrate that by adopting the \textbf{$A^3$}-CodGen framework, we successfully extract, fuse, and feed code repository information into the LLM, generating more accurate, efficient, and highly reusable code. The effectiveness of our framework is further underscored by generating code with a higher reuse rate, compared to human developers. This research contributes significantly to the field of code generation, providing developers with a more powerful tool to address the evolving demands in software development in practice.
翻译:代码生成工具对于辅助开发者完成软件开发过程至关重要。现有工具常与工作上下文(即代码仓库)脱节,导致生成代码与人类开发者编写的代码存在差异。本文提出一种新型代码生成框架\textbf{$A^3$}-CodGen,通过利用代码仓库中的信息生成具有更少逻辑错误、代码冗余及库相关兼容性问题的代码。我们识别出代码仓库中三类代表性信息:当前代码文件中的局部感知信息、其他代码文件中的全局感知信息以及第三方库信息。实验结果表明,采用\textbf{$A^3$}-CodGen框架可成功提取、融合并注入代码仓库信息至大型语言模型中,生成更准确、高效且高复用性的代码。相较于人类开发者,该框架生成的代码具有更高复用率,进一步凸显其有效性。本研究为代码生成领域做出重要贡献,为开发者应对软件开发实践中不断演进的需求提供了更强大的工具。