use of org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation in project bndtools by bndtools.
the class NewTypeWizardPage method createInheritedMethods.
/**
* Creates the bodies of all unimplemented methods and constructors and adds them to the type. Method is typically
* called by implementers of <code>NewTypeWizardPage</code> to add needed method and constructors.
*
* @param type
* the type for which the new methods and constructor are to be created
* @param doConstructors
* if <code>true</code> unimplemented constructors are created
* @param doUnimplementedMethods
* if <code>true</code> unimplemented methods are created
* @param imports
* an import manager to add all needed import statements
* @param monitor
* a progress monitor to report progress
* @return the created methods.
* @throws CoreException
* thrown when the creation fails.
*/
protected IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, ImportsManager imports, IProgressMonitor monitor) throws CoreException {
final ICompilationUnit cu = type.getCompilationUnit();
JavaModelUtil.reconcile(cu);
IMethod[] typeMethods = type.getMethods();
Set<String> handleIds = new HashSet<String>(typeMethods.length);
for (int index = 0; index < typeMethods.length; index++) handleIds.add(typeMethods[index].getHandleIdentifier());
ArrayList<IMethod> newMethods = new ArrayList<IMethod>();
CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaProject());
settings.createComments = isAddComments();
ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setResolveBindings(true);
parser.setSource(cu);
CompilationUnit unit = (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1));
final ITypeBinding binding = ASTNodes.getTypeBinding(unit, type);
if (binding != null) {
if (doUnimplementedMethods) {
AddUnimplementedMethodsOperation operation = new AddUnimplementedMethodsOperation(unit, binding, null, -1, false, true, false);
operation.setCreateComments(isAddComments());
operation.run(monitor);
createImports(imports, operation.getCreatedImports());
}
if (doConstructors) {
AddUnimplementedConstructorsOperation operation = new AddUnimplementedConstructorsOperation(unit, binding, null, -1, false, true, false);
operation.setOmitSuper(true);
operation.setCreateComments(isAddComments());
operation.run(monitor);
createImports(imports, operation.getCreatedImports());
}
}
JavaModelUtil.reconcile(cu);
typeMethods = type.getMethods();
for (int index = 0; index < typeMethods.length; index++) if (!handleIds.contains(typeMethods[index].getHandleIdentifier()))
newMethods.add(typeMethods[index]);
IMethod[] methods = newMethods.toArray(new IMethod[0]);
return methods;
}
Aggregations