简体   繁体   English

从 Android Studio 的全局搜索中删除 dagger 生成的类?

[英]Remove dagger generated classes from Android Studio's global search?

It is really irritating.这真的很烦人。 I need more time to find some class because of dagger 2.由于匕首 2,我需要更多时间来找到一些 class。

If you are talking about the generated MembersInjector and Factory classes: 如果您正在讨论生成的MembersInjectorFactory类:

MyClass_MembersInjector.java
MyClass_Factory.java

you can prevent these from coming up in the Ctr-N or Cmd-O dialog by adding them to the ignored files list in File / Settings / Editor / FileTypes and adding the appropriate wildcards to the Ignore files and folders edittext: 您可以通过将它们添加到File / Settings / Editor / FileTypes文件类型中的忽略文件列表并将相应的通配符添加到Ignore files and folders edittext中来阻止它们出现在Ctr-NCmd-O对话框中:

IntelliJ中的忽略文件和文件夹对话框

*_MembersInjector.java; *_Factory.java; will cause most of the generated classes to be ignored: 将导致大多数生成的类被忽略:

Before: 之前:

在应用设置之前

After: 后:

应用设置后

You can even add Dagger*.java to the list if you don't even want to see the generated component (even though this is rather useful for the project). 如果你甚至不想看到生成的组件,你甚至可以将Dagger*.java添加到列表中(即使这对项目非常有用)。

Update: 更新:

If you are talking about not having the classes appear in auto-import/auto-complete this is done through Settings / Editor / General / Auto Import : 如果您所说的没有在自动导入/自动完成中显示类,则可通过Settings / Editor / General / Auto Import

IntelliJ中的自动导入设置对话框

David Rawson's answer doesn't help to get rid of not showing _Factory classes when performing Find Usages on the class name. 在对类名执行Find Usages时,David Rawson的答案无助于摆脱不显示_Factory类。 This is what will be shown: 这将是显示的内容:

在此输入图像描述

This can be resolved with creating a new scope which will disregard generated files. 这可以通过创建一个忽略生成的文件的新范围来解决。

在此输入图像描述

在此输入图像描述

Here's the regex for generated files in app module: !file[app]:build/generated//* . 这是app模块中生成文件的正则表达式: !file[app]:build/generated//* But you may as well use "Exclude recursively" button locating the directory you want to get rid of. 但是你也可以使用“排除递归”按钮找到你想要删除的目录。

在此输入图像描述

Now, change the search scope to newly created: 现在,将搜索范围更改为新创建的:

在此输入图像描述

And this will be the output: 这将是输出:

在此输入图像描述

No _Factory classes. 没有_Factory类。 You may as well get rid of classes in test packages, thus only classes from production package will be found. 您也可以在测试包中删除类,因此只能找到生产包中的类。

In Android Studio, go to在 Android Studio 中,转到

File -> Settings -> Editor -> File Types -> Ignored Files and Folders文件 -> 设置 -> 编辑器 -> 文件类型 -> 忽略的文件和文件夹

and add wild cards.并添加通配符。 Enter apply.输入申请。

For Hilt , you can add following flags/wildcards *_MembersInjector.java; *_Factory.java; *_Providers.java; *_Bindings.java; *_HiltComponents_*.java; *_Provide*.java对于Hilt ,您可以添加以下标志/通配符*_MembersInjector.java; *_Factory.java; *_Providers.java; *_Bindings.java; *_HiltComponents_*.java; *_Provide*.java *_MembersInjector.java; *_Factory.java; *_Providers.java; *_Bindings.java; *_HiltComponents_*.java; *_Provide*.java

In Android Studio Dolphin there is a new option in Find Usages dialog, so you can ignore usages in generated code.在 Android Studio Dolphin 中,“ Find Usages对话框中有一个新选项,因此您可以忽略生成代码中的用法。

在此处输入图像描述

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

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