简体   繁体   English

IntelliJ 中生成代码的源代码级调试

[英]Source level debugging of generated code in IntelliJ

I want to debug into code generated by Dagger in IntelliJ.我想在 IntelliJ 中调试Dagger生成的代码。 The source files generated by Dagger are put into /target/generated-test-sources/test-annotations and /target/generated-sources/annotations . Dagger 生成的源文件放在/target/generated-test-sources/test-annotations/target/generated-sources/annotations

I've looked at the Run/Debug Configurations dialog, and didn't see anything obvious.我查看了运行/调试配置对话框,没有看到任何明显的东西。 I've also checked the Module Settings and both of these are listed as Source Folders so IntelliJ definitely knows they're source, but for some reason won't hit on any breakpoints I put in generated code.我还检查了模块设置,这两个都被列为源文件夹,所以 IntelliJ 肯定知道它们是源,但由于某种原因,我不会在生成的代码中找到任何断点。

For IntelliJ 13.1.5:对于 IntelliJ 13.1.5:

If /target/generated-sources/annotations is marked as a generated source root, IntelliJ never triggers breakpoints.如果/target/generated-sources/annotations被标记为生成的源根,IntelliJ 永远不会触发断点。 If /target/generated-sources/annotations isn't marked as generated source root, IntelliJ will trigger the breakpoints, but it won't jump to the associated source.如果/target/generated-sources/annotations未标记为生成的源根,IntelliJ 将触发断点,但不会跳转到关联的源。

  1. Unmark /target/generated-sources/annotations as a generated sources root取消将/target/generated-sources/annotations标记为生成的源根
  2. Set your breakpoints in the generated source在生成的源中设置断点
  3. Run your code to trigger the breakpoint运行您的代码以触发断点
  4. Mark /target/generated-sources/annotations as a generated sources root/target/generated-sources/annotations标记为生成的源根

IntelliJ now behaves as expected. IntelliJ 现在按预期运行。 You'll probably need to remove /target/generated-sources/annotations after you're done for breakpoints to be triggered again.在完成断点再次触发后,您可能需要删除/target/generated-sources/annotations

I've created an IntelliJ bug for this issue .为此问题创建了一个 IntelliJ 错误 Please upvote it.请点赞。

All you need is the source files somewhere available to IDEA, then you should be able to debug.您所需要的只是 IDEA 可用的源文件,然后您应该可以进行调试。 Make sure the folders containing the files is included in the project structure settings, then you should be able to open the files with ctrl+n and set breakpoints.确保包含文件的文件夹包含在项目结构设置中,然后您应该能够使用 ctrl+n 打开文件并设置断点。

My working warkaround is:我的工作解决方法是:

  • expand the generated artifact (jar, war, ear, ...)展开生成的工件(jar、war、ear、...)
  • open (and decompile) the class file打开(并反编译)类文件
  • put here the breakpoint把断点放在这里

At this point IntelliJ fires breakpoints as expected.此时 IntelliJ 按预期触发断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM