Search code examples
javaidepreprocessorintellij-idea

Java preprocessing support in Intellij IDEA


Does anyone know about Java preprocessing support in Intellij IDEA? Probably there are some 3rd party plugins?

Just for example: here's a piece of Java code written for Netbeans (which supports preprocessing):

//#if JSR82
//# import javax.bluetooth.*;
//#endif

Netbeans built-in preprocessor parses those //# keys and comments or uncomments pieces of code depending on defined preprocessor keys.

I'd expect something similar in Intellij IDEA.

Thanx in advance


Solution

  • (this is too long for a comment, hence the answer that isn't really an answer but more of a comment).

    I've worked extensively with Java pre-processors and IntelliJ IDEA. I don't know of any plugin/add-on allowing to work with pre-processors (but that would be great).

    Besides that, invariably when a discussion comes on Java and preprocessors, people will point out that "such a thing doesn't exist".

    Yet of course several of these exists. For example here's a cool Nokia (you may have heard of that company, they produce a few Java cellphones) article called: "Java ME Porting using preprocessor directives".

    Truth is: Java never delivered its WORA promise, especially not in the J(2)ME world.

    http://wiki.forum.nokia.com/index.php/Java_ME_Porting_using_preprocessor_directives

    Another very valid reason to use custom (sadly custom) preprocessors and code-generators can be seen in things like the (excellent) Trove API source code: basically it's your only way to avoid repeating the same code for all the Java primitives, etc.

    I've also heard about people wanting to generate different versions of the "same" .jar, without putting all the code in the various .jars produced. Sure, this can be done in a "Java friendly way" using amazing workarounds... But some pre-processing saves the day too in such a case.

    Point is: there are valid case for Java pre-processors. I tend to like the Nokia one because it's kinda hard to argue versus that ;)