OLD | NEW |
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 | 4 |
5 /// Mixins that implement convenience methods on [Element] subclasses. | 5 /// Mixins that implement convenience methods on [Element] subclasses. |
6 | 6 |
7 library elements.common; | 7 library elements.common; |
8 | 8 |
9 import '../common/names.dart' show Identifiers, Names, Uris; | 9 import '../common/names.dart' show Identifiers, Names, Uris; |
10 import '../common_elements.dart' show CommonElements; | 10 import '../common_elements.dart' show CommonElements; |
11 import '../util/util.dart' show Link; | 11 import '../util/util.dart' show Link; |
| 12 import 'entities.dart'; |
12 import 'elements.dart'; | 13 import 'elements.dart'; |
13 import 'resolution_types.dart' | 14 import 'resolution_types.dart' |
14 show ResolutionDartType, ResolutionInterfaceType, ResolutionFunctionType; | 15 show ResolutionDartType, ResolutionInterfaceType, ResolutionFunctionType; |
15 | 16 |
16 abstract class ElementCommon implements Element { | 17 abstract class ElementCommon implements Element { |
17 @override | 18 @override |
18 bool get isLibrary => kind == ElementKind.LIBRARY; | 19 bool get isLibrary => kind == ElementKind.LIBRARY; |
19 | 20 |
20 @override | 21 @override |
21 bool get isCompilationUnit => kind == ElementKind.COMPILATION_UNIT; | 22 bool get isCompilationUnit => kind == ElementKind.COMPILATION_UNIT; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 492 } |
492 return null; | 493 return null; |
493 } | 494 } |
494 | 495 |
495 void forEachBackendMember(void f(Element member)) { | 496 void forEachBackendMember(void f(Element member)) { |
496 backendMembers.forEach(f); | 497 backendMembers.forEach(f); |
497 } | 498 } |
498 } | 499 } |
499 | 500 |
500 abstract class FunctionSignatureCommon implements FunctionSignature { | 501 abstract class FunctionSignatureCommon implements FunctionSignature { |
| 502 ParameterStructure _parameterStructure; |
| 503 |
501 ResolutionDartType get returnType => type.returnType; | 504 ResolutionDartType get returnType => type.returnType; |
502 | 505 |
503 void forEachRequiredParameter(void function(Element parameter)) { | 506 void forEachRequiredParameter(void function(Element parameter)) { |
504 requiredParameters.forEach(function); | 507 requiredParameters.forEach(function); |
505 } | 508 } |
506 | 509 |
507 void forEachOptionalParameter(void function(Element parameter)) { | 510 void forEachOptionalParameter(void function(Element parameter)) { |
508 optionalParameters.forEach(function); | 511 optionalParameters.forEach(function); |
509 } | 512 } |
510 | 513 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 // There must be at least as many arguments as in the other signature, but | 551 // There must be at least as many arguments as in the other signature, but |
549 // this signature must not have more required parameters. Having more | 552 // this signature must not have more required parameters. Having more |
550 // optional parameters is not a problem, they simply are never provided | 553 // optional parameters is not a problem, they simply are never provided |
551 // by call sites of a call to a method with the other signature. | 554 // by call sites of a call to a method with the other signature. |
552 int otherTotalCount = signature.parameterCount; | 555 int otherTotalCount = signature.parameterCount; |
553 return requiredParameterCount <= otherTotalCount && | 556 return requiredParameterCount <= otherTotalCount && |
554 parameterCount >= otherTotalCount; | 557 parameterCount >= otherTotalCount; |
555 } | 558 } |
556 return true; | 559 return true; |
557 } | 560 } |
| 561 |
| 562 ParameterStructure get parameterStructure { |
| 563 if (_parameterStructure == null) { |
| 564 int requiredParameters = requiredParameterCount; |
| 565 int positionalParameters; |
| 566 List<String> namedParameters; |
| 567 if (optionalParametersAreNamed) { |
| 568 namedParameters = type.namedParameters; |
| 569 positionalParameters = requiredParameters; |
| 570 } else { |
| 571 namedParameters = const <String>[]; |
| 572 positionalParameters = requiredParameters + optionalParameterCount; |
| 573 } |
| 574 _parameterStructure = new ParameterStructure( |
| 575 requiredParameters, positionalParameters, namedParameters); |
| 576 } |
| 577 return _parameterStructure; |
| 578 } |
558 } | 579 } |
559 | 580 |
560 abstract class MixinApplicationElementCommon | 581 abstract class MixinApplicationElementCommon |
561 implements MixinApplicationElement { | 582 implements MixinApplicationElement { |
562 Link<ConstructorElement> get constructors { | 583 Link<ConstructorElement> get constructors { |
563 throw new UnsupportedError('Unimplemented $this.constructors'); | 584 throw new UnsupportedError('Unimplemented $this.constructors'); |
564 } | 585 } |
565 | 586 |
566 FunctionElement _lookupLocalConstructor(String name) { | 587 FunctionElement _lookupLocalConstructor(String name) { |
567 for (Link<Element> link = constructors; !link.isEmpty; link = link.tail) { | 588 for (Link<Element> link = constructors; !link.isEmpty; link = link.tail) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 @override | 669 @override |
649 bool get isBoolFromEnvironmentConstructor { | 670 bool get isBoolFromEnvironmentConstructor { |
650 return fromEnvironmentState == _FromEnvironmentState.BOOL; | 671 return fromEnvironmentState == _FromEnvironmentState.BOOL; |
651 } | 672 } |
652 | 673 |
653 @override | 674 @override |
654 bool get isStringFromEnvironmentConstructor { | 675 bool get isStringFromEnvironmentConstructor { |
655 return fromEnvironmentState == _FromEnvironmentState.STRING; | 676 return fromEnvironmentState == _FromEnvironmentState.STRING; |
656 } | 677 } |
657 } | 678 } |
OLD | NEW |