how can I create a method in a new class with the SDK
已回答
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);
}
请先登录再写评论。
use
codeBlock = com.intellij.psi.PsiJavaParserFacade#createCodeBlockFromText("{ this.verify(); } ", null)
and then testMethod.getBody().replace(codeBlock)