Skip to content

V8: Split Class (Extract Class) refactoring - #394

Open
ericwinger wants to merge 6 commits into
mainfrom
eric/RBsplitClassV8
Open

V8: Split Class (Extract Class) refactoring#394
ericwinger wants to merge 6 commits into
mainfrom
eric/RBsplitClassV8

Conversation

@ericwinger

Copy link
Copy Markdown
Member

Summary

V8 of the server-side RB refactoring catalog (#252): Split Class / Extract Class. Extract a cohesive subset of a class's own instance variables — and the methods that use them — into a new component class, leaving the source holding a lazy reference to it (a has-a relationship). Classic Fowler Extract Class, non-committing, previewed and applied through the same engine/panel machinery as the rest of the family.

Explorer class-row / hierarchy command "Split Class…": pick the ivars to extract → name the new class → pre-flight → paginated preview → apply (server-side, all-or-nothing, never commits).

How it works

  • Engine GsSplitClassRefactoring reuses V6/V7's #classAdd change kind and the reversion-by-newVersionOf: machinery. Given source S and extract set E, the movable methods are S's instance methods that touch an E ivar. Apply: create component N carrying E + the movable methods; reversion S to drop E, add a component ivar + a lazy accessor (n ^n ifNil: [n := N new]) + a delegating stub per moved method (so S's external API is unchanged); reparent S's descendant subtree onto the freshly-versioned S.
  • Clean-cut preconditions (declines, surfaced in the preview banner) keep the MVP to a self-contained subset so the delegation is behavior-preserving: a movable method that also touches a retained ivar, sends super, or self-sends a method that stays behind; a descendant that references an extracted ivar; name / component-ivar collisions; empty or invalid inputs. (The self-send guard correctly declines even when the self-sent selector is understood by Object but overridden on the source — otherwise the moved method would silently resolve to Object's implementation.)
  • No instance migration — deliberate (explained in the panel banner). Migration must commit (which breaks the family's "apply never commits" contract), and for extract class GemStone's by-name migration would silently drop the extracted ivars' values, since they no longer exist on the new source shape. Correct migration needs a custom per-instance transform → deferred (below). Existing instances safely keep their prior class version.

Tests

  • Engine SUnit GsSplitClassRefactoringTest — analysis, every decline, preview staging, apply-path survival (component and source both sides, behavior preserved through the delegators incl. keyword-argument weaving, retained-method + class-side survival, subclass reparent), pagination + expired session, no-commit. 36 / 36 on 3.6.2 AND 3.7.5 (topaz stage + run + abort).
  • Client unit — parsers (including every defensive-throw branch), command orchestration + all error/early-exit paths, panel message-handling guards, query builders (dict-scoped and unscoped), and panel HTML rendering.
  • GCI integration refactoringSplitClass.integration.test.ts — asserts applied stone state on both sides (including a retained method no change set mentions, and the reparented subclass's own methods), pagination across byte-bounded pages, and expired-token handling; engine-gated via requireServerPluginFeature, so it runs in the plugin CI pass and skips-with-reason on a bare stone.

Full client suite green; lint / format:check / compile clean.

Follow-ups (deferred to their own PRs)

  • Keep-and-delegate — instead of declining straddling / super-sending / retained-calling methods, keep them on the source and rewrite their extracted-ivar access through generated component accessors. One mechanism lifts the D1–D4 declines and turns "clean partitions only" into "splits real classes."
  • Opt-in instance migration — a committing, per-instance transform that reconstructs the component from the moved values (the correct migration a naive by-name migrate can't do).

Verification

  • Engine SUnit both boundaries: 36/36 on 3.6.2 and 3.7.5.
  • Full client suite (client + server + mcp) green via the pre-push gate.
  • Manually F5-verified on a 3.7.5 dev stone: happy path, guarantees (non-commit, non-migration, behavior through delegators, subclass reparent, abort, cancel), and all declines.

🤖 Generated with Claude Code

ericwinger and others added 6 commits August 6, 2026 12:28
Engine GsSplitClassRefactoring (reuses V6/V7's #classAdd + reversion machinery): extract a chosen
set of the source's OWN instance variables -- and the methods that use them -- into a new component
class; the source keeps a lazy accessor + a delegating stub per moved method; reversion the source
+ reparent its subtree. Clean-cut precondition declines straddling/super/retained-calling methods,
descendant use of an extracted ivar, name collisions. All-or-nothing, no commit, no migration.
SUnit 25/25 on BOTH 3.6.2 and 3.7.5; full engine suite 548/0/0 on 3.6.2.

Client: splitClass command/preview/panel/panelHtml + previewSplitClass query builder + browserQueries
wrappers + Explorer "Split Class..." command/menu wiring. Host-side double-apply latch,
ensureRbSupport gate, no-false-success. 61 client unit tests; tsc + eslint clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…-code removal

- package.json: point the split-class hierarchy menu clause at the renamed view id
  gemstoneExplorerClassHierarchy (a main-merge artifact; caught by explorerViewRegistration).
- splitClassCommand: toast when the ivar pick is confirmed with nothing selected, so it does
  not read as a crash; an Escape/cancel stays silent.
- Engine: delete the unreachable applyMethodRemove: method + the #methodRemove branch in
  applyChange:, and correct the buildChangeSet docstring (the copy-forward already omits moved
  methods, so nothing stages #methodRemove). Payloads rebuilt (manifest 59->58 methods).
  NOT reinstalled or re-tested here -- retest in the review session.
- Tests: new refactoringSplitClass.integration.test.ts (apply-path survival both sides,
  pagination, expired token) and new splitClassPanelHtml.test.ts; extend the preview/command/
  panel/query unit tests to cover the defensive parse throws, command error paths, panel
  guards, and name validation. Engine SUnit +8 (binary/keyword delegators, pagination +
  expired session, previewJsonString, analyzeClass: convenience, clearToken) = 33/33 both
  boundaries.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- HIGH: computeAnalysis self-send guard no longer treats an Object-understood
  selector as safe to leave behind when the SOURCE overrides it (a movable
  method self-sending e.g. #printString would move and silently resolve to the
  component's inherited Object impl, losing the override). Guard is now: the
  selector moves too, OR Object understands it AND the source does not override
  it. Adds a decline test + a non-override control (negative-control verified
  red against the old guard).
- MED: gate both split-class context-menu entries on gemstone.rbSupportAvailable,
  matching every sibling in the 3_refactor group.
- MED: drop the divergent local asCount for the shared previewCounts asCount
  (Math.trunc truncation, not pass-through); adds a truncation-contract test.
- LOW: add class-side method survival coverage (metaclass copy-forward on the
  reversioned source + reparented subclass).

Engine SUnit 36/36 on BOTH 3.6.2 and 3.7.5; full client suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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