[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[News.eclipse.dsdp.mtj] Re: Preprocessing Discussion

Hello Everybody,

using annotations is an interesting approach, although I see some major problems with it.

- Annotations work only on the field and method level. On the other hand, a lot of decisions are done within methods and it whould be annoying to refactor this into several methods to dispatch to the right ones. This would break up the unit of work from one method to severals just to reflect device fragmentation.

Even in simple examples this can become quite complex, like the provided example:

@Implementations(implementations = { @Implementation(dependsOn = "midp1.0", implementationOwner = "randomIntForMidp1") })
public static int randomInt(int range) {
// default implementation
return random.nextInt(range);
}


        @ImplementationOwner
        private static int randomIntForMidp1(int range) {
                // implementation for MIDP-1.0
                int randomInt = randomInt();
                if (randomInt < 0) {
                        // allow only positive numbers
                        randomInt *= -1;
                }
                return randomInt % range;
        }

Note: the availability of random.nextInt(range) is not dependent on the MIDP version, by the way. This is part of the CLDC specification.
A comment-based preprocessing equivalent is much simpler in comparison:


public static int randomInt(int range) {
   int randomInt ;
   //#if polish.cldc1.0
	randomInt = Math.abs(this.random.nextInt()) % range;
   //#else
	randomInt =  this.random.nextInt(range);
   //#endif
   return randomInt;
}

In more complex examples where there are many branches necessary within one method, this yields up quite a lot. Expressing complex statements like /#if polish.hasCommandKeyEvents || (polish.key.LeftSoftKey.defined && polish.key.RightSoftKey.defined) could be quite verbose in an annotation.

- Imports cant be handled by annotations. E.g. if you want to draw a half transparent rectangle you need the nokia ui api (i.e. a platform specific import). With comment-based preprocessing this is quite simple:

//#if polish.api.nokia-ui
	import com.nokia.mid.ui.*;
//#endif


- The plugin processing the annotated classes need to run in a Java5 VM. This is in contrast to the claim eclipse runs on 1.4. On a sidenote if the developer has installed a Java5 VM he can not use Java 5 features like autoboxing, enums and foreach as the target version for midp is 1.2. J2ME Polish converts Java5 class files on the fly to 1.2 compatible ones.


A good thing about the annotation approach is, that the editor doesnt need to be changed at all for the preprocessing stuff. But full tooling support for preprocessing also includes things like occurrence marking or choosing of target platform (target device) so we have to go into the editor nevertheless. The Mepose plugin of J2ME Polish is a good showcase that this can be done and is ready for inclusion.

Regards,

Richard