Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring and reducing code duplication in JsonReader #2083

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

oskaredv
Copy link

Refactored code that was duplicated in several methods into its own method. Five of those methods(peek, nextDouble, nextInt, nextLong and nextString) have high cyclomatic complexity and this will help reducing that a bit.

Copy link
Collaborator

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

There is one more pattern of this in the static block at the end of the file; do you want to replace this as well? Might be good then to make peeked() package-private to avoid a synthetic accessor method (I assume).
Maybe at that point it might also make sense to merge peeked() and doPeek() into one method?

(I am not a member of this project; the maintainers will probably give you more in-depth feedback)

gson/src/main/java/com/google/gson/stream/JsonReader.java Outdated Show resolved Hide resolved
@Marcono1234
Copy link
Collaborator

There is one more pattern of this in the static block at the end of the file; do you want to replace this as well? Might be good then to make peeked() package-private to avoid a synthetic accessor method (I assume).
Maybe at that point it might also make sense to merge peeked() and doPeek() into one method?

@oskaredv, do you want to address that as well? Or do you think that this is not worth it?

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.

2 participants