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 | |
Paul Berry
2016/05/25 17:16:52
Nit: keep this blank line.
| |
1274 @override | 1277 @override |
Brian Wilkerson
2016/05/25 17:18:47
Strange to have the blank line go away. Is that th
scheglov
2016/05/25 17:26:59
It might be just me.
Fixed.
| |
1275 List<ElementAnnotation> get metadata { | 1278 List<ElementAnnotation> get metadata { |
1276 if (_unlinkedPart != null) { | 1279 if (_unlinkedPart != null) { |
1277 return _metadata ??= _buildAnnotations( | 1280 return _metadata ??= _buildAnnotations( |
1278 library.definingCompilationUnit as CompilationUnitElementImpl, | 1281 library.definingCompilationUnit as CompilationUnitElementImpl, |
1279 _unlinkedPart.annotations); | 1282 _unlinkedPart.annotations); |
1280 } | 1283 } |
1281 return super.metadata; | 1284 return super.metadata; |
1282 } | 1285 } |
1283 | 1286 |
1284 @override | 1287 @override |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1326 * given [typeAliases]. | 1329 * given [typeAliases]. |
1327 */ | 1330 */ |
1328 void set typeAliases(List<FunctionTypeAliasElement> typeAliases) { | 1331 void set typeAliases(List<FunctionTypeAliasElement> typeAliases) { |
1329 for (FunctionTypeAliasElement typeAlias in typeAliases) { | 1332 for (FunctionTypeAliasElement typeAlias in typeAliases) { |
1330 (typeAlias as FunctionTypeAliasElementImpl).enclosingElement = this; | 1333 (typeAlias as FunctionTypeAliasElementImpl).enclosingElement = this; |
1331 } | 1334 } |
1332 this._typeAliases = typeAliases; | 1335 this._typeAliases = typeAliases; |
1333 } | 1336 } |
1334 | 1337 |
1335 @override | 1338 @override |
1339 TypeParameterizedElementMixin get typeParameterContext => null; | |
1340 | |
1341 @override | |
1336 List<ClassElement> get types => _types; | 1342 List<ClassElement> get types => _types; |
1337 | 1343 |
1338 /** | 1344 /** |
1339 * Set the types contained in this compilation unit to the given [types]. | 1345 * Set the types contained in this compilation unit to the given [types]. |
1340 */ | 1346 */ |
1341 void set types(List<ClassElement> types) { | 1347 void set types(List<ClassElement> types) { |
1342 for (ClassElement type in types) { | 1348 for (ClassElement type in types) { |
1343 // Another implementation of ClassElement is _DeferredClassElement, | 1349 // Another implementation of ClassElement is _DeferredClassElement, |
1344 // which is used to resynthesize classes lazily. We cannot cast it | 1350 // which is used to resynthesize classes lazily. We cannot cast it |
1345 // to ClassElementImpl, and it already can provide correct values of the | 1351 // 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; | 2344 return _enclosingElement.source; |
2339 } | 2345 } |
2340 | 2346 |
2341 /** | 2347 /** |
2342 * Set whether this element is synthetic. | 2348 * Set whether this element is synthetic. |
2343 */ | 2349 */ |
2344 void set synthetic(bool isSynthetic) { | 2350 void set synthetic(bool isSynthetic) { |
2345 setModifier(Modifier.SYNTHETIC, isSynthetic); | 2351 setModifier(Modifier.SYNTHETIC, isSynthetic); |
2346 } | 2352 } |
2347 | 2353 |
2354 /** | |
2355 * Return the context to resolve type parameters in. | |
Paul Berry
2016/05/25 17:16:52
Comment should specify that `null` will be returne
scheglov
2016/05/25 17:26:59
Done.
| |
2356 */ | |
2357 TypeParameterizedElementMixin get typeParameterContext { | |
2358 return _enclosingElement?.typeParameterContext; | |
2359 } | |
2360 | |
2348 @override | 2361 @override |
2349 CompilationUnit get unit => context.resolveCompilationUnit(source, library); | 2362 CompilationUnit get unit => context.resolveCompilationUnit(source, library); |
2350 | 2363 |
2351 @override | 2364 @override |
2352 bool operator ==(Object object) { | 2365 bool operator ==(Object object) { |
2353 if (identical(this, object)) { | 2366 if (identical(this, object)) { |
2354 return true; | 2367 return true; |
2355 } | 2368 } |
2356 return object is Element && | 2369 return object is Element && |
2357 object.kind == kind && | 2370 object.kind == kind && |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2980 * [parameters]. | 2993 * [parameters]. |
2981 */ | 2994 */ |
2982 void set parameters(List<ParameterElement> parameters) { | 2995 void set parameters(List<ParameterElement> parameters) { |
2983 for (ParameterElement parameter in parameters) { | 2996 for (ParameterElement parameter in parameters) { |
2984 (parameter as ParameterElementImpl).enclosingElement = this; | 2997 (parameter as ParameterElementImpl).enclosingElement = this; |
2985 } | 2998 } |
2986 this._parameters = parameters; | 2999 this._parameters = parameters; |
2987 } | 3000 } |
2988 | 3001 |
2989 @override | 3002 @override |
3003 TypeParameterizedElementMixin get typeParameterContext => this; | |
3004 | |
3005 @override | |
2990 List<TypeParameterElement> get typeParameters => _typeParameters; | 3006 List<TypeParameterElement> get typeParameters => _typeParameters; |
2991 | 3007 |
2992 /** | 3008 /** |
2993 * Set the type parameters defined by this executable element to the given | 3009 * Set the type parameters defined by this executable element to the given |
2994 * [typeParameters]. | 3010 * [typeParameters]. |
2995 */ | 3011 */ |
2996 void set typeParameters(List<TypeParameterElement> typeParameters) { | 3012 void set typeParameters(List<TypeParameterElement> typeParameters) { |
2997 for (TypeParameterElement parameter in typeParameters) { | 3013 for (TypeParameterElement parameter in typeParameters) { |
2998 (parameter as TypeParameterElementImpl).enclosingElement = this; | 3014 (parameter as TypeParameterElementImpl).enclosingElement = this; |
2999 } | 3015 } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3385 : super("", -1) { | 3401 : super("", -1) { |
3386 synthetic = true; | 3402 synthetic = true; |
3387 this.returnType = returnType; | 3403 this.returnType = returnType; |
3388 this.parameters = parameters; | 3404 this.parameters = parameters; |
3389 | 3405 |
3390 type = new FunctionTypeImpl(this); | 3406 type = new FunctionTypeImpl(this); |
3391 } | 3407 } |
3392 | 3408 |
3393 @override | 3409 @override |
3394 TypeParameterizedElementMixin get enclosingTypeParameterContext { | 3410 TypeParameterizedElementMixin get enclosingTypeParameterContext { |
3395 Element enclosingElement = this.enclosingElement; | 3411 return (enclosingElement as ElementImpl).typeParameterContext; |
3396 if (enclosingElement is TypeParameterizedElementMixin) { | |
3397 return enclosingElement; | |
3398 } | |
3399 return null; | |
3400 } | 3412 } |
3401 | 3413 |
3402 @override | 3414 @override |
3403 String get identifier { | 3415 String get identifier { |
3404 String identifier = super.identifier; | 3416 String identifier = super.identifier; |
3405 if (!isStatic) { | 3417 if (!isStatic) { |
3406 identifier += "@$nameOffset"; | 3418 identifier += "@$nameOffset"; |
3407 } | 3419 } |
3408 return identifier; | 3420 return identifier; |
3409 } | 3421 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3615 void set parameters(List<ParameterElement> parameters) { | 3627 void set parameters(List<ParameterElement> parameters) { |
3616 if (parameters != null) { | 3628 if (parameters != null) { |
3617 for (ParameterElement parameter in parameters) { | 3629 for (ParameterElement parameter in parameters) { |
3618 (parameter as ParameterElementImpl).enclosingElement = this; | 3630 (parameter as ParameterElementImpl).enclosingElement = this; |
3619 } | 3631 } |
3620 } | 3632 } |
3621 this._parameters = parameters; | 3633 this._parameters = parameters; |
3622 } | 3634 } |
3623 | 3635 |
3624 @override | 3636 @override |
3637 TypeParameterizedElementMixin get typeParameterContext => this; | |
3638 | |
3639 @override | |
3625 List<TypeParameterElement> get typeParameters { | 3640 List<TypeParameterElement> get typeParameters { |
3626 if (_unlinkedTypedef != null) { | 3641 if (_unlinkedTypedef != null) { |
3627 return super.typeParameters; | 3642 return super.typeParameters; |
3628 } | 3643 } |
3629 return _typeParameters; | 3644 return _typeParameters; |
3630 } | 3645 } |
3631 | 3646 |
3632 /** | 3647 /** |
3633 * Set the type parameters defined for this type to the given | 3648 * Set the type parameters defined for this type to the given |
3634 * [typeParameters]. | 3649 * [typeParameters]. |
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6069 if (serializedExecutable != null && isSetter) { | 6084 if (serializedExecutable != null && isSetter) { |
6070 String name = serializedExecutable.name; | 6085 String name = serializedExecutable.name; |
6071 assert(name.endsWith('=')); | 6086 assert(name.endsWith('=')); |
6072 return name.substring(0, name.length - 1); | 6087 return name.substring(0, name.length - 1); |
6073 } | 6088 } |
6074 return super.displayName; | 6089 return super.displayName; |
6075 } | 6090 } |
6076 | 6091 |
6077 @override | 6092 @override |
6078 TypeParameterizedElementMixin get enclosingTypeParameterContext { | 6093 TypeParameterizedElementMixin get enclosingTypeParameterContext { |
6079 Element enclosingElement = this.enclosingElement; | 6094 return (enclosingElement as ElementImpl).typeParameterContext; |
6080 if (enclosingElement is TypeParameterizedElementMixin) { | |
6081 return enclosingElement; | |
6082 } | |
6083 return null; | |
6084 } | 6095 } |
6085 | 6096 |
6086 /** | 6097 /** |
6087 * Set whether this accessor is a getter. | 6098 * Set whether this accessor is a getter. |
6088 */ | 6099 */ |
6089 void set getter(bool isGetter) { | 6100 void set getter(bool isGetter) { |
6090 assert(serializedExecutable == null); | 6101 assert(serializedExecutable == null); |
6091 setModifier(Modifier.GETTER, isGetter); | 6102 setModifier(Modifier.GETTER, isGetter); |
6092 } | 6103 } |
6093 | 6104 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6232 : super.forSerialized(unlinkedVariable, enclosingElement); | 6243 : super.forSerialized(unlinkedVariable, enclosingElement); |
6233 } | 6244 } |
6234 | 6245 |
6235 /** | 6246 /** |
6236 * The context in which elements are resynthesized. | 6247 * The context in which elements are resynthesized. |
6237 */ | 6248 */ |
6238 abstract class ResynthesizerContext { | 6249 abstract class ResynthesizerContext { |
6239 /** | 6250 /** |
6240 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. | 6251 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. |
6241 */ | 6252 */ |
6242 ElementAnnotationImpl buildAnnotation(Element context, UnlinkedConst uc); | 6253 ElementAnnotationImpl buildAnnotation(ElementImpl context, UnlinkedConst uc); |
6243 | 6254 |
6244 /** | 6255 /** |
6245 * Build [Expression] for the given [UnlinkedConst]. | 6256 * Build [Expression] for the given [UnlinkedConst]. |
6246 */ | 6257 */ |
6247 Expression buildExpression(Element context, UnlinkedConst uc); | 6258 Expression buildExpression(ElementImpl context, UnlinkedConst uc); |
6248 | 6259 |
6249 /** | 6260 /** |
6250 * Build explicit top-level property accessors. | 6261 * Build explicit top-level property accessors. |
6251 */ | 6262 */ |
6252 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); | 6263 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); |
6253 | 6264 |
6254 /** | 6265 /** |
6255 * Build top-level functions. | 6266 * Build top-level functions. |
6256 */ | 6267 */ |
6257 List<FunctionElementImpl> buildTopLevelFunctions(); | 6268 List<FunctionElementImpl> buildTopLevelFunctions(); |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6890 | 6901 |
6891 @override | 6902 @override |
6892 void visitElement(Element element) { | 6903 void visitElement(Element element) { |
6893 int offset = element.nameOffset; | 6904 int offset = element.nameOffset; |
6894 if (offset != -1) { | 6905 if (offset != -1) { |
6895 map[offset] = element; | 6906 map[offset] = element; |
6896 } | 6907 } |
6897 super.visitElement(element); | 6908 super.visitElement(element); |
6898 } | 6909 } |
6899 } | 6910 } |
OLD | NEW |