conditional compiler directives

Hi,

I don't know how to define conditional compiler directives in IDEA. I need to derive a class in dependence on some condition.
For example:

#if TEST
public class MyClass extends SubClass1
#else
public class MyClass extends SubClass2
#endif
{
// Implementation can contain contition testing.
}

I it possible?

Thank you.

-- likeapear


12 comments
Comment actions Permalink

This is possible in C, but not in Java

--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

"likeapear" <likeapear@centrum.cz> wrote in message news:c48ok5$gep$1@is.intellij.net...
Hi,

I don't know how to define conditional compiler directives in IDEA. I need to derive a class in dependence on some condition.
For example:

#if TEST
public class MyClass extends SubClass1
#else
public class MyClass extends SubClass2
#endif
{
// Implementation can contain contition testing.
}

I it possible?

Thank you.

-- likeapear



0
Comment actions Permalink

For that purpose, you should use some preprocessor. You could use the
one in Antenna (http://antenna.sf.net), but sometimes the source files
wouldn't be syntactically correct java files. This prohibits the
complation from IDEA, but still you could use the Ant integration and
most of the advanced code analysys features still work.

Although you should have a good reason to do this (in fact the only
valid reason I can think about is J2ME or some other constrained
applicatiion.)

HTH,
dimiter

0
Comment actions Permalink

I think that it does not depend on programming language, but on IDE. It can filter code by the condition and pass it to the compiler.

BTW: Posted example works in MS Visual J++ (IDE for java language).

-- likeapear



"Eugene Zhuravlev" <jeka@intellij.com> pí?e v diskusním pøíspìvku news:c48qma$cb1$1@is.intellij.net...

This is possible in C, but not in Java

--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Hi,

In this case your example uses J# (not Java :)

likeapear wrote:

I think that it does not depend on programming language, but on IDE. It can filter code by the condition and pass it to the compiler.

BTW: Posted example works in MS Visual J++ (IDE for java language).

-- likeapear



"Eugene Zhuravlev" <jeka@intellij.com> pí?e v diskusním pøíspìvku news:c48qma$cb1$1@is.intellij.net...

>>This is possible in C, but not in Java
>>
>>--
>>Best regards,
>>Eugene Zhuravlev
>>Software Developer
>>JetBrains Inc.
>>http://www.jetbrains.com
>>"Develop with pleasure!"




--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Example comes from my old project written in MS Visual J++ (not J#). I know that these conditional defines (which can be used MS J++ or J#) produces non java compatible code. But I think that it can simplify programing (in some cases) when you know that your project will be always developed in one IDE (for example developing plugins for IDEA).

Thank all for answers.

-- likeapear


"Maxim Mossienko" <Maxim.Mossienko@jetbrains.com> pí?e v diskusním pøíspìvku news:c4912h$sum$1@is.intellij.net...

Hi,

In this case your example uses J# (not Java :)


0
Comment actions Permalink

Why do you want to do this? Just curious...

The usual way to handle this in Java is to have two separate classes which
each extend the relevant base class and delegate to a third class that
contains all common functionality.

Hope that helps,
Vil.
--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0
Comment actions Permalink

On 29-03-2004 11:00, likeapear wrote:

I don't know how to define conditional compiler directives in IDEA. I
need to derive a class in dependence on some condition.
For example:

#if TEST
public class MyClass extends SubClass1
#else
public class MyClass extends SubClass2
#endif
{
// Implementation can contain contition testing.
}

I it possible?


You could use a special ANT task and use ANT to compile your sources.
Then you have the additional advantage that you don't need IDEA to
compile (which doesn't have conditional compiler directives).
ANTENNA looks nice for examle: http://antenna.sourceforge.net/#preprocess
I have never used ANTENNA myself though, so I can't comment on its quality.

Bas

0
Comment actions Permalink

Oops, I didn't see Dimiter's reply...

On 29-03-2004 15:12, Bas Leijdekkers wrote:

On 29-03-2004 11:00, likeapear wrote:

>> I don't know how to define conditional compiler directives in IDEA. I
>> need to derive a class in dependence on some condition.
>> For example:
>>
>> #if TEST
>> public class MyClass extends SubClass1
>> #else
>> public class MyClass extends SubClass2
>> #endif
>> {
>> // Implementation can contain contition testing.
>> }
>>
>> I it possible?


You could use a special ANT task and use ANT to compile your sources.
Then you have the additional advantage that you don't need IDEA to
compile (which doesn't have conditional compiler directives).
ANTENNA looks nice for examle: http://antenna.sourceforge.net/#preprocess
I have never used ANTENNA myself though, so I can't comment on its quality.

Bas

0
Comment actions Permalink

likeapear wrote:

Example comes from my old project written in MS Visual J++ (not J#).


Even J++ isn't "Java" - which is part of the cause of all the legal
disputes between Sun and Microsoft. MS modified the language to suite
themselves - such as adding conditionals and stuff... Not sure what
else they changed thou.

Mark

0
Comment actions Permalink

I think that is the problem.

It isn't that Java does not have this feature it is that J++ does. He
learned J++, but never learned Java. I have been using Java
professionally since 1993 and have never needed this type of
functionality.

BTW, I did NOT come from a C background.

Norris Shelton
Sun Certified Java Programmer




Vilya Harvey wrote:

Why do you want to do this? Just curious...

>

The usual way to handle this in Java is to have two separate classes
which each extend the relevant base class and delegate to a third
class that contains all common functionality.

>

Hope that helps,
Vil.

0
Comment actions Permalink

+I have been using Java
professionally since 1993 and have never needed this type of
functionality. +

eh, that's a year before Gosling and others even thought of it ;)

0
Comment actions Permalink

You are correct. Someone was talking to me and I thought 8 and hit 3. Doh.

1998.

Norris Shelton
Sun Certified Java Programmer




M. J. Milicevic wrote:

>+I have been using Java
>professionally since 1993 and have never needed this type of
>functionality. +
>
>eh, that's a year before Gosling and others even thought of it ;)
>
>

>

0

Please sign in to leave a comment.