1/* 2 * Copyright (c) 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 { 17 ArkAssignStmt, 18 ArkClass, 19 ArkFile, 20 ArkIfStmt, 21 ArkInstanceFieldRef, 22 ArkInstanceInvokeExpr, 23 ArkMethod, 24 ClassType, 25 FunctionType, 26 Local, 27 Stmt, 28 Value, 29} from 'arkanalyzer'; 30import Logger, { LOG_MODULE_TYPE } from 'arkanalyzer/lib/utils/logger'; 31import { BaseChecker, BaseMetaData } from '../BaseChecker'; 32import { Rule, Defects, MatcherTypes, MethodMatcher, MatcherCallback, ClassMatcher } from '../../Index'; 33import { IssueReport } from '../../model/Defects'; 34import { ClassCategory } from 'arkanalyzer/lib/core/model/ArkClass'; 35 36const logger = Logger.getLogger(LOG_MODULE_TYPE.HOMECHECK, 'NoMethodOverridingFieldCheck'); 37const gMetaData: BaseMetaData = { 38 severity: 1, 39 ruleDocPath: '', 40 description: '', 41}; 42 43export class NoMethodOverridingFieldCheck implements BaseChecker { 44 readonly metaData: BaseMetaData = gMetaData; 45 public rule: Rule; 46 public defects: Defects[] = []; 47 public issues: IssueReport[] = []; 48 49 private classMetcher: ClassMatcher = { 50 matcherType: MatcherTypes.CLASS, 51 ClassCategory: [ClassCategory.CLASS], 52 }; 53 54 public registerMatchers(): MatcherCallback[] { 55 const methodCb: MatcherCallback = { 56 matcher: this.classMetcher, 57 callback: this.check, 58 }; 59 return [methodCb]; 60 } 61 62 public check = (target: ArkClass): void => { 63 const interfaces = target.getAllHeritageClasses().filter(c => c.getCategory() === ClassCategory.INTERFACE); 64 for (const i of interfaces) { 65 const fields = i 66 .getFields() 67 .filter(f => f.getType() instanceof FunctionType) 68 .map(f => f.getName()); 69 fields.forEach(f => { 70 const method = target.getMethodWithName(f); 71 if (method) { 72 // record class 73 // console.log(`111`) 74 } 75 }); 76 } 77 }; 78} 79