[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools.jdt] Re: ASTRewrite for new method creation??
|
There have an easy way to achieve your goals:
ICompilationUnit unit = JavaCore.createCompilationUnitFrom(IFile);
IType type = unit.getType("MyClass");
type.createMethod("public static void main() {}", null, true, monitor)
Prashanto Chatterjee wrote:
Hi,
I have used JDT and specifically AST to generate a Java source file. Now I
want to add a new method to this Java source file. The method name is taken
as input from the user and the method has a custom signature.
I have seen examples to add a package declaration and imports using
ASTRewrite. Now my question to the group is whether I do a new method
creation using ASTRewrite? Which is the preferred way to create a new method
in an existing Javas source file?
Regards,
Prashanto