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

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

Issue 1993333003: Fix for resynthesizing default values referencing type parameters. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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/lib/src/summary/resynthesize.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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return true; 424 return true;
425 } 425 }
426 426
427 @override 427 @override
428 ElementKind get kind => ElementKind.CLASS; 428 ElementKind get kind => ElementKind.CLASS;
429 429
430 @override 430 @override
431 List<ElementAnnotation> get metadata { 431 List<ElementAnnotation> get metadata {
432 if (_unlinkedClass != null) { 432 if (_unlinkedClass != null) {
433 return _metadata ??= _unlinkedClass.annotations 433 return _metadata ??= _unlinkedClass.annotations
434 .map(enclosingUnit.resynthesizerContext.buildAnnotation) 434 .map((a) =>
435 enclosingUnit.resynthesizerContext.buildAnnotation(this, a))
435 .toList(); 436 .toList();
436 } 437 }
437 return super.metadata; 438 return super.metadata;
438 } 439 }
439 440
440 @override 441 @override
441 List<MethodElement> get methods => _methods; 442 List<MethodElement> get methods => _methods;
442 443
443 /** 444 /**
444 * Set the methods contained in this class to the given [methods]. 445 * Set the methods contained in this class to the given [methods].
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 String get identifier => source.encoding; 1266 String get identifier => source.encoding;
1266 @override 1267 @override
1267 ElementKind get kind => ElementKind.COMPILATION_UNIT; 1268 ElementKind get kind => ElementKind.COMPILATION_UNIT;
1268 1269
1269 @override 1270 @override
1270 List<ElementAnnotation> get metadata { 1271 List<ElementAnnotation> get metadata {
1271 if (_unlinkedPart != null) { 1272 if (_unlinkedPart != null) {
1272 CompilationUnitElementImpl definingUnit = 1273 CompilationUnitElementImpl definingUnit =
1273 library.definingCompilationUnit as CompilationUnitElementImpl; 1274 library.definingCompilationUnit as CompilationUnitElementImpl;
1274 return _metadata ??= _unlinkedPart.annotations 1275 return _metadata ??= _unlinkedPart.annotations
1275 .map(definingUnit.resynthesizerContext.buildAnnotation) 1276 .map(
1277 (a) => definingUnit.resynthesizerContext.buildAnnotation(this, a))
1276 .toList(); 1278 .toList();
1277 } 1279 }
1278 return super.metadata; 1280 return super.metadata;
1279 } 1281 }
1280 1282
1281 @override 1283 @override
1282 List<TopLevelVariableElement> get topLevelVariables { 1284 List<TopLevelVariableElement> get topLevelVariables {
1283 if (_unlinkedUnit != null) { 1285 if (_unlinkedUnit != null) {
1284 if (_variables == null) { 1286 if (_variables == null) {
1285 _explicitTopLevelAccessors ??= 1287 _explicitTopLevelAccessors ??=
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) 1801 UnlinkedParam unlinkedParam, ElementImpl enclosingElement)
1800 : super.forSerialized(unlinkedParam, enclosingElement); 1802 : super.forSerialized(unlinkedParam, enclosingElement);
1801 1803
1802 @override 1804 @override
1803 Expression get constantInitializer { 1805 Expression get constantInitializer {
1804 if (_unlinkedParam != null) { 1806 if (_unlinkedParam != null) {
1805 UnlinkedConst defaultValue = _unlinkedParam.defaultValue; 1807 UnlinkedConst defaultValue = _unlinkedParam.defaultValue;
1806 if (defaultValue == null) { 1808 if (defaultValue == null) {
1807 return null; 1809 return null;
1808 } 1810 }
1809 return super.constantInitializer ??= 1811 return super.constantInitializer ??= enclosingUnit.resynthesizerContext
1810 enclosingUnit.resynthesizerContext.buildExpression(defaultValue); 1812 .buildExpression(this, defaultValue);
1811 } 1813 }
1812 return super.constantInitializer; 1814 return super.constantInitializer;
1813 } 1815 }
1814 1816
1815 @override 1817 @override
1816 void set constantInitializer(Expression initializer) { 1818 void set constantInitializer(Expression initializer) {
1817 assert(_unlinkedParam == null); 1819 assert(_unlinkedParam == null);
1818 super.constantInitializer = initializer; 1820 super.constantInitializer = initializer;
1819 } 1821 }
1820 1822
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 for (LocalVariableElement variable in variables) { 2920 for (LocalVariableElement variable in variables) {
2919 (variable as LocalVariableElementImpl).enclosingElement = this; 2921 (variable as LocalVariableElementImpl).enclosingElement = this;
2920 } 2922 }
2921 this._localVariables = variables; 2923 this._localVariables = variables;
2922 } 2924 }
2923 2925
2924 @override 2926 @override
2925 List<ElementAnnotation> get metadata { 2927 List<ElementAnnotation> get metadata {
2926 if (serializedExecutable != null) { 2928 if (serializedExecutable != null) {
2927 return _metadata ??= serializedExecutable.annotations 2929 return _metadata ??= serializedExecutable.annotations
2928 .map(enclosingUnit.resynthesizerContext.buildAnnotation) 2930 .map((a) =>
2931 enclosingUnit.resynthesizerContext.buildAnnotation(this, a))
2929 .toList(); 2932 .toList();
2930 } 2933 }
2931 return super.metadata; 2934 return super.metadata;
2932 } 2935 }
2933 2936
2934 @override 2937 @override
2935 String get name { 2938 String get name {
2936 if (serializedExecutable != null) { 2939 if (serializedExecutable != null) {
2937 return serializedExecutable.name; 2940 return serializedExecutable.name;
2938 } 2941 }
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
3426 CompilationUnitElementImpl get enclosingUnit => 3429 CompilationUnitElementImpl get enclosingUnit =>
3427 _enclosingElement as CompilationUnitElementImpl; 3430 _enclosingElement as CompilationUnitElementImpl;
3428 3431
3429 @override 3432 @override
3430 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; 3433 ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS;
3431 3434
3432 @override 3435 @override
3433 List<ElementAnnotation> get metadata { 3436 List<ElementAnnotation> get metadata {
3434 if (_unlinkedTypedef != null) { 3437 if (_unlinkedTypedef != null) {
3435 return _metadata ??= _unlinkedTypedef.annotations 3438 return _metadata ??= _unlinkedTypedef.annotations
3436 .map(enclosingUnit.resynthesizerContext.buildAnnotation) 3439 .map((a) =>
3440 enclosingUnit.resynthesizerContext.buildAnnotation(this, a))
3437 .toList(); 3441 .toList();
3438 } 3442 }
3439 return super.metadata; 3443 return super.metadata;
3440 } 3444 }
3441 3445
3442 @override 3446 @override
3443 String get name { 3447 String get name {
3444 if (_unlinkedTypedef != null) { 3448 if (_unlinkedTypedef != null) {
3445 return _unlinkedTypedef.name; 3449 return _unlinkedTypedef.name;
3446 } 3450 }
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
4104 return _loadLibraryFunction; 4108 return _loadLibraryFunction;
4105 } 4109 }
4106 4110
4107 @override 4111 @override
4108 List<ElementAnnotation> get metadata { 4112 List<ElementAnnotation> get metadata {
4109 if (_unlinkedDefiningUnit != null) { 4113 if (_unlinkedDefiningUnit != null) {
4110 if (_metadata == null) { 4114 if (_metadata == null) {
4111 CompilationUnitElementImpl definingUnit = 4115 CompilationUnitElementImpl definingUnit =
4112 _definingCompilationUnit as CompilationUnitElementImpl; 4116 _definingCompilationUnit as CompilationUnitElementImpl;
4113 _metadata ??= _unlinkedDefiningUnit.libraryAnnotations 4117 _metadata ??= _unlinkedDefiningUnit.libraryAnnotations
4114 .map(definingUnit.resynthesizerContext.buildAnnotation) 4118 .map((a) =>
4119 definingUnit.resynthesizerContext.buildAnnotation(this, a))
4115 .toList(); 4120 .toList();
4116 } 4121 }
4117 return _metadata; 4122 return _metadata;
4118 } 4123 }
4119 return super.metadata; 4124 return super.metadata;
4120 } 4125 }
4121 4126
4122 @override 4127 @override
4123 List<CompilationUnitElement> get parts => _parts; 4128 List<CompilationUnitElement> get parts => _parts;
4124 4129
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
5093 if (_unlinkedVariable != null) { 5098 if (_unlinkedVariable != null) {
5094 return _unlinkedVariable.isFinal; 5099 return _unlinkedVariable.isFinal;
5095 } 5100 }
5096 return super.isFinal; 5101 return super.isFinal;
5097 } 5102 }
5098 5103
5099 @override 5104 @override
5100 List<ElementAnnotation> get metadata { 5105 List<ElementAnnotation> get metadata {
5101 if (_unlinkedVariable != null) { 5106 if (_unlinkedVariable != null) {
5102 return _metadata ??= _unlinkedVariable.annotations 5107 return _metadata ??= _unlinkedVariable.annotations
5103 .map(enclosingUnit.resynthesizerContext.buildAnnotation) 5108 .map((a) =>
5109 enclosingUnit.resynthesizerContext.buildAnnotation(this, a))
5104 .toList(); 5110 .toList();
5105 } 5111 }
5106 return super.metadata; 5112 return super.metadata;
5107 } 5113 }
5108 5114
5109 @override 5115 @override
5110 String get name { 5116 String get name {
5111 if (_unlinkedVariable != null) { 5117 if (_unlinkedVariable != null) {
5112 return _unlinkedVariable.name; 5118 return _unlinkedVariable.name;
5113 } 5119 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
5292 @override 5298 @override
5293 ElementKind get kind => ElementKind.PARAMETER; 5299 ElementKind get kind => ElementKind.PARAMETER;
5294 5300
5295 @override 5301 @override
5296 List<ElementAnnotation> get metadata { 5302 List<ElementAnnotation> get metadata {
5297 if (_unlinkedParam != null) { 5303 if (_unlinkedParam != null) {
5298 if (_unlinkedParam.annotations.isEmpty) { 5304 if (_unlinkedParam.annotations.isEmpty) {
5299 return const <ElementAnnotation>[]; 5305 return const <ElementAnnotation>[];
5300 } 5306 }
5301 return _metadata ??= _unlinkedParam.annotations 5307 return _metadata ??= _unlinkedParam.annotations
5302 .map(enclosingUnit.resynthesizerContext.buildAnnotation) 5308 .map((a) =>
5309 enclosingUnit.resynthesizerContext.buildAnnotation(this, a))
5303 .toList(); 5310 .toList();
5304 } 5311 }
5305 return super.metadata; 5312 return super.metadata;
5306 } 5313 }
5307 5314
5308 @override 5315 @override
5309 String get name { 5316 String get name {
5310 if (_unlinkedParam != null) { 5317 if (_unlinkedParam != null) {
5311 return _unlinkedParam.name; 5318 return _unlinkedParam.name;
5312 } 5319 }
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
5704 : super.forSerialized(unlinkedVariable, enclosingElement); 5711 : super.forSerialized(unlinkedVariable, enclosingElement);
5705 } 5712 }
5706 5713
5707 /** 5714 /**
5708 * The context in which elements are resynthesized. 5715 * The context in which elements are resynthesized.
5709 */ 5716 */
5710 abstract class ResynthesizerContext { 5717 abstract class ResynthesizerContext {
5711 /** 5718 /**
5712 * Build [ElementAnnotationImpl] for the given [UnlinkedConst]. 5719 * Build [ElementAnnotationImpl] for the given [UnlinkedConst].
5713 */ 5720 */
5714 ElementAnnotationImpl buildAnnotation(UnlinkedConst uc); 5721 ElementAnnotationImpl buildAnnotation(Element context, UnlinkedConst uc);
5715 5722
5716 /** 5723 /**
5717 * Build [Expression] for the given [UnlinkedConst]. 5724 * Build [Expression] for the given [UnlinkedConst].
5718 */ 5725 */
5719 Expression buildExpression(UnlinkedConst uc); 5726 Expression buildExpression(Element context, UnlinkedConst uc);
5720 5727
5721 /** 5728 /**
5722 * Build explicit top-level property accessors. 5729 * Build explicit top-level property accessors.
5723 */ 5730 */
5724 UnitExplicitTopLevelAccessors buildTopLevelAccessors(); 5731 UnitExplicitTopLevelAccessors buildTopLevelAccessors();
5725 5732
5726 /** 5733 /**
5727 * Build explicit top-level variables. 5734 * Build explicit top-level variables.
5728 */ 5735 */
5729 UnitExplicitTopLevelVariables buildTopLevelVariables(); 5736 UnitExplicitTopLevelVariables buildTopLevelVariables();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
5933 return super.enclosingElement; 5940 return super.enclosingElement;
5934 } 5941 }
5935 5942
5936 @override 5943 @override
5937 ElementKind get kind => ElementKind.TYPE_PARAMETER; 5944 ElementKind get kind => ElementKind.TYPE_PARAMETER;
5938 5945
5939 @override 5946 @override
5940 List<ElementAnnotation> get metadata { 5947 List<ElementAnnotation> get metadata {
5941 if (_unlinkedTypeParam != null) { 5948 if (_unlinkedTypeParam != null) {
5942 return _metadata ??= _unlinkedTypeParam.annotations 5949 return _metadata ??= _unlinkedTypeParam.annotations
5943 .map(enclosingUnit.resynthesizerContext.buildAnnotation) 5950 .map((a) =>
5951 enclosingUnit.resynthesizerContext.buildAnnotation(this, a))
5944 .toList(); 5952 .toList();
5945 } 5953 }
5946 return super.metadata; 5954 return super.metadata;
5947 } 5955 }
5948 5956
5949 @override 5957 @override
5950 String get name { 5958 String get name {
5951 if (_unlinkedTypeParam != null) { 5959 if (_unlinkedTypeParam != null) {
5952 return _unlinkedTypeParam.name; 5960 return _unlinkedTypeParam.name;
5953 } 5961 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
6288 6296
6289 @override 6297 @override
6290 void visitElement(Element element) { 6298 void visitElement(Element element) {
6291 int offset = element.nameOffset; 6299 int offset = element.nameOffset;
6292 if (offset != -1) { 6300 if (offset != -1) {
6293 map[offset] = element; 6301 map[offset] = element;
6294 } 6302 }
6295 super.visitElement(element); 6303 super.visitElement(element);
6296 } 6304 }
6297 } 6305 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698