Skip to content

feature: Add CollectionWeaver with named weaver classes#383

Merged
xerial merged 2 commits intomainfrom
feature/weaver-factory
Jan 29, 2026
Merged

feature: Add CollectionWeaver with named weaver classes#383
xerial merged 2 commits intomainfrom
feature/weaver-factory

Conversation

@xerial
Copy link
Copy Markdown
Member

@xerial xerial commented Jan 29, 2026

Summary

  • Extract named weaver classes (OptionWeaver, SeqWeaver, MapWeaver, SetWeaver, ArrayWeaver, JavaListWeaver, JavaSetWeaver, JavaMapWeaver) from anonymous instances in Weaver.scala
  • Share helper methods (unpackArrayToBuffer, unpackMapToBuffer) between Weaver and PrimitiveWeaver via CollectionWeaver
  • Reduce code duplication (~400 lines removed, ~385 lines added as reusable classes)

Test plan

  • All existing Weaver tests pass (248 tests)
  • Full uni test suite passes (1291 tests)

🤖 Generated with Claude Code

Extract named weaver classes (OptionWeaver, SeqWeaver, MapWeaver, etc.)
from anonymous instances in Weaver.scala to improve debuggability and
reduce code duplication. Share helper methods (unpackArrayToBuffer,
unpackMapToBuffer) between Weaver and PrimitiveWeaver via CollectionWeaver.

This follows the pattern from airframe-codec where collection codecs
are named classes like SeqCodec, MapCodec, OptionCodec.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added doc Improvements or additions to documentation feature New feature labels Jan 29, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @xerial, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the Weaver implementation to enhance its modularity, debuggability, and maintainability. It achieves this by replacing anonymous weaver instances with explicit, named classes for various collection types and centralizing previously duplicated collection unpacking logic into a new CollectionWeaver object. This change streamlines the codebase and aligns it with established patterns, making future development and debugging more straightforward.

Highlights

  • Named Weaver Classes: Anonymous weaver instances for collections (Option, Seq, Map, Set, Array, JavaList, JavaSet, JavaMap) have been extracted into dedicated, named classes within CollectionWeaver.scala.
  • Shared Unpacking Logic: Common helper methods for unpacking arrays and maps (unpackArrayToBuffer, unpackMapToBuffer) are now centralized in the CollectionWeaver object, eliminating duplication across Weaver.scala and PrimitiveWeaver.scala.
  • Code Duplication Reduction: This refactoring significantly reduces code duplication, improving maintainability and consistency across the Weaver implementation by removing approximately 400 lines of duplicated code and adding about 385 lines of reusable classes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great refactoring effort that extracts collection-related weaver logic into a new CollectionWeaver.scala file. This significantly reduces code duplication in Weaver.scala and PrimitiveWeaver.scala, improving maintainability and debuggability by using named classes instead of anonymous ones. The changes are well-executed. I've added a couple of minor suggestions to make the creation of Java collections more concise.

Comment on lines +142 to +143
val list = java.util.ArrayList[Any](buffer.size)
buffer.foreach(e => list.add(e))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This manual population of the ArrayList can be made more concise by using the constructor that accepts a collection. The asJava converter can be used here to pass the Scala buffer to the Java collection's constructor.

            val list = new java.util.ArrayList[Any](buffer.asJava)

Comment on lines +163 to +164
val set = java.util.HashSet[Any](buffer.size)
buffer.foreach(e => set.add(e))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the JavaListWeaver, this manual population of the HashSet can be simplified by using the constructor that accepts a collection via asJava.

            val set = new java.util.HashSet[Any](buffer.asJava)

Use ArrayList/HashSet constructors with asJava instead of manual iteration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@xerial xerial merged commit d5dcc06 into main Jan 29, 2026
13 checks passed
@xerial xerial deleted the feature/weaver-factory branch January 29, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Improvements or additions to documentation feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant