ADFA-5048 (4/5): Derive the extracted method signature, body and call site - #1820
Open
Daniel-ADFA wants to merge 1 commit into
Open
Conversation
Derives everything the sheet renders and the edit builder emits for one region, or the typed reason it cannot be moved faithfully (ADR 0014). ThrownTypes.kt carries the one rule with no Kotlin analogue: the region's thrown checked types, from invocation and constructor thrownTypes, throw expressions and a try-with-resources close(), minus anything a try *inside* the region catches. Both halves matter -- under-declaring leaves the moved body uncompilable, over-declaring breaks the call site, which is only obliged to handle what the region actually threw. Copying the anchor's own throws clause instead is wrong in exactly the commonest case, a region inside a try whose method declares nothing. A generic `throws E` declines: getThrownTypes reports the callee's declared type variable and javac's public API does not expose what it was inferred to here. MethodSignature.kt is the entry point where the primitives meet, plus the two region-kind-specific parts: the single output the following code still needs, and the exits that decline (with the tail return as the one exception). ExtractMethodPlan.kt is the plain-data result, carrying a typed refusal rather than merely being empty, because "why not" is most of what this refactoring has to say. Java uses 8 of Kotlin's 13 reasons; OutputNotReturnable has no counterpart, since every Java local can be received back as `T x = extracted()`. Java has no local-method form, so unlike Kotlin there is no insert-before case and no "nowhere to anchor" refusal: a lambda in a field initializer anchors on the field.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
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.
Stack 4 of 5 for ADFA-5048. Base: #1819. No caller until PR 5.
The signature analysis: given a region, decide what the extracted method looks like.
MethodSignature.kt-analyseRegionis the entry point. Derives parameters, the return type, outputs and exits, the tail-return shape, the body and call-site forms,methodNamesInfor taken names,suggestedNameFor, andtextBlockSpansInso re-indentation leaves text-block interiors byte-for-byte.ThrownTypes.kt- the derivedthrowsclause.ExtractMethodPlan.kt- the result types the sheet and the edit builder consume:MethodParameter,ExtractedBody,CallSiteForm(Call,CallStatement,AssignOutput,Return),ExtractMethodCandidate,ExtractMethodPlan, andExtractionRefusalwith eight named reasons.ExtractMethodPlanner.kt- assembles candidates from the regions PR 2 resolves.A refusal is a designed outcome, not an error: each reason names the construct in the way, because one generic message reads as the feature being broken (ADR 0014).