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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 @override | 468 @override |
469 int get nameOffset { | 469 int get nameOffset { |
470 if (_unlinkedClass != null) { | 470 if (_unlinkedClass != null) { |
471 return _unlinkedClass.nameOffset; | 471 return _unlinkedClass.nameOffset; |
472 } | 472 } |
473 return super.nameOffset; | 473 return super.nameOffset; |
474 } | 474 } |
475 | 475 |
476 @override | 476 @override |
| 477 TypeParameterizedElementMixin get typeParameterContext => this; |
| 478 |
| 479 @override |
477 List<TypeParameterElement> get typeParameters { | 480 List<TypeParameterElement> get typeParameters { |
478 if (_unlinkedClass != null) { | 481 if (_unlinkedClass != null) { |
479 return super.typeParameters; | 482 return super.typeParameters; |
480 } | 483 } |
481 return _typeParameters; | 484 return _typeParameters; |
482 } | 485 } |
483 | 486 |
484 /** | 487 /** |
485 * Set the type parameters defined for this class to the given | 488 * Set the type parameters defined for this class to the given |
486 * [typeParameters]. | 489 * [typeParameters]. |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 for (int i = 0; i < functions.length; i++) { | 1264 for (int i = 0; i < functions.length; i++) { |
1262 if (functions[i].name == FunctionElement.LOAD_LIBRARY_NAME) { | 1265 if (functions[i].name == FunctionElement.LOAD_LIBRARY_NAME) { |
1263 return true; | 1266 return true; |
1264 } | 1267 } |
1265 } | 1268 } |
1266 return false; | 1269 return false; |
1267 } | 1270 } |
1268 | 1271 |
1269 @override | 1272 @override |
1270 String get identifier => source.encoding; | 1273 String get identifier => source.encoding; |
| 1274 |
1271 @override | 1275 @override |
1272 ElementKind get kind => ElementKind.COMPILATION_UNIT; | 1276 ElementKind get kind => ElementKind.COMPILATION_UNIT; |
1273 | 1277 |
1274 @override | 1278 @override |
1275 List<ElementAnnotation> get metadata { | 1279 List<ElementAnnotation> get metadata { |
1276 if (_unlinkedPart != null) { | 1280 if (_unlinkedPart != null) { |
1277 return _metadata ??= _buildAnnotations( | 1281 return _metadata ??= _buildAnnotations( |
1278 library.definingCompilationUnit as CompilationUnitElementImpl, | 1282 library.definingCompilationUnit as CompilationUnitElementImpl, |
1279 _unlinkedPart.annotations); | 1283 _unlinkedPart.annotations); |
1280 } | 1284 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 * given [typeAliases]. | 1330 * given [typeAliases]. |
1327 */ | 1331 */ |
1328 void set typeAliases(List<FunctionTypeAliasElement> typeAliases) { | 1332 void set typeAliases(List<FunctionTypeAliasElement> typeAliases) { |
1329 for (FunctionTypeAliasElement typeAlias in typeAliases) { | 1333 for (FunctionTypeAliasElement typeAlias in typeAliases) { |
1330 (typeAlias as FunctionTypeAliasElementImpl).enclosingElement = this; | 1334 (typeAlias as FunctionTypeAliasElementImpl).enclosingElement = this; |
1331 } | 1335 } |
1332 this._typeAliases = typeAliases; | 1336 this._typeAliases = typeAliases; |
1333 } | 1337 } |
1334 | 1338 |
1335 @override | 1339 @override |
| 1340 TypeParameterizedElementMixin get typeParameterContext => null; |
| 1341 |
| 1342 @override |
1336 List<ClassElement> get types => _types; | 1343 List<ClassElement> get types => _types; |
1337 | 1344 |
1338 /** | 1345 /** |
1339 * Set the types contained in this compilation unit to the given [types]. | 1346 * Set the types contained in this compilation unit to the given [types]. |
1340 */ | 1347 */ |
1341 void set types(List<ClassElement> types) { | 1348 void set types(List<ClassElement> types) { |
1342 for (ClassElement type in types) { | 1349 for (ClassElement type in types) { |
1343 // Another implementation of ClassElement is _DeferredClassElement, | 1350 // Another implementation of ClassElement is _DeferredClassElement, |
1344 // which is used to resynthesize classes lazily. We cannot cast it | 1351 // which is used to resynthesize classes lazily. We cannot cast it |
1345 // to ClassElementImpl, and it already can provide correct values of the | 1352 // to ClassElementImpl, and it already can provide correct values of the |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 return _enclosingElement.source; | 2345 return _enclosingElement.source; |
2339 } | 2346 } |
2340 | 2347 |
2341 /** | 2348 /** |
2342 * Set whether this element is synthetic. | 2349 * Set whether this element is synthetic. |
2343 */ | 2350 */ |
2344 void set synthetic(bool isSynthetic) { | 2351 void set synthetic(bool isSynthetic) { |
2345 setModifier(Modifier.SYNTHETIC, isSynthetic); | 2352 setModifier(Modifier.SYNTHETIC, isSynthetic); |
2346 } | 2353 } |
2347 | 2354 |
| 2355 /** |
| 2356 * Return the context to resolve type parameters in, or `null` if neither this |
| 2357 * element nor any of its ancestors is of a kind that can declare type |
| 2358 * parameters. |
| 2359 */ |
| 2360 TypeParameterizedElementMixin get typeParameterContext { |
| 2361 return _enclosingElement?.typeParameterContext; |
| 2362 } |
| 2363 |
2348 @override | 2364 @override |
2349 CompilationUnit get unit => context.resolveCompilationUnit(source, library); | 2365 CompilationUnit get unit => context.resolveCompilationUnit(source, library); |
2350 | 2366 |
2351 @override | 2367 @override |
2352 bool operator ==(Object object) { | 2368 bool operator ==(Object object) { |
2353 if (identical(this, object)) { | 2369 if (identical(this, object)) { |
2354 return true; | 2370 return true; |
2355 } | 2371 } |
2356 return object is Element && | 2372 return object is Element && |
2357 object.kind == kind && | 2373 object.kind == kind && |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2980 * [parameters]. | 2996 * [parameters]. |
2981 */ | 2997 */ |
2982 void set parameters(List<ParameterElement> parameters) { | 2998 void set parameters(List<ParameterElement> parameters) { |
2983 for (ParameterElement parameter in parameters) { | 2999 for (ParameterElement parameter in parameters) { |
2984 (parameter as ParameterElementImpl).enclosingElement = this; | 3000 (parameter as ParameterElementImpl).enclosingElement = this; |
2985 } | 3001 } |
2986 this._parameters = parameters; | 3002 this._parameters = parameters; |
2987 } | 3003 } |
2988 | 3004 |
2989 @override | 3005 @override |
| 3006 TypeParameterizedElementMixin get typeParameterContext => this; |
| 3007 |
| 3008 @override |
2990 List<TypeParameterElement> get typeParameters => _typeParameters; | 3009 List<TypeParameterElement> get typeParameters => _typeParameters; |
2991 | 3010 |
2992 /** | 3011 /** |
2993 * Set the type parameters defined by this executable element to the given | 3012 * Set the type parameters defined by this executable element to the given |
2994 * [typeParameters]. | 3013 * [typeParameters]. |
2995 */ | 3014 */ |
2996 void set typeParameters(List<TypeParameterElement> typeParameters) { | 3015 void set typeParameters(List<TypeParameterElement> typeParameters) { |
2997 for (TypeParameterElement parameter in typeParameters) { | 3016 for (TypeParameterElement parameter in typeParameters) { |
2998 (parameter as TypeParameterElementImpl).enclosingElement = this; | 3017 (parameter as TypeParameterElementImpl).enclosingElement = this; |
2999 } | 3018 } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3385 : super("", -1) { | 3404 : super("", -1) { |
3386 synthetic = true; | 3405 synthetic = true; |
3387 this.returnType = returnType; | 3406 this.returnType = returnType; |
3388 this.parameters = parameters; | 3407 this.parameters = parameters; |
3389 | 3408 |
3390 type = new FunctionTypeImpl(this); | 3409 type = new FunctionTypeImpl(this); |
3391 } | 3410 } |
3392 | 3411 |
3393 @override | 3412 @override |
3394 TypeParameterizedElementMixin get enclosingTypeParameterContext { | 3413 TypeParameterizedElementMixin get enclosingTypeParameterContext { |
3395 Element enclosingElement = this.enclosingElement; | 3414 return (enclosingElement as ElementImpl).typeParameterContext; |
3396 if (enclosingElement is TypeParameterizedElementMixin) { | |
3397 return enclosingElement; | |
3398 } | |
3399 return null; | |
3400 } | 3415 } |
3401 | 3416 |
3402 @override | 3417 @override |
3403 String get identifier { | 3418 String get identifier { |
3404 String identifier = super.identifier; | 3419 String identifier = super.identifier; |
3405 if (!isStatic) { | 3420 if (!isStatic) { |
3406 identifier += "@$nameOffset"; | 3421 identifier += "@$nameOffset"; |
3407 } | 3422 } |
3408 return identifier; | 3423 return identifier; |
3409 } | 3424 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3615 void set parameters(List<ParameterElement> parameters) { | 3630 void set parameters(List<ParameterElement> parameters) { |
3616 if (parameters != null) { | 3631 if (parameters != null) { |
3617 for (ParameterElement parameter in parameters) { | 3632 for (ParameterElement parameter in parameters) { |
3618 (parameter as ParameterElementImpl).enclosingElement = this; | 3633 (parameter as ParameterElementImpl).enclosingElement = this; |
3619 } | 3634 } |
3620 } | 3635 } |
3621 this._parameters = parameters; | 3636 this._parameters = parameters; |
3622 } | 3637 } |
3623 | 3638 |
3624 @override | 3639 @override |
| 3640 TypeParameterizedElementMixin get typeParameterContext => this; |
| 3641 |
| 3642 @override |
3625 List<TypeParameterElement> get typeParameters { | 3643 List<TypeParameterElement> get typeParameters { |
3626 if (_unlinkedTypedef != null) { | 3644 if (_unlinkedTypedef != null) { |
3627 return super.typeParameters; | 3645 return super.typeParameters; |
3628 } | 3646 } |
3629 return _typeParameters; | 3647 return _typeParameters; |
3630 } | 3648 } |
3631 | 3649 |
3632 /** | 3650 /** |
3633 * Set the type parameters defined for this type to the given | 3651 * Set the type parameters defined for this type to the given |
3634 * [typeParameters]. | 3652 * [typeParameters]. |
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6069 if (serializedExecutable != null && isSetter) { | 6087 if (serializedExecutable != null && isSetter) { |
6070 String name = serializedExecutable.name; | 6088 String name = serializedExecutable.name; |
6071 assert(name.endsWith('=')); | 6089 assert(name.endsWith('=')); |
6072 return name.substring(0, name.length - 1); | 6090 return name.substring(0, name.length - 1); |
6073 } | 6091 } |
6074 return super.displayName; | 6092 return super.displayName; |
6075 } | 6093 } |
6076 | 6094 |
6077 @override | 6095 @override |
6078 TypeParameterizedElementMixin get enclosingTypeParameterContext { | 6096 TypeParameterizedElementMixin get enclosingTypeParameterContext { |
6079 Element enclosingElement = this.enclosingElement; | 6097 return (enclosingElement as ElementImpl).typeParameterContext; |
6080 if (enclosingElement is TypeParameterizedElementMixin) { | |
6081 return enclosingElement; | |
6082 } | |
6083 return null; | |
6084 } | 6098 } |
6085 | 6099 |
6086 /** | 6100 /** |
6087 * Set whether this accessor is a getter. | 6101 * Set whether this accessor is a getter. |
6088 */ | 6102 */ |
6089 void set getter(bool isGetter) { | 6103 void set getter(bool isGetter) { |
6090 assert(serializedExecutable == null); | 6104 assert(serializedExecutable == null); |
6091 setModifier(Modifier.GETTER, isGetter); | 6105 setModifier(Modifier.GETTER, isGetter); |
6092 } | 6106 } |
6093 | 6107 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6232 : super.forSerialized(unlinkedVariable, enclosingElement); | 6246 : super.forSerialized(unlinkedVariable, enclosingElement); |
6233 } | 6247 } |
6234 | 6248 |
6235 /** | 6249 /** |
6236 * The context in which elements are resynthesized. | 6250 * The context in which elements are resynthesized. |
6237 */ | 6251 */ |
6238 abstract class ResynthesizerContext { | 6252 abstract class ResynthesizerContext { |
6239 /** | 6253 /** |
6240 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. | 6254 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. |
6241 */ | 6255 */ |
6242 ElementAnnotationImpl buildAnnotation(Element context, UnlinkedConst uc); | 6256 ElementAnnotationImpl buildAnnotation(ElementImpl context, UnlinkedConst uc); |
6243 | 6257 |
6244 /** | 6258 /** |
6245 * Build [Expression] for the given [UnlinkedConst]. | 6259 * Build [Expression] for the given [UnlinkedConst]. |
6246 */ | 6260 */ |
6247 Expression buildExpression(Element context, UnlinkedConst uc); | 6261 Expression buildExpression(ElementImpl context, UnlinkedConst uc); |
6248 | 6262 |
6249 /** | 6263 /** |
6250 * Build explicit top-level property accessors. | 6264 * Build explicit top-level property accessors. |
6251 */ | 6265 */ |
6252 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); | 6266 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); |
6253 | 6267 |
6254 /** | 6268 /** |
6255 * Build top-level functions. | 6269 * Build top-level functions. |
6256 */ | 6270 */ |
6257 List<FunctionElementImpl> buildTopLevelFunctions(); | 6271 List<FunctionElementImpl> buildTopLevelFunctions(); |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6890 | 6904 |
6891 @override | 6905 @override |
6892 void visitElement(Element element) { | 6906 void visitElement(Element element) { |
6893 int offset = element.nameOffset; | 6907 int offset = element.nameOffset; |
6894 if (offset != -1) { | 6908 if (offset != -1) { |
6895 map[offset] = element; | 6909 map[offset] = element; |
6896 } | 6910 } |
6897 super.visitElement(element); | 6911 super.visitElement(element); |
6898 } | 6912 } |
6899 } | 6913 } |
OLD | NEW |