From 2120a897d52a94141e8bc69a3136f0ffaaf94217 Mon Sep 17 00:00:00 2001 From: Zhelyapov Aleksey Date: Fri, 11 Jul 2025 16:04:31 +0300 Subject: [PATCH] Remove enum conversions Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICL8SL Signed-off-by: Zhelyapov Aleksey --- .../display_ani/ets/@ohos.display.ets | 22 ++++++++--------- .../ets/@ohos.uiExtensionHost.ets | 2 +- .../screen_ani/ets/@ohos.screen.ets | 4 ++-- .../window_stage_ani/ets/@ohos.window.ets | 24 +++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/interfaces/kits/ani/display_runtime/display_ani/ets/@ohos.display.ets b/interfaces/kits/ani/display_runtime/display_ani/ets/@ohos.display.ets index 4f99569c2f..381f05c4f6 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/ets/@ohos.display.ets +++ b/interfaces/kits/ani/display_runtime/display_ani/ets/@ohos.display.ets @@ -360,14 +360,14 @@ export native function isCaptured(): boolean; export function getFoldDisplayMode(): FoldDisplayMode { let res = getFoldDisplayModeNative(); - return res as FoldDisplayMode; + return FoldDisplayMode.fromValue(res); } export native function getFoldDisplayModeNative(): int; export function getFoldStatus(): FoldStatus{ let res = getFoldStatusNative(); - return res as FoldStatus; + return FoldStatus.fromValue(res); } export native function getFoldStatusNative(): int; @@ -398,8 +398,8 @@ export native function getCurrentFoldCreaseRegionNative(foldCreaseRegion: object export function getDisplayByIdSync(displayId: number): Display { let display = new DisplayImpl(); getDisplayByIdSyncNative(display as object, displayId); - display.state = display.state_ as DisplayState; - display.orientation = display.orientation_ as Orientation; + display.state = DisplayState.fromValue(display.state_); + display.orientation = Orientation.fromValue(display.orientation_); return display; } @@ -408,8 +408,8 @@ export native function getDisplayByIdSyncNative(obj: object, displayId: number): export function getDefaultDisplaySync(): Display { let display = new DisplayImpl(); getDefaultDisplaySyncNative(display as object); - display.state = display.state_ as DisplayState; - display.orientation = display.orientation_ as Orientation; + display.state = DisplayState.fromValue(display.state_); + display.orientation = Orientation.fromValue(display.orientation_); return display; } @@ -458,8 +458,8 @@ function minusDisplayArray(displayArr: Array): void { break; } let dp = displayArr[i] as DisplayImpl; - dp.state = dp.state_ as DisplayState; - dp.orientation = dp.orientation_ as Orientation; + dp.state = DisplayState.fromValue(dp.state_); + dp.orientation = Orientation.fromValue(dp.orientation_); } displayArr.splice(i); } @@ -487,12 +487,12 @@ export function displayEventCallBack(cb: object, cbArg: double): void { export function foldStatusCallback(cb: object, cbArg: int): void { const func = cb as (cbArg: FoldStatus) => void; - func(cbArg as FoldStatus); + func(FoldStatus.fromValue(cbArg)); } export function foldDisplayModeCallback(cb: object, cbArg: int): void { const func = cb as (cbArg: FoldDisplayMode) => void; - func(cbArg as FoldDisplayMode); + func(FoldDisplayMode.fromValue(cbArg)); } export function foldAngleChangeCallback(cb: object, cbArg: object): void { @@ -538,7 +538,7 @@ function minusResolutionArray(resolutions: Array): vo break; } let resolution = resolutions[index] as DisplayPhysicalResolutionImpl; - resolution.foldDisplayMode = resolution.foldDisplayMode_ as FoldDisplayMode; + resolution.foldDisplayMode = FoldDisplayMode.fromValue(resolution.foldDisplayMode_); } resolutions.splice(index); } diff --git a/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets b/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets index d8f8bb2bbf..6ba5c58ace 100644 --- a/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets +++ b/interfaces/kits/ani/embeddable_window_stage/ets/@ohos.uiExtensionHost.ets @@ -121,7 +121,7 @@ namespace uiExtensionHost { } getWindowAvoidArea(type: window.AvoidAreaType): window.AvoidArea { let area: window.AvoidArea = new UIEAvoidArea(); - let ret = this.getWindowAvoidArea(this.nativeObj, type as int, area as object); + let ret = this.getWindowAvoidArea(this.nativeObj, type, area as object); return area; } diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/ets/@ohos.screen.ets b/interfaces/kits/ani/screen_runtime/screen_ani/ets/@ohos.screen.ets index 374ae6e506..1567a512a0 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/ets/@ohos.screen.ets +++ b/interfaces/kits/ani/screen_runtime/screen_ani/ets/@ohos.screen.ets @@ -154,9 +154,9 @@ class ScreenImpl implements Screen { this.id = screen.id; this.parent = screen.parent; this.activeModeIndex = screen.activeModeIndex; - this.orientation = screen.orientation_ as Orientation; + this.orientation = Orientation.fromValue(screen.orientation_); this.supportedModeInfo = screen.supportedModeInfo_; - this.sourceMode = screen.sourceMode_ as ScreenSourceMode; + this.sourceMode = ScreenSourceMode.fromValue(screen.sourceMode_); this.screenNativeObj = screen.screenNativeObj; } diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets b/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets index a394f0e289..2cc1cae4ee 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets @@ -2199,7 +2199,7 @@ export class WindowInternal implements Window { } public getWindowStatus(): WindowStatusType { - return this.getWindowStatus(this.nativeObj) as WindowStatusType; + return WindowStatusType.fromValue(this.getWindowStatus(this.nativeObj)); } public minimize(): Promise { @@ -2228,10 +2228,10 @@ export class WindowInternal implements Window { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void ) :void => { taskpool.execute((): void => { if (presentation == undefined) { - this.maximize(this.nativeObj, MaximizePresentation.ENTER_IMMERSIVE as int); + this.maximize(this.nativeObj, MaximizePresentation.ENTER_IMMERSIVE); } else { - this.maximize(this.nativeObj, presentation as int); + this.maximize(this.nativeObj, presentation); } }).then((ret: NullishType) :void => { resolve(undefined); @@ -2337,7 +2337,7 @@ export class WindowInternal implements Window { public getWindowProperties(): WindowProperties { let windowProperties = this.getWindowProperties(this.nativeObj) as WindowPropertiesInternal; - windowProperties.type = windowProperties.typeInternal as WindowType; + windowProperties.type = WindowType.fromValue(windowProperties.typeInternal); return windowProperties; } @@ -2346,7 +2346,7 @@ export class WindowInternal implements Window { reject: (error: BusinessError) => void) => { taskpool.execute((): WindowProperties => { let res = this.getProperties(this.nativeObj) as WindowPropertiesInternal; - res.type = res.typeInternal as WindowType; + res.type = WindowType.fromValue(res.typeInternal); return res; }).then((ret: NullishType) => { resolve(ret as WindowProperties); @@ -2498,7 +2498,7 @@ export class WindowInternal implements Window { public setWindowColorSpace(colorSpace: ColorSpace): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { - this.setWindowColorSpaceSync(this.nativeObj, colorSpace as int); + this.setWindowColorSpaceSync(this.nativeObj, colorSpace); }).then((ret: NullishType) => { resolve(undefined); }).catch((err: NullishType) => { @@ -2509,7 +2509,7 @@ export class WindowInternal implements Window { public setWindowColorSpace(colorSpace: ColorSpace, callback: AsyncCallback): void { taskpool.execute((): void => { - this.setWindowColorSpaceSync(this.nativeObj, colorSpace as int); + this.setWindowColorSpaceSync(this.nativeObj, colorSpace); }).then((ret: NullishType) => { callback(new BusinessError(), undefined); }).catch((err: NullishType) => { @@ -2520,7 +2520,7 @@ export class WindowInternal implements Window { public setPreferredOrientation(orientation: Orientation): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { - this.setPreferredOrientationSync(this.nativeObj, orientation as int); + this.setPreferredOrientationSync(this.nativeObj, orientation); }).then((ret: NullishType) => { resolve(undefined); }).catch((err: NullishType) => { @@ -2531,7 +2531,7 @@ export class WindowInternal implements Window { public setPreferredOrientation(orientation: Orientation, callback: AsyncCallback): void { taskpool.execute((): void => { - this.setPreferredOrientationSync(this.nativeObj, orientation as int); + this.setPreferredOrientationSync(this.nativeObj, orientation); }).then((ret: NullishType) => { callback(new BusinessError(), undefined); }).catch((err: NullishType) => { @@ -3131,7 +3131,7 @@ function runSystemBarTintChangeCallback(cb: object, tint: object): void { function runAvoidAreaChangeCallback(cb: object, area: object, type: int): void { const func = cb as (data: AvoidAreaOptions) => void; - func({type: type as AvoidAreaType, area: area as AvoidArea}); + func({type: AvoidAreaType.fromValue(type), area: area as AvoidArea}); } export function shiftAppWindowFocus(sourceWindowId: int, targetWindowId: int): Promise { @@ -3153,7 +3153,7 @@ function runWindowDialogTargetCallback(cb: object): void { function runWindowEventCallback(cb: object, cbArg: int): void { const func = cb as (cbArg: WindowEventType) => void; - func(cbArg as WindowEventType); + func(WindowEventType.fromValue(cbArg)); } function runWindowStageEventCallback(cb: object, cbArg: int): void { @@ -3193,7 +3193,7 @@ function runKeyboardDidHideCallback(cb: object, cbArg: object): void { function runWindowStatusCallback(cb: object, cbArg: int): void { const func = cb as (cbArg: WindowStatusType) => void; - func(cbArg as WindowStatusType); + func(WindowStatusType.fromValue(cbArg)); } function runWindowNoInteractionCallback(cb: object): void { -- Gitee