With any luck, we now have no compilation problems. Two tasks remain before we can move on: fixing the @ThisWasAProperty fields, and changing the Main() method into something Java likes. The second task is trivial. But how do you encapsulate a few hundred fields, without manually going over each of them?
You script it. Eclipse has a Refactor Script1 mechanism! You can’t yet tell it “Encapsulate all my fields”, but you can write a bit of code to tell it for you. Ideally, we’d have a library that takes all the refactoring data and produces a script, but we don’t, or at least I couldn’t find it. Instead, we need to generate the script (Exported from your Refactoring History), and with some trials-and-errors understand how to write commands you need for your fields. It’s safe to make errors in Eclipse, since not only does it keep a very powerful Undo engine, but also a complete history of every file in the projects. The Preview and Cancel Script are also good.
We use reflection to go over all the classes we’ve ported, and seek out public fields with the @ThisWasAProperty annotation. For each of these fields, we write the script for encapsulating it. If we give it a name of an existing method, it will use the method and not generate anything. If a getter / setter is missing, we don’t wish to generate a getter either – but we have no choice. So we give it a very specific name (Like __REMOVE_METHOD_getFoo), and later remove it.
You should refactor out the method you’ve just created (“Inline method”), and the fields. I wasn’t able to inline the methods, but the fields were easy: just move them to some dumpster class (Again, in the generated script) and let them rot. The methods, now that they all have a special marker in their name (And are all one-liners) are easily rid of with regexp:
public (\w*) (__REMOVE_\w*)\(\)\{([^\])*}\} |
==> | Leave empty. |
Now everything still builds: The fields we’ve moved aren’t used anywhere, because we’ve made them. We’ve also made the only methods that might use them (getters/setters that didn’t exist), but we just deleted them all.
Congratulations. The application part is done – now all we need is the API to make it work.