Skip to content

ADFA-5048 (4/5): Derive the extracted method signature, body and call site - #1820

Open
Daniel-ADFA wants to merge 1 commit into
feat/ADFA-5048-region-analysis-primitivesfrom
feat/ADFA-5048-signature-analysis
Open

ADFA-5048 (4/5): Derive the extracted method signature, body and call site#1820
Daniel-ADFA wants to merge 1 commit into
feat/ADFA-5048-region-analysis-primitivesfrom
feat/ADFA-5048-signature-analysis

Conversation

@Daniel-ADFA

@Daniel-ADFA Daniel-ADFA commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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 - analyseRegion is the entry point. Derives parameters, the return type, outputs and exits, the tail-return shape, the body and call-site forms, methodNamesIn for taken names, suggestedNameFor, and textBlockSpansIn so re-indentation leaves text-block interiors byte-for-byte.
  • ThrownTypes.kt - the derived throws clause.
  • ExtractMethodPlan.kt - the result types the sheet and the edit builder consume: MethodParameter, ExtractedBody, CallSiteForm (Call, CallStatement, AssignOutput, Return), ExtractMethodCandidate, ExtractMethodPlan, and ExtractionRefusal with 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).

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.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants