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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 4
5 library mirrors_dart2js; 5 library mirrors_dart2js;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show LinkedHashMap; 8 import 'dart:collection' show LinkedHashMap;
9 import 'dart:io' show Path; 9 import 'dart:io' show Path;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 diagnosticHandler(uri, begin, end, message, kind); 258 diagnosticHandler(uri, begin, end, message, kind);
259 } 259 }
260 260
261 Compiler compiler = new apiimpl.Compiler(inputProvider, 261 Compiler compiler = new apiimpl.Compiler(inputProvider,
262 null, 262 null,
263 internalDiagnosticHandler, 263 internalDiagnosticHandler,
264 libraryRoot, packageRoot, options); 264 libraryRoot, packageRoot, options);
265 compiler.librariesToAnalyzeWhenRun = libraries; 265 compiler.librariesToAnalyzeWhenRun = libraries;
266 bool success = compiler.run(null); 266 bool success = compiler.run(null);
267 if (success && !compilationFailed) { 267 if (success && !compilationFailed) {
268 return new Future<MirrorSystem>.immediate( 268 return new Future<MirrorSystem>.value(new Dart2JsMirrorSystem(compiler));
269 new Dart2JsMirrorSystem(compiler));
270 } else { 269 } else {
271 return new Future<MirrorSystem>.immediateError( 270 return new Future<MirrorSystem>.error('Failed to create mirror system.');
272 'Failed to create mirror system.');
273 } 271 }
274 } 272 }
275 273
276 /** 274 /**
277 * Analyzes set of libraries and provides a mirror system which can be used for 275 * Analyzes set of libraries and provides a mirror system which can be used for
278 * static inspection of the source code. 276 * static inspection of the source code.
279 */ 277 */
280 // TODO(johnniwinther): Move dart:io dependent parts outside 278 // TODO(johnniwinther): Move dart:io dependent parts outside
281 // dart2js_mirror.dart. 279 // dart2js_mirror.dart.
282 Future<MirrorSystem> analyze(List<Path> libraries, 280 Future<MirrorSystem> analyze(List<Path> libraries,
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 ListConstant constant) 1617 ListConstant constant)
1620 : super(mirrors, constant); 1618 : super(mirrors, constant);
1621 1619
1622 ListConstant get _constant => super._constant; 1620 ListConstant get _constant => super._constant;
1623 1621
1624 int get length => _constant.length; 1622 int get length => _constant.length;
1625 1623
1626 Future<InstanceMirror> operator[](int index) { 1624 Future<InstanceMirror> operator[](int index) {
1627 if (index < 0) throw new RangeError('Negative index'); 1625 if (index < 0) throw new RangeError('Negative index');
1628 if (index >= _constant.length) throw new RangeError('Index out of bounds'); 1626 if (index >= _constant.length) throw new RangeError('Index out of bounds');
1629 return new Future<InstanceMirror>.immediate( 1627 return new Future<InstanceMirror>.value(
1630 _convertConstantToInstanceMirror(mirrors, _constant.entries[index])); 1628 _convertConstantToInstanceMirror(mirrors, _constant.entries[index]));
1631 } 1629 }
1632 } 1630 }
1633 1631
1634 class Dart2JsMapConstantMirror extends Dart2JsConstantMirror 1632 class Dart2JsMapConstantMirror extends Dart2JsConstantMirror
1635 implements MapInstanceMirror { 1633 implements MapInstanceMirror {
1636 List<String> _listCache; 1634 List<String> _listCache;
1637 1635
1638 Dart2JsMapConstantMirror(Dart2JsMirrorSystem mirrors, 1636 Dart2JsMapConstantMirror(Dart2JsMirrorSystem mirrors,
1639 MapConstant constant) 1637 MapConstant constant)
(...skipping 16 matching lines...) Expand all
1656 int get length => _constant.length; 1654 int get length => _constant.length;
1657 1655
1658 Iterable<String> get keys { 1656 Iterable<String> get keys {
1659 // TODO(johnniwinther): Return an unmodifiable list instead. 1657 // TODO(johnniwinther): Return an unmodifiable list instead.
1660 return new List<String>.from(_list); 1658 return new List<String>.from(_list);
1661 } 1659 }
1662 1660
1663 Future<InstanceMirror> operator[](String key) { 1661 Future<InstanceMirror> operator[](String key) {
1664 int index = _list.indexOf(key); 1662 int index = _list.indexOf(key);
1665 if (index == -1) return null; 1663 if (index == -1) return null;
1666 return new Future<InstanceMirror>.immediate( 1664 return new Future<InstanceMirror>.value(
1667 _convertConstantToInstanceMirror(mirrors, _constant.values[index])); 1665 _convertConstantToInstanceMirror(mirrors, _constant.values[index]));
1668 } 1666 }
1669 } 1667 }
1670 1668
1671 class Dart2JsTypeConstantMirror extends Dart2JsConstantMirror 1669 class Dart2JsTypeConstantMirror extends Dart2JsConstantMirror
1672 implements TypeInstanceMirror { 1670 implements TypeInstanceMirror {
1673 1671
1674 Dart2JsTypeConstantMirror(Dart2JsMirrorSystem mirrors, 1672 Dart2JsTypeConstantMirror(Dart2JsMirrorSystem mirrors,
1675 TypeConstant constant) 1673 TypeConstant constant)
1676 : super(mirrors, constant); 1674 : super(mirrors, constant);
(...skipping 25 matching lines...) Expand all
1702 index++; 1700 index++;
1703 }, includeBackendMembers: true, includeSuperMembers: true); 1701 }, includeBackendMembers: true, includeSuperMembers: true);
1704 } 1702 }
1705 } 1703 }
1706 return _fieldMapCache; 1704 return _fieldMapCache;
1707 } 1705 }
1708 1706
1709 Future<InstanceMirror> getField(String fieldName) { 1707 Future<InstanceMirror> getField(String fieldName) {
1710 Constant fieldConstant = _fieldMap[fieldName]; 1708 Constant fieldConstant = _fieldMap[fieldName];
1711 if (fieldConstant != null) { 1709 if (fieldConstant != null) {
1712 return new Future<InstanceMirror>.immediate( 1710 return new Future<InstanceMirror>.value(
1713 _convertConstantToInstanceMirror(mirrors, fieldConstant)); 1711 _convertConstantToInstanceMirror(mirrors, fieldConstant));
1714 } 1712 }
1715 return super.getField(fieldName); 1713 return super.getField(fieldName);
1716 } 1714 }
1717 } 1715 }
1718 1716
1719 class Dart2JsCommentInstanceMirror implements CommentInstanceMirror { 1717 class Dart2JsCommentInstanceMirror implements CommentInstanceMirror {
1720 final Dart2JsMirrorSystem mirrors; 1718 final Dart2JsMirrorSystem mirrors;
1721 final String text; 1719 final String text;
1722 String _trimmedText; 1720 String _trimmedText;
(...skipping 15 matching lines...) Expand all
1738 1736
1739 bool get hasReflectee => false; 1737 bool get hasReflectee => false;
1740 1738
1741 get reflectee { 1739 get reflectee {
1742 // TODO(johnniwinther): Which exception/error should be thrown here? 1740 // TODO(johnniwinther): Which exception/error should be thrown here?
1743 throw new UnsupportedError('InstanceMirror does not have a reflectee'); 1741 throw new UnsupportedError('InstanceMirror does not have a reflectee');
1744 } 1742 }
1745 1743
1746 Future<InstanceMirror> getField(String fieldName) { 1744 Future<InstanceMirror> getField(String fieldName) {
1747 if (fieldName == 'isDocComment') { 1745 if (fieldName == 'isDocComment') {
1748 return new Future.immediate( 1746 return new Future.value(
1749 new Dart2JsBoolConstantMirror.fromBool(mirrors, isDocComment)); 1747 new Dart2JsBoolConstantMirror.fromBool(mirrors, isDocComment));
1750 } else if (fieldName == 'text') { 1748 } else if (fieldName == 'text') {
1751 return new Future.immediate( 1749 return new Future.value(
1752 new Dart2JsStringConstantMirror.fromString(mirrors, text)); 1750 new Dart2JsStringConstantMirror.fromString(mirrors, text));
1753 } else if (fieldName == 'trimmedText') { 1751 } else if (fieldName == 'trimmedText') {
1754 return new Future.immediate( 1752 return new Future.value(
1755 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); 1753 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText));
1756 } 1754 }
1757 // TODO(johnniwinther): Which exception/error should be thrown here? 1755 // TODO(johnniwinther): Which exception/error should be thrown here?
1758 throw new UnsupportedError('InstanceMirror does not have a reflectee'); 1756 throw new UnsupportedError('InstanceMirror does not have a reflectee');
1759 } 1757 }
1760 } 1758 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698