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

Side by Side Diff: lib/dartdoc/mirrors/dart2js_mirror.dart

Issue 10779010: Parameters with function types supported + Added features in mirrors implementation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 8 years, 5 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('../../compiler/compiler.dart', prefix: 'diagnostics'); 7 #import('../../compiler/compiler.dart', prefix: 'diagnostics');
8 #import('../../compiler/implementation/elements/elements.dart'); 8 #import('../../compiler/implementation/elements/elements.dart');
9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api');
10 #import('../../compiler/implementation/scanner/scannerlib.dart'); 10 #import('../../compiler/implementation/scanner/scannerlib.dart');
(...skipping 18 matching lines...) Expand all
29 return name.startsWith('_'); 29 return name.startsWith('_');
30 } 30 }
31 31
32 List<ParameterMirror> _parametersFromFunctionSignature( 32 List<ParameterMirror> _parametersFromFunctionSignature(
33 Dart2JsMirrorSystem system, 33 Dart2JsMirrorSystem system,
34 Dart2JsMethodMirror method, 34 Dart2JsMethodMirror method,
35 FunctionSignature signature) { 35 FunctionSignature signature) {
36 var parameters = <ParameterMirror>[]; 36 var parameters = <ParameterMirror>[];
37 Link<Element> link = signature.requiredParameters; 37 Link<Element> link = signature.requiredParameters;
38 while (!link.isEmpty()) { 38 while (!link.isEmpty()) {
39 parameters.add(new Dart2JsParameterMirror(system, method, 39 parameters.add(new Dart2JsParameterMirror(
40 link.head, false)); 40 system, method, link.head, false));
41 link = link.tail; 41 link = link.tail;
42 } 42 }
43 link = signature.optionalParameters; 43 link = signature.optionalParameters;
44 while (!link.isEmpty()) { 44 while (!link.isEmpty()) {
45 parameters.add(new Dart2JsParameterMirror(system, method, 45 parameters.add(new Dart2JsParameterMirror(
46 link.head, true)); 46 system, method, link.head, true));
47 link = link.tail; 47 link = link.tail;
48 } 48 }
49 return parameters; 49 return parameters;
50 } 50 }
51 51
52 Dart2JsTypeMirror _convertTypeToTypeMirror( 52 Dart2JsTypeMirror _convertTypeToTypeMirror(
53 Dart2JsMirrorSystem system, 53 Dart2JsMirrorSystem system,
54 Type type, 54 Type type,
55 InterfaceType defaultType, 55 InterfaceType defaultType,
56 [FunctionSignature functionSignature]) { 56 [FunctionSignature functionSignature]) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 558
559 Uri uri() => _script.uri; 559 Uri uri() => _script.uri;
560 String text() => _script.text; 560 String text() => _script.text;
561 } 561 }
562 562
563 class Dart2JsParameterMirror extends Dart2JsElementMirror 563 class Dart2JsParameterMirror extends Dart2JsElementMirror
564 implements ParameterMirror { 564 implements ParameterMirror {
565 final MethodMirror _method; 565 final MethodMirror _method;
566 final bool _isOptional; 566 final bool _isOptional;
567 567
568 Dart2JsParameterMirror(Dart2JsMirrorSystem system, 568 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system,
569 MethodMirror method,
570 VariableElement element,
571 bool isOptional) {
572 if (element is FieldParameterElement) {
573 return new Dart2JsFieldParameterMirror(system,
574 method, element, isOptional);
575 }
576 return new Dart2JsParameterMirror._normal(system,
577 method, element, isOptional);
578 }
579
580 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system,
569 this._method, 581 this._method,
570 VariableElement element, 582 VariableElement element,
571 this._isOptional) 583 this._isOptional)
572 : super(system, element); 584 : super(system, element);
573 585
574 VariableElement get _variableElement() => _element; 586 VariableElement get _variableElement() => _element;
575 587
576 String get canonicalName() => simpleName(); 588 String get canonicalName() => simpleName();
577 589
578 String qualifiedName() => '${_method.qualifiedName()}#${simpleName()}'; 590 String qualifiedName() => '${_method.qualifiedName()}#${simpleName()}';
579 591
580 // TODO(johnniwinther): Provide
581 // [:_variableElement.variables.functionSignature:] instead of [:null:].
582 TypeMirror type() => _convertTypeToTypeMirror(system, 592 TypeMirror type() => _convertTypeToTypeMirror(system,
583 _variableElement.computeType(system.compiler), 593 _variableElement.computeType(system.compiler),
584 system.compiler.dynamicClass.computeType(system.compiler), 594 system.compiler.dynamicClass.computeType(system.compiler),
585 null); 595 _variableElement.variables.functionSignature);
586 596
587 String defaultValue() => null; // TODO(johnniwinther): How to compute this? 597 String defaultValue() {
588 598 if (hasDefaultValue()) {
589 bool hasDefaultValue() => false; // TODO(johnniwinther): How to compute this? 599 SendSet expression = _variableElement.cachedNode.asSendSet();
600 return expression.arguments.head.unparse();
601 }
602 return null;
603 }
604 bool hasDefaultValue() {
605 return _variableElement.cachedNode !== null &&
606 _variableElement.cachedNode is SendSet;
607 }
590 608
591 bool isOptional() => _isOptional; 609 bool isOptional() => _isOptional;
610
611 bool isInitializingFormal() => false;
612
613 FieldMirror initializedField() => null;
614 }
615
616 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror {
617
618 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system,
619 MethodMirror method,
620 FieldParameterElement element,
621 bool isOptional)
622 : super._normal(system, method, element, isOptional);
623
624 FieldParameterElement get _fieldParameterElement() => _element;
625
626 TypeMirror type() {
627 if (_fieldParameterElement.variables.cachedNode.type !== null) {
628 return super.type();
629 }
630 return _convertTypeToTypeMirror(system,
631 _fieldParameterElement.fieldElement.computeType(system.compiler),
632 system.compiler.dynamicClass.computeType(system.compiler),
633 _variableElement.variables.functionSignature);
634 }
635
636 bool isInitializingFormal() => true;
637
638 FieldMirror initializedField() => new Dart2JsFieldMirror(
639 _method.surroundingDeclaration(), _fieldParameterElement.fieldElement);
592 } 640 }
593 641
594 //------------------------------------------------------------------------------ 642 //------------------------------------------------------------------------------
595 // Declarations 643 // Declarations
596 //------------------------------------------------------------------------------ 644 //------------------------------------------------------------------------------
597 class Dart2JsInterfaceMirror extends Dart2JsObjectMirror 645 class Dart2JsInterfaceMirror extends Dart2JsObjectMirror
598 implements Dart2JsTypeMirror, InterfaceMirror { 646 implements Dart2JsTypeMirror, InterfaceMirror {
599 final Dart2JsLibraryMirror _library; 647 final Dart2JsLibraryMirror _library;
600 Map<String, Dart2JsMemberMirror> _members; 648 Map<String, Dart2JsMemberMirror> _members;
601 List<TypeVariableMirror> _typeVariables; 649 List<TypeVariableMirror> _typeVariables;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 if (node !== null) { 1359 if (node !== null) {
1312 var span = system.compiler.spanFromNode(node, script.uri); 1360 var span = system.compiler.spanFromNode(node, script.uri);
1313 return new Dart2JsLocation(script, span); 1361 return new Dart2JsLocation(script, span);
1314 } else { 1362 } else {
1315 var span = system.compiler.spanFromElement(_variable); 1363 var span = system.compiler.spanFromElement(_variable);
1316 return new Dart2JsLocation(script, span); 1364 return new Dart2JsLocation(script, span);
1317 } 1365 }
1318 } 1366 }
1319 } 1367 }
1320 1368
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698