Enable and apply Ktfmt to xplat/simplesql, xplat/sonar, and xplat/spectrum

Summary: As title.

Reviewed By: zertosh

Differential Revision: D30425160

fbshipit-source-id: c72d270d7cd3f30990aac55e33e8f72d60ed5fe2
This commit is contained in:
Omer Strulovich
2021-08-19 07:27:32 -07:00
committed by Facebook GitHub Bot
parent 8e2a839f9d
commit 1db39b8171
18 changed files with 359 additions and 387 deletions

View File

@@ -22,8 +22,8 @@ class FlipperLeakListener : OnHeapAnalyzedListener {
leaks.addAll(heapAnalysis.toLeakList())
AndroidFlipperClient.getInstanceIfInitialized()?.let { client ->
(client.getPlugin(LeakCanary2FlipperPlugin.ID) as? LeakCanary2FlipperPlugin)
?.reportLeaks(leaks)
(client.getPlugin(LeakCanary2FlipperPlugin.ID) as? LeakCanary2FlipperPlugin)?.reportLeaks(
leaks)
}
defaultListener.onHeapAnalyzed(heapAnalysis)
@@ -31,13 +31,15 @@ class FlipperLeakListener : OnHeapAnalyzedListener {
private fun HeapAnalysis.toLeakList(): List<Leak> {
return if (this is HeapAnalysisSuccess) {
allLeaks.mapNotNull {
allLeaks
.mapNotNull {
if (it.leakTraces.isNotEmpty()) {
it.leakTraces[0].toLeak(it.shortDescription)
} else {
null
}
}.toList()
}
.toList()
} else {
emptyList()
}

View File

@@ -10,12 +10,13 @@ package com.facebook.flipper.plugins.leakcanary2
import com.facebook.flipper.core.FlipperArray
import com.facebook.flipper.core.FlipperObject
import com.facebook.flipper.core.FlipperValue
import java.util.UUID
import shark.LeakTrace
import shark.LeakTraceObject
import java.util.UUID
internal data class LeakCanary2Report(val leaks: List<Leak>) : FlipperValue {
override fun toFlipperObject(): FlipperObject = FlipperObject.Builder()
override fun toFlipperObject(): FlipperObject =
FlipperObject.Builder()
.put("leaks", leaks.map { it.toFlipperObject() }.toFlipperArray())
.build()
}
@@ -44,9 +45,7 @@ internal data class Leak(
@JvmName("toFlipperObjectStringFlipperObject")
private fun Map<String, FlipperObject>.toFlipperObject(): FlipperObject =
asIterable()
.fold(FlipperObject.Builder()) { builder, entry ->
builder.put(entry.key, entry.value)
}
.fold(FlipperObject.Builder()) { builder, entry -> builder.put(entry.key, entry.value) }
.build()
}
@@ -58,23 +57,25 @@ internal fun LeakTrace.toLeak(title: String): Leak {
retainedSize = retainedHeapByteSize?.let { "$it bytes" } ?: "unknown size",
signature = signature,
root = elements.first().first,
details = "$this"
)
details = "$this")
}
private fun LeakTrace.getElements(): List<Pair<String, Element>> {
val referenceElements = referencePath.map { reference ->
val referenceElements =
referencePath
.map { reference ->
val id = UUID.randomUUID().toString()
id to Element(id, reference.originObject)
}.toMutableList()
}
.toMutableList()
val leakId = UUID.randomUUID().toString()
referenceElements.add(leakId to Element(leakId, leakingObject))
return referenceElements.mapIndexed { index, pair ->
pair.first to if (index == referenceElements.lastIndex) pair.second else pair.second.copy(
children = listOf(referenceElements[index + 1].second.id)
)
pair.first to
if (index == referenceElements.lastIndex) pair.second
else pair.second.copy(children = listOf(referenceElements[index + 1].second.id))
}
}
@@ -86,14 +87,16 @@ internal data class Element(
val attributes: List<ElementAttribute>,
val decoration: String = ""
) : FlipperValue {
constructor(id: String, leakObject: LeakTraceObject) : this(
constructor(
id: String,
leakObject: LeakTraceObject
) : this(
id = id,
name = "${leakObject.className} (${leakObject.typeName})",
attributes = listOf(
attributes =
listOf(
ElementAttribute("leaking", leakObject.leakingStatus.shortName),
ElementAttribute("retaining", leakObject.retaining)
)
)
ElementAttribute("retaining", leakObject.retaining)))
override fun toFlipperObject(): FlipperObject {
return FlipperObject.Builder()
@@ -121,7 +124,8 @@ internal fun Iterable<FlipperObject>.toFlipperArray(): FlipperArray =
fold(FlipperArray.Builder()) { builder, row -> builder.put(row) }.build()
private val LeakTraceObject.LeakingStatus.shortName: String
get() = when (this) {
get() =
when (this) {
LeakTraceObject.LeakingStatus.NOT_LEAKING -> "N"
LeakTraceObject.LeakingStatus.LEAKING -> "Y"
LeakTraceObject.LeakingStatus.UNKNOWN -> "?"
@@ -131,14 +135,8 @@ private val LeakTraceObject.retaining: String
private val EMPTY_FLIPPER_OBJECT = FlipperObject.Builder().build()
data class ElementAttribute(
val name: String,
val value: String
) : FlipperValue {
data class ElementAttribute(val name: String, val value: String) : FlipperValue {
override fun toFlipperObject(): FlipperObject {
return FlipperObject.Builder()
.put("name", name)
.put("value", value)
.build()
return FlipperObject.Builder().put("name", name).put("value", value).build()
}
}

View File

@@ -17,10 +17,8 @@ import com.facebook.flipper.plugins.retrofit2protobuf.model.CallNestedMessagesPa
object SendProtobufToFlipperFromRetrofit {
operator fun invoke(baseUrl: String, service: Class<*>) {
getNetworkPlugin()?.addProtobufDefinitions(
baseUrl,
generateProtobufDefinitions(service).toFlipperArray()
)
getNetworkPlugin()
?.addProtobufDefinitions(baseUrl, generateProtobufDefinitions(service).toFlipperArray())
}
private fun getNetworkPlugin(): NetworkFlipperPlugin? {
@@ -30,9 +28,9 @@ object SendProtobufToFlipperFromRetrofit {
}
private fun generateProtobufDefinitions(service: Class<*>): List<CallNestedMessagesPayload> {
return RetrofitServiceToGenericCallDefinitions(service).let { definitions ->
GenericCallDefinitionsToMessageDefinitionsIfProtobuf(definitions)
}.let { messages ->
return RetrofitServiceToGenericCallDefinitions(service)
.let { definitions -> GenericCallDefinitionsToMessageDefinitionsIfProtobuf(definitions) }
.let { messages ->
messages.map {
CallNestedMessagesPayload(
path = it.path,
@@ -40,8 +38,7 @@ object SendProtobufToFlipperFromRetrofit {
requestMessageFullName = it.requestMessageFullName,
requestDefinitions = it.requestModel,
responseMessageFullName = it.responseMessageFullName,
responseDefinitions = it.responseModel
)
responseDefinitions = it.responseModel)
}
}
}

View File

@@ -12,14 +12,14 @@ import com.facebook.flipper.plugins.retrofit2protobuf.model.GenericCallDefinitio
import me.haroldmartin.protobufjavatoprotobufjs.ProtobufGeneratedJavaToProtobufJs
internal object GenericCallDefinitionsToMessageDefinitionsIfProtobuf {
operator fun invoke(callDefinitions: List<GenericCallDefinition>): List<FullNamedMessagesCallDefinition> {
operator fun invoke(
callDefinitions: List<GenericCallDefinition>
): List<FullNamedMessagesCallDefinition> {
return callDefinitions.mapNotNull { definition ->
val responseRootAndMessages = definition.responseType?.let {
ProtobufGeneratedJavaToProtobufJs(it)
}
val requestRootAndMessages = definition.requestType?.let {
ProtobufGeneratedJavaToProtobufJs(it)
}
val responseRootAndMessages =
definition.responseType?.let { ProtobufGeneratedJavaToProtobufJs(it) }
val requestRootAndMessages =
definition.requestType?.let { ProtobufGeneratedJavaToProtobufJs(it) }
FullNamedMessagesCallDefinition(
path = definition.path,
@@ -27,8 +27,7 @@ internal object GenericCallDefinitionsToMessageDefinitionsIfProtobuf {
responseMessageFullName = responseRootAndMessages?.rootFullName,
responseModel = responseRootAndMessages?.descriptors,
requestMessageFullName = requestRootAndMessages?.rootFullName,
requestModel = requestRootAndMessages?.descriptors
)
requestModel = requestRootAndMessages?.descriptors)
}
}
}

View File

@@ -24,9 +24,7 @@ internal object RetrofitServiceToGenericCallDefinitions {
path = path,
method = httpMethod,
responseType = responseType,
requestType = method.requestBodyType
)
)
requestType = method.requestBodyType))
}
return methodToProtobufDefinition
}
@@ -36,7 +34,8 @@ private val Array<Annotation>.urlPathAndMethod: Pair<String, String>?
get() {
var path: Pair<String, String>? = null
for (a in this) {
path = when (a.annotationClass) {
path =
when (a.annotationClass) {
retrofit2.http.DELETE::class -> (a as retrofit2.http.DELETE).value to "DELETE"
retrofit2.http.GET::class -> (a as retrofit2.http.GET).value to "GET"
retrofit2.http.HEAD::class -> (a as retrofit2.http.HEAD).value to "HEAD"

View File

@@ -34,7 +34,8 @@ internal data class CallNestedMessagesPayload(
private fun Map<*, *>.toFlipperObject(): FlipperObject {
val builder = FlipperObject.Builder()
this.forEach { (key, value) ->
val castValue = when (value) {
val castValue =
when (value) {
is Map<*, *> -> value.toFlipperObject()
is Iterable<*> -> value.toFlipperArray()
else -> value

View File

@@ -7,8 +7,8 @@
package com.facebook.flipper.sample.tutorial
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.facebook.flipper.sample.tutorial.ui.RootComponent
import com.facebook.litho.LithoView
import com.facebook.litho.sections.SectionContext
@@ -20,8 +20,6 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(
LithoView.create(this, RootComponent.create(sectionContext).build())
)
setContentView(LithoView.create(this, RootComponent.create(sectionContext).build()))
}
}

View File

@@ -10,7 +10,8 @@ package com.facebook.flipper.sample.tutorial
import androidx.core.net.toUri
object MarineMammals {
val list = listOf(
val list =
listOf(
MarineMammal(
"Polar Bear",
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Ursus_maritimus_4_1996-08-04.jpg/190px-Ursus_maritimus_4_1996-08-04.jpg".toUri()),
@@ -22,6 +23,5 @@ object MarineMammals {
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg".toUri()),
MarineMammal(
"Bottlenose Dolphin",
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg".toUri())
)
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg".toUri()))
}

View File

@@ -20,12 +20,15 @@ class SeaMammalFlipperPlugin : FlipperPlugin {
override fun onConnect(connection: FlipperConnection?) {
this.connection = connection
MarineMammals.list.mapIndexed { index, (title, picture_url) ->
MarineMammals.list
.mapIndexed { index, (title, picture_url) ->
FlipperObject.Builder()
.put("id", index)
.put("title", title)
.put("url", picture_url).build()
}.forEach(this::newRow)
.put("url", picture_url)
.build()
}
.forEach(this::newRow)
}
override fun onDisconnect() {

View File

@@ -15,7 +15,6 @@ import com.facebook.litho.annotations.LayoutSpec
import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.Prop
import com.facebook.litho.widget.Card
import com.facebook.yoga.YogaEdge.HORIZONTAL
import com.facebook.yoga.YogaEdge.VERTICAL
@@ -23,17 +22,10 @@ import com.facebook.yoga.YogaEdge.VERTICAL
object FeedItemCardSpec {
@OnCreateLayout
fun onCreateLayout(
c: ComponentContext,
@Prop mammal: MarineMammal
): Component =
fun onCreateLayout(c: ComponentContext, @Prop mammal: MarineMammal): Component =
Column.create(c)
.paddingDip(VERTICAL, 8f)
.paddingDip(HORIZONTAL, 16f)
.child(
Card.create(c)
.content(
MarineMammelComponent.create(c)
.mammal(mammal)))
.child(Card.create(c).content(MarineMammelComponent.create(c).mammal(mammal)))
.build()
}

View File

@@ -25,17 +25,13 @@ object FeedSectionSpec {
@OnCreateChildren
fun onCreateChildren(c: SectionContext, @Prop data: List<MarineMammal>): Children =
Children.create()
.child(DataDiffSection.create<MarineMammal>(c)
.child(
DataDiffSection.create<MarineMammal>(c)
.data(data)
.renderEventHandler(FeedSection.render(c)))
.build()
@OnEvent(RenderEvent::class)
fun render(
c: SectionContext,
@FromEvent model: MarineMammal
): RenderInfo =
ComponentRenderInfo.create()
.component(FeedItemCard.create(c).mammal(model).build())
.build()
fun render(c: SectionContext, @FromEvent model: MarineMammal): RenderInfo =
ComponentRenderInfo.create().component(FeedItemCard.create(c).mammal(model).build()).build()
}

View File

@@ -17,22 +17,16 @@ import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.Prop
import com.facebook.litho.widget.Text
import com.facebook.yoga.YogaEdge.BOTTOM
import com.facebook.yoga.YogaEdge.LEFT
import com.facebook.yoga.YogaEdge.HORIZONTAL
import com.facebook.yoga.YogaEdge.LEFT
import com.facebook.yoga.YogaPositionType.ABSOLUTE
@LayoutSpec
object MarineMammelComponentSpec {
@OnCreateLayout
fun onCreateLayout(
c: ComponentContext,
@Prop mammal: MarineMammal
): Component =
fun onCreateLayout(c: ComponentContext, @Prop mammal: MarineMammal): Component =
Column.create(c)
.child(SingleImageComponent.create(c)
.image(mammal.picture_url)
.build()
)
.child(SingleImageComponent.create(c).image(mammal.picture_url).build())
.child(
Text.create(c)
.text(mammal.title)
@@ -44,5 +38,4 @@ object MarineMammelComponentSpec {
.positionDip(LEFT, 4f)
.paddingDip(HORIZONTAL, 6f))
.build()
}

View File

@@ -20,20 +20,15 @@ import com.facebook.litho.fresco.FrescoImage
@LayoutSpec
object SingleImageComponentSpec {
@PropDefault
val imageAspectRatio = 1f
@PropDefault val imageAspectRatio = 1f
@OnCreateLayout
fun onCreateLayout(
c: ComponentContext,
@Prop image: Uri,
@Prop(optional = true) imageAspectRatio: Float): Component =
Fresco.newDraweeControllerBuilder()
.setUri(image)
.build().let {
FrescoImage.create(c)
.controller(it)
.imageAspectRatio(imageAspectRatio)
.build()
@Prop(optional = true) imageAspectRatio: Float
): Component =
Fresco.newDraweeControllerBuilder().setUri(image).build().let {
FrescoImage.create(c).controller(it).imageAspectRatio(imageAspectRatio).build()
}
}

View File

@@ -7,9 +7,8 @@
package com.facebook.flipper.sample.tutorial
import org.junit.Test
import org.junit.Assert.*
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).