/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import { commentsAsBlockFromStringArray } from '../objc-comment-utils' ; import * as Maybe from '../maybe' ; import * as ObjC from '../objc' ; import * as ObjectSpec from '../object-spec' ; import * as ObjectSpecUtils from '../object-spec-utils' ; import * as ObjectSpecCodeUtils from '../object-spec-code-utils' ; function shouldValidateNSCodingConformanceOfAttribute ( supportsValueSemantics , attribute ) { return ( ObjectSpecCodeUtils . shouldCopyIncomingValueForAttribute ( supportsValueSemantics , attribute ) ) ; } function codingValidatorFunction ( supportsValueSemantics , attributes ) { return { comments : commentsAsBlockFromStringArray ( [ 'This unused function ensures that all object fields conform to NSCoding.' , 'The encoding methods do not check for protocol conformance.' , ] ) , name : 'RMCodingValidatorFunction' , parameters : [ ] , returnType : { type : null , modifiers : [ ] } , code : attributes . filter ( ( attribute ) => shouldValidateNSCodingConformanceOfAttribute ( supportsValueSemantics , attribute ) ) . map ( ( attribute ) => `id<NSCoding> ${ attribute . name }_must_conform_to_NSCoding __unused = (${ attribute . type . reference })nil;` ) , isInline : false , isPublic : false , compilerAttributes : [ '__attribute__((unused))' ] } ; } export function createPlugin ( ) { return { additionalFiles : empty ( ) , additionalTypes : empty ( ) , attributes : empty ( ) , classMethods : empty ( ) , fileType : nothing ( ) , forwardDeclarations : empty ( ) , functions : ( objectType ) => [ codingValidatorFunction ( ObjectSpecUtils . typeSupportsValueObjectSemantics ( objectType ) , objectType . attributes ) , ] , headerComments : empty ( ) , implementedProtocols : empty ( ) , imports : empty ( ) , instanceMethods : empty ( ) , macros : empty ( ) , properties : empty ( ) , requiredIncludesToRun : [ 'RMCodingTypeSafety' ] , staticConstants : empty ( ) , transformBaseFile : ( _ , file ) => file , transformFileRequest : ( file ) => file , validationErrors : empty ( ) , nullability : nothing ( ) , subclassingRestricted : ( _ ) => false } ; } function nothing < T , R > ( ) { return ( _ ) => null ; } function empty < T , R > ( ) { return ( _ ) => [ ] ; }