Format all kotlin according to ktlint (#143390)

Entire pr generated with [ktlint](https://github.com/pinterest/ktlint) --format. First step before enabling linting as part of presubmit for kotlin changes.
This commit is contained in:
Gray Mackall 2024-02-14 09:58:18 -08:00 committed by GitHub
parent dc1f9f183f
commit c61dc2a586
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 272 additions and 228 deletions

View File

@ -2,5 +2,4 @@ package com.example.a11y_assessments
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -4,18 +4,13 @@
package dev.flutter.multipleflutters
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import io.flutter.FlutterInjector
import io.flutter.embedding.android.FlutterFragment
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor
@ -25,9 +20,10 @@ class MainActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val root = LinearLayout(this)
root.layoutParams = LinearLayout.LayoutParams(
root.layoutParams =
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
root.orientation = LinearLayout.VERTICAL
root.weightSum = numberOfFlutters.toFloat()
@ -39,9 +35,11 @@ class MainActivity : FragmentActivity() {
val app = applicationContext as App
val dartEntrypoint =
DartExecutor.DartEntrypoint(
FlutterInjector.instance().flutterLoader().findAppBundlePath(), "main"
FlutterInjector.instance().flutterLoader().findAppBundlePath(),
"main",
)
val engines = generateSequence(0) { it + 1 }
val engines =
generateSequence(0) { it + 1 }
.take(numberOfFlutters)
.map { app.engines.createAndRunEngine(this, dartEntrypoint) }
.toList()
@ -49,10 +47,11 @@ class MainActivity : FragmentActivity() {
val flutterContainer = FrameLayout(this)
root.addView(flutterContainer)
flutterContainer.id = 12345 + i
flutterContainer.layoutParams = LinearLayout.LayoutParams(
flutterContainer.layoutParams =
LinearLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT,
1.0f
1.0f,
)
val engine = engines[i]
FlutterEngineCache.getInstance().put(i.toString(), engine)
@ -62,7 +61,7 @@ class MainActivity : FragmentActivity() {
.beginTransaction()
.add(
12345 + i,
flutterFragment
flutterFragment,
)
.commit()
}

View File

@ -16,23 +16,35 @@ class MainActivity: FlutterActivity() {
// the reply requires a direct buffer, but the input is not a direct buffer.
// We can't directly send the input back to the reply currently.
private var byteBufferCache: ByteBuffer? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
val reset = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.reset", StandardMessageCodec.INSTANCE)
reset.setMessageHandler { message, reply -> run {
reset.setMessageHandler { message, reply ->
run {
byteBufferCache = null
} }
val basicStandard = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.standard", StandardMessageCodec.INSTANCE)
}
}
val basicStandard =
BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.standard", StandardMessageCodec.INSTANCE)
basicStandard.setMessageHandler { message, reply -> reply.reply(message) }
val basicBinary = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.binary", BinaryCodec.INSTANCE_DIRECT)
basicBinary.setMessageHandler { message, reply -> run {
basicBinary.setMessageHandler { message, reply ->
run {
if (byteBufferCache == null) {
byteBufferCache = ByteBuffer.allocateDirect(message!!.capacity())
byteBufferCache!!.put(message)
}
reply.reply(byteBufferCache)
} }
val taskQueue = flutterEngine.dartExecutor.getBinaryMessenger().makeBackgroundTaskQueue();
val backgroundStandard = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.background.standard", StandardMessageCodec.INSTANCE, taskQueue)
}
}
val taskQueue = flutterEngine.dartExecutor.getBinaryMessenger().makeBackgroundTaskQueue()
val backgroundStandard =
BasicMessageChannel(
flutterEngine.dartExecutor,
"dev.flutter.echo.background.standard",
StandardMessageCodec.INSTANCE,
taskQueue,
)
backgroundStandard.setMessageHandler { message, reply -> reply.reply(message) }
super.configureFlutterEngine(flutterEngine)
}

View File

@ -2,7 +2,6 @@ package com.example.abstract_method_smoke_test
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.annotation.NonNull
@ -30,17 +29,26 @@ class MainActivity : FlutterActivity() {
}
}
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
override fun configureFlutterEngine(
@NonNull flutterEngine: FlutterEngine,
) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
val shimPluginRegistry = ShimPluginRegistry(flutterEngine);
val shimPluginRegistry = ShimPluginRegistry(flutterEngine)
shimPluginRegistry.registrarFor("com.example.abstract_method_smoke_test")
.platformViewRegistry()
.registerViewFactory("simple", object : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
override fun create(context: Context?, viewId: Int, args: Any?): PlatformView {
.registerViewFactory(
"simple",
object : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
override fun create(
context: Context?,
viewId: Int,
args: Any?,
): PlatformView {
return SimplePlatformView(this@MainActivity)
}
})
},
)
// Triggers the Android keyboard, which causes the resize of the Flutter view.
// We need to wait for the app to complete.

View File

@ -1,12 +1,14 @@
package com.example.android_embedding_v2_smoke_test
import androidx.annotation.NonNull;
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
override fun configureFlutterEngine(
@NonNull flutterEngine: FlutterEngine,
) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}

View File

@ -2,5 +2,4 @@ package io.flutter.integration.deferred_components_test
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -2,5 +2,4 @@ package com.example.non_nullable
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -2,5 +2,4 @@ package com.example.spell_check
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -2,5 +2,4 @@ package dev.flutter.manual_tests
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -2,5 +2,4 @@ package com.example.tracing_tests
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -2,5 +2,4 @@ package dev.flutter.flutter_api_samples
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity()

View File

@ -7,7 +7,8 @@
// See #141540.
pluginManagement {
val flutterSdkPath = run {
val flutterSdkPath =
run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")

View File

@ -7,7 +7,6 @@ plugins {
`groovy`
}
group = "dev.flutter.plugin"
version = "1.0.0"

View File

@ -33,7 +33,6 @@ class FlutterDependencyCheckerPlugin : Plugin<Project> {
}
}
class DependencyVersionChecker {
companion object {
private const val GRADLE_NAME: String = "Gradle"
@ -53,7 +52,8 @@ class DependencyVersionChecker {
// The potential java fix does not make use of the project directory,
// so it left as a constant.
private const val POTENTIAL_JAVA_FIX : String = "The Java version used by Flutter can be " +
private const val POTENTIAL_JAVA_FIX: String =
"The Java version used by Flutter can be " +
"set with `flutter config --jdk-dir=<path>`. \nFor more information about how Flutter " +
"chooses which version of Java to use, see the --jdk-dir section of the " +
"output of `flutter config -h`.\n"
@ -113,16 +113,20 @@ class DependencyVersionChecker {
if (agpVersion != null) {
checkAGPVersion(agpVersion, project)
} else {
project.logger.error("Warning: unable to detect project AGP version. Skipping " +
"version checking. \nThis may be because you have applied AGP after the Flutter Gradle Plugin.")
project.logger.error(
"Warning: unable to detect project AGP version. Skipping " +
"version checking. \nThis may be because you have applied AGP after the Flutter Gradle Plugin.",
)
}
kgpVersion = getKGPVersion(project)
if (kgpVersion != null) {
checkKGPVersion(kgpVersion, project)
} else {
project.logger.error("Warning: unable to detect project KGP version. Skipping " +
"version checking. \nThis may be because you have applied KGP after the Flutter Gradle Plugin.")
project.logger.error(
"Warning: unable to detect project KGP version. Skipping " +
"version checking. \nThis may be because you have applied KGP after the Flutter Gradle Plugin.",
)
}
}
@ -143,24 +147,26 @@ class DependencyVersionChecker {
// This approach is taken from AGP's own version checking plugin:
// https://android.googlesource.com/platform/tools/base/+/1839aa23b8dc562005e2f0f0cc8e8b4c5caa37d0/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/utils/agpVersionChecker.kt#58.
fun getAGPVersion(project: Project): Version? {
val agpPluginName : String = "com.android.base";
val agpPluginName: String = "com.android.base"
val agpVersionFieldName: String = "ANDROID_GRADLE_PLUGIN_VERSION"
var agpVersion: Version? = null
try {
agpVersion = Version.fromString(
agpVersion =
Version.fromString(
project.plugins.getPlugin(agpPluginName)::class.java.classLoader.loadClass(
com.android.Version::class.java.name
com.android.Version::class.java.name,
).fields.find { it.name == agpVersionFieldName }!!
.get(null) as String
.get(null) as String,
)
} catch (ignored: ClassNotFoundException) {
// Use deprecated Version class as it exists in older AGP (com.android.Version) does
// not exist in those versions.
agpVersion = Version.fromString(
agpVersion =
Version.fromString(
project.plugins.getPlugin(agpPluginName)::class.java.classLoader.loadClass(
com.android.builder.model.Version::class.java.name
com.android.builder.model.Version::class.java.name,
).fields.find { it.name == agpVersionFieldName }!!
.get(null) as String
.get(null) as String,
)
}
return agpVersion
@ -175,10 +181,13 @@ class DependencyVersionChecker {
if (project.hasProperty(kotlinVersionProperty)) {
return Version.fromString(project.properties.get(kotlinVersionProperty) as String)
}
val kotlinPlugin = project.getPlugins()
val kotlinPlugin =
project.getPlugins()
.findPlugin(KotlinAndroidPluginWrapper::class.java)
val versionfield =
kotlinPlugin?.javaClass?.kotlin?.members?.first { it.name == firstKotlinVersionFieldName || it.name == secondKotlinVersionFieldName }
kotlinPlugin?.javaClass?.kotlin?.members?.first {
it.name == firstKotlinVersionFieldName || it.name == secondKotlinVersionFieldName
}
val versionString = versionfield?.call(kotlinPlugin)
if (versionString == null) {
return null
@ -187,10 +196,12 @@ class DependencyVersionChecker {
}
}
private fun getErrorMessage(dependencyName : String,
private fun getErrorMessage(
dependencyName: String,
versionString: String,
errorVersion: String,
potentialFix : String) : String {
potentialFix: String,
): String {
return "Error: Your project's $dependencyName version ($versionString) is lower " +
"than Flutter's minimum supported version of $errorVersion. Please upgrade " +
"your $dependencyName version. \nAlternatively, use the flag " +
@ -198,10 +209,12 @@ class DependencyVersionChecker {
"Potential fix: $potentialFix"
}
private fun getWarnMessage(dependencyName : String,
private fun getWarnMessage(
dependencyName: String,
versionString: String,
warnVersion: String,
potentialFix : String) : String {
potentialFix: String,
): String {
return "Warning: Flutter support for your project's $dependencyName version " +
"($versionString) will soon be dropped. Please upgrade your $dependencyName " +
"version to a version of at least $warnVersion soon." +
@ -209,85 +222,101 @@ class DependencyVersionChecker {
" to bypass this check.\n\nPotential fix: $potentialFix"
}
fun checkGradleVersion(version : Version, project : Project) {
fun checkGradleVersion(
version: Version,
project: Project,
) {
if (version < errorGradleVersion) {
val errorMessage : String = getErrorMessage(
val errorMessage: String =
getErrorMessage(
GRADLE_NAME,
version.toString(),
errorGradleVersion.toString(),
getPotentialGradleFix(project.getRootDir().getPath())
getPotentialGradleFix(project.getRootDir().getPath()),
)
throw GradleException(errorMessage)
}
else if (version < warnGradleVersion) {
val warnMessage : String = getWarnMessage(
} else if (version < warnGradleVersion) {
val warnMessage: String =
getWarnMessage(
GRADLE_NAME,
version.toString(),
warnGradleVersion.toString(),
getPotentialGradleFix(project.getRootDir().getPath())
getPotentialGradleFix(project.getRootDir().getPath()),
)
project.logger.error(warnMessage)
}
}
fun checkJavaVersion(version : JavaVersion, project : Project) {
fun checkJavaVersion(
version: JavaVersion,
project: Project,
) {
if (version < errorJavaVersion) {
val errorMessage : String = getErrorMessage(
val errorMessage: String =
getErrorMessage(
JAVA_NAME,
version.toString(),
errorJavaVersion.toString(),
POTENTIAL_JAVA_FIX
POTENTIAL_JAVA_FIX,
)
throw GradleException(errorMessage)
}
else if (version < warnJavaVersion) {
val warnMessage : String = getWarnMessage(
} else if (version < warnJavaVersion) {
val warnMessage: String =
getWarnMessage(
JAVA_NAME,
version.toString(),
warnJavaVersion.toString(),
POTENTIAL_JAVA_FIX
POTENTIAL_JAVA_FIX,
)
project.logger.error(warnMessage)
}
}
fun checkAGPVersion(version : Version, project : Project) {
fun checkAGPVersion(
version: Version,
project: Project,
) {
if (version < errorAGPVersion) {
val errorMessage : String = getErrorMessage(
val errorMessage: String =
getErrorMessage(
AGP_NAME,
version.toString(),
errorAGPVersion.toString(),
getPotentialAGPFix(project.getRootDir().getPath())
getPotentialAGPFix(project.getRootDir().getPath()),
)
throw GradleException(errorMessage)
}
else if (version < warnAGPVersion) {
val warnMessage : String = getWarnMessage(
} else if (version < warnAGPVersion) {
val warnMessage: String =
getWarnMessage(
AGP_NAME,
version.toString(),
warnAGPVersion.toString(),
getPotentialAGPFix(project.getRootDir().getPath())
getPotentialAGPFix(project.getRootDir().getPath()),
)
project.logger.error(warnMessage)
}
}
fun checkKGPVersion(version : Version, project : Project) {
fun checkKGPVersion(
version: Version,
project: Project,
) {
if (version < errorKGPVersion) {
val errorMessage : String = getErrorMessage(
val errorMessage: String =
getErrorMessage(
KGP_NAME,
version.toString(),
errorKGPVersion.toString(),
getPotentialKGPFix(project.getRootDir().getPath())
getPotentialKGPFix(project.getRootDir().getPath()),
)
throw GradleException(errorMessage)
}
else if (version < warnKGPVersion) {
val warnMessage : String = getWarnMessage(
} else if (version < warnKGPVersion) {
val warnMessage: String =
getWarnMessage(
KGP_NAME,
version.toString(),
warnKGPVersion.toString(),
getPotentialKGPFix(project.getRootDir().getPath())
getPotentialKGPFix(project.getRootDir().getPath()),
)
project.logger.error(warnMessage)
}
@ -295,7 +324,6 @@ class DependencyVersionChecker {
}
}
// Helper class to parse the versions that are provided as plain strings (Gradle, Kotlin) and
// perform easy comparisons. All versions will have a major, minor, and patch value. These values
// default to 0 when they are not provided or are otherwise unparseable.
@ -308,10 +336,11 @@ class Version(val major : Int, val minor : Int, val patch : Int) : Comparable<Ve
return Version(
major = convertedToNumbers.getOrElse(0, { 0 }),
minor = convertedToNumbers.getOrElse(1, { 0 }),
patch = convertedToNumbers.getOrElse(2, {0})
patch = convertedToNumbers.getOrElse(2, { 0 }),
)
}
}
override fun compareTo(otherVersion: Version): Int {
if (major != otherVersion.major) {
return major - otherVersion.major
@ -324,6 +353,7 @@ class Version(val major : Int, val minor : Int, val patch : Int) : Comparable<Ve
}
return 0
}
override fun toString(): String {
return major.toString() + "." + minor.toString() + "." + patch.toString()
}