chore: drop redundant toReplayable overrides and derive Method token from enum name#189
Merged
Merged
Conversation
…from name Remove a cluster of declarations in http/request that restate inherited behavior. All changes are behavior-preserving. - RequestBody: the base toReplayable() short-circuits to `this` whenever isReplayable() is true. The three private replayable bodies (BufferRequestBody, ByteArrayRequestBody, ResettableInputStreamRequestBody) each return true from isReplayable() and then override toReplayable to return `this` — exactly the inherited behavior. Drop the overrides. - FileRequestBody: same no-op override on the public body. The inherited toReplayable() still returns `this` (the FileRequestBody), so the transport-side `is FileRequestBody` sendfile(2) fast path keeps matching. Removing it leaves the IoProvider import unreferenced, so drop that too. - Method: every constant passed a wire-token string identical to its own enum name, and toString() returned that string — which is what the default enum toString() already produces. Drop the constructor parameter and the nine duplicated literals; expose the token as `method` computed from `name`, and let the default toString() stand. getMethod() stays public and callable. Public API: FileRequestBody.toReplayable(IoProvider) and Method.toString() were explicit overrides in the snapshot and are now inherited/default, so both lines drop from sdk-core.api (regenerated). getMethod() is unchanged. Closes #174
Moving the wire-token from a constructor parameter to a body-level computed property surfaces detekt's MemberNameEqualsClassName (the rule only inspects body-declared members, so it was dormant while method was a constructor val). The accessor is kept for API compatibility and the token genuinely is the method's name, so suppress the rule rather than rename.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes a small cluster of declarations in
http/requestthat restate behavior they already inherit. All three changes are behavior-preserving.Changes
RequestBody— drop the no-optoReplayableoverrides on the replayable bodiesThe base
RequestBody.toReplayable()short-circuits tothiswheneverisReplayable()istrue. The three private replayable bodies (BufferRequestBody,ByteArrayRequestBody,ResettableInputStreamRequestBody) all returntruefromisReplayable()and then re-declare an override that returnsthis— exactly what they'd inherit. The overrides are removed. (IoProviderstays imported; the basetoReplayablestill references it.)FileRequestBody— drop the no-op override and its now-unused importSame restatement, on the public body. The inherited
toReplayable()still returnsthis— the sameFileRequestBody— so transports that type-checkis FileRequestBodyfor the zero-copysendfile(2)path keep matching. With the override gone,import …io.IoProvideris unreferenced and is removed in the same change.Method— derive the wire token from the enum nameEvery constant passed a string literal identical to its own enum
name(GET("GET", …), …), andtoString()returned that string — which is what the default enumtoString()already produces. The constructor parameter and the nine duplicated literals are dropped; the token is now a computedval method: String get() = name, and the defaulttoString()stands.getMethod()remains public and callable, sorequest.method.method(okhttp adapter, Digest auth) andrequest.method.name(instrumentation) render the same token as before.API
Two explicit overrides become inherited/default, so their lines drop from
sdk-core/api/sdk-core.api(regenerated and committed):FileRequestBody.toReplayable (…IoProvider;)…Method.toString ()Ljava/lang/String;getMethod()is unchanged. TheMethodenum constructor is implicitly private and not in the snapshot, so dropping its parameter is not itself an API change.Verification
:sdk-core:compileKotlin, ktlint, andapiCheck(against the regenerated snapshot) pass.Method,RequestBody, andFileRequestBodytest suites pass — includingMethodTest'stoString()-equals-token check, which holds under the default enumtoString().Closes #174