idlize
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
16import * as ts from 'typescript'17
18export class PeerGeneratorConfig {19public static commonMethod = ["CommonMethod"]20public static customComponent = ["CustomComponent"]21
22public static ignoreSerialization = [23"Array", "Callback", "ErrorCallback", "Resource", "Length", "AttributeModifier",24"Number", "String", "Function", "Optional", "RelativeIndexable"25]26public static ignorePeerMethod = ["attributeModifier"]27public static ignoreComponents = [28"Particle",29"Progress",30"ForEach",31"LazyForEach",32"ContentSlot",33]34
35private static knownParametrized = [36"Indicator", "AttributeModifier", "AnimationRange", "ContentModifier", "SizeT", "PositionT", "Record"37]38
39public static invalidAttributes = ["ScrollableCommonMethod"]40
41public static invalidEvents = ["onRenderExited"]42
43public static rootComponents = [44"CommonMethod",45"SecurityComponentMethod",46"CommonTransition",47"CalendarAttribute",48"ContainerSpanAttribute",49]50
51public static standaloneComponents = [52"TextPickerDialog",53"TimePickerDialog",54"AlertDialog",55"CanvasPattern"56]57
58public static builderClasses = [59"SubTabBarStyle",60"BottomTabBarStyle",61"DotIndicator",62"DigitIndicator",63]64
65private static ignoreStandardNames = [66// standard exclusion67"Attribute",68"Interface",69"Method",70]71
72public static isStandardNameIgnored(name: string) {73for (const ignore of this.ignoreStandardNames) {74if (name.endsWith(ignore)) return true75}76return false77}78
79private static ignoreMaterialized = [80// TBD81"Event",82"Configuration",83"UIGestureEvent",84"GestureHandler", // class with generics85"ICurve", // parent interface for materialized classes86"TransitionEffect", // Generics `Type` and `Effect` types are used in static ctor87// constant values need to be generated88// "equals(id: TextMenuItemId): boolean" method leads to the "cycle detected" message89"TextMenuItemId",90]91
92public static isMaterializedIgnored(name: string) {93if (this.isStandardNameIgnored(name)) return true94
95for (const ignore of this.ignoreMaterialized) {96if (name.endsWith(ignore)) return true97}98return false99}100
101static mapComponentName(originalName: string): string {102if (originalName.endsWith("Attribute"))103return originalName.substring(0, originalName.length - 9)104return originalName105}106
107static isKnownParametrized(name: string | undefined) : boolean {108return name != undefined && PeerGeneratorConfig.knownParametrized.includes(name)109}110
111static isConflictedDeclaration(node: ts.Declaration): boolean {112if (!this.needInterfaces) return false113// duplicate type declarations with different signatures114if (ts.isTypeAliasDeclaration(node) && node.name.text === 'OnWillScrollCallback') return true115// has same named class and interface116if ((ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) && node.name?.text === 'LinearGradient') return true117// just has ugly dependency WrappedBuilder - there is conflict in generic types118if (ts.isInterfaceDeclaration(node) && node.name.text === 'ContentModifier') return true119// complicated type arguments120if (ts.isClassDeclaration(node) && node.name?.text === 'TransitionEffect') return true121// inside namespace122if (ts.isEnumDeclaration(node) && node.name.text === 'GestureType') return true123// no return type in some methods124if (ts.isInterfaceDeclaration(node) && node.name.text === 'LayoutChild') return true125return false126}127
128static cppPrefix = "GENERATED_"129static needInterfaces = true130}
131