Skip to content

Refactor Parser and YamlReader#176

Merged
NathanSweet merged 5 commits intoEsotericSoftware:masterfrom
ramchaik:master
Mar 16, 2024
Merged

Refactor Parser and YamlReader#176
NathanSweet merged 5 commits intoEsotericSoftware:masterfrom
ramchaik:master

Conversation

@ramchaik
Copy link
Copy Markdown
Contributor

@ramchaik ramchaik commented Mar 16, 2024

After looking through the codebase, I was impressed by the code coverage and thought it was pretty amazing.

I made the decision to refactor certain small portions because I wanted to contribute to the project.

This PR refactors some methods of the Parser and YamlReader classes.

Parser

Decompose type conditional for implicit document in initProductionTable
  • The produce() method calls the helper method isNextTokenImplicitDocument() to check if the next token indicates an implicit document. This makes the condition clearer and easier to understand.

  • The isNextTokenImplicitDocument() method encapsulates the condition logic, making it self-explanatory.

  • If the condition is met, the parseImplicitDocument() method is called, which contains the logic for adding items to the parse stack. This separates concerns and improves code readability.

YamlReader

Rename method valueConvertedNumber() to parseNumber()
  • The method valueConvertedNumber has been renamed to parseNumber for improved clarity and consistency with naming conventions.

  • Enhances the readability of the codebase and better reflects the purpose of the method, which is to parse a string value into a Number object.

Extract method readScalarValue() from readValueInternal()
  • Extract the deserialization of scalar values into a new method.
  • Increases modularity of readValueInternal.
  • Improved the documentation by adding Javadoc for the readScalarValue() method.

Checklist

Checklist I followed before raising the PR.

  • Build the project
  • Run the tests after the refactor
Screenshot 2024-03-16 at 2 06 48 PM

Makes the name more descriptive and readable.
By reading the name you can tell it's a hashmap
which was not clear previously.
…nternal

Extract out the deserialization of scalar values to a new method.
Make readValueInternal more modular
@ramchaik ramchaik marked this pull request as draft March 16, 2024 16:49
@ramchaik ramchaik marked this pull request as ready for review March 16, 2024 17:09
Comment thread src/com/esotericsoftware/yamlbeans/YamlReader.java Outdated
@NathanSweet
Copy link
Copy Markdown
Member

Just the one comment. The other changes look good!

The method valueConvertedNumber has been renamed to parseNumber for improved clarity and consistency with naming conventions.

Enhances the readability of the codebase and better reflects the purpose of the method, which is to parse a string value into a Number object.
@NathanSweet NathanSweet merged commit 5bb07f1 into EsotericSoftware:master Mar 16, 2024
@NathanSweet
Copy link
Copy Markdown
Member

Cheers!

@ramchaik
Copy link
Copy Markdown
Contributor Author

Thanks @NathanSweet!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants