private void setFunctionCaller ( MethodDeclaration method , ExecutableElement methodElement ) { TypeMirror returnType = methodElement . getReturnType ( ) ; TypeElement declaringClass = ElementUtil . getDeclaringClass ( methodElement ) ; Block body = new Block ( ) ; method . setBody ( body ) ; method . removeModifiers ( Modifier . NATIVE ) ; List < Statement > stmts = body . getStatements ( ) ; FunctionInvocation invocation = new FunctionInvocation ( newFunctionElement ( methodElement ) , returnType ) ; List < Expression > args = invocation . getArguments ( ) ; if ( ! ElementUtil . isStatic ( methodElement ) ) { args . add ( new ThisExpression ( declaringClass . asType ( ) ) ) ; } for ( SingleVariableDeclaration param : method . getParameters ( ) ) { args . add ( new SimpleName ( param . getVariableElement ( ) ) ) ; } if ( TypeUtil . isVoid ( returnType ) ) { stmts . add ( new ExpressionStatement ( invocation ) ) ; if ( ElementUtil . isConstructor ( methodElement ) ) { stmts . add ( new ReturnStatement ( new ThisExpression ( declaringClass . asType ( ) ) ) ) ; } } else { stmts . add ( new ReturnStatement ( invocation ) ) ; } }
Replace method block statements with single statement that invokes function .