You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi ! I've been using the workaround described here to type my annotation but now I'm having trouble trying to get the ast of my annotation. For example say I have the user define the root of a firebase collection
part'root.fire.dart';
// UndefinedType is not created until I generate output in my `root.fire.dart` fileconst_UsersCollection=Collection<UndefinedType>(name:'users');
@rootclassDatabasewith_$Database {
// TODO: This should have the option to pass in an app
@_UsersCollectionDatabase._();
staticfinal instance =Database._();
}
I can get annotations over the named constructor _ but how do I then get the non-synthetic element declaration const _UsersCollection.
I tried this but because I always get back a synthetic element from declaration calling getElementDeclaration by design returns null
@overrideFutureOr<String> generateForAnnotatedElement(
Element element,
ConstantReader annotation,
BuildStep buildStep,
) async {
if (element is!ClassElement) {
// ...
}
final stringBuffer =StringBuffer();
final constructor = element.constructors.singleWhere(
(constructor) => constructor.displayName =='_',
orElse: () {
// ...
},
);
for (final annotation in constructor.metadata) {
final annotationElement = annotation.element!.declaration!;
final elementDecleration = element.library.session
.getParsedLibraryByElement(element.library)
.getElementDeclaration(annotationElement);
// elementDecleration is null i think because annotationElement is syntheticfinal node = element.node; // throwsfinalString type =_getUndefinedType(node);
_createClassWithName(type);
}
}
I want to get the ast because I need to get the undefined type on Collection<T> so I can use that name to build it. Any help is much appreciated.
The text was updated successfully, but these errors were encountered:
In this case I think the following will get you close
final annotationElement = annotation.element;
// note, the following may not work if the code has a different pattern// for example if the annotation isn't a top level variable...final variable = (annotationElement asPropertyAccessorElement).variable;
final astNode =await buildStep.resolver.astNodeFor(variable);
Hi ! I've been using the workaround described here to type my annotation but now I'm having trouble trying to get the ast of my annotation. For example say I have the user define the root of a firebase collection
I can get annotations over the named constructor
_
but how do I then get the non-synthetic element declarationconst _UsersCollection
.I tried this but because I always get back a synthetic element from
declaration
callinggetElementDeclaration
by design returns nullI want to get the ast because I need to get the undefined type on
Collection<T>
so I can use that name to build it. Any help is much appreciated.The text was updated successfully, but these errors were encountered: