Skip to content

Commit

Permalink
Declare types & Cleanup (square#6842)
Browse files Browse the repository at this point in the history
* Declare types

* Code cleanup

* Declare types
  • Loading branch information
Goooler authored Aug 31, 2021
1 parent 98fae58 commit e1af67f
Show file tree
Hide file tree
Showing 45 changed files with 153 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 6 additions & 6 deletions mockwebserver/src/main/kotlin/mockwebserver3/MockResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions mockwebserver/src/main/kotlin/mockwebserver3/MockWebServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions mockwebserver/src/main/kotlin/mockwebserver3/PushPromise.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion okcurl/src/main/kotlin/okhttp3/curl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion okhttp-hpacktests/src/test/resources/hpack-test-case
Submodule hpack-test-case updated 510 files
20 changes: 10 additions & 10 deletions okhttp-testing-support/src/main/kotlin/okhttp3/CallEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sealed class CallEvent {
val domainName: String,
val inetAddressList: List<InetAddress>
) : CallEvent() {
override fun closes(timestampNs: Long) = DnsStart(timestampNs, call, domainName)
override fun closes(timestampNs: Long): CallEvent = DnsStart(timestampNs, call, domainName)
}

data class ConnectStart(
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions okhttp-tls/src/main/kotlin/okhttp3/tls/internal/der/Adapters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 1L,
codec = object : BasicDerAdapter.Codec<Boolean> {
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)
}
)
Expand All @@ -43,7 +43,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 2L,
codec = object : BasicDerAdapter.Codec<Long> {
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)
}
)
Expand All @@ -53,7 +53,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 2L,
codec = object : BasicDerAdapter.Codec<BigInteger> {
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)
}
)
Expand All @@ -63,7 +63,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 3L,
codec = object : BasicDerAdapter.Codec<BitString> {
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)
}
)
Expand All @@ -73,7 +73,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 4L,
codec = object : BasicDerAdapter.Codec<ByteString> {
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)
}
)
Expand All @@ -94,7 +94,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 6L,
codec = object : BasicDerAdapter.Codec<String> {
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)
}
)
Expand All @@ -104,7 +104,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 12L,
codec = object : BasicDerAdapter.Codec<String> {
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)
}
)
Expand All @@ -122,7 +122,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 19L,
codec = object : BasicDerAdapter.Codec<String> {
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)
}
)
Expand All @@ -137,7 +137,7 @@ internal object Adapters {
tagClass = DerHeader.TAG_CLASS_UNIVERSAL,
tag = 22L,
codec = object : BasicDerAdapter.Codec<String> {
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)
}
)
Expand Down Expand Up @@ -209,7 +209,7 @@ internal object Adapters {

/** Decodes any value without interpretation as [AnyValue]. */
val ANY_VALUE = object : DerAdapter<AnyValue> {
override fun matches(header: DerHeader) = true
override fun matches(header: DerHeader): Boolean = true

override fun fromDer(reader: DerReader): AnyValue {
reader.read("ANY") { header ->
Expand Down Expand Up @@ -329,7 +329,7 @@ internal object Adapters {
(adapter as DerAdapter<Any?>).toDer(writer, v)
}

override fun toString() = choices.joinToString(separator = " OR ")
override fun toString(): String = choices.joinToString(separator = " OR ")
}
}

Expand All @@ -346,7 +346,7 @@ internal object Adapters {
chooser: (Any?) -> DerAdapter<*>?
): DerAdapter<Any?> {
return object : DerAdapter<Any?> {
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
Expand Down
Loading

0 comments on commit e1af67f

Please sign in to comment.