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

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