getMethods.add(method);
/*
* the statement
*/
org.eclipse.jdt.core.dom.Block block = ast.newBlock();
MethodInvocation methodInvocation = ast.newMethodInvocation();
methodInvocation.setName(ast.newSimpleName("get"));
/*
* the parameter
*/
String thePropertyKey = method.getName().toString().substring(3);
StringLiteral literal = ast.newStringLiteral();
literal.setLiteralValue(thePropertyKey);
methodInvocation.arguments().add(literal);
/*
* the return statement
*/
ReturnStatement returnStatement = ast.newReturnStatement();
returnStatement.setExpression(methodInvocation);
block.statements().add(returnStatement); //add the return statement to the block
newMethod.setBody(block); // add the block to the method
newType.bodyDeclarations().add(newMethod); //add the method to the type
}
if (method.getName().getIdentifier().startsWith("set")) {
List<SingleVariableDeclaration> parameters = method.parameters();
if (parameters.size() != 1)
continue;
setMethods.add(method);
MethodDeclaration newMethod = copyMethodDeclaration(newType.getAST(), method);
SingleVariableDeclaration oldParameter = parameters.get(0);
SimpleName paramName = oldParameter.getName();
/*
* the statement
*/
org.eclipse.jdt.core.dom.Block block = ast.newBlock();
MethodInvocation methodInvocation = ast.newMethodInvocation();
methodInvocation.setName(ast.newSimpleName("set"));
/*
* the parameters
*/
String thePropertyKey = method.getName().toString().substring(3);
StringLiteral literal = ast.newStringLiteral();
literal.setLiteralValue(thePropertyKey);
methodInvocation.arguments().add(literal);
methodInvocation.arguments().add(paramName.copySubtree(newMethod.getAST(), paramName));
ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
block.statements().add(expressionStatement);
newMethod.setBody(block); // add the block to the method