idlize

Форк
0
/
PeerGeneratorConfig.ts 
130 строк · 4.5 Кб
1
/*
2
 * Copyright (c) 2024 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

16
import * as ts from 'typescript'
17

18
export class PeerGeneratorConfig {
19
    public static commonMethod = ["CommonMethod"]
20
    public static customComponent = ["CustomComponent"]
21

22
    public static ignoreSerialization = [
23
        "Array", "Callback", "ErrorCallback", "Resource", "Length", "AttributeModifier",
24
        "Number", "String", "Function", "Optional", "RelativeIndexable"
25
    ]
26
    public static ignorePeerMethod = ["attributeModifier"]
27
    public static ignoreComponents = [
28
        "Particle", 
29
        "Progress", 
30
        "ForEach", 
31
        "LazyForEach",
32
        "ContentSlot",
33
    ]
34

35
    private static knownParametrized = [
36
        "Indicator", "AttributeModifier", "AnimationRange", "ContentModifier", "SizeT", "PositionT", "Record"
37
    ]
38

39
    public static invalidAttributes = ["ScrollableCommonMethod"]
40

41
    public static invalidEvents = ["onRenderExited"]
42

43
    public static rootComponents = [
44
        "CommonMethod",
45
        "SecurityComponentMethod",
46
        "CommonTransition",
47
        "CalendarAttribute",
48
        "ContainerSpanAttribute",
49
    ]
50

51
    public static standaloneComponents = [
52
        "TextPickerDialog",
53
        "TimePickerDialog",
54
        "AlertDialog",
55
        "CanvasPattern"
56
    ]
57

58
    public static builderClasses = [
59
        "SubTabBarStyle",
60
        "BottomTabBarStyle",
61
        "DotIndicator",
62
        "DigitIndicator",
63
    ]
64

65
    private static ignoreStandardNames = [
66
        // standard exclusion
67
        "Attribute",
68
        "Interface",
69
        "Method",
70
    ]
71

72
    public static isStandardNameIgnored(name: string) {
73
        for (const ignore of this.ignoreStandardNames) {
74
            if (name.endsWith(ignore)) return true
75
        }
76
        return false
77
    }
78

79
    private static ignoreMaterialized = [
80
        // TBD
81
        "Event",
82
        "Configuration",
83
        "UIGestureEvent",
84
        "GestureHandler",           // class with generics
85
        "ICurve",                   // parent interface for materialized classes
86
        "TransitionEffect",         // Generics `Type` and `Effect` types are used in static ctor
87
        // constant values need to be generated
88
        // "equals(id: TextMenuItemId): boolean" method leads to the "cycle detected" message
89
        "TextMenuItemId",
90
    ]
91

92
    public static isMaterializedIgnored(name: string) {
93
        if (this.isStandardNameIgnored(name)) return true
94

95
        for (const ignore of this.ignoreMaterialized) {
96
            if (name.endsWith(ignore)) return true
97
        }
98
        return false
99
    }
100

101
    static mapComponentName(originalName: string): string {
102
        if (originalName.endsWith("Attribute"))
103
            return originalName.substring(0, originalName.length - 9)
104
        return originalName
105
    }
106

107
    static isKnownParametrized(name: string | undefined) : boolean {
108
        return name != undefined && PeerGeneratorConfig.knownParametrized.includes(name)
109
    }
110

111
    static isConflictedDeclaration(node: ts.Declaration): boolean {
112
        if (!this.needInterfaces) return false
113
        // duplicate type declarations with different signatures
114
        if (ts.isTypeAliasDeclaration(node) && node.name.text === 'OnWillScrollCallback') return true
115
        // has same named class and interface
116
        if ((ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) && node.name?.text === 'LinearGradient') return true
117
        // just has ugly dependency WrappedBuilder - there is conflict in generic types 
118
        if (ts.isInterfaceDeclaration(node) && node.name.text === 'ContentModifier') return true
119
        // complicated type arguments
120
        if (ts.isClassDeclaration(node) && node.name?.text === 'TransitionEffect') return true
121
        // inside namespace
122
        if (ts.isEnumDeclaration(node) && node.name.text === 'GestureType') return true
123
        // no return type in some methods
124
        if (ts.isInterfaceDeclaration(node) && node.name.text === 'LayoutChild') return true
125
        return false
126
    }
127

128
    static cppPrefix = "GENERATED_"
129
    static needInterfaces = true
130
}
131

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.