Skip to content

Find a solution for single-add situations like utility methods #223

Closed
@natebosch

Description

@natebosch

Sometime a Generator can run 1 or more times on a library. It might want to write some code that should only appear once in the output, regardless of how many elements were run. Potential use cases are utility methods, and (maybe?) imports for standalone builders.

A few ways we could solve this:

  1. Add an argument to the Generator.generate method that has an explicit way to add a utility method and knows it should only add it once.
  2. Make the Generators run more explicitly serially and operate on a StringBuffer or similar so they can see previous content and check whether it contains certain strings already.
  3. Change the api Generator.generate(List<Element> elements, BuildStep buildStep) and have it run once per library with all elements available together.
  4. Add some sort of 'context' object, maybe a Map<String, Object>, which gets passed repeatedly to each Generator and allows it to communicate with itself across elements in the library.

cc @matanlurey

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions