schultek / super_annotations

Write your code generation functions naturally alongside your normal code. Define and use custom annotations in the same file or project.
https://pub.dev/packages/super_annotations
MIT License
39 stars 5 forks source link

Passing values across apply visits #13

Closed Dvergar closed 11 months ago

Dvergar commented 11 months ago

I'm trying to make a simple integer id generator for each visit of an apply call but it seems like super_annotation build is running so isolated that i cannot even read/write a static value. How would you handle such a case?

I'm trying to bind a unique id (incremented) to every class having a specific annotation.

Thanks 🙌.

schultek commented 11 months ago

Interesting case. Currently each file runs in a separate isolate, so there is no memory sharing between files.

You could try to actually write to a file to store the current value.

Dvergar commented 11 months ago

Thanks for the trick @schultek !

I made it work this way: I actually need a type id per class type so I'm storing the class name in a text file (if it does not exist) and get the index of the lines list of that very class name. The index becomes my type id.

This works but I'm a bit stuck with an endless growing file (i'm limiting this by storing the class name and not an id) as I cannot find a way to reset its content before or after a codegen and I can only make the runAfter property of @Codegen on a per-file basis.

A bit dirty as i'll probably have to clean the text file manually from time to time but it works for now 👍.