Skip to content

Analyzer: I need the user visible import URL for a type #31556

Open
@matanlurey

Description

@matanlurey

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-apiIssues that impact the public API of the analyzer packagearea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions