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
const predefinedAnnotation =SomeAnnotation('this is predefined');
@predefinedAnnotation// this is the first case@SomeAnnotation('this is defined as it's needed') // this is the second caseclass SomeClass {}
In this case, I am currently getting a declaration by using below code.
// `element `is `ClassElement` of SomeClassfor (final annotations in element. metadata) {
print(annotations.toSource());
}
In the first case (predefined annotation), it only prints predefinedAnnotation, the name of the constant variable.
In the second case, it prints what I want. The full code of @SomeAnnotation('this is defined as it's needed').
Is there a way to get the full code in case of predefinedAnnotation?
The text was updated successfully, but these errors were encountered:
The first step is to get a DartObject for the annotation. I think annotations.computConstantValue() works in most cases, but if the annotation is not resolvable it may return null. With the DartObject you can use a ConstantReader to read fields from it. https://pub.dev/documentation/source_gen/latest/source_gen/ConstantReader-class.html
See also LibraryReader which has methods for finding annotated elements and creating a ConstantReader for the annotations.
In this case, I am currently getting a declaration by using below code.
In the first case (predefined annotation), it only prints
predefinedAnnotation
, the name of the constant variable.In the second case, it prints what I want. The full code of
@SomeAnnotation('this is defined as it's needed')
.Is there a way to get the full code in case of
predefinedAnnotation
?The text was updated successfully, but these errors were encountered: