• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { PropertyTranslator } from './base';
19import { DecoratorNames, hasDecorator } from './utils';
20import { StateTranslator } from './state';
21import { PropTranslator } from './prop';
22import { StorageLinkTranslator } from './storagelink';
23import { LocalStorageLinkTranslator } from './localstoragelink';
24import { LinkTranslator } from './link';
25import { ObjectLinkTranslator } from './objectlink';
26import { LocalStoragePropTranslator } from './localstorageprop';
27import { regularPropertyTranslator } from './regularProperty';
28import { staticPropertyTranslator } from './staticProperty';
29import { isStatic } from '../utils';
30import { StoragePropTranslator } from './storageProp';
31import { ConsumeTranslator } from './consume';
32import { ProvideTranslator } from './provide';
33import { BuilderParamTranslator } from './builderParam';
34import { ObservedTrackTranslator } from './observedTrack';
35import { ClassScopeInfo } from 'ui-plugins/checked-transformer';
36
37export { PropertyTranslator };
38
39export function classifyProperty(member: arkts.AstNode, structName: string): PropertyTranslator | undefined {
40    if (!arkts.isClassProperty(member)) return undefined;
41    if (isStatic(member)) return new staticPropertyTranslator(member, structName);
42
43    if (hasDecorator(member, DecoratorNames.STATE)) {
44        return new StateTranslator(member, structName);
45    }
46    if (hasDecorator(member, DecoratorNames.STORAGE_LINK)) {
47        return new StorageLinkTranslator(member, structName);
48    }
49    if (hasDecorator(member, DecoratorNames.LOCAL_STORAGE_LINK)) {
50        return new LocalStorageLinkTranslator(member, structName);
51    }
52    if (hasDecorator(member, DecoratorNames.LINK)) {
53        return new LinkTranslator(member, structName);
54    }
55    if (hasDecorator(member, DecoratorNames.OBJECT_LINK)) {
56        return new ObjectLinkTranslator(member, structName);
57    }
58    if (hasDecorator(member, DecoratorNames.LOCAL_STORAGE_PROP)) {
59        return new LocalStoragePropTranslator(member, structName);
60    }
61    if (hasDecorator(member, DecoratorNames.STORAGE_PROP)) {
62        return new StoragePropTranslator(member, structName);
63    }
64    if (hasDecorator(member, DecoratorNames.PROP)) {
65        return new PropTranslator(member, structName);
66    }
67    if (hasDecorator(member, DecoratorNames.PROVIDE)) {
68        return new ProvideTranslator(member, structName);
69    }
70    if (hasDecorator(member, DecoratorNames.CONSUME)) {
71        return new ConsumeTranslator(member, structName);
72    }
73    if (hasDecorator(member, DecoratorNames.BUILDER_PARAM)) {
74        return new BuilderParamTranslator(member, structName);
75    }
76
77    return new regularPropertyTranslator(member, structName);
78}
79
80export function classifyObservedTrack(member: arkts.AstNode, classScopeInfo: ClassScopeInfo): ObservedTrackTranslator | undefined {
81    if (!arkts.isClassProperty(member)) {
82        return undefined;
83    }
84    return new ObservedTrackTranslator(member, classScopeInfo);
85}