I want to provide some template for a code generator I am developing. A typical pattern for class is :
public ${class_type} ${class_name} extends ${super_class} implements ${interfaces} {
${class_body}
}
Problem is if super_class is blank or interfaces. I replace extends ${super_class} with empty string. But I get extra spaces. So a class with no super_class and interfaces end up like :
public class Foo { //see the extra spaces before {?
${class_body}
}
I know I can replace multiple spaces with single, but is there any better approach?
EDIT : I received some good answers, but it is not addressing the issue. I cannot specify the template, users will set it. Otherwise, what is the point? What if they like to to have :
public ${class_type} ${class_name} extends ${super_class}
implements ${interfaces} {
${class_body}
}
I guess I can always remove all white spaces between extends ${super_class}
and
implements ${interfaces}
when either one is blank. It will still not be perfect but will be better.