如何在IntelliJ中查看代码实现?当前仅显示编译代码
解决IntelliJ IDEA查看代码显示编译后代码的问题
问题场景
使用IntelliJ IDEA 2023.1.2旗舰版,尝试查看代码(如示例中调用的windowed方法)实现时,打开的是编译后的反编译代码,而非原始源码。
示例代码:
private fun simpleWindowed(unFilteredMovieList: List<NewMovieItem>) { val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9) numberList.windowed(size = 2, step = 1, partialWindows = true).forEach { window: List<Int> -> val first = window.first() val second = window.last() println(window) } }
IDE配置信息:
IntelliJ IDEA 2023.1.2 (Ultimate Edition) Build #IU-231.9011.34, built on May 16, 2023 Runtime version: 17.0.6+10-b829.9 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 13.3.1 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 16 Metal Rendering is ON Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true Non-Bundled Plugins: com.intellij.nativeDebug (231.8770.15) Kotlin: 231-1.8.21-IJ9011.34
解决步骤
检查并下载Kotlin源码
- 打开反编译代码时,IDE顶部一般会出现“Download Sources”提示,点击即可自动下载对应版本的Kotlin源码。
- 若无提示,进入
File > Project Structure > Platform Settings > SDKs,选中当前JDK切换到Sourcepath标签页,点击加号添加IDE安装目录下plugins/Kotlin/kotlib中带-sources.jar后缀的文件。
清除缓存重启IDE
- 执行
File > Invalidate Caches...,选择“Invalidate and Restart”,清除缓存后重启,解决缓存导致的源码加载异常。
- 执行
确认项目依赖配置
- Gradle项目中确保
kotlin-stdlib依赖包含源码构件,示例配置:dependencies { implementation(kotlin("stdlib")) implementation(kotlin("stdlib-jdk8")) } - 同步项目后重新尝试查看源码。
- Gradle项目中确保
排查插件冲突
- 临时禁用
com.intellij.nativeDebug插件,重启IDE后验证是否恢复正常。
- 临时禁用
内容的提问来源于stack exchange,提问作者Compose Learner
相关产品推荐
相关产品推荐

