• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <algorithm>
16 
17 #include "checker_test.h"
18 
19 namespace test::utils {
20 
FindClassType(varbinder_alias::ETSBinder * varbinder,std::string_view className)21 checker_alias::Type *CheckerTest::FindClassType(varbinder_alias::ETSBinder *varbinder, std::string_view className)
22 {
23     auto classDefs = varbinder->AsETSBinder()->GetRecordTable()->ClassDefinitions();
24     auto baseClass = std::find_if(classDefs.begin(), classDefs.end(), [className](ir_alias::ClassDefinition *cdef) {
25         return cdef->Ident()->Name().Is(className);
26     });
27     if (baseClass == classDefs.end()) {
28         return nullptr;
29     }
30     return (*baseClass)->TsType();
31 }
32 
FindTypeAlias(checker_alias::ETSChecker * checker,std::string_view aliasName)33 checker_alias::Type *CheckerTest::FindTypeAlias(checker_alias::ETSChecker *checker, std::string_view aliasName)
34 {
35     auto *foundVar =
36         checker->Scope()->FindLocal(aliasName, varbinder_alias::ResolveBindingOptions::TYPE_ALIASES)->AsLocalVariable();
37     if (foundVar == nullptr) {
38         return nullptr;
39     }
40     return foundVar->Declaration()->Node()->AsTSTypeAliasDeclaration()->TypeAnnotation()->TsType();
41 }
42 
43 }  // namespace test::utils