IntelliJ PlugIn Development- Get the Project Structure - intellij-plugin

I want to visualize a part of the project structure. Therefore I need something like a VirtualFileVisitor that can be attached to a VirtualFile. (2 get the subtree of this element).
Does something like this exists? And are there some examples online?

VirtualFileVisitor in com.intellij.openapi.vfs package. You can new it, and Override method depends on your business logic.

Related

Can you create a folder of documents in Sanity and how?

I have a lot of documents of same type and i want to organize them in folders and subfolders. Is that possible in sanity?
Sanity doesn't have a concept of generic folders/subfolders in the traditional sense. But there's a new(ish) feature called Structure that makes it possible to declare nested navigation hierarchies in the content studio. Sounds like it could be a good match for your use case: https://www.sanity.io/docs/content-studio/structure-builder.
In particular the section about segmented content would be relevant I think: https://www.sanity.io/docs/structure-builder/how-it-works#segmented-content
Structure was introduced in version 0.134.0, so you may have to upgrade your content studio with sanity upgrade to start using it.

How can i provide Custom code-styles within a plugin

Basically my task is nearly a copy of [1], the only thing i want to achieve is, to put the generated codestyle.xml into a plugin to share this.
So i have my codeStyle.xml in my resources folder under codestyles like this:
ressources/codestyles/codeStyle.xml
The reason behind this is, that we started using an internal plugin repo for intellij, and in that way it is easier for us to distribute the settings internally.
Maybe my approach is not the best one, but i am glad for any input regarding this ticket.
[1] How can I create custom Live Templates with an Intellij plugin
Thank you
Simon
it looks like this is sadly not possible, as a solution we swapped to project based settings

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.

Find child plug-ins of features in eclipse workspace

I want to find all the child plug-ins of a feature ? I know the name of the feature, but IWorkspaceRoot.getProject(String) does not really help me. I get an IProject that I don't know how to convert to a feature object (IFeature ?). Maybe I am on the wrong track and there is a better / easier way to do this. Any ideas ?
You could check that a selected IProject is a feature project by checking for the nature called org.eclipse.pde.FeatureNature.
Then you could try to use IProject.getAdapter(IFeature.class) call, the cast the result to IFeature. I did not try this with feature projects, but works well with Java projects.
The correct answer is the use of PDECore static class. This class provides a FeatureModelManager, that would provide the corresponding information:
FeatureModelManager manager = PDECore.getDefault().getFeatureModelManager();
How to obtain this information? I looked with the plug-in spy to find which project defines the 'Deployable Features' export wizard (use Alt+Shift+F3 when the wizard is selected), and then looked at the implementation of the wizard class, where the addPages() method contains the previously described code block.

In a Maven project, what are reasons for either a nested or a flat directory layout?

As my Maven project grows, I'm trying to stay on top of the project structure. So far, I have a nested directory layout with 2-3 levels, where there's a POM on each level with module entries corresponding to the directories at that level. POM inheritance (parent property) does not necessarily follow this, and is not relevant for the purpose of this question.
Now, while the nested structure seems pretty natural to Maven, and it's nice and clean as long as you are on one particular level, I'm starting to get confused by what I look at in my IDE (Eclipse and IntelliJ IDEA).
I had a look at the Apache Felix sources, and they have a pretty complex project in what seems to be a flat directory structure, so I'm wondering if this would be a better way to go.
What are some pros and cons for either approach that you have experienced in practice?
Note that this question (which I found meanwhile) seems to be very similar. I'll leave it to the community to decide whether this should be closed as a duplicate.
I use a kind of mixed approach. Things with distinct lifecycle (from a release and thus VCS point of view) are flat, things with the same lifecycle are nested. And I use svn:externals for the checkout. I wrote about this approach in this previous answer.
I vote for nesting. I'm using IDEA 9 which shows the nesting in the project pane, so the presentation mirrors your logical project structure. (This wasn't the case in 8.1 - it was flattened out.)
I prefer keeping things nested, especially if the names are very similar - makes navigation much easier when using a command prompt. I have a project with names like myapp-layer-component, so they all start with the same prefix, and many have the same -layer-, so using autocomplete on the commandline is next to useless. Separating these out into a nested structure is then much easier because each part of the name (appname, layer or component) is repeated just once at each level in the directory structure.
If building from the command line, it's much easier to build a subset of the project, e.g. if I'm working on the db model, then often I need to build all projects in that area. This is tricky to do when the files are flattened out - the only way I know is to use the -pl argument to maven and specify the proejcts to build. With the nested directories, I just cd to the db directory and run mvn.
For example, instead of
myapp-web-gui1
myapp-web-gui2
myapp-web-base
myapp-svc-clustered
myapp-svc-clustered-integrationtest
myapp-svc-simple
myapp-db-model
myapp-db-hibernate
We have the structure
\myapp
\web
\gui1
pom.xml
\gui2
pom.xml (other poms omitted to keep it short)
\base
\svc
\clustered
\clustered-it
\simple
\db
\model
\hibernate
You could also add nesting for the integration tests, but this seems like driving the point too far.
With nesting, you also get all the benefits of inheritance (and some of it's pains...)
The only issue I've had with this is that the directory name doesn't match the artifact id. (I'm still using full artifactIds.) And so each project must explicitly define SCM paths, since these can no longer be inferred from the parent pom. Of course, each directory can be made the same as the artifactId, and then the SCM details can be inferred from the parent, but I found the long directory names a bit unwieldy.