Lune

ICSE2022顶会

SnR: Constraint-Based Type Inference for Incomplete Java Code Snippets

Yiwen Dong, Tianxiao Gu, Yongqiang Tian, Chengnian Sun

摘要

Code snippets are prevalent on websites such as Stack Overflow and are effective in demonstrating API usages concisely. However they are usually difficult to be used directly because most code snippets not only are syntactically incomplete but also lack dependency information, and thus do not compile. For example, Java snippets usually do not have import statements or required library names; only 6.88% of Java snippets on Stack Overflow include import statements necessary for compilation.

This paper proposes SnR, a precise, efficient, constraint-based technique to automatically infer the exact types used in code snippets and the libraries containing the inferred types, to compile and therefore reuse the code snippets. Initially, SnR builds a knowledge base of APIs, i.e., various facts about the available APIs, from a corpus of Java libraries. Given a code snippet with missing import statements, SnR automatically extracts typing constraints from the snippet, solves the constraints against the knowledge base, and returns a set of APIs that satisfies the constraints to be imported into the snippet.

We have evaluated SnR on a benchmark of 267 code snippets from Stack Overflow. SnR significantly outperforms the state-of-theart tool Coster. SnR correctly infers 91.0% of the import statements, which makes 73.8% of the snippets compile, compared to 36.0% of the import statements and 9.0% of the snippets by Coster.

问 Lune

几分钟读透这篇 Paper,不用再花一下午。

Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。

已有 3 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。

可以从这些问题问起

Lune 可以查阅

全文 · 引用它的顶会 Paper · 相关的 Paper

获取答案

免费开始,无需绑卡

脉络

它引用的引用它的从左到右按年份排列,引用越多,位置越高。

引用它的顶会 Paper3

  1. Statistical Type Inference for Incomplete ProgramsYaohui Peng, Jing Xie, Qiongling Yang, Hanwen Guo 等FSE 2023 · 2 次引用
  2. Large Language Model-Aided Partial Program Dependence AnalysisXiaokai Rong, Aashish Yadavally, Tien N. NguyenICSE 2026 · 1 次引用
  3. CKTyper: Enhancing Type Inference for Java Code Snippets by Leveraging Crowdsourcing Knowledge in Stack OverflowAnji Li, Neng Zhang, Ying Zou, Zhixiang Chen 等FSE 2025 · 1 次引用

它引用的 Paper1

  1. APIzation: Generating Reusable APIs from StackOverflow Code SnippetsValerio Terragni, Pasquale SalzaASE 2021 · 12 次引用

相关 Paper

  1. Scitix: Scalable Constraint-Based Type Inference for Code Snippets with Missing TypesYiwen Dong, Zhenyang Xu, Yongqiang Tian, Edward Lee 等ISSTA 2026
  2. Feedback-Directed Partial ExecutionIshrak Hayet, Adam Scott, Marcelo d'AmorimISSTA 2024 · 1 次引用
  3. Are Human Rules Necessary? Generating Reusable APIs with CoT Reasoning and In-Context LearningYubo Mai, Zhipeng Gao, Xing Hu, Lingfeng Bao 等FSE 2024 · 4 次引用
  4. Measuring the Effects of Stack Overflow Code Snippet Evolution on Open-Source Software SecurityAlfusainey Jallow, Michael Schilling, Michael Backes, Sven BugielS&P 2024 · 6 次引用
  5. Prompt-tuned Code Language Model as a Neural Knowledge Base for Type Inference in Statically-Typed Partial CodeQing Huang, Zhiqiang Yuan, Zhenchang Xing, Xiwei Xu 等ASE 2022 · 40 次引用
黄昏的海面,两侧是细线勾勒的悬崖