From 73186f15050f8c368052c1f8679bc62664786de1 Mon Sep 17 00:00:00 2001 From: liqing-yang Date: Mon, 16 Jun 2025 11:41:54 +0800 Subject: [PATCH] custombuilder: should not report issue on lambda Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICFE5X Signed-off-by: liqing-yang --- .../checker/migration/CustomBuilderCheck.ts | 50 +------------------ 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/ets2panda/linter/homecheck/src/checker/migration/CustomBuilderCheck.ts b/ets2panda/linter/homecheck/src/checker/migration/CustomBuilderCheck.ts index ac46794b55..c001d84975 100644 --- a/ets2panda/linter/homecheck/src/checker/migration/CustomBuilderCheck.ts +++ b/ets2panda/linter/homecheck/src/checker/migration/CustomBuilderCheck.ts @@ -23,19 +23,14 @@ import { AliasType, AbstractInvokeExpr, Value, - ArkFile, AstTreeUtils, ts, - FunctionType, - ArkClass, - ANONYMOUS_METHOD_PREFIX, - ArkInvokeStmt, } from 'arkanalyzer'; import Logger, { LOG_MODULE_TYPE } from 'arkanalyzer/lib/utils/logger'; import { BaseChecker, BaseMetaData } from '../BaseChecker'; import { Rule, Defects, MatcherTypes, MatcherCallback, MethodMatcher } from '../../Index'; import { IssueReport } from '../../model/Defects'; -import { FixInfo, RuleFix } from '../../model/Fix'; +import { RuleFix } from '../../model/Fix'; import { FixPosition, FixUtils } from '../../utils/common/FixUtils'; import { WarnInfo } from '../../utils/common/Utils'; @@ -79,52 +74,9 @@ export class CustomBuilderCheck implements BaseChecker { if (usage) { this.addIssueReport(usage.getDeclaringStmt()!, usage); } - - // 场景2:函数调用包在箭头函数中赋值给CustomBuilder类型的对象 - if (stmt instanceof ArkAssignStmt) { - const arrowMethod = this.findPotentialArrowFunction(stmt, target.getDeclaringArkClass()); - if (arrowMethod !== null && this.isCallToBuilderWrapWithArrow(arrowMethod)) { - this.addIssueReport(stmt, stmt.getRightOp()); - } - } } }; - // 只有当赋值语句leftOp为CustomBuilder类型时,若rightOp是匿名箭头函数,则返回该箭头函数 - private findPotentialArrowFunction(stmt: Stmt, arkClass: ArkClass): ArkMethod | null { - if (!(stmt instanceof ArkAssignStmt) || !this.isCustomBuilderTy(stmt.getLeftOp().getType())) { - return null; - } - - const rightOpType = stmt.getRightOp().getType(); - if (!(rightOpType instanceof FunctionType)) { - return null; - } - - const methodName = rightOpType.getMethodSignature().getMethodSubSignature().getMethodName(); - const method = arkClass.getMethodWithName(methodName); - if (method === null || !method.isAnonymousMethod()) { - return null; - } - return method; - } - - private isCallToBuilderWrapWithArrow(arrowMethod: ArkMethod): boolean { - const scene = arrowMethod.getDeclaringArkFile().getScene(); - const stmts = arrowMethod.getBody()?.getCfg().getStmts() ?? []; - for (const stmt of stmts) { - if (!(stmt instanceof ArkInvokeStmt)) { - continue; - } - const invokeExpr = stmt.getInvokeExpr(); - const method = scene.getMethod(invokeExpr.getMethodSignature()); - if (method && method.hasBuilderDecorator()) { - return true; - } - } - return false; - } - private isCallToBuilder(stmt: Stmt, scene: Scene): Local | undefined { if (!(stmt instanceof ArkAssignStmt)) { return undefined; -- Gitee