Improved the snippet generation by auto-importing needed classes

Fixes #517