eclipse jdt automatic method stub generation
开发者_StackOverflowi am creating java source files using eclipse JDT & AST. There are cases that generated source files are implementing or extending something.
is it possible to add method stubs automatically before actually creating them? like invoking this "Add unimplemented methods" quick fix via JDT.
i know i can add them myself via those API's, but i want to tweak.
i found solution after a couple of hours; code is roughly like this. there are also many good code manipulation classes in this package "org.eclipse.jdt.internal.corext.codemanipulation.*"
ICompilationUnit createCompilationUnit = getItSomeHow();
RefactoringASTParser parser1 = new RefactoringASTParser(AST.JLS3);
CompilationUnit unit = parser1.parse(createCompilationUnit, true);
AbstractTypeDeclaration declaration = (AbstractTypeDeclaration) ASTNodes.getParent(
NodeFinder.perform(unit, createCompilationUnit.getTypes()[0].getNameRange()),
AbstractTypeDeclaration.class);
ITypeBinding binding = declaration.resolveBinding();
IMethodBinding[] overridableMethods = StubUtility2.getOverridableMethods(unit.getAST(), binding, false);
AddUnimplementedMethodsOperation op = new AddUnimplementedMethodsOperation(unit, binding,
null/* overridableMethods */, -1, true, true, true);
精彩评论