1/* 2 * Copyright (c) 2024-2025 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 { ClassSignature, MethodSignature } from '../../core/model/ArkSignature'; 17 18export function IsCollectionClass(classSignature: ClassSignature): boolean { 19 if (classSignature.toString().endsWith('lib.es2015.collection.d.ts: Set') || classSignature.toString().endsWith('lib.es2015.collection.d.ts: Map')) { 20 return true; 21 } 22 return false; 23} 24 25export enum BuiltApiType { 26 SetAdd, 27 MapSet, 28 FunctionCall, 29 FunctionApply, 30 FunctionBind, 31 NotBuiltIn, 32} 33 34export function getBuiltInApiType(method: MethodSignature): BuiltApiType { 35 let methodSigStr = method.toString(); 36 37 const regex = /lib\.es5\.d\.ts: Function\.(call|apply|bind)\(/; 38 39 if (methodSigStr.endsWith('lib.es2015.collection.d.ts: Set.add(T)')) { 40 return BuiltApiType.SetAdd; 41 } else if (methodSigStr.endsWith('lib.es2015.collection.d.ts: Map.set(K, V)')) { 42 return BuiltApiType.MapSet; 43 } else { 44 const match = methodSigStr.match(regex); 45 if (match) { 46 const functionName = match[1]; 47 switch (functionName) { 48 case 'call': 49 return BuiltApiType.FunctionCall; 50 case 'apply': 51 return BuiltApiType.FunctionApply; 52 case 'bind': 53 return BuiltApiType.FunctionBind; 54 default: 55 } 56 } 57 } 58 59 return BuiltApiType.NotBuiltIn; 60} 61