Depends-Kotlin: A Cross-Language Kotlin Dependency Extractor

Qiong Feng,Xiaotian Ma,Huan Ji,Wei Song,Peng Liang
2024-08-21
Abstract:Since Google introduced Kotlin as an official programming language for developing Android apps in 2017, Kotlin has gained widespread adoption in Android development. However, compared to Java, there is limited support for Kotlin code dependency analysis, which is the foundation to software analysis. To bridge this gap, we develop Depends-Kotlin to extract entities and their dependencies in Kotlin source code. Not only does Depends-Kotlin support extracting entities' dependencies in Kotlin code, but it can also extract dependency relations between Kotlin and Java. Using three open-source Kotlin-Java mixing projects as our subjects, Depends-Kotlin demonstrates high accuracy and performance in resolving Kotlin-Kotlin and Kotlin-Java dependencies relations. The source code of Depends-Kotlin and the dataset used have been made available at https: //github.com/XYZboom/depends-kotlin. We also provide a screen-cast presenting Depends-Kotlin at <a class="link-external link-https" href="https://youtu.be/ZPq8SRhgXzM" rel="external noopener nofollow">this https URL</a>.
Software Engineering
What problem does this paper attempt to address?
The problem that this paper attempts to solve is the lack of Kotlin code dependency analysis tools, especially when dealing with mixed Kotlin and Java projects. Specifically, the paper aims to develop a cross - language dependency extraction tool named **Depends - Kotlin** to address the following two main challenges: 1. **Complexity of Kotlin Syntax**: The Kotlin language is characterized by conciseness, strong expressiveness, type - safety and null - safety, and contains a lot of syntactic sugar (such as extension functions, delegated properties, etc.), which increases the difficulty of dependency relationship resolution. For example, the use of higher - order functions and receiver types in Kotlin makes the dependency relationships more complex. 2. **Interoperability between Kotlin and Java**: Kotlin is designed to be fully interoperable with Java and can run on the JVM, which makes it easy to migrate from Java to Kotlin. However, this interoperability also brings new challenges, especially the inability to identify implicit calls (such as the getter method of Kotlin properties) in static code analysis. Therefore, a tool that can handle the dependencies between Kotlin and Java is required. To meet these challenges, the authors propose **Depends - Kotlin**, an enhanced version based on the existing Depends framework, which is specifically used to parse entities in Kotlin code and their dependencies, and supports cross - language dependencies between Kotlin and Java. By improving the architecture of the original framework, Depends - Kotlin can generate implicit code for Kotlin properties (such as getter/setter), and handle Kotlin's unique dependency types (such as delegation and extension functions). In summary, the main objective of this paper is to develop an efficient tool that can accurately parse the dependency relationships in Kotlin code and handle cross - language dependency problems in mixed Kotlin and Java projects, thereby providing a solid foundation for software analysis.