Refractoring code smells#220
Open
DarunNayeem wants to merge 2 commits into
Open
Conversation
Before, the library mixed startup work, indexing, and ordering logic directly inside the static initializer in EmojiManager.java, and EmojiParser.java repeated nearly identical anonymous transformer logic for aliases and HTML encodings. EmojiLoader.java also used manual stream handling and verbose JSON field branching. After, the bootstrap logic is split into small helpers for indexing and sorting, the parser’s transformation rules are centralized in dedicated methods, and the loader uses simpler field extraction and safer cleanup. I also preserved variation selectors in parser candidates because that was required to keep the round-trip emoji tests passing. This refactor improves readability and maintainability without changing the library’s public API. It addresses three areas: static initialization in the emoji manager, duplicated transformation logic in the parser, and stream/JSON handling in the loader. The parser change also fixes a loss of variation selector data that broke round-trip behavior on some emoji sequences.
There was a problem hiding this comment.
Pull request overview
Refactors core emoji initialization and parsing code to reduce duplication, improve readability, and preserve variation selector data to maintain round-trip behavior for certain emoji sequences.
Changes:
- Extracted repeated
EmojiTransformerswitch logic inEmojiParserinto dedicated helper methods and added variation-selector support to unicode candidates and extraction. - Split
EmojiManagerstatic initialization into smaller indexing/sorting helpers and added safer stream cleanup. - Simplified JSON field extraction and made stream-to-string reading safer in
EmojiLoader.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/com/vdurmont/emoji/EmojiParser.java | Centralizes transformer logic and preserves variation selectors in unicode candidate handling and extraction. |
| src/main/java/com/vdurmont/emoji/EmojiManager.java | Refactors static initialization into helper methods and improves stream cleanup. |
| src/main/java/com/vdurmont/emoji/EmojiLoader.java | Simplifies JSON optional-field handling and ensures reader cleanup via finally. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Before, the library mixed startup work, indexing, and ordering logic directly inside the static initializer in EmojiManager.java, and EmojiParser.java repeated nearly identical anonymous transformer logic for aliases and HTML encodings. EmojiLoader.java also used manual stream handling and verbose JSON field branching.
After, the bootstrap logic is split into small helpers for indexing and sorting, the parser’s transformation rules are centralized in dedicated methods, and the loader uses simpler field extraction and safer cleanup. I also preserved variation selectors in parser candidates because that was required to keep the round-trip emoji tests passing.
This refactor improves readability and maintainability without changing the library’s public API. It addresses three areas: static initialization in the emoji manager, duplicated transformation logic in the parser, and stream/JSON handling in the loader. The parser change also fixes a loss of variation selector data that broke round-trip behavior on some emoji sequences.