From e1af67f082027dd7811c88434749b7b8f807ceca Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 31 Aug 2021 11:32:43 +0800 Subject: [PATCH] Declare types & Cleanup (#6842) * Declare types * Code cleanup * Declare types --- .../okhttp3/mockwebserver/MockResponse.kt | 12 +++++----- .../okhttp3/mockwebserver/PushPromise.kt | 8 +++---- .../kotlin/mockwebserver3/MockResponse.kt | 12 +++++----- .../kotlin/mockwebserver3/MockWebServer.kt | 4 ++-- .../main/kotlin/mockwebserver3/PushPromise.kt | 8 +++---- okcurl/src/main/kotlin/okhttp3/curl/Main.kt | 2 +- .../src/test/resources/hpack-test-case | 2 +- .../src/main/kotlin/okhttp3/CallEvent.kt | 20 ++++++++-------- .../kotlin/okhttp3/OkHttpClientTestRule.kt | 1 - .../okhttp3/tls/internal/der/Adapters.kt | 24 +++++++++---------- .../tls/internal/der/BasicDerAdapter.kt | 10 ++++---- .../okhttp3/tls/internal/der/DerAdapter.kt | 2 +- .../okhttp3/tls/internal/der/DerHeader.kt | 2 +- .../okhttp3/tls/internal/der/DerReader.kt | 2 +- .../okhttp3/tls/internal/der/DerWriter.kt | 2 +- okhttp/src/main/kotlin/okhttp3/Address.kt | 22 ++++++++--------- okhttp/src/main/kotlin/okhttp3/Cache.kt | 2 +- .../src/main/kotlin/okhttp3/CacheControl.kt | 20 ++++++++-------- okhttp/src/main/kotlin/okhttp3/Challenge.kt | 6 ++--- okhttp/src/main/kotlin/okhttp3/FormBody.kt | 12 +++++----- okhttp/src/main/kotlin/okhttp3/Handshake.kt | 12 +++++----- okhttp/src/main/kotlin/okhttp3/HttpUrl.kt | 4 ++-- okhttp/src/main/kotlin/okhttp3/MediaType.kt | 10 ++++---- .../main/kotlin/okhttp3/MultipartReader.kt | 2 +- okhttp/src/main/kotlin/okhttp3/Protocol.kt | 2 +- okhttp/src/main/kotlin/okhttp3/Request.kt | 14 +++++------ okhttp/src/main/kotlin/okhttp3/RequestBody.kt | 6 ++--- okhttp/src/main/kotlin/okhttp3/Response.kt | 2 +- .../src/main/kotlin/okhttp3/ResponseBody.kt | 14 +++++------ okhttp/src/main/kotlin/okhttp3/Route.kt | 2 +- okhttp/src/main/kotlin/okhttp3/TlsVersion.kt | 2 +- .../src/main/kotlin/okhttp3/internal/Util.kt | 18 +++++++------- .../internal/cache/CacheInterceptor.kt | 3 ++- .../okhttp3/internal/concurrent/Task.kt | 2 +- .../okhttp3/internal/concurrent/TaskQueue.kt | 2 +- .../okhttp3/internal/connection/RealCall.kt | 9 +++---- .../internal/connection/RealConnectionPool.kt | 6 ++--- .../internal/http/CallServerInterceptor.kt | 2 +- .../okhttp3/internal/http/HttpHeaders.kt | 2 +- .../okhttp3/internal/http/RequestLine.kt | 2 +- .../kotlin/okhttp3/internal/http2/Http2.kt | 2 +- .../main/kotlin/okhttp3/internal/internal.kt | 8 +++---- .../internal/platform/Android10Platform.kt | 2 +- .../internal/platform/AndroidPlatform.kt | 2 +- .../okhttp3/internal/ws/MessageDeflater.kt | 2 +- 45 files changed, 153 insertions(+), 152 deletions(-) diff --git a/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/MockResponse.kt b/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/MockResponse.kt index f1b43faea..288f72f1a 100644 --- a/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/MockResponse.kt +++ b/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/MockResponse.kt @@ -45,16 +45,16 @@ class MockResponse : Cloneable { private var body: Buffer? = null - var throttleBytesPerPeriod = Long.MAX_VALUE + var throttleBytesPerPeriod: Long = Long.MAX_VALUE private set private var throttlePeriodAmount = 1L private var throttlePeriodUnit = TimeUnit.SECONDS @set:JvmName("socketPolicy") - var socketPolicy = SocketPolicy.KEEP_OPEN + var socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN @set:JvmName("http2ErrorCode") - var http2ErrorCode = -1 + var http2ErrorCode: Int = -1 private var bodyDelayAmount = 0L private var bodyDelayUnit = TimeUnit.MILLISECONDS @@ -182,7 +182,7 @@ class MockResponse : Cloneable { message = "moved to var", replaceWith = ReplaceWith(expression = "socketPolicy"), level = DeprecationLevel.ERROR) - fun getSocketPolicy() = socketPolicy + fun getSocketPolicy(): SocketPolicy = socketPolicy fun setSocketPolicy(socketPolicy: SocketPolicy) = apply { this.socketPolicy = socketPolicy @@ -193,7 +193,7 @@ class MockResponse : Cloneable { message = "moved to var", replaceWith = ReplaceWith(expression = "http2ErrorCode"), level = DeprecationLevel.ERROR) - fun getHttp2ErrorCode() = http2ErrorCode + fun getHttp2ErrorCode(): Int = http2ErrorCode fun setHttp2ErrorCode(http2ErrorCode: Int) = apply { this.http2ErrorCode = http2ErrorCode @@ -240,7 +240,7 @@ class MockResponse : Cloneable { webSocketListener = listener } - override fun toString() = status + override fun toString(): String = status companion object { private const val CHUNKED_BODY_HEADER = "Transfer-encoding: chunked" diff --git a/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/PushPromise.kt b/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/PushPromise.kt index 38daf8166..aed629265 100644 --- a/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/PushPromise.kt +++ b/mockwebserver-deprecated/src/main/kotlin/okhttp3/mockwebserver/PushPromise.kt @@ -29,26 +29,26 @@ class PushPromise( message = "moved to val", replaceWith = ReplaceWith(expression = "method"), level = DeprecationLevel.ERROR) - fun method() = method + fun method(): String = method @JvmName("-deprecated_path") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "path"), level = DeprecationLevel.ERROR) - fun path() = path + fun path(): String = path @JvmName("-deprecated_headers") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "headers"), level = DeprecationLevel.ERROR) - fun headers() = headers + fun headers(): Headers = headers @JvmName("-deprecated_response") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "response"), level = DeprecationLevel.ERROR) - fun response() = response + fun response(): MockResponse = response } diff --git a/mockwebserver/src/main/kotlin/mockwebserver3/MockResponse.kt b/mockwebserver/src/main/kotlin/mockwebserver3/MockResponse.kt index 77a5a0482..8dc320357 100644 --- a/mockwebserver/src/main/kotlin/mockwebserver3/MockResponse.kt +++ b/mockwebserver/src/main/kotlin/mockwebserver3/MockResponse.kt @@ -49,13 +49,13 @@ class MockResponse : Cloneable { private var body: Buffer? = null - var throttleBytesPerPeriod = Long.MAX_VALUE + var throttleBytesPerPeriod: Long = Long.MAX_VALUE private set private var throttlePeriodAmount = 1L private var throttlePeriodUnit = TimeUnit.SECONDS @set:JvmName("socketPolicy") - var socketPolicy = SocketPolicy.KEEP_OPEN + var socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN /** * Sets the [HTTP/2 error code](https://tools.ietf.org/html/rfc7540#section-7) to be @@ -64,7 +64,7 @@ class MockResponse : Cloneable { * [SocketPolicy.DO_NOT_READ_REQUEST_BODY]. */ @set:JvmName("http2ErrorCode") - var http2ErrorCode = -1 + var http2ErrorCode: Int = -1 private var bodyDelayAmount = 0L private var bodyDelayUnit = TimeUnit.MILLISECONDS @@ -253,7 +253,7 @@ class MockResponse : Cloneable { message = "moved to var", replaceWith = ReplaceWith(expression = "socketPolicy"), level = DeprecationLevel.ERROR) - fun getSocketPolicy() = socketPolicy + fun getSocketPolicy(): SocketPolicy = socketPolicy /** * Sets the socket policy and returns this. @@ -271,7 +271,7 @@ class MockResponse : Cloneable { message = "moved to var", replaceWith = ReplaceWith(expression = "http2ErrorCode"), level = DeprecationLevel.ERROR) - fun getHttp2ErrorCode() = http2ErrorCode + fun getHttp2ErrorCode(): Int = http2ErrorCode /** * Sets the HTTP/2 error code and returns this. @@ -345,7 +345,7 @@ class MockResponse : Cloneable { webSocketListener = listener } - override fun toString() = status + override fun toString(): String = status companion object { private const val CHUNKED_BODY_HEADER = "Transfer-encoding: chunked" diff --git a/mockwebserver/src/main/kotlin/mockwebserver3/MockWebServer.kt b/mockwebserver/src/main/kotlin/mockwebserver3/MockWebServer.kt index 6bcf0fb89..67c742662 100644 --- a/mockwebserver/src/main/kotlin/mockwebserver3/MockWebServer.kt +++ b/mockwebserver/src/main/kotlin/mockwebserver3/MockWebServer.kt @@ -117,7 +117,7 @@ class MockWebServer : Closeable { get() = atomicRequestCount.get() /** The number of bytes of the POST body to keep in memory to the given limit. */ - var bodyLimit = Long.MAX_VALUE + var bodyLimit: Long = Long.MAX_VALUE var serverSocketFactory: ServerSocketFactory? = null @Synchronized get() { @@ -165,7 +165,7 @@ class MockWebServer : Closeable { * HTTP/2. This is true by default; set to false to disable negotiation and restrict connections * to HTTP/1.1. */ - var protocolNegotiationEnabled = true + var protocolNegotiationEnabled: Boolean = true /** * The protocols supported by ALPN on incoming HTTPS connections in order of preference. The list diff --git a/mockwebserver/src/main/kotlin/mockwebserver3/PushPromise.kt b/mockwebserver/src/main/kotlin/mockwebserver3/PushPromise.kt index 0f3e83c2a..286f19924 100644 --- a/mockwebserver/src/main/kotlin/mockwebserver3/PushPromise.kt +++ b/mockwebserver/src/main/kotlin/mockwebserver3/PushPromise.kt @@ -30,26 +30,26 @@ class PushPromise( message = "moved to val", replaceWith = ReplaceWith(expression = "method"), level = DeprecationLevel.ERROR) - fun method() = method + fun method(): String = method @JvmName("-deprecated_path") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "path"), level = DeprecationLevel.ERROR) - fun path() = path + fun path(): String = path @JvmName("-deprecated_headers") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "headers"), level = DeprecationLevel.ERROR) - fun headers() = headers + fun headers(): Headers = headers @JvmName("-deprecated_response") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "response"), level = DeprecationLevel.ERROR) - fun response() = response + fun response(): MockResponse = response } diff --git a/okcurl/src/main/kotlin/okhttp3/curl/Main.kt b/okcurl/src/main/kotlin/okhttp3/curl/Main.kt index 51aebcc86..0127164b4 100644 --- a/okcurl/src/main/kotlin/okhttp3/curl/Main.kt +++ b/okcurl/src/main/kotlin/okhttp3/curl/Main.kt @@ -291,7 +291,7 @@ class Main : Runnable { override fun format(record: LogRecord): String { val parameters = record.parameters return if (parameters != null) { - format("%s%n%s%n", record.message, record.parameters.first()) + format("%s%n%s%n", record.message, parameters.first()) } else { format("%s%n", record.message) } diff --git a/okhttp-hpacktests/src/test/resources/hpack-test-case b/okhttp-hpacktests/src/test/resources/hpack-test-case index a5652bc2b..8a1406e7d 160000 --- a/okhttp-hpacktests/src/test/resources/hpack-test-case +++ b/okhttp-hpacktests/src/test/resources/hpack-test-case @@ -1 +1 @@ -Subproject commit a5652bc2bc3d2a992f39446369fb004a72e881d4 +Subproject commit 8a1406e7d14bfcb6c046021f13cc15cfb162726d diff --git a/okhttp-testing-support/src/main/kotlin/okhttp3/CallEvent.kt b/okhttp-testing-support/src/main/kotlin/okhttp3/CallEvent.kt index b9abc4f84..bc91e6f22 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/CallEvent.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/CallEvent.kt @@ -58,7 +58,7 @@ sealed class CallEvent { val domainName: String, val inetAddressList: List ) : CallEvent() { - override fun closes(timestampNs: Long) = DnsStart(timestampNs, call, domainName) + override fun closes(timestampNs: Long): CallEvent = DnsStart(timestampNs, call, domainName) } data class ConnectStart( @@ -75,7 +75,7 @@ sealed class CallEvent { val proxy: Proxy?, val protocol: Protocol? ) : CallEvent() { - override fun closes(timestampNs: Long) = + override fun closes(timestampNs: Long): CallEvent = ConnectStart(timestampNs, call, inetSocketAddress, proxy) } @@ -87,7 +87,7 @@ sealed class CallEvent { val protocol: Protocol?, val ioe: IOException ) : CallEvent() { - override fun closes(timestampNs: Long) = + override fun closes(timestampNs: Long): CallEvent = ConnectStart(timestampNs, call, inetSocketAddress, proxy) } @@ -101,7 +101,7 @@ sealed class CallEvent { override val call: Call, val handshake: Handshake? ) : CallEvent() { - override fun closes(timestampNs: Long) = SecureConnectStart(timestampNs, call) + override fun closes(timestampNs: Long): CallEvent = SecureConnectStart(timestampNs, call) } data class ConnectionAcquired( @@ -115,7 +115,7 @@ sealed class CallEvent { override val call: Call, val connection: Connection ) : CallEvent() { - override fun closes(timestampNs: Long) = ConnectionAcquired(timestampNs, call, connection) + override fun closes(timestampNs: Long): CallEvent = ConnectionAcquired(timestampNs, call, connection) } data class CallStart( @@ -127,7 +127,7 @@ sealed class CallEvent { override val timestampNs: Long, override val call: Call ) : CallEvent() { - override fun closes(timestampNs: Long) = CallStart(timestampNs, call) + override fun closes(timestampNs: Long): CallEvent = CallStart(timestampNs, call) } data class CallFailed( @@ -151,7 +151,7 @@ sealed class CallEvent { override val call: Call, val headerLength: Long ) : CallEvent() { - override fun closes(timestampNs: Long) = RequestHeadersStart(timestampNs, call) + override fun closes(timestampNs: Long): CallEvent = RequestHeadersStart(timestampNs, call) } data class RequestBodyStart( @@ -164,7 +164,7 @@ sealed class CallEvent { override val call: Call, val bytesWritten: Long ) : CallEvent() { - override fun closes(timestampNs: Long) = RequestBodyStart(timestampNs, call) + override fun closes(timestampNs: Long): CallEvent = RequestBodyStart(timestampNs, call) } data class RequestFailed( @@ -183,7 +183,7 @@ sealed class CallEvent { override val call: Call, val headerLength: Long ) : CallEvent() { - override fun closes(timestampNs: Long) = RequestHeadersStart(timestampNs, call) + override fun closes(timestampNs: Long): CallEvent = RequestHeadersStart(timestampNs, call) } data class ResponseBodyStart( @@ -196,7 +196,7 @@ sealed class CallEvent { override val call: Call, val bytesRead: Long ) : CallEvent() { - override fun closes(timestampNs: Long) = ResponseBodyStart(timestampNs, call) + override fun closes(timestampNs: Long): CallEvent = ResponseBodyStart(timestampNs, call) } data class ResponseFailed( diff --git a/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt b/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt index beeebdd95..dc781f188 100644 --- a/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt +++ b/okhttp-testing-support/src/main/kotlin/okhttp3/OkHttpClientTestRule.kt @@ -15,7 +15,6 @@ */ package okhttp3 -import java.net.InetAddress import java.util.concurrent.TimeUnit import java.util.logging.Handler import java.util.logging.Level diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Adapters.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Adapters.kt index 9c57cb1db..a1f93b38b 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Adapters.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Adapters.kt @@ -33,7 +33,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 1L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readBoolean() + override fun decode(reader: DerReader): Boolean = reader.readBoolean() override fun encode(writer: DerWriter, value: Boolean) = writer.writeBoolean(value) } ) @@ -43,7 +43,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 2L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readLong() + override fun decode(reader: DerReader): Long = reader.readLong() override fun encode(writer: DerWriter, value: Long) = writer.writeLong(value) } ) @@ -53,7 +53,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 2L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readBigInteger() + override fun decode(reader: DerReader): BigInteger = reader.readBigInteger() override fun encode(writer: DerWriter, value: BigInteger) = writer.writeBigInteger(value) } ) @@ -63,7 +63,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 3L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readBitString() + override fun decode(reader: DerReader): BitString = reader.readBitString() override fun encode(writer: DerWriter, value: BitString) = writer.writeBitString(value) } ) @@ -73,7 +73,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 4L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readOctetString() + override fun decode(reader: DerReader): ByteString = reader.readOctetString() override fun encode(writer: DerWriter, value: ByteString) = writer.writeOctetString(value) } ) @@ -94,7 +94,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 6L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readObjectIdentifier() + override fun decode(reader: DerReader): String = reader.readObjectIdentifier() override fun encode(writer: DerWriter, value: String) = writer.writeObjectIdentifier(value) } ) @@ -104,7 +104,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 12L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readUtf8String() + override fun decode(reader: DerReader): String = reader.readUtf8String() override fun encode(writer: DerWriter, value: String) = writer.writeUtf8(value) } ) @@ -122,7 +122,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 19L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readUtf8String() + override fun decode(reader: DerReader): String = reader.readUtf8String() override fun encode(writer: DerWriter, value: String) = writer.writeUtf8(value) } ) @@ -137,7 +137,7 @@ internal object Adapters { tagClass = DerHeader.TAG_CLASS_UNIVERSAL, tag = 22L, codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = reader.readUtf8String() + override fun decode(reader: DerReader): String = reader.readUtf8String() override fun encode(writer: DerWriter, value: String) = writer.writeUtf8(value) } ) @@ -209,7 +209,7 @@ internal object Adapters { /** Decodes any value without interpretation as [AnyValue]. */ val ANY_VALUE = object : DerAdapter { - override fun matches(header: DerHeader) = true + override fun matches(header: DerHeader): Boolean = true override fun fromDer(reader: DerReader): AnyValue { reader.read("ANY") { header -> @@ -329,7 +329,7 @@ internal object Adapters { (adapter as DerAdapter).toDer(writer, v) } - override fun toString() = choices.joinToString(separator = " OR ") + override fun toString(): String = choices.joinToString(separator = " OR ") } } @@ -346,7 +346,7 @@ internal object Adapters { chooser: (Any?) -> DerAdapter<*>? ): DerAdapter { return object : DerAdapter { - override fun matches(header: DerHeader) = true + override fun matches(header: DerHeader): Boolean = true override fun toDer(writer: DerWriter, value: Any?) { // If we don't understand this hint, encode the body as a byte string. The byte string diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt index 109cdb6ba..6cdcd9756 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/BasicDerAdapter.kt @@ -50,7 +50,7 @@ internal data class BasicDerAdapter( require(tag >= 0) } - override fun matches(header: DerHeader) = header.tagClass == tagClass && header.tag == tag + override fun matches(header: DerHeader): Boolean = header.tagClass == tagClass && header.tag == tag override fun fromDer(reader: DerReader): T { val peekedHeader = reader.peekHeader() @@ -109,16 +109,16 @@ internal data class BasicDerAdapter( fun withTag( tagClass: Int = DerHeader.TAG_CLASS_CONTEXT_SPECIFIC, tag: Long - ) = copy(tagClass = tagClass, tag = tag) + ): BasicDerAdapter = copy(tagClass = tagClass, tag = tag) /** Returns a copy of this adapter that doesn't encode values equal to [defaultValue]. */ - fun optional(defaultValue: T? = null) = copy(isOptional = true, defaultValue = defaultValue) + fun optional(defaultValue: T? = null): BasicDerAdapter = copy(isOptional = true, defaultValue = defaultValue) /** * Returns a copy of this adapter that sets the encoded or decoded value as the type hint for the * other adapters on this SEQUENCE to interrogate. */ - fun asTypeHint() = copy(typeHint = true) + fun asTypeHint(): BasicDerAdapter = copy(typeHint = true) // Avoid Long.hashCode(long) which isn't available on Android 5. override fun hashCode(): Int { @@ -133,7 +133,7 @@ internal data class BasicDerAdapter( return result } - override fun toString() = "$name [$tagClass/$tag]" + override fun toString(): String = "$name [$tagClass/$tag]" /** Reads and writes values without knowledge of the enclosing tag, length, or defaults. */ interface Codec { diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerAdapter.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerAdapter.kt index eccb85019..440f52b4a 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerAdapter.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerAdapter.kt @@ -80,7 +80,7 @@ internal interface DerAdapter { forceConstructed: Boolean? = null ): BasicDerAdapter { val codec = object : BasicDerAdapter.Codec { - override fun decode(reader: DerReader) = fromDer(reader) + override fun decode(reader: DerReader): T = fromDer(reader) override fun encode(writer: DerWriter, value: T) { toDer(writer, value) if (forceConstructed != null) { diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt index 4cce53360..feec4c84c 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerHeader.kt @@ -65,7 +65,7 @@ internal data class DerHeader( return result } - override fun toString() = "$tagClass/$tag" + override fun toString(): String = "$tagClass/$tag" companion object { const val TAG_CLASS_UNIVERSAL = 0b0000_0000 diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerReader.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerReader.kt index 6e2d8a59c..b51a19dca 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerReader.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerReader.kt @@ -311,7 +311,7 @@ internal class DerReader(source: Source) { return source.readByteString(bytesLeft) } - override fun toString() = path.joinToString(separator = " / ") + override fun toString(): String = path.joinToString(separator = " / ") companion object { /** diff --git a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerWriter.kt b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerWriter.kt index 6bccca4ea..7db879bfa 100644 --- a/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerWriter.kt +++ b/okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/DerWriter.kt @@ -182,5 +182,5 @@ internal class DerWriter(sink: BufferedSink) { } } - override fun toString() = path.joinToString(separator = " / ") + override fun toString(): String = path.joinToString(separator = " / ") } diff --git a/okhttp/src/main/kotlin/okhttp3/Address.kt b/okhttp/src/main/kotlin/okhttp3/Address.kt index 1911a42f8..2d2bc66b6 100644 --- a/okhttp/src/main/kotlin/okhttp3/Address.kt +++ b/okhttp/src/main/kotlin/okhttp3/Address.kt @@ -91,77 +91,77 @@ class Address( message = "moved to val", replaceWith = ReplaceWith(expression = "url"), level = DeprecationLevel.ERROR) - fun url() = url + fun url(): HttpUrl = url @JvmName("-deprecated_dns") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "dns"), level = DeprecationLevel.ERROR) - fun dns() = dns + fun dns(): Dns = dns @JvmName("-deprecated_socketFactory") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "socketFactory"), level = DeprecationLevel.ERROR) - fun socketFactory() = socketFactory + fun socketFactory(): SocketFactory = socketFactory @JvmName("-deprecated_proxyAuthenticator") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "proxyAuthenticator"), level = DeprecationLevel.ERROR) - fun proxyAuthenticator() = proxyAuthenticator + fun proxyAuthenticator(): Authenticator = proxyAuthenticator @JvmName("-deprecated_protocols") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "protocols"), level = DeprecationLevel.ERROR) - fun protocols() = protocols + fun protocols(): List = protocols @JvmName("-deprecated_connectionSpecs") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "connectionSpecs"), level = DeprecationLevel.ERROR) - fun connectionSpecs() = connectionSpecs + fun connectionSpecs(): List = connectionSpecs @JvmName("-deprecated_proxySelector") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "proxySelector"), level = DeprecationLevel.ERROR) - fun proxySelector() = proxySelector + fun proxySelector(): ProxySelector = proxySelector @JvmName("-deprecated_proxy") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "proxy"), level = DeprecationLevel.ERROR) - fun proxy() = proxy + fun proxy(): Proxy? = proxy @JvmName("-deprecated_sslSocketFactory") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "sslSocketFactory"), level = DeprecationLevel.ERROR) - fun sslSocketFactory() = sslSocketFactory + fun sslSocketFactory(): SSLSocketFactory? = sslSocketFactory @JvmName("-deprecated_hostnameVerifier") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "hostnameVerifier"), level = DeprecationLevel.ERROR) - fun hostnameVerifier() = hostnameVerifier + fun hostnameVerifier(): HostnameVerifier? = hostnameVerifier @JvmName("-deprecated_certificatePinner") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "certificatePinner"), level = DeprecationLevel.ERROR) - fun certificatePinner() = certificatePinner + fun certificatePinner(): CertificatePinner? = certificatePinner override fun equals(other: Any?): Boolean { return other is Address && diff --git a/okhttp/src/main/kotlin/okhttp3/Cache.kt b/okhttp/src/main/kotlin/okhttp3/Cache.kt index cc57df21b..8e3b189ff 100644 --- a/okhttp/src/main/kotlin/okhttp3/Cache.kt +++ b/okhttp/src/main/kotlin/okhttp3/Cache.kt @@ -741,7 +741,7 @@ class Cache( } /** Returns true if a Vary header contains an asterisk. Such responses cannot be cached. */ - fun Response.hasVaryAll() = "*" in headers.varyFields() + fun Response.hasVaryAll(): Boolean = "*" in headers.varyFields() /** * Returns the names of the request headers that need to be checked for equality when caching. diff --git a/okhttp/src/main/kotlin/okhttp3/CacheControl.kt b/okhttp/src/main/kotlin/okhttp3/CacheControl.kt index 08f6936f6..ff440a36e 100644 --- a/okhttp/src/main/kotlin/okhttp3/CacheControl.kt +++ b/okhttp/src/main/kotlin/okhttp3/CacheControl.kt @@ -75,70 +75,70 @@ class CacheControl private constructor( message = "moved to val", replaceWith = ReplaceWith(expression = "noCache"), level = DeprecationLevel.ERROR) - fun noCache() = noCache + fun noCache(): Boolean = noCache @JvmName("-deprecated_noStore") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "noStore"), level = DeprecationLevel.ERROR) - fun noStore() = noStore + fun noStore(): Boolean = noStore @JvmName("-deprecated_maxAgeSeconds") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "maxAgeSeconds"), level = DeprecationLevel.ERROR) - fun maxAgeSeconds() = maxAgeSeconds + fun maxAgeSeconds(): Int = maxAgeSeconds @JvmName("-deprecated_sMaxAgeSeconds") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "sMaxAgeSeconds"), level = DeprecationLevel.ERROR) - fun sMaxAgeSeconds() = sMaxAgeSeconds + fun sMaxAgeSeconds(): Int = sMaxAgeSeconds @JvmName("-deprecated_mustRevalidate") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "mustRevalidate"), level = DeprecationLevel.ERROR) - fun mustRevalidate() = mustRevalidate + fun mustRevalidate(): Boolean = mustRevalidate @JvmName("-deprecated_maxStaleSeconds") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "maxStaleSeconds"), level = DeprecationLevel.ERROR) - fun maxStaleSeconds() = maxStaleSeconds + fun maxStaleSeconds(): Int = maxStaleSeconds @JvmName("-deprecated_minFreshSeconds") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "minFreshSeconds"), level = DeprecationLevel.ERROR) - fun minFreshSeconds() = minFreshSeconds + fun minFreshSeconds(): Int = minFreshSeconds @JvmName("-deprecated_onlyIfCached") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "onlyIfCached"), level = DeprecationLevel.ERROR) - fun onlyIfCached() = onlyIfCached + fun onlyIfCached(): Boolean = onlyIfCached @JvmName("-deprecated_noTransform") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "noTransform"), level = DeprecationLevel.ERROR) - fun noTransform() = noTransform + fun noTransform(): Boolean = noTransform @JvmName("-deprecated_immutable") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "immutable"), level = DeprecationLevel.ERROR) - fun immutable() = immutable + fun immutable(): Boolean = immutable override fun toString(): String { var result = headerValue diff --git a/okhttp/src/main/kotlin/okhttp3/Challenge.kt b/okhttp/src/main/kotlin/okhttp3/Challenge.kt index fbf4d0444..bfd738acd 100644 --- a/okhttp/src/main/kotlin/okhttp3/Challenge.kt +++ b/okhttp/src/main/kotlin/okhttp3/Challenge.kt @@ -78,14 +78,14 @@ class Challenge( message = "moved to val", replaceWith = ReplaceWith(expression = "scheme"), level = DeprecationLevel.ERROR) - fun scheme() = scheme + fun scheme(): String = scheme @JvmName("-deprecated_authParams") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "authParams"), level = DeprecationLevel.ERROR) - fun authParams() = authParams + fun authParams(): Map = authParams @JvmName("-deprecated_realm") @Deprecated( @@ -114,5 +114,5 @@ class Challenge( return result } - override fun toString() = "$scheme authParams=$authParams" + override fun toString(): String = "$scheme authParams=$authParams" } diff --git a/okhttp/src/main/kotlin/okhttp3/FormBody.kt b/okhttp/src/main/kotlin/okhttp3/FormBody.kt index 97d3b323d..747086a8d 100644 --- a/okhttp/src/main/kotlin/okhttp3/FormBody.kt +++ b/okhttp/src/main/kotlin/okhttp3/FormBody.kt @@ -43,17 +43,17 @@ class FormBody internal constructor( level = DeprecationLevel.ERROR) fun size(): Int = size - fun encodedName(index: Int) = encodedNames[index] + fun encodedName(index: Int): String = encodedNames[index] - fun name(index: Int) = encodedName(index).percentDecode(plusIsSpace = true) + fun name(index: Int): String = encodedName(index).percentDecode(plusIsSpace = true) - fun encodedValue(index: Int) = encodedValues[index] + fun encodedValue(index: Int): String = encodedValues[index] - fun value(index: Int) = encodedValue(index).percentDecode(plusIsSpace = true) + fun value(index: Int): String = encodedValue(index).percentDecode(plusIsSpace = true) - override fun contentType() = CONTENT_TYPE + override fun contentType(): MediaType = CONTENT_TYPE - override fun contentLength() = writeOrCountBytes(null, true) + override fun contentLength(): Long = writeOrCountBytes(null, true) @Throws(IOException::class) override fun writeTo(sink: BufferedSink) { diff --git a/okhttp/src/main/kotlin/okhttp3/Handshake.kt b/okhttp/src/main/kotlin/okhttp3/Handshake.kt index 91cc2545b..6b0f8c703 100644 --- a/okhttp/src/main/kotlin/okhttp3/Handshake.kt +++ b/okhttp/src/main/kotlin/okhttp3/Handshake.kt @@ -61,21 +61,21 @@ class Handshake internal constructor( message = "moved to val", replaceWith = ReplaceWith(expression = "tlsVersion"), level = DeprecationLevel.ERROR) - fun tlsVersion() = tlsVersion + fun tlsVersion(): TlsVersion = tlsVersion @JvmName("-deprecated_cipherSuite") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "cipherSuite"), level = DeprecationLevel.ERROR) - fun cipherSuite() = cipherSuite + fun cipherSuite(): CipherSuite = cipherSuite @JvmName("-deprecated_peerCertificates") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "peerCertificates"), level = DeprecationLevel.ERROR) - fun peerCertificates() = peerCertificates + fun peerCertificates(): List = peerCertificates /** Returns the remote peer's principle, or null if that peer is anonymous. */ @get:JvmName("peerPrincipal") @@ -87,14 +87,14 @@ class Handshake internal constructor( message = "moved to val", replaceWith = ReplaceWith(expression = "peerPrincipal"), level = DeprecationLevel.ERROR) - fun peerPrincipal() = peerPrincipal + fun peerPrincipal(): Principal? = peerPrincipal @JvmName("-deprecated_localCertificates") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "localCertificates"), level = DeprecationLevel.ERROR) - fun localCertificates() = localCertificates + fun localCertificates(): List = localCertificates /** Returns the local principle, or null if this peer is anonymous. */ @get:JvmName("localPrincipal") @@ -106,7 +106,7 @@ class Handshake internal constructor( message = "moved to val", replaceWith = ReplaceWith(expression = "localPrincipal"), level = DeprecationLevel.ERROR) - fun localPrincipal() = localPrincipal + fun localPrincipal(): Principal? = localPrincipal override fun equals(other: Any?): Boolean { return other is Handshake && diff --git a/okhttp/src/main/kotlin/okhttp3/HttpUrl.kt b/okhttp/src/main/kotlin/okhttp3/HttpUrl.kt index e6bbea528..4b12eb286 100644 --- a/okhttp/src/main/kotlin/okhttp3/HttpUrl.kt +++ b/okhttp/src/main/kotlin/okhttp3/HttpUrl.kt @@ -778,14 +778,14 @@ class HttpUrl internal constructor( message = "moved to toUrl()", replaceWith = ReplaceWith(expression = "toUrl()"), level = DeprecationLevel.ERROR) - fun url() = toUrl() + fun url(): URL = toUrl() @JvmName("-deprecated_uri") @Deprecated( message = "moved to toUri()", replaceWith = ReplaceWith(expression = "toUri()"), level = DeprecationLevel.ERROR) - fun uri() = toUri() + fun uri(): URI = toUri() @JvmName("-deprecated_scheme") @Deprecated( diff --git a/okhttp/src/main/kotlin/okhttp3/MediaType.kt b/okhttp/src/main/kotlin/okhttp3/MediaType.kt index cb91a198e..bdcbd7ed7 100644 --- a/okhttp/src/main/kotlin/okhttp3/MediaType.kt +++ b/okhttp/src/main/kotlin/okhttp3/MediaType.kt @@ -74,24 +74,24 @@ class MediaType private constructor( message = "moved to val", replaceWith = ReplaceWith(expression = "type"), level = DeprecationLevel.ERROR) - fun type() = type + fun type(): String = type @JvmName("-deprecated_subtype") @Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "subtype"), level = DeprecationLevel.ERROR) - fun subtype() = subtype + fun subtype(): String = subtype /** * Returns the encoded media type, like "text/plain; charset=utf-8", appropriate for use in a * Content-Type header. */ - override fun toString() = mediaType + override fun toString(): String = mediaType - override fun equals(other: Any?) = other is MediaType && other.mediaType == mediaType + override fun equals(other: Any?): Boolean = other is MediaType && other.mediaType == mediaType - override fun hashCode() = mediaType.hashCode() + override fun hashCode(): Int = mediaType.hashCode() companion object { private const val TOKEN = "([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)" diff --git a/okhttp/src/main/kotlin/okhttp3/MultipartReader.kt b/okhttp/src/main/kotlin/okhttp3/MultipartReader.kt index 6f100eb23..ec1530116 100644 --- a/okhttp/src/main/kotlin/okhttp3/MultipartReader.kt +++ b/okhttp/src/main/kotlin/okhttp3/MultipartReader.kt @@ -166,7 +166,7 @@ class MultipartReader @Throws(IOException::class) constructor( error("unreachable") // TODO(jwilson): fix intersectWith() to return T. } - override fun timeout() = timeout + override fun timeout(): Timeout = timeout } /** diff --git a/okhttp/src/main/kotlin/okhttp3/Protocol.kt b/okhttp/src/main/kotlin/okhttp3/Protocol.kt index 466cdf463..cda927580 100644 --- a/okhttp/src/main/kotlin/okhttp3/Protocol.kt +++ b/okhttp/src/main/kotlin/okhttp3/Protocol.kt @@ -91,7 +91,7 @@ enum class Protocol(private val protocol: String) { * * [iana]: https://www.iana.org/assignments/tls-extensiontype-values */ - override fun toString() = protocol + override fun toString(): String = protocol companion object { /** diff --git a/okhttp/src/main/kotlin/okhttp3/Request.kt b/okhttp/src/main/kotlin/okhttp3/Request.kt index 015905858..8e88157fb 100644 --- a/okhttp/src/main/kotlin/okhttp3/Request.kt +++ b/okhttp/src/main/kotlin/okhttp3/Request.kt @@ -109,7 +109,7 @@ class Request internal constructor( level = DeprecationLevel.ERROR) fun cacheControl(): CacheControl = cacheControl - override fun toString() = buildString { + override fun toString(): String = buildString { append("Request{method=") append(method) append(", url=") @@ -233,18 +233,18 @@ class Request internal constructor( } } - open fun get() = method("GET", null) + open fun get(): Builder = method("GET", null) - open fun head() = method("HEAD", null) + open fun head(): Builder = method("HEAD", null) - open fun post(body: RequestBody) = method("POST", body) + open fun post(body: RequestBody): Builder = method("POST", body) @JvmOverloads - open fun delete(body: RequestBody? = EMPTY_REQUEST) = method("DELETE", body) + open fun delete(body: RequestBody? = EMPTY_REQUEST): Builder = method("DELETE", body) - open fun put(body: RequestBody) = method("PUT", body) + open fun put(body: RequestBody): Builder = method("PUT", body) - open fun patch(body: RequestBody) = method("PATCH", body) + open fun patch(body: RequestBody): Builder = method("PATCH", body) open fun method(method: String, body: RequestBody?): Builder = apply { require(method.isNotEmpty()) { diff --git a/okhttp/src/main/kotlin/okhttp3/RequestBody.kt b/okhttp/src/main/kotlin/okhttp3/RequestBody.kt index b1e287be1..8d0426aa9 100644 --- a/okhttp/src/main/kotlin/okhttp3/RequestBody.kt +++ b/okhttp/src/main/kotlin/okhttp3/RequestBody.kt @@ -196,7 +196,7 @@ abstract class RequestBody { imports = ["okhttp3.RequestBody.Companion.toRequestBody"] ), level = DeprecationLevel.WARNING) - fun create(contentType: MediaType?, content: String) = content.toRequestBody(contentType) + fun create(contentType: MediaType?, content: String): RequestBody = content.toRequestBody(contentType) @JvmStatic @Deprecated( @@ -225,7 +225,7 @@ abstract class RequestBody { content: ByteArray, offset: Int = 0, byteCount: Int = content.size - ) = content.toRequestBody(contentType, offset, byteCount) + ): RequestBody = content.toRequestBody(contentType, offset, byteCount) @JvmStatic @Deprecated( @@ -235,6 +235,6 @@ abstract class RequestBody { imports = ["okhttp3.RequestBody.Companion.asRequestBody"] ), level = DeprecationLevel.WARNING) - fun create(contentType: MediaType?, file: File) = file.asRequestBody(contentType) + fun create(contentType: MediaType?, file: File): RequestBody= file.asRequestBody(contentType) } } diff --git a/okhttp/src/main/kotlin/okhttp3/Response.kt b/okhttp/src/main/kotlin/okhttp3/Response.kt index aeff0d66f..9b2e9bb6a 100644 --- a/okhttp/src/main/kotlin/okhttp3/Response.kt +++ b/okhttp/src/main/kotlin/okhttp3/Response.kt @@ -302,7 +302,7 @@ class Response internal constructor( checkNotNull(body) { "response is not eligible for a body and must not be closed" }.close() } - override fun toString() = + override fun toString(): String = "Response{protocol=$protocol, code=$code, message=$message, url=${request.url}}" open class Builder { diff --git a/okhttp/src/main/kotlin/okhttp3/ResponseBody.kt b/okhttp/src/main/kotlin/okhttp3/ResponseBody.kt index acdb1471e..e04e9b67f 100644 --- a/okhttp/src/main/kotlin/okhttp3/ResponseBody.kt +++ b/okhttp/src/main/kotlin/okhttp3/ResponseBody.kt @@ -266,11 +266,11 @@ abstract class ResponseBody : Closeable { contentType: MediaType? = null, contentLength: Long = -1L ): ResponseBody = object : ResponseBody() { - override fun contentType() = contentType + override fun contentType(): MediaType? = contentType - override fun contentLength() = contentLength + override fun contentLength(): Long = contentLength - override fun source() = this@asResponseBody + override fun source(): BufferedSource = this@asResponseBody } @JvmStatic @@ -281,7 +281,7 @@ abstract class ResponseBody : Closeable { imports = ["okhttp3.ResponseBody.Companion.toResponseBody"] ), level = DeprecationLevel.WARNING) - fun create(contentType: MediaType?, content: String) = content.toResponseBody(contentType) + fun create(contentType: MediaType?, content: String): ResponseBody = content.toResponseBody(contentType) @JvmStatic @Deprecated( @@ -291,7 +291,7 @@ abstract class ResponseBody : Closeable { imports = ["okhttp3.ResponseBody.Companion.toResponseBody"] ), level = DeprecationLevel.WARNING) - fun create(contentType: MediaType?, content: ByteArray) = content.toResponseBody(contentType) + fun create(contentType: MediaType?, content: ByteArray): ResponseBody = content.toResponseBody(contentType) @JvmStatic @Deprecated( @@ -301,7 +301,7 @@ abstract class ResponseBody : Closeable { imports = ["okhttp3.ResponseBody.Companion.toResponseBody"] ), level = DeprecationLevel.WARNING) - fun create(contentType: MediaType?, content: ByteString) = content.toResponseBody(contentType) + fun create(contentType: MediaType?, content: ByteString): ResponseBody = content.toResponseBody(contentType) @JvmStatic @Deprecated( @@ -315,6 +315,6 @@ abstract class ResponseBody : Closeable { contentType: MediaType?, contentLength: Long, content: BufferedSource - ) = content.asResponseBody(contentType, contentLength) + ): ResponseBody = content.asResponseBody(contentType, contentLength) } } diff --git a/okhttp/src/main/kotlin/okhttp3/Route.kt b/okhttp/src/main/kotlin/okhttp3/Route.kt index 6913ee8c1..a844e2b11 100644 --- a/okhttp/src/main/kotlin/okhttp3/Route.kt +++ b/okhttp/src/main/kotlin/okhttp3/Route.kt @@ -70,7 +70,7 @@ class Route( * * [rfc_2817]: http://www.ietf.org/rfc/rfc2817.txt */ - fun requiresTunnel() = address.sslSocketFactory != null && proxy.type() == Proxy.Type.HTTP + fun requiresTunnel(): Boolean = address.sslSocketFactory != null && proxy.type() == Proxy.Type.HTTP override fun equals(other: Any?): Boolean { return other is Route && diff --git a/okhttp/src/main/kotlin/okhttp3/TlsVersion.kt b/okhttp/src/main/kotlin/okhttp3/TlsVersion.kt index 79e8a586f..9d24b72df 100644 --- a/okhttp/src/main/kotlin/okhttp3/TlsVersion.kt +++ b/okhttp/src/main/kotlin/okhttp3/TlsVersion.kt @@ -33,7 +33,7 @@ enum class TlsVersion( message = "moved to val", replaceWith = ReplaceWith(expression = "javaName"), level = DeprecationLevel.ERROR) - fun javaName() = javaName + fun javaName(): String = javaName companion object { @JvmStatic diff --git a/okhttp/src/main/kotlin/okhttp3/internal/Util.kt b/okhttp/src/main/kotlin/okhttp3/internal/Util.kt index dcd6ff197..f702f2bc7 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/Util.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/Util.kt @@ -44,8 +44,10 @@ import okhttp3.Headers.Companion.headersOf import okhttp3.HttpUrl import okhttp3.OkHttp import okhttp3.OkHttpClient +import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response +import okhttp3.ResponseBody import okhttp3.ResponseBody.Companion.toResponseBody import okhttp3.internal.http2.Header import okio.Buffer @@ -59,14 +61,14 @@ import okio.Path import okio.Source @JvmField -val EMPTY_BYTE_ARRAY = ByteArray(0) +val EMPTY_BYTE_ARRAY: ByteArray = ByteArray(0) @JvmField -val EMPTY_HEADERS = headersOf() +val EMPTY_HEADERS: Headers = headersOf() @JvmField -val EMPTY_RESPONSE = EMPTY_BYTE_ARRAY.toResponseBody() +val EMPTY_RESPONSE: ResponseBody = EMPTY_BYTE_ARRAY.toResponseBody() @JvmField -val EMPTY_REQUEST = EMPTY_BYTE_ARRAY.toRequestBody() +val EMPTY_REQUEST: RequestBody = EMPTY_BYTE_ARRAY.toRequestBody() /** Byte order marks. */ private val UNICODE_BOMS = Options.of( @@ -79,7 +81,7 @@ private val UNICODE_BOMS = Options.of( /** GMT and UTC are equivalent for our purposes. */ @JvmField -val UTC = TimeZone.getTimeZone("GMT")!! +val UTC: TimeZone = TimeZone.getTimeZone("GMT")!! /** * Quick and dirty pattern to differentiate IP addresses from hostnames. This is an approximation @@ -633,7 +635,7 @@ internal fun MutableList.addIfAbsent(element: E) { } @JvmField -val assertionsEnabled = OkHttpClient::class.java.desiredAssertionStatus() +val assertionsEnabled: Boolean = OkHttpClient::class.java.desiredAssertionStatus() /** * Returns the string "OkHttp" unless the library has been shaded for inclusion in another library, @@ -642,7 +644,7 @@ val assertionsEnabled = OkHttpClient::class.java.desiredAssertionStatus() * instances; this makes it clear which is which. */ @JvmField -internal val okHttpName = +internal val okHttpName: String = OkHttpClient::class.java.name.removePrefix("okhttp3.").removeSuffix("Client") @Suppress("NOTHING_TO_INLINE") @@ -674,4 +676,4 @@ internal inline fun Iterable.filterList(predicate: T.() -> Boolean): List return result } -const val userAgent = "okhttp/${OkHttp.VERSION}" +const val userAgent: String = "okhttp/${OkHttp.VERSION}" diff --git a/okhttp/src/main/kotlin/okhttp3/internal/cache/CacheInterceptor.kt b/okhttp/src/main/kotlin/okhttp3/internal/cache/CacheInterceptor.kt index 7001ee6f9..b7db4576a 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/cache/CacheInterceptor.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/cache/CacheInterceptor.kt @@ -36,6 +36,7 @@ import okhttp3.internal.http.RealResponseBody import okhttp3.internal.http.promisesBody import okio.Buffer import okio.Source +import okio.Timeout import okio.buffer /** Serves requests from the cache and writes responses to the cache. */ @@ -197,7 +198,7 @@ class CacheInterceptor(internal val cache: Cache?) : Interceptor { return bytesRead } - override fun timeout() = source.timeout() + override fun timeout(): Timeout = source.timeout() @Throws(IOException::class) override fun close() { diff --git a/okhttp/src/main/kotlin/okhttp3/internal/concurrent/Task.kt b/okhttp/src/main/kotlin/okhttp3/internal/concurrent/Task.kt index 61cef201a..29345fb63 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/concurrent/Task.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/concurrent/Task.kt @@ -66,5 +66,5 @@ abstract class Task( this.queue = queue } - override fun toString() = name + override fun toString(): String = name } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskQueue.kt b/okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskQueue.kt index c9a9ea741..1ea324c0b 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskQueue.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/concurrent/TaskQueue.kt @@ -215,5 +215,5 @@ class TaskQueue internal constructor( return tasksCanceled } - override fun toString() = name + override fun toString(): String = name } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/connection/RealCall.kt b/okhttp/src/main/kotlin/okhttp3/internal/connection/RealCall.kt index 70a391139..12aa3e7c6 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/connection/RealCall.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/connection/RealCall.kt @@ -47,6 +47,7 @@ import okhttp3.internal.http.RetryAndFollowUpInterceptor import okhttp3.internal.platform.Platform import okhttp3.internal.threadName import okio.AsyncTimeout +import okio.Timeout /** * Bridge between OkHttp's application and network layers. This class exposes high-level application @@ -116,10 +117,10 @@ class RealCall( @Volatile private var exchange: Exchange? = null @Volatile var connectionToCancel: RealConnection? = null - override fun timeout() = timeout + override fun timeout(): Timeout = timeout @SuppressWarnings("CloneDoesntCallSuperClone") // We are a final type & this saves clearing state. - override fun clone() = RealCall(client, originalRequest, forWebSocket) + override fun clone(): Call = RealCall(client, originalRequest, forWebSocket) override fun request(): Request = originalRequest @@ -142,7 +143,7 @@ class RealCall( eventListener.canceled(this) } - override fun isCanceled() = canceled + override fun isCanceled(): Boolean = canceled override fun execute(): Response { check(executed.compareAndSet(false, true)) { "Already Executed" } @@ -453,7 +454,7 @@ class RealCall( ) } - fun retryAfterFailure() = exchangeFinder!!.retryAfterFailure() + fun retryAfterFailure(): Boolean = exchangeFinder!!.retryAfterFailure() /** * Returns a string that describes this call. Doesn't include a full URL as that might contain diff --git a/okhttp/src/main/kotlin/okhttp3/internal/connection/RealConnectionPool.kt b/okhttp/src/main/kotlin/okhttp3/internal/connection/RealConnectionPool.kt index c349be707..fe0b01759 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/connection/RealConnectionPool.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/connection/RealConnectionPool.kt @@ -41,7 +41,7 @@ class RealConnectionPool( private val cleanupQueue: TaskQueue = taskRunner.newQueue() private val cleanupTask = object : Task("$okHttpName ConnectionPool") { - override fun runOnce() = cleanup(System.nanoTime()) + override fun runOnce(): Long = cleanup(System.nanoTime()) } /** @@ -162,9 +162,7 @@ class RealConnectionPool( if (idleDurationNs > longestIdleDurationNs) { longestIdleDurationNs = idleDurationNs longestIdleConnection = connection - } else { - Unit - } + } else Unit } } } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt b/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt index 6801154b3..ece51d080 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt @@ -135,7 +135,7 @@ class CallServerInterceptor(private val forWebSocket: Boolean) : Interceptor { "close".equals(response.header("Connection"), ignoreCase = true)) { exchange.noNewExchangesOnConnection() } - if ((code == 204 || code == 205) && response.body?.contentLength() ?: -1L > 0L) { + if ((code == 204 || code == 205) && (response.body?.contentLength() ?: -1L) > 0L) { throw ProtocolException( "HTTP $code had non-zero Content-Length: ${response.body?.contentLength()}") } diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http/HttpHeaders.kt b/okhttp/src/main/kotlin/okhttp3/internal/http/HttpHeaders.kt index d61cb6d0c..94c6a0d24 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http/HttpHeaders.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http/HttpHeaders.kt @@ -154,7 +154,7 @@ private fun Buffer.skipCommasAndWhitespace(): Boolean { return commaFound } -private fun Buffer.startsWith(prefix: Byte) = !exhausted() && this[0] == prefix +private fun Buffer.startsWith(prefix: Byte): Boolean = !exhausted() && this[0] == prefix /** * Reads a double-quoted string, unescaping quoted pairs like `\"` to the 2nd character in each diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http/RequestLine.kt b/okhttp/src/main/kotlin/okhttp3/internal/http/RequestLine.kt index 917607d4d..8fb22418a 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http/RequestLine.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http/RequestLine.kt @@ -27,7 +27,7 @@ object RequestLine { * [HttpURLConnection.getHeaderFields], so it needs to be set even if the transport is * HTTP/2. */ - fun get(request: Request, proxyType: Proxy.Type) = buildString { + fun get(request: Request, proxyType: Proxy.Type): String = buildString { append(request.method) append(' ') if (includeAuthorityInRequestLine(request, proxyType)) { diff --git a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2.kt b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2.kt index eb65a18ba..1996b5ec1 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2.kt @@ -119,7 +119,7 @@ object Http2 { direction, streamId, length, formattedType, formattedFlags) } - internal fun formattedType(type: Int) = + internal fun formattedType(type: Int): String = if (type < FRAME_NAMES.size) FRAME_NAMES[type] else format("0x%02x", type) /** diff --git a/okhttp/src/main/kotlin/okhttp3/internal/internal.kt b/okhttp/src/main/kotlin/okhttp3/internal/internal.kt index df1b580bf..65b09261b 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/internal.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/internal.kt @@ -33,16 +33,16 @@ import okhttp3.internal.connection.RealConnection fun parseCookie(currentTimeMillis: Long, url: HttpUrl, setCookie: String): Cookie? = Cookie.parse(currentTimeMillis, url, setCookie) -fun cookieToString(cookie: Cookie, forObsoleteRfc2965: Boolean) = +fun cookieToString(cookie: Cookie, forObsoleteRfc2965: Boolean): String = cookie.toString(forObsoleteRfc2965) -fun addHeaderLenient(builder: Headers.Builder, line: String) = +fun addHeaderLenient(builder: Headers.Builder, line: String): Headers.Builder = builder.addLenient(line) -fun addHeaderLenient(builder: Headers.Builder, name: String, value: String) = +fun addHeaderLenient(builder: Headers.Builder, name: String, value: String): Headers.Builder = builder.addLenient(name, value) -fun cacheGet(cache: Cache, request: Request) = cache.get(request) +fun cacheGet(cache: Cache, request: Request): Response? = cache.get(request) fun applyConnectionSpec(connectionSpec: ConnectionSpec, sslSocket: SSLSocket, isFallback: Boolean) = connectionSpec.apply(sslSocket, isFallback) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/Android10Platform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/Android10Platform.kt index 1accc7d25..71b56a86e 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/Android10Platform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/Android10Platform.kt @@ -53,7 +53,7 @@ class Android10Platform : Platform() { ?.configureTlsExtensions(sslSocket, hostname, protocols) } - override fun getSelectedProtocol(sslSocket: SSLSocket) = + override fun getSelectedProtocol(sslSocket: SSLSocket): String? = // No TLS extensions if the socket class is custom. socketAdapters.find { it.matchesSocket(sslSocket) }?.getSelectedProtocol(sslSocket) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/AndroidPlatform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/AndroidPlatform.kt index 9febab21a..5c564a5d4 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/AndroidPlatform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/AndroidPlatform.kt @@ -83,7 +83,7 @@ class AndroidPlatform : Platform() { ?.configureTlsExtensions(sslSocket, hostname, protocols) } - override fun getSelectedProtocol(sslSocket: SSLSocket) = + override fun getSelectedProtocol(sslSocket: SSLSocket): String? = // No TLS extensions if the socket class is custom. socketAdapters.find { it.matchesSocket(sslSocket) }?.getSelectedProtocol(sslSocket) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/ws/MessageDeflater.kt b/okhttp/src/main/kotlin/okhttp3/internal/ws/MessageDeflater.kt index a7f7a0ec6..362fb07e5 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/ws/MessageDeflater.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/ws/MessageDeflater.kt @@ -61,5 +61,5 @@ class MessageDeflater( @Throws(IOException::class) override fun close() = deflaterSink.close() - private fun Buffer.endsWith(suffix: ByteString) = rangeEquals(size - suffix.size, suffix) + private fun Buffer.endsWith(suffix: ByteString): Boolean = rangeEquals(size - suffix.size, suffix) }