Barmaley
Barmaley

Reputation: 16363

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

Upvotes: 2

Views: 2306

Answers (4)

Michael Kay
Michael Kay

Reputation: 163342

Eleven years on from this question, there seems to be the Manifold preprocessor which integrates with the Java compiler and with IntelliJ via a plugin.

Upvotes: 0

sblundy
sblundy

Reputation: 61414

You may want to look into configuring different artifacts for the various versions of the lib and then restructuring your code to isolate the version specific code in subclasses/components that are only including in the relevant artifact. This may be impractical, especially in an existing project, but less trouble than writing a plugin. Maven has similar functionality via classifiers.

Upvotes: 3

sblundy
sblundy

Reputation: 61414

Java programmers don't normally use preprocessers the way C/C++ do. Other techniques and systems have been developed like annotations, code generation, etc. Perhaps if you let us know what problem you're trying to solve, someone will know of a java friendly way to help.

Edit: I think the consensus is that you're looking at writing an IntelliJ plugin

Upvotes: 0

SyntaxT3rr0r
SyntaxT3rr0r

Reputation: 28293

(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 ;)

Upvotes: 6

Related Questions