ADFA-5048 (5/5): Add the Java extract-method action, edit builder and tests - #1821
Open
Daniel-ADFA wants to merge 4 commits into
Open
ADFA-5048 (5/5): Add the Java extract-method action, edit builder and tests#1821Daniel-ADFA wants to merge 4 commits into
Daniel-ADFA wants to merge 4 commits into
Conversation
Emits the two replacements: the region becomes a call, the new method appears after the anchor member. Descending document order is mandatory, not stylistic -- applyActionEdits applies each edit with line/column ranges against whatever the text is at that moment, so an earlier edit must never shift a later one. In Java the insertion always leads, since the anchor contains the region. The method is emitted fully indented at the anchor's own indentation, because code-action edits bypass the editor's auto-indent. Lines inside a text block are emitted byte-for-byte: their whitespace is part of the literal's value. Known consequence, tracked by ADFA-5081: nothing on that path calls beginBatchEdit, so this costs two undo steps and the intermediate state does not compile.
Registers "Extract method" in the Java code-actions menu with one new tooltip tag, editor.codeactions.extractmethod, fixed by ADFA-4821. One attributed compile produces the plan on a background thread; the sheet does pure string and offset arithmetic and never re-enters javac on confirm. No prepare() visibility gate: deciding extractability needs that compile, far too costly for the UI thread, so the action stays visible on any Java file and reports a specific refusal instead. The document version is re-read on confirm rather than trusted from the plan, and a plan built while the document was closed carries no version to compare, so it refuses rather than applying spans on trust. No new strings: every message this needs already exists from ADFA-5080.
41 cases across three layers, mirroring the extract-variable split so a failure localises: region resolution (parse only), the analysis rules and every refusal reason, and the emitted text. Every plan case feeds the rewritten file back through javac via compiles(). That is the assertion that matters for throws, static and captured types, where a signature that merely looks plausible is exactly the failure mode those rules exist to prevent. JavacFixture gains methodPlanAfter/methodPlanOver/applyMethod. Selecting by text rather than offsets keeps a snap-outward case readable: the selection is written exactly as a finger would have dragged it.
The feature doc states the Java deltas from the Kotlin spec against the same R1-R16 numbering, so the two read side by side, and records what is deliberately not supported. ADR 0013 anticipated its own revisit -- "reconsider once extract-method and inline-variable have landed and the UI surface is known". Both have now landed in both languages, and the trigger turned out to be duplication between two modules rather than a third appearing. The rule is now: a refactoring sheet used by more than one language server lives in :lsp:ui behind a plain-data contract; one used by exactly one stays in its own module, as Kotlin's inline-variable sheet does.
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 5 of 5 for ADFA-5048, the tip. Base: #1820. This is the PR that makes the feature reachable, and it carries the tests for the whole stack.
ExtractMethodAction(ide.editor.lsp.java.extractMethod), registered inJavaCodeActionsMenu, with a tooltip tag (editor.codeactions.extractmethod).ExtractMethodEdit.kt- builds the rewrite: the new declaration after the enclosing member, the call site in place, indentation matched to the anchor, text-block interiors untouched.JavaExtractMethodUi.kt- adapts the plan to the:lsp:uicontract from PR 1.docs/features/java-extract-method.md(R1-R16), status Implemented.Tests, 41 in this PR:
ExtractMethodRegionTest(8),ExtractMethodPlanTest(25),ExtractMethodEditTest(8), plusJavacFixturehelpers (methodPlanAfter,methodPlanOver,applyMethod).Verification
:lsp:java:testV7DebugUnitTest --tests "com.itsaky.androidide.lsp.java.refactor.*"plus the:lsp:ui,:lsp:refactor-coreand:lsp:kotlinrefactor suites: 419 tests, 0 failures, unchanged from before the split. The--testsfilter is required; the unfiltered:lsp:javasuite exceeds its 10-minute task timeout.Steps to QA are on the ticket.