JET FAQ What is JMerge?

Question

What is JMerge?

Answer

JMerge is a technology developed by the Eclipse Modeling Framework (EMF) so that code generators that produce Java code can allow for user modification of that code, while still permitting the code generator to be re-executed.

Using JMerge creates a contract between the Code Generator and the Consumer. The actual contract depends on which JMerge rules are used. Here is a description of the contract for the JMerge rules provided with EMF.

On code generation execution/re-execution

The Code Generator shall only update Java elements with an intact @generated tag.

The Code Generator may remove Java elements with an intact @generated tag if those elements no longer exist in the input to the code generator. The Consumer must be aware that such removal can result in compilation errors in the Consumer's code.

While editing generated Java code

The Consumer may add new Java elements without worry that the Code Generator will overwrite them. The Consumer must be aware that a subsequent change in the Code Generator's input may cause the Code Generator to fail to write a Java element with the same signature as the new element. JMerge provides no feedback that such a failure has occured.

The Consumer may modify generated Java elements (and ensure that the code generator will not revert or modify them) by removing or defacing the @generated javadoc tag on the element. Defacing is a good practice, as it clearly indicates the Consumer's intent to modify generated code. Common ways of defacing the @generated tag are to change it to '@generated not' or '@!generated'.