Peter Friese

Developer Advocate / Mobile Developer / Public Speaker

Generated or Not, That Is the Question...

Finally, I ventured into the world of EMF. One of the biggest challenges with EMF is to tell which classes and methods have been generated by a code generator and which ones have been written by a human being. Of course, EMF supports the @generated marker to tell the generator which classes and methods have been generated (and may thus be re-generated and overwritten), but still it is difficult for a human reader to tell the generated parts from the non-generated by just having a quick look at the code.

Some time ago I blogged about Eclipse color decorators – a great way to visually express certain charcteristics of your code. Wouldn’t it be great to use color decorators to highlight the non-generated parts of your EMF code? By just looking at the package explorer, you could see which are the methods you coded manually.

Enter emf.bits! This is a handy little plug-in that allows you to highlight generated and non-generated code using two different colors. Highlighting takes place in structured viewers (e.g. package explorer and outline): All elements that have been marked as @generated will be displayed in different color (blue by default, but you can adjust this using the preference dialog). The same goes for elements that have been marked as @generated NOT – these will be displayed in different color (red by default). I adjusted the preference so that all generated code is displayed in gray, whereas non-generated code is displayed in black. This way, generated code is less visible than non-generated code and I can focus on the non-generated code:

Click to see larger image.