private FunctionDeclaration makeAllocatingConstructor ( MethodDeclaration method , boolean releasing ) { assert method . isConstructor ( ) ; ExecutableElement element = method . getExecutableElement ( ) ; TypeElement declaringClass = ElementUtil . getDeclaringClass ( element ) ; String name = releasing ? nameTable . getReleasingConstructorName ( element ) : nameTable . getAllocatingConstructorName ( element ) ; FunctionDeclaration function = new FunctionDeclaration ( name , declaringClass . asType ( ) ) ; function . setLineNumber ( method . getLineNumber ( ) ) ; function . setModifiers ( ElementUtil . isPrivate ( element ) ? Modifier . PRIVATE : Modifier . PUBLIC ) ; function . setReturnsRetained ( ! releasing ) ; TreeUtil . copyList ( method . getParameters ( ) , function . getParameters ( ) ) ; Block body = new Block ( ) ; function . setBody ( body ) ; StringBuilder sb = new StringBuilder ( releasing ? "J2OBJC_CREATE_IMPL(" : "J2OBJC_NEW_IMPL(" ) ; sb . append ( nameTable . getFullName ( declaringClass ) ) ; sb . append ( ", " ) . append ( nameTable . getFunctionName ( element ) ) ; for ( SingleVariableDeclaration param : function . getParameters ( ) ) { sb . append ( ", " ) . append ( nameTable . getVariableQualifiedName ( param . getVariableElement ( ) ) ) ; } sb . append ( ")" ) ; body . addStatement ( new NativeStatement ( sb . toString ( ) ) ) ; return function ; }
Create a wrapper for a constructor that does the object allocation .