Introduction: Code generation technology is a common way to reduce workload in project construction, but most developers don't know much about the code generation technology under the Eclipse platform. This article details the techniques for code generation under the Eclipse platform, including the use of Eclipse's own template engine JET, the technology used for Eclipse Project generation, and related assistive technologies for code generation under the Eclipse platform. This article will benefit both the software architect and the Eclipse developer.
Eclipse's Java Emitter templates (JET) is an open source template engine that is capable of generating code in the Eclipse Modeling Framework (EMF). The syntax of JET is similar to JSP syntax, but they are in different areas of application.
JET's template file (template files) suffix is generally (*.jet), but it is recommended that the extension take the form of a makefile type plus a jet suffix, such as ***.javajet, ***.textjet, for the type that distinguishes the generated file.
Org.eclipse.emf.codegen.jet.JETEmitter is the core class of jet, and its generate () method accomplishes two functions, transforming the template file into a template execution class (template implementation Class) and then generates the appropriate code or text from the output of the template execution class.
Figure 1. Text Generation flowchart
View artwork (larger)
JET Application Example
This article comes with three sample source code, the three examples described below correspond to the Demo1, Demo2, and Demo3 in the sample source code, and the specific method in the example is written in the Dofinish method of the example source code Samplenewwizard. After you run the sample project in Eclipse application, select Menu Filenewother on the newly running Eclipse platform, select JET Sample Wizards Demo1 to Demo3 in the new dialog box that pops up The dialog box fills in the appropriate content to display the sample effect.
Figure 2. JET Sample Wizards