how can I create a method in a new class with the SDK

Answered

I try to create a new class (it works) but this class doesn't have the created method

The following sourcecode for creating the method doesn't work (the class is created without any method)

private void addTestMethod() {
final PsiElementFactory elementFactory = ...
final PsiMethod testMethod = this.factory.createMethod("...", PsiType.VOID);
testMethod.getBody().add(elementFactory.createExpressionFromText("this.verify()", testMethod));
this.testClass.add(testMethod);
}
0
1 comment

use

codeBlock = com.intellij.psi.PsiJavaParserFacade#createCodeBlockFromText("{ this.verify(); } ", null)

and then testMethod.getBody().replace(codeBlock)

0

Please sign in to leave a comment.