IntelliJ DSL plugin provide completion of Java classes and methods - java

I'm attempting to write an IntelliJ plugin for a DSL which references Java classes and methods. The DSL is exposed in *.conf files within a Java project. A typical snippet of the DSL looks like this:
TASK taskClass=com.example.Foo taskMethod=someMethod;
I've been working through the IJ 'Simple' plugin tutorial to learn about plugins and am able to implement a fair bit of my own plugin. Currently, however, I'm stuck on trying to understand how I can provide auto-completion for the taskClass and taskMethod keywords. Having worked through the Simple tutorial all my completion shows is 'Hello'. Now I want to be able to extend my CompletionContributor to show java classes and methods that exist in the project. This doesn't seem to be addressed in the tutorial, but perhaps I'm just missing it.
What do I need, in order to do this? I would guess that there is already some cached info about all the existing java code in a project that my Contributor could leverage.

I think you are looking for the existing stub indices.
For example, to get all class names in your project, you can use
val classNames = JavaFullClassNameIndex.getInstance().getAllKeys(project)
When using indices - your own or already existing ones - it is often useful to use the Index Viewer plugin so you can have a look at which things are in which index.
To add it as a dependency of your plugin (so you don't have to install it manually each time you build your plugin) add the following to intellij block of your build.gradle.kts:
plugins.set(listOf("java", "com.jetbrains.hackathon.indices.viewer:1.19"))
It should appear as a tool window on the right.
Don't forget to remove it once you are done with debugging the indices.
I also found the PsiShortNamesCache which might be useful.

Related

How can I use my utility classes in different git-projects at once?

I'm a beginning programmer and I apologize if my questions is trivial but I haven't found a sufficient answer to my problem.
I have a git repository called "toolbox" with some utility classes that I frequently use in other projects. Until now, I have manually copied those class files from this project in other projects whenever I needed them.
This if of course not a good way of doing it. I frequently add new features and fixes in whatever project I'm currently working on to these files. It makes version management a nightmare.
What I'd like to to is to import the toolbox-classes directly into the IntelliJ-Project(s) (which is also on the same git as the toolbox repo) and whenever I make a change to those files in the toolbox-repo I want the other projects to be able to automatically pull those changes as well.
If possible I'd also like to be able to share my toolbox-repo easily with others who might need those classes. But that is not a requirement. I'd just be nice to be able to do so.
I tried to use git submodule. It included the entire toolbox-repo in the target-repo but unfortunately I wasn't able to use the utility classes. I asked someone more experienced and they told me that I need to define "SourceSet" in the gradle.build but I wasn't able to configure that due to my lack of knowledge.
How can I include/import/use my utility classes from my toolbox-repo within other projects?
Thanks for any advice.

What is the best way to find the maven coordinates of a dependency in order to use a class?

Whenever I look at any documentation page for a Java class, it never specifies the maven coordinates of the dependency I need in order to use the class. I have to find the maven coordinates by doing additional searches. Why is it like that? Below is an example:
In contrast this is a C# documentation page:
It clearly specifies that in order to use this class, I will need to add a reference to Microsoft.WindowsAzure.Storage.dll. Is this another example of how Java sucks compared to C#?
Whenever I look at any documentation page for a Java class, it never specifies the maven coordinates of the dependency I need in order to use the class.
You are currently looking at the javadocs for the class. The Maven coordinates don't belong there1.
What you need to do is to look for the documentation for the library (or whatever) that the class belongs to. If the library documentation is well written, it will tell you the Maven coordinates, probably in the "getting started" section.
The other approach is to use to use a search tool to identify the name of the distribution JAR file, then try to find that in Maven Central. That won't tell you which version of the library is best to use. For that you need to read the library's documentation; e.g. the release notes or change logs.
UPDATE - In this case, finding the Maven coordinates in the Amazon documentation is challenging. (They seem to think we should all be using their Eclipse plugin ...) However, a little bit of digging and here is the Maven Central query to list all available versions:
http://search.maven.org/#search|gav|1|g%3A%22com.amazonaws%22%20AND%20a%3A%22aws-java-sdk%22
1 - Please don't presume to tell the Java community that they have got it all wrong, just because they don't conform to your expectations. If you think Java sucks, find a job where you don't need to use it. Or at least, keep your unwanted opinions to yourself.

How to generate java code from MoDisco java model within eclipse?

I started looking into MoDisco. So far I can discover a java model from an existing java project and write transformations using ATL to modify my java model. However I was unable to generate java code for that modified java model. In this demo there is java code generated from a modified model. An Acceleo launch configuration called JPAProject_Regeneration is used for that as can be seen in this screenshot:
Does anyone know how that launch configuration looks like? Is there a tutorial that explains the creation of this launch configuration?
The mentioned launch configuration can be found in the eclipse svn. However it isn't that helpful, because it heavily depends on a very specific local setup that includes hard coded absolute paths.
MoDisco also provides a discoverer in the plugin org.eclipse.gmt.modisco.java.generation. However this discoverer is registered under the wrong extension point and therefore unavailable from within the UI. See the filed bug.
Also note that once the discoverer is registered correctly it is only applicable if the java model is within a file ending with .javaxmi.
EDIT:
The whole plugin org.eclipse.gmt.modisco.java.generation seems deprecated, because there is a new API for discovery. I built a new plugin that does the same as the mentioned MoDisco plugin based on the new API.

JCodeModel to use in custom maven archetype

I am new to maven and Jcodemodel. I am trying to create an archetype which will accept the wsdl and generate the code. I need to create java code for implementation class file by implementing the interface. I need to use JCodeModel to generate java code. But I am new to JCode. How to use Jcodemodel inside Maven archetype to generate java code?
Kindly, guide me
Maven will build your projects and automate some aspects of managing the builds and the project; but, it will not decide for you what the project does, or how to go about writing the project.
You might need to write Java code that (because you mentioned a WSDL) runs as a web service. That web service apparently should accept "something" and reply back with "something". It is a guess (this is a very vague question), that the something it should accept is some sort of description of a Java class, and the something it should reply will be either Java source code, or a compiled java class.
In either case, the project can be managed by Maven, meaning that Maven will compile, test, and package your project. In certain cases, it will also deploy it (if you configured Maven to do so).
Now if you want Maven to actually accept the WSDL and generate the code, then what Maven will build will be static, meaning that the "generated" code will not be able to change after Maven completes the build. You can; however, build the "next" version which might change. If this scenario sounds more like what you had in mind, then your "source" would be a static file, and the "built project" would be the source code or the object code corresponding to the source.
Without more direction, this is probably the best guide you are going to get. It is just too vague a question, covering too much ground to say much definitively. You also seem to lack a lot of knowledge in a lot key places simultaneously; perhaps the best solution is to identify what you will likely need to brush up on, order those by "what needs what" and start with the element that depends on nothing else.

What benefits do GWT IDE plugins have considering that GWT is simply Java?

Seen that writing GWT code is basically writing Java code, what does a GWT for an IDE exactly do? For example there are GWT plugins for IDEA and for Eclipse (and maybe for NetBeans?) but do they do that I cannot do simply by using Eclipse or IDEA without the GWT plugin?
They add wizards, dialogs, editors, and other extensions to the IDE that help specifically with GWT tasks. For example, rather then creating a new GWT project from scratch using the command line, or creating an eclipse java project and then creating all the necessary files yourself, the plug-in adds a wizard that lets you type in the name of the project, and it creates all the necessary files for you.
Other additions can be large stuff like a local server, or minimal like a source code formatter. The sky is the limit with plug-ins.
I know the GWT adds a GUI editor to eclipse so you can drag and drop controls rather then manually entering them all.
I've only used the IDEA plugin myself. I definitely would not want to give it up. As others have said, you can create a GWT project and debug in hosted mode as easily as you would run any other application, but that's only the beginning.
IDEA also has several GWT-specific class creation options. You can create a new UiBinder file, which will generate both the .ui.xml file and the Java file, and will already have the plumbing in place for creating the UiBinder object. You can create a new GWT Remote Service, which will create the service interface, async interface, and implementation class for you.
The GWT plugin will also warn you about tons of probable errors right in the editor. It will warn you if your service interface doesn't have proper matching methods in the async interface, and has an intention for fixing the problem. It will warn if your service implementation class does not have an entry defined in the web.xml file (yep, with an intention available to automatically register it). It will warn you if you have fields in your UiBinder class that aren't defined in the .ui.xml file, again with an intention to help resolve the issue with just a couple keystrokes.
On top of that, the code completion is excellent for everything including CSS attributes, Javascript, HTML, and the various XML files.
Yes, you can, however using a plugin for a given IDE, helps you by not needing to swap from the IDE to another tool ( for testing for instance )
Here's the demo of IDEA
http://www.jetbrains.com/idea/training/demos/GWT.html
The same way you can also compile from the command line ( I do it sometimes ) or let the IDE help you by pressing a single button.
Doesn't the GWT Eclipse plugin provide the debugging capabilities? GWT debugging in eclipse is the most useful tool ever.
There also is a plug-in for MyEclipse that gives you a Matisse-like drag and drop Toolbox for GWT.
For Netbeans we have the GWT4NB plug-in, which offers among other things good debugging and code completion which works also for .ui.xml files.
OK ...
GWT RPC - With Google plugin, it does reduce the tedium verifying the interface RPC interface-async pair declaration.
UiBinder. Each uibinder set is a pair of files: The ui template and the template bean. The plugin helps me verify the correspondence of uifields in the template and the template bean. Then there are #uifactory, #uifield(provided=true).
You can declare another an "external" bean (a java code other than its template bean) using ui:with in the ui template. With that you pull in functions from the bean to provide values for your gwt widget attributes. The plugin provides me with auto-complete/verification of functions that are visible in ui:with bean.
Of course, the plugin provides the compiler too, which compiles the java code into javascript.
The debugger which works with the client-side. Imagine how the plugin works when we step the debugger on the client code which is compiled to javascript.
The run config, which automatically fills in the blanks, the args and params. I would hate writing a gwt launch config by myself.
Without the plugin, GWT development would be rather tedious.

Categories

Resources