Refactoring template

refactors the template mechanism:

* introduces an AbstractTemplate that contains generic template code
* clarifies the responsibilities of Template and TemplateParameter
* reifies the responsibility of Substitution.insertAll as an ExtensionTemplate
* changes SubstitutionVisitor (allows null targetType, handles cloning of parameters, better variable name for factory)

+ new test cases