How to create new classes with IntelliJ Plugin API? - java

I am very new to IntelliJ Plugin Programming and mainly got to it because my current project requires me to do the same steps again and again and only having small differences.
Becauste this takes a lot of time, I decided to take like some hours once to create a plugin which does the most work for me and then save a lot of time when having these steps again.
My question is basically how I can create new class files programmatically with the IntelliJ Plugin API. I already found out how to get the content of the currently open and in editor selected file and also how to change the content, but now how to create completely new files in a specific package.
To be honest, I think there must be something in the documentation but I already wasted like 1 hour for googling without any success. So I hope some of you guys are already experienced in creating plugins for IntelliJ Platform and maybe you can send me a good handbook or reference. I don't think that I have to write a lot of plugins but sometimes, they can really help.
Thanks in advance.

Please see Meo's tip for com.intellij.ide.actions.CreateClassAction#doCreate.
The code does the following:
return JavaDirectoryService.getInstance().createClass(dir, className, templateName, true);
And from here we can see different signatures in JavaDirectoryService
Perhaps this one might be relevant:
public abstract PsiClass createClass(#NotNull PsiDirectory dir, #NotNull String name) throws IncorrectOperationException;

Related

Extension to generate Javadoc file in Visual Code

I want to create a documentation file of my code. I've added the Javadoc comment in every public method I have. If I use other IDE, probably there is a menu to generate it, but unfortunately I use Visual Code.
Is there a way to generate Javadoc file in Visual Code? I only find one extension, with 2 thousands downloads but its not working. The name is Javadoc-Generator
I have tried to run using javadoc command in terminal, but it is not recognized. Do I need to install additional file?
Well firstly thanks for the good question and now i'm going to try to help you with your problem. I searched for an plug in of Javadoc for Visual Studio which is Javadoc Tools with this plug in you can create coments just selecting where you want to make the comments, also you can export your comments and the best thing it's free. I tried this for one of my programmes and it works for me. Definitly i recommend you this, try it and i hope i helped you with your problem.
Selecting where i want to create the comments
Final result
For Javadoc-Generator. In the documentation state "This generator will use the Javadoc located in the JDK referenced in your JAVA_HOME." Make sure you have JAVA_HOME set in your Environment Variables.

Java: Simple Validation API Validation Strategy Change

This is in reference to the question posted at org.netbeans.validation.api.ui.ValidationGroup.add() - How to specify ValidationStrategy?
I am trying to do something similar. Please guide me on what needs to be changed and where. I went through the given links but couldn't find the relevant info.
P.S.: Asking in a separate question because I can't comment on the original one due to lack of reputation points.
Regards
Uday
I found out what was required.
Check out the code from their repository (https://svn.kenai.com/svn/simplevalidation~src) and open ValidationAPI as a project in Netbeans (or whatever IDE you're using).
To change the default validation strategy you'll need to make the changes in ValidationGroup and SwingValidationGroup classes under org.netbeans.validation.api.ui and org.netbeans.validation.api.ui.swing respectively.
In these classes find ValidationStrategy.DEFAULT and replace it with the strategy you want (INPUT_VERIFIER, ON_FOCUS_LOSS, ON_CHANGE_OR_ACTION).
Build the project to generate a new jar and incorporate that jar in your own project.
That's it.

How do I use BIRT in an RCP application without using the BIRT runtime?

Here's what I'm trying to do: I have an eclipse plugin that contains certain data (actually Strings representing the file structure of a project). These Strings are acesssible over usual getters and are stored in Lists. I now want to put these Strings into BIRT to get a pdf or html. From what I found out so far, I will need to integrate BIRT in the plugin somehow (I do not want to have to select a data source and data set and so on like you'd have to using BIRD's UI - this should happen automatically in my code). Further, I wouldn't like to use the BIRT runtime, but only the normal jars you get from the common installation way over eclispe->help->istall new software. Is that even possible without the runtime and without digging really deep in the BIRT source files? I am actually looking for something like:
Datasource source = new DataSource();
/* put somehow the strings into the data source */
DataSet set = new DataSet();
/* connect set to source, create layout and so on */
This is the mthod I'm currently working in:
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
/* the strings are accessible over "fs" */
FileStructure fs = extractFileStructure(event);
/* TODO: Implement the layout */
}
I hope my question's clear enough :).
Alright, I managed to answer this question myself, so I'm going to answer it in case someone has the same problem.
Actually my question was slightly silly because I didn't really know what I was talking about. I don't think it's very wise to try to implement this without using the BIRT runtime. What I was talking about was the installation of the BIRT runtime environment (where you had to set a HOME variable and so on) which was only necessary before version 3.7 of BIRT. Now you can just skip this step which is exactly what I wanted. Actually it's not such a big deal. All the information I needed could be found in this eclipse tutorial. But I recommend you not to copy the code straight away because the tutorial seems to be a little older, so some of the methods used there are deprecated in the current BIRT version (they actually might have been disappeared if you read this post later).
I hope that this was/is helpful for some of you. :)

Sphinx4 Beta API Problems With Eclipse

I'm trying to set up a simple helloworld demo with Sphinx 4.0 (which is apparently a beta?) I downloaded the source and added it as source to Eclipse, but the problem is, it doesn't recognize a lot of the classes. I've been looking, and as far as I can tell, the classes it wants just aren't there! For example, the line:
import javax.speech.Central;
throws a compiler error, saying something about how the import couldn't be resolved. Is this a part of a bigger API I was supposed to download before trying to do Sphinx4? It didn't say anything about any other API but I'm open to the possibility.
If you want, I can post a list of all the imports that can't be resolved, I will, but that means looking through all the code which is kind of a pain. I have a hunch that I need to download the JSAPI, but I don't know which implementation would be good for Sphinx4.
Links to Sphinx4 downloads:
http://sourceforge.net/projects/cmusphinx/files/sphinx4/1.0%20beta6/
http://cmusphinx.sourceforge.net/
EDIT: In addition, I've found a few lines that I think might mean I need to download JUnit? Again, I'm not totally sure how to set this up.
The great thing about this site is that the simple act of typing out a question and nervously analyzing it before finalizing any revisions (because, after all, someone WILL read this!) 95% of the time I answer my own question within 5 minutes of posting it.
Anyways, the solution was simple, I downloaded junit4-10.jar and jsapi.jar and added them to my Java build path. Then, I got more errors, and I said TO HECK with building from the source (which I was doing with sphinx4 here) and I just downloaded the already-built library and it works great. Got the HelloWorld I wanted!

Can I include code from one file to the next, similar to Includes in html

Ok, Please be gentle and kind. I am taking an Android Programming class in college and its our teachers first semester so he is learning as we are... Nothing against him, he's a good teacher, just doesn't know the answer.
I don't know how to put this in Android/java language so here goes...
Is there a way to use something similar to Includes, in web design, in Android. I am looking to add similar java code from one activity to the next, can i make a file that if i change this one file it will change in all the files its included it.
I know it can be done with the XML files but i couldn't find anything to show that it can be done in the actually coding... but then again i don't know the correct terminology. Please any help would be great. And thank you for taking the time to read and answer me. I apologize if this was somewhere else, I just couldn't find it.. Thanks again
Put anything you wish to "include" in Java classes, then import them. http://leepoint.net/notes-java/language/10basics/import.html
Android Programming class! I would've loved that in University...
Regardless, if you're using Eclipse for your IDE, it should pickup any changes from your java imports automatically. If you choose to refactor other java classes within your project, a rename for example (with "Update All References"), will update all references to that class across your project.
You could also use Maven (dependency management) to pull the latest third-party (or other) .jars at build time, if that's applicable to what your needs are.
:)

Categories

Resources