Skip to content

[pigeon] Tidy GeneratorAdapters to be const, with getters instead of fields#11131

Merged
srawlins merged 2 commits intoflutter:mainfrom
srawlins:const
Feb 26, 2026
Merged

[pigeon] Tidy GeneratorAdapters to be const, with getters instead of fields#11131
srawlins merged 2 commits intoflutter:mainfrom
srawlins:const

Conversation

@srawlins
Copy link
Contributor

While walking through the GeneratorAdapter code, I noticed a few oddities. While tidying things up, I found that each of the subclasses could have const constructors, which I think are preferred by the Flutter team.

  • The parent class, GeneratorAdapter, had a fileTypeList field which never stored a value. Each subclass implements the parent class, so the constructor was never called. I changed the field to a getter (for the interface), and removed the constructor.
  • Some adapters had a mutable instance field, String languageString which could be made static and const.
  • In each adapter subclass, I made the List<FileType> fileTypeList into a getter, to avoid the "Fields in const classes should not have initializers" enforced lint rule.
  • Some of the adapter subclasses had this.fileTypeList as a constructor parameter, but a value was essentially never passed in. (There was once instance in a test, but it had no effect.) So I removed this constructor parameter, moving the const default values to the getter value.
  • Then each constructor can be made const.
  • The implementation of _openSink had some unnecessary statements, so I made it more concise. The sink variable was unnecessary, and the file variable was only used in one else-branch, and so should be declared in that block.

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

Copy link

@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 refactors the GeneratorAdapter classes to enable const constructors. This involves converting the fileTypeList instance field to a getter in GeneratorAdapter and its subclasses, and changing languageString to a static const field. Additionally, the _openSink function is refactored for conciseness by removing unnecessary local variables.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Seems like this is old code that I would guess was just here for testing when it was added. This seems like a good improvement, thank you

@tarrinneal
Copy link
Contributor

@stuartmorgan-g more exceptions here I believe

@stuartmorgan-g
Copy link
Collaborator

This is a non-trivial (even if relatively straightforward) set of changes to production code, so our standard practice to version this for continuous release applies.

@srawlins
Copy link
Contributor Author

Thanks! I've bumped the version now.

@srawlins srawlins merged commit a27d7c5 into flutter:main Feb 26, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants