Trigger action on file creation

Hi all,

I'm quite new to creating plugins, but I was wondering if it's possible (and how) to trigger an action (e.g. create a file <-- Junit test) when a class is created.

Any tips on where to start are highly appreciated.

Erik

9 comments
Comment actions Permalink

I think VirtualFileManager.addVirtualFileListener should do the trick

0
Comment actions Permalink

Hello Erik,

I'm quite new to creating plugins, but I was wondering if it's
possible (and how) to trigger an action (e.g. create a file <-- Junit
test) when a class is created.


Assuming that you want tests to be created only when the user creates a class
through the "New" menu and not every time a class is created (during refactorings
etc.), your best bet is to create a new action ("New | Class with Tests")
in the menu, rather than listen to appearance of classes through the VFS
or PSI.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hello Hugo,

I think VirtualFileManager.addVirtualFileListener should do the trick


This is a bit overkill - you don't want tests to be created for classes that
you pull from the VCS when updating the project, do you? :)

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

I guess it depends on the exact use case, but yes, for most use cases this would be overkill i guess.
Well, either way, Erik now has two options to choose from for the desired use case.....better for him :)

0
Comment actions Permalink

Hi everyone, thanks for the suggestions.

Actually, I'm looking something in the middle, I guess. New Class with Test is great, but often I don't use the New Class menu to create classes.

For example, when I type something like:

and Name doesn't exist yet, I create it with ALT+Enter. I'd like the test to be created than too.

I also agree with Dimitri: creating tests for all classes I get from VCS might be a bit overkill.

Is there a solution somewhere in the middle? E.g., can I intercept the ALT+Enter call when creating a new class, and create a test class then too?

Thanks for the help so far!

0
Comment actions Permalink

Why not simply add an "Add Test" intention?

-tt


0
Comment actions Permalink

Also fine by me :)

Could you give me a hint on how to create my own intention?

0
Comment actions Permalink

Hello Erik,

Also fine by me :)

Could you give me a hint on how to create my own intention?


Erik, "examples" directory of plugin development package contains an example:
ConditionalOperatorConvertor.
Reading that code and modifying it is a good start.

Feel free to post follow-up questions in this thread.

-tt


0
Comment actions Permalink

Great, I'll have a look!

Thanks!

0

Please sign in to leave a comment.