-
Notifications
You must be signed in to change notification settings - Fork 110
Add types to ConstantReader, fix issue with parts, migrate annotation helpers #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d070fad to
14e2274
Compare
aligns with URL behavior of _MirrorTypeChecker - which also returns the library URI (not the part)
| /// Returns a [DartType] representing this as a `Type` value. | ||
| /// | ||
| /// Throws [FormatException] if [isType] is `false`. | ||
| DartType get typeValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matanlurey – can't get the actual Type because runtime vs static.
| _object.toIntValue() ?? | ||
| _object.toStringValue() ?? | ||
| _object.toDoubleValue() ?? | ||
| (isSymbol ? this.symbolValue : null) ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Special case here to return an actual Symbol and not a String
| var annotationObject = annotation.constantValue; | ||
| try { | ||
| return _getValue(annotationObject, annotation.element.context.typeProvider); | ||
| return _getValue(annotation.constantValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK you always want to use computeConstantValue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ran a little test – in all cases constantValue and computeConstantValue return the same result. 🤷♂️
| dynamic _getValue(DartObject object) { | ||
| var reader = new ConstantReader(object); | ||
|
|
||
| if (reader.isNull) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: You can use anyValue for this purpose if you'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly no, we need to talk about that.
Type, List, and Map are weird – you get DartType.
I think we should update anyValue to exclude those and explain why.
| bool get isType => _object.toTypeValue() != null; | ||
|
|
||
| @override | ||
| DartType get typeValue => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistent use of ' please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done – enable a lint 😁
| @override | ||
| bool get isDouble => false; | ||
|
|
||
| @override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh...geez...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| @override | ||
| bool get isSymbol => false; | ||
|
|
||
| @override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| @override | ||
| get isType => false; | ||
|
|
||
| @override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
… helpers (dart-lang/source_gen#184) * ConstantReader: Add Symbol, Type, double * urlOfElement: use librarySource.uri aligns with URL behavior of _MirrorTypeChecker - which also returns the library URI (not the part) * Migrate annotation helpers to TypeChecker and ConstantReader
… helpers (dart-lang/source_gen#184) * ConstantReader: Add Symbol, Type, double * urlOfElement: use librarySource.uri aligns with URL behavior of _MirrorTypeChecker - which also returns the library URI (not the part) * Migrate annotation helpers to TypeChecker and ConstantReader
No description provided.