iJTyper:融合约束类方法与统计类方法的Java迭代类型推断框架
iJTyper: An Iterative Type Inference Framework for Java by Integrating Constraint- and Statistically-based Methods
AI总结:
针对现有Java代码片段类型推断方法召回率或精确率低的问题,提出融合约束与统计方法的迭代框架iJTyper,通过迭代上下文扩充与知识库缩减提升推断效果,在多个基线和数据集上表现更优。
摘要:
推断不完整代码片段(例如问答论坛上的代码片段)中API元素的类型,是对代码片段进行处理的前置步骤。现有类型推断方法主要可分为基于约束的方法和基于统计的方法两类。前者对代码语法要求较高,且常因代码片段的语法局限性存在召回率低的问题;后者依赖从训练语料中学习到的统计规律,未充分利用代码片段中的类型约束,可能导致精确率较低。\n本文提出了一种面向Java的迭代类型推断框架iJTyper,融合了两类方法的优势。针对某一代码片段,iJTyper首先采用基于约束的方法,利用推断出的API元素类型扩充代码上下文;随后对扩充后的代码片段应用基于统计的方法。预测得到的API元素候选类型会进一步用于优化基于约束的方法,具体方式为缩减其预构建的知识库。iJTyper迭代执行两类方法,持续进行代码上下文扩充与知识库缩减,直至满足终止条件,最终结合两类方法的结果得到最终推断结果。\n我们在两个开源数据集上对iJTyper进行了评估。结果显示:1)iJTyper在两个数据集上均取得了较高的平均精确率/召回率,分别为97.31%和92.52%;2)iJTyper显著提升了两个当前最优基线模型SnR和MLMTyper的召回率,提升幅度分别至少为7.31%和27.44%;3)iJTyper在两个数据集上将主流语言模型ChatGPT的平均精确率/召回率分别提升了3.25%和0.51%。
英文摘要:
Inferring the types of API elements in incomplete code snippets (e.g., those on Q&A forums) is a prepositive step required to work with the code snippets. Existing type inference methods can be mainly categorized as constraint-based or statistically-based. The former imposes higher requirements on code syntax and often suffers from low recall due to the syntactic limitation of code snippets. The latter relies on the statistical regularities learned from a training corpus and does not take full advantage of the type constraints in code snippets, which may lead to low precision. In this paper, we propose an iterative type inference framework for Java, called iJTyper, by integrating the strengths of both constraint- and statistically-based methods. For a code snippet, iJTyper first applies a constraint-based method and augments the code context with the inferred types of API elements. iJTyper then applies a statistically-based method to the augmented code snippet. The predicted candidate types of API elements are further used to improve the constraint-based method by reducing its pre-built knowledge base. iJTyper iteratively executes both methods and performs code context augmentation and knowledge base reduction until a termination condition is satisfied. Finally, the final inference results are obtained by combining the results of both methods. We evaluated iJTyper on two open-source datasets. Results show that 1) iJTyper achieves high average precision/recall of 97.31% and 92.52% on both datasets; 2) iJTyper significantly improves the recall of two state-of-the-art baselines, SnR and MLMTyper, by at least 7.31% and 27.44%, respectively; and 3) iJTyper improves the average precision/recall of the popular language model, ChatGPT, by 3.25% and 0.51% on both datasets.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。