IDEA - Custom Errors - java

While working on my code I was reminded of just how much IDEA does for me. This gave me the idea, what if I could add some custom compile time processing. In which, if my code is invalid it will prompt me with an error. Say for example I left a return type as a null when it should never be null. Basically framework and API checks to reduce production errors.
The problem is I have no clue where to start on doing this. I assume I need to develop a plugin but am having issues finding documentation. If someone would be so kind as to help me get started. As well maybe even provide links to example projects or existing projects (github if possible).
As well I plan to release this plugin as part of a few APIs I develop. So helping me will help others in the long run :)

You can create an intellij plugin that implements custom inspections.
Example here:
https://confluence.jetbrains.com/display/IDEADEV/Inspection+of+Code+Source
The inspections that you create can highlight code red, allow the user to disable them, and also prompt for fixes. Please see intellij plugin development API's for more details.

You can use standard java assertions for this:
https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html

Related

How to avoid endless formatting cycle eclipse vs intellij [duplicate]

Few weeks ago I tried Intellij and I found it really awesome. Now, at my project there are two programmers (including me) using Intellij and few other programmers who are going to keep using Eclipse. Since this project is already very large and it's going to grow a lot, we need to use compatible Code Style and Code Formatting between Intellij and Eclipse. We do not want to have problems when one user edits some file and reformats it before saving. With Eclipse "alone" we used to have some exported configuration, and before anybody starts to work, the first step is just to import this configuration. We already tried to use External Code Formatter, but it didn't work on Intellij 9.
So, I have a bunch of questions here:
Is there any way to import eclipse formatting configuration on Intellij 9?
Anybody could share their experience managing this kind of situation? Do you guys have any other suggestion to manage this situation?
There is an updated plugin for IDEA, called Eclipse Code Formatter:
http://plugins.intellij.net/plugin/?idea&id=6546
I would recommend someone spends the time to configure their IntelliJ's code style to be the same as Eclipse. This will take a little time and effort but once it is done, you can export it just like in eclipse so that any other IDEA users can import it.
You could also search online to see if anyone has already done this and you can simply download the code style config and use it.
The only alternative I can think of would be to find a standardized code style template that is available for both eclipse and IntelliJ, like the Recommended Sun Java Code Style.
There seems to be a plugin for that (emerged from this discussion).

Configure autocomplete in intellij with hamcrest and mockito dsl

I'm wondering if its possible to configure Intellij's smart insert to suggest hamcrest and mockito dsl idioms when in test classes. Really I'm looking for something like eclipse's 'static favorites', so that when I hit ctrl + space or ctrl +shift +space the idioms are present.
In general is it possible to configure autocomplete/smart insert or the suggestions balloon for that matter. I've looked through the settings without much luck but could easily have overlooked something.
I don't think it's possible to tweak the Smart Insert feature, but I was able to create my own Live Templates for Mockito. As IntelliJ was a bit limited about export, I just posted a guide to create them manually.
The page is in french but the most important parts should be understandable for an english speaking reader.
http://blog.arkey.fr/2011/10/21/quelques-live-template-intellij-pour-mockito/
There might be some typo error in the page, also these Live Templates were created on a older version of IntelliJ. Let me know if you encounter issues about them.
And you should be able create your own live templates for Hamcrest. Also did you tried FEST-Assert, I found the API of this library pretty nice to use.
Cheers
In terms Eclipse's favourite imports feature: when using Intellij, have you tried using Alt+Return?
When I use Mockito I just write mock(MyService.class) and then pressing Alt+Return gives me the option to statically import the method Mockito.mock.

GWTP Eclipse plugin generates empty presenters

I'm trying to create a GWTP sample app. There is a really nice screencast, but I have to deal with a problem that didn't appear there (but, according to comments, some more newbies had to deal with errors). I use Eclipse Helios and a plugin suggested here. Do I deal with incompatible versions?
When I generate the WelcomePresenter, there is nothing in WelcomePresenter.java and WelcomeView.java except the package strings. Also nothing is added in ClientGinjector.java and ClientModule.java. I tried to add everything that is needed by myself, but it's a bit hard because, well, I tried to create this app to understand how exactly GWTP works.
Could someone please provide the needed WelcomePresenter.java and WelcomeView.java (the other two classes in the my.pack.client.gin can be seen in the screencast, so it's not really a problem)? And what can be a reason for such Eclipse GWTP plugin behavior?
I'm not sure if it's a OS spesific problem, I tried to generate a presenter using Ubuntu.
UPDATE: I didn't face this problem when installed GWTP plugin in Eclipse using Ubuntu last time, which is great.
If you want to understand GWTP, it is probably better to start without the Eclipse Plugin. It is like saying you want to learn Java and you are already using Eclipse. First things first, start from the beginning.
To create the view and presenters, simply follow the tutorial here.
If you want some more inspiration, take a look at the examples which are fully working projects. It can help to familiarize yourself with the basic GWTP concepts.
If you are still stuck with them, then post code you have so far.
For the error you are seeing in the Eclipse plugin, I would suggest to contact GWTP members directly on their website. I have never used their plugin, so I cannot tell how it works what are the potential issues.

Using Apache Ant APIs in Java program to programmatically build source files

I am looking for good and practical resources that will help me use the Ant APIs effectively. The project website just gives the documentation of the API which is not useful at all. Very few websites seem to give very brief tutorials on the subject.
Is there some resource I am missing out on? How can I use the Ant APIs for simple tasks, without spending hours browsing through them and looking at source code?
Thanks.
(Answers to previously asked questions not helpful - How can i use Apache ANT Programmatically )
As it turns out, the lack of good resources on using the Ant API, is known and intended.
The bottom paragraph of this article from the Ant says -
The question you are probably asking yourself at this point is: How would I know which classes and methods have to be called in order to set up a dummy Project and Target? The answer is: you don't. Ultimately, you have to be willing to get your feet wet and read the source code. The above example is merely designed to whet your appetite and get you started. Go for it!
So this seems to be the only way to make best use of the API.
..Java program to programmatically build source files
If compiling/Jarring is all you need and you can run it in an SDK (as opposed to a plain JRE), look to the JavaCompiler class for compilation. Then use the Jar related classes to build the Jars.
All J2SE. Ant not included, Ant not required.
There is no better manual to understand ANT than : http://ant.apache.org/manual/index.html
I am not sure if you've gone through this link that explains in detail about creating a task. A word of caution, If you're new to ANT, there is no easy way to jump on this tutorial. Better to learn the basics before you come here. Refer above link for a good starting point.

Which javac compiler settings would you expect as default when using an open source library?

I have recently had feedback about my open source library jOOQ's binaries not being delivered with debug information. That was good feedback. I never noticed this, because I never debugged the binaries when running integration tests.
This incident led me to an interesting question:
Which javac compiler settings and options would you choose / expect as default when using an open source library?
Note:
I'm using ant to build, so please refer to the ant javac task API.
I know how the options work. No need to explain me. I'm curious about which ones to choose.
The source is available to my users, and the deliverable can easily be rebuilt, so the user can change their settings if they need to optimise for a special case.
EDIT: I especially appreciate concrete answers referencing concrete options. I know that good work is expected :-)
Enable as much debug info as you possibly can, do not obfuscate, and have a source download corresponding to your binary.
Essentially you should give the best possible conditions for single-stepping through your code in case of problems. A developer may have to identify failing conditions to avoid triggering some code or similar, and in that situation you need all the help you can get.
Well, if one of your library's users encounters a problem, would you prefer a bug report with a stacktrace with line numbers or without? I know which one i would prefer.
I've used lots of java libraries, mainly open source, but a few closed as well. about the only libraries which don't include debug info are the closed source libraries which have been run through an obfuscator.

Categories

Resources