Skip to content

Macros: Could ClassTypeBuilder have access to user-defined class methods? #3809

Closed as not planned
@rrousselGit

Description

@rrousselGit

Hello again!

It appears that there is no way for a ClassTypeBuilder to obtain the methods of the annotated class.
This is particularly problematic in my case, because I need to add a mixin to the class that's based on the return value of a method present in said class.

Consider:

@riverpod
class Foo {
  Model build();
}

I want to generate:

import 'model.dart' as prefix0;

// New type:
class FooProvider extends Provider<prefix0.Model> {...}

// Added a mixin to the type that depend s
augment class Foo with Notifier<prefix0.Model> {
  ...
}

The problem is, both the newly declared type and the mixin applied on the existing type depends on the return value of that build method (and the output is not constant. There's some logic around it).
So I need to find that build method in a phase that's able to add new types and mixin. But there doesn't seem to be a way to do so, as far as I know.

For information, it is an error if users do not define that build method. And I don't care about cases where that build method is coming from a different macro or a mixins or a subclass. That build method should always be directly specified by users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problemstatic-metaprogrammingIssues related to static metaprogramming

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions