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.GenerateMethodAbstractAction
that is used by eclipse to implementGenerateToStringAction
andGeneateHashCodeEqualsAction
.Basically:
GenerateMethodAbstractAction
generateCandidates()
. You also need to decide if you recurse into superclass or not.MethodDeclaration
s for readExternal/writeExternal methods using data collected in step 2.MethodDeclaration
s into anIWorkspaceRunnable
that 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: