Skip to content

Commit 73e5132

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Kotlin: fix static code analysis weak warnings (5/n) (#52337)
Summary: Static code analysis reports several weak warnings, many of which seem to be leftovers after Kotlin migration. This PR addresses quite a few: - [Unnecessary type argument](https://www.jetbrains.com/help/inspectopedia/RemoveExplicitTypeArguments.html) - [Variable declaration could be moved inside 'when'](https://www.jetbrains.com/help/inspectopedia/MoveVariableDeclarationIntoWhen.html) - [Assignment can be replaced with operator assignment](https://www.jetbrains.com/help/inspectopedia/AssignmentReplaceableWithOperatorAssignment.html) - [Negated call can be simplified](https://www.jetbrains.com/help/inspectopedia/SimplifyNegatedBinaryExpression.html) ## Changelog: [INTERNAL] - Kotlin: fix static code analysis weak warnings (5/n) Pull Request resolved: #52337 Test Plan: ```sh yarn android yarn test-android ``` Reviewed By: cortinico Differential Revision: D77525702 Pulled By: rshest fbshipit-source-id: b0bd2e7616340c22b22e7f58387c53c51cbf073e
1 parent 9a2c422 commit 73e5132

File tree

6 files changed

+12
-18
lines changed

6 files changed

+12
-18
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ public class NativeAnimatedNodesManager(
105105
throw JSApplicationIllegalArgumentException(
106106
"createAnimatedNode: Animated node [$tag] already exists")
107107
}
108-
val type = config.getString("type")
109108
val node =
110-
when (type) {
109+
when (val type = config.getString("type")) {
111110
"style" -> StyleAnimatedNode(config, this)
112111
"value" -> ValueAnimatedNode(config)
113112
"color" -> ColorAnimatedNode(config, this, checkNotNull(reactApplicationContext))
@@ -239,9 +238,8 @@ public class NativeAnimatedNodesManager(
239238
return
240239
}
241240

242-
val type = animationConfig.getString("type")
243241
val animation =
244-
when (type) {
242+
when (val type = animationConfig.getString("type")) {
245243
"frames" -> FrameBasedAnimationDriver(animationConfig)
246244
"spring" -> SpringAnimation(animationConfig)
247245
"decay" -> DecayAnimation(animationConfig)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/JSONArguments.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public object JSONArguments {
3636
val result = buildReadableMap {
3737
while (keys.hasNext()) {
3838
val key = keys.next()
39-
val value = obj.get(key)
40-
41-
when (value) {
39+
when (val value = obj.get(key)) {
4240
is JSONObject -> put(key, fromJSONObject(value))
4341
is JSONArray -> put(key, fromJSONArray(value))
4442
is String -> put(key, value)
@@ -82,9 +80,7 @@ public object JSONArguments {
8280
public fun fromJSONArray(arr: JSONArray): ReadableArray {
8381
val result = buildReadableArray {
8482
repeat(arr.length()) {
85-
val value = arr.get(it)
86-
87-
when (value) {
83+
when (val value = arr.get(it)) {
8884
is JSONObject -> add(fromJSONObject(value))
8985
is JSONArray -> add(fromJSONArray(value))
9086
is String -> add(value)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactSoftExceptionLogger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal object ReactSoftExceptionLogger {
6262

6363
@JvmStatic
6464
fun logSoftException(@CategoryMode category: String, cause: Throwable): Unit {
65-
if (!listeners.isEmpty()) {
65+
if (listeners.isNotEmpty()) {
6666
for (listener in listeners) {
6767
listener.logSoftException(category, cause)
6868
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/mapbuffer/ReadableMapBuffer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ private constructor(
140140
var curLen = 0
141141
while (curLen < sizeMapBufferList) {
142142
val sizeMapBuffer = buffer.getInt(offset + curLen)
143-
curLen = curLen + Int.SIZE_BYTES
143+
curLen += Int.SIZE_BYTES
144144
readMapBufferList.add(cloneWithOffset(offset + curLen))
145-
curLen = curLen + sizeMapBuffer
145+
curLen += sizeMapBuffer
146146
}
147147
return readMapBufferList
148148
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/internal/bolts/Task.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public class Task<TResult> : TaskInterface<TResult> {
260260

261261
@JvmStatic
262262
internal fun <TResult> create(): TaskCompletionSource<TResult> {
263-
return TaskCompletionSource<TResult>()
263+
return TaskCompletionSource()
264264
}
265265

266266
/** Creates a completed task with the given value. */

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public object ReactScrollViewHelper {
261261
// Register the listeners for the fling animator if there isn't any
262262
val flingAnimator = scrollView.getFlingAnimator()
263263
if (flingAnimator.listeners == null || flingAnimator.listeners.size == 0) {
264-
registerFlingAnimator<T>(scrollView)
264+
registerFlingAnimator(scrollView)
265265
}
266266
val scrollState = scrollView.reactScrollViewScrollState
267267
scrollState.setFinalAnimatedPositionScroll(x, y)
@@ -400,7 +400,7 @@ public object ReactScrollViewHelper {
400400

401401
override fun onAnimationEnd(animator: Animator) {
402402
scrollView.reactScrollViewScrollState.isFinished = true
403-
updateFabricScrollState<T>(scrollView)
403+
updateFabricScrollState(scrollView)
404404
}
405405

406406
override fun onAnimationCancel(animator: Animator) {
@@ -456,9 +456,9 @@ public object ReactScrollViewHelper {
456456
val height = scrollView.height - scrollView.paddingBottom - scrollView.paddingTop
457457
val finalAnimatedPositionScroll = scrollState.finalAnimatedPositionScroll
458458
scroller.fling(
459-
getNextFlingStartValue<T>(
459+
getNextFlingStartValue(
460460
scrollView, scrollView.scrollX, finalAnimatedPositionScroll.x, velocityX), // startX
461-
getNextFlingStartValue<T>(
461+
getNextFlingStartValue(
462462
scrollView, scrollView.scrollY, finalAnimatedPositionScroll.y, velocityY), // startY
463463
velocityX, // velocityX
464464
velocityY, // velocityY

0 commit comments

Comments
 (0)