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

被引:10
作者
Dong, Yiwen [1 ]
Gu, Tianxiao [2 ]
Tian, Yongqiang [1 ]
Sun, Chengnian [1 ]
机构
[1] Univ Waterloo, David R Cheriton Sch Comp Sci, Waterloo, ON, Canada
[2] Alibaba Grp, Hangzhou, Peoples R China
来源
2022 ACM/IEEE 44TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE 2022) | 2022年
基金
加拿大自然科学与工程研究理事会;
关键词
type inference; constraint satisfaction; automated repair; datalog; STACKOVERFLOW;
D O I
10.1145/3510003.3510061
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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-the-art 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.
引用
收藏
页码:1982 / 1993
页数:12
相关论文
共 44 条
[31]  
Saifullah C. M. K, 2020, COSTER TOOL FINDING
[32]   Learning from Examples to Find Fully Qualified Names of API Elements in Code Snippets [J].
Saifullah, C. M. Khaled ;
Asaduzzaman, Muhammad ;
Roy, Chanchal K. .
34TH IEEE/ACM INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING (ASE 2019), 2019, :243-254
[33]  
Saifullah C M Khaled, 2021, ICSE 21 DEMO
[34]  
Smith Daniel., 2008, OOPSLA 2008, P505, DOI [10.1145/1449764.1449804, DOI 10.1145/1449764.1449804]
[35]   Live API Documentation [J].
Subramanian, Siddharth ;
Inozemtseva, Laura ;
Holmes, Reid .
36TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING (ICSE 2014), 2014, :643-652
[36]  
Terragni V., 2016, P 25 INT S SOFTW TES, P118
[37]   APIzation: Generating Reusable APIs from StackOverflow Code Snippets [J].
Terragni, Valerio ;
Salza, Pasquale .
2021 36TH IEEE/ACM INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING ASE 2021, 2021, :542-554
[38]  
Tiejun Wang, 2001, ECOOP 2001 - Object-Oriented Programming. 15th European Conference. Proceedings (Lecture Notes in Computer Science Vol.2072), P99
[39]   Do the Dependency Conflicts in My Project Matter? [J].
Wang, Ying ;
Wen, Ming ;
Liu, Zhenwei ;
Wu, Rongxin ;
Wang, Rui ;
Yang, Bo ;
Yu, Hai ;
Zhu, Zhiliang ;
Cheung, Shing-Chi .
ESEC/FSE'18: PROCEEDINGS OF THE 2018 26TH ACM JOINT MEETING ON EUROPEAN SOFTWARE ENGINEERING CONFERENCE AND SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING, 2018, :319-330
[40]   Syntax and Stack Overflow: A methodology for extracting a corpus of syntax errors and fixes [J].
Wong, Alexander William ;
Salimi, Amir ;
Chowdhury, Shaiful ;
Hindle, Abram .
2019 IEEE INTERNATIONAL CONFERENCE ON SOFTWARE MAINTENANCE AND EVOLUTION (ICSME 2019), 2019, :318-322