OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.dart.element.member; | 5 library analyzer.src.dart.element.member; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/constant/value.dart'; | 8 import 'package:analyzer/dart/constant/value.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 int get nameEnd => baseElement.nameEnd; | 52 int get nameEnd => baseElement.nameEnd; |
53 | 53 |
54 @override | 54 @override |
55 int get periodOffset => baseElement.periodOffset; | 55 int get periodOffset => baseElement.periodOffset; |
56 | 56 |
57 @override | 57 @override |
58 ConstructorElement get redirectedConstructor => | 58 ConstructorElement get redirectedConstructor => |
59 from(baseElement.redirectedConstructor, definingType); | 59 from(baseElement.redirectedConstructor, definingType); |
60 | 60 |
61 @override | 61 @override |
62 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 62 T accept<T>(ElementVisitor<T> visitor) => |
63 visitor.visitConstructorElement(this); | 63 visitor.visitConstructorElement(this); |
64 | 64 |
65 @override | 65 @override |
66 ConstructorDeclaration computeNode() => baseElement.computeNode(); | 66 ConstructorDeclaration computeNode() => baseElement.computeNode(); |
67 | 67 |
68 @override | 68 @override |
69 String toString() { | 69 String toString() { |
70 ConstructorElement baseElement = this.baseElement; | 70 ConstructorElement baseElement = this.baseElement; |
71 List<ParameterElement> parameters = this.parameters; | 71 List<ParameterElement> parameters = this.parameters; |
72 FunctionType type = this.type; | 72 FunctionType type = this.type; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return FieldMember.from( | 236 return FieldMember.from( |
237 field, substituteFor(field.enclosingElement.type)); | 237 field, substituteFor(field.enclosingElement.type)); |
238 } | 238 } |
239 return field; | 239 return field; |
240 } | 240 } |
241 | 241 |
242 @override | 242 @override |
243 bool get isCovariant => baseElement.isCovariant; | 243 bool get isCovariant => baseElement.isCovariant; |
244 | 244 |
245 @override | 245 @override |
246 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 246 T accept<T>(ElementVisitor<T> visitor) => |
247 visitor.visitFieldFormalParameterElement(this); | 247 visitor.visitFieldFormalParameterElement(this); |
248 } | 248 } |
249 | 249 |
250 /** | 250 /** |
251 * A field element defined in a parameterized type where the values of the type | 251 * A field element defined in a parameterized type where the values of the type |
252 * parameters are known. | 252 * parameters are known. |
253 */ | 253 */ |
254 class FieldMember extends VariableMember implements FieldElement { | 254 class FieldMember extends VariableMember implements FieldElement { |
255 /** | 255 /** |
256 * Initialize a newly created element to represent a field, based on the | 256 * Initialize a newly created element to represent a field, based on the |
(...skipping 19 matching lines...) Expand all Loading... |
276 bool get isVirtual => baseElement.isVirtual; | 276 bool get isVirtual => baseElement.isVirtual; |
277 | 277 |
278 @override | 278 @override |
279 DartType get propagatedType => substituteFor(baseElement.propagatedType); | 279 DartType get propagatedType => substituteFor(baseElement.propagatedType); |
280 | 280 |
281 @override | 281 @override |
282 PropertyAccessorElement get setter => | 282 PropertyAccessorElement get setter => |
283 PropertyAccessorMember.from(baseElement.setter, definingType); | 283 PropertyAccessorMember.from(baseElement.setter, definingType); |
284 | 284 |
285 @override | 285 @override |
286 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 286 T accept<T>(ElementVisitor<T> visitor) => visitor.visitFieldElement(this); |
287 visitor.visitFieldElement(this); | |
288 | 287 |
289 @override | 288 @override |
290 VariableDeclaration computeNode() => baseElement.computeNode(); | 289 VariableDeclaration computeNode() => baseElement.computeNode(); |
291 | 290 |
292 @override | 291 @override |
293 String toString() => '$type $displayName'; | 292 String toString() => '$type $displayName'; |
294 | 293 |
295 /** | 294 /** |
296 * If the given [field]'s type is different when any type parameters from the | 295 * If the given [field]'s type is different when any type parameters from the |
297 * defining type's declaration are replaced with the actual type arguments | 296 * defining type's declaration are replaced with the actual type arguments |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 @override | 334 @override |
336 Element get enclosingElement => baseElement.enclosingElement; | 335 Element get enclosingElement => baseElement.enclosingElement; |
337 | 336 |
338 @override | 337 @override |
339 bool get isEntryPoint => baseElement.isEntryPoint; | 338 bool get isEntryPoint => baseElement.isEntryPoint; |
340 | 339 |
341 @override | 340 @override |
342 SourceRange get visibleRange => baseElement.visibleRange; | 341 SourceRange get visibleRange => baseElement.visibleRange; |
343 | 342 |
344 @override | 343 @override |
345 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 344 T accept<T>(ElementVisitor<T> visitor) => visitor.visitFunctionElement(this); |
346 visitor.visitFunctionElement(this); | |
347 | 345 |
348 @override | 346 @override |
349 FunctionDeclaration computeNode() => baseElement.computeNode(); | 347 FunctionDeclaration computeNode() => baseElement.computeNode(); |
350 | 348 |
351 @override | 349 @override |
352 String toString() { | 350 String toString() { |
353 StringBuffer buffer = new StringBuffer(); | 351 StringBuffer buffer = new StringBuffer(); |
354 buffer.write(baseElement.displayName); | 352 buffer.write(baseElement.displayName); |
355 (type as FunctionTypeImpl).appendTo(buffer, new Set.identity()); | 353 (type as FunctionTypeImpl).appendTo(buffer, new Set.identity()); |
356 return buffer.toString(); | 354 return buffer.toString(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 @override | 476 @override |
479 CompilationUnit get unit => _baseElement.unit; | 477 CompilationUnit get unit => _baseElement.unit; |
480 | 478 |
481 @override | 479 @override |
482 String computeDocumentationComment() => documentationComment; | 480 String computeDocumentationComment() => documentationComment; |
483 | 481 |
484 @override | 482 @override |
485 AstNode computeNode() => _baseElement.computeNode(); | 483 AstNode computeNode() => _baseElement.computeNode(); |
486 | 484 |
487 @override | 485 @override |
488 Element/*=E*/ getAncestor/*<E extends Element >*/( | 486 E getAncestor<E extends Element>(Predicate<Element> predicate) => |
489 Predicate<Element> predicate) => | |
490 baseElement.getAncestor(predicate); | 487 baseElement.getAncestor(predicate); |
491 | 488 |
492 @override | 489 @override |
493 String getExtendedDisplayName(String shortName) => | 490 String getExtendedDisplayName(String shortName) => |
494 _baseElement.getExtendedDisplayName(shortName); | 491 _baseElement.getExtendedDisplayName(shortName); |
495 | 492 |
496 @override | 493 @override |
497 bool isAccessibleIn(LibraryElement library) => | 494 bool isAccessibleIn(LibraryElement library) => |
498 _baseElement.isAccessibleIn(library); | 495 _baseElement.isAccessibleIn(library); |
499 | 496 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 [DartType type]) | 552 [DartType type]) |
556 : super(baseElement, definingType, type); | 553 : super(baseElement, definingType, type); |
557 | 554 |
558 @override | 555 @override |
559 MethodElement get baseElement => super.baseElement as MethodElement; | 556 MethodElement get baseElement => super.baseElement as MethodElement; |
560 | 557 |
561 @override | 558 @override |
562 ClassElement get enclosingElement => baseElement.enclosingElement; | 559 ClassElement get enclosingElement => baseElement.enclosingElement; |
563 | 560 |
564 @override | 561 @override |
565 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 562 T accept<T>(ElementVisitor<T> visitor) => visitor.visitMethodElement(this); |
566 visitor.visitMethodElement(this); | |
567 | 563 |
568 @override | 564 @override |
569 MethodDeclaration computeNode() => baseElement.computeNode(); | 565 MethodDeclaration computeNode() => baseElement.computeNode(); |
570 | 566 |
571 @override | 567 @override |
572 FunctionType getReifiedType(DartType objectType) => | 568 FunctionType getReifiedType(DartType objectType) => |
573 substituteFor(baseElement.getReifiedType(objectType)); | 569 substituteFor(baseElement.getReifiedType(objectType)); |
574 | 570 |
575 @override | 571 @override |
576 String toString() { | 572 String toString() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 return ParameterElement.EMPTY_LIST; | 692 return ParameterElement.EMPTY_LIST; |
697 } | 693 } |
698 | 694 |
699 @override | 695 @override |
700 List<TypeParameterElement> get typeParameters => baseElement.typeParameters; | 696 List<TypeParameterElement> get typeParameters => baseElement.typeParameters; |
701 | 697 |
702 @override | 698 @override |
703 SourceRange get visibleRange => baseElement.visibleRange; | 699 SourceRange get visibleRange => baseElement.visibleRange; |
704 | 700 |
705 @override | 701 @override |
706 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 702 T accept<T>(ElementVisitor<T> visitor) => visitor.visitParameterElement(this); |
707 visitor.visitParameterElement(this); | |
708 | 703 |
709 @override | 704 @override |
710 FormalParameter computeNode() => baseElement.computeNode(); | 705 FormalParameter computeNode() => baseElement.computeNode(); |
711 | 706 |
712 @override | 707 @override |
713 Element/*=E*/ getAncestor/*<E extends Element>*/( | 708 E getAncestor<E extends Element>(Predicate<Element> predicate) { |
714 Predicate<Element> predicate) { | |
715 Element element = baseElement.getAncestor(predicate); | 709 Element element = baseElement.getAncestor(predicate); |
716 ParameterizedType definingType = this.definingType; | 710 ParameterizedType definingType = this.definingType; |
717 if (definingType is InterfaceType) { | 711 if (definingType is InterfaceType) { |
718 if (element is ConstructorElement) { | 712 if (element is ConstructorElement) { |
719 return ConstructorMember.from(element, definingType) as Element/*=E*/; | 713 return ConstructorMember.from(element, definingType) as E; |
720 } else if (element is MethodElement) { | 714 } else if (element is MethodElement) { |
721 return MethodMember.from(element, definingType) as Element/*=E*/; | 715 return MethodMember.from(element, definingType) as E; |
722 } else if (element is PropertyAccessorElement) { | 716 } else if (element is PropertyAccessorElement) { |
723 return PropertyAccessorMember.from(element, definingType) | 717 return PropertyAccessorMember.from(element, definingType) as E; |
724 as Element/*=E*/; | |
725 } | 718 } |
726 } | 719 } |
727 return element as Element/*=E*/; | 720 return element as E; |
728 } | 721 } |
729 | 722 |
730 @override | 723 @override |
731 String toString() { | 724 String toString() { |
732 ParameterElement baseElement = this.baseElement; | 725 ParameterElement baseElement = this.baseElement; |
733 String left = ""; | 726 String left = ""; |
734 String right = ""; | 727 String right = ""; |
735 while (true) { | 728 while (true) { |
736 if (baseElement.parameterKind == ParameterKind.NAMED) { | 729 if (baseElement.parameterKind == ParameterKind.NAMED) { |
737 left = "{"; | 730 left = "{"; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 @override | 786 @override |
794 PropertyInducingElement get variable { | 787 PropertyInducingElement get variable { |
795 PropertyInducingElement variable = baseElement.variable; | 788 PropertyInducingElement variable = baseElement.variable; |
796 if (variable is FieldElement) { | 789 if (variable is FieldElement) { |
797 return FieldMember.from(variable, definingType); | 790 return FieldMember.from(variable, definingType); |
798 } | 791 } |
799 return variable; | 792 return variable; |
800 } | 793 } |
801 | 794 |
802 @override | 795 @override |
803 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 796 T accept<T>(ElementVisitor<T> visitor) => |
804 visitor.visitPropertyAccessorElement(this); | 797 visitor.visitPropertyAccessorElement(this); |
805 | 798 |
806 @override | 799 @override |
807 String toString() { | 800 String toString() { |
808 PropertyAccessorElement baseElement = this.baseElement; | 801 PropertyAccessorElement baseElement = this.baseElement; |
809 List<ParameterElement> parameters = this.parameters; | 802 List<ParameterElement> parameters = this.parameters; |
810 FunctionType type = this.type; | 803 FunctionType type = this.type; |
811 StringBuffer builder = new StringBuffer(); | 804 StringBuffer builder = new StringBuffer(); |
812 if (isGetter) { | 805 if (isGetter) { |
813 builder.write("get "); | 806 builder.write("get "); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 int get hashCode => baseElement.hashCode; | 884 int get hashCode => baseElement.hashCode; |
892 | 885 |
893 @override | 886 @override |
894 TypeParameterType get type => _type; | 887 TypeParameterType get type => _type; |
895 | 888 |
896 @override | 889 @override |
897 bool operator ==(Object other) => | 890 bool operator ==(Object other) => |
898 other is TypeParameterMember && baseElement == other.baseElement; | 891 other is TypeParameterMember && baseElement == other.baseElement; |
899 | 892 |
900 @override | 893 @override |
901 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => | 894 T accept<T>(ElementVisitor<T> visitor) => |
902 visitor.visitTypeParameterElement(this); | 895 visitor.visitTypeParameterElement(this); |
903 | 896 |
904 /** | 897 /** |
905 * If the given [parameter]'s type is different when any type parameters from | 898 * If the given [parameter]'s type is different when any type parameters from |
906 * the defining type's declaration are replaced with the actual type | 899 * the defining type's declaration are replaced with the actual type |
907 * arguments from the [definingType], create a parameter member representing | 900 * arguments from the [definingType], create a parameter member representing |
908 * the given parameter. Return the member that was created, or the base | 901 * the given parameter. Return the member that was created, or the base |
909 * parameter if no member was created. | 902 * parameter if no member was created. |
910 */ | 903 */ |
911 static List<TypeParameterElement> from( | 904 static List<TypeParameterElement> from( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 DartObject computeConstantValue() => baseElement.computeConstantValue(); | 1006 DartObject computeConstantValue() => baseElement.computeConstantValue(); |
1014 | 1007 |
1015 @override | 1008 @override |
1016 void visitChildren(ElementVisitor visitor) { | 1009 void visitChildren(ElementVisitor visitor) { |
1017 // TODO(brianwilkerson) We need to finish implementing the accessors used | 1010 // TODO(brianwilkerson) We need to finish implementing the accessors used |
1018 // below so that we can safely invoke them. | 1011 // below so that we can safely invoke them. |
1019 super.visitChildren(visitor); | 1012 super.visitChildren(visitor); |
1020 baseElement.initializer?.accept(visitor); | 1013 baseElement.initializer?.accept(visitor); |
1021 } | 1014 } |
1022 } | 1015 } |
OLD | NEW |