Skip to content

Comments

Fix #129: Add covariant return types for builder methods#140

Open
gnodet wants to merge 1 commit intomainfrom
fix/129-builder-method-ordering
Open

Fix #129: Add covariant return types for builder methods#140
gnodet wants to merge 1 commit intomainfrom
fix/129-builder-method-ordering

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Feb 21, 2026

Summary

  • Override precedingWhitespace(String) and parent(ContainerNode) in all concrete Node subclasses (Element, Comment, Text, ProcessingInstruction, Document) to return their specific type
  • Enables fluent method chaining in any order, e.g. Element.of("foo").precedingWhitespace(" ").innerPrecedingWhitespace(" ")

Test plan

  • precedingWhitespace before innerPrecedingWhitespace works
  • Reverse order also works
  • Covariant return types work on all node types (Element, Comment, Text, PI)

Closes #129

…types

Element.of("foo").precedingWhitespace("  ").innerPrecedingWhitespace("  ") failed
because Node.precedingWhitespace(String) returned Node, losing the Element type.
Override precedingWhitespace(String) and parent(ContainerNode) in Element, Comment,
Text, ProcessingInstruction, and Document to return their specific type, enabling
fluent chaining in any order.
@github-actions
Copy link

✅ CI Build PASSED

Build Status: PASSED
Java Version: 21
Maven Command: ./mvnw verify

🎉 All tests passed! The build is ready for merge.

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

Labels

None yet

Projects

None yet

1 participant