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

Side by Side Diff: packages/initialize/lib/transformer.dart

Issue 3014633002: Roll to pickup pool changes (Closed)
Patch Set: Created 3 years, 2 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 | « packages/initialize/lib/src/mirror_loader.dart ('k') | packages/initialize/pubspec.yaml » ('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.transformer; 4 library initialize.transformer;
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 return uriToAssetId( 124 return uriToAssetId(
125 entryPoint, src, transform.logger, scripts[0].sourceSpan); 125 entryPoint, src, transform.logger, scripts[0].sourceSpan);
126 } 126 }
127 127
128 // Replaces script tags pointing to [originalDartFile] with [newDartFile] in 128 // Replaces script tags pointing to [originalDartFile] with [newDartFile] in
129 // [entryPoint]. 129 // [entryPoint].
130 void _replaceEntryWithBootstrap(Transform transform, dom.Document document, 130 void _replaceEntryWithBootstrap(Transform transform, dom.Document document,
131 AssetId entryPoint, AssetId originalDartFile, AssetId newDartFile) { 131 AssetId entryPoint, AssetId originalDartFile, AssetId newDartFile) {
132 var scripts = _getScripts(document) 132 var scripts = _getScripts(document).where((script) {
133 .where((script) {
134 var assetId = uriToAssetId(entryPoint, _getScriptAttribute(script), 133 var assetId = uriToAssetId(entryPoint, _getScriptAttribute(script),
135 transform.logger, script.sourceSpan); 134 transform.logger, script.sourceSpan);
136 return assetId == originalDartFile; 135 return assetId == originalDartFile;
137 }).toList(); 136 }).toList();
138 137
139 if (scripts.length != 1) { 138 if (scripts.length != 1) {
140 transform.logger 139 transform.logger
141 .error('Expected exactly one script pointing to $originalDartFile in ' 140 .error('Expected exactly one script pointing to $originalDartFile in '
142 '$entryPoint, but found ${scripts.length}.'); 141 '$entryPoint, but found ${scripts.length}.');
143 return; 142 return;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 readSuperClassAnnotations(superClass.superclass); 250 readSuperClassAnnotations(superClass.superclass);
252 if (_readAnnotations(superClass.element) && 251 if (_readAnnotations(superClass.element) &&
253 superClass.element.library != clazz.library) { 252 superClass.element.library != clazz.library) {
254 _logger.warning( 253 _logger.warning(
255 'We have detected a cycle in your import graph when running ' 254 'We have detected a cycle in your import graph when running '
256 'initializers on ${clazz.name}. This means the super class ' 255 'initializers on ${clazz.name}. This means the super class '
257 '${superClass.name} has a dependency on this library ' 256 '${superClass.name} has a dependency on this library '
258 '(possibly transitive).'); 257 '(possibly transitive).');
259 } 258 }
260 } 259 }
260
261 readSuperClassAnnotations(clazz.supertype); 261 readSuperClassAnnotations(clazz.supertype);
262 _readAnnotations(clazz); 262 _readAnnotations(clazz);
263 } 263 }
264 } 264 }
265 265
266 bool _readAnnotations(Element element) { 266 bool _readAnnotations(Element element) {
267 var found = false; 267 var found = false;
268 // analyzer 0.29 doesn't allow this optimization : 268 // analyzer 0.29 doesn't allow this optimization :
269 //if (element.metadata.isEmpty) return found; 269 //if (element.metadata.isEmpty) return found;
270 270
271 var metaNodes; 271 var metaNodes;
272 var node = element.computeNode(); 272 var node = element.computeNode();
273 if (node is SimpleIdentifier && node.parent is LibraryIdentifier) { 273 if (node is SimpleIdentifier && node.parent is LibraryIdentifier) {
274 metaNodes = node.parent.parent.metadata; 274 metaNodes = (node.parent.parent as AnnotatedNode).metadata;
275 } else if (node is ClassDeclaration || node is FunctionDeclaration) { 275 } else if (node is ClassDeclaration || node is FunctionDeclaration) {
276 metaNodes = node.metadata; 276 metaNodes = (node as AnnotatedNode).metadata;
277 } else { 277 } else {
278 return found; 278 return found;
279 } 279 }
280 280
281 metaNodes.where((Annotation metaNode) { 281 metaNodes.where((Annotation metaNode) {
282 // First filter out anything that is not a Initializer. 282 // First filter out anything that is not a Initializer.
283 var meta = metaNode.elementAnnotation; 283 var meta = metaNode.elementAnnotation;
284 var e = meta.element; 284 var e = meta.element;
285 if (e is PropertyAccessorElement) { 285 if (e is PropertyAccessorElement) {
286 return _isInitializer(e.variable.evaluationResult.value.type); 286 // 'as dynamic' is because evaluationResult is a property on an impl cla ss, e.g. one that
287 // isn't supposed to be used externally.
288 return _isInitializer(
289 (e.variable as dynamic).evaluationResult.value.type);
287 } else if (e is ConstructorElement) { 290 } else if (e is ConstructorElement) {
288 return _isInitializer(e.returnType); 291 return _isInitializer(e.returnType);
289 } 292 }
290 return false; 293 return false;
291 }).where((Annotation metaNode) { 294 }).where((Annotation metaNode) {
292 var meta = metaNode.elementAnnotation; 295 var meta = metaNode.elementAnnotation;
293 _seenAnnotations.putIfAbsent(element, () => new Set<ElementAnnotation>()); 296 _seenAnnotations.putIfAbsent(element, () => new Set<ElementAnnotation>());
294 return !_seenAnnotations[element].contains(meta); 297 return !_seenAnnotations[element].contains(meta);
295 }).forEach((Annotation metaNode) { 298 }).forEach((Annotation metaNode) {
296 var meta = metaNode.elementAnnotation; 299 var meta = metaNode.elementAnnotation;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 error = false; 491 error = false;
489 } else { 492 } else {
490 error = true; 493 error = true;
491 } 494 }
492 if (error) { 495 if (error) {
493 print('Bad value for "$field" in the initialize transformer. ' 496 print('Bad value for "$field" in the initialize transformer. '
494 'Expected either one String or a list of Strings.'); 497 'Expected either one String or a list of Strings.');
495 } 498 }
496 return files; 499 return files;
497 } 500 }
OLDNEW
« no previous file with comments | « packages/initialize/lib/src/mirror_loader.dart ('k') | packages/initialize/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698