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.element; | 5 library analyzer.src.dart.element.element; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 | 2451 |
2452 @override | 2452 @override |
2453 accept(ElementVisitor visitor) => null; | 2453 accept(ElementVisitor visitor) => null; |
2454 } | 2454 } |
2455 | 2455 |
2456 /** | 2456 /** |
2457 * A concrete implementation of an [ElementAnnotation]. | 2457 * A concrete implementation of an [ElementAnnotation]. |
2458 */ | 2458 */ |
2459 class ElementAnnotationImpl implements ElementAnnotation { | 2459 class ElementAnnotationImpl implements ElementAnnotation { |
2460 /** | 2460 /** |
| 2461 * The name of the top-level variable used to mark a method as covariant. |
| 2462 */ |
| 2463 static String _COVARIANT_VARIABLE_NAME = "covariant"; |
| 2464 |
| 2465 /** |
2461 * The name of the class used to mark an element as being deprecated. | 2466 * The name of the class used to mark an element as being deprecated. |
2462 */ | 2467 */ |
2463 static String _DEPRECATED_CLASS_NAME = "Deprecated"; | 2468 static String _DEPRECATED_CLASS_NAME = "Deprecated"; |
2464 | 2469 |
2465 /** | 2470 /** |
2466 * The name of the top-level variable used to mark an element as being | 2471 * The name of the top-level variable used to mark an element as being |
2467 * deprecated. | 2472 * deprecated. |
2468 */ | 2473 */ |
2469 static String _DEPRECATED_VARIABLE_NAME = "deprecated"; | 2474 static String _DEPRECATED_VARIABLE_NAME = "deprecated"; |
2470 | 2475 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2553 * compilation unit in which the annotation appears. | 2558 * compilation unit in which the annotation appears. |
2554 */ | 2559 */ |
2555 ElementAnnotationImpl(this.compilationUnit); | 2560 ElementAnnotationImpl(this.compilationUnit); |
2556 | 2561 |
2557 @override | 2562 @override |
2558 DartObject get constantValue => evaluationResult?.value; | 2563 DartObject get constantValue => evaluationResult?.value; |
2559 | 2564 |
2560 @override | 2565 @override |
2561 AnalysisContext get context => compilationUnit.library.context; | 2566 AnalysisContext get context => compilationUnit.library.context; |
2562 | 2567 |
| 2568 /** |
| 2569 * Return `true` if this annotation marks the associated parameter as being |
| 2570 * covariant, meaning it is allowed to have a narrower type in an override. |
| 2571 */ |
| 2572 bool get isCovariant => |
| 2573 element is PropertyAccessorElement && |
| 2574 element.name == _COVARIANT_VARIABLE_NAME && |
| 2575 element.library?.name == _META_LIB_NAME; |
| 2576 |
2563 @override | 2577 @override |
2564 bool get isDeprecated { | 2578 bool get isDeprecated { |
2565 if (element?.library?.isDartCore == true) { | 2579 if (element?.library?.isDartCore == true) { |
2566 if (element is ConstructorElement) { | 2580 if (element is ConstructorElement) { |
2567 return element.enclosingElement.name == _DEPRECATED_CLASS_NAME; | 2581 return element.enclosingElement.name == _DEPRECATED_CLASS_NAME; |
2568 } else if (element is PropertyAccessorElement) { | 2582 } else if (element is PropertyAccessorElement) { |
2569 return element.name == _DEPRECATED_VARIABLE_NAME; | 2583 return element.name == _DEPRECATED_VARIABLE_NAME; |
2570 } | 2584 } |
2571 } | 2585 } |
2572 return false; | 2586 return false; |
(...skipping 4361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6934 */ | 6948 */ |
6935 int _visibleRangeOffset = 0; | 6949 int _visibleRangeOffset = 0; |
6936 | 6950 |
6937 /** | 6951 /** |
6938 * The length of the visible range for this element, or `-1` if this element | 6952 * The length of the visible range for this element, or `-1` if this element |
6939 * does not have a visible range. | 6953 * does not have a visible range. |
6940 */ | 6954 */ |
6941 int _visibleRangeLength = -1; | 6955 int _visibleRangeLength = -1; |
6942 | 6956 |
6943 /** | 6957 /** |
| 6958 * True if this parameter inherits `@covariant` because it overrides a |
| 6959 * method in a supertype that has this parameter as covariant. |
| 6960 */ |
| 6961 bool inheritsCovariant = false; |
| 6962 |
| 6963 /** |
6944 * Initialize a newly created parameter element to have the given [name] and | 6964 * Initialize a newly created parameter element to have the given [name] and |
6945 * [nameOffset]. | 6965 * [nameOffset]. |
6946 */ | 6966 */ |
6947 ParameterElementImpl(String name, int nameOffset) | 6967 ParameterElementImpl(String name, int nameOffset) |
6948 : _unlinkedParam = null, | 6968 : _unlinkedParam = null, |
6949 super(name, nameOffset); | 6969 super(name, nameOffset); |
6950 | 6970 |
6951 /** | 6971 /** |
6952 * Initialize a newly created parameter element to have the given [name]. | 6972 * Initialize a newly created parameter element to have the given [name]. |
6953 */ | 6973 */ |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7088 | 7108 |
7089 @override | 7109 @override |
7090 bool get isConst { | 7110 bool get isConst { |
7091 if (_unlinkedParam != null) { | 7111 if (_unlinkedParam != null) { |
7092 return false; | 7112 return false; |
7093 } | 7113 } |
7094 return super.isConst; | 7114 return super.isConst; |
7095 } | 7115 } |
7096 | 7116 |
7097 @override | 7117 @override |
| 7118 bool get isCovariant { |
| 7119 if (inheritsCovariant) { |
| 7120 return true; |
| 7121 } |
| 7122 for (ElementAnnotationImpl annotation in metadata) { |
| 7123 if (annotation.isCovariant) { |
| 7124 return true; |
| 7125 } |
| 7126 } |
| 7127 return false; |
| 7128 } |
| 7129 |
| 7130 @override |
7098 bool get isFinal { | 7131 bool get isFinal { |
7099 if (_unlinkedParam != null) { | 7132 if (_unlinkedParam != null) { |
7100 return false; | 7133 return false; |
7101 } | 7134 } |
7102 return super.isFinal; | 7135 return super.isFinal; |
7103 } | 7136 } |
7104 | 7137 |
7105 @override | 7138 @override |
7106 bool get isInitializingFormal => false; | 7139 bool get isInitializingFormal => false; |
7107 | 7140 |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8504 | 8537 |
8505 @override | 8538 @override |
8506 void visitElement(Element element) { | 8539 void visitElement(Element element) { |
8507 int offset = element.nameOffset; | 8540 int offset = element.nameOffset; |
8508 if (offset != -1) { | 8541 if (offset != -1) { |
8509 map[offset] = element; | 8542 map[offset] = element; |
8510 } | 8543 } |
8511 super.visitElement(element); | 8544 super.visitElement(element); |
8512 } | 8545 } |
8513 } | 8546 } |
OLD | NEW |