Open
Description
Problem
Internally we have a dependency injection package that uses code generation.
Basically it looks at the following pattern:
import 'dart:io';
import 'package:some_di/some_di.dart';
import 'app.g.dart' as generated;
@module
class HttpModule {
@provide
HttpClient provideHttpClient() => new HttpClient();
}
abstract class AppInjector {
factory AppInjector() = generated.$AppInjector;
}
And generates some boilerplate code like so:
import 'dart:_http';
import 'app.dart';
class $AppInjector implements AppInjector {
HttpClient provideHttpClient() => new HttpClient();
}
See the problem? It has "resolved" HttpClient
to belonging to dart:_http
, which is not a user-importable library. This is because when we ask for the library URL of an Element
, we get back the absolute location - which is good for canonicalization, but bad for generating valid code, in this case.
What is the best way to get back dart:io
, instead, using the analyzer API?