private FunctionDeclaration makeFunction ( MethodDeclaration method ) { ExecutableElement elem = method . getExecutableElement ( ) ; TypeElement declaringClass = ElementUtil . getDeclaringClass ( elem ) ; boolean isInstanceMethod = ! ElementUtil . isStatic ( elem ) && ! ElementUtil . isConstructor ( elem ) ; FunctionDeclaration function = new FunctionDeclaration ( nameTable . getFullFunctionName ( elem ) , elem . getReturnType ( ) ) ; function . setJniSignature ( signatureGenerator . createJniFunctionSignature ( elem ) ) ; function . setLineNumber ( method . getLineNumber ( ) ) ; if ( ! ElementUtil . isStatic ( elem ) ) { VariableElement var = GeneratedVariableElement . newParameter ( NameTable . SELF_NAME , declaringClass . asType ( ) , null ) ; function . addParameter ( new SingleVariableDeclaration ( var ) ) ; } TreeUtil . copyList ( method . getParameters ( ) , function . getParameters ( ) ) ; function . setModifiers ( method . getModifiers ( ) & Modifier . STATIC ) ; if ( ElementUtil . isPrivate ( elem ) || ( isInstanceMethod && ! ElementUtil . isDefault ( elem ) ) ) { function . addModifiers ( Modifier . PRIVATE ) ; } else { function . addModifiers ( Modifier . PUBLIC ) ; } if ( Modifier . isNative ( method . getModifiers ( ) ) ) { function . addModifiers ( Modifier . NATIVE ) ; return function ; } function . setBody ( TreeUtil . remove ( method . getBody ( ) ) ) ; if ( ElementUtil . isStatic ( elem ) || ElementUtil . isDefault ( elem ) ) { // Add class initialization invocation, since this may be the first use of this class. String initName = UnicodeUtils . format ( "%s_initialize" , nameTable . getFullName ( declaringClass ) ) ; TypeMirror voidType = typeUtil . getVoid ( ) ; FunctionElement initElement = new FunctionElement ( initName , voidType , declaringClass ) ; FunctionInvocation initCall = new FunctionInvocation ( initElement , voidType ) ; function . getBody ( ) . addStatement ( 0 , new ExpressionStatement ( initCall ) ) ; } else { FunctionConverter . convert ( function ) ; } return function ; }
Create an equivalent function declaration for a given method .