How to write an own dependency plugin for a Java project

Hi Community,

I want to write an own plugin that finds the dependencies and usages for a Java Class in a project. The problem here is that I don't know where to start.
I tried to find the references of a file through a PsiJavaFile and its fields, but I can't access the Javafile that represents the type of a reference.

My goal of this plugin is to select unit tests that have dependencies to a modified Javafile. I want to find the classes for which I need to run JUnit tests so I don't need to run all tests in the project.
I need to do this because of my bachelor thesis.

Greetings
Markus
0
7 comments

Hi Markus,

Have you seen the JavaPsiFacade class?  For example, you can obtain an instance of the class with JavaPsiFacade.getInstance(project).
It has a lot of useful methods you can make use of :)

Alan

Edit - Definitely check out http://confluence.jetbrains.com/display/IDEADEV/PSI+Cookbook - it has a lot of pointers for the common usecases

0
Avatar
Markus Neubauer

Thank you for your answer Alan it helped a lot,

now I get the dependencies of a class, but if I want to get the corresponding JUnit test I need to find the usages of a class as well.

Markus

Edit - I read the PSI Cookbook and found the ReferencesSearch.search()entry but i don't know how to use it

0

Have you tried calling the method?

Seriously, this is a very simple API. What exactly is unclear about how to use it?

0
Avatar
Markus Neubauer

Hi Dmitry,

my mistake was that I tried to search for a PsiJavaFile and not for a class element in it.

0
Avatar
Markus Neubauer

I have another question.

Is there any way to trigger a maven or gradle task from the plugin
or access the cmd and execute a command?

Markus

0

Hi Markus,

I'm not entirely sure how to do this currently;

But within IntelliJ there are the concept of services (http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Plugin+Structure#IntelliJIDEAPluginStructure-PluginServices) which allows a plugin component to be loaded on demand.
And I can also see from the Maven plugin.xml file that it exposes some services (https://github.com/JetBrains/intellij-community/blob/master/plugins/maven/src/main/resources/META-INF/plugin.xml)

That might be worth checking out.

On a side note, it would have been good to raise a separate post for this question; as it would aid people in the future who try searching for a similiar question :)

Alan

0
Avatar
Markus Neubauer

Hi Alan,

Thank you for your answer and for the advice.
I opened http://devnet.jetbrains.com/thread/445589?tstart=0

Markus

0

Please sign in to leave a comment.