From 897bd1c532be8a73019473f28f39414c73ceaffc Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 12:09:41 +0200 Subject: [PATCH 1/7] WireSchemaTests as MPP module --- .../com/squareup/wire/SchemaBuilderTest.kt | 67 +++++++++++++++++ .../recipes/ErrorReportingSchemaHandler.kt | 45 +++++++++++ .../ErrorReportingSchemaHandlerTest.kt | 71 ++++++++++++++++++ .../squareup/wire/recipes/LogToFileHandler.kt | 54 +++++++++++++ .../wire/recipes/LogToFileHandlerTest.kt | 75 +++++++++++++++++++ .../wire/recipes/LogToWireLoggerHandler.kt | 46 ++++++++++++ .../recipes/LogToWireLoggerHandlerTest.kt | 73 ++++++++++++++++++ 7 files changed, 431 insertions(+) create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt create mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt new file mode 100644 index 0000000000..b1e145495d --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.wire + +import com.squareup.wire.schema.Location +import com.squareup.wire.schema.SchemaException +import okio.Path.Companion.toPath +import org.assertj.core.api.Assertions.assertThat +import kotlin.test.Test +import kotlin.test.assertFailsWith + +class SchemaBuilderTest { + @Test fun emptySchema() { + val exception = assertFailsWith { + buildSchema {} + } + assertThat(exception.message).isEqualTo("no sources") + } + + @Test fun sourcePathOnly() { + val schema = buildSchema { + add( + "example1.proto".toPath(), + """ + |syntax = "proto2"; + | + |message A { + | optional B b = 1; + |} + |message B { + | optional C c = 1; + |} + |message C { + |} + |""".trimMargin() + ) + add( + "example2.proto".toPath(), + """ + |syntax = "proto2"; + | + |message D { + |} + |""".trimMargin() + ) + } + assertThat(schema.protoFiles.map { it.location }).containsExactlyInAnyOrder( + Location.get("/sourcePath", "example1.proto"), + Location.get("/sourcePath", "example2.proto"), + Location.get("google/protobuf/descriptor.proto"), + Location.get("wire/extensions.proto"), + ) + } +} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt new file mode 100644 index 0000000000..b9d4ef6315 --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.wire.recipes + +import com.squareup.wire.schema.Extend +import com.squareup.wire.schema.Field +import com.squareup.wire.schema.MessageType +import com.squareup.wire.schema.SchemaHandler +import com.squareup.wire.schema.Service +import com.squareup.wire.schema.Type +import okio.Path + +/** Sample schema validator that enforces a field naming pattern. */ +class ErrorReportingSchemaHandler : SchemaHandler() { + override fun handle(type: Type, context: SchemaHandler.Context): Path? { + val errorCollector = context.errorCollector + + if ("descriptor.proto" in type.location.path) return null // Don't report errors on built-in stuff. + if (type is MessageType) { + for (field in type.fields) { + if (field.name.startsWith("a")) { + errorCollector.at(field) += "field starts with 'a'" + } + } + } + return null + } + + override fun handle(service: Service, context: SchemaHandler.Context): List = emptyList() + + override fun handle(extend: Extend, field: Field, context: SchemaHandler.Context): Path? = null +} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt new file mode 100644 index 0000000000..831789977b --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.wire.recipes + +import com.squareup.wire.WireTestLogger +import com.squareup.wire.buildSchema +import com.squareup.wire.schema.ErrorCollector +import com.squareup.wire.schema.SchemaException +import com.squareup.wire.schema.SchemaHandler +import okio.Path.Companion.toPath +import okio.fakefilesystem.FakeFileSystem +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import kotlin.test.assertFailsWith + +class ErrorReportingSchemaHandlerTest { + @Test fun errorsWhenStartsWithA() { + val schema = buildSchema { + add( + name = "a.proto".toPath(), + protoFile = """ + |syntax = "proto2"; + | + |message A { + | optional string acrobatic = 1; + | optional string biofidus = 2; + |} + """.trimMargin() + ) + add( + name = "b.proto".toPath(), + protoFile = """ + |syntax = "proto2"; + | + |message B { + | optional string comment = 1; + | optional string dinosaur = 2; + |} + """.trimMargin() + ) + } + + val errorCollector = ErrorCollector() + val context = SchemaHandler.Context( + fileSystem = FakeFileSystem(), + outDirectory = "out".toPath(), + logger = WireTestLogger(), + errorCollector = errorCollector, + ) + + ErrorReportingSchemaHandler().handle(schema, context) + val exception = assertFailsWith { + errorCollector.throwIfNonEmpty() + } + + assertThat(exception.message).startsWith("field starts with 'a'") + } +} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt new file mode 100644 index 0000000000..e2601b239f --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.wire.recipes + +import com.squareup.wire.schema.Extend +import com.squareup.wire.schema.Field +import com.squareup.wire.schema.SchemaHandler +import com.squareup.wire.schema.Service +import com.squareup.wire.schema.Type +import okio.Path +import okio.Path.Companion.toPath +import okio.buffer + +/** Sample schema handler which writes to disk generated artifacts. */ +class LogToFileHandler : SchemaHandler() { + private val filePath = "log.txt".toPath() + + override fun handle(type: Type, context: SchemaHandler.Context): Path? { + context.fileSystem.appendingSink(filePath).buffer().use { + it.writeUtf8("Generating type: ${type.type}\n") + } + + return null + } + + override fun handle(service: Service, context: SchemaHandler.Context): List { + context.fileSystem.appendingSink(filePath).buffer().use { + it.writeUtf8("Generating service: ${service.type}\n") + } + + return listOf() + } + + override fun handle(extend: Extend, field: Field, context: SchemaHandler.Context): Path? { + context.fileSystem.appendingSink(filePath).buffer().use { + it.writeUtf8("Generating ${extend.type} on ${field.location}\n") + } + + return null + } +} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt new file mode 100644 index 0000000000..21a3c2de18 --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.wire.recipes + +import com.squareup.wire.WireTestLogger +import com.squareup.wire.buildSchema +import com.squareup.wire.schema.SchemaHandler +import okio.BufferedSource +import okio.Path.Companion.toPath +import okio.fakefilesystem.FakeFileSystem +import org.junit.Test +import kotlin.test.assertEquals + +class LogToFileHandlerTest { + @Test fun loggingTypes() { + val schema = buildSchema { + add( + name = "test/message.proto".toPath(), + protoFile = """ + |syntax = "proto2"; + | + |package test; + | + |message Request {} + |message Response { + | optional string result = 1; + |} + """.trimMargin() + ) + add( + name = "test/service.proto".toPath(), + protoFile = """ + |syntax = "proto2"; + | + |package test; + | + |import "test/message.proto"; + | + |service MyService { + | rpc fetch(test.Request) returns(test.Response) {}; + |} + """.trimMargin() + ) + } + + val context = SchemaHandler.Context( + fileSystem = FakeFileSystem(), + outDirectory = "/".toPath(), + logger = WireTestLogger(), + sourcePathPaths = setOf("test/message.proto", "test/service.proto"), + ) + LogToFileHandler().handle(schema, context) + + val content = context.fileSystem.read("log.txt".toPath(), BufferedSource::readUtf8) + val expected = """ + |Generating type: test.Request + |Generating type: test.Response + |Generating service: test.MyService + |""".trimMargin() + assertEquals(expected, content) + } +} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt new file mode 100644 index 0000000000..ef660abe0a --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.wire.recipes + +import com.squareup.wire.schema.Extend +import com.squareup.wire.schema.Field +import com.squareup.wire.schema.SchemaHandler +import com.squareup.wire.schema.Service +import com.squareup.wire.schema.Type +import okio.Path + +/** Sample schema handler which logs handled types and services. */ +class LogToWireLoggerHandler : SchemaHandler() { + override fun handle(type: Type, context: SchemaHandler.Context): Path? { + context.logger.artifactHandled( + context.outDirectory, type.type.enclosingTypeOrPackage ?: "", type.type.simpleName + ) + + return null + } + + override fun handle(service: Service, context: SchemaHandler.Context): List { + context.logger.artifactHandled( + context.outDirectory, service.type.enclosingTypeOrPackage ?: "", service.type.simpleName + ) + + return listOf() + } + + override fun handle(extend: Extend, field: Field, context: SchemaHandler.Context): Path? { + return null + } +} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt new file mode 100644 index 0000000000..0bbaea5292 --- /dev/null +++ b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2022 Block Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@file:Suppress("UsePropertyAccessSyntax") + +package com.squareup.wire.recipes + +import com.squareup.wire.WireTestLogger +import com.squareup.wire.buildSchema +import com.squareup.wire.schema.SchemaHandler +import okio.Path.Companion.toPath +import okio.fakefilesystem.FakeFileSystem +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test + +class LogToWireLoggerHandlerTest { + @Test fun loggingArtifacts() { + val schema = buildSchema { + add( + name = "test/message.proto".toPath(), + protoFile = """ + |syntax = "proto2"; + | + |package test; + | + |message Request {} + |message Response { + | optional string result = 1; + |} + """.trimMargin() + ) + add( + name = "test/service.proto".toPath(), + protoFile = """ + |syntax = "proto2"; + | + |package test; + | + |import "test/message.proto"; + | + |service MyService { + | rpc fetch(test.Request) returns(test.Response) {}; + |} + """.trimMargin() + ) + } + val logger = WireTestLogger() + val context = SchemaHandler.Context( + fileSystem = FakeFileSystem(), + outDirectory = "out".toPath(), + logger = logger, + sourcePathPaths = setOf("test/message.proto", "test/service.proto"), + ) + LogToWireLoggerHandler().handle(schema, context) + + assertThat(logger.artifactHandled.removeFirst()).isEqualTo(Triple("out".toPath(), "test", "Request")) + assertThat(logger.artifactHandled.removeFirst()).isEqualTo(Triple("out".toPath(), "test", "Response")) + assertThat(logger.artifactHandled.removeFirst()).isEqualTo(Triple("out".toPath(), "test", "MyService")) + assertThat(logger.artifactHandled.isEmpty()).isTrue() + } +} From 5c30aee4408d8bddb8907ac8bc9a0f7e227694da Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 19:31:56 +0200 Subject: [PATCH 2/7] Spotless: wire-compiler --- build.gradle.kts | 25 +- gradle/libs.versions.toml | 5 +- .../com/squareup/wire/ConsoleWireLogger.kt | 12 +- .../com/squareup/wire/DryRunFileSystem.kt | 4 +- .../main/java/com/squareup/wire/Manifest.kt | 8 +- .../java/com/squareup/wire/WireCompiler.kt | 22 +- .../java/com/squareup/wire/WireException.kt | 4 +- .../java/com/squareup/wire/schema/Target.kt | 31 +- .../com/squareup/wire/schema/fileSystems.kt | 2 +- .../squareup/wire/CommandLineOptionsTest.kt | 18 +- .../com/squareup/wire/ManifestParseTest.kt | 4 +- .../com/squareup/wire/StringWireLogger.kt | 14 +- .../squareup/wire/WireCompilerErrorTest.kt | 39 ++- .../com/squareup/wire/WireCompilerTest.kt | 63 ++-- .../squareup/wire/schema/CycleCheckerTest.kt | 58 ++-- .../com/squareup/wire/schema/LinkerTest.kt | 32 +- .../squareup/wire/schema/MarkdownHandler.kt | 8 +- .../wire/schema/OptionsLinkingTest.kt | 42 +-- .../com/squareup/wire/schema/WireRunTest.kt | 322 +++++++++--------- wire-grpc-server-generator/build.gradle.kts | 8 - wire-grpc-tests/build.gradle.kts | 9 - wire-gson-support/build.gradle.kts | 11 - wire-moshi-adapter/build.gradle.kts | 11 - 23 files changed, 375 insertions(+), 377 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1a17264dd9..0a90225df6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -58,13 +58,34 @@ allprojects { subprojects { apply(plugin = "com.diffplug.spotless") configure { - setEnforceCheck(false) + val licenseHeaderFile = rootProject.file("gradle/license-header.txt") kotlin { target("**/*.kt") - ktlint(libs.versions.ktlint.get()).userData(kotlin.collections.mapOf("indent_size" to "2")) + ktlint(libs.versions.ktlint.get()).editorConfigOverride( + mapOf("ktlint_standard_filename" to "disabled"), + ) trimTrailingWhitespace() endWithNewline() toggleOffOn() + // We cannot use it because the licensing job happens before. The header will be replaced and + // spotless will throw. We have to manually exclude stuff for now. + // See https://github.com/diffplug/spotless/discussions/1738 + toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""") + + licenseHeaderFile(licenseHeaderFile) + } + java { + target("**/*.java") + googleJavaFormat(libs.googleJavaFormat.get().version) + trimTrailingWhitespace() + endWithNewline() + toggleOffOn() + // We cannot use it because the licensing job happens before. The header will be replaced and + // spotless will throw. We have to manually exclude stuff for now. + // See https://github.com/diffplug/spotless/discussions/1738 + // toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""") + + licenseHeaderFile(licenseHeaderFile) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0b52b12acd..0a474da3dd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ jsr305 = "3.0.2" junit = "4.13.2" kotlin = "1.8.20" kotlinpoet = "1.14.2" -ktlint = "0.42.1" +ktlint = "0.48.2" moshi = "1.13.0" okhttp = "4.9.3" okio = "3.4.0" @@ -32,6 +32,7 @@ assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } contour = { module = "app.cash.contour:contour", version = "1.1.0" } dokka-core = { module = "org.jetbrains.dokka:dokka-core", version.ref = "dokka" } dokka-gradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" } +googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.17.0" grpc-genJava = { module = "io.grpc:protoc-gen-grpc-java", version.ref = "grpc" } grpc-netty = { module = "io.grpc:grpc-netty", version.ref = "grpc" } grpc-protobuf = { module = "io.grpc:grpc-protobuf", version.ref = "grpc" } @@ -73,7 +74,7 @@ pluginz-binaryCompatibilityValidator = { module = "org.jetbrains.kotlinx.binary- pluginz-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } pluginz-kotlinSerialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } pluginz-shadow = { module = "com.github.jengelman.gradle.plugins:shadow", version = "4.0.1" } -pluginz-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.3.0" } +pluginz-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.19.0" } pluginz-buildConfig = { module = "com.github.gmazzo:gradle-buildconfig-plugin", version = "3.1.0" } protobuf-gradlePlugin = { module = "com.google.protobuf:protobuf-gradle-plugin", version.ref = "protobufGradlePlugin" } protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" } diff --git a/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt b/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt index 2f217275a8..f29621f6d2 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ internal class ConsoleWireLogger : WireLogger { println( """Unused element in treeShakingRoots: | ${unusedRoots.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -37,7 +37,7 @@ internal class ConsoleWireLogger : WireLogger { println( """Unused element in treeShakingRubbish: | ${unusedPrunes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -47,7 +47,7 @@ internal class ConsoleWireLogger : WireLogger { println( """Unused includes in targets: | ${unusedIncludes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -57,7 +57,7 @@ internal class ConsoleWireLogger : WireLogger { println( """Unused excludes in targets: | ${unusedExcludes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } diff --git a/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt b/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt index 30cfdcdb2e..de1cc496e6 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt @@ -1,11 +1,11 @@ /* - * Copyright 2023 Block Inc. + * Copyright (C) 2023 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt b/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt index 615f604dd1..44d344891e 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,7 +29,7 @@ private val defaultPrunes = emptySet() private data class ManifestModule( val dependencies: Set = emptySet(), val roots: Set = defaultRoots, - val prunes: Set = defaultPrunes + val prunes: Set = defaultPrunes, ) private val serializer = MapSerializer(String.serializer(), ManifestModule.serializer()) @@ -46,7 +46,7 @@ internal fun parseManifestModules(yaml: String): Map { .build() } else { null - } + }, ) } } diff --git a/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt b/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt index f705c5aa52..4cd8698141 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,16 +24,16 @@ import com.squareup.wire.schema.Target import com.squareup.wire.schema.WIRE_RUNTIME_JAR import com.squareup.wire.schema.WireRun import com.squareup.wire.schema.isWireRuntimeProto -import com.squareup.wire.schema.newSchemaHandler import com.squareup.wire.schema.newEventListenerFactory +import com.squareup.wire.schema.newSchemaHandler import com.squareup.wire.schema.toOkioFileSystem +import java.io.IOException +import java.nio.file.FileSystem as NioFileSystem import okio.FileNotFoundException import okio.FileSystem import okio.Path import okio.Path.Companion.toPath import okio.openZip -import java.io.IOException -import java.nio.file.FileSystem as NioFileSystem /** * Command line interface to the Wire Java generator. @@ -128,7 +128,7 @@ class WireCompiler internal constructor( androidAnnotations = emitAndroidAnnotations, compact = emitCompact, emitDeclaredOptions = emitDeclaredOptions, - emitAppliedOptions = emitAppliedOptions + emitAppliedOptions = emitAppliedOptions, ) } else if (kotlinOut != null) { targets += KotlinTarget( @@ -141,7 +141,7 @@ class WireCompiler internal constructor( ) } else if (swiftOut != null) { targets += SwiftTarget( - outDirectory = swiftOut + outDirectory = swiftOut, ) } else if (customOut != null || schemaHandlerFactoryClass != null) { if (customOut == null || schemaHandlerFactoryClass == null) { @@ -149,7 +149,7 @@ class WireCompiler internal constructor( } targets += CustomTarget( outDirectory = customOut, - schemaHandlerFactory = newSchemaHandler(schemaHandlerFactoryClass) + schemaHandlerFactory = newSchemaHandler(schemaHandlerFactoryClass), ) } @@ -249,7 +249,7 @@ class WireCompiler internal constructor( fun forArgs( fileSystem: NioFileSystem, logger: WireLogger, - vararg args: String + vararg args: String, ): WireCompiler { return forArgs(fileSystem.toOkioFileSystem(), logger, *args) } @@ -260,7 +260,7 @@ class WireCompiler internal constructor( fun forArgs( fileSystem: FileSystem = FileSystem.SYSTEM, logger: WireLogger = ConsoleWireLogger(), - vararg args: String + vararg args: String, ): WireCompiler { val sourceFileNames = mutableListOf() val treeShakingRoots = mutableListOf() @@ -361,7 +361,7 @@ class WireCompiler internal constructor( if (javaOut == null && kotlinOut == null && swiftOut == null && customOut == null) { throw WireException( - "Nothing to do! Specify $JAVA_OUT_FLAG, $KOTLIN_OUT_FLAG, $SWIFT_OUT_FLAG, or $CUSTOM_OUT_FLAG" + "Nothing to do! Specify $JAVA_OUT_FLAG, $KOTLIN_OUT_FLAG, $SWIFT_OUT_FLAG, or $CUSTOM_OUT_FLAG", ) } diff --git a/wire-compiler/src/main/java/com/squareup/wire/WireException.kt b/wire-compiler/src/main/java/com/squareup/wire/WireException.kt index df2dc1f155..d417f6f80a 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/WireException.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/WireException.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt b/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt index 42e378f775..2cee9968ea 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,9 +21,9 @@ import com.squareup.wire.kotlin.KotlinSchemaHandler import com.squareup.wire.kotlin.RpcCallStyle import com.squareup.wire.kotlin.RpcRole import com.squareup.wire.swift.SwiftGenerator -import okio.Path -import java.io.IOException import io.outfoxx.swiftpoet.FileSpec as SwiftFileSpec +import java.io.IOException +import okio.Path /** Generate `.java` sources. */ data class JavaTarget( @@ -70,7 +70,7 @@ data class JavaTarget( includes: List, excludes: List, exclusive: Boolean, - outDirectory: String + outDirectory: String, ): Target { return copy( includes = includes, @@ -153,7 +153,7 @@ data class KotlinTarget( includes: List, excludes: List, exclusive: Boolean, - outDirectory: String + outDirectory: String, ): Target { return copy( includes = includes, @@ -169,7 +169,7 @@ data class SwiftTarget( override val includes: List = listOf("*"), override val excludes: List = listOf(), override val exclusive: Boolean = true, - override val outDirectory: String + override val outDirectory: String, ) : Target() { override fun newHandler(): SchemaHandler { return object : SchemaHandler() { @@ -203,7 +203,8 @@ data class SwiftTarget( } } catch (e: IOException) { throw IOException( - "Error emitting ${swiftFile.moduleName}.${typeName.canonicalName} to $modulePath", e + "Error emitting ${swiftFile.moduleName}.${typeName.canonicalName} to $modulePath", + e, ) } @@ -219,7 +220,7 @@ data class SwiftTarget( override fun handle( extend: Extend, field: Field, - context: Context + context: Context, ): Path? = null } } @@ -228,7 +229,7 @@ data class SwiftTarget( includes: List, excludes: List, exclusive: Boolean, - outDirectory: String + outDirectory: String, ): Target { return copy( includes = includes, @@ -240,7 +241,7 @@ data class SwiftTarget( } data class ProtoTarget( - override val outDirectory: String + override val outDirectory: String, ) : Target() { override val includes: List = listOf() override val excludes: List = listOf() @@ -286,7 +287,7 @@ data class ProtoTarget( includes: List, excludes: List, exclusive: Boolean, - outDirectory: String + outDirectory: String, ): Target { return copy( outDirectory = outDirectory, @@ -306,7 +307,7 @@ data class CustomTarget( includes: List, excludes: List, exclusive: Boolean, - outDirectory: String + outDirectory: String, ): Target { return this.copy( includes = includes, @@ -342,7 +343,7 @@ fun newSchemaHandler(schemaHandlerFactoryClass: String): SchemaHandler.Factory { * even if the delegate handler class is itself not serializable. */ private class ClassNameSchemaHandlerFactory( - private val schemaHandlerFactoryClass: String + private val schemaHandlerFactoryClass: String, ) : SchemaHandler.Factory { @Transient private var cachedDelegate: SchemaHandler.Factory? = null @@ -380,7 +381,7 @@ private class ClassNameSchemaHandlerFactory( excludes: List, exclusive: Boolean, outDirectory: String, - options: Map + options: Map, ): SchemaHandler { return delegate.create(includes, excludes, exclusive, outDirectory, options) } diff --git a/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt b/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt index fed4d70c8c..309a44c617 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt b/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt index a5904acce6..561d2bd38d 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.squareup.wire import com.squareup.wire.schema.WireRun -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test import java.io.File import java.io.FileOutputStream import java.io.PrintWriter import kotlin.test.assertFailsWith +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test class CommandLineOptionsTest { @Test @@ -41,7 +41,10 @@ class CommandLineOptionsTest { assertThat(compiler.protoPaths).containsOnly("foo/bar") compiler = parseArgs( - "--java_out=.", "--proto_path=foo/bar", "--proto_path=one/two", "--proto_path=three/four" + "--java_out=.", + "--proto_path=foo/bar", + "--proto_path=one/two", + "--proto_path=three/four", ) assertThat(compiler.protoPaths).containsExactly("foo/bar", "one/two", "three/four") } @@ -114,14 +117,15 @@ class CommandLineOptionsTest { |b: | dependencies: | - a - |""".trimMargin() + | + """.trimMargin(), ) val compiler = parseArgs("--java_out=.", "--experimental-module-manifest=${tmpFile.absolutePath}") assertThat(compiler.modules).isEqualTo( - mapOf("a" to WireRun.Module(), "b" to WireRun.Module(dependencies = setOf("a"))) + mapOf("a" to WireRun.Module(), "b" to WireRun.Module(dependencies = setOf("a"))), ) } diff --git a/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt b/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt index d3fdf018f6..564970bd0e 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt b/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt index 350bbd01bc..cff0387b92 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ internal class StringWireLogger : WireLogger { @Synchronized override fun artifactHandled( outputPath: Path, qualifiedName: String, - targetName: String + targetName: String, ) { buffer.append("$outputPath $qualifiedName (target=$targetName)\n") } @@ -42,7 +42,7 @@ internal class StringWireLogger : WireLogger { buffer.append( """Unused element in treeShakingRoots: | ${unusedRoots.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -52,7 +52,7 @@ internal class StringWireLogger : WireLogger { buffer.append( """Unused element in treeShakingRubbish: | ${unusedPrunes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -62,7 +62,7 @@ internal class StringWireLogger : WireLogger { buffer.append( """Unused includes in targets: | ${unusedIncludes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -72,7 +72,7 @@ internal class StringWireLogger : WireLogger { buffer.append( """Unused excludes in targets: | ${unusedExcludes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } } diff --git a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt index ae82e6f596..2d44914bbc 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,12 +16,12 @@ package com.squareup.wire import com.squareup.wire.schema.SchemaException +import kotlin.test.assertFailsWith import okio.Path import okio.Path.Companion.toPath import okio.fakefilesystem.FakeFileSystem import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.assertFailsWith class WireCompilerErrorTest { private var fileSystem = FakeFileSystem().apply { @@ -46,8 +46,11 @@ class WireCompilerErrorTest { } val compiler = WireCompiler.forArgs( - fileSystem, StringWireLogger(), - "--proto_path=/source", "--java_out=/target", *fileNames.toTypedArray() + fileSystem, + StringWireLogger(), + "--proto_path=/source", + "--java_out=/target", + *fileNames.toTypedArray(), ) compiler.compile() } @@ -60,11 +63,11 @@ class WireCompilerErrorTest { |message Simple { | optional int32 f = 1; |} - """.trimMargin() + """.trimMargin(), ) val generatedSource = readFile("/target/com/squareup/protos/test/Simple.java") assertThat(generatedSource).contains( - "public final class Simple extends Message {" + "public final class Simple extends Message {", ) } @@ -77,7 +80,7 @@ class WireCompilerErrorTest { |message Simple { | optional int32 f = 0; |} - """.trimMargin() + """.trimMargin(), ) } assertThat(e).hasMessage( @@ -85,7 +88,7 @@ class WireCompilerErrorTest { |tag is out of range: 0 | for field f (/source/test_1.proto:3:3) | in message com.squareup.protos.test.Simple (/source/test_1.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } @@ -99,7 +102,7 @@ class WireCompilerErrorTest { | optional int32 f = 1; | optional int32 g = 1; |} - """.trimMargin() + """.trimMargin(), ) } assertThat(e).hasMessage( @@ -108,7 +111,7 @@ class WireCompilerErrorTest { | 1. f (/source/test_1.proto:3:3) | 2. g (/source/test_1.proto:4:3) | for message com.squareup.protos.test.Simple (/source/test_1.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } @@ -129,7 +132,7 @@ class WireCompilerErrorTest { | QUIX = 1; | } |} - """.trimMargin() + """.trimMargin(), ) } assertThat(e).hasMessage( @@ -138,7 +141,7 @@ class WireCompilerErrorTest { | 1. com.squareup.protos.test.Foo.Bar.QUIX (/source/test_1.proto:4:5) | 2. com.squareup.protos.test.Foo.Bar2.QUIX (/source/test_1.proto:10:5) | for message com.squareup.protos.test.Foo (/source/test_1.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } @@ -153,7 +156,7 @@ class WireCompilerErrorTest { | QUIX = 0; | FOO = 1; |} - """.trimMargin(), + """.trimMargin(), """ |package com.squareup.protos.test; | @@ -161,7 +164,7 @@ class WireCompilerErrorTest { | BAZ = 0; | QUIX = 1; |} - """.trimMargin() + """.trimMargin(), ) } assertThat(e).hasMessage( @@ -170,7 +173,7 @@ class WireCompilerErrorTest { | 1. com.squareup.protos.test.Bar.QUIX (/source/test_1.proto:4:3) | 2. com.squareup.protos.test.Bar2.QUIX (/source/test_2.proto:5:3) | for file /source/test_1.proto - """.trimMargin() + """.trimMargin(), ) } @@ -190,7 +193,7 @@ class WireCompilerErrorTest { | BAZ = 0; | QUIX = 1; |} - """.trimMargin() + """.trimMargin(), ) } assertThat(e).hasMessage( @@ -199,7 +202,7 @@ class WireCompilerErrorTest { | 1. com.squareup.protos.test.Bar.QUIX (/source/test_1.proto:4:3) | 2. com.squareup.protos.test.Bar2.QUIX (/source/test_1.proto:10:3) | for file /source/test_1.proto - """.trimMargin() + """.trimMargin(), ) } diff --git a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt index c2e91ae699..87b430c099 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package com.squareup.wire import com.squareup.wire.schema.ProtoType +import java.util.Collections import okio.FileSystem import okio.Path import okio.Path.Companion.toOkioPath @@ -27,7 +28,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -import java.util.Collections class WireCompilerTest { @Rule @@ -58,7 +58,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/foobar/protos/bar/Bar.java", - "com/squareup/foobar/protos/foo/Foo.java" + "com/squareup/foobar/protos/foo/Foo.java", ) assertJavaOutputs(outputs) } @@ -70,7 +70,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/differentpackage/protos/bar/Bar.java", - "com/squareup/differentpackage/protos/foo/Foo.java" + "com/squareup/differentpackage/protos/foo/Foo.java", ) assertJavaOutputs(outputs) } @@ -143,7 +143,7 @@ class WireCompilerTest { "com/squareup/wire/protos/simple/ExternalMessage.java", "com/squareup/wire/protos/foreign/ForeignEnum.java", "com/squareup/wire/protos/foreign/ForeignEnumValueOptionOption.java", - "com/squareup/wire/protos/foreign/ForeignMessage.java" + "com/squareup/wire/protos/foreign/ForeignMessage.java", ) assertJavaOutputs(outputs) } @@ -164,7 +164,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/wire/protos/single_level/Foo.java", - "com/squareup/wire/protos/single_level/Foos.java" + "com/squareup/wire/protos/single_level/Foos.java", ) assertJavaOutputs(outputs) } @@ -173,7 +173,7 @@ class WireCompilerTest { fun testSameBasename() { val sources = arrayOf( "single_level.proto", - "samebasename/single_level.proto" + "samebasename/single_level.proto", ) compileToJava(sources) @@ -181,7 +181,7 @@ class WireCompilerTest { "com/squareup/wire/protos/single_level/Foo.java", "com/squareup/wire/protos/single_level/Foos.java", "com/squareup/wire/protos/single_level/Bar.java", - "com/squareup/wire/protos/single_level/Bars.java" + "com/squareup/wire/protos/single_level/Bars.java", ) assertJavaOutputs(outputs) } @@ -213,7 +213,7 @@ class WireCompilerTest { "com/squareup/wire/protos/edgecases/NoFields.java", "com/squareup/wire/protos/edgecases/OneField.java", "com/squareup/wire/protos/edgecases/OneBytesField.java", - "com/squareup/wire/protos/edgecases/Recursive.java" + "com/squareup/wire/protos/edgecases/Recursive.java", ) assertJavaOutputs(outputs) } @@ -229,7 +229,7 @@ class WireCompilerTest { "com/squareup/wire/protos/unknownfields/VersionOne.java", "com/squareup/wire/protos/unknownfields/VersionTwo.java", "com/squareup/wire/protos/unknownfields/NestedVersionOne.java", - "com/squareup/wire/protos/unknownfields/NestedVersionTwo.java" + "com/squareup/wire/protos/unknownfields/NestedVersionTwo.java", ) assertJavaOutputs(outputs) } @@ -270,7 +270,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/wire/protos/custom_options/FooBar.java", - "com/squareup/wire/protos/custom_options/MessageWithOptions.java" + "com/squareup/wire/protos/custom_options/MessageWithOptions.java", ) assertJavaOutputs(outputs, ".noOptions") } @@ -288,7 +288,7 @@ class WireCompilerTest { "com/squareup/wire/protos/redacted/RedactedExtension.java", "com/squareup/wire/protos/redacted/RedactedFields.java", "com/squareup/wire/protos/redacted/RedactedRepeated.java", - "com/squareup/wire/protos/redacted/RedactedRequired.java" + "com/squareup/wire/protos/redacted/RedactedRequired.java", ) assertJavaOutputs(outputs) } @@ -309,7 +309,7 @@ class WireCompilerTest { "com/squareup/wire/protos/roots/H.java", "com/squareup/wire/protos/roots/I.java", "com/squareup/wire/protos/roots/J.java", - "com/squareup/wire/protos/roots/K.java" + "com/squareup/wire/protos/roots/K.java", ) assertJavaOutputs(outputs) } @@ -320,13 +320,13 @@ class WireCompilerTest { compileToJava( sources, "--includes=squareup.protos.roots.A", - "--excludes=squareup.protos.roots.B" + "--excludes=squareup.protos.roots.B", ) val outputs = arrayOf( "com/squareup/wire/protos/roots/A.java", - "com/squareup/wire/protos/roots/D.java" + "com/squareup/wire/protos/roots/D.java", ) assertJavaOutputs(outputs, ".pruned") } @@ -341,7 +341,7 @@ class WireCompilerTest { "com/squareup/wire/protos/roots/A.java", "com/squareup/wire/protos/roots/B.java", "com/squareup/wire/protos/roots/C.java", - "com/squareup/wire/protos/roots/D.java" + "com/squareup/wire/protos/roots/D.java", ) assertJavaOutputs(outputs) } @@ -353,7 +353,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/wire/protos/roots/B.java", - "com/squareup/wire/protos/roots/C.java" + "com/squareup/wire/protos/roots/C.java", ) assertJavaOutputs(outputs) } @@ -365,7 +365,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/wire/protos/roots/E.java", - "com/squareup/wire/protos/roots/G.java" + "com/squareup/wire/protos/roots/G.java", ) assertJavaOutputs(outputs) } @@ -377,7 +377,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/wire/protos/roots/E.java", - "com/squareup/wire/protos/roots/H.java" + "com/squareup/wire/protos/roots/H.java", ) assertJavaOutputs(outputs, ".pruned") } @@ -390,7 +390,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/wire/protos/roots/I.java", "com/squareup/wire/protos/roots/J.java", - "com/squareup/wire/protos/roots/K.java" + "com/squareup/wire/protos/roots/K.java", ) assertJavaOutputs(outputs) } @@ -403,7 +403,7 @@ class WireCompilerTest { // TheService is not created. val outputs = arrayOf( "com/squareup/wire/protos/roots/TheResponse.java", - "com/squareup/wire/protos/roots/TheRequest.java" + "com/squareup/wire/protos/roots/TheRequest.java", ) assertJavaOutputs(outputs) } @@ -417,7 +417,7 @@ class WireCompilerTest { "com/squareup/wire/protos/kotlin/services/GrpcSomeServiceClient.kt", "com/squareup/wire/protos/kotlin/services/SomeServiceClient.kt", "com/squareup/wire/protos/kotlin/services/SomeResponse.kt", - "com/squareup/wire/protos/kotlin/services/SomeRequest.kt" + "com/squareup/wire/protos/kotlin/services/SomeRequest.kt", ) assertKotlinOutputs(outputs) } @@ -431,7 +431,7 @@ class WireCompilerTest { "com/squareup/wire/protos/kotlin/services/GrpcNoPackageServiceClient.kt", "com/squareup/wire/protos/kotlin/services/NoPackageServiceClient.kt", "com/squareup/wire/protos/kotlin/services/NoPackageResponse.kt", - "com/squareup/wire/protos/kotlin/services/NoPackageRequest.kt" + "com/squareup/wire/protos/kotlin/services/NoPackageRequest.kt", ) assertKotlinOutputs(outputs) } @@ -466,7 +466,7 @@ class WireCompilerTest { val outputs = arrayOf( "com/squareup/geology/Period.kt", - "com/squareup/dinosaurs/Dinosaur.kt" + "com/squareup/dinosaurs/Dinosaur.kt", ) assertKotlinOutputs(outputs) } @@ -612,7 +612,7 @@ class WireCompilerTest { "com/squareup/wire/protos/kotlin/redacted/RedactedCycleB.kt", "com/squareup/wire/protos/kotlin/redacted/RedactedRepeated.kt", "com/squareup/wire/protos/kotlin/redacted/RedactedRequired.kt", - "com/squareup/wire/protos/kotlin/redacted/RedactedExtension.kt" + "com/squareup/wire/protos/kotlin/redacted/RedactedExtension.kt", ) assertKotlinOutputs(outputs) } @@ -623,7 +623,7 @@ class WireCompilerTest { compileToKotlin(sources) val outputs = arrayOf( - "com/squareup/wire/protos/kotlin/redacted/RedactedOneOf.kt" + "com/squareup/wire/protos/kotlin/redacted/RedactedOneOf.kt", ) assertKotlinOutputs(outputs) } @@ -634,7 +634,7 @@ class WireCompilerTest { compileToKotlin(sources, "--java_interop") val outputs = arrayOf( - "com/squareup/wire/protos/kotlin/redacted/RedactedOneOf.kt" + "com/squareup/wire/protos/kotlin/redacted/RedactedOneOf.kt", ) assertKotlinOutputs(outputs, ".java.interop") } @@ -685,7 +685,7 @@ class WireCompilerTest { private fun invokeCompiler( target: TargetLanguage, sources: Array, - vararg extraArgs: String + vararg extraArgs: String, ) { val args = ArrayList() args.add(target.protoPathArg()) @@ -720,7 +720,7 @@ class WireCompilerTest { target: TargetLanguage, outputDir: Path, path: String, - suffix: String + suffix: String, ) { // Compare against file with suffix if present. val expectedFile = target.expectedFile(path, suffix) @@ -748,7 +748,8 @@ class WireCompilerTest { override fun protoPathArg() = "--proto_path=../wire-tests/src/commonTest/proto/kotlin" override fun outArg(testDirPath: Path) = "--kotlin_out=$testDirPath" override fun protoFolderSuffix() = "kotlin" - }; + }, + ; abstract fun protoPathArg(): String abstract fun outArg(testDirPath: Path): String diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt index f0ef1cda03..425a19a6f3 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package com.squareup.wire.schema import com.squareup.wire.testing.add +import kotlin.test.assertFailsWith import okio.Path import okio.fakefilesystem.FakeFileSystem import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.assertFailsWith class CycleCheckerTest { private val fs = FakeFileSystem().apply { @@ -38,7 +38,7 @@ class CycleCheckerTest { |import "ouroboros.proto"; |message Snake { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { @@ -49,7 +49,7 @@ class CycleCheckerTest { |imports form a cycle: | ouroboros.proto: | import "ouroboros.proto"; - """.trimMargin() + """.trimMargin(), ) } @@ -62,7 +62,7 @@ class CycleCheckerTest { |import "rock.proto"; |message Paper { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/rock.proto", @@ -71,7 +71,7 @@ class CycleCheckerTest { |import "scissors.proto"; |message Rock { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/scissors.proto", @@ -80,7 +80,7 @@ class CycleCheckerTest { |import "paper.proto"; |message Scissors { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { @@ -95,7 +95,7 @@ class CycleCheckerTest { | import "scissors.proto"; | scissors.proto: | import "paper.proto"; - """.trimMargin() + """.trimMargin(), ) } @@ -109,7 +109,7 @@ class CycleCheckerTest { |import "d.proto"; |message A { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/b.proto", @@ -118,7 +118,7 @@ class CycleCheckerTest { |import "c.proto"; |message B { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/c.proto", @@ -128,7 +128,7 @@ class CycleCheckerTest { |import "b.proto"; |message C { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/d.proto", @@ -136,7 +136,7 @@ class CycleCheckerTest { |syntax = "proto2"; |message D { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { @@ -152,7 +152,7 @@ class CycleCheckerTest { | c.proto: | import "a.proto"; | import "b.proto"; - """.trimMargin() + """.trimMargin(), ) } @@ -170,7 +170,7 @@ class CycleCheckerTest { | optional locations.Office office = 1; | optional locations.Residence residence = 2; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/locations/office.proto", @@ -181,7 +181,7 @@ class CycleCheckerTest { |message Office { | optional people.OfficeManager office_manager = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/locations/residence.proto", @@ -190,7 +190,7 @@ class CycleCheckerTest { |package locations; |message Residence { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/people/office_manager.proto", @@ -199,7 +199,7 @@ class CycleCheckerTest { |package people; |message OfficeManager { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { @@ -215,7 +215,7 @@ class CycleCheckerTest { | people/employee.proto: | import "locations/office.proto"; | import "locations/residence.proto"; - """.trimMargin() + """.trimMargin(), ) } @@ -232,7 +232,7 @@ class CycleCheckerTest { |syntax = "proto2"; |import "b.proto"; |option go_package = "a"; - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/b.proto", @@ -241,7 +241,7 @@ class CycleCheckerTest { |package b; |import "c.proto"; |option go_package = "b"; - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/c.proto", @@ -249,7 +249,7 @@ class CycleCheckerTest { |syntax = "proto2"; |import "d.proto"; |option go_package = "c"; - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/d.proto", @@ -258,14 +258,14 @@ class CycleCheckerTest { |package d; |import "e.proto"; |option go_package = "a"; - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/e.proto", """ |syntax = "proto2"; |package b; - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { @@ -285,7 +285,7 @@ class CycleCheckerTest { | c imports a | c.proto: | import "d.proto"; - """.trimMargin() + """.trimMargin(), ) } @@ -297,7 +297,7 @@ class CycleCheckerTest { """ |syntax = "proto2"; |import "b.proto"; - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/b.proto", @@ -305,13 +305,13 @@ class CycleCheckerTest { |syntax = "proto2"; |package b; |import "c.proto"; - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/c.proto", """ |syntax = "proto2"; - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { @@ -326,7 +326,7 @@ class CycleCheckerTest { | b imports | b.proto: | import "c.proto"; - """.trimMargin() + """.trimMargin(), ) } @@ -334,7 +334,7 @@ class CycleCheckerTest { val loader = SchemaLoader(fs) loader.initRoots( sourcePath = listOf(Location.get("source-path")), - protoPath = listOf() + protoPath = listOf(), ) return loader.loadSchema() } diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt index 6b564e5af8..2cf19421e2 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,14 +37,14 @@ class LinkerTest { |message A { | optional B b = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/b.proto", """ |message B { |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -64,21 +64,21 @@ class LinkerTest { |import "b.proto"; |message A { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/b.proto", """ |message B { |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() assertThat(schema.protoFiles.map { it.location }).containsExactly( Location.get("source-path", "a.proto"), Location.get("google/protobuf/descriptor.proto"), - Location.get("wire/extensions.proto") + Location.get("wire/extensions.proto"), ) } @@ -91,7 +91,7 @@ class LinkerTest { |message A { | optional B b = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/b.proto", @@ -100,7 +100,7 @@ class LinkerTest { |} |message C { |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -117,7 +117,7 @@ class LinkerTest { |message A { | optional string s = 1 [formatting_options.language.name = "English"]; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/formatting_options.proto", @@ -143,7 +143,7 @@ class LinkerTest { | TITLE_CASE = 2; | SENTENCE_CASE = 3; |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -168,7 +168,7 @@ class LinkerTest { |message A { | optional B b = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/b.proto", @@ -178,7 +178,7 @@ class LinkerTest { |} |message C { |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -196,7 +196,7 @@ class LinkerTest { |message A { | optional B b = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/b.proto", @@ -204,7 +204,7 @@ class LinkerTest { |option java_package = "com.squareup.b"; |message B { |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -223,7 +223,7 @@ class LinkerTest { | SCISSORS = 2; | PAPER = 3; |} - """.trimMargin() + """.trimMargin(), ) fs.add("proto-path/b.proto", "") val schema = loadAndLinkSchema() @@ -236,7 +236,7 @@ class LinkerTest { val loader = SchemaLoader(fs) loader.initRoots( sourcePath = listOf(Location.get("source-path")), - protoPath = listOf(Location.get("proto-path")) + protoPath = listOf(Location.get("proto-path")), ) return loader.loadSchema() } diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt index b4b029e40d..f1e43fd5c8 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -59,7 +59,8 @@ private class MarkdownHandler : SchemaHandler() { |# ${type.type.simpleName} | |${type.documentation} - |""".trimMargin() + | + """.trimMargin() } private fun toMarkdown(service: Service): String { @@ -67,6 +68,7 @@ private class MarkdownHandler : SchemaHandler() { |# ${service.type.simpleName} | |${service.documentation} - |""".trimMargin() + | + """.trimMargin() } } diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt index 41e96d8982..37290260f8 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,7 +38,7 @@ class OptionsLinkingTest { |message A { | optional string s = 1 [(formatting_options).language = "English"]; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/formatting_options.proto", @@ -52,7 +52,7 @@ class OptionsLinkingTest { |extend google.protobuf.FieldOptions { | optional FormattingOptions formatting_options = 22001; |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -60,9 +60,9 @@ class OptionsLinkingTest { assertThat(typeA.field("s")!!.options.map).isEqualTo( mapOf( formattingOptionsField to mapOf( - languageField to "English" - ) - ) + languageField to "English", + ), + ), ) } @@ -75,7 +75,7 @@ class OptionsLinkingTest { |message A { | optional string s = 1 [(formatting_options).language = "English"]; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/formatting_options.proto", @@ -89,7 +89,7 @@ class OptionsLinkingTest { |extend google.protobuf.FieldOptions { | optional FormattingOptions formatting_options = 22001; |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -97,9 +97,9 @@ class OptionsLinkingTest { assertThat(typeA.field("s")!!.options.map).isEqualTo( mapOf( formattingOptionsField to mapOf( - languageField to "English" - ) - ) + languageField to "English", + ), + ), ) } @@ -113,7 +113,7 @@ class OptionsLinkingTest { | optional string s = 1 [(formatting_options).language.name = "English"]; | optional string t = 2 [(length).max = 80]; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/formatting_options.proto", @@ -145,7 +145,7 @@ class OptionsLinkingTest { | optional double min = 1; | optional double max = 2; |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -154,10 +154,10 @@ class OptionsLinkingTest { mapOf( formattingOptionsField to mapOf( languageField to mapOf( - nameField to "English" - ) - ) - ) + nameField to "English", + ), + ), + ), ) val typeLanguage = schema.getType("Language") as MessageType @@ -177,7 +177,7 @@ class OptionsLinkingTest { |message A { | optional string s = 2 [(length).max = 80]; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/extensions.proto", @@ -188,7 +188,7 @@ class OptionsLinkingTest { |extend google.protobuf.FieldOptions { | optional Range length = 22002; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "proto-path/range.proto", @@ -198,7 +198,7 @@ class OptionsLinkingTest { | optional double min = 1; | optional double max = 2; |} - """.trimMargin() + """.trimMargin(), ) val schema = loadAndLinkSchema() @@ -215,7 +215,7 @@ class OptionsLinkingTest { loader.initRoots( sourcePath = listOf(Location.get("source-path")), - protoPath = protoPath + protoPath = protoPath, ) return loader.loadSchema() } diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt index f9e3b526cc..ddcaf6cd99 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,21 +21,18 @@ import com.squareup.wire.WireLogger.Companion.NONE import com.squareup.wire.kotlin.RpcCallStyle import com.squareup.wire.kotlin.RpcRole import com.squareup.wire.schema.WireRun.Module -import com.squareup.wire.schema.internal.TypeMover import com.squareup.wire.schema.internal.TypeMover.Move import com.squareup.wire.testing.add import com.squareup.wire.testing.containsRelativePaths import com.squareup.wire.testing.findFiles import com.squareup.wire.testing.readUtf8 -import okio.Buffer -import okio.FileSystem +import kotlin.test.assertFailsWith import okio.Path import okio.Path.Companion.toPath import okio.fakefilesystem.FakeFileSystem import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import kotlin.test.assertFailsWith class WireRunTest { private val fs = FakeFileSystem().apply { @@ -52,13 +49,13 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(JavaTarget(outDirectory = "generated/java")) + targets = listOf(JavaTarget(outDirectory = "generated/java")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/colors/Blue.java", - "generated/java/squareup/colors/Red.java" + "generated/java/squareup/colors/Red.java", ) assertThat(fs.readUtf8("generated/java/squareup/colors/Blue.java")) .contains("public final class Blue extends Message") @@ -75,13 +72,13 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/kt/squareup/colors/Blue.kt", - "generated/kt/squareup/colors/Red.kt" + "generated/kt/squareup/colors/Red.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/colors/Blue.kt")) .contains("class Blue") @@ -100,25 +97,25 @@ class WireRunTest { sourcePath = listOf(Location.get("routes/src/main/proto")), protoPath = listOf( Location.get("colors/src/main/proto"), - Location.get("polygons/src/main/proto") + Location.get("polygons/src/main/proto"), ), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/kt/squareup/routes/RouteClient.kt", - "generated/kt/squareup/routes/GrpcRouteClient.kt" + "generated/kt/squareup/routes/GrpcRouteClient.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/routes/RouteClient.kt")) .contains( "interface RouteClient : Service", - "fun GetUpdatedBlue()" + "fun GetUpdatedBlue()", ) assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteClient.kt")) .contains( "class GrpcRouteClient(\n private val client: GrpcClient,\n) : RouteClient", - "override fun GetUpdatedBlue()" + "override fun GetUpdatedBlue()", ) } @@ -133,25 +130,25 @@ class WireRunTest { sourcePath = listOf(Location.get("routes/src/main/proto")), protoPath = listOf( Location.get("colors/src/main/proto"), - Location.get("polygons/src/main/proto") + Location.get("polygons/src/main/proto"), ), targets = listOf( KotlinTarget( outDirectory = "generated/kt", rpcCallStyle = RpcCallStyle.BLOCKING, - rpcRole = RpcRole.SERVER - ) - ) + rpcRole = RpcRole.SERVER, + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/kt/squareup/routes/RouteBlockingServer.kt" + "generated/kt/squareup/routes/RouteBlockingServer.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/routes/RouteBlockingServer.kt")) .contains( "interface RouteBlockingServer : Service", - "fun GetUpdatedRed" + "fun GetUpdatedRed", ) .doesNotContain("suspend fun GetUpdatedRed") } @@ -167,11 +164,11 @@ class WireRunTest { sourcePath = listOf(Location.get("routes/src/main/proto")), protoPath = listOf( Location.get("colors/src/main/proto"), - Location.get("polygons/src/main/proto") + Location.get("polygons/src/main/proto"), ), targets = listOf( - KotlinTarget(outDirectory = "generated/kt", singleMethodServices = true) - ) + KotlinTarget(outDirectory = "generated/kt", singleMethodServices = true), + ), ) wireRun.execute(fs, logger) @@ -179,7 +176,7 @@ class WireRunTest { "generated/kt/squareup/routes/RouteGetUpdatedBlueClient.kt", "generated/kt/squareup/routes/RouteGetUpdatedRedClient.kt", "generated/kt/squareup/routes/GrpcRouteGetUpdatedBlueClient.kt", - "generated/kt/squareup/routes/GrpcRouteGetUpdatedRedClient.kt" + "generated/kt/squareup/routes/GrpcRouteGetUpdatedRedClient.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/routes/RouteGetUpdatedBlueClient.kt")) .contains("interface RouteGetUpdatedBlueClient : Service") @@ -187,12 +184,12 @@ class WireRunTest { .contains("interface RouteGetUpdatedRedClient : Service") assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteGetUpdatedBlueClient.kt")) .contains( - "class GrpcRouteGetUpdatedBlueClient(\n private val client: GrpcClient,\n) : RouteGetUpdatedBlueClient" + "class GrpcRouteGetUpdatedBlueClient(\n private val client: GrpcClient,\n) : RouteGetUpdatedBlueClient", ) .doesNotContain("RouteGetUpdatedRedClient") assertThat(fs.readUtf8("generated/kt/squareup/routes/GrpcRouteGetUpdatedRedClient.kt")) .contains( - "class GrpcRouteGetUpdatedRedClient(\n private val client: GrpcClient,\n) : RouteGetUpdatedRedClient" + "class GrpcRouteGetUpdatedRedClient(\n private val client: GrpcClient,\n) : RouteGetUpdatedRedClient", ) .doesNotContain("RouteGetUpdatedBlueClient") } @@ -206,13 +203,13 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(ProtoTarget(outDirectory = "generated/proto")) + targets = listOf(ProtoTarget(outDirectory = "generated/proto")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/proto/squareup/colors/blue.proto", - "generated/proto/squareup/colors/red.proto" + "generated/proto/squareup/colors/red.proto", ) assertThat(fs.readUtf8("generated/proto/squareup/colors/blue.proto")) .contains("message Blue {") @@ -232,18 +229,18 @@ class WireRunTest { targets = listOf( KotlinTarget( outDirectory = "generated/kt", - includes = listOf("squareup.colors.Blue") + includes = listOf("squareup.colors.Blue"), ), JavaTarget( - outDirectory = "generated/java" - ) - ) + outDirectory = "generated/java", + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/colors/Red.java", - "generated/kt/squareup/colors/Blue.kt" + "generated/kt/squareup/colors/Blue.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/colors/Blue.kt")) .contains("class Blue") @@ -256,7 +253,7 @@ class WireRunTest { assertThat( assertFailsWith { newEventListenerFactory("foo").create() - } + }, ).hasMessage("Couldn't find EventListenerClass 'foo'") } @@ -265,7 +262,7 @@ class WireRunTest { assertThat( assertFailsWith { newEventListenerFactory("java.lang.Void").create() - } + }, ).hasMessage("No public constructor on java.lang.Void") } @@ -274,7 +271,7 @@ class WireRunTest { assertThat( assertFailsWith { newEventListenerFactory("java.lang.Object").create() - } + }, ).hasMessage("java.lang.Object does not implement EventListener.Factory") } @@ -294,11 +291,11 @@ class WireRunTest { targets = listOf( KotlinTarget( outDirectory = "generated/kt", - includes = listOf("squareup.colors.Blue") + includes = listOf("squareup.colors.Blue"), ), KotlinTarget( - outDirectory = "generated/kt" - ) + outDirectory = "generated/kt", + ), ), eventListeners = listeners, ) @@ -421,18 +418,18 @@ class WireRunTest { targets = listOf( JavaTarget( outDirectory = "generated/java", - includes = listOf("squareup.colors.Blue") + includes = listOf("squareup.colors.Blue"), ), KotlinTarget( - outDirectory = "generated/kt" - ) - ) + outDirectory = "generated/kt", + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/colors/Blue.java", - "generated/kt/squareup/colors/Red.kt" + "generated/kt/squareup/colors/Red.kt", ) assertThat(fs.readUtf8("generated/java/squareup/colors/Blue.java")) .contains("public final class Blue extends Message") @@ -449,24 +446,24 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf( Location.get("colors/src/main/proto"), - Location.get("polygons/src/main/proto") + Location.get("polygons/src/main/proto"), ), targets = listOf( KotlinTarget( outDirectory = "generated/kt", - excludes = listOf("squareup.colors.Red") + excludes = listOf("squareup.colors.Red"), ), JavaTarget( - outDirectory = "generated/java" - ) - ) + outDirectory = "generated/java", + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/kt/squareup/colors/Blue.kt", "generated/java/squareup/colors/Red.java", - "generated/kt/squareup/polygons/Triangle.kt" + "generated/kt/squareup/polygons/Triangle.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/colors/Blue.kt")) .contains("class Blue") @@ -485,24 +482,24 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf( Location.get("colors/src/main/proto"), - Location.get("polygons/src/main/proto") + Location.get("polygons/src/main/proto"), ), targets = listOf( KotlinTarget( outDirectory = "generated/kt", - excludes = listOf("squareup.colors.*") + excludes = listOf("squareup.colors.*"), ), JavaTarget( - outDirectory = "generated/java" - ) - ) + outDirectory = "generated/java", + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/colors/Blue.java", "generated/java/squareup/colors/Red.java", - "generated/kt/squareup/polygons/Triangle.kt" + "generated/kt/squareup/polygons/Triangle.kt", ) assertThat(fs.readUtf8("generated/java/squareup/colors/Blue.java")) .contains("public final class Blue extends Message") @@ -522,12 +519,12 @@ class WireRunTest { sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), treeShakingRoots = listOf("squareup.colors.Blue"), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/kt/squareup/colors/Blue.kt" + "generated/kt/squareup/colors/Blue.kt", ) } @@ -555,7 +552,7 @@ class WireRunTest { assertThat(expected).hasMessage( "Unused element(s) in roots:\n" + " squareup.colors.Purple\n" + - " squareup.colors.Color#name" + " squareup.colors.Color#name", ) } } @@ -581,7 +578,7 @@ class WireRunTest { assertThat(expected).hasMessage( "Unused element(s) in prunes:\n" + " squareup.colors.Purple\n" + - " squareup.colors.Color#name" + " squareup.colors.Color#name", ) } } @@ -609,7 +606,7 @@ class WireRunTest { " squareup.colors.Green\n" + "Unused element(s) in prunes:\n" + " squareup.colors.Purple\n" + - " squareup.colors.Color#name" + " squareup.colors.Color#name", ) } } @@ -624,12 +621,12 @@ class WireRunTest { sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), treeShakingRubbish = listOf("squareup.colors.Red"), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/kt/squareup/colors/Blue.kt" + "generated/kt/squareup/colors/Blue.kt", ) } @@ -643,18 +640,18 @@ class WireRunTest { targets = listOf( JavaTarget( outDirectory = "generated/java", - includes = listOf("squareup.polygons.Square") + includes = listOf("squareup.polygons.Square"), ), KotlinTarget( - outDirectory = "generated/kt" - ) - ) + outDirectory = "generated/kt", + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/com/squareup/polygons/Square.java", - "generated/kt/com/squareup/polygons/Rhombus.kt" + "generated/kt/com/squareup/polygons/Rhombus.kt", ) } @@ -667,21 +664,21 @@ class WireRunTest { sourcePath = listOf(Location.get("polygons/src/main/proto")), targets = listOf( JavaTarget( - outDirectory = "generated/java" + outDirectory = "generated/java", ), KotlinTarget( outDirectory = "generated/kt", exclusive = false, - includes = listOf("squareup.polygons.Square") - ) - ) + includes = listOf("squareup.polygons.Square"), + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/com/squareup/polygons/Square.java", "generated/java/com/squareup/polygons/Rhombus.java", - "generated/kt/com/squareup/polygons/Square.kt" + "generated/kt/com/squareup/polygons/Square.kt", ) } @@ -696,20 +693,20 @@ class WireRunTest { |message Red { | string oval = 1; |} - """.trimMargin() + """.trimMargin(), ) writeTriangleProto() val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/kt/squareup/colors/Blue.kt", - "generated/kt/squareup/colors/Red.kt" + "generated/kt/squareup/colors/Red.kt", ) } @@ -729,18 +726,18 @@ class WireRunTest { |message Triangle { | repeated squareup.geometry.Angle angles = 2; // No such type! |} - """.trimMargin() + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(JavaTarget(outDirectory = "generated/java")) + targets = listOf(JavaTarget(outDirectory = "generated/java")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/java/squareup/colors/Blue.java" + "generated/java/squareup/colors/Blue.java", ) assertThat(fs.readUtf8("generated/java/squareup/colors/Blue.java")) .contains("public final class Blue extends Message") @@ -757,16 +754,16 @@ class WireRunTest { |option (unicorn) = true; // No such option! |message Triangle { |} - """.trimMargin() + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(JavaTarget(outDirectory = "generated/java")) + targets = listOf(JavaTarget(outDirectory = "generated/java")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/java/squareup/colors/Blue.java" + "generated/java/squareup/colors/Blue.java", ) assertThat(fs.readUtf8("generated/java/squareup/colors/Blue.java")) .contains("public final class Blue extends Message") @@ -785,28 +782,30 @@ class WireRunTest { CustomTarget( outDirectory = "generated/markdown", schemaHandlerFactory = MarkdownHandlerFactory(), - ) - ) + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/markdown/squareup/colors/Blue.md", - "generated/markdown/squareup/colors/Red.md" + "generated/markdown/squareup/colors/Red.md", ) assertThat(fs.readUtf8("generated/markdown/squareup/colors/Blue.md")).isEqualTo( """ |# Blue | |This is the color of the sky. - |""".trimMargin() + | + """.trimMargin(), ) assertThat(fs.readUtf8("generated/markdown/squareup/colors/Red.md")).isEqualTo( """ |# Red | |This is the color of the sky when the sky is lava. - |""".trimMargin() + | + """.trimMargin(), ) } @@ -815,7 +814,7 @@ class WireRunTest { assertThat( assertFailsWith { callCustomHandler(newSchemaHandler("foo")) - } + }, ).hasMessage("Couldn't find SchemaHandlerClass 'foo'") } @@ -824,7 +823,7 @@ class WireRunTest { assertThat( assertFailsWith { callCustomHandler(newSchemaHandler("java.lang.Void")) - } + }, ).hasMessage("No public constructor on java.lang.Void") } @@ -833,7 +832,7 @@ class WireRunTest { assertThat( assertFailsWith { callCustomHandler(newSchemaHandler("java.lang.Object")) - } + }, ).hasMessage("java.lang.Object does not implement SchemaHandler.Factory") } @@ -863,18 +862,18 @@ class WireRunTest { @Test fun errorReportingCustomHandler() { val customHandler = newSchemaHandler( - "${WireRunTest::class.qualifiedName}${"$"}ErrorReportingCustomHandler" + "${WireRunTest::class.qualifiedName}${"$"}ErrorReportingCustomHandler", ) assertThat( assertFailsWith { callCustomHandler(customHandler) - } + }, ).hasMessage( """ |field starts with 'a' | for field angles (polygons/src/main/proto/squareup/polygons/triangle.proto:4:3) - """.trimMargin() + """.trimMargin(), ) } @@ -892,7 +891,7 @@ class WireRunTest { logger = NULL_LOGGER, errorCollector = errorCollector, claimedPaths = ClaimedPaths(), - ) + ), ) errorCollector.throwIfNonEmpty() @@ -908,7 +907,7 @@ class WireRunTest { |message Red { | optional string oval = 1; |} - """.trimMargin() + """.trimMargin(), ) } @@ -920,12 +919,12 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/kt/squareup/colors/Orange.kt" + "generated/kt/squareup/colors/Orange.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/colors/Orange.kt")) .contains("class Orange") @@ -940,12 +939,12 @@ class WireRunTest { sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), treeShakingRoots = listOf("squareup.colors.*"), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( - "generated/kt/squareup/colors/Orange.kt" + "generated/kt/squareup/colors/Orange.kt", ) assertThat(fs.readUtf8("generated/kt/squareup/colors/Orange.kt")) .contains("class Orange") @@ -959,7 +958,8 @@ class WireRunTest { |syntax = "proto2"; |message A {} |message B {} - |""".trimMargin() + | + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("protos")), @@ -968,10 +968,10 @@ class WireRunTest { "a" to Module( pruningRules = PruningRules.Builder() .prune("B") - .build() + .build(), ), - "b" to Module(dependencies = setOf("a")) - ) + "b" to Module(dependencies = setOf("a")), + ), ) wireRun.execute(fs, logger) @@ -1003,7 +1003,8 @@ class WireRunTest { |} |message B { |} - |""".trimMargin() + | + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("protos")), @@ -1012,12 +1013,12 @@ class WireRunTest { "a" to Module( pruningRules = PruningRules.Builder() .prune("example.B") - .build() + .build(), ), "b" to Module( - dependencies = setOf("a") - ) - ) + dependencies = setOf("a"), + ), + ), ) wireRun.execute(fs, logger) @@ -1025,12 +1026,12 @@ class WireRunTest { assertThat(fs.findFiles("gen/a")).containsRelativePaths( "gen/a/example/A.java", "gen/a/example/MapsToOption.java", - "gen/a/example/TypeOption.java" + "gen/a/example/TypeOption.java", ) assertThat(fs.findFiles("gen/b")).containsRelativePaths( "gen/b/example/B.java", "gen/b/example/MapsToOption.java", - "gen/b/example/TypeOption.java" + "gen/b/example/TypeOption.java", ) } @@ -1041,7 +1042,8 @@ class WireRunTest { |package one; |option java_package = "same.package"; |message Owner {} - |""".trimMargin() + | + """.trimMargin(), ) fs.add( "protos/two/jp.proto", @@ -1049,11 +1051,12 @@ class WireRunTest { |package two; |option java_package = "same.package"; |message Owner {} - |""".trimMargin() + | + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("protos")), - targets = listOf(JavaTarget(outDirectory = "generated/java")) + targets = listOf(JavaTarget(outDirectory = "generated/java")), ) try { @@ -1063,7 +1066,7 @@ class WireRunTest { assertThat(expected).hasMessage( "Same file generated/java/same/package/Owner.java is getting generated by different messages:\n" + " Owner at protos/one/au.proto:3:1\n" + - " Owner at protos/two/jp.proto:3:1" + " Owner at protos/two/jp.proto:3:1", ) } } @@ -1080,7 +1083,7 @@ class WireRunTest { |service Route { | rpc GetUpdatedRed(squareup.colors.Red) returns (squareup.colors.Red) {} |} - """.trimMargin() + """.trimMargin(), ) fs.add( "routes/src/main/proto/squareup/routes2/route.proto", @@ -1092,12 +1095,12 @@ class WireRunTest { |service Route { | rpc GetUpdatedRed(squareup.colors.Red) returns (squareup.colors.Red) {} |} - """.trimMargin() + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("routes/src/main/proto")), protoPath = listOf(Location.get("colors/src/main/proto")), - targets = listOf(KotlinTarget(outDirectory = "generated/kt", exclusive = false)) + targets = listOf(KotlinTarget(outDirectory = "generated/kt", exclusive = false)), ) try { @@ -1107,7 +1110,7 @@ class WireRunTest { assertThat(expected).hasMessage( "Same file generated/kt/same/package/RouteClient.kt is getting generated by different services:\n" + " Route at routes/src/main/proto/squareup/routes1/route.proto:5:1\n" + - " Route at routes/src/main/proto/squareup/routes2/route.proto:5:1" + " Route at routes/src/main/proto/squareup/routes2/route.proto:5:1", ) } } @@ -1120,8 +1123,8 @@ class WireRunTest { modules = mapOf( "one" to Module(dependencies = setOf("two")), "two" to Module(dependencies = setOf("three")), - "three" to Module(dependencies = setOf("one")) - ) + "three" to Module(dependencies = setOf("one")), + ), ).execute(fs, NONE) fail() } catch (e: IllegalArgumentException) { @@ -1129,7 +1132,8 @@ class WireRunTest { """ |ERROR: Modules contain dependency cycle(s): | - [one, two, three] - |""".trimMargin() + | + """.trimMargin(), ) } } @@ -1146,7 +1150,7 @@ class WireRunTest { | optional locations.Office office = 1; | optional locations.Residence residence = 2; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/locations/office.proto", @@ -1157,7 +1161,7 @@ class WireRunTest { |message Office { | optional people.OfficeManager office_manager = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/locations/residence.proto", @@ -1166,7 +1170,7 @@ class WireRunTest { |package locations; |message Residence { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/people/office_manager.proto", @@ -1175,7 +1179,7 @@ class WireRunTest { |package people; |message OfficeManager { |} - """.trimMargin() + """.trimMargin(), ) val wireRun = WireRun( @@ -1197,7 +1201,7 @@ class WireRunTest { | people/employee.proto: | import "locations/office.proto"; | import "locations/residence.proto"; - """.trimMargin() + """.trimMargin(), ) } } @@ -1211,19 +1215,19 @@ class WireRunTest { JavaTarget( outDirectory = "generated/java", emitDeclaredOptions = true, - exclusive = false + exclusive = false, ), KotlinTarget( outDirectory = "generated/kt", emitDeclaredOptions = true, - exclusive = false - ) - ) + exclusive = false, + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/options/DocumentationUrlOption.java", - "generated/kt/squareup/options/DocumentationUrlOption.kt" + "generated/kt/squareup/options/DocumentationUrlOption.kt", ) assertThat(fs.readUtf8("generated/java/squareup/options/DocumentationUrlOption.java")) .contains("public @interface DocumentationUrlOption") @@ -1240,14 +1244,14 @@ class WireRunTest { JavaTarget( outDirectory = "generated/java", emitDeclaredOptions = false, - exclusive = false + exclusive = false, ), KotlinTarget( outDirectory = "generated/kt", emitDeclaredOptions = false, - exclusive = false - ) - ) + exclusive = false, + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths() @@ -1264,19 +1268,19 @@ class WireRunTest { JavaTarget( outDirectory = "generated/java", emitAppliedOptions = true, - exclusive = false + exclusive = false, ), KotlinTarget( outDirectory = "generated/kt", emitAppliedOptions = true, - exclusive = false - ) - ) + exclusive = false, + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/polygons/Octagon.java", - "generated/kt/squareup/polygons/Octagon.kt" + "generated/kt/squareup/polygons/Octagon.kt", ) assertThat(fs.readUtf8("generated/java/squareup/polygons/Octagon.java")) .contains("@DocumentationUrlOption(\"https://en.wikipedia.org/wiki/Octagon\")") @@ -1295,19 +1299,19 @@ class WireRunTest { JavaTarget( outDirectory = "generated/java", emitAppliedOptions = false, - exclusive = false + exclusive = false, ), KotlinTarget( outDirectory = "generated/kt", emitAppliedOptions = false, - exclusive = false - ) - ) + exclusive = false, + ), + ), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( "generated/java/squareup/polygons/Octagon.java", - "generated/kt/squareup/polygons/Octagon.kt" + "generated/kt/squareup/polygons/Octagon.kt", ) assertThat(fs.readUtf8("generated/java/squareup/polygons/Octagon.java")) .doesNotContain("@DocumentationUrl") @@ -1323,7 +1327,7 @@ class WireRunTest { val wireRun = WireRun( sourcePath = listOf(Location.get("colors/src/main/proto")), protoPath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) try { @@ -1339,7 +1343,7 @@ class WireRunTest { |unable to resolve squareup.polygons.Triangle | for field triangle (colors/src/main/proto/squareup/colors/blue.proto:7:3) | in message squareup.colors.Blue (colors/src/main/proto/squareup/colors/blue.proto:5:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1364,11 +1368,11 @@ class WireRunTest { |extend squareup.polygons.Triangle { | optional string documentation_url = 22202; |} - """.trimMargin() + """.trimMargin(), ) val wireRun = WireRun( sourcePath = listOf(Location.get("polygons/src/main/proto")), - targets = listOf(KotlinTarget(outDirectory = "generated/kt")) + targets = listOf(KotlinTarget(outDirectory = "generated/kt")), ) wireRun.execute(fs, logger) assertThat(fs.findFiles("generated")).containsRelativePaths( @@ -1392,7 +1396,7 @@ class WireRunTest { | optional string circle = 1; | optional squareup.polygons.Triangle.Type triangle = 2; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1408,7 +1412,7 @@ class WireRunTest { | rpc GetUpdatedRed(squareup.colors.Red) returns (squareup.colors.Red) {} | rpc GetUpdatedBlue(squareup.colors.Blue) returns (squareup.colors.Blue) {} |} - """.trimMargin() + """.trimMargin(), ) } @@ -1424,7 +1428,7 @@ class WireRunTest { | optional string circle = 1; | optional squareup.polygons.Triangle triangle = 2; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1442,7 +1446,7 @@ class WireRunTest { | RIGHTANGLED = 3; | } |} - """.trimMargin() + """.trimMargin(), ) } @@ -1456,7 +1460,7 @@ class WireRunTest { |message Square { | optional double length = 1; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1471,7 +1475,7 @@ class WireRunTest { | optional double length = 1; | optional double acute_angle = 2; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1486,7 +1490,7 @@ class WireRunTest { |extend google.protobuf.MessageOptions { | optional string documentation_url = 22200; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1502,7 +1506,7 @@ class WireRunTest { | option (options.documentation_url) = "https://en.wikipedia.org/wiki/Octagon"; | optional bool stop = 1; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1511,7 +1515,7 @@ class WireRunTest { override fun artifactHandled( outputPath: Path, qualifiedName: String, - targetName: String + targetName: String, ) = Unit override fun artifactSkipped(type: ProtoType, targetName: String) = Unit diff --git a/wire-grpc-server-generator/build.gradle.kts b/wire-grpc-server-generator/build.gradle.kts index 7053205168..ea7459fde2 100644 --- a/wire-grpc-server-generator/build.gradle.kts +++ b/wire-grpc-server-generator/build.gradle.kts @@ -42,12 +42,4 @@ if (project.rootProject.name == "wire") { KotlinJvm(javadocJar = Dokka("dokkaGfm"), sourcesJar = true) ) } - - configure { - kotlin { - targetExclude( - "src/test/golden/*.kt", - ) - } - } } diff --git a/wire-grpc-tests/build.gradle.kts b/wire-grpc-tests/build.gradle.kts index 601b180956..2a8b9aec7f 100644 --- a/wire-grpc-tests/build.gradle.kts +++ b/wire-grpc-tests/build.gradle.kts @@ -1,4 +1,3 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import com.google.protobuf.gradle.generateProtoTasks import com.google.protobuf.gradle.id import com.google.protobuf.gradle.ofSourceSet @@ -80,11 +79,3 @@ val test by tasks.getting(Test::class) { exceptionFormat = TestExceptionFormat.FULL } } - -configure { - kotlin { - targetExclude( - "src/test/proto-grpc/**/*.kt", - ) - } -} diff --git a/wire-gson-support/build.gradle.kts b/wire-gson-support/build.gradle.kts index d9bd62119e..a4158d4006 100644 --- a/wire-gson-support/build.gradle.kts +++ b/wire-gson-support/build.gradle.kts @@ -1,4 +1,3 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.MavenPublishBaseExtension @@ -28,13 +27,3 @@ dependencies { testImplementation(libs.assertj) testImplementation(projects.wireTestUtils) } - -configure { - kotlin { - targetExclude( - "src/test/java/com/squareup/wire/protos/**/*.kt", - "src/test/java/com/squareup/wire/proto2/**/*.kt", - "src/test/java/squareup/proto2/keywords/**/*.kt", - ) - } -} diff --git a/wire-moshi-adapter/build.gradle.kts b/wire-moshi-adapter/build.gradle.kts index 5bd250ce8f..4d20ba11a9 100644 --- a/wire-moshi-adapter/build.gradle.kts +++ b/wire-moshi-adapter/build.gradle.kts @@ -1,4 +1,3 @@ -import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.MavenPublishBaseExtension @@ -28,13 +27,3 @@ dependencies { testImplementation(libs.junit) testImplementation(libs.moshiKotlin) } - -configure { - kotlin { - targetExclude( - "src/test/java/com/squareup/wire/proto2/**/*.kt", - "src/test/java/com/squareup/wire/protos/**/*.kt", - "src/test/java/squareup/proto2/keywords/**/*.kt", - ) - } -} From bcc4c22a928f5d3766d8f3fffbc3d6a82af6a932 Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 19:41:02 +0200 Subject: [PATCH 3/7] Spotless: wire-tests --- .../com/squareup/wire/ConsoleWireLogger.kt | 2 +- .../com/squareup/wire/DryRunFileSystem.kt | 2 +- .../main/java/com/squareup/wire/Manifest.kt | 2 +- .../java/com/squareup/wire/WireCompiler.kt | 2 +- .../java/com/squareup/wire/WireException.kt | 2 +- .../java/com/squareup/wire/schema/Target.kt | 2 +- .../com/squareup/wire/schema/fileSystems.kt | 2 +- .../squareup/wire/CommandLineOptionsTest.kt | 2 +- .../com/squareup/wire/ManifestParseTest.kt | 2 +- .../com/squareup/wire/StringWireLogger.kt | 2 +- .../squareup/wire/WireCompilerErrorTest.kt | 2 +- .../com/squareup/wire/WireCompilerTest.kt | 2 +- .../squareup/wire/schema/CycleCheckerTest.kt | 2 +- .../com/squareup/wire/schema/LinkerTest.kt | 2 +- .../squareup/wire/schema/MarkdownHandler.kt | 2 +- .../wire/schema/OptionsLinkingTest.kt | 2 +- .../com/squareup/wire/schema/WireRunTest.kt | 2 +- wire-tests/build.gradle.kts | 15 +- .../kotlin/com/squareup/wire/Tests.kt | 15 + .../com/squareup/wire/AnyMessageTest.kt | 28 +- .../kotlin/com/squareup/wire/Asserts.kt | 6 +- .../kotlin/com/squareup/wire/BoxOneOfTest.kt | 6 +- .../kotlin/com/squareup/wire/IgnoreJs.kt | 15 + .../kotlin/com/squareup/wire/IgnoreNative.kt | 15 + .../com/squareup/wire/KotlinEnumTest.kt | 4 +- .../com/squareup/wire/KotlinListTest.kt | 4 +- .../kotlin/com/squareup/wire/KotlinMapTest.kt | 15 +- .../kotlin/com/squareup/wire/OneOfTest.kt | 4 +- .../kotlin/com/squareup/wire/ParseTest.kt | 12 +- .../com/squareup/wire/ProtoAdapterTest.kt | 14 +- .../kotlin/com/squareup/wire/RedactTest.kt | 14 +- .../kotlin/com/squareup/wire/TestAllTypes.kt | 22 +- .../com/squareup/wire/TestAllTypesData.kt | 4 +- .../com/squareup/wire/UnknownFieldsTest.kt | 14 +- .../kotlin/com/squareup/wire/WireTest.kt | 11 +- .../squareup/wire/DarwinProtoAdapterTest.kt | 12 +- .../kotlin/com/squareup/wire/IgnoreJs.kt | 15 + .../kotlin/com/squareup/wire/IgnoreNative.kt | 15 + .../java/com/squareup/wire/MapTest.kt | 17 +- .../com/squareup/wire/MoshiRedactedTest.kt | 10 +- .../java/com/squareup/wire/OneOfTest.java | 28 +- .../java/com/squareup/wire/ParseTest.java | 58 +- .../com/squareup/wire/ProtoAdapterTest.java | 47 +- .../wire/RuntimeMessageAdapterRedactTest.java | 115 ++- .../com/squareup/wire/SerializableTest.java | 74 +- .../java/com/squareup/wire/TestAllTypes.java | 59 +- .../com/squareup/wire/TestAllTypesData.java | 941 +++++++++--------- .../com/squareup/wire/UnknownFieldsTest.java | 146 ++- .../java/com/squareup/wire/WireTest.java | 237 ++--- .../wire/AnnotationsTestAgainstJava.kt | 15 + .../squareup/wire/ProtoAdapterIdentityTest.kt | 18 +- .../squareup/wire/ProtoAdapterTypeUrlTest.kt | 8 +- .../com/squareup/wire/WireKotlinTest.kt | 4 +- .../kotlin/com/squareup/wire/WireJsonTest.kt | 176 ++-- .../internal/DurationJsonFormatterTest.kt | 6 +- .../wire/internal/InstantJsonFormatterTest.kt | 4 +- .../wire/AnnotationsTestAgainstKotlin.kt | 15 + .../kotlin/com/squareup/wire/KotlinMapTest.kt | 12 +- .../com/squareup/wire/KotlinRepeatedTest.kt | 36 +- .../kotlin/com/squareup/wire/OneOfTest.kt | 27 +- .../com/squareup/wire/ProtoAdapterTest.kt | 6 +- .../com/squareup/wire/RecursiveMapTest.kt | 4 +- .../com/squareup/wire/SerializableTest.kt | 12 +- .../kotlin/com/squareup/wire/TestAllTypes.kt | 12 +- .../com/squareup/wire/TestAllTypesData.kt | 4 +- .../com/squareup/wire/UnknownFieldsTest.kt | 4 +- .../kotlin/com/squareup/wire/IgnoreJs.kt | 15 + .../kotlin/com/squareup/wire/IgnoreNative.kt | 15 + .../kotlin/com/squareup/wire/IgnoreJs.kt | 15 + .../kotlin/com/squareup/wire/IgnoreNative.kt | 15 + 70 files changed, 1342 insertions(+), 1107 deletions(-) diff --git a/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt b/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt index f29621f6d2..1e3ad4a4a6 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/ConsoleWireLogger.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt b/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt index de1cc496e6..6d714f0310 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/DryRunFileSystem.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt b/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt index 44d344891e..28d2fecbbb 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/Manifest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt b/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt index 4cd8698141..92bc0591f3 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/WireCompiler.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/WireException.kt b/wire-compiler/src/main/java/com/squareup/wire/WireException.kt index d417f6f80a..aae3d300b0 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/WireException.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/WireException.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt b/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt index 2cee9968ea..7a81bb027a 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt b/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt index 309a44c617..a8f7c26d4b 100644 --- a/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt +++ b/wire-compiler/src/main/java/com/squareup/wire/schema/fileSystems.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt b/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt index 561d2bd38d..5612dba57d 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/CommandLineOptionsTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt b/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt index 564970bd0e..9ff90bc6b9 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/ManifestParseTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt b/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt index cff0387b92..3023f5453c 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/StringWireLogger.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt index 2d44914bbc..24ed1f7206 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerErrorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt index 87b430c099..36c6ff81d4 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/WireCompilerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt index 425a19a6f3..eae321ad78 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/CycleCheckerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt index 2cf19421e2..13013501f5 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/LinkerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt index f1e43fd5c8..1396298a7c 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/MarkdownHandler.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt index 37290260f8..fdab2b5d62 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/OptionsLinkingTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt b/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt index ddcaf6cd99..d91696e489 100644 --- a/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt +++ b/wire-compiler/src/test/java/com/squareup/wire/schema/WireRunTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/build.gradle.kts b/wire-tests/build.gradle.kts index 15d51a2f4f..3303c1312f 100644 --- a/wire-tests/build.gradle.kts +++ b/wire-tests/build.gradle.kts @@ -289,6 +289,19 @@ configure { "src/jvmKotlinInteropTest/proto-kotlin/**/*.kt", "src/jvmJsonJavaTest/proto-java/**/*.kt", "src/jvmJsonKotlinTest/proto-kotlin/**/*.kt", - ) + ) + } + java { + targetExclude( + "src/jvmJavaTest/proto-java/**/*.java", + "src/jvmJavaNoOptionsTest/proto-java/**/*.java", + "src/jvmJavaCompactTest/proto-java/**/*.java", + "src/jvmJavaPrunedTest/proto-java/**/*.java", + "src/jvmJavaAndroidTest/proto-java/**/*.java", + "src/jvmJavaAndroidCompactTest/proto-java/**/*.java", + "src/jvmJavaTest/proto-java/**/*.java", + "src/jvmKotlinInteropTest/proto-kotlin/**/*.java", + "src/jvmJsonJavaTest/proto-java/**/*.java", + ) } } diff --git a/wire-tests/src/commonMain/kotlin/com/squareup/wire/Tests.kt b/wire-tests/src/commonMain/kotlin/com/squareup/wire/Tests.kt index 345fc3c283..1e9746c9f5 100644 --- a/wire-tests/src/commonMain/kotlin/com/squareup/wire/Tests.kt +++ b/wire-tests/src/commonMain/kotlin/com/squareup/wire/Tests.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire object Tests diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/AnyMessageTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/AnyMessageTest.kt index ace099d9af..9ce0576f0f 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/AnyMessageTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/AnyMessageTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,8 +18,6 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.edgecases.NoFields import com.squareup.wire.protos.kotlin.edgecases.OneField import com.squareup.wire.protos.usesany.UsesAny -import okio.ByteString -import okio.ByteString.Companion.decodeHex import kotlin.jvm.JvmField import kotlin.test.Test import kotlin.test.assertEquals @@ -27,6 +25,8 @@ import kotlin.test.assertFailsWith import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.test.fail +import okio.ByteString +import okio.ByteString.Companion.decodeHex class AnyMessageTest { @Test fun happyPath() { @@ -37,8 +37,8 @@ class AnyMessageTest { just_one = AnyMessage.pack(three), many_anys = listOf( AnyMessage.pack(three), - AnyMessage.pack(four) - ) + AnyMessage.pack(four), + ), ) assertEquals(three, usesAny.just_one!!.unpack(OneField.ADAPTER)) @@ -64,8 +64,8 @@ class AnyMessageTest { just_one = AnyMessage.pack(three), many_anys = listOf( AnyMessage.pack(three), - AnyMessage.pack(four) - ) + AnyMessage.pack(four), + ), ) assertEquals(hex, usesAny.encodeByteString().hex()) @@ -86,7 +86,7 @@ class AnyMessageTest { @Test fun unpackWithWrongTypeUrlThrow() { val usesAny = UsesAny( just_one = AnyMessage.pack(OneField(opt_int32 = 3)), - many_anys = listOf() + many_anys = listOf(), ) try { @@ -96,7 +96,7 @@ class AnyMessageTest { assertEquals( "type mismatch: type.googleapis.com/squareup.protos.kotlin.edgecases.OneField " + "!= type.googleapis.com/squareup.protos.kotlin.edgecases.NoFields", - expected.message + expected.message, ) } } @@ -104,7 +104,7 @@ class AnyMessageTest { @Test fun unpackOrNullWithWrongTypeUrlReturnsNull() { val usesAny = UsesAny( just_one = AnyMessage.pack(OneField(opt_int32 = 3)), - many_anys = listOf() + many_anys = listOf(), ) assertNull(usesAny.just_one!!.unpackOrNull(NoTypeUrlMessage.ADAPTER)) @@ -118,13 +118,13 @@ class AnyMessageTest { assertTrue(expected.message!!.startsWith("recompile class "), expected.message) assertTrue( expected.message!!.endsWith("NoTypeUrlMessage to use it with AnyMessage"), - expected.message + expected.message, ) } } private class NoTypeUrlMessage( - unknownFields: ByteString = ByteString.EMPTY + unknownFields: ByteString = ByteString.EMPTY, ) : Message(ADAPTER, unknownFields) { override fun newBuilder(): Nothing = throw AssertionError() @@ -135,7 +135,7 @@ class AnyMessageTest { NoTypeUrlMessage::class, null, // TypeUrl. Syntax.PROTO_2, - null // Identity. + null, // Identity. ) { override fun encodedSize(value: NoTypeUrlMessage) = TODO() override fun encode(writer: ProtoWriter, value: NoTypeUrlMessage) = TODO() diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/Asserts.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/Asserts.kt index 4e7ad7a2f5..616e61e0da 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/Asserts.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/Asserts.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ fun assertFloatEquals(expected: Float, actual: Float, delta: Float = 0.01f) { if (diff > delta) { fail( "Expected difference between <$expected> and <$actual> to not be greater than <$delta>," + - " but was <$diff>." + " but was <$diff>.", ) } } diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/BoxOneOfTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/BoxOneOfTest.kt index b6298514fa..d87d0059af 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/BoxOneOfTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/BoxOneOfTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,9 +16,9 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.Form -import okio.ByteString.Companion.decodeHex import kotlin.test.Test import kotlin.test.assertEquals +import okio.ByteString.Companion.decodeHex class BoxOneOfTest { @Test diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreJs.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreJs.kt index 6c7e9125dd..be79320eca 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreJs.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreJs.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreNative.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreNative.kt index 0a536bcd58..b1f80a4dd0 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreNative.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/IgnoreNative.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinEnumTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinEnumTest.kt index 8285b871b2..624dc4695f 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinEnumTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinEnumTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinListTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinListTest.kt index 9c33191f59..3372364d6a 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinListTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinListTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinMapTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinMapTest.kt index b0984be1cb..f42562f8a0 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinMapTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/KotlinMapTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,12 +17,12 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.map.Mappy import com.squareup.wire.protos.kotlin.map.Thing -import okio.ByteString -import okio.ByteString.Companion.decodeHex import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.fail +import okio.ByteString +import okio.ByteString.Companion.decodeHex class KotlinMapTest { private val adapter = Mappy.ADAPTER @@ -42,7 +42,8 @@ class KotlinMapTest { @IgnoreJs @IgnoreNative - @Test fun mapsAreImmutable() { + @Test + fun mapsAreImmutable() { val map = mutableMapOf("one" to Thing("One")) val mappy = Mappy(things = map) @@ -66,8 +67,8 @@ class KotlinMapTest { things = mapOf( "one" to Thing("One"), "two" to Thing("Two"), - "three" to Thing("Three") - ) + "three" to Thing("Three"), + ), ) } } diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/OneOfTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/OneOfTest.kt index 8d6502eaa3..7b99fa5a90 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/OneOfTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/OneOfTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/ParseTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/ParseTest.kt index 9dda672990..bd7c12ae58 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/ParseTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/ParseTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2014 Square Inc. + * Copyright (C) 2014 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,14 +19,14 @@ import com.squareup.wire.internal.ProtocolException import com.squareup.wire.protos.kotlin.edgecases.OneBytesField import com.squareup.wire.protos.kotlin.edgecases.OneField import com.squareup.wire.protos.kotlin.edgecases.Recursive -import okio.ByteString -import okio.ByteString.Companion.decodeHex -import okio.EOFException -import okio.IOException import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals import kotlin.test.fail +import okio.ByteString +import okio.ByteString.Companion.decodeHex +import okio.EOFException +import okio.IOException class ParseTest { @Test diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt index 1544ed9ebd..b2afa9c371 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,12 +17,12 @@ package com.squareup.wire import com.squareup.wire.proto3.kotlin.person.Person import com.squareup.wire.protos.kotlin.bool.TrueBoolean -import okio.ByteString.Companion.decodeHex -import squareup.protos.packed_encoding.EmbeddedMessage -import squareup.protos.packed_encoding.OuterMessage import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertSame +import okio.ByteString.Companion.decodeHex +import squareup.protos.packed_encoding.EmbeddedMessage +import squareup.protos.packed_encoding.OuterMessage class ProtoAdapterTest { @Test fun repeatedHelpersCacheInstances() { @@ -35,7 +35,7 @@ class ProtoAdapterTest { @Test fun embeddedEmptyPackedMessage() { val outerMessage = OuterMessage( outer_number_before = 2, - embedded_message = EmbeddedMessage(inner_number_after = 1) + embedded_message = EmbeddedMessage(inner_number_after = 1), ) val outerMessagesAfterSerialisation = OuterMessage.ADAPTER .decode(OuterMessage.ADAPTER.encode(outerMessage)) @@ -45,7 +45,7 @@ class ProtoAdapterTest { @Test fun getFromClassProto3() { val person = Person( name = "Somebody", - phones = listOf(Person.PhoneNumber()) + phones = listOf(Person.PhoneNumber()), ) val hexByteString = "0a08536f6d65626f64792200" assertEquals(hexByteString, Person.ADAPTER.encodeByteString(person).hex()) diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/RedactTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/RedactTest.kt index f79b97b46a..a51acd3e04 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/RedactTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/RedactTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2014 Square Inc. + * Copyright (C) 2014 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,12 +32,12 @@ class RedactTest { assertEquals("RedactedFields{a=██, b=b, c=c}", redacted.toString()) val redactedRepeated = RedactedRepeated( a = listOf("a", "b"), - b = listOf(RedactedFields("a", "b", "c", null), RedactedFields("d", "e", "f", null)) + b = listOf(RedactedFields("a", "b", "c", null), RedactedFields("d", "e", "f", null)), ) assertEquals( "RedactedRepeated{a=██, b=[RedactedFields{a=██, b=b, c=c}, " + "RedactedFields{a=██, b=e, c=f}]}", - redactedRepeated.toString() + redactedRepeated.toString(), ) } @@ -56,7 +56,7 @@ class RedactTest { val message = RedactedChild( a = "a", b = RedactedFields(a = "a", b = "b", c = "c"), - c = NotRedacted(a = "a", b = "b") + c = NotRedacted(a = "a", b = "b"), ) val expected = message.copy(b = message.b!!.copy(a = null)) assertEquals(expected, RedactedChild.ADAPTER.redact(message)) @@ -76,10 +76,10 @@ class RedactTest { @Test fun repeatedField() { val message = RedactedRepeated( a = listOf("a", "b"), - b = listOf(RedactedFields("a", "b", "c", null), RedactedFields("d", "e", "f", null)) + b = listOf(RedactedFields("a", "b", "c", null), RedactedFields("d", "e", "f", null)), ) val expected = RedactedRepeated( - b = listOf(RedactedFields(null, "b", "c", null), RedactedFields(null, "e", "f", null)) + b = listOf(RedactedFields(null, "b", "c", null), RedactedFields(null, "e", "f", null)), ) val actual = RedactedRepeated.ADAPTER.redact(message) assertEquals(expected, actual) diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypes.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypes.kt index 8ad9bf688a..df6708b7c1 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypes.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypes.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.alltypes.AllTypes -import okio.Buffer -import okio.ByteString import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull +import okio.Buffer +import okio.ByteString class TestAllTypes { @@ -264,7 +264,7 @@ class TestAllTypes { builder = builder.copy( ext_opt_bool = false, ext_rep_bool = list(false), - ext_pack_bool = list(false) + ext_pack_bool = list(false), ) assertEquals(false, builder.ext_opt_bool) @@ -331,7 +331,8 @@ class TestAllTypes { } @IgnoreJs // https://youtrack.jetbrains.com/issue/KT-35078 - @Test fun testToString() { + @Test + fun testToString() { val data = adapter.encode(allTypes) val parsed = adapter.decode(data) assertEquals(TestAllTypesData.expectedToString, parsed.toString()) @@ -343,7 +344,7 @@ class TestAllTypes { assertEquals( "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011" + "\u0001\u0001\u0011güzel", - AllTypes.DEFAULT_DEFAULT_STRING + AllTypes.DEFAULT_DEFAULT_STRING, ) } @@ -385,8 +386,11 @@ class TestAllTypes { data[index++] = 0xa4.toByte() // end group, tag = 20, type = 4 data[index++] = 0x01.toByte() arraycopy( - TestAllTypesData.expectedOutput.toByteArray(), 17, data, index, - TestAllTypesData.expectedOutput.size - 17 + TestAllTypesData.expectedOutput.toByteArray(), + 17, + data, + index, + TestAllTypesData.expectedOutput.size - 17, ) val parsed = adapter.decode(data) assertEquals(allTypes, parsed) diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypesData.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypesData.kt index 4b6b5cba14..e6c4ed1e32 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypesData.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/TestAllTypesData.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt index 92b9ec36ff..6ba93457ab 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,12 +20,12 @@ import com.squareup.wire.protos.kotlin.unknownfields.NestedVersionOne import com.squareup.wire.protos.kotlin.unknownfields.NestedVersionTwo import com.squareup.wire.protos.kotlin.unknownfields.VersionOne import com.squareup.wire.protos.kotlin.unknownfields.VersionTwo -import okio.ByteString -import okio.ByteString.Companion.decodeHex import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals import kotlin.test.assertNull +import okio.ByteString +import okio.ByteString.Companion.decodeHex class UnknownFieldsTest { private val v1Adapter = VersionOne.ADAPTER @@ -40,7 +40,7 @@ class UnknownFieldsTest { v2_s = "222", v2_f32 = 67890, v2_f64 = 98765L, - v2_rs = listOf("1", "2") + v2_rs = listOf("1", "2"), ) val v2 = VersionTwo( @@ -50,7 +50,7 @@ class UnknownFieldsTest { v2_f32 = 67890, v2_f64 = 98765L, v2_rs = listOf("1", "2"), - obj = v2_obj + obj = v2_obj, ) assertEquals(111, v2.i) assertEquals(v2.obj!!.copy(), v2.obj) @@ -80,7 +80,7 @@ class UnknownFieldsTest { // Unknown fields can be removed for equals() and hashCode(); val v1Known = v1.copy( obj = v1.obj.copy(unknownFields = ByteString.EMPTY), - unknownFields = ByteString.EMPTY + unknownFields = ByteString.EMPTY, ) assertEquals(v1Simple, v1Known) assertEquals(v1Simple.hashCode(), v1Known.hashCode()) diff --git a/wire-tests/src/commonTest/kotlin/com/squareup/wire/WireTest.kt b/wire-tests/src/commonTest/kotlin/com/squareup/wire/WireTest.kt index aad6d8206f..2966e88e2f 100644 --- a/wire-tests/src/commonTest/kotlin/com/squareup/wire/WireTest.kt +++ b/wire-tests/src/commonTest/kotlin/com/squareup/wire/WireTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,7 +41,7 @@ class WireTest { optional_external_msg = ExternalMessage(f = 99.9f), default_nested_enum = SimpleMessage.NestedEnum.BAR, required_int32 = 456, - repeated_double = doubles + repeated_double = doubles, ) assertEquals(789, msg.optional_int32) @@ -73,14 +73,15 @@ class WireTest { id = 1, name = "Such, I mean it, such [a] {funny} name.", phone = listOf(Person.PhoneNumber(number = "123,456,789")), - aliases = listOf("B-lo,ved", "D{esperado}") + aliases = listOf("B-lo,ved", "D{esperado}"), ) val expected = """Person{ |id=1 |, name=Such\, I mean it\, such \[a\] \{funny\} name. |, phone=[PhoneNumber{number=123\,456\,789}] |, aliases=[B-lo\,ved, D\{esperado\}] - |}""".trimMargin().replace("\n", "") + |} + """.trimMargin().replace("\n", "") assertEquals(expected, person.toString()) } } diff --git a/wire-tests/src/darwinTest/kotlin/com/squareup/wire/DarwinProtoAdapterTest.kt b/wire-tests/src/darwinTest/kotlin/com/squareup/wire/DarwinProtoAdapterTest.kt index 02adb191d6..71915dcc0c 100644 --- a/wire-tests/src/darwinTest/kotlin/com/squareup/wire/DarwinProtoAdapterTest.kt +++ b/wire-tests/src/darwinTest/kotlin/com/squareup/wire/DarwinProtoAdapterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,10 +18,10 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.person.Person import com.squareup.wire.protos.kotlin.person.Person.PhoneNumber import com.squareup.wire.protos.kotlin.person.Person.PhoneType.WORK -import platform.Foundation.NSData -import platform.Foundation.create import kotlin.test.Test import kotlin.test.assertEquals +import platform.Foundation.NSData +import platform.Foundation.create class DarwinProtoAdapterTest { @Test fun decodeNSData() { @@ -29,10 +29,10 @@ class DarwinProtoAdapterTest { name = "Alice", id = 1, phone = listOf(PhoneNumber(number = "+15551234567", type = WORK)), - email = "alice@squareup.com" + email = "alice@squareup.com", ) val data = NSData.create( - base64Encoding = "CgVBbGljZRABGhJhbGljZUBzcXVhcmV1cC5jb20iEAoMKzE1NTUxMjM0NTY3EAI=" + base64Encoding = "CgVBbGljZRABGhJhbGljZUBzcXVhcmV1cC5jb20iEAoMKzE1NTUxMjM0NTY3EAI=", )!! assertEquals(expected, Person.ADAPTER.decode(data)) } diff --git a/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreJs.kt b/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreJs.kt index e76a4db3e0..a266ea04fc 100644 --- a/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreJs.kt +++ b/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreJs.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire actual typealias IgnoreJs = kotlin.test.Ignore diff --git a/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreNative.kt b/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreNative.kt index 6d24ad94db..4f98ada91d 100644 --- a/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreNative.kt +++ b/wire-tests/src/jsTest/kotlin/com/squareup/wire/IgnoreNative.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire actual annotation class IgnoreNative diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MapTest.kt b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MapTest.kt index 7f77aec890..662e7da1e9 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MapTest.kt +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MapTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2016 Square Inc. + * Copyright (C) 2016 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,6 +18,7 @@ package com.squareup.wire import com.squareup.wire.internal.createRuntimeMessageAdapter import com.squareup.wire.map.Mappy import com.squareup.wire.map.Thing +import java.io.IOException import okio.ByteString import okio.ByteString.Companion.decodeHex import org.assertj.core.api.Assertions.assertThat @@ -26,12 +27,12 @@ import org.junit.runner.RunWith import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameter import org.junit.runners.Parameterized.Parameters -import java.io.IOException @RunWith(Parameterized::class) class MapTest { @Parameter(0) lateinit var name: String + @Parameter(1) lateinit var adapter: ProtoAdapter @@ -42,7 +43,8 @@ class MapTest { assertThat(adapter.encode(EMPTY)).isEmpty() } - @Test @Throws(IOException::class) + @Test + @Throws(IOException::class) fun deserialize() { assertThat(adapter.decode(BYTES)).isEqualTo(THREE) @@ -65,13 +67,14 @@ class MapTest { fun parameters() = listOf( arrayOf("Generated", Mappy.ADAPTER), arrayOf( - "Runtime", createRuntimeMessageAdapter( + "Runtime", + createRuntimeMessageAdapter( Mappy::class.java, "square.github.io/wire/unknown", Syntax.PROTO_2, Mappy::class.java.classLoader, - ) - ) + ), + ), ) } } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MoshiRedactedTest.kt b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MoshiRedactedTest.kt index a1344678c2..ae0622d4cd 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MoshiRedactedTest.kt +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/MoshiRedactedTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -50,17 +50,17 @@ class MoshiRedactedTest { .a("a") .b("b") .c("c") - .build() + .build(), ).c( NotRedacted.Builder() .a("a") .b("b") - .build() + .build(), ).build() val jsonAdapter = moshi.adapter(RedactedChild::class.java).redacting() assertThat(jsonAdapter.toJson(redacted)).isEqualTo( - """{"a":"a","b":{"b":"b","c":"c","__redacted_fields":["a"]},"c":{"a":"a","b":"b"}}""" + """{"a":"a","b":{"b":"b","c":"c","__redacted_fields":["a"]},"c":{"a":"a","b":"b"}}""", ) } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/OneOfTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/OneOfTest.java index 9dd7863955..1cc665e451 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/OneOfTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/OneOfTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,24 +15,25 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + import com.squareup.wire.protos.oneof.OneOfMessage; import java.io.IOException; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - public class OneOfTest { private static final byte[] INITIAL_BYTES = {}; // (Tag #1 << 3 | VARINT) = 8. - private static final byte[] FOO_BYTES = { 8, 17 }; + private static final byte[] FOO_BYTES = {8, 17}; // (Tag #3 << 3 | LENGTH_DELIMITED) = 26, string length = 6. - private static final byte[] BAR_BYTES = { 26, 6, 'b', 'a', 'r', 'b', 'a', 'r'}; + private static final byte[] BAR_BYTES = {26, 6, 'b', 'a', 'r', 'b', 'a', 'r'}; private final ProtoAdapter adapter = OneOfMessage.ADAPTER; - @Test public void testOneOf() throws Exception { + @Test + public void testOneOf() throws Exception { OneOfMessage.Builder builder = new OneOfMessage.Builder(); validate(builder, null, null, INITIAL_BYTES); @@ -55,7 +56,8 @@ public class OneOfTest { validate(builder, null, null, INITIAL_BYTES); } - @Test public void buildFailsWhenBothFieldsAreNonNull() throws Exception { + @Test + public void buildFailsWhenBothFieldsAreNonNull() throws Exception { OneOfMessage.Builder builder = new OneOfMessage.Builder(); builder.foo = 1; builder.bar = "two"; @@ -67,7 +69,8 @@ public class OneOfTest { } } - @Test public void constructorFailsWhenBothFieldsAreNonNull() throws Exception { + @Test + public void constructorFailsWhenBothFieldsAreNonNull() throws Exception { try { new OneOfMessage(1, "two", null); fail(); @@ -76,8 +79,9 @@ public class OneOfTest { } } - private void validate(OneOfMessage.Builder builder, Integer expectedFoo, String expectedBar, - byte[] expectedBytes) throws IOException { + private void validate( + OneOfMessage.Builder builder, Integer expectedFoo, String expectedBar, byte[] expectedBytes) + throws IOException { // Check builder fields assertThat(builder.foo).isEqualTo(expectedFoo); assertThat(builder.bar).isEqualTo(expectedBar); diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ParseTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ParseTest.java index cb1a049258..84c842471c 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ParseTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ParseTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 Square Inc. + * Copyright (C) 2014 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,9 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + import com.squareup.wire.protos.edgecases.OneBytesField; import com.squareup.wire.protos.edgecases.OneField; import com.squareup.wire.protos.edgecases.Recursive; @@ -25,11 +28,9 @@ import org.junit.Ignore; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - public final class ParseTest { - @Test public void unknownTagIgnored() throws Exception { + @Test + public void unknownTagIgnored() throws Exception { // tag 1 / type 0: 456 // tag 2 / type 0: 789 ByteString data = ByteString.decodeHex("08c803109506"); @@ -39,7 +40,8 @@ public final class ParseTest { assertThat(oneField.withoutUnknownFields()).isEqualTo(expected); } - @Test public void unknownTypeThrowsIOException() throws Exception { + @Test + public void unknownTypeThrowsIOException() throws Exception { // tag 1 / type 0: 456 // tag 2 / type 7: 789 ByteString data = ByteString.decodeHex("08c803179506"); @@ -52,7 +54,8 @@ public final class ParseTest { } @Ignore("TODO(jwilson)") - @Test public void typeMismatchHonorsWireDeclaredType() throws Exception { + @Test + public void typeMismatchHonorsWireDeclaredType() throws Exception { // tag 1 / 3-byte length-delimited string: 0x109506 // (0x109506 is a well-formed proto message that sets tag 2 to 456). ByteString data = ByteString.decodeHex("0a03109506"); @@ -60,7 +63,8 @@ public final class ParseTest { assertThat(oneField).isEqualTo(new OneField.Builder().opt_int32(3).build()); } - @Test public void truncatedMessageThrowsEOFException() throws Exception { + @Test + public void truncatedMessageThrowsEOFException() throws Exception { // tag 1 / 4-byte length delimited string: 0x000000 (3 bytes) ByteString data = ByteString.decodeHex("0a04000000"); try { @@ -71,7 +75,8 @@ public final class ParseTest { } @Ignore("we no longer enforce this constraint") - @Test public void repeatedUnknownValueWithDifferentTypesThrowsIOException() throws Exception { + @Test + public void repeatedUnknownValueWithDifferentTypesThrowsIOException() throws Exception { // tag 2 / 3-byte length-delimited string: 0x109506 // tag 2 / type 0: 456 ByteString data = ByteString.decodeHex("120300000010c803"); @@ -79,12 +84,13 @@ public final class ParseTest { OneField.ADAPTER.decode(data.toByteArray()); fail(); } catch (ProtocolException expected) { - assertThat(expected).hasMessage( - "Wire type VARINT differs from previous type LENGTH_DELIMITED for tag 2"); + assertThat(expected) + .hasMessage("Wire type VARINT differs from previous type LENGTH_DELIMITED for tag 2"); } } - @Test public void lastValueWinsForRepeatedValueOfNonrepeatedField() throws Exception { + @Test + public void lastValueWinsForRepeatedValueOfNonrepeatedField() throws Exception { // tag 1 / type 0: 456 // tag 1 / type 0: 789 ByteString data = ByteString.decodeHex("08c803089506"); @@ -92,24 +98,30 @@ public final class ParseTest { assertThat(new OneField.Builder().opt_int32(789).build()).isEqualTo(oneField); } - @Test public void upToRecursionLimit() throws Exception { + @Test + public void upToRecursionLimit() throws Exception { // tag 2: nested message (64 times) // tag 1: signed varint32 456 - ByteString data = ByteString.decodeHex("127e127c127a12781276127412721270126e126c126a12681266126" - + "412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c123a123" - + "81236123412321230122e122c122a12281226122412221220121e121c121a12181216121412121210120e120" - + "c120a1208120612041202120008c803"); + ByteString data = + ByteString.decodeHex( + "127e127c127a12781276127412721270126e126c126a12681266126" + + "412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c123a123" + + "81236123412321230122e122c122a12281226122412221220121e121c121a12181216121412121210120e120" + + "c120a1208120612041202120008c803"); Recursive recursive = Recursive.ADAPTER.decode(data.toByteArray()); assertThat(recursive.value.intValue()).isEqualTo(456); } - @Test public void overRecursionLimitThrowsIOException() throws Exception { + @Test + public void overRecursionLimitThrowsIOException() throws Exception { // tag 2: nested message (65 times) // tag 1: signed varint32 456 - ByteString data = ByteString.decodeHex("128001127e127c127a12781276127412721270126e126c126a12681" - + "266126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c1" - + "23a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212101" - + "20e120c120a1208120612041202120008c803"); + ByteString data = + ByteString.decodeHex( + "128001127e127c127a12781276127412721270126e126c126a12681" + + "266126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c1" + + "23a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212101" + + "20e120c120a1208120612041202120008c803"); try { Recursive.ADAPTER.decode(data.toByteArray()); fail(); diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ProtoAdapterTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ProtoAdapterTest.java index bc4b41ae4c..392c7749a3 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ProtoAdapterTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/ProtoAdapterTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,9 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; + import com.squareup.wire.protos.person.Person; import java.io.IOException; import okio.ByteString; @@ -22,15 +25,10 @@ import squareup.protos.packed_encoding.EmbeddedMessage; import squareup.protos.packed_encoding.OuterMessage; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; - public final class ProtoAdapterTest { - @Test public void getFromClass() throws Exception { - Person person = new Person.Builder() - .id(99) - .name("Omar Little") - .build(); + @Test + public void getFromClass() throws Exception { + Person person = new Person.Builder().id(99).name("Omar Little").build(); ByteString encoded = ByteString.decodeHex("10630a0b4f6d6172204c6974746c65"); ProtoAdapter personAdapter = ProtoAdapter.get(Person.class); @@ -38,11 +36,9 @@ public final class ProtoAdapterTest { assertThat(personAdapter.decode(encoded)).isEqualTo(person); } - @Test public void getFromInstanceSameAsFromClass() throws Exception { - Person person = new Person.Builder() - .id(99) - .name("Omar Little") - .build(); + @Test + public void getFromInstanceSameAsFromClass() throws Exception { + Person person = new Person.Builder().id(99).name("Omar Little").build(); ProtoAdapter instanceAdapter = ProtoAdapter.get(person); ProtoAdapter classAdapter = ProtoAdapter.get(Person.class); @@ -50,22 +46,23 @@ public final class ProtoAdapterTest { assertThat(instanceAdapter).isSameAs(classAdapter); } - @Test public void repeatedHelpersCacheInstances() { + @Test + public void repeatedHelpersCacheInstances() { ProtoAdapter adapter = ProtoAdapter.UINT64; assertThat(adapter.asRepeated()).isSameAs(adapter.asRepeated()); assertThat(adapter.asPacked()).isSameAs(adapter.asPacked()); } /** https://github.com/square/wire/issues/541 */ - @Test public void embeddedEmptyPackedMessage() throws IOException { - OuterMessage outerMessage = new OuterMessage.Builder() - .outer_number_before(2) - .embedded_message(new EmbeddedMessage.Builder() - .inner_number_after(1) - .build()) - .build(); - OuterMessage outerMessagesAfterSerialisation = OuterMessage.ADAPTER.decode( - OuterMessage.ADAPTER.encode(outerMessage)); + @Test + public void embeddedEmptyPackedMessage() throws IOException { + OuterMessage outerMessage = + new OuterMessage.Builder() + .outer_number_before(2) + .embedded_message(new EmbeddedMessage.Builder().inner_number_after(1).build()) + .build(); + OuterMessage outerMessagesAfterSerialisation = + OuterMessage.ADAPTER.decode(OuterMessage.ADAPTER.encode(outerMessage)); assertEquals(outerMessagesAfterSerialisation, outerMessage); } } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/RuntimeMessageAdapterRedactTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/RuntimeMessageAdapterRedactTest.java index e72a69d74b..c9a2568ff9 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/RuntimeMessageAdapterRedactTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/RuntimeMessageAdapterRedactTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2014 Square Inc. + * Copyright (C) 2014 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,9 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + import com.squareup.wire.protos.redacted.NotRedacted; import com.squareup.wire.protos.redacted.RedactedChild; import com.squareup.wire.protos.redacted.RedactedCycleA; @@ -26,82 +29,93 @@ import java.util.Arrays; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - public class RuntimeMessageAdapterRedactTest { - @Test public void string() throws IOException { + @Test + public void string() throws IOException { RedactedFields redacted = new RedactedFields.Builder().a("a").b("b").c("c").build(); assertThat(redacted.toString()).isEqualTo("RedactedFields{a=██, b=b, c=c}"); - RedactedRepeated redactedRepeated = new RedactedRepeated.Builder() - .a(Arrays.asList("a", "b")) - .b(Arrays.asList( - new RedactedFields("a", "b", "c", null), new RedactedFields("d", "e", "f", null))) - .build(); - assertThat(redactedRepeated.toString()).isEqualTo( - "RedactedRepeated{a=██, b=[RedactedFields{a=██, b=b, c=c}," - + " RedactedFields{a=██, b=e, c=f}]}"); + RedactedRepeated redactedRepeated = + new RedactedRepeated.Builder() + .a(Arrays.asList("a", "b")) + .b( + Arrays.asList( + new RedactedFields("a", "b", "c", null), + new RedactedFields("d", "e", "f", null))) + .build(); + assertThat(redactedRepeated.toString()) + .isEqualTo( + "RedactedRepeated{a=██, b=[RedactedFields{a=██, b=b, c=c}," + + " RedactedFields{a=██, b=e, c=f}]}"); } - @Test public void message() { + @Test + public void message() { RedactedFields message = new RedactedFields.Builder().a("a").b("b").c("c").build(); RedactedFields expected = message.newBuilder().a(null).build(); assertThat(RedactedFields.ADAPTER.redact(message)).isEqualTo(expected); } - @Test public void messageWithNoRedactions() { + @Test + public void messageWithNoRedactions() { NotRedacted message = new NotRedacted.Builder().a("a").b("b").build(); assertThat(NotRedacted.ADAPTER.redact(message)).isEqualTo(message); } - @Test public void nestedRedactions() { - RedactedChild message = new RedactedChild.Builder() - .a("a") - .b(new RedactedFields.Builder().a("a").b("b").c("c").build()) - .c(new NotRedacted.Builder().a("a").b("b").build()) - .build(); - RedactedChild expected = message.newBuilder() - .b(message.b.newBuilder().a(null).build()) - .build(); + @Test + public void nestedRedactions() { + RedactedChild message = + new RedactedChild.Builder() + .a("a") + .b(new RedactedFields.Builder().a("a").b("b").c("c").build()) + .c(new NotRedacted.Builder().a("a").b("b").build()) + .build(); + RedactedChild expected = message.newBuilder().b(message.b.newBuilder().a(null).build()).build(); assertThat(RedactedChild.ADAPTER.redact(message)).isEqualTo(expected); } - @Test public void redactedExtensions() { - RedactedFields message = new RedactedFields.Builder() - .extension(new RedactedExtension.Builder() - .d("d") - .e("e") - .build()) - .build(); - RedactedFields expected = new RedactedFields.Builder() - .extension(new RedactedExtension.Builder() - .e("e") - .build()) - .build(); + @Test + public void redactedExtensions() { + RedactedFields message = + new RedactedFields.Builder() + .extension(new RedactedExtension.Builder().d("d").e("e").build()) + .build(); + RedactedFields expected = + new RedactedFields.Builder() + .extension(new RedactedExtension.Builder().e("e").build()) + .build(); assertThat(RedactedFields.ADAPTER.redact(message)).isEqualTo(expected); } - @Test public void messageCycle() { + @Test + public void messageCycle() { RedactedCycleA message = new RedactedCycleA.Builder().build(); assertThat(RedactedCycleA.ADAPTER.redact(message)).isEqualTo(message); } - @Test public void repeatedField() { - RedactedRepeated message = new RedactedRepeated.Builder() - .a(Arrays.asList("a", "b")) - .b(Arrays.asList( - new RedactedFields("a", "b", "c", null), new RedactedFields("d", "e", "f", null))) - .build(); - RedactedRepeated expected = new RedactedRepeated.Builder() - .b(Arrays.asList( - new RedactedFields(null, "b", "c", null), new RedactedFields(null, "e", "f", null))) - .build(); + @Test + public void repeatedField() { + RedactedRepeated message = + new RedactedRepeated.Builder() + .a(Arrays.asList("a", "b")) + .b( + Arrays.asList( + new RedactedFields("a", "b", "c", null), + new RedactedFields("d", "e", "f", null))) + .build(); + RedactedRepeated expected = + new RedactedRepeated.Builder() + .b( + Arrays.asList( + new RedactedFields(null, "b", "c", null), + new RedactedFields(null, "e", "f", null))) + .build(); RedactedRepeated actual = RedactedRepeated.ADAPTER.redact(message); assertThat(actual).isEqualTo(expected); } - @Test public void requiredRedactedFieldThrowsRedacting() { + @Test + public void requiredRedactedFieldThrowsRedacting() { ProtoAdapter adapter = RedactedRequired.ADAPTER; try { adapter.redact(new RedactedRequired("a")); @@ -111,7 +125,8 @@ public class RuntimeMessageAdapterRedactTest { } } - @Test public void requiredRedactedFieldToString() { + @Test + public void requiredRedactedFieldToString() { ProtoAdapter adapter = RedactedRequired.ADAPTER; assertThat(adapter.toString(new RedactedRequired("a"))).isEqualTo("RedactedRequired{a=██}"); } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/SerializableTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/SerializableTest.java index ba97da52b3..ce6613d4b3 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/SerializableTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/SerializableTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,8 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; + import com.squareup.wire.protos.edgecases.NoFields; import com.squareup.wire.protos.person.Person; import com.squareup.wire.protos.simple.SimpleMessage; @@ -25,51 +27,55 @@ import okio.ByteString; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class SerializableTest { - @Test public void simple() throws Exception { + @Test + public void simple() throws Exception { SimpleMessage message = new SimpleMessage.Builder().required_int32(42).build(); assertThat(deserialize(serialize(message))).isEqualTo(message); } - @Test public void nestedMessage() throws Exception { - Person person = new Person.Builder() - .name("Omar") - .id(1234) - .email("omar@wire.com") - .phone(Arrays.asList(new Person.PhoneNumber.Builder() - .number("410-555-0909") - .type(Person.PhoneType.MOBILE) - .build())) - .build(); + @Test + public void nestedMessage() throws Exception { + Person person = + new Person.Builder() + .name("Omar") + .id(1234) + .email("omar@wire.com") + .phone( + Arrays.asList( + new Person.PhoneNumber.Builder() + .number("410-555-0909") + .type(Person.PhoneType.MOBILE) + .build())) + .build(); assertThat(deserialize(serialize(person))).isEqualTo(person); } - @Test public void noFields() throws Exception { + @Test + public void noFields() throws Exception { NoFields noFields = new NoFields(); assertThat(deserialize(serialize(noFields))).isEqualTo(noFields); } - @Test public void decodeGolden() throws Exception { - SimpleMessage goldenValue = new SimpleMessage.Builder() - .required_int32(99) - .result("tacos") - .build(); - ByteString goldenSerialized = ByteString.decodeBase64("rO0ABXNyACdjb20uc3F1YXJldXAud2lyZS5NZXNz" - + "YWdlU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABWJ5dGVzdAACW0JMAAxtZXNzYWdlQ2xhc3N0ABFMamF2YS9s" - + "YW5nL0NsYXNzO3hwdXIAAltCrPMX+AYIVOACAAB4cAAAAAkoY1IFdGFjb3N2cgAtY29tLnNxdWFyZXVwLndpcmUu" - + "cHJvdG9zLnNpbXBsZS5TaW1wbGVNZXNzYWdlAAAAAAAAAAACAAxMABRkZWZhdWx0X2ZvcmVpZ25fZW51bXQALkxj" - + "b20vc3F1YXJldXAvd2lyZS9wcm90b3MvZm9yZWlnbi9Gb3JlaWduRW51bTtMABNkZWZhdWx0X25lc3RlZF9lbnVt" - + "dAA6TGNvbS9zcXVhcmV1cC93aXJlL3Byb3Rvcy9zaW1wbGUvU2ltcGxlTWVzc2FnZSROZXN0ZWRFbnVtO0wAF25v" - + "X2RlZmF1bHRfZm9yZWlnbl9lbnVtcQB+AAdMAAFvdAASTGphdmEvbGFuZy9TdHJpbmc7TAAVb3B0aW9uYWxfZXh0" - + "ZXJuYWxfbXNndAAxTGNvbS9zcXVhcmV1cC93aXJlL3Byb3Rvcy9zaW1wbGUvRXh0ZXJuYWxNZXNzYWdlO0wADm9w" - + "dGlvbmFsX2ludDMydAATTGphdmEvbGFuZy9JbnRlZ2VyO0wAE29wdGlvbmFsX25lc3RlZF9tc2d0AD1MY29tL3Nx" - + "dWFyZXVwL3dpcmUvcHJvdG9zL3NpbXBsZS9TaW1wbGVNZXNzYWdlJE5lc3RlZE1lc3NhZ2U7TAAFb3RoZXJxAH4A" - + "CUwACHBhY2thZ2VfcQB+AAlMAA9yZXBlYXRlZF9kb3VibGV0ABBMamF2YS91dGlsL0xpc3Q7TAAOcmVxdWlyZWRf" - + "aW50MzJxAH4AC0wABnJlc3VsdHEAfgAJeHIAGWNvbS5zcXVhcmV1cC53aXJlLk1lc3NhZ2UAAAAAAAAAAAIAAHhw" - ); + @Test + public void decodeGolden() throws Exception { + SimpleMessage goldenValue = + new SimpleMessage.Builder().required_int32(99).result("tacos").build(); + ByteString goldenSerialized = + ByteString.decodeBase64( + "rO0ABXNyACdjb20uc3F1YXJldXAud2lyZS5NZXNz" + + "YWdlU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABWJ5dGVzdAACW0JMAAxtZXNzYWdlQ2xhc3N0ABFMamF2YS9s" + + "YW5nL0NsYXNzO3hwdXIAAltCrPMX+AYIVOACAAB4cAAAAAkoY1IFdGFjb3N2cgAtY29tLnNxdWFyZXVwLndpcmUu" + + "cHJvdG9zLnNpbXBsZS5TaW1wbGVNZXNzYWdlAAAAAAAAAAACAAxMABRkZWZhdWx0X2ZvcmVpZ25fZW51bXQALkxj" + + "b20vc3F1YXJldXAvd2lyZS9wcm90b3MvZm9yZWlnbi9Gb3JlaWduRW51bTtMABNkZWZhdWx0X25lc3RlZF9lbnVt" + + "dAA6TGNvbS9zcXVhcmV1cC93aXJlL3Byb3Rvcy9zaW1wbGUvU2ltcGxlTWVzc2FnZSROZXN0ZWRFbnVtO0wAF25v" + + "X2RlZmF1bHRfZm9yZWlnbl9lbnVtcQB+AAdMAAFvdAASTGphdmEvbGFuZy9TdHJpbmc7TAAVb3B0aW9uYWxfZXh0" + + "ZXJuYWxfbXNndAAxTGNvbS9zcXVhcmV1cC93aXJlL3Byb3Rvcy9zaW1wbGUvRXh0ZXJuYWxNZXNzYWdlO0wADm9w" + + "dGlvbmFsX2ludDMydAATTGphdmEvbGFuZy9JbnRlZ2VyO0wAE29wdGlvbmFsX25lc3RlZF9tc2d0AD1MY29tL3Nx" + + "dWFyZXVwL3dpcmUvcHJvdG9zL3NpbXBsZS9TaW1wbGVNZXNzYWdlJE5lc3RlZE1lc3NhZ2U7TAAFb3RoZXJxAH4A" + + "CUwACHBhY2thZ2VfcQB+AAlMAA9yZXBlYXRlZF9kb3VibGV0ABBMamF2YS91dGlsL0xpc3Q7TAAOcmVxdWlyZWRf" + + "aW50MzJxAH4AC0wABnJlc3VsdHEAfgAJeHIAGWNvbS5zcXVhcmV1cC53aXJlLk1lc3NhZ2UAAAAAAAAAAAIAAHhw"); assertThat(deserialize(goldenSerialized)).isEqualTo(goldenValue); assertThat(serialize(goldenValue)).isEqualTo(goldenSerialized); } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypes.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypes.java index 09690da1bf..2f75ceeb96 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypes.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypes.java @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,10 @@ */ package com.squareup.wire; +import static com.squareup.wire.protos.alltypes.AllTypes.NestedEnum.A; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + import com.squareup.wire.protos.alltypes.AllTypes; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -23,7 +27,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import kotlin.KotlinNullPointerException; import okio.Buffer; import okio.ByteString; import okio.ForwardingSource; @@ -32,10 +35,6 @@ import org.junit.Ignore; import org.junit.Test; -import static com.squareup.wire.protos.alltypes.AllTypes.NestedEnum.A; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - public class TestAllTypes { // Return a two-element list with a given repeated value @@ -394,7 +393,8 @@ private static class SlowSource extends ForwardingSource { super(delegate); } - @Override public long read(Buffer sink, long byteCount) throws IOException { + @Override + public long read(Buffer sink, long byteCount) throws IOException { long bytesToReturn = Math.min(byteCount, (pos % 4) + 1); pos += bytesToReturn; return super.read(sink, byteCount); @@ -423,8 +423,7 @@ public void testReadNoExtension() throws IOException { @Test public void testReadNonPacked() throws IOException { - AllTypes parsed = adapter.decode( - new Buffer().write(TestAllTypesData.nonPacked)); + AllTypes parsed = adapter.decode(new Buffer().write(TestAllTypesData.nonPacked)); assertThat(parsed).isEqualTo(allTypes); } @@ -454,20 +453,23 @@ public void testRequiredFields() { builder.build(); fail(); } catch (IllegalStateException e) { - assertThat(e).hasMessage( - "Required fields not set:\n req_int32\n req_sfixed64\n req_bool"); + assertThat(e).hasMessage("Required fields not set:\n req_int32\n req_sfixed64\n req_bool"); } } @Test public void testDefaults() throws Exception { assertThat(AllTypes.DEFAULT_DEFAULT_BOOL).isEqualTo((Object) true); - // original: "ok\a\b\f\n\r\t\v\1\01\001\17\017\176\x1\x01\x11\X1\X01\X11gzel" - assertThat(AllTypes.DEFAULT_DEFAULT_STRING).isEqualTo( "çok\u0007\b\f\n\r\t\u000b\u0001\u0001" - + "\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001\u0011güzel"); - assertThat(new String(AllTypes.DEFAULT_DEFAULT_BYTES.toByteArray(), "ISO-8859-1")).isEqualTo( - "çok\u0007\b\f\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001" - + "\u0011güzel"); + // original: "ok\a\b\f\n\r\t\v\1\01\001\17\017\176\x1\x01\x11\X1\X01\X11gzel" + assertThat(AllTypes.DEFAULT_DEFAULT_STRING) + .isEqualTo( + "çok\u0007\b\f\n\r\t\u000b\u0001\u0001" + + "\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001\u0011güzel"); + assertThat(new String(AllTypes.DEFAULT_DEFAULT_BYTES.toByteArray(), "ISO-8859-1")) + .isEqualTo( + "çok\u0007\b\f\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001" + + "\u0011güzel"); } @Test @@ -479,7 +481,7 @@ public void testEnums() { @Test public void testSkipGroup() throws IOException { - byte[] data = new byte[TestAllTypesData.expectedOutput.size() + 27]; + byte[] data = new byte[TestAllTypesData.expectedOutput.size() + 27]; System.arraycopy(TestAllTypesData.expectedOutput.toByteArray(), 0, data, 0, 17); int index = 17; data[index++] = (byte) 0xa3; // start group, tag = 20, type = 3 @@ -510,7 +512,11 @@ public void testSkipGroup() throws IOException { data[index++] = (byte) 0xa4; // end group, tag = 20, type = 4 data[index++] = (byte) 0x01; - System.arraycopy(TestAllTypesData.expectedOutput.toByteArray(), 17, data, index, + System.arraycopy( + TestAllTypesData.expectedOutput.toByteArray(), + 17, + data, + index, TestAllTypesData.expectedOutput.size() - 17); AllTypes parsed = adapter.decode(data); @@ -531,7 +537,8 @@ public void testUnknownFields() { assertThat(data[count + 3]).isEqualTo((byte) 0x01); } - @Test @Ignore("we no longer enforce this constraint") + @Test + @Ignore("we no longer enforce this constraint") public void testUnknownFieldsTypeMismatch() { AllTypes.Builder builder = getBuilder(); builder.addUnknownField(10000, FieldEncoding.VARINT, 1); @@ -540,8 +547,8 @@ public void testUnknownFieldsTypeMismatch() { builder.addUnknownField(10000, FieldEncoding.FIXED32, 2); fail(); } catch (IllegalArgumentException expected) { - assertThat(expected).hasMessage( - "Wire type FIXED32 differs from previous type VARINT for tag 10000"); + assertThat(expected) + .hasMessage("Wire type FIXED32 differs from previous type VARINT for tag 10000"); } } @@ -563,8 +570,10 @@ public void testNullRepeated() { getBuilder().rep_nested_enum(null); fail(); } catch (NullPointerException e) { - assertThat(e).hasMessage("Parameter specified as non-null is null: method " - + "com.squareup.wire.internal.Internal__InternalKt.checkElementsNotNull, parameter list"); + assertThat(e) + .hasMessage( + "Parameter specified as non-null is null: method " + + "com.squareup.wire.internal.Internal__InternalKt.checkElementsNotNull, parameter list"); } } } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypesData.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypesData.java index 723fdfe95c..540029669e 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypesData.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/TestAllTypesData.java @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,490 +19,495 @@ class TestAllTypesData { - public static final String expectedToString = "" - + "AllTypes{opt_int32=111, opt_uint32=112, opt_sint32=113, opt_fixed32=114, opt_sfixed32=115," - + " opt_int64=116, opt_uint64=117, opt_sint64=118, opt_fixed64=119, opt_sfixed64=120, opt_boo" - + "l=true, opt_float=122.0, opt_double=123.0, opt_string=124, opt_bytes=[hex=7de1], opt_neste" - + "d_enum=A, opt_nested_message=NestedMessage{a=999}, req_int32=111, req_uint32=112, req_sint" - + "32=113, req_fixed32=114, req_sfixed32=115, req_int64=116, req_uint64=117, req_sint64=118, " - + "req_fixed64=119, req_sfixed64=120, req_bool=true, req_float=122.0, req_double=123.0, req_s" - + "tring=124, req_bytes=[hex=7de1], req_nested_enum=A, req_nested_message=NestedMessage{a=999" - + "}, rep_int32=[111, 111], rep_uint32=[112, 112], rep_sint32=[113, 113], rep_fixed32=[114, 1" - + "14], rep_sfixed32=[115, 115], rep_int64=[116, 116], rep_uint64=[117, 117], rep_sint64=[118" - + ", 118], rep_fixed64=[119, 119], rep_sfixed64=[120, 120], rep_bool=[true, true], rep_float=" - + "[122.0, 122.0], rep_double=[123.0, 123.0], rep_string=[124, 124], rep_bytes=[[hex=7de1], [" - + "hex=7de1]], rep_nested_enum=[A, A], rep_nested_message=[NestedMessage{a=999}, NestedMessag" - + "e{a=999}], pack_int32=[111, 111], pack_uint32=[112, 112], pack_sint32=[113, 113], pack_fix" - + "ed32=[114, 114], pack_sfixed32=[115, 115], pack_int64=[116, 116], pack_uint64=[117, 117], " - + "pack_sint64=[118, 118], pack_fixed64=[119, 119], pack_sfixed64=[120, 120], pack_bool=[true" - + ", true], pack_float=[122.0, 122.0], pack_double=[123.0, 123.0], pack_nested_enum=[A, A], e" - + "xt_opt_bool=true, ext_rep_bool=[true, true], ext_pack_bool=[true, true]}"; - public static final ByteString expectedOutput = ByteString.decodeHex("" - // optional + public static final String expectedToString = + "" + + "AllTypes{opt_int32=111, opt_uint32=112, opt_sint32=113, opt_fixed32=114, opt_sfixed32=115," + + " opt_int64=116, opt_uint64=117, opt_sint64=118, opt_fixed64=119, opt_sfixed64=120, opt_boo" + + "l=true, opt_float=122.0, opt_double=123.0, opt_string=124, opt_bytes=[hex=7de1], opt_neste" + + "d_enum=A, opt_nested_message=NestedMessage{a=999}, req_int32=111, req_uint32=112, req_sint" + + "32=113, req_fixed32=114, req_sfixed32=115, req_int64=116, req_uint64=117, req_sint64=118, " + + "req_fixed64=119, req_sfixed64=120, req_bool=true, req_float=122.0, req_double=123.0, req_s" + + "tring=124, req_bytes=[hex=7de1], req_nested_enum=A, req_nested_message=NestedMessage{a=999" + + "}, rep_int32=[111, 111], rep_uint32=[112, 112], rep_sint32=[113, 113], rep_fixed32=[114, 1" + + "14], rep_sfixed32=[115, 115], rep_int64=[116, 116], rep_uint64=[117, 117], rep_sint64=[118" + + ", 118], rep_fixed64=[119, 119], rep_sfixed64=[120, 120], rep_bool=[true, true], rep_float=" + + "[122.0, 122.0], rep_double=[123.0, 123.0], rep_string=[124, 124], rep_bytes=[[hex=7de1], [" + + "hex=7de1]], rep_nested_enum=[A, A], rep_nested_message=[NestedMessage{a=999}, NestedMessag" + + "e{a=999}], pack_int32=[111, 111], pack_uint32=[112, 112], pack_sint32=[113, 113], pack_fix" + + "ed32=[114, 114], pack_sfixed32=[115, 115], pack_int64=[116, 116], pack_uint64=[117, 117], " + + "pack_sint64=[118, 118], pack_fixed64=[119, 119], pack_sfixed64=[120, 120], pack_bool=[true" + + ", true], pack_float=[122.0, 122.0], pack_double=[123.0, 123.0], pack_nested_enum=[A, A], e" + + "xt_opt_bool=true, ext_rep_bool=[true, true], ext_pack_bool=[true, true]}"; + public static final ByteString expectedOutput = + ByteString.decodeHex( + "" + // optional - + "08" // tag = 1, type = 0 - + "6f" // value = 111 - + "10" // tag = 2, type = 0 - + "70" // value = 112 - + "18" // tag = 3, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "25" // tag = 4, type = 5 - + "72000000" // value = 114 (fixed32) - + "2d" // tag = 5, type = 5 - + "73000000" // value = 115 (sfixed32) - + "30" // tag = 6, type = 0 - + "74" // value = 116 - + "38" // tag = 7, type = 0 - + "75" // value = 117 - + "40" // tag = 8, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "49" // tag = 9, type = 1 - + "7700000000000000" // value = 119 - + "51" // tag = 10, type = 1 - + "7800000000000000" // value = 120 - + "58" // tag = 11, type = 0 - + "01" // value = 1 (true) - + "65" // tag = 12, type = 5 - + "0000f442" // value = 122.0F - + "69" // tag = 13, type = 1 - + "0000000000c05e40" // value = 123.0 - + "72" // tag = 14, type = 2 - + "03" // length = 3 - + "313234" - + "7a" // tag = 15, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "8001" // tag = 16, type = 0 - + "01" // value = 1 - + "8a01" // tag = 17, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 + + "08" // tag = 1, type = 0 + + "6f" // value = 111 + + "10" // tag = 2, type = 0 + + "70" // value = 112 + + "18" // tag = 3, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "25" // tag = 4, type = 5 + + "72000000" // value = 114 (fixed32) + + "2d" // tag = 5, type = 5 + + "73000000" // value = 115 (sfixed32) + + "30" // tag = 6, type = 0 + + "74" // value = 116 + + "38" // tag = 7, type = 0 + + "75" // value = 117 + + "40" // tag = 8, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "49" // tag = 9, type = 1 + + "7700000000000000" // value = 119 + + "51" // tag = 10, type = 1 + + "7800000000000000" // value = 120 + + "58" // tag = 11, type = 0 + + "01" // value = 1 (true) + + "65" // tag = 12, type = 5 + + "0000f442" // value = 122.0F + + "69" // tag = 13, type = 1 + + "0000000000c05e40" // value = 123.0 + + "72" // tag = 14, type = 2 + + "03" // length = 3 + + "313234" + + "7a" // tag = 15, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "8001" // tag = 16, type = 0 + + "01" // value = 1 + + "8a01" // tag = 17, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 - // required + // required - + "a806" // tag = 101, type = 0 - + "6f" // value = 111 - + "b006" // tag = 102, type = 0 - + "70" // value = 112 - + "b806" // tag = 103, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "c506" // tag = 104, type = 5 - + "72000000" // value = 114 (fixed32) - + "cd06" // tag = 105, type = 5 - + "73000000" // value = 115 (sfixed32) - + "d006" // tag = 106, type = 0 - + "74" // value = 116 - + "d806" // tag = 107, type = 0 - + "75" // value = 117 - + "e006" // tag = 108, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "e906" // tag = 109, type = 1 - + "7700000000000000" // value = 119 - + "f106" // tag = 110, type = 1 - + "7800000000000000" // value = 120 - + "f806" // tag = 111, type = 0 - + "01" // value = 1 (true) - + "8507" // tag = 112, type = 5 - + "0000f442" // value = 122.0F - + "8907" // tag = 113, type = 1 - + "0000000000c05e40" // value = 123.0 - + "9207" // tag = 114, type = 2 - + "03" // length = 3 - + "313234" // value = "124" - + "9a07" // tag = 115, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "a007" // tag = 116, type = 0 - + "01" // value = 1 - + "aa07" // tag = 117, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 + + "a806" // tag = 101, type = 0 + + "6f" // value = 111 + + "b006" // tag = 102, type = 0 + + "70" // value = 112 + + "b806" // tag = 103, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "c506" // tag = 104, type = 5 + + "72000000" // value = 114 (fixed32) + + "cd06" // tag = 105, type = 5 + + "73000000" // value = 115 (sfixed32) + + "d006" // tag = 106, type = 0 + + "74" // value = 116 + + "d806" // tag = 107, type = 0 + + "75" // value = 117 + + "e006" // tag = 108, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "e906" // tag = 109, type = 1 + + "7700000000000000" // value = 119 + + "f106" // tag = 110, type = 1 + + "7800000000000000" // value = 120 + + "f806" // tag = 111, type = 0 + + "01" // value = 1 (true) + + "8507" // tag = 112, type = 5 + + "0000f442" // value = 122.0F + + "8907" // tag = 113, type = 1 + + "0000000000c05e40" // value = 123.0 + + "9207" // tag = 114, type = 2 + + "03" // length = 3 + + "313234" // value = "124" + + "9a07" // tag = 115, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "a007" // tag = 116, type = 0 + + "01" // value = 1 + + "aa07" // tag = 117, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 - // repeated + // repeated - + "c80c"// tag = 201, type = 0 - + "6f" // value = 111 - + "c80c" // tag = 201, type = 0 - + "6f" // value = 111 - + "d00c" // tag = 202, type = 0 - + "70" // value = 112 - + "d00c" // tag = 202, type = 0 - + "70" // value = 112 - + "d80c" // tag = 203, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "d80c" // tag = 203, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "e50c" // tag = 204, type = 5 - + "72000000" // value = 114 (fixed32) - + "e50c" // tag = 204, type = 5 - + "72000000" // value = 114 (fixed32) - + "ed0c" // tag = 205, type = 5 - + "73000000" // value = 115 (sfixed32) - + "ed0c" // tag = 205, type = 5 - + "73000000" // value = 115 (sfixed32) - + "f00c" // tag = 206, type = 0 - + "74" // value = 116 - + "f00c" // tag = 206, type = 0 - + "74" // value = 116 - + "f80c" // tag = 207, type = 0 - + "75" // value = 117 - + "f80c" // tag = 207, type = 0 - + "75" // value = 117 - + "800d" // tag = 208, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "800d" // tag = 208, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "890d" // tag = 209, type = 1 - + "7700000000000000" // value = 119 - + "890d" // tag = 209, type = 1 - + "7700000000000000" // value = 119 - + "910d" // tag = 210, type = 1 - + "7800000000000000" // value = 120 - + "910d" // tag = 210, type = 1 - + "7800000000000000" // value = 120 - + "980d" // tag = 211, type = 0 - + "01" // value = 1 (true) - + "980d" // tag = 211, type = 0 - + "01" // value = 1 (true) - + "a50d" // tag = 212, type = 5 - + "0000f442" // value = 122.0F - + "a50d" // tag = 212, type = 5 - + "0000f442" // value = 122.0F - + "a90d" // tag = 213, type = 1 - + "0000000000c05e40" // value = 123.0 - + "a90d" // tag = 213, type = 1 - + "0000000000c05e40" // value = 123.0 - + "b20d" // tag = 214, type = 2 - + "03" // length = 3 - + "313234" // value = "124" - + "b20d" // tag = 214, type = 2 - + "03" // length = 3 - + "313234" // value = "124" - + "ba0d" // tag = 215, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "ba0d" // tag = 215, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "c00d" // tag = 216, type = 0 - + "01" // value = 1 - + "c00d" // tag = 216, type = 0 - + "01" // value = 1 - + "ca0d" // tag = 217, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 - + "ca0d" // tag = 217, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 + + "c80c" // tag = 201, type = 0 + + "6f" // value = 111 + + "c80c" // tag = 201, type = 0 + + "6f" // value = 111 + + "d00c" // tag = 202, type = 0 + + "70" // value = 112 + + "d00c" // tag = 202, type = 0 + + "70" // value = 112 + + "d80c" // tag = 203, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "d80c" // tag = 203, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "e50c" // tag = 204, type = 5 + + "72000000" // value = 114 (fixed32) + + "e50c" // tag = 204, type = 5 + + "72000000" // value = 114 (fixed32) + + "ed0c" // tag = 205, type = 5 + + "73000000" // value = 115 (sfixed32) + + "ed0c" // tag = 205, type = 5 + + "73000000" // value = 115 (sfixed32) + + "f00c" // tag = 206, type = 0 + + "74" // value = 116 + + "f00c" // tag = 206, type = 0 + + "74" // value = 116 + + "f80c" // tag = 207, type = 0 + + "75" // value = 117 + + "f80c" // tag = 207, type = 0 + + "75" // value = 117 + + "800d" // tag = 208, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "800d" // tag = 208, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "890d" // tag = 209, type = 1 + + "7700000000000000" // value = 119 + + "890d" // tag = 209, type = 1 + + "7700000000000000" // value = 119 + + "910d" // tag = 210, type = 1 + + "7800000000000000" // value = 120 + + "910d" // tag = 210, type = 1 + + "7800000000000000" // value = 120 + + "980d" // tag = 211, type = 0 + + "01" // value = 1 (true) + + "980d" // tag = 211, type = 0 + + "01" // value = 1 (true) + + "a50d" // tag = 212, type = 5 + + "0000f442" // value = 122.0F + + "a50d" // tag = 212, type = 5 + + "0000f442" // value = 122.0F + + "a90d" // tag = 213, type = 1 + + "0000000000c05e40" // value = 123.0 + + "a90d" // tag = 213, type = 1 + + "0000000000c05e40" // value = 123.0 + + "b20d" // tag = 214, type = 2 + + "03" // length = 3 + + "313234" // value = "124" + + "b20d" // tag = 214, type = 2 + + "03" // length = 3 + + "313234" // value = "124" + + "ba0d" // tag = 215, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "ba0d" // tag = 215, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "c00d" // tag = 216, type = 0 + + "01" // value = 1 + + "c00d" // tag = 216, type = 0 + + "01" // value = 1 + + "ca0d" // tag = 217, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 + + "ca0d" // tag = 217, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 - // packed + // packed - + "ea12" // tag = 301, type = 2 - + "02" // length = 2 - + "6f" // value = 111 - + "6f" // value = 111 - + "f212" // tag = 302, type = 2 - + "02" // length = 2 - + "70" // value = 112 - + "70" // value = 112 - + "fa12" // tag = 303, type = 2 - + "04" // length = 4 - + "e201" // value = 226 (=113 zig-zag) - + "e201" // value = 226 (=113 zig-zag) - + "8213" // tag = 304, type = 2 - + "08" // length = 8 - + "72000000" // value = 114 (fixed32) - + "72000000" // value = 114 (fixed32) - + "8a13" // tag = 305, type = 2 - + "08" // length = 8 - + "73000000" // value = 115 (sfixed32) - + "73000000" // value = 115 (sfixed32) - + "9213" // tag = 306, type = 2 - + "02" // length = 2 - + "74" // value = 116 - + "74" // value = 116 - + "9a13" // tag = 307, type = 2 - + "02" // length = 2 - + "75" // value = 117 - + "75" // value = 117 - + "a213" // tag = 308, type = 2 - + "04" // length = 4 - + "ec01" // value = 236 (=118 zigzag) - + "ec01" // value = 236 (=118 zigzag) - + "aa13" // tag = 309, type = 2 - + "10" // length = 16 - + "7700000000000000" // value = 119 - + "7700000000000000" // value = 119 - + "b213" // tag = 310, type = 2 - + "10" // length = 16 - + "7800000000000000" // value = 120 - + "7800000000000000" // value = 120 - + "ba13" // tag = 311, type = 2 - + "02" // length = 2 - + "01" // value = 1 (true) - + "01" // value = 1 (true) - + "c213" // tag = 312, type = 2 - + "08" // length = 8 - + "0000f442" // value = 122.0F - + "0000f442" // value = 122.0F - + "ca13" // tag = 313, type = 2 - + "10" // length = 16 - + "0000000000c05e40" // value = 123.0 - + "0000000000c05e40" // value = 123.0 - + "e213" // tag = 316, type = 2 - + "02" // length = 2 - + "01" // value = 1 - + "01" // value = 1 + + "ea12" // tag = 301, type = 2 + + "02" // length = 2 + + "6f" // value = 111 + + "6f" // value = 111 + + "f212" // tag = 302, type = 2 + + "02" // length = 2 + + "70" // value = 112 + + "70" // value = 112 + + "fa12" // tag = 303, type = 2 + + "04" // length = 4 + + "e201" // value = 226 (=113 zig-zag) + + "e201" // value = 226 (=113 zig-zag) + + "8213" // tag = 304, type = 2 + + "08" // length = 8 + + "72000000" // value = 114 (fixed32) + + "72000000" // value = 114 (fixed32) + + "8a13" // tag = 305, type = 2 + + "08" // length = 8 + + "73000000" // value = 115 (sfixed32) + + "73000000" // value = 115 (sfixed32) + + "9213" // tag = 306, type = 2 + + "02" // length = 2 + + "74" // value = 116 + + "74" // value = 116 + + "9a13" // tag = 307, type = 2 + + "02" // length = 2 + + "75" // value = 117 + + "75" // value = 117 + + "a213" // tag = 308, type = 2 + + "04" // length = 4 + + "ec01" // value = 236 (=118 zigzag) + + "ec01" // value = 236 (=118 zigzag) + + "aa13" // tag = 309, type = 2 + + "10" // length = 16 + + "7700000000000000" // value = 119 + + "7700000000000000" // value = 119 + + "b213" // tag = 310, type = 2 + + "10" // length = 16 + + "7800000000000000" // value = 120 + + "7800000000000000" // value = 120 + + "ba13" // tag = 311, type = 2 + + "02" // length = 2 + + "01" // value = 1 (true) + + "01" // value = 1 (true) + + "c213" // tag = 312, type = 2 + + "08" // length = 8 + + "0000f442" // value = 122.0F + + "0000f442" // value = 122.0F + + "ca13" // tag = 313, type = 2 + + "10" // length = 16 + + "0000000000c05e40" // value = 123.0 + + "0000000000c05e40" // value = 123.0 + + "e213" // tag = 316, type = 2 + + "02" // length = 2 + + "01" // value = 1 + + "01" // value = 1 - // extensions + // extensions - + "983f" // tag = 1011, type = 0 - + "01" // value = 1 (true) - + "b845" // tag = 1111, type = 0 - + "01" // value = 1 (true) - + "b845" // tag = 1111, type = 0 - + "01" // value = 1 (true) - + "da4b" // tag = 1211, type = 2 - + "02" // length = 2 - + "01" // value = 1 (true) - + "01"); // value = 1 (true) + + "983f" // tag = 1011, type = 0 + + "01" // value = 1 (true) + + "b845" // tag = 1111, type = 0 + + "01" // value = 1 (true) + + "b845" // tag = 1111, type = 0 + + "01" // value = 1 (true) + + "da4b" // tag = 1211, type = 2 + + "02" // length = 2 + + "01" // value = 1 (true) + + "01"); // value = 1 (true) // message with 'packed' fields stored non-packed, must still be readable - public static final ByteString nonPacked = ByteString.decodeHex("" - // optional + public static final ByteString nonPacked = + ByteString.decodeHex( + "" + // optional - + "08" // tag = 1, type = 0 - + "6f" // value = 111 - + "10" // tag = 2, type = 0 - + "70" // value = 112 - + "18" // tag = 3, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "25" // tag = 4, type = 5 - + "72000000" // value = 114 (fixed32) - + "2d" // tag = 5, type = 5 - + "73000000" // value = 115 (sfixed32) - + "30" // tag = 6, type = 0 - + "74" // value = 116 - + "38" // tag = 7, type = 0 - + "75" // value = 117 - + "40" // tag = 8, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "49" // tag = 9, type = 1 - + "7700000000000000" // value = 119 - + "51" // tag = 10, type = 1 - + "7800000000000000" // value = 120 - + "58" // tag = 11, type = 0 - + "01" // value = 1 (true) - + "65" // tag = 12, type = 5 - + "0000f442" // value = 122.0F - + "69" // tag = 13, type = 1 - + "0000000000c05e40" // value = 123.0 - + "72" // tag = 14, type = 2 - + "03" // length = 3 - + "313234" - + "7a" // tag = 15, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "8001" // tag = 16, type = 0 - + "01" // value = 1 - + "8a01" // tag = 17, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 + + "08" // tag = 1, type = 0 + + "6f" // value = 111 + + "10" // tag = 2, type = 0 + + "70" // value = 112 + + "18" // tag = 3, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "25" // tag = 4, type = 5 + + "72000000" // value = 114 (fixed32) + + "2d" // tag = 5, type = 5 + + "73000000" // value = 115 (sfixed32) + + "30" // tag = 6, type = 0 + + "74" // value = 116 + + "38" // tag = 7, type = 0 + + "75" // value = 117 + + "40" // tag = 8, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "49" // tag = 9, type = 1 + + "7700000000000000" // value = 119 + + "51" // tag = 10, type = 1 + + "7800000000000000" // value = 120 + + "58" // tag = 11, type = 0 + + "01" // value = 1 (true) + + "65" // tag = 12, type = 5 + + "0000f442" // value = 122.0F + + "69" // tag = 13, type = 1 + + "0000000000c05e40" // value = 123.0 + + "72" // tag = 14, type = 2 + + "03" // length = 3 + + "313234" + + "7a" // tag = 15, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "8001" // tag = 16, type = 0 + + "01" // value = 1 + + "8a01" // tag = 17, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 - // required + // required - + "a806" // tag = 101, type = 0 - + "6f" // value = 111 - + "b006" // tag = 102, type = 0 - + "70" // value = 112 - + "b806" // tag = 103, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "c506" // tag = 104, type = 5 - + "72000000" // value = 114 (fixed32) - + "cd06" // tag = 105, type = 5 - + "73000000" // value = 115 (sfixed32) - + "d006" // tag = 106, type = 0 - + "74" // value = 116 - + "d806" // tag = 107, type = 0 - + "75" // value = 117 - + "e006" // tag = 108, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "e906" // tag = 109, type = 1 - + "7700000000000000" // value = 119 - + "f106" // tag = 110, type = 1 - + "7800000000000000" // value = 120 - + "f806" // tag = 111, type = 0 - + "01" // value = 1 (true) - + "8507" // tag = 112, type = 5 - + "0000f442" // value = 122.0F - + "8907" // tag = 113, type = 1 - + "0000000000c05e40" // value = 123.0 - + "9207" // tag = 114, type = 2 - + "03" // length = 3 - + "313234" // value = "124" - + "9a07" // tag = 115, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "a007" // tag = 116, type = 0 - + "01" // value = 1 - + "aa07" // tag = 117, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 + + "a806" // tag = 101, type = 0 + + "6f" // value = 111 + + "b006" // tag = 102, type = 0 + + "70" // value = 112 + + "b806" // tag = 103, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "c506" // tag = 104, type = 5 + + "72000000" // value = 114 (fixed32) + + "cd06" // tag = 105, type = 5 + + "73000000" // value = 115 (sfixed32) + + "d006" // tag = 106, type = 0 + + "74" // value = 116 + + "d806" // tag = 107, type = 0 + + "75" // value = 117 + + "e006" // tag = 108, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "e906" // tag = 109, type = 1 + + "7700000000000000" // value = 119 + + "f106" // tag = 110, type = 1 + + "7800000000000000" // value = 120 + + "f806" // tag = 111, type = 0 + + "01" // value = 1 (true) + + "8507" // tag = 112, type = 5 + + "0000f442" // value = 122.0F + + "8907" // tag = 113, type = 1 + + "0000000000c05e40" // value = 123.0 + + "9207" // tag = 114, type = 2 + + "03" // length = 3 + + "313234" // value = "124" + + "9a07" // tag = 115, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "a007" // tag = 116, type = 0 + + "01" // value = 1 + + "aa07" // tag = 117, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 - // repeated + // repeated - + "c80c"// tag = 201, type = 0 - + "6f" // value = 111 - + "c80c" // tag = 201, type = 0 - + "6f" // value = 111 - + "d00c" // tag = 202, type = 0 - + "70" // value = 112 - + "d00c" // tag = 202, type = 0 - + "70" // value = 112 - + "d80c" // tag = 203, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "d80c" // tag = 203, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "e50c" // tag = 204, type = 5 - + "72000000" // value = 114 (fixed32) - + "e50c" // tag = 204, type = 5 - + "72000000" // value = 114 (fixed32) - + "ed0c" // tag = 205, type = 5 - + "73000000" // value = 115 (sfixed32) - + "ed0c" // tag = 205, type = 5 - + "73000000" // value = 115 (sfixed32) - + "f00c" // tag = 206, type = 0 - + "74" // value = 116 - + "f00c" // tag = 206, type = 0 - + "74" // value = 116 - + "f80c" // tag = 207, type = 0 - + "75" // value = 117 - + "f80c" // tag = 207, type = 0 - + "75" // value = 117 - + "800d" // tag = 208, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "800d" // tag = 208, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "890d" // tag = 209, type = 1 - + "7700000000000000" // value = 119 - + "890d" // tag = 209, type = 1 - + "7700000000000000" // value = 119 - + "910d" // tag = 210, type = 1 - + "7800000000000000" // value = 120 - + "910d" // tag = 210, type = 1 - + "7800000000000000" // value = 120 - + "980d" // tag = 211, type = 0 - + "01" // value = 1 (true) - + "980d" // tag = 211, type = 0 - + "01" // value = 1 (true) - + "a50d" // tag = 212, type = 5 - + "0000f442" // value = 122.0F - + "a50d" // tag = 212, type = 5 - + "0000f442" // value = 122.0F - + "a90d" // tag = 213, type = 1 - + "0000000000c05e40" // value = 123.0 - + "a90d" // tag = 213, type = 1 - + "0000000000c05e40" // value = 123.0 - + "b20d" // tag = 214, type = 2 - + "03" // length = 3 - + "313234" // value = "124" - + "b20d" // tag = 214, type = 2 - + "03" // length = 3 - + "313234" // value = "124" - + "ba0d" // tag = 215, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "ba0d" // tag = 215, type = 2 - + "02" // length = 2 - + "7de1" // value = { 125, 225 } - + "c00d" // tag = 216, type = 0 - + "01" // value = 1 - + "c00d" // tag = 216, type = 0 - + "01" // value = 1 - + "ca0d" // tag = 217, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 - + "ca0d" // tag = 217, type = 2 - + "03" // length = 3 - + "08" // nested tag = 1, type = 0 - + "e707" // value = 999 + + "c80c" // tag = 201, type = 0 + + "6f" // value = 111 + + "c80c" // tag = 201, type = 0 + + "6f" // value = 111 + + "d00c" // tag = 202, type = 0 + + "70" // value = 112 + + "d00c" // tag = 202, type = 0 + + "70" // value = 112 + + "d80c" // tag = 203, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "d80c" // tag = 203, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "e50c" // tag = 204, type = 5 + + "72000000" // value = 114 (fixed32) + + "e50c" // tag = 204, type = 5 + + "72000000" // value = 114 (fixed32) + + "ed0c" // tag = 205, type = 5 + + "73000000" // value = 115 (sfixed32) + + "ed0c" // tag = 205, type = 5 + + "73000000" // value = 115 (sfixed32) + + "f00c" // tag = 206, type = 0 + + "74" // value = 116 + + "f00c" // tag = 206, type = 0 + + "74" // value = 116 + + "f80c" // tag = 207, type = 0 + + "75" // value = 117 + + "f80c" // tag = 207, type = 0 + + "75" // value = 117 + + "800d" // tag = 208, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "800d" // tag = 208, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "890d" // tag = 209, type = 1 + + "7700000000000000" // value = 119 + + "890d" // tag = 209, type = 1 + + "7700000000000000" // value = 119 + + "910d" // tag = 210, type = 1 + + "7800000000000000" // value = 120 + + "910d" // tag = 210, type = 1 + + "7800000000000000" // value = 120 + + "980d" // tag = 211, type = 0 + + "01" // value = 1 (true) + + "980d" // tag = 211, type = 0 + + "01" // value = 1 (true) + + "a50d" // tag = 212, type = 5 + + "0000f442" // value = 122.0F + + "a50d" // tag = 212, type = 5 + + "0000f442" // value = 122.0F + + "a90d" // tag = 213, type = 1 + + "0000000000c05e40" // value = 123.0 + + "a90d" // tag = 213, type = 1 + + "0000000000c05e40" // value = 123.0 + + "b20d" // tag = 214, type = 2 + + "03" // length = 3 + + "313234" // value = "124" + + "b20d" // tag = 214, type = 2 + + "03" // length = 3 + + "313234" // value = "124" + + "ba0d" // tag = 215, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "ba0d" // tag = 215, type = 2 + + "02" // length = 2 + + "7de1" // value = { 125, 225 } + + "c00d" // tag = 216, type = 0 + + "01" // value = 1 + + "c00d" // tag = 216, type = 0 + + "01" // value = 1 + + "ca0d" // tag = 217, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 + + "ca0d" // tag = 217, type = 2 + + "03" // length = 3 + + "08" // nested tag = 1, type = 0 + + "e707" // value = 999 - // packed + // packed - + "e812" // tag = 301, type = 0 - + "6f" // value = 111 - + "e812" // tag = 301, type = 0 - + "6f" // value = 111 - + "f012" // tag = 302, type = 0 - + "70" // value = 112 - + "f012" // tag = 302, type = 0 - + "70" // value = 112 - + "f812" // tag = 303, type = 0 - + "e201" // value = 226 (=113 zig-zag) - + "f812" // tag = 303, type = - - + "e201" // value = 226 (=113 zig-zag) - + "8513" // tag = 304, type = 5 - + "72000000" // value = 114 (fixed32) - + "8513" // tag = 304, type = 5 - + "72000000" // value = 114 (fixed32) - + "8d13" // tag = 305, type = 5 - + "73000000" // value = 115 (sfixed32) - + "8d13" // tag = 305, type = 5 - + "73000000" // value = 115 (sfixed32) - + "9013" // tag = 306, type = 0 - + "74" // value = 116 - + "9013" // tag = 306, type = 0 - + "74" // value = 116 - + "9813" // tag = 307, type = 0 - + "75" // value = 117 - + "9813" // tag = 307, type = 0 - + "75" // value = 117 - + "a013" // tag = 308, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "a013" // tag = 308, type = 0 - + "ec01" // value = 236 (=118 zigzag) - + "a913" // tag = 309, type = 0 - + "7700000000000000" // value = 119 - + "a913" // tag = 309, type = 0 - + "7700000000000000" // value = 119 - + "b113" // tag = 310, type = 0 - + "7800000000000000" // value = 120 - + "b113" // tag = 310, type = 0 - + "7800000000000000" // value = 120 - + "b813" // tag = 311, type = 0 - + "01" // value = 1 (true) - + "b813" // tag = 311, type = 0 - + "01" // value = 1 (true) - + "c513" // tag = 312, type = 0 - + "0000f442" // value = 122.0F - + "c513" // tag = 312, type = 0 - + "0000f442" // value = 122.0F - + "c913" // tag = 313, type = 0 - + "0000000000c05e40" // value = 123.0 - + "c913" // tag = 313, type = 0 - + "0000000000c05e40" // value = 123.0 - + "e013" // tag = 316, type = 0 - + "01" // value = 1 - + "e013" // tag = 316, type = 0 - + "01" // value = 1 + + "e812" // tag = 301, type = 0 + + "6f" // value = 111 + + "e812" // tag = 301, type = 0 + + "6f" // value = 111 + + "f012" // tag = 302, type = 0 + + "70" // value = 112 + + "f012" // tag = 302, type = 0 + + "70" // value = 112 + + "f812" // tag = 303, type = 0 + + "e201" // value = 226 (=113 zig-zag) + + "f812" // tag = 303, type = - + + "e201" // value = 226 (=113 zig-zag) + + "8513" // tag = 304, type = 5 + + "72000000" // value = 114 (fixed32) + + "8513" // tag = 304, type = 5 + + "72000000" // value = 114 (fixed32) + + "8d13" // tag = 305, type = 5 + + "73000000" // value = 115 (sfixed32) + + "8d13" // tag = 305, type = 5 + + "73000000" // value = 115 (sfixed32) + + "9013" // tag = 306, type = 0 + + "74" // value = 116 + + "9013" // tag = 306, type = 0 + + "74" // value = 116 + + "9813" // tag = 307, type = 0 + + "75" // value = 117 + + "9813" // tag = 307, type = 0 + + "75" // value = 117 + + "a013" // tag = 308, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "a013" // tag = 308, type = 0 + + "ec01" // value = 236 (=118 zigzag) + + "a913" // tag = 309, type = 0 + + "7700000000000000" // value = 119 + + "a913" // tag = 309, type = 0 + + "7700000000000000" // value = 119 + + "b113" // tag = 310, type = 0 + + "7800000000000000" // value = 120 + + "b113" // tag = 310, type = 0 + + "7800000000000000" // value = 120 + + "b813" // tag = 311, type = 0 + + "01" // value = 1 (true) + + "b813" // tag = 311, type = 0 + + "01" // value = 1 (true) + + "c513" // tag = 312, type = 0 + + "0000f442" // value = 122.0F + + "c513" // tag = 312, type = 0 + + "0000f442" // value = 122.0F + + "c913" // tag = 313, type = 0 + + "0000000000c05e40" // value = 123.0 + + "c913" // tag = 313, type = 0 + + "0000000000c05e40" // value = 123.0 + + "e013" // tag = 316, type = 0 + + "01" // value = 1 + + "e013" // tag = 316, type = 0 + + "01" // value = 1 - // extension + // extension - + "983f" // tag = 1011, type = 0 - + "01" // value = 1 (true) - + "b845" // tag = 1111, type = 0 - + "01" // value = 1 (true) - + "b845" // tag = 1111, type = 0 - + "01" // value = 1 (true) - + "d84b" // tag = 1211, type = 0 - + "01" // value = 1 (true) - + "d84b" // tag = 1211, type = 0 - + "01"); // value = 1 (true) + + "983f" // tag = 1011, type = 0 + + "01" // value = 1 (true) + + "b845" // tag = 1111, type = 0 + + "01" // value = 1 (true) + + "b845" // tag = 1111, type = 0 + + "01" // value = 1 (true) + + "d84b" // tag = 1211, type = 0 + + "01" // value = 1 (true) + + "d84b" // tag = 1211, type = 0 + + "01"); // value = 1 (true) } diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/UnknownFieldsTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/UnknownFieldsTest.java index e2648ad7c4..b7783fb4f7 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/UnknownFieldsTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/UnknownFieldsTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,8 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; + import com.squareup.wire.protos.unknownfields.EnumVersionTwo; import com.squareup.wire.protos.unknownfields.NestedVersionOne; import com.squareup.wire.protos.unknownfields.NestedVersionTwo; @@ -25,8 +27,6 @@ import okio.ByteString; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class UnknownFieldsTest { private final ProtoAdapter v1Adapter = VersionOne.ADAPTER; @@ -34,27 +34,27 @@ public class UnknownFieldsTest { @Test public void testUnknownFields() throws IOException { - NestedVersionOne v1_obj = new NestedVersionOne.Builder() - .i(111) - .build(); - NestedVersionTwo v2_obj = new NestedVersionTwo.Builder() - .i(111) - .v2_i(12345) - .v2_s("222") - .v2_f32(67890) - .v2_f64(98765L) - .v2_rs(Arrays.asList("1", "2")) - .build(); - - VersionTwo v2 = new VersionTwo.Builder() - .i(111) - .v2_i(12345) - .v2_s("222") - .v2_f32(67890) - .v2_f64(98765L) - .v2_rs(Arrays.asList("1", "2")) - .obj(v2_obj) - .build(); + NestedVersionOne v1_obj = new NestedVersionOne.Builder().i(111).build(); + NestedVersionTwo v2_obj = + new NestedVersionTwo.Builder() + .i(111) + .v2_i(12345) + .v2_s("222") + .v2_f32(67890) + .v2_f64(98765L) + .v2_rs(Arrays.asList("1", "2")) + .build(); + + VersionTwo v2 = + new VersionTwo.Builder() + .i(111) + .v2_i(12345) + .v2_s("222") + .v2_f32(67890) + .v2_f64(98765L) + .v2_rs(Arrays.asList("1", "2")) + .obj(v2_obj) + .build(); assertThat(v2.i).isEqualTo(new Integer(111)); assertThat(v2.obj).isEqualTo(v2_obj.newBuilder().build()); // Check v.2 fields @@ -81,11 +81,8 @@ public void testUnknownFields() throws IOException { assertThat(v1Adapter.encode(v1)).isNotEqualTo(v1Adapter.encode(v1Simple)); // Unknown fields can be removed for equals() and hashCode(); - VersionOne v1Known = v1 - .withoutUnknownFields() - .newBuilder() - .obj(v1.obj.withoutUnknownFields()) - .build(); + VersionOne v1Known = + v1.withoutUnknownFields().newBuilder().obj(v1.obj.withoutUnknownFields()).build(); assertThat(v1Known).isEqualTo(v1Simple); assertThat(v1Known.hashCode()).isEqualTo(v1Simple.hashCode()); assertThat(v1Adapter.encode(v1Known)).isEqualTo(v1Adapter.encode(v1Simple)); @@ -101,10 +98,7 @@ public void testUnknownFields() throws IOException { assertThat(v2B.obj).isEqualTo(v2_obj); // "Modify" v1 via a merged builder, serialize, and re-parse - VersionOne v1Modified = v1.newBuilder() - .i(777) - .obj(v1_obj.newBuilder().i(777).build()) - .build(); + VersionOne v1Modified = v1.newBuilder().i(777).obj(v1_obj.newBuilder().i(777).build()).build(); assertThat(v1Modified.i).isEqualTo(new Integer(777)); assertThat(v1Modified.obj).isEqualTo(v1_obj.newBuilder().i(777).build()); byte[] v1ModifiedBytes = v1Adapter.encode(v1Modified); @@ -115,26 +109,25 @@ public void testUnknownFields() throws IOException { assertThat(v2C.v2_s).isEqualTo("222"); assertThat(v2C.v2_f32).isEqualTo(new Integer(67890)); assertThat(v2C.v2_f64).isEqualTo(new Long(98765L)); - assertThat(v2C.obj).isEqualTo(new NestedVersionTwo.Builder() - .i(777) - .build()); + assertThat(v2C.obj).isEqualTo(new NestedVersionTwo.Builder().i(777).build()); assertThat(v2C.v2_rs).containsExactly("1", "2"); } @Test public void repeatedCallsToBuildRetainUnknownFields() throws IOException { - VersionTwo v2 = new VersionTwo.Builder() - .i(111) - .v2_i(12345) - .v2_s("222") - .v2_f32(67890) - .v2_f64(98765L) - .v2_rs(Arrays.asList("1", "2")) - .build(); + VersionTwo v2 = + new VersionTwo.Builder() + .i(111) + .v2_i(12345) + .v2_s("222") + .v2_f32(67890) + .v2_f64(98765L) + .v2_rs(Arrays.asList("1", "2")) + .build(); // Serializes v2 and decodes it as a VersionOne. byte[] v2Bytes = v2Adapter.encode(v2); - VersionOne.Builder v1Builder = v1Adapter.decode(v2Bytes).newBuilder(); + VersionOne.Builder v1Builder = v1Adapter.decode(v2Bytes).newBuilder(); // Builds v1Builder. It should equal to v2. VersionOne v1A = v1Builder.build(); @@ -149,26 +142,13 @@ public void repeatedCallsToBuildRetainUnknownFields() throws IOException { @Test public void unknownFieldsCanBeAddedBetweenCallsToBuild() throws IOException { - VersionTwo v2A = new VersionTwo.Builder() - .i(111) - .v2_i(12345) - .v2_s("222") - .v2_f32(67890) - .build(); - VersionTwo v2B = new VersionTwo.Builder() - .v2_f64(98765L) - .build(); - VersionTwo v2C = new VersionTwo.Builder() - .v2_rs(Arrays.asList("1", "2")) - .build(); + VersionTwo v2A = new VersionTwo.Builder().i(111).v2_i(12345).v2_s("222").v2_f32(67890).build(); + VersionTwo v2B = new VersionTwo.Builder().v2_f64(98765L).build(); + VersionTwo v2C = new VersionTwo.Builder().v2_rs(Arrays.asList("1", "2")).build(); // A combination of v1A and v1B. - VersionTwo v2AB = v2A.newBuilder() - .v2_f64(v2B.v2_f64) - .build(); + VersionTwo v2AB = v2A.newBuilder().v2_f64(v2B.v2_f64).build(); // A combination of v1A, v1B and v1C. - VersionTwo v2All = v2AB.newBuilder() - .v2_rs(v2C.v2_rs) - .build(); + VersionTwo v2All = v2AB.newBuilder().v2_rs(v2C.v2_rs).build(); // Serializes v2A and decodes it as a VersionOne. byte[] v2ABytes = v2Adapter.encode(v2A); @@ -208,14 +188,15 @@ public void unknownFieldsCanBeAddedBetweenCallsToBuild() throws IOException { @Test public void unknownFieldsCanBeAddedAfterClearingUnknownFields() throws IOException { - VersionTwo v2 = new VersionTwo.Builder() - .i(111) - .v2_i(12345) - .v2_s("222") - .v2_f32(67890) - .v2_f64(98765L) - .v2_rs(Arrays.asList("1", "2")) - .build(); + VersionTwo v2 = + new VersionTwo.Builder() + .i(111) + .v2_i(12345) + .v2_s("222") + .v2_f32(67890) + .v2_f64(98765L) + .v2_rs(Arrays.asList("1", "2")) + .build(); // Serializes v2 and decodes it as a VersionOne. byte[] v2Bytes = v2Adapter.encode(v2); @@ -233,31 +214,24 @@ public void unknownFieldsCanBeAddedAfterClearingUnknownFields() throws IOExcepti @Test public void addedUnknownFieldsCanBeClearedFromBuilder() throws IOException { - VersionTwo v2 = new VersionTwo.Builder() - .i(111) - .v2_i(12345) - .v2_s("222") - .v2_f32(67890) - .build(); + VersionTwo v2 = new VersionTwo.Builder().i(111).v2_i(12345).v2_s("222").v2_f32(67890).build(); // Serializes v2 and decodes it as a VersionOne. byte[] v2Bytes = v2Adapter.encode(v2); VersionOne fromV2 = v1Adapter.decode(v2Bytes); // Adds unknown fields to an empty builder and clears them again. - VersionOne emptyV1 = new VersionOne.Builder() - .addUnknownFields(fromV2.unknownFields()) - .clearUnknownFields() - .build(); + VersionOne emptyV1 = + new VersionOne.Builder() + .addUnknownFields(fromV2.unknownFields()) + .clearUnknownFields() + .build(); assertThat(emptyV1.unknownFields()).isEqualTo(ByteString.EMPTY); } @Test public void unknownEnumFields() throws IOException { - VersionTwo v2 = new VersionTwo.Builder() - .en(EnumVersionTwo.PUSS_IN_BOOTS_V2) - .i(100) - .build(); + VersionTwo v2 = new VersionTwo.Builder().en(EnumVersionTwo.PUSS_IN_BOOTS_V2).i(100).build(); byte[] v2Serialized = VersionTwo.ADAPTER.encode(v2); VersionOne v1 = VersionOne.ADAPTER.decode(v2Serialized); assertThat(v1.i).isEqualTo(100); diff --git a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/WireTest.java b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/WireTest.java index 13f0dfebe1..f5a6e01a72 100644 --- a/wire-tests/src/jvmJavaTest/java/com/squareup/wire/WireTest.java +++ b/wire-tests/src/jvmJavaTest/java/com/squareup/wire/WireTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,10 @@ */ package com.squareup.wire; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; + import com.squareup.wire.protos.custom_options.FooBar; import com.squareup.wire.protos.custom_options.MessageWithOptions; import com.squareup.wire.protos.custom_options.MyFieldOptionOneOption; @@ -37,13 +41,7 @@ import okio.ByteString; import org.junit.Test; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.fail; - -/** - * Test Wire runtime. - */ +/** Test Wire runtime. */ public class WireTest { @Test @@ -63,8 +61,7 @@ public void testSimpleMessage() throws Exception { new SimpleMessage.NestedMessage.Builder(); nested_msg_builder.bb(2); builder.optional_nested_msg(nested_msg_builder.build()); - ExternalMessage.Builder external_msg_builder = - new ExternalMessage.Builder(); + ExternalMessage.Builder external_msg_builder = new ExternalMessage.Builder(); external_msg_builder.f(99.9f); builder.optional_external_msg(external_msg_builder.build()); builder.default_nested_enum(SimpleMessage.NestedEnum.BAR); @@ -121,34 +118,38 @@ public void testSimpleMessage() throws Exception { assertThat(msg.repeated_double).isEqualTo(doubles); } - @Test public void mutateBuilder() throws Exception { - SimpleMessage message = new SimpleMessage.Builder() - .required_int32(10) - .build(); + @Test + public void mutateBuilder() throws Exception { + SimpleMessage message = new SimpleMessage.Builder().required_int32(10).build(); SimpleMessage.Builder builder = message.newBuilder(); builder.required_int32 = 20; builder.repeated_double.add(30.5); builder.optional_int32 = 40; - assertThat(builder.build()).isEqualTo(new SimpleMessage.Builder() - .required_int32(20) - .repeated_double(Arrays.asList(30.5)) - .optional_int32(40) - .build()); + assertThat(builder.build()) + .isEqualTo( + new SimpleMessage.Builder() + .required_int32(20) + .repeated_double(Arrays.asList(30.5)) + .optional_int32(40) + .build()); } @Test public void testPerson() throws IOException { - Person person = new Person.Builder() - .name("Omar") - .id(1234) - .email("omar@wire.com") - .phone(Arrays.asList(new PhoneNumber.Builder() - .number("410-555-0909") - .type(PhoneType.MOBILE) - .build())) - .build(); + Person person = + new Person.Builder() + .name("Omar") + .id(1234) + .email("omar@wire.com") + .phone( + Arrays.asList( + new PhoneNumber.Builder() + .number("410-555-0909") + .type(PhoneType.MOBILE) + .build())) + .build(); ProtoAdapter adapter = Person.ADAPTER; @@ -158,24 +159,25 @@ public void testPerson() throws IOException { @Test public void testExtensions() throws Exception { - ExternalMessage optional_external_msg = new ExternalMessage.Builder() - .fooext(Arrays.asList(444, 555)) - .barext(333) - .bazext(222) - .nested_message_ext(new SimpleMessage.NestedMessage.Builder().bb(77).build()) - .nested_enum_ext(SimpleMessage.NestedEnum.BAZ) - .build(); - - SimpleMessage msg = new SimpleMessage.Builder() - .optional_external_msg(optional_external_msg) - .required_int32(456) - .build(); + ExternalMessage optional_external_msg = + new ExternalMessage.Builder() + .fooext(Arrays.asList(444, 555)) + .barext(333) + .bazext(222) + .nested_message_ext(new SimpleMessage.NestedMessage.Builder().bb(77).build()) + .nested_enum_ext(SimpleMessage.NestedEnum.BAZ) + .build(); + + SimpleMessage msg = + new SimpleMessage.Builder() + .optional_external_msg(optional_external_msg) + .required_int32(456) + .build(); assertThat(msg.optional_external_msg.fooext).containsExactly(444, 555); assertThat(msg.optional_external_msg.barext).isEqualTo(new Integer(333)); assertThat(msg.optional_external_msg.bazext).isEqualTo(new Integer(222)); - assertThat(msg.optional_external_msg.nested_message_ext.bb) - .isEqualTo(new Integer(77)); + assertThat(msg.optional_external_msg.nested_message_ext.bb).isEqualTo(new Integer(77)); assertThat(msg.optional_external_msg.nested_enum_ext).isEqualTo(SimpleMessage.NestedEnum.BAZ); ProtoAdapter adapter = SimpleMessage.ADAPTER; @@ -191,14 +193,14 @@ public void testExtensions() throws Exception { @Test public void testExtensionEnum() throws Exception { - ExternalMessage optional_external_msg = new ExternalMessage.Builder() - .nested_enum_ext(SimpleMessage.NestedEnum.BAZ) - .build(); + ExternalMessage optional_external_msg = + new ExternalMessage.Builder().nested_enum_ext(SimpleMessage.NestedEnum.BAZ).build(); - SimpleMessage msg = new SimpleMessage.Builder() - .optional_external_msg(optional_external_msg) - .required_int32(456) - .build(); + SimpleMessage msg = + new SimpleMessage.Builder() + .optional_external_msg(optional_external_msg) + .required_int32(456) + .build(); ProtoAdapter adapter = SimpleMessage.ADAPTER; @@ -213,8 +215,8 @@ public void testExtensionEnum() throws Exception { // Original value shows up as an extension. assertThat(msg.toString()).contains("nested_enum_ext=BAZ"); // New value is unknown in the tag map. - ProtoReader reader = new ProtoReader(new Buffer().write( - newMsg.optional_external_msg.unknownFields())); + ProtoReader reader = + new ProtoReader(new Buffer().write(newMsg.optional_external_msg.unknownFields())); reader.beginMessage(); assertThat(reader.nextTag()).isEqualTo(129); assertThat(reader.peekFieldEncoding().rawProtoAdapter().decode(reader)).isEqualTo(17L); @@ -233,10 +235,11 @@ public void testExtensionsNoRegistry() throws Exception { .bazext(222) .build(); - SimpleMessage msg = new SimpleMessage.Builder() - .optional_external_msg(optional_external_msg) - .required_int32(456) - .build(); + SimpleMessage msg = + new SimpleMessage.Builder() + .optional_external_msg(optional_external_msg) + .required_int32(456) + .build(); assertThat(msg.optional_external_msg.fooext).containsExactly(444, 555); assertThat(msg.optional_external_msg.barext).isEqualTo(new Integer(333)); @@ -255,13 +258,12 @@ public void testExtensionsNoRegistry() throws Exception { @Test public void testEmptyList() throws IOException { - SimpleMessage noListMessage = new SimpleMessage.Builder() - .required_int32(1) - .build(); - SimpleMessage emptyListMessage = new SimpleMessage.Builder() - .required_int32(1) - .repeated_double(new ArrayList()) - .build(); + SimpleMessage noListMessage = new SimpleMessage.Builder().required_int32(1).build(); + SimpleMessage emptyListMessage = + new SimpleMessage.Builder() + .required_int32(1) + .repeated_double(new ArrayList()) + .build(); assertThat(noListMessage.repeated_double).isNotNull(); assertThat(noListMessage.repeated_double).hasSize(0); @@ -300,12 +302,14 @@ public void testEmptyList() throws IOException { @Test public void testBadEnum() throws IOException { - Person person = new Person.Builder() - .id(1) - .name("Joe Schmoe") - .phone(Arrays.asList( - new PhoneNumber.Builder().number("555-1212").type(PhoneType.WORK).build())) - .build(); + Person person = + new Person.Builder() + .id(1) + .name("Joe Schmoe") + .phone( + Arrays.asList( + new PhoneNumber.Builder().number("555-1212").type(PhoneType.WORK).build())) + .build(); assertThat(person.phone.get(0).type).isEqualTo(PhoneType.WORK); @@ -335,7 +339,8 @@ public void testBadEnum() throws IOException { assertThat(data).isEqualTo(newData); } - @Test public void listMustBeNonNull() { + @Test + public void listMustBeNonNull() { Person.Builder builder = new Person.Builder(); builder.id = 1; builder.name = "Joe Schmoe"; @@ -344,13 +349,15 @@ public void testBadEnum() throws IOException { builder.build(); fail(); } catch (NullPointerException expected) { - assertThat(expected).hasMessage("Parameter specified as non-null is null: " - + "method com.squareup.wire.internal.Internal__InternalKt.immutableCopyOf, parameter list" - ); + assertThat(expected) + .hasMessage( + "Parameter specified as non-null is null: " + + "method com.squareup.wire.internal.Internal__InternalKt.immutableCopyOf, parameter list"); } } - @Test public void listElementsMustBeNonNull() { + @Test + public void listElementsMustBeNonNull() { Person.Builder builder = new Person.Builder(); builder.id = 1; builder.name = "Joe Schmoe"; @@ -363,73 +370,81 @@ public void testBadEnum() throws IOException { } } - @Test public void builderListsAreAlwaysMutable() { + @Test + public void builderListsAreAlwaysMutable() { PhoneNumber phone = new PhoneNumber.Builder().number("555-1212").type(PhoneType.WORK).build(); Person.Builder newBuilder = new Person.Builder(); newBuilder.phone.add(phone); - Person person = new Person.Builder() - .id(1) - .name("Joe Schmoe") - .phone(singletonList(phone)) - .build(); + Person person = + new Person.Builder().id(1).name("Joe Schmoe").phone(singletonList(phone)).build(); Person.Builder copyBuilder = person.newBuilder(); copyBuilder.phone.add(phone); } - @Test public void emptyMessageToString() { + @Test + public void emptyMessageToString() { NoFields empty = new NoFields(); assertThat(empty.toString()).isEqualTo("NoFields{}"); } - @Test public void sanitizedToString() { - Person person = new Person.Builder().id(1).name("Such, I mean it, such [a] {funny} name.") - .phone(singletonList(new PhoneNumber.Builder().number("123,456,789").build())) - .aliases(Arrays.asList("B-lo,ved", "D{esperado}")) - .build(); + @Test + public void sanitizedToString() { + Person person = + new Person.Builder() + .id(1) + .name("Such, I mean it, such [a] {funny} name.") + .phone(singletonList(new PhoneNumber.Builder().number("123,456,789").build())) + .aliases(Arrays.asList("B-lo,ved", "D{esperado}")) + .build(); String printedPerson = person.toString(); - assertThat(printedPerson).isEqualTo( - "Person{" - + "id=1, " - + "name=Such\\, I mean it\\, such \\[a\\] \\{funny\\} name., " - + "phone=[PhoneNumber{number=123\\,456\\,789}], " - + "aliases=[B-lo\\,ved, D\\{esperado\\}]" - + "}"); + assertThat(printedPerson) + .isEqualTo( + "Person{" + + "id=1, " + + "name=Such\\, I mean it\\, such \\[a\\] \\{funny\\} name., " + + "phone=[PhoneNumber{number=123\\,456\\,789}], " + + "aliases=[B-lo\\,ved, D\\{esperado\\}]" + + "}"); } - @Test public void createUseResursiveMapBuilderWithoutCrashing() { - ModelEvaluation model = new ModelEvaluation.Builder() - .name("name") - .score(33.0) - .models(new LinkedHashMap<>()) - .build(); + @Test + public void createUseResursiveMapBuilderWithoutCrashing() { + ModelEvaluation model = + new ModelEvaluation.Builder() + .name("name") + .score(33.0) + .models(new LinkedHashMap<>()) + .build(); assertThat(ModelEvaluation.ADAPTER.encodeByteString(model).hex()) .isEqualTo("0a046e616d65110000000000804040"); } - @Test public void optionsOnMessageType() { - MyMessageOptionTwoOption myMessageOptionTwo - = MessageWithOptions.class.getAnnotation(MyMessageOptionTwoOption.class); + @Test + public void optionsOnMessageType() { + MyMessageOptionTwoOption myMessageOptionTwo = + MessageWithOptions.class.getAnnotation(MyMessageOptionTwoOption.class); assertThat(myMessageOptionTwo.value()).isEqualTo(91011.0f); - MyMessageOptionFourOption myMessageOptionFour - = MessageWithOptions.class.getAnnotation(MyMessageOptionFourOption.class); + MyMessageOptionFourOption myMessageOptionFour = + MessageWithOptions.class.getAnnotation(MyMessageOptionFourOption.class); assertThat(myMessageOptionFour.value()).isEqualTo(FooBar.FooBarBazEnum.FOO); } - @Test public void optionsOnField() throws Exception { - MyFieldOptionOneOption myFieldOptionOne = FooBar.class.getDeclaredField("foo") - .getAnnotation(MyFieldOptionOneOption.class); + @Test + public void optionsOnField() throws Exception { + MyFieldOptionOneOption myFieldOptionOne = + FooBar.class.getDeclaredField("foo").getAnnotation(MyFieldOptionOneOption.class); assertThat(myFieldOptionOne.value()).isEqualTo(17); - MyFieldOptionTwoOption myFieldOptionTwo = FooBar.class.getDeclaredField("bar") - .getAnnotation(MyFieldOptionTwoOption.class); + MyFieldOptionTwoOption myFieldOptionTwo = + FooBar.class.getDeclaredField("bar").getAnnotation(MyFieldOptionTwoOption.class); assertThat(myFieldOptionTwo.value()).isEqualTo(33.5f); - MyFieldOptionThreeOption myFieldOptionThree = FooBar.class.getDeclaredField("baz") - .getAnnotation(MyFieldOptionThreeOption.class); + MyFieldOptionThreeOption myFieldOptionThree = + FooBar.class.getDeclaredField("baz").getAnnotation(MyFieldOptionThreeOption.class); assertThat(myFieldOptionThree.value()).isEqualTo(FooBar.FooBarBazEnum.BAR); } } diff --git a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/AnnotationsTestAgainstJava.kt b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/AnnotationsTestAgainstJava.kt index 9746d89431..0ef470541c 100644 --- a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/AnnotationsTestAgainstJava.kt +++ b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/AnnotationsTestAgainstJava.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire import com.squareup.wire.protos.custom_options.EnumOptionOption diff --git a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterIdentityTest.kt b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterIdentityTest.kt index 57d7c2d93a..ddfb83b4c0 100644 --- a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterIdentityTest.kt +++ b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterIdentityTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,11 +19,11 @@ import com.squareup.wire.FieldEncoding.LENGTH_DELIMITED import com.squareup.wire.protos.person.Person import com.squareup.wire.protos.person.Person.PhoneType import com.squareup.wire.protos.simple.SimpleMessage.NestedEnum -import okio.ByteString -import org.assertj.core.api.Assertions.assertThat import java.lang.reflect.Modifier import kotlin.reflect.KClass import kotlin.test.Test +import okio.ByteString +import org.assertj.core.api.Assertions.assertThat class ProtoAdapterIdentityTest { @Test fun generatedAdaptersHaveNullIdentities() { @@ -108,21 +108,21 @@ class ProtoAdapterIdentityTest { @Test fun runtimeMessageAdaptersHaveNullIdentities() { val protoAdapter = ProtoAdapter.newMessageAdapter( - Person::class.java + Person::class.java, ) assertThat(protoAdapter.identity).isNull() } @Test fun runtimeEnumAdaptersHaveZeroIdentities() { val protoAdapter = ProtoAdapter.newEnumAdapter( - PhoneType::class.java + PhoneType::class.java, ) assertThat(protoAdapter.identity).isEqualTo(PhoneType.MOBILE) // value = 0. } @Test fun runtimeEnumAdaptersHaveNullIdentitiesWhenThereIsNoZero() { val protoAdapter = ProtoAdapter.newEnumAdapter( - NestedEnum::class.java + NestedEnum::class.java, ) assertThat(protoAdapter.identity).isNull() } @@ -161,8 +161,8 @@ class ProtoAdapterIdentityTest { assertThat( ProtoAdapter.newMapAdapter( ProtoAdapter.STRING, - ProtoAdapter.STRING - ).identity + ProtoAdapter.STRING, + ).identity, ) .isEqualTo(mapOf()) } diff --git a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterTypeUrlTest.kt b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterTypeUrlTest.kt index a191db2309..03ae310cbd 100644 --- a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterTypeUrlTest.kt +++ b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/ProtoAdapterTypeUrlTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,11 +17,11 @@ package com.squareup.wire import com.squareup.wire.protos.person.Person import com.squareup.wire.protos.person.Person.PhoneType -import okio.ByteString -import org.assertj.core.api.Assertions.assertThat import java.lang.reflect.Modifier import kotlin.reflect.KClass import kotlin.test.Test +import okio.ByteString +import org.assertj.core.api.Assertions.assertThat class ProtoAdapterTypeUrlTest { @Test fun allBuiltInAdaptersHaveReasonableTypeUrls() { diff --git a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/WireKotlinTest.kt b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/WireKotlinTest.kt index 18e56b268d..c5708ec7fa 100644 --- a/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/WireKotlinTest.kt +++ b/wire-tests/src/jvmJavaTest/kotlin/com/squareup/wire/WireKotlinTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/WireJsonTest.kt b/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/WireJsonTest.kt index 19d0ca13f1..69c0cdf897 100644 --- a/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/WireJsonTest.kt +++ b/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/WireJsonTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,6 +21,10 @@ import com.google.gson.JsonSyntaxException import com.squareup.moshi.JsonDataException import com.squareup.moshi.Moshi import com.squareup.wire.json.assertJsonEquals +import com.squareup.wire.proto2.alltypes.AllTypes as AllTypesProto2 +import com.squareup.wire.proto3.alltypes.AllTypes as AllTypesProto3 +import java.io.File +import java.util.Collections import okio.ByteString import okio.buffer import okio.source @@ -42,10 +46,6 @@ import squareup.proto3.FreeGarlicBreadPromotion import squareup.proto3.MapTypes import squareup.proto3.Pizza import squareup.proto3.PizzaDelivery -import java.io.File -import java.util.Collections -import com.squareup.wire.proto2.alltypes.AllTypes as AllTypesProto2 -import com.squareup.wire.proto3.alltypes.AllTypes as AllTypesProto3 /** * Tests meant to be executed against both Java generated and Kotlin generated code among different @@ -68,7 +68,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllTypesProto2::class.java), - jsonLibrary.toJson(value, AllTypesProto2::class.java) + jsonLibrary.toJson(value, AllTypesProto2::class.java), ) } @@ -76,7 +76,7 @@ class WireJsonTest { val value = allTypesProto2IdentityBuilder().build() assertJsonEquals( ALL_TYPES_IDENTITY_PROTO2_JSON, - jsonLibrary.toJson(value, AllTypesProto2::class.java) + jsonLibrary.toJson(value, AllTypesProto2::class.java), ) } @@ -87,7 +87,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllTypesProto2::class.java), - jsonLibrary.toJson(value, AllTypesProto2::class.java) + jsonLibrary.toJson(value, AllTypesProto2::class.java), ) } @@ -96,8 +96,9 @@ class WireJsonTest { builder.addUnknownField(9000, FieldEncoding.FIXED32, 9000) builder.addUnknownField(9001, FieldEncoding.FIXED64, 9001L) builder.addUnknownField( - 9002, FieldEncoding.LENGTH_DELIMITED, - ByteString.of('9'.toByte(), '0'.toByte(), '0'.toByte(), '2'.toByte()) + 9002, + FieldEncoding.LENGTH_DELIMITED, + ByteString.of('9'.toByte(), '0'.toByte(), '0'.toByte(), '2'.toByte()), ) builder.addUnknownField(9003, FieldEncoding.VARINT, 9003L) @@ -126,21 +127,21 @@ class WireJsonTest { // Encoding. assertThat(jsonLibrary.toJson(nested, NestedCamelCase::class.java)).isEqualTo( - """{"oneInt32":1}""" + """{"oneInt32":1}""", ) // More fields assertThat(jsonLibrary.fromJson("""{"nestedMessage":{"oneInt32":1}}""", CamelCase::class.java)) .isEqualTo( CamelCase.Builder().nested__message(NestedCamelCase.Builder().one_int32(1).build()) - .build() + .build(), ) assertThat( - jsonLibrary.fromJson("""{"nested__message":{"one_int32":1}}""", CamelCase::class.java) + jsonLibrary.fromJson("""{"nested__message":{"one_int32":1}}""", CamelCase::class.java), ) .isEqualTo( CamelCase.Builder().nested__message(NestedCamelCase.Builder().one_int32(1).build()) - .build() + .build(), ) assertThat(jsonLibrary.fromJson("""{"RepInt32":[1, 2]}""", CamelCase::class.java)) .isEqualTo(CamelCase.Builder()._Rep_int32(listOf(1, 2)).build()) @@ -178,7 +179,8 @@ class WireJsonTest { | "1": 2 | } |} - |""".trimMargin() + | + """.trimMargin(), ) // Confirm protoc prints the same. @@ -205,7 +207,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllStructs::class.java), - jsonLibrary.toJson(value, AllStructs::class.java) + jsonLibrary.toJson(value, AllStructs::class.java), ) } @@ -232,7 +234,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllStructs::class.java), - jsonLibrary.toJson(value, AllStructs::class.java) + jsonLibrary.toJson(value, AllStructs::class.java), ) } @@ -255,7 +257,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, PizzaDelivery::class.java), - jsonLibrary.toJson(value, PizzaDelivery::class.java) + jsonLibrary.toJson(value, PizzaDelivery::class.java), ) } @@ -267,14 +269,14 @@ class WireJsonTest { // Moshi. assertThat(expected).hasMessage( "Cannot resolve type: " + - "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion in \$.promotion" + "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion in \$.promotion", ) } catch (expected: JsonSyntaxException) { // Gson. assertThat(expected) .hasMessageContaining( "Cannot resolve type: " + - "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion in \$.promotion" + "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion in \$.promotion", ) } } @@ -284,7 +286,7 @@ class WireJsonTest { .address("507 Cross Street") .pizzas(listOf(Pizza.Builder().toppings(listOf("pineapple", "onion")).build())) .promotion( - AnyMessage.pack(FreeGarlicBreadPromotion.Builder().is_extra_cheesey(true).build()) + AnyMessage.pack(FreeGarlicBreadPromotion.Builder().is_extra_cheesey(true).build()), ) .delivered_within_or_free(durationOfSeconds(1_799L, 500_000_000L)) .loyalty(emptyMap()) @@ -300,14 +302,14 @@ class WireJsonTest { .hasMessage( "Cannot find type for url: " + "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion " + - "in \$.promotion.@type" + "in \$.promotion.@type", ) } catch (expected: JsonIOException) { // Gson. assertThat(expected) .hasMessageContaining( "Cannot find type for url: " + - "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion" + "type.googleapis.com/squareup.proto3.FreeGarlicBreadPromotion", ) } } @@ -378,7 +380,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, All64::class.java), - jsonLibrary.toJson(value, All64::class.java) + jsonLibrary.toJson(value, All64::class.java), ) } @@ -414,7 +416,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, All64::class.java), - jsonLibrary.toJson(value, All64::class.java) + jsonLibrary.toJson(value, All64::class.java), ) } @@ -440,20 +442,20 @@ class WireJsonTest { assertThat( jsonLibrary.fromJson( """{"mySint64":"123", "repSint64": ["456"]}""", - All64::class.java - ) + All64::class.java, + ), ).isEqualTo(signed) assertThat( jsonLibrary.fromJson( """{"mySint64":123, "repSint64": [456]}""", - All64::class.java - ) + All64::class.java, + ), ).isEqualTo(signed) assertThat( jsonLibrary.fromJson( """{"mySint64":123.0, "repSint64": [456.0]}""", - All64::class.java - ) + All64::class.java, + ), ).isEqualTo(signed) val signedJson = jsonLibrary.toJson(signed, All64::class.java) @@ -464,20 +466,20 @@ class WireJsonTest { assertThat( jsonLibrary.fromJson( """{"myUint64":"123", "repUint64": ["456"]}""", - All64::class.java - ) + All64::class.java, + ), ).isEqualTo(unsigned) assertThat( jsonLibrary.fromJson( """{"myUint64":123, "repUint64": [456]}""", - All64::class.java - ) + All64::class.java, + ), ).isEqualTo(unsigned) assertThat( jsonLibrary.fromJson( """{"myUint64":123.0, "repUint64": [456.0]}""", - All64::class.java - ) + All64::class.java, + ), ).isEqualTo(unsigned) val unsignedJson = jsonLibrary.toJson(unsigned, All64::class.java) @@ -490,20 +492,20 @@ class WireJsonTest { assertThat( jsonLibrary.fromJson( """{"mySint32":"-2147483648", "repSint32": ["-2147483648"]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(signed) assertThat( jsonLibrary.fromJson( """{"mySint32":-2147483648, "repSint32": [-2147483648]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(signed) assertThat( jsonLibrary.fromJson( """{"mySint32":-2147483648.0, "repSint32": [-2147483648.0]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(signed) val signedJson = jsonLibrary.toJson(signed, All32::class.java) @@ -515,32 +517,32 @@ class WireJsonTest { assertThat( jsonLibrary.fromJson( """{"myUint32":-2147483648, "repUint32": [-2147483648]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(unsigned) assertThat( jsonLibrary.fromJson( """{"myUint32":-2147483648.0, "repUint32": [-2147483648.0]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(unsigned) assertThat( jsonLibrary.fromJson( """{"myUint32":2147483648.0, "repUint32": [-2147483648.0]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(unsigned) assertThat( jsonLibrary.fromJson( """{"myUint32":2.147483648E9, "repUint32": [2.147483648E9]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(unsigned) assertThat( jsonLibrary.fromJson( """{"myUint32":-2.147483648E9, "repUint32": [-2.147483648E9]}""", - All32::class.java - ) + All32::class.java, + ), ).isEqualTo(unsigned) val unsignedJson = jsonLibrary.toJson(unsigned, All32::class.java) @@ -560,7 +562,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(allTypes.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllTypesProto3::class.java), - jsonLibrary.toJson(allTypes, AllTypesProto3::class.java) + jsonLibrary.toJson(allTypes, AllTypesProto3::class.java), ) } @@ -582,7 +584,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(allTypes.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllTypesProto3::class.java), - jsonLibrary.toJson(allTypes, AllTypesProto3::class.java) + jsonLibrary.toJson(allTypes, AllTypesProto3::class.java), ) } @@ -592,7 +594,7 @@ class WireJsonTest { val value = allTypesExplicitIdentityProto3Builder().build() assertJsonEquals( ALL_TYPES_EXPLICIT_IDENTITY_PROTO3_JSON, - jsonLibrary.toJson(value, AllTypesProto3::class.java) + jsonLibrary.toJson(value, AllTypesProto3::class.java), ) } @@ -601,13 +603,13 @@ class WireJsonTest { val parsed = jsonLibrary.fromJson( ALL_TYPES_EXPLICIT_IDENTITY_PROTO3_JSON, - AllTypesProto3::class.java + AllTypesProto3::class.java, ) assertThat(parsed).isEqualTo(value) assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllTypesProto3::class.java), - jsonLibrary.toJson(value, AllTypesProto3::class.java) + jsonLibrary.toJson(value, AllTypesProto3::class.java), ) } @@ -645,7 +647,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, AllWrappers::class.java), - jsonLibrary.toJson(value, AllWrappers::class.java) + jsonLibrary.toJson(value, AllWrappers::class.java), ) } @@ -655,62 +657,62 @@ class WireJsonTest { .map_int32_int32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .map_sint32_sint32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .map_sfixed32_sfixed32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .map_fixed32_fixed32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .map_uint32_uint32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .map_int64_int64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .map_sfixed64_sfixed64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .map_sint64_sint64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .map_fixed64_fixed64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .map_uint64_uint64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .build() @@ -721,7 +723,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, MapTypes::class.java), - jsonLibrary.toJson(value, MapTypes::class.java) + jsonLibrary.toJson(value, MapTypes::class.java), ) } @@ -757,7 +759,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, All32::class.java), - jsonLibrary.toJson(value, All32::class.java) + jsonLibrary.toJson(value, All32::class.java), ) } @@ -793,7 +795,7 @@ class WireJsonTest { assertThat(parsed.toString()).isEqualTo(value.toString()) assertJsonEquals( jsonLibrary.toJson(parsed, All32::class.java), - jsonLibrary.toJson(value, All32::class.java) + jsonLibrary.toJson(value, All32::class.java), ) } @@ -1151,7 +1153,7 @@ class WireJsonTest { private val moshi = Moshi.Builder() .add( WireJsonAdapterFactory(writeIdentityValues = writeIdentityValues) - .plus(listOf(BuyOneGetOnePromotion.ADAPTER)) + .plus(listOf(BuyOneGetOnePromotion.ADAPTER)), ) .build() @@ -1172,7 +1174,7 @@ class WireJsonTest { private val gson = GsonBuilder() .registerTypeAdapterFactory( WireTypeAdapterFactory(writeIdentityValues = writeIdentityValues) - .plus(listOf(BuyOneGetOnePromotion.ADAPTER)) + .plus(listOf(BuyOneGetOnePromotion.ADAPTER)), ) .disableHtmlEscaping() .create() @@ -1194,7 +1196,7 @@ class WireJsonTest { private val moshi = Moshi.Builder() .add( WireJsonAdapterFactory(writeIdentityValues = writeIdentityValues) - .plus(listOf(BuyOneGetOnePromotion.ADAPTER)) + .plus(listOf(BuyOneGetOnePromotion.ADAPTER)), ) .build() @@ -1215,7 +1217,7 @@ class WireJsonTest { private val gson = GsonBuilder() .registerTypeAdapterFactory( WireTypeAdapterFactory(writeIdentityValues = writeIdentityValues) - .plus(listOf(BuyOneGetOnePromotion.ADAPTER)) + .plus(listOf(BuyOneGetOnePromotion.ADAPTER)), ) .disableHtmlEscaping() .create() diff --git a/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/DurationJsonFormatterTest.kt b/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/DurationJsonFormatterTest.kt index aa7cab4684..10afa58953 100644 --- a/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/DurationJsonFormatterTest.kt +++ b/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/DurationJsonFormatterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,7 +35,7 @@ class DurationJsonFormatterTest { assertThat(fromString("-0.2s")).isEqualTo(durationOfSeconds(0L, -200000000L)) assertThat(fromString("0.2s")).isEqualTo(durationOfSeconds(0L, 200000000L)) assertThat(fromString("-9223372036854775808s")).isEqualTo( - durationOfSeconds(Long.MIN_VALUE, 0L) + durationOfSeconds(Long.MIN_VALUE, 0L), ) assertThat(fromString("9223372036854775807.999999999s")) .isEqualTo(durationOfSeconds(Long.MAX_VALUE, 999_999_999L)) diff --git a/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/InstantJsonFormatterTest.kt b/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/InstantJsonFormatterTest.kt index b979350ffa..8743002996 100644 --- a/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/InstantJsonFormatterTest.kt +++ b/wire-tests/src/jvmJsonTest/kotlin/com/squareup/wire/internal/InstantJsonFormatterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/AnnotationsTestAgainstKotlin.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/AnnotationsTestAgainstKotlin.kt index dd417c93d7..cf4abea5c7 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/AnnotationsTestAgainstKotlin.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/AnnotationsTestAgainstKotlin.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ @file:Suppress("UsePropertyAccessSyntax") package com.squareup.wire diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinMapTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinMapTest.kt index bb2b167d38..ea31a8c290 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinMapTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinMapTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package com.squareup.wire import com.squareup.wire.internal.createRuntimeMessageAdapter import com.squareup.wire.protos.kotlin.map.Mappy import com.squareup.wire.protos.kotlin.map.Thing -import okio.ByteString -import okio.ByteString.Companion.decodeHex import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull +import okio.ByteString +import okio.ByteString.Companion.decodeHex class KotlinMapTest { private val adapter = createRuntimeMessageAdapter( @@ -53,8 +53,8 @@ class KotlinMapTest { things = mapOf( "one" to Thing("One"), "two" to Thing("Two"), - "three" to Thing("Three") - ) + "three" to Thing("Three"), + ), ) } } diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinRepeatedTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinRepeatedTest.kt index 41a441b039..8ff22f5013 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinRepeatedTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/KotlinRepeatedTest.kt @@ -1,28 +1,28 @@ /* -* Copyright 2019 Square Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (C) 2019 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire import com.squareup.wire.internal.createRuntimeMessageAdapter import com.squareup.wire.protos.kotlin.repeated.Repeated import com.squareup.wire.protos.kotlin.repeated.Thing -import okio.ByteString.Companion.decodeHex -import okio.ByteString.Companion.toByteString import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull +import okio.ByteString.Companion.decodeHex +import okio.ByteString.Companion.toByteString class KotlinRepeatedTest { private val adapter = createRuntimeMessageAdapter( @@ -52,8 +52,8 @@ class KotlinRepeatedTest { things = listOf( Thing("One"), Thing("Two"), - Thing("Three") - ) + Thing("Three"), + ), ) } } diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/OneOfTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/OneOfTest.kt index 52d4025b4e..4b7c58d425 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/OneOfTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/OneOfTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,18 +17,27 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.Form import com.squareup.wire.protos.kotlin.OneOfMessage +import kotlin.test.assertEquals import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import kotlin.test.assertEquals class OneOfTest { private val INITIAL_BYTES = byteArrayOf() + // (Tag #1 << 3 | VARINT) = 8. private val FOO_BYTES = byteArrayOf(8, 17) + // (Tag #3 << 3 | LENGTH_DELIMITED) = 26, string length = 6. private val BAR_BYTES = byteArrayOf( - 26, 6, 'b'.toByte(), 'a'.toByte(), 'r'.toByte(), 'b'.toByte(), 'a'.toByte(), 'r'.toByte() + 26, + 6, + 'b'.toByte(), + 'a'.toByte(), + 'r'.toByte(), + 'b'.toByte(), + 'a'.toByte(), + 'r'.toByte(), ) private val adapter = OneOfMessage.ADAPTER @@ -39,28 +48,28 @@ class OneOfTest { builder.validate( expectedFoo = null, expectedBar = null, - expectedBytes = INITIAL_BYTES + expectedBytes = INITIAL_BYTES, ) builder.foo(17) builder.validate( expectedFoo = 17, expectedBar = null, - expectedBytes = FOO_BYTES + expectedBytes = FOO_BYTES, ) builder.bar("barbar") builder.validate( expectedFoo = null, expectedBar = "barbar", - expectedBytes = BAR_BYTES + expectedBytes = BAR_BYTES, ) builder.foo(17) builder.validate( expectedFoo = 17, expectedBar = null, - expectedBytes = FOO_BYTES + expectedBytes = FOO_BYTES, ) } @@ -101,7 +110,7 @@ class OneOfTest { private fun OneOfMessage.Builder.validate( expectedFoo: Int?, expectedBar: String?, - expectedBytes: ByteArray + expectedBytes: ByteArray, ) { // Check builder fields assertThat(foo).isEqualTo(expectedFoo) diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt index 57fc2d7667..aa0bf2bc72 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,10 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.person.Person +import kotlin.test.Test import okio.ByteString.Companion.decodeHex import okio.ByteString.Companion.toByteString import org.assertj.core.api.Assertions.assertThat -import kotlin.test.Test class ProtoAdapterTest { @Test fun fromClass() { diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/RecursiveMapTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/RecursiveMapTest.kt index c3cf82f3df..53a8fff066 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/RecursiveMapTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/RecursiveMapTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/SerializableTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/SerializableTest.kt index dc0aa3df60..0459a9e580 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/SerializableTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/SerializableTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,13 +18,13 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.NoFields import com.squareup.wire.protos.kotlin.person.Person import com.squareup.wire.protos.kotlin.simple.SimpleMessage +import java.io.ObjectInputStream +import java.io.ObjectOutputStream import okio.Buffer import okio.ByteString import okio.ByteString.Companion.decodeBase64 import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import java.io.ObjectInputStream -import java.io.ObjectOutputStream class SerializableTest { @Test fun simple() { @@ -42,8 +42,8 @@ class SerializableTest { Person.PhoneNumber.Builder() .number("410-555-0909") .type(Person.PhoneType.MOBILE) - .build() - ) + .build(), + ), ) .build() assertThat(deserialize(serialize(person))).isEqualTo(person) diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypes.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypes.kt index b9c3c3716e..bc0cc73e66 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypes.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypes.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,9 @@ package com.squareup.wire import com.squareup.wire.protos.kotlin.alltypes.AllTypes +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import kotlin.math.min import okio.Buffer import okio.ByteString import okio.ForwardingSource @@ -23,9 +26,6 @@ import okio.Source import okio.buffer import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import kotlin.math.min class TestAllTypes { @@ -161,7 +161,7 @@ class TestAllTypes { assertThat(String(AllTypes.DEFAULT_DEFAULT_BYTES.toByteArray(), Charsets.ISO_8859_1)) .isEqualTo( "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001" + - "\u0011\u0001\u0001\u0011güzel" + "\u0011\u0001\u0001\u0011güzel", ) } diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypesData.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypesData.kt index f6ee772af1..8c632cf883 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypesData.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/TestAllTypesData.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt index 8dea721907..c2dd86fb4c 100644 --- a/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt +++ b/wire-tests/src/jvmKotlinInteropTest/kotlin/com/squareup/wire/UnknownFieldsTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreJs.kt b/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreJs.kt index a9033086ac..6d018ceb6e 100644 --- a/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreJs.kt +++ b/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreJs.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire actual annotation class IgnoreJs diff --git a/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreNative.kt b/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreNative.kt index 6d24ad94db..4f98ada91d 100644 --- a/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreNative.kt +++ b/wire-tests/src/jvmTest/kotlin/com/squareup/wire/IgnoreNative.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire actual annotation class IgnoreNative diff --git a/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreJs.kt b/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreJs.kt index a9033086ac..6d018ceb6e 100644 --- a/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreJs.kt +++ b/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreJs.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire actual annotation class IgnoreJs diff --git a/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreNative.kt b/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreNative.kt index 1583f6aa88..3d94f7ec19 100644 --- a/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreNative.kt +++ b/wire-tests/src/nativeTest/kotlin/com/squareup/wire/IgnoreNative.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire actual typealias IgnoreNative = kotlin.test.Ignore From 85fd554e7d4cd7e06948c495d2acbbd912d193ab Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 20:02:27 +0200 Subject: [PATCH 4/7] Spotless: wire-schema --- wire-grpc-server-generator/build.gradle.kts | 8 + wire-schema/build.gradle.kts | 10 + .../kotlin/com/squareup/wire/WireLogger.kt | 4 +- .../wire/schema/ClaimedDefinitions.kt | 2 +- .../com/squareup/wire/schema/ClaimedPaths.kt | 2 +- .../com/squareup/wire/schema/CoreLoader.kt | 2 +- .../com/squareup/wire/schema/CycleChecker.kt | 4 +- .../wire/schema/DirectedAcyclicGraph.kt | 6 +- .../com/squareup/wire/schema/EmittingRules.kt | 2 +- .../com/squareup/wire/schema/EnclosingType.kt | 6 +- .../com/squareup/wire/schema/EnumConstant.kt | 13 +- .../com/squareup/wire/schema/EnumType.kt | 17 +- .../squareup/wire/schema/ErrorCollector.kt | 2 +- .../com/squareup/wire/schema/EventListener.kt | 2 +- .../kotlin/com/squareup/wire/schema/Extend.kt | 10 +- .../com/squareup/wire/schema/Extensions.kt | 4 +- .../kotlin/com/squareup/wire/schema/Field.kt | 16 +- .../com/squareup/wire/schema/FileLinker.kt | 8 +- .../squareup/wire/schema/LinkedOptionEntry.kt | 17 +- .../kotlin/com/squareup/wire/schema/Linker.kt | 10 +- .../kotlin/com/squareup/wire/schema/Loader.kt | 2 +- .../com/squareup/wire/schema/Location.kt | 6 +- .../com/squareup/wire/schema/MarkSet.kt | 6 +- .../com/squareup/wire/schema/MessageType.kt | 16 +- .../com/squareup/wire/schema/Multimap.kt | 2 +- .../kotlin/com/squareup/wire/schema/OneOf.kt | 10 +- .../com/squareup/wire/schema/Options.kt | 58 +- .../squareup/wire/schema/PartitionedSchema.kt | 12 +- .../com/squareup/wire/schema/Profile.kt | 6 +- .../com/squareup/wire/schema/ProfileLoader.kt | 4 +- .../com/squareup/wire/schema/ProtoFile.kt | 12 +- .../com/squareup/wire/schema/ProtoMember.kt | 4 +- .../com/squareup/wire/schema/ProtoType.kt | 37 +- .../kotlin/com/squareup/wire/schema/Pruner.kt | 7 +- .../com/squareup/wire/schema/PruningRules.kt | 4 +- .../com/squareup/wire/schema/Reserved.kt | 4 +- .../kotlin/com/squareup/wire/schema/Root.kt | 14 +- .../kotlin/com/squareup/wire/schema/Rpc.kt | 10 +- .../kotlin/com/squareup/wire/schema/Schema.kt | 10 +- .../squareup/wire/schema/SchemaException.kt | 4 +- .../com/squareup/wire/schema/SchemaHandler.kt | 6 +- .../com/squareup/wire/schema/SchemaLoader.kt | 6 +- .../wire/schema/SchemaProtoAdapterFactory.kt | 17 +- .../kotlin/com/squareup/wire/schema/SemVer.kt | 8 +- .../com/squareup/wire/schema/Service.kt | 30 +- .../com/squareup/wire/schema/SyntaxRules.kt | 29 +- .../kotlin/com/squareup/wire/schema/Target.kt | 4 +- .../kotlin/com/squareup/wire/schema/Type.kt | 4 +- .../com/squareup/wire/schema/WireRun.kt | 16 +- .../schema/internal/CommonSchemaLoader.kt | 8 +- .../wire/schema/internal/DagChecker.kt | 6 +- .../schema/internal/ProfileFileElement.kt | 4 +- .../wire/schema/internal/ProfileParser.kt | 10 +- .../wire/schema/internal/SchemaEncoder.kt | 32 +- .../wire/schema/internal/TypeConfigElement.kt | 4 +- .../wire/schema/internal/TypeMover.kt | 8 +- .../com/squareup/wire/schema/internal/Util.kt | 20 +- .../internal/parser/EnumConstantElement.kt | 4 +- .../schema/internal/parser/EnumElement.kt | 2 +- .../schema/internal/parser/ExtendElement.kt | 4 +- .../internal/parser/ExtensionsElement.kt | 4 +- .../schema/internal/parser/FieldElement.kt | 14 +- .../schema/internal/parser/GroupElement.kt | 4 +- .../schema/internal/parser/MessageElement.kt | 2 +- .../schema/internal/parser/OneOfElement.kt | 2 +- .../schema/internal/parser/OptionElement.kt | 16 +- .../schema/internal/parser/OptionReader.kt | 9 +- .../internal/parser/ProtoFileElement.kt | 4 +- .../schema/internal/parser/ProtoParser.kt | 45 +- .../schema/internal/parser/ReservedElement.kt | 4 +- .../wire/schema/internal/parser/RpcElement.kt | 4 +- .../schema/internal/parser/ServiceElement.kt | 4 +- .../schema/internal/parser/SyntaxReader.kt | 6 +- .../schema/internal/parser/TypeElement.kt | 2 +- .../com/squareup/wire/schema/CoreLoader.kt | 2 +- .../com/squareup/wire/schema/Multimap.kt | 2 +- .../com/squareup/wire/schema/Profile.kt | 4 +- .../kotlin/com/squareup/wire/schema/Roots.kt | 9 +- .../com/squareup/wire/schema/SchemaLoader.kt | 6 +- .../squareup/wire/schema/internal/UtilJS.kt | 2 +- .../squareup/wire/schema/AdapterConstant.kt | 6 +- .../com/squareup/wire/schema/CoreLoader.kt | 2 +- .../squareup/wire/schema/EventListeners.kt | 4 +- .../com/squareup/wire/schema/Multimap.kt | 2 +- .../com/squareup/wire/schema/Profile.kt | 6 +- .../kotlin/com/squareup/wire/schema/Roots.kt | 8 +- .../com/squareup/wire/schema/SchemaLoader.kt | 8 +- .../wire/schema/internal/JvmLanguages.kt | 3 +- .../squareup/wire/schema/internal/UtilJVM.kt | 2 +- .../wire/schema/internal/fileSystems.kt | 10 +- .../wire/schema/DynamicSerializationTest.kt | 8 +- .../squareup/wire/schema/EmittingRulesTest.kt | 4 +- .../wire/schema/ManifestPartitionTest.kt | 35 +- .../com/squareup/wire/schema/OptionsTest.kt | 33 +- .../squareup/wire/schema/ProfileLoaderTest.kt | 36 +- .../com/squareup/wire/schema/ProtoFileTest.kt | 29 +- .../com/squareup/wire/schema/ProtoTypeTest.kt | 2 +- .../com/squareup/wire/schema/PrunerTest.kt | 280 ++-- .../squareup/wire/schema/PruningRulesTest.kt | 16 +- .../com/squareup/wire/schema/RootTest.kt | 14 +- .../squareup/wire/schema/SchemaLoaderTest.kt | 165 +-- .../wire/schema/SchemaProtoAdapterTest.kt | 42 +- .../com/squareup/wire/schema/SchemaTest.kt | 420 +++--- .../com/squareup/wire/schema/SemVerTest.kt | 26 +- .../wire/schema/internal/DagCheckerTest.kt | 8 +- .../wire/schema/internal/ProfileParserTest.kt | 20 +- .../wire/schema/internal/SchemaEncoderTest.kt | 85 +- .../wire/schema/internal/TypeMoverTest.kt | 85 +- .../squareup/wire/schema/internal/UtilTest.kt | 11 +- .../schema/internal/parser/EnumElementTest.kt | 50 +- .../internal/parser/ExtendElementTest.kt | 46 +- .../internal/parser/ExtensionsElementTest.kt | 13 +- .../internal/parser/FieldElementTest.kt | 25 +- .../internal/parser/MessageElementTest.kt | 219 +-- .../internal/parser/OptionElementTest.kt | 14 +- .../schema/internal/parser/ParsingTester.kt | 6 +- .../internal/parser/ProtoFileElementTest.kt | 154 ++- .../schema/internal/parser/ProtoParserTest.kt | 1174 +++++++++-------- .../internal/parser/ServiceElementTest.kt | 66 +- 119 files changed, 2115 insertions(+), 1762 deletions(-) diff --git a/wire-grpc-server-generator/build.gradle.kts b/wire-grpc-server-generator/build.gradle.kts index ea7459fde2..7053205168 100644 --- a/wire-grpc-server-generator/build.gradle.kts +++ b/wire-grpc-server-generator/build.gradle.kts @@ -42,4 +42,12 @@ if (project.rootProject.name == "wire") { KotlinJvm(javadocJar = Dokka("dokkaGfm"), sourcesJar = true) ) } + + configure { + kotlin { + targetExclude( + "src/test/golden/*.kt", + ) + } + } } diff --git a/wire-schema/build.gradle.kts b/wire-schema/build.gradle.kts index 529009e71a..6ca0a47ea9 100644 --- a/wire-schema/build.gradle.kts +++ b/wire-schema/build.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinMultiplatform import com.vanniktech.maven.publish.MavenPublishBaseExtension @@ -76,4 +77,13 @@ if (project.rootProject.name == "wire") { KotlinMultiplatform(javadocJar = Dokka("dokkaGfm")) ) } + + configure { + kotlin { + targetExclude( + // Apache 2-licensed files from Apache. + "src/jvmTest/kotlin/com/squareup/wire/schema/MavenVersionsTest.kt", + ) + } + } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/WireLogger.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/WireLogger.kt index 7790e9925b..719cc4f0ca 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/WireLogger.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/WireLogger.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedDefinitions.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedDefinitions.kt index 6602680082..31c0e6a1af 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedDefinitions.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedDefinitions.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedPaths.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedPaths.kt index 7d5d3c50f0..dfbcca5465 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedPaths.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ClaimedPaths.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CoreLoader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CoreLoader.kt index 2074119b91..fcebe48103 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CoreLoader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CoreLoader.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CycleChecker.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CycleChecker.kt index 15eebc9247..e224503d87 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CycleChecker.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/CycleChecker.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,7 +29,7 @@ import com.squareup.wire.schema.internal.DagChecker */ internal class CycleChecker( private val fileLinkers: Map, - private val errors: ErrorCollector + private val errors: ErrorCollector, ) { private val goPackageOption = ProtoMember.get("google.protobuf.FileOptions#go_package") diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/DirectedAcyclicGraph.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/DirectedAcyclicGraph.kt index 33af2fca8f..8eeddbad9b 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/DirectedAcyclicGraph.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/DirectedAcyclicGraph.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,7 +17,7 @@ package com.squareup.wire.schema internal class DirectedAcyclicGraph( private val nodes: Iterable, - private val edges: (N) -> Iterable + private val edges: (N) -> Iterable, ) { /** Nodes which have no outgoing edges. */ private val seeds = nodes.filterNot { edges(it).iterator().hasNext() } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EmittingRules.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EmittingRules.kt index cec96015b0..daf5127dd4 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EmittingRules.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EmittingRules.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnclosingType.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnclosingType.kt index ef6742ca27..16c159998f 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnclosingType.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnclosingType.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ data class EnclosingType( override val documentation: String, override val nestedTypes: List, override val nestedExtendList: List, - override val syntax: Syntax + override val syntax: Syntax, ) : Type() { override val options get() = Options(Options.MESSAGE_OPTIONS, listOf()) @@ -57,6 +57,6 @@ data class EnclosingType( fun toElement() = MessageElement( location = location, name = type.simpleName, - nestedTypes = toElements(nestedTypes) + nestedTypes = toElements(nestedTypes), ) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumConstant.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumConstant.kt index 9d55d9e611..bfbeffcd3b 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumConstant.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumConstant.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ data class EnumConstant( val name: String, val tag: Int, val documentation: String, - val options: Options + val options: Options, ) { val isDeprecated: Boolean get() = "true" == options.get(DEPRECATED) @@ -39,7 +39,7 @@ data class EnumConstant( internal fun retainAll( schema: Schema, - markSet: MarkSet + markSet: MarkSet, ) = EnumConstant(location, name, tag, documentation, options.retainAll(schema, markSet)) internal fun retainLinked() = @@ -51,8 +51,11 @@ data class EnumConstant( internal fun fromElements(elements: List) = elements.map { EnumConstant( - it.location, it.name, it.tag, it.documentation, - Options(ENUM_VALUE_OPTIONS, it.options) + it.location, + it.name, + it.tag, + it.documentation, + Options(ENUM_VALUE_OPTIONS, it.options), ) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumType.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumType.kt index c1b9de589d..d8d8fe7761 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumType.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EnumType.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,7 +31,7 @@ data class EnumType( val constants: List, private val reserveds: List, override val options: Options, - override val syntax: Syntax + override val syntax: Syntax, ) : Type() { private var allowAlias: Any? = null @@ -94,8 +94,11 @@ data class EnumType( constants.groupBy { buildString(it.name.length) { for (char in it.name) { - if (char in 'A'..'Z') append(char - ('A' - 'a')) - else append(char) + if (char in 'A'..'Z') { + append(char - ('A' - 'a')) + } else { + append(char) + } } } } @@ -107,7 +110,7 @@ data class EnumType( val error = buildString { append( "Ambiguous constant names (if you are using allow_alias, use the same value for " + - "these constants):" + "these constants):", ) constants.forEach { append("\n ${it.name}:${it.tag} (${it.location})") @@ -155,7 +158,7 @@ data class EnumType( constants = retainedConstants, options = options.retainAll(schema, markSet), syntax = syntax, - reserveds = reserveds + reserveds = reserveds, ) result.allowAlias = allowAlias return result @@ -199,7 +202,7 @@ data class EnumType( fun fromElement( protoType: ProtoType, enumElement: EnumElement, - syntax: Syntax + syntax: Syntax, ): EnumType { return EnumType( type = protoType, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ErrorCollector.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ErrorCollector.kt index 11a3e437fa..877a01e1b8 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ErrorCollector.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ErrorCollector.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EventListener.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EventListener.kt index c0b03a1625..728415e1fe 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EventListener.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/EventListener.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extend.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extend.kt index ca38005249..272724e710 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extend.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extend.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ data class Extend( val location: Location, val documentation: String, val name: String, - val fields: List + val fields: List, ) { // Null until this extend is linked. var type: ProtoType? = null @@ -80,13 +80,13 @@ data class Extend( @JvmStatic fun fromElements( namespaces: List, - extendElements: List + extendElements: List, ) = extendElements.map { Extend( location = it.location, documentation = it.documentation, name = it.name, - fields = Field.fromElements(namespaces, it.fields, extension = true, oneOf = false) + fields = Field.fromElements(namespaces, it.fields, extension = true, oneOf = false), ) } @@ -96,7 +96,7 @@ data class Extend( location = it.location, name = it.name, documentation = it.documentation, - fields = Field.toElements(it.fields) + fields = Field.toElements(it.fields), ) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extensions.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extensions.kt index 80fbe028a6..c52ae93242 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extensions.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Extensions.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import kotlin.jvm.JvmStatic data class Extensions( val location: Location, val documentation: String, - val values: List + val values: List, ) { fun validate(linker: Linker) { @Suppress("NAME_SHADOWING") diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Field.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Field.kt index 1b98f54d3d..f2ef7e41ef 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Field.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Field.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -54,7 +54,7 @@ data class Field( val isOneOf: Boolean, - val declaredJsonName: String? + val declaredJsonName: String?, ) { // Null until this field is linked. var type: ProtoType? = null @@ -184,7 +184,9 @@ data class Field( if (!markSet.contains(protoMember) && !(GOOGLE_PROTOBUF_OPTION_TYPES.contains(enclosingType) && !isExtension) - ) return null + ) { + return null + } return withOptions(options.retainAll(schema, markSet)) } @@ -221,7 +223,7 @@ data class Field( REPEATED, /** Indicates the field is a member of a `oneof` block. */ - ONE_OF + ONE_OF, } enum class EncodeMode { @@ -253,7 +255,7 @@ data class Field( namespaces: List, fieldElements: List, extension: Boolean, - oneOf: Boolean + oneOf: Boolean, ) = fieldElements.map { Field( namespaces = namespaces, @@ -282,7 +284,7 @@ data class Field( jsonName = it.declaredJsonName, tag = it.tag, documentation = it.documentation, - options = it.options.elements + options = it.options.elements, ) } @@ -296,7 +298,7 @@ data class Field( schema: Schema, markSet: MarkSet, enclosingType: ProtoType, - fields: Collection + fields: Collection, ) = fields.mapNotNull { it.retainAll(schema, markSet, enclosingType) } } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/FileLinker.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/FileLinker.kt index c359366491..29a9a71ebe 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/FileLinker.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/FileLinker.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,10 +17,11 @@ package com.squareup.wire.schema internal class FileLinker( val protoFile: ProtoFile, - private val linker: Linker + private val linker: Linker, ) { /** Lazily computed set of files used to reference other types and options. */ private var effectiveImports: Set? = null + /** True once this linker has registered its types with the enclosing linker. */ private var typesRegistered = false private var extensionsLinked = false @@ -28,6 +29,7 @@ internal class FileLinker( private var extensionOptionsLinked = false private var importedExtensionOptionsLinked = false private var fileOptionsLinked = false + /** The set of types defined in this file whose members have been linked. */ private val typesWithMembersLinked: MutableSet = LinkedHashSet() @@ -47,7 +49,7 @@ internal class FileLinker( private fun addImportsRecursive( sink: MutableSet, - paths: Collection + paths: Collection, ) { for (path in paths) { if (sink.add(path)) { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/LinkedOptionEntry.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/LinkedOptionEntry.kt index 591c0cab98..39ab2d038d 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/LinkedOptionEntry.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/LinkedOptionEntry.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.schema import com.squareup.wire.schema.internal.parser.OptionElement @@ -5,5 +20,5 @@ import com.squareup.wire.schema.internal.parser.OptionElement data class LinkedOptionEntry( val optionElement: OptionElement, val protoMember: ProtoMember, - val value: Any? + val value: Any?, ) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Linker.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Linker.kt index 53f4050f3b..1b42ea8c8c 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Linker.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Linker.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -362,7 +362,8 @@ class Linker { protoType: ProtoType, field: String, ): Field? { - @Suppress("NAME_SHADOWING") var field = field + @Suppress("NAME_SHADOWING") + var field = field if (field.startsWith("[") && field.endsWith("]")) { field = field.substring(1, field.length - 1) } @@ -509,7 +510,7 @@ class Linker { values.forEachIndexed { index, enumType -> append( "\n ${index + 1}. ${enumType.type}.$constant " + - "(${enumType.constant(constant)!!.location})" + "(${enumType.constant(constant)!!.location})", ) } } @@ -522,7 +523,8 @@ class Linker { location: Location, type: ProtoType, ) { - @Suppress("NAME_SHADOWING") var type = type + @Suppress("NAME_SHADOWING") + var type = type // Map key type is always scalar. No need to validate it. if (type.isMap) type = type.valueType!! diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Loader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Loader.kt index 6dda09273e..9acb5fa0a8 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Loader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Loader.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt index 7041fe544e..ab04e34e71 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,7 +32,7 @@ data class Location( val line: Int = -1, /** The column on the line of this location, or -1 for no specific column. */ - val column: Int = -1 + val column: Int = -1, ) { fun at(line: Int, column: Int) = Location(base, path, line, column) @@ -68,7 +68,7 @@ data class Location( @JvmStatic fun get( base: String, - path: String + path: String, ): Location { return Location(base.trimEnd('/'), path, -1, -1) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MarkSet.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MarkSet.kt index d9be2b52ea..a5ec887575 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MarkSet.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MarkSet.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,15 +27,17 @@ package com.squareup.wire.schema * 3. Retaining which members and types have been marked. */ class MarkSet( - val pruningRules: PruningRules + val pruningRules: PruningRules, ) { /** The types to retain. We may retain a type but not all of its members. */ val types = mutableSetOf() /** The members to retain. Any member not in here should be pruned! */ val members = mutableMapOf>() + /** The root members which are never to be pruned, including their referenced type. */ private val rootMemberTypes = mutableMapOf() + /** The members this MarkSet have seen. The values should be non-null once the marking is done. */ private val memberTypes = mutableMapOf() diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MessageType.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MessageType.kt index 0ce8d268c3..f50f5b4ebb 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MessageType.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/MessageType.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,7 +46,7 @@ data class MessageType( val extensionsList: List, private val reserveds: List, override val options: Options, - override val syntax: Syntax + override val syntax: Syntax, ) : Type() { private var deprecated: Any? = null @@ -160,7 +160,7 @@ data class MessageType( override fun retainAll( schema: Schema, - markSet: MarkSet + markSet: MarkSet, ): Type? { val retainedNestedTypes = nestedTypes.mapNotNull { it.retainAll(schema, markSet) } val retainedNestedExtends = nestedExtendList.mapNotNull { it.retainAll(schema, markSet) } @@ -188,7 +188,7 @@ data class MessageType( extensionsList = extensionsList, reserveds = reserveds, options = options.retainAll(schema, markSet), - syntax = syntax + syntax = syntax, ) result.deprecated = deprecated return result @@ -223,7 +223,7 @@ data class MessageType( extensionsList = emptyList(), reserveds = emptyList(), options = options.retainLinked(), - syntax = syntax + syntax = syntax, ) } @@ -239,7 +239,7 @@ data class MessageType( fields = toElements(declaredFields), oneOfs = toElements(oneOfs), extensions = toElements(extensionsList), - groups = emptyList() + groups = emptyList(), ) } @@ -250,7 +250,7 @@ data class MessageType( namespaces: List, protoType: ProtoType, messageElement: MessageElement, - syntax: Syntax + syntax: Syntax, ): MessageType { check(messageElement.groups.isEmpty()) { "${messageElement.groups[0].location}: 'group' is not supported" @@ -278,7 +278,7 @@ data class MessageType( extensionsList = fromElements(messageElement.extensions), reserveds = fromElements(messageElement.reserveds), options = Options(MESSAGE_OPTIONS, messageElement.options), - syntax = syntax + syntax = syntax, ) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Multimap.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Multimap.kt index 59be619cb7..eab31d1e99 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Multimap.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Multimap.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/OneOf.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/OneOf.kt index 31137a36b7..1beab1d5ce 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/OneOf.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/OneOf.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,7 @@ import kotlin.jvm.JvmStatic data class OneOf( val name: String, val documentation: String, - val fields: List + val fields: List, ) { fun link(linker: Linker) { for (field in fields) { @@ -55,7 +55,7 @@ data class OneOf( @JvmStatic fun fromElements( namespaces: List, - elements: List + elements: List, ) = elements.map { if (it.groups.isNotEmpty()) { val (_, location) = it.groups[0] @@ -65,7 +65,7 @@ data class OneOf( return@map OneOf( name = it.name, documentation = it.documentation, - fields = Field.fromElements(namespaces, it.fields, false, oneOf = true) + fields = Field.fromElements(namespaces, it.fields, false, oneOf = true), ) } @@ -76,7 +76,7 @@ data class OneOf( name = it.name, documentation = it.documentation, fields = Field.toElements(it.fields), - groups = emptyList() + groups = emptyList(), ) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Options.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Options.kt index 7279342f2f..015cc45ace 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Options.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Options.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ import kotlin.jvm.JvmField */ class Options( private val optionType: ProtoType, - private val optionElements: List + private val optionElements: List, ) { // Null until this options is linked. private var entries: List? = null @@ -78,7 +78,7 @@ class Options( extensionType: ProtoType, option: OptionElement, validate: Boolean, - location: Location + location: Location, ): List? { val type = linker.getForOptions(extensionType) as? MessageType ?: return null // No known extensions for the given extension type. @@ -146,7 +146,7 @@ class Options( linker: Linker, context: ProtoType, isRepeated: Boolean, - value: Any + value: Any, ): Any { when (value) { is OptionElement -> { @@ -168,15 +168,27 @@ class Options( val mapFieldKeyAsString = value["key"] val mapFieldValueAsString = value["value"] val mapFieldKey = - if (mapFieldKeyAsString == null) null - else canonicalizeValue( - linker, context.keyType!!, isRepeated = false, mapFieldKeyAsString - ) + if (mapFieldKeyAsString == null) { + null + } else { + canonicalizeValue( + linker, + context.keyType!!, + isRepeated = false, + mapFieldKeyAsString, + ) + } val mapFieldValue = - if (mapFieldValueAsString == null) null - else canonicalizeValue( - linker, context.valueType!!, isRepeated = false, mapFieldValueAsString - ) + if (mapFieldValueAsString == null) { + null + } else { + canonicalizeValue( + linker, + context.valueType!!, + isRepeated = false, + mapFieldValueAsString, + ) + } return coerceValueForField(context, mapOf(mapFieldKey to mapFieldValue), isRepeated) } else { val result = mutableMapOf() @@ -246,9 +258,10 @@ class Options( private fun union( linker: Linker, a: List, - b: List + b: List, ): List { val aMap: Map = a.toMap() + @Suppress("UNCHECKED_CAST") val bMap: Map = b.toMap() as Map @@ -268,7 +281,7 @@ class Options( LinkedOptionEntry( optionElement, protoMember, - valuesMap[protoMember] + valuesMap[protoMember], ) } } @@ -276,7 +289,7 @@ class Options( private fun union( linker: Linker, a: Map, - b: Map + b: Map, ): Map { val result: MutableMap = LinkedHashMap(a) for (entry in b) { @@ -304,7 +317,7 @@ class Options( sink: MutableMap>, type: ProtoType, o: Any?, - pruningRules: PruningRules + pruningRules: PruningRules, ) { when (o) { is Map<*, *> -> { @@ -346,7 +359,7 @@ class Options( schema: Schema, markSet: MarkSet, type: ProtoType?, - o: Any + o: Any, ): Any? { return when { o is Map<*, *> -> { @@ -390,12 +403,19 @@ class Options( companion object { @JvmField val FILE_OPTIONS = ProtoType.get("google.protobuf.FileOptions") + @JvmField val MESSAGE_OPTIONS = ProtoType.get("google.protobuf.MessageOptions") + @JvmField val FIELD_OPTIONS = ProtoType.get("google.protobuf.FieldOptions") + @JvmField val ONEOF_OPTIONS = ProtoType.get("google.protobuf.OneofOptions") + @JvmField val ENUM_OPTIONS = ProtoType.get("google.protobuf.EnumOptions") + @JvmField val ENUM_VALUE_OPTIONS = ProtoType.get("google.protobuf.EnumValueOptions") + @JvmField val SERVICE_OPTIONS = ProtoType.get("google.protobuf.ServiceOptions") + @JvmField val METHOD_OPTIONS = ProtoType.get("google.protobuf.MethodOptions") val GOOGLE_PROTOBUF_OPTION_TYPES = arrayOf( FILE_OPTIONS, @@ -405,7 +425,7 @@ class Options( ENUM_OPTIONS, ENUM_VALUE_OPTIONS, SERVICE_OPTIONS, - METHOD_OPTIONS + METHOD_OPTIONS, ) /** @@ -426,7 +446,7 @@ class Options( */ fun resolveFieldPath( name: String, - fullyQualifiedNames: Set + fullyQualifiedNames: Set, ): Array? { // Try to resolve a local name. var pos = 0 val chompedName = name.removePrefix(".") diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PartitionedSchema.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PartitionedSchema.kt index ad0ef5e56e..90ce712fcd 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PartitionedSchema.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PartitionedSchema.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,14 +23,14 @@ internal class PartitionedSchema( /** Module name to partition info. The iteration order of this map is the generation order. */ val partitions: Map, val warnings: List, - val errors: List + val errors: List, ) { class Partition( val schema: Schema, /** The types that this partition will generate. */ val types: Set = schema.types, /** These are the types depended upon by [types] associated with their module name. */ - val transitiveUpstreamTypes: Map = emptyMap() + val transitiveUpstreamTypes: Map = emptyMap(), ) } @@ -57,7 +57,7 @@ internal fun Schema.partition(modules: Map): PartitionedSchema { |$moduleName sees $duplicate in ${sourceModules.joinToString()}. | In order to avoid confusion and incompatibility, either make one of these modules | depend on the other or move this type up into a common dependency. - """.trimMargin() + """.trimMargin() } } @@ -105,7 +105,7 @@ internal fun Schema.partition(modules: Map): PartitionedSchema { |$duplicate is generated twice in peer modules $currentName and $otherName. | Consider moving this type into a common dependency of both modules. | To suppress this warning, explicitly add the type to the roots of both modules. - """.trimMargin() + """.trimMargin() } } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Profile.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Profile.kt index faf9d38dc5..9077a463ac 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Profile.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Profile.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,5 +18,5 @@ package com.squareup.wire.schema import com.squareup.wire.schema.internal.ProfileFileElement expect class Profile( - profileFiles: List = emptyList() + profileFiles: List = emptyList(), ) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProfileLoader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProfileLoader.kt index 8cb3de0483..5e131f83d8 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProfileLoader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProfileLoader.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoFile.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoFile.kt index fbbdaed1b6..bd66d2d688 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoFile.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoFile.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -45,7 +45,7 @@ data class ProtoFile( Type.toElements(types), Service.toElements(services), Extend.toElements(extendList), - options.elements + options.elements, ) } @@ -103,7 +103,7 @@ data class ProtoFile( val result = ProtoFile( location, imports, publicImports, packageName, retainedTypes, - retainedServices, retainedExtends, retainedOptions, syntax + retainedServices, retainedExtends, retainedOptions, syntax, ) result.javaPackage = javaPackage result.wirePackage = wirePackage @@ -122,7 +122,7 @@ data class ProtoFile( val result = ProtoFile( location, imports, publicImports, packageName, retainedTypes, - retainedServices, retainedExtends, retainedOptions, syntax + retainedServices, retainedExtends, retainedOptions, syntax, ) result.javaPackage = javaPackage result.wirePackage = wirePackage @@ -151,7 +151,7 @@ data class ProtoFile( return if (imports.size != retainedImports.size) { val result = ProtoFile( location, retainedImports, publicImports, packageName, types, services, - extendList, options, syntax + extendList, options, syntax, ) result.javaPackage = javaPackage result.wirePackage = wirePackage @@ -198,7 +198,7 @@ data class ProtoFile( return ProtoFile( protoFileElement.location, protoFileElement.imports, protoFileElement.publicImports, packageName, types, services, wireExtends, options, - protoFileElement.syntax + protoFileElement.syntax, ) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoMember.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoMember.kt index fe1ce0258d..febd959ab5 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoMember.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoMember.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ import kotlin.jvm.JvmStatic */ class ProtoMember private constructor( val type: ProtoType, - val member: String + val member: String, ) { val simpleName: String get() = member.substringAfterLast('.') // Strip package prefix for extension fields. diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoType.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoType.kt index 6a341e92cb..1fd0980cf2 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoType.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/ProtoType.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -101,36 +101,67 @@ class ProtoType { companion object { @JvmField val BOOL = ProtoType(true, "bool") + @JvmField val BYTES = ProtoType(true, "bytes") + @JvmField val DOUBLE = ProtoType(true, "double") + @JvmField val FLOAT = ProtoType(true, "float") + @JvmField val FIXED32 = ProtoType(true, "fixed32") + @JvmField val FIXED64 = ProtoType(true, "fixed64") + @JvmField val INT32 = ProtoType(true, "int32") + @JvmField val INT64 = ProtoType(true, "int64") + @JvmField val SFIXED32 = ProtoType(true, "sfixed32") + @JvmField val SFIXED64 = ProtoType(true, "sfixed64") + @JvmField val SINT32 = ProtoType(true, "sint32") + @JvmField val SINT64 = ProtoType(true, "sint64") + @JvmField val STRING = ProtoType(true, "string") + @JvmField val UINT32 = ProtoType(true, "uint32") + @JvmField val UINT64 = ProtoType(true, "uint64") + @JvmField val ANY = ProtoType(false, "google.protobuf.Any") + @JvmField val DURATION = ProtoType(false, "google.protobuf.Duration") + @JvmField val TIMESTAMP = ProtoType(false, "google.protobuf.Timestamp") + @JvmField val EMPTY = ProtoType(false, "google.protobuf.Empty") + @JvmField val STRUCT_MAP = ProtoType(false, "google.protobuf.Struct") + @JvmField val STRUCT_VALUE = ProtoType(false, "google.protobuf.Value") + @JvmField val STRUCT_NULL = ProtoType(false, "google.protobuf.NullValue") + @JvmField val STRUCT_LIST = ProtoType(false, "google.protobuf.ListValue") + @JvmField val DOUBLE_VALUE = ProtoType(false, "google.protobuf.DoubleValue") + @JvmField val FLOAT_VALUE = ProtoType(false, "google.protobuf.FloatValue") + @JvmField val INT64_VALUE = ProtoType(false, "google.protobuf.Int64Value") + @JvmField val UINT64_VALUE = ProtoType(false, "google.protobuf.UInt64Value") + @JvmField val INT32_VALUE = ProtoType(false, "google.protobuf.Int32Value") + @JvmField val UINT32_VALUE = ProtoType(false, "google.protobuf.UInt32Value") + @JvmField val BOOL_VALUE = ProtoType(false, "google.protobuf.BoolValue") + @JvmField val STRING_VALUE = ProtoType(false, "google.protobuf.StringValue") + @JvmField val BYTES_VALUE = ProtoType(false, "google.protobuf.BytesValue") private val SCALAR_TYPES: Map = listOf( @@ -148,7 +179,7 @@ class ProtoType { SINT64, STRING, UINT32, - UINT64 + UINT64, ).associateBy { it.string } internal val NUMERIC_SCALAR_TYPES = listOf( @@ -163,7 +194,7 @@ class ProtoType { SINT32, SINT64, UINT32, - UINT64 + UINT64, ) /** All types defined in `google/protobuf/wrappers.proto`. */ diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Pruner.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Pruner.kt index 2d136a7a91..64d4cd5082 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Pruner.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Pruner.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,9 +24,10 @@ import com.squareup.wire.schema.internal.mutableQueueOf */ class Pruner( private val schema: Schema, - private val pruningRules: PruningRules + private val pruningRules: PruningRules, ) { private val marks = MarkSet(pruningRules) + /** * [types][ProtoType] and [members][ProtoMember] whose immediate dependencies have not * yet been visited. @@ -44,7 +45,7 @@ class Pruner( private fun retainAll( schema: Schema, - marks: MarkSet + marks: MarkSet, ): List { return schema.protoFiles.map { protoFile -> protoFile.retainAll(schema, marks) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PruningRules.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PruningRules.kt index 7bdc461658..973cb5a517 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PruningRules.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/PruningRules.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -100,7 +100,7 @@ class PruningRules private constructor(builder: Builder) { private fun isRetainedVersion( options: Options, sinceMember: ProtoMember, - untilMember: ProtoMember + untilMember: ProtoMember, ): Boolean { if (_until != null || _only != null) { val sinceOption = options.get(sinceMember) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Reserved.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Reserved.kt index 6c756141b4..bb21708841 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Reserved.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Reserved.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,7 @@ import kotlin.jvm.JvmStatic data class Reserved( val location: Location, val documentation: String, - val values: List + val values: List, ) { fun matchesTag(tag: Int) = values.any { it is Int && tag == it || (it as? IntRange)?.contains(tag) == true diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Root.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Root.kt index 52c930f30a..e2badb06b9 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Root.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Root.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,7 +41,7 @@ internal sealed class Root { // TODO(jwilson): rework this API to combine baseToRoots and Closer. internal fun Location.roots( fs: FileSystem, - baseToRoots: MutableMap> = mutableMapOf() + baseToRoots: MutableMap> = mutableMapOf(), ): List { if (isWireRuntimeProto(this)) { // Handle descriptor.proto, etc. by returning a placeholder path. @@ -80,7 +80,7 @@ internal expect fun ProtoFilePath.parse(): ProtoFile internal class ProtoFilePath( val location: Location, val fileSystem: FileSystem, - val path: Path + val path: Path, ) : Root() { override val base: String? get() = null @@ -113,7 +113,7 @@ internal class DirectoryRoot( val fileSystem: FileSystem, /** The root to search. If this is a .zip file this is within its internal file system. */ - val rootDirectory: Path + val rootDirectory: Path, ) : Root() { override fun allProtoFiles(): Set { return fileSystem.listRecursively(rootDirectory) @@ -121,7 +121,7 @@ internal class DirectoryRoot( .map { descendant -> val location = Location.get( base = base, - path = descendant.relativeTo(rootDirectory).withUnixSlashes().toString() + path = descendant.relativeTo(rootDirectory).withUnixSlashes().toString(), ) ProtoFilePath(location, fileSystem, descendant) } @@ -134,7 +134,7 @@ internal class DirectoryRoot( return ProtoFilePath( location = Location.get(base, import.toPath().withUnixSlashes().toString()), fileSystem = fileSystem, - path = resolved + path = resolved, ) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Rpc.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Rpc.kt index c7ffee8544..7e90507dd2 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Rpc.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Rpc.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ data class Rpc( private val responseTypeElement: String, val requestStreaming: Boolean, val responseStreaming: Boolean, - val options: Options + val options: Options, ) { // Null until this RPC is linked. var requestType: ProtoType? = null @@ -66,7 +66,7 @@ data class Rpc( responseTypeElement = responseTypeElement, requestStreaming = requestStreaming, responseStreaming = responseStreaming, - options = options.retainAll(schema, markSet) + options = options.retainAll(schema, markSet), ) result.requestType = requestType result.responseType = responseType @@ -85,7 +85,7 @@ data class Rpc( responseTypeElement = element.responseType, requestStreaming = element.requestStreaming, responseStreaming = element.responseStreaming, - options = Options(Options.METHOD_OPTIONS, element.options) + options = Options(Options.METHOD_OPTIONS, element.options), ) } } @@ -101,7 +101,7 @@ data class Rpc( responseType = rpc.responseTypeElement, requestStreaming = rpc.requestStreaming, responseStreaming = rpc.responseStreaming, - options = rpc.options.elements + options = rpc.options.elements, ) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Schema.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Schema.kt index 4e0c864844..156f165d4c 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Schema.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Schema.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,8 @@ package com.squareup.wire.schema import com.squareup.wire.ProtoAdapter -import okio.Path import kotlin.collections.set +import okio.Path /** * A collection of .proto files that describe a set of messages. A schema is *linked*: each @@ -113,7 +113,7 @@ class Schema internal constructor(protoFiles: Iterable) { */ fun protoAdapter( typeName: String, - includeUnknown: Boolean + includeUnknown: Boolean, ): ProtoAdapter { val type = requireNotNull(getType(typeName)) { "unexpected type $typeName" } return SchemaProtoAdapterFactory(this, includeUnknown)[type.type] @@ -128,7 +128,7 @@ class Schema internal constructor(protoFiles: Iterable) { private fun buildTypesIndex( protoFiles: Iterable, - protoFilesIndex: MutableMap + protoFilesIndex: MutableMap, ): Map { val typesByName = mutableMapOf() @@ -153,7 +153,7 @@ class Schema internal constructor(protoFiles: Iterable) { private fun buildServicesIndex( protoFiles: Iterable, - protoFilesIndex: MutableMap + protoFilesIndex: MutableMap, ): Map { val result = mutableMapOf() for (protoFile in protoFiles) { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaException.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaException.kt index 79941f4ded..e926e1430e 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaException.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaException.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,5 +16,5 @@ package com.squareup.wire.schema class SchemaException(errors: List) : RuntimeException( - errors.joinToString(separator = "\n") + errors.joinToString(separator = "\n"), ) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaHandler.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaHandler.kt index 7d5dc0b7b9..1d375e1486 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaHandler.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaHandler.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,7 +37,7 @@ abstract class SchemaHandler { // Remove types from the file which are not owned by this partition. val filteredProtoFile = protoFile.copy( types = protoFile.types.filter { if (moduleTypes != null) it.type in moduleTypes else true }, - services = protoFile.services.filter { if (moduleTypes != null) it.type in moduleTypes else true } + services = protoFile.services.filter { if (moduleTypes != null) it.type in moduleTypes else true }, ) handle(filteredProtoFile, context) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt index 3eef4a4c39..140160ab95 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,7 +38,7 @@ expect class SchemaLoader(fileSystem: FileSystem) : Loader, ProfileLoader { /** Initialize the [WireRun.sourcePath] and [WireRun.protoPath] from which files are loaded. */ fun initRoots( sourcePath: List, - protoPath: List = listOf() + protoPath: List = listOf(), ) @Throws(IOException::class) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaProtoAdapterFactory.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaProtoAdapterFactory.kt index 8824051530..400bbc6534 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaProtoAdapterFactory.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SchemaProtoAdapterFactory.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -36,7 +36,7 @@ import okio.ByteString */ internal class SchemaProtoAdapterFactory( val schema: Schema, - private val includeUnknown: Boolean + private val includeUnknown: Boolean, ) { private val adapterMap = mutableMapOf>( ProtoType.BOOL to ProtoAdapter.BOOL, @@ -110,12 +110,12 @@ internal class SchemaProtoAdapterFactory( /** We prevent cycles by linking against while we're still building the graph of adapters. */ private class DeferredAdapter( - binding: SchemaMessageBinding + binding: SchemaMessageBinding, ) : ProtoAdapter( fieldEncoding = FieldEncoding.LENGTH_DELIMITED, type = binding.messageType, typeUrl = binding.typeUrl, - syntax = binding.syntax + syntax = binding.syntax, ) { lateinit var delegate: ProtoAdapter @@ -131,7 +131,7 @@ internal class SchemaProtoAdapterFactory( } private class EnumAdapter( - private val enumType: EnumType + private val enumType: EnumType, ) : ProtoAdapter(VARINT, Any::class, null, enumType.syntax) { override fun encodedSize(value: Any): Int { return when (value) { @@ -189,7 +189,7 @@ internal class SchemaProtoAdapterFactory( private class SchemaMessageBinding( override val typeUrl: String?, override val syntax: Syntax, - private val includeUnknown: Boolean + private val includeUnknown: Boolean, ) : MessageBinding, MutableMap> { override val messageType = Map::class @@ -212,10 +212,11 @@ internal class SchemaProtoAdapterFactory( builder: MutableMap, tag: Int, fieldEncoding: FieldEncoding, - value: Any? + value: Any?, ) { if (!includeUnknown || value == null) return val name = tag.toString() + @Suppress("UNCHECKED_CAST") val values = builder.getOrPut(name) { mutableListOf() } as MutableList values.add(value) @@ -227,7 +228,7 @@ internal class SchemaProtoAdapterFactory( private inner class SchemaFieldOrOneOfBinding( val field: Field, - val oneOf: OneOf? + val oneOf: OneOf?, ) : FieldOrOneOfBinding, MutableMap>() { override val tag: Int = field.tag override val label: WireField.Label diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SemVer.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SemVer.kt index f3c69afcc5..1c366e781c 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SemVer.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SemVer.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -73,7 +73,7 @@ internal data class SemVer(val version: String) : Comparable { val result = compareSegment( a.substring(aPos, aLimit), - b.substring(bPos, bLimit) + b.substring(bPos, bLimit), ) if (result != 0) return result @@ -129,7 +129,7 @@ internal data class SemVer(val version: String) : Comparable { private fun String.find( chars: CharArray, startIndex: Int = 0, - endIndex: Int = length + endIndex: Int = length, ): Int { val result = indexOfAny(chars, startIndex = startIndex) if (result != -1 && result < endIndex) return result @@ -139,8 +139,10 @@ internal data class SemVer(val version: String) : Comparable { companion object { /** Characters that signal the end of the release section. */ private val RELEASE_TERMINATORS = charArrayOf('+', '-') + /** Characters that signal the end of the pre-release section. */ private val PRERELEASE_TERMINATORS = charArrayOf('+') + /** Characters that separate segments within a section. */ private val SEPARATORS = charArrayOf('.', '-') diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Service.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Service.kt index aba617bec2..5270638a66 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Service.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Service.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -36,7 +36,7 @@ data class Service( @get:JvmName("rpcs") // For binary compatibility. val rpcs: List, @get:JvmName("options") // For binary compatibility. - val options: Options + val options: Options, ) { /** Returns the RPC named `name`, or null if this service has no such method. */ fun rpc(name: String): Rpc? { @@ -70,7 +70,7 @@ data class Service( private fun validateRpcUniqueness( linker: Linker, - rpcs: List + rpcs: List, ) { val nameToRpc = linkedMapOf>() for (rpc in rpcs) { @@ -91,7 +91,7 @@ data class Service( fun retainAll( schema: Schema, - markSet: MarkSet + markSet: MarkSet, ): Service? { // If this service is not retained, prune it. if (!markSet.contains(type)) { @@ -107,28 +107,36 @@ data class Service( } return Service( - type, location, documentation, name, retainedRpcs, - options.retainAll(schema, markSet) + type, + location, + documentation, + name, + retainedRpcs, + options.retainAll(schema, markSet), ) } companion object { internal fun fromElement( protoType: ProtoType, - element: ServiceElement + element: ServiceElement, ): Service { val rpcs = fromElements(element.rpcs) val options = Options(Options.SERVICE_OPTIONS, element.options) return Service( - protoType, element.location, element.documentation, element.name, rpcs, - options + protoType, + element.location, + element.documentation, + element.name, + rpcs, + options, ) } @JvmStatic internal fun fromElements( packageName: String?, - elements: List + elements: List, ): List { return elements.map { service -> val protoType = get(packageName, service.name) @@ -143,7 +151,7 @@ data class Service( service.name, service.documentation, Rpc.toElements(service.rpcs), - service.options.elements + service.options.elements, ) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SyntaxRules.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SyntaxRules.kt index d7f1fb27a2..21160b5902 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SyntaxRules.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/SyntaxRules.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,7 +32,7 @@ interface SyntaxRules { protoType: ProtoType, label: Field.Label?, isPacked: Boolean, - isOneOf: Boolean + isOneOf: Boolean, ): Field.EncodeMode fun jsonName(name: String, declaredJsonName: String?): String @@ -42,44 +42,49 @@ interface SyntaxRules { return when (syntax) { PROTO_3 -> PROTO_3_SYNTAX_RULES PROTO_2, - null -> PROTO_2_SYNTAX_RULES + null, + -> PROTO_2_SYNTAX_RULES } } internal val PROTO_2_SYNTAX_RULES = object : SyntaxRules { override fun validateDefaultValue( hasDefaultValue: Boolean, - errors: ErrorCollector + errors: ErrorCollector, ) = Unit override fun validateExtension(protoType: ProtoType, errors: ErrorCollector) = Unit override fun validateEnumConstants( constants: List, - errors: ErrorCollector + errors: ErrorCollector, ) = Unit override fun validateTypeReference(type: Type?, errors: ErrorCollector) = Unit override fun isPackedByDefault( type: ProtoType, - label: Field.Label? + label: Field.Label?, ): Boolean = false override fun getEncodeMode( protoType: ProtoType, label: Field.Label?, isPacked: Boolean, - isOneOf: Boolean + isOneOf: Boolean, ): Field.EncodeMode { return when (label) { Field.Label.REPEATED -> - if (isPacked) Field.EncodeMode.PACKED - else Field.EncodeMode.REPEATED + if (isPacked) { + Field.EncodeMode.PACKED + } else { + Field.EncodeMode.REPEATED + } Field.Label.OPTIONAL -> Field.EncodeMode.NULL_IF_ABSENT Field.Label.REQUIRED -> Field.EncodeMode.REQUIRED Field.Label.ONE_OF, - null -> if (protoType.isMap) Field.EncodeMode.MAP else Field.EncodeMode.NULL_IF_ABSENT + null, + -> if (protoType.isMap) Field.EncodeMode.MAP else Field.EncodeMode.NULL_IF_ABSENT } } @@ -117,7 +122,7 @@ interface SyntaxRules { override fun isPackedByDefault( type: ProtoType, - label: Field.Label? + label: Field.Label?, ): Boolean { return label == Field.Label.REPEATED && type in ProtoType.NUMERIC_SCALAR_TYPES } @@ -126,7 +131,7 @@ interface SyntaxRules { protoType: ProtoType, label: Field.Label?, isPacked: Boolean, - isOneOf: Boolean + isOneOf: Boolean, ): Field.EncodeMode { if (label == Field.Label.REPEATED) { return if (isPacked) { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Target.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Target.kt index 03bfd17fd7..9a1f5b2c8b 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Target.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Target.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Type.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Type.kt index 98a18b4b20..63e879b88b 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Type.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Type.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -72,7 +72,7 @@ sealed class Type { fun fromElements( packageName: String?, elements: List, - syntax: Syntax + syntax: Syntax, ) = elements.map { val protoType = ProtoType.get(packageName, it.name) val namespaces = when { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/WireRun.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/WireRun.kt index d76eea5e32..31f2148952 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/WireRun.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/WireRun.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -359,19 +359,21 @@ class WireRun( if (rejectUnusedRootsOrPrunes) { throw IllegalStateException( buildList { - if (hasUnusedRoots) + if (hasUnusedRoots) { add( """Unused element(s) in roots: | ${pruningRules.unusedRoots().joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) - if (hasUnusedPrunes) + } + if (hasUnusedPrunes) { add( """Unused element(s) in prunes: | ${pruningRules.unusedPrunes().joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) - }.joinToString(separator = "\n") + } + }.joinToString(separator = "\n"), ) } else { if (hasUnusedRoots) { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/CommonSchemaLoader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/CommonSchemaLoader.kt index 959784b374..db04749dfc 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/CommonSchemaLoader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/CommonSchemaLoader.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -89,7 +89,7 @@ internal class CommonSchemaLoader : Loader, ProfileLoader { /** Initialize the [WireRun.sourcePath] and [WireRun.protoPath] from which files are loaded. */ fun initRoots( sourcePath: List, - protoPath: List = listOf() + protoPath: List = listOf(), ) { check(sourcePathRoots == null && protoPathRoots == null) sourcePathRoots = allRoots(sourcePath) @@ -152,7 +152,7 @@ internal class CommonSchemaLoader : Loader, ProfileLoader { |unable to find $path | searching ${protoPathRoots!!.size} proto paths: | ${protoPathRoots!!.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin() return ProtoFile.get(ProtoFileElement.empty(path)) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/DagChecker.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/DagChecker.kt index de0fb40c71..74cfddd087 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/DagChecker.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/DagChecker.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ package com.squareup.wire.schema.internal */ class DagChecker( private val nodes: Iterable, - private val edges: (N) -> Iterable + private val edges: (N) -> Iterable, ) { private var nextDiscoveryId = 0 private val tags = nodes.associateWith { Tag(it) } @@ -105,7 +105,7 @@ class DagChecker( } private class Tag( - var node: N + var node: N, ) { var discoveryId = -1 var lowestConnectedDiscoveryId = -1 diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileFileElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileFileElement.kt index c425df8f15..6b3600536e 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileFileElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileFileElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -55,7 +55,7 @@ data class ProfileFileElement( val location: Location, val packageName: String? = null, val imports: List = emptyList(), - val typeConfigs: List = emptyList() + val typeConfigs: List = emptyList(), ) { fun toSchema() = buildString { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileParser.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileParser.kt index 02effd6271..e8f30f1407 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileParser.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/ProfileParser.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ import com.squareup.wire.schema.internal.parser.SyntaxReader /** Parses `.wire` files. */ class ProfileParser( private val location: Location, - data: String + data: String, ) { private val reader = SyntaxReader(data.toCharArray(), location) private val imports = mutableListOf() @@ -47,7 +47,7 @@ class ProfileParser( location = location, packageName = packageName, imports = imports, - typeConfigs = typeConfigs + typeConfigs = typeConfigs, ) } @@ -78,7 +78,7 @@ class ProfileParser( /** Reads a type config and returns it. */ private fun readTypeConfig( location: Location, - documentation: String + documentation: String, ): TypeConfigElement { val name = reader.readDataType() val withOptions = mutableListOf() @@ -116,7 +116,7 @@ class ProfileParser( documentation = documentation, with = withOptions, target = target, - adapter = adapter + adapter = adapter, ) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/SchemaEncoder.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/SchemaEncoder.kt index c02f1869e3..a3076a5383 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/SchemaEncoder.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/SchemaEncoder.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -57,7 +57,7 @@ import okio.ByteString.Companion.toByteString * commented out below. */ class SchemaEncoder( - private val schema: Schema + private val schema: Schema, ) { private val fileOptionsProtoAdapter = schema.protoAdapter(Options.FILE_OPTIONS.toString(), false) @@ -90,14 +90,15 @@ class SchemaEncoder( // TODO(jwilson): can extension fields be maps? for (extend in value.extendList.reversed()) { fieldEncoder.asRepeated().encodeWithTag( - writer, 7, + writer, + 7, extend.fields.map { EncodedField( syntax = value.syntax, field = it, - extendee = extend.type!!.dotName + extendee = extend.type!!.dotName, ) - } + }, ) } @@ -129,7 +130,7 @@ class SchemaEncoder( EncodedField( syntax = syntax, field = it, - oneOfIndex = encodedOneOfs.size + oneOfIndex = encodedOneOfs.size, ) } encodedOneOfs.add(EncodedOneOf(oneOf.name, fields = oneOfFields)) @@ -142,7 +143,7 @@ class SchemaEncoder( var encodedField = EncodedField( syntax = syntax, field = field, - type = syntheticMap?.fieldType ?: field.type!! + type = syntheticMap?.fieldType ?: field.type!!, ) if (encodedField.isProto3Optional) { encodedField = encodedField.copy(oneOfIndex = encodedOneOfs.size) @@ -199,7 +200,7 @@ class SchemaEncoder( */ private fun collectSyntheticMapEntries( enclosingTypeOrPackage: String?, - fields: List + fields: List, ): Map { val result = mutableMapOf() for (field in fields) { @@ -210,7 +211,7 @@ class SchemaEncoder( enclosingTypeOrPackage = enclosingTypeOrPackage, name = name, keyType = fieldType.keyType!!, - valueType = fieldType.valueType!! + valueType = fieldType.valueType!!, ) } } @@ -221,7 +222,7 @@ class SchemaEncoder( enclosingTypeOrPackage: String?, val name: String, val keyType: ProtoType, - val valueType: ProtoType + val valueType: ProtoType, ) { val fieldType = ProtoType.get(enclosingTypeOrPackage, name) } @@ -268,7 +269,7 @@ class SchemaEncoder( val field: Field, val type: ProtoType = field.type!!, val extendee: String? = null, - val oneOfIndex: Int? = null + val oneOfIndex: Int? = null, ) { val isProto3Optional get() = syntax == Syntax.PROTO_3 && field.label == Field.Label.OPTIONAL @@ -336,7 +337,7 @@ class SchemaEncoder( private class EncodedOneOf( val name: String, - val fields: List = listOf() + val fields: List = listOf(), ) private val oneOfEncoder: Encoder = object : Encoder() { @@ -405,7 +406,10 @@ class SchemaEncoder( /** Encodes a synthetic map type. */ private abstract class Encoder : ProtoAdapter( - FieldEncoding.LENGTH_DELIMITED, null, null, Syntax.PROTO_2 + FieldEncoding.LENGTH_DELIMITED, + null, + null, + Syntax.PROTO_2, ) { override fun redact(value: T) = value override fun encodedSize(value: T): Int = throw UnsupportedOperationException() diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeConfigElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeConfigElement.kt index 5ed934fb60..794a9be2de 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeConfigElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeConfigElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,7 +28,7 @@ data class TypeConfigElement( val documentation: String = "", val with: List = emptyList(), val target: String? = null, - val adapter: String? = null + val adapter: String? = null, ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeMover.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeMover.kt index 76f2041a2b..a21d0b6885 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeMover.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/TypeMover.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,7 +32,7 @@ import com.squareup.wire.schema.Type */ class TypeMover( private val oldSchema: Schema, - private val moves: List + private val moves: List, ) { /** The working copy of proto files. This is mutated as we perform the moves. */ private val pathToFile = oldSchema.protoFiles.associateBy { it.location.path }.toMutableMap() @@ -158,7 +158,7 @@ class TypeMover( return copy( imports = newImports, - publicImports = newPublicImports + publicImports = newPublicImports, ) } @@ -232,6 +232,6 @@ class TypeMover( data class Move( val type: ProtoType, - val targetPath: String + val targetPath: String, ) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/Util.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/Util.kt index bc5d73be62..4347858347 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/Util.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/Util.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,7 +29,7 @@ import okio.Path.Companion.toPath // TODO internal and friend for wire-java-generator: https://youtrack.jetbrains.com/issue/KT-34102 fun StringBuilder.appendDocumentation( - documentation: String + documentation: String, ) { if (documentation.isEmpty()) { return @@ -46,7 +46,7 @@ fun StringBuilder.appendDocumentation( } internal fun StringBuilder.appendOptions( - options: List + options: List, ) { val count = options.size if (count == 1) { @@ -65,7 +65,7 @@ internal fun StringBuilder.appendOptions( // TODO internal and friend for wire-java-generator: https://youtrack.jetbrains.com/issue/KT-34102 fun StringBuilder.appendIndented( - value: String + value: String, ) { var lines = value.split("\n") if (lines.count() > 1 && lines.last().isEmpty()) { @@ -117,10 +117,10 @@ fun Schema.withStubs(typesToStub: Set): Schema { }, services = protoFile.services.map { service -> if (service.type in typesToStub) service.asStub() else service - } + }, ) return@map result - } + }, ) } @@ -133,16 +133,16 @@ private fun Type.asStub(): Type = when { declaredFields = emptyList(), extensionFields = mutableListOf(), nestedTypes = nestedTypes.map { it.asStub() }, - options = Options(Options.MESSAGE_OPTIONS, emptyList()) + options = Options(Options.MESSAGE_OPTIONS, emptyList()), ) this is EnumType -> copy( constants = emptyList(), - options = Options(Options.ENUM_OPTIONS, emptyList()) + options = Options(Options.ENUM_OPTIONS, emptyList()), ) this is EnclosingType -> copy( - nestedTypes = nestedTypes.map { it.asStub() } + nestedTypes = nestedTypes.map { it.asStub() }, ) else -> throw AssertionError("Unknown type $type") @@ -151,7 +151,7 @@ private fun Type.asStub(): Type = when { /** Return a copy of this service with all possible type references removed. */ private fun Service.asStub() = copy( rpcs = emptyList(), - options = Options(Options.SERVICE_OPTIONS, emptyList()) + options = Options(Options.SERVICE_OPTIONS, emptyList()), ) fun Path.withUnixSlashes(): Path { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumConstantElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumConstantElement.kt index f80466e8dc..ab868a9b8c 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumConstantElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumConstantElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ data class EnumConstantElement( val name: String, val tag: Int, val documentation: String = "", - val options: List = emptyList() + val options: List = emptyList(), ) { fun toSchema() = buildString { diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumElement.kt index 63a0d2c62d..2ff6ff2ec2 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/EnumElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtendElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtendElement.kt index 4455d2b2ef..dea619d363 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtendElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtendElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ data class ExtendElement( val location: Location, val name: String, val documentation: String = "", - val fields: List = emptyList() + val fields: List = emptyList(), ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElement.kt index 763fa80715..1059bb2cc1 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ data class ExtensionsElement( val location: Location, val documentation: String = "", /** An [Int] or [IntRange] tag. */ - val values: List + val values: List, ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/FieldElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/FieldElement.kt index cedbf6a7db..006e2b3cc6 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/FieldElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/FieldElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,7 +31,7 @@ data class FieldElement( val jsonName: String? = null, val tag: Int = 0, val documentation: String = "", - val options: List = emptyList() + val options: List = emptyList(), ) { fun toSchema() = buildString { appendDocumentation(documentation) @@ -64,8 +64,11 @@ data class FieldElement( } options = - if (jsonName == null) options - else options + OptionElement.create("json_name", OptionElement.Kind.STRING, jsonName) + if (jsonName == null) { + options + } else { + options + OptionElement.create("json_name", OptionElement.Kind.STRING, jsonName) + } return options } @@ -87,7 +90,8 @@ data class FieldElement( "sint32", "sint64", "uint32", - "uint64" -> OptionElement.Kind.NUMBER + "uint64", + -> OptionElement.Kind.NUMBER else -> OptionElement.Kind.ENUM } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/GroupElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/GroupElement.kt index 4e03e5ed95..c9cabb84bb 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/GroupElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/GroupElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ data class GroupElement( val name: String, val tag: Int, val documentation: String = "", - val fields: List = emptyList() + val fields: List = emptyList(), ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/MessageElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/MessageElement.kt index 908d85384e..4a8cbe4290 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/MessageElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/MessageElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OneOfElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OneOfElement.kt index fe691c9980..ac6542feb4 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OneOfElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OneOfElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionElement.kt index 6c0540d513..8c29e67aca 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,7 +31,7 @@ data class OptionElement( val kind: Kind, val value: Any, /** If true, this [OptionElement] is a custom option. */ - val isParenthesized: Boolean + val isParenthesized: Boolean, ) { enum class Kind { STRING, @@ -40,7 +40,7 @@ data class OptionElement( ENUM, MAP, LIST, - OPTION + OPTION, } /** An internal representation of the Option primitive types. */ @@ -53,7 +53,8 @@ data class OptionElement( STRING -> append("""$formattedName = "$value"""") BOOLEAN, NUMBER, - ENUM -> append("$formattedName = $value") + ENUM, + -> append("$formattedName = $value") OPTION -> { // Treat nested options as non-parenthesized always, prevents double parentheses. val optionValue = (value as OptionElement).copy() @@ -77,7 +78,7 @@ data class OptionElement( private fun formatOptionMap( builder: StringBuilder, - valueMap: Map + valueMap: Map, ) { val lastIndex = valueMap.size - 1 valueMap.entries.forEachIndexed { index, entry -> @@ -95,7 +96,8 @@ data class OptionElement( when (value.kind) { BOOLEAN, NUMBER, - ENUM -> { + ENUM, + -> { append("${value.value}") } else -> append(formatOptionMapValue(value.value)) @@ -134,7 +136,7 @@ data class OptionElement( name: String, kind: Kind, value: Any, - isParenthesized: Boolean = false + isParenthesized: Boolean = false, ) = OptionElement(name, kind, value, isParenthesized) } } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionReader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionReader.kt index 292682709b..34b93bc91a 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionReader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/OptionReader.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -79,6 +79,7 @@ class OptionReader(internal val reader: SyntaxReader) { var value = kindAndValue.value subNames.reversed().forEach { subName -> var parenthesized = false + @Suppress("NAME_SHADOWING") var name = subName if (name.startsWith("(")) { @@ -117,7 +118,7 @@ class OptionReader(internal val reader: SyntaxReader) { private fun readMap( openBrace: Char, closeBrace: Char, - keyValueSeparator: Char + keyValueSeparator: Char, ): Map { if (reader.readChar() != openBrace) throw AssertionError() val result = mutableMapOf() @@ -168,7 +169,7 @@ class OptionReader(internal val reader: SyntaxReader) { /** Adds an object or objects to a List. */ private fun addToList( list: MutableList, - value: Any + value: Any, ) { if (value is List<*>) { @Suppress("UNCHECKED_CAST") @@ -203,6 +204,6 @@ class OptionReader(internal val reader: SyntaxReader) { internal data class KindAndValue( internal val kind: Kind, - internal val value: Any + internal val value: Any, ) } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElement.kt index 7eb1fa0c14..af2bbce211 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,7 +29,7 @@ data class ProtoFileElement( val types: List = emptyList(), val services: List = emptyList(), val extendDeclarations: List = emptyList(), - val options: List = emptyList() + val options: List = emptyList(), ) { fun toSchema() = buildString { append("// Proto schema formatted by Wire, do not edit.\n") diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt index 7db5ff5fd7..5df7c0a9f7 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ProtoParser.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ import okio.Path.Companion.toPath /** Basic parser for `.proto` schema declarations. */ class ProtoParser internal constructor( private val location: Location, - data: CharArray + data: CharArray, ) { private val reader: SyntaxReader = SyntaxReader(data, location) private val publicImports = mutableListOf() @@ -62,7 +62,7 @@ class ProtoParser internal constructor( types = nestedTypes, services = services, extendDeclarations = extendsList, - options = options + options = options, ) } @@ -72,7 +72,7 @@ class ProtoParser internal constructor( if (duplicate != null) { error( "${declaration.name} (${declaration.location}) is already defined at " + - "${duplicate.location}" + "${duplicate.location}", ) } nestedTypes.add(declaration) @@ -82,7 +82,7 @@ class ProtoParser internal constructor( if (duplicate != null) { error( "${declaration.name} (${declaration.location}) is already defined at " + - "${duplicate.location}" + "${duplicate.location}", ) } services.add(declaration) @@ -176,7 +176,7 @@ class ProtoParser internal constructor( /** Reads a message declaration. */ private fun readMessage( location: Location, - documentation: String + documentation: String, ): MessageElement { val name = reader.readName() val fields = mutableListOf() @@ -221,7 +221,7 @@ class ProtoParser internal constructor( oneOfs = oneOfs, extensions = extensions, groups = groups, - extendDeclarations = extendDeclarations + extendDeclarations = extendDeclarations, ) } @@ -245,7 +245,7 @@ class ProtoParser internal constructor( location = location, name = name, documentation = documentation, - fields = fields + fields = fields, ) } @@ -272,14 +272,14 @@ class ProtoParser internal constructor( name = name, documentation = documentation, rpcs = rpcs, - options = options + options = options, ) } /** Reads an enumerated type declaration and returns it. */ private fun readEnumElement( location: Location, - documentation: String + documentation: String, ): EnumElement { val name = reader.readName() val constants = mutableListOf() @@ -328,7 +328,7 @@ class ProtoParser internal constructor( reader.expect( syntax == PROTO_3 || (word == "map" && reader.peekChar() == '<'), - location + location, ) { "unexpected label: $word" } @@ -352,7 +352,7 @@ class ProtoParser internal constructor( location: Location, documentation: String, label: Field.Label?, - type: String + type: String, ): FieldElement { val name = reader.readName(allowLeadingDigit = false) reader.require('=') @@ -377,7 +377,7 @@ class ProtoParser internal constructor( jsonName = jsonName, tag = tag, documentation = documentation, - options = options.toList() + options = options.toList(), ) } @@ -442,7 +442,7 @@ class ProtoParser internal constructor( private fun readGroup( location: Location, documentation: String, - label: Field.Label? + label: Field.Label?, ): GroupElement { val name = reader.readWord() reader.require('=') @@ -468,7 +468,7 @@ class ProtoParser internal constructor( name = name, tag = tag, documentation = documentation, - fields = fields + fields = fields, ) } @@ -514,14 +514,14 @@ class ProtoParser internal constructor( return ReservedElement( location = location, documentation = documentation, - values = values + values = values, ) } /** Reads extensions like "extensions 101;" or "extensions 101 to max;". */ private fun readExtensions( location: Location, - documentation: String + documentation: String, ): ExtensionsElement { val values = mutableListOf() loop@ while (true) { @@ -548,7 +548,7 @@ class ProtoParser internal constructor( return ExtensionsElement( location = location, documentation = documentation, - values = values + values = values, ) } @@ -556,7 +556,7 @@ class ProtoParser internal constructor( private fun readEnumConstant( documentation: String, location: Location, - label: String + label: String, ): EnumConstantElement { reader.require('=') val tag = reader.readInt() @@ -572,7 +572,7 @@ class ProtoParser internal constructor( name = label, tag = tag, documentation = documentation, - options = options + options = options, ) } @@ -621,7 +621,7 @@ class ProtoParser internal constructor( responseType = responseType, requestStreaming = requestStreaming, responseStreaming = responseStreaming, - options = options + options = options, ) } @@ -631,7 +631,8 @@ class ProtoParser internal constructor( ENUM, RPC, EXTEND, - SERVICE; + SERVICE, + ; fun permitsPackage() = this == FILE diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ReservedElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ReservedElement.kt index 42fe72e5b2..9d1f8a3c2b 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ReservedElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ReservedElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ data class ReservedElement( val location: Location, val documentation: String = "", /** A [String] name or [Int] or [IntRange] tag. */ - val values: List + val values: List, ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/RpcElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/RpcElement.kt index cf4bcf9631..07aa1ed8c5 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/RpcElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/RpcElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ data class RpcElement( val responseType: String, val requestStreaming: Boolean = false, val responseStreaming: Boolean = false, - val options: List = emptyList() + val options: List = emptyList(), ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ServiceElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ServiceElement.kt index c36e3b8331..ca4c2a5053 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ServiceElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/ServiceElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ data class ServiceElement( val name: String, val documentation: String = "", val rpcs: List = emptyList(), - val options: List = emptyList() + val options: List = emptyList(), ) { fun toSchema() = buildString { appendDocumentation(documentation) diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/SyntaxReader.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/SyntaxReader.kt index 9ba5c1f704..1c2015bcae 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/SyntaxReader.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/SyntaxReader.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,7 @@ import com.squareup.wire.schema.Location /** A general purpose reader for formats like `.proto`. */ class SyntaxReader( private val data: CharArray, - private val location: Location + private val location: Location, ) { /** Our cursor within the document. `data[pos]` is the next character to be read. */ private var pos = 0 @@ -420,6 +420,6 @@ class SyntaxReader( fun unexpected( message: String, - location: Location? = location() + location: Location? = location(), ): RuntimeException = throw IllegalStateException("Syntax error in $location: $message") } diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/TypeElement.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/TypeElement.kt index d76da40ba9..83087f6f0f 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/TypeElement.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/internal/parser/TypeElement.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/CoreLoader.kt b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/CoreLoader.kt index a5444f84e5..73401b62c2 100644 --- a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/CoreLoader.kt +++ b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/CoreLoader.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Multimap.kt b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Multimap.kt index 43d3051522..9636e2c0fc 100644 --- a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Multimap.kt +++ b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Multimap.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Profile.kt b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Profile.kt index 0c35a6ad7c..15ca0cf72a 100644 --- a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Profile.kt +++ b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Profile.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Roots.kt b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Roots.kt index 3ecba3654e..d950ba49f3 100644 --- a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Roots.kt +++ b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/Roots.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import okio.Path internal actual fun Path.roots( fileSystem: FileSystem, - location: Location + location: Location, ): List { val symlinkTarget = fileSystem.metadataOrNull(this)?.symlinkTarget val path = symlinkTarget ?: this @@ -38,7 +38,8 @@ internal actual fun Path.roots( else -> throw IllegalArgumentException( """ |expected a directory, or .proto: $path - |archive (.zip / .jar / etc.) are not supported in JS""".trimMargin() + |archive (.zip / .jar / etc.) are not supported in JS + """.trimMargin(), ) } } diff --git a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt index f67936a63e..4cb4046dc6 100644 --- a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt +++ b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -55,7 +55,7 @@ actual class SchemaLoader : Loader, ProfileLoader { /** Initialize the [WireRun.sourcePath] and [WireRun.protoPath] from which files are loaded. */ actual fun initRoots( sourcePath: List, - protoPath: List + protoPath: List, ) { delegate.initRoots(sourcePath, protoPath) } diff --git a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/internal/UtilJS.kt b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/internal/UtilJS.kt index b953ad54f3..0995a3aedc 100644 --- a/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/internal/UtilJS.kt +++ b/wire-schema/src/jsMain/kotlin/com/squareup/wire/schema/internal/UtilJS.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt index 81e1727f07..9149b3413e 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/AdapterConstant.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ import com.squareup.kotlinpoet.ClassName as KClassName data class AdapterConstant( @JvmField val javaClassName: ClassName, @JvmField val kotlinClassName: KClassName, - @JvmField val memberName: String + @JvmField val memberName: String, ) { companion object { operator fun invoke(adapter: String): AdapterConstant { @@ -35,7 +35,7 @@ data class AdapterConstant( return AdapterConstant( javaClassName = ClassName.bestGuess(names[0]), kotlinClassName = KClassName.bestGuess(names[0]), - memberName = names[1] + memberName = names[1], ) } } diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/CoreLoader.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/CoreLoader.kt index 4ce79239ac..c7f0759644 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/CoreLoader.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/CoreLoader.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/EventListeners.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/EventListeners.kt index c83564a020..a27eea5d3a 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/EventListeners.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/EventListeners.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -30,7 +30,7 @@ fun newEventListenerFactory(eventListenerFactoryClass: String): EventListener.Fa * even if the delegate event listener class is itself not serializable. */ private class ClassNameEventListenerFactory( - private val eventListenerFactoryClass: String + private val eventListenerFactoryClass: String, ) : EventListener.Factory { @Transient private var cachedDelegate: EventListener.Factory? = null diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Multimap.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Multimap.kt index ea0fd4f3c4..b096e14dc4 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Multimap.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Multimap.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt index 30633aaa97..1e83ff2fd6 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Profile.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,16 +17,16 @@ package com.squareup.wire.schema import com.squareup.javapoet.ClassName import com.squareup.javapoet.TypeName -import com.squareup.wire.schema.internal.ProfileFileElement import com.squareup.kotlinpoet.ClassName as KClassName import com.squareup.kotlinpoet.TypeName as KTypeName +import com.squareup.wire.schema.internal.ProfileFileElement /** * Describes how to map `.proto` to `.java`. A single repository of `.proto` files * may have multiple profiles; for example a project may target both Android and Java. */ actual class Profile actual constructor( - private val profileFiles: List + private val profileFiles: List, ) { fun javaTarget(type: ProtoType): TypeName? { val typeConfig = typeConfig(type) diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Roots.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Roots.kt index f018b1e885..8a122a4227 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Roots.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/Roots.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,7 @@ import okio.openZip internal actual fun Path.roots( fileSystem: FileSystem, - location: Location + location: Location, ): List { val symlinkTarget = fileSystem.metadataOrNull(this)?.symlinkTarget val path = symlinkTarget ?: this @@ -45,7 +45,7 @@ internal actual fun Path.roots( listOf(DirectoryRoot(location.path, sourceFs, "/".toPath())) } catch (_: IOException) { throw IllegalArgumentException( - "expected a directory, archive (.zip / .jar / etc.), or .proto: $path" + "expected a directory, archive (.zip / .jar / etc.), or .proto: $path", ) } } diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt index eed9e1c6df..980602bff9 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/SchemaLoader.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,8 +17,8 @@ package com.squareup.wire.schema import com.squareup.wire.schema.internal.CommonSchemaLoader import com.squareup.wire.schema.internal.toOkioFileSystem -import okio.FileSystem import java.nio.file.FileSystem as NioFileSystem +import okio.FileSystem actual class SchemaLoader : Loader, ProfileLoader { private val delegate: CommonSchemaLoader @@ -59,7 +59,7 @@ actual class SchemaLoader : Loader, ProfileLoader { /** Initialize the [WireRun.sourcePath] and [WireRun.protoPath] from which files are loaded. */ actual fun initRoots( sourcePath: List, - protoPath: List + protoPath: List, ) { delegate.initRoots(sourcePath, protoPath) } diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt index a27f6ef6b8..3ebd7cacd9 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,7 @@ * limitations under the License. */ @file:JvmName("JvmLanguages") + package com.squareup.wire.schema.internal import com.squareup.wire.ProtoAdapter diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/UtilJVM.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/UtilJVM.kt index d4464924d2..0d284f62c7 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/UtilJVM.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/UtilJVM.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/fileSystems.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/fileSystems.kt index d9ef74c10d..895b7d5e1b 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/fileSystems.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/fileSystems.kt @@ -1,11 +1,11 @@ /* - * Copyright (C) 2022 Block, Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,11 +15,11 @@ */ package com.squareup.wire.schema.internal -import okio.BufferedSource -import okio.ByteString.Companion.decodeHex import java.nio.charset.Charset import java.nio.file.FileSystem import java.nio.file.FileSystems +import okio.BufferedSource +import okio.ByteString.Companion.decodeHex internal fun FileSystem.toOkioFileSystem(): okio.FileSystem { return when { @@ -33,7 +33,7 @@ private val UNICODE_BOMS = okio.Options.of( "feff".decodeHex(), // UTF-16BE "fffe".decodeHex(), // UTF-16LE "0000ffff".decodeHex(), // UTF-32BE - "ffff0000".decodeHex() // UTF-32LE + "ffff0000".decodeHex(), // UTF-32LE ) internal fun BufferedSource.readBomAsCharset(default: Charset = Charsets.UTF_8): Charset { diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/DynamicSerializationTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/DynamicSerializationTest.kt index 9250dad9f9..15eab4c88b 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/DynamicSerializationTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/DynamicSerializationTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -56,7 +56,8 @@ class DynamicSerializationTest { | google.protobuf.StringValue string_value_field = 15; | google.protobuf.BytesValue bytes_value_field = 16; |} - |""".trimMargin(), + | + """.trimMargin(), ) } @@ -93,7 +94,8 @@ class DynamicSerializationTest { |message Message { | map currencies = 1; |} - |""".trimMargin(), + | + """.trimMargin(), ) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/EmittingRulesTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/EmittingRulesTest.kt index 12b7b9635e..a087ffa8af 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/EmittingRulesTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/EmittingRulesTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,9 +15,9 @@ */ package com.squareup.wire.schema +import kotlin.test.fail import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.fail class EmittingRulesTest { @Test diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ManifestPartitionTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ManifestPartitionTest.kt index 518f475e0d..4756b461a7 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ManifestPartitionTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ManifestPartitionTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,7 +37,8 @@ class ManifestPartitionTest { |} |message C { |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -46,14 +47,14 @@ class ManifestPartitionTest { pruningRules = PruningRules.Builder() .addRoot("B") .prune("C") - .build() + .build(), ), "feature" to Module( dependencies = setOf("common"), pruningRules = PruningRules.Builder() .addRoot("A") - .build() - ) + .build(), + ), ) val partitionedSchema = schema.partition(modules) @@ -85,7 +86,8 @@ class ManifestPartitionTest { |} |message C { |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -94,14 +96,14 @@ class ManifestPartitionTest { pruningRules = PruningRules.Builder() .addRoot("B") .prune("C") - .build() + .build(), ), "feature" to Module( dependencies = setOf("common"), pruningRules = PruningRules.Builder() .addRoot("A") - .build() - ) + .build(), + ), ) val partitionedSchema = schema.partition(modules) @@ -135,7 +137,8 @@ class ManifestPartitionTest { |} |message C { |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -144,20 +147,20 @@ class ManifestPartitionTest { pruningRules = PruningRules.Builder() .addRoot("B") .prune("C") - .build() + .build(), ), "feature1" to Module( dependencies = setOf("common"), pruningRules = PruningRules.Builder() .addRoot("A") - .build() + .build(), ), "feature2" to Module( dependencies = setOf("common"), pruningRules = PruningRules.Builder() .addRoot("A") - .build() - ) + .build(), + ), ) val partitionedSchema = schema.partition(modules) @@ -167,7 +170,7 @@ class ManifestPartitionTest { |C is generated twice in peer modules feature1 and feature2. | Consider moving this type into a common dependency of both modules. | To suppress this warning, explicitly add the type to the roots of both modules. - """.trimMargin() + """.trimMargin(), ) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/OptionsTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/OptionsTest.kt index 0b647fd4ef..4fd126e471 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/OptionsTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/OptionsTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -42,7 +42,7 @@ class OptionsTest { | optional int32 a = 1 [(foo_options).opt1 = 123, (foo_options).opt2 = "baz"]; | optional int32 b = 2 [(foo_options) = { opt1: 456 opt2: "quux" }]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -78,7 +78,7 @@ class OptionsTest { |message Message { | optional int32 b = 2 [(foo) = { bar { baz: 123 } }]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -133,7 +133,7 @@ class OptionsTest { | | optional int32 b = 2; |} - """.trimMargin() + """.trimMargin(), ) } @@ -152,7 +152,8 @@ class OptionsTest { | HTTP, | HTTPS | ] - |}""".trimMargin() + |} + """.trimMargin(), ) val foo = ProtoMember.get(Options.MESSAGE_OPTIONS, "foo") @@ -170,9 +171,9 @@ class OptionsTest { foo to arrayListOf( mapOf(name to "test", type to "STRING", schemes to listOf("HTTP", "HTTPS")), - mapOf(name to "test2", type to "NUMBER", schemes to listOf("HTTP", "HTTPS")) - ) - ) + mapOf(name to "test2", type to "NUMBER", schemes to listOf("HTTP", "HTTPS")), + ), + ), ) } @@ -194,7 +195,7 @@ class OptionsTest { |message MoreOptions { | extensions 100 to 200; |} - """.trimMargin() + """.trimMargin(), ) add( "a/c/event_more_options.proto".toPath(), @@ -211,7 +212,7 @@ class OptionsTest { |message EvenMoreOptions { | optional string string_option = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "a/d/message.proto".toPath(), @@ -227,7 +228,7 @@ class OptionsTest { | [a.c.even_more_options]: {string_option: "foo"} | }; |} - """.trimMargin() + """.trimMargin(), ) } val moreOptionsType = ProtoType.get("a.b.MoreOptions") @@ -330,7 +331,7 @@ class OptionsTest { |extend google.protobuf.EnumValueOptions { | optional MyOption my_option = 1000; |} - """.trimMargin() + """.trimMargin(), ) } @@ -349,9 +350,9 @@ class OptionsTest { mapOf("key-3" to mapOf()), mapOf("key-4" to null), mapOf("key-5" to mapOf(someString to "value-5", someInt32 to "5")), - ) - ) - ) + ), + ), + ), ) } @@ -398,7 +399,7 @@ class OptionsTest { |extend google.protobuf.EnumValueOptions { | MyOption my_option = 1000; |} - """.trimMargin() + """.trimMargin(), ) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt index b5cdcbc73e..66cad29e39 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProfileLoaderTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,12 +18,12 @@ package com.squareup.wire.schema import com.squareup.javapoet.ClassName import com.squareup.wire.testing.add import com.squareup.wire.testing.addZip +import java.io.IOException import okio.Path import okio.fakefilesystem.FakeFileSystem import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import java.io.IOException // TODO(Benoit) Move to `commonTest`. class ProfileLoaderTest { @@ -31,7 +31,8 @@ class ProfileLoaderTest { if (Path.DIRECTORY_SEPARATOR == "\\") emulateWindows() else emulateUnix() } - @Test @Throws(IOException::class) + @Test + @Throws(IOException::class) fun test() { fs.add( "source-path/a/b/message1.proto", @@ -39,7 +40,7 @@ class ProfileLoaderTest { |package a.b; |message Message1 { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/a/b/c/message2.proto", @@ -47,7 +48,7 @@ class ProfileLoaderTest { |package a.b.c; |message Message2 { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/android.wire", @@ -57,7 +58,7 @@ class ProfileLoaderTest { |type a.b.Message1 { | target java.lang.Object using com.example.Message1#OBJECT_ADAPTER; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/a/b/c/android.wire", @@ -68,7 +69,7 @@ class ProfileLoaderTest { |type a.b.c.Message2 { | target java.lang.String using com.example.Message2#STRING_ADAPTER; |} - """.trimMargin() + """.trimMargin(), ) val profile = loadAndLinkProfile("android") @@ -85,14 +86,15 @@ class ProfileLoaderTest { .isEqualTo(AdapterConstant("com.example.Message2#STRING_ADAPTER")) } - @Test @Throws(IOException::class) + @Test + @Throws(IOException::class) fun profileInZip() { fs.addZip( "/source/protos.zip", "a/b/message.proto" to """ |package a.b; |message Message {} - """.trimMargin(), + """.trimMargin(), "a/b/android.wire" to """ |syntax = "wire2"; |package a.b; @@ -100,12 +102,12 @@ class ProfileLoaderTest { |type a.b.Message { | target java.lang.Object using com.example.Message#ADAPTER; |} - """.trimMargin() + """.trimMargin(), ) val profile = loadAndLinkProfile( "android", - sourcePath = listOf(Location.get("/source/protos.zip")) + sourcePath = listOf(Location.get("/source/protos.zip")), ) val message = ProtoType.get("a.b.Message") @@ -122,7 +124,7 @@ class ProfileLoaderTest { |package a.b; |message Message { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/a/b/android.wire", @@ -131,7 +133,7 @@ class ProfileLoaderTest { |type a.b.Message2 { | target java.lang.Object using com.example.Message#OBJECT_ADAPTER; |} - """.trimMargin() + """.trimMargin(), ) val profile = loadAndLinkProfile("android") val message = ProtoType.get("a.b.Message") @@ -146,7 +148,7 @@ class ProfileLoaderTest { |package a.b; |message Message { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "source-path/a/b/android.wire", @@ -155,7 +157,7 @@ class ProfileLoaderTest { |type a.b.Message { | target java.lang.Object using com.example.Message#OBJECT_ADAPTER; |} - """.trimMargin() + """.trimMargin(), ) try { loadAndLinkProfile("android") @@ -163,14 +165,14 @@ class ProfileLoaderTest { } catch (expected: SchemaException) { assertThat(expected).hasMessage( "a/b/android.wire needs to import a/b/message.proto" + - " (source-path/a/b/android.wire:2:1)" + " (source-path/a/b/android.wire:2:1)", ) } } private fun loadAndLinkProfile( name: String, - sourcePath: List = listOf(Location.get("source-path")) + sourcePath: List = listOf(Location.get("source-path")), ): Profile { val loader = SchemaLoader(fs) loader.initRoots(sourcePath) diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoFileTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoFileTest.kt index 003e2335fc..33287918f6 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoFileTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoFileTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,7 @@ class ProtoFileTest { val element1 = MessageElement( location = location.at(11, 1), name = "Message1", - documentation = "Some comments about Message1" + documentation = "Some comments about Message1", ) val element2 = MessageElement( location = location.at(12, 1), @@ -43,18 +43,18 @@ class ProtoFileTest { location = location.at(13, 3), type = "string", name = "field", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val extend1 = ExtendElement( location = location.at(16, 1), - name = "Extend1" + name = "Extend1", ) val extend2 = ExtendElement( location = location.at(17, 1), - name = "Extend2" + name = "Extend2", ) val option1 = OptionElement.create("kit", OptionElement.Kind.STRING, "kat") val option2 = OptionElement.create("foo", OptionElement.Kind.STRING, "bar") @@ -68,14 +68,14 @@ class ProtoFileTest { requestType = "Message2", responseType = "Message1", options = listOf( - OptionElement.create("methodoption", OptionElement.Kind.NUMBER, 1) - ) - ) - ) + OptionElement.create("methodoption", OptionElement.Kind.NUMBER, 1), + ), + ), + ), ) val service2 = ServiceElement( location = location.at(24, 1), - name = "Service2" + name = "Service2", ) val fileElement = ProtoFileElement( location = location, @@ -85,7 +85,7 @@ class ProtoFileTest { types = listOf(element1, element2), services = listOf(service1, service2), extendDeclarations = listOf(extend1, extend2), - options = listOf(option1, option2) + options = listOf(option1, option2), ) val file = ProtoFile.get(fileElement) @@ -119,7 +119,8 @@ class ProtoFileTest { |} | |service Service2 {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) assertThat(file.toElement()).isEqualToComparingFieldByField(fileElement) diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoTypeTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoTypeTest.kt index 75c9e29ffa..f20817b932 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoTypeTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/ProtoTypeTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PrunerTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PrunerTest.kt index 7b3628e0e7..8e119b7b1c 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PrunerTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PrunerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,13 +35,13 @@ class PrunerTest { |} |message MessageB { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA") - .build() + .build(), ) assertThat(pruned.getType("MessageA")).isNotNull() assertThat(pruned.getType("MessageB")).isNull() @@ -58,13 +58,13 @@ class PrunerTest { | message MessageB { | } |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA") - .build() + .build(), ) assertThat(pruned.getType("MessageA")).isNotNull() assertThat(pruned.getField(ProtoMember.get("MessageA#maps"))).isNotNull() @@ -81,14 +81,14 @@ class PrunerTest { | message MessageB { | } |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA") .prune("MessageA#maps") - .build() + .build(), ) assertThat(pruned.getType("MessageA")).isNotNull() assertThat(pruned.getField(ProtoMember.get("MessageA#maps"))).isNull() @@ -108,13 +108,13 @@ class PrunerTest { | message D { | } |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("A.B") - .build() + .build(), ) assertThat(pruned.getType("A")).isInstanceOf(EnclosingType::class.java) assertThat(pruned.getType("A.B")).isInstanceOf(MessageType::class.java) @@ -138,13 +138,13 @@ class PrunerTest { |} |message MessageD { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA") - .build() + .build(), ) assertThat(pruned.getType("MessageA")).isNotNull() assertThat(pruned.getType("MessageB")).isNotNull() @@ -170,13 +170,13 @@ class PrunerTest { | rpc CallA (RequestA) returns (ResponseA); | rpc CallB (RequestB) returns (ResponseB); |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Service#CallA") - .build() + .build(), ) assertThat(pruned.getService("Service")!!.rpc("CallA")).isNotNull() assertThat(pruned.getType("RequestA")).isNotNull() @@ -198,13 +198,13 @@ class PrunerTest { |} |message MessageB { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA#b") - .build() + .build(), ) assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() assertThat((pruned.getType("MessageA") as MessageType).field("c")).isNull() @@ -228,13 +228,13 @@ class PrunerTest { |} |message MessageD { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA#b") - .build() + .build(), ) assertThat(pruned.getType("MessageA")).isNotNull() assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() @@ -259,13 +259,13 @@ class PrunerTest { | string baz = 4; | } |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("oneof.OneOfMessage") - .build() + .build(), ) val oneOfs = (pruned.getType("oneof.OneOfMessage") as MessageType).oneOfs assertThat(oneOfs).isNotEmpty() @@ -285,13 +285,13 @@ class PrunerTest { | } | optional string c = 3; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#c") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).oneOfs).isEmpty() } @@ -309,13 +309,13 @@ class PrunerTest { | } | optional string c = 3; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#b") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType val onlyOneOf = message.oneOfs.single() @@ -342,14 +342,14 @@ class PrunerTest { |} |message MessageD { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA#b") .addRoot("MessageB#c") - .build() + .build(), ) assertThat(pruned.getType("MessageA")).isNotNull() assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() @@ -371,13 +371,13 @@ class PrunerTest { | SCISSORS = 1; | PAPER = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Roshambo#SCISSORS") - .build() + .build(), ) assertThat((pruned.getType("Roshambo") as EnumType).constant("ROCK")).isNull() assertThat((pruned.getType("Roshambo") as EnumType).constant("SCISSORS")).isNotNull() @@ -398,14 +398,14 @@ class PrunerTest { | SCISSORS = 1; | PAPER = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") .addRoot("Roshambo#SCISSORS") - .build() + .build(), ) assertThat(pruned.getType("Message")).isNotNull() assertThat((pruned.getType("Message") as MessageType).field("roshambo")).isNotNull() @@ -428,13 +428,13 @@ class PrunerTest { |message Message { | optional string f = 1 [a = "a"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#f") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("f")).isNotNull() assertThat(pruned.getType("google.protobuf.FieldOptions") as MessageType).isNotNull() @@ -454,13 +454,13 @@ class PrunerTest { | optional string f = 1 [a = "a"]; | optional string g = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#g") - .build() + .build(), ) val fieldOptions = pruned.getType("google.protobuf.FieldOptions") as MessageType @@ -488,14 +488,14 @@ class PrunerTest { |message Message { | optional string f = 1 [some_field_options.a = "a"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") .addRoot("SomeFieldOptions#b") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("f")).isNotNull() assertThat((pruned.getType("SomeFieldOptions") as MessageType).field("a")).isNotNull() @@ -521,13 +521,13 @@ class PrunerTest { |message Message { | optional string f = 1 [some_field_options.a = "a"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("f")).isNotNull() assertThat((pruned.getType("SomeFieldOptions") as MessageType).field("a")).isNotNull() @@ -547,13 +547,13 @@ class PrunerTest { |extend Message { | optional string b = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("a")).isNotNull() assertThat((pruned.getType("Message") as MessageType).extensionField("b")).isNotNull() @@ -574,14 +574,14 @@ class PrunerTest { | optional string d = 4; | repeated string e = 5; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#a") .addRoot("Message#c") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("a")).isNotNull() assertThat((pruned.getType("Message") as MessageType).field("b")).isNull() @@ -605,13 +605,13 @@ class PrunerTest { | optional string d = 4; | repeated string e = 5; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("a")).isNotNull() assertThat((pruned.getType("Message") as MessageType).field("b")).isNotNull() @@ -635,13 +635,13 @@ class PrunerTest { | optional string d = 4; | repeated string e = 5; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#c") - .build() + .build(), ) assertThat((pruned.getType("Message") as MessageType).field("a")).isNull() assertThat((pruned.getType("Message") as MessageType).field("b")).isNull() @@ -672,13 +672,13 @@ class PrunerTest { |extend ExternalMessage { | repeated int32 extension_field = 121; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("squareup.Message") - .build() + .build(), ) val message = pruned.getType("squareup.Message") as MessageType assertThat(message.field("a")).isNotNull() @@ -699,13 +699,13 @@ class PrunerTest { | optional string b = 1; | optional string c = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("MessageA#c") - .build() + .build(), ) assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() assertThat((pruned.getType("MessageA") as MessageType).field("c")).isNull() @@ -721,14 +721,14 @@ class PrunerTest { | optional string b = 1; | optional string c = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA") .prune("MessageA#c") - .build() + .build(), ) assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() assertThat((pruned.getType("MessageA") as MessageType).field("c")).isNull() @@ -748,14 +748,14 @@ class PrunerTest { |} |message MessageC { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MessageA") .prune("MessageC") - .build() + .build(), ) assertThat(pruned.getType("MessageB")).isNotNull() assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() @@ -777,14 +777,14 @@ class PrunerTest { |} |message MessageC { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("ServiceA") .prune("MessageC") - .build() + .build(), ) assertThat(pruned.getType("MessageB")).isNotNull() assertThat(pruned.getService("ServiceA")!!.rpc("CallB")).isNotNull() @@ -806,14 +806,14 @@ class PrunerTest { |} |message MessageC { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("ServiceA") .prune("ServiceA#CallC") - .build() + .build(), ) assertThat(pruned.getType("MessageB")).isNotNull() assertThat(pruned.getService("ServiceA")!!.rpc("CallB")).isNotNull() @@ -838,7 +838,7 @@ class PrunerTest { |} |message MessageD { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( @@ -846,7 +846,7 @@ class PrunerTest { .addRoot("MessageA") .prune("MessageA#c") .prune("MessageA#d") - .build() + .build(), ) assertThat((pruned.getType("MessageA") as MessageType).field("b")).isNotNull() assertThat(pruned.getType("MessageB")).isNotNull() @@ -873,14 +873,14 @@ class PrunerTest { |message Message { | optional int32 c = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Enum") .prune("Enum#B") - .build() + .build(), ) assertThat((pruned.getType("Enum") as EnumType).constant("A")).isNotNull() assertThat((pruned.getType("Enum") as EnumType).constant("B")).isNull() @@ -901,13 +901,13 @@ class PrunerTest { |message Message { | optional string f = 1 [a = "a", b = "b"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("google.protobuf.FieldOptions#b") - .build() + .build(), ) val field = (pruned.getType("Message") as MessageType).field("f")!! assertThat(field.options.get(ProtoMember.get(FIELD_OPTIONS, "a"))).isEqualTo("a") @@ -931,13 +931,13 @@ class PrunerTest { |message Message { | optional string f = 1 [some_field_options.a = "a", b = "b"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("SomeFieldOptions") - .build() + .build(), ) val field = (pruned.getType("Message") as MessageType).field("f") val map = field!!.options.map @@ -963,17 +963,17 @@ class PrunerTest { |message Message { | optional string f = 1 [some_field_options = { a: "a", b: "b" }]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("SomeFieldOptions#b") - .build() + .build(), ) val field = (pruned.getType("Message") as MessageType).field("f") val map = field!!.options.get( - ProtoMember.get(FIELD_OPTIONS, "some_field_options") + ProtoMember.get(FIELD_OPTIONS, "some_field_options"), ) as Map<*, *> val onlyOption = map.entries.single() assertThat((onlyOption.key as ProtoMember).member).isEqualTo("a") @@ -996,7 +996,7 @@ class PrunerTest { | /* This is C. */ | C = 3; |} - """.trimMargin() + """.trimMargin(), ) } @@ -1033,13 +1033,13 @@ class PrunerTest { | b = "b" | ]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("Dimensions") - .build() + .build(), ) val field = (pruned.getType("Message") as MessageType).field("f") val map = field!!.options.map @@ -1062,13 +1062,13 @@ class PrunerTest { |message Message { | optional string f = 1 [ a = "a", b = "b" ]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("google.protobuf.FieldOptions") - .build() + .build(), ) val field = (pruned.getType("Message") as MessageType).field("f") assertThat(field!!.options.map).isEmpty() @@ -1092,13 +1092,13 @@ class PrunerTest { | option (b) = "b2"; | optional string f = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("google.protobuf.MessageOptions#a") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.options.get(ProtoMember.get(MESSAGE_OPTIONS, "a"))).isNull() @@ -1115,7 +1115,7 @@ class PrunerTest { |package a.b; |message MessageAB { |} - """.trimMargin() + """.trimMargin(), ) add( "a/c/messages.proto".toPath(), @@ -1123,13 +1123,13 @@ class PrunerTest { |package a.c; |message MessageAC { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("a.b.*") - .build() + .build(), ) assertThat(pruned.getType("a.b.MessageAB")).isNotNull() assertThat(pruned.getType("a.c.MessageAC")).isNull() @@ -1144,7 +1144,7 @@ class PrunerTest { |package a.b; |message MessageAB { |} - """.trimMargin() + """.trimMargin(), ) add( "a/c/messages.proto".toPath(), @@ -1152,13 +1152,13 @@ class PrunerTest { |package a.c; |message MessageAC { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("a.c.*") - .build() + .build(), ) assertThat(pruned.getType("a.b.MessageAB")).isNotNull() assertThat(pruned.getType("a.c.MessageAC")).isNull() @@ -1181,13 +1181,13 @@ class PrunerTest { | A = 1; | B = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .prune("google.protobuf.*") - .build() + .build(), ) val protoFile = pruned.protoFile("message.proto") assertThat(protoFile!!.javaPackage()).isEqualTo("p") @@ -1216,7 +1216,7 @@ class PrunerTest { |message Message { | optional Title title = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "title.proto".toPath(), @@ -1224,7 +1224,7 @@ class PrunerTest { |message Title { | optional string label = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "footer.proto".toPath(), @@ -1232,13 +1232,13 @@ class PrunerTest { |message Footer { | optional string label = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") - .build() + .build(), ) assertThat(pruned.protoFile("footer.proto")!!.types).isEmpty() @@ -1275,13 +1275,13 @@ class PrunerTest { | NZD = 554 [(cash_rounding) = 10, (rounding_mode) = DOWN_ON_HALF]; |} | - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("CurrencyCode") - .build() + .build(), ) assertThat(pruned.getType("RoundingMode")).isNotNull() @@ -1307,13 +1307,13 @@ class PrunerTest { |message Message { | optional string s = 1 [a = "a"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") - .build() + .build(), ) val fieldOptions = pruned.getType("google.protobuf.FieldOptions") as MessageType @@ -1345,13 +1345,13 @@ class PrunerTest { |message Message { | optional string s = 1 [message_option.a = "a"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") - .build() + .build(), ) val messageOption = pruned.getType("MessageOption") as MessageType @@ -1384,14 +1384,14 @@ class PrunerTest { |message Message { | optional string s = 1 [message_option.a = "a"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message") .addRoot("MessageOption#c") - .build() + .build(), ) val messageOption = pruned.getType("MessageOption") as MessageType @@ -1410,13 +1410,13 @@ class PrunerTest { | optional string a = 1; | optional string b = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("Message#a") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType @@ -1458,14 +1458,14 @@ class PrunerTest { | APOLLO = 3 [(style) = RUDE, (message_option) = {a: "some", c: "things"}]; | POSEIDON = 4 [deprecated = true]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("squareup.Author") .prune("google.protobuf.*") - .build() + .build(), ) assertThat(pruned.getType("squareup.Style")).isNull() @@ -1514,14 +1514,14 @@ class PrunerTest { | optional string author = 3 [(style) = RUDE, (message_option) = {a: "some", c: "things"}]; | optional string signature = 4 [default = "Sent from Wire"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("squareup.Letter") .prune("google.protobuf.*") - .build() + .build(), ) assertThat(pruned.getType("squareup.Style")).isNull() @@ -1556,14 +1556,14 @@ class PrunerTest { | optional string radio = 1 [(wire.until) = "1950"]; | optional string video = 2 [(wire.since) = "1950"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("1949") .until("1950") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("radio")).isNotNull() @@ -1582,13 +1582,13 @@ class PrunerTest { | optional string radio = 1 [(wire.until) = "1950"]; | optional string video = 2 [(wire.since) = "1950"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .only("1949") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("radio")).isNotNull() @@ -1607,14 +1607,14 @@ class PrunerTest { | optional string radio = 1 [(wire.until) = "1950"]; | optional string video = 2 [(wire.since) = "1950"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("1950") .until("1951") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("radio")).isNull() @@ -1633,13 +1633,13 @@ class PrunerTest { | optional string radio = 1 [(wire.until) = "1950"]; | optional string video = 2 [(wire.since) = "1950"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .only("1950") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("radio")).isNull() @@ -1663,14 +1663,14 @@ class PrunerTest { | optional string since_30 = 5 [(wire.since) = "30"]; | optional string since_31 = 6 [(wire.since) = "31"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("20") .until("30") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("since_19")).isNotNull() @@ -1699,14 +1699,14 @@ class PrunerTest { | optional string until_30 = 5 [(wire.until) = "30"]; | optional string until_31 = 6 [(wire.until) = "31"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("20") .until("30") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("until_19")).isNull() @@ -1734,13 +1734,13 @@ class PrunerTest { | optional string since_30 = 5 [(wire.since) = "30"]; | optional string since_31 = 6 [(wire.since) = "31"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .only("20") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("since_19")).isNotNull() @@ -1769,13 +1769,13 @@ class PrunerTest { | optional string until_30 = 5 [(wire.until) = "30"]; | optional string until_31 = 6 [(wire.until) = "31"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .only("20") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("until_19")).isNull() @@ -1798,7 +1798,7 @@ class PrunerTest { | optional string until_20 = 1 [(wire.until) = "20"]; | optional string since_20 = 2 [(wire.since) = "20"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune(PruningRules.Builder().build()) @@ -1818,14 +1818,14 @@ class PrunerTest { |message Message { | optional string always = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("20") .until("30") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("always")).isNotNull() @@ -1842,13 +1842,13 @@ class PrunerTest { |message Message { | optional string always = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .only("20") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("always")).isNotNull() @@ -1867,14 +1867,14 @@ class PrunerTest { | SCISSORS = 2 [(wire.constant_since) = "30"]; | PAPER = 3 [(wire.constant_since) = "29"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("29") .until("30") - .build() + .build(), ) val enum = pruned.getType("Roshambo") as EnumType assertThat(enum.constant("ROCK")).isNull() @@ -1895,13 +1895,13 @@ class PrunerTest { | SCISSORS = 2 [(wire.constant_since) = "30"]; | PAPER = 3 [(wire.constant_since) = "29"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .only("29") - .build() + .build(), ) val enum = pruned.getType("Roshambo") as EnumType assertThat(enum.constant("ROCK")).isNull() @@ -1924,14 +1924,14 @@ class PrunerTest { | optional string field_4 = 4 [(wire.since) = "1.0.0-beta"]; | optional string field_5 = 5 [(wire.since) = "1.0.0"]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .since("1.0.0-alpha.1") .until("1.0.0-beta") - .build() + .build(), ) val message = pruned.getType("Message") as MessageType assertThat(message.field("field_1")).isNull() @@ -1953,14 +1953,14 @@ class PrunerTest { |} |message MessageB { |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("wire.MessageA") .prune("wire.*") - .build() + .build(), ) assertThat(pruned.getType("wire.MessageA")).isNotNull() assertThat(pruned.getType("wire.MessageB")).isNull() @@ -1976,14 +1976,14 @@ class PrunerTest { | optional string a = 1; | optional string b = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MyMessage#a") .prune("MyMessage") - .build() + .build(), ) assertThat(pruned.getType("MyMessage")).isNotNull() val myMessageType = pruned.getType("MyMessage") as MessageType @@ -2001,14 +2001,14 @@ class PrunerTest { | A = 1; | B = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( PruningRules.Builder() .addRoot("MyEnum#A") .prune("MyEnum") - .build() + .build(), ) assertThat(pruned.getType("MyEnum")).isNotNull() val myEnumType = pruned.getType("MyEnum") as EnumType @@ -2036,7 +2036,7 @@ class PrunerTest { | optional string title = 1 [(wire.relevant) = true]; | optional string content = 2 [(wire.irrelevant) = true]; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( @@ -2044,7 +2044,7 @@ class PrunerTest { .addRoot("wire.Lecture") .addRoot("google.protobuf.FieldOptions#wire.relevant") .prune("google.protobuf.*") - .build() + .build(), ) val fieldOptions = pruned.getType("google.protobuf.FieldOptions") as MessageType assertThat(fieldOptions.extensionField("wire.relevant")).isNotNull() @@ -2073,7 +2073,7 @@ class PrunerTest { | C = 1; | D = 2; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( @@ -2081,7 +2081,7 @@ class PrunerTest { .prune("MyEnum#D") .addRoot("MyMessage#b") .prune("MyMessage") - .build() + .build(), ) assertThat(pruned.getType("MyMessage")).isNotNull() assertThat(pruned.getType("MyEnum")).isNotNull() @@ -2112,7 +2112,7 @@ class PrunerTest { |message Book { | optional string title = 1; |} - """.trimMargin() + """.trimMargin(), ) } val pruned = schema.prune( @@ -2121,7 +2121,7 @@ class PrunerTest { .addRoot("MessageB") .prune("Book") .prune("Stuff") - .build() + .build(), ) val messageA = pruned.getType("MessageA") as MessageType diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PruningRulesTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PruningRulesTest.kt index fbccf69359..c3a6ded94c 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PruningRulesTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/PruningRulesTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,9 +15,9 @@ */ package com.squareup.wire.schema +import kotlin.test.fail import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.fail class PruningRulesTest { @Test @@ -189,8 +189,9 @@ class PruningRulesTest { .addRoot("c.IncludedMember#member") .build() assertThat(set.unusedRoots()).containsExactly( - "a.*", "b.IncludedType", - "c.IncludedMember#member" + "a.*", + "b.IncludedType", + "c.IncludedMember#member", ) set.isRoot(ProtoType.get("a.*")) @@ -211,8 +212,9 @@ class PruningRulesTest { .prune("c.ExcludedMember#member") .build() assertThat(set.unusedPrunes()).containsExactly( - "a.*", "b.ExcludedType", - "c.ExcludedMember#member" + "a.*", + "b.ExcludedType", + "c.ExcludedMember#member", ) set.isRoot(ProtoType.get("a.*")) @@ -299,6 +301,6 @@ class PruningRulesTest { internal enum class Policy { INCLUDED, UNSPECIFIED, - EXCLUDED + EXCLUDED, } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/RootTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/RootTest.kt index 8503b29784..6c3a20463d 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/RootTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/RootTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,11 +17,11 @@ package com.squareup.wire.schema import com.squareup.wire.testing.add import com.squareup.wire.testing.addZip +import kotlin.test.assertFailsWith import okio.Path import okio.fakefilesystem.FakeFileSystem import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.assertFailsWith // TODO(Benoit) Move to `commonTest`. class RootTest { @@ -59,7 +59,7 @@ class RootTest { assertThat(roots[0].allProtoFiles().map { it.location }).containsExactlyInAnyOrder( Location.get(sourceDir.toString(), "squareup/dinosaurs/dinosaur.proto"), - Location.get(sourceDir.toString(), "squareup/dinosaurs/geology.proto") + Location.get(sourceDir.toString(), "squareup/dinosaurs/geology.proto"), ) } @@ -67,7 +67,7 @@ class RootTest { fs.addZip( "lib/dinosaurs.zip", "squareup/dinosaurs/dinosaur.proto" to "/* dinosaur.proto */", - "squareup/dinosaurs/geology.proto" to "/* geology.proto */" + "squareup/dinosaurs/geology.proto" to "/* geology.proto */", ) val sourceZip = Location.get("lib/dinosaurs.zip") @@ -81,7 +81,7 @@ class RootTest { assertThat(roots[0].allProtoFiles().map { it.location }).containsExactlyInAnyOrder( Location.get(sourceZip.toString(), "squareup/dinosaurs/dinosaur.proto"), - Location.get(sourceZip.toString(), "squareup/dinosaurs/geology.proto") + Location.get(sourceZip.toString(), "squareup/dinosaurs/geology.proto"), ) } @@ -89,7 +89,7 @@ class RootTest { fs.addZip( "lib/dinosaurs.zip", "squareup/dinosaurs/raptor.proto" to "/* raptor.proto */", - "squareup/dinosaurs/raptor.nba" to "/* raptor.nba */" + "squareup/dinosaurs/raptor.nba" to "/* raptor.nba */", ) val sourceZip = Location.get("lib/dinosaurs.zip") diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaLoaderTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaLoaderTest.kt index c9b43c1a80..37f0f1baf7 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaLoaderTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaLoaderTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,18 +18,18 @@ package com.squareup.wire.schema import com.squareup.wire.schema.internal.CommonSchemaLoader import com.squareup.wire.testing.add import com.squareup.wire.testing.addZip -import okio.ByteString.Companion.decodeHex -import okio.Path -import okio.Path.Companion.toPath -import okio.fakefilesystem.FakeFileSystem -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test import kotlin.test.assertFailsWith import kotlin.text.Charsets.UTF_16BE import kotlin.text.Charsets.UTF_16LE import kotlin.text.Charsets.UTF_32BE import kotlin.text.Charsets.UTF_32LE import kotlin.text.Charsets.UTF_8 +import okio.ByteString.Companion.decodeHex +import okio.Path +import okio.Path.Companion.toPath +import okio.fakefilesystem.FakeFileSystem +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test // TODO(Benoit) Move this class to commonTest, and test `SchemaLoader` instead of `CommonSchemaLoader`. class SchemaLoaderTest { @@ -55,7 +55,7 @@ class SchemaLoaderTest { |import "squareup/curves/circle.proto"; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "colors/src/main/proto/squareup/colors/red.proto", @@ -66,7 +66,7 @@ class SchemaLoaderTest { |import "squareup/polygons/triangle.proto"; |message Red { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "polygons/src/main/proto/squareup/polygons/octagon.proto", @@ -75,7 +75,7 @@ class SchemaLoaderTest { |package squareup.polygons; |message Octagon { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "polygons/src/main/proto/squareup/polygons/triangle.proto", @@ -84,7 +84,7 @@ class SchemaLoaderTest { |package squareup.polygons; |message Triangle { |} - """.trimMargin() + """.trimMargin(), ) fs.addZip( "lib/curves.zip", @@ -94,29 +94,29 @@ class SchemaLoaderTest { |import "squareup/polygons/triangle.proto"; |message Circle { |} - """.trimMargin(), + """.trimMargin(), "squareup/curves/oval.proto" to """ |syntax = "proto2"; |package squareup.curves; |message Oval { |} - """.trimMargin() + """.trimMargin(), ) val loader = CommonSchemaLoader(fs) loader.initRoots( sourcePath = listOf( - Location.get("colors/src/main/proto") + Location.get("colors/src/main/proto"), ), protoPath = listOf( Location.get("polygons/src/main/proto"), - Location.get("lib/curves.zip") - ) + Location.get("lib/curves.zip"), + ), ) val sourcePathFiles = loader.loadSourcePathFiles() assertThat(sourcePathFiles.map { it.location }).containsExactly( Location.get("colors/src/main/proto", "squareup/colors/blue.proto"), - Location.get("colors/src/main/proto", "squareup/colors/red.proto") + Location.get("colors/src/main/proto", "squareup/colors/red.proto"), ) assertThat(loader.load("google/protobuf/descriptor.proto").location) .isEqualTo(Location.get("google/protobuf/descriptor.proto")) @@ -148,12 +148,12 @@ class SchemaLoaderTest { |package squareup.colors; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) val loader = CommonSchemaLoader(fs) loader.initRoots( - sourcePath = listOf(Location.get("colors/src/main/proto", "squareup/shapes/blue.proto")) + sourcePath = listOf(Location.get("colors/src/main/proto", "squareup/shapes/blue.proto")), ) val sourcePathFiles = loader.loadSourcePathFiles() assertThat(sourcePathFiles.map { it.location.path }) @@ -169,19 +169,19 @@ class SchemaLoaderTest { |package squareup.colors; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { val loader = CommonSchemaLoader(fs) loader.initRoots( - sourcePath = listOf(Location.get("colors/src/main/proto/squareup/shapes/blue.proto")) + sourcePath = listOf(Location.get("colors/src/main/proto/squareup/shapes/blue.proto")), ) loader.loadSourcePathFiles() } assertThat(exception).hasMessage( "expected colors/src/main/proto/squareup/shapes/blue.proto " + - "to have a path ending with squareup/colors/blue.proto" + "to have a path ending with squareup/colors/blue.proto", ) } @@ -195,7 +195,7 @@ class SchemaLoaderTest { |import "squareup/curves/circle.proto"; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "curves/src/main/proto/squareup/curves/circle.proto", @@ -204,17 +204,17 @@ class SchemaLoaderTest { |package squareup.curves; |message Circle { |} - """.trimMargin() + """.trimMargin(), ) val loader = CommonSchemaLoader(fs) loader.initRoots( sourcePath = listOf(Location.get("colors/src/main/proto")), - protoPath = listOf(Location.get("curves/src/main/proto", "squareup/curves/circle.proto")) + protoPath = listOf(Location.get("curves/src/main/proto", "squareup/curves/circle.proto")), ) val sourcePathFiles = loader.loadSourcePathFiles() assertThat(sourcePathFiles.map { it.location.path }).containsExactlyInAnyOrder( - "squareup/colors/blue.proto" + "squareup/colors/blue.proto", ) assertThat(loader.load("google/protobuf/descriptor.proto").location) .isEqualTo(Location.get("google/protobuf/descriptor.proto")) @@ -234,7 +234,8 @@ class SchemaLoaderTest { | string street = 1; | int32 zip = 2; | string city = 3; - |}""".trimMargin() + |} + """.trimMargin(), ) fs.add( @@ -248,7 +249,8 @@ class SchemaLoaderTest { |message Customer { | string name = 1; | Address address = 3; - |}""".trimMargin() + |} + """.trimMargin(), ) val loader = CommonSchemaLoader(fs) @@ -270,8 +272,9 @@ class SchemaLoaderTest { |package squareup.colors; |message Red { |} - """.trimMargin(), - charset = UTF_8, bom = "efbbbf".decodeHex() + """.trimMargin(), + charset = UTF_8, + bom = "efbbbf".decodeHex(), ) fs.add( "colors/squareup/colors/orange.proto", @@ -280,8 +283,9 @@ class SchemaLoaderTest { |package squareup.colors; |message Orange { |} - """.trimMargin(), - charset = UTF_16BE, bom = "feff".decodeHex() + """.trimMargin(), + charset = UTF_16BE, + bom = "feff".decodeHex(), ) fs.add( "colors/squareup/colors/yellow.proto", @@ -290,8 +294,9 @@ class SchemaLoaderTest { |package squareup.colors; |message Yellow { |} - """.trimMargin(), - charset = UTF_16LE, bom = "fffe".decodeHex() + """.trimMargin(), + charset = UTF_16LE, + bom = "fffe".decodeHex(), ) fs.add( "colors/squareup/colors/green.proto", @@ -300,8 +305,9 @@ class SchemaLoaderTest { |package squareup.colors; |message Green { |} - """.trimMargin(), - charset = UTF_32BE, bom = "0000ffff".decodeHex() + """.trimMargin(), + charset = UTF_32BE, + bom = "0000ffff".decodeHex(), ) fs.add( "colors/squareup/colors/blue.proto", @@ -310,8 +316,9 @@ class SchemaLoaderTest { |package squareup.colors; |message Blue { |} - """.trimMargin(), - charset = UTF_32LE, bom = "ffff0000".decodeHex() + """.trimMargin(), + charset = UTF_32LE, + bom = "ffff0000".decodeHex(), ) val loader = CommonSchemaLoader(fs) @@ -322,7 +329,7 @@ class SchemaLoaderTest { "squareup/colors/orange.proto", "squareup/colors/yellow.proto", "squareup/colors/green.proto", - "squareup/colors/blue.proto" + "squareup/colors/blue.proto", ) } @@ -337,21 +344,21 @@ class SchemaLoaderTest { |package squareup.colors; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) fs.createDirectories("colors/src/main".toPath()) fs.createSymlink( "colors/src/main/proto".toPath(), - "../../../secret/proto".toPath() + "../../../secret/proto".toPath(), ) val loader = CommonSchemaLoader(fs) loader.initRoots( - sourcePath = listOf(Location.get("colors/src/main/proto")) + sourcePath = listOf(Location.get("colors/src/main/proto")), ) val sourcePathFiles = loader.loadSourcePathFiles() assertThat(sourcePathFiles.map { it.location }).containsExactly( - Location("colors/src/main/proto", "squareup/colors/blue.proto") + Location("colors/src/main/proto", "squareup/colors/blue.proto"), ) } @@ -361,7 +368,7 @@ class SchemaLoaderTest { |syntax = "proto2"; |package squareup.colors; |message Blue {} - """.trimMargin() + """.trimMargin() fs.add("colors/squareup/colors/a.proto", content) @@ -376,7 +383,7 @@ class SchemaLoaderTest { |same type 'squareup.colors.Blue' from the same file loaded from different paths: | 1. base:colors, path:squareup/colors/a.proto:3:1 | 2. base:colors/squareup, path:colors/a.proto:3:1 - """.trimMargin() + """.trimMargin(), ) } @@ -391,21 +398,21 @@ class SchemaLoaderTest { |package squareup.colors; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) fs.createDirectories("colors/src/main/proto/squareup/colors".toPath()) fs.createSymlink( "colors/src/main/proto/squareup/colors/blue.proto".toPath(), - "../../../../../../secret/proto/squareup/colors/blue.proto".toPath() + "../../../../../../secret/proto/squareup/colors/blue.proto".toPath(), ) val loader = CommonSchemaLoader(fs) loader.initRoots( - sourcePath = listOf(Location.get("colors/src/main/proto")) + sourcePath = listOf(Location.get("colors/src/main/proto")), ) val sourcePathFiles = loader.loadSourcePathFiles() assertThat(sourcePathFiles.map { it.location }).containsExactlyInAnyOrder( - Location("colors/src/main/proto", "squareup/colors/blue.proto") + Location("colors/src/main/proto", "squareup/colors/blue.proto"), ) } @@ -420,7 +427,7 @@ class SchemaLoaderTest { |import "squareup/polygons/rectangle.proto"; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "polygons/src/main/proto/squareup/polygons/triangle.proto", @@ -429,7 +436,7 @@ class SchemaLoaderTest { |package squareup.polygons; |message Triangle { |} - """.trimMargin() + """.trimMargin(), ) fs.addZip( "lib/curves.zip", @@ -438,19 +445,19 @@ class SchemaLoaderTest { |package squareup.curves; |message Oval { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { val loader = CommonSchemaLoader(fs) loader.initRoots( sourcePath = listOf( - Location.get("colors/src/main/proto") + Location.get("colors/src/main/proto"), ), protoPath = listOf( Location.get("polygons/src/main/proto"), - Location.get("lib/curves.zip") - ) + Location.get("lib/curves.zip"), + ), ) loader.loadSourcePathFiles() loader.load("squareup/curves/circle.proto") @@ -467,7 +474,7 @@ class SchemaLoaderTest { | searching 2 proto paths: | polygons/src/main/proto | lib/curves.zip - """.trimMargin() + """.trimMargin(), ) } @@ -481,7 +488,7 @@ class SchemaLoaderTest { |import "squareup/curves/circle.proto"; |message Blue { |} - """.trimMargin() + """.trimMargin(), ) fs.add( "polygons/src/main/proto/squareup/curves/circle.proto", @@ -490,7 +497,7 @@ class SchemaLoaderTest { |package squareup.curves; |message Circle { |} - """.trimMargin() + """.trimMargin(), ) fs.addZip( "lib/curves.zip", @@ -499,19 +506,19 @@ class SchemaLoaderTest { |package squareup.curves; |message Circle { |} - """.trimMargin() + """.trimMargin(), ) val exception = assertFailsWith { val loader = CommonSchemaLoader(fs) loader.initRoots( sourcePath = listOf( - Location.get("colors/src/main/proto") + Location.get("colors/src/main/proto"), ), protoPath = listOf( Location.get("polygons/src/main/proto"), - Location.get("lib/curves.zip") - ) + Location.get("lib/curves.zip"), + ), ) loader.loadSourcePathFiles() loader.load("squareup/curves/circle.proto") @@ -522,7 +529,7 @@ class SchemaLoaderTest { |squareup/curves/circle.proto is ambiguous: | lib/curves.zip/squareup/curves/circle.proto | polygons/src/main/proto/squareup/curves/circle.proto - """.trimMargin() + """.trimMargin(), ) } @@ -535,8 +542,8 @@ class SchemaLoaderTest { Location.get("shared-protos.jar", "squareup/cash/money/Money.proto"), Location.get("src/main/proto", "squareup/cash/Service.proto"), Location.get("src/main/proto", "squareup/cash/cashtags/Cashtag.proto"), - Location.get("src/main/proto", "squareup/cash/payments/Payment.proto") - ) + Location.get("src/main/proto", "squareup/cash/payments/Payment.proto"), + ), ) assertThat(result).containsExactlyInAnyOrder( Location.get("shared-protos.jar", "java.wire"), @@ -547,7 +554,7 @@ class SchemaLoaderTest { Location.get("src/main/proto", "squareup/cash/cashtags/java.wire"), Location.get("src/main/proto", "squareup/cash/java.wire"), Location.get("src/main/proto", "squareup/cash/payments/java.wire"), - Location.get("src/main/proto", "squareup/java.wire") + Location.get("src/main/proto", "squareup/java.wire"), ) } @@ -557,13 +564,13 @@ class SchemaLoaderTest { val result = newSchemaLoader.locationsToCheck( "android", listOf( - Location.get("/a/b", "c/d/e.proto") - ) + Location.get("/a/b", "c/d/e.proto"), + ), ) assertThat(result).containsExactlyInAnyOrder( Location.get("/a/b", "c/d/android.wire"), Location.get("/a/b", "c/android.wire"), - Location.get("/a/b", "android.wire") + Location.get("/a/b", "android.wire"), ) } @@ -576,8 +583,8 @@ class SchemaLoaderTest { Location.get("/a/b", "c/d/e.proto"), Location.get("/a/b", "c/f/g/h.proto"), Location.get("/i/j.zip", "k/l/m.proto"), - Location.get("/i/j.zip", "k/l/m/n.proto") - ) + Location.get("/i/j.zip", "k/l/m/n.proto"), + ), ) assertThat(result).containsExactlyInAnyOrder( Location.get("/a/b", "c/d/android.wire"), @@ -588,7 +595,7 @@ class SchemaLoaderTest { Location.get("/i/j.zip", "k/l/android.wire"), Location.get("/i/j.zip", "k/android.wire"), Location.get("/i/j.zip", "android.wire"), - Location.get("/i/j.zip", "k/l/m/android.wire") + Location.get("/i/j.zip", "k/l/m/android.wire"), ) } @@ -603,7 +610,7 @@ class SchemaLoaderTest { |message Red { | optional Orange orange = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "colors/src/main/proto/squareup/colors/orange.proto", @@ -614,7 +621,7 @@ class SchemaLoaderTest { |message Orange { | optional Yellow yellow = 1; |} - """.trimMargin() + """.trimMargin(), ) fs.add( "colors/src/main/proto/squareup/colors/yellow.proto", @@ -625,18 +632,18 @@ class SchemaLoaderTest { |message Yellow { | // optional Green green = 1; |} - """.trimMargin() + """.trimMargin(), ) val loader = CommonSchemaLoader(fs) loader.loadExhaustively = true loader.initRoots( sourcePath = listOf( - Location.get("colors/src/main/proto", "squareup/colors/red.proto") + Location.get("colors/src/main/proto", "squareup/colors/red.proto"), ), protoPath = listOf( - Location.get("colors/src/main/proto") - ) + Location.get("colors/src/main/proto"), + ), ) val schema = loader.loadSchema() val redMessage = schema.getType("squareup.colors.Red") as MessageType diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaProtoAdapterTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaProtoAdapterTest.kt index 67c9552275..3c66abb79b 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaProtoAdapterTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaProtoAdapterTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,9 @@ package com.squareup.wire.schema import com.squareup.wire.buildSchema +import java.io.EOFException +import java.io.IOException +import java.net.ProtocolException import okio.Buffer import okio.ByteString.Companion.decodeHex import okio.ByteString.Companion.toByteString @@ -23,9 +26,6 @@ import okio.Path.Companion.toPath import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import java.io.EOFException -import java.io.IOException -import java.net.ProtocolException class SchemaProtoAdapterTest { private val coffeeSchema = buildSchema { @@ -54,7 +54,7 @@ class SchemaProtoAdapterTest { | optional string bean_type = 1; | optional double caffeine_level = 2; |} - """.trimMargin() + """.trimMargin(), ) } @@ -63,7 +63,7 @@ class SchemaProtoAdapterTest { "customer_name" to "Dan", "shots" to listOf(mapOf("caffeine_level" to 0.5)), "size_ounces" to 16, - "dairy" to mapOf("count" to 1) + "dairy" to mapOf("count" to 1), ) private val dansCoffeeEncoded = "0a0344616e120911000000000000e03f70107a021001".decodeHex() @@ -73,10 +73,10 @@ class SchemaProtoAdapterTest { "shots" to listOf( mapOf("bean_type" to "colombian", "caffeine_level" to 1.0), - mapOf("bean_type" to "colombian", "caffeine_level" to 1.0) + mapOf("bean_type" to "colombian", "caffeine_level" to 1.0), ), "foam" to "ZOMG_SO_FOAMY", - "size_ounces" to 24 + "size_ounces" to 24, ) private val jessesCoffeeEncoded = ( @@ -119,7 +119,7 @@ class SchemaProtoAdapterTest { | // } | optional string b = 4; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("Message") val encoded = ( @@ -141,7 +141,7 @@ class SchemaProtoAdapterTest { |message Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("Message") val encoded = "130a0161".decodeHex() @@ -162,7 +162,7 @@ class SchemaProtoAdapterTest { |message Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("Message") val encoded = "0a01611c".decodeHex() @@ -184,7 +184,7 @@ class SchemaProtoAdapterTest { |message Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("Message") val encoded = "130a01611c".decodeHex() @@ -206,7 +206,7 @@ class SchemaProtoAdapterTest { |message Message { | repeated int32 a = 90 [packed = false]; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("Message") val expected = mapOf("a" to listOf(601, 701)) @@ -228,7 +228,7 @@ class SchemaProtoAdapterTest { |message Message { | repeated int32 a = 90 [packed = true]; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("Message") val expected = mapOf("a" to listOf(601, 701)) @@ -252,7 +252,7 @@ class SchemaProtoAdapterTest { | optional BinaryTreeNode right = 2; | optional string value = 3; |} - """.trimMargin() + """.trimMargin(), ) }.protoAdapter("BinaryTreeNode") val value = mapOf( @@ -260,13 +260,13 @@ class SchemaProtoAdapterTest { "left" to mapOf( "value" to "B", "left" to mapOf("value" to "A"), - "right" to mapOf("value" to "C") + "right" to mapOf("value" to "C"), ), "right" to mapOf( "value" to "F", "left" to mapOf("value" to "E"), - "right" to mapOf("value" to "G") - ) + "right" to mapOf("value" to "G"), + ), ) val encoded = "0a0d0a031a014112031a01431a0142120d0a031a014512031a01471a01461a0144".decodeHex() assertThat(adapter.encode(value).toByteString()).isEqualTo(encoded) @@ -283,7 +283,7 @@ class SchemaProtoAdapterTest { | optional string customer_name = 1; | optional int32 size_ounces = 14; |} - """.trimMargin() + """.trimMargin(), ) } @@ -291,7 +291,7 @@ class SchemaProtoAdapterTest { "customer_name" to "Dan", "2" to listOf("11000000000000e03f".decodeHex()), "size_ounces" to 16, - "15" to listOf("1001".decodeHex()) + "15" to listOf("1001".decodeHex()), ) val adapter = schema.protoAdapter("CafeDrink", true) @@ -309,7 +309,7 @@ class SchemaProtoAdapterTest { | optional string customer_name = 1; | optional int32 size_ounces = 14; |} - """.trimMargin() + """.trimMargin(), ) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt index 887cbc6fda..d8cb64fc28 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SchemaTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,21 +39,21 @@ class SchemaTest { |service Service { | rpc Call (Request) returns (Response); |} - """.trimMargin() + """.trimMargin(), ) add( "request.proto".toPath(), """ |message Request { |} - """.trimMargin() + """.trimMargin(), ) add( "response.proto".toPath(), """ |message Response { |} - """.trimMargin() + """.trimMargin(), ) } @@ -74,7 +74,7 @@ class SchemaTest { | optional foo_package.Foo field = 1; | map bars = 2; |} - """.trimMargin() + """.trimMargin(), ) add( "foo.proto".toPath(), @@ -84,7 +84,7 @@ class SchemaTest { |} |message Bar { |} - """.trimMargin() + """.trimMargin(), ) } @@ -115,7 +115,7 @@ class SchemaTest { | extend Other { | optional Choice choice = 1; | } - """.trimMargin() + """.trimMargin(), ) } @@ -152,7 +152,7 @@ class SchemaTest { | optional int32 g = 536870911; | optional int32 h = 536870912; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -171,7 +171,7 @@ class SchemaTest { |tag is out of range: 536870912 | for field h (/sourcePath/message.proto:9:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -192,7 +192,7 @@ class SchemaTest { | extensions 536870911; | extensions 536870912; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -208,7 +208,7 @@ class SchemaTest { |tags are out of range: 536870912 | for extensions (/sourcePath/message.proto:8:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -224,7 +224,7 @@ class SchemaTest { | repeated int32 b = 2 [packed=false]; | repeated int32 c = 3 [packed=true]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -246,7 +246,7 @@ class SchemaTest { | EARTH = 1; | } |} - """.trimMargin() + """.trimMargin(), ) } val message = schema.getType("Message") as MessageType @@ -272,7 +272,7 @@ class SchemaTest { | repeated bytes g = 7 [packed=false]; | repeated bytes h = 8 [packed=true]; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -291,7 +291,7 @@ class SchemaTest { |packed=true not permitted on bytes | for field h (/sourcePath/message.proto:11:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -310,7 +310,7 @@ class SchemaTest { | repeated Message b = 2 [wire.use_array=true]; | repeated float c = 3 [wire.use_array=true]; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -329,7 +329,7 @@ class SchemaTest { |wire.use_array=true only permitted on packed fields | for field c (/sourcePath/message.proto:6:3) | in message Message (/sourcePath/message.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -345,7 +345,7 @@ class SchemaTest { | optional int32 b = 2 [deprecated=false]; | optional int32 c = 3 [deprecated=true]; |} - """.trimMargin() + """.trimMargin(), ) } @@ -373,7 +373,7 @@ class SchemaTest { | PAPER = 2; | } |} - """.trimMargin() + """.trimMargin(), ) } @@ -399,7 +399,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string color = 60001; |} - """.trimMargin() + """.trimMargin(), ) } val message = schema.getType("Message") as MessageType @@ -429,7 +429,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string color = 60001; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -439,7 +439,7 @@ class SchemaTest { |conflicting options: red, blue | for field a (/sourcePath/message.proto:3:3) | in message Message (/sourcePath/message.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -454,7 +454,7 @@ class SchemaTest { |message Message { | optional foo_package.Foo unknown = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -464,7 +464,7 @@ class SchemaTest { |unable to resolve foo_package.Foo | for field unknown (/sourcePath/message.proto:2:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -482,7 +482,7 @@ class SchemaTest { | foo_package.Foo unknown = 2; | } |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -492,7 +492,7 @@ class SchemaTest { |unable to resolve foo_package.Foo | for field unknown (/sourcePath/message.proto:4:5) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -509,7 +509,7 @@ class SchemaTest { |} |message Response { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -519,7 +519,7 @@ class SchemaTest { |expected a message but was string | for rpc Call (/sourcePath/service.proto:2:3) | in service Service (/sourcePath/service.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } @@ -533,7 +533,7 @@ class SchemaTest { |} |message Request { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -543,7 +543,7 @@ class SchemaTest { |expected a message but was string | for rpc Call (/sourcePath/service.proto:2:3) | in service Service (/sourcePath/service.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -560,7 +560,7 @@ class SchemaTest { |} |message Response { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -570,7 +570,7 @@ class SchemaTest { |unable to resolve foo_package.Foo | for rpc Call (/sourcePath/service.proto:2:3) | in service Service (/sourcePath/service.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } @@ -584,7 +584,7 @@ class SchemaTest { |} |message Request { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -594,7 +594,7 @@ class SchemaTest { |unable to resolve foo_package.Foo | for rpc Call (/sourcePath/service.proto:2:3) | in service Service (/sourcePath/service.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -608,7 +608,7 @@ class SchemaTest { """ |extend foo_package.Foo { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -617,7 +617,7 @@ class SchemaTest { """ |unable to resolve foo_package.Foo | for extend (/sourcePath/extend.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -634,7 +634,7 @@ class SchemaTest { |} |message Value { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -643,7 +643,7 @@ class SchemaTest { """ |expected a message but was string | for extend (/sourcePath/extend.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -660,7 +660,7 @@ class SchemaTest { |extend Message { | optional foo_package.Foo unknown = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -670,7 +670,7 @@ class SchemaTest { |unable to resolve foo_package.Foo | for field unknown (/sourcePath/message.proto:4:3) | in extend Message (/sourcePath/message.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -686,7 +686,7 @@ class SchemaTest { | optional foo_package.Foo unknown = 1; | optional foo_package.Foo also_unknown = 2; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -699,7 +699,7 @@ class SchemaTest { |unable to resolve foo_package.Foo | for field also_unknown (/sourcePath/message.proto:3:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -715,7 +715,7 @@ class SchemaTest { | required string name1 = 1; | required string name2 = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -726,7 +726,7 @@ class SchemaTest { | 1. name1 (/sourcePath/message.proto:2:3) | 2. name2 (/sourcePath/message.proto:3:3) | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -744,7 +744,7 @@ class SchemaTest { | string name2 = 1; | } |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -755,7 +755,7 @@ class SchemaTest { | 1. name1 (/sourcePath/message.proto:2:3) | 2. name2 (/sourcePath/message.proto:4:5) | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -773,7 +773,7 @@ class SchemaTest { | optional string name1 = 1; | optional string name2 = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -784,7 +784,7 @@ class SchemaTest { | 1. name1 (/sourcePath/message.proto:4:3) | 2. name2 (/sourcePath/message.proto:5:3) | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -800,7 +800,7 @@ class SchemaTest { | optional string a = 1; | optional string a = 2; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -811,7 +811,7 @@ class SchemaTest { | 1. a (/sourcePath/message.proto:2:3) | 2. a (/sourcePath/message.proto:3:3) | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -825,7 +825,7 @@ class SchemaTest { |message Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "extend.proto".toPath(), @@ -835,7 +835,7 @@ class SchemaTest { |extend Message { | optional string a = 2; |} - """.trimMargin() + """.trimMargin(), ) } val messageType = schema.getType("Message") as MessageType @@ -853,7 +853,7 @@ class SchemaTest { """ |message Message { |} - """.trimMargin() + """.trimMargin(), ) add( "extend1.proto".toPath(), @@ -862,7 +862,7 @@ class SchemaTest { |extend Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "extend2.proto".toPath(), @@ -871,7 +871,7 @@ class SchemaTest { |extend Message { | optional string a = 2; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -882,7 +882,7 @@ class SchemaTest { | 1. a (/sourcePath/extend1.proto:3:3) | 2. a (/sourcePath/extend2.proto:3:3) | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -895,7 +895,7 @@ class SchemaTest { """ |message Message { |} - """.trimMargin() + """.trimMargin(), ) add( "extend1.proto".toPath(), @@ -905,7 +905,7 @@ class SchemaTest { |extend Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "extend2.proto".toPath(), @@ -915,7 +915,7 @@ class SchemaTest { |extend Message { | optional string a = 2; |} - """.trimMargin() + """.trimMargin(), ) } val messageType = schema.getType("Message") as MessageType @@ -936,7 +936,7 @@ class SchemaTest { | A = 1; | B = 2; |} - """.trimMargin() + """.trimMargin(), ) add( "extend.proto".toPath(), @@ -945,7 +945,7 @@ class SchemaTest { |extend Enum { | optional string a = 2; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -954,7 +954,7 @@ class SchemaTest { """ |expected a message but was Enum | for extend (/sourcePath/extend.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -971,7 +971,7 @@ class SchemaTest { |extend Message { | required string a = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -981,7 +981,7 @@ class SchemaTest { |extension fields cannot be required | for field a (/sourcePath/message.proto:4:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -996,7 +996,7 @@ class SchemaTest { |message Message { | oneof string s = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1020,7 +1020,7 @@ class SchemaTest { | VALUE = 2; | } |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1031,7 +1031,7 @@ class SchemaTest { | 1. Message.Enum1.VALUE (/sourcePath/message.proto:3:5) | 2. Message.Enum2.VALUE (/sourcePath/message.proto:6:5) | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1047,7 +1047,7 @@ class SchemaTest { | A = 1; | B = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1058,7 +1058,7 @@ class SchemaTest { | 1. A (/sourcePath/message.proto:2:3) | 2. B (/sourcePath/message.proto:3:3) | for enum Enum (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1075,7 +1075,7 @@ class SchemaTest { | A = 1; | B = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1086,7 +1086,7 @@ class SchemaTest { | 1. A (/sourcePath/message.proto:3:3) | 2. B (/sourcePath/message.proto:4:3) | for enum Enum (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1102,7 +1102,7 @@ class SchemaTest { | A = 1; | B = 1; |} - """.trimMargin() + """.trimMargin(), ) } val enumType = schema.getType("Enum") as EnumType @@ -1121,7 +1121,7 @@ class SchemaTest { |message A { | optional pb.B b = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1129,7 +1129,7 @@ class SchemaTest { |package pb; |message B { |} - """.trimMargin() + """.trimMargin(), ) } val a = schema.getType("pa.A") as MessageType @@ -1148,7 +1148,7 @@ class SchemaTest { |message A { | map b = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1156,7 +1156,7 @@ class SchemaTest { |package pb; |message B { |} - """.trimMargin() + """.trimMargin(), ) } val a = schema.getType("pa.A") as MessageType @@ -1175,7 +1175,7 @@ class SchemaTest { |message A { | optional pb.B b = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1183,7 +1183,7 @@ class SchemaTest { |package pb; |message B { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1193,7 +1193,7 @@ class SchemaTest { |a.proto needs to import b.proto | for field b (/sourcePath/a.proto:3:3) | in message pa.A (/sourcePath/a.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1209,7 +1209,7 @@ class SchemaTest { |message A { | map b = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1217,7 +1217,7 @@ class SchemaTest { |package pb; |message B { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1227,7 +1227,7 @@ class SchemaTest { |a.proto needs to import b.proto | for field b (/sourcePath/a.proto:3:3) | in message pa.A (/sourcePath/a.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1243,7 +1243,7 @@ class SchemaTest { |service Service { | rpc Call (pb.B) returns (pb.B); |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1251,7 +1251,7 @@ class SchemaTest { |package pb; |message B { |} - """.trimMargin() + """.trimMargin(), ) } val service = schema.getService("pa.Service")!! @@ -1271,7 +1271,7 @@ class SchemaTest { |service Service { | rpc Call (pb.B) returns (pb.B); |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1279,7 +1279,7 @@ class SchemaTest { |package pb; |message B { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1292,7 +1292,7 @@ class SchemaTest { |a.proto needs to import b.proto | for rpc Call (/sourcePath/a.proto:3:3) | in service pa.Service (/sourcePath/a.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1308,7 +1308,7 @@ class SchemaTest { |extend pb.B { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1317,7 +1317,7 @@ class SchemaTest { |message B { | extensions 1; |} - """.trimMargin() + """.trimMargin(), ) } val extendB = schema.protoFiles[0].extendList[0] @@ -1336,7 +1336,7 @@ class SchemaTest { |extend pb.B { | optional string a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1345,7 +1345,7 @@ class SchemaTest { |message B { | extensions 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1354,7 +1354,7 @@ class SchemaTest { """ |a.proto needs to import b.proto | for extend pb.B (/sourcePath/a.proto:2:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1371,7 +1371,7 @@ class SchemaTest { |message A { | optional pc.C c = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1380,7 +1380,7 @@ class SchemaTest { |import "c.proto"; |message B { |} - """.trimMargin() + """.trimMargin(), ) add( "c.proto".toPath(), @@ -1388,7 +1388,7 @@ class SchemaTest { |package pc; |message C { |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1398,7 +1398,7 @@ class SchemaTest { |a.proto needs to import c.proto | for field c (/sourcePath/a.proto:4:3) | in message pa.A (/sourcePath/a.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1414,7 +1414,7 @@ class SchemaTest { |message A { | optional pc.C c = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -1423,7 +1423,7 @@ class SchemaTest { |import public "c.proto"; |message B { |} - """.trimMargin() + """.trimMargin(), ) add( "c.proto".toPath(), @@ -1431,7 +1431,7 @@ class SchemaTest { |package pc; |message C { |} - """.trimMargin() + """.trimMargin(), ) } val a = schema.getType("pa.A") as MessageType @@ -1455,7 +1455,7 @@ class SchemaTest { | optional b.MessageC c3 = 3; | optional MessageC c4 = 4; |} - """.trimMargin() + """.trimMargin(), ) add( "a_b_2.proto".toPath(), @@ -1464,7 +1464,7 @@ class SchemaTest { | |message MessageC { |} - """.trimMargin() + """.trimMargin(), ) } val messageC = schema.getType("a.b.MessageB") as MessageType @@ -1484,7 +1484,7 @@ class SchemaTest { | |message MessageB { |} - """.trimMargin() + """.trimMargin(), ) add( "a_b_c.proto".toPath(), @@ -1496,7 +1496,7 @@ class SchemaTest { |message MessageC { | optional b.MessageB message_b = 1; |} - """.trimMargin() + """.trimMargin(), ) } val messageC = schema.getType("a.b.c.MessageC") as MessageType @@ -1516,7 +1516,7 @@ class SchemaTest { |message MessageB { | optional c.MessageC message_c = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "a_b_c.proto".toPath(), @@ -1525,7 +1525,7 @@ class SchemaTest { | |message MessageC { |} - """.trimMargin() + """.trimMargin(), ) } val messageC = schema.getType("a.b.MessageB") as MessageType @@ -1542,7 +1542,7 @@ class SchemaTest { | |message MessageA { |} - """.trimMargin() + """.trimMargin(), ) add( "a_b.proto".toPath(), @@ -1555,7 +1555,7 @@ class SchemaTest { |message MessageB { | optional a.MessageA message_a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "a_b_a.proto".toPath(), @@ -1564,7 +1564,7 @@ class SchemaTest { | |message MessageA { |} - """.trimMargin() + """.trimMargin(), ) } val messageC = schema.getType("a.b.MessageB") as MessageType @@ -1581,7 +1581,7 @@ class SchemaTest { | |message MessageA { |} - """.trimMargin() + """.trimMargin(), ) add( "a_b.proto".toPath(), @@ -1594,7 +1594,7 @@ class SchemaTest { |message MessageB { | optional .a.MessageA message_a = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "a_b_a.proto".toPath(), @@ -1603,7 +1603,7 @@ class SchemaTest { | |message MessageA { |} - """.trimMargin() + """.trimMargin(), ) } val messageC = schema.getType("a.b.MessageB") as MessageType @@ -1621,7 +1621,7 @@ class SchemaTest { | |message MessageB { |} - """.trimMargin() + """.trimMargin(), ) add( "a_b_c.proto".toPath(), @@ -1633,7 +1633,7 @@ class SchemaTest { |message MessageC { | optional .b.MessageB message_b = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1643,7 +1643,7 @@ class SchemaTest { |unable to resolve .b.MessageB | for field message_b (/sourcePath/a_b_c.proto:6:3) | in message a.b.c.MessageC (/sourcePath/a_b_c.proto:5:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1662,7 +1662,7 @@ class SchemaTest { | repeated string snippets = 4; | } |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1688,7 +1688,7 @@ class SchemaTest { | } | } |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1708,7 +1708,7 @@ class SchemaTest { | reserved 1; | optional string name = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1718,7 +1718,7 @@ class SchemaTest { |tag 1 is reserved (/sourcePath/test.proto:2:3) | for field name (/sourcePath/test.proto:3:3) | in message Message (/sourcePath/test.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1734,7 +1734,7 @@ class SchemaTest { | reserved 1 to max; | optional string name = 3; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1744,7 +1744,7 @@ class SchemaTest { |tag 3 is reserved (/sourcePath/test.proto:2:3) | for field name (/sourcePath/test.proto:3:3) | in message Message (/sourcePath/test.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1761,7 +1761,7 @@ class SchemaTest { | FOO = 2; | NAME = 4; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1774,7 +1774,7 @@ class SchemaTest { |tag 4 is reserved (/sourcePath/test.proto:2:3) | for constant NAME (/sourcePath/test.proto:4:3) | in enum Enum (/sourcePath/test.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1790,7 +1790,7 @@ class SchemaTest { | reserved 1 to 3; | optional string name = 2; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1800,7 +1800,7 @@ class SchemaTest { |tag 2 is reserved (/sourcePath/test.proto:2:3) | for field name (/sourcePath/test.proto:3:3) | in message Message (/sourcePath/test.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1816,7 +1816,7 @@ class SchemaTest { | reserved 'foo'; | optional string foo = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1826,7 +1826,7 @@ class SchemaTest { |name 'foo' is reserved (/sourcePath/test.proto:2:3) | for field foo (/sourcePath/test.proto:3:3) | in message Message (/sourcePath/test.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1843,7 +1843,7 @@ class SchemaTest { | reserved 1; | optional string foo = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -1856,7 +1856,7 @@ class SchemaTest { |tag 1 is reserved (/sourcePath/test.proto:3:3) | for field foo (/sourcePath/test.proto:4:3) | in message Message (/sourcePath/test.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1875,7 +1875,8 @@ class SchemaTest { | JURASSIC = 2; | TRIASSIC = 3; |} - |""".trimMargin() + | + """.trimMargin(), ) } val enum = schema.getType("Period") as EnumType @@ -1899,7 +1900,8 @@ class SchemaTest { | JURASSIC = 2; | TRIASSIC = 3; |} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -1908,7 +1910,7 @@ class SchemaTest { """ |missing a zero value at the first element in proto3 | for enum Period (/sourcePath/period.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1928,7 +1930,8 @@ class SchemaTest { | JURASSIC = 2; | TRIASSIC = 3; |} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -1937,7 +1940,7 @@ class SchemaTest { """ |missing a zero value at the first element in proto3 | for enum Period (/sourcePath/period.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1952,7 +1955,8 @@ class SchemaTest { |syntax = "proto3"; | |enum Period {} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -1961,7 +1965,7 @@ class SchemaTest { """ |missing a zero value at the first element in proto3 | for enum Period (/sourcePath/period.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -1979,7 +1983,8 @@ class SchemaTest { | JURASSIC = 2; | TRIASSIC = 3; |} - |""".trimMargin() + | + """.trimMargin(), ) } val enum = schema.getType("Period") as EnumType @@ -2000,7 +2005,8 @@ class SchemaTest { | JURASSIC = 2; | TRIASSIC = 3; |} - |""".trimMargin() + | + """.trimMargin(), ) } val enum = schema.getType("Period") as EnumType @@ -2025,7 +2031,7 @@ class SchemaTest { |message Message { | string title = 1 [(a) = "hello"]; |} - """.trimMargin() + """.trimMargin(), ) } val fieldOptions = schema.getType("google.protobuf.FieldOptions") as MessageType @@ -2052,12 +2058,12 @@ class SchemaTest { | string two = 2; | } |} - """.trimMargin() + """.trimMargin(), ) } val fieldOptions = schema.getType("google.protobuf.OneofOptions") as MessageType assertThat(fieldOptions.extensionField("my_oneof_option")!!.type).isEqualTo( - ProtoType.get("string") + ProtoType.get("string"), ) } @@ -2077,7 +2083,8 @@ class SchemaTest { |extend Dinosaur { | bool scary = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -2086,7 +2093,7 @@ class SchemaTest { """ |extensions are not allowed in proto3 | for extend Dinosaur (/sourcePath/dinosaur.proto:7:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2103,7 +2110,8 @@ class SchemaTest { |message Dinosaur { | string name = 1 [default = "T-Rex"]; |} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -2113,7 +2121,7 @@ class SchemaTest { |user-defined default values are not permitted in proto3 | for field name (/sourcePath/dinosaur.proto:4:3) | in message Dinosaur (/sourcePath/dinosaur.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2150,7 +2158,8 @@ class SchemaTest { |} | |message OtherMessage {} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -2183,7 +2192,9 @@ class SchemaTest { @Test fun deprecatedOptionsForProto3() { val deprecatedOptionElement = OptionElement.create( name = "deprecated", - kind = OptionElement.Kind.BOOLEAN, value = "true", isParenthesized = false + kind = OptionElement.Kind.BOOLEAN, + value = "true", + isParenthesized = false, ) val schema = buildSchema { @@ -2210,7 +2221,8 @@ class SchemaTest { |} |message Request {} |message Response {} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -2243,7 +2255,8 @@ class SchemaTest { | string myName = 1; | string my_name = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -2254,7 +2267,7 @@ class SchemaTest { | 1. myName (/sourcePath/dinosaur.proto:4:3) | 2. my_name (/sourcePath/dinosaur.proto:5:3) | for message Dinosaur (/sourcePath/dinosaur.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2273,7 +2286,8 @@ class SchemaTest { | string myName = 1 [json_name = "one"]; | string my_name = 2 [json_name = "two"]; |} - |""".trimMargin() + | + """.trimMargin(), ) } assertThat(schema).isNotNull() @@ -2290,7 +2304,8 @@ class SchemaTest { | optional string myName = 1 [json_name = "JsonName"]; | optional string my_name = 2 [json_name = "JsonName"]; |} - |""".trimMargin() + | + """.trimMargin(), ) } fail() @@ -2301,7 +2316,7 @@ class SchemaTest { | 1. myName (/sourcePath/dinosaur.proto:2:3) | 2. my_name (/sourcePath/dinosaur.proto:3:3) | for message Dinosaur (/sourcePath/dinosaur.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2318,7 +2333,8 @@ class SchemaTest { | optional string myName = 1; | optional string my_name = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) } assertThat(schema.getType("Dinosaur")).isNotNull() @@ -2342,7 +2358,8 @@ class SchemaTest { |message Nested { | optional string value = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } assertThat(schema.getType("wire.Foo")).isNotNull() @@ -2358,7 +2375,7 @@ class SchemaTest { |message Message { | optional string name = 1 [(unicorn) = true]; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2368,7 +2385,7 @@ class SchemaTest { |unable to resolve option unicorn | for field name (/sourcePath/message.proto:2:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2385,7 +2402,8 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional bool friday = 60004; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "message.proto".toPath(), @@ -2393,7 +2411,7 @@ class SchemaTest { |message Message { | optional string name = 1 [(cashapp.friday) = true]; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2404,7 +2422,7 @@ class SchemaTest { | for field friday (/sourcePath/cashapp/pii.proto:4:3) | in field name (/sourcePath/message.proto:2:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2419,7 +2437,7 @@ class SchemaTest { |enum Enum { | A = 1 [(unicorn) = true]; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2429,7 +2447,7 @@ class SchemaTest { |unable to resolve option unicorn | for constant A (/sourcePath/enum.proto:2:3) | in enum Enum (/sourcePath/enum.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2444,7 +2462,7 @@ class SchemaTest { |message Message { | option (unicorn) = true; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2453,7 +2471,7 @@ class SchemaTest { """ |unable to resolve option unicorn | for message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2468,7 +2486,7 @@ class SchemaTest { | |option (unicorn) = true; |message Message {} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2477,7 +2495,7 @@ class SchemaTest { """ |unable to resolve option unicorn | for file /sourcePath/message.proto - """.trimMargin() + """.trimMargin(), ) } } @@ -2495,7 +2513,7 @@ class SchemaTest { |extend google.protobuf.FileOptions { | optional string file_status = 60000; |} - """.trimMargin() + """.trimMargin(), ) add( "squareup/domain/message.proto".toPath(), @@ -2506,7 +2524,7 @@ class SchemaTest { |option (common.file_status) = "INTERNAL"; | |message Message{} - """.trimMargin() + """.trimMargin(), ) } assertThat(schema.protoFile("squareup/domain/message.proto")).isNotNull() @@ -2522,7 +2540,7 @@ class SchemaTest { |package squareup.domain; | |message Message{} - """.trimMargin() + """.trimMargin(), ) add( "squareup/common/options.proto".toPath(), @@ -2540,7 +2558,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123301; |} - """.trimMargin() + """.trimMargin(), ) } assertThat(schema.protoFile("squareup/domain/message.proto")).isNotNull() @@ -2557,7 +2575,7 @@ class SchemaTest { |package squareup.domain; | |message Message{} - """.trimMargin() + """.trimMargin(), ) add( "squareup/common/options.proto".toPath(), @@ -2572,7 +2590,7 @@ class SchemaTest { |extend squareup.domain.Message { | optional string type = 12000 [(maps_to) = "sup"]; // missing package qualifier |} - """.trimMargin() + """.trimMargin(), ) add( "squareup/options1/special.proto".toPath(), @@ -2585,7 +2603,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123301; |} - """.trimMargin() + """.trimMargin(), ) add( "squareup/options2/special.proto".toPath(), @@ -2598,7 +2616,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123302; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2608,7 +2626,7 @@ class SchemaTest { |unable to resolve option maps_to | for field type (/sourcePath/squareup/common/options.proto:9:3) | in extend squareup.domain.Message (/sourcePath/squareup/common/options.proto:8:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2623,7 +2641,7 @@ class SchemaTest { |package squareup.domain; | |message Message{} - """.trimMargin() + """.trimMargin(), ) add( "squareup/common/options.proto".toPath(), @@ -2642,7 +2660,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123301; |} - """.trimMargin() + """.trimMargin(), ) add( "squareup/options/special.proto".toPath(), @@ -2655,7 +2673,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123302; |} - """.trimMargin() + """.trimMargin(), ) } } @@ -2670,7 +2688,7 @@ class SchemaTest { |package squareup.domain; | |message Message{} - """.trimMargin() + """.trimMargin(), ) add( "squareup/common/options.proto".toPath(), @@ -2685,7 +2703,7 @@ class SchemaTest { |extend squareup.domain.Message { | optional string type = 12000 [(options1.maps_to) = "sup"]; |} - """.trimMargin() + """.trimMargin(), ) add( "squareup/options1/special.proto".toPath(), @@ -2698,7 +2716,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123301; |} - """.trimMargin() + """.trimMargin(), ) add( "squareup/options2/special.proto".toPath(), @@ -2711,7 +2729,7 @@ class SchemaTest { |extend google.protobuf.FieldOptions { | optional string maps_to = 123302; |} - """.trimMargin() + """.trimMargin(), ) } assertThat(schema.protoFile("squareup/domain/message.proto")).isNotNull() @@ -2728,7 +2746,7 @@ class SchemaTest { |extend Message { | map map_int_int = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2738,7 +2756,7 @@ class SchemaTest { |extension fields cannot be a map | for field map_int_int (/sourcePath/message.proto:3:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2756,7 +2774,7 @@ class SchemaTest { |enum Enum { | ONE = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2766,7 +2784,7 @@ class SchemaTest { |enum value in map must define 0 as the first value | for field map (/sourcePath/message.proto:2:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2785,7 +2803,7 @@ class SchemaTest { | ONE = 1; | ZERO = 0; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2795,7 +2813,7 @@ class SchemaTest { |enum value in map must define 0 as the first value | for field map (/sourcePath/message.proto:2:3) | in message Message (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2813,13 +2831,13 @@ class SchemaTest { |message Message { | optional string title = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() } catch (exception: IllegalStateException) { assertThat(exception).hasMessage( - "Message (/sourcePath/message.proto:4:1) is already defined at /sourcePath/message.proto:1:1" + "Message (/sourcePath/message.proto:4:1) is already defined at /sourcePath/message.proto:1:1", ) } } @@ -2838,13 +2856,13 @@ class SchemaTest { | rpc Receive (Data) returns (Data) {} |} |message Data {} - """.trimMargin() + """.trimMargin(), ) } fail() } catch (exception: IllegalStateException) { assertThat(exception).hasMessage( - "Service (/sourcePath/service.proto:4:1) is already defined at /sourcePath/service.proto:1:1" + "Service (/sourcePath/service.proto:4:1) is already defined at /sourcePath/service.proto:1:1", ) } } @@ -2861,7 +2879,7 @@ class SchemaTest { | rpc Send (Data) returns (Data) {} |} |message Data {} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2872,7 +2890,7 @@ class SchemaTest { | 1. Send (/sourcePath/service.proto:2:3) | 2. Send (/sourcePath/service.proto:3:3) | for service Service (/sourcePath/service.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2889,7 +2907,7 @@ class SchemaTest { | ZERO = 0; | ONE = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "proto3.proto".toPath(), @@ -2899,7 +2917,7 @@ class SchemaTest { |message Joint { | Bit bit = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2909,7 +2927,7 @@ class SchemaTest { |Proto2 enums cannot be referenced in a proto3 message | for field bit (/sourcePath/proto3.proto:4:3) | in message Joint (/sourcePath/proto3.proto:3:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2924,7 +2942,7 @@ class SchemaTest { | ZERO = 0; | zero = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2934,7 +2952,7 @@ class SchemaTest { | ZERO:0 (/sourcePath/message.proto:2:3) | zero:1 (/sourcePath/message.proto:3:3) | for enum Foo (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } @@ -2949,7 +2967,7 @@ class SchemaTest { | ZERO = 0; | zero = 0; |} - """.trimMargin() + """.trimMargin(), ) } @@ -2969,7 +2987,7 @@ class SchemaTest { | ZERO = 0; | zero = 1; |} - """.trimMargin() + """.trimMargin(), ) } fail() @@ -2979,7 +2997,7 @@ class SchemaTest { | ZERO:0 (/sourcePath/message.proto:3:3) | zero:1 (/sourcePath/message.proto:4:3) | for enum Foo (/sourcePath/message.proto:1:1) - """.trimMargin() + """.trimMargin(), ) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SemVerTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SemVerTest.kt index 68f2a9a452..7b1d6a41ad 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SemVerTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/SemVerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,7 +31,7 @@ internal class SemVerTest { "1.3.2", "1.3.3", "2.0.0", - "3.0.0" + "3.0.0", ) } @@ -46,7 +46,7 @@ internal class SemVerTest { "1.500.0", "1.505.0", "1.1000.0", - "1.1005.0" + "1.1005.0", ) } @@ -61,7 +61,7 @@ internal class SemVerTest { "1.a15.0", "1.a5.0", "1.a500.0", - "1.a505.0" + "1.a505.0", ) } @@ -77,7 +77,7 @@ internal class SemVerTest { "2.0-a.b", "2.0", "2.0.a", - "2.0.a.b" + "2.0.a.b", ) } @@ -90,7 +90,7 @@ internal class SemVerTest { "1.0.0-rc-2", "1.0.0-rc-10", "1.0.0-rc-20", - "1.0.0" + "1.0.0", ) } @@ -113,28 +113,28 @@ internal class SemVerTest { assertSorted( "1.9.0", "1.10.0", - "1.11.0" + "1.11.0", ) assertSorted( "1.0.0-0.3.7", "1.0.0-alpha", "1.0.0-alpha.1", - "1.0.0-x.7.z.92" + "1.0.0-x.7.z.92", ) assertSorted( "1.0.0-alpha+001", "1.0.0-beta+exp.sha.5114f85", - "1.0.0+20130313144700" + "1.0.0+20130313144700", ) assertSorted( "1.0.0", "2.0.0", "2.1.0", - "2.1.1" + "2.1.1", ) assertSorted( "1.0.0-alpha", - "1.0.0" + "1.0.0", ) assertSorted( "1.0.0-alpha", @@ -144,7 +144,7 @@ internal class SemVerTest { "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", - "1.0.0" + "1.0.0", ) } @@ -152,7 +152,7 @@ internal class SemVerTest { fun wideNumbers() { assertSorted( "10000000000000000000.0", - "10000000000000000000.1" + "10000000000000000000.1", ) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/DagCheckerTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/DagCheckerTest.kt index 0f6dde1477..5e532b8f18 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/DagCheckerTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/DagCheckerTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -106,14 +106,14 @@ class DagCheckerTest { val nodes = listOf("a", "b", "c", "d", "e", "f", "g", "h") val edges = listOf( "ae", "ba", "cb", "cd", "dc", "eb", - "fb", "fe", "fg", "gc", "gf", "hd", "hg", "hh" + "fb", "fe", "fg", "gc", "gf", "hd", "hg", "hh", ) val cycleFinder = DagChecker(nodes) { it.targets(edges) } assertThat(cycleFinder.check()).containsExactly( listOf("a", "e", "b"), listOf("c", "d"), listOf("f", "g"), - listOf("h") + listOf("h"), ) } @@ -133,7 +133,7 @@ class DagCheckerTest { val edges = listOf( "ad", "ba", "cb", "de", "dg", "eb", "ef", "fi", - "he", "ih" + "he", "ih", ) val cycleFinder = DagChecker(nodes) { it.targets(edges) } assertThat(cycleFinder.check()).containsExactly(listOf("a", "d", "e", "b", "f", "i", "h")) diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/ProfileParserTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/ProfileParserTest.kt index 1475a5c4bb..b8655b26eb 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/ProfileParserTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/ProfileParserTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,6 +23,7 @@ import org.junit.Test class ProfileParserTest { private var location = Location.get("android.wire") + @Test fun parseType() { val proto = @@ -52,7 +53,7 @@ class ProfileParserTest { documentation = "Roar!", type = "squareup.dinosaurs.Dinosaur", target = "com.squareup.dino.Dinosaur", - adapter = "com.squareup.dino.Dinosaurs#DINO_ADAPTER" + adapter = "com.squareup.dino.Dinosaurs#DINO_ADAPTER", ), TypeConfigElement( @@ -60,13 +61,15 @@ class ProfileParserTest { type = "squareup.geology.Period", with = listOf( OptionElement.create( - "custom_type", OptionElement.Kind.STRING, "duration" - ) + "custom_type", + OptionElement.Kind.STRING, + "duration", + ), ), target = "java.time.Period", - adapter = "com.squareup.time.Time#PERIOD_ADAPTER" - ) - ) + adapter = "com.squareup.time.Time#PERIOD_ADAPTER", + ), + ), ) val parser = ProfileParser(location, proto) @@ -130,7 +133,8 @@ class ProfileParserTest { | with custom_type = "duration"; | target java.time.Period using com.squareup.time.Time#PERIOD_ADAPTER; |} - |""".trimMargin() + | + """.trimMargin() val parser = ProfileParser(location, proto) assertThat(parser.read().toSchema()).isEqualTo(proto) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/SchemaEncoderTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/SchemaEncoderTest.kt index 97c1da7a53..93bcd53e9a 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/SchemaEncoderTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/SchemaEncoderTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.schema.internal import com.google.protobuf.DescriptorProtos @@ -50,7 +65,8 @@ class SchemaEncoderTest { | option (fraternity) = [ALPHA, BETA, ALPHA]; | } |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -69,25 +85,25 @@ class SchemaEncoderTest { EnumValueDescriptorProto.newBuilder() .setName("ALPHA") .setNumber(1) - .build() + .build(), ) .addValue( EnumValueDescriptorProto.newBuilder() .setName("BETA") .setNumber(2) - .build() + .build(), ) - .build() + .build(), ) .addMessageType( DescriptorProto.newBuilder() .setName("HandleRequest") - .build() + .build(), ) .addMessageType( DescriptorProto.newBuilder() .setName("HandleResponse") - .build() + .build(), ) .addService( ServiceDescriptorProto.newBuilder() @@ -105,13 +121,13 @@ class SchemaEncoderTest { 22000, UnknownFieldSet.Field.newBuilder() .addFixed64(java.lang.Double.doubleToLongBits(2.1)) - .build() + .build(), ) .addField( 22001, UnknownFieldSet.Field.newBuilder() .addVarint(2L) - .build() + .build(), ) .addField( 22002, @@ -119,14 +135,14 @@ class SchemaEncoderTest { .addVarint(1L) .addVarint(2L) .addVarint(1L) - .build() + .build(), ) - .build() + .build(), ) - .build() + .build(), ) - .build() - ) + .build(), + ), ) .addExtension( FieldDescriptorProto.newBuilder() @@ -135,7 +151,7 @@ class SchemaEncoderTest { .setNumber(22000) .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) .setType(FieldDescriptorProto.Type.TYPE_DOUBLE) - .build() + .build(), ) .addExtension( FieldDescriptorProto.newBuilder() @@ -145,7 +161,7 @@ class SchemaEncoderTest { .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) .setType(FieldDescriptorProto.Type.TYPE_ENUM) .setTypeName(".GreekLetter") - .build() + .build(), ) .addExtension( FieldDescriptorProto.newBuilder() @@ -155,9 +171,9 @@ class SchemaEncoderTest { .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED) .setType(FieldDescriptorProto.Type.TYPE_ENUM) .setTypeName(".GreekLetter") - .build() + .build(), ) - .build() + .build(), ) } @@ -171,7 +187,8 @@ class SchemaEncoderTest { |message TestMessage { | extensions 5, 1000 to max; |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -189,17 +206,17 @@ class SchemaEncoderTest { ExtensionRange.newBuilder() .setStart(5) .setEnd(6) - .build() + .build(), ) .addExtensionRange( ExtensionRange.newBuilder() .setStart(1000) .setEnd(MAX_TAG_VALUE + 1) - .build() + .build(), ) - .build() + .build(), ) - .build() + .build(), ) } @@ -216,7 +233,8 @@ class SchemaEncoderTest { | NESTED_DEFINED = 1; | } |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -234,11 +252,11 @@ class SchemaEncoderTest { EnumDescriptorProto.newBuilder() .setName("Nested") .addValue(0, EnumValueDescriptorProto.newBuilder().setName("NESTED_UNDEFINED").setNumber(0)) - .addValue(1, EnumValueDescriptorProto.newBuilder().setName("NESTED_DEFINED").setNumber(1)) + .addValue(1, EnumValueDescriptorProto.newBuilder().setName("NESTED_DEFINED").setNumber(1)), ) - .build() + .build(), ) - .build() + .build(), ) } @@ -257,7 +275,8 @@ class SchemaEncoderTest { | string three = 3; | } |} - |""".trimMargin() + | + """.trimMargin(), ) } val handleServiceProto = schema.protoFile("test.proto")!! @@ -278,7 +297,7 @@ class SchemaEncoderTest { .setName("two") .setNumber(2) .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) - .build() + .build(), ) .addField( FieldDescriptorProto.newBuilder() @@ -287,7 +306,7 @@ class SchemaEncoderTest { .setNumber(1) .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) .setOneofIndex(0) - .build() + .build(), ) .addField( FieldDescriptorProto.newBuilder() @@ -296,16 +315,16 @@ class SchemaEncoderTest { .setNumber(3) .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) .setOneofIndex(0) - .build() + .build(), ) .addOneofDecl( DescriptorProtos.OneofDescriptorProto.newBuilder() .setName("a_oneof") - .build() + .build(), ) - .build() + .build(), ) - .build() + .build(), ) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/TypeMoverTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/TypeMoverTest.kt index 8ba0a5da77..494494c614 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/TypeMoverTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/TypeMoverTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -52,7 +52,7 @@ class TypeMoverTest { | optional Roast roast = 1; | optional bool decaf = 2; |} - """.trimMargin() + """.trimMargin(), ) add( "cafe/roast.proto".toPath(), @@ -65,13 +65,13 @@ class TypeMoverTest { | MEDIUM = 1; | DARK = 2; |} - """.trimMargin() + """.trimMargin(), ) } val newSchema = TypeMover( oldSchema, - listOf(TypeMover.Move(ProtoType.get("cafe", "EspressoShot"), "cafe/espresso.proto")) + listOf(TypeMover.Move(ProtoType.get("cafe", "EspressoShot"), "cafe/espresso.proto")), ).move() assertThat(newSchema.protoFile("cafe/cafe.proto")!!.toSchema()).isEqualTo( @@ -90,7 +90,8 @@ class TypeMoverTest { | | repeated EspressoShot shots = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) assertThat(newSchema.protoFile("cafe/espresso.proto")!!.toSchema()).isEqualTo( """ @@ -108,7 +109,8 @@ class TypeMoverTest { | | optional bool decaf = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -132,7 +134,7 @@ class TypeMoverTest { | optional Roast roast = 1; | optional bool decaf = 2; |} - """.trimMargin() + """.trimMargin(), ) add( "cafe/roast.proto".toPath(), @@ -145,13 +147,13 @@ class TypeMoverTest { | MEDIUM = 1; | DARK = 2; |} - """.trimMargin() + """.trimMargin(), ) } val newSchema = TypeMover( oldSchema, - listOf(TypeMover.Move(ProtoType.get("cafe", "EspressoShot"), "cafe/roast.proto")) + listOf(TypeMover.Move(ProtoType.get("cafe", "EspressoShot"), "cafe/roast.proto")), ).move() assertThat(newSchema.protoFile("cafe/cafe.proto")!!.toSchema()).isEqualTo( @@ -170,7 +172,8 @@ class TypeMoverTest { | | repeated EspressoShot shots = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) assertThat(newSchema.protoFile("cafe/roast.proto")!!.toSchema()).isEqualTo( """ @@ -191,7 +194,8 @@ class TypeMoverTest { | | optional bool decaf = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -213,7 +217,7 @@ class TypeMoverTest { | |message C { |} - """.trimMargin() + """.trimMargin(), ) } @@ -222,8 +226,8 @@ class TypeMoverTest { moves = listOf( TypeMover.Move(ProtoType.get("A"), "a.proto"), TypeMover.Move(ProtoType.get("B"), "b.proto"), - TypeMover.Move(ProtoType.get("C"), "c.proto") - ) + TypeMover.Move(ProtoType.get("C"), "c.proto"), + ), ).move() assertThat(newSchema.protoFile("abc.proto")!!.toSchema()).isEqualTo( @@ -232,7 +236,8 @@ class TypeMoverTest { |// Source: abc.proto | |syntax = "proto2"; - |""".trimMargin() + | + """.trimMargin(), ) assertThat(newSchema.protoFile("a.proto")!!.toSchema()).isEqualTo( @@ -250,7 +255,8 @@ class TypeMoverTest { | | optional C c = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) assertThat(newSchema.protoFile("b.proto")!!.toSchema()).isEqualTo( @@ -265,7 +271,8 @@ class TypeMoverTest { |message B { | optional C c = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) assertThat(newSchema.protoFile("c.proto")!!.toSchema()).isEqualTo( @@ -276,7 +283,8 @@ class TypeMoverTest { |syntax = "proto2"; | |message C {} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -296,7 +304,7 @@ class TypeMoverTest { |service C { | rpc Go (A) returns (B); |} - """.trimMargin() + """.trimMargin(), ) } @@ -304,8 +312,8 @@ class TypeMoverTest { oldSchema = oldSchema, moves = listOf( TypeMover.Move(ProtoType.get("A"), "a.proto"), - TypeMover.Move(ProtoType.get("B"), "b.proto") - ) + TypeMover.Move(ProtoType.get("B"), "b.proto"), + ), ).move() assertThat(newSchema.protoFile("abc.proto")!!.toSchema()).isEqualTo( @@ -321,7 +329,8 @@ class TypeMoverTest { |service C { | rpc Go (A) returns (B); |} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -337,7 +346,7 @@ class TypeMoverTest { |message A { | optional B b = 1; |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), @@ -346,7 +355,7 @@ class TypeMoverTest { | |message B { |} - """.trimMargin() + """.trimMargin(), ) } @@ -354,8 +363,8 @@ class TypeMoverTest { oldSchema = oldSchema, moves = listOf( TypeMover.Move(ProtoType.get("A"), "b.proto"), - TypeMover.Move(ProtoType.get("B"), "a.proto") - ) + TypeMover.Move(ProtoType.get("B"), "a.proto"), + ), ).move() assertThat(newSchema.protoFile("b.proto")!!.toSchema()).isEqualTo( @@ -370,7 +379,8 @@ class TypeMoverTest { |message A { | optional B b = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) assertThat(newSchema.protoFile("a.proto")!!.toSchema()).isEqualTo( """ @@ -380,7 +390,8 @@ class TypeMoverTest { |syntax = "proto2"; | |message B {} - |""".trimMargin() + | + """.trimMargin(), ) } @@ -395,21 +406,22 @@ class TypeMoverTest { | |message A { |} - """.trimMargin() + """.trimMargin(), ) add( "b.proto".toPath(), """ |syntax = "proto2"; - |""".trimMargin() + | + """.trimMargin(), ) } val newSchema = TypeMover( oldSchema = oldSchema, moves = listOf( - TypeMover.Move(ProtoType.get("A"), "c.proto") - ) + TypeMover.Move(ProtoType.get("A"), "c.proto"), + ), ).move() assertThat(newSchema.protoFile("a.proto")!!.toSchema()).isEqualTo( @@ -420,7 +432,8 @@ class TypeMoverTest { |syntax = "proto2"; | |import "b.proto"; - |""".trimMargin() + | + """.trimMargin(), ) } @@ -433,7 +446,7 @@ class TypeMoverTest { | |message A { |} - """.trimMargin() + """.trimMargin(), ) } @@ -441,8 +454,8 @@ class TypeMoverTest { TypeMover( oldSchema = oldSchema, moves = listOf( - TypeMover.Move(ProtoType.get("B"), "b.proto") - ) + TypeMover.Move(ProtoType.get("B"), "b.proto"), + ), ).move() fail() } catch (expected: IllegalArgumentException) { diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/UtilTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/UtilTest.kt index a225b1d69d..ebd77bafc8 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/UtilTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/UtilTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,12 +24,14 @@ class UtilTest { val input = """ |Foo |Bar - |Baz""".trimMargin() + |Baz + """.trimMargin() val expected = """ | Foo | Bar | Baz - |""".trimMargin() + | + """.trimMargin() val actual = buildString { appendIndented(input) } @@ -43,7 +45,8 @@ class UtilTest { |// Foo |// Bar |// Baz - |""".trimMargin() + | + """.trimMargin() val actual = buildString { appendDocumentation(input) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/EnumElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/EnumElementTest.kt index 79e532cb8e..85a44af72d 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/EnumElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/EnumElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,7 +28,7 @@ class EnumElementTest { fun emptyToSchema() { val element = EnumElement( location = location, - name = "Enum" + name = "Enum", ) val expected = "enum Enum {}\n" assertThat(element.toSchema()).isEqualTo(expected) @@ -42,8 +42,8 @@ class EnumElementTest { constants = listOf( EnumConstantElement(location = location, name = "ONE", tag = 1), EnumConstantElement(location = location, name = "TWO", tag = 2), - EnumConstantElement(location = location, name = "SIX", tag = 6) - ) + EnumConstantElement(location = location, name = "SIX", tag = 6), + ), ) val expected = """ |enum Enum { @@ -51,7 +51,8 @@ class EnumElementTest { | TWO = 2; | SIX = 6; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -63,7 +64,7 @@ class EnumElementTest { val element = EnumElement( location = location, name = "Enum", - constants = listOf(one, two, six) + constants = listOf(one, two, six), ) assertThat(element.constants).hasSize(3) } @@ -77,8 +78,8 @@ class EnumElementTest { constants = listOf( EnumConstantElement(location = location, name = "ONE", tag = 1), EnumConstantElement(location = location, name = "TWO", tag = 2), - EnumConstantElement(location = location, name = "SIX", tag = 6) - ) + EnumConstantElement(location = location, name = "SIX", tag = 6), + ), ) val expected = """ |enum Enum { @@ -87,7 +88,8 @@ class EnumElementTest { | TWO = 2; | SIX = 6; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -99,7 +101,7 @@ class EnumElementTest { location = location, name = "Enum", options = listOf(kitKat, fooBar), - constants = listOf(EnumConstantElement(location = location, name = "ONE", tag = 1)) + constants = listOf(EnumConstantElement(location = location, name = "ONE", tag = 1)), ) assertThat(element.options).hasSize(2) } @@ -114,8 +116,8 @@ class EnumElementTest { listOf( EnumConstantElement(location = location, name = "ONE", tag = 1), EnumConstantElement(location = location, name = "TWO", tag = 2), - EnumConstantElement(location = location, name = "SIX", tag = 6) - ) + EnumConstantElement(location = location, name = "SIX", tag = 6), + ), ) val expected = """ |// Hello @@ -124,7 +126,8 @@ class EnumElementTest { | TWO = 2; | SIX = 6; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -137,13 +140,13 @@ class EnumElementTest { ReservedElement(location = location, values = listOf(10, 12..14, "FOO")), ReservedElement(location = location, values = listOf(10)), ReservedElement(location = location, values = listOf(25..MAX_TAG_VALUE)), - ReservedElement(location = location, values = listOf("FOO")) + ReservedElement(location = location, values = listOf("FOO")), ), constants = listOf( EnumConstantElement(location = location, name = "ONE", tag = 1), EnumConstantElement(location = location, name = "TWO", tag = 2), - EnumConstantElement(location = location, name = "SIX", tag = 6) - ) + EnumConstantElement(location = location, name = "SIX", tag = 6), + ), ) val expected = """ |enum Enum { @@ -155,7 +158,8 @@ class EnumElementTest { | TWO = 2; | SIX = 6; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -172,12 +176,13 @@ class EnumElementTest { location = location, name = "NAME", tag = 1, - documentation = "Hello" + documentation = "Hello", ) val expected = """ |// Hello |NAME = 1; - |""".trimMargin() + | + """.trimMargin() assertThat(value.toSchema()).isEqualTo(expected) } @@ -189,15 +194,16 @@ class EnumElementTest { tag = 1, options = listOf( OptionElement.create("kit", STRING, "kat", true), - OptionElement.create("tit", STRING, "tat") - ) + OptionElement.create("tit", STRING, "tat"), + ), ) val expected = """ |NAME = 1 [ | (kit) = "kat", | tit = "tat" |]; - |""".trimMargin() + | + """.trimMargin() assertThat(value.toSchema()).isEqualTo(expected) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtendElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtendElementTest.kt index 3a9e1dd86d..723d2c1641 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtendElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtendElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ class ExtendElementTest { fun emptyToSchema() { val extend = ExtendElement( location = location, - name = "Name" + name = "Name", ) val expected = "extend Name {}\n" assertThat(extend.toSchema()).isEqualTo(expected) @@ -44,15 +44,16 @@ class ExtendElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val expected = """ |extend Name { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin() assertThat(extend.toSchema()).isEqualTo(expected) } @@ -63,19 +64,19 @@ class ExtendElementTest { label = REQUIRED, type = "string", name = "first_name", - tag = 1 + tag = 1, ) val lastName = FieldElement( location = location, label = REQUIRED, type = "string", name = "last_name", - tag = 2 + tag = 2, ) val extend = ExtendElement( location = location, name = "Name", - fields = listOf(firstName, lastName) + fields = listOf(firstName, lastName), ) assertThat(extend.fields).hasSize(2) } @@ -92,16 +93,17 @@ class ExtendElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val expected = """ |// Hello |extend Name { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin() assertThat(extend.toSchema()).isEqualTo(expected) } @@ -117,15 +119,16 @@ class ExtendElementTest { type = "string", name = "name", jsonName = "my_json", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val expected = """ |extend Name { | required string name = 1 [json_name = "my_json"]; |} - |""".trimMargin() + | + """.trimMargin() assertThat(extend.toSchema()).isEqualTo(expected) } @@ -142,16 +145,17 @@ class ExtendElementTest { type = "string", name = "name", tag = 1, - defaultValue = "defaultValue" - ) - ) + defaultValue = "defaultValue", + ), + ), ) val expected = """ |// Hello |extend Name { | required string name = 1 [default = "defaultValue"]; |} - |""".trimMargin() + | + """.trimMargin() assertThat(extend.toSchema()).isEqualTo(expected) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElementTest.kt index a0a3b5b4e1..4c575d6f97 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ExtensionsElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ class ExtensionsElementTest { fun singleValueToSchema() { val actual = ExtensionsElement( location = location, - values = listOf(500) + values = listOf(500), ) val expected = "extensions 500;\n" assertThat(actual.toSchema()).isEqualTo(expected) @@ -37,7 +37,7 @@ class ExtensionsElementTest { fun rangeToSchema() { val actual = ExtensionsElement( location = location, - values = listOf(500..505) + values = listOf(500..505), ) val expected = "extensions 500 to 505;\n" assertThat(actual.toSchema()).isEqualTo(expected) @@ -47,7 +47,7 @@ class ExtensionsElementTest { fun maxRangeToSchema() { val actual = ExtensionsElement( location = location, - values = listOf(500..MAX_TAG_VALUE) + values = listOf(500..MAX_TAG_VALUE), ) val expected = "extensions 500 to max;\n" assertThat(actual.toSchema()).isEqualTo(expected) @@ -58,12 +58,13 @@ class ExtensionsElementTest { val actual = ExtensionsElement( location = location, documentation = "Hello", - values = listOf(500) + values = listOf(500), ) val expected = """ |// Hello |extensions 500; - |""".trimMargin() + | + """.trimMargin() assertThat(actual.toSchema()).isEqualTo(expected) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/FieldElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/FieldElementTest.kt index 266318b6e1..91c840216f 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/FieldElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/FieldElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,14 +35,14 @@ class FieldElementTest { tag = 1, options = listOf( OptionElement.create("default", Kind.ENUM, "TEST"), - OptionElement.create("deprecated", Kind.BOOLEAN, "true") - ) + OptionElement.create("deprecated", Kind.BOOLEAN, "true"), + ), ) assertThat(field.options) .containsOnly( OptionElement.create("default", Kind.ENUM, "TEST"), - OptionElement.create("deprecated", Kind.BOOLEAN, "true") + OptionElement.create("deprecated", Kind.BOOLEAN, "true"), ) } @@ -56,7 +56,7 @@ class FieldElementTest { type = "string", name = "name", tag = 1, - options = listOf(kitKat, fooBar) + options = listOf(kitKat, fooBar), ) assertThat(field.options).hasSize(2) @@ -70,14 +70,15 @@ class FieldElementTest { type = "string", name = "name", tag = 1, - defaultValue = "defaultValue" + defaultValue = "defaultValue", ) assertThat(field.toSchema()) .isEqualTo( """ |required string name = 1 [default = "defaultValue"]; - |""".trimMargin() + | + """.trimMargin(), ) } @@ -90,7 +91,7 @@ class FieldElementTest { name = "name", defaultValue = "defaultValue", jsonName = "my_json", - tag = 1 + tag = 1, ) assertThat(field.toSchema()) @@ -100,7 +101,8 @@ class FieldElementTest { | default = "defaultValue", | json_name = "my_json" |]; - |""".trimMargin() + | + """.trimMargin(), ) } @@ -112,14 +114,15 @@ class FieldElementTest { type = "string", name = "name", jsonName = "my_json", - tag = 1 + tag = 1, ) assertThat(field.toSchema()) .isEqualTo( """ |required string name = 1 [json_name = "my_json"]; - |""".trimMargin() + | + """.trimMargin(), ) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt index 9845be1562..bfa09d2e22 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,11 +26,12 @@ import org.junit.Test class MessageElementTest { internal var location = Location.get("file.proto") + @Test fun emptyToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val expected = "message Message {}\n" assertThat(element.toSchema()).isEqualTo(expected) @@ -47,15 +48,16 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val expected = """ |message Message { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -66,19 +68,19 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "first_name", - tag = 1 + tag = 1, ) val lastName = FieldElement( location = location, label = REQUIRED, type = "string", name = "last_name", - tag = 2 + tag = 2, ) val element = MessageElement( location = location, name = "Message", - fields = listOf(firstName, lastName) + fields = listOf(firstName, lastName), ) assertThat(element.fields).hasSize(2) } @@ -95,16 +97,17 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val expected = """ |// Hello |message Message { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -115,13 +118,13 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 + tag = 1, ) val element = MessageElement( location = location, name = "Message", fields = listOf(field), - options = listOf(OptionElement.create("kit", Kind.STRING, "kat")) + options = listOf(OptionElement.create("kit", Kind.STRING, "kat")), ) val expected = """message Message { @@ -129,7 +132,8 @@ class MessageElementTest { | | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -140,7 +144,7 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 + tag = 1, ) val kitKat = OptionElement.create("kit", Kind.STRING, "kat") val fooBar = OptionElement.create("foo", Kind.STRING, "bar") @@ -148,7 +152,7 @@ class MessageElementTest { location = location, name = "Message", fields = listOf(field), - options = listOf(kitKat, fooBar) + options = listOf(kitKat, fooBar), ) assertThat(element.options).hasSize(2) } @@ -164,8 +168,8 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) + tag = 1, + ), ), nestedTypes = listOf( MessageElement( @@ -177,11 +181,11 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) - ) - ) - ) + tag = 1, + ), + ), + ), + ), ) val expected = """ |message Message { @@ -191,7 +195,8 @@ class MessageElementTest { | required string name = 1; | } |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -199,11 +204,11 @@ class MessageElementTest { fun addMultipleTypes() { val nested1 = MessageElement( location = location, - name = "Nested1" + name = "Nested1", ) val nested2 = MessageElement( location = location, - name = "Nested2" + name = "Nested2", ) val element = MessageElement( location = location, @@ -214,10 +219,10 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) + tag = 1, + ), ), - nestedTypes = listOf(nested1, nested2) + nestedTypes = listOf(nested1, nested2), ) assertThat(element.nestedTypes).hasSize(2) } @@ -233,10 +238,10 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) + tag = 1, + ), ), - extensions = listOf(ExtensionsElement(location = location, values = listOf(500..501))) + extensions = listOf(ExtensionsElement(location = location, values = listOf(500..501))), ) val expected = """ |message Message { @@ -244,7 +249,8 @@ class MessageElementTest { | | extensions 500 to 501; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -261,10 +267,10 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 - ) + tag = 1, + ), ), - extensions = listOf(fives, sixes) + extensions = listOf(fives, sixes), ) assertThat(element.extensions).hasSize(2) } @@ -282,11 +288,11 @@ class MessageElementTest { location = location, type = "string", name = "name", - tag = 1 - ) - ) - ) - ) + tag = 1, + ), + ), + ), + ), ) val expected = """ |message Message { @@ -294,7 +300,8 @@ class MessageElementTest { | string name = 1; | } |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -311,8 +318,8 @@ class MessageElementTest { location = location, type = "string", name = "name", - tag = 1 - ) + tag = 1, + ), ), groups = listOf( GroupElement( @@ -325,34 +332,35 @@ class MessageElementTest { label = OPTIONAL, type = "int32", name = "result_per_page", - tag = 4 + tag = 4, ), FieldElement( location = location.at(7, 7), label = OPTIONAL, type = "int32", name = "page_count", - tag = 5 - ) - ) - ) - ) - ) - ) + tag = 5, + ), + ), + ), + ), + ), + ), ) // spotless:off because spotless will remove the indents (trailing spaces) in the oneof block. val expected = """ |message Message { | oneof hi { | string name = 1; - | + | | group Stuff = 3 { | optional int32 result_per_page = 4; | optional int32 page_count = 5; | } | } |} - |""".trimMargin() + | + """.trimMargin() // spotless:on assertThat(element.toSchema()).isEqualTo(expected) } @@ -366,9 +374,9 @@ class MessageElementTest { location = location, type = "string", name = "name", - tag = 1 - ) - ) + tag = 1, + ), + ), ) val hey = OneOfElement( name = "hey", @@ -377,14 +385,14 @@ class MessageElementTest { location = location, type = "string", name = "city", - tag = 2 - ) - ) + tag = 2, + ), + ), ) val element = MessageElement( location = location, name = "Message", - oneOfs = listOf(hi, hey) + oneOfs = listOf(hi, hey), ) assertThat(element.oneOfs).hasSize(2) } @@ -398,8 +406,8 @@ class MessageElementTest { ReservedElement(location = location, values = listOf(10, 12..14, "foo")), ReservedElement(location = location, values = listOf(10)), ReservedElement(location = location, values = listOf(12..MAX_TAG_VALUE)), - ReservedElement(location = location, values = listOf("foo")) - ) + ReservedElement(location = location, values = listOf("foo")), + ), ) val expected = """ |message Message { @@ -408,7 +416,8 @@ class MessageElementTest { | reserved 12 to max; | reserved "foo"; |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -429,25 +438,25 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "url", - tag = 2 + tag = 2, ), FieldElement( location = location.at(4, 5), label = OPTIONAL, type = "string", name = "title", - tag = 3 + tag = 3, ), FieldElement( location = location.at(5, 5), label = REPEATED, type = "string", name = "snippets", - tag = 4 - ) - ) - ) - ) + tag = 4, + ), + ), + ), + ), ) val expected = """ |message SearchResponse { @@ -457,7 +466,8 @@ class MessageElementTest { | repeated string snippets = 4; | } |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -468,48 +478,48 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 2 + tag = 2, ) val oneOf1Field1 = FieldElement( location = location.at(1, 1), type = "string", name = "namey", - tag = 1 + tag = 1, ) val oneOf1Field2 = FieldElement( location = location.at(2, 1), type = "int32", name = "aField", - tag = 5 + tag = 5, ) val oneOf1 = OneOfElement( name = "thingy", - fields = listOf(oneOf1Field1, oneOf1Field2) + fields = listOf(oneOf1Field1, oneOf1Field2), ) val field2 = FieldElement( location = location.at(2, 3), label = REQUIRED, type = "bool", name = "other_name", - tag = 3 + tag = 3, ) val oneOf2Field = FieldElement( location = location.at(3, 0), type = "string", name = "namer", - tag = 4 + tag = 4, ) val oneOf2 = OneOfElement( name = "thinger", - fields = listOf(oneOf2Field) + fields = listOf(oneOf2Field), ) val extensions1 = ExtensionsElement(location = location.at(5, 0), values = listOf(500..501)) val extensions2 = ExtensionsElement(location = location.at(6, 2), values = listOf(503)) val nested = MessageElement( location = location.at(7, 1), name = "Nested", - fields = listOf(field1) + fields = listOf(field1), ) val option = OptionElement.create("kit", Kind.STRING, "kat") val element = MessageElement( @@ -519,7 +529,7 @@ class MessageElementTest { oneOfs = listOf(oneOf1, oneOf2), nestedTypes = listOf(nested), extensions = listOf(extensions1, extensions2), - options = listOf(option) + options = listOf(option), ) val expected = """ |message Message { @@ -545,7 +555,8 @@ class MessageElementTest { | required string name = 2; | } |} - |""".trimMargin() + | + """.trimMargin() assertThat(element.toSchema()).isEqualTo(expected) } @@ -556,7 +567,7 @@ class MessageElementTest { label = REQUIRED, type = "string", name = "name", - tag = 1 + tag = 1, ) val expected = "required string name = 1;\n" assertThat(field.toSchema()).isEqualTo(expected) @@ -570,7 +581,7 @@ class MessageElementTest { type = "string", name = "name", tag = 1, - defaultValue = "benoît" + defaultValue = "benoît", ) val expected = "required string name = 1 [default = \"benoît\"];\n" assertThat(field.toSchema()).isEqualTo(expected) @@ -584,7 +595,7 @@ class MessageElementTest { type = "int32", name = "age", tag = 1, - defaultValue = "34" + defaultValue = "34", ) val expected = "required int32 age = 1 [default = 34];\n" assertThat(field.toSchema()).isEqualTo(expected) @@ -598,7 +609,7 @@ class MessageElementTest { type = "bool", name = "human", tag = 1, - defaultValue = "true" + defaultValue = "true", ) val expected = "required bool human = 1 [default = true];\n" assertThat(field.toSchema()).isEqualTo(expected) @@ -610,7 +621,7 @@ class MessageElementTest { location = location, type = "string", name = "name", - tag = 1 + tag = 1, ) val expected = "string name = 1;\n" assertThat(field.toSchema()).isEqualTo(expected) @@ -624,12 +635,13 @@ class MessageElementTest { type = "string", name = "name", tag = 1, - documentation = "Hello" + documentation = "Hello", ) val expected = """// Hello |required string name = 1; - |""".trimMargin() + | + """.trimMargin() assertThat(field.toSchema()).isEqualTo(expected) } @@ -641,11 +653,12 @@ class MessageElementTest { type = "string", name = "name", tag = 1, - options = listOf(OptionElement.create("kit", Kind.STRING, "kat")) + options = listOf(OptionElement.create("kit", Kind.STRING, "kat")), ) val expected = """required string name = 1 [kit = "kat"]; - |""".trimMargin() + | + """.trimMargin() assertThat(field.toSchema()).isEqualTo(expected) } @@ -659,15 +672,16 @@ class MessageElementTest { tag = 1, options = listOf( OptionElement.create("kit", Kind.STRING, "kat"), - OptionElement.create("dup", Kind.STRING, "lo") - ) + OptionElement.create("dup", Kind.STRING, "lo"), + ), ) val expected = """required string name = 1 [ | kit = "kat", | dup = "lo" |]; - |""".trimMargin() + | + """.trimMargin() assertThat(field.toSchema()).isEqualTo(expected) } @@ -679,7 +693,8 @@ class MessageElementTest { | int32 page_number = 2; | int32 result_per_page = 3; |} - |""".trimMargin() + | + """.trimMargin() val oneOf = OneOfElement( name = "page_info", fields = listOf( @@ -687,18 +702,18 @@ class MessageElementTest { location = location.at(4, 5), type = "int32", name = "page_number", - tag = 2 + tag = 2, ), FieldElement( location = location.at(5, 5), type = "int32", name = "result_per_page", - tag = 3 - ) + tag = 3, + ), ), options = listOf( - OptionElement.create("my_option", Kind.BOOLEAN, "true", true) - ) + OptionElement.create("my_option", Kind.BOOLEAN, "true", true), + ), ) assertThat(oneOf.toSchema()).isEqualTo(expected) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/OptionElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/OptionElementTest.kt index 616a36739c..a5c0b8014e 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/OptionElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/OptionElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,23 +46,25 @@ class OptionElementTest { LIST, listOf( OptionElement.create("ping", STRING, "pong", true), - OptionElement.create("kit", STRING, "kat") + OptionElement.create("kit", STRING, "kat"), ), - true + true, ) val expected = """ |(foo) = [ | (ping) = "pong", | kit = "kat" |] - """.trimMargin() + """.trimMargin() assertThat(option.toSchema()).isEqualTo(expected) } @Test fun mapToSchema() { val option = OptionElement.create( - "foo", MAP, mapOf("ping" to "pong", "kit" to listOf("kat", "kot")) + "foo", + MAP, + mapOf("ping" to "pong", "kit" to listOf("kat", "kot")), ) val expected = """ |foo = { @@ -72,7 +74,7 @@ class OptionElementTest { | "kot" | ] |} - """.trimMargin() + """.trimMargin() assertThat(option.toSchema()).isEqualTo(expected) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ParsingTester.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ParsingTester.kt index bd34e1cf36..01fbe94331 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ParsingTester.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ParsingTester.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,11 +16,11 @@ package com.squareup.wire.schema.internal.parser import com.squareup.wire.schema.Location -import okio.buffer -import okio.source import java.io.File import java.util.ArrayDeque import java.util.Collections +import okio.buffer +import okio.source /** Recursively traverse a directory and attempt to parse all of its proto files. */ object ParsingTester { diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElementTest.kt index 19844d9320..b54a09d6f2 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoFileElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,8 @@ class ProtoFileElementTest { val expected = """ |// Proto schema formatted by Wire, do not edit. |// Source: file.proto - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -41,14 +42,15 @@ class ProtoFileElementTest { fun emptyWithPackageToSchema() { val file = ProtoFileElement( location = location, - packageName = "example.simple" + packageName = "example.simple", ) val expected = """ |// Proto schema formatted by Wire, do not edit. |// Source: file.proto | |package example.simple; - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -56,18 +58,19 @@ class ProtoFileElementTest { fun simpleToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val file = ProtoFileElement( location = location, - types = listOf(element) + types = listOf(element), ) val expected = """ |// Proto schema formatted by Wire, do not edit. |// Source: file.proto | |message Message {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -75,12 +78,12 @@ class ProtoFileElementTest { fun simpleWithImportsToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val file = ProtoFileElement( location = location, imports = listOf("example.other"), - types = listOf(element) + types = listOf(element), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -89,7 +92,8 @@ class ProtoFileElementTest { |import "example.other"; | |message Message {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -97,12 +101,12 @@ class ProtoFileElementTest { fun addMultipleDependencies() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val file = ProtoFileElement( location = location, imports = listOf("example.other", "example.another"), - types = listOf(element) + types = listOf(element), ) assertThat(file.imports).hasSize(2) } @@ -111,12 +115,12 @@ class ProtoFileElementTest { fun simpleWithPublicImportsToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val file = ProtoFileElement( location = location, publicImports = listOf("example.other"), - types = listOf(element) + types = listOf(element), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -125,7 +129,8 @@ class ProtoFileElementTest { |import public "example.other"; | |message Message {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -133,12 +138,12 @@ class ProtoFileElementTest { fun addMultiplePublicDependencies() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val file = ProtoFileElement( location = location, publicImports = listOf("example.other", "example.another"), - types = listOf(element) + types = listOf(element), ) assertThat(file.publicImports).hasSize(2) } @@ -147,13 +152,13 @@ class ProtoFileElementTest { fun simpleWithBothImportsToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val file = ProtoFileElement( location = location, imports = listOf("example.thing"), publicImports = listOf("example.other"), - types = listOf(element) + types = listOf(element), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -163,7 +168,8 @@ class ProtoFileElementTest { |import public "example.other"; | |message Message {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -171,16 +177,16 @@ class ProtoFileElementTest { fun simpleWithServicesToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val service = ServiceElement( location = location, - name = "Service" + name = "Service", ) val file = ProtoFileElement( location = location, types = listOf(element), - services = listOf(service) + services = listOf(service), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -189,7 +195,8 @@ class ProtoFileElementTest { |message Message {} | |service Service {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -197,15 +204,15 @@ class ProtoFileElementTest { fun addMultipleServices() { val service1 = ServiceElement( location = location, - name = "Service1" + name = "Service1", ) val service2 = ServiceElement( location = location, - name = "Service2" + name = "Service2", ) val file = ProtoFileElement( location = location, - services = listOf(service1, service2) + services = listOf(service1, service2), ) assertThat(file.services).hasSize(2) } @@ -214,13 +221,13 @@ class ProtoFileElementTest { fun simpleWithOptionsToSchema() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val option = OptionElement.create("kit", Kind.STRING, "kat") val file = ProtoFileElement( location = location, options = listOf(option), - types = listOf(element) + types = listOf(element), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -229,7 +236,8 @@ class ProtoFileElementTest { |option kit = "kat"; | |message Message {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -237,14 +245,14 @@ class ProtoFileElementTest { fun addMultipleOptions() { val element = MessageElement( location = location, - name = "Message" + name = "Message", ) val kitKat = OptionElement.create("kit", Kind.STRING, "kat") val fooBar = OptionElement.create("foo", Kind.STRING, "bar") val file = ProtoFileElement( location = location, options = listOf(kitKat, fooBar), - types = listOf(element) + types = listOf(element), ) assertThat(file.options).hasSize(2) } @@ -254,7 +262,7 @@ class ProtoFileElementTest { val file = ProtoFileElement( location = location, extendDeclarations = listOf(ExtendElement(location = location.at(5, 1), name = "Extend")), - types = listOf(MessageElement(location = location, name = "Message")) + types = listOf(MessageElement(location = location, name = "Message")), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -263,7 +271,8 @@ class ProtoFileElementTest { |message Message {} | |extend Extend {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -273,7 +282,7 @@ class ProtoFileElementTest { val extend2 = ExtendElement(location = location, name = "Extend2") val file = ProtoFileElement( location = location, - extendDeclarations = listOf(extend1, extend2) + extendDeclarations = listOf(extend1, extend2), ) assertThat(file.extendDeclarations).hasSize(2) } @@ -288,11 +297,11 @@ class ProtoFileElementTest { val option2 = OptionElement.create("foo", Kind.STRING, "bar") val service1 = ServiceElement( location = location.at(20, 1), - name = "Service1" + name = "Service1", ) val service2 = ServiceElement( location = location.at(22, 1), - name = "Service2" + name = "Service2", ) val file = ProtoFileElement( location = location, @@ -302,7 +311,7 @@ class ProtoFileElementTest { types = listOf(element1, element2), services = listOf(service1, service2), extendDeclarations = listOf(extend1, extend2), - options = listOf(option1, option2) + options = listOf(option1, option2), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -327,7 +336,8 @@ class ProtoFileElementTest { |service Service1 {} | |service Service2 {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) // Re-parse the expected string into a ProtoFile and ensure they're equal. @@ -341,7 +351,7 @@ class ProtoFileElementTest { val file = ProtoFileElement( location = location, syntax = PROTO_2, - types = listOf(element) + types = listOf(element), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -350,7 +360,8 @@ class ProtoFileElementTest { |syntax = "proto2"; | |message Message {} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) } @@ -362,7 +373,7 @@ class ProtoFileElementTest { type = "string", name = "name", tag = 1, - defaultValue = "defaultValue" + defaultValue = "defaultValue", ) val message = MessageElement(location = location.at(11, 1), name = "Message", fields = listOf(field)) @@ -372,7 +383,7 @@ class ProtoFileElementTest { packageName = "example.simple", imports = listOf("example.thing"), publicImports = listOf("example.other"), - types = listOf(message) + types = listOf(message), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -388,7 +399,8 @@ class ProtoFileElementTest { |message Message { | required string name = 1 [default = "defaultValue"]; |} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) // Re-parse the expected string into a ProtoFile and ensure they're equal. @@ -403,7 +415,7 @@ class ProtoFileElementTest { label = Field.Label.REPEATED, type = "int32", name = "numeric_without_packed_option", - tag = 1 + tag = 1, ) val fieldNumericPackedTrue = FieldElement( location = location.at(11, 3), @@ -411,7 +423,7 @@ class ProtoFileElementTest { type = "int32", name = "numeric_packed_true", tag = 2, - options = listOf(PACKED_OPTION_ELEMENT) + options = listOf(PACKED_OPTION_ELEMENT), ) val fieldNumericPackedFalse = FieldElement( location = location.at(13, 3), @@ -419,14 +431,14 @@ class ProtoFileElementTest { type = "int32", name = "numeric_packed_false", tag = 3, - options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")) + options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")), ) val fieldString = FieldElement( location = location.at(15, 3), label = Field.Label.REPEATED, type = "string", name = "string_without_packed_option", - tag = 4 + tag = 4, ) val fieldStringPackedTrue = FieldElement( location = location.at(17, 3), @@ -434,7 +446,7 @@ class ProtoFileElementTest { type = "string", name = "string_packed_true", tag = 5, - options = listOf(PACKED_OPTION_ELEMENT) + options = listOf(PACKED_OPTION_ELEMENT), ) val fieldStringPackedFalse = FieldElement( location = location.at(19, 3), @@ -442,16 +454,20 @@ class ProtoFileElementTest { type = "string", name = "string_packed_false", tag = 6, - options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")) + options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")), ) val message = MessageElement( location = location.at(8, 1), name = "Message", fields = listOf( - fieldNumeric, fieldNumericPackedTrue, fieldNumericPackedFalse, fieldString, - fieldStringPackedTrue, fieldStringPackedFalse - ) + fieldNumeric, + fieldNumericPackedTrue, + fieldNumericPackedFalse, + fieldString, + fieldStringPackedTrue, + fieldStringPackedFalse, + ), ) val file = ProtoFileElement( syntax = PROTO_2, @@ -459,7 +475,7 @@ class ProtoFileElementTest { packageName = "example.simple", imports = emptyList(), publicImports = emptyList(), - types = listOf(message) + types = listOf(message), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -482,7 +498,8 @@ class ProtoFileElementTest { | | repeated string string_packed_false = 6 [packed = false]; |} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) // Re-parse the expected string into a ProtoFile and ensure they're equal. @@ -497,7 +514,7 @@ class ProtoFileElementTest { label = Field.Label.REPEATED, type = "int32", name = "numeric_without_packed_option", - tag = 1 + tag = 1, ) val fieldNumericPackedTrue = FieldElement( location = location.at(11, 3), @@ -505,7 +522,7 @@ class ProtoFileElementTest { type = "int32", name = "numeric_packed_true", tag = 2, - options = listOf(PACKED_OPTION_ELEMENT) + options = listOf(PACKED_OPTION_ELEMENT), ) val fieldNumericPackedFalse = FieldElement( location = location.at(13, 3), @@ -513,14 +530,14 @@ class ProtoFileElementTest { type = "int32", name = "numeric_packed_false", tag = 3, - options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")) + options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")), ) val fieldString = FieldElement( location = location.at(15, 3), label = Field.Label.REPEATED, type = "string", name = "string_without_packed_option", - tag = 4 + tag = 4, ) val fieldStringPackedTrue = FieldElement( location = location.at(17, 3), @@ -528,7 +545,7 @@ class ProtoFileElementTest { type = "string", name = "string_packed_true", tag = 5, - options = listOf(PACKED_OPTION_ELEMENT) + options = listOf(PACKED_OPTION_ELEMENT), ) val fieldStringPackedFalse = FieldElement( location = location.at(19, 3), @@ -536,16 +553,20 @@ class ProtoFileElementTest { type = "string", name = "string_packed_false", tag = 6, - options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")) + options = listOf(PACKED_OPTION_ELEMENT.copy(value = "false")), ) val message = MessageElement( location = location.at(8, 1), name = "Message", fields = listOf( - fieldNumeric, fieldNumericPackedTrue, fieldNumericPackedFalse, fieldString, - fieldStringPackedTrue, fieldStringPackedFalse - ) + fieldNumeric, + fieldNumericPackedTrue, + fieldNumericPackedFalse, + fieldString, + fieldStringPackedTrue, + fieldStringPackedFalse, + ), ) val file = ProtoFileElement( syntax = PROTO_3, @@ -553,7 +574,7 @@ class ProtoFileElementTest { packageName = "example.simple", imports = emptyList(), publicImports = emptyList(), - types = listOf(message) + types = listOf(message), ) val expected = """ |// Proto schema formatted by Wire, do not edit. @@ -576,7 +597,8 @@ class ProtoFileElementTest { | | repeated string string_packed_false = 6 [packed = false]; |} - |""".trimMargin() + | + """.trimMargin() assertThat(file.toSchema()).isEqualTo(expected) // Re-parse the expected string into a ProtoFile and ensure they're equal. diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt index 4b2797f2b9..9d2ccd8e03 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ProtoParserTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,11 +22,11 @@ import com.squareup.wire.schema.Field.Label.REQUIRED import com.squareup.wire.schema.Location import com.squareup.wire.schema.internal.MAX_TAG_VALUE import com.squareup.wire.schema.internal.parser.OptionElement.Kind +import java.util.Arrays +import java.util.LinkedHashMap import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import java.util.Arrays -import java.util.LinkedHashMap class ProtoParserTest { internal var location = Location.get("file.proto") @@ -56,7 +56,7 @@ class ProtoParserTest { | required arbitrary f19 = 19; | required nested.nested f20 = 20; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, @@ -70,142 +70,142 @@ class ProtoParserTest { label = REQUIRED, type = "any", name = "f1", - tag = 1 + tag = 1, ), FieldElement( location = location.at(3, 3), label = REQUIRED, type = "bool", name = "f2", - tag = 2 + tag = 2, ), FieldElement( location = location.at(4, 3), label = REQUIRED, type = "bytes", name = "f3", - tag = 3 + tag = 3, ), FieldElement( location = location.at(5, 3), label = REQUIRED, type = "double", name = "f4", - tag = 4 + tag = 4, ), FieldElement( location = location.at(6, 3), label = REQUIRED, type = "float", name = "f5", - tag = 5 + tag = 5, ), FieldElement( location = location.at(7, 3), label = REQUIRED, type = "fixed32", name = "f6", - tag = 6 + tag = 6, ), FieldElement( location = location.at(8, 3), label = REQUIRED, type = "fixed64", name = "f7", - tag = 7 + tag = 7, ), FieldElement( location = location.at(9, 3), label = REQUIRED, type = "int32", name = "f8", - tag = 8 + tag = 8, ), FieldElement( location = location.at(10, 3), label = REQUIRED, type = "int64", name = "f9", - tag = 9 + tag = 9, ), FieldElement( location = location.at(11, 3), label = REQUIRED, type = "sfixed32", name = "f10", - tag = 10 + tag = 10, ), FieldElement( location = location.at(12, 3), label = REQUIRED, type = "sfixed64", name = "f11", - tag = 11 + tag = 11, ), FieldElement( location = location.at(13, 3), label = REQUIRED, type = "sint32", name = "f12", - tag = 12 + tag = 12, ), FieldElement( location = location.at(14, 3), label = REQUIRED, type = "sint64", name = "f13", - tag = 13 + tag = 13, ), FieldElement( location = location.at(15, 3), label = REQUIRED, type = "string", name = "f14", - tag = 14 + tag = 14, ), FieldElement( location = location.at(16, 3), label = REQUIRED, type = "uint32", name = "f15", - tag = 15 + tag = 15, ), FieldElement( location = location.at(17, 3), label = REQUIRED, type = "uint64", name = "f16", - tag = 16 + tag = 16, ), FieldElement( location = location.at(18, 3), type = "map", name = "f17", - tag = 17 + tag = 17, ), FieldElement( location = location.at(19, 3), type = "map", name = "f18", - tag = 18 + tag = 18, ), FieldElement( location = location.at(20, 3), label = REQUIRED, type = "arbitrary", name = "f19", - tag = 19 + tag = 19, ), FieldElement( location = location.at(21, 3), label = REQUIRED, type = "nested.nested", name = "f20", - tag = 20 - ) - ) - ) - ) + tag = 20, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) @@ -218,7 +218,7 @@ class ProtoParserTest { fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:1:15: 'map' type cannot have label" + "Syntax error in file.proto:1:15: 'map' type cannot have label", ) } @@ -227,7 +227,7 @@ class ProtoParserTest { fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:1:15: 'map' type cannot have label" + "Syntax error in file.proto:1:15: 'map' type cannot have label", ) } @@ -236,7 +236,7 @@ class ProtoParserTest { fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:1:15: 'map' type cannot have label" + "Syntax error in file.proto:1:15: 'map' type cannot have label", ) } } @@ -248,7 +248,8 @@ class ProtoParserTest { |message Message { | required string a = 1 [default = "b", faulted = "c"]; |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( location = location, @@ -264,11 +265,11 @@ class ProtoParserTest { name = "a", defaultValue = "b", options = listOf(OptionElement.create("faulted", Kind.STRING, "c")), - tag = 1 - ) - ) - ) - ) + tag = 1, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -280,7 +281,8 @@ class ProtoParserTest { |message Message { | required string a = 1 [json_name = "b", faulted = "c"]; |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( location = location, @@ -296,11 +298,11 @@ class ProtoParserTest { name = "a", jsonName = "b", tag = 1, - options = listOf(OptionElement.create("faulted", Kind.STRING, "c")) - ) - ) - ) - ) + options = listOf(OptionElement.create("faulted", Kind.STRING, "c")), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -310,7 +312,7 @@ class ProtoParserTest { val proto = """ |// Test all the things! |message Test {} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] assertThat(type.documentation).isEqualTo("Test all the things!") @@ -322,11 +324,11 @@ class ProtoParserTest { |// Test all |// the things! |message Test {} - """.trimMargin() + """.trimMargin() val expected = """ |Test all |the things! - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] @@ -338,7 +340,8 @@ class ProtoParserTest { val proto = """ |/** Test */ |message Test {} - |""".trimMargin() + | + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] assertThat(type.documentation).isEqualTo("Test") @@ -353,12 +356,13 @@ class ProtoParserTest { | * Foo | */ |message Test {} - |""".trimMargin() + | + """.trimMargin() val expected = """ |Test | |Foo - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] assertThat(type.documentation).isEqualTo(expected) @@ -372,13 +376,13 @@ class ProtoParserTest { |// The |// Things! |message Test {} - """.trimMargin() + """.trimMargin() val expected = """ |Test | All | The | Things! - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] assertThat(type.documentation).isEqualTo(expected) @@ -394,13 +398,13 @@ class ProtoParserTest { | * Things! | */ |message Test {} - """.trimMargin() + """.trimMargin() val expected = """ |Test | All | The | Things! - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] assertThat(type.documentation).isEqualTo(expected) @@ -417,13 +421,13 @@ class ProtoParserTest { | Things! | */ |message Test {} - """.trimMargin() + """.trimMargin() val expected = """ |Test |All |The |Things! - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val type = parsed.types[0] assertThat(type.documentation).isEqualTo(expected) @@ -436,7 +440,7 @@ class ProtoParserTest { |message Test { | optional string name = 1; // Test all the things! |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val message = parsed.types[0] as MessageElement val field = message.fields[0] @@ -450,7 +454,7 @@ class ProtoParserTest { | // Test all... | optional string name = 1; // ...the things! |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val message = parsed.types[0] as MessageElement val field = message.fields[0] @@ -464,7 +468,7 @@ class ProtoParserTest { | optional string first_name = 1; // Testing! | optional string last_name = 2; |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val message = parsed.types[0] as MessageElement val field1 = message.fields[0] @@ -479,7 +483,7 @@ class ProtoParserTest { |enum Test { | FOO = 1; // Test all the things! |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val enumElement = parsed.types[0] as EnumElement val value = enumElement.constants[0] @@ -493,7 +497,7 @@ class ProtoParserTest { | FOO = 1; /* Test all the things! */ | BAR = 2;/*Test all the things!*/ |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val enumElement = parsed.types[0] as EnumElement val foo = enumElement.constants[0] @@ -509,7 +513,7 @@ class ProtoParserTest { | FOO = 1; /* Test all the |things! */ |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val enumElement = parsed.types[0] as EnumElement val value = enumElement.constants[0] @@ -522,13 +526,13 @@ class ProtoParserTest { |enum Test { | FOO = 1; /* Test all the things! */ BAR = 2; |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:2:40: no syntax may follow trailing comment" + "Syntax error in file.proto:2:40: no syntax may follow trailing comment", ) } } @@ -539,13 +543,13 @@ class ProtoParserTest { |message Test { | optional string 3DS = 1; |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:2:18: field and constant names cannot start with a digit" + "Syntax error in file.proto:2:18: field and constant names cannot start with a digit", ) } } @@ -556,13 +560,13 @@ class ProtoParserTest { |enum Test { | 3DS = 1; |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:2:2: field and constant names cannot start with a digit" + "Syntax error in file.proto:2:2: field and constant names cannot start with a digit", ) } } @@ -573,13 +577,13 @@ class ProtoParserTest { |enum Test { | FOO = 1; / |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (e: IllegalStateException) { assertThat(e).hasMessage( - "Syntax error in file.proto:2:13: expected '//' or '/*'" + "Syntax error in file.proto:2:13: expected '//' or '/*'", ) } } @@ -591,7 +595,7 @@ class ProtoParserTest { | // Test all... | FOO = 1; // ...the things! |} - """.trimMargin() + """.trimMargin() val parsed = ProtoParser.parse(location, proto) val enumElement = parsed.types[0] as EnumElement val value = enumElement.constants[0] @@ -623,16 +627,16 @@ class ProtoParserTest { val proto = """ |syntax = "proto3"; |message Foo {} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, syntax = PROTO_3, types = listOf( MessageElement( location = location.at(2, 1), - name = "Foo" - ) - ) + name = "Foo", + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -642,7 +646,7 @@ class ProtoParserTest { val proto = """ |syntax = "proto4"; |message Foo {} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() @@ -656,13 +660,13 @@ class ProtoParserTest { val proto = """ |message Foo {} |syntax = "proto3"; - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (expected: IllegalStateException) { assertThat(expected).hasMessage( - "Syntax error in file.proto:2:1: 'syntax' element must be the first declaration in a file" + "Syntax error in file.proto:2:1: 'syntax' element must be the first declaration in a file", ) } } @@ -675,16 +679,16 @@ class ProtoParserTest { | |syntax = "proto3"; |message Foo {} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, syntax = PROTO_3, types = listOf( MessageElement( location = location.at(5, 1), - name = "Foo" - ) - ) + name = "Foo", + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -697,7 +701,7 @@ class ProtoParserTest { | string a = 1; | int32 b = 2; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, syntax = PROTO_3, @@ -710,17 +714,17 @@ class ProtoParserTest { location = location.at(3, 3), type = "string", name = "a", - tag = 1 + tag = 1, ), FieldElement( location = location.at(4, 3), type = "int32", name = "b", - tag = 2 - ) - ) - ) - ) + tag = 2, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -735,15 +739,15 @@ class ProtoParserTest { | string a = 1; | int32 b = 2; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, syntax = PROTO_3, types = listOf( MessageElement( location = location.at(2, 1), - name = "Message" - ) + name = "Message", + ), ), extendDeclarations = listOf( ExtendElement( @@ -754,17 +758,17 @@ class ProtoParserTest { location = location.at(5, 3), type = "string", name = "a", - tag = 1 + tag = 1, ), FieldElement( location = location.at(6, 3), type = "int32", name = "b", - tag = 2 - ) - ) - ) - ) + tag = 2, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -776,7 +780,7 @@ class ProtoParserTest { |message Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, @@ -791,11 +795,11 @@ class ProtoParserTest { type = "string", name = "a", tag = 1, - label = OPTIONAL - ) - ) - ) - ) + label = OPTIONAL, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -807,13 +811,13 @@ class ProtoParserTest { |message Message { | required string a = 1; |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (expected: IllegalStateException) { assertThat(expected).hasMessage( - "Syntax error in file.proto:3:3: 'required' label forbidden in proto3 field declarations" + "Syntax error in file.proto:3:3: 'required' label forbidden in proto3 field declarations", ) } } @@ -827,15 +831,15 @@ class ProtoParserTest { |extend Message { | optional string a = 1; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, syntax = PROTO_3, types = listOf( MessageElement( location = location.at(2, 1), - name = "Message" - ) + name = "Message", + ), ), extendDeclarations = listOf( ExtendElement( @@ -847,11 +851,11 @@ class ProtoParserTest { type = "string", name = "a", tag = 1, - label = OPTIONAL - ) - ) - ) - ) + label = OPTIONAL, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -865,13 +869,13 @@ class ProtoParserTest { |extend Message { | required string a = 1; |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() } catch (expected: IllegalStateException) { assertThat(expected).hasMessage( - "Syntax error in file.proto:5:3: 'required' label forbidden in proto3 field declarations" + "Syntax error in file.proto:5:3: 'required' label forbidden in proto3 field declarations", ) } } @@ -883,7 +887,7 @@ class ProtoParserTest { |message Message { | repeated string a = 1; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, @@ -898,11 +902,11 @@ class ProtoParserTest { label = REPEATED, type = "string", name = "a", - tag = 1 - ) - ) - ) - ) + tag = 1, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -916,15 +920,15 @@ class ProtoParserTest { |extend Message { | repeated string a = 1; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, syntax = PROTO_3, types = listOf( MessageElement( location = location.at(2, 1), - name = "Message" - ) + name = "Message", + ), ), extendDeclarations = listOf( ExtendElement( @@ -936,11 +940,11 @@ class ProtoParserTest { label = REPEATED, type = "string", name = "a", - tag = 1 - ) - ) - ) - ) + tag = 1, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -953,7 +957,7 @@ class ProtoParserTest { | optional int32 page_number = 2; | optional int32 result_per_page = 3; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -966,25 +970,25 @@ class ProtoParserTest { label = REQUIRED, type = "string", name = "query", - tag = 1 + tag = 1, ), FieldElement( location = location.at(3, 3), label = OPTIONAL, type = "int32", name = "page_number", - tag = 2 + tag = 2, ), FieldElement( location = location.at(4, 3), label = OPTIONAL, type = "int32", name = "result_per_page", - tag = 3 - ) - ) - ) - ) + tag = 3, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -999,7 +1003,7 @@ class ProtoParserTest { | repeated string snippets = 4; | } |} - """.trimMargin() + """.trimMargin() val message = MessageElement( location = location.at(1, 1), name = "SearchResponse", @@ -1015,29 +1019,29 @@ class ProtoParserTest { label = REQUIRED, type = "string", name = "url", - tag = 2 + tag = 2, ), FieldElement( location = location.at(4, 5), label = OPTIONAL, type = "string", name = "title", - tag = 3 + tag = 3, ), FieldElement( location = location.at(5, 5), label = REPEATED, type = "string", name = "snippets", - tag = 4 - ) - ) - ) - ) + tag = 4, + ), + ), + ), + ), ) val expected = ProtoFileElement( location = location, - types = listOf(message) + types = listOf(message), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1052,7 +1056,7 @@ class ProtoParserTest { | int32 result_per_page = 3; | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1065,8 +1069,8 @@ class ProtoParserTest { label = REQUIRED, type = "string", name = "query", - tag = 1 - ) + tag = 1, + ), ), oneOfs = listOf( OneOfElement( @@ -1076,19 +1080,19 @@ class ProtoParserTest { location = location.at(4, 5), type = "int32", name = "page_number", - tag = 2 + tag = 2, ), FieldElement( location = location.at(5, 5), type = "int32", name = "result_per_page", - tag = 3 - ) - ) - ) - ) - ) - ) + tag = 3, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1106,7 +1110,7 @@ class ProtoParserTest { | } | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1119,8 +1123,8 @@ class ProtoParserTest { label = REQUIRED, type = "string", name = "query", - tag = 1 - ) + tag = 1, + ), ), oneOfs = listOf( OneOfElement( @@ -1130,8 +1134,8 @@ class ProtoParserTest { location = location.at(4, 5), type = "int32", name = "page_number", - tag = 2 - ) + tag = 2, + ), ), groups = listOf( GroupElement( @@ -1144,22 +1148,22 @@ class ProtoParserTest { label = OPTIONAL, type = "int32", name = "result_per_page", - tag = 4 + tag = 4, ), FieldElement( location = location.at(7, 7), label = OPTIONAL, type = "int32", name = "page_count", - tag = 5 - ) - ) - ) - ) - ) - ) - ) - ) + tag = 5, + ), + ), + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1179,7 +1183,7 @@ class ProtoParserTest { | // Quebec Maple syrup | SYRUP = 3; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1191,23 +1195,23 @@ class ProtoParserTest { EnumConstantElement( location = location.at(6, 3), name = "FRUIT", - tag = 1 + tag = 1, ), EnumConstantElement( location = location.at(8, 3), name = "CREAM", tag = 2, - documentation = "Yummy, yummy cream." + documentation = "Yummy, yummy cream.", ), EnumConstantElement( location = location.at(11, 3), name = "SYRUP", tag = 3, - documentation = "Quebec Maple syrup" - ) - ) - ) - ) + documentation = "Quebec Maple syrup", + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1229,7 +1233,7 @@ class ProtoParserTest { | // Quebec Maple syrup | SYRUP = 3; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1244,24 +1248,24 @@ class ProtoParserTest { name = "FRUIT", tag = 1, options = listOf( - OptionElement.create("healthy", Kind.BOOLEAN, "true", true) - ) + OptionElement.create("healthy", Kind.BOOLEAN, "true", true), + ), ), EnumConstantElement( location = location.at(10, 3), name = "CREAM", tag = 2, - documentation = "Yummy, yummy cream." + documentation = "Yummy, yummy cream.", ), EnumConstantElement( location = location.at(13, 3), name = "SYRUP", tag = 3, - documentation = "Quebec Maple syrup" - ) - ) - ) - ) + documentation = "Quebec Maple syrup", + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1276,7 +1280,7 @@ class ProtoParserTest { |// files it parses. |message FileDescriptorSet { |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, packageName = "google.protobuf", @@ -1284,10 +1288,10 @@ class ProtoParserTest { MessageElement( location = location.at(6, 1), name = "FileDescriptorSet", - documentation = "The protocol compiler can output a FileDescriptorSet containing the .proto\nfiles it parses." - ) + documentation = "The protocol compiler can output a FileDescriptorSet containing the .proto\nfiles it parses.", + ), ), - options = listOf(OptionElement.create("java_package", Kind.STRING, "com.google.protobuf")) + options = listOf(OptionElement.create("java_package", Kind.STRING, "com.google.protobuf")), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1304,7 +1308,7 @@ class ProtoParserTest { | extensions 500; | extensions 1000 to max; |} - """.trimMargin() + """.trimMargin() val enumElement = EnumElement( location = location.at(3, 3), name = "CType", @@ -1315,10 +1319,10 @@ class ProtoParserTest { tag = 0, options = listOf( OptionElement.create("opt_a", Kind.NUMBER, "1", true), - OptionElement.create("opt_b", Kind.NUMBER, "2", true) - ) - ) - ) + OptionElement.create("opt_b", Kind.NUMBER, "2", true), + ), + ), + ), ) val field = FieldElement( location = location.at(2, 3), @@ -1328,13 +1332,13 @@ class ProtoParserTest { tag = 1, options = listOf( OptionElement.create("old_default", Kind.ENUM, "STRING"), - OptionElement.create("deprecated", Kind.BOOLEAN, "true") - ) + OptionElement.create("deprecated", Kind.BOOLEAN, "true"), + ), ) assertThat(field.options) .containsOnly( OptionElement.create("old_default", Kind.ENUM, "STRING"), - OptionElement.create("deprecated", Kind.BOOLEAN, "true") + OptionElement.create("deprecated", Kind.BOOLEAN, "true"), ) val messageElement = MessageElement( @@ -1346,14 +1350,14 @@ class ProtoParserTest { ExtensionsElement( location = location.at(7, 3), documentation = "Clients can define custom options in extensions of this message. See above.", - values = listOf(500) + values = listOf(500), ), - ExtensionsElement(location.at(8, 3), "", listOf(1000..MAX_TAG_VALUE)) - ) + ExtensionsElement(location.at(8, 3), "", listOf(1000..MAX_TAG_VALUE)), + ), ) val expected = ProtoFileElement( location = location, - types = listOf(messageElement) + types = listOf(messageElement), ) val actual = ProtoParser.parse(location, proto) assertThat(actual).isEqualTo(expected) @@ -1365,7 +1369,7 @@ class ProtoParserTest { |message MeGustaExtensions { | extensions 1, 5 to 200, 500, 1000 to max; |} - """.trimMargin() + """.trimMargin() val messageElement = MessageElement( location = location.at(1, 1), name = "MeGustaExtensions", @@ -1374,13 +1378,13 @@ class ProtoParserTest { extensions = listOf( ExtensionsElement( location = location.at(2, 3), - values = listOf(1, 5..200, 500, 1000..MAX_TAG_VALUE) - ) - ) + values = listOf(1, 5..200, 500, 1000..MAX_TAG_VALUE), + ), + ), ) val expected = ProtoFileElement( location = location, - types = listOf(messageElement) + types = listOf(messageElement), ) val actual = ProtoParser.parse(location, proto) assertThat(actual).isEqualTo(expected) @@ -1395,7 +1399,7 @@ class ProtoParserTest { | optional bool coo_coo_ca_cha = 3[old_default = true, (delay) = 200]; | optional bool cha_chee_cha = 4; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, @@ -1411,8 +1415,8 @@ class ProtoParserTest { name = "koka_ko_koka_ko", tag = 1, options = listOf( - OptionElement.create("old_default", Kind.BOOLEAN, "true") - ) + OptionElement.create("old_default", Kind.BOOLEAN, "true"), + ), ), FieldElement( location = location.at(3, 3), @@ -1422,8 +1426,8 @@ class ProtoParserTest { tag = 2, options = listOf( OptionElement.create("delay", Kind.NUMBER, "100", true), - OptionElement.create("old_default", Kind.BOOLEAN, "false") - ) + OptionElement.create("old_default", Kind.BOOLEAN, "false"), + ), ), FieldElement( location = location.at(4, 3), @@ -1433,19 +1437,19 @@ class ProtoParserTest { tag = 3, options = listOf( OptionElement.create("old_default", Kind.BOOLEAN, "true"), - OptionElement.create("delay", Kind.NUMBER, "200", true) - ) + OptionElement.create("delay", Kind.NUMBER, "200", true), + ), ), FieldElement( location = location.at(5, 3), label = OPTIONAL, type = "bool", name = "cha_chee_cha", - tag = 4 - ) - ) - ) - ) + tag = 4, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1455,7 +1459,7 @@ class ProtoParserTest { val proto = "import \"src/test/resources/unittest_import.proto\";\n" val expected = ProtoFileElement( location = location, - imports = listOf("src/test/resources/unittest_import.proto") + imports = listOf("src/test/resources/unittest_import.proto"), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1465,7 +1469,7 @@ class ProtoParserTest { val proto = "import public \"src/test/resources/unittest_import.proto\";\n" val expected = ProtoFileElement( location = location, - publicImports = listOf("src/test/resources/unittest_import.proto") + publicImports = listOf("src/test/resources/unittest_import.proto"), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1477,7 +1481,7 @@ class ProtoParserTest { |extend Foo { | optional int32 bar = 126; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, extendDeclarations = listOf( @@ -1491,11 +1495,11 @@ class ProtoParserTest { label = OPTIONAL, type = "int32", name = "bar", - tag = 126 - ) - ) - ) - ) + tag = 126, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1508,7 +1512,7 @@ class ProtoParserTest { | optional Bar bar = 126; | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1525,13 +1529,13 @@ class ProtoParserTest { label = OPTIONAL, type = "Bar", name = "bar", - tag = 126 - ) - ) - ) - ) - ) - ) + tag = 126, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1546,7 +1550,7 @@ class ProtoParserTest { | optional Bar bar = 126; | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, packageName = "kit.kat", @@ -1564,13 +1568,13 @@ class ProtoParserTest { label = OPTIONAL, type = "Bar", name = "bar", - tag = 126 - ) - ) - ) - ) - ) - ) + tag = 126, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1583,7 +1587,7 @@ class ProtoParserTest { | optional Bar bar = 126; | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1600,13 +1604,13 @@ class ProtoParserTest { label = OPTIONAL, type = "Bar", name = "bar", - tag = 126 - ) - ) - ) - ) - ) - ) + tag = 126, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1621,7 +1625,7 @@ class ProtoParserTest { | optional Bar bar = 126; | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, packageName = "kit.kat", @@ -1639,13 +1643,13 @@ class ProtoParserTest { label = OPTIONAL, type = "Bar", name = "bar", - tag = 126 - ) - ) - ) - ) - ) - ) + tag = 126, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1656,14 +1660,14 @@ class ProtoParserTest { |message Foo { | optional string claim_token = 2[(squareup.redacted) = true]; |} - """.trimMargin() + """.trimMargin() val field = FieldElement( location = location.at(2, 3), label = OPTIONAL, type = "string", name = "claim_token", tag = 2, - options = listOf(OptionElement.create("squareup.redacted", Kind.BOOLEAN, "true", true)) + options = listOf(OptionElement.create("squareup.redacted", Kind.BOOLEAN, "true", true)), ) assertThat(field.options) .containsOnly(OptionElement.create("squareup.redacted", Kind.BOOLEAN, "true", true)) @@ -1671,11 +1675,11 @@ class ProtoParserTest { val messageElement = MessageElement( location = location.at(1, 1), name = "Foo", - fields = listOf(field) + fields = listOf(field), ) val expected = ProtoFileElement( location = location, - types = listOf(messageElement) + types = listOf(messageElement), ) assertThat(ProtoParser.parse(location, proto)) .isEqualTo(expected) @@ -1690,7 +1694,7 @@ class ProtoParserTest { | x = "\a\b\f\n\r\t\v\1f\01\001\11\011\111\xe\Xe\xE\xE\x41\X41" | ]; |} - """.trimMargin() + """.trimMargin() val field = FieldElement( location = location.at(2, 3), label = OPTIONAL, @@ -1699,27 +1703,29 @@ class ProtoParserTest { tag = 1, options = listOf( OptionElement.create( - "x", Kind.STRING, - "\u0007\b\u000C\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA" - ) - ) + "x", + Kind.STRING, + "\u0007\b\u000C\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA", + ), + ), ) assertThat(field.options) .containsOnly( OptionElement.create( - "x", Kind.STRING, - "\u0007\b\u000C\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA" - ) + "x", + Kind.STRING, + "\u0007\b\u000C\n\r\t\u000b\u0001f\u0001\u0001\u0009\u0009I\u000e\u000e\u000e\u000eAA", + ), ) val messageElement = MessageElement( location = location.at(1, 1), name = "Foo", - fields = listOf(field) + fields = listOf(field), ) val expected = ProtoFileElement( location = location, - types = listOf(messageElement) + types = listOf(messageElement), ) assertThat(ProtoParser.parse(location, proto)) .isEqualTo(expected) @@ -1731,7 +1737,7 @@ class ProtoParserTest { |message Foo { | optional string name = 1[default = 'single\"quotes']; |} - """.trimMargin() + """.trimMargin() val field = FieldElement( location = location.at(2, 3), @@ -1739,16 +1745,16 @@ class ProtoParserTest { type = "string", name = "name", tag = 1, - defaultValue = "single\"quotes" + defaultValue = "single\"quotes", ) val messageElement = MessageElement( location = location.at(1, 1), name = "Foo", - fields = listOf(field) + fields = listOf(field), ) val expected = ProtoFileElement( location = location, - types = listOf(messageElement) + types = listOf(messageElement), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1763,7 +1769,7 @@ class ProtoParserTest { | "please" | ]; |} - """.trimMargin() + """.trimMargin() val field = FieldElement( location = location.at(2, 3), @@ -1771,16 +1777,16 @@ class ProtoParserTest { type = "string", name = "name", tag = 1, - defaultValue = "concat these please" + defaultValue = "concat these please", ) val messageElement = MessageElement( location = location.at(1, 1), name = "Foo", - fields = listOf(field) + fields = listOf(field), ) val expected = ProtoFileElement( location = location, - types = listOf(messageElement) + types = listOf(messageElement), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1791,7 +1797,7 @@ class ProtoParserTest { |message Foo { | optional string name = 1 [default = "\xW"]; |} - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() @@ -1817,7 +1823,7 @@ class ProtoParserTest { | }; | } |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, services = listOf( @@ -1825,14 +1831,14 @@ class ProtoParserTest { location = location.at(1, 1), name = "SearchService", options = listOf( - OptionElement.create("default_timeout", Kind.NUMBER, "30", true) + OptionElement.create("default_timeout", Kind.NUMBER, "30", true), ), rpcs = listOf( RpcElement( location = location.at(4, 3), name = "Search", requestType = "SearchRequest", - responseType = "SearchResponse" + responseType = "SearchResponse", ), RpcElement( location = location.at(5, 3), @@ -1845,13 +1851,13 @@ class ProtoParserTest { "squareup.a.b", Kind.MAP, mapOf("value" to listOf(OptionElement.OptionPrimitive(Kind.ENUM, "FOO"), OptionElement.OptionPrimitive(Kind.ENUM, "BAR"))), - true - ) - ) - ) - ) - ) - ) + true, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1865,7 +1871,7 @@ class ProtoParserTest { | rpc RecordRoute (stream Point) returns (RouteSummary) {} | rpc RouteChat (stream RouteNote) returns (stream RouteNote) {} |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, services = listOf( @@ -1877,21 +1883,21 @@ class ProtoParserTest { location = location.at(2, 3), name = "GetFeature", requestType = "Point", - responseType = "Feature" + responseType = "Feature", ), RpcElement( location = location.at(3, 3), name = "ListFeatures", requestType = "Rectangle", responseType = "Feature", - responseStreaming = true + responseStreaming = true, ), RpcElement( location = location.at(4, 3), name = "RecordRoute", requestType = "Point", responseType = "RouteSummary", - requestStreaming = true + requestStreaming = true, ), RpcElement( location = location.at(5, 3), @@ -1899,11 +1905,11 @@ class ProtoParserTest { requestType = "RouteNote", responseType = "RouteNote", requestStreaming = true, - responseStreaming = true - ) - ) - ) - ) + responseStreaming = true, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1915,7 +1921,7 @@ class ProtoParserTest { | required string hex = 0x10; | required string uppercase_x_hex = 0X11; |} - """.trimMargin() + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -1928,18 +1934,18 @@ class ProtoParserTest { label = REQUIRED, type = "string", name = "hex", - tag = 16 + tag = 16, ), FieldElement( location = location.at(3, 3), label = REQUIRED, type = "string", name = "uppercase_x_hex", - tag = 17 - ) - ) - ) - ) + tag = 17, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -1954,7 +1960,7 @@ class ProtoParserTest { | option (squareup.three) = {x: {y: 1 y: 2 } }; // NOTE: Omitted optional comma | option (squareup.four) = {x: {y: {z: 1 }, y: {z: 2 }}}; |} - """.trimMargin() + """.trimMargin() val option_one_map = LinkedHashMap() option_one_map["name"] = "Name" @@ -1986,18 +1992,27 @@ class ProtoParserTest { options = listOf( OptionElement.create("squareup.one", Kind.MAP, option_one_map, true), OptionElement.create( - "squareup.two.a", Kind.MAP, option_two_a_map, true + "squareup.two.a", + Kind.MAP, + option_two_a_map, + true, ), OptionElement.create( - "squareup.two.b", Kind.MAP, option_two_b_map, true + "squareup.two.b", + Kind.MAP, + option_two_b_map, + true, ), OptionElement.create( - "squareup.three", Kind.MAP, option_three_map, true + "squareup.three", + Kind.MAP, + option_three_map, + true, ), - OptionElement.create("squareup.four", Kind.MAP, option_four_map, true) - ) - ) - ) + OptionElement.create("squareup.four", Kind.MAP, option_four_map, true), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2013,7 +2028,7 @@ class ProtoParserTest { | (option_string) = ["string1","string2"] | ]; |} - """.trimMargin() + """.trimMargin() val field = FieldElement( location = location.at(2, 5), label = OPTIONAL, @@ -2025,12 +2040,12 @@ class ProtoParserTest { "option_map", Kind.MAP, mapOf( - "nested_map" to mapOf("key" to "value", "key2" to listOf("value2a", "value2b")) + "nested_map" to mapOf("key" to "value", "key2" to listOf("value2a", "value2b")), ), - true + true, ), - OptionElement.create("option_string", Kind.LIST, listOf("string1", "string2"), true) - ) + OptionElement.create("option_string", Kind.LIST, listOf("string1", "string2"), true), + ), ) assertThat(field.options) .containsOnly( @@ -2038,21 +2053,21 @@ class ProtoParserTest { "option_map", Kind.MAP, mapOf( - "nested_map" to mapOf("key" to "value", "key2" to listOf("value2a", "value2b")) + "nested_map" to mapOf("key" to "value", "key2" to listOf("value2a", "value2b")), ), - true + true, ), - OptionElement.create("option_string", Kind.LIST, listOf("string1", "string2"), true) + OptionElement.create("option_string", Kind.LIST, listOf("string1", "string2"), true), ) val expected = MessageElement( location = location.at(1, 1), name = "StructuredOption", - fields = listOf(field) + fields = listOf(field), ) val protoFile = ProtoFileElement( location = location, - types = listOf(expected) + types = listOf(expected), ) assertThat(ProtoParser.parse(location, proto)) .isEqualTo(protoFile) @@ -2078,7 +2093,8 @@ class ProtoParserTest { | optional string default_string = 414 [x = "çok\a\b\f\n\r\t\v\1\01\001\17\017\176\x1\x01\x11\X1\X01\X11güzel" ]; | optional bytes default_bytes = 415 [x = "çok\a\b\f\n\r\t\v\1\01\001\17\017\176\x1\x01\x11\X1\X01\X11güzel" ]; | optional NestedEnum default_nested_enum = 416 [x = A ]; - |}""".trimMargin() + |} + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -2092,7 +2108,7 @@ class ProtoParserTest { type = "int32", name = "default_int32", tag = 401, - options = listOf(OptionElement.create("x", Kind.NUMBER, "2147483647")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "2147483647")), ), FieldElement( location = location.at(3, 3), @@ -2100,7 +2116,7 @@ class ProtoParserTest { type = "uint32", name = "default_uint32", tag = 402, - options = listOf(OptionElement.create("x", Kind.NUMBER, "4294967295")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "4294967295")), ), FieldElement( location = location.at(4, 3), @@ -2108,7 +2124,7 @@ class ProtoParserTest { type = "sint32", name = "default_sint32", tag = 403, - options = listOf(OptionElement.create("x", Kind.NUMBER, "-2147483648")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "-2147483648")), ), FieldElement( location = location.at(5, 3), @@ -2116,7 +2132,7 @@ class ProtoParserTest { type = "fixed32", name = "default_fixed32", tag = 404, - options = listOf(OptionElement.create("x", Kind.NUMBER, "4294967295")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "4294967295")), ), FieldElement( location = location.at(6, 3), @@ -2124,7 +2140,7 @@ class ProtoParserTest { type = "sfixed32", name = "default_sfixed32", tag = 405, - options = listOf(OptionElement.create("x", Kind.NUMBER, "-2147483648")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "-2147483648")), ), FieldElement( location = location.at(7, 3), @@ -2133,8 +2149,8 @@ class ProtoParserTest { name = "default_int64", tag = 406, options = listOf( - OptionElement.create("x", Kind.NUMBER, "9223372036854775807") - ) + OptionElement.create("x", Kind.NUMBER, "9223372036854775807"), + ), ), FieldElement( location = location.at(8, 3), @@ -2143,8 +2159,8 @@ class ProtoParserTest { name = "default_uint64", tag = 407, options = listOf( - OptionElement.create("x", Kind.NUMBER, "18446744073709551615") - ) + OptionElement.create("x", Kind.NUMBER, "18446744073709551615"), + ), ), FieldElement( location = location.at(9, 3), @@ -2153,8 +2169,8 @@ class ProtoParserTest { name = "default_sint64", tag = 408, options = listOf( - OptionElement.create("x", Kind.NUMBER, "-9223372036854775808") - ) + OptionElement.create("x", Kind.NUMBER, "-9223372036854775808"), + ), ), FieldElement( location = location.at(10, 3), @@ -2163,8 +2179,8 @@ class ProtoParserTest { name = "default_fixed64", tag = 409, options = listOf( - OptionElement.create("x", Kind.NUMBER, "18446744073709551615") - ) + OptionElement.create("x", Kind.NUMBER, "18446744073709551615"), + ), ), FieldElement( location = location.at(11, 3), @@ -2173,8 +2189,8 @@ class ProtoParserTest { name = "default_sfixed64", tag = 410, options = listOf( - OptionElement.create("x", Kind.NUMBER, "-9223372036854775808") - ) + OptionElement.create("x", Kind.NUMBER, "-9223372036854775808"), + ), ), FieldElement( location = location.at(12, 3), @@ -2182,7 +2198,7 @@ class ProtoParserTest { type = "bool", name = "default_bool", tag = 411, - options = listOf(OptionElement.create("x", Kind.BOOLEAN, "true")) + options = listOf(OptionElement.create("x", Kind.BOOLEAN, "true")), ), FieldElement( location = location.at(13, 3), @@ -2190,7 +2206,7 @@ class ProtoParserTest { type = "float", name = "default_float", tag = 412, - options = listOf(OptionElement.create("x", Kind.NUMBER, "123.456e7")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "123.456e7")), ), FieldElement( location = location.at(14, 3), @@ -2198,7 +2214,7 @@ class ProtoParserTest { type = "double", name = "default_double", tag = 413, - options = listOf(OptionElement.create("x", Kind.NUMBER, "123.456e78")) + options = listOf(OptionElement.create("x", Kind.NUMBER, "123.456e78")), ), FieldElement( location = location.at(15, 3), @@ -2210,9 +2226,9 @@ class ProtoParserTest { OptionElement.create( "x", Kind.STRING, - "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001\u0011güzel" - ) - ) + "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001\u0011güzel", + ), + ), ), FieldElement( location = location.at(17, 3), @@ -2224,9 +2240,9 @@ class ProtoParserTest { OptionElement.create( "x", Kind.STRING, - "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001\u0011güzel" - ) - ) + "çok\u0007\b\u000C\n\r\t\u000b\u0001\u0001\u0001\u000f\u000f~\u0001\u0001\u0011\u0001\u0001\u0011güzel", + ), + ), ), FieldElement( location = location.at(19, 3), @@ -2234,11 +2250,11 @@ class ProtoParserTest { type = "NestedEnum", name = "default_nested_enum", tag = 416, - options = listOf(OptionElement.create("x", Kind.ENUM, "A")) - ) - ) - ) - ) + options = listOf(OptionElement.create("x", Kind.ENUM, "A")), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2253,7 +2269,7 @@ class ProtoParserTest { | old_default = 20 | ]; |} - """.trimMargin() + """.trimMargin() val field = FieldElement( location = location.at(2, 3), label = OPTIONAL, @@ -2265,16 +2281,16 @@ class ProtoParserTest { "validation.range", Kind.OPTION, OptionElement.create("min", Kind.NUMBER, "1"), - true + true, ), OptionElement.create( "validation.range", Kind.OPTION, OptionElement.create("max", Kind.NUMBER, "100"), - true + true, ), - OptionElement.create("old_default", Kind.NUMBER, "20") - ) + OptionElement.create("old_default", Kind.NUMBER, "20"), + ), ) assertThat(field.options) .containsOnly( @@ -2282,25 +2298,25 @@ class ProtoParserTest { "validation.range", Kind.OPTION, OptionElement.create("min", Kind.NUMBER, "1"), - true + true, ), OptionElement.create( "validation.range", Kind.OPTION, OptionElement.create("max", Kind.NUMBER, "100"), - true + true, ), - OptionElement.create("old_default", Kind.NUMBER, "20") + OptionElement.create("old_default", Kind.NUMBER, "20"), ) val expected = MessageElement( location = location.at(1, 1), name = "Foo", - fields = listOf(field) + fields = listOf(field), ) val protoFile = ProtoFileElement( location = location, - types = listOf(expected) + types = listOf(expected), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(protoFile) } @@ -2311,20 +2327,20 @@ class ProtoParserTest { |message Foo { | reserved 10, 12 to 14, 23 to max, 'foo', "bar"; |} - """.trimMargin() + """.trimMargin() val message = MessageElement( location = location.at(1, 1), name = "Foo", reserveds = listOf( ReservedElement( location = location.at(2, 3), - values = listOf(10, 12..14, 23..MAX_TAG_VALUE, "foo", "bar") - ) - ) + values = listOf(10, 12..14, 23..MAX_TAG_VALUE, "foo", "bar"), + ), + ), ) val expected = ProtoFileElement( location = location, - types = listOf(message) + types = listOf(message), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2338,24 +2354,24 @@ class ProtoParserTest { | reserved 10, 12 to 14, 23 to max, 'FOO', "BAR"; | reserved 3; |} - """.trimMargin() + """.trimMargin() val message = EnumElement( location = location.at(1, 1), name = "Foo", reserveds = listOf( ReservedElement( location = location.at(2, 3), - values = listOf(10, 12..14, 23..MAX_TAG_VALUE, "FOO", "BAR") + values = listOf(10, 12..14, 23..MAX_TAG_VALUE, "FOO", "BAR"), ), ReservedElement( location = location.at(3, 3), - values = listOf(3) + values = listOf(3), ), ), ) val expected = ProtoFileElement( location = location, - types = listOf(message) + types = listOf(message), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2368,7 +2384,7 @@ class ProtoParserTest { | reserved 2; // This is reserved. | optional string c = 3; // This is C. |} - """.trimMargin() + """.trimMargin() val message = MessageElement( location = location.at(1, 1), @@ -2380,7 +2396,7 @@ class ProtoParserTest { type = "string", name = "a", tag = 1, - documentation = "This is A." + documentation = "This is A.", ), FieldElement( location = location.at(4, 3), @@ -2388,20 +2404,20 @@ class ProtoParserTest { type = "string", name = "c", tag = 3, - documentation = "This is C." - ) + documentation = "This is C.", + ), ), reserveds = listOf( ReservedElement( location = location.at(3, 3), values = listOf(2), - documentation = "This is reserved." - ) - ) + documentation = "This is reserved.", + ), + ), ) val expected = ProtoFileElement( location = location, - types = listOf(message) + types = listOf(message), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2421,11 +2437,11 @@ class ProtoParserTest { label = OPTIONAL, type = "A.B", name = "ab", - tag = 1 - ) - ) - ) - ) + tag = 1, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2436,7 +2452,8 @@ class ProtoParserTest { |message Foo { | optional string a = 1 [(wire.my_field_option).baz.value = "a"]; |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -2463,15 +2480,15 @@ class ProtoParserTest { name = "value", kind = Kind.STRING, isParenthesized = false, - value = "a" - ) - ) - ) - ) - ) - ) - ) - ) + value = "a", + ), + ), + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2493,7 +2510,8 @@ class ProtoParserTest { | oneof = 10; | extensions = 11; |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -2505,8 +2523,10 @@ class ProtoParserTest { EnumConstantElement(location.at(3, 3), "import", 1), EnumConstantElement(location.at(4, 3), "package", 2), EnumConstantElement( - location.at(7, 3), "message", 5, - documentation = "option = 3;\nreserved = 4;" + location.at(7, 3), + "message", + 5, + documentation = "option = 3;\nreserved = 4;", ), EnumConstantElement(location.at(8, 3), "enum", 6), EnumConstantElement(location.at(9, 3), "service", 7), @@ -2514,9 +2534,9 @@ class ProtoParserTest { EnumConstantElement(location.at(11, 3), "rpc", 9), EnumConstantElement(location.at(12, 3), "oneof", 10), EnumConstantElement(location.at(13, 3), "extensions", 11), - ) - ) - ) + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2560,7 +2580,8 @@ class ProtoParserTest { |message extensions { | optional extensions extensions = 1; |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( location = location, types = listOf( @@ -2569,122 +2590,158 @@ class ProtoParserTest { name = "syntax", fields = listOf( FieldElement( - location.at(2, 3), label = OPTIONAL, type = "syntax", - name = "syntax", tag = 1 - ) - ) + location.at(2, 3), + label = OPTIONAL, + type = "syntax", + name = "syntax", + tag = 1, + ), + ), ), MessageElement( location = location.at(4, 1), name = "import", fields = listOf( FieldElement( - location.at(5, 3), label = OPTIONAL, type = "import", - name = "import", tag = 1 - ) - ) + location.at(5, 3), + label = OPTIONAL, + type = "import", + name = "import", + tag = 1, + ), + ), ), MessageElement( location = location.at(7, 1), name = "package", fields = listOf( FieldElement( - location.at(8, 3), label = OPTIONAL, type = "package", - name = "package", tag = 1 - ) - ) + location.at(8, 3), + label = OPTIONAL, + type = "package", + name = "package", + tag = 1, + ), + ), ), MessageElement( location = location.at(10, 1), name = "option", fields = listOf( FieldElement( - location.at(11, 3), label = OPTIONAL, type = "option", - name = "option", tag = 1 - ) - ) + location.at(11, 3), + label = OPTIONAL, + type = "option", + name = "option", + tag = 1, + ), + ), ), MessageElement( location = location.at(13, 1), name = "reserved", fields = listOf( FieldElement( - location.at(14, 3), label = OPTIONAL, type = "reserved", - name = "reserved", tag = 1 - ) - ) + location.at(14, 3), + label = OPTIONAL, + type = "reserved", + name = "reserved", + tag = 1, + ), + ), ), MessageElement( location = location.at(16, 1), name = "message", fields = listOf( FieldElement( - location.at(17, 3), label = OPTIONAL, type = "message", - name = "message", tag = 1 - ) - ) + location.at(17, 3), + label = OPTIONAL, + type = "message", + name = "message", + tag = 1, + ), + ), ), MessageElement( location = location.at(19, 1), name = "enum", fields = listOf( FieldElement( - location.at(20, 3), label = OPTIONAL, type = "enum", - name = "enum", tag = 1 - ) - ) + location.at(20, 3), + label = OPTIONAL, + type = "enum", + name = "enum", + tag = 1, + ), + ), ), MessageElement( location = location.at(22, 1), name = "service", fields = listOf( FieldElement( - location.at(23, 3), label = OPTIONAL, type = "service", - name = "service", tag = 1 - ) - ) + location.at(23, 3), + label = OPTIONAL, + type = "service", + name = "service", + tag = 1, + ), + ), ), MessageElement( location = location.at(25, 1), name = "extend", fields = listOf( FieldElement( - location.at(26, 3), label = OPTIONAL, type = "extend", - name = "extend", tag = 1 - ) - ) + location.at(26, 3), + label = OPTIONAL, + type = "extend", + name = "extend", + tag = 1, + ), + ), ), MessageElement( location = location.at(28, 1), name = "rpc", fields = listOf( FieldElement( - location.at(29, 3), label = OPTIONAL, type = "rpc", - name = "rpc", tag = 1 - ) - ) + location.at(29, 3), + label = OPTIONAL, + type = "rpc", + name = "rpc", + tag = 1, + ), + ), ), MessageElement( location = location.at(31, 1), name = "oneof", fields = listOf( FieldElement( - location.at(32, 3), label = OPTIONAL, type = "oneof", - name = "oneof", tag = 1 - ) - ) + location.at(32, 3), + label = OPTIONAL, + type = "oneof", + name = "oneof", + tag = 1, + ), + ), ), MessageElement( location = location.at(34, 1), name = "extensions", fields = listOf( FieldElement( - location.at(35, 3), label = OPTIONAL, type = "extensions", - name = "extensions", tag = 1 - ) - ) + location.at(35, 3), + label = OPTIONAL, + type = "extensions", + name = "extensions", + tag = 1, + ), + ), ), - ) + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2729,7 +2786,8 @@ class ProtoParserTest { |message extensions { | // extensions extensions = 1; |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( syntax = PROTO_3, location = location, @@ -2738,31 +2796,33 @@ class ProtoParserTest { location = location.at(2, 1), name = "syntax", fields = listOf( - FieldElement(location.at(3, 3), type = "syntax", name = "syntax", tag = 1) - ) + FieldElement(location.at(3, 3), type = "syntax", name = "syntax", tag = 1), + ), ), MessageElement( location = location.at(5, 1), name = "import", fields = listOf( - FieldElement(location.at(6, 3), type = "import", name = "import", tag = 1) - ) + FieldElement(location.at(6, 3), type = "import", name = "import", tag = 1), + ), ), MessageElement( location = location.at(8, 1), name = "package", fields = listOf( - FieldElement(location.at(9, 3), type = "package", name = "package", tag = 1) - ) + FieldElement(location.at(9, 3), type = "package", name = "package", tag = 1), + ), ), MessageElement( location = location.at(11, 1), name = "option", options = listOf( OptionElement( - name = "option", kind = Kind.NUMBER, value = "1", - isParenthesized = false - ) + name = "option", + kind = Kind.NUMBER, + value = "1", + isParenthesized = false, + ), ), ), MessageElement( @@ -2781,8 +2841,8 @@ class ProtoParserTest { location = location.at(23, 1), name = "service", fields = listOf( - FieldElement(location.at(24, 3), type = "service", name = "service", tag = 1) - ) + FieldElement(location.at(24, 3), type = "service", name = "service", tag = 1), + ), ), MessageElement( location = location.at(26, 1), @@ -2792,8 +2852,8 @@ class ProtoParserTest { location = location.at(29, 1), name = "rpc", fields = listOf( - FieldElement(location.at(30, 3), type = "rpc", name = "rpc", tag = 1) - ) + FieldElement(location.at(30, 3), type = "rpc", name = "rpc", tag = 1), + ), ), MessageElement( location = location.at(32, 1), @@ -2803,7 +2863,7 @@ class ProtoParserTest { location = location.at(35, 1), name = "extensions", ), - ) + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2847,7 +2907,8 @@ class ProtoParserTest { |service extensions { | rpc extensions (google.protobuf.StringValue) returns (google.protobuf.StringValue); |} - |""".trimMargin() + | + """.trimMargin() val expected = ProtoFileElement( location = location, services = listOf( @@ -2856,122 +2917,146 @@ class ProtoParserTest { name = "syntax", rpcs = listOf( RpcElement( - location.at(2, 3), name = "syntax", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(2, 3), + name = "syntax", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(4, 1), name = "import", rpcs = listOf( RpcElement( - location.at(5, 3), name = "import", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(5, 3), + name = "import", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(7, 1), name = "package", rpcs = listOf( RpcElement( - location.at(8, 3), name = "package", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(8, 3), + name = "package", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(10, 1), name = "option", rpcs = listOf( RpcElement( - location.at(11, 3), name = "option", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(11, 3), + name = "option", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(13, 1), name = "reserved", rpcs = listOf( RpcElement( - location.at(14, 3), name = "reserved", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(14, 3), + name = "reserved", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(16, 1), name = "message", rpcs = listOf( RpcElement( - location.at(17, 3), name = "message", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(17, 3), + name = "message", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(19, 1), name = "enum", rpcs = listOf( RpcElement( - location.at(20, 3), name = "enum", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(20, 3), + name = "enum", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(22, 1), name = "service", rpcs = listOf( RpcElement( - location.at(23, 3), name = "service", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(23, 3), + name = "service", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(25, 1), name = "extend", rpcs = listOf( RpcElement( - location.at(26, 3), name = "extend", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(26, 3), + name = "extend", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(28, 1), name = "rpc", rpcs = listOf( RpcElement( - location.at(29, 3), name = "rpc", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(29, 3), + name = "rpc", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(31, 1), name = "oneof", rpcs = listOf( RpcElement( - location.at(32, 3), name = "oneof", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(32, 3), + name = "oneof", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), ServiceElement( location = location.at(34, 1), name = "extensions", rpcs = listOf( RpcElement( - location.at(35, 3), name = "extensions", - requestType = "google.protobuf.StringValue", responseType = "google.protobuf.StringValue" - ) - ) + location.at(35, 3), + name = "extensions", + requestType = "google.protobuf.StringValue", + responseType = "google.protobuf.StringValue", + ), + ), ), - ) + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -2980,7 +3065,7 @@ class ProtoParserTest { val proto = """ | syntax = "proto2"; | syntax = "proto2"; - """.trimMargin() + """.trimMargin() try { ProtoParser.parse(location, proto) fail() @@ -3013,8 +3098,8 @@ class ProtoParserTest { label = REQUIRED, type = "string", name = "query", - tag = 1 - ) + tag = 1, + ), ), oneOfs = listOf( OneOfElement( @@ -3024,25 +3109,27 @@ class ProtoParserTest { location = location.at(5, 5), type = "int32", name = "page_number", - tag = 2 + tag = 2, ), FieldElement( location = location.at(6, 5), type = "int32", name = "result_per_page", - tag = 3 - ) + tag = 3, + ), ), options = listOf( OptionElement.create( - "my_option", Kind.BOOLEAN, value = "true", - isParenthesized = true - ) - ) - ) - ) - ) - ) + "my_option", + Kind.BOOLEAN, + value = "true", + isParenthesized = true, + ), + ), + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } @@ -3067,14 +3154,15 @@ class ProtoParserTest { "custom_rule", Kind.MAP, mapOf( - "my_string" to "abc", "my_int" to OptionElement.OptionPrimitive(Kind.NUMBER, "3"), - "my_list" to listOf("a", "b", "c") + "my_string" to "abc", + "my_int" to OptionElement.OptionPrimitive(Kind.NUMBER, "3"), + "my_list" to listOf("a", "b", "c"), ), - isParenthesized = true - ) - ) - ) - ) + isParenthesized = true, + ), + ), + ), + ), ) assertThat(ProtoParser.parse(location, proto)).isEqualTo(expected) } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ServiceElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ServiceElementTest.kt index ddc6ad9d39..99d18d39a2 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ServiceElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/ServiceElementTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ class ServiceElementTest { fun emptyToSchema() { val service = ServiceElement( location = location, - name = "Service" + name = "Service", ) val expected = "service Service {}\n" assertThat(service.toSchema()).isEqualTo(expected) @@ -43,15 +43,16 @@ class ServiceElementTest { location = location, name = "Name", requestType = "RequestType", - responseType = "ResponseType" - ) - ) + responseType = "ResponseType", + ), + ), ) val expected = """ |service Service { | rpc Name (RequestType) returns (ResponseType); |} - |""".trimMargin() + | + """.trimMargin() assertThat(service.toSchema()).isEqualTo(expected) } @@ -61,18 +62,18 @@ class ServiceElementTest { location = location, name = "FirstName", requestType = "RequestType", - responseType = "ResponseType" + responseType = "ResponseType", ) val lastName = RpcElement( location = location, name = "LastName", requestType = "RequestType", - responseType = "ResponseType" + responseType = "ResponseType", ) val service = ServiceElement( location = location, name = "Service", - rpcs = listOf(firstName, lastName) + rpcs = listOf(firstName, lastName), ) assertThat(service.rpcs).hasSize(2) } @@ -88,9 +89,9 @@ class ServiceElementTest { location = location, name = "Name", requestType = "RequestType", - responseType = "ResponseType" - ) - ) + responseType = "ResponseType", + ), + ), ) val expected = """ |service Service { @@ -98,7 +99,8 @@ class ServiceElementTest { | | rpc Name (RequestType) returns (ResponseType); |} - |""".trimMargin() + | + """.trimMargin() assertThat(service.toSchema()).isEqualTo(expected) } @@ -115,9 +117,9 @@ class ServiceElementTest { location = location, name = "Name", requestType = "RequestType", - responseType = "ResponseType" - ) - ) + responseType = "ResponseType", + ), + ), ) assertThat(service.options).hasSize(2) } @@ -133,16 +135,17 @@ class ServiceElementTest { location = location, name = "Name", requestType = "RequestType", - responseType = "ResponseType" - ) - ) + responseType = "ResponseType", + ), + ), ) val expected = """ |// Hello |service Service { | rpc Name (RequestType) returns (ResponseType); |} - |""".trimMargin() + | + """.trimMargin() assertThat(service.toSchema()).isEqualTo(expected) } @@ -152,19 +155,20 @@ class ServiceElementTest { location = location, name = "Name", requestType = "RequestType", - responseType = "ResponseType" + responseType = "ResponseType", ) val service = ServiceElement( location = location, name = "Service", - rpcs = listOf(rpc, rpc) + rpcs = listOf(rpc, rpc), ) val expected = """ |service Service { | rpc Name (RequestType) returns (ResponseType); | rpc Name (RequestType) returns (ResponseType); |} - |""".trimMargin() + | + """.trimMargin() assertThat(service.toSchema()).isEqualTo(expected) } @@ -175,7 +179,7 @@ class ServiceElementTest { location = location, name = "Name", requestType = "RequestType", - responseType = "ResponseType" + responseType = "ResponseType", ) val expected = "rpc Name (RequestType) returns (ResponseType);\n" assertThat(rpc.toSchema()).isEqualTo(expected) @@ -188,12 +192,13 @@ class ServiceElementTest { name = "Name", documentation = "Hello", requestType = "RequestType", - responseType = "ResponseType" + responseType = "ResponseType", ) val expected = """ |// Hello |rpc Name (RequestType) returns (ResponseType); - |""".trimMargin() + | + """.trimMargin() assertThat(rpc.toSchema()).isEqualTo(expected) } @@ -204,14 +209,15 @@ class ServiceElementTest { name = "Name", requestType = "RequestType", responseType = "ResponseType", - options = listOf(OptionElement.create("foo", Kind.STRING, "bar")) + options = listOf(OptionElement.create("foo", Kind.STRING, "bar")), ) val expected = """ |rpc Name (RequestType) returns (ResponseType) { | option foo = "bar"; |}; - |""".trimMargin() + | + """.trimMargin() assertThat(rpc.toSchema()).isEqualTo(expected) } @@ -222,7 +228,7 @@ class ServiceElementTest { name = "Name", requestType = "RequestType", responseType = "ResponseType", - requestStreaming = true + requestStreaming = true, ) val expected = "rpc Name (stream RequestType) returns (ResponseType);\n" assertThat(rpc.toSchema()).isEqualTo(expected) @@ -235,7 +241,7 @@ class ServiceElementTest { name = "Name", requestType = "RequestType", responseType = "ResponseType", - responseStreaming = true + responseStreaming = true, ) val expected = "rpc Name (RequestType) returns (stream ResponseType);\n" assertThat(rpc.toSchema()).isEqualTo(expected) From 00abb930b9e88a641b14639493a6cdc6689eaeab Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 20:18:58 +0200 Subject: [PATCH 5/7] Spotless: wire-runtime --- wire-runtime/build.gradle.kts | 17 +++ .../kotlin/com/squareup/wire/AnyMessage.kt | 14 +-- .../kotlin/com/squareup/wire/Duration.kt | 5 +- .../kotlin/com/squareup/wire/EnumAdapter.kt | 10 +- .../kotlin/com/squareup/wire/FieldEncoding.kt | 6 +- .../kotlin/com/squareup/wire/Instant.kt | 4 +- .../kotlin/com/squareup/wire/Message.kt | 8 +- .../kotlin/com/squareup/wire/MessageSink.kt | 4 +- .../kotlin/com/squareup/wire/MessageSource.kt | 4 +- .../kotlin/com/squareup/wire/OneOf.kt | 8 +- .../kotlin/com/squareup/wire/ProtoAdapter.kt | 106 ++++++++++++------ .../kotlin/com/squareup/wire/ProtoReader.kt | 16 ++- .../kotlin/com/squareup/wire/ProtoWriter.kt | 4 +- .../com/squareup/wire/ReverseProtoWriter.kt | 8 +- .../kotlin/com/squareup/wire/Service.kt | 4 +- .../kotlin/com/squareup/wire/Syntax.kt | 7 +- .../kotlin/com/squareup/wire/WireEnum.kt | 4 +- .../com/squareup/wire/WireEnumConstant.kt | 4 +- .../kotlin/com/squareup/wire/WireField.kt | 15 ++- .../kotlin/com/squareup/wire/WireRpc.kt | 6 +- .../com/squareup/wire/internal/-Platform.kt | 6 +- .../wire/internal/FieldOrOneOfBinding.kt | 6 +- .../squareup/wire/internal/ImmutableList.kt | 7 +- .../com/squareup/wire/internal/Internal.kt | 10 +- .../squareup/wire/internal/MessageBinding.kt | 6 +- .../wire/internal/MutableOnWriteList.kt | 9 +- .../wire/internal/RuntimeMessageAdapter.kt | 10 +- .../kotlin/com/squareup/wire/internal/Util.kt | 2 +- .../kotlin/com/squareup/wire/DurationTest.kt | 4 +- .../kotlin/com/squareup/wire/InstantTest.kt | 4 +- .../com/squareup/wire/ProtoAdapterTest.kt | 4 +- .../com/squareup/wire/ProtoReaderTest.kt | 8 +- .../com/squareup/wire/ProtoWriterTest.kt | 8 +- .../squareup/wire/ReverseProtoWriterTest.kt | 16 +-- .../wire/internal/DoubleArrayListTest.kt | 4 +- .../wire/internal/FloatArrayListTest.kt | 4 +- .../wire/internal/IntArrayListTest.kt | 4 +- .../squareup/wire/internal/InternalTest.kt | 17 ++- .../wire/internal/LongArrayListTest.kt | 4 +- .../kotlin/com/squareup/wire/ProtoAdapter.kt | 4 +- .../kotlin/com/squareup/wire/Duration.kt | 8 +- .../kotlin/com/squareup/wire/EnumAdapter.kt | 6 +- .../kotlin/com/squareup/wire/Instant.kt | 6 +- .../kotlin/com/squareup/wire/Message.kt | 13 ++- .../kotlin/com/squareup/wire/MessageSink.kt | 4 +- .../kotlin/com/squareup/wire/MessageSource.kt | 4 +- .../kotlin/com/squareup/wire/ProtoAdapter.kt | 15 +-- .../com/squareup/wire/internal/-Platform.kt | 4 +- .../com/squareup/wire/AndroidMessage.kt | 10 +- .../kotlin/com/squareup/wire/Duration.kt | 4 +- .../kotlin/com/squareup/wire/EnumAdapter.kt | 6 +- .../kotlin/com/squareup/wire/Instant.kt | 4 +- .../squareup/wire/KotlinConstructorBuilder.kt | 6 +- .../kotlin/com/squareup/wire/Message.kt | 26 +++-- .../squareup/wire/MessageSerializedForm.kt | 6 +- .../kotlin/com/squareup/wire/MessageSink.kt | 6 +- .../kotlin/com/squareup/wire/MessageSource.kt | 6 +- .../kotlin/com/squareup/wire/ProtoAdapter.kt | 74 +++++++++--- .../com/squareup/wire/RuntimeEnumAdapter.kt | 8 +- .../jvmMain/kotlin/com/squareup/wire/Wire.kt | 4 +- .../com/squareup/wire/internal/-Platform.kt | 4 +- .../wire/internal/DurationJsonFormatter.kt | 4 +- .../wire/internal/EnumJsonFormatter.kt | 6 +- .../squareup/wire/internal/FieldBinding.kt | 4 +- .../wire/internal/InstantJsonFormatter.kt | 4 +- .../com/squareup/wire/internal/InternalJvm.kt | 4 +- .../squareup/wire/internal/JsonFormatter.kt | 4 +- .../squareup/wire/internal/JsonIntegration.kt | 40 ++++--- .../squareup/wire/internal/OneOfBinding.kt | 4 +- .../com/squareup/wire/internal/reflection.kt | 14 +-- .../kotlin/com/squareup/wire/Duration.kt | 8 +- .../kotlin/com/squareup/wire/EnumAdapter.kt | 6 +- .../kotlin/com/squareup/wire/Instant.kt | 6 +- .../kotlin/com/squareup/wire/Message.kt | 10 +- .../kotlin/com/squareup/wire/MessageSink.kt | 4 +- .../kotlin/com/squareup/wire/MessageSource.kt | 4 +- .../kotlin/com/squareup/wire/ProtoAdapter.kt | 15 +-- .../com/squareup/wire/internal/-Platform.kt | 4 +- wire-schema/build.gradle.kts | 2 +- 79 files changed, 455 insertions(+), 303 deletions(-) diff --git a/wire-runtime/build.gradle.kts b/wire-runtime/build.gradle.kts index 8a54b0690c..800a8e3916 100644 --- a/wire-runtime/build.gradle.kts +++ b/wire-runtime/build.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinMultiplatform import com.vanniktech.maven.publish.MavenPublishBaseExtension @@ -158,4 +159,20 @@ if (project.rootProject.name == "wire") { KotlinMultiplatform(javadocJar = Dokka("dokkaGfm")) ) } + + configure { + kotlin { + targetExclude( + // Google license for Protobuf. + "src/commonMain/kotlin/com/squareup/wire/ProtoReader.kt", + // Google license for R8. + "src/commonMain/kotlin/com/squareup/wire/internal/MathMethods.kt", + // Apache 2-licensed files from Jetbrains. + "src/commonMain/kotlin/com/squareup/wire/internal/DoubleArrayList.kt", + "src/commonMain/kotlin/com/squareup/wire/internal/FloatArrayList.kt", + "src/commonMain/kotlin/com/squareup/wire/internal/IntArrayList.kt", + "src/commonMain/kotlin/com/squareup/wire/internal/LongArrayList.kt", + ) + } + } } diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/AnyMessage.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/AnyMessage.kt index e5f5261994..84b3452abd 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/AnyMessage.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/AnyMessage.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,8 @@ package com.squareup.wire import com.squareup.wire.AnyMessage.Companion.pack -import okio.ByteString import kotlin.jvm.JvmField +import okio.ByteString /** * Wire implementation of the `google.protobuf.Any` type. The `Any` type wraps an arbitrary @@ -34,7 +34,7 @@ import kotlin.jvm.JvmField */ class AnyMessage( val typeUrl: String, - val value: ByteString = ByteString.EMPTY + val value: ByteString = ByteString.EMPTY, ) : Message(ADAPTER, ByteString.EMPTY) { fun unpack(adapter: ProtoAdapter): T { @@ -50,7 +50,7 @@ class AnyMessage( @Deprecated( message = "Shouldn't be used in Kotlin", - level = DeprecationLevel.HIDDEN + level = DeprecationLevel.HIDDEN, ) override fun newBuilder(): Nothing = throw AssertionError() @@ -74,7 +74,7 @@ class AnyMessage( fun copy( typeUrl: String = this.typeUrl, - value: ByteString = this.value + value: ByteString = this.value, ) = AnyMessage(typeUrl, value) companion object { @@ -89,7 +89,7 @@ class AnyMessage( FieldEncoding.LENGTH_DELIMITED, AnyMessage::class, "type.googleapis.com/google.protobuf.Any", - Syntax.PROTO_3 + Syntax.PROTO_3, ) { override fun encodedSize(value: AnyMessage): Int = STRING.encodedSizeWithTag(1, value.typeUrl) + diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Duration.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Duration.kt index e2224ff1c6..2f3ecb611c 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Duration.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Duration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,6 +27,7 @@ package com.squareup.wire */ expect class Duration { fun getSeconds(): Long + /** Returns a value in `[0..1,000,000,000)`. */ fun getNano(): Int } diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/EnumAdapter.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/EnumAdapter.kt index fa29d676c2..8f2d45ee4a 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/EnumAdapter.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/EnumAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2016 Square Inc. + * Copyright (C) 2016 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,8 +16,8 @@ package com.squareup.wire import com.squareup.wire.internal.Throws -import okio.IOException import kotlin.reflect.KClass +import okio.IOException /** * An abstract [ProtoAdapter] that converts values of an enum to and from integers. @@ -25,7 +25,7 @@ import kotlin.reflect.KClass expect abstract class EnumAdapter protected constructor( type: KClass, syntax: Syntax, - identity: E? + identity: E?, ) : ProtoAdapter { override fun encodedSize(value: E): Int @@ -65,7 +65,7 @@ internal inline fun commonEncode(writer: ReverseProtoWriter, valu @Suppress("NOTHING_TO_INLINE") internal inline fun EnumAdapter.commonDecode( reader: ProtoReader, - fromValue: (Int) -> E? + fromValue: (Int) -> E?, ): E { val value = reader.readVarint32() return fromValue(value) ?: throw ProtoAdapter.EnumConstantNotFoundException(value, type) diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/FieldEncoding.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/FieldEncoding.kt index e4bd2f7b74..b87fcb42db 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/FieldEncoding.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/FieldEncoding.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,8 +17,8 @@ package com.squareup.wire import com.squareup.wire.internal.ProtocolException import com.squareup.wire.internal.Throws -import okio.IOException import kotlin.jvm.JvmStatic +import okio.IOException enum class FieldEncoding(internal val value: Int) { VARINT(0), FIXED64(1), LENGTH_DELIMITED(2), FIXED32(5); diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Instant.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Instant.kt index 43257e38c2..8bdb1be5ed 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Instant.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Instant.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Message.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Message.kt index 5fd5b4a3ab..6dabf40a37 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Message.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Message.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import okio.ByteString /** A protocol buffer message. */ expect abstract class Message, B : Message.Builder> protected constructor( adapter: ProtoAdapter, - unknownFields: ByteString + unknownFields: ByteString, ) { /** If non-zero, the hash code of this message. Accessed by generated code. */ protected var hashCode: Int @@ -75,7 +75,7 @@ expect abstract class Message, B : Message.Builder> prot fun addUnknownField( tag: Int, fieldEncoding: FieldEncoding, - value: Any? + value: Any?, ): Builder fun clearUnknownFields(): Builder diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt index 0815c8616f..03210dc603 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt index f3b7fd0193..92ce649672 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/OneOf.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/OneOf.kt index 78836d23fb..78eaa2afc8 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/OneOf.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/OneOf.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -105,7 +105,7 @@ import com.squareup.wire.internal.sanitize */ data class OneOf, T>( val key: K, - val value: T + val value: T, ) { @Suppress("UNCHECKED_CAST") // We statically guarantee Keys and Values are of the same types. fun getOrNull(key: Key): X? { @@ -161,6 +161,6 @@ data class OneOf, T>( val adapter: ProtoAdapter, val declaredName: String, val redacted: Boolean = false, - val jsonName: String = "" + val jsonName: String = "", ) } diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt index 7344233ce6..6361e9cbe5 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,15 +26,15 @@ import com.squareup.wire.ProtoWriter.Companion.tagSize import com.squareup.wire.ProtoWriter.Companion.varint32Size import com.squareup.wire.ProtoWriter.Companion.varint64Size import com.squareup.wire.internal.Throws +import kotlin.jvm.JvmField +import kotlin.jvm.JvmStatic +import kotlin.reflect.KClass import okio.Buffer import okio.BufferedSink import okio.BufferedSource import okio.ByteString import okio.IOException import okio.utf8Size -import kotlin.jvm.JvmField -import kotlin.jvm.JvmStatic -import kotlin.reflect.KClass expect abstract class ProtoAdapter( fieldEncoding: FieldEncoding, @@ -170,7 +170,7 @@ expect abstract class ProtoAdapter( class EnumConstantNotFoundException( value: Int, - type: KClass<*>? + type: KClass<*>?, ) : IllegalArgumentException { @JvmField val value: Int @@ -187,55 +187,97 @@ expect abstract class ProtoAdapter( @JvmStatic fun newMapAdapter( keyAdapter: ProtoAdapter, - valueAdapter: ProtoAdapter + valueAdapter: ProtoAdapter, ): ProtoAdapter> @JvmField val BOOL: ProtoAdapter + @JvmField val INT32: ProtoAdapter + @JvmField val INT32_ARRAY: ProtoAdapter + @JvmField val UINT32: ProtoAdapter + @JvmField val UINT32_ARRAY: ProtoAdapter + @JvmField val SINT32: ProtoAdapter + @JvmField val SINT32_ARRAY: ProtoAdapter + @JvmField val FIXED32: ProtoAdapter + @JvmField val FIXED32_ARRAY: ProtoAdapter + @JvmField val SFIXED32: ProtoAdapter + @JvmField val SFIXED32_ARRAY: ProtoAdapter + @JvmField val INT64: ProtoAdapter + @JvmField val INT64_ARRAY: ProtoAdapter + /** * Like INT64, but negative longs are interpreted as large positive values, and encoded that way * in JSON. */ @JvmField val UINT64: ProtoAdapter + @JvmField val UINT64_ARRAY: ProtoAdapter + @JvmField val SINT64: ProtoAdapter + @JvmField val SINT64_ARRAY: ProtoAdapter + @JvmField val FIXED64: ProtoAdapter + @JvmField val FIXED64_ARRAY: ProtoAdapter + @JvmField val SFIXED64: ProtoAdapter + @JvmField val SFIXED64_ARRAY: ProtoAdapter + @JvmField val FLOAT: ProtoAdapter + @JvmField val FLOAT_ARRAY: ProtoAdapter + @JvmField val DOUBLE: ProtoAdapter + @JvmField val DOUBLE_ARRAY: ProtoAdapter + @JvmField val BYTES: ProtoAdapter + @JvmField val STRING: ProtoAdapter + @JvmField val DURATION: ProtoAdapter + @JvmField val INSTANT: ProtoAdapter + @JvmField val EMPTY: ProtoAdapter + @JvmField val STRUCT_MAP: ProtoAdapter?> + @JvmField val STRUCT_LIST: ProtoAdapter?> + @JvmField val STRUCT_NULL: ProtoAdapter + @JvmField val STRUCT_VALUE: ProtoAdapter + @JvmField val DOUBLE_VALUE: ProtoAdapter + @JvmField val FLOAT_VALUE: ProtoAdapter + @JvmField val INT64_VALUE: ProtoAdapter + @JvmField val UINT64_VALUE: ProtoAdapter + @JvmField val INT32_VALUE: ProtoAdapter + @JvmField val UINT32_VALUE: ProtoAdapter + @JvmField val BOOL_VALUE: ProtoAdapter + @JvmField val STRING_VALUE: ProtoAdapter + @JvmField val BYTES_VALUE: ProtoAdapter } } @@ -253,7 +295,7 @@ internal inline fun ProtoAdapter.commonEncodedSizeWithTag(tag: Int, value @Suppress("NOTHING_TO_INLINE") internal inline fun ProtoAdapter.delegateEncode( writer: ReverseProtoWriter, - value: E + value: E, ) { writer.writeForward { forwardWriter -> encode(forwardWriter, value) @@ -264,7 +306,7 @@ internal inline fun ProtoAdapter.delegateEncode( internal inline fun ProtoAdapter.commonEncodeWithTag( writer: ProtoWriter, tag: Int, - value: E? + value: E?, ) { if (value == null) return writer.writeTag(tag, fieldEncoding) @@ -278,7 +320,7 @@ internal inline fun ProtoAdapter.commonEncodeWithTag( internal inline fun ProtoAdapter.commonEncodeWithTag( writer: ReverseProtoWriter, tag: Int, - value: E? + value: E?, ) { if (value == null) return if (fieldEncoding == LENGTH_DELIMITED) { @@ -357,13 +399,13 @@ internal inline fun ProtoAdapter.commonCreatePacked(): ProtoAdapter( - private val originalAdapter: ProtoAdapter + private val originalAdapter: ProtoAdapter, ) : ProtoAdapter>( LENGTH_DELIMITED, List::class, null, originalAdapter.syntax, - listOf() + listOf(), ) { @Throws(IOException::class) override fun encodeWithTag(writer: ProtoWriter, tag: Int, value: List?) { @@ -417,13 +459,13 @@ internal inline fun ProtoAdapter.commonCreateRepeated(): ProtoAdapter( - private val originalAdapter: ProtoAdapter + private val originalAdapter: ProtoAdapter, ) : ProtoAdapter>( originalAdapter.fieldEncoding, List::class, null, originalAdapter.syntax, - listOf() + listOf(), ) { override fun encodedSize(value: List): Int { throw UnsupportedOperationException("Repeated values can only be sized with a tag.") @@ -692,13 +734,13 @@ internal class IntArrayProtoAdapter( internal class MapProtoAdapter internal constructor( keyAdapter: ProtoAdapter, - valueAdapter: ProtoAdapter + valueAdapter: ProtoAdapter, ) : ProtoAdapter>( LENGTH_DELIMITED, Map::class, null, valueAdapter.syntax, - mapOf() + mapOf(), ) { private val entryAdapter = MapEntryProtoAdapter(keyAdapter, valueAdapter) @@ -766,12 +808,12 @@ internal class MapProtoAdapter internal constructor( private class MapEntryProtoAdapter internal constructor( internal val keyAdapter: ProtoAdapter, - internal val valueAdapter: ProtoAdapter + internal val valueAdapter: ProtoAdapter, ) : ProtoAdapter>( LENGTH_DELIMITED, Map.Entry::class, null, - valueAdapter.syntax + valueAdapter.syntax, ) { override fun encodedSize(value: Map.Entry): Int { @@ -807,7 +849,7 @@ private const val FIXED_64_SIZE = 8 @Suppress("NOTHING_TO_INLINE") internal inline fun commonNewMapAdapter( keyAdapter: ProtoAdapter, - valueAdapter: ProtoAdapter + valueAdapter: ProtoAdapter, ): ProtoAdapter> { return MapProtoAdapter(keyAdapter, valueAdapter) } @@ -817,7 +859,7 @@ internal fun commonBool(): ProtoAdapter = object : ProtoAdapter( Float::class, null, Syntax.PROTO_2, - 0.0f + 0.0f, ) { @Throws(IOException::class) override fun encode(writer: ProtoWriter, value: Float) { @@ -1082,7 +1124,7 @@ internal class DoubleProtoAdapter : ProtoAdapter( Double::class, null, Syntax.PROTO_2, - 0.0 + 0.0, ) { override fun encodedSize(value: Double): Int = FIXED_64_SIZE @@ -1109,7 +1151,7 @@ internal fun commonString(): ProtoAdapter = object : ProtoAdapter = object : ProtoAdapter = object : ProtoAdapter = object : ProtoAdapter = object : ProtoAdapter( LENGTH_DELIMITED, Unit::class, "type.googleapis.com/google.protobuf.Empty", - Syntax.PROTO_3 + Syntax.PROTO_3, ) { override fun encodedSize(value: Unit): Int = 0 @@ -1291,7 +1333,7 @@ internal fun commonStructMap(): ProtoAdapter?> = object : ProtoAd LENGTH_DELIMITED, Map::class, "type.googleapis.com/google.protobuf.Struct", - Syntax.PROTO_3 + Syntax.PROTO_3, ) { override fun encodedSize(value: Map?): Int { if (value == null) return 0 @@ -1318,7 +1360,7 @@ internal fun commonStructMap(): ProtoAdapter?> = object : ProtoAd override fun encode( writer: ReverseProtoWriter, - value: Map? + value: Map?, ) { if (value == null) return @@ -1357,7 +1399,7 @@ internal fun commonStructList(): ProtoAdapter?> = object : ProtoAdapter< LENGTH_DELIMITED, Map::class, "type.googleapis.com/google.protobuf.ListValue", - Syntax.PROTO_3 + Syntax.PROTO_3, ) { override fun encodedSize(value: List<*>?): Int { if (value == null) return 0 @@ -1399,7 +1441,7 @@ internal fun commonStructNull(): ProtoAdapter = object : ProtoAdapter< VARINT, Nothing::class, "type.googleapis.com/google.protobuf.NullValue", - Syntax.PROTO_3 + Syntax.PROTO_3, ) { override fun encodedSize(value: Nothing?): Int = varint32Size(0) @@ -1439,7 +1481,7 @@ internal fun commonStructValue(): ProtoAdapter = object : ProtoAdapter() @@ -118,7 +125,7 @@ class ProtoReader(private val source: BufferedSource) { @Deprecated( level = DeprecationLevel.WARNING, message = "prefer endMessageAndGetUnknownFields()", - replaceWith = ReplaceWith("endMessageAndGetUnknownFields(token)") + replaceWith = ReplaceWith("endMessageAndGetUnknownFields(token)"), ) fun endMessage(token: Long) { endMessageAndGetUnknownFields(token) @@ -277,7 +284,8 @@ class ProtoReader(private val source: BufferedSource) { } STATE_VARINT, STATE_FIXED64, - STATE_FIXED32 -> true // Not packed. + STATE_FIXED32, + -> true // Not packed. else -> throw ProtocolException("unexpected state: $state") } @@ -465,7 +473,7 @@ class ProtoReader(private val source: BufferedSource) { fun addUnknownField( tag: Int, fieldEncoding: FieldEncoding, - value: Any? + value: Any?, ) { val unknownFieldsWriter = ProtoWriter(bufferStack[recursionDepth - 1]) val protoAdapter = fieldEncoding.rawProtoAdapter() diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoWriter.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoWriter.kt index 08b4989e5d..330c09e45f 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoWriter.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ProtoWriter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ReverseProtoWriter.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ReverseProtoWriter.kt index 300807c6b5..0f39c1a6ef 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ReverseProtoWriter.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/ReverseProtoWriter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package com.squareup.wire import com.squareup.wire.ProtoWriter.Companion.varint32Size import com.squareup.wire.ProtoWriter.Companion.varint64Size import com.squareup.wire.internal.Throws +import kotlin.LazyThreadSafetyMode.NONE import okio.Buffer import okio.BufferedSink import okio.ByteString import okio.IOException -import kotlin.LazyThreadSafetyMode.NONE /** * Encodes protocol buffer message fields from back-to-front for efficiency. Callers should write @@ -223,6 +223,7 @@ class ReverseProtoWriter { require(varint32Size) arrayLimit -= varint32Size var offset = arrayLimit + @Suppress("NAME_SHADOWING") var value = value while (value and 0x7f.inv() != 0) { @@ -238,6 +239,7 @@ class ReverseProtoWriter { require(varint64Size) arrayLimit -= varint64Size var offset = arrayLimit + @Suppress("NAME_SHADOWING") var value = value while (value and 0x7fL.inv() != 0L) { diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Service.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Service.kt index c1dc387564..d9436011d1 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Service.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Service.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Syntax.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Syntax.kt index e4069eddb4..72a983ff55 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Syntax.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/Syntax.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,7 +18,8 @@ package com.squareup.wire /** Syntax version. */ enum class Syntax(private val string: String) { PROTO_2("proto2"), - PROTO_3("proto3"); + PROTO_3("proto3"), + ; override fun toString(): String = string diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnum.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnum.kt index a57a9ee332..31f3576828 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnum.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnum.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnumConstant.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnumConstant.kt index 513ce4cd31..3cf5b9c576 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnumConstant.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireEnumConstant.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireField.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireField.kt index c9c3009f82..625005e210 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireField.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireField.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -76,8 +76,10 @@ annotation class WireField( OPTIONAL, REPEATED, ONE_OF, + /** Implies [REPEATED]. */ PACKED, + /** * Special label to define proto3 fields which should not be emitted if their value is equal * to their type's respective identity value. E.g.: a field of type `int32` will not get emitted @@ -87,12 +89,15 @@ annotation class WireField( ; val isRepeated: Boolean - @JvmName("isRepeated") get() = this == REPEATED || this == PACKED + @JvmName("isRepeated") + get() = this == REPEATED || this == PACKED val isPacked: Boolean - @JvmName("isPacked") get() = this == PACKED + @JvmName("isPacked") + get() = this == PACKED val isOneOf: Boolean - @JvmName("isOneOf") get() = this == ONE_OF + @JvmName("isOneOf") + get() = this == ONE_OF } } diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireRpc.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireRpc.kt index 97fd37ee19..1e81ba7fec 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireRpc.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/WireRpc.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,5 +33,5 @@ annotation class WireRpc( val path: String, val requestAdapter: String, val responseAdapter: String, - val sourceFile: String = "" + val sourceFile: String = "", ) diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/-Platform.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/-Platform.kt index 4676940ad3..427ed97449 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/-Platform.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/-Platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,8 +15,8 @@ */ package com.squareup.wire.internal -import okio.IOException import kotlin.reflect.KClass +import okio.IOException expect interface Serializable diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/FieldOrOneOfBinding.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/FieldOrOneOfBinding.kt index 9488a4e973..7a177ffe1a 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/FieldOrOneOfBinding.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/FieldOrOneOfBinding.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -62,7 +62,7 @@ abstract class FieldOrOneOfBinding { if (isMap) { ProtoAdapter.newMapAdapter( keyAdapter as ProtoAdapter, - singleAdapter as ProtoAdapter + singleAdapter as ProtoAdapter, ) as ProtoAdapter } else { singleAdapter.withLabel(label) as ProtoAdapter diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/ImmutableList.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/ImmutableList.kt index f54819f863..caac658f9c 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/ImmutableList.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/ImmutableList.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,8 @@ internal class ImmutableList(list: List) : AbstractList(), RandomAcces private val list = ArrayList(list) override val size: Int - @get:JvmName("size") get() = list.size + @get:JvmName("size") + get() = list.size override fun get(index: Int): T = list[index] diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Internal.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Internal.kt index 20a25b619d..97bf9000c5 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Internal.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Internal.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,7 +35,7 @@ fun newMutableMap(): MutableMap = LinkedHashMap() @Deprecated( message = "Please regenerate code using wire-compiler version 3.0.0 or higher.", - replaceWith = ReplaceWith("com.squareup.internal.Internal.copyOf(list)") + replaceWith = ReplaceWith("com.squareup.internal.Internal.copyOf(list)"), ) fun copyOf(@Suppress("UNUSED_PARAMETER") name: String, list: List?): MutableList = copyOf(list!!) @@ -49,7 +49,7 @@ fun copyOf(list: List): MutableList { @Deprecated( message = "Please regenerate code using wire-compiler version 3.0.0 or higher.", - replaceWith = ReplaceWith("com.squareup.internal.Internal.copyOf(map)") + replaceWith = ReplaceWith("com.squareup.internal.Internal.copyOf(map)"), ) fun copyOf(@Suppress("UNUSED_PARAMETER") name: String, map: Map?): MutableMap = copyOf(map!!) @@ -119,7 +119,7 @@ fun immutableCopyOfStruct(name: String, value: T): T { else -> { throw IllegalArgumentException( "struct value $name must be a JSON type " + - "(null, Boolean, Double, String, List, or Map) but was ${value.typeName}: $value" + "(null, Boolean, Double, String, List, or Map) but was ${value.typeName}: $value", ) } } diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MessageBinding.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MessageBinding.kt index 437744ca5c..d2a02f35d0 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MessageBinding.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MessageBinding.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,8 +17,8 @@ package com.squareup.wire.internal import com.squareup.wire.FieldEncoding import com.squareup.wire.Syntax -import okio.ByteString import kotlin.reflect.KClass +import okio.ByteString /** * A representation of a message and its builder class. Typically these are generated subtypes of diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MutableOnWriteList.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MutableOnWriteList.kt index 52a054ac37..76480b2352 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MutableOnWriteList.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/MutableOnWriteList.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,14 +19,15 @@ import kotlin.jvm.JvmName /** A wrapper around an empty/immutable list which only switches to mutable on first mutation. */ internal class MutableOnWriteList( - private val immutableList: List + private val immutableList: List, ) : AbstractMutableList(), RandomAccess, Serializable { internal var mutableList: List = immutableList override fun get(index: Int): T = mutableList[index] override val size: Int - @get:JvmName("size") get() = mutableList.size + @get:JvmName("size") + get() = mutableList.size override fun set(index: Int, element: T): T { if (mutableList === immutableList) { diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/RuntimeMessageAdapter.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/RuntimeMessageAdapter.kt index 2370310272..2e618a4666 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/RuntimeMessageAdapter.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/RuntimeMessageAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,7 +28,7 @@ class RuntimeMessageAdapter( fieldEncoding = FieldEncoding.LENGTH_DELIMITED, type = binding.messageType, typeUrl = binding.typeUrl, - syntax = binding.syntax + syntax = binding.syntax, ) { private val messageType = binding.messageType val fields = binding.fields @@ -117,7 +117,7 @@ class RuntimeMessageAdapter( for (field in fields.values) { if (field.redacted && field.label == WireField.Label.REQUIRED) { throw UnsupportedOperationException( - "Field '${field.name}' in $type is required and cannot be redacted." + "Field '${field.name}' in $type is required and cannot be redacted.", ) } val isMessage = field.isMessage @@ -200,7 +200,7 @@ class RuntimeMessageAdapter( message: M?, jsonAdapters: List, redactedFieldsAdapter: A?, - encodeValue: (String, Any?, A) -> Unit + encodeValue: (String, Any?, A) -> Unit, ) { var redactedFields: MutableList? = null for (index in fieldBindingsArray.indices) { diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Util.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Util.kt index c81fe07452..47c45acc7a 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Util.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/internal/Util.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/DurationTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/DurationTest.kt index aef4a07a10..88c8f98832 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/DurationTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/DurationTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/InstantTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/InstantTest.kt index e7707f6a48..84129c7f1d 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/InstantTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/InstantTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt index c5a6e6a631..badcdd624a 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoAdapterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoReaderTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoReaderTest.kt index 29d7b1b822..e888668459 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoReaderTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoReaderTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,10 +15,10 @@ */ package com.squareup.wire -import okio.Buffer -import okio.ByteString.Companion.decodeHex import kotlin.test.Test import kotlin.test.assertEquals +import okio.Buffer +import okio.ByteString.Companion.decodeHex class ProtoReaderTest { @Test fun packedExposedAsRepeated() { diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoWriterTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoWriterTest.kt index 79cac4d869..4433829d62 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoWriterTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ProtoWriterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,10 +15,10 @@ */ package com.squareup.wire -import okio.Buffer -import okio.utf8Size import kotlin.test.Test import kotlin.test.assertEquals +import okio.Buffer +import okio.utf8Size class ProtoWriterTest { @Test fun utf8() { diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ReverseProtoWriterTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ReverseProtoWriterTest.kt index 5aab3a3e7f..27293e0170 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ReverseProtoWriterTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/ReverseProtoWriterTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package com.squareup.wire import com.squareup.wire.FieldEncoding.LENGTH_DELIMITED import com.squareup.wire.ProtoAdapter.Companion.newMapAdapter import com.squareup.wire.Syntax.PROTO_2 +import kotlin.test.Test +import kotlin.test.assertEquals import okio.Buffer import okio.ByteString.Companion.encodeUtf8 import okio.utf8Size -import kotlin.test.Test -import kotlin.test.assertEquals class ReverseProtoWriterTest { @Test fun utf8() { @@ -146,11 +146,11 @@ class ReverseProtoWriterTest { @Test fun reverseEncodedMessageEmbedsForwardEncodedMessage() { val alanGrant = Person( name = "Alan Grant", - birthYear = 1950 + birthYear = 1950, ) val digUpDinosaurs = Task( description = "dig up dinosaurs", - assignee = alanGrant + assignee = alanGrant, ) val alanGrantEncoded = Person.ADAPTER.encodeByteString(alanGrant) assertEquals(alanGrant, Person.ADAPTER.decode(alanGrantEncoded)) @@ -206,7 +206,7 @@ class ReverseProtoWriterTest { Person::class, "type.googleapis.com/Person", PROTO_2, - null + null, ) { override fun redact(value: Person) = error("unexpected call") @@ -246,7 +246,7 @@ class ReverseProtoWriterTest { Task::class, "type.googleapis.com/Task", PROTO_2, - null + null, ) { override fun redact(value: Task) = error("unexpected call") diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/DoubleArrayListTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/DoubleArrayListTest.kt index 33bc95e60b..636fde80af 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/DoubleArrayListTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/DoubleArrayListTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2023 Square Inc. + * Copyright (C) 2023 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/FloatArrayListTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/FloatArrayListTest.kt index 911717789b..e2bca8cef0 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/FloatArrayListTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/FloatArrayListTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2023 Square Inc. + * Copyright (C) 2023 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/IntArrayListTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/IntArrayListTest.kt index e41a7878e2..e966af47fe 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/IntArrayListTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/IntArrayListTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2023 Square Inc. + * Copyright (C) 2023 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/InternalTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/InternalTest.kt index cbd3d05430..7ed3a3ce77 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/InternalTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/InternalTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.internal import com.squareup.wire.VERSION @@ -29,7 +44,7 @@ class InternalTest { assertEquals( """[\,, \{, \}, \[, \], \\]""", - sanitize(listOf(""",""", """{""", """}""", """[""", """]""", """\""")) + sanitize(listOf(""",""", """{""", """}""", """[""", """]""", """\""")), ) } diff --git a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/LongArrayListTest.kt b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/LongArrayListTest.kt index da11d801b6..2b885c92a1 100644 --- a/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/LongArrayListTest.kt +++ b/wire-runtime/src/commonTest/kotlin/com/squareup/wire/internal/LongArrayListTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2023 Square Inc. + * Copyright (C) 2023 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/darwinMain/kotlin/com/squareup/wire/ProtoAdapter.kt b/wire-runtime/src/darwinMain/kotlin/com/squareup/wire/ProtoAdapter.kt index bda0063c2f..4f47eab0ba 100644 --- a/wire-runtime/src/darwinMain/kotlin/com/squareup/wire/ProtoAdapter.kt +++ b/wire-runtime/src/darwinMain/kotlin/com/squareup/wire/ProtoAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Duration.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Duration.kt index 5b7f864bd4..4c8973ec37 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Duration.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Duration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import com.squareup.wire.internal.floorModLong actual class Duration internal constructor( private val seconds: Long, - private val nanos: Int + private val nanos: Int, ) { actual fun getSeconds(): Long = seconds actual fun getNano(): Int = nanos @@ -30,7 +30,7 @@ actual class Duration internal constructor( actual fun durationOfSeconds( seconds: Long, - nano: Long + nano: Long, ): Duration { val secs = addExactLong(seconds, floorDivLong(nano, NANOS_PER_SECOND)) val nos = floorModLong(nano, NANOS_PER_SECOND).toInt() diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/EnumAdapter.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/EnumAdapter.kt index 3dcbd3e10c..1a3c0a79d6 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/EnumAdapter.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/EnumAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2016 Square Inc. + * Copyright (C) 2016 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ import kotlin.reflect.KClass actual abstract class EnumAdapter protected actual constructor( type: KClass, syntax: Syntax, - identity: E? + identity: E?, ) : ProtoAdapter(FieldEncoding.VARINT, type, null, syntax, identity) { actual override fun encodedSize(value: E): Int = commonEncodedSize(value) diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Instant.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Instant.kt index bf22258ef7..e9a9f6d74f 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Instant.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Instant.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import com.squareup.wire.internal.floorModLong actual class Instant internal constructor( private val epochSeconds: Long, - private val nanos: Int + private val nanos: Int, ) { actual fun getEpochSecond(): Long = epochSeconds actual fun getNano(): Int = nanos diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Message.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Message.kt index 7702028ae8..bc5650fb11 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Message.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/Message.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,10 +28,11 @@ protected actual constructor( * Returns a byte string containing the proto encoding of this message's unknown fields. Returns * an empty byte string if this message has no unknown fields. */ - actual val unknownFields: ByteString + actual val unknownFields: ByteString, ) { /** If non-zero, the hash code of this message. Accessed by generated code. */ - @JsName("cachedHashCode") protected actual var hashCode = 0 + @JsName("cachedHashCode") + protected actual var hashCode = 0 /** * Returns a new builder initialized with the data in this message. @@ -74,10 +75,10 @@ protected actual constructor( actual fun addUnknownField( tag: Int, fieldEncoding: FieldEncoding, - value: Any? + value: Any?, ): Builder = apply { prepareForNewUnknownFields() - @Suppress("UNCHECKED_CAST") + @Suppress("UNCHECKED_CAST") val protoAdapter = fieldEncoding.rawProtoAdapter() as ProtoAdapter protoAdapter.encodeWithTag(unknownFieldsWriter!!, tag, value) } diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSink.kt index 44ed2c98d1..4817cd7135 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSink.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSink.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSource.kt index 8a986d41fa..87d837452a 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSource.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/MessageSource.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/ProtoAdapter.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/ProtoAdapter.kt index 8fb747ac4e..3c72ee342d 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/ProtoAdapter.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/ProtoAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ actual abstract class ProtoAdapter actual constructor( actual val typeUrl: String?, actual val syntax: Syntax, actual val identity: E?, - actual val sourceFile: String? + actual val sourceFile: String?, ) { internal actual val packedAdapter: ProtoAdapter>? = when { this is PackedProtoAdapter<*> || this is RepeatedProtoAdapter<*> -> null @@ -126,7 +126,7 @@ actual abstract class ProtoAdapter actual constructor( "Unable to pack a length-delimited type." } return packedAdapter ?: throw UnsupportedOperationException( - "Can't create a packed adapter from a packed or repeated adapter." + "Can't create a packed adapter from a packed or repeated adapter.", ) } @@ -139,13 +139,13 @@ actual abstract class ProtoAdapter actual constructor( */ actual fun asRepeated(): ProtoAdapter> { return repeatedAdapter ?: throw UnsupportedOperationException( - "Can't create a repeated adapter from a repeated or packed adapter." + "Can't create a repeated adapter from a repeated or packed adapter.", ) } actual class EnumConstantNotFoundException actual constructor( actual val value: Int, - type: KClass<*>? + type: KClass<*>?, ) : IllegalArgumentException("Unknown enum tag $value for ${type?.simpleName}") actual companion object { @@ -158,7 +158,7 @@ actual abstract class ProtoAdapter actual constructor( */ actual fun newMapAdapter( keyAdapter: ProtoAdapter, - valueAdapter: ProtoAdapter + valueAdapter: ProtoAdapter, ): ProtoAdapter> { return commonNewMapAdapter(keyAdapter, valueAdapter) } @@ -177,6 +177,7 @@ actual abstract class ProtoAdapter actual constructor( actual val SFIXED32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(SFIXED32) actual val INT64: ProtoAdapter = commonInt64() actual val INT64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(INT64) + /** * Like INT64, but negative longs are interpreted as large positive values, and encoded that way * in JSON. diff --git a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/internal/-Platform.kt b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/internal/-Platform.kt index 026c91af54..f82328d58b 100644 --- a/wire-runtime/src/jsMain/kotlin/com/squareup/wire/internal/-Platform.kt +++ b/wire-runtime/src/jsMain/kotlin/com/squareup/wire/internal/-Platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/AndroidMessage.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/AndroidMessage.kt index 55b7a057a2..6d6d333fa7 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/AndroidMessage.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/AndroidMessage.kt @@ -1,11 +1,11 @@ /* - * Copyright 2016 Square Inc. + * Copyright (C) 2016 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,13 +17,13 @@ package com.squareup.wire import android.os.Parcel import android.os.Parcelable -import okio.ByteString import java.lang.reflect.Array.newInstance +import okio.ByteString /** An Android-specific [Message] which adds support for [Parcelable]. */ abstract class AndroidMessage, B : Message.Builder> protected constructor( adapter: ProtoAdapter, - unknownFields: ByteString + unknownFields: ByteString, ) : Message(adapter, unknownFields), Parcelable { override fun writeToParcel(dest: Parcel, flags: Int) { @@ -33,7 +33,7 @@ abstract class AndroidMessage, B : Message.Builder> prot override fun describeContents() = 0 private class ProtoAdapterCreator internal constructor( - private val adapter: ProtoAdapter + private val adapter: ProtoAdapter, ) : Parcelable.Creator { override fun createFromParcel(input: Parcel): M = adapter.decode(input.createByteArray()) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Duration.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Duration.kt index 8f5f81823c..55eb031187 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Duration.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Duration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt index 9ee8efe8ec..0d8fcc505b 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2016 Square Inc. + * Copyright (C) 2016 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,7 @@ import kotlin.reflect.KClass actual abstract class EnumAdapter protected actual constructor( type: KClass, syntax: Syntax, - identity: E? + identity: E?, ) : ProtoAdapter(FieldEncoding.VARINT, type, null, syntax, identity) { constructor(type: Class, syntax: Syntax, identity: E?) : this(type.kotlin, syntax, identity) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Instant.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Instant.kt index ef6f7e94d8..eea4b83e7d 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Instant.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Instant.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/KotlinConstructorBuilder.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/KotlinConstructorBuilder.kt index 70e9c186d4..09d204bf70 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/KotlinConstructorBuilder.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/KotlinConstructorBuilder.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,7 @@ internal class KotlinConstructorBuilder, B : Message.Builder { diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Message.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Message.kt index 7339cb2273..080839b07c 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Message.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Message.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,26 +15,29 @@ */ package com.squareup.wire -import okio.Buffer -import okio.BufferedSink -import okio.ByteString import java.io.IOException import java.io.ObjectStreamException import java.io.OutputStream import java.io.Serializable +import okio.Buffer +import okio.BufferedSink +import okio.ByteString /** A protocol buffer message. */ actual abstract class Message, B : Message.Builder> protected actual constructor( /** The [ProtoAdapter] for encoding and decoding messages of this type. */ - @field:Transient @get:JvmName("adapter") actual val adapter: ProtoAdapter, - unknownFields: ByteString + @field:Transient + @get:JvmName("adapter") + actual val adapter: ProtoAdapter, + unknownFields: ByteString, ) : Serializable { /** * Returns a byte string containing the proto encoding of this message's unknown fields. Returns * an empty byte string if this message has no unknown fields. */ - @field:Transient @get:JvmName("unknownFields") + @field:Transient + @get:JvmName("unknownFields") actual val unknownFields: ByteString = unknownFields get() { // Some naughty libraries construct Messages by reflection which causes this non-null field @@ -48,7 +51,8 @@ protected actual constructor( @Transient internal var cachedSerializedSize = 0 /** If non-zero, the hash code of this message. Accessed by generated code. */ - @Transient @JvmField protected actual var hashCode = 0 + @Transient @JvmField + protected actual var hashCode = 0 /** * Returns a new builder initialized with the data in this message. @@ -94,7 +98,9 @@ protected actual constructor( */ actual abstract class Builder, B : Builder> protected constructor() { @Transient internal actual var unknownFieldsByteString = ByteString.EMPTY + @Transient internal actual var unknownFieldsBuffer: Buffer? = null + @Transient internal actual var unknownFieldsWriter: ProtoWriter? = null actual fun addUnknownFields(unknownFields: ByteString): Builder = apply { @@ -107,7 +113,7 @@ protected actual constructor( actual fun addUnknownField( tag: Int, fieldEncoding: FieldEncoding, - value: Any? + value: Any?, ): Builder = apply { prepareForNewUnknownFields() @Suppress("UNCHECKED_CAST") diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSerializedForm.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSerializedForm.kt index 847913a7d4..59728b2cf9 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSerializedForm.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSerializedForm.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import java.io.StreamCorruptedException internal class MessageSerializedForm, B : Message.Builder>( private val bytes: ByteArray, - private val messageClass: Class + private val messageClass: Class, ) : Serializable { @Throws(ObjectStreamException::class) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt index 4e5833753f..7a69974b70 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,8 +15,8 @@ */ package com.squareup.wire -import okio.IOException import java.io.Closeable +import okio.IOException actual interface MessageSink : Closeable { @Throws(IOException::class) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt index 234dc9dd12..481ccf20a6 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,8 +15,8 @@ */ package com.squareup.wire -import okio.IOException import java.io.Closeable +import okio.IOException actual interface MessageSource : Closeable { @Throws(IOException::class) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt index 558cc35ec5..42904d34e1 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,16 +18,16 @@ package com.squareup.wire import com.squareup.wire.internal.createRuntimeMessageAdapter +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream +import kotlin.reflect.KClass import okio.BufferedSink import okio.BufferedSource import okio.ByteString import okio.buffer import okio.sink import okio.source -import java.io.IOException -import java.io.InputStream -import java.io.OutputStream -import kotlin.reflect.KClass actual abstract class ProtoAdapter actual constructor( internal actual val fieldEncoding: FieldEncoding, @@ -80,7 +80,7 @@ actual abstract class ProtoAdapter actual constructor( type: KClass<*>?, typeUrl: String?, syntax: Syntax, - identity: E? + identity: E?, ) : this(fieldEncoding, type, typeUrl, syntax, identity, null) @@ -178,13 +178,13 @@ actual abstract class ProtoAdapter actual constructor( "Unable to pack a length-delimited type." } return packedAdapter ?: throw UnsupportedOperationException( - "Can't create a packed adapter from a packed or repeated adapter." + "Can't create a packed adapter from a packed or repeated adapter.", ) } actual fun asRepeated(): ProtoAdapter> { return repeatedAdapter ?: throw UnsupportedOperationException( - "Can't create a repeated adapter from a repeated or packed adapter." + "Can't create a repeated adapter from a repeated or packed adapter.", ) } @@ -193,7 +193,7 @@ actual abstract class ProtoAdapter actual constructor( actual class EnumConstantNotFoundException actual constructor( @JvmField actual val value: Int, - type: KClass<*>? + type: KClass<*>?, ) : IllegalArgumentException("Unknown enum tag $value for ${type?.java?.name}") { constructor(value: Int, type: Class<*>) : this(value, type.kotlin) } @@ -201,14 +201,14 @@ actual abstract class ProtoAdapter actual constructor( actual companion object { @JvmStatic actual fun newMapAdapter( keyAdapter: ProtoAdapter, - valueAdapter: ProtoAdapter + valueAdapter: ProtoAdapter, ): ProtoAdapter> { return commonNewMapAdapter(keyAdapter, valueAdapter) } // Obsolete; for Java classes generated before typeUrl and syntax were added. @JvmStatic fun , B : Message.Builder> newMessageAdapter( - type: Class + type: Class, ): ProtoAdapter { return createRuntimeMessageAdapter(type, null, Syntax.PROTO_2) } @@ -216,7 +216,7 @@ actual abstract class ProtoAdapter actual constructor( // Obsolete; for Java classes generated before typeUrl and syntax were added. @JvmStatic fun , B : Message.Builder> newMessageAdapter( type: Class, - typeUrl: String + typeUrl: String, ): ProtoAdapter { return createRuntimeMessageAdapter(type, typeUrl, Syntax.PROTO_2) } @@ -225,7 +225,7 @@ actual abstract class ProtoAdapter actual constructor( @JvmStatic fun , B : Message.Builder> newMessageAdapter( type: Class, typeUrl: String, - syntax: Syntax + syntax: Syntax, ): ProtoAdapter { return createRuntimeMessageAdapter(type, typeUrl, syntax) } @@ -235,7 +235,7 @@ actual abstract class ProtoAdapter actual constructor( type: Class, typeUrl: String, syntax: Syntax, - classLoader: ClassLoader? + classLoader: ClassLoader?, ): ProtoAdapter { return createRuntimeMessageAdapter(type, typeUrl, syntax, classLoader) } @@ -292,52 +292,94 @@ actual abstract class ProtoAdapter actual constructor( } @JvmField actual val BOOL: ProtoAdapter = commonBool() + @JvmField actual val INT32: ProtoAdapter = commonInt32() + @JvmField actual val INT32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(INT32) + @JvmField actual val UINT32: ProtoAdapter = commonUint32() + @JvmField actual val UINT32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(UINT32) + @JvmField actual val SINT32: ProtoAdapter = commonSint32() + @JvmField actual val SINT32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(SINT32) + @JvmField actual val FIXED32: ProtoAdapter = commonFixed32() + @JvmField actual val FIXED32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(FIXED32) + @JvmField actual val SFIXED32: ProtoAdapter = commonSfixed32() + @JvmField actual val SFIXED32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(SFIXED32) + @JvmField actual val INT64: ProtoAdapter = commonInt64() + @JvmField actual val INT64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(INT64) + @JvmField actual val UINT64: ProtoAdapter = commonUint64() + @JvmField actual val UINT64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(UINT64) + @JvmField actual val SINT64: ProtoAdapter = commonSint64() + @JvmField actual val SINT64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(SINT64) + @JvmField actual val FIXED64: ProtoAdapter = commonFixed64() + @JvmField actual val FIXED64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(FIXED64) + @JvmField actual val SFIXED64: ProtoAdapter = commonSfixed64() + @JvmField actual val SFIXED64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(SFIXED64) + @JvmField actual val FLOAT: ProtoAdapter = commonFloat() + @JvmField actual val FLOAT_ARRAY: ProtoAdapter = FloatArrayProtoAdapter(FLOAT) + @JvmField actual val DOUBLE: ProtoAdapter = commonDouble() + @JvmField actual val DOUBLE_ARRAY: ProtoAdapter = DoubleArrayProtoAdapter(DOUBLE) + @JvmField actual val BYTES: ProtoAdapter = commonBytes() + @JvmField actual val STRING: ProtoAdapter = commonString() + @JvmField actual val EMPTY: ProtoAdapter = commonEmpty() + @JvmField actual val STRUCT_MAP: ProtoAdapter?> = commonStructMap() + @JvmField actual val STRUCT_LIST: ProtoAdapter?> = commonStructList() + @JvmField actual val STRUCT_NULL: ProtoAdapter = commonStructNull() + @JvmField actual val STRUCT_VALUE: ProtoAdapter = commonStructValue() + @JvmField actual val DOUBLE_VALUE: ProtoAdapter = commonWrapper(DOUBLE, "type.googleapis.com/google.protobuf.DoubleValue") + @JvmField actual val FLOAT_VALUE: ProtoAdapter = commonWrapper(FLOAT, "type.googleapis.com/google.protobuf.FloatValue") + @JvmField actual val INT64_VALUE: ProtoAdapter = commonWrapper(INT64, "type.googleapis.com/google.protobuf.Int64Value") + @JvmField actual val UINT64_VALUE: ProtoAdapter = commonWrapper(UINT64, "type.googleapis.com/google.protobuf.UInt64Value") + @JvmField actual val INT32_VALUE: ProtoAdapter = commonWrapper(INT32, "type.googleapis.com/google.protobuf.Int32Value") + @JvmField actual val UINT32_VALUE: ProtoAdapter = commonWrapper(UINT32, "type.googleapis.com/google.protobuf.UInt32Value") + @JvmField actual val BOOL_VALUE: ProtoAdapter = commonWrapper(BOOL, "type.googleapis.com/google.protobuf.BoolValue") + @JvmField actual val STRING_VALUE: ProtoAdapter = commonWrapper(STRING, "type.googleapis.com/google.protobuf.StringValue") + @JvmField actual val BYTES_VALUE: ProtoAdapter = commonWrapper(BYTES, "type.googleapis.com/google.protobuf.BytesValue") + @JvmField actual val DURATION: ProtoAdapter = try { commonDuration() } catch (_: NoClassDefFoundError) { @Suppress("UNCHECKED_CAST") UnsupportedTypeProtoAdapter() as ProtoAdapter } + @JvmField actual val INSTANT: ProtoAdapter = try { commonInstant() } catch (_: NoClassDefFoundError) { @@ -352,7 +394,7 @@ actual abstract class ProtoAdapter actual constructor( */ class UnsupportedTypeProtoAdapter : ProtoAdapter( FieldEncoding.LENGTH_DELIMITED, - Nothing::class + Nothing::class, ) { override fun redact(value: Nothing) = throw IllegalStateException("Operation not supported.") diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/RuntimeEnumAdapter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/RuntimeEnumAdapter.kt index 3739d1990a..f3d99dcf5b 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/RuntimeEnumAdapter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/RuntimeEnumAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ import java.lang.reflect.Method */ class RuntimeEnumAdapter internal constructor( private val javaType: Class, - syntax: Syntax + syntax: Syntax, ) : EnumAdapter(javaType.kotlin, syntax, javaType.identityOrNull) { // Obsolete; for Java classes generated before syntax were added. constructor(javaType: Class) : this(javaType, Syntax.PROTO_2) @@ -45,7 +45,7 @@ class RuntimeEnumAdapter internal constructor( companion object { @JvmStatic fun create( - enumType: Class + enumType: Class, ): RuntimeEnumAdapter { val defaultAdapter = get(enumType as Class<*>) return RuntimeEnumAdapter(enumType, defaultAdapter.syntax) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Wire.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Wire.kt index 34de237b7a..e71e47373b 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Wire.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/Wire.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/-Platform.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/-Platform.kt index 8e877ae2b1..ca894628b2 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/-Platform.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/-Platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/DurationJsonFormatter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/DurationJsonFormatter.kt index c275e88696..340cd2b195 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/DurationJsonFormatter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/DurationJsonFormatter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/EnumJsonFormatter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/EnumJsonFormatter.kt index fe2015bbf6..8281aada4e 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/EnumJsonFormatter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/EnumJsonFormatter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,7 @@ import com.squareup.wire.WireEnumConstant * names, or their tags. */ class EnumJsonFormatter( - adapter: EnumAdapter + adapter: EnumAdapter, ) : JsonFormatter { private val stringToValue: Map private val valueToString: Map diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/FieldBinding.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/FieldBinding.kt index 1fe4c49d75..163e1bc0e2 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/FieldBinding.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/FieldBinding.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InstantJsonFormatter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InstantJsonFormatter.kt index c4e1a19cea..bb16bb8cf4 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InstantJsonFormatter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InstantJsonFormatter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InternalJvm.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InternalJvm.kt index 5539f97c7b..9e13bfcc62 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InternalJvm.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/InternalJvm.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonFormatter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonFormatter.kt index 782a2c567c..de7e03cc0f 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonFormatter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonFormatter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonIntegration.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonIntegration.kt index 819f09b788..86514b26e7 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonIntegration.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/JsonIntegration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package com.squareup.wire.internal import com.squareup.wire.EnumAdapter import com.squareup.wire.ProtoAdapter import com.squareup.wire.Syntax -import okio.ByteString -import okio.ByteString.Companion.decodeBase64 import java.lang.reflect.Type import java.math.BigDecimal import java.math.BigInteger +import okio.ByteString +import okio.ByteString.Companion.decodeBase64 /** * Integrates a JSON library like Moshi or Gson into proto. This rigid interface attempts to make it @@ -39,7 +39,7 @@ abstract class JsonIntegration { abstract fun mapAdapter( framework: F, keyFormatter: JsonFormatter<*>, - valueAdapter: A + valueAdapter: A, ): A /** @@ -54,7 +54,7 @@ abstract class JsonIntegration { /** Returns a message type that supports encoding and decoding JSON objects of type [type]. */ fun jsonAdapters( adapter: RuntimeMessageAdapter, - framework: F + framework: F, ): List { val fieldBindings = adapter.fields.values.toTypedArray() return fieldBindings.map { jsonAdapter(framework, adapter.syntax, it) } @@ -64,7 +64,7 @@ abstract class JsonIntegration { private fun jsonAdapter( framework: F, syntax: Syntax, - field: FieldOrOneOfBinding + field: FieldOrOneOfBinding, ): A { if (field.singleAdapter.isStruct) { return structAdapter(framework) @@ -81,7 +81,7 @@ abstract class JsonIntegration { field.isMap -> mapAdapter( framework = framework, keyFormatter = mapKeyJsonFormatter(field.keyAdapter), - valueAdapter = singleAdapter + valueAdapter = singleAdapter, ) else -> singleAdapter } @@ -90,7 +90,8 @@ abstract class JsonIntegration { private fun jsonFormatter(syntax: Syntax, protoAdapter: ProtoAdapter<*>): JsonFormatter<*>? { when (protoAdapter) { ProtoAdapter.BYTES, - ProtoAdapter.BYTES_VALUE -> return ByteStringJsonFormatter + ProtoAdapter.BYTES_VALUE, + -> return ByteStringJsonFormatter ProtoAdapter.DURATION -> return DurationJsonFormatter ProtoAdapter.INSTANT -> return InstantJsonFormatter is EnumAdapter<*> -> return EnumJsonFormatter(protoAdapter) @@ -105,14 +106,17 @@ abstract class JsonIntegration { return when (protoAdapter) { ProtoAdapter.UINT32, ProtoAdapter.FIXED32, - ProtoAdapter.UINT32_VALUE -> UnsignedIntAsNumberJsonFormatter + ProtoAdapter.UINT32_VALUE, + -> UnsignedIntAsNumberJsonFormatter ProtoAdapter.INT64, ProtoAdapter.SFIXED64, ProtoAdapter.SINT64, - ProtoAdapter.INT64_VALUE -> LongAsStringJsonFormatter + ProtoAdapter.INT64_VALUE, + -> LongAsStringJsonFormatter ProtoAdapter.FIXED64, ProtoAdapter.UINT64, - ProtoAdapter.UINT64_VALUE -> UnsignedLongAsStringJsonFormatter + ProtoAdapter.UINT64_VALUE, + -> UnsignedLongAsStringJsonFormatter else -> null } } @@ -123,14 +127,18 @@ abstract class JsonIntegration { ProtoAdapter.STRING -> StringJsonFormatter ProtoAdapter.INT32, ProtoAdapter.SINT32, - ProtoAdapter.SFIXED32 -> IntAsStringJsonFormatter + ProtoAdapter.SFIXED32, + -> IntAsStringJsonFormatter ProtoAdapter.FIXED32, - ProtoAdapter.UINT32 -> UnsignedIntAsStringJsonFormatter + ProtoAdapter.UINT32, + -> UnsignedIntAsStringJsonFormatter ProtoAdapter.INT64, ProtoAdapter.SFIXED64, - ProtoAdapter.SINT64 -> LongAsStringJsonFormatter + ProtoAdapter.SINT64, + -> LongAsStringJsonFormatter ProtoAdapter.FIXED64, - ProtoAdapter.UINT64 -> UnsignedLongAsStringJsonFormatter + ProtoAdapter.UINT64, + -> UnsignedLongAsStringJsonFormatter else -> error("Unexpected map key type: ${protoAdapter.type}") } } diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/OneOfBinding.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/OneOfBinding.kt index ee6c3cfae7..7cf196b304 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/OneOfBinding.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/OneOfBinding.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/reflection.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/reflection.kt index cc56c034a7..cf1c33c6d8 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/reflection.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/internal/reflection.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -72,13 +72,13 @@ fun , B : Message.Builder> createRuntimeMessageAdapter( newBuilderInstance, Collections.unmodifiableMap(fields), typeUrl, - syntax - ) + syntax, + ), ) } private fun , B : Message.Builder> getKeys( - messageField: Field + messageField: Field, ): Set> { val messageClass = messageField.declaringClass val keysField = messageClass.getDeclaredField(boxedOneOfKeysFieldName(messageField.name)) @@ -104,7 +104,7 @@ fun , B : Message.Builder> createRuntimeMessageAdapter( @Suppress("UNCHECKED_CAST") private fun , B : Message.Builder> getBuilderType( - messageType: Class + messageType: Class, ): Class { return runCatching { Class.forName("${messageType.name}\$Builder") as Class @@ -118,7 +118,7 @@ private class RuntimeMessageBinding, B : Message.Builder private val createBuilder: () -> B, override val fields: Map>, override val typeUrl: String?, - override val syntax: Syntax + override val syntax: Syntax, ) : MessageBinding { override fun unknownFields(message: M) = message.unknownFields diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Duration.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Duration.kt index ab409ce218..29d988b005 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Duration.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Duration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import com.squareup.wire.internal.floorModLong actual class Duration internal constructor( private val seconds: Long, - private val nanos: Int + private val nanos: Int, ) { actual fun getSeconds(): Long = seconds actual fun getNano(): Int = nanos @@ -30,7 +30,7 @@ actual class Duration internal constructor( actual fun durationOfSeconds( seconds: Long, - nano: Long + nano: Long, ): Duration { val s = addExactLong(seconds, floorDivLong(nano, NANOS_PER_SECOND)) val ns = floorModLong(nano, NANOS_PER_SECOND).toInt() diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/EnumAdapter.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/EnumAdapter.kt index 3dcbd3e10c..1a3c0a79d6 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/EnumAdapter.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/EnumAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2016 Square Inc. + * Copyright (C) 2016 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,7 +23,7 @@ import kotlin.reflect.KClass actual abstract class EnumAdapter protected actual constructor( type: KClass, syntax: Syntax, - identity: E? + identity: E?, ) : ProtoAdapter(FieldEncoding.VARINT, type, null, syntax, identity) { actual override fun encodedSize(value: E): Int = commonEncodedSize(value) diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Instant.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Instant.kt index bf22258ef7..e9a9f6d74f 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Instant.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Instant.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ import com.squareup.wire.internal.floorModLong actual class Instant internal constructor( private val epochSeconds: Long, - private val nanos: Int + private val nanos: Int, ) { actual fun getEpochSecond(): Long = epochSeconds actual fun getNano(): Int = nanos diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Message.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Message.kt index 839ef11296..4258ab9b43 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Message.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/Message.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,7 +28,7 @@ protected actual constructor( * Returns a byte string containing the proto encoding of this message's unknown fields. Returns * an empty byte string if this message has no unknown fields. */ - actual val unknownFields: ByteString + actual val unknownFields: ByteString, ) { /** If non-zero, the hash code of this message. Accessed by generated code. */ @Suppress("SetterBackingFieldAssignment", "UNUSED_PARAMETER") @@ -78,10 +78,10 @@ protected actual constructor( actual fun addUnknownField( tag: Int, fieldEncoding: FieldEncoding, - value: Any? + value: Any?, ): Builder = apply { prepareForNewUnknownFields() - @Suppress("UNCHECKED_CAST") + @Suppress("UNCHECKED_CAST") val protoAdapter = fieldEncoding.rawProtoAdapter() as ProtoAdapter protoAdapter.encodeWithTag(unknownFieldsWriter!!, tag, value) } diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSink.kt index f9dcd218ad..af5a026977 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSink.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSink.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSource.kt index a6c933c4a4..a6aa0abc1a 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSource.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/MessageSource.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/ProtoAdapter.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/ProtoAdapter.kt index ec57701bcb..4e88bf8ac9 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/ProtoAdapter.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/ProtoAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,10 +15,10 @@ */ package com.squareup.wire +import kotlin.reflect.KClass import okio.BufferedSink import okio.BufferedSource import okio.ByteString -import kotlin.reflect.KClass actual abstract class ProtoAdapter actual constructor( internal actual val fieldEncoding: FieldEncoding, @@ -126,7 +126,7 @@ actual abstract class ProtoAdapter actual constructor( "Unable to pack a length-delimited type." } return packedAdapter ?: throw UnsupportedOperationException( - "Can't create a packed adapter from a packed or repeated adapter." + "Can't create a packed adapter from a packed or repeated adapter.", ) } @@ -139,13 +139,13 @@ actual abstract class ProtoAdapter actual constructor( */ actual fun asRepeated(): ProtoAdapter> { return repeatedAdapter ?: throw UnsupportedOperationException( - "Can't create a repeated adapter from a repeated or packed adapter." + "Can't create a repeated adapter from a repeated or packed adapter.", ) } actual class EnumConstantNotFoundException actual constructor( actual val value: Int, - type: KClass<*>? + type: KClass<*>?, ) : IllegalArgumentException("Unknown enum tag $value for ${type?.simpleName}") actual companion object { @@ -158,7 +158,7 @@ actual abstract class ProtoAdapter actual constructor( */ actual fun newMapAdapter( keyAdapter: ProtoAdapter, - valueAdapter: ProtoAdapter + valueAdapter: ProtoAdapter, ): ProtoAdapter> { return commonNewMapAdapter(keyAdapter, valueAdapter) } @@ -176,6 +176,7 @@ actual abstract class ProtoAdapter actual constructor( actual val SFIXED32_ARRAY: ProtoAdapter = IntArrayProtoAdapter(SFIXED32) actual val INT64: ProtoAdapter = commonInt64() actual val INT64_ARRAY: ProtoAdapter = LongArrayProtoAdapter(INT64) + /** * Like INT64, but negative longs are interpreted as large positive values, and encoded that way * in JSON. diff --git a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/internal/-Platform.kt b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/internal/-Platform.kt index 026c91af54..f82328d58b 100644 --- a/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/internal/-Platform.kt +++ b/wire-runtime/src/nativeMain/kotlin/com/squareup/wire/internal/-Platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema/build.gradle.kts b/wire-schema/build.gradle.kts index 6ca0a47ea9..1c12045860 100644 --- a/wire-schema/build.gradle.kts +++ b/wire-schema/build.gradle.kts @@ -81,7 +81,7 @@ if (project.rootProject.name == "wire") { configure { kotlin { targetExclude( - // Apache 2-licensed files from Apache. + // Apache 2-licensed file from Apache. "src/jvmTest/kotlin/com/squareup/wire/schema/MavenVersionsTest.kt", ) } From ae064e5c14044e250a93f3f7bf5e2efac4885b36 Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 20:39:24 +0200 Subject: [PATCH 6/7] Spotless: wire-reflector --- .../wire/reflector/SchemaReflector.kt | 44 ++++++------ .../reflector/GrpcurlProto2InteropTest.kt | 31 ++++---- .../reflector/GrpcurlProto3InteropTest.kt | 47 +++++++------ .../wire/reflector/SchemaReflectorTest.kt | 70 +++++++++++-------- 4 files changed, 103 insertions(+), 89 deletions(-) diff --git a/wire-reflector/src/main/kotlin/com/squareup/wire/reflector/SchemaReflector.kt b/wire-reflector/src/main/kotlin/com/squareup/wire/reflector/SchemaReflector.kt index 41211f2883..c802c2bbb1 100644 --- a/wire-reflector/src/main/kotlin/com/squareup/wire/reflector/SchemaReflector.kt +++ b/wire-reflector/src/main/kotlin/com/squareup/wire/reflector/SchemaReflector.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -35,7 +35,7 @@ import grpc.reflection.v1alpha.ServiceResponse */ class SchemaReflector( private val schema: Schema, - private val includeDependencies: Boolean = true + private val includeDependencies: Boolean = true, ) { fun process(request: ServerReflectionRequest): ServerReflectionResponse { val response = when { @@ -43,23 +43,23 @@ class SchemaReflector( request.file_by_filename != null -> fileByFilename(request) request.file_containing_symbol != null -> fileContainingSymbol(request.file_containing_symbol) request.all_extension_numbers_of_type != null -> allExtensionNumbersOfType( - request.all_extension_numbers_of_type + request.all_extension_numbers_of_type, ) request.file_containing_extension != null -> fileContainingExtension( - request.file_containing_extension + request.file_containing_extension, ) else -> { ServerReflectionResponse( error_response = ErrorResponse( error_code = GrpcStatus.INVALID_ARGUMENT.code, - "unsupported request" - ) + "unsupported request", + ), ) } } return response.copy( valid_host = request.host, - original_request = request + original_request = request, ) } @@ -69,8 +69,8 @@ class SchemaReflector( return ServerReflectionResponse( error_response = ErrorResponse( error_code = GrpcStatus.NOT_FOUND.code, - error_message = "unknown type: \"$type\"" - ) + error_message = "unknown type: \"$type\"", + ), ) } @@ -80,7 +80,7 @@ class SchemaReflector( all_extension_numbers_response = ExtensionNumberResponse( base_type_name = type, extension_number = extensionNumbers, - ) + ), ) } @@ -91,8 +91,8 @@ class SchemaReflector( return ServerReflectionResponse( error_response = ErrorResponse( error_code = GrpcStatus.NOT_FOUND.code, - error_message = "unknown type: \"$extension.containing_type\"" - ) + error_message = "unknown type: \"$extension.containing_type\"", + ), ) } @@ -101,8 +101,8 @@ class SchemaReflector( ?: return ServerReflectionResponse( error_response = ErrorResponse( error_code = GrpcStatus.NOT_FOUND.code, - error_message = "unknown type: \"$extension.containing_type\"" - ) + error_message = "unknown type: \"$extension.containing_type\"", + ), ) val location = field.location @@ -111,7 +111,7 @@ class SchemaReflector( val allProtoFiles = allDependencies(protoFile) val schemaEncoder = SchemaEncoder(schema) return ServerReflectionResponse( - file_descriptor_response = FileDescriptorResponse(allProtoFiles.map { schemaEncoder.encode(it) }) + file_descriptor_response = FileDescriptorResponse(allProtoFiles.map { schemaEncoder.encode(it) }), ) } @@ -130,8 +130,8 @@ class SchemaReflector( return ServerReflectionResponse( list_services_response = ListServiceResponse( - service = allServiceNames.sortedBy { it.name } - ) + service = allServiceNames.sortedBy { it.name }, + ), ) } @@ -140,7 +140,7 @@ class SchemaReflector( val allProtoFiles = allDependencies(protoFile) val schemaEncoder = SchemaEncoder(schema) return ServerReflectionResponse( - file_descriptor_response = FileDescriptorResponse(allProtoFiles.map { schemaEncoder.encode(it) }) + file_descriptor_response = FileDescriptorResponse(allProtoFiles.map { schemaEncoder.encode(it) }), ) } @@ -151,15 +151,15 @@ class SchemaReflector( ?: return ServerReflectionResponse( error_response = ErrorResponse( error_code = GrpcStatus.NOT_FOUND.code, - "unknown symbol: $file_containing_symbol" - ) + "unknown symbol: $file_containing_symbol", + ), ) val protoFile = schema.protoFile(location.path)!! val allProtoFiles = allDependencies(protoFile) val schemaEncoder = SchemaEncoder(schema) return ServerReflectionResponse( - file_descriptor_response = FileDescriptorResponse(allProtoFiles.map { schemaEncoder.encode(it) }) + file_descriptor_response = FileDescriptorResponse(allProtoFiles.map { schemaEncoder.encode(it) }), ) } diff --git a/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto2InteropTest.kt b/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto2InteropTest.kt index 9447e18a1d..c6d924ab18 100644 --- a/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto2InteropTest.kt +++ b/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto2InteropTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,13 +39,14 @@ internal class GrpcurlProto2InteropTest { SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( list_services = "", - host = "localhost:0" - ) - ) + host = "localhost:0", + ), + ), ).isEqualTo(expectedResponse) } val ECHO2_FILEDESCRIPTOR_RESPONSE = "Cg5sb2NhbGhvc3Q6OTA5MBIcCg5sb2NhbGhvc3Q6OTA5MCIKZWNobzIuRWNobyLxTwr5CgoRZWNobzIvZWNobzIucHJvdG8SBWVjaG8yGhxnb29nbGUvYXBpL2Fubm90YXRpb25zLnByb3RvGhlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvIlsKDEhlbGxvUmVxdWVzdBIYCgdtZXNzYWdlGAEgAigJUgdtZXNzYWdlEjEKDG1vcmVfZGV0YWlscxgCIAEoCzIOLmVjaG8yLkRldGFpbHNSC21vcmVEZXRhaWxzIjYKDUhlbGxvUmVzcG9uc2USJQoOcm9ib3RfcmVzcG9uc2UYASACKAlSDXJvYm90UmVzcG9uc2Ui/gQKB0RldGFpbHMSPwoLbGFiZWxfY291bnQYASADKAsyHi5lY2hvMi5EZXRhaWxzLkxhYmVsQ291bnRFbnRyeVIKbGFiZWxDb3VudBIvCgpjb2xvcl90eXBlGAIgAigOMhAuZWNobzIuQ29sb3JUeXBlUgljb2xvclR5cGUSJgoDYW55GAMgAigLMhQuZ29vZ2xlLnByb3RvYnVmLkFueVIDYW55EjkKDW5vdGlmaWNhdGlvbnMYBCADKAsyEy5lY2hvMi5Ob3RpZmljYXRpb25SDW5vdGlmaWNhdGlvbnMSFwoHYV9pbnQzMhgFIAEoBVIGYUludDMyEhkKCGFfdWludDMyGAYgASgNUgdhVWludDMyEhcKB2FfaW50NjQYByABKANSBmFJbnQ2NBIZCghhX3VpbnQ2NBgIIAEoBFIHYVVpbnQ2NBIVCgZhX2Jvb2wYCSABKAhSBWFCb29sEhkKCGFfc2ludDMyGAogASgRUgdhU2ludDMyEhkKCGFfc2ludDY0GAsgASgSUgdhU2ludDY0EhkKCGFfc3RyaW5nGAwgASgJUgdhU3RyaW5nEhcKB2FfYnl0ZXMYDSABKAxSBmFCeXRlcxIbCglhX2ZpeGVkMzIYDiABKAdSCGFGaXhlZDMyEh0KCmFfc2ZpeGVkMzIYDyABKA9SCWFTZml4ZWQzMhIbCglhX2ZpeGVkNjQYECABKAZSCGFGaXhlZDY0Eh0KCmFfc2ZpeGVkNjQYESABKBBSCWFTZml4ZWQ2NBo9Cg9MYWJlbENvdW50RW50cnkSEAoDa2V5GAEgASgJUgNrZXkSFAoFdmFsdWUYAiABKANSBXZhbHVlOgI4ASKZAQoMTm90aWZpY2F0aW9uEg4KAmlkGAEgAigFUgJpZBI2Cgdwcml2YXRlGAIgASgLMhouZWNobzIuUHJpdmF0ZU5vdGlmaWNhdGlvbkgAUgdwcml2YXRlEjMKBnB1YmxpYxgDIAEoCzIZLmVjaG8yLlB1YmxpY05vdGlmaWNhdGlvbkgAUgZwdWJsaWNCDAoKaW5zdHJ1bWVudCI8ChNQcml2YXRlTm90aWZpY2F0aW9uEiUKDnNlY3JldF9jb250ZW50GAEgAigJUg1zZWNyZXRDb250ZW50Ii4KElB1YmxpY05vdGlmaWNhdGlvbhIYCgdjb250ZW50GAEgAigJUgdjb250ZW50KikKCUNvbG9yVHlwZRIHCgNSRUQQABIICgRCTFVFEAESCQoFR1JFRU4QAjKvAQoERWNobxJOCgVIZWxsbxITLmVjaG8yLkhlbGxvUmVxdWVzdBoULmVjaG8yLkhlbGxvUmVzcG9uc2UiGoLT5JMCFDoBKiIPL2FwaS9lY2hvL2hlbGxvElcKC0hlbGxvU3RyZWFtEhMuZWNobzIuSGVsbG9SZXF1ZXN0GhQuZWNobzIuSGVsbG9SZXNwb25zZSIbgtPkkwIVOgEqIhAvYXBpL2VjaG8vc3RyZWFtMAFCJ1olZ2l0aHViLmNvbS9qdWxpYW9ncmlzL2d1cHB5L3BrZy9lY2hvMgqoAgocZ29vZ2xlL2FwaS9hbm5vdGF0aW9ucy5wcm90bxIKZ29vZ2xlLmFwaRoVZ29vZ2xlL2FwaS9odHRwLnByb3RvGiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bzpLCgRodHRwEh4uZ29vZ2xlLnByb3RvYnVmLk1ldGhvZE9wdGlvbnMYsMq8IiABKAsyFC5nb29nbGUuYXBpLkh0dHBSdWxlUgRodHRwQm4KDmNvbS5nb29nbGUuYXBpQhBBbm5vdGF0aW9uc1Byb3RvUAFaQWdvb2dsZS5nb2xhbmcub3JnL2dlbnByb3RvL2dvb2dsZWFwaXMvYXBpL2Fubm90YXRpb25zO2Fubm90YXRpb25zogIER0FQSWIGcHJvdG8zCuQBChlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYiNgoDQW55EhkKCHR5cGVfdXJsGAEgASgJUgd0eXBlVXJsEhQKBXZhbHVlGAIgASgMUgV2YWx1ZUJ2ChNjb20uZ29vZ2xlLnByb3RvYnVmQghBbnlQcm90b1ABWixnb29nbGUuZ29sYW5nLm9yZy9wcm90b2J1Zi90eXBlcy9rbm93bi9hbnlwYqICA0dQQqoCHkdvb2dsZS5Qcm90b2J1Zi5XZWxsS25vd25UeXBlc2IGcHJvdG8zCqwFChVnb29nbGUvYXBpL2h0dHAucHJvdG8SCmdvb2dsZS5hcGkieQoESHR0cBIqCgVydWxlcxgBIAMoCzIULmdvb2dsZS5hcGkuSHR0cFJ1bGVSBXJ1bGVzEkUKH2Z1bGx5X2RlY29kZV9yZXNlcnZlZF9leHBhbnNpb24YAiABKAhSHGZ1bGx5RGVjb2RlUmVzZXJ2ZWRFeHBhbnNpb24i2gIKCEh0dHBSdWxlEhoKCHNlbGVjdG9yGAEgASgJUghzZWxlY3RvchISCgNnZXQYAiABKAlIAFIDZ2V0EhIKA3B1dBgDIAEoCUgAUgNwdXQSFAoEcG9zdBgEIAEoCUgAUgRwb3N0EhgKBmRlbGV0ZRgFIAEoCUgAUgZkZWxldGUSFgoFcGF0Y2gYBiABKAlIAFIFcGF0Y2gSNwoGY3VzdG9tGAggASgLMh0uZ29vZ2xlLmFwaS5DdXN0b21IdHRwUGF0dGVybkgAUgZjdXN0b20SEgoEYm9keRgHIAEoCVIEYm9keRIjCg1yZXNwb25zZV9ib2R5GAwgASgJUgxyZXNwb25zZUJvZHkSRQoTYWRkaXRpb25hbF9iaW5kaW5ncxgLIAMoCzIULmdvb2dsZS5hcGkuSHR0cFJ1bGVSEmFkZGl0aW9uYWxCaW5kaW5nc0IJCgdwYXR0ZXJuIjsKEUN1c3RvbUh0dHBQYXR0ZXJuEhIKBGtpbmQYASABKAlSBGtpbmQSEgoEcGF0aBgCIAEoCVIEcGF0aEJqCg5jb20uZ29vZ2xlLmFwaUIJSHR0cFByb3RvUAFaQWdvb2dsZS5nb2xhbmcub3JnL2dlbnByb3RvL2dvb2dsZWFwaXMvYXBpL2Fubm90YXRpb25zO2Fubm90YXRpb25z+AEBogIER0FQSWIGcHJvdG8zCrE7CiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bxIPZ29vZ2xlLnByb3RvYnVmIk0KEUZpbGVEZXNjcmlwdG9yU2V0EjgKBGZpbGUYASADKAsyJC5nb29nbGUucHJvdG9idWYuRmlsZURlc2NyaXB0b3JQcm90b1IEZmlsZSLkBAoTRmlsZURlc2NyaXB0b3JQcm90bxISCgRuYW1lGAEgASgJUgRuYW1lEhgKB3BhY2thZ2UYAiABKAlSB3BhY2thZ2USHgoKZGVwZW5kZW5jeRgDIAMoCVIKZGVwZW5kZW5jeRIrChFwdWJsaWNfZGVwZW5kZW5jeRgKIAMoBVIQcHVibGljRGVwZW5kZW5jeRInCg93ZWFrX2RlcGVuZGVuY3kYCyADKAVSDndlYWtEZXBlbmRlbmN5EkMKDG1lc3NhZ2VfdHlwZRgEIAMoCzIgLmdvb2dsZS5wcm90b2J1Zi5EZXNjcmlwdG9yUHJvdG9SC21lc3NhZ2VUeXBlEkEKCWVudW1fdHlwZRgFIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5FbnVtRGVzY3JpcHRvclByb3RvUghlbnVtVHlwZRJBCgdzZXJ2aWNlGAYgAygLMicuZ29vZ2xlLnByb3RvYnVmLlNlcnZpY2VEZXNjcmlwdG9yUHJvdG9SB3NlcnZpY2USQwoJZXh0ZW5zaW9uGAcgAygLMiUuZ29vZ2xlLnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3RvUglleHRlbnNpb24SNgoHb3B0aW9ucxgIIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5GaWxlT3B0aW9uc1IHb3B0aW9ucxJJChBzb3VyY2VfY29kZV9pbmZvGAkgASgLMh8uZ29vZ2xlLnByb3RvYnVmLlNvdXJjZUNvZGVJbmZvUg5zb3VyY2VDb2RlSW5mbxIWCgZzeW50YXgYDCABKAlSBnN5bnRheCK5BgoPRGVzY3JpcHRvclByb3RvEhIKBG5hbWUYASABKAlSBG5hbWUSOwoFZmllbGQYAiADKAsyJS5nb29nbGUucHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJvdG9SBWZpZWxkEkMKCWV4dGVuc2lvbhgGIAMoCzIlLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90b1IJZXh0ZW5zaW9uEkEKC25lc3RlZF90eXBlGAMgAygLMiAuZ29vZ2xlLnByb3RvYnVmLkRlc2NyaXB0b3JQcm90b1IKbmVzdGVkVHlwZRJBCgllbnVtX3R5cGUYBCADKAsyJC5nb29nbGUucHJvdG9idWYuRW51bURlc2NyaXB0b3JQcm90b1IIZW51bVR5cGUSWAoPZXh0ZW5zaW9uX3JhbmdlGAUgAygLMi8uZ29vZ2xlLnByb3RvYnVmLkRlc2NyaXB0b3JQcm90by5FeHRlbnNpb25SYW5nZVIOZXh0ZW5zaW9uUmFuZ2USRAoKb25lb2ZfZGVjbBgIIAMoCzIlLmdvb2dsZS5wcm90b2J1Zi5PbmVvZkRlc2NyaXB0b3JQcm90b1IJb25lb2ZEZWNsEjkKB29wdGlvbnMYByABKAsyHy5nb29nbGUucHJvdG9idWYuTWVzc2FnZU9wdGlvbnNSB29wdGlvbnMSVQoOcmVzZXJ2ZWRfcmFuZ2UYCSADKAsyLi5nb29nbGUucHJvdG9idWYuRGVzY3JpcHRvclByb3RvLlJlc2VydmVkUmFuZ2VSDXJlc2VydmVkUmFuZ2USIwoNcmVzZXJ2ZWRfbmFtZRgKIAMoCVIMcmVzZXJ2ZWROYW1lGnoKDkV4dGVuc2lvblJhbmdlEhQKBXN0YXJ0GAEgASgFUgVzdGFydBIQCgNlbmQYAiABKAVSA2VuZBJACgdvcHRpb25zGAMgASgLMiYuZ29vZ2xlLnByb3RvYnVmLkV4dGVuc2lvblJhbmdlT3B0aW9uc1IHb3B0aW9ucxo3Cg1SZXNlcnZlZFJhbmdlEhQKBXN0YXJ0GAEgASgFUgVzdGFydBIQCgNlbmQYAiABKAVSA2VuZCJ8ChVFeHRlbnNpb25SYW5nZU9wdGlvbnMSWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiLBBgoURmllbGREZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRIWCgZudW1iZXIYAyABKAVSBm51bWJlchJBCgVsYWJlbBgEIAEoDjIrLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90by5MYWJlbFIFbGFiZWwSPgoEdHlwZRgFIAEoDjIqLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90by5UeXBlUgR0eXBlEhsKCXR5cGVfbmFtZRgGIAEoCVIIdHlwZU5hbWUSGgoIZXh0ZW5kZWUYAiABKAlSCGV4dGVuZGVlEiMKDWRlZmF1bHRfdmFsdWUYByABKAlSDGRlZmF1bHRWYWx1ZRIfCgtvbmVvZl9pbmRleBgJIAEoBVIKb25lb2ZJbmRleBIbCglqc29uX25hbWUYCiABKAlSCGpzb25OYW1lEjcKB29wdGlvbnMYCCABKAsyHS5nb29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zUgdvcHRpb25zEicKD3Byb3RvM19vcHRpb25hbBgRIAEoCFIOcHJvdG8zT3B0aW9uYWwitgIKBFR5cGUSDwoLVFlQRV9ET1VCTEUQARIOCgpUWVBFX0ZMT0FUEAISDgoKVFlQRV9JTlQ2NBADEg8KC1RZUEVfVUlOVDY0EAQSDgoKVFlQRV9JTlQzMhAFEhAKDFRZUEVfRklYRUQ2NBAGEhAKDFRZUEVfRklYRUQzMhAHEg0KCVRZUEVfQk9PTBAIEg8KC1RZUEVfU1RSSU5HEAkSDgoKVFlQRV9HUk9VUBAKEhAKDFRZUEVfTUVTU0FHRRALEg4KClRZUEVfQllURVMQDBIPCgtUWVBFX1VJTlQzMhANEg0KCVRZUEVfRU5VTRAOEhEKDVRZUEVfU0ZJWEVEMzIQDxIRCg1UWVBFX1NGSVhFRDY0EBASDwoLVFlQRV9TSU5UMzIQERIPCgtUWVBFX1NJTlQ2NBASIkMKBUxhYmVsEhIKDkxBQkVMX09QVElPTkFMEAESEgoOTEFCRUxfUkVRVUlSRUQQAhISCg5MQUJFTF9SRVBFQVRFRBADImMKFE9uZW9mRGVzY3JpcHRvclByb3RvEhIKBG5hbWUYASABKAlSBG5hbWUSNwoHb3B0aW9ucxgCIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5PbmVvZk9wdGlvbnNSB29wdGlvbnMi4wIKE0VudW1EZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRI/CgV2YWx1ZRgCIAMoCzIpLmdvb2dsZS5wcm90b2J1Zi5FbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG9SBXZhbHVlEjYKB29wdGlvbnMYAyABKAsyHC5nb29nbGUucHJvdG9idWYuRW51bU9wdGlvbnNSB29wdGlvbnMSXQoOcmVzZXJ2ZWRfcmFuZ2UYBCADKAsyNi5nb29nbGUucHJvdG9idWYuRW51bURlc2NyaXB0b3JQcm90by5FbnVtUmVzZXJ2ZWRSYW5nZVINcmVzZXJ2ZWRSYW5nZRIjCg1yZXNlcnZlZF9uYW1lGAUgAygJUgxyZXNlcnZlZE5hbWUaOwoRRW51bVJlc2VydmVkUmFuZ2USFAoFc3RhcnQYASABKAVSBXN0YXJ0EhAKA2VuZBgCIAEoBVIDZW5kIoMBChhFbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRIWCgZudW1iZXIYAiABKAVSBm51bWJlchI7CgdvcHRpb25zGAMgASgLMiEuZ29vZ2xlLnByb3RvYnVmLkVudW1WYWx1ZU9wdGlvbnNSB29wdGlvbnMipwEKFlNlcnZpY2VEZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRI+CgZtZXRob2QYAiADKAsyJi5nb29nbGUucHJvdG9idWYuTWV0aG9kRGVzY3JpcHRvclByb3RvUgZtZXRob2QSOQoHb3B0aW9ucxgDIAEoCzIfLmdvb2dsZS5wcm90b2J1Zi5TZXJ2aWNlT3B0aW9uc1IHb3B0aW9ucyKJAgoVTWV0aG9kRGVzY3JpcHRvclByb3RvEhIKBG5hbWUYASABKAlSBG5hbWUSHQoKaW5wdXRfdHlwZRgCIAEoCVIJaW5wdXRUeXBlEh8KC291dHB1dF90eXBlGAMgASgJUgpvdXRwdXRUeXBlEjgKB29wdGlvbnMYBCABKAsyHi5nb29nbGUucHJvdG9idWYuTWV0aG9kT3B0aW9uc1IHb3B0aW9ucxIwChBjbGllbnRfc3RyZWFtaW5nGAUgASgIOgVmYWxzZVIPY2xpZW50U3RyZWFtaW5nEjAKEHNlcnZlcl9zdHJlYW1pbmcYBiABKAg6BWZhbHNlUg9zZXJ2ZXJTdHJlYW1pbmcikQkKC0ZpbGVPcHRpb25zEiEKDGphdmFfcGFja2FnZRgBIAEoCVILamF2YVBhY2thZ2USMAoUamF2YV9vdXRlcl9jbGFzc25hbWUYCCABKAlSEmphdmFPdXRlckNsYXNzbmFtZRI1ChNqYXZhX211bHRpcGxlX2ZpbGVzGAogASgIOgVmYWxzZVIRamF2YU11bHRpcGxlRmlsZXMSRAodamF2YV9nZW5lcmF0ZV9lcXVhbHNfYW5kX2hhc2gYFCABKAhCAhgBUhlqYXZhR2VuZXJhdGVFcXVhbHNBbmRIYXNoEjoKFmphdmFfc3RyaW5nX2NoZWNrX3V0ZjgYGyABKAg6BWZhbHNlUhNqYXZhU3RyaW5nQ2hlY2tVdGY4ElMKDG9wdGltaXplX2ZvchgJIAEoDjIpLmdvb2dsZS5wcm90b2J1Zi5GaWxlT3B0aW9ucy5PcHRpbWl6ZU1vZGU6BVNQRUVEUgtvcHRpbWl6ZUZvchIdCgpnb19wYWNrYWdlGAsgASgJUglnb1BhY2thZ2USNQoTY2NfZ2VuZXJpY19zZXJ2aWNlcxgQIAEoCDoFZmFsc2VSEWNjR2VuZXJpY1NlcnZpY2VzEjkKFWphdmFfZ2VuZXJpY19zZXJ2aWNlcxgRIAEoCDoFZmFsc2VSE2phdmFHZW5lcmljU2VydmljZXMSNQoTcHlfZ2VuZXJpY19zZXJ2aWNlcxgSIAEoCDoFZmFsc2VSEXB5R2VuZXJpY1NlcnZpY2VzEjcKFHBocF9nZW5lcmljX3NlcnZpY2VzGCogASgIOgVmYWxzZVIScGhwR2VuZXJpY1NlcnZpY2VzEiUKCmRlcHJlY2F0ZWQYFyABKAg6BWZhbHNlUgpkZXByZWNhdGVkEi4KEGNjX2VuYWJsZV9hcmVuYXMYHyABKAg6BHRydWVSDmNjRW5hYmxlQXJlbmFzEioKEW9iamNfY2xhc3NfcHJlZml4GCQgASgJUg9vYmpjQ2xhc3NQcmVmaXgSKQoQY3NoYXJwX25hbWVzcGFjZRglIAEoCVIPY3NoYXJwTmFtZXNwYWNlEiEKDHN3aWZ0X3ByZWZpeBgnIAEoCVILc3dpZnRQcmVmaXgSKAoQcGhwX2NsYXNzX3ByZWZpeBgoIAEoCVIOcGhwQ2xhc3NQcmVmaXgSIwoNcGhwX25hbWVzcGFjZRgpIAEoCVIMcGhwTmFtZXNwYWNlEjQKFnBocF9tZXRhZGF0YV9uYW1lc3BhY2UYLCABKAlSFHBocE1ldGFkYXRhTmFtZXNwYWNlEiEKDHJ1YnlfcGFja2FnZRgtIAEoCVILcnVieVBhY2thZ2USWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24iOgoMT3B0aW1pemVNb2RlEgkKBVNQRUVEEAESDQoJQ09ERV9TSVpFEAISEAoMTElURV9SVU5USU1FEAMqCQjoBxCAgICAAkoECCYQJyLRAgoOTWVzc2FnZU9wdGlvbnMSPAoXbWVzc2FnZV9zZXRfd2lyZV9mb3JtYXQYASABKAg6BWZhbHNlUhRtZXNzYWdlU2V0V2lyZUZvcm1hdBJMCh9ub19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZVIcbm9TdGFuZGFyZERlc2NyaXB0b3JBY2Nlc3NvchIlCgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZVIKZGVwcmVjYXRlZBIbCgltYXBfZW50cnkYByABKAhSCG1hcEVudHJ5ElgKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uUhN1bmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgIEAlKBAgJEAoi4gMKDEZpZWxkT3B0aW9ucxJBCgVjdHlwZRgBIAEoDjIjLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlvbnMuQ1R5cGU6BlNUUklOR1IFY3R5cGUSFgoGcGFja2VkGAIgASgIUgZwYWNrZWQSRwoGanN0eXBlGAYgASgOMiQuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5KU1R5cGU6CUpTX05PUk1BTFIGanN0eXBlEhkKBGxhenkYBSABKAg6BWZhbHNlUgRsYXp5EiUKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlUgpkZXByZWNhdGVkEhkKBHdlYWsYCiABKAg6BWZhbHNlUgR3ZWFrElgKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uUhN1bmludGVycHJldGVkT3B0aW9uIi8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElFQ0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAESDQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJzCgxPbmVvZk9wdGlvbnMSWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiLAAQoLRW51bU9wdGlvbnMSHwoLYWxsb3dfYWxpYXMYAiABKAhSCmFsbG93QWxpYXMSJQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2VSCmRlcHJlY2F0ZWQSWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAUQBiKeAQoQRW51bVZhbHVlT3B0aW9ucxIlCgpkZXByZWNhdGVkGAEgASgIOgVmYWxzZVIKZGVwcmVjYXRlZBJYChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvblITdW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICAgIACIpwBCg5TZXJ2aWNlT3B0aW9ucxIlCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZVIKZGVwcmVjYXRlZBJYChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvblITdW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICAgIACIuACCg1NZXRob2RPcHRpb25zEiUKCmRlcHJlY2F0ZWQYISABKAg6BWZhbHNlUgpkZXByZWNhdGVkEnEKEWlkZW1wb3RlbmN5X2xldmVsGCIgASgOMi8uZ29vZ2xlLnByb3RvYnVmLk1ldGhvZE9wdGlvbnMuSWRlbXBvdGVuY3lMZXZlbDoTSURFTVBPVEVOQ1lfVU5LTk9XTlIQaWRlbXBvdGVuY3lMZXZlbBJYChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvblITdW5pbnRlcnByZXRlZE9wdGlvbiJQChBJZGVtcG90ZW5jeUxldmVsEhcKE0lERU1QT1RFTkNZX1VOS05PV04QABITCg9OT19TSURFX0VGRkVDVFMQARIOCgpJREVNUE9URU5UEAIqCQjoBxCAgICAAiKaAwoTVW5pbnRlcnByZXRlZE9wdGlvbhJBCgRuYW1lGAIgAygLMi0uZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24uTmFtZVBhcnRSBG5hbWUSKQoQaWRlbnRpZmllcl92YWx1ZRgDIAEoCVIPaWRlbnRpZmllclZhbHVlEiwKEnBvc2l0aXZlX2ludF92YWx1ZRgEIAEoBFIQcG9zaXRpdmVJbnRWYWx1ZRIsChJuZWdhdGl2ZV9pbnRfdmFsdWUYBSABKANSEG5lZ2F0aXZlSW50VmFsdWUSIQoMZG91YmxlX3ZhbHVlGAYgASgBUgtkb3VibGVWYWx1ZRIhCgxzdHJpbmdfdmFsdWUYByABKAxSC3N0cmluZ1ZhbHVlEicKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCVIOYWdncmVnYXRlVmFsdWUaSgoITmFtZVBhcnQSGwoJbmFtZV9wYXJ0GAEgAigJUghuYW1lUGFydBIhCgxpc19leHRlbnNpb24YAiACKAhSC2lzRXh0ZW5zaW9uIqcCCg5Tb3VyY2VDb2RlSW5mbxJECghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvblIIbG9jYXRpb24azgEKCExvY2F0aW9uEhYKBHBhdGgYASADKAVCAhABUgRwYXRoEhYKBHNwYW4YAiADKAVCAhABUgRzcGFuEikKEGxlYWRpbmdfY29tbWVudHMYAyABKAlSD2xlYWRpbmdDb21tZW50cxIrChF0cmFpbGluZ19jb21tZW50cxgEIAEoCVIQdHJhaWxpbmdDb21tZW50cxI6ChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJUhdsZWFkaW5nRGV0YWNoZWRDb21tZW50cyLRAQoRR2VuZXJhdGVkQ29kZUluZm8STQoKYW5ub3RhdGlvbhgBIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9uUgphbm5vdGF0aW9uGm0KCkFubm90YXRpb24SFgoEcGF0aBgBIAMoBUICEAFSBHBhdGgSHwoLc291cmNlX2ZpbGUYAiABKAlSCnNvdXJjZUZpbGUSFAoFYmVnaW4YAyABKAVSBWJlZ2luEhAKA2VuZBgEIAEoBVIDZW5kQn4KE2NvbS5nb29nbGUucHJvdG9idWZCEERlc2NyaXB0b3JQcm90b3NIAVotZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMvZGVzY3JpcHRvcnBi+AEBogIDR1BCqgIaR29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rpb24=" + @Test fun `file_containing_symbol service`() { val schema = loadSchema() @@ -53,8 +54,8 @@ internal class GrpcurlProto2InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "echo2.Echo", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -68,8 +69,8 @@ internal class GrpcurlProto2InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "echo2.HelloRequest", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -83,8 +84,8 @@ internal class GrpcurlProto2InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "echo2.Echo.HelloStream", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -98,8 +99,8 @@ internal class GrpcurlProto2InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_by_filename = "echo2/echo2.proto", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -109,7 +110,7 @@ internal class GrpcurlProto2InteropTest { private val ServerReflectionResponse.fileDescriptors get() = file_descriptor_response!!.file_descriptor_proto.map { FileDescriptorProto.parseFrom( - it.toByteArray() + it.toByteArray(), ) } } @@ -126,7 +127,7 @@ private fun loadSchema(): Schema { Location.get("src/test/proto", "google/api/http.proto"), Location.get("src/test/proto", "google/protobuf/any.proto"), ), - protoPath = listOf() + protoPath = listOf(), ) } .loadSchema() diff --git a/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto3InteropTest.kt b/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto3InteropTest.kt index caf71dfa1c..33077c6e1e 100644 --- a/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto3InteropTest.kt +++ b/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/GrpcurlProto3InteropTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -41,13 +41,14 @@ internal class GrpcurlProto3InteropTest { SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( list_services = "", - host = "localhost:0" - ) - ) + host = "localhost:0", + ), + ), ).isEqualTo(expectedListResponse) } val ECHO3_FILEDESCRIPTOR_RESPONSE = "Cg5sb2NhbGhvc3Q6OTA5MBIcCg5sb2NhbGhvc3Q6OTA5MCIKZWNobzMuRWNobyKGUAqOCwoRZWNobzMvZWNobzMucHJvdG8SBWVjaG8zGhxnb29nbGUvYXBpL2Fubm90YXRpb25zLnByb3RvGhlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvIlsKDEhlbGxvUmVxdWVzdBIYCgdtZXNzYWdlGAEgASgJUgdtZXNzYWdlEjEKDG1vcmVfZGV0YWlscxgCIAEoCzIOLmVjaG8zLkRldGFpbHNSC21vcmVEZXRhaWxzIjYKDUhlbGxvUmVzcG9uc2USJQoOcm9ib3RfcmVzcG9uc2UYASABKAlSDXJvYm90UmVzcG9uc2UiiwUKB0RldGFpbHMSPwoLbGFiZWxfY291bnQYASADKAsyHi5lY2hvMy5EZXRhaWxzLkxhYmVsQ291bnRFbnRyeVIKbGFiZWxDb3VudBIvCgpjb2xvcl90eXBlGAIgASgOMhAuZWNobzMuQ29sb3JUeXBlUgljb2xvclR5cGUSKwoDYW55GAMgASgLMhQuZ29vZ2xlLnByb3RvYnVmLkFueUgAUgNhbnmIAQESOQoNbm90aWZpY2F0aW9ucxgEIAMoCzITLmVjaG8zLk5vdGlmaWNhdGlvblINbm90aWZpY2F0aW9ucxIXCgdhX2ludDMyGAUgASgFUgZhSW50MzISGQoIYV91aW50MzIYBiABKA1SB2FVaW50MzISFwoHYV9pbnQ2NBgHIAEoA1IGYUludDY0EhkKCGFfdWludDY0GAggASgEUgdhVWludDY0EhUKBmFfYm9vbBgJIAEoCFIFYUJvb2wSGQoIYV9zaW50MzIYCiABKBFSB2FTaW50MzISGQoIYV9zaW50NjQYCyABKBJSB2FTaW50NjQSGQoIYV9zdHJpbmcYDCABKAlSB2FTdHJpbmcSFwoHYV9ieXRlcxgNIAEoDFIGYUJ5dGVzEhsKCWFfZml4ZWQzMhgOIAEoB1IIYUZpeGVkMzISHQoKYV9zZml4ZWQzMhgPIAEoD1IJYVNmaXhlZDMyEhsKCWFfZml4ZWQ2NBgQIAEoBlIIYUZpeGVkNjQSHQoKYV9zZml4ZWQ2NBgRIAEoEFIJYVNmaXhlZDY0Gj0KD0xhYmVsQ291bnRFbnRyeRIQCgNrZXkYASABKAlSA2tleRIUCgV2YWx1ZRgCIAEoA1IFdmFsdWU6AjgBQgYKBF9hbnkimQEKDE5vdGlmaWNhdGlvbhIOCgJpZBgBIAEoBVICaWQSNgoHcHJpdmF0ZRgCIAEoCzIaLmVjaG8zLlByaXZhdGVOb3RpZmljYXRpb25IAFIHcHJpdmF0ZRIzCgZwdWJsaWMYAyABKAsyGS5lY2hvMy5QdWJsaWNOb3RpZmljYXRpb25IAFIGcHVibGljQgwKCmluc3RydW1lbnQiPAoTUHJpdmF0ZU5vdGlmaWNhdGlvbhIlCg5zZWNyZXRfY29udGVudBgBIAEoCVINc2VjcmV0Q29udGVudCIuChJQdWJsaWNOb3RpZmljYXRpb24SGAoHY29udGVudBgBIAEoCVIHY29udGVudCopCglDb2xvclR5cGUSBwoDUkVEEAASCAoEQkxVRRABEgkKBUdSRUVOEAIyrwEKBEVjaG8STgoFSGVsbG8SEy5lY2hvMy5IZWxsb1JlcXVlc3QaFC5lY2hvMy5IZWxsb1Jlc3BvbnNlIhqC0+STAhQ6ASoiDy9hcGkvZWNoby9oZWxsbxJXCgtIZWxsb1N0cmVhbRITLmVjaG8zLkhlbGxvUmVxdWVzdBoULmVjaG8zLkhlbGxvUmVzcG9uc2UiG4LT5JMCFToBKiIQL2FwaS9lY2hvL3N0cmVhbTABQidaJWdpdGh1Yi5jb20vanVsaWFvZ3Jpcy9ndXBweS9wa2cvZWNobzNiBnByb3RvMwqoAgocZ29vZ2xlL2FwaS9hbm5vdGF0aW9ucy5wcm90bxIKZ29vZ2xlLmFwaRoVZ29vZ2xlL2FwaS9odHRwLnByb3RvGiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bzpLCgRodHRwEh4uZ29vZ2xlLnByb3RvYnVmLk1ldGhvZE9wdGlvbnMYsMq8IiABKAsyFC5nb29nbGUuYXBpLkh0dHBSdWxlUgRodHRwQm4KDmNvbS5nb29nbGUuYXBpQhBBbm5vdGF0aW9uc1Byb3RvUAFaQWdvb2dsZS5nb2xhbmcub3JnL2dlbnByb3RvL2dvb2dsZWFwaXMvYXBpL2Fubm90YXRpb25zO2Fubm90YXRpb25zogIER0FQSWIGcHJvdG8zCuQBChlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYiNgoDQW55EhkKCHR5cGVfdXJsGAEgASgJUgd0eXBlVXJsEhQKBXZhbHVlGAIgASgMUgV2YWx1ZUJ2ChNjb20uZ29vZ2xlLnByb3RvYnVmQghBbnlQcm90b1ABWixnb29nbGUuZ29sYW5nLm9yZy9wcm90b2J1Zi90eXBlcy9rbm93bi9hbnlwYqICA0dQQqoCHkdvb2dsZS5Qcm90b2J1Zi5XZWxsS25vd25UeXBlc2IGcHJvdG8zCqwFChVnb29nbGUvYXBpL2h0dHAucHJvdG8SCmdvb2dsZS5hcGkieQoESHR0cBIqCgVydWxlcxgBIAMoCzIULmdvb2dsZS5hcGkuSHR0cFJ1bGVSBXJ1bGVzEkUKH2Z1bGx5X2RlY29kZV9yZXNlcnZlZF9leHBhbnNpb24YAiABKAhSHGZ1bGx5RGVjb2RlUmVzZXJ2ZWRFeHBhbnNpb24i2gIKCEh0dHBSdWxlEhoKCHNlbGVjdG9yGAEgASgJUghzZWxlY3RvchISCgNnZXQYAiABKAlIAFIDZ2V0EhIKA3B1dBgDIAEoCUgAUgNwdXQSFAoEcG9zdBgEIAEoCUgAUgRwb3N0EhgKBmRlbGV0ZRgFIAEoCUgAUgZkZWxldGUSFgoFcGF0Y2gYBiABKAlIAFIFcGF0Y2gSNwoGY3VzdG9tGAggASgLMh0uZ29vZ2xlLmFwaS5DdXN0b21IdHRwUGF0dGVybkgAUgZjdXN0b20SEgoEYm9keRgHIAEoCVIEYm9keRIjCg1yZXNwb25zZV9ib2R5GAwgASgJUgxyZXNwb25zZUJvZHkSRQoTYWRkaXRpb25hbF9iaW5kaW5ncxgLIAMoCzIULmdvb2dsZS5hcGkuSHR0cFJ1bGVSEmFkZGl0aW9uYWxCaW5kaW5nc0IJCgdwYXR0ZXJuIjsKEUN1c3RvbUh0dHBQYXR0ZXJuEhIKBGtpbmQYASABKAlSBGtpbmQSEgoEcGF0aBgCIAEoCVIEcGF0aEJqCg5jb20uZ29vZ2xlLmFwaUIJSHR0cFByb3RvUAFaQWdvb2dsZS5nb2xhbmcub3JnL2dlbnByb3RvL2dvb2dsZWFwaXMvYXBpL2Fubm90YXRpb25zO2Fubm90YXRpb25z+AEBogIER0FQSWIGcHJvdG8zCrE7CiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bxIPZ29vZ2xlLnByb3RvYnVmIk0KEUZpbGVEZXNjcmlwdG9yU2V0EjgKBGZpbGUYASADKAsyJC5nb29nbGUucHJvdG9idWYuRmlsZURlc2NyaXB0b3JQcm90b1IEZmlsZSLkBAoTRmlsZURlc2NyaXB0b3JQcm90bxISCgRuYW1lGAEgASgJUgRuYW1lEhgKB3BhY2thZ2UYAiABKAlSB3BhY2thZ2USHgoKZGVwZW5kZW5jeRgDIAMoCVIKZGVwZW5kZW5jeRIrChFwdWJsaWNfZGVwZW5kZW5jeRgKIAMoBVIQcHVibGljRGVwZW5kZW5jeRInCg93ZWFrX2RlcGVuZGVuY3kYCyADKAVSDndlYWtEZXBlbmRlbmN5EkMKDG1lc3NhZ2VfdHlwZRgEIAMoCzIgLmdvb2dsZS5wcm90b2J1Zi5EZXNjcmlwdG9yUHJvdG9SC21lc3NhZ2VUeXBlEkEKCWVudW1fdHlwZRgFIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5FbnVtRGVzY3JpcHRvclByb3RvUghlbnVtVHlwZRJBCgdzZXJ2aWNlGAYgAygLMicuZ29vZ2xlLnByb3RvYnVmLlNlcnZpY2VEZXNjcmlwdG9yUHJvdG9SB3NlcnZpY2USQwoJZXh0ZW5zaW9uGAcgAygLMiUuZ29vZ2xlLnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3RvUglleHRlbnNpb24SNgoHb3B0aW9ucxgIIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5GaWxlT3B0aW9uc1IHb3B0aW9ucxJJChBzb3VyY2VfY29kZV9pbmZvGAkgASgLMh8uZ29vZ2xlLnByb3RvYnVmLlNvdXJjZUNvZGVJbmZvUg5zb3VyY2VDb2RlSW5mbxIWCgZzeW50YXgYDCABKAlSBnN5bnRheCK5BgoPRGVzY3JpcHRvclByb3RvEhIKBG5hbWUYASABKAlSBG5hbWUSOwoFZmllbGQYAiADKAsyJS5nb29nbGUucHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJvdG9SBWZpZWxkEkMKCWV4dGVuc2lvbhgGIAMoCzIlLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90b1IJZXh0ZW5zaW9uEkEKC25lc3RlZF90eXBlGAMgAygLMiAuZ29vZ2xlLnByb3RvYnVmLkRlc2NyaXB0b3JQcm90b1IKbmVzdGVkVHlwZRJBCgllbnVtX3R5cGUYBCADKAsyJC5nb29nbGUucHJvdG9idWYuRW51bURlc2NyaXB0b3JQcm90b1IIZW51bVR5cGUSWAoPZXh0ZW5zaW9uX3JhbmdlGAUgAygLMi8uZ29vZ2xlLnByb3RvYnVmLkRlc2NyaXB0b3JQcm90by5FeHRlbnNpb25SYW5nZVIOZXh0ZW5zaW9uUmFuZ2USRAoKb25lb2ZfZGVjbBgIIAMoCzIlLmdvb2dsZS5wcm90b2J1Zi5PbmVvZkRlc2NyaXB0b3JQcm90b1IJb25lb2ZEZWNsEjkKB29wdGlvbnMYByABKAsyHy5nb29nbGUucHJvdG9idWYuTWVzc2FnZU9wdGlvbnNSB29wdGlvbnMSVQoOcmVzZXJ2ZWRfcmFuZ2UYCSADKAsyLi5nb29nbGUucHJvdG9idWYuRGVzY3JpcHRvclByb3RvLlJlc2VydmVkUmFuZ2VSDXJlc2VydmVkUmFuZ2USIwoNcmVzZXJ2ZWRfbmFtZRgKIAMoCVIMcmVzZXJ2ZWROYW1lGnoKDkV4dGVuc2lvblJhbmdlEhQKBXN0YXJ0GAEgASgFUgVzdGFydBIQCgNlbmQYAiABKAVSA2VuZBJACgdvcHRpb25zGAMgASgLMiYuZ29vZ2xlLnByb3RvYnVmLkV4dGVuc2lvblJhbmdlT3B0aW9uc1IHb3B0aW9ucxo3Cg1SZXNlcnZlZFJhbmdlEhQKBXN0YXJ0GAEgASgFUgVzdGFydBIQCgNlbmQYAiABKAVSA2VuZCJ8ChVFeHRlbnNpb25SYW5nZU9wdGlvbnMSWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiLBBgoURmllbGREZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRIWCgZudW1iZXIYAyABKAVSBm51bWJlchJBCgVsYWJlbBgEIAEoDjIrLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90by5MYWJlbFIFbGFiZWwSPgoEdHlwZRgFIAEoDjIqLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90by5UeXBlUgR0eXBlEhsKCXR5cGVfbmFtZRgGIAEoCVIIdHlwZU5hbWUSGgoIZXh0ZW5kZWUYAiABKAlSCGV4dGVuZGVlEiMKDWRlZmF1bHRfdmFsdWUYByABKAlSDGRlZmF1bHRWYWx1ZRIfCgtvbmVvZl9pbmRleBgJIAEoBVIKb25lb2ZJbmRleBIbCglqc29uX25hbWUYCiABKAlSCGpzb25OYW1lEjcKB29wdGlvbnMYCCABKAsyHS5nb29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zUgdvcHRpb25zEicKD3Byb3RvM19vcHRpb25hbBgRIAEoCFIOcHJvdG8zT3B0aW9uYWwitgIKBFR5cGUSDwoLVFlQRV9ET1VCTEUQARIOCgpUWVBFX0ZMT0FUEAISDgoKVFlQRV9JTlQ2NBADEg8KC1RZUEVfVUlOVDY0EAQSDgoKVFlQRV9JTlQzMhAFEhAKDFRZUEVfRklYRUQ2NBAGEhAKDFRZUEVfRklYRUQzMhAHEg0KCVRZUEVfQk9PTBAIEg8KC1RZUEVfU1RSSU5HEAkSDgoKVFlQRV9HUk9VUBAKEhAKDFRZUEVfTUVTU0FHRRALEg4KClRZUEVfQllURVMQDBIPCgtUWVBFX1VJTlQzMhANEg0KCVRZUEVfRU5VTRAOEhEKDVRZUEVfU0ZJWEVEMzIQDxIRCg1UWVBFX1NGSVhFRDY0EBASDwoLVFlQRV9TSU5UMzIQERIPCgtUWVBFX1NJTlQ2NBASIkMKBUxhYmVsEhIKDkxBQkVMX09QVElPTkFMEAESEgoOTEFCRUxfUkVRVUlSRUQQAhISCg5MQUJFTF9SRVBFQVRFRBADImMKFE9uZW9mRGVzY3JpcHRvclByb3RvEhIKBG5hbWUYASABKAlSBG5hbWUSNwoHb3B0aW9ucxgCIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5PbmVvZk9wdGlvbnNSB29wdGlvbnMi4wIKE0VudW1EZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRI/CgV2YWx1ZRgCIAMoCzIpLmdvb2dsZS5wcm90b2J1Zi5FbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG9SBXZhbHVlEjYKB29wdGlvbnMYAyABKAsyHC5nb29nbGUucHJvdG9idWYuRW51bU9wdGlvbnNSB29wdGlvbnMSXQoOcmVzZXJ2ZWRfcmFuZ2UYBCADKAsyNi5nb29nbGUucHJvdG9idWYuRW51bURlc2NyaXB0b3JQcm90by5FbnVtUmVzZXJ2ZWRSYW5nZVINcmVzZXJ2ZWRSYW5nZRIjCg1yZXNlcnZlZF9uYW1lGAUgAygJUgxyZXNlcnZlZE5hbWUaOwoRRW51bVJlc2VydmVkUmFuZ2USFAoFc3RhcnQYASABKAVSBXN0YXJ0EhAKA2VuZBgCIAEoBVIDZW5kIoMBChhFbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRIWCgZudW1iZXIYAiABKAVSBm51bWJlchI7CgdvcHRpb25zGAMgASgLMiEuZ29vZ2xlLnByb3RvYnVmLkVudW1WYWx1ZU9wdGlvbnNSB29wdGlvbnMipwEKFlNlcnZpY2VEZXNjcmlwdG9yUHJvdG8SEgoEbmFtZRgBIAEoCVIEbmFtZRI+CgZtZXRob2QYAiADKAsyJi5nb29nbGUucHJvdG9idWYuTWV0aG9kRGVzY3JpcHRvclByb3RvUgZtZXRob2QSOQoHb3B0aW9ucxgDIAEoCzIfLmdvb2dsZS5wcm90b2J1Zi5TZXJ2aWNlT3B0aW9uc1IHb3B0aW9ucyKJAgoVTWV0aG9kRGVzY3JpcHRvclByb3RvEhIKBG5hbWUYASABKAlSBG5hbWUSHQoKaW5wdXRfdHlwZRgCIAEoCVIJaW5wdXRUeXBlEh8KC291dHB1dF90eXBlGAMgASgJUgpvdXRwdXRUeXBlEjgKB29wdGlvbnMYBCABKAsyHi5nb29nbGUucHJvdG9idWYuTWV0aG9kT3B0aW9uc1IHb3B0aW9ucxIwChBjbGllbnRfc3RyZWFtaW5nGAUgASgIOgVmYWxzZVIPY2xpZW50U3RyZWFtaW5nEjAKEHNlcnZlcl9zdHJlYW1pbmcYBiABKAg6BWZhbHNlUg9zZXJ2ZXJTdHJlYW1pbmcikQkKC0ZpbGVPcHRpb25zEiEKDGphdmFfcGFja2FnZRgBIAEoCVILamF2YVBhY2thZ2USMAoUamF2YV9vdXRlcl9jbGFzc25hbWUYCCABKAlSEmphdmFPdXRlckNsYXNzbmFtZRI1ChNqYXZhX211bHRpcGxlX2ZpbGVzGAogASgIOgVmYWxzZVIRamF2YU11bHRpcGxlRmlsZXMSRAodamF2YV9nZW5lcmF0ZV9lcXVhbHNfYW5kX2hhc2gYFCABKAhCAhgBUhlqYXZhR2VuZXJhdGVFcXVhbHNBbmRIYXNoEjoKFmphdmFfc3RyaW5nX2NoZWNrX3V0ZjgYGyABKAg6BWZhbHNlUhNqYXZhU3RyaW5nQ2hlY2tVdGY4ElMKDG9wdGltaXplX2ZvchgJIAEoDjIpLmdvb2dsZS5wcm90b2J1Zi5GaWxlT3B0aW9ucy5PcHRpbWl6ZU1vZGU6BVNQRUVEUgtvcHRpbWl6ZUZvchIdCgpnb19wYWNrYWdlGAsgASgJUglnb1BhY2thZ2USNQoTY2NfZ2VuZXJpY19zZXJ2aWNlcxgQIAEoCDoFZmFsc2VSEWNjR2VuZXJpY1NlcnZpY2VzEjkKFWphdmFfZ2VuZXJpY19zZXJ2aWNlcxgRIAEoCDoFZmFsc2VSE2phdmFHZW5lcmljU2VydmljZXMSNQoTcHlfZ2VuZXJpY19zZXJ2aWNlcxgSIAEoCDoFZmFsc2VSEXB5R2VuZXJpY1NlcnZpY2VzEjcKFHBocF9nZW5lcmljX3NlcnZpY2VzGCogASgIOgVmYWxzZVIScGhwR2VuZXJpY1NlcnZpY2VzEiUKCmRlcHJlY2F0ZWQYFyABKAg6BWZhbHNlUgpkZXByZWNhdGVkEi4KEGNjX2VuYWJsZV9hcmVuYXMYHyABKAg6BHRydWVSDmNjRW5hYmxlQXJlbmFzEioKEW9iamNfY2xhc3NfcHJlZml4GCQgASgJUg9vYmpjQ2xhc3NQcmVmaXgSKQoQY3NoYXJwX25hbWVzcGFjZRglIAEoCVIPY3NoYXJwTmFtZXNwYWNlEiEKDHN3aWZ0X3ByZWZpeBgnIAEoCVILc3dpZnRQcmVmaXgSKAoQcGhwX2NsYXNzX3ByZWZpeBgoIAEoCVIOcGhwQ2xhc3NQcmVmaXgSIwoNcGhwX25hbWVzcGFjZRgpIAEoCVIMcGhwTmFtZXNwYWNlEjQKFnBocF9tZXRhZGF0YV9uYW1lc3BhY2UYLCABKAlSFHBocE1ldGFkYXRhTmFtZXNwYWNlEiEKDHJ1YnlfcGFja2FnZRgtIAEoCVILcnVieVBhY2thZ2USWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24iOgoMT3B0aW1pemVNb2RlEgkKBVNQRUVEEAESDQoJQ09ERV9TSVpFEAISEAoMTElURV9SVU5USU1FEAMqCQjoBxCAgICAAkoECCYQJyLRAgoOTWVzc2FnZU9wdGlvbnMSPAoXbWVzc2FnZV9zZXRfd2lyZV9mb3JtYXQYASABKAg6BWZhbHNlUhRtZXNzYWdlU2V0V2lyZUZvcm1hdBJMCh9ub19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZVIcbm9TdGFuZGFyZERlc2NyaXB0b3JBY2Nlc3NvchIlCgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZVIKZGVwcmVjYXRlZBIbCgltYXBfZW50cnkYByABKAhSCG1hcEVudHJ5ElgKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uUhN1bmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgIEAlKBAgJEAoi4gMKDEZpZWxkT3B0aW9ucxJBCgVjdHlwZRgBIAEoDjIjLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlvbnMuQ1R5cGU6BlNUUklOR1IFY3R5cGUSFgoGcGFja2VkGAIgASgIUgZwYWNrZWQSRwoGanN0eXBlGAYgASgOMiQuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5KU1R5cGU6CUpTX05PUk1BTFIGanN0eXBlEhkKBGxhenkYBSABKAg6BWZhbHNlUgRsYXp5EiUKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlUgpkZXByZWNhdGVkEhkKBHdlYWsYCiABKAg6BWZhbHNlUgR3ZWFrElgKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uUhN1bmludGVycHJldGVkT3B0aW9uIi8KBUNUeXBlEgoKBlNUUklORxAAEggKBENPUkQQARIQCgxTVFJJTkdfUElFQ0UQAiI1CgZKU1R5cGUSDQoJSlNfTk9STUFMEAASDQoJSlNfU1RSSU5HEAESDQoJSlNfTlVNQkVSEAIqCQjoBxCAgICAAkoECAQQBSJzCgxPbmVvZk9wdGlvbnMSWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiLAAQoLRW51bU9wdGlvbnMSHwoLYWxsb3dfYWxpYXMYAiABKAhSCmFsbG93QWxpYXMSJQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2VSCmRlcHJlY2F0ZWQSWAoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb25SE3VuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAUQBiKeAQoQRW51bVZhbHVlT3B0aW9ucxIlCgpkZXByZWNhdGVkGAEgASgIOgVmYWxzZVIKZGVwcmVjYXRlZBJYChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvblITdW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICAgIACIpwBCg5TZXJ2aWNlT3B0aW9ucxIlCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZVIKZGVwcmVjYXRlZBJYChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvblITdW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICAgIACIuACCg1NZXRob2RPcHRpb25zEiUKCmRlcHJlY2F0ZWQYISABKAg6BWZhbHNlUgpkZXByZWNhdGVkEnEKEWlkZW1wb3RlbmN5X2xldmVsGCIgASgOMi8uZ29vZ2xlLnByb3RvYnVmLk1ldGhvZE9wdGlvbnMuSWRlbXBvdGVuY3lMZXZlbDoTSURFTVBPVEVOQ1lfVU5LTk9XTlIQaWRlbXBvdGVuY3lMZXZlbBJYChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvblITdW5pbnRlcnByZXRlZE9wdGlvbiJQChBJZGVtcG90ZW5jeUxldmVsEhcKE0lERU1QT1RFTkNZX1VOS05PV04QABITCg9OT19TSURFX0VGRkVDVFMQARIOCgpJREVNUE9URU5UEAIqCQjoBxCAgICAAiKaAwoTVW5pbnRlcnByZXRlZE9wdGlvbhJBCgRuYW1lGAIgAygLMi0uZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24uTmFtZVBhcnRSBG5hbWUSKQoQaWRlbnRpZmllcl92YWx1ZRgDIAEoCVIPaWRlbnRpZmllclZhbHVlEiwKEnBvc2l0aXZlX2ludF92YWx1ZRgEIAEoBFIQcG9zaXRpdmVJbnRWYWx1ZRIsChJuZWdhdGl2ZV9pbnRfdmFsdWUYBSABKANSEG5lZ2F0aXZlSW50VmFsdWUSIQoMZG91YmxlX3ZhbHVlGAYgASgBUgtkb3VibGVWYWx1ZRIhCgxzdHJpbmdfdmFsdWUYByABKAxSC3N0cmluZ1ZhbHVlEicKD2FnZ3JlZ2F0ZV92YWx1ZRgIIAEoCVIOYWdncmVnYXRlVmFsdWUaSgoITmFtZVBhcnQSGwoJbmFtZV9wYXJ0GAEgAigJUghuYW1lUGFydBIhCgxpc19leHRlbnNpb24YAiACKAhSC2lzRXh0ZW5zaW9uIqcCCg5Tb3VyY2VDb2RlSW5mbxJECghsb2NhdGlvbhgBIAMoCzIoLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5mby5Mb2NhdGlvblIIbG9jYXRpb24azgEKCExvY2F0aW9uEhYKBHBhdGgYASADKAVCAhABUgRwYXRoEhYKBHNwYW4YAiADKAVCAhABUgRzcGFuEikKEGxlYWRpbmdfY29tbWVudHMYAyABKAlSD2xlYWRpbmdDb21tZW50cxIrChF0cmFpbGluZ19jb21tZW50cxgEIAEoCVIQdHJhaWxpbmdDb21tZW50cxI6ChlsZWFkaW5nX2RldGFjaGVkX2NvbW1lbnRzGAYgAygJUhdsZWFkaW5nRGV0YWNoZWRDb21tZW50cyLRAQoRR2VuZXJhdGVkQ29kZUluZm8STQoKYW5ub3RhdGlvbhgBIAMoCzItLmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9uUgphbm5vdGF0aW9uGm0KCkFubm90YXRpb24SFgoEcGF0aBgBIAMoBUICEAFSBHBhdGgSHwoLc291cmNlX2ZpbGUYAiABKAlSCnNvdXJjZUZpbGUSFAoFYmVnaW4YAyABKAVSBWJlZ2luEhAKA2VuZBgEIAEoBVIDZW5kQn4KE2NvbS5nb29nbGUucHJvdG9idWZCEERlc2NyaXB0b3JQcm90b3NIAVotZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMvZGVzY3JpcHRvcnBi+AEBogIDR1BCqgIaR29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rpb24=" + @Test fun `file_containing_symbol service`() { val schema = loadSchema() @@ -55,8 +56,8 @@ internal class GrpcurlProto3InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "echo3.Echo", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) // TODO(juliaogirs): We should be comparing _all_ filedescriptors, not jsut the first one. @@ -71,8 +72,8 @@ internal class GrpcurlProto3InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "echo3.HelloRequest", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -86,8 +87,8 @@ internal class GrpcurlProto3InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "echo3.Echo.HelloStream", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -103,8 +104,8 @@ internal class GrpcurlProto3InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_containing_symbol = "google.api.http", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -118,8 +119,8 @@ internal class GrpcurlProto3InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( file_by_filename = "echo3/echo3.proto", - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -132,8 +133,8 @@ internal class GrpcurlProto3InteropTest { val response = SchemaReflector(schema, includeDependencies = false).process( ServerReflectionRequest( all_extension_numbers_of_type = "google.protobuf.MethodOptions", - host = "localhost:0" - ) + host = "localhost:0", + ), ) assertThat(response.error_response).isNull() @@ -141,7 +142,7 @@ internal class GrpcurlProto3InteropTest { ExtensionNumberResponse( base_type_name = "google.protobuf.MethodOptions", extension_number = listOf(72295728), - ) + ), ) } @@ -154,10 +155,10 @@ internal class GrpcurlProto3InteropTest { ServerReflectionRequest( file_containing_extension = ExtensionRequest( containing_type = "google.protobuf.MethodOptions", - extension_number = 72295728 + extension_number = 72295728, ), - host = "localhost:0" - ) + host = "localhost:0", + ), ) val unwantedValueStripper = UnwantedValueStripper(clearJsonName = true) assertThat(unwantedValueStripper.stripOptionsAndDefaults(response.fileDescriptors[0])) @@ -167,7 +168,7 @@ internal class GrpcurlProto3InteropTest { private val ServerReflectionResponse.fileDescriptors get() = file_descriptor_response!!.file_descriptor_proto.map { FileDescriptorProto.parseFrom( - it.toByteArray() + it.toByteArray(), ) } } @@ -183,7 +184,7 @@ private fun loadSchema(): Schema { Location.get("src/test/proto", "google/api/http.proto"), Location.get("src/test/proto", "google/protobuf/any.proto"), ), - protoPath = listOf() + protoPath = listOf(), ) } .loadSchema() diff --git a/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/SchemaReflectorTest.kt b/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/SchemaReflectorTest.kt index e618ca8b49..dfc72dfc64 100644 --- a/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/SchemaReflectorTest.kt +++ b/wire-reflector/src/test/kotlin/com/squareup/wire/reflector/SchemaReflectorTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -34,14 +34,14 @@ internal class SchemaReflectorTest { } val request = ServerReflectionRequest(list_services = "*") assertThat( - SchemaReflector(schema, includeDependencies = true).process(request) + SchemaReflector(schema, includeDependencies = true).process(request), ).isEqualTo( ServerReflectionResponse( original_request = request, list_services_response = ListServiceResponse( - service = listOf(ServiceResponse(name = "routeguide.RouteGuide")) - ) - ) + service = listOf(ServiceResponse(name = "routeguide.RouteGuide")), + ), + ), ) } @@ -54,9 +54,9 @@ internal class SchemaReflectorTest { assertThat( SchemaReflector(schema, includeDependencies = true).process( ServerReflectionRequest( - file_by_filename = "src/test/proto/RouteGuideProto.proto" - ) - ) + file_by_filename = "src/test/proto/RouteGuideProto.proto", + ), + ), ).extracting { it.file_descriptor_response }.isNotNull } @@ -69,9 +69,9 @@ internal class SchemaReflectorTest { assertThat( SchemaReflector(schema, includeDependencies = true).process( ServerReflectionRequest( - file_containing_symbol = "routeguide.RouteGuide" - ) - ) + file_containing_symbol = "routeguide.RouteGuide", + ), + ), ).extracting { it.file_descriptor_response }.isNotNull } @@ -85,13 +85,15 @@ internal class SchemaReflectorTest { |message A { | optional B b = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "b.proto".toPath(), """ |message B { } - |""".trimMargin() + | + """.trimMargin(), ) } @@ -100,7 +102,7 @@ internal class SchemaReflectorTest { assertThat( response.file_descriptor_response!!.file_descriptor_proto.map { DescriptorProtos.FileDescriptorProto.parseFrom(it.toByteArray()) - }.map { it.name } + }.map { it.name }, ).containsExactly("a.proto", "b.proto") val responseB = SchemaReflector(schema, includeDependencies = true) @@ -108,7 +110,7 @@ internal class SchemaReflectorTest { assertThat( responseB.file_descriptor_response!!.file_descriptor_proto.map { DescriptorProtos.FileDescriptorProto.parseFrom(it.toByteArray()) - }.map { it.name } + }.map { it.name }, ).containsExactly("b.proto") } @@ -124,19 +126,22 @@ internal class SchemaReflectorTest { | optional B b = 1; | optional C c = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "b.proto".toPath(), """ |message B { } - |""".trimMargin() + | + """.trimMargin(), ) add( "c.proto".toPath(), """ |message C { } - |""".trimMargin() + | + """.trimMargin(), ) } @@ -145,7 +150,7 @@ internal class SchemaReflectorTest { assertThat( response.file_descriptor_response!!.file_descriptor_proto.map { DescriptorProtos.FileDescriptorProto.parseFrom(it.toByteArray()) - }.map { it.name } + }.map { it.name }, ).containsExactly("a.proto", "b.proto", "c.proto") } @@ -161,7 +166,8 @@ internal class SchemaReflectorTest { | optional B b = 1; | optional C c = 2; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "b.proto".toPath(), @@ -170,13 +176,15 @@ internal class SchemaReflectorTest { |message B { | optional C c = 1; | } - |""".trimMargin() + | + """.trimMargin(), ) add( "c.proto".toPath(), """ |message C { } - |""".trimMargin() + | + """.trimMargin(), ) } @@ -185,7 +193,7 @@ internal class SchemaReflectorTest { assertThat( response.file_descriptor_response!!.file_descriptor_proto.map { DescriptorProtos.FileDescriptorProto.parseFrom(it.toByteArray()) - }.map { it.name } + }.map { it.name }, ).containsExactly("a.proto", "b.proto", "c.proto") } @@ -199,13 +207,15 @@ internal class SchemaReflectorTest { |message A { | optional B b = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "b.proto".toPath(), """ |import public "b-new.proto"; - |""".trimMargin() + | + """.trimMargin(), ) add( "b-new.proto".toPath(), @@ -214,13 +224,15 @@ internal class SchemaReflectorTest { |message B { | optional C c = 1; | } - |""".trimMargin() + | + """.trimMargin(), ) add( "c.proto".toPath(), """ |message C { } - |""".trimMargin() + | + """.trimMargin(), ) } @@ -229,7 +241,7 @@ internal class SchemaReflectorTest { assertThat( response.file_descriptor_response!!.file_descriptor_proto.map { DescriptorProtos.FileDescriptorProto.parseFrom(it.toByteArray()) - }.map { it.name } + }.map { it.name }, ).containsExactly("a.proto", "b.proto", "b-new.proto", "c.proto") } } From 898acc229b8f768996eaf08b1ddff47739e8160c Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Fri, 7 Jul 2023 20:58:14 +0200 Subject: [PATCH 7/7] =?UTF-8?q?Spotless:=20the=20rest=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - build.gradle.kts | 57 +- gradle/license-header.txt | 15 + .../wire/android/app/java/MainActivity.java | 7 +- .../wire/android/app/kotlin/MainActivity.kt | 4 +- .../wire/android/app/variants/MainActivity.kt | 15 + .../android/app/variants/CommonUnitTest.kt | 15 + .../android/app/variants/DebugUnitTest.kt | 15 + .../android/app/variants/ReleaseUnitTest.kt | 15 + .../wire/android/lib/java/SomeObject.java | 4 +- .../wire/android/lib/kotlin/SomeObject.kt | 4 +- samples/js/src/main/kotlin/Main.kt | 15 + samples/native/src/nativeMain/kotlin/Main.kt | 15 + .../java/com/squareup/dinosaurs/Sample.java | 31 +- .../wire/sample/ServiceGenerator.java | 8 +- .../wire/sample/ServiceGeneratorTest.kt | 19 +- .../wire/whiteboard/GrpcClientProvider.kt | 20 +- .../squareup/wire/whiteboard/MainActivity.kt | 8 +- .../wire/whiteboard/ui/MainContentView.kt | 6 +- .../wire/whiteboard/ui/WhiteboardView.kt | 19 +- .../wire/whiteboard/WhiteboardCompatImpl.kt | 14 +- .../wire/whiteboard/WhiteboardImpl.kt | 12 +- .../wire/whiteboard/WhiteboardServer.kt | 4 +- .../java/com/squareup/wire/whiteboard/Grpc.kt | 4 +- .../wire/whiteboard/MiskGrpcServer.kt | 6 +- .../wire/whiteboard/WhiteboardConfig.kt | 6 +- .../wire/whiteboard/WhiteboardGrpcAction.kt | 14 +- .../wire/whiteboard/WhiteboardGrpcModule.kt | 4 +- .../wire/benchmarks/AllTypesBenchmark.kt | 6 +- .../benchmarks/SimpleMessageBenchmark.java | 32 +- .../squareup/wire/benchmarks/SampleData.kt | 32 +- .../src/main/java/MyListener.java | 49 +- .../com/squareup/wire/gradle/InputLocation.kt | 18 +- .../kotlin/com/squareup/wire/gradle/Move.kt | 4 +- .../com/squareup/wire/gradle/WireExtension.kt | 4 +- .../com/squareup/wire/gradle/WireInput.kt | 18 +- .../com/squareup/wire/gradle/WireOutput.kt | 7 +- .../com/squareup/wire/gradle/WirePlugin.kt | 23 +- .../com/squareup/wire/gradle/WireTask.kt | 6 +- .../wire/gradle/internal/GradleWireLogger.kt | 12 +- .../squareup/wire/gradle/internal/projects.kt | 15 + .../wire/gradle/kotlin/SourceRoots.kt | 25 +- .../squareup/wire/gradle/WirePluginTest.kt | 98 +- .../java/com/squareup/dinosaurs/Sample.java | 30 +- .../java/com/squareup/dinosaurs/Sample.java | 30 +- .../java/com/squareup/dinosaurs/Sample.kt | 17 +- .../java/com/squareup/dinosaurs/Sample.kt | 19 +- .../java/com/squareup/dinosaurs/Sample.kt | 19 +- .../java/com/squareup/dinosaurs/Sample.kt | 19 +- .../kotlin/com/squareup/wire/GrpcCall.kt | 4 +- .../kotlin/com/squareup/wire/GrpcClient.kt | 4 +- .../kotlin/com/squareup/wire/GrpcException.kt | 5 +- .../kotlin/com/squareup/wire/GrpcHeaders.kt | 4 +- .../kotlin/com/squareup/wire/GrpcHttpUrl.kt | 4 +- .../kotlin/com/squareup/wire/GrpcMethod.kt | 6 +- .../kotlin/com/squareup/wire/GrpcRequest.kt | 5 +- .../com/squareup/wire/GrpcRequestBody.kt | 4 +- .../kotlin/com/squareup/wire/GrpcResponse.kt | 9 +- .../com/squareup/wire/GrpcResponseBody.kt | 5 +- .../kotlin/com/squareup/wire/GrpcStatus.kt | 23 +- .../com/squareup/wire/GrpcStreamingCall.kt | 8 +- .../com/squareup/wire/WireGrpcExperimental.kt | 5 +- .../com/squareup/wire/internal/GrpcDecoder.kt | 4 +- .../com/squareup/wire/internal/GrpcEncoder.kt | 4 +- .../squareup/wire/internal/GrpcMessageSink.kt | 6 +- .../wire/internal/GrpcMessageSource.kt | 8 +- .../squareup/wire/internal/platform.common.kt | 4 +- .../kotlin/com/squareup/wire/internal/util.kt | 4 +- .../kotlin/com/squareup/wire/GrpcClient.kt | 4 +- .../kotlin/com/squareup/wire/GrpcHeaders.kt | 4 +- .../kotlin/com/squareup/wire/GrpcHttpUrl.kt | 4 +- .../kotlin/com/squareup/wire/GrpcRequest.kt | 8 +- .../com/squareup/wire/GrpcRequestBody.kt | 4 +- .../kotlin/com/squareup/wire/GrpcResponse.kt | 6 +- .../com/squareup/wire/GrpcResponseBody.kt | 4 +- .../com/squareup/wire/internal/platform.kt | 4 +- .../kotlin/com/squareup/wire/GrpcCalls.kt | 12 +- .../kotlin/com/squareup/wire/GrpcClient.kt | 14 +- .../kotlin/com/squareup/wire/GrpcHeaders.kt | 4 +- .../kotlin/com/squareup/wire/GrpcHttpUrl.kt | 4 +- .../kotlin/com/squareup/wire/GrpcRequest.kt | 4 +- .../com/squareup/wire/GrpcRequestBody.kt | 4 +- .../kotlin/com/squareup/wire/GrpcResponse.kt | 4 +- .../com/squareup/wire/GrpcResponseBody.kt | 4 +- .../wire/internal/BlockingMessageSource.kt | 8 +- .../squareup/wire/internal/LateInitTimeout.kt | 6 +- .../wire/internal/PipeDuplexRequestBody.kt | 6 +- .../squareup/wire/internal/RealGrpcCall.kt | 14 +- .../wire/internal/RealGrpcStreamingCall.kt | 24 +- .../kotlin/com/squareup/wire/internal/grpc.kt | 22 +- .../com/squareup/wire/internal/platform.kt | 7 +- .../kotlin/com/squareup/wire/GrpcClient.kt | 4 +- .../kotlin/com/squareup/wire/GrpcHeaders.kt | 4 +- .../kotlin/com/squareup/wire/GrpcHttpUrl.kt | 4 +- .../kotlin/com/squareup/wire/GrpcRequest.kt | 8 +- .../com/squareup/wire/GrpcRequestBody.kt | 4 +- .../kotlin/com/squareup/wire/GrpcResponse.kt | 6 +- .../com/squareup/wire/GrpcResponseBody.kt | 4 +- .../com/squareup/wire/internal/platform.kt | 4 +- .../wire/mockwebserver/GrpcDispatcher.kt | 16 +- .../grpcserver/BindableAdapterGenerator.kt | 135 +- .../grpcserver/BlockingStubGenerator.kt | 37 +- .../kotlin/grpcserver/ClassNameGenerator.kt | 17 +- .../grpcserver/FileDescriptorGenerator.kt | 23 +- .../kotlin/grpcserver/ImplBaseGenerator.kt | 46 +- .../kotlin/grpcserver/KotlinGrpcGenerator.kt | 6 +- .../grpcserver/MethodDescriptorGenerator.kt | 18 +- .../grpcserver/ServiceDescriptorGenerator.kt | 22 +- .../wire/kotlin/grpcserver/StubGenerator.kt | 62 +- .../kotlin/grpcserver/BindableAdapterTest.kt | 92 +- .../grpcserver/FileDescriptorGeneratorTest.kt | 87 +- .../wire/kotlin/grpcserver/GoldenTestUtils.kt | 2 +- .../kotlin/grpcserver/GrpcGeneratorHelpers.kt | 21 +- .../wire/kotlin/grpcserver/ImplBaseTest.kt | 8 +- .../grpcserver/KotlinGrpcGeneratorTest.kt | 22 +- .../kotlin/grpcserver/MethodDescriptorTest.kt | 6 +- .../grpcserver/ServiceDescriptorTest.kt | 4 +- .../wire/kotlin/grpcserver/StubTest.kt | 67 +- .../wire/kotlin/grpcserver/FlowAdapter.kt | 10 +- .../kotlin/grpcserver/MessageSinkAdapter.kt | 2 +- .../kotlin/grpcserver/MessageSourceAdapter.kt | 2 +- .../kotlin/grpcserver/WireBindableService.kt | 15 + .../kotlin/grpcserver/WireMethodMarshaller.kt | 15 + wire-grpc-tests/build.gradle.kts | 10 + .../java/com/squareup/wire/GrpcCallsTest.kt | 14 +- .../java/com/squareup/wire/GrpcClientTest.kt | 95 +- .../squareup/wire/GrpcOnMockWebServerTest.kt | 17 +- .../squareup/wire/GrpcStreamingCallsTest.kt | 4 +- .../squareup/wire/MockRouteGuideService.kt | 48 +- wire-gson-support/build.gradle.kts | 16 + .../squareup/wire/AnyMessageTypeAdapter.kt | 6 +- .../java/com/squareup/wire/EnumTypeAdapter.kt | 4 +- .../com/squareup/wire/GsonJsonIntegration.kt | 14 +- .../com/squareup/wire/MessageTypeAdapter.kt | 10 +- .../squareup/wire/WireTypeAdapterFactory.kt | 6 +- .../com/squareup/wire/GsonNoAdapterTest.java | 149 +- .../test/java/com/squareup/wire/GsonTest.java | 210 +-- .../com/squareup/wire/java/JavaGenerator.java | 981 +++++++----- .../squareup/wire/java/JavaSchemaHandler.kt | 24 +- .../squareup/wire/java/JavaGeneratorHelper.kt | 7 +- .../squareup/wire/java/JavaGeneratorTest.java | 1402 +++++++++-------- .../wire/java/JavaWithProfilesGenerator.kt | 8 +- .../squareup/wire/kotlin/FieldExtensions.kt | 8 +- .../squareup/wire/kotlin/KotlinGenerator.kt | 254 +-- .../wire/kotlin/KotlinSchemaHandler.kt | 19 +- .../com/squareup/wire/kotlin/RpcCallStyle.kt | 4 +- .../java/com/squareup/wire/kotlin/RpcRole.kt | 3 +- .../wire/kotlin/KotlinGeneratorTest.kt | 334 ++-- .../kotlin/KotlinWithProfilesGenerator.kt | 4 +- wire-moshi-adapter/build.gradle.kts | 16 + .../squareup/wire/AnyMessageJsonAdapter.kt | 6 +- .../java/com/squareup/wire/EnumJsonAdapter.kt | 4 +- .../com/squareup/wire/MessageJsonAdapter.kt | 6 +- .../com/squareup/wire/MoshiJsonIntegration.kt | 18 +- .../com/squareup/wire/RedactingJsonAdapter.kt | 4 +- .../squareup/wire/WireJsonAdapterFactory.kt | 10 +- .../java/com/squareup/wire/MoshiTest.java | 114 +- .../squareup/wire/DurationRoundTripTest.kt | 4 +- .../com/squareup/wire/EmptyRoundTripTest.kt | 8 +- .../com/squareup/wire/InstantRoundTripTest.kt | 4 +- .../java/com/squareup/wire/InteropChecker.kt | 4 +- .../java/com/squareup/wire/InteropTest.kt | 29 +- .../Proto2WireProtocCompatibilityTests.kt | 32 +- .../Proto3WireProtocCompatibilityTests.kt | 128 +- .../com/squareup/wire/ProtocStructHelper.kt | 4 +- .../com/squareup/wire/ProtocWrappersHelper.kt | 4 +- .../squareup/wire/SchemaEncoderInteropTest.kt | 20 +- .../test/java/com/squareup/wire/StructTest.kt | 32 +- .../squareup/wire/UnwantedValueStripper.kt | 6 +- .../kotlin/com/squareup/wire/SchemaBuilder.kt | 4 +- .../com/squareup/wire/WireTestLogger.kt | 4 +- .../com/squareup/wire/SchemaBuilderTest.kt | 67 - .../recipes/ErrorReportingSchemaHandler.kt | 45 - .../ErrorReportingSchemaHandlerTest.kt | 71 - .../squareup/wire/recipes/LogToFileHandler.kt | 54 - .../wire/recipes/LogToFileHandlerTest.kt | 75 - .../wire/recipes/LogToWireLoggerHandler.kt | 46 - .../recipes/LogToWireLoggerHandlerTest.kt | 73 - .../com/squareup/wire/SchemaBuilderTest.kt | 14 +- .../recipes/ErrorReportingSchemaHandler.kt | 4 +- .../ErrorReportingSchemaHandlerTest.kt | 10 +- .../squareup/wire/recipes/LogToFileHandler.kt | 4 +- .../wire/recipes/LogToFileHandlerTest.kt | 13 +- .../wire/recipes/LogToWireLoggerHandler.kt | 12 +- .../recipes/LogToWireLoggerHandlerTest.kt | 8 +- .../squareup/wire/recipes/MarkdownHandler.kt | 12 +- .../wire/recipes/MarkdownHandlerTest.kt | 18 +- .../internal/parser/MessageElementTest.kt | 2 +- .../com/squareup/wire/swift/SwiftGenerator.kt | 207 +-- .../main/java/com/squareup/wire/json/Json.kt | 5 +- .../com/squareup/wire/schema/SchemaHelpers.kt | 8 +- .../wire/testing/UnwantedValueStripper.kt | 6 +- .../java/com/squareup/wire/testing/files.kt | 14 +- 193 files changed, 3706 insertions(+), 3078 deletions(-) create mode 100644 gradle/license-header.txt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt delete mode 100644 wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt diff --git a/.gitignore b/.gitignore index acb22fef47..a0f2b0e98b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ out/ .gradle build generated -gradle gradlew gradlew.bat diff --git a/build.gradle.kts b/build.gradle.kts index 0a90225df6..4ad490b857 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ import com.diffplug.gradle.spotless.SpotlessExtension +import com.diffplug.spotless.LineEnding import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.SonatypeHost +import kotlinx.validation.ApiValidationExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED @@ -10,7 +12,6 @@ import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import kotlinx.validation.ApiValidationExtension buildscript { dependencies { @@ -56,36 +57,30 @@ allprojects { } subprojects { - apply(plugin = "com.diffplug.spotless") - configure { - val licenseHeaderFile = rootProject.file("gradle/license-header.txt") - kotlin { - target("**/*.kt") - ktlint(libs.versions.ktlint.get()).editorConfigOverride( - mapOf("ktlint_standard_filename" to "disabled"), - ) - trimTrailingWhitespace() - endWithNewline() - toggleOffOn() - // We cannot use it because the licensing job happens before. The header will be replaced and - // spotless will throw. We have to manually exclude stuff for now. - // See https://github.com/diffplug/spotless/discussions/1738 - toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""") - - licenseHeaderFile(licenseHeaderFile) - } - java { - target("**/*.java") - googleJavaFormat(libs.googleJavaFormat.get().version) - trimTrailingWhitespace() - endWithNewline() - toggleOffOn() - // We cannot use it because the licensing job happens before. The header will be replaced and - // spotless will throw. We have to manually exclude stuff for now. - // See https://github.com/diffplug/spotless/discussions/1738 - // toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""") - - licenseHeaderFile(licenseHeaderFile) + if (name != "wire-golden-files") { + apply(plugin = "com.diffplug.spotless") + configure { + val licenseHeaderFile = rootProject.file("gradle/license-header.txt") + kotlin { + target("**/*.kt") + ktlint(libs.versions.ktlint.get()).editorConfigOverride( + mapOf("ktlint_standard_filename" to "disabled"), + ) + trimTrailingWhitespace() + endWithNewline() + toggleOffOn() + lineEndings = LineEnding.UNIX + licenseHeaderFile(licenseHeaderFile) + } + java { + target("**/*.java") + googleJavaFormat(libs.googleJavaFormat.get().version) + trimTrailingWhitespace() + endWithNewline() + toggleOffOn() + lineEndings = LineEnding.UNIX + licenseHeaderFile(licenseHeaderFile) + } } } diff --git a/gradle/license-header.txt b/gradle/license-header.txt new file mode 100644 index 0000000000..b2a05698ab --- /dev/null +++ b/gradle/license-header.txt @@ -0,0 +1,15 @@ +/* + * Copyright (C) $YEAR Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ diff --git a/samples/android-app-java-sample/src/main/java/com/squareup/wire/android/app/java/MainActivity.java b/samples/android-app-java-sample/src/main/java/com/squareup/wire/android/app/java/MainActivity.java index 080659dfee..4d1f7d409e 100644 --- a/samples/android-app-java-sample/src/main/java/com/squareup/wire/android/app/java/MainActivity.java +++ b/samples/android-app-java-sample/src/main/java/com/squareup/wire/android/app/java/MainActivity.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,10 +15,9 @@ */ package com.squareup.wire.android.app.java; +import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; - public class MainActivity extends AppCompatActivity { diff --git a/samples/android-app-kotlin-sample/src/main/java/com/squareup/wire/android/app/kotlin/MainActivity.kt b/samples/android-app-kotlin-sample/src/main/java/com/squareup/wire/android/app/kotlin/MainActivity.kt index 41b093f4c8..2910c9b279 100644 --- a/samples/android-app-kotlin-sample/src/main/java/com/squareup/wire/android/app/kotlin/MainActivity.kt +++ b/samples/android-app-kotlin-sample/src/main/java/com/squareup/wire/android/app/kotlin/MainActivity.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/samples/android-app-variants-sample/src/main/java/com/squareup/wire/android/app/variants/MainActivity.kt b/samples/android-app-variants-sample/src/main/java/com/squareup/wire/android/app/variants/MainActivity.kt index 5c7e009e68..1b232623fa 100644 --- a/samples/android-app-variants-sample/src/main/java/com/squareup/wire/android/app/variants/MainActivity.kt +++ b/samples/android-app-variants-sample/src/main/java/com/squareup/wire/android/app/variants/MainActivity.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.android.app.variants import android.os.Bundle diff --git a/samples/android-app-variants-sample/src/test/java/com/squareup/wire/android/app/variants/CommonUnitTest.kt b/samples/android-app-variants-sample/src/test/java/com/squareup/wire/android/app/variants/CommonUnitTest.kt index 955da2b043..deeb5d8321 100644 --- a/samples/android-app-variants-sample/src/test/java/com/squareup/wire/android/app/variants/CommonUnitTest.kt +++ b/samples/android-app-variants-sample/src/test/java/com/squareup/wire/android/app/variants/CommonUnitTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.android.app.variants import org.junit.Test diff --git a/samples/android-app-variants-sample/src/testDebug/java/com/squareup/wire/android/app/variants/DebugUnitTest.kt b/samples/android-app-variants-sample/src/testDebug/java/com/squareup/wire/android/app/variants/DebugUnitTest.kt index d9af3e72f3..21909db589 100644 --- a/samples/android-app-variants-sample/src/testDebug/java/com/squareup/wire/android/app/variants/DebugUnitTest.kt +++ b/samples/android-app-variants-sample/src/testDebug/java/com/squareup/wire/android/app/variants/DebugUnitTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.android.app.variants import org.junit.Assert.fail diff --git a/samples/android-app-variants-sample/src/testRelease/java/com/squareup/wire/android/app/variants/ReleaseUnitTest.kt b/samples/android-app-variants-sample/src/testRelease/java/com/squareup/wire/android/app/variants/ReleaseUnitTest.kt index 6315a22664..ba6ebd4b07 100644 --- a/samples/android-app-variants-sample/src/testRelease/java/com/squareup/wire/android/app/variants/ReleaseUnitTest.kt +++ b/samples/android-app-variants-sample/src/testRelease/java/com/squareup/wire/android/app/variants/ReleaseUnitTest.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.android.app.variants import org.junit.Assert.fail diff --git a/samples/android-lib-java-sample/src/main/java/com/squareup/wire/android/lib/java/SomeObject.java b/samples/android-lib-java-sample/src/main/java/com/squareup/wire/android/lib/java/SomeObject.java index 1ab8d3a322..1bc7f605e1 100644 --- a/samples/android-lib-java-sample/src/main/java/com/squareup/wire/android/lib/java/SomeObject.java +++ b/samples/android-lib-java-sample/src/main/java/com/squareup/wire/android/lib/java/SomeObject.java @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/samples/android-lib-kotlin-sample/src/main/java/com/squareup/wire/android/lib/kotlin/SomeObject.kt b/samples/android-lib-kotlin-sample/src/main/java/com/squareup/wire/android/lib/kotlin/SomeObject.kt index 3e31e2e12e..dd2c1c195c 100644 --- a/samples/android-lib-kotlin-sample/src/main/java/com/squareup/wire/android/lib/kotlin/SomeObject.kt +++ b/samples/android-lib-kotlin-sample/src/main/java/com/squareup/wire/android/lib/kotlin/SomeObject.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/samples/js/src/main/kotlin/Main.kt b/samples/js/src/main/kotlin/Main.kt index 30714c04f0..a56e922d9a 100644 --- a/samples/js/src/main/kotlin/Main.kt +++ b/samples/js/src/main/kotlin/Main.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import human.Person fun main() { diff --git a/samples/native/src/nativeMain/kotlin/Main.kt b/samples/native/src/nativeMain/kotlin/Main.kt index 30714c04f0..a56e922d9a 100644 --- a/samples/native/src/nativeMain/kotlin/Main.kt +++ b/samples/native/src/nativeMain/kotlin/Main.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import human.Person fun main() { diff --git a/samples/simple-sample/src/main/java/com/squareup/dinosaurs/Sample.java b/samples/simple-sample/src/main/java/com/squareup/dinosaurs/Sample.java index eebeb3217a..496b07cc67 100644 --- a/samples/simple-sample/src/main/java/com/squareup/dinosaurs/Sample.java +++ b/samples/simple-sample/src/main/java/com/squareup/dinosaurs/Sample.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 Square Inc. + * Copyright (C) 2015 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,24 +23,27 @@ public final class Sample { public void run() throws IOException { // Create an immutable value object with the Builder API. - Dinosaur stegosaurus = new Dinosaur.Builder() - .name("Stegosaurus") - .period(Period.JURASSIC) - .length_meters(9.0) - .mass_kilograms(5_000.0) - .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) - .build(); + Dinosaur stegosaurus = + new Dinosaur.Builder() + .name("Stegosaurus") + .period(Period.JURASSIC) + .length_meters(9.0) + .mass_kilograms(5_000.0) + .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) + .build(); // Encode that value to bytes, and print that as base64. byte[] stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus); System.out.println(ByteString.of(stegosaurusEncoded).base64()); // Decode base64 bytes, and decode those bytes as a dinosaur. - ByteString tyrannosaurusEncoded = ByteString.decodeBase64("Cg1UeXJhbm5vc2F1cnVzEmhodHRwOi8vdmln" - + "bmV0dGUxLndpa2lhLm5vY29va2llLm5ldC9qdXJhc3NpY3BhcmsvaW1hZ2VzLzYvNmEvTGVnbzUuanBnL3Jldmlz" - + "aW9uL2xhdGVzdD9jYj0yMDE1MDMxOTAxMTIyMRJtaHR0cDovL3ZpZ25ldHRlMy53aWtpYS5ub2Nvb2tpZS5uZXQv" - + "anVyYXNzaWNwYXJrL2ltYWdlcy81LzUwL1JleHlfcHJlcGFyaW5nX2Zvcl9iYXR0bGVfd2l0aF9JbmRvbWludXNf" - + "cmV4LmpwZxmamZmZmZkoQCEAAAAAAJC6QCgB"); + ByteString tyrannosaurusEncoded = + ByteString.decodeBase64( + "Cg1UeXJhbm5vc2F1cnVzEmhodHRwOi8vdmln" + + "bmV0dGUxLndpa2lhLm5vY29va2llLm5ldC9qdXJhc3NpY3BhcmsvaW1hZ2VzLzYvNmEvTGVnbzUuanBnL3Jldmlz" + + "aW9uL2xhdGVzdD9jYj0yMDE1MDMxOTAxMTIyMRJtaHR0cDovL3ZpZ25ldHRlMy53aWtpYS5ub2Nvb2tpZS5uZXQv" + + "anVyYXNzaWNwYXJrL2ltYWdlcy81LzUwL1JleHlfcHJlcGFyaW5nX2Zvcl9iYXR0bGVfd2l0aF9JbmRvbWludXNf" + + "cmV4LmpwZxmamZmZmZkoQCEAAAAAAJC6QCgB"); Dinosaur tyrannosaurus = Dinosaur.ADAPTER.decode(tyrannosaurusEncoded.toByteArray()); // Print both of our dinosaurs. diff --git a/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java b/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java index 3511e8fd9c..7b0fa5d144 100644 --- a/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java +++ b/samples/wire-codegen-sample/src/main/java/com/squareup/wire/sample/ServiceGenerator.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,9 @@ */ package com.squareup.wire.sample; +import static javax.lang.model.element.Modifier.ABSTRACT; +import static javax.lang.model.element.Modifier.PUBLIC; + import com.squareup.javapoet.ClassName; import com.squareup.javapoet.MethodSpec; import com.squareup.javapoet.TypeName; @@ -24,9 +27,6 @@ import com.squareup.wire.schema.Rpc; import com.squareup.wire.schema.Service; -import static javax.lang.model.element.Modifier.ABSTRACT; -import static javax.lang.model.element.Modifier.PUBLIC; - final class ServiceGenerator { final JavaGenerator javaGenerator; diff --git a/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt b/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt index e431759d4a..f8e43ceb80 100644 --- a/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt +++ b/samples/wire-codegen-sample/src/test/java/com/squareup/wire/sample/ServiceGeneratorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,21 +21,22 @@ import com.squareup.wire.java.JavaGenerator import com.squareup.wire.schema.Location import com.squareup.wire.schema.Schema import com.squareup.wire.schema.SchemaLoader +import java.io.File +import java.io.IOException +import java.nio.file.FileSystems import okio.buffer import okio.sink import org.assertj.core.api.Assertions.assertThat import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -import java.io.File -import java.io.IOException -import java.nio.file.FileSystems class ServiceGeneratorTest { @get:Rule var temporaryFolder = TemporaryFolder() - @Test @Throws(IOException::class) + @Test + @Throws(IOException::class) fun service() { val schema = schema( mapOf( @@ -62,8 +63,9 @@ class ServiceGeneratorTest { | rpc FirstRpc (SampleRequest) returns (SampleResponse); | rpc OtherOne (SampleRequest) returns (SampleResponse); |} - |""".trimMargin() - ) + | + """.trimMargin(), + ), ) val service = schema.getService("squareup.wire.sample.SampleApi") val javaGenerator = JavaGenerator.get(schema) @@ -85,7 +87,8 @@ class ServiceGeneratorTest { | | SampleResponse OtherOne(SampleRequest request); |} - |""".trimMargin() + | + """.trimMargin(), ) } diff --git a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/GrpcClientProvider.kt b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/GrpcClientProvider.kt index eba97993a2..0135e974a8 100644 --- a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/GrpcClientProvider.kt +++ b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/GrpcClientProvider.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,6 @@ package com.squareup.wire.whiteboard import com.squareup.wire.GrpcClient -import okhttp3.OkHttpClient -import okhttp3.Protocol.HTTP_1_1 -import okhttp3.Protocol.HTTP_2 -import okio.Buffer import java.io.IOException import java.io.InputStream import java.security.GeneralSecurityException @@ -32,6 +28,10 @@ import javax.net.ssl.SSLContext import javax.net.ssl.SSLSocketFactory import javax.net.ssl.TrustManagerFactory import javax.net.ssl.X509TrustManager +import okhttp3.OkHttpClient +import okhttp3.Protocol.HTTP_1_1 +import okhttp3.Protocol.HTTP_2 +import okio.Buffer object GrpcClientProvider { private val okHttpClient = OkHttpClient.Builder() @@ -55,7 +55,7 @@ object GrpcClientProvider { val sslSocketFactory: SSLSocketFactory try { trustManager = trustManagerForCertificates( - trustedCertificatesInputStream() + trustedCertificatesInputStream(), ) val sslContext = SSLContext.getInstance("TLS") sslContext.init(null, arrayOf(trustManager), null) @@ -109,17 +109,17 @@ object GrpcClientProvider { // Use it to build an X509 trust manager. val keyManagerFactory = KeyManagerFactory.getInstance( - KeyManagerFactory.getDefaultAlgorithm() + KeyManagerFactory.getDefaultAlgorithm(), ) keyManagerFactory.init(keyStore, password) val trustManagerFactory = TrustManagerFactory.getInstance( - TrustManagerFactory.getDefaultAlgorithm() + TrustManagerFactory.getDefaultAlgorithm(), ) trustManagerFactory.init(keyStore) val trustManagers = trustManagerFactory.trustManagers if (trustManagers.size != 1 || trustManagers[0] !is X509TrustManager) { throw IllegalStateException( - "Unexpected default trust managers:" + Arrays.toString(trustManagers) + "Unexpected default trust managers:" + Arrays.toString(trustManagers), ) } return trustManagers[0] as X509TrustManager diff --git a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/MainActivity.kt b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/MainActivity.kt index d6b425f468..0c2515ff3c 100644 --- a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/MainActivity.kt +++ b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/MainActivity.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,6 +24,7 @@ import com.squareup.wire.whiteboard.WhiteboardUpdate.InitialiseBoard import com.squareup.wire.whiteboard.WhiteboardUpdate.UpdatePoints import com.squareup.wire.whiteboard.ui.MainContentView import com.squareup.wire.whiteboard.ui.WhiteboardView +import java.io.IOException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -31,7 +32,6 @@ import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import java.io.IOException class MainActivity : ComponentActivity(), OnBoardEventListener { private lateinit var sendCommandChannel: SendChannel @@ -60,7 +60,7 @@ class MainActivity : ComponentActivity(), OnBoardEventListener { withContext(Dispatchers.Main) { when { update.initialise_board != null -> initialiseBoard( - update.initialise_board as InitialiseBoard + update.initialise_board as InitialiseBoard, ) update.update_points != null -> updatePoints(update.update_points as UpdatePoints) diff --git a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/MainContentView.kt b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/MainContentView.kt index 8521b444dd..1fec2e30eb 100644 --- a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/MainContentView.kt +++ b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/MainContentView.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -50,7 +50,7 @@ class MainContentView(context: Context) : ContourLayout(context) { ) button.layoutBy( x = centerHorizontallyTo { parent.centerX() }.widthOf(AtMost) { parent.width() - 48.dip }, - y = bottomTo { parent.bottom() - 24.dip } + y = bottomTo { parent.bottom() - 24.dip }, ) } } diff --git a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/WhiteboardView.kt b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/WhiteboardView.kt index 70a59f319a..8a96664711 100644 --- a/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/WhiteboardView.kt +++ b/samples/wire-grpc-sample/client/src/main/java/com/squareup/wire/whiteboard/ui/WhiteboardView.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -55,7 +55,7 @@ class WhiteboardView( realY - realHeight / 2f, realX + realWidth / 2f - 1, realY + realHeight / 2f - 1, - Paint().apply { color = point.color } + Paint().apply { color = point.color }, ) } } @@ -64,7 +64,8 @@ class WhiteboardView( override fun onTouchEvent(event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN, - MotionEvent.ACTION_MOVE -> { + MotionEvent.ACTION_MOVE, + -> { val (abstractX, abstractY) = convertToAbstract(event.x, event.y) onBoardEventListener!!.onPoint(Point(abstractX, abstractY, color)) } @@ -76,18 +77,18 @@ class WhiteboardView( private fun convertToReal( x: Int, - y: Int + y: Int, ) = Pair( x * width / abstractWidth, - y * height / abstractHeight + y * height / abstractHeight, ) private fun convertToAbstract( x: Float, - y: Float + y: Float, ) = Pair( (x / width * abstractWidth).roundToInt(), - (y / height * abstractHeight).roundToInt() + (y / height * abstractHeight).roundToInt(), ) private fun Canvas.showEmptyView() { @@ -103,7 +104,7 @@ class WhiteboardView( text, (centerX - (paint.measureText(text) / 2).toInt()).toFloat(), (centerY - (paint.descent() + paint.ascent()) / 2).toInt().toFloat(), - paint + paint, ) } } diff --git a/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardCompatImpl.kt b/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardCompatImpl.kt index 6b388b6504..1d78d4238e 100644 --- a/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardCompatImpl.kt +++ b/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardCompatImpl.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ class WhiteboardCompatImpl() : WhiteboardWireGrpc.WhiteboardImplBase() { override fun Whiteboard(response: StreamObserver): StreamObserver { return WhiteboardWireGrpc.BindableAdapter( Whiteboard = { WhiteboardCompat() }, - streamExecutor = Executors.newSingleThreadExecutor() + streamExecutor = Executors.newSingleThreadExecutor(), ) .Whiteboard(response) } @@ -33,14 +33,14 @@ class WhiteboardCompatImpl() : WhiteboardWireGrpc.WhiteboardImplBase() { class WhiteboardCompat : WhiteboardWhiteboardBlockingServer { override fun Whiteboard( request: MessageSource, - response: MessageSink + response: MessageSink, ) { response.write( WhiteboardUpdate( update_points = WhiteboardUpdate.UpdatePoints( - listOf(Point(0, 0, 0)) - ) - ) + listOf(Point(0, 0, 0)), + ), + ), ) } } diff --git a/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardImpl.kt b/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardImpl.kt index 83566dc3a1..bf8bdc114f 100644 --- a/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardImpl.kt +++ b/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardImpl.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,10 +25,10 @@ class WhiteboardImpl : WhiteboardWireGrpc.WhiteboardImplBase() { WhiteboardUpdate( update_points = WhiteboardUpdate.UpdatePoints( listOf( - Point(0, 0, 0) - ) - ) - ) + Point(0, 0, 0), + ), + ), + ), ) } diff --git a/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardServer.kt b/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardServer.kt index 4c97b3fba7..741b3aebac 100644 --- a/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardServer.kt +++ b/samples/wire-grpc-sample/server-plain/src/main/java/com/squareup/wire/whiteboard/WhiteboardServer.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/Grpc.kt b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/Grpc.kt index 64845bafcf..8f13fe85bb 100644 --- a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/Grpc.kt +++ b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/Grpc.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/MiskGrpcServer.kt b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/MiskGrpcServer.kt index 3ef189dc00..f9af920663 100644 --- a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/MiskGrpcServer.kt +++ b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/MiskGrpcServer.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,6 +32,6 @@ fun main(args: Array) { MiskWebModule(config.web), WhiteboardGrpcModule(), ConfigModule.create("whiteboard", config), - EnvironmentModule(environment) + EnvironmentModule(environment), ).run(args) } diff --git a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardConfig.kt b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardConfig.kt index 41d2f99772..127a82f853 100644 --- a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardConfig.kt +++ b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardConfig.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,5 +19,5 @@ import misk.config.Config import misk.web.WebConfig data class WhiteboardConfig( - val web: WebConfig + val web: WebConfig, ) : Config diff --git a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcAction.kt b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcAction.kt index 46a756acfb..56f0d79336 100644 --- a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcAction.kt +++ b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcAction.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,8 +19,8 @@ import com.squareup.wire.MessageSink import com.squareup.wire.MessageSource import com.squareup.wire.whiteboard.WhiteboardUpdate.InitialiseBoard import com.squareup.wire.whiteboard.WhiteboardUpdate.UpdatePoints -import misk.web.actions.WebAction import javax.inject.Singleton +import misk.web.actions.WebAction @Singleton class WhiteboardGrpcAction : WebAction, WhiteboardWhiteboardBlockingServer { @@ -29,7 +29,7 @@ class WhiteboardGrpcAction : WebAction, WhiteboardWhiteboardBlockingServer { override fun Whiteboard( request: MessageSource, - response: MessageSink + response: MessageSink, ) { val client = Client(request, response) clients += client @@ -38,14 +38,14 @@ class WhiteboardGrpcAction : WebAction, WhiteboardWhiteboardBlockingServer { inner class Client( private val commands: MessageSource, - private val updates: MessageSink + private val updates: MessageSink, ) { fun process() { updates.use { val initialiseBoard = InitialiseBoard( BOARD_WIDTH, BOARD_HEIGHT, - COLORS[clients.indexOf(this) % COLORS.size] + COLORS[clients.indexOf(this) % COLORS.size], ) updates.write(WhiteboardUpdate(initialise_board = initialiseBoard)) updates.write(WhiteboardUpdate(update_points = UpdatePoints(points))) @@ -75,7 +75,7 @@ class WhiteboardGrpcAction : WebAction, WhiteboardWhiteboardBlockingServer { 0xff00c8fa.toInt(), // Blue 0xfff46e38.toInt(), // Red 0xff0bb634.toInt(), // Green - 0xff333333.toInt() // Black + 0xff333333.toInt(), // Black ) } } diff --git a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcModule.kt b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcModule.kt index 583d3d678d..27eb2fca4a 100644 --- a/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcModule.kt +++ b/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcModule.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/AllTypesBenchmark.kt b/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/AllTypesBenchmark.kt index 7660dcefb9..378e2c0259 100644 --- a/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/AllTypesBenchmark.kt +++ b/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/AllTypesBenchmark.kt @@ -1,11 +1,11 @@ /* - * Copyright (C) 2022 Block, Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,6 +19,7 @@ import com.squareup.moshi.Moshi import com.squareup.wire.ProtoWriter import com.squareup.wire.ReverseProtoWriter import com.squareup.wire.WireJsonAdapterFactory +import java.util.concurrent.TimeUnit import okio.Buffer import okio.BufferedSource import okio.FileSystem @@ -33,7 +34,6 @@ import org.openjdk.jmh.annotations.Scope import org.openjdk.jmh.annotations.Setup import org.openjdk.jmh.annotations.State import org.openjdk.jmh.annotations.Warmup -import java.util.concurrent.TimeUnit import squareup.wire.benchmarks.proto2.AllTypes as Proto2Wire import squareup.wire.benchmarks.proto2.AllTypesProto2.AllTypes as Proto2Protobuf import squareup.wire.benchmarks.proto3.AllTypes as Proto3Wire diff --git a/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/SimpleMessageBenchmark.java b/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/SimpleMessageBenchmark.java index f3323bff57..3127947c5f 100644 --- a/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/SimpleMessageBenchmark.java +++ b/wire-benchmarks/src/jmh/java/com/squareup/wire/benchmarks/SimpleMessageBenchmark.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,9 @@ */ package com.squareup.wire.benchmarks; +import static java.util.concurrent.TimeUnit.MICROSECONDS; +import static org.openjdk.jmh.annotations.Mode.SampleTime; + import com.squareup.wire.ProtoWriter; import com.squareup.wire.ReverseProtoWriter; import java.io.File; @@ -36,9 +39,6 @@ import squareup.wire.benchmarks.EmailSearchResponse; import squareup.wire.benchmarks.EmailSearchResponseProto; -import static java.util.concurrent.TimeUnit.MICROSECONDS; -import static org.openjdk.jmh.annotations.Mode.SampleTime; - @Fork(1) @Warmup(iterations = 5, time = 2) @Measurement(iterations = 5, time = 2) @@ -49,45 +49,49 @@ public class SimpleMessageBenchmark { Buffer buffer = new Buffer(); byte[] bytes; - @Setup public void setup() throws IOException { + @Setup + public void setup() throws IOException { // `medium_value.bytes` contains bytes for the message // [squareup.wire.benchmarks.EmailSearchResponse]. File file = new File("src/main/resources/medium_value.bytes"); try (Source fileSource = Okio.source(file); - BufferedSource bufferedFileSource = Okio.buffer(fileSource)) { + BufferedSource bufferedFileSource = Okio.buffer(fileSource)) { bytes = bufferedFileSource.readByteArray(); } } - @Benchmark public void encodeWire3x() throws IOException { + @Benchmark + public void encodeWire3x() throws IOException { ProtoWriter writer = new ProtoWriter(buffer); EmailSearchResponse.ADAPTER.encode(writer, SampleData.newMediumValueWire()); buffer.clear(); } - @Benchmark public void encodeWire4x() throws IOException { + @Benchmark + public void encodeWire4x() throws IOException { ReverseProtoWriter writer = new ReverseProtoWriter(); EmailSearchResponse.ADAPTER.encode(writer, SampleData.newMediumValueWire()); writer.writeTo(buffer); buffer.clear(); } - @Benchmark public void encodeProtobuf() throws IOException { + @Benchmark + public void encodeProtobuf() throws IOException { SampleData.newMediumValueProtobuf().writeTo(buffer.outputStream()); buffer.clear(); } - @Benchmark public void decodeWire() throws IOException { + @Benchmark + public void decodeWire() throws IOException { EmailSearchResponse.ADAPTER.decode(bytes); } - @Benchmark public void decodeProtobuf() throws IOException { + @Benchmark + public void decodeProtobuf() throws IOException { EmailSearchResponseProto.EmailSearchResponse.parseFrom(bytes); } - /** - * Run encode for 10 seconds to capture a profile. - */ + /** Run encode for 10 seconds to capture a profile. */ public static void main(String[] args) throws IOException { long now = System.nanoTime(); long done = now + TimeUnit.SECONDS.toNanos(10L); diff --git a/wire-benchmarks/src/main/kotlin/com/squareup/wire/benchmarks/SampleData.kt b/wire-benchmarks/src/main/kotlin/com/squareup/wire/benchmarks/SampleData.kt index 76a5c5bb93..d62d005e9d 100644 --- a/wire-benchmarks/src/main/kotlin/com/squareup/wire/benchmarks/SampleData.kt +++ b/wire-benchmarks/src/main/kotlin/com/squareup/wire/benchmarks/SampleData.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.benchmarks import squareup.wire.benchmarks.EmailMessage as EmailMessageWire @@ -45,7 +60,8 @@ object SampleData { |> (519) 555-2233 |> dentist@example.com |> - |""".trimMargin() + | + """.trimMargin() @JvmStatic fun newMediumValueWire(): EmailSearchResponseWire { @@ -54,9 +70,9 @@ object SampleData { results = listOf( EmailThreadWire( subject = subject, - messages = listOf(newEmailMessageWire()) - ) - ) + messages = listOf(newEmailMessageWire()), + ), + ), ) } @@ -65,17 +81,17 @@ object SampleData { sender = newSenderWire(), recipients = listOf(newRecipientWire()), subject = subject, - body = body + body = body, ) fun newSenderWire() = NameAndAddressWire( display_name = senderDisplayName, - email_address = senderEmailAddress + email_address = senderEmailAddress, ) fun newRecipientWire() = NameAndAddressWire( display_name = recipientDisplayName, - email_address = recipientEmailAddress + email_address = recipientEmailAddress, ) @JvmStatic @@ -88,7 +104,7 @@ object SampleData { .apply { subject = SampleData.subject addMessages(newEmailMessageProtobuf()) - }.build() + }.build(), ) }.build() } diff --git a/wire-gradle-plugin-playground/src/main/java/MyListener.java b/wire-gradle-plugin-playground/src/main/java/MyListener.java index c93b793d5c..c7cae0b690 100644 --- a/wire-gradle-plugin-playground/src/main/java/MyListener.java +++ b/wire-gradle-plugin-playground/src/main/java/MyListener.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import com.squareup.wire.schema.EmittingRules; import com.squareup.wire.schema.EventListener; import com.squareup.wire.schema.PruningRules; @@ -9,27 +24,33 @@ import org.jetbrains.annotations.NotNull; public class MyListener extends EventListener { - @Override public void runStart(@NotNull WireRun wireRun) { + @Override + public void runStart(@NotNull WireRun wireRun) { super.runStart(wireRun); } - @Override public void runSuccess(@NotNull WireRun wireRun) { + @Override + public void runSuccess(@NotNull WireRun wireRun) { super.runSuccess(wireRun); } - @Override public void runFailed(@NotNull List errors) { + @Override + public void runFailed(@NotNull List errors) { super.runFailed(errors); } - @Override public void loadSchemaStart() { + @Override + public void loadSchemaStart() { super.loadSchemaStart(); } - @Override public void loadSchemaSuccess(@NotNull Schema schema) { + @Override + public void loadSchemaSuccess(@NotNull Schema schema) { super.loadSchemaSuccess(schema); } - @Override public void treeShakeStart(@NotNull Schema schema, @NotNull PruningRules pruningRules) { + @Override + public void treeShakeStart(@NotNull Schema schema, @NotNull PruningRules pruningRules) { super.treeShakeStart(schema, pruningRules); } @@ -48,21 +69,25 @@ public void moveTypesEnd(@NotNull Schema refactoredSchema, @NotNull List, sourceTrees: MutableSet, sourceJars: MutableSet, - name: String + name: String, ) { val protoRootSet = objectFactory.newInstance(ProtoRootSet::class.java) action.execute(protoRootSet) diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt index 0947fa132f..dbc9f7bf6f 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireInput.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,10 @@ package com.squareup.wire.gradle import com.squareup.wire.gradle.WireExtension.ProtoRootSet +import java.io.EOFException +import java.io.File +import java.io.RandomAccessFile +import java.net.URI import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Dependency @@ -26,10 +30,6 @@ import org.gradle.api.internal.catalog.DelegatingProjectDependency import org.gradle.api.internal.file.FileOrUriNotationConverter import org.gradle.api.logging.Logger import org.gradle.api.provider.Provider -import java.io.EOFException -import java.io.File -import java.io.RandomAccessFile -import java.net.URI /** * Builds Wire's inputs (expressed as [InputLocation] lists) from Gradle's objects (expressed as @@ -108,12 +108,12 @@ internal class WireInput(var configuration: Configuration) { | include 'relativePath' | } |} - """.trimMargin() + """.trimMargin(), ) } } else if (converted is URI && isURL(converted)) { throw IllegalArgumentException( - "Invalid path string: \"$dependency\". URL dependencies are not allowed." + "Invalid path string: \"$dependency\". URL dependencies are not allowed.", ) } else { // Assume it's a possible external dependency and let Gradle sort it out later. @@ -170,8 +170,8 @@ internal class WireInput(var configuration: Configuration) { InputLocation.get( project = project, base = srcDir.path, - path = relativeTo(srcDir).toString() - ) + path = relativeTo(srcDir).toString(), + ), ) } else if (isZip) { val filters = dependencyFilters.getOrDefault(dependency, listOf()) diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt index 939d2ec699..857ab4cfc5 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireOutput.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -89,12 +89,12 @@ open class KotlinOutput @Inject constructor() : WireOutput() { val rpcCallStyle = RpcCallStyle.values() .singleOrNull { it.toString().equals(rpcCallStyle, ignoreCase = true) } ?: throw IllegalArgumentException( - "Unknown rpcCallStyle $rpcCallStyle. Valid values: ${RpcCallStyle.values().contentToString()}" + "Unknown rpcCallStyle $rpcCallStyle. Valid values: ${RpcCallStyle.values().contentToString()}", ) val rpcRole = RpcRole.values() .singleOrNull { it.toString().equals(rpcRole, ignoreCase = true) } ?: throw IllegalArgumentException( - "Unknown rpcRole $rpcRole. Valid values: ${RpcRole.values().contentToString()}" + "Unknown rpcRole $rpcRole. Valid values: ${RpcRole.values().contentToString()}", ) return KotlinTarget( @@ -127,6 +127,7 @@ open class CustomOutput @Inject constructor() : WireOutput() { var includes: List? = null var excludes: List? = null var exclusive: Boolean = true + /** * Black boxed payload which a caller can set for the custom [SchemaHandler.Factory] to receive. */ diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt index ed959a0c7a..2299e9b0d4 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,6 +23,9 @@ import com.squareup.wire.gradle.internal.targetDefaultOutputPath import com.squareup.wire.gradle.kotlin.Source import com.squareup.wire.gradle.kotlin.sourceRoots import com.squareup.wire.schema.newEventListenerFactory +import java.io.File +import java.lang.reflect.Array as JavaArray +import java.util.concurrent.atomic.AtomicBoolean import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Dependency @@ -37,9 +40,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.io.File -import java.util.concurrent.atomic.AtomicBoolean -import java.lang.reflect.Array as JavaArray class WirePlugin : Plugin { private val android = AtomicBoolean(false) @@ -149,7 +149,7 @@ class WirePlugin : Plugin { project.relativePath(source.outputDir(project)) } else { output.out!! - } + }, ) } val generatedSourcesDirectories: Set = @@ -259,8 +259,11 @@ class WirePlugin : Plugin { } private fun Source.outputDir(project: Project): File { - return if (sources.size > 1) File(project.targetDefaultOutputPath(), name) - else File(project.targetDefaultOutputPath()) + return if (sources.size > 1) { + File(project.targetDefaultOutputPath(), name) + } else { + File(project.targetDefaultOutputPath()) + } } private fun Project.addWireRuntimeDependency( @@ -282,7 +285,7 @@ class WirePlugin : Plugin { project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets val sourceSet = (sourceSets.getByName("commonMain") as DefaultKotlinSourceSet) project.configurations.getByName(sourceSet.apiConfigurationName).dependencies.add( - runtimeDependency + runtimeDependency, ) } @@ -291,7 +294,7 @@ class WirePlugin : Plugin { project.extensions.getByType(KotlinJsProjectExtension::class.java).sourceSets val sourceSet = (sourceSets.getByName("main") as DefaultKotlinSourceSet) project.configurations.getByName(sourceSet.apiConfigurationName).dependencies.add( - runtimeDependency + runtimeDependency, ) } @@ -334,7 +337,7 @@ class WirePlugin : Plugin { // 1.7.x: `fun source(vararg sources: Any)` private val SOURCE_FUNCTION = KotlinCompile::class.java.getMethod( "source", - JavaArray.newInstance(Any::class.java, 0).javaClass + JavaArray.newInstance(Any::class.java, 0).javaClass, ) } } diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireTask.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireTask.kt index 9c0dcd22ed..2923cde25e 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireTask.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WireTask.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,6 +22,8 @@ import com.squareup.wire.schema.EventListener import com.squareup.wire.schema.Location import com.squareup.wire.schema.Target import com.squareup.wire.schema.WireRun +import java.io.File +import javax.inject.Inject import okio.FileSystem import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty @@ -40,8 +42,6 @@ import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SkipWhenEmpty import org.gradle.api.tasks.SourceTask import org.gradle.api.tasks.TaskAction -import java.io.File -import javax.inject.Inject @CacheableTask abstract class WireTask @Inject constructor(objects: ObjectFactory) : SourceTask() { diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/GradleWireLogger.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/GradleWireLogger.kt index f384f090d3..0b56a681b8 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/GradleWireLogger.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/GradleWireLogger.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,7 +28,7 @@ internal object GradleWireLogger : WireLogger { slf4jLogger.warn( """Unused element in treeShakingRoots: | ${unusedRoots.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -36,7 +36,7 @@ internal object GradleWireLogger : WireLogger { slf4jLogger.warn( """Unused element in treeShakingRubbish: | ${unusedPrunes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -44,7 +44,7 @@ internal object GradleWireLogger : WireLogger { slf4jLogger.warn( """Unused includes in targets: | ${unusedIncludes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } @@ -52,7 +52,7 @@ internal object GradleWireLogger : WireLogger { slf4jLogger.warn( """Unused excludes in targets: | ${unusedExcludes.joinToString(separator = "\n ")} - """.trimMargin() + """.trimMargin(), ) } diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/projects.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/projects.kt index ed725bc111..ad6fbbada1 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/projects.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/internal/projects.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.gradle.internal import org.gradle.api.Project diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/kotlin/SourceRoots.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/kotlin/SourceRoots.kt index 3e934a2b98..c84184462d 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/kotlin/SourceRoots.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/kotlin/SourceRoots.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -65,7 +65,7 @@ internal fun WirePlugin.sourceRoots(kotlin: Boolean, java: Boolean): List throw IllegalStateException("Unknown Android plugin $this") } val androidSourceSets: Map? = - if (kotlin) null else { + if (kotlin) { + null + } else { sourceSets .associate { sourceSet -> sourceSet.name to sourceSet.java @@ -125,7 +127,9 @@ private fun BaseExtension.sourceRoots(project: Project, kotlin: Boolean): List sourceSet.name to kotlinSourceSets.getByName(sourceSet.name).kotlin } - } else null + } else { + null + } } return variants.map { variant -> @@ -158,8 +162,11 @@ private fun BaseExtension.sourceRoots(project: Project, kotlin: Boolean): List, val registerGeneratedDirectory: ((Provider) -> Unit)? = null, - val registerTaskDependency: ((TaskProvider) -> Unit)? = null + val registerTaskDependency: ((TaskProvider) -> Unit)? = null, ) internal class WireSourceDirectorySet private constructor( @@ -184,7 +191,7 @@ internal class WireSourceDirectorySet private constructor( init { check( (sourceDirectorySet == null || androidSourceDirectorySet == null) && - (sourceDirectorySet != null || androidSourceDirectorySet != null) + (sourceDirectorySet != null || androidSourceDirectorySet != null), ) { "At least and at most one of sourceDirectorySet, androidSourceDirectorySet should be non-null" } diff --git a/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt b/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt index e2c371b408..ba5fcd47eb 100644 --- a/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt +++ b/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt @@ -1,9 +1,29 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ @file:Suppress("UsePropertyAccessSyntax") package com.squareup.wire.gradle import com.squareup.wire.VERSION import com.squareup.wire.testing.withPlatformSlashes +import java.io.File +import java.io.IOException +import java.util.zip.ZipFile +import kotlin.text.RegexOption.DOT_MATCHES_ALL +import kotlin.text.RegexOption.MULTILINE import org.assertj.core.api.Assertions.assertThat import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner @@ -14,11 +34,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -import java.io.File -import java.io.IOException -import java.util.zip.ZipFile -import kotlin.text.RegexOption.DOT_MATCHES_ALL -import kotlin.text.RegexOption.MULTILINE class WirePluginTest { @@ -83,7 +98,7 @@ class WirePluginTest { | include 'relativePath' | } |} - """.trimMargin() + """.trimMargin(), ) } @@ -180,7 +195,7 @@ class WirePluginTest { | include 'relativePath' | } |} - """.trimMargin() + """.trimMargin(), ) } @@ -193,7 +208,7 @@ class WirePluginTest { assertThat(result.task(":generateProtos")).isNull() assertThat(result.output) .contains( - """Invalid path string: "http://www.squareup.com". URL dependencies are not allowed.""" + """Invalid path string: "http://www.squareup.com". URL dependencies are not allowed.""", ) } @@ -287,7 +302,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .contains("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcetree-one-srcdir-many-files/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcetree-one-srcdir-many-files/build/generated/source/wire".withPlatformSlashes(), ) } @@ -306,7 +321,7 @@ class WirePluginTest { | squareup.dinosaurs.Crustacean |Unused element(s) in prunes: | squareup.mammals.Human - """.trimMargin() + """.trimMargin(), ) } @@ -334,7 +349,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .contains("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcejar-local-many-files/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-local-many-files/build/generated/source/wire".withPlatformSlashes(), ) } @@ -349,7 +364,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .contains("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcejar-local-nonproto-file/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-local-nonproto-file/build/generated/source/wire".withPlatformSlashes(), ) } @@ -364,7 +379,7 @@ class WirePluginTest { .doesNotContain("Writing com.squareup.dinosaurs.Dinosaur") .contains("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcejar-local-single-file/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-local-single-file/build/generated/source/wire".withPlatformSlashes(), ) } @@ -380,7 +395,7 @@ class WirePluginTest { .contains("Writing com.squareup.geology.Period") .doesNotContain("Writing com.excluded.Martian") .contains( - "src/test/projects/sourcejar-mixed-conflicts/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-mixed-conflicts/build/generated/source/wire".withPlatformSlashes(), ) } @@ -395,7 +410,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .contains("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcejar-remote-many-files/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-remote-many-files/build/generated/source/wire".withPlatformSlashes(), ) } @@ -411,7 +426,7 @@ class WirePluginTest { .contains("Writing com.squareup.geology.Period") .doesNotContain("Writing com.excluded.Martian") .contains( - "src/test/projects/sourcejar-remote-wildcards/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-remote-wildcards/build/generated/source/wire".withPlatformSlashes(), ) } @@ -426,7 +441,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .doesNotContain("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcejar-remote-protopath/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-remote-protopath/build/generated/source/wire".withPlatformSlashes(), ) } @@ -440,7 +455,7 @@ class WirePluginTest { assertThat(result.output) .contains("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcejar-remote-version-catalog/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcejar-remote-version-catalog/build/generated/source/wire".withPlatformSlashes(), ) } @@ -455,7 +470,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .doesNotContain("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcezip-local-protopath/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcezip-local-protopath/build/generated/source/wire".withPlatformSlashes(), ) } @@ -470,7 +485,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .doesNotContain("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourceaar-local-protopath/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourceaar-local-protopath/build/generated/source/wire".withPlatformSlashes(), ) } @@ -486,15 +501,15 @@ class WirePluginTest { .isIn(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE) val generatedProto1 = File( fixtureRoot, - "dinosaurs/build/generated/source/wire/com/squareup/dinosaurs/Dinosaur.kt" + "dinosaurs/build/generated/source/wire/com/squareup/dinosaurs/Dinosaur.kt", ) val generatedProto2 = File( fixtureRoot, - "geology/build/generated/source/wire/com/squareup/geology/Period.kt" + "geology/build/generated/source/wire/com/squareup/geology/Period.kt", ) val generatedProto3 = File( fixtureRoot, - "dinosaurs/build/generated/source/wire/com/squareup/location/Continent.kt" + "dinosaurs/build/generated/source/wire/com/squareup/location/Continent.kt", ) assertThat(generatedProto1).exists() assertThat(generatedProto2).exists() @@ -502,7 +517,7 @@ class WirePluginTest { val notExpected = File( fixtureRoot, - "dinosaurs/build/generated/source/wire/com/squareup/location/Planet.kt" + "dinosaurs/build/generated/source/wire/com/squareup/location/Planet.kt", ) assertThat(notExpected).doesNotExist() @@ -570,7 +585,7 @@ class WirePluginTest { assertThat(result.task(":generateProtos")).isNull() assertThat(result.output) .contains( - "Wire Gradle plugin applied in project ':' but no supported Kotlin plugin was found" + "Wire Gradle plugin applied in project ':' but no supported Kotlin plugin was found", ) } @@ -834,7 +849,7 @@ class WirePluginTest { .contains("Writing com.squareup.dinosaurs.Dinosaur") .doesNotContain("Writing com.squareup.geology.Period") .contains( - "src/test/projects/sourcepath-and-protopath-intersect/build/generated/source/wire".withPlatformSlashes() + "src/test/projects/sourcepath-and-protopath-intersect/build/generated/source/wire".withPlatformSlashes(), ) } @@ -954,10 +969,10 @@ class WirePluginTest { val outputRoot = File(fixtureRoot, "build/generated/source/wire") assertThat(File(outputRoot, "com/squareup/dinosaurs/BattleServiceClient.kt")).exists() assertThat( - File(outputRoot, "com/squareup/dinosaurs/BattleServiceFightBlockingServer.kt") + File(outputRoot, "com/squareup/dinosaurs/BattleServiceFightBlockingServer.kt"), ).exists() assertThat( - File(outputRoot, "com/squareup/dinosaurs/BattleServiceBrawlBlockingServer.kt") + File(outputRoot, "com/squareup/dinosaurs/BattleServiceBrawlBlockingServer.kt"), ).exists() } @@ -1022,7 +1037,7 @@ class WirePluginTest { "custom handler is running!! " + "squareup.dinosaurs.Dinosaur, " + "squareup.geology.Period, true, " + - "a=one, b=two, c=three" + "a=one, b=two, c=three", ) } @@ -1081,7 +1096,11 @@ class WirePluginTest { val result = gradleRunner.runFixture(fixtureRoot) { withArguments( - "assemble", "--stacktrace", "-Dkjs=$kmpJsEnabled", "-Dknative=$kmpNativeEnabled", "--info" + "assemble", + "--stacktrace", + "-Dkjs=$kmpJsEnabled", + "-Dknative=$kmpNativeEnabled", + "--info", ).build() } @@ -1205,7 +1224,8 @@ class WirePluginTest { assertThat(result.output).contains("Writing squareup.options.DocumentationUrlOption") val generatedProto = File( - fixtureRoot, "build/generated/source/wire/squareup/polygons/Octagon.java" + fixtureRoot, + "build/generated/source/wire/squareup/polygons/Octagon.java", ) val octagon = generatedProto.readText() assertThat(octagon) @@ -1222,7 +1242,8 @@ class WirePluginTest { assertThat(result.output).contains("Writing squareup.options.DocumentationUrlOption") val generatedProto = File( - fixtureRoot, "build/generated/source/wire/squareup/polygons/Octagon.kt" + fixtureRoot, + "build/generated/source/wire/squareup/polygons/Octagon.kt", ) val octagon = generatedProto.readText() assertThat(octagon) @@ -1261,15 +1282,15 @@ class WirePluginTest { .isIn(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE) val generatedProto1 = File( fixtureRoot, - "dinosaurs/build/generated/source/wire/com/squareup/dinosaurs/Dinosaur.kt" + "dinosaurs/build/generated/source/wire/com/squareup/dinosaurs/Dinosaur.kt", ) val generatedProto2 = File( fixtureRoot, - "geology/build/generated/source/wire/com/squareup/geology/Period.kt" + "geology/build/generated/source/wire/com/squareup/geology/Period.kt", ) val generatedProto3 = File( fixtureRoot, - "dinosaurs/build/generated/source/wire/com/squareup/location/Continent.kt" + "dinosaurs/build/generated/source/wire/com/squareup/location/Continent.kt", ) assertThat(generatedProto1).exists() assertThat(generatedProto2).exists() @@ -1277,7 +1298,7 @@ class WirePluginTest { val notExpected = File( fixtureRoot, - "dinosaurs/build/generated/source/wire/com/squareup/location/Planet.kt" + "dinosaurs/build/generated/source/wire/com/squareup/location/Planet.kt", ) assertThat(notExpected).doesNotExist() @@ -1408,7 +1429,7 @@ class WirePluginTest { private fun GradleRunner.runFixture( root: File, - action: GradleRunner.() -> BuildResult + action: GradleRunner.() -> BuildResult, ): BuildResult { var generatedSettings = false val settings = File(root, "settings.gradle") @@ -1459,7 +1480,8 @@ class WirePluginTest { } // This follows symlink so don't use it at home. - @Throws(IOException::class) fun unsafeDelete(f: File) { + @Throws(IOException::class) + fun unsafeDelete(f: File) { if (f.isDirectory) { for (c in f.listFiles()!!) unsafeDelete(c) } diff --git a/wire-gradle-plugin/src/test/projects/java-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.java b/wire-gradle-plugin/src/test/projects/java-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.java index f4260af01b..6f8a3a0c02 100644 --- a/wire-gradle-plugin/src/test/projects/java-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.java +++ b/wire-gradle-plugin/src/test/projects/java-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.dinosaurs; import com.squareup.geology.Period; @@ -8,13 +23,14 @@ public final class Sample { public void run() throws IOException { // Create an immutable value object with the Builder API. - Dinosaur stegosaurus = new Dinosaur.Builder() - .name("Stegosaurus") - .period(Period.JURASSIC) - .length_meters(9.0) - .mass_kilograms(5_000.0) - .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) - .build(); + Dinosaur stegosaurus = + new Dinosaur.Builder() + .name("Stegosaurus") + .period(Period.JURASSIC) + .length_meters(9.0) + .mass_kilograms(5_000.0) + .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) + .build(); // Encode that value to bytes, and print that as base64. byte[] stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus); diff --git a/wire-gradle-plugin/src/test/projects/java-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.java b/wire-gradle-plugin/src/test/projects/java-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.java index f4260af01b..6f8a3a0c02 100644 --- a/wire-gradle-plugin/src/test/projects/java-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.java +++ b/wire-gradle-plugin/src/test/projects/java-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.dinosaurs; import com.squareup.geology.Period; @@ -8,13 +23,14 @@ public final class Sample { public void run() throws IOException { // Create an immutable value object with the Builder API. - Dinosaur stegosaurus = new Dinosaur.Builder() - .name("Stegosaurus") - .period(Period.JURASSIC) - .length_meters(9.0) - .mass_kilograms(5_000.0) - .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) - .build(); + Dinosaur stegosaurus = + new Dinosaur.Builder() + .name("Stegosaurus") + .period(Period.JURASSIC) + .length_meters(9.0) + .mass_kilograms(5_000.0) + .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) + .build(); // Encode that value to bytes, and print that as base64. byte[] stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus); diff --git a/wire-gradle-plugin/src/test/projects/kotlin-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.kt b/wire-gradle-plugin/src/test/projects/kotlin-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.kt index 7fa5aa419b..e2bfdf2948 100644 --- a/wire-gradle-plugin/src/test/projects/kotlin-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.kt +++ b/wire-gradle-plugin/src/test/projects/kotlin-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.kt @@ -1,8 +1,23 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.dinosaurs import com.squareup.geology.Period -import okio.ByteString.Companion.toByteString import java.io.IOException +import okio.ByteString.Companion.toByteString class Sample { @Throws(IOException::class) diff --git a/wire-gradle-plugin/src/test/projects/kotlin-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.kt b/wire-gradle-plugin/src/test/projects/kotlin-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.kt index f7a8bfbd41..40d8b49602 100644 --- a/wire-gradle-plugin/src/test/projects/kotlin-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.kt +++ b/wire-gradle-plugin/src/test/projects/kotlin-project-kotlin-protos/src/main/java/com/squareup/dinosaurs/Sample.kt @@ -1,8 +1,23 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.dinosaurs import com.squareup.geology.Period -import okio.ByteString.Companion.toByteString import java.io.IOException +import okio.ByteString.Companion.toByteString class Sample { @Throws(IOException::class) @@ -13,7 +28,7 @@ class Sample { period = Period.JURASSIC, length_meters = 9.0, mass_kilograms = 5_000.0, - picture_urls = listOf("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67") + picture_urls = listOf("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67"), ) // Encode that value to bytes, and print that as base64. val stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus) diff --git a/wire-gradle-plugin/src/test/projects/sourcedir-exclude/src/main/java/com/squareup/dinosaurs/Sample.kt b/wire-gradle-plugin/src/test/projects/sourcedir-exclude/src/main/java/com/squareup/dinosaurs/Sample.kt index f7a8bfbd41..40d8b49602 100644 --- a/wire-gradle-plugin/src/test/projects/sourcedir-exclude/src/main/java/com/squareup/dinosaurs/Sample.kt +++ b/wire-gradle-plugin/src/test/projects/sourcedir-exclude/src/main/java/com/squareup/dinosaurs/Sample.kt @@ -1,8 +1,23 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.dinosaurs import com.squareup.geology.Period -import okio.ByteString.Companion.toByteString import java.io.IOException +import okio.ByteString.Companion.toByteString class Sample { @Throws(IOException::class) @@ -13,7 +28,7 @@ class Sample { period = Period.JURASSIC, length_meters = 9.0, mass_kilograms = 5_000.0, - picture_urls = listOf("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67") + picture_urls = listOf("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67"), ) // Encode that value to bytes, and print that as base64. val stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus) diff --git a/wire-gradle-plugin/src/test/projects/sourcedir-include/src/main/java/com/squareup/dinosaurs/Sample.kt b/wire-gradle-plugin/src/test/projects/sourcedir-include/src/main/java/com/squareup/dinosaurs/Sample.kt index f7a8bfbd41..40d8b49602 100644 --- a/wire-gradle-plugin/src/test/projects/sourcedir-include/src/main/java/com/squareup/dinosaurs/Sample.kt +++ b/wire-gradle-plugin/src/test/projects/sourcedir-include/src/main/java/com/squareup/dinosaurs/Sample.kt @@ -1,8 +1,23 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.dinosaurs import com.squareup.geology.Period -import okio.ByteString.Companion.toByteString import java.io.IOException +import okio.ByteString.Companion.toByteString class Sample { @Throws(IOException::class) @@ -13,7 +28,7 @@ class Sample { period = Period.JURASSIC, length_meters = 9.0, mass_kilograms = 5_000.0, - picture_urls = listOf("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67") + picture_urls = listOf("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67"), ) // Encode that value to bytes, and print that as base64. val stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus) diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcCall.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcCall.kt index 412c820463..b9fbd17e00 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcCall.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcCall.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcClient.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcClient.kt index 4ee3a61200..deff0315e5 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcClient.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcClient.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcException.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcException.kt index e45a3ddf88..4f37904561 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcException.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcException.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.squareup.wire import okio.IOException diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHeaders.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHeaders.kt index bdd4acbb37..980847f649 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHeaders.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHeaders.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt index 545e40bb18..205f61b584 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcMethod.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcMethod.kt index c5867c0fd2..3543797967 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcMethod.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcMethod.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,5 +18,5 @@ package com.squareup.wire class GrpcMethod( val path: String, val requestAdapter: ProtoAdapter, - val responseAdapter: ProtoAdapter + val responseAdapter: ProtoAdapter, ) diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequest.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequest.kt index 3d412b8c65..9f8b1b7521 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequest.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.squareup.wire expect class GrpcRequest diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequestBody.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequestBody.kt index 3cd7ba1aab..419b15660e 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequestBody.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcRequestBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponse.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponse.kt index 9931ddb307..c021f3bf73 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponse.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponse.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,12 +18,13 @@ package com.squareup.wire import com.squareup.wire.internal.addSuppressed -import okio.IOException import kotlin.jvm.JvmName import kotlin.jvm.JvmOverloads +import okio.IOException expect class GrpcResponse { - @get:JvmName("body") val body: GrpcResponseBody? + @get:JvmName("body") + val body: GrpcResponseBody? @JvmOverloads fun header(name: String, defaultValue: String? = null): String? diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponseBody.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponseBody.kt index bc2fbbadbc..007d938f6f 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponseBody.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcResponseBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.squareup.wire import okio.BufferedSource diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStatus.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStatus.kt index 163e4b41a9..23bd4d4328 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStatus.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStatus.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.squareup.wire import kotlin.jvm.JvmField @@ -21,27 +20,43 @@ import kotlin.jvm.Synchronized class GrpcStatus private constructor( val name: String, - val code: Int + val code: Int, ) { companion object { private val INSTANCES = mutableMapOf() @JvmField val OK: GrpcStatus = create("OK", 0) + @JvmField val CANCELLED: GrpcStatus = create("CANCELLED", 1) + @JvmField val UNKNOWN: GrpcStatus = create("UNKNOWN", 2) + @JvmField val INVALID_ARGUMENT: GrpcStatus = create("INVALID_ARGUMENT", 3) + @JvmField val DEADLINE_EXCEEDED: GrpcStatus = create("DEADLINE_EXCEEDED", 4) + @JvmField val NOT_FOUND: GrpcStatus = create("NOT_FOUND", 5) + @JvmField val ALREADY_EXISTS: GrpcStatus = create("ALREADY_EXISTS", 6) + @JvmField val PERMISSION_DENIED: GrpcStatus = create("PERMISSION_DENIED", 7) + @JvmField val RESOURCE_EXHAUSTED: GrpcStatus = create("RESOURCE_EXHAUSTED", 8) + @JvmField val FAILED_PRECONDITION: GrpcStatus = create("FAILED_PRECONDITION", 9) + @JvmField val ABORTED: GrpcStatus = create("ABORTED", 10) + @JvmField val OUT_OF_RANGE: GrpcStatus = create("OUT_OF_RANGE", 11) + @JvmField val UNIMPLEMENTED: GrpcStatus = create("UNIMPLEMENTED", 12) + @JvmField val INTERNAL: GrpcStatus = create("INTERNAL", 13) + @JvmField val UNAVAILABLE: GrpcStatus = create("UNAVAILABLE", 14) + @JvmField val DATA_LOSS: GrpcStatus = create("DATA_LOSS", 15) + @JvmField val UNAUTHENTICATED: GrpcStatus = create("UNAUTHENTICATED", 16) private fun create(name: String, status: Int): GrpcStatus { diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStreamingCall.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStreamingCall.kt index 9ab8b3e69d..2b4261c9ee 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStreamingCall.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/GrpcStreamingCall.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -96,8 +96,8 @@ interface GrpcStreamingCall { message = "Provide a scope, preferably not GlobalScope", replaceWith = ReplaceWith( expression = "executeIn(GlobalScope)", - imports = ["kotlinx.coroutines.GlobalScope"] - ) + imports = ["kotlinx.coroutines.GlobalScope"], + ), ) fun execute(): Pair, ReceiveChannel> diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/WireGrpcExperimental.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/WireGrpcExperimental.kt index 7491fc9cdd..039057d3e4 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/WireGrpcExperimental.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/WireGrpcExperimental.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.squareup.wire import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcDecoder.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcDecoder.kt index c891ee6524..ef311cf573 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcDecoder.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcDecoder.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcEncoder.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcEncoder.kt index 3b0ed86c85..5a998211f7 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcEncoder.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcEncoder.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSink.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSink.kt index bb76321998..27acdc7d44 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSink.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSink.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,7 +33,7 @@ class GrpcMessageSink( private val minMessageToCompress: Long, private val messageAdapter: ProtoAdapter, private val callForCancel: Call?, - private val grpcEncoding: String + private val grpcEncoding: String, ) : MessageSink { private var closed = false override fun write(message: T) { diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSource.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSource.kt index 896bd321c9..3f957473f6 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSource.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/GrpcMessageSource.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,7 +31,7 @@ import okio.buffer class GrpcMessageSource( private val source: BufferedSource, private val messageAdapter: ProtoAdapter, - private val grpcEncoding: String? = null + private val grpcEncoding: String? = null, ) : MessageSource { override fun read(): T? { if (source.exhausted()) return null @@ -46,7 +46,7 @@ class GrpcMessageSource( compressedFlag.toInt() == 0 -> GrpcDecoder.IdentityGrpcDecoder compressedFlag.toInt() == 1 -> { grpcEncoding?.toGrpcDecoding() ?: throw ProtocolException( - "message is encoded but message-encoding header was omitted" + "message is encoded but message-encoding header was omitted", ) } else -> throw ProtocolException("unexpected compressed-flag: $compressedFlag") diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/platform.common.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/platform.common.kt index fe0402f968..8f1d430066 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/platform.common.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/platform.common.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/util.kt b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/util.kt index 6f2e14a327..697dd319c3 100644 --- a/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/util.kt +++ b/wire-grpc-client/src/commonMain/kotlin/com/squareup/wire/internal/util.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcClient.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcClient.kt index 77d0cd3048..cfd6b41d9f 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcClient.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcClient.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHeaders.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHeaders.kt index 36f75d003e..b31a389465 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHeaders.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHeaders.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt index 2bb9b89de7..69714cbf4d 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequest.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequest.kt index f69dc65c31..fba5417072 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequest.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,11 +21,11 @@ actual open class GrpcRequestBuilder { actual open fun url(url: GrpcHttpUrl): GrpcRequestBuilder = TODO("Not yet implemented") actual open fun addHeader( name: String, - value: String + value: String, ): GrpcRequestBuilder = TODO("Not yet implemented") actual open fun method( method: String, - body: GrpcRequestBody? + body: GrpcRequestBody?, ): GrpcRequestBuilder = TODO("Not yet implemented") actual open fun build(): GrpcRequest = TODO("Not yet implemented") } diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequestBody.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequestBody.kt index 8892a872c9..64a54e1288 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequestBody.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcRequestBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponse.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponse.kt index 409fbaa0ce..f57c38a409 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponse.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponse.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,7 @@ actual class GrpcResponse { actual fun header( name: String, - defaultValue: String? + defaultValue: String?, ): String? { TODO("Not yet implemented") } diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponseBody.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponseBody.kt index 8f610a9ed4..f46dc85c8b 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponseBody.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/GrpcResponseBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/internal/platform.kt b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/internal/platform.kt index 542a815f0e..61fc943fae 100644 --- a/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/internal/platform.kt +++ b/wire-grpc-client/src/jsMain/kotlin/com/squareup/wire/internal/platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcCalls.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcCalls.kt index b502d94435..a6dd1ba971 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcCalls.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcCalls.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,6 +17,7 @@ package com.squareup.wire +import java.util.concurrent.atomic.AtomicBoolean import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -28,7 +29,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import okio.IOException import okio.Timeout -import java.util.concurrent.atomic.AtomicBoolean /** * Returns a new instance of [GrpcCall] that can be used for a single call to @@ -70,7 +70,7 @@ fun GrpcCall(function: (S) -> R): GrpcCall { get() = GrpcMethod( path = "/wire/AnonymousEndpoint", requestAdapter = ProtoAdapter.BYTES, - responseAdapter = ProtoAdapter.BYTES + responseAdapter = ProtoAdapter.BYTES, ) as GrpcMethod override val timeout: Timeout = Timeout.NONE @@ -145,7 +145,7 @@ fun GrpcCall(function: (S) -> R): GrpcCall { */ @JvmName("grpcStreamingCall") fun GrpcStreamingCall( - function: suspend (ReceiveChannel, SendChannel) -> Unit + function: suspend (ReceiveChannel, SendChannel) -> Unit, ): GrpcStreamingCall { return object : GrpcStreamingCall { @Suppress("UNCHECKED_CAST") @@ -153,7 +153,7 @@ fun GrpcStreamingCall( get() = GrpcMethod( path = "/wire/AnonymousEndpoint", requestAdapter = ProtoAdapter.BYTES, - responseAdapter = ProtoAdapter.BYTES + responseAdapter = ProtoAdapter.BYTES, ) as GrpcMethod private var canceled = AtomicBoolean() diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcClient.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcClient.kt index 20e22d381d..98846cbda6 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcClient.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcClient.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,16 +17,16 @@ package com.squareup.wire import com.squareup.wire.internal.RealGrpcCall import com.squareup.wire.internal.RealGrpcStreamingCall +import kotlin.reflect.KClass import okhttp3.Call import okhttp3.OkHttpClient import okhttp3.Protocol.H2_PRIOR_KNOWLEDGE import okhttp3.Protocol.HTTP_2 -import kotlin.reflect.KClass actual abstract class GrpcClient private constructor( internal val client: Call.Factory, internal val baseUrl: GrpcHttpUrl, - internal val minMessageToCompress: Long + internal val minMessageToCompress: Long, ) { /** Returns a [T] that makes gRPC calls using this client. */ inline fun create(): T = create(T::class) @@ -68,7 +68,7 @@ actual abstract class GrpcClient private constructor( internal fun newCall( method: GrpcMethod<*, *>, requestMetadata: Map, - requestBody: GrpcRequestBody + requestBody: GrpcRequestBody, ): Call { return client.newCall( GrpcRequestBuilder() @@ -86,7 +86,7 @@ actual abstract class GrpcClient private constructor( } .tag(GrpcMethod::class.java, method) .method("POST", requestBody) - .build() + .build(), ) } @@ -132,7 +132,7 @@ actual abstract class GrpcClient private constructor( fun build(): GrpcClient = object : GrpcClient( client = client ?: throw IllegalArgumentException("client is not set"), baseUrl = baseUrl ?: throw IllegalArgumentException("baseUrl is not set"), - minMessageToCompress = minMessageToCompress + minMessageToCompress = minMessageToCompress, ) { override fun newCall(method: GrpcMethod): GrpcCall { return RealGrpcCall(this, method) diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHeaders.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHeaders.kt index 1d95352adb..7dd11e9f1c 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHeaders.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHeaders.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt index c3cfa2d740..c7ad47510a 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequest.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequest.kt index a3600752bf..22bc78ccac 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequest.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequestBody.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequestBody.kt index f3e3826ce9..796c1193c8 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequestBody.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcRequestBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponse.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponse.kt index e99cd042b1..c71ed98bd3 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponse.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponse.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponseBody.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponseBody.kt index 041b290648..e577c69ad7 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponseBody.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcResponseBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/BlockingMessageSource.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/BlockingMessageSource.kt index ea64da0747..4483ff44eb 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/BlockingMessageSource.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/BlockingMessageSource.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,10 +19,10 @@ import com.squareup.wire.GrpcResponse import com.squareup.wire.MessageSource import com.squareup.wire.ProtoAdapter import com.squareup.wire.use +import java.util.concurrent.LinkedBlockingDeque import okhttp3.Call import okhttp3.Callback import okio.IOException -import java.util.concurrent.LinkedBlockingDeque /** * This message source uses a [LinkedBlockingDeque] to connect a reading source with a writing @@ -36,7 +36,7 @@ import java.util.concurrent.LinkedBlockingDeque internal class BlockingMessageSource( val grpcCall: RealGrpcStreamingCall<*, R>, val responseAdapter: ProtoAdapter, - val call: Call + val call: Call, ) : MessageSource { private val queue = LinkedBlockingDeque(1) diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/LateInitTimeout.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/LateInitTimeout.kt index 7de694ed73..cb9417058e 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/LateInitTimeout.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/LateInitTimeout.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,9 +15,9 @@ */ package com.squareup.wire.internal +import java.util.concurrent.TimeUnit import okio.ForwardingTimeout import okio.Timeout -import java.util.concurrent.TimeUnit internal class LateInitTimeout : ForwardingTimeout(Timeout()) { fun init(newDelegate: Timeout) { diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/PipeDuplexRequestBody.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/PipeDuplexRequestBody.kt index 88850276c6..7cac4ec079 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/PipeDuplexRequestBody.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/PipeDuplexRequestBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,7 @@ import okio.buffer */ internal class PipeDuplexRequestBody( private val contentType: MediaType?, - pipeMaxBufferSize: Long + pipeMaxBufferSize: Long, ) : RequestBody() { private val pipe = Pipe(pipeMaxBufferSize) diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcCall.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcCall.kt index 92638b5fac..d4b3223a73 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcCall.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcCall.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,18 +20,18 @@ import com.squareup.wire.GrpcClient import com.squareup.wire.GrpcMethod import com.squareup.wire.GrpcResponse import com.squareup.wire.use +import java.util.concurrent.TimeUnit +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.Callback import okhttp3.Response import okio.IOException import okio.Timeout -import java.util.concurrent.TimeUnit -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException internal class RealGrpcCall( private val grpcClient: GrpcClient, - override val method: GrpcMethod + override val method: GrpcMethod, ) : GrpcCall { /** Non-null once this is executed. */ private var call: Call? = null @@ -137,7 +137,7 @@ internal class RealGrpcCall( val requestBody = newRequestBody( minMessageToCompress = grpcClient.minMessageToCompress, requestAdapter = method.requestAdapter, - onlyMessage = request + onlyMessage = request, ) val result = grpcClient.newCall(method, requestMetadata, requestBody) this.call = result diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcStreamingCall.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcStreamingCall.kt index c4f1709c58..9e40579b66 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcStreamingCall.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/RealGrpcStreamingCall.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,8 @@ import com.squareup.wire.GrpcMethod import com.squareup.wire.GrpcStreamingCall import com.squareup.wire.MessageSink import com.squareup.wire.MessageSource +import java.util.concurrent.TimeUnit +import kotlin.DeprecationLevel.WARNING import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -29,14 +31,13 @@ import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.launch import okio.Timeout -import java.util.concurrent.TimeUnit -import kotlin.DeprecationLevel.WARNING internal class RealGrpcStreamingCall( private val grpcClient: GrpcClient, - override val method: GrpcMethod + override val method: GrpcMethod, ) : GrpcStreamingCall { private val requestBody = newDuplexRequestBody() + /** Non-null once this is executed. */ private var call: Call? = null private var canceled = false @@ -63,7 +64,7 @@ internal class RealGrpcStreamingCall( @Deprecated( "Provide a scope, preferably not GlobalScope", replaceWith = ReplaceWith("executeIn(GlobalScope)", "kotlinx.coroutines.GlobalScope"), - level = WARNING + level = WARNING, ) @Suppress("OPT_IN_USAGE") override fun execute(): Pair, ReceiveChannel> = executeIn(GlobalScope) @@ -87,7 +88,7 @@ internal class RealGrpcStreamingCall( requestBody = requestBody, minMessageToCompress = grpcClient.minMessageToCompress, requestAdapter = method.requestAdapter, - callForCancel = call + callForCancel = call, ) } call.enqueue(responseChannel.readFromResponseBodyCallback(this, method.responseAdapter)) @@ -101,7 +102,7 @@ internal class RealGrpcStreamingCall( val messageSink = requestBody.messageSink( minMessageToCompress = grpcClient.minMessageToCompress, requestAdapter = method.requestAdapter, - callForCancel = call + callForCancel = call, ) call.enqueue(messageSource.readFromResponseBodyCallback()) @@ -115,8 +116,11 @@ internal class RealGrpcStreamingCall( val oldTimeout = this.timeout result.timeout.also { newTimeout -> newTimeout.timeout(oldTimeout.timeoutNanos(), TimeUnit.NANOSECONDS) - if (oldTimeout.hasDeadline()) newTimeout.deadlineNanoTime(oldTimeout.deadlineNanoTime()) - else newTimeout.clearDeadline() + if (oldTimeout.hasDeadline()) { + newTimeout.deadlineNanoTime(oldTimeout.deadlineNanoTime()) + } else { + newTimeout.clearDeadline() + } } result.requestMetadata += this.requestMetadata return result diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/grpc.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/grpc.kt index 26dc83d9b0..81c3562ebc 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/grpc.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/grpc.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,8 @@ import com.squareup.wire.GrpcResponse import com.squareup.wire.GrpcStatus import com.squareup.wire.ProtoAdapter import com.squareup.wire.use +import java.io.Closeable +import java.util.Base64 import kotlinx.coroutines.CancellationException import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.channels.SendChannel @@ -33,8 +35,6 @@ import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody import okio.BufferedSink import okio.IOException -import java.io.Closeable -import java.util.Base64 internal val APPLICATION_GRPC_MEDIA_TYPE: MediaType = "application/grpc".toMediaType() @@ -42,7 +42,7 @@ internal val APPLICATION_GRPC_MEDIA_TYPE: MediaType = "application/grpc".toMedia internal fun newRequestBody( minMessageToCompress: Long, requestAdapter: ProtoAdapter, - onlyMessage: S + onlyMessage: S, ): RequestBody { return object : RequestBody() { override fun contentType() = APPLICATION_GRPC_MEDIA_TYPE @@ -74,7 +74,7 @@ internal fun newDuplexRequestBody(): PipeDuplexRequestBody { internal fun PipeDuplexRequestBody.messageSink( minMessageToCompress: Long, requestAdapter: ProtoAdapter, - callForCancel: Call + callForCancel: Call, ) = GrpcMessageSink( sink = createSink(), minMessageToCompress = minMessageToCompress, @@ -86,7 +86,7 @@ internal fun PipeDuplexRequestBody.messageSink( /** Sends the response messages to the channel. */ internal fun SendChannel.readFromResponseBodyCallback( grpcCall: RealGrpcStreamingCall<*, R>, - responseAdapter: ProtoAdapter + responseAdapter: ProtoAdapter, ): Callback { return object : Callback { override fun onFailure(call: Call, e: IOException) { @@ -141,7 +141,7 @@ internal suspend fun ReceiveChannel.writeToRequestBody( requestBody: PipeDuplexRequestBody, minMessageToCompress: Long, requestAdapter: ProtoAdapter, - callForCancel: Call + callForCancel: Call, ) { val requestWriter = requestBody.messageSink(minMessageToCompress, requestAdapter, callForCancel) try { @@ -168,7 +168,7 @@ internal suspend fun ReceiveChannel.writeToRequestBody( /** Reads messages from the response body. */ internal fun GrpcResponse.messageSource( - protoAdapter: ProtoAdapter + protoAdapter: ProtoAdapter, ): GrpcMessageSource { checkGrpcResponse() val grpcEncoding = header("grpc-encoding") @@ -210,7 +210,7 @@ internal fun GrpcResponse.grpcResponseToException(suppressed: IOException? = nul throw IOException( "gRPC transport failure, invalid grpc-status-details-bin" + " (HTTP status=$code, grpc-status=$grpcStatus, grpc-message=$grpcMessage)", - e + e, ) } } @@ -222,7 +222,7 @@ internal fun GrpcResponse.grpcResponseToException(suppressed: IOException? = nul return IOException( "gRPC transport failure" + " (HTTP status=$code, grpc-status=$grpcStatus, grpc-message=$grpcMessage)", - transportException + transportException, ) } diff --git a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/platform.kt b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/platform.kt index 7e78429a64..00f4efe20b 100644 --- a/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/platform.kt +++ b/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/internal/platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,15 +15,16 @@ */ package com.squareup.wire.internal +import java.lang.reflect.Method import okio.Sink import okio.Source import okio.gzip -import java.lang.reflect.Method actual typealias Call = okhttp3.Call @Suppress("NOTHING_TO_INLINE") internal actual inline fun Sink.asGzip(): Sink = gzip() + @Suppress("NOTHING_TO_INLINE") internal actual inline fun Source.asGzip(): Source = gzip() diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcClient.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcClient.kt index 77d0cd3048..cfd6b41d9f 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcClient.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcClient.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHeaders.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHeaders.kt index 36f75d003e..b31a389465 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHeaders.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHeaders.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt index 2bb9b89de7..69714cbf4d 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcHttpUrl.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequest.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequest.kt index f69dc65c31..fba5417072 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequest.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,11 +21,11 @@ actual open class GrpcRequestBuilder { actual open fun url(url: GrpcHttpUrl): GrpcRequestBuilder = TODO("Not yet implemented") actual open fun addHeader( name: String, - value: String + value: String, ): GrpcRequestBuilder = TODO("Not yet implemented") actual open fun method( method: String, - body: GrpcRequestBody? + body: GrpcRequestBody?, ): GrpcRequestBuilder = TODO("Not yet implemented") actual open fun build(): GrpcRequest = TODO("Not yet implemented") } diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequestBody.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequestBody.kt index 8892a872c9..64a54e1288 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequestBody.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcRequestBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponse.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponse.kt index 409fbaa0ce..f57c38a409 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponse.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponse.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,7 +21,7 @@ actual class GrpcResponse { actual fun header( name: String, - defaultValue: String? + defaultValue: String?, ): String? { TODO("Not yet implemented") } diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponseBody.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponseBody.kt index 8f610a9ed4..f46dc85c8b 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponseBody.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/GrpcResponseBody.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/internal/platform.kt b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/internal/platform.kt index e833c4009a..adf216d088 100644 --- a/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/internal/platform.kt +++ b/wire-grpc-client/src/nativeMain/kotlin/com/squareup/wire/internal/platform.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-mockwebserver/src/main/java/com/squareup/wire/mockwebserver/GrpcDispatcher.kt b/wire-grpc-mockwebserver/src/main/java/com/squareup/wire/mockwebserver/GrpcDispatcher.kt index 0adb7b69cc..2f5ce2ae76 100644 --- a/wire-grpc-mockwebserver/src/main/java/com/squareup/wire/mockwebserver/GrpcDispatcher.kt +++ b/wire-grpc-mockwebserver/src/main/java/com/squareup/wire/mockwebserver/GrpcDispatcher.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,6 +22,7 @@ import com.squareup.wire.ProtoAdapter import com.squareup.wire.Service import com.squareup.wire.internal.GrpcMessageSink import com.squareup.wire.internal.GrpcMessageSource +import java.lang.reflect.Method import okhttp3.Call import okhttp3.Callback import okhttp3.Headers.Companion.headersOf @@ -31,7 +32,6 @@ import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest import okio.Buffer import okio.Timeout -import java.lang.reflect.Method /** * Serves gRPC calls using MockWebServer over HTTP/2. @@ -129,7 +129,7 @@ class GrpcDispatcher( private fun dispatchGrpc( endpoint: Endpoint, - recordedRequest: RecordedRequest + recordedRequest: RecordedRequest, ): MockResponse { // TODO(oldergod): recover gracefully if the parameters don't decode to the expected types. @@ -152,19 +152,19 @@ class GrpcDispatcher( private fun decodeRequest( request: RecordedRequest, - protoAdapter: ProtoAdapter + protoAdapter: ProtoAdapter, ): S { val source = GrpcMessageSource( source = request.body, messageAdapter = protoAdapter, - grpcEncoding = request.headers["grpc-encoding"] + grpcEncoding = request.headers["grpc-encoding"], ) return source.readExactlyOneAndClose() } private fun encodeResponse( response: R, - protoAdapter: ProtoAdapter + protoAdapter: ProtoAdapter, ): Buffer { val result = Buffer() GrpcMessageSink( @@ -182,7 +182,7 @@ class GrpcDispatcher( private class Endpoint( val grpcMethod: GrpcMethod, val javaMethod: Method, - val service: Service + val service: Service, ) { @Suppress("UNCHECKED_CAST") // The GrpcCall type and GrpcMethod type always align. fun newGrpcCall(): GrpcCall = javaMethod.invoke(service) as GrpcCall diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterGenerator.kt index ecc123a275..294325b721 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,12 +15,17 @@ */ package com.squareup.wire.kotlin.grpcserver -import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.LambdaTypeName import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeSpec import com.squareup.wire.kotlin.grpcserver.ImplBaseGenerator.addImplBaseRpcSignature import com.squareup.wire.schema.Service import java.util.concurrent.ExecutorService -import kotlinx.coroutines.channels.Channel object BindableAdapterGenerator { @@ -28,13 +33,13 @@ object BindableAdapterGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { val serviceClassName = generator.classNameFor(service.type) val implBaseClassName = ClassName( serviceClassName.packageName, "${service.name}WireGrpc", - "${service.name}ImplBase" + "${service.name}ImplBase", ) return builder .addType( @@ -42,31 +47,34 @@ object BindableAdapterGenerator { .superclass(implBaseClassName) .primaryConstructor( FunSpec.constructorBuilder() - .apply { if (!options.suspendingCalls) { - // non suspending calls need an executor for the streaming calls - // suspending calls use CoroutineContext instead - this.addParameter( - name = "streamExecutor", - type = ExecutorService::class - ) - } } - + .apply { + if (!options.suspendingCalls) { + // non suspending calls need an executor for the streaming calls + // suspending calls use CoroutineContext instead + this.addParameter( + name = "streamExecutor", + type = ExecutorService::class, + ) + } + } .apply { addRpcConstructorParameters(generator, this, service, options) } - .build() + .build(), ) - .apply { if (!options.suspendingCalls) { - this.addProperty( - PropertySpec.builder("streamExecutor", ExecutorService::class) - .addModifiers(KModifier.PRIVATE) - .initializer("streamExecutor") - .build() - ) - } } + .apply { + if (!options.suspendingCalls) { + this.addProperty( + PropertySpec.builder("streamExecutor", ExecutorService::class) + .addModifiers(KModifier.PRIVATE) + .initializer("streamExecutor") + .build(), + ) + } + } .apply { addRpcProperties(generator, this, service, options) addRpcAdapterCodeBlocks(generator, this, service, options) } - .build() + .build(), ) } @@ -74,7 +82,7 @@ object BindableAdapterGenerator { generator: ClassNameGenerator, builder: FunSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): FunSpec.Builder { val serviceSuffix = if (options.suspendingCalls) { SUSPENDING_SERVER_SUFFIX @@ -88,9 +96,9 @@ object BindableAdapterGenerator { type = LambdaTypeName.get( returnType = ClassName( generator.classNameFor(service.type).packageName, - "${service.name}${rpc.name}${serviceSuffix}" - ) - ) + "${service.name}${rpc.name}$serviceSuffix", + ), + ), ) } } else { @@ -99,9 +107,9 @@ object BindableAdapterGenerator { type = LambdaTypeName.get( returnType = ClassName( generator.classNameFor(service.type).packageName, - "${service.name}${serviceSuffix}" - ) - ) + "${service.name}$serviceSuffix", + ), + ), ) } return builder @@ -111,7 +119,7 @@ object BindableAdapterGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { val serviceSuffix = if (options.suspendingCalls) { SUSPENDING_SERVER_SUFFIX @@ -126,13 +134,13 @@ object BindableAdapterGenerator { type = LambdaTypeName.get( returnType = ClassName( generator.classNameFor(service.type).packageName, - "${service.name}${rpc.name}${serviceSuffix}" - ) - ) + "${service.name}${rpc.name}$serviceSuffix", + ), + ), ) .initializer(rpc.name) .addModifiers(KModifier.PRIVATE) - .build() + .build(), ) } } else { @@ -142,13 +150,13 @@ object BindableAdapterGenerator { type = LambdaTypeName.get( returnType = ClassName( generator.classNameFor(service.type).packageName, - "${service.name}${serviceSuffix}" - ) - ) + "${service.name}$serviceSuffix", + ), + ), ) .initializer(SERVICE_CONSTRUCTOR_ARGUMENT) .addModifiers(KModifier.PRIVATE) - .build() + .build(), ) } return builder @@ -158,7 +166,7 @@ object BindableAdapterGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { service.rpcs.forEach { rpc -> val serviceProviderName = if (options.singleMethodServices) { @@ -170,16 +178,25 @@ object BindableAdapterGenerator { val codeBlock = if (options.suspendingCalls) { when { !rpc.requestStreaming && !rpc.responseStreaming -> CodeBlock.of( - "return ${serviceProviderName}().${rpc.name}(request)" + "return $serviceProviderName().${rpc.name}(request)", ) !rpc.requestStreaming -> CodeBlock.of( - "return %T.serverStream(context, request, %L()::%L)", FlowAdapter::class, serviceProviderName, rpc.name + "return %T.serverStream(context, request, %L()::%L)", + FlowAdapter::class, + serviceProviderName, + rpc.name, ) !rpc.responseStreaming -> CodeBlock.of( - "return %T.clientStream(context, request, %L()::%L)", FlowAdapter::class, serviceProviderName, rpc.name + "return %T.clientStream(context, request, %L()::%L)", + FlowAdapter::class, + serviceProviderName, + rpc.name, ) else -> CodeBlock.of( - "return %T.bidiStream(context, request, %L()::%L)", FlowAdapter::class, serviceProviderName, rpc.name + "return %T.bidiStream(context, request, %L()::%L)", + FlowAdapter::class, + serviceProviderName, + rpc.name, ) } } else { @@ -189,40 +206,44 @@ object BindableAdapterGenerator { """ |val requestStream = %T() |streamExecutor.submit { - | ${serviceProviderName}().${rpc.name}(requestStream, %T(response)) + | $serviceProviderName().${rpc.name}(requestStream, %T(response)) |} |return requestStream - |""".trimMargin(), + | + """.trimMargin(), ClassName("com.squareup.wire.kotlin.grpcserver", "MessageSourceAdapter") .parameterizedBy(generator.classNameFor(rpc.requestType!!)), - responseAdapter + responseAdapter, ) rpc.requestStreaming -> CodeBlock.of( """ |val requestStream = %T() |streamExecutor.submit { - | response.onNext(${serviceProviderName}().${rpc.name}(requestStream)) + | response.onNext($serviceProviderName().${rpc.name}(requestStream)) | response.onCompleted() |} |return requestStream - |""".trimMargin(), + | + """.trimMargin(), ClassName("com.squareup.wire.kotlin.grpcserver", "MessageSourceAdapter") - .parameterizedBy(generator.classNameFor(rpc.requestType!!)) + .parameterizedBy(generator.classNameFor(rpc.requestType!!)), ) rpc.responseStreaming -> CodeBlock.of( """ - |${serviceProviderName}().${rpc.name}(request, %T(response)) - |""".trimMargin(), - responseAdapter + |$serviceProviderName().${rpc.name}(request, %T(response)) + | + """.trimMargin(), + responseAdapter, ) else -> CodeBlock.of( """ - |response.onNext(${serviceProviderName}().${rpc.name}(request)) + |response.onNext($serviceProviderName().${rpc.name}(request)) |response.onCompleted() - |""".trimMargin() + | + """.trimMargin(), ) } } @@ -232,7 +253,7 @@ object BindableAdapterGenerator { .apply { addImplBaseRpcSignature(generator, this, rpc, options) } .apply { if (options.suspendingCalls && !rpc.responseStreaming) { addModifiers(KModifier.SUSPEND) } } .addCode(codeBlock) - .build() + .build(), ) } return builder diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BlockingStubGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BlockingStubGenerator.kt index 1e6ee0bb46..f8c9636d26 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BlockingStubGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/BlockingStubGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,14 +31,14 @@ object BlockingStubGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { if (!options.suspendingCalls) { val serviceClassName = generator.classNameFor(service.type) val stubClassName = ClassName( packageName = serviceClassName.packageName, "${serviceClassName.simpleName}WireGrpc", - "${serviceClassName.simpleName}BlockingStub" + "${serviceClassName.simpleName}BlockingStub", ) return builder .addFunction( @@ -46,14 +46,20 @@ object BlockingStubGenerator { .addParameter("channel", ClassName("io.grpc", "Channel")) .returns(stubClassName) .addCode("return %T(channel)", stubClassName) - .build() + .build(), ) .addType( TypeSpec.classBuilder(stubClassName) - .apply { addAbstractStubConstructor(generator, this, service, - ClassName("io.grpc.stub", "AbstractStub")) } + .apply { + addAbstractStubConstructor( + generator, + this, + service, + ClassName("io.grpc.stub", "AbstractStub"), + ) + } .addBlockingStubRpcCalls(generator, service) - .build() + .build(), ) } else { return builder @@ -68,15 +74,18 @@ object BlockingStubGenerator { "return %M(channel, get${rpc.name}Method(), callOptions, request)", MemberName( enclosingClassName = ClassName("io.grpc.stub", "ClientCalls"), - simpleName = if (rpc.requestStreaming) "blockingServerStreamingCall" - else "blockingUnaryCall" - ) + simpleName = if (rpc.requestStreaming) { + "blockingServerStreamingCall" + } else { + "blockingUnaryCall" + }, + ), ) this.addFunction( FunSpec.builder(rpc.name) .addBlockingStubSignature(generator, rpc) .addCode(codeBlock) - .build() + .build(), ) } return this @@ -85,9 +94,11 @@ object BlockingStubGenerator { private fun FunSpec.Builder.addBlockingStubSignature(generator: ClassNameGenerator, rpc: Rpc): FunSpec.Builder = this .addParameter("request", ClassName.bestGuess(generator.classNameFor(rpc.requestType!!).toString())) .returns( - if (rpc.requestStreaming) + if (rpc.requestStreaming) { Iterator::class.asClassName() .parameterizedBy(generator.classNameFor(rpc.responseType!!)) - else generator.classNameFor(rpc.responseType!!) + } else { + generator.classNameFor(rpc.responseType!!) + }, ) } diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ClassNameGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ClassNameGenerator.kt index d506790104..7d6ae2791d 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ClassNameGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ClassNameGenerator.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.kotlin.grpcserver import com.squareup.kotlinpoet.ClassName @@ -9,7 +24,7 @@ internal class ClassNameGenerator(private val typeToKotlinName: Map) { builder.addProperty( PropertySpec - .builder("descriptorMap", Map::class.parameterizedBy( - String::class, DescriptorProtos.FileDescriptorProto::class - ) + .builder( + "descriptorMap", + Map::class.parameterizedBy( + String::class, + DescriptorProtos.FileDescriptorProto::class, + ), ) .addModifiers(KModifier.PRIVATE) .initializer( @@ -86,8 +89,8 @@ object FileDescriptorGenerator { } }.addStatement(")),") } - }.addStatement(")").build() - ).build() + }.addStatement(")").build(), + ).build(), ) } @@ -104,8 +107,8 @@ object FileDescriptorGenerator { val proto = descriptorMap[path]!! val deps = proto.dependencyList.filter { !visited.contains(it) }.map { fileDescriptor(it, visited + path) } return Descriptors.FileDescriptor.buildFrom(proto, deps.toTypedArray()) - """.trimIndent() - ).build() + """.trimIndent(), + ).build(), ) } @@ -121,8 +124,8 @@ object FileDescriptorGenerator { val str = data.fold(java.lang.StringBuilder()) { b, s -> b.append(s) }.toString() val bytes = java.util.Base64.getDecoder().decode(str) return DescriptorProtos.FileDescriptorProto.parseFrom(bytes) - """.trimIndent() - ).build() + """.trimIndent(), + ).build(), ) } diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ImplBaseGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ImplBaseGenerator.kt index c843957467..19ad8b1e02 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ImplBaseGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ImplBaseGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,7 +39,7 @@ object ImplBaseGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ) = builder .addType( TypeSpec.classBuilder("${service.name}ImplBase") @@ -47,7 +47,7 @@ object ImplBaseGenerator { .addSuperinterface(WireBindableService::class) .apply { addImplBaseConstructor(options) } .apply { addImplBaseBody(generator, this, service, options) } - .build() + .build(), ) private fun TypeSpec.Builder.addImplBaseConstructor(options: KotlinGrpcGenerator.Companion.Options) { @@ -59,14 +59,14 @@ object ImplBaseGenerator { .defaultValue( CodeBlock.builder() .addStatement("kotlin.coroutines.EmptyCoroutineContext") - .build() - ).build() + .build(), + ).build(), ) - .build() + .build(), ).addProperty( PropertySpec.builder("context", CoroutineContext::class, KModifier.PROTECTED) .initializer("context") - .build() + .build(), ) } } @@ -75,7 +75,7 @@ object ImplBaseGenerator { generator: ClassNameGenerator, builder: FunSpec.Builder, rpc: Rpc, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): FunSpec.Builder { val rpcRequestType = generator.classNameFor(rpc.requestType!!) val rpcResponseType = generator.classNameFor(rpc.responseType!!) @@ -96,17 +96,19 @@ object ImplBaseGenerator { rpc.requestStreaming -> builder .addParameter( - "response", ClassName("io.grpc.stub", "StreamObserver").parameterizedBy(rpcResponseType) + "response", + ClassName("io.grpc.stub", "StreamObserver").parameterizedBy(rpcResponseType), ) .returns( - ClassName("io.grpc.stub", "StreamObserver").parameterizedBy(rpcRequestType) + ClassName("io.grpc.stub", "StreamObserver").parameterizedBy(rpcRequestType), ) else -> builder .addParameter("request", rpcRequestType) .addParameter( - "response", ClassName("io.grpc.stub", "StreamObserver").parameterizedBy(rpcResponseType) + "response", + ClassName("io.grpc.stub", "StreamObserver").parameterizedBy(rpcResponseType), ) .returns(UNIT) } @@ -117,7 +119,7 @@ object ImplBaseGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { service.rpcs.forEach { rpc -> builder.addFunction( @@ -126,7 +128,7 @@ object ImplBaseGenerator { .apply { addImplBaseRpcSignature(generator, this, rpc, options) } .apply { if (options.suspendingCalls && !rpc.responseStreaming) { addModifiers(KModifier.SUSPEND) } } .addCode(CodeBlock.of("throw %T()", UnsupportedOperationException::class.java)) - .build() + .build(), ) } @@ -135,7 +137,7 @@ object ImplBaseGenerator { .addModifiers(KModifier.OVERRIDE) .returns(ClassName("io.grpc", "ServerServiceDefinition")) .addCode(bindServiceCodeBlock(service, options)) - .build() + .build(), ) service.rpcs @@ -152,14 +154,14 @@ object ImplBaseGenerator { .addParameter(ParameterSpec(name = "value", type = className)) .returns(InputStream::class) .addCode(streamCodeFor(it, className)) - .build() + .build(), ) .addFunction( FunSpec.builder("marshalledClass") .addModifiers(KModifier.OVERRIDE) .returns(Class::class.asClassName().parameterizedBy(className)) .addCode(CodeBlock.of("return %T::class.java", className)) - .build() + .build(), ) .addFunction( FunSpec.builder("parse") @@ -167,9 +169,9 @@ object ImplBaseGenerator { .addParameter("stream", InputStream::class) .returns(className) .addCode(parseCodeFor(it, className)) - .build() + .build(), ) - .build() + .build(), ) } @@ -224,8 +226,8 @@ object ImplBaseGenerator { implementation = this@${service.name}ImplBase::${it.name}, ) ) - """.trimIndent(), - MemberName(ClassName("io.grpc.stub", "ServerCalls"), bindServiceCallType(it)) + """.trimIndent(), + MemberName(ClassName("io.grpc.stub", "ServerCalls"), bindServiceCallType(it)), ) } else { codeBlock.add( @@ -233,8 +235,8 @@ object ImplBaseGenerator { get${it.name}Method(), %M(this@${service.name}ImplBase::${it.name}) ) - """.trimIndent(), - MemberName(ClassName("io.grpc.stub", "ServerCalls"), bindServiceCallType(it)) + """.trimIndent(), + MemberName(ClassName("io.grpc.stub", "ServerCalls"), bindServiceCallType(it)), ) } } diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGenerator.kt index 2694e89d94..8e7082ccdb 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,9 +18,9 @@ package com.squareup.wire.kotlin.grpcserver import com.squareup.kotlinpoet.ClassName import com.squareup.kotlinpoet.TypeName import com.squareup.kotlinpoet.TypeSpec +import com.squareup.wire.kotlin.grpcserver.BindableAdapterGenerator.addBindableAdapter import com.squareup.wire.kotlin.grpcserver.BlockingStubGenerator.addBlockingStub import com.squareup.wire.kotlin.grpcserver.ImplBaseGenerator.addImplBase -import com.squareup.wire.kotlin.grpcserver.BindableAdapterGenerator.addBindableAdapter import com.squareup.wire.kotlin.grpcserver.MethodDescriptorGenerator.addMethodDescriptor import com.squareup.wire.kotlin.grpcserver.ServiceDescriptorGenerator.addServiceDescriptor import com.squareup.wire.kotlin.grpcserver.StubGenerator.addStub @@ -33,7 +33,7 @@ class KotlinGrpcGenerator( private val typeToKotlinName: Map, private val singleMethodServices: Boolean, private val suspendingCalls: Boolean, - ) { +) { fun generateGrpcServer(service: Service, protoFile: ProtoFile?, schema: Schema): Pair { val options = Options( singleMethodServices = singleMethodServices, diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorGenerator.kt index 87a7707066..69acc27bfa 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -30,7 +30,7 @@ object MethodDescriptorGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - rpc: Rpc + rpc: Rpc, ): TypeSpec.Builder { val requestType = generator.classNameFor(rpc.requestType!!) val responseType = generator.classNameFor(rpc.responseType!!) @@ -39,32 +39,32 @@ object MethodDescriptorGenerator { PropertySpec.builder( name = "get${rpc.name}Method", type = methodDescriptorType(requestType, responseType).copy(nullable = true), - modifiers = listOf(KModifier.PRIVATE) + modifiers = listOf(KModifier.PRIVATE), ) .mutable(true) .addAnnotation(Volatile::class) .initializer("null") - .build() + .build(), ) .addFunction( FunSpec.builder("get${rpc.name}Method") .returns(methodDescriptorType(requestType, responseType)) .addCode(methodDescriptorCodeBlock(generator, service, rpc)) - .build() + .build(), ) } private fun methodDescriptorCodeBlock( generator: ClassNameGenerator, service: Service, - rpc: Rpc + rpc: Rpc, ): CodeBlock { val requestType = generator.classNameFor(rpc.requestType!!) val responseType = generator.classNameFor(rpc.responseType!!) val codeBlock = CodeBlock.builder() codeBlock.addStatement( "var result: %T = get${rpc.name}Method", - methodDescriptorType(requestType, responseType).copy(nullable = true) + methodDescriptorType(requestType, responseType).copy(nullable = true), ) codeBlock.add( """ @@ -89,14 +89,14 @@ object MethodDescriptorGenerator { return get${rpc.name}Method!! """.trimIndent(), requestType, - responseType + responseType, ) return codeBlock.build() } private fun methodDescriptorType( requestType: ClassName, - responseType: ClassName + responseType: ClassName, ) = ClassName("io.grpc", "MethodDescriptor").parameterizedBy(requestType, responseType) private fun methodType(rpc: Rpc): String = when { diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorGenerator.kt index e42b256ea0..adda6eb6a2 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -37,10 +37,10 @@ object ServiceDescriptorGenerator { PropertySpec.builder( name = "SERVICE_NAME", type = String::class, - modifiers = emptyList() + modifiers = emptyList(), ) .initializer("\"${service.type}\"") - .build() + .build(), ) .addProperty( PropertySpec.builder( @@ -51,14 +51,14 @@ object ServiceDescriptorGenerator { .addAnnotation(Volatile::class) .initializer("null") .mutable(true) - .build() + .build(), ) .apply { FileDescriptorGenerator.addDescriptorDataProperty(this, protoFile, schema) } .addFunction( FunSpec.builder("getServiceDescriptor") .returns(ClassName("io.grpc", "ServiceDescriptor").copy(nullable = true)) .addCode(serviceDescriptorCodeBlock(service, protoFile)) - .build() + .build(), ) private fun serviceDescriptorCodeBlock(service: Service, protoFile: ProtoFile?): CodeBlock { @@ -82,15 +82,17 @@ object ServiceDescriptorGenerator { "result = %M(SERVICE_NAME)", MemberName( enclosingClassName = ClassName("io.grpc", "ServiceDescriptor"), - simpleName = "newBuilder" - ) + simpleName = "newBuilder", + ), ) service.rpcs.forEach { builder.addStatement(".addMethod(get${it.name}Method())") } - if (protoFile != null){ - builder.addStatement(""" + if (protoFile != null) { + builder.addStatement( + """ .setSchemaDescriptor(io.grpc.protobuf.ProtoFileDescriptorSupplier { fileDescriptor("${protoFile.location.path}", emptySet()) - })""".trimIndent() + }) + """.trimIndent(), ) } builder diff --git a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/StubGenerator.kt b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/StubGenerator.kt index 7f254d0286..c98edd8ad1 100644 --- a/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/StubGenerator.kt +++ b/wire-grpc-server-generator/src/main/java/com/squareup/wire/kotlin/grpcserver/StubGenerator.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,8 +15,13 @@ */ package com.squareup.wire.kotlin.grpcserver -import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.CodeBlock +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.MemberName import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.TypeSpec import com.squareup.wire.kotlin.grpcserver.ImplBaseGenerator.addImplBaseRpcSignature import com.squareup.wire.schema.Rpc import com.squareup.wire.schema.Service @@ -26,7 +31,7 @@ object StubGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { return if (options.suspendingCalls) { suspendedStubs(generator, service, builder, options) @@ -39,12 +44,13 @@ object StubGenerator { generator: ClassNameGenerator, service: Service, builder: TypeSpec.Builder, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { val serviceClassName = generator.classNameFor(service.type) val stubClassName = ClassName( packageName = serviceClassName.packageName, - "${serviceClassName.simpleName}WireGrpc", "${serviceClassName.simpleName}Stub" + "${serviceClassName.simpleName}WireGrpc", + "${serviceClassName.simpleName}Stub", ) return builder .addFunction( @@ -52,16 +58,20 @@ object StubGenerator { .addParameter("channel", ClassName("io.grpc", "Channel")) .returns(stubClassName) .addCode("return %T(channel)", stubClassName) - .build() + .build(), ) .addType( TypeSpec.classBuilder(stubClassName) .apply { - addAbstractStubConstructor(generator, this, service, - ClassName("io.grpc.kotlin", "AbstractCoroutineStub")) + addAbstractStubConstructor( + generator, + this, + service, + ClassName("io.grpc.kotlin", "AbstractCoroutineStub"), + ) addSuspendedStubRpcCalls(generator, this, service, options) } - .build() + .build(), ) } @@ -69,12 +79,13 @@ object StubGenerator { generator: ClassNameGenerator, service: Service, builder: TypeSpec.Builder, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { val serviceClassName = generator.classNameFor(service.type) val stubClassName = ClassName( packageName = serviceClassName.packageName, - "${serviceClassName.simpleName}WireGrpc", "${serviceClassName.simpleName}Stub" + "${serviceClassName.simpleName}WireGrpc", + "${serviceClassName.simpleName}Stub", ) return builder .addFunction( @@ -82,7 +93,7 @@ object StubGenerator { .addParameter("channel", ClassName("io.grpc", "Channel")) .returns(stubClassName) .addCode("return %T(channel)", stubClassName) - .build() + .build(), ) .addType( TypeSpec.classBuilder(stubClassName) @@ -90,7 +101,7 @@ object StubGenerator { addAbstractStubConstructor(generator, this, service, ClassName("io.grpc.stub", "AbstractStub")) addStubRpcCalls(generator, this, service, options) } - .build() + .build(), ) } @@ -98,12 +109,13 @@ object StubGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - superClass: ClassName + superClass: ClassName, ): TypeSpec.Builder { val serviceClassName = generator.classNameFor(service.type) val stubClassName = ClassName( packageName = serviceClassName.packageName, - "${serviceClassName.simpleName}WireGrpc", "${serviceClassName.simpleName}Stub" + "${serviceClassName.simpleName}WireGrpc", + "${serviceClassName.simpleName}Stub", ) return builder // Really this is a superclass, just want to add secondary constructors. @@ -113,7 +125,7 @@ object StubGenerator { .addModifiers(KModifier.INTERNAL) .addParameter("channel", ClassName("io.grpc", "Channel")) .callSuperConstructor("channel") - .build() + .build(), ) .addFunction( FunSpec.constructorBuilder() @@ -121,7 +133,7 @@ object StubGenerator { .addParameter("channel", ClassName("io.grpc", "Channel")) .addParameter("callOptions", ClassName("io.grpc", "CallOptions")) .callSuperConstructor("channel", "callOptions") - .build() + .build(), ) .addFunction( FunSpec.builder("build") @@ -130,7 +142,7 @@ object StubGenerator { .addParameter("callOptions", ClassName("io.grpc", "CallOptions")) .addStatement("return ${service.name}Stub(channel, callOptions)") .returns(ClassName("", "${service.name}Stub")) - .build() + .build(), ) } @@ -138,26 +150,26 @@ object StubGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { service.rpcs.forEach { rpc -> val codeBlock = when { rpc.requestStreaming -> CodeBlock.of( "return %M(channel.newCall(get${rpc.name}Method(), callOptions), response)", - MemberName(ClassName("io.grpc.stub", "ClientCalls"), clientCallType(rpc)) + MemberName(ClassName("io.grpc.stub", "ClientCalls"), clientCallType(rpc)), ) else -> CodeBlock.of( "%M(channel.newCall(get${rpc.name}Method(), callOptions), request, response)", - MemberName(ClassName("io.grpc.stub", "ClientCalls"), clientCallType(rpc)) + MemberName(ClassName("io.grpc.stub", "ClientCalls"), clientCallType(rpc)), ) } builder.addFunction( FunSpec.builder(rpc.name) .apply { addImplBaseRpcSignature(generator, this, rpc, options) } .addCode(codeBlock) - .build() + .build(), ) } return builder @@ -167,19 +179,19 @@ object StubGenerator { generator: ClassNameGenerator, builder: TypeSpec.Builder, service: Service, - options: KotlinGrpcGenerator.Companion.Options + options: KotlinGrpcGenerator.Companion.Options, ): TypeSpec.Builder { service.rpcs.forEach { rpc -> val codeBlock = CodeBlock.of( "return %M(channel, get${rpc.name}Method(), request, callOptions)", - MemberName(ClassName("io.grpc.kotlin", "ClientCalls"), suspendedClientCallType(rpc)) + MemberName(ClassName("io.grpc.kotlin", "ClientCalls"), suspendedClientCallType(rpc)), ) builder.addFunction( FunSpec.builder(rpc.name) .apply { addImplBaseRpcSignature(generator, this, rpc, options) } .addModifiers(KModifier.SUSPEND) .addCode(codeBlock) - .build() + .build(), ) } return builder diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterTest.kt index c7a91584b2..7d1071b732 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/BindableAdapterTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,14 +19,10 @@ import com.squareup.kotlinpoet.FileSpec import com.squareup.kotlinpoet.TypeSpec import com.squareup.wire.buildSchema import com.squareup.wire.kotlin.grpcserver.BindableAdapterGenerator.addBindableAdapter -import com.squareup.wire.schema.addLocal import com.squareup.wire.kotlin.grpcserver.GoldenTestUtils.assertFileEquals -import java.io.File +import com.squareup.wire.schema.addLocal import kotlin.test.assertEquals import okio.Path.Companion.toPath -import okio.buffer -import okio.source -import org.assertj.core.api.Assertions import org.junit.Test class BindableAdapterTest { @@ -47,7 +43,7 @@ class BindableAdapterTest { KotlinGrpcGenerator.Companion.Options(singleMethodServices = true, suspendingCalls = false), ) } - .build() + .build(), ) .build() @@ -56,7 +52,10 @@ class BindableAdapterTest { @Test fun `works on suspending streaming responses`() { - val code = bindableCodeFor("test", "TestService", """ + val code = bindableCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -64,8 +63,10 @@ class BindableAdapterTest { service TestService { rpc TestRPC(Test) returns (stream Test){} } - """.trimMargin()) - assertEquals(""" + """.trimMargin(), + ) + assertEquals( + """ package test import com.squareup.wire.kotlin.grpcserver.FlowAdapter @@ -79,12 +80,17 @@ class BindableAdapterTest { service()::TestRPC) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } @Test fun `works on suspending streaming requests`() { - val code = bindableCodeFor("test", "TestService", """ + val code = bindableCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -92,8 +98,10 @@ class BindableAdapterTest { service TestService { rpc TestRPC(stream Test) returns (Test){} } - """.trimMargin()) - assertEquals(""" + """.trimMargin(), + ) + assertEquals( + """ package test import com.squareup.wire.kotlin.grpcserver.FlowAdapter @@ -107,12 +115,17 @@ class BindableAdapterTest { request, service()::TestRPC) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } @Test fun `works on suspending streaming bidi rpcs`() { - val code = bindableCodeFor("test", "TestService", """ + val code = bindableCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -120,8 +133,10 @@ class BindableAdapterTest { service TestService { rpc TestRPC(stream Test) returns (stream Test){} } - """.trimMargin()) - assertEquals(""" + """.trimMargin(), + ) + assertEquals( + """ package test import com.squareup.wire.kotlin.grpcserver.FlowAdapter @@ -135,12 +150,17 @@ class BindableAdapterTest { service()::TestRPC) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } @Test fun `works on suspending streaming bidi rpcs with single method services`() { - val code = bindableCodeFor("test", "TestService", """ + val code = bindableCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -148,11 +168,14 @@ class BindableAdapterTest { service TestService { rpc TestRPC(stream Test) returns (stream Test){} } - """.trimMargin(), KotlinGrpcGenerator.Companion.Options( - singleMethodServices = true, - suspendingCalls = true - )) - assertEquals(""" + """.trimMargin(), + KotlinGrpcGenerator.Companion.Options( + singleMethodServices = true, + suspendingCalls = true, + ), + ) + assertEquals( + """ package test import com.squareup.wire.kotlin.grpcserver.FlowAdapter @@ -166,14 +189,20 @@ class BindableAdapterTest { TestRPC()::TestRPC) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } - private fun bindableCodeFor(pkg: String, serviceName: String, schemaCode: String, - options: KotlinGrpcGenerator.Companion.Options = KotlinGrpcGenerator.Companion.Options( - singleMethodServices = false, - suspendingCalls = true - )): String { + private fun bindableCodeFor( + pkg: String, + serviceName: String, + schemaCode: String, + options: KotlinGrpcGenerator.Companion.Options = KotlinGrpcGenerator.Companion.Options( + singleMethodServices = false, + suspendingCalls = true, + ), + ): String { val schema = buildSchema { add("test.proto".toPath(), schemaCode) } val service = schema.getService("$pkg.$serviceName")!! val typeSpec = TypeSpec.classBuilder("${serviceName}WireGrpc") @@ -188,4 +217,3 @@ class BindableAdapterTest { .trim() } } - diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/FileDescriptorGeneratorTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/FileDescriptorGeneratorTest.kt index 3b634b00fd..d5dac74168 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/FileDescriptorGeneratorTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/FileDescriptorGeneratorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,11 +24,11 @@ import com.squareup.kotlinpoet.TypeSpec import com.squareup.wire.buildSchema import com.squareup.wire.schema.Pruner import com.squareup.wire.schema.PruningRules -import okio.Path.Companion.toPath -import org.junit.Test import javax.script.ScriptEngineManager import kotlin.test.assertEquals +import okio.Path.Companion.toPath import org.assertj.core.api.Assertions +import org.junit.Test internal class FileDescriptorGeneratorTest { private data class Schema(val path: String, val content: String) @@ -38,31 +38,36 @@ internal class FileDescriptorGeneratorTest { val descriptor = descriptorFor( "test.proto", PruningRules.Builder(), - Schema("test.proto", - """ + Schema( + "test.proto", + """ |syntax = "proto2"; | |package test; |import "imported.proto"; | |message Test {} - |""".trimMargin() - ), Schema( - "imported.proto", - """ + | + """.trimMargin(), + ), + Schema( + "imported.proto", + """ |syntax = "proto2"; | |package test; | |message Imported {} - |""".trimMargin() - )) + | + """.trimMargin(), + ), + ) assertEquals("test", descriptor.`package`) assertEquals("test.proto", descriptor.name) assertEquals(descriptor.messageTypes.size, 1) assertEquals("Test", descriptor.messageTypes.first().name) - assertEquals( 1, descriptor.dependencies.size) + assertEquals(1, descriptor.dependencies.size) } @Test @@ -70,8 +75,9 @@ internal class FileDescriptorGeneratorTest { val descriptor = descriptorFor( "test.proto", PruningRules.Builder().addRoot("test.Caller"), - Schema("test.proto", - """ + Schema( + "test.proto", + """ |syntax = "proto2"; |package test; | @@ -85,8 +91,10 @@ internal class FileDescriptorGeneratorTest { |message Caller { | optional Test.Nested field = 1; |} - |""".trimMargin() - )) + | + """.trimMargin(), + ), + ) Assertions.assertThat(descriptor.toProto()).isEqualTo( DescriptorProtos.FileDescriptorProto.newBuilder() @@ -97,22 +105,24 @@ internal class FileDescriptorGeneratorTest { .setName("Test") .addEnumType( DescriptorProtos.EnumDescriptorProto.newBuilder() - .setName("Nested") - .addValue(0, DescriptorProtos.EnumValueDescriptorProto.newBuilder().setName("NESTED_UNDEFINED").setNumber(0)) - .addValue(1, DescriptorProtos.EnumValueDescriptorProto.newBuilder().setName("NESTED_DEFINED").setNumber(1)) - ) + .setName("Nested") + .addValue(0, DescriptorProtos.EnumValueDescriptorProto.newBuilder().setName("NESTED_UNDEFINED").setNumber(0)) + .addValue(1, DescriptorProtos.EnumValueDescriptorProto.newBuilder().setName("NESTED_DEFINED").setNumber(1)), + ), ) - .addMessageType(DescriptorProtos.DescriptorProto.newBuilder() - .setName("Caller") - .addField(DescriptorProtos.FieldDescriptorProto.newBuilder() - .setName("field") - .setNumber(1) - .setTypeName(".test.Test.Nested") - .setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_ENUM) - .setLabel(Label.LABEL_OPTIONAL) - ) + .addMessageType( + DescriptorProtos.DescriptorProto.newBuilder() + .setName("Caller") + .addField( + DescriptorProtos.FieldDescriptorProto.newBuilder() + .setName("field") + .setNumber(1) + .setTypeName(".test.Test.Nested") + .setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_ENUM) + .setLabel(Label.LABEL_OPTIONAL), + ), ) - .build() + .build(), ) } @@ -126,13 +136,16 @@ internal class FileDescriptorGeneratorTest { val pruned = pruner.prune() val protoFile = pruned.protoFile(schemas.first().path.toPath()) val file = FileSpec.scriptBuilder("test", "test.kts") - .addType(TypeSpec.classBuilder("Test") - .apply { FileDescriptorGenerator.addDescriptorDataProperty(this, protoFile, pruned) } - .addFunction(FunSpec.builder("output") - .returns(Descriptors.FileDescriptor::class) - .addCode("return fileDescriptor(\"$fileName\", emptySet())") - .build()) - .build() + .addType( + TypeSpec.classBuilder("Test") + .apply { FileDescriptorGenerator.addDescriptorDataProperty(this, protoFile, pruned) } + .addFunction( + FunSpec.builder("output") + .returns(Descriptors.FileDescriptor::class) + .addCode("return fileDescriptor(\"$fileName\", emptySet())") + .build(), + ) + .build(), ).addCode("Test().output()").build() val engine = ScriptEngineManager().getEngineByExtension("kts") diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt index 48486812a1..eb720a238f 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GoldenTestUtils.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GrpcGeneratorHelpers.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GrpcGeneratorHelpers.kt index 06e08567ab..7b99589ecb 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GrpcGeneratorHelpers.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/GrpcGeneratorHelpers.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.kotlin.grpcserver import com.squareup.kotlinpoet.ClassName @@ -19,13 +34,13 @@ internal fun buildClassMap(schema: Schema, service: Service): Map + types: List, ): List> { return types.map { type -> val className = enclosingClassName?.nestedClass(type.type.simpleName) diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ImplBaseTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ImplBaseTest.kt index 35fabcd0c9..08c5f4d461 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ImplBaseTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ImplBaseTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,11 +39,11 @@ class ImplBaseTest { service = service, options = KotlinGrpcGenerator.Companion.Options( singleMethodServices = false, - suspendingCalls = false - ) + suspendingCalls = false, + ), ) } - .build() + .build(), ) .build() diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGeneratorTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGeneratorTest.kt index 5d982983de..83e5bbc48b 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGeneratorTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/KotlinGrpcGeneratorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,7 +32,7 @@ internal class KotlinGrpcGeneratorTest { val (_, typeSpec) = KotlinGrpcGenerator( buildClassMap(schema, service!!), singleMethodServices = true, - suspendingCalls = false + suspendingCalls = false, ).generateGrpcServer(service, schema.protoFile(path), schema) val output = FileSpec.get("routeguide", typeSpec) @@ -52,7 +52,8 @@ internal class KotlinGrpcGeneratorTest { | rpc Call1(Request) returns (Response) {} | rpc Call2(Request) returns (Response) {} |} - |""".trimMargin() + | + """.trimMargin() @Test fun `correctly generates singleMethodService = false adapters`() { @@ -62,7 +63,7 @@ internal class KotlinGrpcGeneratorTest { val (_, typeSpec) = KotlinGrpcGenerator( buildClassMap(schema, service!!), singleMethodServices = false, - suspendingCalls = false + suspendingCalls = false, ).generateGrpcServer(service, schema.protoFile(path), schema) val output = FileSpec.get("com.foo.bar", typeSpec) @@ -77,7 +78,7 @@ internal class KotlinGrpcGeneratorTest { val (_, typeSpec) = KotlinGrpcGenerator( buildClassMap(schema, service!!), singleMethodServices = true, - suspendingCalls = false + suspendingCalls = false, ).generateGrpcServer(service, schema.protoFile(path), schema) val output = FileSpec.get("com.foo.bar", typeSpec) @@ -87,19 +88,24 @@ internal class KotlinGrpcGeneratorTest { @Test fun `correctly generates adapters for Unit return values`() { val path = "service.proto".toPath() - val schema = buildSchema { add(path, """ + val schema = buildSchema { + add( + path, + """ syntax = "proto3"; import "google/protobuf/empty.proto"; service MyService { rpc doSomething(google.protobuf.Empty) returns (google.protobuf.Empty); } - """.trimIndent()) } + """.trimIndent(), + ) + } val service = schema.getService("MyService") val (_, typeSpec) = KotlinGrpcGenerator( buildClassMap(schema, service!!), singleMethodServices = false, - suspendingCalls = true + suspendingCalls = true, ).generateGrpcServer(service, schema.protoFile(path), schema) val output = FileSpec.get("", typeSpec) diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorTest.kt index c582d2fb20..7606fecb24 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/MethodDescriptorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,10 +38,10 @@ class MethodDescriptorTest { generator = ClassNameGenerator(buildClassMap(schema, service!!)), builder = this, service = service, - rpc = service.rpc("GetFeature")!! + rpc = service.rpc("GetFeature")!!, ) } - .build() + .build(), ) .build() diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorTest.kt index dc6b029d0e..710a3bde67 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/ServiceDescriptorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -36,7 +36,7 @@ class ServiceDescriptorTest { .apply { ServiceDescriptorGenerator.addServiceDescriptor(this, service!!, schema.protoFile(path), schema) } - .build() + .build(), ) .build() diff --git a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/StubTest.kt b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/StubTest.kt index 8c0af3eb87..5965267bb4 100644 --- a/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/StubTest.kt +++ b/wire-grpc-server-generator/src/test/java/com/squareup/wire/kotlin/grpcserver/StubTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -40,11 +40,11 @@ class StubTest { service, options = KotlinGrpcGenerator.Companion.Options( singleMethodServices = false, - suspendingCalls = false - ) + suspendingCalls = false, + ), ) } - .build() + .build(), ) .build() @@ -53,7 +53,10 @@ class StubTest { @Test fun `generates stubs for suspended bidi streaming rpc`() { - val code = stubCodeFor("test", "TestService", """ + val code = stubCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -61,8 +64,10 @@ class StubTest { service TestService { rpc TestRPC(stream Test) returns (stream Test){} } - """.trimMargin()) - assertEquals(""" + """.trimMargin(), + ) + assertEquals( + """ package test import io.grpc.CallOptions @@ -86,12 +91,17 @@ class StubTest { getTestRPCMethod(), request, callOptions) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } @Test fun `generates stubs for suspended server streaming rpc`() { - val code = stubCodeFor("test", "TestService", """ + val code = stubCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -99,8 +109,10 @@ class StubTest { service TestService { rpc TestRPC(Test) returns (stream Test){} } - """.trimMargin()) - assertEquals(""" + """.trimMargin(), + ) + assertEquals( + """ package test import io.grpc.CallOptions @@ -124,12 +136,17 @@ class StubTest { getTestRPCMethod(), request, callOptions) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } @Test fun `generates stubs for suspended client streaming rpc`() { - val code = stubCodeFor("test", "TestService", """ + val code = stubCodeFor( + "test", + "TestService", + """ syntax = "proto2"; package test; @@ -137,8 +154,10 @@ class StubTest { service TestService { rpc TestRPC(stream Test) returns (Test){} } - """.trimMargin()) - assertEquals(""" + """.trimMargin(), + ) + assertEquals( + """ package test import io.grpc.CallOptions @@ -162,14 +181,20 @@ class StubTest { getTestRPCMethod(), request, callOptions) } } - """.trimIndent().trim(), code) + """.trimIndent().trim(), + code, + ) } - private fun stubCodeFor(pkg: String, serviceName: String, schemaCode: String, - options: KotlinGrpcGenerator.Companion.Options = KotlinGrpcGenerator.Companion.Options( - singleMethodServices = false, - suspendingCalls = true - )): String { + private fun stubCodeFor( + pkg: String, + serviceName: String, + schemaCode: String, + options: KotlinGrpcGenerator.Companion.Options = KotlinGrpcGenerator.Companion.Options( + singleMethodServices = false, + suspendingCalls = true, + ), + ): String { val schema = buildSchema { add("test.proto".toPath(), schemaCode) } val service = schema.getService("$pkg.$serviceName")!! val typeSpec = TypeSpec.classBuilder("${serviceName}WireGrpc") diff --git a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/FlowAdapter.kt b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/FlowAdapter.kt index a36898e2cc..7f83c96d81 100644 --- a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/FlowAdapter.kt +++ b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/FlowAdapter.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,7 @@ */ package com.squareup.wire.kotlin.grpcserver +import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.ReceiveChannel @@ -24,7 +25,6 @@ import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.launch -import kotlin.coroutines.CoroutineContext /** * This is an adapter class to convert Wire generated Channel based routines to @@ -35,7 +35,7 @@ object FlowAdapter { fun serverStream( context: CoroutineContext, request: I, - f: suspend (I, SendChannel) -> Unit + f: suspend (I, SendChannel) -> Unit, ): Flow { val sendChannel = Channel() @@ -46,7 +46,7 @@ object FlowAdapter { suspend fun clientStream( context: CoroutineContext, request: Flow, - f: suspend (ReceiveChannel) -> O + f: suspend (ReceiveChannel) -> O, ): O { val receiveChannel = Channel() @@ -61,7 +61,7 @@ object FlowAdapter { fun bidiStream( context: CoroutineContext, request: Flow, - f: suspend (ReceiveChannel, SendChannel) -> Unit + f: suspend (ReceiveChannel, SendChannel) -> Unit, ): Flow { val sendChannel = Channel() val receiveChannel = Channel() diff --git a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSinkAdapter.kt b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSinkAdapter.kt index 66762103b5..f0259387f8 100644 --- a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSinkAdapter.kt +++ b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSinkAdapter.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSourceAdapter.kt b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSourceAdapter.kt index b9e27f0626..82864e2e3f 100644 --- a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSourceAdapter.kt +++ b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/MessageSourceAdapter.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireBindableService.kt b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireBindableService.kt index 98f3d90fc9..4dfbac8258 100644 --- a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireBindableService.kt +++ b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireBindableService.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.kotlin.grpcserver import io.grpc.BindableService diff --git a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireMethodMarshaller.kt b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireMethodMarshaller.kt index 91184fd0fb..e06de4bd90 100644 --- a/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireMethodMarshaller.kt +++ b/wire-grpc-server/src/main/java/com/squareup/wire/kotlin/grpcserver/WireMethodMarshaller.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.kotlin.grpcserver import io.grpc.MethodDescriptor diff --git a/wire-grpc-tests/build.gradle.kts b/wire-grpc-tests/build.gradle.kts index 2a8b9aec7f..e2f59f7bdb 100644 --- a/wire-grpc-tests/build.gradle.kts +++ b/wire-grpc-tests/build.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.SpotlessExtension import com.google.protobuf.gradle.generateProtoTasks import com.google.protobuf.gradle.id import com.google.protobuf.gradle.ofSourceSet @@ -79,3 +80,12 @@ val test by tasks.getting(Test::class) { exceptionFormat = TestExceptionFormat.FULL } } + +configure { + kotlin { + targetExclude( + // Generated files. + "src/test/proto-grpc/**/*.kt", + ) + } +} diff --git a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcCallsTest.kt b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcCallsTest.kt index 94973562e1..0e3f652533 100644 --- a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcCallsTest.kt +++ b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcCallsTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,7 @@ */ package com.squareup.wire +import java.util.concurrent.LinkedBlockingQueue import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ObsoleteCoroutinesApi import kotlinx.coroutines.runBlocking @@ -22,7 +23,6 @@ import okio.IOException import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import java.util.concurrent.LinkedBlockingQueue @ExperimentalCoroutinesApi @ObsoleteCoroutinesApi @@ -62,7 +62,7 @@ class GrpcCallsTest { override fun onSuccess(call: GrpcCall, response: String) { log.add("success: $response") } - } + }, ) assertThat(log.take()).isEqualTo("success: HELLO") @@ -115,7 +115,7 @@ class GrpcCallsTest { override fun onSuccess(call: GrpcCall, response: String) { log.add("success: $response") } - } + }, ) assertThat(log.take()) @@ -173,7 +173,7 @@ class GrpcCallsTest { override fun onSuccess(call: GrpcCall, response: String) { error("unexpected call") } - } + }, ) fail() } catch (e: IllegalStateException) { @@ -231,7 +231,7 @@ class GrpcCallsTest { override fun onSuccess(call: GrpcCall, response: String) { log.add("success: $response") } - } + }, ) assertThat(log.take()).isEqualTo("failure: java.io.IOException: canceled") diff --git a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcClientTest.kt b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcClientTest.kt index b3d7c5bad6..cb350d3273 100644 --- a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcClientTest.kt +++ b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcClientTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,6 +26,10 @@ import com.squareup.wire.MockRouteGuideService.Action.SendMessage import io.grpc.Metadata import io.grpc.Status import io.grpc.StatusException +import java.io.IOException +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicReference import kotlinx.coroutines.CancellationException import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ObsoleteCoroutinesApi @@ -39,6 +43,8 @@ import okhttp3.Interceptor import okhttp3.Interceptor.Chain import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient +import okhttp3.Protocol.H2_PRIOR_KNOWLEDGE +import okhttp3.Protocol.HTTP_1_1 import okhttp3.Protocol.HTTP_2 import okhttp3.Request import okhttp3.Response @@ -48,6 +54,7 @@ import okio.Buffer import okio.ByteString import org.assertj.core.api.Assertions.assertThat import org.junit.After +import org.junit.Assert.assertThrows import org.junit.Assert.fail import org.junit.Before import org.junit.Ignore @@ -61,19 +68,15 @@ import routeguide.RouteGuideClient import routeguide.RouteGuideProto import routeguide.RouteNote import routeguide.RouteSummary -import java.io.IOException -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicReference -import okhttp3.Protocol.H2_PRIOR_KNOWLEDGE -import okhttp3.Protocol.HTTP_1_1 -import org.junit.Assert.assertThrows @ExperimentalCoroutinesApi @ObsoleteCoroutinesApi class GrpcClientTest { - @JvmField @Rule val mockService = MockRouteGuideService() - @JvmField @Rule val timeout = Timeout(30, TimeUnit.SECONDS) + @JvmField @Rule + val mockService = MockRouteGuideService() + + @JvmField @Rule + val timeout = Timeout(30, TimeUnit.SECONDS) private lateinit var okhttpClient: OkHttpClient private lateinit var grpcClient: GrpcClient @@ -118,7 +121,7 @@ class GrpcClientTest { } assertThat(exception.message) .isEqualTo( - "OkHttpClient is not configured with a HTTP/2 protocol which is required for gRPC connections." + "OkHttpClient is not configured with a HTTP/2 protocol which is required for gRPC connections.", ) } @@ -214,7 +217,7 @@ class GrpcClientTest { feature = response latch.countDown() } - } + }, ) mockService.awaitSuccessBlocking() @@ -886,7 +889,7 @@ class GrpcClientTest { feature = response latch.countDown() } - } + }, ) assertThat(grpcCall.isExecuted()).isTrue() @@ -949,7 +952,7 @@ class GrpcClientTest { fail() } catch (expected: IOException) { assertThat(expected).hasMessage( - "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)" + "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)", ) } } @@ -970,7 +973,7 @@ class GrpcClientTest { fail() } catch (expected: IOException) { assertThat(expected).hasMessage( - "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)" + "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)", ) } } @@ -991,7 +994,7 @@ class GrpcClientTest { object : GrpcCall.Callback { override fun onFailure(call: GrpcCall, exception: IOException) { assertThat(exception).hasMessage( - "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)" + "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)", ) latch.countDown() } @@ -999,7 +1002,7 @@ class GrpcClientTest { override fun onSuccess(call: GrpcCall, response: Feature) { throw AssertionError() } - } + }, ) mockService.awaitSuccessBlocking() @@ -1027,7 +1030,7 @@ class GrpcClientTest { fail() } catch (expected: IOException) { assertThat(expected).hasMessage( - "expected gRPC but was HTTP status=500, content-type=application/grpc" + "expected gRPC but was HTTP status=500, content-type=application/grpc", ) } } @@ -1054,7 +1057,7 @@ class GrpcClientTest { fail() } catch (expected: IOException) { assertThat(expected).hasMessage( - "expected gRPC but was HTTP status=200, content-type=text/plain" + "expected gRPC but was HTTP status=200, content-type=text/plain", ) } } @@ -1151,7 +1154,7 @@ class GrpcClientTest { } catch (expected: GrpcException) { assertThat(expected.grpcStatus).isEqualTo(GrpcStatus.INTERNAL) assertThat(expected).hasMessage( - "grpc-status=13, grpc-status-name=INTERNAL, grpc-message=boom" + "grpc-status=13, grpc-status-name=INTERNAL, grpc-message=boom", ) } } @@ -1172,7 +1175,7 @@ class GrpcClientTest { fail() } catch (expected: IOException) { assertThat(expected).hasMessage( - "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)" + "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)", ) assertThat(expected.cause).hasMessage("stream was reset: CANCEL") } @@ -1197,7 +1200,7 @@ class GrpcClientTest { // It's racy whether we receive trailers first or close the response stream first. assertThat(expected.message).isIn( "gRPC transport failure (HTTP status=200, grpc-status=0, grpc-message=null)", - "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)" + "gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)", ) assertThat(expected.cause).hasMessage("expected 1 message but got multiple") } @@ -1217,7 +1220,7 @@ class GrpcClientTest { fail() } catch (expected: IOException) { assertThat(expected).hasMessage( - "gRPC transport failure (HTTP status=200, grpc-status=0, grpc-message=null)" + "gRPC transport failure (HTTP status=200, grpc-status=0, grpc-message=null)", ) assertThat(expected.cause).hasMessage("expected 1 message but got none") } @@ -1338,7 +1341,7 @@ class GrpcClientTest { ReceiveCall( path = "/routeguide.RouteGuide/GetFeature", requestHeaders = mapOf("request-lucky-number" to "twenty-two"), - ) + ), ) mockService.enqueueReceivePoint(latitude = 5, longitude = 6) mockService.enqueue(ReceiveComplete) @@ -1347,8 +1350,8 @@ class GrpcClientTest { message = RouteGuideProto.Feature.newBuilder() .setName("tree at 5,6") .build(), - responseHeaders = mapOf("response-lucky-animal" to "horse") - ) + responseHeaders = mapOf("response-lucky-animal" to "horse"), + ), ) mockService.enqueue(SendCompleted) @@ -1368,7 +1371,7 @@ class GrpcClientTest { ReceiveCall( path = "/routeguide.RouteGuide/GetFeature", requestHeaders = mapOf("request-lucky-number" to "twenty-two"), - ) + ), ) mockService.enqueueReceivePoint(latitude = 5, longitude = 6) mockService.enqueue(ReceiveComplete) @@ -1377,8 +1380,8 @@ class GrpcClientTest { message = RouteGuideProto.Feature.newBuilder() .setName("tree at 5,6") .build(), - responseHeaders = mapOf("response-lucky-animal" to "horse") - ) + responseHeaders = mapOf("response-lucky-animal" to "horse"), + ), ) mockService.enqueue(SendCompleted) // Cloned call. @@ -1386,7 +1389,7 @@ class GrpcClientTest { ReceiveCall( path = "/routeguide.RouteGuide/GetFeature", requestHeaders = mapOf("request-lucky-number" to "twenty-two", "all-in" to "true"), - ) + ), ) mockService.enqueueReceivePoint(latitude = 15, longitude = 16) mockService.enqueue(ReceiveComplete) @@ -1395,8 +1398,8 @@ class GrpcClientTest { message = RouteGuideProto.Feature.newBuilder() .setName("tree at 15,16") .build(), - responseHeaders = mapOf("response-lucky-animal" to "emu") - ) + responseHeaders = mapOf("response-lucky-animal" to "emu"), + ), ) mockService.enqueue(SendCompleted) @@ -1425,7 +1428,7 @@ class GrpcClientTest { ReceiveCall( path = "/routeguide.RouteGuide/ListFeatures", requestHeaders = mapOf("request-lucky-number" to "twenty-two"), - ) + ), ) mockService.enqueueReceiveRectangle(lo = Point(0, 0), hi = Point(4, 5)) mockService.enqueue(ReceiveComplete) @@ -1434,8 +1437,8 @@ class GrpcClientTest { message = RouteGuideProto.Feature.newBuilder() .setName("tree") .build(), - responseHeaders = mapOf("response-lucky-animal" to "horse") - ) + responseHeaders = mapOf("response-lucky-animal" to "horse"), + ), ) mockService.enqueueSendFeature(name = "house") mockService.enqueue(SendCompleted) @@ -1459,7 +1462,7 @@ class GrpcClientTest { ReceiveCall( path = "/routeguide.RouteGuide/ListFeatures", requestHeaders = mapOf("request-lucky-number" to "twenty-two"), - ) + ), ) mockService.enqueueReceiveRectangle(lo = Point(0, 0), hi = Point(4, 5)) mockService.enqueue(ReceiveComplete) @@ -1468,8 +1471,8 @@ class GrpcClientTest { message = RouteGuideProto.Feature.newBuilder() .setName("tree") .build(), - responseHeaders = mapOf("response-lucky-animal" to "horse") - ) + responseHeaders = mapOf("response-lucky-animal" to "horse"), + ), ) mockService.enqueueSendFeature(name = "house") mockService.enqueue(SendCompleted) @@ -1478,7 +1481,7 @@ class GrpcClientTest { ReceiveCall( path = "/routeguide.RouteGuide/ListFeatures", requestHeaders = mapOf("request-lucky-number" to "twenty-two", "all-in" to "true"), - ) + ), ) mockService.enqueueReceiveRectangle(lo = Point(0, 0), hi = Point(14, 15)) mockService.enqueue(ReceiveComplete) @@ -1487,8 +1490,8 @@ class GrpcClientTest { message = RouteGuideProto.Feature.newBuilder() .setName("forest") .build(), - responseHeaders = mapOf("response-lucky-animal" to "emu") - ) + responseHeaders = mapOf("response-lucky-animal" to "emu"), + ), ) mockService.enqueueSendFeature(name = "cabane") mockService.enqueue(SendCompleted) @@ -1572,7 +1575,7 @@ class GrpcClientTest { val metadata = Metadata().apply { put( Metadata.Key.of("grpc-status-details-bin", Metadata.BINARY_BYTE_MARSHALLER), - RouteNote(message = "marco").encode() + RouteNote(message = "marco").encode(), ) } mockService.enqueueSendError(Status.INTERNAL.withDescription("boom").asRuntimeException(metadata)) @@ -1634,15 +1637,15 @@ class GrpcClientTest { } class IncompatibleRouteGuideClient( - private val client: GrpcClient + private val client: GrpcClient, ) { fun RouteChat(): GrpcCall = client.newCall( GrpcMethod( path = "/routeguide.RouteGuide/RouteChat", requestAdapter = RouteNote.ADAPTER, - responseAdapter = RouteNote.ADAPTER - ) + responseAdapter = RouteNote.ADAPTER, + ), ) } } diff --git a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcOnMockWebServerTest.kt b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcOnMockWebServerTest.kt index 85a7cbf8f4..6ec495fa2d 100644 --- a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcOnMockWebServerTest.kt +++ b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcOnMockWebServerTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,6 +16,8 @@ package com.squareup.wire import com.squareup.wire.mockwebserver.GrpcDispatcher +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicReference import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ObsoleteCoroutinesApi import kotlinx.coroutines.runBlocking @@ -35,14 +37,15 @@ import routeguide.Rectangle import routeguide.RouteGuideClient import routeguide.RouteNote import routeguide.RouteSummary -import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicReference @ExperimentalCoroutinesApi @ObsoleteCoroutinesApi class GrpcOnMockWebServerTest { - @JvmField @Rule val mockWebServer = MockWebServer() - @JvmField @Rule val timeout = Timeout(30, TimeUnit.SECONDS) + @JvmField @Rule + val mockWebServer = MockWebServer() + + @JvmField @Rule + val timeout = Timeout(30, TimeUnit.SECONDS) private lateinit var okhttpClient: OkHttpClient private lateinit var grpcClient: GrpcClient @@ -59,7 +62,7 @@ class GrpcOnMockWebServerTest { fun setUp() { mockWebServer.dispatcher = GrpcDispatcher( services = listOf(fakeRouteGuide), - delegate = mockWebServer.dispatcher + delegate = mockWebServer.dispatcher, ) mockWebServer.protocols = listOf(Protocol.H2_PRIOR_KNOWLEDGE) diff --git a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcStreamingCallsTest.kt b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcStreamingCallsTest.kt index 2a676c8c9d..77a7086f2b 100644 --- a/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcStreamingCallsTest.kt +++ b/wire-grpc-tests/src/test/java/com/squareup/wire/GrpcStreamingCallsTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-grpc-tests/src/test/java/com/squareup/wire/MockRouteGuideService.kt b/wire-grpc-tests/src/test/java/com/squareup/wire/MockRouteGuideService.kt index 1ae1b7cbda..3bf67f3236 100644 --- a/wire-grpc-tests/src/test/java/com/squareup/wire/MockRouteGuideService.kt +++ b/wire-grpc-tests/src/test/java/com/squareup/wire/MockRouteGuideService.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,6 +27,8 @@ import io.grpc.ServerCall.Listener import io.grpc.ServerCallHandler import io.grpc.ServerInterceptor import io.grpc.stub.StreamObserver +import java.util.ArrayDeque +import java.util.concurrent.TimeUnit import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED @@ -43,8 +45,6 @@ import routeguide.RouteGuideProto.Point import routeguide.RouteGuideProto.Rectangle import routeguide.RouteGuideProto.RouteNote import routeguide.RouteGuideProto.RouteSummary -import java.util.ArrayDeque -import java.util.concurrent.TimeUnit /** * An assertive scriptable implementation of the [RouteGuideGrpc] gRPC service. Receiving and @@ -71,8 +71,8 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.ReceiveMessage( RouteNote.newBuilder() .setMessage(message) - .build() - ) + .build(), + ), ) } @@ -82,8 +82,8 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Point.newBuilder() .setLatitude(latitude) .setLongitude(longitude) - .build() - ) + .build(), + ), ) } @@ -93,8 +93,8 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Rectangle.newBuilder() .setLo(Point.newBuilder().setLatitude(lo.latitude!!).setLongitude(lo.longitude!!).build()) .setHi(Point.newBuilder().setLatitude(hi.latitude!!).setLongitude(hi.longitude!!).build()) - .build() - ) + .build(), + ), ) } @@ -103,8 +103,8 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.SendMessage( Feature.newBuilder() .setName(name) - .build() - ) + .build(), + ), ) } @@ -113,8 +113,8 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.SendMessage( RouteNote.newBuilder() .setMessage(message) - .build() - ) + .build(), + ), ) } @@ -123,8 +123,8 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.SendMessage( RouteSummary.newBuilder() .setPointCount(pointCount) - .build() - ) + .build(), + ), ) } @@ -168,7 +168,7 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.ReceiveCall( path = "/routeguide.RouteGuide/GetFeature", requestHeaders = takeLastRequestHeaders(it), - ) + ), ) } assertNextActionAndProcessScript { @@ -186,7 +186,7 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.ReceiveCall( path = "/routeguide.RouteGuide/RecordRoute", requestHeaders = takeLastRequestHeaders(it), - ) + ), ) } return createAssertingStreamObserver() @@ -199,7 +199,7 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.ReceiveCall( path = "/routeguide.RouteGuide/ListFeatures", requestHeaders = takeLastRequestHeaders(it), - ) + ), ) } assertNextActionAndProcessScript { @@ -217,7 +217,7 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser Action.ReceiveCall( path = "/routeguide.RouteGuide/RouteChat", requestHeaders = takeLastRequestHeaders(it), - ) + ), ) } return createAssertingStreamObserver() @@ -227,7 +227,7 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser override fun interceptCall( call: ServerCall, requestHeaders: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): Listener { lastRequestHeaders = requestHeaders return next.startCall( @@ -240,7 +240,7 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser super.sendHeaders(responseHeaders) } }, - requestHeaders + requestHeaders, ) } @@ -338,14 +338,14 @@ class MockRouteGuideService : RouteGuideGrpc.RouteGuideImplBase(), TestRule, Ser sealed class Action { data class ReceiveCall( val path: String, - val requestHeaders: Map = mapOf() + val requestHeaders: Map = mapOf(), ) : Action() data class ReceiveMessage(val message: com.google.protobuf.Message) : Action() object ReceiveError : Action() object ReceiveComplete : Action() data class SendMessage( val message: com.google.protobuf.Message, - val responseHeaders: Map = mapOf() + val responseHeaders: Map = mapOf(), ) : Action() data class SendError(val throwable: Throwable) : Action() object SendCompleted : Action() diff --git a/wire-gson-support/build.gradle.kts b/wire-gson-support/build.gradle.kts index a4158d4006..2edacf1113 100644 --- a/wire-gson-support/build.gradle.kts +++ b/wire-gson-support/build.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.MavenPublishBaseExtension @@ -17,6 +18,21 @@ if (project.rootProject.name == "wire") { KotlinJvm(javadocJar = Dokka("dokkaGfm"), sourcesJar = true) ) } + + configure { + kotlin { + targetExclude( + // Generated files. + "src/test/java/**/*.kt", + ) + } + java { + targetExclude( + // Generated files. + "src/test/java/**/*.java", + ) + } + } } dependencies { diff --git a/wire-gson-support/src/main/java/com/squareup/wire/AnyMessageTypeAdapter.kt b/wire-gson-support/src/main/java/com/squareup/wire/AnyMessageTypeAdapter.kt index 7ccf1d52dd..3ea20ae4df 100644 --- a/wire-gson-support/src/main/java/com/squareup/wire/AnyMessageTypeAdapter.kt +++ b/wire-gson-support/src/main/java/com/squareup/wire/AnyMessageTypeAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,7 @@ import java.io.IOException class AnyMessageTypeAdapter( private val gson: Gson, - private val typeUrlToAdapter: Map> + private val typeUrlToAdapter: Map>, ) : TypeAdapter() { private val elementAdapter: TypeAdapter = gson.getAdapter(JsonElement::class.java) diff --git a/wire-gson-support/src/main/java/com/squareup/wire/EnumTypeAdapter.kt b/wire-gson-support/src/main/java/com/squareup/wire/EnumTypeAdapter.kt index 54400a2d1c..c753ee51ed 100644 --- a/wire-gson-support/src/main/java/com/squareup/wire/EnumTypeAdapter.kt +++ b/wire-gson-support/src/main/java/com/squareup/wire/EnumTypeAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-gson-support/src/main/java/com/squareup/wire/GsonJsonIntegration.kt b/wire-gson-support/src/main/java/com/squareup/wire/GsonJsonIntegration.kt index a491c7f98d..781d3d4733 100644 --- a/wire-gson-support/src/main/java/com/squareup/wire/GsonJsonIntegration.kt +++ b/wire-gson-support/src/main/java/com/squareup/wire/GsonJsonIntegration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,7 +28,7 @@ import java.lang.reflect.Type internal object GsonJsonIntegration : JsonIntegration>() { override fun frameworkAdapter( framework: Gson, - type: Type + type: Type, ): TypeAdapter = framework.getAdapter(TypeToken.get(type)).nullSafe() as TypeAdapter override fun listAdapter(elementAdapter: TypeAdapter): TypeAdapter = @@ -37,7 +37,7 @@ internal object GsonJsonIntegration : JsonIntegration>() override fun mapAdapter( framework: Gson, keyFormatter: JsonFormatter<*>, - valueAdapter: TypeAdapter + valueAdapter: TypeAdapter, ): TypeAdapter = MapJsonAdapter(keyFormatter, valueAdapter).nullSafe() as TypeAdapter fun TypeAdapter.serializeNulls(): TypeAdapter { @@ -67,7 +67,7 @@ internal object GsonJsonIntegration : JsonIntegration>() FormatterJsonAdapter(jsonFormatter).nullSafe() as TypeAdapter private class FormatterJsonAdapter( - private val formatter: JsonFormatter + private val formatter: JsonFormatter, ) : TypeAdapter() { override fun write(writer: JsonWriter, value: T) { val stringOrNumber = formatter.toStringOrNumber(value) @@ -90,7 +90,7 @@ internal object GsonJsonIntegration : JsonIntegration>() /** Adapt a list of values by delegating to an adapter for a single value. */ private class ListJsonAdapter( - private val single: TypeAdapter + private val single: TypeAdapter, ) : TypeAdapter>() { override fun read(reader: JsonReader): List { val result = mutableListOf() @@ -114,7 +114,7 @@ internal object GsonJsonIntegration : JsonIntegration>() /** Adapt a list of values by delegating to an adapter for a single value. */ private class MapJsonAdapter( private val keyFormatter: JsonFormatter, - private val valueAdapter: TypeAdapter + private val valueAdapter: TypeAdapter, ) : TypeAdapter>() { override fun read(reader: JsonReader): Map { val result = mutableMapOf() diff --git a/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt b/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt index 19c0b375c8..5344b43b63 100644 --- a/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt +++ b/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ import java.io.IOException internal class MessageTypeAdapter, B : Message.Builder>( private val messageAdapter: RuntimeMessageAdapter, - private val jsonAdapters: List> + private val jsonAdapters: List>, ) : TypeAdapter() { private val nameToField = mutableMapOf>() .also { map -> @@ -45,7 +45,7 @@ internal class MessageTypeAdapter, B : Message.Builder>( messageAdapter.writeAllFields( message = message, jsonAdapters = jsonAdapters, - redactedFieldsAdapter = null + redactedFieldsAdapter = null, ) { name, value, jsonAdapter -> out.name(name) jsonAdapter.write(out, value) @@ -79,6 +79,6 @@ internal class MessageTypeAdapter, B : Message.Builder>( data class JsonField, B : Message.Builder>( val adapter: TypeAdapter, - val fieldBinding: FieldOrOneOfBinding + val fieldBinding: FieldOrOneOfBinding, ) } diff --git a/wire-gson-support/src/main/java/com/squareup/wire/WireTypeAdapterFactory.kt b/wire-gson-support/src/main/java/com/squareup/wire/WireTypeAdapterFactory.kt index 63adc5b799..f42212e174 100644 --- a/wire-gson-support/src/main/java/com/squareup/wire/WireTypeAdapterFactory.kt +++ b/wire-gson-support/src/main/java/com/squareup/wire/WireTypeAdapterFactory.kt @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -57,7 +57,7 @@ class WireTypeAdapterFactory @JvmOverloads constructor( val newMap = typeUrlToAdapter.toMutableMap() for (adapter in adapters) { val key = adapter.typeUrl ?: throw IllegalArgumentException( - "recompile ${adapter.type} to use it with WireTypeAdapterFactory" + "recompile ${adapter.type} to use it with WireTypeAdapterFactory", ) newMap[key] = adapter } diff --git a/wire-gson-support/src/test/java/com/squareup/wire/GsonNoAdapterTest.java b/wire-gson-support/src/test/java/com/squareup/wire/GsonNoAdapterTest.java index d8c89f5b20..565301b750 100644 --- a/wire-gson-support/src/test/java/com/squareup/wire/GsonNoAdapterTest.java +++ b/wire-gson-support/src/test/java/com/squareup/wire/GsonNoAdapterTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,8 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.squareup.wire.proto2.dinosaurs.java.Dinosaur; @@ -25,33 +27,32 @@ import org.junit.Ignore; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; - /** * Using Gson without the adapter is quite fragile: it leaks implementation details of how Gson * works, and it breaks on absent collection types. Nevertheless this is sufficiently commonplace * that we support it like it were a public API. */ public class GsonNoAdapterTest { - private final Gson gson = new GsonBuilder() - .disableHtmlEscaping() - .create(); + private final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); - @Test public void javaFullObject() { - Dinosaur value = new Dinosaur.Builder() - .name("Stegosaurus") - .period(Period.JURASSIC) - .length_meters(9.0) - .mass_kilograms(5_000.0) - .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) - .build(); - String json = "{" - + "\"name\":\"Stegosaurus\"," - + "\"picture_urls\":[\"http://goo.gl/LD5KY5\",\"http://goo.gl/VYRM67\"]," - + "\"length_meters\":9.0," - + "\"mass_kilograms\":5000.0," - + "\"period\":\"JURASSIC\"" - + "}"; + @Test + public void javaFullObject() { + Dinosaur value = + new Dinosaur.Builder() + .name("Stegosaurus") + .period(Period.JURASSIC) + .length_meters(9.0) + .mass_kilograms(5_000.0) + .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) + .build(); + String json = + "{" + + "\"name\":\"Stegosaurus\"," + + "\"picture_urls\":[\"http://goo.gl/LD5KY5\",\"http://goo.gl/VYRM67\"]," + + "\"length_meters\":9.0," + + "\"mass_kilograms\":5000.0," + + "\"period\":\"JURASSIC\"" + + "}"; assertThat(gson.toJson(value)).isEqualTo(json); Dinosaur decoded = gson.fromJson(json, Dinosaur.class); assertThat(decoded).isEqualTo(value); @@ -59,12 +60,10 @@ public class GsonNoAdapterTest { assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void javaListsOnly() { - Dinosaur value = new Dinosaur.Builder() - .build(); - String json = "{" - + "\"picture_urls\":[]" - + "}"; + @Test + public void javaListsOnly() { + Dinosaur value = new Dinosaur.Builder().build(); + String json = "{" + "\"picture_urls\":[]" + "}"; assertThat(gson.toJson(value)).isEqualTo(json); Dinosaur decoded = gson.fromJson(json, Dinosaur.class); assertThat(decoded).isEqualTo(value); @@ -73,9 +72,9 @@ public class GsonNoAdapterTest { } @Ignore("Absent lists are initialized to null in Java.") - @Test public void javaEmptyObject() { - Dinosaur value = new Dinosaur.Builder() - .build(); + @Test + public void javaEmptyObject() { + Dinosaur value = new Dinosaur.Builder().build(); String json = "{}"; assertThat(gson.toJson(value)).isEqualTo("{\"picture_urls\":[]}"); Dinosaur decoded = gson.fromJson(json, Dinosaur.class); @@ -84,54 +83,60 @@ public class GsonNoAdapterTest { assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void interopFullObject() { + @Test + public void interopFullObject() { com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur value = new com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.Builder() - .name("Stegosaurus") - .period(com.squareup.wire.proto2.geology.javainteropkotlin.Period.JURASSIC) - .length_meters(9.0) - .mass_kilograms(5_000.0) - .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) - .build(); - String json = "{" - + "\"name\":\"Stegosaurus\"," - + "\"length_meters\":9.0," - + "\"mass_kilograms\":5000.0," - + "\"period\":\"JURASSIC\"," - + "\"picture_urls\":[\"http://goo.gl/LD5KY5\",\"http://goo.gl/VYRM67\"]" - + "}"; + .name("Stegosaurus") + .period(com.squareup.wire.proto2.geology.javainteropkotlin.Period.JURASSIC) + .length_meters(9.0) + .mass_kilograms(5_000.0) + .picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) + .build(); + String json = + "{" + + "\"name\":\"Stegosaurus\"," + + "\"length_meters\":9.0," + + "\"mass_kilograms\":5000.0," + + "\"period\":\"JURASSIC\"," + + "\"picture_urls\":[\"http://goo.gl/LD5KY5\",\"http://goo.gl/VYRM67\"]" + + "}"; assertThat(gson.toJson(value)).isEqualTo(json); - com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur decoded = gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.class); + com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur decoded = + gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.class); assertThat(decoded).isEqualTo(value); assertThat(decoded.hashCode()).isEqualTo(value.hashCode()); assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void interopListsOnly() { + @Test + public void interopListsOnly() { com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur value = new com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.Builder().build(); - String json = "{" - + "\"picture_urls\":[]" - + "}"; + String json = "{" + "\"picture_urls\":[]" + "}"; assertThat(gson.toJson(value)).isEqualTo(json); - com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur decoded = gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.class); + com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur decoded = + gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.class); assertThat(decoded).isEqualTo(value); assertThat(decoded.hashCode()).isEqualTo(value.hashCode()); assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void interopEmptyObject() { + @Test + public void interopEmptyObject() { com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur value = new com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.Builder().build(); String json = "{}"; assertThat(gson.toJson(value)).isEqualTo("{\"picture_urls\":[]}"); - com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur decoded = gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.class); + com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur decoded = + gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.javainteropkotlin.Dinosaur.class); assertThat(decoded).isEqualTo(value); assertThat(decoded.hashCode()).isEqualTo(value.hashCode()); assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void kotlinFullObject() { + @Test + public void kotlinFullObject() { com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur value = new com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur( "Stegosaurus", @@ -139,15 +144,15 @@ public class GsonNoAdapterTest { 9.0, 5_000.0, com.squareup.wire.proto2.geology.kotlin.Period.JURASSIC, - ByteString.EMPTY - ); - String json = "{" - + "\"name\":\"Stegosaurus\"," - + "\"length_meters\":9.0," - + "\"mass_kilograms\":5000.0," - + "\"period\":\"JURASSIC\"," - + "\"picture_urls\":[\"http://goo.gl/LD5KY5\",\"http://goo.gl/VYRM67\"]" - + "}"; + ByteString.EMPTY); + String json = + "{" + + "\"name\":\"Stegosaurus\"," + + "\"length_meters\":9.0," + + "\"mass_kilograms\":5000.0," + + "\"period\":\"JURASSIC\"," + + "\"picture_urls\":[\"http://goo.gl/LD5KY5\",\"http://goo.gl/VYRM67\"]" + + "}"; assertThat(gson.toJson(value)).isEqualTo(json); com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur decoded = gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur.class); @@ -156,13 +161,12 @@ public class GsonNoAdapterTest { assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void kotlinListsOnly() { + @Test + public void kotlinListsOnly() { com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur value = - new com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur(null, Collections.emptyList(), null, - null, null, ByteString.EMPTY); - String json = "{" - + "\"picture_urls\":[]" - + "}"; + new com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur( + null, Collections.emptyList(), null, null, null, ByteString.EMPTY); + String json = "{" + "\"picture_urls\":[]" + "}"; assertThat(gson.toJson(value)).isEqualTo(json); com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur decoded = gson.fromJson(json, com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur.class); @@ -171,10 +175,11 @@ public class GsonNoAdapterTest { assertThat(decoded.toString()).isEqualTo(value.toString()); } - @Test public void kotlinEmptyObject() { + @Test + public void kotlinEmptyObject() { com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur value = - new com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur(null, Collections.emptyList(), null, - null, null, ByteString.EMPTY); + new com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur( + null, Collections.emptyList(), null, null, null, ByteString.EMPTY); String json = "{}"; assertThat(gson.toJson(value)).isEqualTo("{\"picture_urls\":[]}"); com.squareup.wire.proto2.dinosaurs.kotlin.Dinosaur decoded = diff --git a/wire-gson-support/src/test/java/com/squareup/wire/GsonTest.java b/wire-gson-support/src/test/java/com/squareup/wire/GsonTest.java index 57965cfcfb..06ad01189f 100644 --- a/wire-gson-support/src/test/java/com/squareup/wire/GsonTest.java +++ b/wire-gson-support/src/test/java/com/squareup/wire/GsonTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2013 Square Inc. + * Copyright (C) 2013 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,9 @@ */ package com.squareup.wire; +import static com.squareup.wire.json.JsonUtils.assertJsonEquals; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -34,9 +37,6 @@ import squareup.proto2.keywords.KeywordKotlin; import squareup.proto2.keywords.KeywordKotlin.KeywordKotlinEnum; -import static com.squareup.wire.json.JsonUtils.assertJsonEquals; -import static org.assertj.core.api.Assertions.assertThat; - public class GsonTest { private static final String ALL_TYPES_JSON; @@ -44,51 +44,55 @@ public class GsonTest { try { ALL_TYPES_JSON = Okio.buffer( - Okio.source( - new File("../wire-tests/src/commonTest/shared/json", "all_types_proto2.json")) - ).readUtf8(); + Okio.source( + new File( + "../wire-tests/src/commonTest/shared/json", "all_types_proto2.json"))) + .readUtf8(); } catch (IOException e) { throw new RuntimeException(e); } } - private final Gson gson = new GsonBuilder() - .registerTypeAdapterFactory(new WireTypeAdapterFactory()) - .disableHtmlEscaping() - .create(); + private final Gson gson = + new GsonBuilder() + .registerTypeAdapterFactory(new WireTypeAdapterFactory()) + .disableHtmlEscaping() + .create(); - @Test public void deserializationOfNullValues() { + @Test + public void deserializationOfNullValues() { // Modifying JSON string manually, cause serialization omits fields with null values. String json = ALL_TYPES_JSON.replace("\"opt_string\": \"124\",", "\"opt_string\": null,"); AllTypes deserializedAllTypesWithNulls = gson.fromJson(json, AllTypes.class); assertThat(deserializedAllTypesWithNulls.opt_string).isNull(); } - @Test public void nullRepeatedField() { + @Test + public void nullRepeatedField() { RepeatedPackedAndMap parsed = - gson.fromJson("{rep_int32=null,pack_int32=null,map_int32_int32=null}", - RepeatedPackedAndMap.class); + gson.fromJson( + "{rep_int32=null,pack_int32=null,map_int32_int32=null}", RepeatedPackedAndMap.class); assertThat(parsed.rep_int32).isEmpty(); assertThat(parsed.pack_int32).isEmpty(); assertThat(parsed.map_int32_int32).isEmpty(); } - @Test public void usedKeywordsInKotlin() { - KeywordKotlin keyword = new KeywordKotlin.Builder() - .object_("object") - .when_(1) - .enums( - Arrays.asList( - KeywordKotlinEnum.object_, - KeywordKotlinEnum.when_, - KeywordKotlinEnum.fun_, - KeywordKotlinEnum.return_, - KeywordKotlinEnum.open_, - KeywordKotlinEnum.name_, - KeywordKotlinEnum.ordinal_ - ) - ) - .build(); + @Test + public void usedKeywordsInKotlin() { + KeywordKotlin keyword = + new KeywordKotlin.Builder() + .object_("object") + .when_(1) + .enums( + Arrays.asList( + KeywordKotlinEnum.object_, + KeywordKotlinEnum.when_, + KeywordKotlinEnum.fun_, + KeywordKotlinEnum.return_, + KeywordKotlinEnum.open_, + KeywordKotlinEnum.name_, + KeywordKotlinEnum.ordinal_)) + .build(); String json = gson.toJson(keyword); assertJsonEquals( "{\"object\":\"object\",\"when\":1, \"fun\":{}, \"return\":[], \"enums\":[\"object\", " @@ -97,25 +101,26 @@ public class GsonTest { KeywordKotlin parseKeyword = gson.fromJson(json, KeywordKotlin.class); assertThat(parseKeyword).isEqualTo(keyword); - String generatedNamedJson = "{\"object_\":\"object\",\"when_\":1, \"fun_\":{}, \"return_\":[], " - + "\"enums\":[\"object_\", \"when_\", \"fun_\", \"return_\", \"open_\", \"name_\", " - + "\"ordinal_\"]}"; + String generatedNamedJson = + "{\"object_\":\"object\",\"when_\":1, \"fun_\":{}, \"return_\":[], " + + "\"enums\":[\"object_\", \"when_\", \"fun_\", \"return_\", \"open_\", \"name_\", " + + "\"ordinal_\"]}"; assertThat(gson.fromJson(generatedNamedJson, KeywordKotlin.class)).isEqualTo(keyword); } - @Test public void usedKeywordsInJava() { - KeywordJava keyword = new KeywordJava.Builder() - .final_("final") - .public_(true) - .enums( - Arrays.asList( - KeywordJavaEnum.final_, - KeywordJavaEnum.public_, - KeywordJavaEnum.package_, - KeywordJavaEnum.return_ - ) - ) - .build(); + @Test + public void usedKeywordsInJava() { + KeywordJava keyword = + new KeywordJava.Builder() + .final_("final") + .public_(true) + .enums( + Arrays.asList( + KeywordJavaEnum.final_, + KeywordJavaEnum.public_, + KeywordJavaEnum.package_, + KeywordJavaEnum.return_)) + .build(); String json = gson.toJson(keyword); assertJsonEquals( "{\"final\":\"final\", \"public\":true, \"package\":{}, \"return\":[], " @@ -124,12 +129,14 @@ public class GsonTest { KeywordJava parseKeyword = gson.fromJson(json, KeywordJava.class); assertThat(parseKeyword).isEqualTo(keyword); - String generatedNamedJson = "{\"final_\":\"final\", \"public_\":true, \"package_\":{}, " - + "\"return_\":[], \"enums\":[\"final_\", \"public_\", \"package_\", \"return_\"]}"; + String generatedNamedJson = + "{\"final_\":\"final\", \"public_\":true, \"package_\":{}, " + + "\"return_\":[], \"enums\":[\"final_\", \"public_\", \"package_\", \"return_\"]}"; assertThat(gson.fromJson(generatedNamedJson, KeywordJava.class)).isEqualTo(keyword); } - @Test public void enumKeywordsAtRootInKotlin() { + @Test + public void enumKeywordsAtRootInKotlin() { KeywordKotlinEnum constant = KeywordKotlinEnum.object_; String json = gson.toJson(constant); assertJsonEquals("\"object\"", json); @@ -140,7 +147,8 @@ public class GsonTest { assertThat(gson.fromJson(generatedNamedJson, KeywordKotlinEnum.class)).isEqualTo(constant); } - @Test public void enumKeywordsAtRootInJava() { + @Test + public void enumKeywordsAtRootInJava() { KeywordJavaEnum constant = KeywordJavaEnum.final_; String json = gson.toJson(constant); assertJsonEquals("\"final\"", json); @@ -151,62 +159,72 @@ public class GsonTest { assertThat(gson.fromJson(generatedNamedJson, KeywordJavaEnum.class)).isEqualTo(constant); } - @Test public void kotlinWithoutBuilderFromJson() { - Person person = gson.fromJson( - "{" - + "\"id\":1," - + "\"name\":\"Jo\"," - + "\"email\":\"foo@square.com\"," - + "\"phone\":[{\"number\": \"555-555-5555\"}, {\"number\": \"444-444-4444\"}]," - + "\"favorite_numbers\":[1, 2, 3]," - + "\"area_numbers\":{\"519\":\"555-5555\"}," - + "\"is_canadian\":true" - + "}", - Person.class); - assertThat(person).isEqualTo( - new Person( - "Jo", - 1, - "foo@square.com", - Arrays.asList(new PhoneNumber("555-555-5555", null, ByteString.EMPTY), new PhoneNumber("444-444-4444", null, ByteString.EMPTY)), - Arrays.asList(1, 2, 3), - ImmutableMap.builder().put(519, "555-5555").build(), - true, - ByteString.EMPTY)); + @Test + public void kotlinWithoutBuilderFromJson() { + Person person = + gson.fromJson( + "{" + + "\"id\":1," + + "\"name\":\"Jo\"," + + "\"email\":\"foo@square.com\"," + + "\"phone\":[{\"number\": \"555-555-5555\"}, {\"number\": \"444-444-4444\"}]," + + "\"favorite_numbers\":[1, 2, 3]," + + "\"area_numbers\":{\"519\":\"555-5555\"}," + + "\"is_canadian\":true" + + "}", + Person.class); + assertThat(person) + .isEqualTo( + new Person( + "Jo", + 1, + "foo@square.com", + Arrays.asList( + new PhoneNumber("555-555-5555", null, ByteString.EMPTY), + new PhoneNumber("444-444-4444", null, ByteString.EMPTY)), + Arrays.asList(1, 2, 3), + ImmutableMap.builder().put(519, "555-5555").build(), + true, + ByteString.EMPTY)); } - @Test public void kotlinWithoutBuilderToJson() { + @Test + public void kotlinWithoutBuilderToJson() { Person person = new Person( - "Jo", - 1, - "foo@square.com", - Arrays.asList(new PhoneNumber("555-555-5555", null, ByteString.EMPTY), new PhoneNumber("444-444-4444", null, ByteString.EMPTY)), - Arrays.asList(1, 2, 3), - ImmutableMap.builder().put(519, "555-5555").build(), - false, - ByteString.EMPTY); + "Jo", + 1, + "foo@square.com", + Arrays.asList( + new PhoneNumber("555-555-5555", null, ByteString.EMPTY), + new PhoneNumber("444-444-4444", null, ByteString.EMPTY)), + Arrays.asList(1, 2, 3), + ImmutableMap.builder().put(519, "555-5555").build(), + false, + ByteString.EMPTY); String json = gson.toJson(person); assertJsonEquals( - "{" - + "\"id\":1," - + "\"name\":\"Jo\"," - + "\"email\":\"foo@square.com\"," - + "\"phone\":[{\"number\": \"555-555-5555\"}, {\"number\": \"444-444-4444\"}]," - + "\"favorite_numbers\":[1, 2, 3]," - + "\"area_numbers\":{\"519\":\"555-5555\"}," - + "\"is_canadian\":false" - + "}", + "{" + + "\"id\":1," + + "\"name\":\"Jo\"," + + "\"email\":\"foo@square.com\"," + + "\"phone\":[{\"number\": \"555-555-5555\"}, {\"number\": \"444-444-4444\"}]," + + "\"favorite_numbers\":[1, 2, 3]," + + "\"area_numbers\":{\"519\":\"555-5555\"}," + + "\"is_canadian\":false" + + "}", json); } - @Test public void kotlinGettersFromJson() { - Getters getters = gson - .fromJson("{\"isa\":1,\"isA\":2,\"is_a\":3,\"is32\":32,\"isb\":true}", Getters.class); + @Test + public void kotlinGettersFromJson() { + Getters getters = + gson.fromJson("{\"isa\":1,\"isA\":2,\"is_a\":3,\"is32\":32,\"isb\":true}", Getters.class); assertThat(getters).isEqualTo(new Getters(1, 2, 3, 32, true, ByteString.EMPTY)); } - @Test public void kotlinGettersToJson() { + @Test + public void kotlinGettersToJson() { Getters getters = new Getters(1, 2, 3, 32, true, ByteString.EMPTY); String json = gson.toJson(getters); assertJsonEquals("{\"isa\":1,\"isA\":2,\"is_a\":3,\"is32\":32,\"isb\":true}", json); diff --git a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java index 9c68cfa5d5..66870453fa 100644 --- a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java +++ b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,23 @@ */ package com.squareup.wire.java; +import static com.google.common.base.Preconditions.checkArgument; +import static com.squareup.wire.schema.internal.JvmLanguages.annotationName; +import static com.squareup.wire.schema.internal.JvmLanguages.annotationTargetType; +import static com.squareup.wire.schema.internal.JvmLanguages.builtInAdapterString; +import static com.squareup.wire.schema.internal.JvmLanguages.eligibleAsAnnotationMember; +import static com.squareup.wire.schema.internal.JvmLanguages.hasEponymousType; +import static com.squareup.wire.schema.internal.JvmLanguages.javaPackage; +import static com.squareup.wire.schema.internal.JvmLanguages.legacyQualifiedFieldName; +import static com.squareup.wire.schema.internal.JvmLanguages.optionValueToInt; +import static com.squareup.wire.schema.internal.JvmLanguages.optionValueToLong; +import static javax.lang.model.element.Modifier.ABSTRACT; +import static javax.lang.model.element.Modifier.FINAL; +import static javax.lang.model.element.Modifier.PRIVATE; +import static javax.lang.model.element.Modifier.PROTECTED; +import static javax.lang.model.element.Modifier.PUBLIC; +import static javax.lang.model.element.Modifier.STATIC; + import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.cache.CacheBuilder; @@ -84,23 +101,6 @@ import javax.annotation.Nullable; import okio.ByteString; -import static com.google.common.base.Preconditions.checkArgument; -import static com.squareup.wire.schema.internal.JvmLanguages.annotationName; -import static com.squareup.wire.schema.internal.JvmLanguages.annotationTargetType; -import static com.squareup.wire.schema.internal.JvmLanguages.builtInAdapterString; -import static com.squareup.wire.schema.internal.JvmLanguages.eligibleAsAnnotationMember; -import static com.squareup.wire.schema.internal.JvmLanguages.hasEponymousType; -import static com.squareup.wire.schema.internal.JvmLanguages.javaPackage; -import static com.squareup.wire.schema.internal.JvmLanguages.legacyQualifiedFieldName; -import static com.squareup.wire.schema.internal.JvmLanguages.optionValueToInt; -import static com.squareup.wire.schema.internal.JvmLanguages.optionValueToLong; -import static javax.lang.model.element.Modifier.ABSTRACT; -import static javax.lang.model.element.Modifier.FINAL; -import static javax.lang.model.element.Modifier.PRIVATE; -import static javax.lang.model.element.Modifier.PROTECTED; -import static javax.lang.model.element.Modifier.PUBLIC; -import static javax.lang.model.element.Modifier.STATIC; - /** * Generates Java source code that matches proto definitions. * @@ -120,11 +120,14 @@ public final class JavaGenerator { static final ClassName NULLABLE = ClassName.get("androidx.annotation", "Nullable"); static final ClassName CREATOR = ClassName.get("android.os", "Parcelable", "Creator"); - private static final Ordering TAG_ORDERING = Ordering.from(new Comparator() { - @Override public int compare(Field o1, Field o2) { - return Integer.compare(o1.getTag(), o2.getTag()); - } - }); + private static final Ordering TAG_ORDERING = + Ordering.from( + new Comparator() { + @Override + public int compare(Field o1, Field o2) { + return Integer.compare(o1.getTag(), o2.getTag()); + } + }); public static boolean builtInType(ProtoType protoType) { return BUILT_IN_TYPES_MAP.containsKey(protoType); @@ -151,14 +154,18 @@ public static boolean builtInType(ProtoType protoType) { .put(ProtoType.DURATION, ClassName.get("java.time", "Duration")) .put(ProtoType.TIMESTAMP, ClassName.get("java.time", "Instant")) .put(ProtoType.EMPTY, ClassName.get("kotlin", "Unit")) - .put(ProtoType.STRUCT_MAP, ParameterizedTypeName.get( - ClassName.get("java.util", "Map"), - ClassName.get("java.lang", "String"), WildcardTypeName.subtypeOf(Object.class))) + .put( + ProtoType.STRUCT_MAP, + ParameterizedTypeName.get( + ClassName.get("java.util", "Map"), + ClassName.get("java.lang", "String"), + WildcardTypeName.subtypeOf(Object.class))) .put(ProtoType.STRUCT_VALUE, ClassName.get("java.lang", "Object")) .put(ProtoType.STRUCT_NULL, ClassName.get("java.lang", "Void")) - .put(ProtoType.STRUCT_LIST, ParameterizedTypeName.get( - ClassName.get("java.util", "List"), - WildcardTypeName.subtypeOf(Object.class))) + .put( + ProtoType.STRUCT_LIST, + ParameterizedTypeName.get( + ClassName.get("java.util", "List"), WildcardTypeName.subtypeOf(Object.class))) .put(ProtoType.DOUBLE_VALUE, TypeName.DOUBLE) .put(ProtoType.FLOAT_VALUE, TypeName.FLOAT) .put(ProtoType.INT64_VALUE, TypeName.LONG) @@ -202,45 +209,50 @@ public static boolean builtInType(ProtoType protoType) { *

"; } - documentation += "NOTE: This type only exists to maintain class structure" - + " for its nested types and is not an actual message."; + documentation += + "NOTE: This type only exists to maintain class structure" + + " for its nested types and is not an actual message."; builder.addJavadoc("$L\n", documentation); - builder.addMethod(MethodSpec.constructorBuilder() - .addModifiers(PRIVATE) - .addStatement("throw new $T()", AssertionError.class) - .build()); + builder.addMethod( + MethodSpec.constructorBuilder() + .addModifiers(PRIVATE) + .addStatement("throw new $T()", AssertionError.class) + .build()); for (Type nestedType : type.getNestedTypes()) { builder.addType(generateType(nestedType)); @@ -815,8 +904,9 @@ public TypeSpec generateAdapterForCustomType(Type type) { TypeSpec.Builder adapter; if (type instanceof MessageType) { - adapter = messageAdapter(nameAllocator, (MessageType) type, typeName, adapterTypeName, null) - .toBuilder(); + adapter = + messageAdapter(nameAllocator, (MessageType) type, typeName, adapterTypeName, null) + .toBuilder(); } else { adapter = enumAdapter(nameAllocator, (EnumType) type, typeName, adapterTypeName).toBuilder(); } @@ -825,10 +915,12 @@ public TypeSpec generateAdapterForCustomType(Type type) { for (Type nestedType : type.getNestedTypes()) { if (profile.getAdapter(nestedType.getType()) == null) { - throw new IllegalArgumentException("Missing custom proto adapter for " - + nestedType.getType().getEnclosingTypeOrPackage() + "." - + nestedType.getType().getSimpleName() - + " when enclosing proto has custom proto adapter."); + throw new IllegalArgumentException( + "Missing custom proto adapter for " + + nestedType.getType().getEnclosingTypeOrPackage() + + "." + + nestedType.getType().getSimpleName() + + " when enclosing proto has custom proto adapter."); } adapter.addType(generateAdapterForCustomType(nestedType)); } @@ -848,13 +940,22 @@ private Set collidingFieldNames(List fields) { return collidingNames; } - private FieldSpec messageAdapterField(String adapterName, ClassName javaType, - ClassName adapterJavaType, ProtoType protoType, Syntax syntax) { - FieldSpec.Builder result = FieldSpec.builder(adapterOf(javaType), adapterName) - .addModifiers(PUBLIC, STATIC, FINAL); + private FieldSpec messageAdapterField( + String adapterName, + ClassName javaType, + ClassName adapterJavaType, + ProtoType protoType, + Syntax syntax) { + FieldSpec.Builder result = + FieldSpec.builder(adapterOf(javaType), adapterName).addModifiers(PUBLIC, STATIC, FINAL); if (emitCompact) { - result.initializer("$T.newMessageAdapter($T.class, $S, $T.$L)", - ProtoAdapter.class, javaType, protoType.getTypeUrl(), Syntax.class, syntax.name()); + result.initializer( + "$T.newMessageAdapter($T.class, $S, $T.$L)", + ProtoAdapter.class, + javaType, + protoType.getTypeUrl(), + Syntax.class, + syntax.name()); } else { result.initializer("new $T()", adapterJavaType); } @@ -863,17 +964,16 @@ private FieldSpec messageAdapterField(String adapterName, ClassName javaType, /** * Generates a custom enum adapter to decode a proto enum to a user-specified Java type. Users - * need to instantiate a constant instance of this adapter that provides all enum constants in - * the constructor in the proper order. - * - *

   {@code
+   * need to instantiate a constant instance of this adapter that provides all enum constants in the
+   * constructor in the proper order.
    *
-   *   public static final ProtoAdapter ADAPTER
-   *       = new RoshamboAdapter(Roshambo.ROCK, Roshambo.SCISSORS, Roshambo.PAPER);
+   * 
{@code
+   * public static final ProtoAdapter ADAPTER
+   *     = new RoshamboAdapter(Roshambo.ROCK, Roshambo.SCISSORS, Roshambo.PAPER);
    * }
*/ - private TypeSpec enumAdapter(NameAllocator nameAllocator, EnumType type, ClassName javaType, - ClassName adapterJavaType) { + private TypeSpec enumAdapter( + NameAllocator nameAllocator, EnumType type, ClassName javaType, ClassName adapterJavaType) { String value = nameAllocator.get("value"); String i = nameAllocator.get("i"); String reader = nameAllocator.get("reader"); @@ -885,12 +985,11 @@ private TypeSpec enumAdapter(NameAllocator nameAllocator, EnumType type, ClassNa MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder(); constructorBuilder.addModifiers(PUBLIC); - constructorBuilder.addStatement("super($T.VARINT, $T.class)", - FieldEncoding.class, javaType); + constructorBuilder.addStatement("super($T.VARINT, $T.class)", FieldEncoding.class, javaType); for (EnumConstant constant : type.getConstants()) { String name = nameAllocator.get(constant); - FieldSpec.Builder fieldBuilder = FieldSpec.builder(javaType, name) - .addModifiers(PROTECTED, FINAL); + FieldSpec.Builder fieldBuilder = + FieldSpec.builder(javaType, name).addModifiers(PROTECTED, FINAL); if (!constant.getDocumentation().isEmpty()) { fieldBuilder.addJavadoc("$L\n", sanitizeJavadoc(constant.getDocumentation())); } @@ -904,10 +1003,11 @@ private TypeSpec enumAdapter(NameAllocator nameAllocator, EnumType type, ClassNa } builder.addMethod(constructorBuilder.build()); - MethodSpec.Builder toValueBuilder = MethodSpec.methodBuilder("toValue") - .addModifiers(PROTECTED) - .returns(int.class) - .addParameter(javaType, value); + MethodSpec.Builder toValueBuilder = + MethodSpec.methodBuilder("toValue") + .addModifiers(PROTECTED) + .returns(int.class) + .addParameter(javaType, value); for (EnumConstant constant : type.getConstants()) { String name = nameAllocator.get(constant); toValueBuilder.addStatement("if ($N.equals($N)) return $L", value, name, constant.getTag()); @@ -915,48 +1015,55 @@ private TypeSpec enumAdapter(NameAllocator nameAllocator, EnumType type, ClassNa toValueBuilder.addStatement("return $L", -1); builder.addMethod(toValueBuilder.build()); - MethodSpec.Builder fromValueBuilder = MethodSpec.methodBuilder("fromValue") - .addModifiers(PROTECTED) - .returns(javaType) - .addParameter(int.class, value); + MethodSpec.Builder fromValueBuilder = + MethodSpec.methodBuilder("fromValue") + .addModifiers(PROTECTED) + .returns(javaType) + .addParameter(int.class, value); fromValueBuilder.beginControlFlow("switch ($N)", value); for (EnumConstant constant : type.getConstants()) { String name = nameAllocator.get(constant); fromValueBuilder.addStatement("case $L: return $N", constant.getTag(), name); } - fromValueBuilder.addStatement("default: throw new $T($N, $T.class)", - EnumConstantNotFoundException.class, value, javaType); + fromValueBuilder.addStatement( + "default: throw new $T($N, $T.class)", + EnumConstantNotFoundException.class, + value, + javaType); fromValueBuilder.endControlFlow(); builder.addMethod(fromValueBuilder.build()); - builder.addMethod(MethodSpec.methodBuilder("encodedSize") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(int.class) - .addParameter(javaType, value) - .addStatement("return $T.UINT32.encodedSize(toValue($N))", ProtoAdapter.class, value) - .build()); + builder.addMethod( + MethodSpec.methodBuilder("encodedSize") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(int.class) + .addParameter(javaType, value) + .addStatement("return $T.UINT32.encodedSize(toValue($N))", ProtoAdapter.class, value) + .build()); builder.addMethod(enumEncode(javaType, value, i, writer, false)); builder.addMethod(enumEncode(javaType, value, i, writer, true)); - builder.addMethod(MethodSpec.methodBuilder("decode") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(javaType) - .addParameter(ProtoReader.class, reader) - .addException(IOException.class) - .addStatement("int $N = $N.readVarint32()", value, reader) - .addStatement("return fromValue($N)", value) - .build()); + builder.addMethod( + MethodSpec.methodBuilder("decode") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(javaType) + .addParameter(ProtoReader.class, reader) + .addException(IOException.class) + .addStatement("int $N = $N.readVarint32()", value, reader) + .addStatement("return fromValue($N)", value) + .build()); - builder.addMethod(MethodSpec.methodBuilder("redact") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(javaType) - .addParameter(javaType, "value") - .addStatement("return value") - .build()); + builder.addMethod( + MethodSpec.methodBuilder("redact") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(javaType) + .addParameter(javaType, "value") + .addStatement("return value") + .build()); return builder.build(); } @@ -970,8 +1077,13 @@ private MethodSpec enumEncode( .addParameter(javaType, value) .addException(IOException.class) .addStatement("int $N = toValue($N)", localInt, value) - .addStatement("if ($N == $L) throw new $T($S + $N)", - localInt, -1, ProtocolException.class, "Unexpected enum constant: ", value) + .addStatement( + "if ($N == $L) throw new $T($S + $N)", + localInt, + -1, + ProtocolException.class, + "Unexpected enum constant: ", + value) .addStatement("$N.writeVarint32($N)", localWriter, localInt) .build(); } @@ -980,25 +1092,35 @@ private TypeSpec enumAdapter(ClassName javaType, ClassName adapterJavaType, Enum return TypeSpec.classBuilder(adapterJavaType.simpleName()) .superclass(enumAdapterOf(javaType)) .addModifiers(PRIVATE, STATIC, FINAL) - .addMethod(MethodSpec.constructorBuilder() - .addStatement("super($T.class, $T.$L, $L)", - javaType, Syntax.class, enumType.getSyntax().name(), identity(enumType)) - .build()) - .addMethod(MethodSpec.methodBuilder("fromValue") - .addAnnotation(Override.class) - .addModifiers(PROTECTED) - .returns(javaType) - .addParameter(int.class, "value") - .addStatement("return $T.fromValue(value)", javaType) - .build()) + .addMethod( + MethodSpec.constructorBuilder() + .addStatement( + "super($T.class, $T.$L, $L)", + javaType, + Syntax.class, + enumType.getSyntax().name(), + identity(enumType)) + .build()) + .addMethod( + MethodSpec.methodBuilder("fromValue") + .addAnnotation(Override.class) + .addModifiers(PROTECTED) + .returns(javaType) + .addParameter(int.class, "value") + .addStatement("return $T.fromValue(value)", javaType) + .build()) .build(); } - private TypeSpec messageAdapter(NameAllocator nameAllocator, MessageType type, ClassName javaType, - ClassName adapterJavaType, ClassName builderType) { + private TypeSpec messageAdapter( + NameAllocator nameAllocator, + MessageType type, + ClassName javaType, + ClassName adapterJavaType, + ClassName builderType) { boolean useBuilder = builderType != null; - TypeSpec.Builder adapter = TypeSpec.classBuilder(adapterJavaType.simpleName()) - .superclass(adapterOf(javaType)); + TypeSpec.Builder adapter = + TypeSpec.classBuilder(adapterJavaType.simpleName()).superclass(adapterOf(javaType)); if (useBuilder) { adapter.addModifiers(PRIVATE, STATIC, FINAL); @@ -1006,27 +1128,33 @@ private TypeSpec messageAdapter(NameAllocator nameAllocator, MessageType type, C adapter.addModifiers(PUBLIC, ABSTRACT); } - adapter.addMethod(MethodSpec.constructorBuilder() - .addModifiers(PUBLIC) - .addStatement("super($T.LENGTH_DELIMITED, $T.class, $S, $T.$L, null, $S)", - FieldEncoding.class, javaType, type.getType().getTypeUrl(), Syntax.class, - type.getSyntax().name(), type.getLocation().getPath()) - .build()); + adapter.addMethod( + MethodSpec.constructorBuilder() + .addModifiers(PUBLIC) + .addStatement( + "super($T.LENGTH_DELIMITED, $T.class, $S, $T.$L, null, $S)", + FieldEncoding.class, + javaType, + type.getType().getTypeUrl(), + Syntax.class, + type.getSyntax().name(), + type.getLocation().getPath()) + .build()); if (!useBuilder) { - MethodSpec.Builder fromProto = MethodSpec.methodBuilder("fromProto") - .addModifiers(PUBLIC, ABSTRACT) - .returns(javaType); + MethodSpec.Builder fromProto = + MethodSpec.methodBuilder("fromProto").addModifiers(PUBLIC, ABSTRACT).returns(javaType); for (Field field : type.getFieldsAndOneOfFields()) { TypeName fieldType = fieldType(field); String fieldName = nameAllocator.get(field); fromProto.addParameter(fieldType, fieldName); - adapter.addMethod(MethodSpec.methodBuilder(fieldName) - .addModifiers(PUBLIC, ABSTRACT) - .addParameter(javaType, "value") - .returns(fieldType) - .build()); + adapter.addMethod( + MethodSpec.methodBuilder(fieldName) + .addModifiers(PUBLIC, ABSTRACT) + .addParameter(javaType, "value") + .returns(fieldType) + .build()); } adapter.addMethod(fromProto.build()); @@ -1052,13 +1180,14 @@ private TypeSpec messageAdapter(NameAllocator nameAllocator, MessageType type, C return adapter.build(); } - private MethodSpec messageAdapterEncodedSize(NameAllocator nameAllocator, MessageType type, - TypeName javaType, boolean useBuilder) { - MethodSpec.Builder result = MethodSpec.methodBuilder("encodedSize") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(int.class) - .addParameter(javaType, "value"); + private MethodSpec messageAdapterEncodedSize( + NameAllocator nameAllocator, MessageType type, TypeName javaType, boolean useBuilder) { + MethodSpec.Builder result = + MethodSpec.methodBuilder("encodedSize") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(int.class) + .addParameter(javaType, "value"); String resultName = nameAllocator.clone().newName("result"); result.addStatement("int $L = 0", resultName); @@ -1068,10 +1197,14 @@ private MethodSpec messageAdapterEncodedSize(NameAllocator nameAllocator, Messag CodeBlock adapter = adapterFor(field, nameAllocator); boolean omitIdentity = field.getEncodeMode().equals(Field.EncodeMode.OMIT_IDENTITY); if (omitIdentity) { - result.beginControlFlow("if (!$T.equals(value.$L, $L))", ClassName.get(Objects.class), - fieldName, identityValue(field)); + result.beginControlFlow( + "if (!$T.equals(value.$L, $L))", + ClassName.get(Objects.class), + fieldName, + identityValue(field)); } - result.addCode("$L += ", resultName) + result + .addCode("$L += ", resultName) .addCode("$L.encodedSizeWithTag($L, ", adapter, fieldTag) .addCode((useBuilder ? "value.$L" : "$L(value)"), fieldName) .addCode(");\n"); @@ -1087,14 +1220,19 @@ private MethodSpec messageAdapterEncodedSize(NameAllocator nameAllocator, Messag return result.build(); } - private MethodSpec messageAdapterEncode(NameAllocator nameAllocator, MessageType type, - TypeName javaType, boolean useBuilder, boolean reverse) { - MethodSpec.Builder result = MethodSpec.methodBuilder("encode") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .addParameter(reverse ? ReverseProtoWriter.class : ProtoWriter.class, "writer") - .addParameter(javaType, "value") - .addException(IOException.class); + private MethodSpec messageAdapterEncode( + NameAllocator nameAllocator, + MessageType type, + TypeName javaType, + boolean useBuilder, + boolean reverse) { + MethodSpec.Builder result = + MethodSpec.methodBuilder("encode") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .addParameter(reverse ? ReverseProtoWriter.class : ProtoWriter.class, "writer") + .addParameter(javaType, "value") + .addException(IOException.class); List encodeCalls = new ArrayList<>(); @@ -1104,19 +1242,22 @@ private MethodSpec messageAdapterEncode(NameAllocator nameAllocator, MessageType String fieldName = nameAllocator.get(field); CodeBlock.Builder encodeCall = CodeBlock.builder(); if (field.getEncodeMode().equals(Field.EncodeMode.OMIT_IDENTITY)) { - encodeCall.add("if (!$T.equals(value.$L, $L)) ", ClassName.get(Objects.class), - fieldName, identityValue(field)); + encodeCall.add( + "if (!$T.equals(value.$L, $L)) ", + ClassName.get(Objects.class), + fieldName, + identityValue(field)); } - encodeCall.add("$L.encodeWithTag(writer, $L, ", adapter, fieldTag) + encodeCall + .add("$L.encodeWithTag(writer, $L, ", adapter, fieldTag) .add((useBuilder ? "value.$L" : "$L(value)"), fieldName) .add(");\n"); encodeCalls.add(encodeCall.build()); } if (useBuilder) { - encodeCalls.add(CodeBlock.builder() - .addStatement("writer.writeBytes(value.unknownFields())") - .build()); + encodeCalls.add( + CodeBlock.builder().addStatement("writer.writeBytes(value.unknownFields())").build()); } if (reverse) { @@ -1130,14 +1271,19 @@ private MethodSpec messageAdapterEncode(NameAllocator nameAllocator, MessageType return result.build(); } - private MethodSpec messageAdapterDecode(NameAllocator nameAllocator, MessageType type, - TypeName javaType, boolean useBuilder, ClassName builderJavaType) { - MethodSpec.Builder result = MethodSpec.methodBuilder("decode") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(javaType) - .addParameter(ProtoReader.class, "reader") - .addException(IOException.class); + private MethodSpec messageAdapterDecode( + NameAllocator nameAllocator, + MessageType type, + TypeName javaType, + boolean useBuilder, + ClassName builderJavaType) { + MethodSpec.Builder result = + MethodSpec.methodBuilder("decode") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(javaType) + .addParameter(ProtoReader.class, "reader") + .addException(IOException.class); List fields = TAG_ORDERING.sortedCopy(type.getFieldsAndOneOfFields()); @@ -1145,8 +1291,8 @@ private MethodSpec messageAdapterDecode(NameAllocator nameAllocator, MessageType result.addStatement("$1T builder = new $1T()", builderJavaType); } else { for (Field field : fields) { - result.addStatement("$T $N = $L", - fieldType(field), nameAllocator.get(field), initialValue(field)); + result.addStatement( + "$T $N = $L", fieldType(field), nameAllocator.get(field), initialValue(field)); } } @@ -1164,8 +1310,8 @@ private MethodSpec messageAdapterDecode(NameAllocator nameAllocator, MessageType result.addCode(";\n"); if (useBuilder) { result.nextControlFlow("catch ($T e)", EnumConstantNotFoundException.class); - result.addStatement("builder.addUnknownField(tag, $T.VARINT, (long) e.value)", - FieldEncoding.class); + result.addStatement( + "builder.addUnknownField(tag, $T.VARINT, (long) e.value)", FieldEncoding.class); result.endControlFlow(); // try/catch } else { result.nextControlFlow("catch ($T ignored)", EnumConstantNotFoundException.class); @@ -1174,8 +1320,8 @@ private MethodSpec messageAdapterDecode(NameAllocator nameAllocator, MessageType result.addStatement("break"); result.endControlFlow(); // case } else { - result.addCode("case $L: $L; break;\n", - fieldTag, decodeAndAssign(field, nameAllocator, useBuilder)); + result.addCode( + "case $L: $L; break;\n", fieldTag, decodeAndAssign(field, nameAllocator, useBuilder)); } } @@ -1217,8 +1363,8 @@ private CodeBlock decodeAndAssign(Field field, NameAllocator nameAllocator, bool if (field.isRepeated()) { return useBuilder ? field.getType().equals(ProtoType.STRUCT_NULL) - ? CodeBlock.of("builder.$L.add(($T) $L)", fieldName, Void.class, decode) - : CodeBlock.of("builder.$L.add($L)", fieldName, decode) + ? CodeBlock.of("builder.$L.add(($T) $L)", fieldName, Void.class, decode) + : CodeBlock.of("builder.$L.add($L)", fieldName, decode) : CodeBlock.of("$L.add($L)", fieldName, decode); } else if (field.getType().isMap()) { return useBuilder @@ -1227,19 +1373,24 @@ private CodeBlock decodeAndAssign(Field field, NameAllocator nameAllocator, bool } else { return useBuilder ? field.getType().equals(ProtoType.STRUCT_NULL) - ? CodeBlock.of("builder.$L(($T) $L)", fieldName, Void.class, decode) - : CodeBlock.of("builder.$L($L)", fieldName, decode) + ? CodeBlock.of("builder.$L(($T) $L)", fieldName, Void.class, decode) + : CodeBlock.of("builder.$L($L)", fieldName, decode) : CodeBlock.of("$L = $L", fieldName, decode); } } - private MethodSpec messageAdapterRedact(NameAllocator nameAllocator, MessageType type, - ClassName javaType, boolean useBuilder, ClassName builderJavaType) { - MethodSpec.Builder result = MethodSpec.methodBuilder("redact") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(javaType) - .addParameter(javaType, "value"); + private MethodSpec messageAdapterRedact( + NameAllocator nameAllocator, + MessageType type, + ClassName javaType, + boolean useBuilder, + ClassName builderJavaType) { + MethodSpec.Builder result = + MethodSpec.methodBuilder("redact") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(javaType) + .addParameter(javaType, "value"); int redactedFieldCount = 0; List requiredRedacted = new ArrayList<>(); @@ -1259,9 +1410,15 @@ private MethodSpec messageAdapterRedact(NameAllocator nameAllocator, MessageType if (!requiredRedacted.isEmpty()) { boolean isPlural = requiredRedacted.size() != 1; - result.addStatement("throw new $T($S)", UnsupportedOperationException.class, - (isPlural ? "Fields" : "Field") + " '" + Joiner.on("', '").join(requiredRedacted) + "' " - + (isPlural ? "are" : "is") + " required and cannot be redacted."); + result.addStatement( + "throw new $T($S)", + UnsupportedOperationException.class, + (isPlural ? "Fields" : "Field") + + " '" + + Joiner.on("', '").join(requiredRedacted) + + "' " + + (isPlural ? "are" : "is") + + " required and cannot be redacted."); return result.build(); } @@ -1280,15 +1437,15 @@ private MethodSpec messageAdapterRedact(NameAllocator nameAllocator, MessageType } else if (!field.getType().isScalar() && !isEnum(field.getType())) { if (field.isRepeated()) { CodeBlock adapter = singleAdapterFor(field, nameAllocator); - result.addStatement("$T.redactElements(builder.$N, $L)", Internal.class, fieldName, - adapter); + result.addStatement( + "$T.redactElements(builder.$N, $L)", Internal.class, fieldName, adapter); } else if (field.getType().isMap()) { // We only need to ask the values to redact themselves if the type is a message. if (!field.getType().getValueType().isScalar() && !isEnum(field.getType().getValueType())) { CodeBlock adapter = singleAdapterFor(field.getType().getValueType()); - result.addStatement("$T.redactElements(builder.$N, $L)", Internal.class, fieldName, - adapter); + result.addStatement( + "$T.redactElements(builder.$N, $L)", Internal.class, fieldName, adapter); } } else { CodeBlock adapter = adapterFor(field, nameAllocator); @@ -1315,7 +1472,8 @@ private String fieldName(ProtoType type, Field field) { private TypeName fieldType(Field field) { ProtoType type = field.getType(); if (type.isMap()) { - return ParameterizedTypeName.get(ClassName.get(Map.class), + return ParameterizedTypeName.get( + ClassName.get(Map.class), typeName(type.getKeyType()).box(), typeName(type.getValueType()).box()); } @@ -1352,8 +1510,8 @@ private FieldSpec defaultField(NameAllocator nameAllocator, Field field, TypeNam // type = INT32 // ) // - private AnnotationSpec wireFieldAnnotation(NameAllocator nameAllocator, Field field, - MessageType message) { + private AnnotationSpec wireFieldAnnotation( + NameAllocator nameAllocator, Field field, MessageType message) { AnnotationSpec.Builder result = AnnotationSpec.builder(WireField.class); NameAllocator localNameAllocator = nameAllocator.clone(); @@ -1378,7 +1536,7 @@ private AnnotationSpec wireFieldAnnotation(NameAllocator nameAllocator, Field fi if (field.getType().isWrapper()) { wireFieldLabel = null; } else { - wireFieldLabel = WireField.Label.OMIT_IDENTITY; + wireFieldLabel = WireField.Label.OMIT_IDENTITY; } break; case REPEATED: @@ -1432,8 +1590,8 @@ private AnnotationSpec wireFieldAnnotation(NameAllocator nameAllocator, Field fi // declaredName = "final", // ) // - private @Nullable AnnotationSpec wireEnumConstantAnnotation(NameAllocator nameAllocator, - EnumConstant constant) { + private @Nullable AnnotationSpec wireEnumConstantAnnotation( + NameAllocator nameAllocator, EnumConstant constant) { AnnotationSpec.Builder result = AnnotationSpec.builder(WireEnumConstant.class); NameAllocator localNameAllocator = nameAllocator.clone(); @@ -1515,8 +1673,7 @@ private MethodSpec messageFieldsConstructor(NameAllocator nameAllocator, Message // } // private MethodSpec messageConstructor( - NameAllocator nameAllocator, MessageType type, - ClassName builderJavaType) { + NameAllocator nameAllocator, MessageType type, ClassName builderJavaType) { boolean constructorTakesAllFields = constructorTakesAllFields(type); NameAllocator localNameAllocator = nameAllocator.clone(); @@ -1524,8 +1681,9 @@ private MethodSpec messageConstructor( String adapterName = localNameAllocator.get("ADAPTER"); String unknownFieldsName = localNameAllocator.newName("unknownFields"); String builderName = localNameAllocator.newName("builder"); - MethodSpec.Builder result = MethodSpec.constructorBuilder() - .addStatement("super($N, $N)", adapterName, unknownFieldsName); + MethodSpec.Builder result = + MethodSpec.constructorBuilder() + .addStatement("super($N, $N)", adapterName, unknownFieldsName); if (!buildersOnly) result.addModifiers(PUBLIC); for (OneOf oneOf : type.getOneOfs()) { @@ -1543,16 +1701,16 @@ private MethodSpec messageConstructor( } CodeBlock fieldNames = fieldNamesBuilder.build(); result.beginControlFlow("if ($T.countNonNull($L) > 1)", Internal.class, fieldNames); - result.addStatement("throw new IllegalArgumentException($S)", + result.addStatement( + "throw new IllegalArgumentException($S)", "at most one of " + fieldNames + " may be non-null"); result.endControlFlow(); } for (Field field : type.getFieldsAndOneOfFields()) { TypeName javaType = fieldType(field); String fieldName = localNameAllocator.get(field); - String fieldAccessName = constructorTakesAllFields - ? fieldName - : builderName + "." + fieldName; + String fieldAccessName = + constructorTakesAllFields ? fieldName : builderName + "." + fieldName; if (constructorTakesAllFields) { ParameterSpec.Builder param = ParameterSpec.builder(javaType, fieldName); @@ -1565,24 +1723,30 @@ private MethodSpec messageConstructor( if (field.getEncodeMode() == Field.EncodeMode.OMIT_IDENTITY) { // Other scalars use not-boxed types to guarantee a value. if (field.getType().isScalar() - && (field.getType() == ProtoType.STRING || field.getType() == ProtoType.BYTES) + && (field.getType() == ProtoType.STRING || field.getType() == ProtoType.BYTES) || (isEnum(field.getType()) && !field.getType().equals(ProtoType.STRUCT_NULL))) { result.beginControlFlow("if ($L == null)", fieldAccessName); - result.addStatement("throw new IllegalArgumentException($S)", - fieldAccessName + " == null"); + result.addStatement( + "throw new IllegalArgumentException($S)", fieldAccessName + " == null"); result.endControlFlow(); } } if (field.getType().isMap() && isStruct(field.getType().getValueType())) { - result.addStatement("this.$1L = $2T.immutableCopyOfMapWithStructValues($1S, $3L)", - fieldName, Internal.class, fieldAccessName); + result.addStatement( + "this.$1L = $2T.immutableCopyOfMapWithStructValues($1S, $3L)", + fieldName, + Internal.class, + fieldAccessName); } else if (isStruct(field.getType())) { - result.addStatement("this.$1L = $2T.immutableCopyOfStruct($1S, $3L)", fieldName, - Internal.class, fieldAccessName); + result.addStatement( + "this.$1L = $2T.immutableCopyOfStruct($1S, $3L)", + fieldName, + Internal.class, + fieldAccessName); } else if (field.isRepeated() || field.getType().isMap()) { - result.addStatement("this.$1L = $2T.immutableCopyOf($1S, $3L)", fieldName, - Internal.class, fieldAccessName); + result.addStatement( + "this.$1L = $2T.immutableCopyOf($1S, $3L)", fieldName, Internal.class, fieldAccessName); } else { result.addStatement("this.$1L = $2L", fieldName, fieldAccessName); } @@ -1632,11 +1796,12 @@ private MethodSpec messageEquals(NameAllocator nameAllocator, MessageType type) String oName = localNameAllocator.newName("o"); TypeName javaType = typeName(type.getType()); - MethodSpec.Builder result = MethodSpec.methodBuilder("equals") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(boolean.class) - .addParameter(Object.class, otherName); + MethodSpec.Builder result = + MethodSpec.methodBuilder("equals") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(boolean.class) + .addParameter(Object.class, otherName); result.addStatement("if ($N == this) return true", otherName); result.addStatement("if (!($N instanceof $T)) return false", otherName, javaType); @@ -1678,10 +1843,11 @@ private MethodSpec messageHashCode(NameAllocator nameAllocator, MessageType type NameAllocator localNameAllocator = nameAllocator.clone(); String resultName = localNameAllocator.newName("result"); - MethodSpec.Builder result = MethodSpec.methodBuilder("hashCode") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(int.class); + MethodSpec.Builder result = + MethodSpec.methodBuilder("hashCode") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(int.class); List fields = type.getFieldsAndOneOfFields(); if (fields.isEmpty()) { @@ -1706,9 +1872,7 @@ private MethodSpec messageHashCode(NameAllocator nameAllocator, MessageType type result.addStatement("$T.hashCode($N)", Float.class, fieldName); } else if (typeName == TypeName.DOUBLE) { result.addStatement("$T.hashCode($N)", Double.class, fieldName); - } else if (field.isRequired() - || field.isRepeated() - || field.getType().isMap()) { + } else if (field.isRequired() || field.isRepeated() || field.getType().isMap()) { result.addStatement("$L.hashCode()", fieldName); } else { result.addStatement("($1L != null ? $1L.hashCode() : 0)", fieldName); @@ -1731,19 +1895,22 @@ private MethodSpec messageHashCode(NameAllocator nameAllocator, MessageType type // return result; // } // - private MethodSpec mapAdapter(NameAllocator nameAllocator, TypeName adapterType, String fieldName, - ProtoType mapType) { + private MethodSpec mapAdapter( + NameAllocator nameAllocator, TypeName adapterType, String fieldName, ProtoType mapType) { NameAllocator localNameAllocator = nameAllocator.clone(); String resultName = localNameAllocator.newName("result"); - MethodSpec.Builder result = MethodSpec.methodBuilder(fieldName + "Adapter") - .addModifiers(PRIVATE) - .returns(adapterType); + MethodSpec.Builder result = + MethodSpec.methodBuilder(fieldName + "Adapter").addModifiers(PRIVATE).returns(adapterType); result.addStatement("$T $N = $N", adapterType, resultName, fieldName); result.beginControlFlow("if ($N == null)", resultName); - result.addStatement("$N = $T.newMapAdapter($L, $L)", resultName, ADAPTER, - singleAdapterFor(mapType.getKeyType()), singleAdapterFor(mapType.getValueType())); + result.addStatement( + "$N = $T.newMapAdapter($L, $L)", + resultName, + ADAPTER, + singleAdapterFor(mapType.getKeyType()), + singleAdapterFor(mapType.getValueType())); result.addStatement("$N = $N", fieldName, resultName); result.endControlFlow(); result.addStatement("return $N", resultName); @@ -1753,10 +1920,11 @@ private MethodSpec mapAdapter(NameAllocator nameAllocator, TypeName adapterType, private MethodSpec messageToString(NameAllocator nameAllocator, MessageType type) { NameAllocator localNameAllocator = nameAllocator.clone(); - MethodSpec.Builder result = MethodSpec.methodBuilder("toString") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(String.class); + MethodSpec.Builder result = + MethodSpec.methodBuilder("toString") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(String.class); String builderName = localNameAllocator.newName("builder"); result.addStatement("$1T $2N = new $1T()", StringBuilder.class, builderName); @@ -1770,27 +1938,31 @@ private MethodSpec messageToString(NameAllocator nameAllocator, MessageType type result.addCode("if ($N != null) ", fieldName); } if (field.isRedacted()) { - result.addStatement("$N.append(\", $N=$L\")", builderName, field.getName(), - DOUBLE_FULL_BLOCK); + result.addStatement( + "$N.append(\", $N=$L\")", builderName, field.getName(), DOUBLE_FULL_BLOCK); } else if (field.getType().equals(ProtoType.STRING)) { - result.addStatement("$N.append(\", $N=\").append($T.sanitize($L))", builderName, - field.getName(), Internal.class, fieldName); - } else { - result.addStatement("$N.append(\", $N=\").append($L)", builderName, field.getName(), + result.addStatement( + "$N.append(\", $N=\").append($T.sanitize($L))", + builderName, + field.getName(), + Internal.class, fieldName); + } else { + result.addStatement( + "$N.append(\", $N=\").append($L)", builderName, field.getName(), fieldName); } } - result.addStatement("return builder.replace(0, 2, \"$L{\").append('}').toString()", + result.addStatement( + "return builder.replace(0, 2, \"$L{\").append('}').toString()", type.getType().getSimpleName()); return result.build(); } - private TypeSpec builder(NameAllocator nameAllocator, MessageType type, ClassName javaType, - ClassName builderType) { - TypeSpec.Builder result = TypeSpec.classBuilder("Builder") - .addModifiers(PUBLIC, STATIC, FINAL); + private TypeSpec builder( + NameAllocator nameAllocator, MessageType type, ClassName javaType, ClassName builderType) { + TypeSpec.Builder result = TypeSpec.classBuilder("Builder").addModifiers(PUBLIC, STATIC, FINAL); result.superclass(builderOf(javaType, builderType)); @@ -1868,11 +2040,12 @@ private MethodSpec newBuilder(NameAllocator nameAllocator, MessageType message) ClassName javaType = (ClassName) typeName(message.getType()); ClassName builderJavaType = javaType.nestedClass("Builder"); - MethodSpec.Builder result = MethodSpec.methodBuilder("newBuilder") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(builderJavaType) - .addStatement("$1T $2L = new $1T()", builderJavaType, builderName); + MethodSpec.Builder result = + MethodSpec.methodBuilder("newBuilder") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(builderJavaType) + .addStatement("$1T $2L = new $1T()", builderJavaType, builderName); List fields = message.getFieldsAndOneOfFields(); for (Field field : fields) { @@ -1894,10 +2067,11 @@ private MethodSpec setter( TypeName javaType = fieldType(field); String fieldName = nameAllocator.get(field); - MethodSpec.Builder result = MethodSpec.methodBuilder(fieldName) - .addModifiers(PUBLIC) - .addParameter(javaType, fieldName) - .returns(builderType); + MethodSpec.Builder result = + MethodSpec.methodBuilder(fieldName) + .addModifiers(PUBLIC) + .addParameter(javaType, fieldName) + .returns(builderType); if (!field.getDocumentation().isEmpty()) { result.addJavadoc("$L\n", sanitizeJavadoc(field.getDocumentation())); @@ -1940,10 +2114,11 @@ private MethodSpec setter( // private MethodSpec builderBuild( NameAllocator nameAllocator, MessageType message, ClassName javaType) { - MethodSpec.Builder result = MethodSpec.methodBuilder("build") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(javaType); + MethodSpec.Builder result = + MethodSpec.methodBuilder("build") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(javaType); List requiredFields = message.getRequiredFields(); if (!requiredFields.isEmpty()) { @@ -1954,13 +2129,12 @@ private MethodSpec builderBuild( if (i > 0) conditionals.add("\n|| "); conditionals.add("$L == null", nameAllocator.get(requiredField)); if (i > 0) missingArgs.add(",\n"); - missingArgs.add("$1L, $2S", nameAllocator.get(requiredField), - requiredField.getName()); + missingArgs.add("$1L, $2S", nameAllocator.get(requiredField), requiredField.getName()); } - result.beginControlFlow("if ($L)", conditionals.add("$]").build()) - .addStatement("throw $T.missingRequiredFields($L)", Internal.class, - missingArgs.build()) + result + .beginControlFlow("if ($L)", conditionals.add("$]").build()) + .addStatement("throw $T.missingRequiredFields($L)", Internal.class, missingArgs.build()) .endControlFlow(); } @@ -2019,7 +2193,7 @@ private CodeBlock fieldInitializer(ProtoType type, @Nullable Object value, boole ProtoMember protoMember = (ProtoMember) entry.getKey(); Field field = schema.getField(protoMember); CodeBlock valueInitializer = - fieldInitializer(field.getType(), entry.getValue(), annotation); + fieldInitializer(field.getType(), entry.getValue(), annotation); builder.add("\n$>$>.$L($L)$<$<", fieldName(type, field), valueInitializer); } builder.add("\n$>$>.build()$<$<"); @@ -2067,7 +2241,9 @@ private CodeBlock fieldInitializer(ProtoType type, @Nullable Object value, boole if (value == null) { return CodeBlock.of("$T.EMPTY", ByteString.class); } else { - return CodeBlock.of("$T.decodeBase64($S)", ByteString.class, + return CodeBlock.of( + "$T.decodeBase64($S)", + ByteString.class, ByteString.encodeString(String.valueOf(value), Charsets.ISO_8859_1).base64()); } @@ -2117,7 +2293,9 @@ private CodeBlock identity(EnumType enumType) { EnumConstant constantZero = enumType.constant(0); if (constantZero == null) return CodeBlock.of("null"); - return CodeBlock.of("$T.$L", typeName(enumType.getType()), + return CodeBlock.of( + "$T.$L", + typeName(enumType.getType()), nameAllocators.getUnchecked(enumType).get(constantZero)); } @@ -2146,12 +2324,12 @@ public ClassName generatedTypeName(ProtoMember member) { if (field.getLabel().equals(Field.Label.REPEATED)) { TypeName typeName = typeName(field.getType()); if (typeName.equals(TypeName.LONG) - || typeName.equals(TypeName.INT) - || typeName.equals(TypeName.FLOAT) - || typeName.equals(TypeName.DOUBLE) - || typeName.equals(TypeName.BOOLEAN) - || typeName.equals(ClassName.get(String.class)) - || isEnum(field.getType())) { + || typeName.equals(TypeName.INT) + || typeName.equals(TypeName.FLOAT) + || typeName.equals(TypeName.DOUBLE) + || typeName.equals(TypeName.BOOLEAN) + || typeName.equals(ClassName.get(String.class)) + || isEnum(field.getType())) { returnType = ArrayTypeName.of(typeName); } else { throw new IllegalStateException("Unsupported annotation for " + field.getType()); @@ -2162,23 +2340,27 @@ public ClassName generatedTypeName(ProtoMember member) { ClassName javaType = generatedTypeName(extend.member(field)); - TypeSpec.Builder builder = TypeSpec.annotationBuilder(javaType.simpleName()) - .addModifiers(PUBLIC) - .addAnnotation(AnnotationSpec.builder(Retention.class) - .addMember("value", "$T.$L", RetentionPolicy.class, RetentionPolicy.RUNTIME) - .build()) - .addAnnotation(AnnotationSpec.builder(Target.class) - .addMember("value", "$T.$L", ElementType.class, elementType) - .build()); + TypeSpec.Builder builder = + TypeSpec.annotationBuilder(javaType.simpleName()) + .addModifiers(PUBLIC) + .addAnnotation( + AnnotationSpec.builder(Retention.class) + .addMember("value", "$T.$L", RetentionPolicy.class, RetentionPolicy.RUNTIME) + .build()) + .addAnnotation( + AnnotationSpec.builder(Target.class) + .addMember("value", "$T.$L", ElementType.class, elementType) + .build()); if (!field.getDocumentation().isEmpty()) { builder.addJavadoc("$L\n", field.getDocumentation()); } - builder.addMethod(MethodSpec.methodBuilder("value") - .returns(returnType) - .addModifiers(PUBLIC, ABSTRACT) - .build()); + builder.addMethod( + MethodSpec.methodBuilder("value") + .returns(returnType) + .addModifiers(PUBLIC, ABSTRACT) + .build()); return builder.build(); } @@ -2205,9 +2387,6 @@ private List optionAnnotations(Options options) { ClassName type = annotationName(protoFile, field, new ClassNameFactory()); CodeBlock fieldValue = fieldInitializer(field.getType(), value, true); - return AnnotationSpec.builder(type) - .addMember("value", fieldValue) - .build(); + return AnnotationSpec.builder(type).addMember("value", fieldValue).build(); } } - diff --git a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt index fcd82420e0..1d537c1a6a 100644 --- a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt +++ b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaSchemaHandler.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.java import com.squareup.javapoet.JavaFile @@ -8,8 +23,8 @@ import com.squareup.wire.schema.Schema import com.squareup.wire.schema.SchemaHandler import com.squareup.wire.schema.Service import com.squareup.wire.schema.Type -import okio.Path import java.io.IOException +import okio.Path class JavaSchemaHandler( /** True for emitted types to implement `android.os.Parcelable`. */ @@ -87,7 +102,9 @@ class JavaSchemaHandler( "${javaTypeName.simpleName()}.java" context.logger.artifactHandled( - outDirectory, "${javaFile.packageName}.${javaFile.typeSpec.name}", "Java" + outDirectory, + "${javaFile.packageName}.${javaFile.typeSpec.name}", + "Java", ) try { context.fileSystem.createDirectories(filePath.parent!!) @@ -96,7 +113,8 @@ class JavaSchemaHandler( } } catch (e: IOException) { throw IOException( - "Error emitting ${javaFile.packageName}.${javaFile.typeSpec.name} to $outDirectory", e + "Error emitting ${javaFile.packageName}.${javaFile.typeSpec.name} to $outDirectory", + e, ) } return filePath diff --git a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt index 59781c58fd..9637f699e8 100644 --- a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt +++ b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorHelper.kt @@ -1,11 +1,11 @@ /* - * Copyright (C) 2022 Block, Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -48,7 +48,8 @@ internal class JavaGeneratorHelper(private val schema: Schema) { } @Throws(IOException::class) - @JvmOverloads fun generateJava(typeName: String, profileName: String? = null): String { + @JvmOverloads + fun generateJava(typeName: String, profileName: String? = null): String { val javaGenerator = JavaGenerator.get(schema) .withProfile(profile(profileName)) val type = schema.getType(typeName) diff --git a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java index 5a2772f066..592127e10e 100644 --- a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java +++ b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaGeneratorTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,10 @@ */ package com.squareup.wire.java; +import static com.google.common.truth.Truth.assertThat; +import static com.squareup.wire.schema.SchemaHelpersKt.addFromTest; +import static org.junit.Assert.fail; + import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.TypeSpec; import com.squareup.wire.SchemaBuilder; @@ -25,382 +29,434 @@ import okio.Path; import org.junit.Test; -import static com.google.common.truth.Truth.assertThat; -import static com.squareup.wire.schema.SchemaHelpersKt.addFromTest; -import static org.junit.Assert.fail; - public final class JavaGeneratorTest { - @Test public void sanitizeJavadocStripsTrailingWhitespace() { + @Test + public void sanitizeJavadocStripsTrailingWhitespace() { String input = "The quick brown fox \nJumps over \n\t \t\nThe lazy dog "; String expected = "The quick brown fox\nJumps over\n\nThe lazy dog"; assertThat(JavaGenerator.sanitizeJavadoc(input)).isEqualTo(expected); } - @Test public void sanitizeJavadocWrapsSeeLinks() { + @Test + public void sanitizeJavadocWrapsSeeLinks() { String input = "Google query.\n\n@see http://google.com"; String expected = "Google query.\n\n@see http://google.com"; assertThat(JavaGenerator.sanitizeJavadoc(input)).isEqualTo(expected); } - @Test public void sanitizeJavadocStarSlash() { + @Test + public void sanitizeJavadocStarSlash() { String input = "/* comment inside comment. */"; String expected = "/* comment inside comment. */"; assertThat(JavaGenerator.sanitizeJavadoc(input)).isEqualTo(expected); } - @Test public void generateTypeUsesNameAllocatorInMessageBuilderBuild() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message Message {\n" - + " required float long = 1;\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .generateJava("Message")).contains("" - + " @Override\n" - + " public Message build() {\n" - + " if (long_ == null) {\n" - + " throw Internal.missingRequiredFields(long_, \"long\");\n" - + " }\n" - + " return new Message(long_, super.buildUnknownFields());\n" - + " }\n"); + @Test + public void generateTypeUsesNameAllocatorInMessageBuilderBuild() throws Exception { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + "message Message {\n" + " required float long = 1;\n" + "}\n") + .build(); + assertThat(new JavaWithProfilesGenerator(schema).generateJava("Message")) + .contains( + "" + + " @Override\n" + + " public Message build() {\n" + + " if (long_ == null) {\n" + + " throw Internal.missingRequiredFields(long_, \"long\");\n" + + " }\n" + + " return new Message(long_, super.buildUnknownFields());\n" + + " }\n"); } - @Test public void tooManyFieldsTest() throws Exception { + @Test + public void tooManyFieldsTest() throws Exception { StringBuilder s = new StringBuilder(); for (int i = 1; i < 257; i++) { s.append(" repeated int32 field_" + i + " = " + i + ";\n"); } - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message Message {\n" - + s.toString() - + " oneof oneof_name {\n" - + " int32 foo = 257;\n" - + " int32 bar = 258;\n" - + " }\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .generateJava("Message")).contains("" - + "public Message(Builder builder, ByteString unknownFields)"); + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message Message {\n" + + s.toString() + + " oneof oneof_name {\n" + + " int32 foo = 257;\n" + + " int32 bar = 258;\n" + + " }\n" + + "}\n") + .build(); + assertThat(new JavaWithProfilesGenerator(schema).generateJava("Message")) + .contains("" + "public Message(Builder builder, ByteString unknownFields)"); } - @Test public void map() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message Message {\n" - + " map templates = 1;\n" - + " message CdnResource {\n" - + " }\n" - + "}\n") - .build(); + @Test + public void map() throws Exception { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message Message {\n" + + " map templates = 1;\n" + + " message CdnResource {\n" + + " }\n" + + "}\n") + .build(); MessageType message = (MessageType) schema.getType("Message"); JavaGenerator javaGenerator = JavaGenerator.get(schema); TypeSpec typeSpec = javaGenerator.generateType(message); - assertThat(JavaFile.builder("", typeSpec).build().toString()).contains("" - + " @WireField(\n" - + " tag = 1,\n" - + " keyAdapter = \"com.squareup.wire.ProtoAdapter#STRING\",\n" - + " adapter = \"Message$CdnResource#ADAPTER\"\n" - + " )\n" - + " public final Map templates;\n"); + assertThat(JavaFile.builder("", typeSpec).build().toString()) + .contains( + "" + + " @WireField(\n" + + " tag = 1,\n" + + " keyAdapter = \"com.squareup.wire.ProtoAdapter#STRING\",\n" + + " adapter = \"Message$CdnResource#ADAPTER\"\n" + + " )\n" + + " public final Map templates;\n"); } - @Test public void generateAbstractAdapter() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "package original.proto;\n" - + "option java_package = \"original.java\";\n" - + "import \"foo.proto\";\n" - + "message ProtoMessage {\n" - + " optional foo.proto.Foo field = 1;\n" - + " repeated int32 numbers = 3;\n" - + " optional foo.proto.CoinFlip coin_flip = 4;\n" - + " map bars = 2;\n" - + "}\n") - .add(Path.get("foo.proto"), "" - + "package foo.proto;\n" - + "option java_package = \"foo.java\";\n" - + "message Foo {\n" - + "}\n" - + "message Bar {\n" - + "}\n" - + "enum CoinFlip {\n" - + " HEADS = 1;\n" - + " TAILS = 2;\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .withProfile("android.wire", "" - + "syntax = \"wire2\";\n" - + "import \"message.proto\";\n" - + "package original.proto;\n" - + "type original.proto.ProtoMessage {\n" - + " target target.java.JavaMessage using target.java.JavaMessage#ADAPTER;\n" - + "}\n") - .generateJava("original.proto.ProtoMessage", "android")).isEqualTo("" - + "package original.java;\n" - + "\n" - + "import com.squareup.wire.FieldEncoding;\n" - + "import com.squareup.wire.ProtoAdapter;\n" - + "import com.squareup.wire.ProtoReader;\n" - + "import com.squareup.wire.ProtoWriter;\n" - + "import com.squareup.wire.ReverseProtoWriter;\n" - + "import com.squareup.wire.Syntax;\n" - + "import com.squareup.wire.internal.Internal;\n" - + "import foo.java.Bar;\n" - + "import foo.java.CoinFlip;\n" - + "import foo.java.Foo;\n" - + "import java.io.IOException;\n" - + "import java.lang.Integer;\n" - + "import java.lang.Override;\n" - + "import java.lang.String;\n" - + "import java.util.List;\n" - + "import java.util.Map;\n" - + "import target.java.JavaMessage;\n" - + "\n" - + "public abstract class AbstractProtoMessageAdapter extends ProtoAdapter {\n" - + " private ProtoAdapter> bars;\n" - + "\n" - + " public AbstractProtoMessageAdapter() {\n" - + " super(FieldEncoding.LENGTH_DELIMITED, JavaMessage.class, \"type.googleapis.com/original.proto.ProtoMessage\", Syntax.PROTO_2, null, \"message.proto\");\n" - + " }\n" - + "\n" - + " public abstract Foo field(JavaMessage value);\n" - + "\n" - + " public abstract List numbers(JavaMessage value);\n" - + "\n" - + " public abstract CoinFlip coin_flip(JavaMessage value);\n" - + "\n" - + " public abstract Map bars(JavaMessage value);\n" - + "\n" - + " public abstract JavaMessage fromProto(Foo field, List numbers, CoinFlip coin_flip,\n" - + " Map bars);\n" - + "\n" - + " @Override\n" - + " public int encodedSize(JavaMessage value) {\n" - + " int result = 0;\n" - + " result += Foo.ADAPTER.encodedSizeWithTag(1, field(value));\n" - + " result += ProtoAdapter.INT32.asRepeated().encodedSizeWithTag(3, numbers(value));\n" - + " result += CoinFlip.ADAPTER.encodedSizeWithTag(4, coin_flip(value));\n" - + " result += barsAdapter().encodedSizeWithTag(2, bars(value));\n" - + " return result;\n" - + " }\n" - + "\n" - + " @Override\n" - + " public void encode(ProtoWriter writer, JavaMessage value) throws IOException {\n" - + " Foo.ADAPTER.encodeWithTag(writer, 1, field(value));\n" - + " ProtoAdapter.INT32.asRepeated().encodeWithTag(writer, 3, numbers(value));\n" - + " CoinFlip.ADAPTER.encodeWithTag(writer, 4, coin_flip(value));\n" - + " barsAdapter().encodeWithTag(writer, 2, bars(value));\n" - + " }\n" - + "\n" - + " @Override\n" - + " public void encode(ReverseProtoWriter writer, JavaMessage value) throws IOException {\n" - + " barsAdapter().encodeWithTag(writer, 2, bars(value));\n" - + " CoinFlip.ADAPTER.encodeWithTag(writer, 4, coin_flip(value));\n" - + " ProtoAdapter.INT32.asRepeated().encodeWithTag(writer, 3, numbers(value));\n" - + " Foo.ADAPTER.encodeWithTag(writer, 1, field(value));\n" - + " }\n" - + "\n" - + " @Override\n" - + " public JavaMessage decode(ProtoReader reader) throws IOException {\n" - + " Foo field = null;\n" - + " Map bars = Internal.newMutableMap();\n" - + " List numbers = Internal.newMutableList();\n" - + " CoinFlip coin_flip = null;\n" - + " long token = reader.beginMessage();\n" - + " for (int tag; (tag = reader.nextTag()) != -1;) {\n" - + " switch (tag) {\n" - + " case 1: field = Foo.ADAPTER.decode(reader); break;\n" - + " case 2: bars.putAll(barsAdapter().decode(reader)); break;\n" - + " case 3: numbers.add(ProtoAdapter.INT32.decode(reader)); break;\n" - + " case 4: {\n" - + " try {\n" - + " coin_flip = CoinFlip.ADAPTER.decode(reader);\n" - + " } catch (ProtoAdapter.EnumConstantNotFoundException ignored) {\n" - + " }\n" - + " break;\n" - + " }\n" - + " default: {\n" - + " reader.skip();\n" - + " }\n" - + " }\n" - + " }\n" - + " reader.endMessageAndGetUnknownFields(token);\n" - + " return fromProto(field, numbers, coin_flip, bars);\n" - + " }\n" - + "\n" - + " @Override\n" - + " public JavaMessage redact(JavaMessage value) {\n" - + " return value;\n" - + " }\n" - + "\n" - + " private ProtoAdapter> barsAdapter() {\n" - + " ProtoAdapter> result = bars;\n" - + " if (result == null) {\n" - + " result = ProtoAdapter.newMapAdapter(ProtoAdapter.STRING, Bar.ADAPTER);\n" - + " bars = result;\n" - + " }\n" - + " return result;\n" - + " }\n" - + "}\n"); + @Test + public void generateAbstractAdapter() throws Exception { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "package original.proto;\n" + + "option java_package = \"original.java\";\n" + + "import \"foo.proto\";\n" + + "message ProtoMessage {\n" + + " optional foo.proto.Foo field = 1;\n" + + " repeated int32 numbers = 3;\n" + + " optional foo.proto.CoinFlip coin_flip = 4;\n" + + " map bars = 2;\n" + + "}\n") + .add( + Path.get("foo.proto"), + "" + + "package foo.proto;\n" + + "option java_package = \"foo.java\";\n" + + "message Foo {\n" + + "}\n" + + "message Bar {\n" + + "}\n" + + "enum CoinFlip {\n" + + " HEADS = 1;\n" + + " TAILS = 2;\n" + + "}\n") + .build(); + assertThat( + new JavaWithProfilesGenerator(schema) + .withProfile( + "android.wire", + "" + + "syntax = \"wire2\";\n" + + "import \"message.proto\";\n" + + "package original.proto;\n" + + "type original.proto.ProtoMessage {\n" + + " target target.java.JavaMessage using target.java.JavaMessage#ADAPTER;\n" + + "}\n") + .generateJava("original.proto.ProtoMessage", "android")) + .isEqualTo( + "" + + "package original.java;\n" + + "\n" + + "import com.squareup.wire.FieldEncoding;\n" + + "import com.squareup.wire.ProtoAdapter;\n" + + "import com.squareup.wire.ProtoReader;\n" + + "import com.squareup.wire.ProtoWriter;\n" + + "import com.squareup.wire.ReverseProtoWriter;\n" + + "import com.squareup.wire.Syntax;\n" + + "import com.squareup.wire.internal.Internal;\n" + + "import foo.java.Bar;\n" + + "import foo.java.CoinFlip;\n" + + "import foo.java.Foo;\n" + + "import java.io.IOException;\n" + + "import java.lang.Integer;\n" + + "import java.lang.Override;\n" + + "import java.lang.String;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import target.java.JavaMessage;\n" + + "\n" + + "public abstract class AbstractProtoMessageAdapter extends ProtoAdapter {\n" + + " private ProtoAdapter> bars;\n" + + "\n" + + " public AbstractProtoMessageAdapter() {\n" + + " super(FieldEncoding.LENGTH_DELIMITED, JavaMessage.class, \"type.googleapis.com/original.proto.ProtoMessage\", Syntax.PROTO_2, null, \"message.proto\");\n" + + " }\n" + + "\n" + + " public abstract Foo field(JavaMessage value);\n" + + "\n" + + " public abstract List numbers(JavaMessage value);\n" + + "\n" + + " public abstract CoinFlip coin_flip(JavaMessage value);\n" + + "\n" + + " public abstract Map bars(JavaMessage value);\n" + + "\n" + + " public abstract JavaMessage fromProto(Foo field, List numbers, CoinFlip coin_flip,\n" + + " Map bars);\n" + + "\n" + + " @Override\n" + + " public int encodedSize(JavaMessage value) {\n" + + " int result = 0;\n" + + " result += Foo.ADAPTER.encodedSizeWithTag(1, field(value));\n" + + " result += ProtoAdapter.INT32.asRepeated().encodedSizeWithTag(3, numbers(value));\n" + + " result += CoinFlip.ADAPTER.encodedSizeWithTag(4, coin_flip(value));\n" + + " result += barsAdapter().encodedSizeWithTag(2, bars(value));\n" + + " return result;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void encode(ProtoWriter writer, JavaMessage value) throws IOException {\n" + + " Foo.ADAPTER.encodeWithTag(writer, 1, field(value));\n" + + " ProtoAdapter.INT32.asRepeated().encodeWithTag(writer, 3, numbers(value));\n" + + " CoinFlip.ADAPTER.encodeWithTag(writer, 4, coin_flip(value));\n" + + " barsAdapter().encodeWithTag(writer, 2, bars(value));\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void encode(ReverseProtoWriter writer, JavaMessage value) throws IOException {\n" + + " barsAdapter().encodeWithTag(writer, 2, bars(value));\n" + + " CoinFlip.ADAPTER.encodeWithTag(writer, 4, coin_flip(value));\n" + + " ProtoAdapter.INT32.asRepeated().encodeWithTag(writer, 3, numbers(value));\n" + + " Foo.ADAPTER.encodeWithTag(writer, 1, field(value));\n" + + " }\n" + + "\n" + + " @Override\n" + + " public JavaMessage decode(ProtoReader reader) throws IOException {\n" + + " Foo field = null;\n" + + " Map bars = Internal.newMutableMap();\n" + + " List numbers = Internal.newMutableList();\n" + + " CoinFlip coin_flip = null;\n" + + " long token = reader.beginMessage();\n" + + " for (int tag; (tag = reader.nextTag()) != -1;) {\n" + + " switch (tag) {\n" + + " case 1: field = Foo.ADAPTER.decode(reader); break;\n" + + " case 2: bars.putAll(barsAdapter().decode(reader)); break;\n" + + " case 3: numbers.add(ProtoAdapter.INT32.decode(reader)); break;\n" + + " case 4: {\n" + + " try {\n" + + " coin_flip = CoinFlip.ADAPTER.decode(reader);\n" + + " } catch (ProtoAdapter.EnumConstantNotFoundException ignored) {\n" + + " }\n" + + " break;\n" + + " }\n" + + " default: {\n" + + " reader.skip();\n" + + " }\n" + + " }\n" + + " }\n" + + " reader.endMessageAndGetUnknownFields(token);\n" + + " return fromProto(field, numbers, coin_flip, bars);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public JavaMessage redact(JavaMessage value) {\n" + + " return value;\n" + + " }\n" + + "\n" + + " private ProtoAdapter> barsAdapter() {\n" + + " ProtoAdapter> result = bars;\n" + + " if (result == null) {\n" + + " result = ProtoAdapter.newMapAdapter(ProtoAdapter.STRING, Bar.ADAPTER);\n" + + " bars = result;\n" + + " }\n" + + " return result;\n" + + " }\n" + + "}\n"); } - @Test public void generateAbstractAdapterForEnum() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "package original.proto;\n" - + "message ProtoMessage {\n" - + " optional CoinFlip coin_flip = 1;\n" - + "}\n" - + "enum CoinFlip {\n" - + " // In Canada this is the Queen!\n" - + " HEADS = 1;\n" - + " TAILS = 2;\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .withProfile("android.wire", "" - + "syntax = \"wire2\";\n" - + "import \"message.proto\";\n" - + "package original.proto;\n" - + "type original.proto.CoinFlip {\n" - + " target target.java.JavaCoinFlip using target.java.JavaCoinFlip#ADAPTER;\n" - + "}\n") - .generateJava("original.proto.CoinFlip", "android")).isEqualTo("" - + "package original.proto;\n" - + "\n" - + "import com.squareup.wire.FieldEncoding;\n" - + "import com.squareup.wire.ProtoAdapter;\n" - + "import com.squareup.wire.ProtoReader;\n" - + "import com.squareup.wire.ProtoWriter;\n" - + "import com.squareup.wire.ReverseProtoWriter;\n" - + "import java.io.IOException;\n" - + "import java.lang.Override;\n" - + "import java.net.ProtocolException;\n" - + "import target.java.JavaCoinFlip;\n" - + "\n" - + "public class CoinFlipAdapter extends ProtoAdapter {\n" - + " /**\n" - + " * In Canada this is the Queen!\n" - + " */\n" - + " protected final JavaCoinFlip HEADS;\n" - + "\n" - + " protected final JavaCoinFlip TAILS;\n" - + "\n" - + " public CoinFlipAdapter(JavaCoinFlip HEADS, JavaCoinFlip TAILS) {\n" - + " super(FieldEncoding.VARINT, JavaCoinFlip.class);\n" - + " this.HEADS = HEADS;\n" - + " this.TAILS = TAILS;\n" - + " }\n" - + "\n" - + " protected int toValue(JavaCoinFlip value) {\n" - + " if (value.equals(HEADS)) return 1;\n" - + " if (value.equals(TAILS)) return 2;\n" - + " return -1;\n" - + " }\n" - + "\n" - + " protected JavaCoinFlip fromValue(int value) {\n" - + " switch (value) {\n" - + " case 1: return HEADS;\n" - + " case 2: return TAILS;\n" - + " default: throw new ProtoAdapter.EnumConstantNotFoundException(value, JavaCoinFlip.class);\n" - + " }\n" - + " }\n" - + "\n" - + " @Override\n" - + " public int encodedSize(JavaCoinFlip value) {\n" - + " return ProtoAdapter.UINT32.encodedSize(toValue(value));\n" - + " }\n" - + "\n" - + " @Override\n" - + " public void encode(ProtoWriter writer, JavaCoinFlip value) throws IOException {\n" - + " int i = toValue(value);\n" - + " if (i == -1) throw new ProtocolException(\"Unexpected enum constant: \" + value);\n" - + " writer.writeVarint32(i);\n" - + " }\n" - + "\n" - + " @Override\n" - + " public void encode(ReverseProtoWriter writer, JavaCoinFlip value) throws IOException {\n" - + " int i = toValue(value);\n" - + " if (i == -1) throw new ProtocolException(\"Unexpected enum constant: \" + value);\n" - + " writer.writeVarint32(i);\n" - + " }\n" - + "\n" - + " @Override\n" - + " public JavaCoinFlip decode(ProtoReader reader) throws IOException {\n" - + " int value = reader.readVarint32();\n" - + " return fromValue(value);\n" - + " }\n" - + "\n" - + " @Override\n" - + " public JavaCoinFlip redact(JavaCoinFlip value) {\n" - + " return value;\n" - + " }\n" - + "}\n"); + @Test + public void generateAbstractAdapterForEnum() throws Exception { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "package original.proto;\n" + + "message ProtoMessage {\n" + + " optional CoinFlip coin_flip = 1;\n" + + "}\n" + + "enum CoinFlip {\n" + + " // In Canada this is the Queen!\n" + + " HEADS = 1;\n" + + " TAILS = 2;\n" + + "}\n") + .build(); + assertThat( + new JavaWithProfilesGenerator(schema) + .withProfile( + "android.wire", + "" + + "syntax = \"wire2\";\n" + + "import \"message.proto\";\n" + + "package original.proto;\n" + + "type original.proto.CoinFlip {\n" + + " target target.java.JavaCoinFlip using target.java.JavaCoinFlip#ADAPTER;\n" + + "}\n") + .generateJava("original.proto.CoinFlip", "android")) + .isEqualTo( + "" + + "package original.proto;\n" + + "\n" + + "import com.squareup.wire.FieldEncoding;\n" + + "import com.squareup.wire.ProtoAdapter;\n" + + "import com.squareup.wire.ProtoReader;\n" + + "import com.squareup.wire.ProtoWriter;\n" + + "import com.squareup.wire.ReverseProtoWriter;\n" + + "import java.io.IOException;\n" + + "import java.lang.Override;\n" + + "import java.net.ProtocolException;\n" + + "import target.java.JavaCoinFlip;\n" + + "\n" + + "public class CoinFlipAdapter extends ProtoAdapter {\n" + + " /**\n" + + " * In Canada this is the Queen!\n" + + " */\n" + + " protected final JavaCoinFlip HEADS;\n" + + "\n" + + " protected final JavaCoinFlip TAILS;\n" + + "\n" + + " public CoinFlipAdapter(JavaCoinFlip HEADS, JavaCoinFlip TAILS) {\n" + + " super(FieldEncoding.VARINT, JavaCoinFlip.class);\n" + + " this.HEADS = HEADS;\n" + + " this.TAILS = TAILS;\n" + + " }\n" + + "\n" + + " protected int toValue(JavaCoinFlip value) {\n" + + " if (value.equals(HEADS)) return 1;\n" + + " if (value.equals(TAILS)) return 2;\n" + + " return -1;\n" + + " }\n" + + "\n" + + " protected JavaCoinFlip fromValue(int value) {\n" + + " switch (value) {\n" + + " case 1: return HEADS;\n" + + " case 2: return TAILS;\n" + + " default: throw new ProtoAdapter.EnumConstantNotFoundException(value, JavaCoinFlip.class);\n" + + " }\n" + + " }\n" + + "\n" + + " @Override\n" + + " public int encodedSize(JavaCoinFlip value) {\n" + + " return ProtoAdapter.UINT32.encodedSize(toValue(value));\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void encode(ProtoWriter writer, JavaCoinFlip value) throws IOException {\n" + + " int i = toValue(value);\n" + + " if (i == -1) throw new ProtocolException(\"Unexpected enum constant: \" + value);\n" + + " writer.writeVarint32(i);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void encode(ReverseProtoWriter writer, JavaCoinFlip value) throws IOException {\n" + + " int i = toValue(value);\n" + + " if (i == -1) throw new ProtocolException(\"Unexpected enum constant: \" + value);\n" + + " writer.writeVarint32(i);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public JavaCoinFlip decode(ProtoReader reader) throws IOException {\n" + + " int value = reader.readVarint32();\n" + + " return fromValue(value);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public JavaCoinFlip redact(JavaCoinFlip value) {\n" + + " return value;\n" + + " }\n" + + "}\n"); } - @Test public void generateAbstractAdapterWithRedactedField() throws IOException { - SchemaBuilder builder = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "import \"option_redacted.proto\";\n" - + "message ProtoMessage {\n" - + " optional string secret = 1 [(squareup.protos.redacted_option.redacted) = true];\n" - + "}\n"); + @Test + public void generateAbstractAdapterWithRedactedField() throws IOException { + SchemaBuilder builder = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "import \"option_redacted.proto\";\n" + + "message ProtoMessage {\n" + + " optional string secret = 1 [(squareup.protos.redacted_option.redacted) = true];\n" + + "}\n"); addFromTest(builder, Path.get("option_redacted.proto")); Schema schema = builder.build(); - assertThat(new JavaWithProfilesGenerator(schema) - .withProfile("android.wire", "" - + "syntax = \"wire2\";\n" - + "import \"message.proto\";\n" - + "type ProtoMessage {\n" - + " target JavaMessage using JavaMessage#ADAPTER;\n" - + "}\n") - .generateJava("ProtoMessage", "android")).contains("" - + " @Override\n" - + " public JavaMessage redact(JavaMessage value) {\n" - + " return null;\n" - + " }\n"); + assertThat( + new JavaWithProfilesGenerator(schema) + .withProfile( + "android.wire", + "" + + "syntax = \"wire2\";\n" + + "import \"message.proto\";\n" + + "type ProtoMessage {\n" + + " target JavaMessage using JavaMessage#ADAPTER;\n" + + "}\n") + .generateJava("ProtoMessage", "android")) + .contains( + "" + + " @Override\n" + + " public JavaMessage redact(JavaMessage value) {\n" + + " return null;\n" + + " }\n"); } - @Test public void nestedAbstractAdapterIsStatic() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message A {\n" - + " message B {\n" - + " optional string c = 1;\n" - + " }\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .withProfile("android.wire", "" - + "syntax = \"wire2\";\n" - + "import \"message.proto\";\n" - + "type A.B {\n" - + " target java.lang.String using AbAdapter#INSTANCE;\n" - + "}\n") - .generateJava("A", "android")).contains("" - + " public abstract static class AbstractBAdapter extends ProtoAdapter {\n"); + @Test + public void nestedAbstractAdapterIsStatic() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message A {\n" + + " message B {\n" + + " optional string c = 1;\n" + + " }\n" + + "}\n") + .build(); + assertThat( + new JavaWithProfilesGenerator(schema) + .withProfile( + "android.wire", + "" + + "syntax = \"wire2\";\n" + + "import \"message.proto\";\n" + + "type A.B {\n" + + " target java.lang.String using AbAdapter#INSTANCE;\n" + + "}\n") + .generateJava("A", "android")) + .contains( + "" + + " public abstract static class AbstractBAdapter extends ProtoAdapter {\n"); } + /** https://github.com/square/wire/issues/655 */ - @Test public void defaultValues() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message Message {\n" - + " optional int32 a = 1 [default = 10 ];\n" - + " optional int32 b = 2 [default = 0x20 ];\n" - + " optional int64 c = 3 [default = 11 ];\n" - + " optional int64 d = 4 [default = 0x21 ];\n" - + " optional float e = 5 [default = inf ];\n" - + " optional double f = 6 [default = -inf ];\n" - + " optional double g = 7 [default = nan ];\n" - + " optional double h = 8 [default = -nan ];\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("Message"); + @Test + public void defaultValues() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message Message {\n" + + " optional int32 a = 1 [default = 10 ];\n" + + " optional int32 b = 2 [default = 0x20 ];\n" + + " optional int64 c = 3 [default = 11 ];\n" + + " optional int64 d = 4 [default = 0x21 ];\n" + + " optional float e = 5 [default = inf ];\n" + + " optional double f = 6 [default = -inf ];\n" + + " optional double g = 7 [default = nan ];\n" + + " optional double h = 8 [default = -nan ];\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("Message"); assertThat(code).contains(" public static final Integer DEFAULT_A = 10;"); assertThat(code).contains(" public static final Integer DEFAULT_B = 32;"); assertThat(code).contains(" public static final Long DEFAULT_C = 11L;"); @@ -411,158 +467,190 @@ public final class JavaGeneratorTest { assertThat(code).contains(" public static final Double DEFAULT_H = Double.NaN;"); } - @Test public void defaultValuesMustNotBeOctal() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message Message {\n" - + " optional int32 a = 1 [default = 020 ];\n" - + " optional int64 b = 2 [default = 021 ];\n" - + "}\n") - .build(); + @Test + public void defaultValuesMustNotBeOctal() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message Message {\n" + + " optional int32 a = 1 [default = 020 ];\n" + + " optional int64 b = 2 [default = 021 ];\n" + + "}\n") + .build(); try { - new JavaWithProfilesGenerator(schema) - .generateJava("Message"); + new JavaWithProfilesGenerator(schema).generateJava("Message"); fail(); } catch (IllegalStateException expected) { assertThat(expected).hasMessageThat().contains("Octal literal unsupported: 020"); } } - @Test public void nullableFieldsWithoutParcelable() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message A {\n" - + " message B {\n" - + " optional string c = 1;\n" - + " }\n" - + "}\n") - .build(); + @Test + public void nullableFieldsWithoutParcelable() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message A {\n" + + " message B {\n" + + " optional string c = 1;\n" + + " }\n" + + "}\n") + .build(); MessageType message = (MessageType) schema.getType("A"); JavaGenerator javaGenerator = JavaGenerator.get(schema).withAndroidAnnotations(true); TypeSpec typeSpec = javaGenerator.generateType(message); - assertThat(JavaFile.builder("", typeSpec).build().toString()).contains("" - + " @WireField(\n" - + " tag = 1,\n" - + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" - + " )\n" - + " @Nullable\n" - + " public final String c;"); + assertThat(JavaFile.builder("", typeSpec).build().toString()) + .contains( + "" + + " @WireField(\n" + + " tag = 1,\n" + + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" + + " )\n" + + " @Nullable\n" + + " public final String c;"); } - @Test public void unsortedTagsPrintSchemaIndex() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message A {\n" - + " optional string two = 2;\n" - + " optional string one = 1;\n" - + "}\n") - .build(); + @Test + public void unsortedTagsPrintSchemaIndex() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message A {\n" + + " optional string two = 2;\n" + + " optional string one = 1;\n" + + "}\n") + .build(); MessageType message = (MessageType) schema.getType("A"); JavaGenerator javaGenerator = JavaGenerator.get(schema).withAndroidAnnotations(true); TypeSpec typeSpec = javaGenerator.generateType(message); String javaOutput = JavaFile.builder("", typeSpec).build().toString(); System.out.println(javaOutput); - assertThat(javaOutput).contains("" - + " @WireField(\n" - + " tag = 2,\n" - + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" - + " )\n" - + " @Nullable\n" - + " public final String two;"); - assertThat(javaOutput).contains("" - + " @WireField(\n" - + " tag = 1,\n" - + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" - + " )\n" - + " @Nullable\n" - + " public final String one;"); + assertThat(javaOutput) + .contains( + "" + + " @WireField(\n" + + " tag = 2,\n" + + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" + + " )\n" + + " @Nullable\n" + + " public final String two;"); + assertThat(javaOutput) + .contains( + "" + + " @WireField(\n" + + " tag = 1,\n" + + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" + + " )\n" + + " @Nullable\n" + + " public final String one;"); } - @Test public void androidSupport() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message A {\n" - + " message B {\n" - + " optional string c = 1;\n" - + " }\n" - + "}\n") - .build(); + @Test + public void androidSupport() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message A {\n" + + " message B {\n" + + " optional string c = 1;\n" + + " }\n" + + "}\n") + .build(); MessageType message = (MessageType) schema.getType("A"); JavaGenerator javaGenerator = JavaGenerator.get(schema).withAndroid(true); TypeSpec typeSpec = javaGenerator.generateType(message); String javaOutput = JavaFile.builder("", typeSpec).build().toString(); - assertThat(javaOutput).contains("" - + " @WireField(\n" - + " tag = 1,\n" - + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" - + " )\n" - + " public final String c;"); - assertThat(javaOutput).contains("" - + "public static final Parcelable.Creator CREATOR = AndroidMessage.newCreator(ADAPTER)"); + assertThat(javaOutput) + .contains( + "" + + " @WireField(\n" + + " tag = 1,\n" + + " adapter = \"com.squareup.wire.ProtoAdapter#STRING\"\n" + + " )\n" + + " public final String c;"); + assertThat(javaOutput) + .contains( + "" + + "public static final Parcelable.Creator CREATOR = AndroidMessage.newCreator(ADAPTER)"); } @Test public void enclosingTypeIsNotMessage() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "message A {\n" - + " message B {\n" - + " }\n" - + " optional B b = 1;\n" - + "}\n") - .build(); - - Schema pruned = schema.prune(new PruningRules.Builder() - .addRoot("A.B") - .build()); + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "message A {\n" + + " message B {\n" + + " }\n" + + " optional B b = 1;\n" + + "}\n") + .build(); + + Schema pruned = schema.prune(new PruningRules.Builder().addRoot("A.B").build()); JavaGenerator javaGenerator = JavaGenerator.get(schema); TypeSpec typeSpec = javaGenerator.generateType(pruned.getType("A")); String javaOutput = JavaFile.builder("", typeSpec).build().toString(); assertThat(javaOutput) - .contains("" - + "public final class A {\n" - + " private A() {\n" - + " throw new AssertionError();\n" - + " }"); + .contains( + "" + + "public final class A {\n" + + " private A() {\n" + + " throw new AssertionError();\n" + + " }"); assertThat(javaOutput).contains("public static final class B extends Message {"); } @Test public void generateTypeUsesPackageNameOnFieldAndClassNameClash() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("person.proto"), "" - + "package common.proto;\n" - + "enum Gender {\n" - + " Gender_Male = 0;\n" - + " Gender_Female = 1;\n" - + "}\n" - + "message Person {\n" - + " optional Gender Gender = 1;\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .generateJava("common.proto.Person")) + Schema schema = + new SchemaBuilder() + .add( + Path.get("person.proto"), + "" + + "package common.proto;\n" + + "enum Gender {\n" + + " Gender_Male = 0;\n" + + " Gender_Female = 1;\n" + + "}\n" + + "message Person {\n" + + " optional Gender Gender = 1;\n" + + "}\n") + .build(); + assertThat(new JavaWithProfilesGenerator(schema).generateJava("common.proto.Person")) .contains("public final Gender common_proto_Gender;"); } @Test public void buildersOnlyGeneratesNonPublicConstructors() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("message.proto"), "" - + "syntax = \"proto2\";\n" - + "message SomeMessage {\n" - + " optional string a = 1;\n" - + " optional string b = 2;\n" - + " message InnerMessage {\n" - + " optional string c = 3;\n" - + " optional string d = 8;\n" - + " }\n" - + "}\n" - ) - .build(); - String javaOutput = new JavaWithProfilesGenerator(schema) - .generateJava("SomeMessage", null /* profileName */, true /* buildersOnly */); + Schema schema = + new SchemaBuilder() + .add( + Path.get("message.proto"), + "" + + "syntax = \"proto2\";\n" + + "message SomeMessage {\n" + + " optional string a = 1;\n" + + " optional string b = 2;\n" + + " message InnerMessage {\n" + + " optional string c = 3;\n" + + " optional string d = 8;\n" + + " }\n" + + "}\n") + .build(); + String javaOutput = + new JavaWithProfilesGenerator(schema) + .generateJava("SomeMessage", null /* profileName */, true /* buildersOnly */); assertThat(javaOutput).contains(" SomeMessage("); assertThat(javaOutput).contains(" InnerMessage("); assertThat(javaOutput).doesNotContain("public SomeMessage("); @@ -571,232 +659,264 @@ public void buildersOnlyGeneratesNonPublicConstructors() throws Exception { @Test public void generateTypeUsesPackageNameOnFieldAndClassNameClashWithinPackage() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("a.proto"), "" - + "package common.proto;\n" - + "enum Status {\n" - + " Status_Approved = 0;\n" - + " Status_Denied = 1;\n" - + "}\n" - + "enum AnotherStatus {\n" - + " AnotherStatus_Processing = 0;\n" - + " AnotherStatus_Completed = 1;\n" - + "}\n" - + "message A {\n" - + " message B {\n" - + " optional Status Status = 1;\n" - + " }\n" - + " repeated B b = 1;" - + " optional AnotherStatus Status = 2;\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .generateJava("common.proto.A")) + Schema schema = + new SchemaBuilder() + .add( + Path.get("a.proto"), + "" + + "package common.proto;\n" + + "enum Status {\n" + + " Status_Approved = 0;\n" + + " Status_Denied = 1;\n" + + "}\n" + + "enum AnotherStatus {\n" + + " AnotherStatus_Processing = 0;\n" + + " AnotherStatus_Completed = 1;\n" + + "}\n" + + "message A {\n" + + " message B {\n" + + " optional Status Status = 1;\n" + + " }\n" + + " repeated B b = 1;" + + " optional AnotherStatus Status = 2;\n" + + "}\n") + .build(); + assertThat(new JavaWithProfilesGenerator(schema).generateJava("common.proto.A")) .contains("public final AnotherStatus common_proto_Status;"); } - @Test public void fieldHasScalarName() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("example.proto"), "" - + "package squareup.testing.wire;\n" - + "\n" - + "option java_package = \"com.squareup.testing.wire\";\n" - + "\n" - + "message Data {\n" - + " optional string string = 1;\n" - + " repeated string values = 2;\n" - + "}\n") - .build(); - assertThat(new JavaWithProfilesGenerator(schema) - .generateJava("squareup.testing.wire.Data")).contains("" - + " public Builder string(String string) {\n" - + " this.string = string;\n" - + " return this;\n" - + " }"); + @Test + public void fieldHasScalarName() throws Exception { + Schema schema = + new SchemaBuilder() + .add( + Path.get("example.proto"), + "" + + "package squareup.testing.wire;\n" + + "\n" + + "option java_package = \"com.squareup.testing.wire\";\n" + + "\n" + + "message Data {\n" + + " optional string string = 1;\n" + + " repeated string values = 2;\n" + + "}\n") + .build(); + assertThat(new JavaWithProfilesGenerator(schema).generateJava("squareup.testing.wire.Data")) + .contains( + "" + + " public Builder string(String string) {\n" + + " this.string = string;\n" + + " return this;\n" + + " }"); } - @Test public void sanitizeStringsOnPrinting() throws Exception { - Schema schema = new SchemaBuilder() - .add(Path.get("example.proto"), "" - + "message Person {\n" - + " required string name = 1;\n" - + " required int32 id = 2;\n" - + " repeated PhoneNumber phone = 3;\n" - + " repeated string aliases = 4;\n" - + "\n" - + " message PhoneNumber {\n" - + " required string number = 1;\n" - + " optional PhoneType type = 2 [default = HOME];\n" - + " }\n" - + " enum PhoneType {\n" - + " HOME = 0;\n" - + " WORK = 1;\n" - + " MOBILE = 2;\n" - + " }\n" - + "}\n") - .build(); - String generatedCode = new JavaWithProfilesGenerator(schema) - .generateJava("Person"); - assertThat(generatedCode).contains("" - + " public String toString() {\n" - + " StringBuilder builder = new StringBuilder();\n" - + " builder.append(\", name=\").append(Internal.sanitize(name));\n" - + " builder.append(\", id=\").append(id);\n" - + " if (!phone.isEmpty()) builder.append(\", phone=\").append(phone);\n" - + " if (!aliases.isEmpty()) builder.append(\", aliases=\").append(Internal.sanitize(aliases));\n" - + " return builder.replace(0, 2, \"Person{\").append('}').toString();\n" - + " }"); - assertThat(generatedCode).contains("" - + " public String toString() {\n" - + " StringBuilder builder = new StringBuilder();\n" - + " builder.append(\", number=\").append(Internal.sanitize(number));\n" - + " if (type != null) builder.append(\", type=\").append(type);\n" - + " return builder.replace(0, 2, \"PhoneNumber{\").append('}').toString();\n" - + " }"); + @Test + public void sanitizeStringsOnPrinting() throws Exception { + Schema schema = + new SchemaBuilder() + .add( + Path.get("example.proto"), + "" + + "message Person {\n" + + " required string name = 1;\n" + + " required int32 id = 2;\n" + + " repeated PhoneNumber phone = 3;\n" + + " repeated string aliases = 4;\n" + + "\n" + + " message PhoneNumber {\n" + + " required string number = 1;\n" + + " optional PhoneType type = 2 [default = HOME];\n" + + " }\n" + + " enum PhoneType {\n" + + " HOME = 0;\n" + + " WORK = 1;\n" + + " MOBILE = 2;\n" + + " }\n" + + "}\n") + .build(); + String generatedCode = new JavaWithProfilesGenerator(schema).generateJava("Person"); + assertThat(generatedCode) + .contains( + "" + + " public String toString() {\n" + + " StringBuilder builder = new StringBuilder();\n" + + " builder.append(\", name=\").append(Internal.sanitize(name));\n" + + " builder.append(\", id=\").append(id);\n" + + " if (!phone.isEmpty()) builder.append(\", phone=\").append(phone);\n" + + " if (!aliases.isEmpty()) builder.append(\", aliases=\").append(Internal.sanitize(aliases));\n" + + " return builder.replace(0, 2, \"Person{\").append('}').toString();\n" + + " }"); + assertThat(generatedCode) + .contains( + "" + + " public String toString() {\n" + + " StringBuilder builder = new StringBuilder();\n" + + " builder.append(\", number=\").append(Internal.sanitize(number));\n" + + " if (type != null) builder.append(\", type=\").append(type);\n" + + " return builder.replace(0, 2, \"PhoneNumber{\").append('}').toString();\n" + + " }"); } - @Test public void wirePackageTakesPrecedenceOverJavaPackage() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "import \"wire/extensions.proto\";\n" - + "\n" - + "option java_package = \"java_package\";\n" - + "option (wire.wire_package) = \"wire_package\";\n" - + "\n" - + "message Person {\n" - + " required string name = 1;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("proto_package.Person"); + @Test + public void wirePackageTakesPrecedenceOverJavaPackage() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "import \"wire/extensions.proto\";\n" + + "\n" + + "option java_package = \"java_package\";\n" + + "option (wire.wire_package) = \"wire_package\";\n" + + "\n" + + "message Person {\n" + + " required string name = 1;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("proto_package.Person"); assertThat(code).contains("package wire_package"); assertThat(code).contains("class Person"); } - @Test public void wirePackageTakesPrecedenceOverProtoPackage() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "import \"wire/extensions.proto\";\n" - + "\n" - + "option (wire.wire_package) = \"wire_package\";\n" - + "\n" - + "message Person {\n" - + " required string name = 1;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("proto_package.Person"); + @Test + public void wirePackageTakesPrecedenceOverProtoPackage() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "import \"wire/extensions.proto\";\n" + + "\n" + + "option (wire.wire_package) = \"wire_package\";\n" + + "\n" + + "message Person {\n" + + " required string name = 1;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("proto_package.Person"); assertThat(code).contains("package wire_package"); assertThat(code).contains("class Person"); } - @Test public void packageNameUsedIfFieldNameIsSameAsNonScalarTypeName() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("common/common_message.proto"), - "package a.Common;\n" - + "option java_package = \"a.common\";" - + "message CommonMessage {\n" - + " required string First = 1;\n" - + "}\n") - .add(Path.get("example.proto"), - "package a;\n" - + "import \"common/common_message.proto\";\n" - + "\n" - + "message Example {\n" - + " required Common.CommonMessage CommonMessage = 1;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("a.Example"); + @Test + public void packageNameUsedIfFieldNameIsSameAsNonScalarTypeName() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("common/common_message.proto"), + "package a.Common;\n" + + "option java_package = \"a.common\";" + + "message CommonMessage {\n" + + " required string First = 1;\n" + + "}\n") + .add( + Path.get("example.proto"), + "package a;\n" + + "import \"common/common_message.proto\";\n" + + "\n" + + "message Example {\n" + + " required Common.CommonMessage CommonMessage = 1;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("a.Example"); assertThat(code).contains("package a"); assertThat(code).contains("import a.common.CommonMessage"); assertThat(code).contains("public CommonMessage a_CommonMessage"); } - @Test public void wirePackageUsedInImport() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "import \"wire/extensions.proto\";\n" - + "\n" - + "option (wire.wire_package) = \"wire_package\";\n" - + "\n" - + "message Person {\n" - + " required string name = 1;\n" - + "}\n") - .add(Path.get("city_package/home.proto"), - "package city_package;\n" - + "import \"proto_package/person.proto\";\n" - + "\n" - + "message Home {\n" - + " repeated proto_package.Person person = 1;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("city_package.Home"); + @Test + public void wirePackageUsedInImport() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "import \"wire/extensions.proto\";\n" + + "\n" + + "option (wire.wire_package) = \"wire_package\";\n" + + "\n" + + "message Person {\n" + + " required string name = 1;\n" + + "}\n") + .add( + Path.get("city_package/home.proto"), + "package city_package;\n" + + "import \"proto_package/person.proto\";\n" + + "\n" + + "message Home {\n" + + " repeated proto_package.Person person = 1;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("city_package.Home"); assertThat(code).contains("package city_package"); assertThat(code).contains("import wire_package.Person"); } - @Test public void deprecatedEnum() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "enum Direction {\n" - + " option deprecated = true;\n" - + " NORTH = 1;\n" - + " EAST = 2;\n" - + " SOUTH = 3;\n" - + " WEST = 4;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("proto_package.Direction"); + @Test + public void deprecatedEnum() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "enum Direction {\n" + + " option deprecated = true;\n" + + " NORTH = 1;\n" + + " EAST = 2;\n" + + " SOUTH = 3;\n" + + " WEST = 4;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("proto_package.Direction"); assertThat(code).contains("@Deprecated\npublic enum Direction"); } - @Test public void deprecatedEnumConstant() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "enum Direction {\n" - + " NORTH = 1;\n" - + " EAST = 2 [deprecated = true];\n" - + " SOUTH = 3;\n" - + " WEST = 4;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("proto_package.Direction"); + @Test + public void deprecatedEnumConstant() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "enum Direction {\n" + + " NORTH = 1;\n" + + " EAST = 2 [deprecated = true];\n" + + " SOUTH = 3;\n" + + " WEST = 4;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("proto_package.Direction"); assertThat(code).contains(" @Deprecated\n EAST(2)"); } - @Test public void deprecatedField() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "message Person {\n" - + " optional string name = 1 [deprecated = true];\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("proto_package.Person"); + @Test + public void deprecatedField() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "message Person {\n" + + " optional string name = 1 [deprecated = true];\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("proto_package.Person"); assertThat(code).contains(" @Deprecated\n public final String name;"); } - @Test public void deprecatedMessage() throws IOException { - Schema schema = new SchemaBuilder() - .add(Path.get("proto_package/person.proto"), - "package proto_package;\n" - + "message Person {\n" - + " option deprecated = true;\n" - + " optional string name = 1;\n" - + "}\n") - .build(); - String code = new JavaWithProfilesGenerator(schema) - .generateJava("proto_package.Person"); + @Test + public void deprecatedMessage() throws IOException { + Schema schema = + new SchemaBuilder() + .add( + Path.get("proto_package/person.proto"), + "package proto_package;\n" + + "message Person {\n" + + " option deprecated = true;\n" + + " optional string name = 1;\n" + + "}\n") + .build(); + String code = new JavaWithProfilesGenerator(schema).generateJava("proto_package.Person"); assertThat(code).contains("@Deprecated\npublic final class Person"); } } diff --git a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt index 49c07b7490..3bfd85053b 100644 --- a/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt +++ b/wire-java-generator/src/test/java/com/squareup/wire/java/JavaWithProfilesGenerator.kt @@ -1,11 +1,11 @@ /* - * Copyright (C) 2022 Block, Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -47,7 +47,9 @@ internal class JavaWithProfilesGenerator(private val schema: Schema) { return if (profileName == null) Profile() else profiles["$profileName.wire"]!! } - @Throws(IOException::class) @JvmOverloads fun generateJava( + @Throws(IOException::class) + @JvmOverloads + fun generateJava( typeName: String, profileName: String? = null, buildersOnly: Boolean = false, diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/FieldExtensions.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/FieldExtensions.kt index c8569ad0db..ec1ca38bb7 100644 --- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/FieldExtensions.kt +++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/FieldExtensions.kt @@ -1,11 +1,11 @@ /* - * Copyright 2019 Square Inc. + * Copyright (C) 2019 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/** - * Extension functions/properties for the Field class - */ package com.squareup.wire.kotlin import com.squareup.wire.schema.Field diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt index bba8787b51..5a523cd290 100644 --- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt +++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -108,11 +108,11 @@ import com.squareup.wire.schema.internal.javaPackage import com.squareup.wire.schema.internal.legacyQualifiedFieldName import com.squareup.wire.schema.internal.optionValueToInt import com.squareup.wire.schema.internal.optionValueToLong +import java.util.Locale import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.channels.SendChannel import okio.ByteString import okio.ByteString.Companion.encode -import java.util.Locale class KotlinGenerator private constructor( val schema: Schema, @@ -212,7 +212,7 @@ class KotlinGenerator private constructor( fun generatedServiceName( service: Service, rpc: Rpc? = null, - isImplementation: Boolean = false + isImplementation: Boolean = false, ): ClassName { val typeName = service.serviceName as ClassName val simpleName = buildString { @@ -275,8 +275,9 @@ class KotlinGenerator private constructor( if (rpcRole == RpcRole.CLIENT) { val (implementationName, implementationSpec) = generateService( - service, onlyRpc, - isImplementation = true + service, + onlyRpc, + isImplementation = true, ) result[implementationName] = implementationSpec } @@ -303,7 +304,7 @@ class KotlinGenerator private constructor( private fun generateService( service: Service, onlyRpc: Rpc?, - isImplementation: Boolean + isImplementation: Boolean, ): Pair { check(rpcRole == RpcRole.CLIENT || !isImplementation) { "only clients may generate implementations" @@ -318,12 +319,12 @@ class KotlinGenerator private constructor( .primaryConstructor( FunSpec.constructorBuilder() .addParameter("client", GrpcClient::class) - .build() + .build(), ) .addProperty( PropertySpec.builder("client", GrpcClient::class, PRIVATE) .initializer("client") - .build() + .build(), ) .addSuperinterface(interfaceName) } @@ -343,8 +344,11 @@ class KotlinGenerator private constructor( for (rpc in rpcs) { builder.addFunction( generateRpcFunction( - rpc, service.name, service.type.enclosingTypeOrPackage, isImplementation - ) + rpc, + service.name, + service.type.enclosingTypeOrPackage, + isImplementation, + ), ) } @@ -356,7 +360,7 @@ class KotlinGenerator private constructor( rpc: Rpc, serviceName: String, servicePackageName: String?, - isImplementation: Boolean + isImplementation: Boolean, ): FunSpec { val packageName = if (servicePackageName.isNullOrBlank()) "" else "$servicePackageName." val funSpecBuilder = FunSpec.builder(rpc.name) @@ -421,7 +425,7 @@ class KotlinGenerator private constructor( rpc.requestStreaming || rpc.responseStreaming -> { funSpecBuilder .returns( - GrpcStreamingCall::class.asClassName().parameterizedBy(requestType, responseType) + GrpcStreamingCall::class.asClassName().parameterizedBy(requestType, responseType), ) if (isImplementation) { funSpecBuilder @@ -434,7 +438,7 @@ class KotlinGenerator private constructor( else -> { funSpecBuilder .returns( - GrpcCall::class.asClassName().parameterizedBy(requestType, responseType) + GrpcCall::class.asClassName().parameterizedBy(requestType, responseType), ) if (isImplementation) { funSpecBuilder @@ -558,7 +562,7 @@ class KotlinGenerator private constructor( addAnnotation( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "${className.simpleName} is deprecated") - .build() + .build(), ) } } @@ -595,7 +599,7 @@ class KotlinGenerator private constructor( companionBuilder.addProperty( PropertySpec.builder("serialVersionUID", LONG, PRIVATE, CONST) .initializer("0L") - .build() + .build(), ) classBuilder.addType(companionBuilder.build()) @@ -641,7 +645,7 @@ class KotlinGenerator private constructor( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "Shouldn't be used in Kotlin") .addMember("level = %T.%L", DeprecationLevel::class, DeprecationLevel.HIDDEN) - .build() + .build(), ) .returns(NOTHING) .addStatement("throw %T(%S)", ClassName("kotlin", "AssertionError"), "Builders are deprecated and only available in a javaInterop build; see https://square.github.io/wire/wire_compiler/#kotlin") @@ -808,7 +812,7 @@ class KotlinGenerator private constructor( result.addParameter( ParameterSpec.builder(fieldName, fieldOrOneOf.typeNameForMessageField) .defaultValue("this.%N", fieldName) - .build() + .build(), ) fieldNames += fieldName } @@ -818,7 +822,7 @@ class KotlinGenerator private constructor( result.addParameter( ParameterSpec.builder(fieldName, fieldClass) .defaultValue("this.%N", fieldName) - .build() + .build(), ) fieldNames += fieldName } @@ -828,13 +832,13 @@ class KotlinGenerator private constructor( result.addParameter( ParameterSpec.builder("unknownFields", ByteString::class) .defaultValue("this.unknownFields") - .build() + .build(), ) fieldNames += "unknownFields" result.addStatement( "return %L", fieldNames - .joinToString(prefix = className.simpleName + "(", postfix = ")") + .joinToString(prefix = className.simpleName + "(", postfix = ")"), ) return result.build() } @@ -842,12 +846,12 @@ class KotlinGenerator private constructor( private fun generateBuilderClass( type: MessageType, className: ClassName, - builderClassName: ClassName + builderClassName: ClassName, ): TypeSpec { val builder = TypeSpec.classBuilder("Builder") .superclass( Message.Builder::class.asTypeName() - .parameterizedBy(className, builderClassName) + .parameterizedBy(className, builderClassName), ) if (!javaInterOp) { @@ -855,20 +859,20 @@ class KotlinGenerator private constructor( .primaryConstructor( FunSpec.constructorBuilder() .addParameter("message", className) - .build() + .build(), ) .addProperty( PropertySpec.builder("message", className) .addModifiers(PRIVATE) .initializer("message") - .build() + .build(), ) .addFunction( FunSpec.builder("build") .addModifiers(OVERRIDE) .returns(className) .addStatement("return message") - .build() + .build(), ) .build() } @@ -953,8 +957,8 @@ class KotlinGenerator private constructor( type, boxOneOf, nameAllocator, - builderClass - ) + builderClass, + ), ) } @@ -972,7 +976,7 @@ class KotlinGenerator private constructor( field: Field, nameAllocator: NameAllocator, builderType: TypeName, - oneOf: OneOf? + oneOf: OneOf?, ): FunSpec { val fieldName = nameAllocator[field] val funBuilder = FunSpec.builder(fieldName) @@ -985,7 +989,7 @@ class KotlinGenerator private constructor( funBuilder.addAnnotation( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "$fieldName is deprecated") - .build() + .build(), ) } if (field.isRepeated && !field.useArray) { @@ -1058,7 +1062,7 @@ class KotlinGenerator private constructor( constructorBuilder.addParameter( ParameterSpec.builder(unknownFields, byteClass) .defaultValue("%T.EMPTY", byteClass) - .build() + .build(), ) classBuilder.primaryConstructor(constructorBuilder.build()) @@ -1066,7 +1070,7 @@ class KotlinGenerator private constructor( private fun parametersAndProperties( message: MessageType, - nameAllocator: NameAllocator + nameAllocator: NameAllocator, ): List> { val result = mutableListOf>() @@ -1079,14 +1083,14 @@ class KotlinGenerator private constructor( field = fieldOrOneOf, nameAllocator = nameAllocator, schemaIndex = schemaIndex++, - ) + ), ) is OneOf -> result.add( constructorParameterAndProperty( message = message, oneOf = fieldOrOneOf, nameAllocator = nameAllocator, - ) + ), ) else -> throw IllegalArgumentException("Unexpected element: $fieldOrOneOf") } @@ -1115,7 +1119,7 @@ class KotlinGenerator private constructor( "%M(%S, %N)", MemberName("com.squareup.wire.internal", "immutableCopyOfMapWithStructValues"), fieldName, - fieldName + fieldName, ) } field.type!!.isStruct -> { @@ -1123,7 +1127,7 @@ class KotlinGenerator private constructor( "%M(%S, %N)", MemberName("com.squareup.wire.internal", "immutableCopyOfStruct"), fieldName, - fieldName + fieldName, ) } field.isPacked && field.isScalar && field.useArray -> { @@ -1134,7 +1138,7 @@ class KotlinGenerator private constructor( "%M(%S, %N)", MemberName("com.squareup.wire.internal", "immutableCopyOf"), fieldName, - fieldName + fieldName, ) } else -> CodeBlock.of("%N", fieldName) @@ -1147,7 +1151,7 @@ class KotlinGenerator private constructor( addAnnotation( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "$fieldName is deprecated") - .build() + .build(), ) } for (annotation in optionAnnotations(field.options)) { @@ -1170,7 +1174,7 @@ class KotlinGenerator private constructor( private fun constructorParameterAndProperty( message: MessageType, oneOf: OneOf, - nameAllocator: NameAllocator + nameAllocator: NameAllocator, ): Pair { val fieldClass = message.oneOfClassFor(oneOf, nameAllocator) val fieldName = nameAllocator[oneOf] @@ -1214,13 +1218,17 @@ class KotlinGenerator private constructor( EncodeMode.REQUIRED -> WireField.Label.REQUIRED EncodeMode.OMIT_IDENTITY -> { // Wrapper types don't omit identity values on JSON as other proto3 messages would. - if (field.type!!.isWrapper) null - else WireField.Label.OMIT_IDENTITY + if (field.type!!.isWrapper) { + null + } else { + WireField.Label.OMIT_IDENTITY + } } EncodeMode.REPEATED -> WireField.Label.REPEATED EncodeMode.PACKED -> WireField.Label.PACKED EncodeMode.MAP, - EncodeMode.NULL_IF_ABSENT -> null + EncodeMode.NULL_IF_ABSENT, + -> null } if (wireFieldLabel != null) { addMember("label = %T.%L", WireField.Label::class, wireFieldLabel) @@ -1288,7 +1296,8 @@ class KotlinGenerator private constructor( } } addStatement( - "%N += %P", resultName, + "%N += %P", + resultName, buildCodeBlock { add(fieldName) if (fieldOrOneOf.isRedacted) { @@ -1306,14 +1315,15 @@ class KotlinGenerator private constructor( add(fieldName) } } - } + }, ) } is OneOf -> { val fieldName = localNameAllocator[fieldOrOneOf] add("if (%N != null) ", fieldName) addStatement( - "%N += %P", resultName, + "%N += %P", + resultName, buildCodeBlock { add(fieldName) if (fieldOrOneOf.fields.any { it.isRedacted }) { @@ -1322,7 +1332,7 @@ class KotlinGenerator private constructor( add("=\$") add(fieldName) } - } + }, ) } else -> throw IllegalArgumentException("Unexpected element: $fieldOrOneOf") @@ -1334,7 +1344,7 @@ class KotlinGenerator private constructor( resultName, className.simpleName + "{", ", ", - "}" + "}", ) } } @@ -1348,7 +1358,7 @@ class KotlinGenerator private constructor( private fun addDefaultFields( type: MessageType, companionBuilder: TypeSpec.Builder, - nameAllocator: NameAllocator + nameAllocator: NameAllocator, ) { for (field in type.fieldsAndFlatOneOfFieldsAndBoxedOneOfs().filterIsInstance()) { val default = field.default ?: continue @@ -1366,7 +1376,7 @@ class KotlinGenerator private constructor( } } .initializer(fieldValue) - .build() + .build(), ) } } @@ -1395,7 +1405,7 @@ class KotlinGenerator private constructor( typeName == ByteString::class.asTypeName() -> CodeBlock.of( "%S.%M()!!", defaultValue.toString().encode(charset = Charsets.ISO_8859_1).base64(), - ByteString.Companion::class.asClassName().member("decodeBase64") + ByteString.Companion::class.asClassName().member("decodeBase64"), ) protoType.isEnum -> CodeBlock.of("%T.%L", typeName, defaultValue) else -> throw IllegalStateException("$protoType is not an allowed scalar type") @@ -1496,13 +1506,13 @@ class KotlinGenerator private constructor( .superclass(ProtoAdapter::class.asClassName().parameterizedBy(parentClassName)) .addSuperclassConstructorParameter( "\n⇥%T.LENGTH_DELIMITED", - FieldEncoding::class.asClassName() + FieldEncoding::class.asClassName(), ) .addSuperclassConstructorParameter("\n%T::class", parentClassName) .addSuperclassConstructorParameter("\n%S", type.type.typeUrl!!) .addSuperclassConstructorParameter( "\n%M", - MemberName(Syntax::class.asClassName(), type.syntax.name) + MemberName(Syntax::class.asClassName(), type.syntax.name), ) .addSuperclassConstructorParameter("\nnull") .addSuperclassConstructorParameter("\n%S\n⇤", type.location.path) @@ -1524,7 +1534,7 @@ class KotlinGenerator private constructor( PropertySpec.builder(adapterName, adapterType) .jvmField() .initializer("%L", adapterObject.build()) - .build() + .build(), ) } @@ -1532,7 +1542,7 @@ class KotlinGenerator private constructor( val adapterType = ProtoAdapter::class.asTypeName() .parameterizedBy( Map::class.asTypeName() - .parameterizedBy(keyType.typeName, valueType.typeName) + .parameterizedBy(keyType.typeName, valueType.typeName), ) // Map adapters have to be lazy in order to avoid a circular reference when its value type @@ -1543,7 +1553,7 @@ class KotlinGenerator private constructor( MemberName("kotlin", "lazy"), ProtoAdapter::class, keyType.getAdapterName(), - valueType.getAdapterName() + valueType.getAdapterName(), ) .build() } @@ -1563,8 +1573,11 @@ class KotlinGenerator private constructor( add(fieldEqualsIdentityBlock(fieldOrOneOf, fieldName)) } addStatement( - "%N += %L.encodedSizeWithTag(%L, value.%L)", sizeName, adapterFor(fieldOrOneOf), - fieldOrOneOf.tag, fieldName + "%N += %L.encodedSizeWithTag(%L, value.%L)", + sizeName, + adapterFor(fieldOrOneOf), + fieldOrOneOf.tag, + fieldName, ) } is OneOf -> { @@ -1625,7 +1638,7 @@ class KotlinGenerator private constructor( "%L.encodeWithTag(writer, %L, value.%L)", adapterFor(field), field.tag, - fieldName + fieldName, ) } } @@ -1699,7 +1712,7 @@ class KotlinGenerator private constructor( " ?: throw %1M(%2L, %3S)", missingRequiredFields, fieldName, - fieldOrOneOf.name + fieldOrOneOf.name, ) } else { CodeBlock.of("") @@ -1747,8 +1760,9 @@ class KotlinGenerator private constructor( addStatement("%L", decodeAndAssign(field, fieldName, adapterName)) nextControlFlow("catch (e: %T)", ProtoAdapter.EnumConstantNotFoundException::class) addStatement( - "reader.addUnknownField(%L, %T.VARINT, e.value.toLong())", tag, - FieldEncoding::class + "reader.addUnknownField(%L, %T.VARINT, e.value.toLong())", + tag, + FieldEncoding::class, ) endControlFlow() } @@ -1798,7 +1812,7 @@ class KotlinGenerator private constructor( val decode = if (field.useArray) { CodeBlock.of( "%M(reader)", - MemberName("com.squareup.wire.internal", "decodePrimitive_${field.type!!.simpleName}") + MemberName("com.squareup.wire.internal", "decodePrimitive_${field.type!!.simpleName}"), ) } else { CodeBlock.of( @@ -1851,10 +1865,12 @@ class KotlinGenerator private constructor( return when (type) { ProtoType.FLOAT, ProtoType.FIXED32, - ProtoType.SFIXED32 -> 4 + ProtoType.SFIXED32, + -> 4 ProtoType.DOUBLE, ProtoType.FIXED64, - ProtoType.SFIXED64 -> 8 + ProtoType.SFIXED64, + -> 8 // If we aren't 100% confident in the size of the field, we assume the worst case scenario of 1 byte which gives // us the maximum possible number of elements in the list. else -> 1 @@ -1877,10 +1893,14 @@ class KotlinGenerator private constructor( ClassName("kotlin", "UnsupportedOperationException"), requiredRedactedMessageFields.joinToString( prefix = if (requiredRedactedMessageFields.size > 1) "Fields [" else "Field '", - postfix = if (requiredRedactedMessageFields.size > 1) "] are " else "' is " + - "required and cannot be redacted.", - transform = nameAllocator::get - ) + postfix = if (requiredRedactedMessageFields.size > 1) { + "] are " + } else { + "' is " + + "required and cannot be redacted." + }, + transform = nameAllocator::get, + ), ) return result.build() } @@ -1907,7 +1927,7 @@ class KotlinGenerator private constructor( return result .addStatement( "return %L", - redactedFields.joinToCode(separator = ",\n", prefix = "value.copy(\n⇥", suffix = "\n⇤)") + redactedFields.joinToCode(separator = ",\n", prefix = "value.copy(\n⇥", suffix = "\n⇤)"), ) .build() } @@ -1958,13 +1978,16 @@ class KotlinGenerator private constructor( adapterConstant != null -> { CodeBlock.of( "%T%L%L", - adapterConstant.kotlinClassName, adapterFieldDelimiterName, adapterConstant.memberName + adapterConstant.kotlinClassName, + adapterFieldDelimiterName, + adapterConstant.memberName, ) } isScalar -> { CodeBlock.of( "%T$adapterFieldDelimiterName%L", - ProtoAdapter::class, simpleName.uppercase(Locale.US) + ProtoAdapter::class, + simpleName.uppercase(Locale.US), ) } this == ProtoType.DURATION -> { @@ -2075,7 +2098,7 @@ class KotlinGenerator private constructor( addAnnotation( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "${type.simpleName} is deprecated") - .build() + .build(), ) } } @@ -2083,7 +2106,7 @@ class KotlinGenerator private constructor( .addProperty( PropertySpec.builder(valueName, Int::class, OVERRIDE) .initializer(valueName) - .build() + .build(), ) .addType(generateEnumCompanion(enum)) @@ -2109,11 +2132,11 @@ class KotlinGenerator private constructor( addAnnotation( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "${constant.name} is deprecated") - .build() + .build(), ) } } - .build() + .build(), ) } @@ -2125,7 +2148,8 @@ class KotlinGenerator private constructor( val format = when (field.type) { // Special case for doubles and floats because of negative zeros. ProtoType.DOUBLE, - ProtoType.FLOAT -> "if (!value.%1L.equals(%2L)) " + ProtoType.FLOAT, + -> "if (!value.%1L.equals(%2L)) " else -> "if (value.%1L != %2L) " } return CodeBlock.of(format, fieldName, field.identityValue) @@ -2178,7 +2202,7 @@ class KotlinGenerator private constructor( .addSuperclassConstructorParameter("\n⇥%T::class", parentClassName) .addSuperclassConstructorParameter( "\n%M", - MemberName(Syntax::class.asClassName(), message.syntax.name) + MemberName(Syntax::class.asClassName(), message.syntax.name), ) .addSuperclassConstructorParameter("\n%L\n⇤", message.identity()) .addFunction( @@ -2187,7 +2211,7 @@ class KotlinGenerator private constructor( .addParameter(valueName, Int::class) .returns(parentClassName.copy(nullable = true)) .addStatement("return %T.fromValue(value)", parentClassName) - .build() + .build(), ) .build() @@ -2217,7 +2241,7 @@ class KotlinGenerator private constructor( PropertySpec.builder(creatorName, creatorTypeName) .jvmField() .initializer("%T.newCreator(ADAPTER)", ANDROID_MESSAGE) - .build() + .build(), ) } @@ -2240,7 +2264,7 @@ class KotlinGenerator private constructor( */ fun generateOptionType( extend: Extend, - field: Field + field: Field, ): TypeSpec? { require(field in extend.fields) val annotationTargets = extend.annotationTargets @@ -2273,7 +2297,7 @@ class KotlinGenerator private constructor( .addAnnotation( AnnotationSpec.builder(Retention::class) .addMember("%T.%L", AnnotationRetention::class, AnnotationRetention.RUNTIME) - .build() + .build(), ) .addAnnotation( AnnotationSpec.builder(Target::class) @@ -2283,7 +2307,7 @@ class KotlinGenerator private constructor( } this } - .build() + .build(), ) if (field.documentation.isNotEmpty()) { builder.addKdoc("%L\n", field.documentation) @@ -2291,12 +2315,12 @@ class KotlinGenerator private constructor( builder.primaryConstructor( FunSpec.constructorBuilder() .addParameter("value", returnType) - .build() + .build(), ) builder.addProperty( PropertySpec.builder("value", returnType, PUBLIC) .initializer("value") - .build() + .build(), ) return builder.build() } @@ -2307,7 +2331,8 @@ class KotlinGenerator private constructor( isRepeated -> CodeBlock.of("val $allocatedName = mutableListOf<%T>()", type!!.typeName) isMap -> CodeBlock.of( "val $allocatedName = mutableMapOf<%T, %T>()", - keyType.typeName, valueType.typeName + keyType.typeName, + valueType.typeName, ) else -> CodeBlock.of("var $allocatedName: %T = %L", typeNameForBuilderField, identityValue) } @@ -2402,7 +2427,7 @@ class KotlinGenerator private constructor( type is MessageType -> CodeBlock.of("null") type is EnumType -> type.identity() else -> throw IllegalArgumentException( - "Unexpected type $protoType for IDENTITY_IF_ABSENT" + "Unexpected type $protoType for IDENTITY_IF_ABSENT", ) } } @@ -2418,7 +2443,8 @@ class KotlinGenerator private constructor( EncodeMode.MAP, EncodeMode.REPEATED, EncodeMode.PACKED, - EncodeMode.REQUIRED -> false + EncodeMode.REQUIRED, + -> false EncodeMode.NULL_IF_ABSENT -> true EncodeMode.OMIT_IDENTITY -> { when { @@ -2487,10 +2513,10 @@ class KotlinGenerator private constructor( .addParameter("tag", Int::class) .addParameter("adapter", ProtoAdapter::class.asClassName().parameterizedBy(typeVariable)) .addParameter("declaredName", String::class) - .build() + .build(), ) .superclass( - com.squareup.wire.OneOf.Key::class.asClassName().parameterizedBy(typeVariable) + com.squareup.wire.OneOf.Key::class.asClassName().parameterizedBy(typeVariable), ) .addSuperclassConstructorParameter("%L", "tag") .addSuperclassConstructorParameter("%L", "adapter") @@ -2502,10 +2528,10 @@ class KotlinGenerator private constructor( .returns( com.squareup.wire.OneOf::class.asClassName().parameterizedBy( boxClassName.parameterizedBy(typeVariable), - typeVariable - ) + typeVariable, + ), ) - .build() + .build(), ) .addFunction( FunSpec.builder("decode") @@ -2513,11 +2539,11 @@ class KotlinGenerator private constructor( .returns( com.squareup.wire.OneOf::class.asClassName().parameterizedBy( boxClassName.parameterizedBy(typeVariable), - typeVariable - ) + typeVariable, + ), ) .addStatement("return create(%L.decode(%L))", "adapter", "reader") - .build() + .build(), ) .build() } @@ -2548,14 +2574,14 @@ class KotlinGenerator private constructor( val allKeys = PropertySpec .builder( keysFieldName, - Set::class.asClassName().parameterizedBy(boxClassName.parameterizedBy(STAR)) + Set::class.asClassName().parameterizedBy(boxClassName.parameterizedBy(STAR)), ) .addAnnotation(ClassName("com.squareup.wire.internal", "JvmStatic")) .initializer( CodeBlock.of( """setOf(${keyFieldNames.map { "%L" }.joinToString(", ")})""", - *keyFieldNames.toTypedArray() - ) + *keyFieldNames.toTypedArray(), + ), ) .build() companionBuilder.addProperty(allKeys) @@ -2581,7 +2607,7 @@ class KotlinGenerator private constructor( addAnnotation( AnnotationSpec.builder(Deprecated::class) .addMember("message = %S", "${field.name} is deprecated") - .build() + .build(), ) } for (annotation in optionAnnotations(field.options)) { @@ -2598,8 +2624,8 @@ class KotlinGenerator private constructor( "adapter", field.getAdapterName(), "declaredName", - field.name - ) + field.name, + ), ) .build() } @@ -2696,12 +2722,13 @@ class KotlinGenerator private constructor( ProtoType.INT32 to CodeBlock.of("0"), ProtoType.SFIXED32 to CodeBlock.of("0"), ProtoType.SINT32 to CodeBlock.of("0"), - ProtoType.UINT32 to CodeBlock.of("0") + ProtoType.UINT32 to CodeBlock.of("0"), ) private val MESSAGE = Message::class.asClassName() private val ANDROID_MESSAGE = MESSAGE.peerClass("AndroidMessage") - @JvmStatic @JvmName("get") + @JvmStatic + @JvmName("get") operator fun invoke( schema: Schema, profile: Profile = Profile(), @@ -2739,9 +2766,11 @@ class KotlinGenerator private constructor( } putAllExtensions( - schema, protoFile, - protoFile.types, protoFile.extendList, - memberToKotlinName + schema, + protoFile, + protoFile.types, + protoFile.extendList, + memberToKotlinName, ) } @@ -2771,7 +2800,7 @@ class KotlinGenerator private constructor( protoFile: ProtoFile, types: List, extendList: List, - memberToKotlinName: MutableMap + memberToKotlinName: MutableMap, ) { for (extend in extendList) { if (extend.annotationTargets.isEmpty()) continue @@ -2783,9 +2812,11 @@ class KotlinGenerator private constructor( } for (type in types) { putAllExtensions( - schema, protoFile, - type.nestedTypes, type.nestedExtendList, - memberToKotlinName + schema, + protoFile, + type.nestedTypes, + type.nestedExtendList, + memberToKotlinName, ) } } @@ -2824,4 +2855,5 @@ class KotlinGenerator private constructor( } private fun PropertySpec.Builder.jvmField(): PropertySpec.Builder = addAnnotation( - ClassName("com.squareup.wire.internal", "JvmField")) + ClassName("com.squareup.wire.internal", "JvmField"), +) diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinSchemaHandler.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinSchemaHandler.kt index efb8b2ba42..5abcff21ee 100644 --- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinSchemaHandler.kt +++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinSchemaHandler.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.kotlin import com.squareup.kotlinpoet.ClassName @@ -10,8 +25,8 @@ import com.squareup.wire.schema.Schema import com.squareup.wire.schema.SchemaHandler import com.squareup.wire.schema.Service import com.squareup.wire.schema.Type -import okio.Path import java.io.IOException +import okio.Path class KotlinSchemaHandler( private val outDirectory: String, @@ -100,7 +115,7 @@ class KotlinSchemaHandler( val map = kotlinGenerator.generateServiceTypeSpecs(service, rpc) for ((className, typeSpec) in map) { generatedPaths.add( - write(className, typeSpec, service.type, service.location, context) + write(className, typeSpec, service.type, service.location, context), ) } } diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcCallStyle.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcCallStyle.kt index ea6e4760ee..577613e0b4 100644 --- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcCallStyle.kt +++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcCallStyle.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,5 +20,5 @@ enum class RpcCallStyle { SUSPENDING, /** Generate blocking APIs callable by Java and Kotlin. */ - BLOCKING; + BLOCKING, } diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcRole.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcRole.kt index 0a7275b0fe..8fe01602ed 100644 --- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcRole.kt +++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/RpcRole.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,5 +24,4 @@ enum class RpcRole { /** Doesn't generate any interfaces. */ NONE, - ; } diff --git a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt index a7eaebe9f1..256f232bf5 100644 --- a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt +++ b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,12 +22,12 @@ import com.squareup.wire.buildSchema import com.squareup.wire.kotlin.KotlinGenerator.Companion.sanitizeKdoc import com.squareup.wire.schema.PruningRules import com.squareup.wire.schema.addFromTest -import okio.Path.Companion.toPath import kotlin.test.Test import kotlin.test.assertContains import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.text.RegexOption.DOT_MATCHES_ALL +import okio.Path.Companion.toPath class KotlinGeneratorTest { @Test fun basic() { @@ -49,7 +49,8 @@ class KotlinGeneratorTest { | optional PhoneType type = 2 [default = HOME]; | } | repeated PhoneNumber phone = 4; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Person").replace("\n", "") @@ -59,7 +60,7 @@ class KotlinGeneratorTest { assertThat(code).contains("PhoneNumber::class") assertThat(code).contains("override fun encode(writer: ProtoWriter, `value`: Person)") assertTrue( - code.contains("enum class PhoneType( override val `value`: Int, ) : WireEnum") + code.contains("enum class PhoneType( override val `value`: Int, ) : WireEnum"), ) assertThat(code).contains("fun fromValue(`value`: Int): PhoneType?") assertThat(code).contains("WORK(1),") @@ -87,7 +88,8 @@ class KotlinGeneratorTest { | optional double n = 14 [default = -inf]; | optional double o = 15 [default = nan]; | optional double p = 16 [default = -nan]; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Message") @@ -103,7 +105,7 @@ class KotlinGeneratorTest { assertThat(code).contains("const val DEFAULT_J: Double = -0.01") assertThat(code).contains( "public const val DEFAULT_K: Double\n" + - " = -1_230_000_000_000_000_000_000_000_000_000_000_000_000_000_000.0" + " = -1_230_000_000_000_000_000_000_000_000_000_000_000_000_000_000.0", ) assertThat(code).contains("const val DEFAULT_L: Double = 255.0") assertThat(code).contains("const val DEFAULT_M: Double = Double.POSITIVE_INFINITY") @@ -121,7 +123,8 @@ class KotlinGeneratorTest { | required float when = 1; | required int32 ADAPTER = 2; | optional int64 adapter = 3; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Message") @@ -144,7 +147,8 @@ class KotlinGeneratorTest { | message B { | } | optional B b = 1; - |}""".trimMargin() + |} + """.trimMargin(), ) } @@ -173,7 +177,8 @@ class KotlinGeneratorTest { | */ | public fun GetFeature(): GrpcCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |package routeguide | @@ -196,7 +201,8 @@ class KotlinGeneratorTest { | responseAdapter = Feature.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -211,12 +217,13 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expectedInterface, expectedImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide"), ) } @@ -259,15 +266,17 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expected), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.SERVER, + ), ) } @@ -311,15 +320,17 @@ class KotlinGeneratorTest { |} |$pointMessage |$routeSummaryMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expected), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.SERVER, + ), ) } @@ -364,15 +375,17 @@ class KotlinGeneratorTest { |$pointMessage |$rectangeMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expected), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.SERVER, + ), ) } @@ -420,15 +433,17 @@ class KotlinGeneratorTest { |$pointMessage |$rectangeMessage |$routeNoteMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expected), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.SERVER, + ), ) } @@ -478,15 +493,17 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expected), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.SERVER, + ), ) } @@ -504,7 +521,8 @@ class KotlinGeneratorTest { | */ | public fun GetFeature(): GrpcCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |import com.squareup.wire.GrpcCall |import com.squareup.wire.GrpcClient @@ -525,7 +543,8 @@ class KotlinGeneratorTest { | responseAdapter = Feature.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -540,12 +559,13 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expectedInterface, expectedImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("RouteGuide") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("RouteGuide"), ) } @@ -565,7 +585,8 @@ class KotlinGeneratorTest { | */ | public fun GetFeature(): GrpcCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |package routeguide.grpc | @@ -588,7 +609,8 @@ class KotlinGeneratorTest { | responseAdapter = Feature.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -605,12 +627,13 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expectedInterface, expectedImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.grpc.RouteGuide") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.grpc.RouteGuide"), ) } @@ -630,7 +653,8 @@ class KotlinGeneratorTest { | */ | public fun RecordRoute(): GrpcStreamingCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |package routeguide | @@ -654,7 +678,8 @@ class KotlinGeneratorTest { | responseAdapter = RouteSummary.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -671,12 +696,13 @@ class KotlinGeneratorTest { |} |$pointMessage |$routeSummaryMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expectedInterface, expectedImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide"), ) } @@ -696,7 +722,8 @@ class KotlinGeneratorTest { | */ | public fun ListFeatures(): GrpcStreamingCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |package routeguide | @@ -720,7 +747,8 @@ class KotlinGeneratorTest { | responseAdapter = Feature.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -738,12 +766,13 @@ class KotlinGeneratorTest { |$rectangeMessage |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expectedInterface, expectedImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide"), ) } @@ -904,7 +933,8 @@ class KotlinGeneratorTest { |} |$pointMessage |$routeNoteMessage - |""".trimMargin() + | + """.trimMargin(), ) } @@ -912,29 +942,33 @@ class KotlinGeneratorTest { listOf(blockingClientInterface, blockingClientImplementation), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.CLIENT - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.CLIENT, + ), ) assertEquals( listOf(blockingServer), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.BLOCKING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.BLOCKING, + rpcRole = RpcRole.SERVER, + ), ) assertEquals( listOf(suspendingClientInterface, suspendingClientImplementation), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.SUSPENDING, rpcRole = RpcRole.CLIENT - ) + rpcCallStyle = RpcCallStyle.SUSPENDING, + rpcRole = RpcRole.CLIENT, + ), ) assertEquals( listOf(suspendingServer), KotlinWithProfilesGenerator(schema).generateGrpcKotlin( "routeguide.RouteGuide", - rpcCallStyle = RpcCallStyle.SUSPENDING, rpcRole = RpcRole.SERVER - ) + rpcCallStyle = RpcCallStyle.SUSPENDING, + rpcRole = RpcRole.SERVER, + ), ) } @@ -960,7 +994,8 @@ class KotlinGeneratorTest { | */ | public fun RouteChat(): GrpcStreamingCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |package routeguide | @@ -994,7 +1029,8 @@ class KotlinGeneratorTest { | responseAdapter = RouteNote.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -1014,12 +1050,13 @@ class KotlinGeneratorTest { |$pointMessage |$featureMessage |$routeNoteMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( listOf(expectedInterface, expectedImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide"), ) } @@ -1037,7 +1074,8 @@ class KotlinGeneratorTest { |$pointMessage |$featureMessage |$routeNoteMessage - |""".trimMargin() + | + """.trimMargin(), ) } @@ -1050,7 +1088,8 @@ class KotlinGeneratorTest { |public interface RouteGuideGetFeatureClient : Service { | public fun GetFeature(): GrpcCall |} - |""".trimMargin() + | + """.trimMargin() val expectedGetFeatureImplementation = """ |package routeguide | @@ -1067,11 +1106,12 @@ class KotlinGeneratorTest { | responseAdapter = Feature.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() assertEquals( listOf(expectedGetFeatureInterface, expectedGetFeatureImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide", "GetFeature") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide", "GetFeature"), ) val expectedRouteChatInterface = """ @@ -1083,7 +1123,8 @@ class KotlinGeneratorTest { |public interface RouteGuideRouteChatClient : Service { | public fun RouteChat(): GrpcStreamingCall |} - |""".trimMargin() + | + """.trimMargin() val expectedRouteChatImplementation = """ |package routeguide | @@ -1101,11 +1142,12 @@ class KotlinGeneratorTest { | responseAdapter = RouteNote.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() assertEquals( listOf(expectedRouteChatInterface, expectedRouteChatImplementation), - KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide", "RouteChat") + KotlinWithProfilesGenerator(schema).generateGrpcKotlin("routeguide.RouteGuide", "RouteChat"), ) } @@ -1132,7 +1174,8 @@ class KotlinGeneratorTest { | ) | public suspend fun GetFeature(request: Point): Feature |} - |""".trimMargin() + | + """.trimMargin() //language=kotlin val blockingInterface = """ @@ -1156,7 +1199,8 @@ class KotlinGeneratorTest { | ) | public fun GetFeature(request: Point): Feature |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -1173,7 +1217,8 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } @@ -1184,7 +1229,7 @@ class KotlinGeneratorTest { rpcRole = RpcRole.SERVER, rpcCallStyle = RpcCallStyle.SUSPENDING, nameSuffix = "", - ) + ), ) assertEquals( @@ -1194,7 +1239,7 @@ class KotlinGeneratorTest { rpcRole = RpcRole.SERVER, rpcCallStyle = RpcCallStyle.BLOCKING, nameSuffix = "Thing", - ) + ), ) } @@ -1205,7 +1250,8 @@ class KotlinGeneratorTest { """ |message Message { | required float tag = 1; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Message") @@ -1222,7 +1268,8 @@ class KotlinGeneratorTest { """ |message Message { | required float var = 1; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Message") @@ -1241,7 +1288,8 @@ class KotlinGeneratorTest { |} |message Person { | optional Gender Gender = 1; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("common.proto.Person") @@ -1268,7 +1316,8 @@ class KotlinGeneratorTest { | } | repeated B b = 1; | optional AnotherStatus Status = 2; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("common.proto.A") @@ -1284,7 +1333,8 @@ class KotlinGeneratorTest { |import "google/protobuf/any.proto"; |message Message { | optional google.protobuf.Any just_one = 1; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("common.proto.Message") @@ -1310,7 +1360,8 @@ class KotlinGeneratorTest { | optional PhoneType type = 2 [default = HOME]; | } | repeated PhoneNumber phone = 4; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Person").replace("\n", "") @@ -1320,7 +1371,7 @@ class KotlinGeneratorTest { assertThat(code).contains("PhoneNumber::class") assertThat(code).contains("override fun encode(writer: ProtoWriter, `value`: Person)") assertTrue( - code.contains("enum class PhoneType( override val `value`: Int, ) : WireEnum") + code.contains("enum class PhoneType( override val `value`: Int, ) : WireEnum"), ) assertThat(code).contains("fun fromValue(`value`: Int): PhoneType?") assertThat(code).contains("WORK(1),") @@ -1346,7 +1397,8 @@ class KotlinGeneratorTest { | WORK = 1; | MOBILE = 2; | } - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Person") @@ -1382,7 +1434,8 @@ class KotlinGeneratorTest { """ |message $longType { | required string $longMember = 1; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin(longType) @@ -1390,7 +1443,7 @@ class KotlinGeneratorTest { | ($longMember | != | other.$longMember) - """.trimMargin() + """.trimMargin() assertThat(code).contains("return false") assertThat(code).contains("return $longType(") @@ -1424,7 +1477,8 @@ class KotlinGeneratorTest { | } | message Baz {} |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("common.proto.LabelMessage") @@ -1451,7 +1505,8 @@ class KotlinGeneratorTest { |message Person { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Person") @@ -1472,7 +1527,8 @@ class KotlinGeneratorTest { |message Person { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Person") @@ -1493,7 +1549,8 @@ class KotlinGeneratorTest { |message Person { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "city_package/home.proto".toPath(), @@ -1504,7 +1561,8 @@ class KotlinGeneratorTest { |message Home { | repeated proto_package.Person person = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("city_package.Home") @@ -1523,7 +1581,8 @@ class KotlinGeneratorTest { |message Person { | repeated float info = 1 [packed = true, wire.use_array = true]; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Person") @@ -1549,7 +1608,7 @@ class KotlinGeneratorTest { | // g [h.i.j] k | CONSTANT = 0; |} - """.trimMargin() + """.trimMargin(), ) } val messageCode = KotlinWithProfilesGenerator(schema).generateKotlin("Message") @@ -1578,7 +1637,8 @@ class KotlinGeneratorTest { | */ | public fun GetFeature(): GrpcCall |} - |""".trimMargin() + | + """.trimMargin() val expectedImplementation = """ |package routeguide | @@ -1605,7 +1665,8 @@ class KotlinGeneratorTest { | responseAdapter = PropertiesFeatureAdapter.ADAPTER | )) |} - |""".trimMargin() + | + """.trimMargin() val schema = buildSchema { add( @@ -1620,7 +1681,8 @@ class KotlinGeneratorTest { |} |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } assertEquals( @@ -1639,9 +1701,10 @@ class KotlinGeneratorTest { |type routeguide.Feature { | target java.util.Properties using com.example.PropertiesFeatureAdapter#ADAPTER; |} - |""".trimMargin() + | + """.trimMargin(), ) - .generateGrpcKotlin("routeguide.RouteGuide", profileName = "java") + .generateGrpcKotlin("routeguide.RouteGuide", profileName = "java"), ) } @@ -1654,7 +1717,8 @@ class KotlinGeneratorTest { | |$pointMessage |$featureMessage - |""".trimMargin() + | + """.trimMargin(), ) } @@ -1668,7 +1732,8 @@ class KotlinGeneratorTest { |type routeguide.Point { | target kotlin.String using com.example.StringPointAdapter#INSTANCE; |} - |""".trimMargin() + | + """.trimMargin(), ) .generateKotlin("routeguide.Feature", profileName = "java") assertThat(kotlin).contains( @@ -1679,7 +1744,7 @@ class KotlinGeneratorTest { | schemaIndex = 1, | ) | public val location: String? = null, - """.trimMargin() + """.trimMargin(), ) assertThat(kotlin).contains( """ @@ -1689,7 +1754,7 @@ class KotlinGeneratorTest { | size += StringPointAdapter.INSTANCE.encodedSizeWithTag(2, value.location) | return size | } - """.trimMargin() + """.trimMargin(), ) assertThat(kotlin).contains( """ @@ -1698,7 +1763,7 @@ class KotlinGeneratorTest { | StringPointAdapter.INSTANCE.encodeWithTag(writer, 2, value.location) | writer.writeBytes(value.unknownFields) | } - """.trimMargin() + """.trimMargin(), ) assertThat(kotlin).contains( """ @@ -1718,7 +1783,8 @@ class KotlinGeneratorTest { | unknownFields = unknownFields | ) | } - |""".trimMargin() + | + """.trimMargin(), ) } @@ -1735,14 +1801,15 @@ class KotlinGeneratorTest { | SOUTH = 3; | WEST = 4; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Direction") assertThat(code).contains( """|@Deprecated(message = "Direction is deprecated") |public enum class Direction( - """.trimMargin() + """.trimMargin(), ) } @@ -1758,18 +1825,19 @@ class KotlinGeneratorTest { | SOUTH = 3; | WEST = 4; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Direction") assertThat(code).contains( """| @Deprecated(message = "EAST is deprecated") | EAST(2), - """.trimMargin() + """.trimMargin(), ) assertThat(code).contains( """| 2 -> @Suppress("DEPRECATION") EAST - """.trimMargin() + """.trimMargin(), ) } @@ -1782,7 +1850,8 @@ class KotlinGeneratorTest { |message Person { | optional string name = 1 [deprecated = true]; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Person") @@ -1794,7 +1863,7 @@ class KotlinGeneratorTest { | schemaIndex = 0, | ) | public val name: String? = null, - """.trimMargin() + """.trimMargin(), ) } @@ -1808,14 +1877,15 @@ class KotlinGeneratorTest { | option deprecated = true; | optional string name = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("proto_package.Person") assertThat(code).contains( """|@Deprecated(message = "Person is deprecated") |public class Person( - """.trimMargin() + """.trimMargin(), ) } @@ -1838,7 +1908,8 @@ class KotlinGeneratorTest { |} | |message SecretData {} - |""".trimMargin() + | + """.trimMargin(), ) addFromTest("option_redacted.proto".toPath()) } @@ -1858,7 +1929,7 @@ class KotlinGeneratorTest { | secret_data = null, | unknownFields = ByteString.EMPTY | ) - """.trimMargin() + """.trimMargin(), ) } @@ -1877,7 +1948,8 @@ class KotlinGeneratorTest { | optional string d = 8; | } |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema) @@ -1898,24 +1970,25 @@ class KotlinGeneratorTest { |message SomeMessage { | optional string a = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } assertThat( KotlinWithProfilesGenerator(schema) - .generateKotlin("SomeMessage", javaInterop = false) + .generateKotlin("SomeMessage", javaInterop = false), ) .contains("Builders are deprecated and only available in a javaInterop build") assertThat( KotlinWithProfilesGenerator(schema) - .generateKotlin("SomeMessage", javaInterop = true) + .generateKotlin("SomeMessage", javaInterop = true), ) .doesNotContain("Builders are deprecated and only available in a javaInterop build") // If `buildersOnly` is set to true, it takes precedence over `javaInterop` for it would // otherwise create non-instantiable types. assertThat( KotlinWithProfilesGenerator(schema) - .generateKotlin("SomeMessage", javaInterop = false, buildersOnly = true) + .generateKotlin("SomeMessage", javaInterop = false, buildersOnly = true), ) .doesNotContain("Builders are deprecated and only available in a javaInterop build") } @@ -1949,7 +2022,8 @@ class KotlinGeneratorTest { |} | |message SecretData {} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("SomeMessage", boxOneOfsMinSize = 3) @@ -2015,7 +2089,7 @@ class KotlinGeneratorTest { | ) | public val k: String? = null, | unknownFields: ByteString = ByteString.EMPTY, - """.trimMargin() + """.trimMargin(), ) } @@ -2042,7 +2116,7 @@ class KotlinGeneratorTest { |message OtherText { | string otherValue = 1; |} - """.trimMargin() + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("SomeText") @@ -2068,7 +2142,7 @@ class KotlinGeneratorTest { | ordinal = 2; | open = 3; |} - """.trimMargin() + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("ConflictingEnumConstants") @@ -2085,7 +2159,7 @@ class KotlinGeneratorTest { | @WireEnumConstant(declaredName = "open") | open_(3), | ; - """.trimMargin() + """.trimMargin(), ) assertThat(code).contains( """ @@ -2096,7 +2170,7 @@ class KotlinGeneratorTest { | 3 -> open_ | else -> null | } - """.trimMargin() + """.trimMargin(), ) } @@ -2107,7 +2181,8 @@ class KotlinGeneratorTest { """ |message Embedding { | repeated float values = 1 [packed = true]; - |}""".trimMargin() + |} + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema).generateKotlin("Embedding") @@ -2133,7 +2208,8 @@ class KotlinGeneratorTest { |message Person { | required string name = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) add( "employer_proto_package/employer.proto".toPath(), @@ -2144,7 +2220,8 @@ class KotlinGeneratorTest { |message Employer { | repeated person_proto_package.Person employees = 1; |} - |""".trimMargin() + | + """.trimMargin(), ) } val code = KotlinWithProfilesGenerator(schema) @@ -2157,25 +2234,29 @@ class KotlinGeneratorTest { |message Point { | optional int32 latitude = 1; | optional int32 longitude = 2; - |}""".trimMargin() + |} + """.trimMargin() private val rectangeMessage = """ |message Rectangle { | optional Point lo = 1; | optional Point hi = 2; - |}""".trimMargin() + |} + """.trimMargin() private val featureMessage = """ |message Feature { | optional string name = 1; | optional Point location = 2; - |}""".trimMargin() + |} + """.trimMargin() private val routeNoteMessage = """ |message RouteNote { | optional Point location = 1; | optional string message = 2; - |}""".trimMargin() + |} + """.trimMargin() private val routeSummaryMessage = """ |message RouteSummary { @@ -2183,6 +2264,7 @@ class KotlinGeneratorTest { | optional int32 feature_count = 2; | optional int32 distance = 3; | optional int32 elapsed_time = 4; - |}""".trimMargin() + |} + """.trimMargin() } } diff --git a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinWithProfilesGenerator.kt b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinWithProfilesGenerator.kt index c7d97a19a7..838138c59b 100644 --- a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinWithProfilesGenerator.kt +++ b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinWithProfilesGenerator.kt @@ -1,11 +1,11 @@ /* - * Copyright (C) 2022 Block, Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-moshi-adapter/build.gradle.kts b/wire-moshi-adapter/build.gradle.kts index 4d20ba11a9..8f28e0a13b 100644 --- a/wire-moshi-adapter/build.gradle.kts +++ b/wire-moshi-adapter/build.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.SpotlessExtension import com.vanniktech.maven.publish.JavadocJar.Dokka import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.MavenPublishBaseExtension @@ -17,6 +18,21 @@ if (project.rootProject.name == "wire") { KotlinJvm(javadocJar = Dokka("dokkaGfm"), sourcesJar = true) ) } + + configure { + kotlin { + targetExclude( + // Generated files. + "src/test/java/**/*.kt", + ) + } + java { + targetExclude( + // Generated files. + "src/test/java/**/*.java", + ) + } + } } dependencies { diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/AnyMessageJsonAdapter.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/AnyMessageJsonAdapter.kt index c5968287d5..e49c827372 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/AnyMessageJsonAdapter.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/AnyMessageJsonAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ import java.io.IOException internal class AnyMessageJsonAdapter( private val moshi: Moshi, - private val typeUrlToAdapter: Map> + private val typeUrlToAdapter: Map>, ) : JsonAdapter() { @Throws(IOException::class) diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/EnumJsonAdapter.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/EnumJsonAdapter.kt index 6f8abe5725..0e32c8f29b 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/EnumJsonAdapter.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/EnumJsonAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt index 6107b3bca4..dd7c906fcb 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/MessageJsonAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -50,7 +50,7 @@ internal class MessageJsonAdapter, B : Message.Builder>( messageAdapter.writeAllFields( message = message, jsonAdapters = jsonAdapters, - redactedFieldsAdapter = redactedFieldsAdapter + redactedFieldsAdapter = redactedFieldsAdapter, ) { name, value, jsonAdapter -> out.name(name) jsonAdapter.toJson(out, value) diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/MoshiJsonIntegration.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/MoshiJsonIntegration.kt index 067d5ee9fa..bc11bcec7e 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/MoshiJsonIntegration.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/MoshiJsonIntegration.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,7 +27,7 @@ import java.lang.reflect.Type internal object MoshiJsonIntegration : JsonIntegration>() { override fun frameworkAdapter( framework: Moshi, - type: Type + type: Type, ): JsonAdapter = framework.adapter(type).nullSafe() override fun listAdapter(elementAdapter: JsonAdapter): JsonAdapter = @@ -36,7 +36,7 @@ internal object MoshiJsonIntegration : JsonIntegration> override fun mapAdapter( framework: Moshi, keyFormatter: JsonFormatter<*>, - valueAdapter: JsonAdapter + valueAdapter: JsonAdapter, ): JsonAdapter = MapJsonAdapter(keyFormatter, valueAdapter).nullSafe() as JsonAdapter override fun structAdapter(framework: Moshi): JsonAdapter = @@ -46,11 +46,11 @@ internal object MoshiJsonIntegration : JsonIntegration> FormatterJsonAdapter(jsonFormatter).nullSafe() as JsonAdapter private class FormatterJsonAdapter( - private val formatter: JsonFormatter + private val formatter: JsonFormatter, ) : JsonAdapter() { override fun toJson( writer: JsonWriter, - value: T? + value: T?, ) { val stringOrNumber = formatter.toStringOrNumber(value!!) if (stringOrNumber is Number) { @@ -72,7 +72,7 @@ internal object MoshiJsonIntegration : JsonIntegration> /** Adapt a list of values by delegating to an adapter for a single value. */ private class ListJsonAdapter( - private val single: JsonAdapter + private val single: JsonAdapter, ) : JsonAdapter>() { override fun fromJson(reader: JsonReader): List { val result = mutableListOf() @@ -86,7 +86,7 @@ internal object MoshiJsonIntegration : JsonIntegration> override fun toJson( writer: JsonWriter, - value: List? + value: List?, ) { writer.beginArray() for (v in value!!) { @@ -99,7 +99,7 @@ internal object MoshiJsonIntegration : JsonIntegration> /** Adapt a list of values by delegating to an adapter for a single value. */ private class MapJsonAdapter( private val keyFormatter: JsonFormatter, - private val valueAdapter: JsonAdapter + private val valueAdapter: JsonAdapter, ) : JsonAdapter>() { override fun fromJson(reader: JsonReader): Map? { val result = mutableMapOf() diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/RedactingJsonAdapter.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/RedactingJsonAdapter.kt index 94daa58eca..d3e2cce6f3 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/RedactingJsonAdapter.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/RedactingJsonAdapter.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-moshi-adapter/src/main/java/com/squareup/wire/WireJsonAdapterFactory.kt b/wire-moshi-adapter/src/main/java/com/squareup/wire/WireJsonAdapterFactory.kt index 2afb0a65fe..45daf01746 100644 --- a/wire-moshi-adapter/src/main/java/com/squareup/wire/WireJsonAdapterFactory.kt +++ b/wire-moshi-adapter/src/main/java/com/squareup/wire/WireJsonAdapterFactory.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -53,7 +53,7 @@ class WireJsonAdapterFactory @JvmOverloads constructor( val newMap = typeUrlToAdapter.toMutableMap() for (adapter in adapters) { val key = adapter.typeUrl ?: throw IllegalArgumentException( - "recompile ${adapter.type} to use it with WireJsonAdapterFactory" + "recompile ${adapter.type} to use it with WireJsonAdapterFactory", ) newMap[key] = adapter } @@ -71,7 +71,7 @@ class WireJsonAdapterFactory @JvmOverloads constructor( override fun create( type: Type, annotations: Set, - moshi: Moshi + moshi: Moshi, ): JsonAdapter<*>? { val rawType = Types.getRawType(type) @@ -86,7 +86,7 @@ class WireJsonAdapterFactory @JvmOverloads constructor( ) val jsonAdapters = MoshiJsonIntegration.jsonAdapters(messageAdapter, moshi) val redactedFieldsAdapter = moshi.adapter>( - Types.newParameterizedType(List::class.java, String::class.java) + Types.newParameterizedType(List::class.java, String::class.java), ) MessageJsonAdapter(messageAdapter, jsonAdapters, redactedFieldsAdapter).nullSafe() } diff --git a/wire-moshi-adapter/src/test/java/com/squareup/wire/MoshiTest.java b/wire-moshi-adapter/src/test/java/com/squareup/wire/MoshiTest.java index 1eb78196cb..438727ad8b 100644 --- a/wire-moshi-adapter/src/test/java/com/squareup/wire/MoshiTest.java +++ b/wire-moshi-adapter/src/test/java/com/squareup/wire/MoshiTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,8 @@ */ package com.squareup.wire; +import static org.assertj.core.api.Assertions.assertThat; + import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; import com.squareup.wire.json.JsonUtils; @@ -31,8 +33,6 @@ import squareup.proto2.keywords.KeywordKotlin; import squareup.proto2.keywords.KeywordKotlin.KeywordKotlinEnum; -import static org.assertj.core.api.Assertions.assertThat; - public class MoshiTest { private static final String ALL_TYPES_IDENTITY_JSON; @@ -40,10 +40,11 @@ public class MoshiTest { try { ALL_TYPES_IDENTITY_JSON = Okio.buffer( - Okio.source( - new File("../wire-tests/src/commonTest/shared/json", - "all_types_identity_proto2.json")) - ).readUtf8(); + Okio.source( + new File( + "../wire-tests/src/commonTest/shared/json", + "all_types_identity_proto2.json"))) + .readUtf8(); } catch (IOException e) { throw new RuntimeException(e); } @@ -87,12 +88,11 @@ private static AllTypes.Builder createIdentityBuilder() { .req_nested_message(new AllTypes.NestedMessage.Builder().a(0).build()); } - private final Moshi moshi = new Moshi.Builder() - .add(new WireJsonAdapterFactory()) - .build(); + private final Moshi moshi = new Moshi.Builder().add(new WireJsonAdapterFactory()).build(); @SuppressWarnings("ConstantConditions") - @Test public void notIdentityOneOf() throws IOException { + @Test + public void notIdentityOneOf() throws IOException { JsonAdapter allTypesAdapter = moshi.adapter(AllTypes.class); AllTypes allTypes = createIdentityBuilder().oneof_int32(0).build(); @@ -100,39 +100,43 @@ private static AllTypes.Builder createIdentityBuilder() { AllTypes parsed = allTypesAdapter.fromJson(ALL_TYPES_IDENTITY_JSON); assertThat(parsed.oneof_int32).isNull(); - String json = ALL_TYPES_IDENTITY_JSON - .substring(0, ALL_TYPES_IDENTITY_JSON.length() - 2) + ",\"oneof_int32\":0}"; + String json = + ALL_TYPES_IDENTITY_JSON.substring(0, ALL_TYPES_IDENTITY_JSON.length() - 2) + + ",\"oneof_int32\":0}"; parsed = allTypesAdapter.fromJson(json); assertThat(parsed.oneof_int32).isEqualTo(0); } @SuppressWarnings("ConstantConditions") - @Test public void nullRepeatedField() throws IOException { - RepeatedPackedAndMap parsed = moshi.adapter(RepeatedPackedAndMap.class) - .fromJson("{\"rep_int32\":null,\"pack_int32\":null,\"map_int32_int32\":null}"); + @Test + public void nullRepeatedField() throws IOException { + RepeatedPackedAndMap parsed = + moshi + .adapter(RepeatedPackedAndMap.class) + .fromJson("{\"rep_int32\":null,\"pack_int32\":null,\"map_int32_int32\":null}"); assertThat(parsed.rep_int32).isEmpty(); assertThat(parsed.pack_int32).isEmpty(); assertThat(parsed.map_int32_int32).isEmpty(); } - @Test public void usedKeywordsInKotlin() throws IOException { + @Test + public void usedKeywordsInKotlin() throws IOException { JsonAdapter adapter = moshi.adapter(KeywordKotlin.class); - KeywordKotlin keyword = new KeywordKotlin.Builder() - .object_("object") - .when_(1) - .enums( - Arrays.asList( - KeywordKotlinEnum.object_, - KeywordKotlinEnum.when_, - KeywordKotlinEnum.fun_, - KeywordKotlinEnum.return_, - KeywordKotlinEnum.open_, - KeywordKotlinEnum.name_, - KeywordKotlinEnum.ordinal_ - ) - ) - .build(); + KeywordKotlin keyword = + new KeywordKotlin.Builder() + .object_("object") + .when_(1) + .enums( + Arrays.asList( + KeywordKotlinEnum.object_, + KeywordKotlinEnum.when_, + KeywordKotlinEnum.fun_, + KeywordKotlinEnum.return_, + KeywordKotlinEnum.open_, + KeywordKotlinEnum.name_, + KeywordKotlinEnum.ordinal_)) + .build(); String json = adapter.toJson(keyword); JsonUtils.assertJsonEquals( "{\"object\":\"object\",\"when\":1, \"fun\":{}, \"return\":[], \"enums\":[\"object\", " @@ -140,27 +144,28 @@ private static AllTypes.Builder createIdentityBuilder() { json); assertThat(adapter.fromJson(json)).isEqualTo(keyword); - String generatedNamedJson = "{\"object_\":\"object\",\"when_\":1, \"fun_\":{}, \"return_\":[], " - + "\"enums\":[\"object_\", \"when_\", \"fun_\", \"return_\", \"open_\", \"name_\", " - + "\"ordinal_\"]}"; + String generatedNamedJson = + "{\"object_\":\"object\",\"when_\":1, \"fun_\":{}, \"return_\":[], " + + "\"enums\":[\"object_\", \"when_\", \"fun_\", \"return_\", \"open_\", \"name_\", " + + "\"ordinal_\"]}"; assertThat(adapter.fromJson(generatedNamedJson)).isEqualTo(keyword); } - @Test public void usedKeywordsInJava() throws IOException { + @Test + public void usedKeywordsInJava() throws IOException { JsonAdapter adapter = moshi.adapter(KeywordJava.class); - KeywordJava keyword = new KeywordJava.Builder() - .public_(true) - .final_("final") - .enums( - Arrays.asList( - KeywordJavaEnum.final_, - KeywordJavaEnum.public_, - KeywordJavaEnum.package_, - KeywordJavaEnum.return_ - ) - ) - .build(); + KeywordJava keyword = + new KeywordJava.Builder() + .public_(true) + .final_("final") + .enums( + Arrays.asList( + KeywordJavaEnum.final_, + KeywordJavaEnum.public_, + KeywordJavaEnum.package_, + KeywordJavaEnum.return_)) + .build(); String json = adapter.toJson(keyword); JsonUtils.assertJsonEquals( "{\"final\":\"final\", \"public\":true, \"package\":{}, \"return\":[], " @@ -168,12 +173,14 @@ private static AllTypes.Builder createIdentityBuilder() { json); assertThat(adapter.fromJson(json)).isEqualTo(keyword); - String generatedNamedJson = "{\"final_\":\"final\", \"public_\":true, \"package_\":{}, " - + "\"return_\":[], \"enums\":[\"final_\", \"public_\", \"package_\", \"return_\"]}"; + String generatedNamedJson = + "{\"final_\":\"final\", \"public_\":true, \"package_\":{}, " + + "\"return_\":[], \"enums\":[\"final_\", \"public_\", \"package_\", \"return_\"]}"; assertThat(adapter.fromJson(generatedNamedJson)).isEqualTo(keyword); } - @Test public void enumKeywordsAtRootInKotlin() throws IOException { + @Test + public void enumKeywordsAtRootInKotlin() throws IOException { JsonAdapter adapter = moshi.adapter(KeywordKotlinEnum.class); KeywordKotlinEnum constant = KeywordKotlinEnum.object_; @@ -185,7 +192,8 @@ private static AllTypes.Builder createIdentityBuilder() { assertThat(adapter.fromJson(generatedNamedJson)).isEqualTo(constant); } - @Test public void enumKeywordsAtRootInJava() throws IOException { + @Test + public void enumKeywordsAtRootInJava() throws IOException { JsonAdapter adapter = moshi.adapter(KeywordJavaEnum.class); KeywordJavaEnum constant = KeywordJavaEnum.final_; diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/DurationRoundTripTest.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/DurationRoundTripTest.kt index 2f86beb83b..784d3b2439 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/DurationRoundTripTest.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/DurationRoundTripTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/EmptyRoundTripTest.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/EmptyRoundTripTest.kt index 6c5556e489..d2c119760e 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/EmptyRoundTripTest.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/EmptyRoundTripTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,9 +18,9 @@ package com.squareup.wire import com.google.protobuf.Empty import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import squareup.proto3.kotlin.alltypes.AllEmptyOuterClass import squareup.proto3.java.alltypes.AllEmpty as AllEmptyJ import squareup.proto3.kotlin.alltypes.AllEmpty as AllEmptyK +import squareup.proto3.kotlin.alltypes.AllEmptyOuterClass class EmptyRoundTripTest { @Test fun empty() { @@ -54,7 +54,7 @@ class EmptyRoundTripTest { empty = Unit, rep_empty = listOf(Unit, Unit), map_int32_empty = mapOf(1 to Unit), - oneof_empty = Unit + oneof_empty = Unit, ) val googleMessageBytes = googleMessage.toByteArray() diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InstantRoundTripTest.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InstantRoundTripTest.kt index 1ae446ba03..56158e16ad 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InstantRoundTripTest.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InstantRoundTripTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropChecker.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropChecker.kt index 516103286b..1314bfee65 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropChecker.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropChecker.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropTest.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropTest.kt index e8cf1c6033..9cc3711bcd 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropTest.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/InteropTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,7 +19,6 @@ import com.google.protobuf.Duration import okio.ByteString import org.junit.Ignore import org.junit.Test -import squareup.proto3.java.interop.InteropTest.InteropWrappers import squareup.proto2.java.interop.InteropBoxOneOf as InteropBoxOneOfJ2 import squareup.proto2.java.interop.InteropCamelCase as InteropCamelCaseJ2 import squareup.proto2.java.interop.InteropDuration as InteropDurationJ2 @@ -43,6 +42,7 @@ import squareup.proto3.java.interop.InteropTest.InteropCamelCase as InteropCamel import squareup.proto3.java.interop.InteropTest.InteropDuration as InteropDurationP3 import squareup.proto3.java.interop.InteropTest.InteropJsonName as InteropJsonNameP3 import squareup.proto3.java.interop.InteropTest.InteropUint64 as InteropUint64P3 +import squareup.proto3.java.interop.InteropTest.InteropWrappers import squareup.proto3.java.interop.InteropUint64 as InteropUint64J3 import squareup.proto3.java.interop.InteropWrappers as InteropWrappersJ3 import squareup.proto3.kotlin.interop.InteropBoxOneOf as InteropBoxOneOfK3 @@ -62,7 +62,7 @@ class InteropTest { Duration.newBuilder() .setSeconds(99L) .setNanos(987_654_321) - .build() + .build(), ) .build(), canonicalJson = """{"value":"99.987654321s"}""", @@ -113,7 +113,7 @@ class InteropTest { .build(), canonicalJson = """{"value":"18446744073709551615"}""", wireAlternateJsons = listOf( - """{"value":"-1"}""" + """{"value":"-1"}""", ), ) max.check(InteropUint64K3(-1L)) @@ -132,7 +132,7 @@ class InteropTest { """{"value":18446744073709551615}""", ), wireAlternateJsons = listOf( - """{"value":"-1"}""" + """{"value":"-1"}""", ), ) max.check(InteropUint64K2(-1L)) @@ -179,7 +179,7 @@ class InteropTest { wireCanonicalJson = """{"hello_world":"1","a__b":"2","_Ccc_ddd":"3","EEee_ff_gGg":"4","a_b_c":"5","GHI":"6","K_L_M":"7","__T__U__V__":"8","_x_y_z_":"9"}""", alternateJsons = listOf( """{"helloWorld":"1","aB":"2","CccDdd":"3","EEeeFfGGg":"4","aBC":"5","GHI":"6","KLM":"7","TUV":"8","XYZ":"9"}""", - ) + ), ) checker.check(InteropCamelCaseK2("1", "2", "3", "4", "5", "6", "7", "8", "9")) @@ -260,17 +260,18 @@ class InteropTest { checker.check( InteropBoxOneOfK2.Builder() .option(OneOf(InteropBoxOneOfK2.OPTION_A, "Hello")) - .build() + .build(), ) checker.check( InteropBoxOneOfK3.Builder() .option(OneOf(InteropBoxOneOfK3.OPTION_A, "Hello")) - .build() + .build(), ) } @Ignore("Needs to implement boxed oneofs in Java.") - @Test fun boxOneOfsJava() { + @Test + fun boxOneOfsJava() { val checker = InteropChecker( protocMessage = InteropBoxOneOfP3.newBuilder() .setA("Hello") @@ -307,7 +308,7 @@ class InteropTest { .bool_value(false) .string_value("") .bytes_value(ByteString.EMPTY) - .build() + .build(), ) checker.check( InteropWrappersK3.Builder() @@ -320,7 +321,7 @@ class InteropTest { .bool_value(false) .string_value("") .bytes_value(ByteString.EMPTY) - .build() + .build(), ) } @@ -359,7 +360,7 @@ class InteropTest { .bool_value(true) .string_value("string") .bytes_value(ByteString.of(1)) - .build() + .build(), ) checker.check( InteropWrappersK3.Builder() @@ -372,7 +373,7 @@ class InteropTest { .bool_value(true) .string_value("string") .bytes_value(ByteString.of(1)) - .build() + .build(), ) } } diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto2WireProtocCompatibilityTests.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto2WireProtocCompatibilityTests.kt index ed7610ec45..c3921d04ab 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto2WireProtocCompatibilityTests.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto2WireProtocCompatibilityTests.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -66,12 +66,12 @@ class Proto2WireProtocCompatibilityTests { no_default_nested_enum = SimpleMessageK.NestedEnum.BAR, repeated_double = listOf(1.0, 33.0), required_int32 = 46, - other = "hello" + other = "hello", ) val googleMessage = SimpleMessageOuterClass.SimpleMessage.newBuilder() .setOptionalNestedMsg( - SimpleMessageOuterClass.SimpleMessage.NestedMessage.newBuilder().setBb(806).build() + SimpleMessageOuterClass.SimpleMessage.NestedMessage.newBuilder().setBb(806).build(), ) .setNoDefaultNestedEnum(SimpleMessageOuterClass.SimpleMessage.NestedEnum.BAR) .addAllRepeatedDouble(listOf(1.0, 33.0)) @@ -172,7 +172,7 @@ class Proto2WireProtocCompatibilityTests { quilt = Quilt( fringe = listOf(QuiltColor.GREEN), cozy = true, - ) + ), ) // A sample value encoded by ts-proto. @@ -183,7 +183,7 @@ class Proto2WireProtocCompatibilityTests { RepeatedEnum.Quilt.newBuilder() .addAllFringe(listOf(RepeatedEnum.QuiltColor.GREEN)) .setCozy(true) - .build() + .build(), ).build() val wireMessageDecodedFromGoogleMessage = @@ -286,7 +286,7 @@ class Proto2WireProtocCompatibilityTests { oneof_int32 = 0, ext_opt_bool = true, ext_rep_bool = list(true), - ext_pack_bool = list(true) + ext_pack_bool = list(true), ) private val defaultAllTypesProtoc = AllTypesOuterClass.AllTypes.newBuilder() @@ -307,7 +307,7 @@ class Proto2WireProtocCompatibilityTests { .setOptBytes(com.google.protobuf.ByteString.copyFrom(ByteString.of(123, 125).toByteArray())) .setOptNestedEnum(AllTypesOuterClass.AllTypes.NestedEnum.A) .setOptNestedMessage( - AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build() + AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build(), ) .setReqInt32(111) .setReqUint32(112) @@ -326,7 +326,7 @@ class Proto2WireProtocCompatibilityTests { .setReqBytes(com.google.protobuf.ByteString.copyFrom(ByteString.of(123, 125).toByteArray())) .setReqNestedEnum(AllTypesOuterClass.AllTypes.NestedEnum.A) .setReqNestedMessage( - AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build() + AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build(), ) .addAllRepInt32(list(111)) .addAllRepUint32(list(112)) @@ -343,13 +343,13 @@ class Proto2WireProtocCompatibilityTests { .addAllRepDouble(list(123.0)) .addAllRepString(list("124")) .addAllRepBytes( - list(com.google.protobuf.ByteString.copyFrom(ByteString.of(123, 125).toByteArray())) + list(com.google.protobuf.ByteString.copyFrom(ByteString.of(123, 125).toByteArray())), ) .addAllRepNestedEnum(list(AllTypesOuterClass.AllTypes.NestedEnum.A)) .addAllRepNestedMessage( list( - AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build() - ) + AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build(), + ), ) .addAllPackInt32(list(111)) .addAllPackUint32(list(112)) @@ -369,7 +369,7 @@ class Proto2WireProtocCompatibilityTests { .putMapStringString("key", "value") .putMapStringMessage( "message", - AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(1).build() + AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(1).build(), ) .putMapStringEnum("enum", AllTypesOuterClass.AllTypes.NestedEnum.A) .setOneofInt32(0) @@ -432,7 +432,7 @@ class Proto2WireProtocCompatibilityTests { map_string_enum = mapOf("" to AllTypesK.NestedEnum.UNKNOWN), ext_opt_bool = false, ext_rep_bool = list(false), - ext_pack_bool = list(false) + ext_pack_bool = list(false), ) private val identityAllTypesProtoc = AllTypesOuterClass.AllTypes.newBuilder() @@ -519,7 +519,7 @@ class Proto2WireProtocCompatibilityTests { .setExtension(extRepProto2Enum, list(EnumProto2.A)) .setExtension( extRepProto2Message, - list(MessageProto2.newBuilder().setA(3).setB("Dwyane").build()) + list(MessageProto2.newBuilder().setA(3).setB("Dwyane").build()), ) .setExtension(extRepProto3Enum, list(EnumProto3.A)) .setExtension(extRepProto3Message, list(MessageProto3.newBuilder().setA(1).build())) @@ -552,7 +552,7 @@ class Proto2WireProtocCompatibilityTests { ext_rep_proto2_message = list(MessageProto2K(3, "Dwyane")), ext_rep_proto3_enum = list(EnumProto3K.A), ext_rep_proto3_message = list(MessageProto3K(1)), - oneof_proto3_enum = EnumProto3K.A + oneof_proto3_enum = EnumProto3K.A, ) private val interopWireJ = InteropMessageJ.Builder() diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto3WireProtocCompatibilityTests.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto3WireProtocCompatibilityTests.kt index dbe9f10e39..6aca5ddf4a 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto3WireProtocCompatibilityTests.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/Proto3WireProtocCompatibilityTests.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,29 +27,17 @@ import com.google.protobuf.Timestamp import com.google.protobuf.Value import com.google.protobuf.util.JsonFormat import com.squareup.wire.json.assertJsonEquals +import com.squareup.wire.proto3.kotlin.requiredextension.RequiredExtension as RequiredExtensionK +import com.squareup.wire.proto3.kotlin.requiredextension.RequiredExtensionMessage as RequiredExtensionMessageK +import java.io.File import okio.ByteString import okio.buffer import okio.source import org.assertj.core.api.Assertions.assertThat import org.junit.Assert.fail import org.junit.Test -import squareup.proto2.kotlin.interop.type.InteropTypes.MessageProto2 -import squareup.proto3.kotlin.MapTypesOuterClass -import squareup.proto3.kotlin.alltypes.All32OuterClass -import squareup.proto3.kotlin.alltypes.All64OuterClass -import squareup.proto3.kotlin.alltypes.AllTypesOuterClass -import squareup.proto3.kotlin.alltypes.AllWrappersOuterClass -import squareup.proto3.kotlin.alltypes.CamelCaseOuterClass -import squareup.proto3.kotlin.extensions.WireMessageOuterClass -import squareup.proto3.kotlin.interop.InteropMessageOuterClass -import squareup.proto3.kotlin.interop.type.InteropTypes.EnumProto3 -import squareup.proto3.kotlin.interop.type.InteropTypes.MessageProto3 -import squareup.proto3.kotlin.pizza.PizzaOuterClass -import squareup.proto3.wire.extensions.WireMessage -import java.io.File -import com.squareup.wire.proto3.kotlin.requiredextension.RequiredExtension as RequiredExtensionK -import com.squareup.wire.proto3.kotlin.requiredextension.RequiredExtensionMessage as RequiredExtensionMessageK import squareup.proto2.java.interop.type.MessageProto2 as MessageProto2J +import squareup.proto2.kotlin.interop.type.InteropTypes.MessageProto2 import squareup.proto2.kotlin.interop.type.MessageProto2 as MessageProto2K import squareup.proto3.java.alltypes.AllTypes as AllTypesJ import squareup.proto3.java.alltypes.AllWrappers as AllWrappersJ @@ -57,12 +45,24 @@ import squareup.proto3.java.interop.InteropMessage as InteropMessageJ import squareup.proto3.java.interop.type.EnumProto3 as EnumProto3J import squareup.proto3.java.interop.type.MessageProto3 as MessageProto3J import squareup.proto3.kotlin.MapTypes as MapTypesK +import squareup.proto3.kotlin.MapTypesOuterClass +import squareup.proto3.kotlin.alltypes.All32OuterClass +import squareup.proto3.kotlin.alltypes.All64OuterClass import squareup.proto3.kotlin.alltypes.AllTypes as AllTypesK +import squareup.proto3.kotlin.alltypes.AllTypesOuterClass import squareup.proto3.kotlin.alltypes.AllWrappers as AllWrappersK +import squareup.proto3.kotlin.alltypes.AllWrappersOuterClass +import squareup.proto3.kotlin.alltypes.CamelCaseOuterClass +import squareup.proto3.kotlin.extensions.WireMessageOuterClass import squareup.proto3.kotlin.interop.InteropMessage as InteropMessageK +import squareup.proto3.kotlin.interop.InteropMessageOuterClass import squareup.proto3.kotlin.interop.type.EnumProto3 as EnumProto3K +import squareup.proto3.kotlin.interop.type.InteropTypes.EnumProto3 +import squareup.proto3.kotlin.interop.type.InteropTypes.MessageProto3 import squareup.proto3.kotlin.interop.type.MessageProto3 as MessageProto3K import squareup.proto3.kotlin.pizza.PizzaDelivery as PizzaDeliveryK +import squareup.proto3.kotlin.pizza.PizzaOuterClass +import squareup.proto3.wire.extensions.WireMessage class Proto3WireProtocCompatibilityTests { // Note: this test mostly make sure we compile required extension without failing. @@ -88,26 +88,26 @@ class Proto3WireProtocCompatibilityTests { Duration.newBuilder() .setSeconds(1_799) .setNanos(500_000_000) - .build() + .build(), ) .addPizzas( PizzaOuterClass.Pizza.newBuilder() .addToppings("pineapple") .addToppings("onion") - .build() + .build(), ) .setPromotion( Any.pack( PizzaOuterClass.BuyOneGetOnePromotion.newBuilder() .setCoupon("MAUI") - .build() - ) + .build(), + ), ) .setOrderedAt( Timestamp.newBuilder() .setSeconds(-631152000L) // 1950-01-01T00:00:00.250Z. .setNanos(250_000_000) - .build() + .build(), ) .setLoyalty(emptyMap().toStruct()) .build() @@ -120,7 +120,7 @@ class Proto3WireProtocCompatibilityTests { // The shared proto schema don't have the same package. val json = PIZZA_DELIVERY_JSON.replace( "type.googleapis.com/squareup.proto3.BuyOneGetOnePromotion", - "type.googleapis.com/squareup.proto3.kotlin.pizza.BuyOneGetOnePromotion" + "type.googleapis.com/squareup.proto3.kotlin.pizza.BuyOneGetOnePromotion", ) val jsonPrinter = JsonFormat.printer() @@ -191,7 +191,7 @@ class Proto3WireProtocCompatibilityTests { val jsonPrinter = JsonFormat.printer() assertJsonEquals( EXPLICIT_IDENTITY_ALL_TYPES_JSON, - jsonPrinter.print(explicitIdentityAllTypesProtoc) + jsonPrinter.print(explicitIdentityAllTypesProtoc), ) } @@ -305,12 +305,12 @@ class Proto3WireProtocCompatibilityTests { Duration.newBuilder() .setSeconds(1_799) .setNanos(500_000_000) - .build() + .build(), ) .build() val wireMessage = PizzaDeliveryK( - delivered_within_or_free = durationOfSeconds(1_799L, 500_000_000L) + delivered_within_or_free = durationOfSeconds(1_799L, 500_000_000L), ) val googleMessageBytes = googleMessage.toByteArray() @@ -324,12 +324,12 @@ class Proto3WireProtocCompatibilityTests { Timestamp.newBuilder() .setSeconds(-631152000000L) // 1950-01-01T00:00:00.250Z. .setNanos(250_000_000) - .build() + .build(), ) .build() val wireMessage = PizzaDeliveryK( - ordered_at = ofEpochSecond(-631152000000L, 250_000_000L) + ordered_at = ofEpochSecond(-631152000000L, 250_000_000L), ) val googleMessageBytes = googleMessage.toByteArray() @@ -348,16 +348,16 @@ class Proto3WireProtocCompatibilityTests { ListValue.newBuilder() .addValues(Value.newBuilder().setStringValue("Benoît").build()) .addValues(Value.newBuilder().setStringValue("Jesse").build()) - .build() + .build(), ) - .build() + .build(), ) - .build() + .build(), ) .build() val wireMessage = PizzaDeliveryK( - loyalty = mapOf("stamps" to 5.0, "members" to listOf("Benoît", "Jesse")) + loyalty = mapOf("stamps" to 5.0, "members" to listOf("Benoît", "Jesse")), ) val googleMessageBytes = googleMessage.toByteArray() @@ -470,62 +470,62 @@ class Proto3WireProtocCompatibilityTests { .putAllMapInt32Int32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .putAllMapSint32Sint32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .putAllMapSfixed32Sfixed32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .putAllMapFixed32Fixed32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .putAllMapUint32Uint32( mapOf( Int.MIN_VALUE to Int.MIN_VALUE + 1, - Int.MAX_VALUE to Int.MAX_VALUE - 1 - ) + Int.MAX_VALUE to Int.MAX_VALUE - 1, + ), ) .putAllMapInt64Int64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .putAllMapSfixed64Sfixed64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .putAllMapSint64Sint64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .putAllMapFixed64Fixed64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .putAllMapUint64Uint64( mapOf( Long.MIN_VALUE to Long.MIN_VALUE + 1L, - Long.MAX_VALUE to Long.MAX_VALUE - 1L - ) + Long.MAX_VALUE to Long.MAX_VALUE - 1L, + ), ) .build() @@ -688,13 +688,13 @@ class Proto3WireProtocCompatibilityTests { .addAllRepDouble(list(123.0)) .addAllRepString(list("124")) .addAllRepBytes( - list(com.google.protobuf.ByteString.copyFrom(ByteString.of(123, 125).toByteArray())) + list(com.google.protobuf.ByteString.copyFrom(ByteString.of(123, 125).toByteArray())), ) .addAllRepNestedEnum(list(AllTypesOuterClass.AllTypes.NestedEnum.A)) .addAllRepNestedMessage( list( - AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build() - ) + AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(999).build(), + ), ) .addAllPackInt32(list(111)) .addAllPackUint32(list(112)) @@ -714,7 +714,7 @@ class Proto3WireProtocCompatibilityTests { .putMapStringString("key", "value") .putMapStringMessage( "message", - AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(1).build() + AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().setA(1).build(), ) .putMapStringEnum("enum", AllTypesOuterClass.AllTypes.NestedEnum.A) .setOneofInt32(0) @@ -788,7 +788,7 @@ class Proto3WireProtocCompatibilityTests { map_string_string = mapOf("key" to "value"), map_string_message = mapOf("message" to AllTypesK.NestedMessage(1)), map_string_enum = mapOf("enum" to AllTypesK.NestedEnum.A), - oneof_int32 = 0 + oneof_int32 = 0, ) private val defaultAllTypesWireJava = AllTypesJ.Builder() @@ -919,7 +919,7 @@ class Proto3WireProtocCompatibilityTests { map_int32_uint32_value = mapOf(23 to -1), map_int32_bool_value = mapOf(23 to true), map_int32_string_value = mapOf(23 to "Bo knows wrappers"), - map_int32_bytes_value = mapOf(23 to ByteString.of(123, 125)) + map_int32_bytes_value = mapOf(23 to ByteString.of(123, 125)), ) private val defaultAllWrappersWireJava = AllWrappersJ.Builder() @@ -1028,7 +1028,7 @@ class Proto3WireProtocCompatibilityTests { map_int32_int32 = mapOf(0 to 0), map_string_message = mapOf("" to AllTypesK.NestedMessage()), map_string_enum = mapOf("" to AllTypesK.NestedEnum.UNKNOWN), - oneof_int32 = 0 + oneof_int32 = 0, ) private val explicitIdentityAllTypesWireJava = AllTypesJ.Builder() @@ -1119,7 +1119,7 @@ class Proto3WireProtocCompatibilityTests { .addAllRepDouble(emptyList()) .addAllRepString(list("")) .addAllRepBytes( - list(com.google.protobuf.ByteString.copyFrom(ByteString.EMPTY.toByteArray())) + list(com.google.protobuf.ByteString.copyFrom(ByteString.EMPTY.toByteArray())), ) .addAllRepNestedEnum(emptyList()) .addAllRepNestedMessage(emptyList()) @@ -1138,8 +1138,8 @@ class Proto3WireProtocCompatibilityTests { .addAllPackDouble(list(0.0)) .addAllPackNestedEnum( list( - AllTypesOuterClass.AllTypes.NestedEnum.UNKNOWN - ) + AllTypesOuterClass.AllTypes.NestedEnum.UNKNOWN, + ), ) .putMapInt32Int32(0, 0) .putMapStringMessage("", AllTypesOuterClass.AllTypes.NestedMessage.newBuilder().build()) @@ -1172,7 +1172,7 @@ class Proto3WireProtocCompatibilityTests { map_string_proto2_message = mapOf("one" to MessageProto2K(23, "MJ")), map_string_proto3_enum = mapOf("two" to EnumProto3K.A), map_string_proto3_message = mapOf("three" to MessageProto3K(b = "three")), - oneof_proto3_message = MessageProto3K() + oneof_proto3_message = MessageProto3K(), ) private val interopWireJ = InteropMessageJ.Builder() diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocStructHelper.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocStructHelper.kt index f2d8c754ed..dfb13e18d3 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocStructHelper.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocStructHelper.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocWrappersHelper.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocWrappersHelper.kt index 93cbdf3f4a..2e423d017d 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocWrappersHelper.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/ProtocWrappersHelper.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/SchemaEncoderInteropTest.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/SchemaEncoderInteropTest.kt index 22da96e9a4..1f1de1c488 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/SchemaEncoderInteropTest.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/SchemaEncoderInteropTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,42 +46,42 @@ class SchemaEncoderInteropTest { @Test fun `proto2 interop_test`() { checkFileSchemasMatch( wireProtoFile = schema.protoFile("squareup/proto2/kotlin/interop/interop_test.proto")!!, - protocProtoFile = InteropTestP2.getDescriptor().toProto() + protocProtoFile = InteropTestP2.getDescriptor().toProto(), ) } @Test fun `proto3 interop_types`() { checkFileSchemasMatch( wireProtoFile = schema.protoFile("squareup/proto3/kotlin/interop/type/interop_types.proto")!!, - protocProtoFile = InteropTypesP2.getDescriptor().toProto() + protocProtoFile = InteropTypesP2.getDescriptor().toProto(), ) } @Test fun `proto2 interop_service`() { checkFileSchemasMatch( wireProtoFile = schema.protoFile("squareup/proto2/kotlin/interop/interop_service.proto")!!, - protocProtoFile = InteropServiceOuterClassP2.getDescriptor().toProto() + protocProtoFile = InteropServiceOuterClassP2.getDescriptor().toProto(), ) } @Test fun `proto2 all_types`() { checkFileSchemasMatch( wireProtoFile = schema.protoFile("squareup/proto2/kotlin/alltypes/all_types.proto")!!, - protocProtoFile = AllTypesOuterClassP2.getDescriptor().toProto() + protocProtoFile = AllTypesOuterClassP2.getDescriptor().toProto(), ) } @Test fun `proto3 all_types`() { checkFileSchemasMatch( wireProtoFile = schema.protoFile("squareup/proto3/kotlin/alltypes/all_types_test_proto3_optional.proto")!!, - protocProtoFile = AllTypesOuterClassP3.getDescriptor().toProto() + protocProtoFile = AllTypesOuterClassP3.getDescriptor().toProto(), ) } @Test fun `proto2 all_options`() { checkFileSchemaOptionsMatch( wireProtoFile = schema.protoFile("squareup/proto2/kotlin/alloptions/all_options.proto")!!, - protocProtoFile = AllOptionsP2.getDescriptor().toProto() + protocProtoFile = AllOptionsP2.getDescriptor().toProto(), ) } @@ -91,7 +91,7 @@ class SchemaEncoderInteropTest { */ private fun checkFileSchemasMatch( wireProtoFile: ProtoFile, - protocProtoFile: FileDescriptorProto + protocProtoFile: FileDescriptorProto, ) { val wireBytes = SchemaEncoder(schema).encode(wireProtoFile) val wireDescriptor = FileDescriptorProto.parseFrom(wireBytes.toByteArray(), extensionRegistry) @@ -107,7 +107,7 @@ class SchemaEncoderInteropTest { */ private fun checkFileSchemaOptionsMatch( wireProtoFile: ProtoFile, - protocProtoFile: FileDescriptorProto + protocProtoFile: FileDescriptorProto, ) { val wireBytes = SchemaEncoder(schema).encode(wireProtoFile) val wireDescriptor = FileDescriptorProto.parseFrom(wireBytes.toByteArray(), extensionRegistry) diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/StructTest.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/StructTest.kt index 2e593860e4..37413f71b8 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/StructTest.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/StructTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,9 +21,9 @@ import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.entry import org.junit.Assert.fail import org.junit.Test -import squareup.proto3.kotlin.alltypes.AllStructsOuterClass import squareup.proto3.java.alltypes.AllStructs as AllStructsJ import squareup.proto3.kotlin.alltypes.AllStructs as AllStructsK +import squareup.proto3.kotlin.alltypes.AllStructsOuterClass class StructTest { @Test fun nullValue() { @@ -52,7 +52,7 @@ class StructTest { -0.0, 0.0, Double.POSITIVE_INFINITY, - Double.NaN + Double.NaN, ).toListValue() val wireMessage = listOf( @@ -60,7 +60,7 @@ class StructTest { -0.0, 0.0, Double.POSITIVE_INFINITY, - Double.NaN + Double.NaN, ) val googleMessageBytes = googleMessage.toByteArray() @@ -135,7 +135,7 @@ class StructTest { "c" to true, "d" to "cash", "e" to listOf("g", "h"), - "f" to mapOf("i" to "j", "k" to "l") + "f" to mapOf("i" to "j", "k" to "l"), ).toStruct() val wireMessage = mapOf( @@ -144,7 +144,7 @@ class StructTest { "c" to true, "d" to "cash", "e" to listOf("g", "h"), - "f" to mapOf("i" to "j", "k" to "l") + "f" to mapOf("i" to "j", "k" to "l"), ) val googleMessageBytes = googleMessage.toByteArray() @@ -224,7 +224,7 @@ class StructTest { true, "cash", listOf("a", "b"), - mapOf("c" to "d", "e" to "f") + mapOf("c" to "d", "e" to "f"), ).toListValue() val wireMessage = listOf( @@ -233,7 +233,7 @@ class StructTest { true, "cash", listOf("a", "b"), - mapOf("c" to "d", "e" to "f") + mapOf("c" to "d", "e" to "f"), ) val googleMessageBytes = googleMessage.toByteArray() @@ -296,7 +296,7 @@ class StructTest { .build() val wireAllStructKotlin = AllStructsK( struct = emptyMap(), - list = emptyList() + list = emptyList(), ) val protocAllStructBytes = protocAllStruct.toByteArray() @@ -336,7 +336,7 @@ class StructTest { value_b = 33.0, value_c = true, value_e = mapOf("a" to 1.0), - value_f = listOf("a", 3.0) + value_f = listOf("a", 3.0), ) val protocAllStructBytes = protocAllStruct.toByteArray() @@ -388,7 +388,7 @@ class StructTest { "c" to "j", "d" to 5.0, "e" to false, - "f" to null + "f" to null, ) val allStructs = AllStructsJ.Builder() @@ -407,7 +407,7 @@ class StructTest { entry("c", "j"), entry("d", 5.0), entry("e", false), - entry("f", null) + entry("f", null), ) } @@ -418,7 +418,7 @@ class StructTest { "c" to "j", "d" to 5.0, "e" to false, - "f" to null + "f" to null, ) val allStructs = AllStructsK.Builder() @@ -437,7 +437,7 @@ class StructTest { entry("c", "j"), entry("d", 5.0), entry("e", false), - entry("f", null) + entry("f", null), ) } @@ -449,7 +449,7 @@ class StructTest { } catch (e: IllegalArgumentException) { assertThat(e).hasMessage( "struct value struct must be a JSON type " + - "(null, Boolean, Double, String, List, or Map) but was class kotlin.Int: 1" + "(null, Boolean, Double, String, List, or Map) but was class kotlin.Int: 1", ) } } diff --git a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/UnwantedValueStripper.kt b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/UnwantedValueStripper.kt index 757b3f94c4..ed21574ef5 100644 --- a/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/UnwantedValueStripper.kt +++ b/wire-protoc-compatibility-tests/src/test/java/com/squareup/wire/UnwantedValueStripper.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,7 @@ import com.google.protobuf.DescriptorProtos.FieldDescriptorProto import com.google.protobuf.DescriptorProtos.FileDescriptorProto class UnwantedValueStripper( - val clearJsonName: Boolean = false + val clearJsonName: Boolean = false, ) { /** diff --git a/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/SchemaBuilder.kt b/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/SchemaBuilder.kt index 28d9cf9a68..8114c5126e 100644 --- a/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/SchemaBuilder.kt +++ b/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/SchemaBuilder.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/WireTestLogger.kt b/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/WireTestLogger.kt index 7e619679b2..e30dd60f74 100644 --- a/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/WireTestLogger.kt +++ b/wire-schema-tests/src/commonMain/kotlin/com/squareup/wire/WireTestLogger.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt deleted file mode 100644 index b1e145495d..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire - -import com.squareup.wire.schema.Location -import com.squareup.wire.schema.SchemaException -import okio.Path.Companion.toPath -import org.assertj.core.api.Assertions.assertThat -import kotlin.test.Test -import kotlin.test.assertFailsWith - -class SchemaBuilderTest { - @Test fun emptySchema() { - val exception = assertFailsWith { - buildSchema {} - } - assertThat(exception.message).isEqualTo("no sources") - } - - @Test fun sourcePathOnly() { - val schema = buildSchema { - add( - "example1.proto".toPath(), - """ - |syntax = "proto2"; - | - |message A { - | optional B b = 1; - |} - |message B { - | optional C c = 1; - |} - |message C { - |} - |""".trimMargin() - ) - add( - "example2.proto".toPath(), - """ - |syntax = "proto2"; - | - |message D { - |} - |""".trimMargin() - ) - } - assertThat(schema.protoFiles.map { it.location }).containsExactlyInAnyOrder( - Location.get("/sourcePath", "example1.proto"), - Location.get("/sourcePath", "example2.proto"), - Location.get("google/protobuf/descriptor.proto"), - Location.get("wire/extensions.proto"), - ) - } -} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt deleted file mode 100644 index b9d4ef6315..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire.recipes - -import com.squareup.wire.schema.Extend -import com.squareup.wire.schema.Field -import com.squareup.wire.schema.MessageType -import com.squareup.wire.schema.SchemaHandler -import com.squareup.wire.schema.Service -import com.squareup.wire.schema.Type -import okio.Path - -/** Sample schema validator that enforces a field naming pattern. */ -class ErrorReportingSchemaHandler : SchemaHandler() { - override fun handle(type: Type, context: SchemaHandler.Context): Path? { - val errorCollector = context.errorCollector - - if ("descriptor.proto" in type.location.path) return null // Don't report errors on built-in stuff. - if (type is MessageType) { - for (field in type.fields) { - if (field.name.startsWith("a")) { - errorCollector.at(field) += "field starts with 'a'" - } - } - } - return null - } - - override fun handle(service: Service, context: SchemaHandler.Context): List = emptyList() - - override fun handle(extend: Extend, field: Field, context: SchemaHandler.Context): Path? = null -} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt deleted file mode 100644 index 831789977b..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire.recipes - -import com.squareup.wire.WireTestLogger -import com.squareup.wire.buildSchema -import com.squareup.wire.schema.ErrorCollector -import com.squareup.wire.schema.SchemaException -import com.squareup.wire.schema.SchemaHandler -import okio.Path.Companion.toPath -import okio.fakefilesystem.FakeFileSystem -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test -import kotlin.test.assertFailsWith - -class ErrorReportingSchemaHandlerTest { - @Test fun errorsWhenStartsWithA() { - val schema = buildSchema { - add( - name = "a.proto".toPath(), - protoFile = """ - |syntax = "proto2"; - | - |message A { - | optional string acrobatic = 1; - | optional string biofidus = 2; - |} - """.trimMargin() - ) - add( - name = "b.proto".toPath(), - protoFile = """ - |syntax = "proto2"; - | - |message B { - | optional string comment = 1; - | optional string dinosaur = 2; - |} - """.trimMargin() - ) - } - - val errorCollector = ErrorCollector() - val context = SchemaHandler.Context( - fileSystem = FakeFileSystem(), - outDirectory = "out".toPath(), - logger = WireTestLogger(), - errorCollector = errorCollector, - ) - - ErrorReportingSchemaHandler().handle(schema, context) - val exception = assertFailsWith { - errorCollector.throwIfNonEmpty() - } - - assertThat(exception.message).startsWith("field starts with 'a'") - } -} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt deleted file mode 100644 index e2601b239f..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire.recipes - -import com.squareup.wire.schema.Extend -import com.squareup.wire.schema.Field -import com.squareup.wire.schema.SchemaHandler -import com.squareup.wire.schema.Service -import com.squareup.wire.schema.Type -import okio.Path -import okio.Path.Companion.toPath -import okio.buffer - -/** Sample schema handler which writes to disk generated artifacts. */ -class LogToFileHandler : SchemaHandler() { - private val filePath = "log.txt".toPath() - - override fun handle(type: Type, context: SchemaHandler.Context): Path? { - context.fileSystem.appendingSink(filePath).buffer().use { - it.writeUtf8("Generating type: ${type.type}\n") - } - - return null - } - - override fun handle(service: Service, context: SchemaHandler.Context): List { - context.fileSystem.appendingSink(filePath).buffer().use { - it.writeUtf8("Generating service: ${service.type}\n") - } - - return listOf() - } - - override fun handle(extend: Extend, field: Field, context: SchemaHandler.Context): Path? { - context.fileSystem.appendingSink(filePath).buffer().use { - it.writeUtf8("Generating ${extend.type} on ${field.location}\n") - } - - return null - } -} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt deleted file mode 100644 index 21a3c2de18..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire.recipes - -import com.squareup.wire.WireTestLogger -import com.squareup.wire.buildSchema -import com.squareup.wire.schema.SchemaHandler -import okio.BufferedSource -import okio.Path.Companion.toPath -import okio.fakefilesystem.FakeFileSystem -import org.junit.Test -import kotlin.test.assertEquals - -class LogToFileHandlerTest { - @Test fun loggingTypes() { - val schema = buildSchema { - add( - name = "test/message.proto".toPath(), - protoFile = """ - |syntax = "proto2"; - | - |package test; - | - |message Request {} - |message Response { - | optional string result = 1; - |} - """.trimMargin() - ) - add( - name = "test/service.proto".toPath(), - protoFile = """ - |syntax = "proto2"; - | - |package test; - | - |import "test/message.proto"; - | - |service MyService { - | rpc fetch(test.Request) returns(test.Response) {}; - |} - """.trimMargin() - ) - } - - val context = SchemaHandler.Context( - fileSystem = FakeFileSystem(), - outDirectory = "/".toPath(), - logger = WireTestLogger(), - sourcePathPaths = setOf("test/message.proto", "test/service.proto"), - ) - LogToFileHandler().handle(schema, context) - - val content = context.fileSystem.read("log.txt".toPath(), BufferedSource::readUtf8) - val expected = """ - |Generating type: test.Request - |Generating type: test.Response - |Generating service: test.MyService - |""".trimMargin() - assertEquals(expected, content) - } -} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt deleted file mode 100644 index ef660abe0a..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire.recipes - -import com.squareup.wire.schema.Extend -import com.squareup.wire.schema.Field -import com.squareup.wire.schema.SchemaHandler -import com.squareup.wire.schema.Service -import com.squareup.wire.schema.Type -import okio.Path - -/** Sample schema handler which logs handled types and services. */ -class LogToWireLoggerHandler : SchemaHandler() { - override fun handle(type: Type, context: SchemaHandler.Context): Path? { - context.logger.artifactHandled( - context.outDirectory, type.type.enclosingTypeOrPackage ?: "", type.type.simpleName - ) - - return null - } - - override fun handle(service: Service, context: SchemaHandler.Context): List { - context.logger.artifactHandled( - context.outDirectory, service.type.enclosingTypeOrPackage ?: "", service.type.simpleName - ) - - return listOf() - } - - override fun handle(extend: Extend, field: Field, context: SchemaHandler.Context): Path? { - return null - } -} diff --git a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt b/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt deleted file mode 100644 index 0bbaea5292..0000000000 --- a/wire-schema-tests/src/commonTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2022 Block Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -@file:Suppress("UsePropertyAccessSyntax") - -package com.squareup.wire.recipes - -import com.squareup.wire.WireTestLogger -import com.squareup.wire.buildSchema -import com.squareup.wire.schema.SchemaHandler -import okio.Path.Companion.toPath -import okio.fakefilesystem.FakeFileSystem -import org.assertj.core.api.Assertions.assertThat -import org.junit.Test - -class LogToWireLoggerHandlerTest { - @Test fun loggingArtifacts() { - val schema = buildSchema { - add( - name = "test/message.proto".toPath(), - protoFile = """ - |syntax = "proto2"; - | - |package test; - | - |message Request {} - |message Response { - | optional string result = 1; - |} - """.trimMargin() - ) - add( - name = "test/service.proto".toPath(), - protoFile = """ - |syntax = "proto2"; - | - |package test; - | - |import "test/message.proto"; - | - |service MyService { - | rpc fetch(test.Request) returns(test.Response) {}; - |} - """.trimMargin() - ) - } - val logger = WireTestLogger() - val context = SchemaHandler.Context( - fileSystem = FakeFileSystem(), - outDirectory = "out".toPath(), - logger = logger, - sourcePathPaths = setOf("test/message.proto", "test/service.proto"), - ) - LogToWireLoggerHandler().handle(schema, context) - - assertThat(logger.artifactHandled.removeFirst()).isEqualTo(Triple("out".toPath(), "test", "Request")) - assertThat(logger.artifactHandled.removeFirst()).isEqualTo(Triple("out".toPath(), "test", "Response")) - assertThat(logger.artifactHandled.removeFirst()).isEqualTo(Triple("out".toPath(), "test", "MyService")) - assertThat(logger.artifactHandled.isEmpty()).isTrue() - } -} diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt index b1e145495d..08f7acc1cd 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/SchemaBuilderTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,10 +17,10 @@ package com.squareup.wire import com.squareup.wire.schema.Location import com.squareup.wire.schema.SchemaException -import okio.Path.Companion.toPath -import org.assertj.core.api.Assertions.assertThat import kotlin.test.Test import kotlin.test.assertFailsWith +import okio.Path.Companion.toPath +import org.assertj.core.api.Assertions.assertThat class SchemaBuilderTest { @Test fun emptySchema() { @@ -45,7 +45,8 @@ class SchemaBuilderTest { |} |message C { |} - |""".trimMargin() + | + """.trimMargin(), ) add( "example2.proto".toPath(), @@ -54,7 +55,8 @@ class SchemaBuilderTest { | |message D { |} - |""".trimMargin() + | + """.trimMargin(), ) } assertThat(schema.protoFiles.map { it.location }).containsExactlyInAnyOrder( diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt index b9d4ef6315..75985fca47 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandler.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt index 831789977b..e1fed515a2 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/ErrorReportingSchemaHandlerTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,11 +20,11 @@ import com.squareup.wire.buildSchema import com.squareup.wire.schema.ErrorCollector import com.squareup.wire.schema.SchemaException import com.squareup.wire.schema.SchemaHandler +import kotlin.test.assertFailsWith import okio.Path.Companion.toPath import okio.fakefilesystem.FakeFileSystem import org.assertj.core.api.Assertions.assertThat import org.junit.Test -import kotlin.test.assertFailsWith class ErrorReportingSchemaHandlerTest { @Test fun errorsWhenStartsWithA() { @@ -38,7 +38,7 @@ class ErrorReportingSchemaHandlerTest { | optional string acrobatic = 1; | optional string biofidus = 2; |} - """.trimMargin() + """.trimMargin(), ) add( name = "b.proto".toPath(), @@ -49,7 +49,7 @@ class ErrorReportingSchemaHandlerTest { | optional string comment = 1; | optional string dinosaur = 2; |} - """.trimMargin() + """.trimMargin(), ) } diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt index e2601b239f..099016c0ac 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandler.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt index 21a3c2de18..5f79546041 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToFileHandlerTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package com.squareup.wire.recipes import com.squareup.wire.WireTestLogger import com.squareup.wire.buildSchema import com.squareup.wire.schema.SchemaHandler +import kotlin.test.assertEquals import okio.BufferedSource import okio.Path.Companion.toPath import okio.fakefilesystem.FakeFileSystem import org.junit.Test -import kotlin.test.assertEquals class LogToFileHandlerTest { @Test fun loggingTypes() { @@ -38,7 +38,7 @@ class LogToFileHandlerTest { |message Response { | optional string result = 1; |} - """.trimMargin() + """.trimMargin(), ) add( name = "test/service.proto".toPath(), @@ -52,7 +52,7 @@ class LogToFileHandlerTest { |service MyService { | rpc fetch(test.Request) returns(test.Response) {}; |} - """.trimMargin() + """.trimMargin(), ) } @@ -69,7 +69,8 @@ class LogToFileHandlerTest { |Generating type: test.Request |Generating type: test.Response |Generating service: test.MyService - |""".trimMargin() + | + """.trimMargin() assertEquals(expected, content) } } diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt index ef660abe0a..6eb424bd0a 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandler.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,7 +26,9 @@ import okio.Path class LogToWireLoggerHandler : SchemaHandler() { override fun handle(type: Type, context: SchemaHandler.Context): Path? { context.logger.artifactHandled( - context.outDirectory, type.type.enclosingTypeOrPackage ?: "", type.type.simpleName + context.outDirectory, + type.type.enclosingTypeOrPackage ?: "", + type.type.simpleName, ) return null @@ -34,7 +36,9 @@ class LogToWireLoggerHandler : SchemaHandler() { override fun handle(service: Service, context: SchemaHandler.Context): List { context.logger.artifactHandled( - context.outDirectory, service.type.enclosingTypeOrPackage ?: "", service.type.simpleName + context.outDirectory, + service.type.enclosingTypeOrPackage ?: "", + service.type.simpleName, ) return listOf() diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt index 0bbaea5292..e66251c331 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/LogToWireLoggerHandlerTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -39,7 +39,7 @@ class LogToWireLoggerHandlerTest { |message Response { | optional string result = 1; |} - """.trimMargin() + """.trimMargin(), ) add( name = "test/service.proto".toPath(), @@ -53,7 +53,7 @@ class LogToWireLoggerHandlerTest { |service MyService { | rpc fetch(test.Request) returns(test.Response) {}; |} - """.trimMargin() + """.trimMargin(), ) } val logger = WireTestLogger() diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandler.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandler.kt index c82b2a50d6..09656227e1 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandler.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandler.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -40,7 +40,7 @@ class MarkdownHandler : SchemaHandler() { private fun writeMarkdownFile( protoType: ProtoType, markdown: String, - context: SchemaHandler.Context + context: SchemaHandler.Context, ): Path { val path = context.outDirectory / toPath(protoType).joinToString(separator = "/") context.fileSystem.createDirectories(path.parent!!) @@ -65,7 +65,8 @@ class MarkdownHandler : SchemaHandler() { |# ${type.type.simpleName} | |${type.documentation} - |""".trimMargin() + | + """.trimMargin() } private fun toMarkdown(service: Service): String { @@ -73,6 +74,7 @@ class MarkdownHandler : SchemaHandler() { |# ${service.type.simpleName} | |${service.documentation} - |""".trimMargin() + | + """.trimMargin() } } diff --git a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandlerTest.kt b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandlerTest.kt index cdc9d9ab0f..219dc8d94e 100644 --- a/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandlerTest.kt +++ b/wire-schema-tests/src/jvmTest/kotlin/com/squareup/wire/recipes/MarkdownHandlerTest.kt @@ -1,11 +1,11 @@ /* - * Copyright 2022 Block Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -38,7 +38,7 @@ class MarkdownHandlerTest { |message Red { | optional string oval = 1; |} - """.trimMargin() + """.trimMargin(), ) add( name = "squareup/colors/blue.proto".toPath(), @@ -51,7 +51,7 @@ class MarkdownHandlerTest { | optional string circle = 1; | optional squareup.polygons.Triangle triangle = 2; |} - """.trimMargin() + """.trimMargin(), ) add( name = "squareup/polygons/triangle.proto".toPath(), @@ -66,7 +66,7 @@ class MarkdownHandlerTest { | RIGHTANGLED = 3; | } |} - """.trimMargin() + """.trimMargin(), ) } @@ -82,7 +82,7 @@ class MarkdownHandlerTest { assertThat(fileSystem.findFiles("generated")) .containsRelativePaths( "generated/markdown/squareup/colors/Blue.md", - "generated/markdown/squareup/colors/Red.md" + "generated/markdown/squareup/colors/Red.md", ) assertThat(fileSystem.readUtf8("generated/markdown/squareup/colors/Blue.md")) .isEqualTo( @@ -90,7 +90,8 @@ class MarkdownHandlerTest { |# Blue | |This is the color of the sky. - |""".trimMargin() + | + """.trimMargin(), ) assertThat(fileSystem.readUtf8("generated/markdown/squareup/colors/Red.md")) .isEqualTo( @@ -98,7 +99,8 @@ class MarkdownHandlerTest { |# Red | |This is the color of the sky when the sky is lava. - |""".trimMargin() + | + """.trimMargin(), ) } } diff --git a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt index bfa09d2e22..c9921e65ab 100644 --- a/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt +++ b/wire-schema/src/jvmTest/kotlin/com/squareup/wire/schema/internal/parser/MessageElementTest.kt @@ -352,7 +352,7 @@ class MessageElementTest { |message Message { | oneof hi { | string name = 1; - | + | | group Stuff = 3 { | optional int32 result_per_page = 4; | optional int32 page_count = 5; diff --git a/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt b/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt index 1de24252e1..eec9834423 100644 --- a/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt +++ b/wire-swift-generator/src/main/java/com/squareup/wire/swift/SwiftGenerator.kt @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2023 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.swift import com.squareup.wire.Syntax.PROTO_2 @@ -29,7 +44,6 @@ import io.outfoxx.swiftpoet.FileMemberSpec import io.outfoxx.swiftpoet.FileSpec import io.outfoxx.swiftpoet.FunctionSignatureSpec import io.outfoxx.swiftpoet.FunctionSpec -import io.outfoxx.swiftpoet.INT import io.outfoxx.swiftpoet.INT32 import io.outfoxx.swiftpoet.INT64 import io.outfoxx.swiftpoet.Modifier.FILEPRIVATE @@ -55,7 +69,7 @@ import java.util.Locale.US class SwiftGenerator private constructor( val schema: Schema, private val nameToTypeName: Map, - private val referenceCycleIndirections: Map> + private val referenceCycleIndirections: Map>, ) { private val proto2Codable = DeclaredTypeName.typeName("Wire.Proto2Codable") private val proto3Codable = DeclaredTypeName.typeName("Wire.Proto3Codable") @@ -157,7 +171,8 @@ class SwiftGenerator private constructor( get() = when (encodeMode!!) { EncodeMode.MAP -> DICTIONARY.parameterizedBy(keyType.typeName, valueType.typeName) EncodeMode.REPEATED, - EncodeMode.PACKED -> ARRAY.parameterizedBy(type!!.typeName) + EncodeMode.PACKED, + -> ARRAY.parameterizedBy(type!!.typeName) EncodeMode.NULL_IF_ABSENT -> OPTIONAL.parameterizedBy(type!!.typeName) EncodeMode.REQUIRED -> type!!.typeName EncodeMode.OMIT_IDENTITY -> { @@ -222,17 +237,17 @@ class SwiftGenerator private constructor( .fields .mapNotNull { schema.getType(it.type!!) as? EnumType } .forEach { enum -> - // ensure that a 0 case exists - if (enum.constants.filter { it.tag == 0 }.isEmpty()) { - throw NoSuchElementException("Missing a zero value for ${enum.name}") - } + // ensure that a 0 case exists + if (enum.constants.filter { it.tag == 0 }.isEmpty()) { + throw NoSuchElementException("Missing a zero value for ${enum.name}") + } } } @OptIn(ExperimentalStdlibApi::class) // TODO move to build flag private fun generateMessage( type: MessageType, - fileMembers: MutableList + fileMembers: MutableList, ): List { val structType = type.typeName val oneOfEnumNames = type.oneOfs.associateWith { structType.nestedType(it.name.capitalize(US)) } @@ -256,13 +271,13 @@ class SwiftGenerator private constructor( if (type.isHeapAllocated) { addAttribute( - AttributeSpec.builder("dynamicMemberLookup").build() + AttributeSpec.builder("dynamicMemberLookup").build(), ) addProperty( PropertySpec.varBuilder(storageName, storageType, PRIVATE) .addAttribute(AttributeSpec.builder(heap).build()) - .build() + .build(), ) generateMessageStoragePropertyDelegates(type, storageName, storageType) @@ -283,10 +298,10 @@ class SwiftGenerator private constructor( "self.%N = %T(%L)", storageName, storageType, - storageParams.joinToCode(separator = ",%W") + storageParams.joinToCode(separator = ",%W"), ) } - .build() + .build(), ) addFunction( @@ -295,7 +310,7 @@ class SwiftGenerator private constructor( .beginControlFlow("if", "!isKnownUniquelyReferenced(&_%N)", storageName) .addStatement("_%1N = %2T(wrappedValue: %1N)", storageName, heap) .endControlFlow("if") - .build() + .build(), ) } else { generateMessageProperties(type, oneOfEnumNames) @@ -353,7 +368,7 @@ class SwiftGenerator private constructor( } } } - .build() + .build(), ) } else { null @@ -368,7 +383,7 @@ class SwiftGenerator private constructor( generateMessageProperties(type, oneOfEnumNames, forStorageType = true) generateMessageConstructor(type, oneOfEnumNames, includeDefaults = false) } - .build() + .build(), ) .build() fileMembers += FileMemberSpec.builder(storageExtension).build() @@ -381,7 +396,7 @@ class SwiftGenerator private constructor( .addParameter("from", "reader", protoReader) .throws(true) .addStatement("self.%N = try %T(from: reader)", storageName, storageType) - .build() + .build(), ) .addFunction( FunctionSpec.builder("encode") @@ -389,7 +404,7 @@ class SwiftGenerator private constructor( .addParameter("to", "writer", protoWriter) .throws(true) .addStatement("try %N.encode(to: writer)", storageName) - .build() + .build(), ) .build() fileMembers += FileMemberSpec.builder(structProtoCodableExtension).build() @@ -442,9 +457,9 @@ class SwiftGenerator private constructor( .getter( FunctionSpec.getterBuilder() .addStatement("return %N.description", storageName) - .build() + .build(), ) - .build() + .build(), ) val storageRedactableExtension = ExtensionSpec.builder(storageType) @@ -452,7 +467,7 @@ class SwiftGenerator private constructor( .addType( TypeAliasSpec.builder("RedactedKeys", structType.nestedType("RedactedKeys")) .addModifiers(PUBLIC) - .build() + .build(), ) .build() fileMembers += FileMemberSpec.builder(storageRedactableExtension) @@ -490,7 +505,7 @@ class SwiftGenerator private constructor( type: MessageType, structType: DeclaredTypeName, oneOfEnumNames: Map, - propertyNames: Collection + propertyNames: Collection, ): ExtensionSpec.Builder = apply { addSuperType(type.protoCodableType) @@ -507,23 +522,23 @@ class SwiftGenerator private constructor( type.fields.forEach { field -> val localType = when (type.syntax) { PROTO_2 -> if (field.isRepeated || field.isMap) { - field.typeName - } else { - field.typeName.makeOptional() - } + field.typeName + } else { + field.typeName.makeOptional() + } PROTO_3 -> if (field.isOptional || (field.isEnum && !field.isRepeated)) { - field.typeName.makeOptional() - } else { - field.typeName - } + field.typeName.makeOptional() + } else { + field.typeName + } } val initializer = when (type.syntax) { PROTO_2 -> when { - field.isMap -> "[:]" - field.isRepeated -> "[]" - else -> "nil" - } + field.isMap -> "[:]" + field.isRepeated -> "[]" + else -> "nil" + } PROTO_3 -> field.proto3InitialValue } @@ -575,7 +590,7 @@ class SwiftGenerator private constructor( field.tag, oneOf.name, field.name, - field.typeName.makeNonOptional() + field.typeName.makeNonOptional(), ) } else -> { @@ -584,7 +599,7 @@ class SwiftGenerator private constructor( field.tag, oneOf.name, field.name, - field.typeName.makeNonOptional() + field.typeName.makeNonOptional(), ) } } @@ -598,7 +613,7 @@ class SwiftGenerator private constructor( // Check required and bind members. addStatement("") type.fields.forEach { field -> - val initializer = when(type.syntax) { + val initializer = when (type.syntax) { PROTO_2 -> if (field.isOptional || field.isRepeated || field.isMap) { CodeBlock.of("%N", field.name) } else { @@ -616,7 +631,7 @@ class SwiftGenerator private constructor( addStatement("self.%1N = %1N", oneOf.name) } } - .build() + .build(), ) val writer = if ("writer" in propertyNames) "_writer" else "writer" @@ -654,7 +669,7 @@ class SwiftGenerator private constructor( } } .addStatement("try $writer.writeUnknownFields(unknownFields)") - .build() + .build(), ) } @@ -668,7 +683,7 @@ class SwiftGenerator private constructor( .addModifiers(PUBLIC) .addModifiers(STATIC) .addStatement("return \"%N\"", type.type.typeUrl!!) - .build() + .build(), ) } @@ -693,8 +708,8 @@ class SwiftGenerator private constructor( .throws(true) .addStatement("let container = try decoder.singleValueContainer()") .addStatement("self.%N = try container.decode(%T.self)", storageName, storageType) - .build() - ) + .build(), + ) addFunction( FunctionSpec.builder("encode") .addParameter("to", "encoder", encoder) @@ -702,15 +717,15 @@ class SwiftGenerator private constructor( .throws(true) .addStatement("var container = encoder.singleValueContainer()") .addStatement("try container.encode(%N)", storageName) - .build() - ) + .build(), + ) } .build() } private fun messageCodableExtension( type: MessageType, - structType: DeclaredTypeName + structType: DeclaredTypeName, ): ExtensionSpec { return ExtensionSpec.builder(structType) .addSuperType(codable) @@ -730,7 +745,7 @@ class SwiftGenerator private constructor( TypeSpec.enumBuilder(codingKeys) .addModifiers(PUBLIC) .addSuperType(codingKey) - .build() + .build(), ) } @@ -776,7 +791,7 @@ class SwiftGenerator private constructor( addStatement( "self.%1N = try container.$decode($typeArg%2T.self, $forKeys: $keys)", field.name, - typeName + typeName, ) } @@ -799,7 +814,7 @@ class SwiftGenerator private constructor( "let %1N = try container.decodeIfPresent(%2T.self, forKey: %3S)", field.name, typeName, - keyName + keyName, ) } else { nextControlFlow( @@ -807,7 +822,7 @@ class SwiftGenerator private constructor( "let %1N = try container.decodeIfPresent(%2T.self, forKey: %3S)", field.name, typeName, - keyName + keyName, ) } addStatement("self.%1N = .%2N(%2N)", oneOf.name, field.name) @@ -817,7 +832,7 @@ class SwiftGenerator private constructor( endControlFlow("if") } } - .build() + .build(), ) addFunction( FunctionSpec.builder("encode") @@ -854,13 +869,13 @@ class SwiftGenerator private constructor( val (keys, args) = field.codableName?.let { codableName -> Pair( "preferCamelCase ? %2S : %1S", - arrayOf(field.name, codableName) + arrayOf(field.name, codableName), ) } ?: Pair("%1S", arrayOf(field.name)) addStatement( "try container.$encode(${typeArg}self.%1N, forKey: $keys)", - *args + *args, ) } @@ -896,20 +911,20 @@ class SwiftGenerator private constructor( val (keys, args) = field.codableName?.let { codableName -> Pair( "preferCamelCase ? %2S : %1S", - arrayOf(field.name, codableName) + arrayOf(field.name, codableName), ) } ?: Pair("%1S", arrayOf(field.name)) addStatement( "case .%1N(let %1N): try container.encode(%1N, forKey: $keys)", - *args + *args, ) } addStatement("case %T.none: break", OPTIONAL) endControlFlow("switch") } } - .build() + .build(), ) } } @@ -927,7 +942,7 @@ class SwiftGenerator private constructor( private fun FunctionSpec.Builder.addParameters( type: MessageType, oneOfEnumNames: Map, - includeDefaults: Boolean = true + includeDefaults: Boolean = true, ) = apply { type.fields.forEach { field -> addParameter( @@ -937,7 +952,7 @@ class SwiftGenerator private constructor( withFieldDefault(field) } } - .build() + .build(), ) } type.oneOfs.forEach { oneOf -> @@ -945,7 +960,7 @@ class SwiftGenerator private constructor( addParameter( ParameterSpec.builder(oneOf.name, enumName) .defaultValue("nil") - .build() + .build(), ) } } @@ -953,7 +968,7 @@ class SwiftGenerator private constructor( private fun TypeSpec.Builder.generateMessageConstructor( type: MessageType, oneOfEnumNames: Map, - includeDefaults: Boolean = true + includeDefaults: Boolean = true, ) { addFunction( FunctionSpec.constructorBuilder() @@ -967,14 +982,14 @@ class SwiftGenerator private constructor( addStatement("self.%1N = %1N", oneOf.name) } } - .build() + .build(), ) } private fun TypeSpec.Builder.generateMessageProperties( type: MessageType, oneOfEnumNames: Map, - forStorageType: Boolean = false + forStorageType: Boolean = false, ) { type.fields.forEach { field -> val property = PropertySpec.varBuilder(field.name, field.typeName, PUBLIC) @@ -1001,21 +1016,21 @@ class SwiftGenerator private constructor( addDoc("%N\n", oneOf.documentation.sanitizeDoc()) } } - .build() + .build(), ) } addProperty( PropertySpec.varBuilder("unknownFields", FOUNDATION_DATA, PUBLIC) .initializer(".init()") - .build() + .build(), ) } private fun TypeSpec.Builder.generateMessageStoragePropertyDelegates( type: MessageType, storageName: String, - storageType: DeclaredTypeName + storageType: DeclaredTypeName, ) { if (!type.isHeapAllocated) { println("Generating storage property delegates for a non-heap allocated type?!") @@ -1032,21 +1047,21 @@ class SwiftGenerator private constructor( writableKeyPath.parameterizedBy(storageType, propertyVariable), ) .returns(propertyVariable) - .build() - ) - .addModifiers(PUBLIC) - .getter( - FunctionSpec.getterBuilder() - .addStatement("%N[keyPath: keyPath]", storageName) - .build() + .build(), ) - .setter( - FunctionSpec.setterBuilder() - .addStatement("copyStorage()") - .addStatement("%N[keyPath: keyPath] = newValue", storageName) - .build() - ) - .build() + .addModifiers(PUBLIC) + .getter( + FunctionSpec.getterBuilder() + .addStatement("%N[keyPath: keyPath]", storageName) + .build(), + ) + .setter( + FunctionSpec.setterBuilder() + .addStatement("copyStorage()") + .addStatement("%N[keyPath: keyPath] = newValue", storageName) + .build(), + ) + .build() addProperty(subscript) } @@ -1054,7 +1069,7 @@ class SwiftGenerator private constructor( private fun TypeSpec.Builder.generateMessageOneOfs( type: MessageType, oneOfEnumNames: Map, - fileMembers: MutableList + fileMembers: MutableList, ) { type.oneOfs.forEach { oneOf -> val enumName = oneOfEnumNames.getValue(oneOf) @@ -1076,7 +1091,7 @@ class SwiftGenerator private constructor( addAttribute(deprecated) } } - .build() + .build(), ) } } @@ -1090,14 +1105,15 @@ class SwiftGenerator private constructor( oneOf.fields.forEach { field -> addStatement( "case .%1N(let %1N): try $writer.encode(tag: %2L, value: %1N)", - field.name, field.tag + field.name, + field.tag, ) } } .endControlFlow("switch") - .build() + .build(), ) - .build() + .build(), ) val equatableExtension = ExtensionSpec.builder(enumName) @@ -1136,7 +1152,7 @@ class SwiftGenerator private constructor( } } } - .build() + .build(), ) .build() fileMembers += FileMemberSpec.builder(redactableExtension) @@ -1155,7 +1171,7 @@ class SwiftGenerator private constructor( private fun generateEnum( type: EnumType, - fileMembers: MutableList + fileMembers: MutableList, ): TypeSpec { val enumName = type.typeName return TypeSpec.enumBuilder(enumName) @@ -1185,7 +1201,7 @@ class SwiftGenerator private constructor( addAttribute(deprecated) } } - .build() + .build(), ) } @@ -1201,9 +1217,9 @@ class SwiftGenerator private constructor( } } .endControlFlow("switch") - .build() + .build(), ) - .build() + .build(), ) // Swift won't synthesize CaseIterable conformance if any constants contain an availability @@ -1217,11 +1233,11 @@ class SwiftGenerator private constructor( .addStatement( "return [%L]", type.constants.map { CodeBlock.of(".%N", it.name) } - .joinToCode(",%W") + .joinToCode(",%W"), ) - .build() + .build(), ) - .build() + .build(), ) } type.nestedTypes.forEach { nestedType -> @@ -1235,14 +1251,14 @@ class SwiftGenerator private constructor( private fun generateEnclosing( type: EnclosingType, - fileMembers: MutableList + fileMembers: MutableList, ): TypeSpec { return TypeSpec.enumBuilder(type.typeName) .addModifiers(PUBLIC) .addDoc( "%N\n", "*Note:* This type only exists to maintain class structure for its nested types and " + - "is not an actual message." + "is not an actual message.", ) .apply { type.nestedTypes.forEach { nestedType -> @@ -1289,10 +1305,11 @@ class SwiftGenerator private constructor( private val NEEDS_CUSTOM_CODABLE = setOf("Duration", "Timestamp") - @JvmStatic @JvmName("get") + @JvmStatic + @JvmName("get") operator fun invoke( schema: Schema, - existingTypeModuleName: Map = emptyMap() + existingTypeModuleName: Map = emptyMap(), ): SwiftGenerator { val nameToTypeName = mutableMapOf() @@ -1341,7 +1358,7 @@ class SwiftGenerator private constructor( private fun computeReferenceCycleIndirections( schema: Schema, - existingTypes: Set + existingTypes: Set, ): Map> { val indirections = mutableMapOf>() diff --git a/wire-test-utils/src/main/java/com/squareup/wire/json/Json.kt b/wire-test-utils/src/main/java/com/squareup/wire/json/Json.kt index 2e6337d658..c8ae17c593 100644 --- a/wire-test-utils/src/main/java/com/squareup/wire/json/Json.kt +++ b/wire-test-utils/src/main/java/com/squareup/wire/json/Json.kt @@ -1,11 +1,11 @@ /* - * Copyright 2020 Square Inc. + * Copyright (C) 2020 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,7 @@ * limitations under the License. */ @file:JvmName("JsonUtils") + package com.squareup.wire.json import com.squareup.moshi.JsonReader diff --git a/wire-test-utils/src/main/java/com/squareup/wire/schema/SchemaHelpers.kt b/wire-test-utils/src/main/java/com/squareup/wire/schema/SchemaHelpers.kt index d2127c638b..a348373ee2 100644 --- a/wire-test-utils/src/main/java/com/squareup/wire/schema/SchemaHelpers.kt +++ b/wire-test-utils/src/main/java/com/squareup/wire/schema/SchemaHelpers.kt @@ -1,11 +1,11 @@ /* - * Copyright (C) 2022 Block, Inc. + * Copyright (C) 2022 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -17,13 +17,13 @@ package com.squareup.wire.schema import com.squareup.wire.ProtoAdapter import com.squareup.wire.SchemaBuilder +import java.io.File import okio.Path import okio.buffer import okio.source -import java.io.File fun Schema.protoAdapter( - messageTypeName: String + messageTypeName: String, ): ProtoAdapter { return protoAdapter(messageTypeName, includeUnknown = true) } diff --git a/wire-test-utils/src/main/java/com/squareup/wire/testing/UnwantedValueStripper.kt b/wire-test-utils/src/main/java/com/squareup/wire/testing/UnwantedValueStripper.kt index 591c429180..5e4c270f1a 100644 --- a/wire-test-utils/src/main/java/com/squareup/wire/testing/UnwantedValueStripper.kt +++ b/wire-test-utils/src/main/java/com/squareup/wire/testing/UnwantedValueStripper.kt @@ -1,11 +1,11 @@ /* - * Copyright 2021 Square Inc. + * Copyright (C) 2021 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,7 @@ import com.google.protobuf.DescriptorProtos.FieldDescriptorProto import com.google.protobuf.DescriptorProtos.FileDescriptorProto class UnwantedValueStripper( - val clearJsonName: Boolean = false + val clearJsonName: Boolean = false, ) { /** diff --git a/wire-test-utils/src/main/java/com/squareup/wire/testing/files.kt b/wire-test-utils/src/main/java/com/squareup/wire/testing/files.kt index 463d9ca3bd..684c1ed0ae 100644 --- a/wire-test-utils/src/main/java/com/squareup/wire/testing/files.kt +++ b/wire-test-utils/src/main/java/com/squareup/wire/testing/files.kt @@ -1,11 +1,11 @@ /* - * Copyright 2018 Square Inc. + * Copyright (C) 2018 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,10 @@ */ package com.squareup.wire.testing +import java.nio.charset.Charset +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream +import kotlin.text.Charsets.UTF_8 import okio.ByteString import okio.FileSystem import okio.Path @@ -23,16 +27,12 @@ import okio.buffer import okio.sink import org.assertj.core.api.IterableAssert import org.assertj.core.api.ListAssert -import java.nio.charset.Charset -import java.util.zip.ZipEntry -import java.util.zip.ZipOutputStream -import kotlin.text.Charsets.UTF_8 fun FileSystem.add( pathString: String, contents: String, charset: Charset = UTF_8, - bom: ByteString = ByteString.EMPTY + bom: ByteString = ByteString.EMPTY, ) { val path = pathString.toPath() if (path.parent != null) {

Name allocations are computed once and reused because some types may be needed when * generating other types. */ - private final LoadingCache nameAllocators - = CacheBuilder.newBuilder().build(new CacheLoader() { - @Override public NameAllocator load(Type type) throws Exception { - NameAllocator nameAllocator = new NameAllocator(); - - if (type instanceof MessageType) { - nameAllocator.newName("serialVersionUID", "serialVersionUID"); - nameAllocator.newName("ADAPTER", "ADAPTER"); - nameAllocator.newName("MESSAGE_OPTIONS", "MESSAGE_OPTIONS"); - if (emitAndroid) { - nameAllocator.newName("CREATOR", "CREATOR"); - } - - List fieldsAndOneOfFields = ((MessageType) type).getFieldsAndOneOfFields(); - Set collidingNames = collidingFieldNames(fieldsAndOneOfFields); - for (Field field : fieldsAndOneOfFields) { - String suggestion = collidingNames.contains(field.getName()) - || (field.getName().equals(field.getType().getSimpleName()) - && !field.getType().isScalar()) - || hasEponymousType(schema, field) - ? legacyQualifiedFieldName(field) - : field.getName(); - nameAllocator.newName(suggestion, field); - } - - } else if (type instanceof EnumType) { - nameAllocator.newName("value", "value"); - nameAllocator.newName("i", "i"); - nameAllocator.newName("reader", "reader"); - nameAllocator.newName("writer", "writer"); - - for (EnumConstant constant : ((EnumType) type).getConstants()) { - nameAllocator.newName(constant.getName(), constant); - } - } - - return nameAllocator; - } - }); + private final LoadingCache nameAllocators = + CacheBuilder.newBuilder() + .build( + new CacheLoader() { + @Override + public NameAllocator load(Type type) throws Exception { + NameAllocator nameAllocator = new NameAllocator(); + + if (type instanceof MessageType) { + nameAllocator.newName("serialVersionUID", "serialVersionUID"); + nameAllocator.newName("ADAPTER", "ADAPTER"); + nameAllocator.newName("MESSAGE_OPTIONS", "MESSAGE_OPTIONS"); + if (emitAndroid) { + nameAllocator.newName("CREATOR", "CREATOR"); + } + + List fieldsAndOneOfFields = + ((MessageType) type).getFieldsAndOneOfFields(); + Set collidingNames = collidingFieldNames(fieldsAndOneOfFields); + for (Field field : fieldsAndOneOfFields) { + String suggestion = + collidingNames.contains(field.getName()) + || (field.getName().equals(field.getType().getSimpleName()) + && !field.getType().isScalar()) + || hasEponymousType(schema, field) + ? legacyQualifiedFieldName(field) + : field.getName(); + nameAllocator.newName(suggestion, field); + } + + } else if (type instanceof EnumType) { + nameAllocator.newName("value", "value"); + nameAllocator.newName("i", "i"); + nameAllocator.newName("reader", "reader"); + nameAllocator.newName("writer", "writer"); + + for (EnumConstant constant : ((EnumType) type).getConstants()) { + nameAllocator.newName(constant.getName(), constant); + } + } + + return nameAllocator; + } + }); private final Schema schema; @@ -258,10 +270,17 @@ public static boolean builtInType(ProtoType protoType) { private final boolean emitAppliedOptions; private final boolean buildersOnly; - private JavaGenerator(Schema schema, Map typeToJavaName, - Map memberToJavaName, Profile profile, boolean emitAndroid, - boolean emitAndroidAnnotations, boolean emitCompact, boolean emitDeclaredOptions, - boolean emitAppliedOptions, boolean buildersOnly) { + private JavaGenerator( + Schema schema, + Map typeToJavaName, + Map memberToJavaName, + Profile profile, + boolean emitAndroid, + boolean emitAndroidAnnotations, + boolean emitCompact, + boolean emitDeclaredOptions, + boolean emitAppliedOptions, + boolean buildersOnly) { this.schema = schema; this.typeToJavaName = ImmutableMap.copyOf(typeToJavaName); this.memberToJavaName = ImmutableMap.copyOf(memberToJavaName); @@ -275,33 +294,87 @@ private JavaGenerator(Schema schema, Map typeToJavaName, } public JavaGenerator withAndroid(boolean emitAndroid) { - return new JavaGenerator(schema, typeToJavaName, memberToJavaName, profile, emitAndroid, - emitAndroidAnnotations, emitCompact, emitDeclaredOptions, emitAppliedOptions, buildersOnly); + return new JavaGenerator( + schema, + typeToJavaName, + memberToJavaName, + profile, + emitAndroid, + emitAndroidAnnotations, + emitCompact, + emitDeclaredOptions, + emitAppliedOptions, + buildersOnly); } public JavaGenerator withAndroidAnnotations(boolean emitAndroidAnnotations) { - return new JavaGenerator(schema, typeToJavaName, memberToJavaName, profile, emitAndroid, - emitAndroidAnnotations, emitCompact, emitDeclaredOptions, emitAppliedOptions, buildersOnly); + return new JavaGenerator( + schema, + typeToJavaName, + memberToJavaName, + profile, + emitAndroid, + emitAndroidAnnotations, + emitCompact, + emitDeclaredOptions, + emitAppliedOptions, + buildersOnly); } public JavaGenerator withCompact(boolean emitCompact) { - return new JavaGenerator(schema, typeToJavaName, memberToJavaName, profile, emitAndroid, - emitAndroidAnnotations, emitCompact, emitDeclaredOptions, emitAppliedOptions, buildersOnly); + return new JavaGenerator( + schema, + typeToJavaName, + memberToJavaName, + profile, + emitAndroid, + emitAndroidAnnotations, + emitCompact, + emitDeclaredOptions, + emitAppliedOptions, + buildersOnly); } public JavaGenerator withProfile(Profile profile) { - return new JavaGenerator(schema, typeToJavaName, memberToJavaName, profile, emitAndroid, - emitAndroidAnnotations, emitCompact, emitDeclaredOptions, emitAppliedOptions, buildersOnly); + return new JavaGenerator( + schema, + typeToJavaName, + memberToJavaName, + profile, + emitAndroid, + emitAndroidAnnotations, + emitCompact, + emitDeclaredOptions, + emitAppliedOptions, + buildersOnly); } public JavaGenerator withOptions(boolean emitDeclaredOptions, boolean emitAppliedOptions) { - return new JavaGenerator(schema, typeToJavaName, memberToJavaName, profile, emitAndroid, - emitAndroidAnnotations, emitCompact, emitDeclaredOptions, emitAppliedOptions, buildersOnly); + return new JavaGenerator( + schema, + typeToJavaName, + memberToJavaName, + profile, + emitAndroid, + emitAndroidAnnotations, + emitCompact, + emitDeclaredOptions, + emitAppliedOptions, + buildersOnly); } public JavaGenerator withBuildersOnly(boolean buildersOnly) { - return new JavaGenerator(schema, typeToJavaName, memberToJavaName, profile, emitAndroid, - emitAndroidAnnotations, emitCompact, emitDeclaredOptions, emitAppliedOptions, buildersOnly); + return new JavaGenerator( + schema, + typeToJavaName, + memberToJavaName, + profile, + emitAndroid, + emitAndroidAnnotations, + emitCompact, + emitDeclaredOptions, + emitAppliedOptions, + buildersOnly); } public static JavaGenerator get(Schema schema) { @@ -317,20 +390,31 @@ public static JavaGenerator get(Schema schema) { nameToJavaName.put(service.type(), className); } - putAllExtensions(schema, protoFile, - protoFile.getTypes(), protoFile.getExtendList(), - memberToJavaName); + putAllExtensions( + schema, protoFile, protoFile.getTypes(), protoFile.getExtendList(), memberToJavaName); } nameToJavaName.putAll(BUILT_IN_TYPES_MAP); - return new JavaGenerator(schema, nameToJavaName, memberToJavaName, new Profile(), - false /* emitAndroid */, false /* emitAndroidAnnotations */, false /* emitCompact */, - false /* emitDeclaredOptions */, false /* emitAppliedOptions */, false /* buildersOnly */); - } - - private static void putAllExtensions(Schema schema, ProtoFile protoFile, List types, - List extendList, Map memberToJavaName) { + return new JavaGenerator( + schema, + nameToJavaName, + memberToJavaName, + new Profile(), + false /* emitAndroid */, + false /* emitAndroidAnnotations */, + false /* emitCompact */, + false /* emitDeclaredOptions */, + false /* emitAppliedOptions */, + false /* buildersOnly */); + } + + private static void putAllExtensions( + Schema schema, + ProtoFile protoFile, + List types, + List extendList, + Map memberToJavaName) { for (Extend extend : extendList) { if (annotationTargetType(extend) == null) continue; @@ -344,9 +428,8 @@ private static void putAllExtensions(Schema schema, ProtoFile protoFile, List wireToJava, String javaPackage, - ClassName enclosingClassName, List types) { + private static void putAll( + Map wireToJava, + String javaPackage, + ClassName enclosingClassName, + List types) { for (Type type : types) { - ClassName className = enclosingClassName != null - ? enclosingClassName.nestedClass(type.getType().getSimpleName()) - : ClassName.get(javaPackage, type.getType().getSimpleName()); + ClassName className = + enclosingClassName != null + ? enclosingClassName.nestedClass(type.getType().getSimpleName()) + : ClassName.get(javaPackage, type.getType().getSimpleName()); wireToJava.put(type.getType(), className); putAll(wireToJava, javaPackage, className, type.getNestedTypes()); } @@ -520,17 +607,15 @@ static String sanitizeJavadoc(String documentation) { documentation = documentation.replaceAll("\\s+$", ""); documentation = documentation.replaceAll("\\*/", "*/"); // Rewrite '@see ' to use an html anchor tag - documentation = documentation.replaceAll( - "@see (http:" + URL_CHARS + "+)", "@see $1"); + documentation = + documentation.replaceAll("@see (http:" + URL_CHARS + "+)", "@see $1"); return documentation; } /** Returns the full name of the class generated for {@code type}. */ public ClassName generatedTypeName(Type type) { ClassName abstractAdapterName = abstractAdapterName(type.getType()); - return abstractAdapterName != null - ? abstractAdapterName - : (ClassName) typeName(type.getType()); + return abstractAdapterName != null ? abstractAdapterName : (ClassName) typeName(type.getType()); } /** Returns the generated code for {@code type}, which may be a top-level or a nested type. */ @@ -556,9 +641,10 @@ private TypeSpec generateEnum(EnumType type) { String value = nameAllocator.get("value"); ClassName javaType = (ClassName) typeName(type.getType()); - TypeSpec.Builder builder = TypeSpec.enumBuilder(javaType.simpleName()) - .addModifiers(PUBLIC) - .addSuperinterface(WireEnum.class); + TypeSpec.Builder builder = + TypeSpec.enumBuilder(javaType.simpleName()) + .addModifiers(PUBLIC) + .addSuperinterface(WireEnum.class); if (!type.getDocumentation().isEmpty()) { builder.addJavadoc("$L\n", sanitizeJavadoc(type.getDocumentation())); @@ -576,17 +662,19 @@ private TypeSpec generateEnum(EnumType type) { builder.addField(TypeName.INT, value, PRIVATE, FINAL); // Enum constructor takes the constant tag. - builder.addMethod(MethodSpec.constructorBuilder() - .addStatement("this.$1N = $1N", value) - .addParameter(TypeName.INT, value) - .build()); - - MethodSpec.Builder fromValueBuilder = MethodSpec.methodBuilder("fromValue") - .addJavadoc("Return the constant for {@code $N} or null.\n", value) - .addModifiers(PUBLIC, STATIC) - .returns(javaType) - .addParameter(int.class, value) - .beginControlFlow("switch ($N)", value); + builder.addMethod( + MethodSpec.constructorBuilder() + .addStatement("this.$1N = $1N", value) + .addParameter(TypeName.INT, value) + .build()); + + MethodSpec.Builder fromValueBuilder = + MethodSpec.methodBuilder("fromValue") + .addJavadoc("Return the constant for {@code $N} or null.\n", value) + .addModifiers(PUBLIC, STATIC) + .returns(javaType) + .addParameter(int.class, value) + .beginControlFlow("switch ($N)", value); Set seenTags = new LinkedHashSet<>(); for (EnumConstant constant : type.getConstants()) { @@ -612,18 +700,17 @@ private TypeSpec generateEnum(EnumType type) { // Ensure constant case tags are unique, which might not be the case if allow_alias is true. if (seenTags.add(constant.getTag())) { - fromValueBuilder.addStatement("case $L: return $L", constant.getTag(), - nameAllocator.get(constant)); + fromValueBuilder.addStatement( + "case $L: return $L", constant.getTag(), nameAllocator.get(constant)); } } - builder.addMethod(fromValueBuilder.addStatement("default: return null") - .endControlFlow() - .build()); + builder.addMethod( + fromValueBuilder.addStatement("default: return null").endControlFlow().build()); // ADAPTER - FieldSpec.Builder adapterBuilder = FieldSpec.builder(adapterOf(javaType), "ADAPTER") - .addModifiers(PUBLIC, STATIC, FINAL); + FieldSpec.Builder adapterBuilder = + FieldSpec.builder(adapterOf(javaType), "ADAPTER").addModifiers(PUBLIC, STATIC, FINAL); ClassName adapterJavaType = javaType.nestedClass("ProtoAdapter_" + javaType.simpleName()); if (!emitCompact) { adapterBuilder.initializer("new $T()", adapterJavaType); @@ -633,12 +720,13 @@ private TypeSpec generateEnum(EnumType type) { builder.addField(adapterBuilder.build()); // Public Getter - builder.addMethod(MethodSpec.methodBuilder("getValue") - .addAnnotation(Override.class) - .addModifiers(PUBLIC) - .returns(TypeName.INT) - .addStatement("return $N", value) - .build()); + builder.addMethod( + MethodSpec.methodBuilder("getValue") + .addAnnotation(Override.class) + .addModifiers(PUBLIC) + .returns(TypeName.INT) + .addStatement("return $N", value) + .build()); if (!emitCompact) { // Adds the ProtoAdapter implementation at the bottom. @@ -682,22 +770,25 @@ private TypeSpec generateMessage(MessageType type) { String protoAdapterName = "ProtoAdapter_" + javaType.simpleName(); String protoAdapterClassName = nameAllocator.newName(protoAdapterName); ClassName adapterJavaType = javaType.nestedClass(protoAdapterClassName); - builder.addField(messageAdapterField(adapterName, javaType, adapterJavaType, type.getType(), - type.getSyntax())); + builder.addField( + messageAdapterField( + adapterName, javaType, adapterJavaType, type.getType(), type.getSyntax())); // Note: The non-compact implementation is added at the very bottom of the surrounding type. if (emitAndroid) { TypeName creatorType = creatorOf(javaType); String creatorName = nameAllocator.get("CREATOR"); - builder.addField(FieldSpec.builder(creatorType, creatorName, PUBLIC, STATIC, FINAL) - .initializer("$T.newCreator($L)", ANDROID_MESSAGE, adapterName) - .build()); + builder.addField( + FieldSpec.builder(creatorType, creatorName, PUBLIC, STATIC, FINAL) + .initializer("$T.newCreator($L)", ANDROID_MESSAGE, adapterName) + .build()); } - builder.addField(FieldSpec.builder(TypeName.LONG, nameAllocator.get("serialVersionUID")) - .addModifiers(PRIVATE, STATIC, FINAL) - .initializer("$LL", 0L) - .build()); + builder.addField( + FieldSpec.builder(TypeName.LONG, nameAllocator.get("serialVersionUID")) + .addModifiers(PRIVATE, STATIC, FINAL) + .initializer("$LL", 0L) + .build()); for (Field field : type.getFieldsAndOneOfFields()) { TypeName fieldJavaType = fieldType(field); @@ -719,9 +810,7 @@ private TypeSpec generateMessage(MessageType type) { for (AnnotationSpec annotation : optionAnnotations(field.getOptions())) { fieldBuilder.addAnnotation(annotation); } - fieldBuilder.addAnnotation( - wireFieldAnnotation(nameAllocator, field, type) - ); + fieldBuilder.addAnnotation(wireFieldAnnotation(nameAllocator, field, type)); if (field.isExtension()) { fieldBuilder.addJavadoc("Extension source: $L\n", field.getLocation().withPathOnly()); } @@ -771,9 +860,7 @@ private TypeSpec generateMessage(MessageType type) { return builder.build(); } - /** - * Decides if a constructor should take all fields or a builder as a parameter. - */ + /** Decides if a constructor should take all fields or a builder as a parameter. */ private boolean constructorTakesAllFields(MessageType type) { return type.fields().size() < MAX_PARAMS_IN_CONSTRUCTOR; } @@ -781,8 +868,8 @@ private boolean constructorTakesAllFields(MessageType type) { private TypeSpec generateEnclosingType(EnclosingType type) { ClassName javaType = (ClassName) typeName(type.getType()); - TypeSpec.Builder builder = TypeSpec.classBuilder(javaType.simpleName()) - .addModifiers(PUBLIC, FINAL); + TypeSpec.Builder builder = + TypeSpec.classBuilder(javaType.simpleName()).addModifiers(PUBLIC, FINAL); if (javaType.enclosingClassName() != null) { builder.addModifiers(STATIC); } @@ -791,14 +878,16 @@ private TypeSpec generateEnclosingType(EnclosingType type) { if (!documentation.isEmpty()) { documentation += "\n\n