idlize

Форк
0
/
PeerFile.ts 
69 строк · 2.4 Кб
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
import { getOrPut } from "../util"
18
import { PeerClass } from "./PeerClass"
19
import { DeclarationTable } from "./DeclarationTable"
20
import { ImportFeature } from './ImportsCollector'
21

22
export class EnumEntity {
23
    constructor(
24
        public readonly name: string,
25
        public readonly comment: string,
26
        public readonly members: EnumMember[] = [],
27
    ) {}
28
    pushMember(name: string, comment: string, initializerText: string | undefined) {
29
        this.members.push(new EnumMember(name, comment, initializerText))
30
    }
31
}
32

33
class EnumMember {
34
    constructor(
35
        public readonly name: string,
36
        public readonly comment: string,
37
        public readonly initializerText: string | undefined,
38
    ) {}
39
}
40

41
export class PeerFile {
42
    readonly peers: Map<string, PeerClass> = new Map()
43
    readonly enums: EnumEntity[] = []
44
    // todo maybe declarations should be converted as same as enums - to
45
    // structs detached from `ts` nodes
46
    readonly declarations: Set<ts.Declaration> = new Set()
47
    readonly importFeatures: ImportFeature[] = []
48
    readonly serializeImportFeatures: ImportFeature[] = []
49
    constructor(
50
        public readonly originalFilename: string,
51
        public readonly declarationTable: DeclarationTable,
52
        private readonly componentsToGenerate: Set<string>,
53
    ) {}
54

55
    get peersToGenerate(): PeerClass[] {
56
        const peers = Array.from(this.peers.values())
57
        if (!this.componentsToGenerate.size)
58
            return peers
59
        return peers.filter(it => this.componentsToGenerate.has(it.componentName))
60
    }
61

62
    getOrPutPeer(componentName: string) {
63
        return getOrPut(this.peers, componentName, () => new PeerClass(this, componentName, this.originalFilename, this.declarationTable))
64
    }
65

66
    pushEnum(enumEntity: EnumEntity) {
67
        this.enums.push(enumEntity)
68
    }
69
}

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

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

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

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