1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import * as arkts from '@koalaui/libarkts'; 17 18import { createGetter, createSetter } from './utils'; 19import { PropertyTranslator } from './base'; 20import { GetterSetter, InitializerConstructor } from './types'; 21import { backingField, expectName } from '../../common/arkts-utils'; 22 23export class staticPropertyTranslator extends PropertyTranslator implements InitializerConstructor, GetterSetter { 24 translateMember(): arkts.AstNode[] { 25 const originalName: string = expectName(this.property.key); 26 const newName: string = backingField(originalName); 27 return this.translateWithoutInitializer(newName, originalName); 28 } 29 30 cacheTranslatedInitializer(newName: string, originalName: string): void {} 31 32 translateWithoutInitializer(newName: string, originalName: string): arkts.AstNode[] { 33 return [this.property]; 34 } 35 36 translateGetter( 37 originalName: string, 38 typeAnnotation: arkts.TypeNode | undefined, 39 returnValue: arkts.Expression 40 ): arkts.MethodDefinition { 41 return createGetter(originalName, typeAnnotation, returnValue); 42 } 43 44 translateSetter( 45 originalName: string, 46 typeAnnotation: arkts.TypeNode | undefined, 47 left: arkts.MemberExpression 48 ): arkts.MethodDefinition { 49 const right: arkts.Identifier = arkts.factory.createIdentifier('value'); 50 return createSetter(originalName, typeAnnotation, left, right); 51 } 52} 53