ripped off Mak's code for Pcl2's CodeGenerator.java