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#include "entityNameVisitor.h"
17
18namespace ark::es2panda::parser {
19
20void EntityNameVisitor::VisitClassDeclaration(ir::ClassDeclaration *classDecl)
21{
22    name_ = classDecl->AsClassDeclaration()->Definition()->Ident()->Name();
23}
24
25void EntityNameVisitor::VisitFunctionDeclaration(ir::FunctionDeclaration *funcDecl)
26{
27    name_ = funcDecl->AsFunctionDeclaration()->Function()->Id()->Name();
28}
29
30void EntityNameVisitor::VisitVariableDeclaration(ir::VariableDeclaration *varDecl)
31{
32    const auto &decls = varDecl->AsVariableDeclaration()->Declarators();
33    ASSERT(decls.size() == 1);
34    auto *id = decls[0]->Id();
35    ASSERT(id->IsIdentifier());
36    name_ = id->AsIdentifier()->Name();
37}
38
39void EntityNameVisitor::VisitTSEnumDeclaration(ir::TSEnumDeclaration *enumDecl)
40{
41    name_ = enumDecl->AsTSEnumDeclaration()->Key()->Name();
42}
43
44void EntityNameVisitor::VisitTSInterfaceDeclaration(ir::TSInterfaceDeclaration *interfaceDecl)
45{
46    name_ = interfaceDecl->AsTSInterfaceDeclaration()->Id()->Name();
47}
48
49void EntityNameVisitor::VisitETSStructDeclaration(ir::ETSStructDeclaration *structDecl)
50{
51    name_ = structDecl->AsETSStructDeclaration()->Definition()->Ident()->Name();
52}
53
54void EntityNameVisitor::VisitTSTypeAliasDeclaration(ir::TSTypeAliasDeclaration *typeAliasDecl)
55{
56    name_ = typeAliasDecl->AsTSTypeAliasDeclaration()->Id()->Name();
57}
58
59}  // namespace ark::es2panda::parser
60