当导航到源时,IDEA 将首先转到附加源。如果不存在,它将反编译该类并显示它。
尝试以下故障排除来查找问题:
1. 确保源已正确连接。
For libraries, Open the Project Structure dialog (Ctrl+Alt+Shift+S or ⌘;) and sel4ct "Libraries" on the left under "Project Settings". Find the library in question, and select it. It will show if the source is attached. You mentioned you have Maven's "Automatically download" sources/documentation both checked. So for any maven libraries that have source available, it should be listed.
If it is not listed or is in red, run "Download Sources" or "Download Sources and Documentation" from the Maven tool window. If the source is till in red, it likely means it is not available for that artifact in the maven repository. Use Maven Search to verify such.
对于 JDK,在“项目结构”对话框中选择“SDK”,找到 JDK,然后选择“源路径”选项卡。确保列出了 {jdk-home}/src.zip 文件。
当您添加 JDK 时,IDEA 应该自动设置此项,但如果没有,请添加它。
2. 确保源 JAR/ZIP 文件未损坏
导航到资源管理器/查找器中的存档,并确保可以打开和查看它。
3.刷新IDEA的缓存
IDEA 的缓存/索引可能已损坏。因此,IDEA 没有“看到”类和源代码之间的链接。去文件 > 使缓存无效/重新启动...”。使缓存无效并重新启动 IDEA。等待 IDEA 完成对项目和库的重新索引(在 IDEA 窗口右下角观察进度)。
上述其中一项应该可以解决该问题。
仅供参考,如果您不希望 IDEA 反编译代码(作为不存在源的备份),据我所知(并且基于它的帮助页面),唯一的方法是禁用插件列表中的“Java Bytecode Decompiler”。