Specify module type in plugin.xml for a plugin


Is there a way to specify a module type for a plugin so that the extensions of this plugin are triggered only if the module is of that type?

I know this can be achieved by overriding a certain method in the implementation of an extension. For example: 

<findUsagesHandlerFactory implementation="com.thoughtworks.gauge.findUsages.CustomFindUsagesHandlerFactory"/>

For the above extension, I can override the following method(canFindUsages) in implementation

public class CustomFindUsagesHandlerFactory extends FindUsagesHandlerFactory {
public boolean canFindUsages(PsiElement psiElement) {
return false;

If I implement using the above approach, I need to have the check in every extension implementation.

Can I define a specific module type in plugin.xml for the plugin where the extension points of the plugin will be triggered?

1 comment

To the best of my knowledge some extension are by language, others are generic. In these you need to test for the pre-requisites in your code.

Considering how much needs to be written to implement an extension, having an extra one line to check if a file belongs to specific module seems like a very small inconvenience.

One line to test for the module:

if (!Plugin.IsRightModule(psiElement)) return false;

A static method in some class:

public class Plugin {
public static boolean isRightModule(@NotNull PsiElement psiElement) {
Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);

if (module != null) {
ModuleType moduleType = ModuleType.get(module);
// more tests as necessary
return true;
return false;



Please sign in to leave a comment.