Skip to content

Commit 4261976

Browse files
committed
Use library URI (not name) to look up annotation
Fixes #100
1 parent c659b90 commit 4261976

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.2-dev
2+
3+
* Use library URIs (not names) to look up annotations in the mirror system.
4+
15
## 0.5.1+7
26

37
* Generate valid strong-mode code for typed lists.

lib/src/annotation.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,22 @@ DeclarationMirror _getDeclarationMirrorFromType(InterfaceType type) {
192192
var system = currentMirrorSystem();
193193

194194
// find library
195-
var libElement = type.element.library;
196-
var libNameSymbol = new Symbol(libElement.name);
197-
var libMirror = system.findLibrary(libNameSymbol);
195+
var libraryUri = type.element.library.librarySource.uri;
196+
197+
if (libraryUri.scheme == 'asset') {
198+
// see if it looks like a package
199+
var segs = libraryUri.pathSegments.toList();
200+
if (segs.length >= 2 && segs[1] == 'lib') {
201+
segs.removeAt(1);
202+
libraryUri = new Uri(scheme: 'package', pathSegments: segs);
203+
} else {
204+
// TODO: we should support this. Just would take some time.
205+
throw new UnsupportedError('Generator annotations must be defined within '
206+
'a package lib directory.');
207+
}
208+
}
209+
210+
var libMirror = system.libraries[libraryUri];
198211

199212
// find class symbol
200213
var typeNameSymbol = new Symbol(type.name);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_gen
2-
version: 0.5.1+7
2+
version: 0.5.2-dev
33
author: Dart Team <[email protected]>
44
description: Automatic sourcecode generation for Dart
55
homepage: https://github.com/dart-lang/source_gen

0 commit comments

Comments
 (0)