@Override public MethodSource<O> setBody(final String body) { if (body == null) { method.setBody(null); } else { List<Problem> problems = Roaster.validateSnippet(body); if (problems.size() > 0) { throw new ParserException(problems); } String stub = "public class Stub { public void method() {" + body + "} }"; JavaClassSource temp = (JavaClassSource) Roaster.parse(stub); List<MethodSource<JavaClassSource>> methods = temp.getMethods(); Block block = ((MethodDeclaration) methods.get(0).getInternal()).getBody(); block = (Block) ASTNode.copySubtree(method.getAST(), block); method.setBody(block); } return this; }
@Override public MethodSource<O> setBody(final String body) { if (body == null) { method.setBody(null); } else { List<Problem> problems = Roaster.validateSnippet(body); if (problems.size() > 0) { throw new ParserException(problems); } String stub = "public class Stub { public void method() {" + body + "} }"; JavaClassSource temp = (JavaClassSource) Roaster.parse(stub); List<MethodSource<JavaClassSource>> methods = temp.getMethods(); Block block = ((MethodDeclaration) methods.get(0).getInternal()).getBody(); block = (Block) ASTNode.copySubtree(method.getAST(), block); method.setBody(block); } return this; }