dart-lang / dart-lang/source_gen
How to get full display type name from DartType?
- Dominant language
- Dart
- Stars
- 494
- Forks
- 115
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 3
Description
I have a property like:
```
Map> animations = {};
```
Before I can read its type when running analyzer with this code:
```
class MyGenerator extends Generator {
@override
String generate(LibraryReader library, BuildStep buildStep) {
ClassElement clazzElement; // get class Element from LibraryReader
for (var field in clazzElement.fields) {
var type = field.type.getDisplayString(withNullability: false); // it returns "Map>"
}
}
}
```
But now the field type result is `Map**>`
The [doc](https://pub.dev/documentation/analyzer/latest/dart_element_type/DartType/getDisplayString.html) says that I shouldn't depend on `getDisplayString()`, but I can't find any way to do this.
How can I get the full type `Map>` from my property?
Flutter doctor:
```
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.5.0-6.0.pre.30, on Mac OS X 10.15.7 19H1323 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.58.2)
[✓] VS Code (version 1.60.0-insider)
[✓] Connected device (2 available)
• No issues found!
```
Contributor guide
Research direction
Start with the LibraryReader, ClassElement.fields, and DartType.getDisplayString(withNullability: false) shown in the issue, then compare the analyzer behavior for the nested Map> property. Done means identifying a supported way to recover the full nested type name without relying on the deprecated display-string behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100