Find class origin within IntelliJ Idea - intellij-idea

I would like to find the library specification for a class opened in the editor. I have a Maven project which is quite big with a lot of modules. When I navigate to a class which is referenced from the source code I can see a module origin in the title bar of Intellij Idea like this "HttpServlet [Maven: org.apache..."
However I am not able to see where exactly this Maven library is included from, I can guess this example above as part of an Web Service and I can think of where it is nested in, but this is a hard process sometimes especially if it is a nested include somewhere...

Related

Intellij not able to resolve Geb content when located in external libraries

We currently have a central repository that holds all our source code (including the Geb page objects), and a seperate repo for the full Geb regression suite which depends on the former page object module.
When working with tests that string a few static content defined Geb objects together, Intellij is not able to resolve them, so I get this:
.
However, if I manually add the page object project source as a module to the regression project, suddenly Intellij is able to resolve these items, like this:
This is also the case for people writing tests directly into the main project containing the page objects.
I know that Intellij has visibility of the decompiled page object code (when I do drill into classes in the page object project, I can see the original source code with no 'this code has been decompiled' type messages, so what is the difference between the two approaches?
I have never tried reusing Geb pages and modules inside of a jar across multiple projects and I have no idea if IntelliJ is only able to autocomplete Geb content definition usages if it has sources of them and not compiled classes.
I think that the only person able to answer your question will be the original author of Geb support in IntelliJ, Daniil Ovchinnikov. You can try filing an issue in YouTrack or point Daniil to this quesiton on twitter.

IntelliJ multi-project

Moving to intellij i'm trying to understand properly the logic behind the its project structure. I come from eclipse. After reading for a while i understood the relation between workspace and project, then between project and modules. However something that is puzzling me is the logic of the default project configuration in Intellij. Indeed, when you create a project there is an initial module which to a certain extend is equivalent to the Project itself. To be more precise, the initial module folder is the Project folder. This is kind of confusing to me. Then when you add more module they are sub-module of that module.
My first question is what is the rationale of making this first module equivalent to the project folder ?
Following this, i would further ask, what the point of having modules as sub-module of others.
In eclipse i use to have simply different project (i.e. module) independent from each other and adding the dependency as necessary. So how does the Idea solution makes it better, if not what is the rational here ?
I saw that one can start an empty project and then add modules to it. However in that case, the modules added are added as subfolder of the Project and therefore there is no initial module equivalent to the Project folder ? So why this difference and what is the rationale behind it ?
What would be the better approach, the first or second ?
Would it be ok to have this first initial module with no src or test folder but just with the proper facet so as to spread it to the sub-module?
I would appreciate if someone could explain a bit the rational of all of it ?
I will move to SBT soon (i.e. maven structure which I suppose inspired all modern IDE project Structure) if one want to explain within that context fine, nevertheless i want to understand the rationale in intelliJ first.
Many thanks,
-M-
PS: What i'm looking for is some advise for some multi-module project structure in Intellij as i'm moving my eclipse workspaces to it.
I think that it's not uncommon for projects to be relatively small, so they don't need fancy modules with dependency management etc. In that case, I find the default project created by IntelliJ to fit perfectly my needs: no need to add submodules, everything is directly in the parent project, it reduces the structure to its bare minimum.
On the other hand, big projects with submodules will likely resemble the structure of a Maven multimodule project (perhaps SBT too, but I don't know this tool at all). You have a parent root which acts as a container for submodules. The parent project may also store configuration (a default SDK, a language level etc. that will be inherited by the submodules). The actual code will be contained in the submodules.
Regarding your questions, it all depends on the kind of project you are developing. For a small codebase, you could keep a simple project with no submodule. For bigger codebases, you can either create modules manually, or import an existing Maven/SBT/whatever project, which will automatically create modules reflecting the imported structure.

Create a simple Java Class in IntelliJ 13

When I am using Eclipse I just configure a project in seconds and create classes in seconds. In intelliJ however, I have to be looking all over the place on how ro create a simple Java class. I swear it is not in the new drop down list. Its giving me options for html and leaves out the class for a Java project! Anything would be accepted.
You just right click on the package you want to create a Java Class in, then select New->Java Class
You need to make sure you have your source tree marked as a sources root (IntelliJ usually does a good job detecting this on its own for existing sources). If not you will need to mark it as a sources root before you are able to create a Java class. Right click on the sources root then Mark Directory As->Sources Root
It depends on the kind of project you're doing. For example, if you're in a maven project, creating a file should be done in src/main/java. If you right click on this folder, you'll have the possibility to create a java class.
In general, the context menu depends on the context you're calling it.
Hope it helps

How does Find Usages choose which modules it searches?

My project was created from an maven project, with additional external maven modules added as I discovered that it was useful to have other source files at hand.
The source for interface X lives in module-library. If I navigate to the source file, highlight the X.execute() signature, and then invoke Find Usages (Project Files), a get a list of the usages in module-library.
The source for the application Y lives in module-app. If I navigate to the source file, find a place where X.execute is invoked, highlight that usage, and then invoke Find Usages (Project Files), I get a list that includes usages in module-app, and also the usages in module-library.
Shouldn't these be the same? Does the fact that they are different imply that I've somehow screwed up the creation/configuration of my project?
It looks like a bug, I've reported it in YouTrack. Please login to the tracker and provide more details (like your IDEA version/build number). Sample project to reproduce this problem would help a lot.
You can also check if File | Invalidate caches helps.

Make IntelliJ aware of links to Java elements in XML files

I have a custom XML format that links to Java resources. For the sake of simplicity let's assume my XML file would look like this:
<root>
<java-class>my.fully.qualified.class.name</java-class>
</root>
Eventually my references will be somewhat more complicated. It will not contain the fully qualified class name directly and I will need some logic to resolve the correct class, but I want to keep the example as simple as possible here.
Now I want it to be possible to Strg+Click on the element's text and want IntelliJ to carry me to the .java file, just like it is possible in Spring-XML files. In the IDEA Plugin Development FAQ there is a link called "How do I add custom references to Java elements in XML files?" which so much sounds like exactly what I need. Unfortunately it links to a discussion where someone is more or less done implementing something like this, having some minor problems. Nevertheless I understood that I probably need to write an implementation of the interface com.intellij.psi.PsiReference. Googling for "PsiReference" and "IntelliJ" or "IDEA" unfortunately did not bring up any tutorials on how to use it, but I found the class XmlValueReference which sounds useful. Yet again googling for "XmlValueReference" did not turn up anything useful on how to use the class. At least the PSI Cookbook tells me that I can find the Java class by using JavaPsiFacade.findClass(). I'd be thankful for any tutorials, hints and the like, that tell the correct usage.
The above linked discussion mentions that I need to call registry.registerReferenceProvider(XmlTag.class, provider) in order to register my provider once I eventually managed to implement it, but of which type is "registry" and where do I get it from?
First of all, here's a nice tutorial that came up a few days ago, which explains the basics of IntelliJ plugin development (you should take a look at the section Reference Contributor).
You will likely have to define your own PsiReferenceContributor, which will be referenced in your plugin.xml like this:
<psi.referenceContributor implementation="com.yourplugin.YourReferenceContributor"/>
In your reference contributor, there's a method registerReferenceProviders(PsiReferenceRegistrar) where you will be able to call registry.registerReferenceProvider(XmlTag.class, provider).
Finally, in your instance of PsiReferenceProvider, you will have to test the tag name to filter out tags which don't contain class references, then find the right Java class using JavaPsiFacade.findClass().
From my experience, the best place to get help regarding IntelliJ plugin development is JetBrains' forums.