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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2781443003: Fix #28120, strong mode allows field overrides (Closed)
Patch Set: fix Created 3 years, 8 months 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | 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) 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 2503 matching lines...) Expand 10 before | Expand all | Expand 10 after
2514 */ 2514 */
2515 static String _REQUIRED_CLASS_NAME = "Required"; 2515 static String _REQUIRED_CLASS_NAME = "Required";
2516 2516
2517 /** 2517 /**
2518 * The name of the top-level variable used to mark a parameter as being 2518 * The name of the top-level variable used to mark a parameter as being
2519 * required. 2519 * required.
2520 */ 2520 */
2521 static String _REQUIRED_VARIABLE_NAME = "required"; 2521 static String _REQUIRED_VARIABLE_NAME = "required";
2522 2522
2523 /** 2523 /**
2524 * The name of the top-level variable used to mark a member as intended to be
2525 * overridden.
2526 */
2527 static String _VIRTUAL_VARIABLE_NAME = "virtual";
2528
2529 /**
2530 * The element representing the field, variable, or constructor being used as 2524 * The element representing the field, variable, or constructor being used as
2531 * an annotation. 2525 * an annotation.
2532 */ 2526 */
2533 Element element; 2527 Element element;
2534 2528
2535 /** 2529 /**
2536 * The compilation unit in which this annotation appears. 2530 * The compilation unit in which this annotation appears.
2537 */ 2531 */
2538 CompilationUnitElementImpl compilationUnit; 2532 CompilationUnitElementImpl compilationUnit;
2539 2533
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2628 @override 2622 @override
2629 bool get isRequired => 2623 bool get isRequired =>
2630 element is ConstructorElement && 2624 element is ConstructorElement &&
2631 element.enclosingElement.name == _REQUIRED_CLASS_NAME && 2625 element.enclosingElement.name == _REQUIRED_CLASS_NAME &&
2632 element.library?.name == _META_LIB_NAME || 2626 element.library?.name == _META_LIB_NAME ||
2633 element is PropertyAccessorElement && 2627 element is PropertyAccessorElement &&
2634 element.name == _REQUIRED_VARIABLE_NAME && 2628 element.name == _REQUIRED_VARIABLE_NAME &&
2635 element.library?.name == _META_LIB_NAME; 2629 element.library?.name == _META_LIB_NAME;
2636 2630
2637 /** 2631 /**
2638 * Return `true` if this annotation marks the associated member as supporting
2639 * overrides.
2640 *
2641 * This is currently used by fields in Strong Mode, as other members are
2642 * already virtual-by-default.
2643 */
2644 bool get isVirtual =>
2645 element is PropertyAccessorElement &&
2646 element.name == _VIRTUAL_VARIABLE_NAME &&
2647 element.library?.name == _META_LIB_NAME;
2648
2649 /**
2650 * Get the library containing this annotation. 2632 * Get the library containing this annotation.
2651 */ 2633 */
2652 Source get librarySource => compilationUnit.librarySource; 2634 Source get librarySource => compilationUnit.librarySource;
2653 2635
2654 @override 2636 @override
2655 Source get source => compilationUnit.source; 2637 Source get source => compilationUnit.source;
2656 2638
2657 @override 2639 @override
2658 DartObject computeConstantValue() { 2640 DartObject computeConstantValue() {
2659 if (evaluationResult == null) { 2641 if (evaluationResult == null) {
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 4248
4267 /** 4249 /**
4268 * Set whether this field is static. 4250 * Set whether this field is static.
4269 */ 4251 */
4270 void set isStatic(bool isStatic) { 4252 void set isStatic(bool isStatic) {
4271 _assertNotResynthesized(_unlinkedVariable); 4253 _assertNotResynthesized(_unlinkedVariable);
4272 setModifier(Modifier.STATIC, isStatic); 4254 setModifier(Modifier.STATIC, isStatic);
4273 } 4255 }
4274 4256
4275 @override 4257 @override
4276 bool get isVirtual { 4258 bool get isVirtual => true;
4277 for (ElementAnnotationImpl annotation in metadata) {
4278 if (annotation.isVirtual) {
4279 return true;
4280 }
4281 }
4282 return false;
4283 }
4284 4259
4285 @override 4260 @override
4286 ElementKind get kind => ElementKind.FIELD; 4261 ElementKind get kind => ElementKind.FIELD;
4287 4262
4288 @override 4263 @override
4289 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) => 4264 /*=T*/ accept/*<T>*/(ElementVisitor<dynamic/*=T*/ > visitor) =>
4290 visitor.visitFieldElement(this); 4265 visitor.visitFieldElement(this);
4291 4266
4292 @override 4267 @override
4293 AstNode computeNode() { 4268 AstNode computeNode() {
(...skipping 4825 matching lines...) Expand 10 before | Expand all | Expand 10 after
9119 9094
9120 @override 9095 @override
9121 void visitElement(Element element) { 9096 void visitElement(Element element) {
9122 int offset = element.nameOffset; 9097 int offset = element.nameOffset;
9123 if (offset != -1) { 9098 if (offset != -1) {
9124 map[offset] = element; 9099 map[offset] = element;
9125 } 9100 }
9126 super.visitElement(element); 9101 super.visitElement(element);
9127 } 9102 }
9128 } 9103 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698