protected void appendCloneFunction ( GenerationContext context , XtendTypeDeclaration source , JvmGenericType target ) { if ( ! isAppendCloneFunctionsEnable ( context ) ) { return ; } for ( final JvmOperation operation : target . getDeclaredOperations ( ) ) { if ( CLONE_FUNCTION_NAME . equals ( operation . getSimpleName ( ) ) ) { return ; } } final ActionPrototype standardPrototype = new ActionPrototype ( CLONE_FUNCTION_NAME , this . sarlSignatureProvider . createParameterTypesForVoid ( ) , false ) ; final Map < ActionPrototype , JvmOperation > finalOperations = new TreeMap <> ( ) ; Utils . populateInheritanceContext ( target , finalOperations , null , null , null , null , this . sarlSignatureProvider ) ; if ( ! finalOperations . containsKey ( standardPrototype ) ) { final JvmTypeReference [ ] genericParameters = new JvmTypeReference [ target . getTypeParameters ( ) . size ( ) ] ; for ( int i = 0 ; i < target . getTypeParameters ( ) . size ( ) ; ++ i ) { final JvmTypeParameter typeParameter = target . getTypeParameters ( ) . get ( i ) ; genericParameters [ i ] = this . _typeReferenceBuilder . typeRef ( typeParameter ) ; } final JvmTypeReference myselfReference = this . _typeReferenceBuilder . typeRef ( target , genericParameters ) ; final JvmOperation operation = this . typeBuilder . toMethod ( source , CLONE_FUNCTION_NAME , myselfReference , null ) ; target . getMembers ( ) . add ( operation ) ; operation . setVisibility ( JvmVisibility . PUBLIC ) ; addAnnotationSafe ( operation , Override . class ) ; if ( context . getGeneratorConfig2 ( ) . isGeneratePureAnnotation ( ) ) { addAnnotationSafe ( operation , Pure . class ) ; } final LightweightTypeReference myselfReference2 = Utils . toLightweightTypeReference ( operation . getReturnType ( ) , this . services ) ; setBody ( operation , it -> { it . append ( "try {" ) ; //$NON-NLS-1$ it . increaseIndentation ( ) . newLine ( ) ; it . append ( "return (" ) . append ( myselfReference2 ) . append ( ") super." ) ; //$NON-NLS-1$//$NON-NLS-2$ it . append ( CLONE_FUNCTION_NAME ) . append ( "();" ) ; //$NON-NLS-1$ it . decreaseIndentation ( ) . newLine ( ) ; it . append ( "} catch (" ) . append ( Throwable . class ) . append ( " exception) {" ) ; //$NON-NLS-1$ //$NON-NLS-2$ it . increaseIndentation ( ) . newLine ( ) ; it . append ( "throw new " ) . append ( Error . class ) . append ( "(exception);" ) ; //$NON-NLS-1$ //$NON-NLS-2$ it . decreaseIndentation ( ) . newLine ( ) ; it . append ( "}" ) ; //$NON-NLS-1$ } ) ; appendGeneratedAnnotation ( operation , context ) ; } }
Append the clone function .