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

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

Issue 2644543005: Element model support for covariant (Closed)
Patch Set: Created 3 years, 11 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
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 4200 matching lines...) Expand 10 before | Expand all | Expand 10 after
4211 unlinkedVariable, enclosingClass); 4211 unlinkedVariable, enclosingClass);
4212 } else { 4212 } else {
4213 return new FieldElementImpl.forSerialized( 4213 return new FieldElementImpl.forSerialized(
4214 unlinkedVariable, enclosingClass); 4214 unlinkedVariable, enclosingClass);
4215 } 4215 }
4216 } 4216 }
4217 4217
4218 @override 4218 @override
4219 ClassElement get enclosingElement => super.enclosingElement as ClassElement; 4219 ClassElement get enclosingElement => super.enclosingElement as ClassElement;
4220 4220
4221 /**
4222 * Return `true` if this field was explicitly marked as being covariant.
4223 */
4224 bool get isCovariant {
4225 if (_unlinkedVariable != null) {
4226 return _unlinkedVariable.isCovariant;
4227 }
4228 return hasModifier(Modifier.COVARIANT);
4229 }
4230
4231 /**
4232 * Set whether this field is explicitly marked as being covariant.
4233 */
4234 void set isCovariant(bool isCovariant) {
4235 _assertNotResynthesized(_unlinkedVariable);
4236 setModifier(Modifier.COVARIANT, isCovariant);
4237 }
4238
4221 @override 4239 @override
4222 bool get isEnumConstant => 4240 bool get isEnumConstant =>
4223 enclosingElement != null ? enclosingElement.isEnum : false; 4241 enclosingElement != null ? enclosingElement.isEnum : false;
4224 4242
4225 @override 4243 @override
4226 bool get isStatic { 4244 bool get isStatic {
4227 if (_unlinkedVariable != null) { 4245 if (_unlinkedVariable != null) {
4228 return _unlinkedVariable.isStatic; 4246 return _unlinkedVariable.isStatic;
4229 } 4247 }
4230 return hasModifier(Modifier.STATIC); 4248 return hasModifier(Modifier.STATIC);
(...skipping 2053 matching lines...) Expand 10 before | Expand all | Expand 10 after
6284 * asynchronous. 6302 * asynchronous.
6285 */ 6303 */
6286 static const Modifier ASYNCHRONOUS = const Modifier('ASYNCHRONOUS', 1); 6304 static const Modifier ASYNCHRONOUS = const Modifier('ASYNCHRONOUS', 1);
6287 6305
6288 /** 6306 /**
6289 * Indicates that the modifier 'const' was applied to the element. 6307 * Indicates that the modifier 'const' was applied to the element.
6290 */ 6308 */
6291 static const Modifier CONST = const Modifier('CONST', 2); 6309 static const Modifier CONST = const Modifier('CONST', 2);
6292 6310
6293 /** 6311 /**
6312 * Indicates that the modifier 'covariant' was applied to the element.
6313 */
6314 static const Modifier COVARIANT = const Modifier('COVARIANT', 3);
6315
6316 /**
6294 * Indicates that the import element represents a deferred library. 6317 * Indicates that the import element represents a deferred library.
6295 */ 6318 */
6296 static const Modifier DEFERRED = const Modifier('DEFERRED', 3); 6319 static const Modifier DEFERRED = const Modifier('DEFERRED', 4);
6297 6320
6298 /** 6321 /**
6299 * Indicates that a class element was defined by an enum declaration. 6322 * Indicates that a class element was defined by an enum declaration.
6300 */ 6323 */
6301 static const Modifier ENUM = const Modifier('ENUM', 4); 6324 static const Modifier ENUM = const Modifier('ENUM', 5);
6302 6325
6303 /** 6326 /**
6304 * Indicates that a class element was defined by an enum declaration. 6327 * Indicates that a class element was defined by an enum declaration.
6305 */ 6328 */
6306 static const Modifier EXTERNAL = const Modifier('EXTERNAL', 5); 6329 static const Modifier EXTERNAL = const Modifier('EXTERNAL', 6);
6307 6330
6308 /** 6331 /**
6309 * Indicates that the modifier 'factory' was applied to the element. 6332 * Indicates that the modifier 'factory' was applied to the element.
6310 */ 6333 */
6311 static const Modifier FACTORY = const Modifier('FACTORY', 6); 6334 static const Modifier FACTORY = const Modifier('FACTORY', 7);
6312 6335
6313 /** 6336 /**
6314 * Indicates that the modifier 'final' was applied to the element. 6337 * Indicates that the modifier 'final' was applied to the element.
6315 */ 6338 */
6316 static const Modifier FINAL = const Modifier('FINAL', 7); 6339 static const Modifier FINAL = const Modifier('FINAL', 8);
6317 6340
6318 /** 6341 /**
6319 * Indicates that an executable element has a body marked as being a 6342 * Indicates that an executable element has a body marked as being a
6320 * generator. 6343 * generator.
6321 */ 6344 */
6322 static const Modifier GENERATOR = const Modifier('GENERATOR', 8); 6345 static const Modifier GENERATOR = const Modifier('GENERATOR', 9);
6323 6346
6324 /** 6347 /**
6325 * Indicates that the pseudo-modifier 'get' was applied to the element. 6348 * Indicates that the pseudo-modifier 'get' was applied to the element.
6326 */ 6349 */
6327 static const Modifier GETTER = const Modifier('GETTER', 9); 6350 static const Modifier GETTER = const Modifier('GETTER', 10);
6328 6351
6329 /** 6352 /**
6330 * A flag used for libraries indicating that the defining compilation unit 6353 * A flag used for libraries indicating that the defining compilation unit
6331 * contains at least one import directive whose URI uses the "dart-ext" 6354 * contains at least one import directive whose URI uses the "dart-ext"
6332 * scheme. 6355 * scheme.
6333 */ 6356 */
6334 static const Modifier HAS_EXT_URI = const Modifier('HAS_EXT_URI', 10); 6357 static const Modifier HAS_EXT_URI = const Modifier('HAS_EXT_URI', 11);
6335 6358
6336 /** 6359 /**
6337 * Indicates that the associated element did not have an explicit type 6360 * Indicates that the associated element did not have an explicit type
6338 * associated with it. If the element is an [ExecutableElement], then the 6361 * associated with it. If the element is an [ExecutableElement], then the
6339 * type being referred to is the return type. 6362 * type being referred to is the return type.
6340 */ 6363 */
6341 static const Modifier IMPLICIT_TYPE = const Modifier('IMPLICIT_TYPE', 11); 6364 static const Modifier IMPLICIT_TYPE = const Modifier('IMPLICIT_TYPE', 12);
6342 6365
6343 /** 6366 /**
6344 * Indicates that a class is a mixin application. 6367 * Indicates that a class is a mixin application.
6345 */ 6368 */
6346 static const Modifier MIXIN_APPLICATION = 6369 static const Modifier MIXIN_APPLICATION =
6347 const Modifier('MIXIN_APPLICATION', 12); 6370 const Modifier('MIXIN_APPLICATION', 13);
6348 6371
6349 /** 6372 /**
6350 * Indicates that a class contains an explicit reference to 'super'. 6373 * Indicates that a class contains an explicit reference to 'super'.
6351 */ 6374 */
6352 static const Modifier REFERENCES_SUPER = 6375 static const Modifier REFERENCES_SUPER =
6353 const Modifier('REFERENCES_SUPER', 13); 6376 const Modifier('REFERENCES_SUPER', 14);
6354 6377
6355 /** 6378 /**
6356 * Indicates that the pseudo-modifier 'set' was applied to the element. 6379 * Indicates that the pseudo-modifier 'set' was applied to the element.
6357 */ 6380 */
6358 static const Modifier SETTER = const Modifier('SETTER', 14); 6381 static const Modifier SETTER = const Modifier('SETTER', 15);
6359 6382
6360 /** 6383 /**
6361 * Indicates that the modifier 'static' was applied to the element. 6384 * Indicates that the modifier 'static' was applied to the element.
6362 */ 6385 */
6363 static const Modifier STATIC = const Modifier('STATIC', 15); 6386 static const Modifier STATIC = const Modifier('STATIC', 16);
6364 6387
6365 /** 6388 /**
6366 * Indicates that the element does not appear in the source code but was 6389 * Indicates that the element does not appear in the source code but was
6367 * implicitly created. For example, if a class does not define any 6390 * implicitly created. For example, if a class does not define any
6368 * constructors, an implicit zero-argument constructor will be created and it 6391 * constructors, an implicit zero-argument constructor will be created and it
6369 * will be marked as being synthetic. 6392 * will be marked as being synthetic.
6370 */ 6393 */
6371 static const Modifier SYNTHETIC = const Modifier('SYNTHETIC', 16); 6394 static const Modifier SYNTHETIC = const Modifier('SYNTHETIC', 17);
6372 6395
6373 static const List<Modifier> values = const [ 6396 static const List<Modifier> values = const [
6374 ABSTRACT, 6397 ABSTRACT,
6375 ASYNCHRONOUS, 6398 ASYNCHRONOUS,
6376 CONST, 6399 CONST,
6400 COVARIANT,
6377 DEFERRED, 6401 DEFERRED,
6378 ENUM, 6402 ENUM,
6379 EXTERNAL, 6403 EXTERNAL,
6380 FACTORY, 6404 FACTORY,
6381 FINAL, 6405 FINAL,
6382 GENERATOR, 6406 GENERATOR,
6383 GETTER, 6407 GETTER,
6384 HAS_EXT_URI, 6408 HAS_EXT_URI,
6385 IMPLICIT_TYPE, 6409 IMPLICIT_TYPE,
6386 MIXIN_APPLICATION, 6410 MIXIN_APPLICATION,
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
7084 } 7108 }
7085 7109
7086 @override 7110 @override
7087 void set isConst(bool isConst) { 7111 void set isConst(bool isConst) {
7088 _assertNotResynthesized(_unlinkedParam); 7112 _assertNotResynthesized(_unlinkedParam);
7089 super.isConst = isConst; 7113 super.isConst = isConst;
7090 } 7114 }
7091 7115
7092 @override 7116 @override
7093 bool get isCovariant { 7117 bool get isCovariant {
7094 if (inheritsCovariant) { 7118 if (isExplicitlyCovariant || inheritsCovariant) {
7095 return true; 7119 return true;
7096 } 7120 }
7097 for (ElementAnnotationImpl annotation in metadata) { 7121 for (ElementAnnotationImpl annotation in metadata) {
7098 if (annotation.isCovariant) { 7122 if (annotation.isCovariant) {
7099 return true; 7123 return true;
7100 } 7124 }
7101 } 7125 }
7102 return false; 7126 return false;
7103 } 7127 }
7104 7128
7129 /**
7130 * Return true if this parameter is explicitly marked as being covariant.
7131 */
7132 bool get isExplicitlyCovariant {
7133 if (_unlinkedParam != null) {
7134 return _unlinkedParam.isExplicitlyCovariant;
7135 }
7136 return hasModifier(Modifier.COVARIANT);
7137 }
7138
7139 /**
7140 * Set whether this variable parameter is explicitly marked as being covariant .
7141 */
7142 void set isExplicitlyCovariant(bool isCovariant) {
7143 _assertNotResynthesized(_unlinkedParam);
7144 setModifier(Modifier.COVARIANT, isCovariant);
7145 }
7146
7105 @override 7147 @override
7106 bool get isFinal { 7148 bool get isFinal {
7107 if (_unlinkedParam != null) { 7149 if (_unlinkedParam != null) {
7108 return false; 7150 return false;
7109 } 7151 }
7110 return super.isFinal; 7152 return super.isFinal;
7111 } 7153 }
7112 7154
7113 @override 7155 @override
7114 void set isFinal(bool isFinal) { 7156 void set isFinal(bool isFinal) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
7361 PropertyAccessorElementImpl_ImplicitSetter setter) 7403 PropertyAccessorElementImpl_ImplicitSetter setter)
7362 : setter = setter, 7404 : setter = setter,
7363 super('_${setter.variable.name}', setter.variable.nameOffset) { 7405 super('_${setter.variable.name}', setter.variable.nameOffset) {
7364 enclosingElement = setter; 7406 enclosingElement = setter;
7365 isSynthetic = true; 7407 isSynthetic = true;
7366 parameterKind = ParameterKind.REQUIRED; 7408 parameterKind = ParameterKind.REQUIRED;
7367 } 7409 }
7368 7410
7369 @override 7411 @override
7370 bool get isCovariant { 7412 bool get isCovariant {
7371 if (inheritsCovariant) { 7413 if (isExplicitlyCovariant || inheritsCovariant) {
7372 return true; 7414 return true;
7373 } 7415 }
7374 for (ElementAnnotationImpl annotation in setter.variable.metadata) { 7416 for (ElementAnnotationImpl annotation in setter.variable.metadata) {
7375 if (annotation.isCovariant) { 7417 if (annotation.isCovariant) {
7376 return true; 7418 return true;
7377 } 7419 }
7378 } 7420 }
7379 return false; 7421 return false;
7380 } 7422 }
7381 7423
7382 @override 7424 @override
7425 bool get isExplicitlyCovariant {
7426 PropertyInducingElement variable = setter.variable;
7427 if (variable is FieldElementImpl) {
7428 return variable.isCovariant;
7429 }
7430 return false;
7431 }
7432
7433 @override
7383 DartType get type => setter.variable.type; 7434 DartType get type => setter.variable.type;
7384 7435
7385 @override 7436 @override
7386 void set type(DartType type) { 7437 void set type(DartType type) {
7387 assert(false); // Should never be called. 7438 assert(false); // Should never be called.
7388 } 7439 }
7389 } 7440 }
7390 7441
7391 /** 7442 /**
7392 * A mixin that provides a common implementation for methods defined in 7443 * A mixin that provides a common implementation for methods defined in
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
8549 8600
8550 @override 8601 @override
8551 void visitElement(Element element) { 8602 void visitElement(Element element) {
8552 int offset = element.nameOffset; 8603 int offset = element.nameOffset;
8553 if (offset != -1) { 8604 if (offset != -1) {
8554 map[offset] = element; 8605 map[offset] = element;
8555 } 8606 }
8556 super.visitElement(element); 8607 super.visitElement(element);
8557 } 8608 }
8558 } 8609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698