Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: lib/src/mirror_loader.dart

Issue 880713002: add LibraryIdentifier (Closed) Base URL: git@github.com:dart-lang/static-init.git@master
Patch Set: code review updates Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/initializer.dart ('k') | lib/transformer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 library initialize.mirror_loader; 4 library initialize.mirror_loader;
5 5
6 import 'dart:collection' show Queue; 6 import 'dart:collection' show Queue;
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 import 'package:initialize/initialize.dart'; 9 import 'package:initialize/initialize.dart';
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (declaration is ClassMirror) { 138 if (declaration is ClassMirror) {
139 annotatedValue = declaration.reflectedType; 139 annotatedValue = declaration.reflectedType;
140 } else if (declaration is MethodMirror) { 140 } else if (declaration is MethodMirror) {
141 if (declaration.owner is! LibraryMirror) { 141 if (declaration.owner is! LibraryMirror) {
142 // TODO(jakemac): Support static class methods. 142 // TODO(jakemac): Support static class methods.
143 throw _TOP_LEVEL_FUNCTIONS_ONLY; 143 throw _TOP_LEVEL_FUNCTIONS_ONLY;
144 } 144 }
145 annotatedValue = (declaration.owner as ObjectMirror) 145 annotatedValue = (declaration.owner as ObjectMirror)
146 .getField(declaration.simpleName).reflectee; 146 .getField(declaration.simpleName).reflectee;
147 } else if (declaration is LibraryMirror) { 147 } else if (declaration is LibraryMirror) {
148 annotatedValue = declaration.qualifiedName; 148 var package;
149 var filePath;
150 Uri uri = declaration.uri;
151 if (uri.scheme == 'file' || uri.scheme.startsWith('http')) {
152 filePath = path.url.relative(
153 uri.path, from: path.url.dirname(_root.uri.path));
154 } else if (uri.scheme == 'package') {
155 var segments = uri.pathSegments;
156 package = segments[0];
157 filePath = path.url.joinAll(segments.getRange(1, segments.length));
158 } else {
159 throw new UnsupportedError('Unsupported uri scheme ${uri.scheme} for '
160 'library ${declaration}.');
161 }
162 annotatedValue =
163 new LibraryIdentifier(declaration.qualifiedName, package, filePath);
149 } else { 164 } else {
150 throw _UNSUPPORTED_DECLARATION; 165 throw _UNSUPPORTED_DECLARATION;
151 } 166 }
152 queue.addLast(() => meta.reflectee.initialize(annotatedValue)); 167 queue.addLast(() => meta.reflectee.initialize(annotatedValue));
153 } 168 }
154 } 169 }
155 170
156 // Filter function that returns true only if `meta` is an `Initializer`, 171 // Filter function that returns true only if `meta` is an `Initializer`,
157 // it passes the `typeFilter` and `customFilter` if they exist, and it has not 172 // it passes the `typeFilter` and `customFilter` if they exist, and it has not
158 // yet been seen. 173 // yet been seen.
(...skipping 11 matching lines...) Expand all
170 return true; 185 return true;
171 } 186 }
172 } 187 }
173 188
174 final _TOP_LEVEL_FUNCTIONS_ONLY = new UnsupportedError( 189 final _TOP_LEVEL_FUNCTIONS_ONLY = new UnsupportedError(
175 'Only top level methods are supported for initializers'); 190 'Only top level methods are supported for initializers');
176 191
177 final _UNSUPPORTED_DECLARATION = new UnsupportedError( 192 final _UNSUPPORTED_DECLARATION = new UnsupportedError(
178 'Initializers are only supported on libraries, classes, and top level ' 193 'Initializers are only supported on libraries, classes, and top level '
179 'methods'); 194 'methods');
OLDNEW
« no previous file with comments | « lib/src/initializer.dart ('k') | lib/transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698