idlize

Форк
0
/
PeerLibrary.ts 
70 строк · 2.6 Кб
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 { DeclarationTable } from "./DeclarationTable";
18
import { MaterializedClass } from "./Materialized";
19
import { PeerClass } from "./PeerClass";
20
import { PeerFile } from "./PeerFile";
21
import { ComponentDeclaration } from './PeerGeneratorVisitor';
22
import { BuilderClass } from './BuilderClass';
23

24
export type PeerLibraryOutput = {
25
    outputC: string[]
26
}
27

28
export class PeerLibrary {
29
    public readonly files: PeerFile[] = []
30
    public readonly builderClasses: Map<string, BuilderClass> = new Map()
31
    public readonly materializedClasses: Map<string, MaterializedClass> = new Map()
32

33
    constructor(
34
        public declarationTable: DeclarationTable,
35
        public componentsToGenerate: Set<string>,
36
    ) {}
37

38
    readonly customComponentMethods: string[] = []
39
    // todo really dirty - we use it until we can generate interfaces
40
    // replacing import type nodes
41
    readonly importTypesStubToSource: Map<string, string> = new Map()
42
    readonly componentsDeclarations: ComponentDeclaration[] = []
43
    readonly conflictedDeclarations: Set<ts.Declaration> = new Set()
44

45
    findPeerByComponentName(componentName: string): PeerClass | undefined {
46
        for (const file of this.files)
47
            for (const peer of file.peers.values())
48
                if (peer.componentName == componentName) 
49
                    return peer
50
        return undefined
51
    }
52

53
    findFileByOriginalFilename(filename: string): PeerFile | undefined {
54
        return this.files.find(it => it.originalFilename === filename)
55
    }
56

57
    findComponentByDeclaration(node: ts.Declaration): ComponentDeclaration | undefined {
58
        return this.componentsDeclarations.find(it => {
59
            return it.interfaceDeclaration === node || it.attributesDeclarations === node 
60
        })
61
    }
62

63
    isComponentDeclaration(node: ts.Declaration): boolean {
64
        return this.findComponentByDeclaration(node) !== undefined
65
    }
66

67
    shouldGenerateComponent(name: string): boolean {
68
        return !this.componentsToGenerate.size || this.componentsToGenerate.has(name)
69
    }
70
}

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

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

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

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