Skip to content

Add static factory methods as initial transitions - #6

Merged
CatarinaGamboa merged 1 commit into
mainfrom
feat/5-static-factory-transitions
Oct 20, 2026
Merged

CatarinaGamboa merged 1 commit into
mainfrom
feat/5-static-factory-transitions

Conversation

@CatarinaGamboa

Copy link
Copy Markdown
Contributor

Closes #5.

Summary

  • Static factory methods are now initial transitions in the DFA, the same way constructors are. A factory method returns the class type and has a @Refinement that names a state on return, e.g. @Refinement("maybeTime(return)").
  • In classes the method must be static. In external-refinements interfaces (where static can't be declared) any method returning the class type counts.
  • Conditional refinements work as for constructors: flag ? open(return) : closed(return) gives two initial transitions, guarded by flag and !flag.
  • Factory transitions are listed after constructor transitions and use the existing constructorSignature field, labelled like UUID.fromString(String).
  • An interface with factory methods but no constructor no longer gets the unlabelled default initial transition into the first state. Classes without a declared constructor still get their implicit new X().

Tests

Three new tests: a class with static factories (plus a non-static method and a non-class-returning method that are ignored), the UUID interface from the issue, and an interface with factories but no constructor. mvn test: 23 tests, all pass.

🤖 Generated with Claude Code

Methods returning the class type with a @refinement on a state of
`return` (e.g. @refinement("maybeTime(return)")) are now initial
transitions in the state machine, labelled like UUID.fromString(String).
In classes they must be static; in external-refinements interfaces any
method returning the class type counts. Interfaces with factory methods
but no constructor no longer get the implicit default initial state.

Closes #5

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@CatarinaGamboa
CatarinaGamboa merged commit 2db9040 into main Oct 20, 2026
2 checks passed
@CatarinaGamboa
CatarinaGamboa deleted the feat/5-static-factory-transitions branch October 20, 2026 21:35
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.

Also add static methods in DFA

1 participant