ifndef [message #189412] |
Sun, 12 December 2004 10:50  |
Eclipse User |
|
|
|
Hello,
I have a j2me project (I use eclipseME). This project is targeted at
different devices, resulting in #ifndef statements in critical places in the
code. I use antenna to preprocess the sources and then compile them, but I
cannot enjoy the benefits of eclipse (e.g., having errors shown while I
code), because it gets confused by the #ifndef statements. Is there a plugin
that allows eclipse to use dynamic definitions, so that the code is
continuously compiled correctly (continuously preprocessed)?
|
|
|
Re: ifndef [message #189710 is a reply to message #189412] |
Wed, 15 December 2004 04:02  |
Eclipse User |
|
|
|
Originally posted by: rabe42.web.de
Hello Zohar,
Zohar schrieb:
> Hello,
> I have a j2me project (I use eclipseME). This project is targeted at
> different devices, resulting in #ifndef statements in critical places in the
> code. I use antenna to preprocess the sources and then compile them, but I
I think, your problems are due to a small misconception about Java. The
intention of the language designer was to provide an alternative for
#ifndef orgies known from C/C++ projects. They decide to introduce
interfaces. Using interfaces, so called template methods and factories
(look at the famous GoF book) will help you to factor out the platform
dependencies into differen classes. This will help to improve the
readability, flexability and testability of your code.
This
E.g.:
public void myFoo() {
doTheCommonBegin();
#ifndef A
doTheAThing();
#else
doTheOtherThing();
#endif
doTheCommonEnd();
}
Refactor to the Java way of doing this:
// 1. The interface for the platform specific methods:
public interface TheThing {
public void do();
// ... further methods
}
// 2. The implementation of the platform specific methods:
public class TheAThing {
public void do() {
doTheAThing();
}
}
public class TheOtherThing {
public void do() {
doTheOtherThing();
}
}
// 3. The factory, the only point where we decide the platform.
public class TheThingFactory {
private TheThing _theThing;
static {
// Decide on which platform we are...
if (onA) {
_theThing = new TheAThing();
}
else {
_theThing = new TheOtherThing();
}
}
public static TheThing getTheThing() {
return _theTing;
}
}
// 4. The templated method
public void myFoo() {
doTheCommonBegin();
TheThingFactory.getTheThing().do();
doTheCommonEnd();
}
The econimics of this approach is better, if the platform specific code
is complex. Or, if you have a large number of different methods.
> cannot enjoy the benefits of eclipse (e.g., having errors shown while I
> code), because it gets confused by the #ifndef statements. Is there a plugin
> that allows eclipse to use dynamic definitions, so that the code is
> continuously compiled correctly (continuously preprocessed)?
I know this was not exactly the answer you've expected, but the best
advice I can give to you. If you follow this track, the problems with
the eclipse platform will be vanished. I promise ;-)
Regards,
Ralf
|
|
|
Powered by
FUDForum. Page generated in 0.03263 seconds