| API constraints are the restrictions and specifications that developers should obey when programming with APIs.When developers violate the API constraints,it will lead to misuse of the API,which may cause program crashes in software development.To detect API misuse in code,researchers propose a knowledge graph-based API misuse detection method.However,the existing research has problems such as incomplete knowledge of API constraints,simple identification methods of API constraints,and weak comprehensibility of API misuse descriptions.Therefore,how to help developers accurately detect and understand API misuse in complex code environments has become a serious challenge.For the construction of API-constrained knowledge graph,this paper defines the ontology structure of knowledge graph in detail,and focuses on modeling seven kinds of API constraint relationships: call-order,statechecking,value-checking,trigger,duplication-checking,redundancychecking,synchronization-checking.Next,this paper proposes an API constraint recognition model based on Deep Conv LSTM to extract API constraint sentences.Finally,this paper summarizes the relevant heuristic rules to extract API constraint triples.For API misuse detection research,this paper proposes an API misuse detection algorithm Misue Hint based on API-constrained knowledge graph.First,the algorithm locates in where API misuse may exist by parsing the code into a PSI tree and matching the PSI tree with the knowledge graph subgraph.The algorithm then checks for misuse of APIs in the code based on different strategies and related static code analysis techniques.In addition,for the problem of weak comprehensibility in API misuse detection,this paper proposes a correct code example mining algorithm KG2 Code based on API-constrained knowledge graph.First,subgraph extraction of different constraint types is performed on the knowledge graph.Second,perform API usage pattern mining on high-quality codebases.Finally,use program slicing to filter out irrelevant lines of code.The algorithm designed in this paper has been implemented into a tool.Experiments on real-world datasets show that,compared with current advanced methods,the Deep Conv LSTM model proposed in this paper can better extract API constraint sentences;the knowledge graph constructed in this paper contains highly accurate API constraint relationships;The proposed Misuse Hint algorithm and KG2 Code algorithm can effectively and practically help developers to detect and modify API misuse. |