String methodSignature = viewClassName + " get" + viewName + "()";
// prepare AstEditor
IPackageFragment factoryPackageFragment = getPackage(root, clientFactoryPackageName);
ICompilationUnit factoryUnit =
factoryPackageFragment.getCompilationUnit(clientFactoryClassName + ".java");
AstEditor editor = new AstEditor(factoryUnit);
TypeDeclaration factoryPrimaryType = editor.getPrimaryType();
BodyDeclarationTarget bodyDeclarationTarget =
new BodyDeclarationTarget(factoryPrimaryType, false);
// modifying ...
MethodDeclaration methodDeclaration;
if (factoryPrimaryType.isInterface()) {
// interface
String methodHeader = "public " + methodSignature + ";";
methodDeclaration = editor.addMethodDeclaration(methodHeader, null, bodyDeclarationTarget);
} else if (AstNodeUtils.isAbstract(factoryPrimaryType)) {
// abstract class
String methodHeader = "public abstract " + methodSignature + ";";
methodDeclaration = editor.addMethodDeclaration(methodHeader, null, bodyDeclarationTarget);
} else {
// regular class
String methodHeader = "public " + methodSignature;
final List<String> lines = Lists.newArrayList("return null; // FIXME");
methodDeclaration = editor.addMethodDeclaration(methodHeader, lines, bodyDeclarationTarget);
}
editor.resolveImports(methodDeclaration);
editor.saveChanges(true);
// create file from templates
IFile file =
createFileFromTemplate(
packageFragment,
className + ".java",