编写你自己的代码检查器:一种基于大语言模型的自动化测试驱动检查器开发方法
Write Your Own CodeChecker: An Automated Test-Driven Checker Development Approach with LLMs
AI总结:
本文提出AutoChecker,一种基于大语言模型的方法,仅凭规则描述和测试套件即可自动生成代码检查器,通过增量式逻辑更新和逻辑引导的API上下文检索,在20条PMD规则上平均测试通过率达82.28%,性能与官方检查器相当。
摘要:
随着对代码质量保证需求的日益增长,开发者不仅在使用现有的静态代码检查器,还寻求定制化检查器以满足其特定需求。如今,各种代码检查框架提供了广泛的检查器定制接口来满足这一需求。然而,大规模检查器框架的抽象检查逻辑和复杂API使用方式都使这一任务充满挑战。为此,自动化代码检查器生成有望减轻检查器开发的负担。在本文中,我们提出了AutoChecker,这是一种由大语言模型(LLM)驱动的创新方法,能够仅根据规则描述和测试套件自动编写代码检查器。为了实现全面的检查逻辑,AutoChecker通过每次聚焦于解决一个选定的用例来增量式地更新检查器的逻辑。为了获得精确的API知识,在每次迭代中,它利用细粒度的逻辑引导API上下文检索,首先将检查逻辑分解为一系列子操作,然后为每个子操作检索与检查器相关的API上下文。在评估方面,我们使用多个大语言模型,将AutoChecker、五个基线方法和三种消融方法应用于为20条随机选取的PMD规则生成检查器。实验结果表明,AutoChecker在所有有效性指标上均显著优于其他方法,平均测试通过率达到82.28%。此外,AutoChecker生成的检查器能够成功应用于真实世界项目,其性能与官方检查器相当。
英文摘要:
With the rising demand for code quality assurance, developers are not only utilizing existing static code checkers but also seeking custom checkers to satisfy their specific needs. Nowadays, various code-checking frameworks provide extensive checker customization interfaces to meet this need. However, both the abstract checking logic and the complex API usage of large-scale checker frameworks make this task challenging. To this end, automated code checker generation is anticipated to ease the burden of checker development. In this paper, we propose AutoChecker, an innovative LLM-powered approach that can write code checkers automatically based on only a rule description and a test suite. To achieve comprehensive checking logic, AutoChecker incrementally updates the checker's logic by focusing on solving one selected case each time. To obtain precise API knowledge, during each iteration, it leverages fine-grained logic-guided API-context retrieval, where it first decomposes the checking logic into a series of sub-operations and then retrieves checker-related API-contexts for each sub-operation. For evaluation, we apply AutoChecker, five baselines, and three ablation methods using multiple LLMs to generate checkers for 20 randomly selected PMD rules. Experimental results show that AutoChecker significantly outperforms others across all effectiveness metrics, with an average test pass rate of 82.28%. Additionally, the checkers generated by AutoChecker can be successfully applied to real-world projects, matching the performance of official checkers.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。