Compile-time created class is shown as non-existent in IntelliJ

旧时模样 提交于 2020-01-05 04:17:05

问题


Motivation:

I'd like to try if compile-time annotation processing fits my problem. It needs to work out of the box, no compiler arguments etc.


Current state:

I have:

  • The annotation
  • An annotation processor
  • A .jar containing both of these and a javax.annotation.processing.Processor file containing the FQCN of my processor in META-INF/services

What should happen:

  • It should autodetect the processor
  • It should process the annotation and create a new class (WiredAnnotated)
  • I should be able to use this class in one step of compilation (not multiple phases)
  • I wan't the editor to accept this class is generated (e.g. AndroidAnnotations manages this as well)

What actually happens:

  • It autodetects the processor
  • It creates a new class (in out/production/*/generated/)
  • I am able to use this class
    • The source code looks right
    • When decompiling it looks ok too
  • The editor cannot resolve the class (see screenshot)

What I tried:

  • Restarting IntelliJ
  • Invalidating caches
  • Checking for output of the annotation processor

Screenshot:

When compiling, it actually works as expected. I guess it has something to do with inspecting the wrong directories.

Does anyone have an idea/clue on what I'm doing wrong? Did I miss information which could help you help me?

Thanks in advance, Till


回答1:


Well, you need to add you out/production/*/generated/ to projects source folder. So, IntelliJ will know about your generated classes.

You can make it via Right click on directory > Mark directory as source root.

or

Project structure (F4) > Modules > Sources tab > Source folders should contain all directories with your source codes, generated one inludes.

In android there is a gen dir in root folder, but notice, it glows blue or green which means it marked as Source folder, it is also visible in Project structure > Modules. It contains R, BuildConfig and Manifest.



来源:https://stackoverflow.com/questions/18904406/compile-time-created-class-is-shown-as-non-existent-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!