Skip to content

Commit 7d01060

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Kotlin: fix static code analysis weak warnings (6/n) (#52338)
Summary: Static code analysis reports several weak warnings, many of which seem to be leftovers after Kotlin migration. This PR addresses quite a few: - [Accessor call that can be replaced with property access syntax](https://www.jetbrains.com/help/inspectopedia/UsePropertyAccessSyntax.html) ## Changelog: [INTERNAL] - Kotlin: fix static code analysis weak warnings (6/n) Pull Request resolved: #52338 Test Plan: ```sh yarn android yarn test-android ``` Reviewed By: NickGerleman Differential Revision: D77504913 Pulled By: cortinico fbshipit-source-id: 62661ba6adafb7893ce27811357020966d5ea4c1
1 parent 69e4252 commit 7d01060

File tree

13 files changed

+27
-29
lines changed

13 files changed

+27
-29
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
5454
}
5555

5656
override fun onChange(selfChange: Boolean, uri: Uri?) {
57-
if (getReactApplicationContext().hasActiveReactInstance()) {
57+
if (reactApplicationContext.hasActiveReactInstance()) {
5858
updateAndSendReduceMotionChangeEvent()
5959
}
6060
}
@@ -67,7 +67,7 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
6767
}
6868

6969
override fun onChange(selfChange: Boolean, uri: Uri?) {
70-
if (getReactApplicationContext().hasActiveReactInstance()) {
70+
if (reactApplicationContext.hasActiveReactInstance()) {
7171
updateAndSendHighTextContrastChangeEvent()
7272
}
7373
}
@@ -90,7 +90,7 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
9090
val appContext = context.applicationContext
9191
accessibilityManager =
9292
appContext.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
93-
contentResolver = getReactApplicationContext().getContentResolver()
93+
contentResolver = reactApplicationContext.contentResolver
9494
touchExplorationEnabled = accessibilityManager.isTouchExplorationEnabled
9595
accessibilityServiceEnabled = accessibilityManager.isEnabled
9696
reduceMotionEnabled = isReduceMotionEnabledValue

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appstate/AppStateModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal class AppStateModule(reactContext: ReactApplicationContext) :
6161
Arguments.createMap().apply { putString("app_state", appState) }
6262

6363
private fun sendEvent(eventName: String, data: Any?) {
64-
val reactApplicationContext = getReactApplicationContext() ?: return
64+
val reactApplicationContext = reactApplicationContext ?: return
6565
// We don't gain anything interesting from logging here, and it's an extremely common
6666
// race condition for an AppState event to be triggered as the Catalyst instance is being
6767
// set up or torn down. So, just fail silently here.
@@ -85,7 +85,7 @@ internal class AppStateModule(reactContext: ReactApplicationContext) :
8585

8686
override fun invalidate() {
8787
super.invalidate()
88-
getReactApplicationContext().removeLifecycleEventListener(this)
88+
reactApplicationContext.removeLifecycleEventListener(this)
8989
}
9090

9191
companion object {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/camera/ImageStoreManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal class ImageStoreManager(reactContext: ReactApplicationContext) :
3636
val executor = Executors.newSingleThreadExecutor()
3737
executor.execute {
3838
try {
39-
val contentResolver = getReactApplicationContext().getContentResolver()
39+
val contentResolver = reactApplicationContext.contentResolver
4040
val parsedUri = Uri.parse(uri)
4141
val inputStream = contentResolver.openInputStream(parsedUri) as InputStream
4242
try {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/DeviceEventManagerModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public open class DeviceEventManagerModule(
5555
// There should be no need to check if the catalyst instance is alive. After initialization
5656
// the thread instances cannot be null, and scheduling on a thread after ReactApplicationContext
5757
// teardown is a noop.
58-
getReactApplicationContext().runOnUiQueueThread(invokeDefaultBackPressRunnable)
58+
reactApplicationContext.runOnUiQueueThread(invokeDefaultBackPressRunnable)
5959
}
6060

6161
public companion object {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal open class HeadlessJsTaskSupportModule(reactContext: ReactApplicationCo
2323
NativeHeadlessJsTaskSupportSpec(reactContext) {
2424
override fun notifyTaskRetry(taskIdDouble: Double, promise: Promise) {
2525
val taskId = taskIdDouble.toInt()
26-
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext())
26+
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactApplicationContext)
2727
if (headlessJsTaskContext.isTaskRunning(taskId)) {
2828
val retryPosted = headlessJsTaskContext.retryTask(taskId)
2929
promise.resolve(retryPosted)
@@ -38,7 +38,7 @@ internal open class HeadlessJsTaskSupportModule(reactContext: ReactApplicationCo
3838

3939
override fun notifyTaskFinished(taskIdDouble: Double) {
4040
val taskId = taskIdDouble.toInt()
41-
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext())
41+
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactApplicationContext)
4242
if (headlessJsTaskContext.isTaskRunning(taskId)) {
4343
headlessJsTaskContext.finishTask(taskId)
4444
} else {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/debug/SourceCodeModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SourceCodeModule(reactContext: ReactApplicationContext) :
2222
mapOf(
2323
"scriptURL" to
2424
Assertions.assertNotNull<String>(
25-
getReactApplicationContext().getSourceURL(),
25+
reactApplicationContext.getSourceURL(),
2626
"No source URL loaded, have you initialised the instance?"))
2727

2828
public companion object {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import com.facebook.react.module.annotations.ReactModule
1616
internal class I18nManagerModule(context: ReactApplicationContext?) :
1717
NativeI18nManagerSpec(context) {
1818
override fun getTypedExportedConstants(): Map<String, Any> {
19-
val context = getReactApplicationContext()
19+
val context = reactApplicationContext
2020
val locale = context.resources.configuration.locales[0]
2121

2222
return mapOf(
@@ -26,15 +26,15 @@ internal class I18nManagerModule(context: ReactApplicationContext?) :
2626
}
2727

2828
override fun allowRTL(value: Boolean) {
29-
I18nUtil.instance.allowRTL(getReactApplicationContext(), value)
29+
I18nUtil.instance.allowRTL(reactApplicationContext, value)
3030
}
3131

3232
override fun forceRTL(value: Boolean) {
33-
I18nUtil.instance.forceRTL(getReactApplicationContext(), value)
33+
I18nUtil.instance.forceRTL(reactApplicationContext, value)
3434
}
3535

3636
override fun swapLeftAndRightInRTL(value: Boolean) {
37-
I18nUtil.instance.swapLeftAndRightInRTL(getReactApplicationContext(), value)
37+
I18nUtil.instance.swapLeftAndRightInRTL(reactApplicationContext, value)
3838
}
3939

4040
companion object {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/image/ImageLoaderModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal class ImageLoaderModule : NativeImageLoaderAndroidSpec, LifecycleEventL
8181
promise.reject(ERROR_INVALID_URI, "Cannot get the size of an image for an empty URI")
8282
return
8383
}
84-
val source = ImageSource(getReactApplicationContext(), uriString)
84+
val source = ImageSource(reactApplicationContext, uriString)
8585
val request: ImageRequest = ImageRequestBuilder.newBuilderWithSource(source.uri).build()
8686
val dataSource: DataSource<CloseableReference<CloseableImage>> =
8787
this.imagePipeline.fetchDecodedImage(request, this.callerContext)
@@ -226,7 +226,7 @@ internal class ImageLoaderModule : NativeImageLoaderAndroidSpec, LifecycleEventL
226226
override fun queryCache(uris: ReadableArray, promise: Promise) {
227227
// perform cache interrogation in async task as disk cache checks are expensive
228228
@Suppress("DEPRECATION", "StaticFieldLeak")
229-
object : GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
229+
object : GuardedAsyncTask<Void, Void>(reactApplicationContext) {
230230
override fun doInBackgroundGuarded(vararg params: Void) {
231231
val result = buildReadableMap {
232232
val imagePipeline: ImagePipeline = this@ImageLoaderModule.imagePipeline

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
3434
synchronized(this) {
3535
pendingOpenURLPromises.clear()
3636
initialURLListener
37-
?.let { listener -> getReactApplicationContext().removeLifecycleEventListener(listener) }
37+
?.let { listener -> reactApplicationContext.removeLifecycleEventListener(listener) }
3838
.also { initialURLListener = null }
3939
}
4040
super.invalidate()
@@ -47,7 +47,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
4747
*/
4848
override fun getInitialURL(promise: Promise) {
4949
try {
50-
val currentActivity = getReactApplicationContext().getCurrentActivity()
50+
val currentActivity = reactApplicationContext.getCurrentActivity()
5151
if (currentActivity == null) {
5252
waitForActivityAndGetInitialURL(promise)
5353
return
@@ -82,7 +82,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
8282
initialURLListener =
8383
object : LifecycleEventListener {
8484
override fun onHostResume() {
85-
getReactApplicationContext().removeLifecycleEventListener(this)
85+
reactApplicationContext.removeLifecycleEventListener(this)
8686
synchronized(this@IntentModule) {
8787
for (pendingPromise in pendingOpenURLPromises) {
8888
getInitialURL(pendingPromise)
@@ -96,7 +96,7 @@ public open class IntentModule(reactContext: ReactApplicationContext) :
9696

9797
override fun onHostDestroy() = Unit
9898
}
99-
getReactApplicationContext().addLifecycleEventListener(initialURLListener)
99+
reactApplicationContext.addLifecycleEventListener(initialURLListener)
100100
}
101101

102102
/**

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/permissions/PermissionsModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PermissionsModule(reactContext: ReactApplicationContext?) :
3838
* permission had been granted, false otherwise. See [Activity.checkSelfPermission].
3939
*/
4040
public override fun checkPermission(permission: String, promise: Promise): Unit {
41-
val context = getReactApplicationContext().getBaseContext()
41+
val context = reactApplicationContext.baseContext
4242
promise.resolve(context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED)
4343
}
4444

0 commit comments

Comments
 (0)