How to create eclipse plugin to auto create the serialization code read/writeExternal on existing code java classes?
Steps needed get the class from active tab (and or info on class field info like one in outline window) and generate code for each field, maybe using reflection will also help.
The easiest way is to build upon
org.eclipse.jdt.ui.actions.GenerateMethodAbstractActionthat is used by eclipse to implementGenerateToStringActionandGeneateHashCodeEqualsAction.Basically:
GenerateMethodAbstractActiongenerateCandidates(). You also need to decide if you recurse into superclass or not.MethodDeclarations for readExternal/writeExternal methods using data collected in step 2.MethodDeclarations into anIWorkspaceRunnablethat applies them as edits (seeGenerateToStringOperation) and return it fromcreateOperation(...).The code required is rather long and involved so it's better to follow the two existing action classes for guidance.
If you choose to put it somewhere else than "Source" menu, you can discover the active editor with
See also: