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

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

Issue 11358005: ParameterMirror extends VariableMirror (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comment Created 8 years, 1 month 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
« no previous file with comments | « pkg/dartdoc/lib/mirrors.dart ('k') | no next file » | 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) 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:io'; 7 import 'dart:io';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import '../../../../../lib/compiler/compiler.dart' as diagnostics; 10 import '../../../../../lib/compiler/compiler.dart' as diagnostics;
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 List<ParameterMirror> _parametersFromFunctionSignature( 37 List<ParameterMirror> _parametersFromFunctionSignature(
38 Dart2JsMirrorSystem system, 38 Dart2JsMirrorSystem system,
39 Dart2JsMethodMirror method, 39 Dart2JsMethodMirror method,
40 FunctionSignature signature) { 40 FunctionSignature signature) {
41 var parameters = <ParameterMirror>[]; 41 var parameters = <ParameterMirror>[];
42 Link<Element> link = signature.requiredParameters; 42 Link<Element> link = signature.requiredParameters;
43 while (!link.isEmpty) { 43 while (!link.isEmpty) {
44 parameters.add(new Dart2JsParameterMirror( 44 parameters.add(new Dart2JsParameterMirror(
45 system, method, link.head, false)); 45 system, method, link.head, false, false));
46 link = link.tail; 46 link = link.tail;
47 } 47 }
48 link = signature.optionalParameters; 48 link = signature.optionalParameters;
49 bool isNamed = signature.optionalParametersAreNamed;
49 while (!link.isEmpty) { 50 while (!link.isEmpty) {
50 parameters.add(new Dart2JsParameterMirror( 51 parameters.add(new Dart2JsParameterMirror(
51 system, method, link.head, true)); 52 system, method, link.head, true, isNamed));
52 link = link.tail; 53 link = link.tail;
53 } 54 }
54 return parameters; 55 return parameters;
55 } 56 }
56 57
57 Dart2JsTypeMirror _convertTypeToTypeMirror( 58 Dart2JsTypeMirror _convertTypeToTypeMirror(
58 Dart2JsMirrorSystem system, 59 Dart2JsMirrorSystem system,
59 DartType type, 60 DartType type,
60 InterfaceType defaultType, 61 InterfaceType defaultType,
61 [FunctionSignature functionSignature]) { 62 [FunctionSignature functionSignature]) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 386 }
386 387
387 abstract class Dart2JsDeclarationMirror 388 abstract class Dart2JsDeclarationMirror
388 implements Dart2JsMirror, DeclarationMirror { 389 implements Dart2JsMirror, DeclarationMirror {
389 390
390 bool get isTopLevel => owner != null && owner is LibraryMirror; 391 bool get isTopLevel => owner != null && owner is LibraryMirror;
391 392
392 bool get isPrivate => _isPrivate(simpleName); 393 bool get isPrivate => _isPrivate(simpleName);
393 } 394 }
394 395
395 abstract class Dart2JsMemberMirror extends Dart2JsDeclarationMirror 396 abstract class Dart2JsMemberMirror extends Dart2JsElementMirror
396 implements MemberMirror { 397 implements MemberMirror {
397 398
399 Dart2JsMemberMirror(Dart2JsMirrorSystem system, Element element)
400 : super(system, element);
401
402 bool get isConstructor => false;
403
404 bool get isField => false;
405
406 bool get isMethod => false;
407
408 bool get isStatic => false;
398 } 409 }
399 410
400 abstract class Dart2JsTypeMirror extends Dart2JsDeclarationMirror 411 abstract class Dart2JsTypeMirror extends Dart2JsDeclarationMirror
401 implements TypeMirror { 412 implements TypeMirror {
402 413
403 } 414 }
404 415
405 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { 416 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror {
406 final Dart2JsMirrorSystem system; 417 final Dart2JsMirrorSystem system;
407 final Element _element; 418 final Element _element;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 class Dart2JsSource implements Source { 643 class Dart2JsSource implements Source {
633 Script _script; 644 Script _script;
634 645
635 Dart2JsSource(this._script); 646 Dart2JsSource(this._script);
636 647
637 Uri get uri => _script.uri; 648 Uri get uri => _script.uri;
638 649
639 String get text => _script.text; 650 String get text => _script.text;
640 } 651 }
641 652
642 class Dart2JsParameterMirror extends Dart2JsElementMirror 653 class Dart2JsParameterMirror extends Dart2JsMemberMirror
643 implements ParameterMirror { 654 implements ParameterMirror {
644 final MethodMirror _method; 655 final MethodMirror _method;
645 final bool isOptional; 656 final bool isOptional;
657 final bool isNamed;
646 658
647 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system, 659 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system,
648 MethodMirror method, 660 MethodMirror method,
649 VariableElement element, 661 VariableElement element,
650 bool isOptional) { 662 bool isOptional,
663 bool isNamed) {
651 if (element is FieldParameterElement) { 664 if (element is FieldParameterElement) {
652 return new Dart2JsFieldParameterMirror(system, 665 return new Dart2JsFieldParameterMirror(system,
653 method, element, isOptional); 666 method, element, isOptional, isNamed);
654 } 667 }
655 return new Dart2JsParameterMirror._normal(system, 668 return new Dart2JsParameterMirror._normal(system,
656 method, element, isOptional); 669 method, element, isOptional, isNamed);
657 } 670 }
658 671
659 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system, 672 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system,
660 this._method, 673 this._method,
661 VariableElement element, 674 VariableElement element,
662 this.isOptional) 675 this.isOptional,
676 this.isNamed)
663 : super(system, element); 677 : super(system, element);
664 678
665 DeclarationMirror get owner => _method; 679 DeclarationMirror get owner => _method;
666 680
667 VariableElement get _variableElement => _element; 681 VariableElement get _variableElement => _element;
668 682
669 String get qualifiedName => '${_method.qualifiedName}#${simpleName}'; 683 String get qualifiedName => '${_method.qualifiedName}#${simpleName}';
670 684
671 TypeMirror get type => _convertTypeToTypeMirror(system, 685 TypeMirror get type => _convertTypeToTypeMirror(system,
672 _variableElement.computeType(system.compiler), 686 _variableElement.computeType(system.compiler),
673 system.compiler.types.dynamicType, 687 system.compiler.types.dynamicType,
674 _variableElement.variables.functionSignature); 688 _variableElement.variables.functionSignature);
675 689
690
691 bool get isFinal => false;
692
693 bool get isConst => false;
694
676 String get defaultValue { 695 String get defaultValue {
677 if (hasDefaultValue) { 696 if (hasDefaultValue) {
678 SendSet expression = _variableElement.cachedNode.asSendSet(); 697 SendSet expression = _variableElement.cachedNode.asSendSet();
679 return unparse(expression.arguments.head); 698 return unparse(expression.arguments.head);
680 } 699 }
681 return null; 700 return null;
682 } 701 }
702
683 bool get hasDefaultValue { 703 bool get hasDefaultValue {
684 return _variableElement.cachedNode !== null && 704 return _variableElement.cachedNode !== null &&
685 _variableElement.cachedNode is SendSet; 705 _variableElement.cachedNode is SendSet;
686 } 706 }
687 707
688 bool get isInitializingFormal => false; 708 bool get isInitializingFormal => false;
689 709
690 VariableMirror get initializedField => null; 710 VariableMirror get initializedField => null;
691 } 711 }
692 712
693 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror { 713 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror {
694 714
695 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system, 715 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system,
696 MethodMirror method, 716 MethodMirror method,
697 FieldParameterElement element, 717 FieldParameterElement element,
698 bool isOptional) 718 bool isOptional,
699 : super._normal(system, method, element, isOptional); 719 bool isNamed)
720 : super._normal(system, method, element, isOptional, isNamed);
700 721
701 FieldParameterElement get _fieldParameterElement => _element; 722 FieldParameterElement get _fieldParameterElement => _element;
702 723
703 TypeMirror get type { 724 TypeMirror get type {
704 if (_fieldParameterElement.variables.cachedNode.type !== null) { 725 if (_fieldParameterElement.variables.cachedNode.type !== null) {
705 return super.type; 726 return super.type;
706 } 727 }
707 return _convertTypeToTypeMirror(system, 728 return _convertTypeToTypeMirror(system,
708 _fieldParameterElement.fieldElement.computeType(system.compiler), 729 _fieldParameterElement.fieldElement.computeType(system.compiler),
709 system.compiler.types.dynamicType, 730 system.compiler.types.dynamicType,
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 return false; 1304 return false;
1284 } 1305 }
1285 return other.isDynamic; 1306 return other.isDynamic;
1286 } 1307 }
1287 } 1308 }
1288 1309
1289 //------------------------------------------------------------------------------ 1310 //------------------------------------------------------------------------------
1290 // Member mirrors implementation. 1311 // Member mirrors implementation.
1291 //------------------------------------------------------------------------------ 1312 //------------------------------------------------------------------------------
1292 1313
1293 class Dart2JsMethodMirror extends Dart2JsElementMirror 1314 class Dart2JsMethodMirror extends Dart2JsMemberMirror
1294 implements Dart2JsMemberMirror, MethodMirror { 1315 implements MethodMirror {
1295 final Dart2JsObjectMirror _objectMirror; 1316 final Dart2JsObjectMirror _objectMirror;
1296 String _simpleName; 1317 String _simpleName;
1297 String _displayName; 1318 String _displayName;
1298 String _constructorName; 1319 String _constructorName;
1299 String _operatorName; 1320 String _operatorName;
1300 Dart2JsMethodKind _kind; 1321 Dart2JsMethodKind _kind;
1301 1322
1302 Dart2JsMethodMirror(Dart2JsObjectMirror objectMirror, 1323 Dart2JsMethodMirror(Dart2JsObjectMirror objectMirror,
1303 FunctionElement function) 1324 FunctionElement function)
1304 : this._objectMirror = objectMirror, 1325 : this._objectMirror = objectMirror,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 String get qualifiedName 1391 String get qualifiedName
1371 => '${owner.qualifiedName}.$simpleName'; 1392 => '${owner.qualifiedName}.$simpleName';
1372 1393
1373 DeclarationMirror get owner => _objectMirror; 1394 DeclarationMirror get owner => _objectMirror;
1374 1395
1375 bool get isTopLevel => _objectMirror is LibraryMirror; 1396 bool get isTopLevel => _objectMirror is LibraryMirror;
1376 1397
1377 bool get isConstructor 1398 bool get isConstructor
1378 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory; 1399 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory;
1379 1400
1380 bool get isField => false;
1381
1382 bool get isMethod => !isConstructor; 1401 bool get isMethod => !isConstructor;
1383 1402
1384 bool get isPrivate => 1403 bool get isPrivate =>
1385 isConstructor ? _isPrivate(constructorName) : _isPrivate(simpleName); 1404 isConstructor ? _isPrivate(constructorName) : _isPrivate(simpleName);
1386 1405
1387 bool get isStatic => _function.modifiers.isStatic(); 1406 bool get isStatic => _function.modifiers.isStatic();
1388 1407
1389 List<ParameterMirror> get parameters { 1408 List<ParameterMirror> get parameters {
1390 return _parametersFromFunctionSignature(system, this, 1409 return _parametersFromFunctionSignature(system, this,
1391 _function.computeSignature(system.compiler)); 1410 _function.computeSignature(system.compiler));
(...skipping 24 matching lines...) Expand all
1416 if (node !== null) { 1435 if (node !== null) {
1417 var script = _function.getCompilationUnit().script; 1436 var script = _function.getCompilationUnit().script;
1418 var span = system.compiler.spanFromNode(node, script.uri); 1437 var span = system.compiler.spanFromNode(node, script.uri);
1419 return new Dart2JsLocation(script, span); 1438 return new Dart2JsLocation(script, span);
1420 } 1439 }
1421 return super.location; 1440 return super.location;
1422 } 1441 }
1423 1442
1424 } 1443 }
1425 1444
1426 class Dart2JsFieldMirror extends Dart2JsElementMirror 1445 class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror {
1427 implements Dart2JsMemberMirror, VariableMirror {
1428 Dart2JsObjectMirror _objectMirror; 1446 Dart2JsObjectMirror _objectMirror;
1429 VariableElement _variable; 1447 VariableElement _variable;
1430 1448
1431 Dart2JsFieldMirror(Dart2JsObjectMirror objectMirror, 1449 Dart2JsFieldMirror(Dart2JsObjectMirror objectMirror,
1432 VariableElement variable) 1450 VariableElement variable)
1433 : this._objectMirror = objectMirror, 1451 : this._objectMirror = objectMirror,
1434 this._variable = variable, 1452 this._variable = variable,
1435 super(objectMirror.system, variable); 1453 super(objectMirror.system, variable);
1436 1454
1437 String get qualifiedName 1455 String get qualifiedName
1438 => '${owner.qualifiedName}.$simpleName'; 1456 => '${owner.qualifiedName}.$simpleName';
1439 1457
1440 DeclarationMirror get owner => _objectMirror; 1458 DeclarationMirror get owner => _objectMirror;
1441 1459
1442 bool get isTopLevel => _objectMirror is LibraryMirror; 1460 bool get isTopLevel => _objectMirror is LibraryMirror;
1443 1461
1444 bool get isConstructor => false;
1445
1446 bool get isField => true; 1462 bool get isField => true;
1447 1463
1448 bool get isMethod => false;
1449
1450 bool get isStatic => _variable.modifiers.isStatic(); 1464 bool get isStatic => _variable.modifiers.isStatic();
1451 1465
1452 bool get isFinal => _variable.modifiers.isFinal(); 1466 bool get isFinal => _variable.modifiers.isFinal();
1453 1467
1454 bool get isConst => _variable.modifiers.isConst(); 1468 bool get isConst => _variable.modifiers.isConst();
1455 1469
1456 TypeMirror get type => _convertTypeToTypeMirror(system, 1470 TypeMirror get type => _convertTypeToTypeMirror(system,
1457 _variable.computeType(system.compiler), 1471 _variable.computeType(system.compiler),
1458 system.compiler.types.dynamicType); 1472 system.compiler.types.dynamicType);
1459 1473
1460 SourceLocation get location { 1474 SourceLocation get location {
1461 var script = _variable.getCompilationUnit().script; 1475 var script = _variable.getCompilationUnit().script;
1462 var node = _variable.variables.parseNode(_diagnosticListener); 1476 var node = _variable.variables.parseNode(_diagnosticListener);
1463 if (node !== null) { 1477 if (node !== null) {
1464 var span = system.compiler.spanFromNode(node, script.uri); 1478 var span = system.compiler.spanFromNode(node, script.uri);
1465 return new Dart2JsLocation(script, span); 1479 return new Dart2JsLocation(script, span);
1466 } else { 1480 } else {
1467 var span = system.compiler.spanFromElement(_variable); 1481 var span = system.compiler.spanFromElement(_variable);
1468 return new Dart2JsLocation(script, span); 1482 return new Dart2JsLocation(script, span);
1469 } 1483 }
1470 } 1484 }
1471 } 1485 }
1472 1486
OLDNEW
« no previous file with comments | « pkg/dartdoc/lib/mirrors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698