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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 221483002: Fix for translation of \!= to \!identical(), but use == and \!= for Enum. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.resolver; 8 library engine.resolver;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 */ 212 */
213 static AngularSelectorElement _parseSelectorFromString(SimpleStringLiteral lit eral) { 213 static AngularSelectorElement _parseSelectorFromString(SimpleStringLiteral lit eral) {
214 int offset = literal.valueOffset; 214 int offset = literal.valueOffset;
215 String text = literal.stringValue; 215 String text = literal.stringValue;
216 return parseSelector(offset, text); 216 return parseSelector(offset, text);
217 } 217 }
218 218
219 /** 219 /**
220 * The listener to which errors will be reported. 220 * The listener to which errors will be reported.
221 */ 221 */
222 AnalysisErrorListener _errorListener; 222 final AnalysisErrorListener _errorListener;
223 223
224 /** 224 /**
225 * The source containing the unit that will be analyzed. 225 * The source containing the unit that will be analyzed.
226 */ 226 */
227 Source _source; 227 final Source _source;
228 228
229 /** 229 /**
230 * The compilation unit with built Dart element models. 230 * The compilation unit with built Dart element models.
231 */ 231 */
232 CompilationUnit _unit; 232 final CompilationUnit _unit;
233 233
234 /** 234 /**
235 * The [ClassDeclaration] that is currently being analyzed. 235 * The [ClassDeclaration] that is currently being analyzed.
236 */ 236 */
237 ClassDeclaration _classDeclaration; 237 ClassDeclaration _classDeclaration;
238 238
239 /** 239 /**
240 * The [ClassElementImpl] that is currently being analyzed. 240 * The [ClassElementImpl] that is currently being analyzed.
241 */ 241 */
242 ClassElementImpl _classElement; 242 ClassElementImpl _classElement;
243 243
244 /** 244 /**
245 * The [ToolkitObjectElement]s to set for [classElement]. 245 * The [ToolkitObjectElement]s to set for [classElement].
246 */ 246 */
247 List<ToolkitObjectElement> _classToolkitObjects = []; 247 List<ToolkitObjectElement> _classToolkitObjects = [];
248 248
249 /** 249 /**
250 * The [Annotation] that is currently being analyzed. 250 * The [Annotation] that is currently being analyzed.
251 */ 251 */
252 Annotation _annotation; 252 Annotation _annotation;
253 253
254 /** 254 /**
255 * Initialize a newly created compilation unit element builder. 255 * Initialize a newly created compilation unit element builder.
256 * 256 *
257 * @param errorListener the listener to which errors will be reported. 257 * @param errorListener the listener to which errors will be reported.
258 * @param source the source containing the unit that will be analyzed 258 * @param source the source containing the unit that will be analyzed
259 * @param unit the compilation unit with built Dart element models 259 * @param unit the compilation unit with built Dart element models
260 */ 260 */
261 AngularCompilationUnitBuilder(AnalysisErrorListener errorListener, Source sour ce, CompilationUnit unit) { 261 AngularCompilationUnitBuilder(this._errorListener, this._source, this._unit);
262 this._errorListener = errorListener;
263 this._source = source;
264 this._unit = unit;
265 }
266 262
267 /** 263 /**
268 * Builds Angular specific element models and adds them to the existing Dart e lements. 264 * Builds Angular specific element models and adds them to the existing Dart e lements.
269 */ 265 */
270 void build() { 266 void build() {
271 _parseViews(); 267 _parseViews();
272 // process classes 268 // process classes
273 for (CompilationUnitMember unitMember in _unit.declarations) { 269 for (CompilationUnitMember unitMember in _unit.declarations) {
274 if (unitMember is ClassDeclaration) { 270 if (unitMember is ClassDeclaration) {
275 this._classDeclaration = unitMember; 271 this._classDeclaration = unitMember;
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 return null; 1547 return null;
1552 } 1548 }
1553 1549
1554 /** 1550 /**
1555 * Return `true` if the given token is a token for the given keyword. 1551 * Return `true` if the given token is a token for the given keyword.
1556 * 1552 *
1557 * @param token the token being tested 1553 * @param token the token being tested
1558 * @param keyword the keyword being tested for 1554 * @param keyword the keyword being tested for
1559 * @return `true` if the given token is a token for the given keyword 1555 * @return `true` if the given token is a token for the given keyword
1560 */ 1556 */
1561 bool _matches(sc.Token token, sc.Keyword keyword) => token != null && identica l(token.type, sc.TokenType.KEYWORD) && identical((token as sc.KeywordToken).keyw ord, keyword); 1557 bool _matches(sc.Token token, sc.Keyword keyword) => token != null && token.ty pe == sc.TokenType.KEYWORD && (token as sc.KeywordToken).keyword == keyword;
1562 1558
1563 /** 1559 /**
1564 * Sets the visible source range for formal parameter. 1560 * Sets the visible source range for formal parameter.
1565 */ 1561 */
1566 void _setParameterVisibleRange(FormalParameter node, ParameterElementImpl elem ent) { 1562 void _setParameterVisibleRange(FormalParameter node, ParameterElementImpl elem ent) {
1567 FunctionBody body = _getFunctionBody(node); 1563 FunctionBody body = _getFunctionBody(node);
1568 if (body != null) { 1564 if (body != null) {
1569 element.setVisibleRange(body.offset, body.length); 1565 element.setVisibleRange(body.offset, body.length);
1570 } 1566 }
1571 } 1567 }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 1970
1975 /** 1971 /**
1976 * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit. 1972 * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit.
1977 */ 1973 */
1978 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { 1974 class HtmlUnitBuilder implements ht.XmlVisitor<Object> {
1979 static String _SRC = "src"; 1975 static String _SRC = "src";
1980 1976
1981 /** 1977 /**
1982 * The analysis context in which the element model will be built. 1978 * The analysis context in which the element model will be built.
1983 */ 1979 */
1984 InternalAnalysisContext _context; 1980 final InternalAnalysisContext _context;
1985 1981
1986 /** 1982 /**
1987 * The error listener to which errors will be reported. 1983 * The error listener to which errors will be reported.
1988 */ 1984 */
1989 RecordingErrorListener _errorListener; 1985 RecordingErrorListener _errorListener;
1990 1986
1991 /** 1987 /**
1992 * The modification time of the source for which an element is being built. 1988 * The modification time of the source for which an element is being built.
1993 */ 1989 */
1994 int _modificationStamp = 0; 1990 int _modificationStamp = 0;
(...skipping 16 matching lines...) Expand all
2011 /** 2007 /**
2012 * A set of the libraries that were resolved while resolving the HTML unit. 2008 * A set of the libraries that were resolved while resolving the HTML unit.
2013 */ 2009 */
2014 Set<Library> _resolvedLibraries = new Set<Library>(); 2010 Set<Library> _resolvedLibraries = new Set<Library>();
2015 2011
2016 /** 2012 /**
2017 * Initialize a newly created HTML unit builder. 2013 * Initialize a newly created HTML unit builder.
2018 * 2014 *
2019 * @param context the analysis context in which the element model will be buil t 2015 * @param context the analysis context in which the element model will be buil t
2020 */ 2016 */
2021 HtmlUnitBuilder(InternalAnalysisContext context) { 2017 HtmlUnitBuilder(this._context) {
2022 this._context = context;
2023 this._errorListener = new RecordingErrorListener(); 2018 this._errorListener = new RecordingErrorListener();
2024 } 2019 }
2025 2020
2026 /** 2021 /**
2027 * Build the HTML element for the given source. 2022 * Build the HTML element for the given source.
2028 * 2023 *
2029 * @param source the source describing the compilation unit 2024 * @param source the source describing the compilation unit
2030 * @param modificationStamp the modification time of the source for which an e lement is being 2025 * @param modificationStamp the modification time of the source for which an e lement is being
2031 * built 2026 * built
2032 * @param unit the AST structure representing the HTML 2027 * @param unit the AST structure representing the HTML
(...skipping 27 matching lines...) Expand all
2060 @override 2055 @override
2061 Object visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) { 2056 Object visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) {
2062 if (_parentNodes.contains(node)) { 2057 if (_parentNodes.contains(node)) {
2063 return _reportCircularity(node); 2058 return _reportCircularity(node);
2064 } 2059 }
2065 _parentNodes.add(node); 2060 _parentNodes.add(node);
2066 try { 2061 try {
2067 Source htmlSource = _htmlElement.source; 2062 Source htmlSource = _htmlElement.source;
2068 ht.XmlAttributeNode scriptAttribute = _getScriptSourcePath(node); 2063 ht.XmlAttributeNode scriptAttribute = _getScriptSourcePath(node);
2069 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribute .text; 2064 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribute .text;
2070 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) { 2065 if (node.attributeEnd.type == ht.TokenType.GT && scriptSourcePath == null) {
2071 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node); 2066 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node);
2072 try { 2067 try {
2073 LibraryResolver resolver = new LibraryResolver(_context); 2068 LibraryResolver resolver = new LibraryResolver(_context);
2074 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc e, _modificationStamp, node.script, true) as LibraryElementImpl; 2069 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc e, _modificationStamp, node.script, true) as LibraryElementImpl;
2075 script.scriptLibrary = library; 2070 script.scriptLibrary = library;
2076 _resolvedLibraries.addAll(resolver.resolvedLibraries); 2071 _resolvedLibraries.addAll(resolver.resolvedLibraries);
2077 _errorListener.addAll(resolver.errorListener); 2072 _errorListener.addAll(resolver.errorListener);
2078 } on AnalysisException catch (exception) { 2073 } on AnalysisException catch (exception) {
2079 //TODO (danrubel): Handle or forward the exception 2074 //TODO (danrubel): Handle or forward the exception
2080 AnalysisEngine.instance.logger.logError2("Could not resolve script tag ", exception); 2075 AnalysisEngine.instance.logger.logError2("Could not resolve script tag ", exception);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 2242
2248 /** 2243 /**
2249 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of 2244 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
2250 * a class. 2245 * a class.
2251 */ 2246 */
2252 ClassElement _enclosingClass; 2247 ClassElement _enclosingClass;
2253 2248
2254 /** 2249 /**
2255 * The error reporter by which errors will be reported. 2250 * The error reporter by which errors will be reported.
2256 */ 2251 */
2257 ErrorReporter _errorReporter; 2252 final ErrorReporter _errorReporter;
2258 2253
2259 /** 2254 /**
2260 * Create a new instance of the [BestPracticesVerifier]. 2255 * Create a new instance of the [BestPracticesVerifier].
2261 * 2256 *
2262 * @param errorReporter the error reporter 2257 * @param errorReporter the error reporter
2263 */ 2258 */
2264 BestPracticesVerifier(ErrorReporter errorReporter) { 2259 BestPracticesVerifier(this._errorReporter);
2265 this._errorReporter = errorReporter;
2266 }
2267 2260
2268 @override 2261 @override
2269 Object visitArgumentList(ArgumentList node) { 2262 Object visitArgumentList(ArgumentList node) {
2270 _checkForArgumentTypesNotAssignableInList(node); 2263 _checkForArgumentTypesNotAssignableInList(node);
2271 return super.visitArgumentList(node); 2264 return super.visitArgumentList(node);
2272 } 2265 }
2273 2266
2274 @override 2267 @override
2275 Object visitAsExpression(AsExpression node) { 2268 Object visitAsExpression(AsExpression node) {
2276 _checkForUnnecessaryCast(node); 2269 _checkForUnnecessaryCast(node);
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 } 2795 }
2803 2796
2804 /** 2797 /**
2805 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for 2798 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for
2806 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE]. 2799 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE].
2807 */ 2800 */
2808 class Dart2JSVerifier extends RecursiveAstVisitor<Object> { 2801 class Dart2JSVerifier extends RecursiveAstVisitor<Object> {
2809 /** 2802 /**
2810 * The error reporter by which errors will be reported. 2803 * The error reporter by which errors will be reported.
2811 */ 2804 */
2812 ErrorReporter _errorReporter; 2805 final ErrorReporter _errorReporter;
2813 2806
2814 /** 2807 /**
2815 * The name of the `double` type. 2808 * The name of the `double` type.
2816 */ 2809 */
2817 static String _DOUBLE_TYPE_NAME = "double"; 2810 static String _DOUBLE_TYPE_NAME = "double";
2818 2811
2819 /** 2812 /**
2820 * Create a new instance of the [Dart2JSVerifier]. 2813 * Create a new instance of the [Dart2JSVerifier].
2821 * 2814 *
2822 * @param errorReporter the error reporter 2815 * @param errorReporter the error reporter
2823 */ 2816 */
2824 Dart2JSVerifier(ErrorReporter errorReporter) { 2817 Dart2JSVerifier(this._errorReporter);
2825 this._errorReporter = errorReporter;
2826 }
2827 2818
2828 @override 2819 @override
2829 Object visitIsExpression(IsExpression node) { 2820 Object visitIsExpression(IsExpression node) {
2830 _checkForIsDoubleHints(node); 2821 _checkForIsDoubleHints(node);
2831 return super.visitIsExpression(node); 2822 return super.visitIsExpression(node);
2832 } 2823 }
2833 2824
2834 /** 2825 /**
2835 * Check for instances of `x is double`, `x is int`, `x is! double` and 2826 * Check for instances of `x is double`, `x is int`, `x is! double` and
2836 * `x is! int`. 2827 * `x is! int`.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 } 2863 }
2873 2864
2874 /** 2865 /**
2875 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of 2866 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of
2876 * [HintCode#DEAD_CODE]. 2867 * [HintCode#DEAD_CODE].
2877 */ 2868 */
2878 class DeadCodeVerifier extends RecursiveAstVisitor<Object> { 2869 class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
2879 /** 2870 /**
2880 * The error reporter by which errors will be reported. 2871 * The error reporter by which errors will be reported.
2881 */ 2872 */
2882 ErrorReporter _errorReporter; 2873 final ErrorReporter _errorReporter;
2883 2874
2884 /** 2875 /**
2885 * Create a new instance of the [DeadCodeVerifier]. 2876 * Create a new instance of the [DeadCodeVerifier].
2886 * 2877 *
2887 * @param errorReporter the error reporter 2878 * @param errorReporter the error reporter
2888 */ 2879 */
2889 DeadCodeVerifier(ErrorReporter errorReporter) { 2880 DeadCodeVerifier(this._errorReporter);
2890 this._errorReporter = errorReporter;
2891 }
2892 2881
2893 @override 2882 @override
2894 Object visitBinaryExpression(BinaryExpression node) { 2883 Object visitBinaryExpression(BinaryExpression node) {
2895 sc.Token operator = node.operator; 2884 sc.Token operator = node.operator;
2896 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND); 2885 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND;
2897 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR); 2886 bool isBarBar = operator.type == sc.TokenType.BAR_BAR;
2898 if (isAmpAmp || isBarBar) { 2887 if (isAmpAmp || isBarBar) {
2899 Expression lhsCondition = node.leftOperand; 2888 Expression lhsCondition = node.leftOperand;
2900 if (!_isDebugConstant(lhsCondition)) { 2889 if (!_isDebugConstant(lhsCondition)) {
2901 ValidResult lhsResult = _getConstantBooleanValue(lhsCondition); 2890 ValidResult lhsResult = _getConstantBooleanValue(lhsCondition);
2902 if (lhsResult != null) { 2891 if (lhsResult != null) {
2903 if (lhsResult.isTrue && isBarBar) { 2892 if (lhsResult.isTrue && isBarBar) {
2904 // report error on else block: true || !e! 2893 // report error on else block: true || !e!
2905 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.rightOper and, []); 2894 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.rightOper and, []);
2906 // only visit the LHS: 2895 // only visit the LHS:
2907 _safelyVisit(lhsCondition); 2896 _safelyVisit(lhsCondition);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3172 bool visitAssignmentExpression(AssignmentExpression node) => node.leftHandSide .accept(this) || node.rightHandSide.accept(this); 3161 bool visitAssignmentExpression(AssignmentExpression node) => node.leftHandSide .accept(this) || node.rightHandSide.accept(this);
3173 3162
3174 @override 3163 @override
3175 bool visitBinaryExpression(BinaryExpression node) { 3164 bool visitBinaryExpression(BinaryExpression node) {
3176 Expression lhsExpression = node.leftOperand; 3165 Expression lhsExpression = node.leftOperand;
3177 sc.TokenType operatorType = node.operator.type; 3166 sc.TokenType operatorType = node.operator.type;
3178 // If the operator is || and the left hand side is false literal, don't cons ider the RHS of the 3167 // If the operator is || and the left hand side is false literal, don't cons ider the RHS of the
3179 // binary expression. 3168 // binary expression.
3180 // TODO(jwren) Do we want to take constant expressions into account, evaluat e if(false) {} 3169 // TODO(jwren) Do we want to take constant expressions into account, evaluat e if(false) {}
3181 // differently than if(<condition>), when <condition> evaluates to a constan t false value? 3170 // differently than if(<condition>), when <condition> evaluates to a constan t false value?
3182 if (identical(operatorType, sc.TokenType.BAR_BAR)) { 3171 if (operatorType == sc.TokenType.BAR_BAR) {
3183 if (lhsExpression is BooleanLiteral) { 3172 if (lhsExpression is BooleanLiteral) {
3184 BooleanLiteral booleanLiteral = lhsExpression; 3173 BooleanLiteral booleanLiteral = lhsExpression;
3185 if (!booleanLiteral.value) { 3174 if (!booleanLiteral.value) {
3186 return false; 3175 return false;
3187 } 3176 }
3188 } 3177 }
3189 } 3178 }
3190 // If the operator is && and the left hand side is true literal, don't consi der the RHS of the 3179 // If the operator is && and the left hand side is true literal, don't consi der the RHS of the
3191 // binary expression. 3180 // binary expression.
3192 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) { 3181 if (operatorType == sc.TokenType.AMPERSAND_AMPERSAND) {
3193 if (lhsExpression is BooleanLiteral) { 3182 if (lhsExpression is BooleanLiteral) {
3194 BooleanLiteral booleanLiteral = lhsExpression; 3183 BooleanLiteral booleanLiteral = lhsExpression;
3195 if (booleanLiteral.value) { 3184 if (booleanLiteral.value) {
3196 return false; 3185 return false;
3197 } 3186 }
3198 } 3187 }
3199 } 3188 }
3200 return lhsExpression.accept(this) || node.rightOperand.accept(this); 3189 Expression rhsExpression = node.rightOperand;
3190 return (lhsExpression != null && lhsExpression.accept(this)) || (rhsExpressi on != null && rhsExpression.accept(this));
3201 } 3191 }
3202 3192
3203 @override 3193 @override
3204 bool visitBlock(Block node) => _visitStatements(node.statements); 3194 bool visitBlock(Block node) => _visitStatements(node.statements);
3205 3195
3206 @override 3196 @override
3207 bool visitBlockFunctionBody(BlockFunctionBody node) => node.block.accept(this) ; 3197 bool visitBlockFunctionBody(BlockFunctionBody node) => node.block.accept(this) ;
3208 3198
3209 @override 3199 @override
3210 bool visitBreakStatement(BreakStatement node) { 3200 bool visitBreakStatement(BreakStatement node) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 } 3546 }
3557 } 3547 }
3558 3548
3559 /** 3549 /**
3560 * Instances of the class `HintGenerator` traverse a library's worth of dart cod e at a time to 3550 * Instances of the class `HintGenerator` traverse a library's worth of dart cod e at a time to
3561 * generate hints over the set of sources. 3551 * generate hints over the set of sources.
3562 * 3552 *
3563 * @see HintCode 3553 * @see HintCode
3564 */ 3554 */
3565 class HintGenerator { 3555 class HintGenerator {
3566 List<CompilationUnit> _compilationUnits; 3556 final List<CompilationUnit> _compilationUnits;
3567 3557
3568 AnalysisContext _context; 3558 final AnalysisContext _context;
3569 3559
3570 AnalysisErrorListener _errorListener; 3560 final AnalysisErrorListener _errorListener;
3571 3561
3572 ImportsVerifier _importsVerifier; 3562 ImportsVerifier _importsVerifier;
3573 3563
3574 bool _enableDart2JSHints = false; 3564 bool _enableDart2JSHints = false;
3575 3565
3576 /** 3566 /**
3577 * The inheritance manager used to find overridden methods. 3567 * The inheritance manager used to find overridden methods.
3578 */ 3568 */
3579 InheritanceManager _manager; 3569 InheritanceManager _manager;
3580 3570
3581 HintGenerator(List<CompilationUnit> compilationUnits, AnalysisContext context, AnalysisErrorListener errorListener) { 3571 HintGenerator(this._compilationUnits, this._context, this._errorListener) {
3582 this._compilationUnits = compilationUnits; 3572 LibraryElement library = _compilationUnits[0].element.library;
3583 this._context = context;
3584 this._errorListener = errorListener;
3585 LibraryElement library = compilationUnits[0].element.library;
3586 _importsVerifier = new ImportsVerifier(library); 3573 _importsVerifier = new ImportsVerifier(library);
3587 _enableDart2JSHints = context.analysisOptions.dart2jsHint; 3574 _enableDart2JSHints = _context.analysisOptions.dart2jsHint;
3588 _manager = new InheritanceManager(compilationUnits[0].element.library); 3575 _manager = new InheritanceManager(_compilationUnits[0].element.library);
3589 } 3576 }
3590 3577
3591 void generateForLibrary() { 3578 void generateForLibrary() {
3592 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.hints.star t(); 3579 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.hints.star t();
3593 try { 3580 try {
3594 for (int i = 0; i < _compilationUnits.length; i++) { 3581 for (int i = 0; i < _compilationUnits.length; i++) {
3595 CompilationUnitElement element = _compilationUnits[i].element; 3582 CompilationUnitElement element = _compilationUnits[i].element;
3596 if (element != null) { 3583 if (element != null) {
3597 if (i == 0) { 3584 if (i == 0) {
3598 _importsVerifier.inDefiningCompilationUnit = true; 3585 _importsVerifier.inDefiningCompilationUnit = true;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3973 } 3960 }
3974 3961
3975 /** 3962 /**
3976 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation 3963 * Instances of the class `OverrideVerifier` visit all of the declarations in a compilation
3977 * unit to verify that if they have an override annotation it is being used corr ectly. 3964 * unit to verify that if they have an override annotation it is being used corr ectly.
3978 */ 3965 */
3979 class OverrideVerifier extends RecursiveAstVisitor<Object> { 3966 class OverrideVerifier extends RecursiveAstVisitor<Object> {
3980 /** 3967 /**
3981 * The inheritance manager used to find overridden methods. 3968 * The inheritance manager used to find overridden methods.
3982 */ 3969 */
3983 InheritanceManager _manager; 3970 final InheritanceManager _manager;
3984 3971
3985 /** 3972 /**
3986 * The error reporter used to report errors. 3973 * The error reporter used to report errors.
3987 */ 3974 */
3988 ErrorReporter _errorReporter; 3975 final ErrorReporter _errorReporter;
3989 3976
3990 /** 3977 /**
3991 * Initialize a newly created verifier to look for inappropriate uses of the o verride annotation. 3978 * Initialize a newly created verifier to look for inappropriate uses of the o verride annotation.
3992 * 3979 *
3993 * @param manager the inheritance manager used to find overridden methods 3980 * @param manager the inheritance manager used to find overridden methods
3994 * @param errorReporter the error reporter used to report errors 3981 * @param errorReporter the error reporter used to report errors
3995 */ 3982 */
3996 OverrideVerifier(InheritanceManager manager, ErrorReporter errorReporter) { 3983 OverrideVerifier(this._manager, this._errorReporter);
3997 this._manager = manager;
3998 this._errorReporter = errorReporter;
3999 }
4000 3984
4001 @override 3985 @override
4002 Object visitMethodDeclaration(MethodDeclaration node) { 3986 Object visitMethodDeclaration(MethodDeclaration node) {
4003 ExecutableElement element = node.element; 3987 ExecutableElement element = node.element;
4004 if (_isOverride(element)) { 3988 if (_isOverride(element)) {
4005 if (_getOverriddenMember(element) == null) { 3989 if (_getOverriddenMember(element) == null) {
4006 if (element is MethodElement) { 3990 if (element is MethodElement) {
4007 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDING_ METHOD, node.name, []); 3991 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_ON_NON_OVERRIDING_ METHOD, node.name, []);
4008 } else if (element is PropertyAccessorElement) { 3992 } else if (element is PropertyAccessorElement) {
4009 if (element.isGetter) { 3993 if (element.isGetter) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4047 /** 4031 /**
4048 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from 4032 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from
4049 * pub best practices. 4033 * pub best practices.
4050 */ 4034 */
4051 class PubVerifier extends RecursiveAstVisitor<Object> { 4035 class PubVerifier extends RecursiveAstVisitor<Object> {
4052 static String _PUBSPEC_YAML = "pubspec.yaml"; 4036 static String _PUBSPEC_YAML = "pubspec.yaml";
4053 4037
4054 /** 4038 /**
4055 * The analysis context containing the sources to be analyzed 4039 * The analysis context containing the sources to be analyzed
4056 */ 4040 */
4057 AnalysisContext _context; 4041 final AnalysisContext _context;
4058 4042
4059 /** 4043 /**
4060 * The error reporter by which errors will be reported. 4044 * The error reporter by which errors will be reported.
4061 */ 4045 */
4062 ErrorReporter _errorReporter; 4046 final ErrorReporter _errorReporter;
4063 4047
4064 PubVerifier(AnalysisContext context, ErrorReporter errorReporter) { 4048 PubVerifier(this._context, this._errorReporter);
4065 this._context = context;
4066 this._errorReporter = errorReporter;
4067 }
4068 4049
4069 @override 4050 @override
4070 Object visitImportDirective(ImportDirective directive) { 4051 Object visitImportDirective(ImportDirective directive) {
4071 return null; 4052 return null;
4072 } 4053 }
4073 4054
4074 /** 4055 /**
4075 * This verifies that the passed file import directive is not contained in a s ource inside a 4056 * This verifies that the passed file import directive is not contained in a s ource inside a
4076 * package "lib" directory hierarchy referencing a source outside that package "lib" directory 4057 * package "lib" directory hierarchy referencing a source outside that package "lib" directory
4077 * hierarchy. 4058 * hierarchy.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4206 } 4187 }
4207 } 4188 }
4208 4189
4209 /** 4190 /**
4210 * Instances of the class `ToDoFinder` find to-do comments in Dart code. 4191 * Instances of the class `ToDoFinder` find to-do comments in Dart code.
4211 */ 4192 */
4212 class ToDoFinder { 4193 class ToDoFinder {
4213 /** 4194 /**
4214 * The error reporter by which to-do comments will be reported. 4195 * The error reporter by which to-do comments will be reported.
4215 */ 4196 */
4216 ErrorReporter _errorReporter; 4197 final ErrorReporter _errorReporter;
4217 4198
4218 /** 4199 /**
4219 * Initialize a newly created to-do finder to report to-do comments to the giv en reporter. 4200 * Initialize a newly created to-do finder to report to-do comments to the giv en reporter.
4220 * 4201 *
4221 * @param errorReporter the error reporter by which to-do comments will be rep orted 4202 * @param errorReporter the error reporter by which to-do comments will be rep orted
4222 */ 4203 */
4223 ToDoFinder(ErrorReporter errorReporter) { 4204 ToDoFinder(this._errorReporter);
4224 this._errorReporter = errorReporter;
4225 }
4226 4205
4227 /** 4206 /**
4228 * Search the comments in the given compilation unit for to-do comments and re port an error for 4207 * Search the comments in the given compilation unit for to-do comments and re port an error for
4229 * each. 4208 * each.
4230 * 4209 *
4231 * @param unit the compilation unit containing the to-do comments 4210 * @param unit the compilation unit containing the to-do comments
4232 */ 4211 */
4233 void findIn(CompilationUnit unit) { 4212 void findIn(CompilationUnit unit) {
4234 _gatherTodoComments(unit.beginToken); 4213 _gatherTodoComments(unit.beginToken);
4235 } 4214 }
4236 4215
4237 /** 4216 /**
4238 * Search the comment tokens reachable from the given token and create errors for each to-do 4217 * Search the comment tokens reachable from the given token and create errors for each to-do
4239 * comment. 4218 * comment.
4240 * 4219 *
4241 * @param token the head of the list of tokens being searched 4220 * @param token the head of the list of tokens being searched
4242 */ 4221 */
4243 void _gatherTodoComments(sc.Token token) { 4222 void _gatherTodoComments(sc.Token token) {
4244 while (token != null && token.type != sc.TokenType.EOF) { 4223 while (token != null && token.type != sc.TokenType.EOF) {
4245 sc.Token commentToken = token.precedingComments; 4224 sc.Token commentToken = token.precedingComments;
4246 while (commentToken != null) { 4225 while (commentToken != null) {
4247 if (identical(commentToken.type, sc.TokenType.SINGLE_LINE_COMMENT) || id entical(commentToken.type, sc.TokenType.MULTI_LINE_COMMENT)) { 4226 if (commentToken.type == sc.TokenType.SINGLE_LINE_COMMENT || commentToke n.type == sc.TokenType.MULTI_LINE_COMMENT) {
4248 _scrapeTodoComment(commentToken); 4227 _scrapeTodoComment(commentToken);
4249 } 4228 }
4250 commentToken = commentToken.next; 4229 commentToken = commentToken.next;
4251 } 4230 }
4252 token = token.next; 4231 token = token.next;
4253 } 4232 }
4254 } 4233 }
4255 4234
4256 /** 4235 /**
4257 * Look for user defined tasks in comments and convert them into info level an alysis issues. 4236 * Look for user defined tasks in comments and convert them into info level an alysis issues.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
4478 SimpleIdentifier functionName = node.name; 4457 SimpleIdentifier functionName = node.name;
4479 sc.Token property = node.propertyKeyword; 4458 sc.Token property = node.propertyKeyword;
4480 if (property == null) { 4459 if (property == null) {
4481 if (_enclosingExecutable != null) { 4460 if (_enclosingExecutable != null) {
4482 _enclosingExecutable = _findIdentifier(_enclosingExecutable.functions, functionName); 4461 _enclosingExecutable = _findIdentifier(_enclosingExecutable.functions, functionName);
4483 } else { 4462 } else {
4484 _enclosingExecutable = _findIdentifier(_enclosingUnit.functions, funct ionName); 4463 _enclosingExecutable = _findIdentifier(_enclosingUnit.functions, funct ionName);
4485 } 4464 }
4486 } else { 4465 } else {
4487 PropertyAccessorElement accessor = _findIdentifier(_enclosingUnit.access ors, functionName); 4466 PropertyAccessorElement accessor = _findIdentifier(_enclosingUnit.access ors, functionName);
4488 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 4467 if ((property as sc.KeywordToken).keyword == sc.Keyword.SET) {
4489 accessor = accessor.variable.setter; 4468 accessor = accessor.variable.setter;
4490 } 4469 }
4491 _enclosingExecutable = accessor; 4470 _enclosingExecutable = accessor;
4492 } 4471 }
4493 processElement(_enclosingExecutable); 4472 processElement(_enclosingExecutable);
4494 return super.visitFunctionDeclaration(node); 4473 return super.visitFunctionDeclaration(node);
4495 } finally { 4474 } finally {
4496 _enclosingExecutable = outerExecutable; 4475 _enclosingExecutable = outerExecutable;
4497 } 4476 }
4498 } 4477 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 SimpleIdentifier methodName = node.name; 4552 SimpleIdentifier methodName = node.name;
4574 String nameOfMethod = methodName.name; 4553 String nameOfMethod = methodName.name;
4575 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) { 4554 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
4576 nameOfMethod = "unary-"; 4555 nameOfMethod = "unary-";
4577 } 4556 }
4578 if (property == null) { 4557 if (property == null) {
4579 _enclosingExecutable = _findWithNameAndOffset(_enclosingClass.methods, n ameOfMethod, methodName.offset); 4558 _enclosingExecutable = _findWithNameAndOffset(_enclosingClass.methods, n ameOfMethod, methodName.offset);
4580 methodName.staticElement = _enclosingExecutable; 4559 methodName.staticElement = _enclosingExecutable;
4581 } else { 4560 } else {
4582 PropertyAccessorElement accessor = _findIdentifier(_enclosingClass.acces sors, methodName); 4561 PropertyAccessorElement accessor = _findIdentifier(_enclosingClass.acces sors, methodName);
4583 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 4562 if ((property as sc.KeywordToken).keyword == sc.Keyword.SET) {
4584 accessor = accessor.variable.setter; 4563 accessor = accessor.variable.setter;
4585 methodName.staticElement = accessor; 4564 methodName.staticElement = accessor;
4586 } 4565 }
4587 _enclosingExecutable = accessor; 4566 _enclosingExecutable = accessor;
4588 } 4567 }
4589 processElement(_enclosingExecutable); 4568 processElement(_enclosingExecutable);
4590 return super.visitMethodDeclaration(node); 4569 return super.visitMethodDeclaration(node);
4591 } finally { 4570 } finally {
4592 _enclosingExecutable = outerExecutable; 4571 _enclosingExecutable = outerExecutable;
4593 } 4572 }
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
5076 SimpleIdentifier functionName = node.name; 5055 SimpleIdentifier functionName = node.name;
5077 sc.Token property = node.propertyKeyword; 5056 sc.Token property = node.propertyKeyword;
5078 if (property == null) { 5057 if (property == null) {
5079 if (_enclosingExecutable != null) { 5058 if (_enclosingExecutable != null) {
5080 _enclosingExecutable = _findIdentifier(_enclosingExecutable.functions, functionName); 5059 _enclosingExecutable = _findIdentifier(_enclosingExecutable.functions, functionName);
5081 } else { 5060 } else {
5082 _enclosingExecutable = _findIdentifier(_enclosingUnit.functions, funct ionName); 5061 _enclosingExecutable = _findIdentifier(_enclosingUnit.functions, funct ionName);
5083 } 5062 }
5084 } else { 5063 } else {
5085 PropertyAccessorElement accessor = _findIdentifier(_enclosingUnit.access ors, functionName); 5064 PropertyAccessorElement accessor = _findIdentifier(_enclosingUnit.access ors, functionName);
5086 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 5065 if ((property as sc.KeywordToken).keyword == sc.Keyword.SET) {
5087 accessor = accessor.variable.setter; 5066 accessor = accessor.variable.setter;
5088 functionName.staticElement = accessor; 5067 functionName.staticElement = accessor;
5089 } 5068 }
5090 _enclosingExecutable = accessor; 5069 _enclosingExecutable = accessor;
5091 } 5070 }
5092 node.functionExpression.element = _enclosingExecutable; 5071 node.functionExpression.element = _enclosingExecutable;
5093 return super.visitFunctionDeclaration(node); 5072 return super.visitFunctionDeclaration(node);
5094 } finally { 5073 } finally {
5095 _enclosingExecutable = outerExecutable; 5074 _enclosingExecutable = outerExecutable;
5096 } 5075 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
5174 SimpleIdentifier methodName = node.name; 5153 SimpleIdentifier methodName = node.name;
5175 String nameOfMethod = methodName.name; 5154 String nameOfMethod = methodName.name;
5176 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) { 5155 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
5177 nameOfMethod = "unary-"; 5156 nameOfMethod = "unary-";
5178 } 5157 }
5179 if (property == null) { 5158 if (property == null) {
5180 _enclosingExecutable = _findWithNameAndOffset(_enclosingClass.methods, n ameOfMethod, methodName.offset); 5159 _enclosingExecutable = _findWithNameAndOffset(_enclosingClass.methods, n ameOfMethod, methodName.offset);
5181 methodName.staticElement = _enclosingExecutable; 5160 methodName.staticElement = _enclosingExecutable;
5182 } else { 5161 } else {
5183 PropertyAccessorElement accessor = _findIdentifier(_enclosingClass.acces sors, methodName); 5162 PropertyAccessorElement accessor = _findIdentifier(_enclosingClass.acces sors, methodName);
5184 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 5163 if ((property as sc.KeywordToken).keyword == sc.Keyword.SET) {
5185 accessor = accessor.variable.setter; 5164 accessor = accessor.variable.setter;
5186 methodName.staticElement = accessor; 5165 methodName.staticElement = accessor;
5187 } 5166 }
5188 _enclosingExecutable = accessor; 5167 _enclosingExecutable = accessor;
5189 } 5168 }
5190 return super.visitMethodDeclaration(node); 5169 return super.visitMethodDeclaration(node);
5191 } finally { 5170 } finally {
5192 _enclosingExecutable = outerExecutable; 5171 _enclosingExecutable = outerExecutable;
5193 } 5172 }
5194 } 5173 }
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
5558 MethodDeclaration method = n as MethodDeclaration; 5537 MethodDeclaration method = n as MethodDeclaration;
5559 return !method.isStatic; 5538 return !method.isStatic;
5560 } 5539 }
5561 } 5540 }
5562 return false; 5541 return false;
5563 } 5542 }
5564 5543
5565 /** 5544 /**
5566 * The resolver driving this participant. 5545 * The resolver driving this participant.
5567 */ 5546 */
5568 ResolverVisitor _resolver; 5547 final ResolverVisitor _resolver;
5569 5548
5570 /** 5549 /**
5571 * The element for the library containing the compilation unit being visited. 5550 * The element for the library containing the compilation unit being visited.
5572 */ 5551 */
5573 LibraryElement _definingLibrary; 5552 LibraryElement _definingLibrary;
5574 5553
5575 /** 5554 /**
5576 * A flag indicating whether we should generate hints. 5555 * A flag indicating whether we should generate hints.
5577 */ 5556 */
5578 bool _enableHints = false; 5557 bool _enableHints = false;
(...skipping 28 matching lines...) Expand all
5607 * The name of the method that will be invoked if an attempt is made to invoke an undefined method 5586 * The name of the method that will be invoked if an attempt is made to invoke an undefined method
5608 * on an object. 5587 * on an object.
5609 */ 5588 */
5610 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; 5589 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
5611 5590
5612 /** 5591 /**
5613 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 5592 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
5614 * 5593 *
5615 * @param resolver the resolver driving this participant 5594 * @param resolver the resolver driving this participant
5616 */ 5595 */
5617 ElementResolver(ResolverVisitor resolver) { 5596 ElementResolver(this._resolver) {
5618 this._resolver = resolver; 5597 this._definingLibrary = _resolver.definingLibrary;
5619 this._definingLibrary = resolver.definingLibrary;
5620 AnalysisOptions options = _definingLibrary.context.analysisOptions; 5598 AnalysisOptions options = _definingLibrary.context.analysisOptions;
5621 _enableHints = options.hint; 5599 _enableHints = options.hint;
5622 _dynamicType = resolver.typeProvider.dynamicType; 5600 _dynamicType = _resolver.typeProvider.dynamicType;
5623 _typeType = resolver.typeProvider.typeType; 5601 _typeType = _resolver.typeProvider.typeType;
5624 _subtypeManager = new SubtypeManager(); 5602 _subtypeManager = new SubtypeManager();
5625 _promoteManager = resolver.promoteManager; 5603 _promoteManager = _resolver.promoteManager;
5626 } 5604 }
5627 5605
5628 @override 5606 @override
5629 Object visitAssignmentExpression(AssignmentExpression node) { 5607 Object visitAssignmentExpression(AssignmentExpression node) {
5630 sc.Token operator = node.operator; 5608 sc.Token operator = node.operator;
5631 sc.TokenType operatorType = operator.type; 5609 sc.TokenType operatorType = operator.type;
5632 if (operatorType != sc.TokenType.EQ) { 5610 if (operatorType != sc.TokenType.EQ) {
5633 operatorType = _operatorFromCompoundAssignment(operatorType); 5611 operatorType = _operatorFromCompoundAssignment(operatorType);
5634 Expression leftHandSide = node.leftHandSide; 5612 Expression leftHandSide = node.leftHandSide;
5635 if (leftHandSide != null) { 5613 if (leftHandSide != null) {
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
6223 // is really equivalent to a property access node. 6201 // is really equivalent to a property access node.
6224 // 6202 //
6225 _resolvePropertyAccess(prefix, identifier); 6203 _resolvePropertyAccess(prefix, identifier);
6226 return null; 6204 return null;
6227 } 6205 }
6228 6206
6229 @override 6207 @override
6230 Object visitPrefixExpression(PrefixExpression node) { 6208 Object visitPrefixExpression(PrefixExpression node) {
6231 sc.Token operator = node.operator; 6209 sc.Token operator = node.operator;
6232 sc.TokenType operatorType = operator.type; 6210 sc.TokenType operatorType = operator.type;
6233 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { 6211 if (operatorType.isUserDefinableOperator || operatorType == sc.TokenType.PLU S_PLUS || operatorType == sc.TokenType.MINUS_MINUS) {
6234 Expression operand = node.operand; 6212 Expression operand = node.operand;
6235 String methodName = _getPrefixOperator(node); 6213 String methodName = _getPrefixOperator(node);
6236 DartType staticType = _getStaticType(operand); 6214 DartType staticType = _getStaticType(operand);
6237 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName ); 6215 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName );
6238 node.staticElement = staticMethod; 6216 node.staticElement = staticMethod;
6239 DartType propagatedType = _getPropagatedType(operand); 6217 DartType propagatedType = _getPropagatedType(operand);
6240 MethodElement propagatedMethod = _lookUpMethod(operand, propagatedType, me thodName); 6218 MethodElement propagatedMethod = _lookUpMethod(operand, propagatedType, me thodName);
6241 node.propagatedElement = propagatedMethod; 6219 node.propagatedElement = propagatedMethod;
6242 if (_shouldReportMissingMember(staticType, staticMethod)) { 6220 if (_shouldReportMissingMember(staticType, staticMethod)) {
6243 _resolver.reportProxyConditionalErrorForToken(staticType.element, Static TypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.displayNam e]); 6221 _resolver.reportProxyConditionalErrorForToken(staticType.element, Static TypeWarningCode.UNDEFINED_OPERATOR, operator, [methodName, staticType.displayNam e]);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
6316 if (node.name == _dynamicType.name) { 6294 if (node.name == _dynamicType.name) {
6317 node.staticElement = _dynamicType.element; 6295 node.staticElement = _dynamicType.element;
6318 node.staticType = _typeType; 6296 node.staticType = _typeType;
6319 return null; 6297 return null;
6320 } 6298 }
6321 // 6299 //
6322 // Otherwise, the node should be resolved. 6300 // Otherwise, the node should be resolved.
6323 // 6301 //
6324 Element element = _resolveSimpleIdentifier(node); 6302 Element element = _resolveSimpleIdentifier(node);
6325 ClassElement enclosingClass = _resolver.enclosingClass; 6303 ClassElement enclosingClass = _resolver.enclosingClass;
6326 if (_isFactoryConstructorReturnType(node) && element != enclosingClass) { 6304 if (_isFactoryConstructorReturnType(node) && !identical(element, enclosingCl ass)) {
6327 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT _A_CLASS, node, []); 6305 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT _A_CLASS, node, []);
6328 } else if (_isConstructorReturnType(node) && element != enclosingClass) { 6306 } else if (_isConstructorReturnType(node) && !identical(element, enclosingCl ass)) {
6329 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME , node, []); 6307 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME , node, []);
6330 element = null; 6308 element = null;
6331 } else if (element == null || (element is PrefixElement && !_isValidAsPrefix (node))) { 6309 } else if (element == null || (element is PrefixElement && !_isValidAsPrefix (node))) {
6332 // TODO(brianwilkerson) Recover from this error. 6310 // TODO(brianwilkerson) Recover from this error.
6333 if (_isConstructorReturnType(node)) { 6311 if (_isConstructorReturnType(node)) {
6334 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NA ME, node, []); 6312 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NA ME, node, []);
6335 } else if (node.parent is Annotation) { 6313 } else if (node.parent is Annotation) {
6336 Annotation annotation = node.parent as Annotation; 6314 Annotation annotation = node.parent as Annotation;
6337 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, an notation, []); 6315 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, an notation, []);
6338 } else { 6316 } else {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
6642 } 6620 }
6643 return element; 6621 return element;
6644 } 6622 }
6645 6623
6646 /** 6624 /**
6647 * Return the name of the method invoked by the given postfix expression. 6625 * Return the name of the method invoked by the given postfix expression.
6648 * 6626 *
6649 * @param node the postfix expression being invoked 6627 * @param node the postfix expression being invoked
6650 * @return the name of the method invoked by the expression 6628 * @return the name of the method invoked by the expression
6651 */ 6629 */
6652 String _getPostfixOperator(PostfixExpression node) => (identical(node.operator .type, sc.TokenType.PLUS_PLUS)) ? sc.TokenType.PLUS.lexeme : sc.TokenType.MINUS. lexeme; 6630 String _getPostfixOperator(PostfixExpression node) => (node.operator.type == s c.TokenType.PLUS_PLUS) ? sc.TokenType.PLUS.lexeme : sc.TokenType.MINUS.lexeme;
6653 6631
6654 /** 6632 /**
6655 * Return the name of the method invoked by the given postfix expression. 6633 * Return the name of the method invoked by the given postfix expression.
6656 * 6634 *
6657 * @param node the postfix expression being invoked 6635 * @param node the postfix expression being invoked
6658 * @return the name of the method invoked by the expression 6636 * @return the name of the method invoked by the expression
6659 */ 6637 */
6660 String _getPrefixOperator(PrefixExpression node) { 6638 String _getPrefixOperator(PrefixExpression node) {
6661 sc.Token operator = node.operator; 6639 sc.Token operator = node.operator;
6662 sc.TokenType operatorType = operator.type; 6640 sc.TokenType operatorType = operator.type;
6663 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { 6641 if (operatorType == sc.TokenType.PLUS_PLUS) {
6664 return sc.TokenType.PLUS.lexeme; 6642 return sc.TokenType.PLUS.lexeme;
6665 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { 6643 } else if (operatorType == sc.TokenType.MINUS_MINUS) {
6666 return sc.TokenType.MINUS.lexeme; 6644 return sc.TokenType.MINUS.lexeme;
6667 } else if (identical(operatorType, sc.TokenType.MINUS)) { 6645 } else if (operatorType == sc.TokenType.MINUS) {
6668 return "unary-"; 6646 return "unary-";
6669 } else { 6647 } else {
6670 return operator.lexeme; 6648 return operator.lexeme;
6671 } 6649 }
6672 } 6650 }
6673 6651
6674 /** 6652 /**
6675 * Return the propagated type of the given expression that is to be used for t ype analysis. 6653 * Return the propagated type of the given expression that is to be used for t ype analysis.
6676 * 6654 *
6677 * @param expression the expression whose type is to be returned 6655 * @param expression the expression whose type is to be returned
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
6952 labelElement = labelScope.lookup(labelNode.name) as LabelElementImpl; 6930 labelElement = labelScope.lookup(labelNode.name) as LabelElementImpl;
6953 if (labelElement == null) { 6931 if (labelElement == null) {
6954 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_UNDEFINED, lab elNode, [labelNode.name]); 6932 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_UNDEFINED, lab elNode, [labelNode.name]);
6955 } else { 6933 } else {
6956 labelNode.staticElement = labelElement; 6934 labelNode.staticElement = labelElement;
6957 } 6935 }
6958 } 6936 }
6959 } 6937 }
6960 if (labelElement != null) { 6938 if (labelElement != null) {
6961 ExecutableElement labelContainer = labelElement.getAncestor((element) => e lement is ExecutableElement); 6939 ExecutableElement labelContainer = labelElement.getAncestor((element) => e lement is ExecutableElement);
6962 if (labelContainer != _resolver.enclosingFunction) { 6940 if (!identical(labelContainer, _resolver.enclosingFunction)) {
6963 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNode, [labelNode.name]); 6941 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNode, [labelNode.name]);
6964 labelElement = null; 6942 labelElement = null;
6965 } 6943 }
6966 } 6944 }
6967 return labelElement; 6945 return labelElement;
6968 } 6946 }
6969 6947
6970 /** 6948 /**
6971 * Look up the method with the given name in the given type. Return the elemen t representing the 6949 * Look up the method with the given name in the given type. Return the elemen t representing the
6972 * method that was found, or `null` if there is no method with the given name. 6950 * method that was found, or `null` if there is no method with the given name.
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
7339 * @param argumentList the list of arguments being passed to the element 7317 * @param argumentList the list of arguments being passed to the element
7340 * @param parameters the of the function that will be invoked with the argumen ts 7318 * @param parameters the of the function that will be invoked with the argumen ts
7341 * @return the parameters that correspond to the arguments 7319 * @return the parameters that correspond to the arguments
7342 */ 7320 */
7343 List<ParameterElement> _resolveArgumentsToParameters(bool reportError, Argumen tList argumentList, List<ParameterElement> parameters) { 7321 List<ParameterElement> _resolveArgumentsToParameters(bool reportError, Argumen tList argumentList, List<ParameterElement> parameters) {
7344 List<ParameterElement> requiredParameters = new List<ParameterElement>(); 7322 List<ParameterElement> requiredParameters = new List<ParameterElement>();
7345 List<ParameterElement> positionalParameters = new List<ParameterElement>(); 7323 List<ParameterElement> positionalParameters = new List<ParameterElement>();
7346 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle ment>(); 7324 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle ment>();
7347 for (ParameterElement parameter in parameters) { 7325 for (ParameterElement parameter in parameters) {
7348 ParameterKind kind = parameter.parameterKind; 7326 ParameterKind kind = parameter.parameterKind;
7349 if (identical(kind, ParameterKind.REQUIRED)) { 7327 if (kind == ParameterKind.REQUIRED) {
7350 requiredParameters.add(parameter); 7328 requiredParameters.add(parameter);
7351 } else if (identical(kind, ParameterKind.POSITIONAL)) { 7329 } else if (kind == ParameterKind.POSITIONAL) {
7352 positionalParameters.add(parameter); 7330 positionalParameters.add(parameter);
7353 } else { 7331 } else {
7354 namedParameters[parameter.name] = parameter; 7332 namedParameters[parameter.name] = parameter;
7355 } 7333 }
7356 } 7334 }
7357 List<ParameterElement> unnamedParameters = new List<ParameterElement>.from(r equiredParameters); 7335 List<ParameterElement> unnamedParameters = new List<ParameterElement>.from(r equiredParameters);
7358 unnamedParameters.addAll(positionalParameters); 7336 unnamedParameters.addAll(positionalParameters);
7359 int unnamedParameterCount = unnamedParameters.length; 7337 int unnamedParameterCount = unnamedParameters.length;
7360 int unnamedIndex = 0; 7338 int unnamedIndex = 0;
7361 NodeList<Expression> arguments = argumentList.arguments; 7339 NodeList<Expression> arguments = argumentList.arguments;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
7766 /** 7744 /**
7767 * Instances of the class `SyntheticIdentifier` implement an identifier that can be used to 7745 * Instances of the class `SyntheticIdentifier` implement an identifier that can be used to
7768 * look up names in the lexical scope when there is no identifier in the AST str ucture. There is 7746 * look up names in the lexical scope when there is no identifier in the AST str ucture. There is
7769 * no identifier in the AST when the parser could not distinguish between a meth od invocation and 7747 * no identifier in the AST when the parser could not distinguish between a meth od invocation and
7770 * an invocation of a top-level function imported with a prefix. 7748 * an invocation of a top-level function imported with a prefix.
7771 */ 7749 */
7772 class ElementResolver_SyntheticIdentifier extends Identifier { 7750 class ElementResolver_SyntheticIdentifier extends Identifier {
7773 /** 7751 /**
7774 * The name of the synthetic identifier. 7752 * The name of the synthetic identifier.
7775 */ 7753 */
7776 String name; 7754 final String name;
7777 7755
7778 /** 7756 /**
7779 * Initialize a newly created synthetic identifier to have the given name. 7757 * Initialize a newly created synthetic identifier to have the given name.
7780 * 7758 *
7781 * @param name the name of the synthetic identifier 7759 * @param name the name of the synthetic identifier
7782 */ 7760 */
7783 ElementResolver_SyntheticIdentifier(String name) { 7761 ElementResolver_SyntheticIdentifier(this.name);
7784 this.name = name;
7785 }
7786 7762
7787 @override 7763 @override
7788 accept(AstVisitor visitor) => null; 7764 accept(AstVisitor visitor) => null;
7789 7765
7790 @override 7766 @override
7791 sc.Token get beginToken => null; 7767 sc.Token get beginToken => null;
7792 7768
7793 @override 7769 @override
7794 Element get bestElement => null; 7770 Element get bestElement => null;
7795 7771
(...skipping 15 matching lines...) Expand all
7811 } 7787 }
7812 7788
7813 /** 7789 /**
7814 * Instances of the class `IncrementalResolver` resolve the smallest portion of an AST 7790 * Instances of the class `IncrementalResolver` resolve the smallest portion of an AST
7815 * structure that we currently know how to resolve. 7791 * structure that we currently know how to resolve.
7816 */ 7792 */
7817 class IncrementalResolver { 7793 class IncrementalResolver {
7818 /** 7794 /**
7819 * The element for the library containing the compilation unit being visited. 7795 * The element for the library containing the compilation unit being visited.
7820 */ 7796 */
7821 LibraryElement _definingLibrary; 7797 final LibraryElement _definingLibrary;
7822 7798
7823 /** 7799 /**
7824 * The source representing the compilation unit being visited. 7800 * The source representing the compilation unit being visited.
7825 */ 7801 */
7826 Source _source; 7802 final Source _source;
7827 7803
7828 /** 7804 /**
7829 * The object used to access the types from the core library. 7805 * The object used to access the types from the core library.
7830 */ 7806 */
7831 TypeProvider _typeProvider; 7807 final TypeProvider _typeProvider;
7832 7808
7833 /** 7809 /**
7834 * The error listener that will be informed of any errors that are found durin g resolution. 7810 * The error listener that will be informed of any errors that are found durin g resolution.
7835 */ 7811 */
7836 AnalysisErrorListener _errorListener; 7812 final AnalysisErrorListener _errorListener;
7837 7813
7838 /** 7814 /**
7839 * Initialize a newly created incremental resolver to resolve a node in the gi ven source in the 7815 * Initialize a newly created incremental resolver to resolve a node in the gi ven source in the
7840 * given library, reporting errors to the given error listener. 7816 * given library, reporting errors to the given error listener.
7841 * 7817 *
7842 * @param definingLibrary the element for the library containing the compilati on unit being 7818 * @param definingLibrary the element for the library containing the compilati on unit being
7843 * visited 7819 * visited
7844 * @param source the source representing the compilation unit being visited 7820 * @param source the source representing the compilation unit being visited
7845 * @param typeProvider the object used to access the types from the core libra ry 7821 * @param typeProvider the object used to access the types from the core libra ry
7846 * @param errorListener the error listener that will be informed of any errors that are found 7822 * @param errorListener the error listener that will be informed of any errors that are found
7847 * during resolution 7823 * during resolution
7848 */ 7824 */
7849 IncrementalResolver(LibraryElement definingLibrary, Source source, TypeProvide r typeProvider, AnalysisErrorListener errorListener) { 7825 IncrementalResolver(this._definingLibrary, this._source, this._typeProvider, t his._errorListener);
7850 this._definingLibrary = definingLibrary;
7851 this._source = source;
7852 this._typeProvider = typeProvider;
7853 this._errorListener = errorListener;
7854 }
7855 7826
7856 /** 7827 /**
7857 * Resolve the given node, reporting any errors or warnings to the given liste ner. 7828 * Resolve the given node, reporting any errors or warnings to the given liste ner.
7858 * 7829 *
7859 * @param node the root of the AST structure to be resolved 7830 * @param node the root of the AST structure to be resolved
7860 * @throws AnalysisException if the node could not be resolved 7831 * @throws AnalysisException if the node could not be resolved
7861 */ 7832 */
7862 void resolve(AstNode node) { 7833 void resolve(AstNode node) {
7863 AstNode rootNode = _findResolutionRoot(node); 7834 AstNode rootNode = _findResolutionRoot(node);
7864 Scope scope = ScopeBuilder.scopeFor(rootNode, _errorListener); 7835 Scope scope = ScopeBuilder.scopeFor(rootNode, _errorListener);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
8045 } 8016 }
8046 8017
8047 /** 8018 /**
8048 * Given some [ExecutableElement], return the list of named parameters. 8019 * Given some [ExecutableElement], return the list of named parameters.
8049 */ 8020 */
8050 static List<String> _getNamedParameterNames(ExecutableElement executableElemen t) { 8021 static List<String> _getNamedParameterNames(ExecutableElement executableElemen t) {
8051 List<String> namedParameterNames = new List<String>(); 8022 List<String> namedParameterNames = new List<String>();
8052 List<ParameterElement> parameters = executableElement.parameters; 8023 List<ParameterElement> parameters = executableElement.parameters;
8053 for (int i = 0; i < parameters.length; i++) { 8024 for (int i = 0; i < parameters.length; i++) {
8054 ParameterElement parameterElement = parameters[i]; 8025 ParameterElement parameterElement = parameters[i];
8055 if (identical(parameterElement.parameterKind, ParameterKind.NAMED)) { 8026 if (parameterElement.parameterKind == ParameterKind.NAMED) {
8056 namedParameterNames.add(parameterElement.name); 8027 namedParameterNames.add(parameterElement.name);
8057 } 8028 }
8058 } 8029 }
8059 return namedParameterNames; 8030 return namedParameterNames;
8060 } 8031 }
8061 8032
8062 /** 8033 /**
8063 * Given some [ExecutableElement] return the number of parameters of the speci fied kind. 8034 * Given some [ExecutableElement] return the number of parameters of the speci fied kind.
8064 */ 8035 */
8065 static int _getNumOfParameters(ExecutableElement executableElement, ParameterK ind parameterKind) { 8036 static int _getNumOfParameters(ExecutableElement executableElement, ParameterK ind parameterKind) {
8066 int parameterCount = 0; 8037 int parameterCount = 0;
8067 List<ParameterElement> parameters = executableElement.parameters; 8038 List<ParameterElement> parameters = executableElement.parameters;
8068 for (int i = 0; i < parameters.length; i++) { 8039 for (int i = 0; i < parameters.length; i++) {
8069 ParameterElement parameterElement = parameters[i]; 8040 ParameterElement parameterElement = parameters[i];
8070 if (identical(parameterElement.parameterKind, parameterKind)) { 8041 if (parameterElement.parameterKind == parameterKind) {
8071 parameterCount++; 8042 parameterCount++;
8072 } 8043 }
8073 } 8044 }
8074 return parameterCount; 8045 return parameterCount;
8075 } 8046 }
8076 8047
8077 /** 8048 /**
8078 * Given some [ExecutableElement] return the number of positional parameters. 8049 * Given some [ExecutableElement] return the number of positional parameters.
8079 * 8050 *
8080 * Note: by positional we mean [ParameterKind#REQUIRED] or [ParameterKind#POSI TIONAL]. 8051 * Note: by positional we mean [ParameterKind#REQUIRED] or [ParameterKind#POSI TIONAL].
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
8589 // If the list is empty, just the new value 8560 // If the list is empty, just the new value
8590 list.add(newExecutableElementEntry); 8561 list.add(newExecutableElementEntry);
8591 } else { 8562 } else {
8592 // Otherwise, only add the newExecutableElementEntry if it isn't alrea dy in the list, this 8563 // Otherwise, only add the newExecutableElementEntry if it isn't alrea dy in the list, this
8593 // covers situation where a class inherits two methods (or two getters ) that are 8564 // covers situation where a class inherits two methods (or two getters ) that are
8594 // identical. 8565 // identical.
8595 bool alreadyInList = false; 8566 bool alreadyInList = false;
8596 bool isMethod1 = newExecutableElementEntry is MethodElement; 8567 bool isMethod1 = newExecutableElementEntry is MethodElement;
8597 for (ExecutableElement executableElementInList in list) { 8568 for (ExecutableElement executableElementInList in list) {
8598 bool isMethod2 = executableElementInList is MethodElement; 8569 bool isMethod2 = executableElementInList is MethodElement;
8599 if (identical(isMethod1, isMethod2) && executableElementInList.type == newExecutableElementEntry.type) { 8570 if (isMethod1 == isMethod2 && executableElementInList.type == newExe cutableElementEntry.type) {
8600 alreadyInList = true; 8571 alreadyInList = true;
8601 break; 8572 break;
8602 } 8573 }
8603 } 8574 }
8604 if (!alreadyInList) { 8575 if (!alreadyInList) {
8605 list.add(newExecutableElementEntry); 8576 list.add(newExecutableElementEntry);
8606 } 8577 }
8607 } 8578 }
8608 } 8579 }
8609 } 8580 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
8813 8784
8814 /** 8785 /**
8815 * Instances of the class `Library` represent the data about a single library du ring the 8786 * Instances of the class `Library` represent the data about a single library du ring the
8816 * resolution of some (possibly different) library. They are not intended to be used except during 8787 * resolution of some (possibly different) library. They are not intended to be used except during
8817 * the resolution process. 8788 * the resolution process.
8818 */ 8789 */
8819 class Library { 8790 class Library {
8820 /** 8791 /**
8821 * The analysis context in which this library is being analyzed. 8792 * The analysis context in which this library is being analyzed.
8822 */ 8793 */
8823 InternalAnalysisContext _analysisContext; 8794 final InternalAnalysisContext _analysisContext;
8824 8795
8825 /** 8796 /**
8826 * The inheritance manager which is used for this member lookups in this libra ry. 8797 * The inheritance manager which is used for this member lookups in this libra ry.
8827 */ 8798 */
8828 InheritanceManager _inheritanceManager; 8799 InheritanceManager _inheritanceManager;
8829 8800
8830 /** 8801 /**
8831 * The listener to which analysis errors will be reported. 8802 * The listener to which analysis errors will be reported.
8832 */ 8803 */
8833 AnalysisErrorListener _errorListener; 8804 final AnalysisErrorListener _errorListener;
8834 8805
8835 /** 8806 /**
8836 * The source specifying the defining compilation unit of this library. 8807 * The source specifying the defining compilation unit of this library.
8837 */ 8808 */
8838 Source librarySource; 8809 final Source librarySource;
8839 8810
8840 /** 8811 /**
8841 * The library element representing this library. 8812 * The library element representing this library.
8842 */ 8813 */
8843 LibraryElementImpl _libraryElement; 8814 LibraryElementImpl _libraryElement;
8844 8815
8845 /** 8816 /**
8846 * A list containing all of the libraries that are imported into this library. 8817 * A list containing all of the libraries that are imported into this library.
8847 */ 8818 */
8848 List<Library> _importedLibraries = _EMPTY_ARRAY; 8819 List<Library> _importedLibraries = _EMPTY_ARRAY;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
8883 */ 8854 */
8884 static String _DART_EXT_SCHEME = "dart-ext:"; 8855 static String _DART_EXT_SCHEME = "dart-ext:";
8885 8856
8886 /** 8857 /**
8887 * Initialize a newly created data holder that can maintain the data associate d with a library. 8858 * Initialize a newly created data holder that can maintain the data associate d with a library.
8888 * 8859 *
8889 * @param analysisContext the analysis context in which this library is being analyzed 8860 * @param analysisContext the analysis context in which this library is being analyzed
8890 * @param errorListener the listener to which analysis errors will be reported 8861 * @param errorListener the listener to which analysis errors will be reported
8891 * @param librarySource the source specifying the defining compilation unit of this library 8862 * @param librarySource the source specifying the defining compilation unit of this library
8892 */ 8863 */
8893 Library(InternalAnalysisContext analysisContext, AnalysisErrorListener errorLi stener, Source librarySource) { 8864 Library(this._analysisContext, this._errorListener, this.librarySource) {
8894 this._analysisContext = analysisContext; 8865 this._libraryElement = _analysisContext.getLibraryElement(librarySource) as LibraryElementImpl;
8895 this._errorListener = errorListener;
8896 this.librarySource = librarySource;
8897 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L ibraryElementImpl;
8898 } 8866 }
8899 8867
8900 /** 8868 /**
8901 * Return the AST structure associated with the given source. 8869 * Return the AST structure associated with the given source.
8902 * 8870 *
8903 * @param source the source representing the compilation unit whose AST is to be returned 8871 * @param source the source representing the compilation unit whose AST is to be returned
8904 * @return the AST structure associated with the given source 8872 * @return the AST structure associated with the given source
8905 * @throws AnalysisException if an AST structure could not be created for the compilation unit 8873 * @throws AnalysisException if an AST structure could not be created for the compilation unit
8906 */ 8874 */
8907 CompilationUnit getAST(Source source) { 8875 CompilationUnit getAST(Source source) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
9120 String toString() => librarySource.shortName; 9088 String toString() => librarySource.shortName;
9121 } 9089 }
9122 9090
9123 /** 9091 /**
9124 * Instances of the class `LibraryElementBuilder` build an element model for a s ingle library. 9092 * Instances of the class `LibraryElementBuilder` build an element model for a s ingle library.
9125 */ 9093 */
9126 class LibraryElementBuilder { 9094 class LibraryElementBuilder {
9127 /** 9095 /**
9128 * The analysis context in which the element model will be built. 9096 * The analysis context in which the element model will be built.
9129 */ 9097 */
9130 InternalAnalysisContext _analysisContext; 9098 final InternalAnalysisContext _analysisContext;
9131 9099
9132 /** 9100 /**
9133 * The listener to which errors will be reported. 9101 * The listener to which errors will be reported.
9134 */ 9102 */
9135 AnalysisErrorListener _errorListener; 9103 final AnalysisErrorListener _errorListener;
9136 9104
9137 /** 9105 /**
9138 * The name of the function used as an entry point. 9106 * The name of the function used as an entry point.
9139 */ 9107 */
9140 static String ENTRY_POINT_NAME = "main"; 9108 static String ENTRY_POINT_NAME = "main";
9141 9109
9142 /** 9110 /**
9143 * Initialize a newly created library element builder. 9111 * Initialize a newly created library element builder.
9144 * 9112 *
9145 * @param analysisContext the analysis context in which the element model will be built 9113 * @param analysisContext the analysis context in which the element model will be built
9146 * @param errorListener the listener to which errors will be reported 9114 * @param errorListener the listener to which errors will be reported
9147 */ 9115 */
9148 LibraryElementBuilder(InternalAnalysisContext analysisContext, AnalysisErrorLi stener errorListener) { 9116 LibraryElementBuilder(this._analysisContext, this._errorListener);
9149 this._analysisContext = analysisContext;
9150 this._errorListener = errorListener;
9151 }
9152 9117
9153 /** 9118 /**
9154 * Build the library element for the given library. 9119 * Build the library element for the given library.
9155 * 9120 *
9156 * @param library the library for which an element model is to be built 9121 * @param library the library for which an element model is to be built
9157 * @return the library element that was built 9122 * @return the library element that was built
9158 * @throws AnalysisException if the analysis could not be performed 9123 * @throws AnalysisException if the analysis could not be performed
9159 */ 9124 */
9160 LibraryElementImpl buildLibrary(Library library) { 9125 LibraryElementImpl buildLibrary(Library library) {
9161 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 9126 CompilationUnitBuilder builder = new CompilationUnitBuilder();
(...skipping 14 matching lines...) Expand all
9176 // the possibility of circular references). 9141 // the possibility of circular references).
9177 // 9142 //
9178 if (directive is LibraryDirective) { 9143 if (directive is LibraryDirective) {
9179 if (libraryNameNode == null) { 9144 if (libraryNameNode == null) {
9180 libraryNameNode = directive.name; 9145 libraryNameNode = directive.name;
9181 directivesToResolve.add(directive); 9146 directivesToResolve.add(directive);
9182 } 9147 }
9183 } else if (directive is PartDirective) { 9148 } else if (directive is PartDirective) {
9184 PartDirective partDirective = directive; 9149 PartDirective partDirective = directive;
9185 StringLiteral partUri = partDirective.uri; 9150 StringLiteral partUri = partDirective.uri;
9186 Source partSource = library.getSource(partDirective); 9151 Source partSource = partDirective.source;
9187 if (_analysisContext.exists(partSource)) { 9152 if (_analysisContext.exists(partSource)) {
9188 hasPartDirective = true; 9153 hasPartDirective = true;
9189 CompilationUnit partUnit = library.getAST(partSource); 9154 CompilationUnit partUnit = library.getAST(partSource);
9190 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, partUnit); 9155 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, partUnit);
9191 part.uriOffset = partUri.offset; 9156 part.uriOffset = partUri.offset;
9192 part.uriEnd = partUri.end; 9157 part.uriEnd = partUri.end;
9193 part.uri = library.getUri(partDirective); 9158 part.uri = partDirective.uriContent;
9194 // 9159 //
9195 // Validate that the part contains a part-of directive with the same n ame as the library. 9160 // Validate that the part contains a part-of directive with the same n ame as the library.
9196 // 9161 //
9197 String partLibraryName = _getPartLibraryName(partSource, partUnit, dir ectivesToResolve); 9162 String partLibraryName = _getPartLibraryName(partSource, partUnit, dir ectivesToResolve);
9198 if (partLibraryName == null) { 9163 if (partLibraryName == null) {
9199 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSourc e()])); 9164 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSourc e()]));
9200 } else if (libraryNameNode == null) { 9165 } else if (libraryNameNode == null) {
9201 } else if (libraryNameNode.name != partLibraryName) { 9166 } else if (libraryNameNode.name != partLibraryName) {
9202 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryNa meNode.name, partLibraryName])); 9167 _errorListener.onError(new AnalysisError.con2(librarySource, partUri .offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryNa meNode.name, partLibraryName]));
9203 } 9168 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
9401 } 9366 }
9402 9367
9403 /** 9368 /**
9404 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent 9369 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent
9405 * libraries within a single context. 9370 * libraries within a single context.
9406 */ 9371 */
9407 class LibraryResolver { 9372 class LibraryResolver {
9408 /** 9373 /**
9409 * The analysis context in which the libraries are being analyzed. 9374 * The analysis context in which the libraries are being analyzed.
9410 */ 9375 */
9411 InternalAnalysisContext analysisContext; 9376 final InternalAnalysisContext analysisContext;
9412 9377
9413 /** 9378 /**
9414 * The listener to which analysis errors will be reported, this error listener is either 9379 * The listener to which analysis errors will be reported, this error listener is either
9415 * references [recordingErrorListener], or it unions the passed 9380 * references [recordingErrorListener], or it unions the passed
9416 * [AnalysisErrorListener] with the [recordingErrorListener]. 9381 * [AnalysisErrorListener] with the [recordingErrorListener].
9417 */ 9382 */
9418 RecordingErrorListener _errorListener; 9383 RecordingErrorListener _errorListener;
9419 9384
9420 /** 9385 /**
9421 * A source object representing the core library (dart:core). 9386 * A source object representing the core library (dart:core).
(...skipping 18 matching lines...) Expand all
9440 /** 9405 /**
9441 * A collection containing the libraries that are being resolved together. 9406 * A collection containing the libraries that are being resolved together.
9442 */ 9407 */
9443 Set<Library> _librariesInCycles; 9408 Set<Library> _librariesInCycles;
9444 9409
9445 /** 9410 /**
9446 * Initialize a newly created library resolver to resolve libraries within the given context. 9411 * Initialize a newly created library resolver to resolve libraries within the given context.
9447 * 9412 *
9448 * @param analysisContext the analysis context in which the library is being a nalyzed 9413 * @param analysisContext the analysis context in which the library is being a nalyzed
9449 */ 9414 */
9450 LibraryResolver(InternalAnalysisContext analysisContext) { 9415 LibraryResolver(this.analysisContext) {
9451 this.analysisContext = analysisContext;
9452 this._errorListener = new RecordingErrorListener(); 9416 this._errorListener = new RecordingErrorListener();
9453 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ; 9417 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ;
9454 } 9418 }
9455 9419
9456 /** 9420 /**
9457 * Return the listener to which analysis errors will be reported. 9421 * Return the listener to which analysis errors will be reported.
9458 * 9422 *
9459 * @return the listener to which analysis errors will be reported 9423 * @return the listener to which analysis errors will be reported
9460 */ 9424 */
9461 RecordingErrorListener get errorListener => _errorListener; 9425 RecordingErrorListener get errorListener => _errorListener;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
9695 * @param dependencyMap the dependency map being computed 9659 * @param dependencyMap the dependency map being computed
9696 * @param visitedLibraries the libraries that have already been visited, used to prevent infinite 9660 * @param visitedLibraries the libraries that have already been visited, used to prevent infinite
9697 * recursion 9661 * recursion
9698 */ 9662 */
9699 void _addToDependencyMap(Library library, Map<Library, List<Library>> dependen cyMap, Set<Library> visitedLibraries) { 9663 void _addToDependencyMap(Library library, Map<Library, List<Library>> dependen cyMap, Set<Library> visitedLibraries) {
9700 if (visitedLibraries.add(library)) { 9664 if (visitedLibraries.add(library)) {
9701 for (Library referencedLibrary in library.importsAndExports) { 9665 for (Library referencedLibrary in library.importsAndExports) {
9702 _addDependencyToMap(dependencyMap, library, referencedLibrary); 9666 _addDependencyToMap(dependencyMap, library, referencedLibrary);
9703 _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); 9667 _addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries);
9704 } 9668 }
9705 if (!library.explicitlyImportsCore && library != _coreLibrary) { 9669 if (!library.explicitlyImportsCore && !identical(library, _coreLibrary)) {
9706 _addDependencyToMap(dependencyMap, library, _coreLibrary); 9670 _addDependencyToMap(dependencyMap, library, _coreLibrary);
9707 } 9671 }
9708 } 9672 }
9709 } 9673 }
9710 9674
9711 /** 9675 /**
9712 * Build the element model representing the combinators declared by the given directive. 9676 * Build the element model representing the combinators declared by the given directive.
9713 * 9677 *
9714 * @param directive the directive that declares the combinators 9678 * @param directive the directive that declares the combinators
9715 * @return an array containing the import combinators that were built 9679 * @return an array containing the import combinators that were built
(...skipping 24 matching lines...) Expand all
9740 * be accessed 9704 * be accessed
9741 */ 9705 */
9742 void _buildDirectiveModels() { 9706 void _buildDirectiveModels() {
9743 for (Library library in _librariesInCycles) { 9707 for (Library library in _librariesInCycles) {
9744 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>(); 9708 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>();
9745 List<ImportElement> imports = new List<ImportElement>(); 9709 List<ImportElement> imports = new List<ImportElement>();
9746 List<ExportElement> exports = new List<ExportElement>(); 9710 List<ExportElement> exports = new List<ExportElement>();
9747 for (Directive directive in library.definingCompilationUnit.directives) { 9711 for (Directive directive in library.definingCompilationUnit.directives) {
9748 if (directive is ImportDirective) { 9712 if (directive is ImportDirective) {
9749 ImportDirective importDirective = directive; 9713 ImportDirective importDirective = directive;
9750 Source importedSource = library.getSource(importDirective); 9714 String uriContent = importDirective.uriContent;
9715 if (DartUriResolver.isDartExtUri(uriContent)) {
9716 library.libraryElement.hasExtUri = true;
9717 }
9718 Source importedSource = importDirective.source;
9751 if (importedSource != null) { 9719 if (importedSource != null) {
9752 // The imported source will be null if the URI in the import directi ve was invalid. 9720 // The imported source will be null if the URI in the import directi ve was invalid.
9753 Library importedLibrary = _libraryMap[importedSource]; 9721 Library importedLibrary = _libraryMap[importedSource];
9754 if (importedLibrary != null) { 9722 if (importedLibrary != null) {
9755 ImportElementImpl importElement = new ImportElementImpl(directive. offset); 9723 ImportElementImpl importElement = new ImportElementImpl(directive. offset);
9756 StringLiteral uriLiteral = importDirective.uri; 9724 StringLiteral uriLiteral = importDirective.uri;
9757 importElement.uriOffset = uriLiteral.offset; 9725 importElement.uriOffset = uriLiteral.offset;
9758 importElement.uriEnd = uriLiteral.end; 9726 importElement.uriEnd = uriLiteral.end;
9759 importElement.uri = library.getUri(importDirective); 9727 importElement.uri = uriContent;
9760 importElement.combinators = _buildCombinators(importDirective); 9728 importElement.combinators = _buildCombinators(importDirective);
9761 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment; 9729 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment;
9762 if (importedLibraryElement != null) { 9730 if (importedLibraryElement != null) {
9763 importElement.importedLibrary = importedLibraryElement; 9731 importElement.importedLibrary = importedLibraryElement;
9764 } 9732 }
9765 SimpleIdentifier prefixNode = directive.prefix; 9733 SimpleIdentifier prefixNode = directive.prefix;
9766 if (prefixNode != null) { 9734 if (prefixNode != null) {
9767 importElement.prefixOffset = prefixNode.offset; 9735 importElement.prefixOffset = prefixNode.offset;
9768 String prefixName = prefixNode.name; 9736 String prefixName = prefixNode.name;
9769 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; 9737 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
9770 if (prefix == null) { 9738 if (prefix == null) {
9771 prefix = new PrefixElementImpl(prefixNode); 9739 prefix = new PrefixElementImpl(prefixNode);
9772 nameToPrefixMap[prefixName] = prefix; 9740 nameToPrefixMap[prefixName] = prefix;
9773 } 9741 }
9774 importElement.prefix = prefix; 9742 importElement.prefix = prefix;
9775 prefixNode.staticElement = prefix; 9743 prefixNode.staticElement = prefix;
9776 } 9744 }
9777 directive.element = importElement; 9745 directive.element = importElement;
9778 imports.add(importElement); 9746 imports.add(importElement);
9779 if (analysisContext.computeKindOf(importedSource) != SourceKind.LI BRARY) { 9747 if (analysisContext.computeKindOf(importedSource) != SourceKind.LI BRARY) {
9780 _errorListener.onError(new AnalysisError.con2(library.librarySou rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LI BRARY, [uriLiteral.toSource()])); 9748 _errorListener.onError(new AnalysisError.con2(library.librarySou rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LI BRARY, [uriLiteral.toSource()]));
9781 } 9749 }
9782 } 9750 }
9783 } 9751 }
9784 } else if (directive is ExportDirective) { 9752 } else if (directive is ExportDirective) {
9785 ExportDirective exportDirective = directive; 9753 ExportDirective exportDirective = directive;
9786 Source exportedSource = library.getSource(exportDirective); 9754 Source exportedSource = exportDirective.source;
9787 if (exportedSource != null) { 9755 if (exportedSource != null) {
9788 // The exported source will be null if the URI in the export directi ve was invalid. 9756 // The exported source will be null if the URI in the export directi ve was invalid.
9789 Library exportedLibrary = _libraryMap[exportedSource]; 9757 Library exportedLibrary = _libraryMap[exportedSource];
9790 if (exportedLibrary != null) { 9758 if (exportedLibrary != null) {
9791 ExportElementImpl exportElement = new ExportElementImpl(); 9759 ExportElementImpl exportElement = new ExportElementImpl();
9792 StringLiteral uriLiteral = exportDirective.uri; 9760 StringLiteral uriLiteral = exportDirective.uri;
9793 exportElement.uriOffset = uriLiteral.offset; 9761 exportElement.uriOffset = uriLiteral.offset;
9794 exportElement.uriEnd = uriLiteral.end; 9762 exportElement.uriEnd = uriLiteral.end;
9795 exportElement.uri = library.getUri(exportDirective); 9763 exportElement.uri = exportDirective.uriContent;
9796 exportElement.combinators = _buildCombinators(exportDirective); 9764 exportElement.combinators = _buildCombinators(exportDirective);
9797 LibraryElement exportedLibraryElement = exportedLibrary.libraryEle ment; 9765 LibraryElement exportedLibraryElement = exportedLibrary.libraryEle ment;
9798 if (exportedLibraryElement != null) { 9766 if (exportedLibraryElement != null) {
9799 exportElement.exportedLibrary = exportedLibraryElement; 9767 exportElement.exportedLibrary = exportedLibraryElement;
9800 } 9768 }
9801 directive.element = exportElement; 9769 directive.element = exportElement;
9802 exports.add(exportElement); 9770 exports.add(exportElement);
9803 if (analysisContext.computeKindOf(exportedSource) != SourceKind.LI BRARY) { 9771 if (analysisContext.computeKindOf(exportedSource) != SourceKind.LI BRARY) {
9804 _errorListener.onError(new AnalysisError.con2(library.librarySou rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LI BRARY, [uriLiteral.toSource()])); 9772 _errorListener.onError(new AnalysisError.con2(library.librarySou rce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LI BRARY, [uriLiteral.toSource()]));
9805 } 9773 }
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
10131 } 10099 }
10132 10100
10133 /** 10101 /**
10134 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent 10102 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent
10135 * libraries within a single context. 10103 * libraries within a single context.
10136 */ 10104 */
10137 class LibraryResolver2 { 10105 class LibraryResolver2 {
10138 /** 10106 /**
10139 * The analysis context in which the libraries are being analyzed. 10107 * The analysis context in which the libraries are being analyzed.
10140 */ 10108 */
10141 InternalAnalysisContext analysisContext; 10109 final InternalAnalysisContext analysisContext;
10142 10110
10143 /** 10111 /**
10144 * The listener to which analysis errors will be reported, this error listener is either 10112 * The listener to which analysis errors will be reported, this error listener is either
10145 * references [recordingErrorListener], or it unions the passed 10113 * references [recordingErrorListener], or it unions the passed
10146 * [AnalysisErrorListener] with the [recordingErrorListener]. 10114 * [AnalysisErrorListener] with the [recordingErrorListener].
10147 */ 10115 */
10148 RecordingErrorListener _errorListener; 10116 RecordingErrorListener _errorListener;
10149 10117
10150 /** 10118 /**
10151 * A source object representing the core library (dart:core). 10119 * A source object representing the core library (dart:core).
(...skipping 18 matching lines...) Expand all
10170 /** 10138 /**
10171 * A collection containing the libraries that are being resolved together. 10139 * A collection containing the libraries that are being resolved together.
10172 */ 10140 */
10173 List<ResolvableLibrary> _librariesInCycle; 10141 List<ResolvableLibrary> _librariesInCycle;
10174 10142
10175 /** 10143 /**
10176 * Initialize a newly created library resolver to resolve libraries within the given context. 10144 * Initialize a newly created library resolver to resolve libraries within the given context.
10177 * 10145 *
10178 * @param analysisContext the analysis context in which the library is being a nalyzed 10146 * @param analysisContext the analysis context in which the library is being a nalyzed
10179 */ 10147 */
10180 LibraryResolver2(InternalAnalysisContext analysisContext) { 10148 LibraryResolver2(this.analysisContext) {
10181 this.analysisContext = analysisContext;
10182 this._errorListener = new RecordingErrorListener(); 10149 this._errorListener = new RecordingErrorListener();
10183 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ; 10150 _coreLibrarySource = analysisContext.sourceFactory.forUri(DartSdk.DART_CORE) ;
10184 } 10151 }
10185 10152
10186 /** 10153 /**
10187 * Return the listener to which analysis errors will be reported. 10154 * Return the listener to which analysis errors will be reported.
10188 * 10155 *
10189 * @return the listener to which analysis errors will be reported 10156 * @return the listener to which analysis errors will be reported
10190 */ 10157 */
10191 RecordingErrorListener get errorListener => _errorListener; 10158 RecordingErrorListener get errorListener => _errorListener;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
10306 * be accessed 10273 * be accessed
10307 */ 10274 */
10308 void _buildDirectiveModels() { 10275 void _buildDirectiveModels() {
10309 for (ResolvableLibrary library in _librariesInCycle) { 10276 for (ResolvableLibrary library in _librariesInCycle) {
10310 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>(); 10277 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>();
10311 List<ImportElement> imports = new List<ImportElement>(); 10278 List<ImportElement> imports = new List<ImportElement>();
10312 List<ExportElement> exports = new List<ExportElement>(); 10279 List<ExportElement> exports = new List<ExportElement>();
10313 for (Directive directive in library.definingCompilationUnit.directives) { 10280 for (Directive directive in library.definingCompilationUnit.directives) {
10314 if (directive is ImportDirective) { 10281 if (directive is ImportDirective) {
10315 ImportDirective importDirective = directive; 10282 ImportDirective importDirective = directive;
10283 String uriContent = importDirective.uriContent;
10284 if (DartUriResolver.isDartExtUri(uriContent)) {
10285 library.libraryElement.hasExtUri = true;
10286 }
10316 Source importedSource = importDirective.source; 10287 Source importedSource = importDirective.source;
10317 if (importedSource != null && analysisContext.exists(importedSource)) { 10288 if (importedSource != null && analysisContext.exists(importedSource)) {
10318 // The imported source will be null if the URI in the import directi ve was invalid. 10289 // The imported source will be null if the URI in the import directi ve was invalid.
10319 ResolvableLibrary importedLibrary = _libraryMap[importedSource]; 10290 ResolvableLibrary importedLibrary = _libraryMap[importedSource];
10320 if (importedLibrary != null) { 10291 if (importedLibrary != null) {
10321 ImportElementImpl importElement = new ImportElementImpl(directive. offset); 10292 ImportElementImpl importElement = new ImportElementImpl(directive. offset);
10322 StringLiteral uriLiteral = importDirective.uri; 10293 StringLiteral uriLiteral = importDirective.uri;
10323 if (uriLiteral != null) { 10294 if (uriLiteral != null) {
10324 importElement.uriOffset = uriLiteral.offset; 10295 importElement.uriOffset = uriLiteral.offset;
10325 importElement.uriEnd = uriLiteral.end; 10296 importElement.uriEnd = uriLiteral.end;
10326 } 10297 }
10327 importElement.uri = importDirective.uriContent; 10298 importElement.uri = uriContent;
10328 importElement.combinators = _buildCombinators(importDirective); 10299 importElement.combinators = _buildCombinators(importDirective);
10329 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment; 10300 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment;
10330 if (importedLibraryElement != null) { 10301 if (importedLibraryElement != null) {
10331 importElement.importedLibrary = importedLibraryElement; 10302 importElement.importedLibrary = importedLibraryElement;
10332 } 10303 }
10333 SimpleIdentifier prefixNode = directive.prefix; 10304 SimpleIdentifier prefixNode = directive.prefix;
10334 if (prefixNode != null) { 10305 if (prefixNode != null) {
10335 importElement.prefixOffset = prefixNode.offset; 10306 importElement.prefixOffset = prefixNode.offset;
10336 String prefixName = prefixNode.name; 10307 String prefixName = prefixNode.name;
10337 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; 10308 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
10707 * 10678 *
10708 * If we have other conditional error codes in the future, we should have this c lass implement some 10679 * If we have other conditional error codes in the future, we should have this c lass implement some
10709 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode can be visited 10680 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode can be visited
10710 * instead of multiple lists of *ConditionalErrorCodes. 10681 * instead of multiple lists of *ConditionalErrorCodes.
10711 */ 10682 */
10712 class ProxyConditionalAnalysisError { 10683 class ProxyConditionalAnalysisError {
10713 /** 10684 /**
10714 * The enclosing [ClassElement], this is what will determine if the error code should, or 10685 * The enclosing [ClassElement], this is what will determine if the error code should, or
10715 * should not, be generated on the source. 10686 * should not, be generated on the source.
10716 */ 10687 */
10717 Element _enclosingElement; 10688 final Element _enclosingElement;
10718 10689
10719 /** 10690 /**
10720 * The conditional analysis error. 10691 * The conditional analysis error.
10721 */ 10692 */
10722 AnalysisError analysisError; 10693 final AnalysisError analysisError;
10723 10694
10724 /** 10695 /**
10725 * Instantiate a new [ProxyConditionalAnalysisError] with some enclosing eleme nt and the 10696 * Instantiate a new [ProxyConditionalAnalysisError] with some enclosing eleme nt and the
10726 * conditional analysis error. 10697 * conditional analysis error.
10727 * 10698 *
10728 * @param enclosingElement the enclosing element 10699 * @param enclosingElement the enclosing element
10729 * @param analysisError the conditional analysis error 10700 * @param analysisError the conditional analysis error
10730 */ 10701 */
10731 ProxyConditionalAnalysisError(Element enclosingElement, AnalysisError analysis Error) { 10702 ProxyConditionalAnalysisError(this._enclosingElement, this.analysisError);
10732 this._enclosingElement = enclosingElement;
10733 this.analysisError = analysisError;
10734 }
10735 10703
10736 /** 10704 /**
10737 * Return `true` iff the enclosing class has the proxy annotation. 10705 * Return `true` iff the enclosing class has the proxy annotation.
10738 * 10706 *
10739 * @return `true` iff the enclosing class has the proxy annotation 10707 * @return `true` iff the enclosing class has the proxy annotation
10740 */ 10708 */
10741 bool shouldIncludeErrorCode() { 10709 bool shouldIncludeErrorCode() {
10742 if (_enclosingElement is ClassElement) { 10710 if (_enclosingElement is ClassElement) {
10743 return !(_enclosingElement as ClassElement).isOrInheritsProxy; 10711 return !(_enclosingElement as ClassElement).isOrInheritsProxy;
10744 } 10712 }
10745 return true; 10713 return true;
10746 } 10714 }
10747 } 10715 }
10748 10716
10749 /** 10717 /**
10750 * Instances of the class `Library` represent the data about a single library du ring the 10718 * Instances of the class `Library` represent the data about a single library du ring the
10751 * resolution of some (possibly different) library. They are not intended to be used except during 10719 * resolution of some (possibly different) library. They are not intended to be used except during
10752 * the resolution process. 10720 * the resolution process.
10753 */ 10721 */
10754 class ResolvableLibrary { 10722 class ResolvableLibrary {
10755 /** 10723 /**
10756 * The source specifying the defining compilation unit of this library. 10724 * The source specifying the defining compilation unit of this library.
10757 */ 10725 */
10758 Source librarySource; 10726 final Source librarySource;
10759 10727
10760 /** 10728 /**
10761 * A list containing all of the libraries that are imported into this library. 10729 * A list containing all of the libraries that are imported into this library.
10762 */ 10730 */
10763 List<ResolvableLibrary> _importedLibraries = _EMPTY_ARRAY; 10731 List<ResolvableLibrary> _importedLibraries = _EMPTY_ARRAY;
10764 10732
10765 /** 10733 /**
10766 * A flag indicating whether this library explicitly imports core. 10734 * A flag indicating whether this library explicitly imports core.
10767 */ 10735 */
10768 bool explicitlyImportsCore = false; 10736 bool explicitlyImportsCore = false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
10802 * The library scope used when resolving elements within this library's compil ation units. 10770 * The library scope used when resolving elements within this library's compil ation units.
10803 */ 10771 */
10804 LibraryScope _libraryScope; 10772 LibraryScope _libraryScope;
10805 10773
10806 /** 10774 /**
10807 * Initialize a newly created data holder that can maintain the data associate d with a library. 10775 * Initialize a newly created data holder that can maintain the data associate d with a library.
10808 * 10776 *
10809 * @param librarySource the source specifying the defining compilation unit of this library 10777 * @param librarySource the source specifying the defining compilation unit of this library
10810 * @param errorListener the listener to which analysis errors will be reported 10778 * @param errorListener the listener to which analysis errors will be reported
10811 */ 10779 */
10812 ResolvableLibrary(Source librarySource) { 10780 ResolvableLibrary(this.librarySource);
10813 this.librarySource = librarySource;
10814 }
10815 10781
10816 /** 10782 /**
10817 * Return the AST structure associated with the given source, or `null` if the source does 10783 * Return the AST structure associated with the given source, or `null` if the source does
10818 * not represent a compilation unit that is included in this library. 10784 * not represent a compilation unit that is included in this library.
10819 * 10785 *
10820 * @param source the source representing the compilation unit whose AST is to be returned 10786 * @param source the source representing the compilation unit whose AST is to be returned
10821 * @return the AST structure associated with the given source 10787 * @return the AST structure associated with the given source
10822 * @throws AnalysisException if an AST structure could not be created for the compilation unit 10788 * @throws AnalysisException if an AST structure could not be created for the compilation unit
10823 */ 10789 */
10824 CompilationUnit getAST(Source source) { 10790 CompilationUnit getAST(Source source) {
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
11151 super.visitAssertStatement(node); 11117 super.visitAssertStatement(node);
11152 _propagateTrueState(node.condition); 11118 _propagateTrueState(node.condition);
11153 return null; 11119 return null;
11154 } 11120 }
11155 11121
11156 @override 11122 @override
11157 Object visitBinaryExpression(BinaryExpression node) { 11123 Object visitBinaryExpression(BinaryExpression node) {
11158 sc.TokenType operatorType = node.operator.type; 11124 sc.TokenType operatorType = node.operator.type;
11159 Expression leftOperand = node.leftOperand; 11125 Expression leftOperand = node.leftOperand;
11160 Expression rightOperand = node.rightOperand; 11126 Expression rightOperand = node.rightOperand;
11161 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) { 11127 if (operatorType == sc.TokenType.AMPERSAND_AMPERSAND) {
11162 safelyVisit(leftOperand); 11128 safelyVisit(leftOperand);
11163 if (rightOperand != null) { 11129 if (rightOperand != null) {
11164 try { 11130 try {
11165 _overrideManager.enterScope(); 11131 _overrideManager.enterScope();
11166 _promoteManager.enterScope(); 11132 _promoteManager.enterScope();
11167 _propagateTrueState(leftOperand); 11133 _propagateTrueState(leftOperand);
11168 // Type promotion. 11134 // Type promotion.
11169 _promoteTypes(leftOperand); 11135 _promoteTypes(leftOperand);
11170 _clearTypePromotionsIfPotentiallyMutatedIn(leftOperand); 11136 _clearTypePromotionsIfPotentiallyMutatedIn(leftOperand);
11171 _clearTypePromotionsIfPotentiallyMutatedIn(rightOperand); 11137 _clearTypePromotionsIfPotentiallyMutatedIn(rightOperand);
11172 _clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(rightOpe rand); 11138 _clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(rightOpe rand);
11173 // Visit right operand. 11139 // Visit right operand.
11174 rightOperand.accept(this); 11140 rightOperand.accept(this);
11175 } finally { 11141 } finally {
11176 _overrideManager.exitScope(); 11142 _overrideManager.exitScope();
11177 _promoteManager.exitScope(); 11143 _promoteManager.exitScope();
11178 } 11144 }
11179 } 11145 }
11180 } else if (identical(operatorType, sc.TokenType.BAR_BAR)) { 11146 } else if (operatorType == sc.TokenType.BAR_BAR) {
11181 safelyVisit(leftOperand); 11147 safelyVisit(leftOperand);
11182 if (rightOperand != null) { 11148 if (rightOperand != null) {
11183 try { 11149 try {
11184 _overrideManager.enterScope(); 11150 _overrideManager.enterScope();
11185 _propagateFalseState(leftOperand); 11151 _propagateFalseState(leftOperand);
11186 rightOperand.accept(this); 11152 rightOperand.accept(this);
11187 } finally { 11153 } finally {
11188 _overrideManager.exitScope(); 11154 _overrideManager.exitScope();
11189 } 11155 }
11190 } 11156 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
11229 } finally { 11195 } finally {
11230 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; 11196 _typeAnalyzer.thisType = outerType == null ? null : outerType.type;
11231 _enclosingClass = outerType; 11197 _enclosingClass = outerType;
11232 } 11198 }
11233 return null; 11199 return null;
11234 } 11200 }
11235 11201
11236 @override 11202 @override
11237 Object visitComment(Comment node) { 11203 Object visitComment(Comment node) {
11238 if (node.parent is FunctionDeclaration || node.parent is ConstructorDeclarat ion || node.parent is MethodDeclaration) { 11204 if (node.parent is FunctionDeclaration || node.parent is ConstructorDeclarat ion || node.parent is MethodDeclaration) {
11239 if (node != _commentBeforeFunction) { 11205 if (!identical(node, _commentBeforeFunction)) {
11240 _commentBeforeFunction = node; 11206 _commentBeforeFunction = node;
11241 return null; 11207 return null;
11242 } 11208 }
11243 } 11209 }
11244 super.visitComment(node); 11210 super.visitComment(node);
11245 _commentBeforeFunction = null; 11211 _commentBeforeFunction = null;
11246 return null; 11212 return null;
11247 } 11213 }
11248 11214
11249 @override 11215 @override
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
11767 } 11733 }
11768 if (expression is! SimpleIdentifier) { 11734 if (expression is! SimpleIdentifier) {
11769 return null; 11735 return null;
11770 } 11736 }
11771 SimpleIdentifier identifier = expression as SimpleIdentifier; 11737 SimpleIdentifier identifier = expression as SimpleIdentifier;
11772 Element element = identifier.staticElement; 11738 Element element = identifier.staticElement;
11773 if (element is! VariableElement) { 11739 if (element is! VariableElement) {
11774 return null; 11740 return null;
11775 } 11741 }
11776 ElementKind kind = element.kind; 11742 ElementKind kind = element.kind;
11777 if (identical(kind, ElementKind.LOCAL_VARIABLE)) { 11743 if (kind == ElementKind.LOCAL_VARIABLE) {
11778 return element as VariableElement; 11744 return element as VariableElement;
11779 } 11745 }
11780 if (identical(kind, ElementKind.PARAMETER)) { 11746 if (kind == ElementKind.PARAMETER) {
11781 return element as VariableElement; 11747 return element as VariableElement;
11782 } 11748 }
11783 return null; 11749 return null;
11784 } 11750 }
11785 11751
11786 /** 11752 /**
11787 * If it is appropriate to do so, override the current type of the static and propagated elements 11753 * If it is appropriate to do so, override the current type of the static and propagated elements
11788 * associated with the given expression with the given type. Generally speakin g, it is appropriate 11754 * associated with the given expression with the given type. Generally speakin g, it is appropriate
11789 * if the given type is more specific than the current type. 11755 * if the given type is more specific than the current type.
11790 * 11756 *
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
12161 _promoteManager.setType(element, potentialType); 12127 _promoteManager.setType(element, potentialType);
12162 } 12128 }
12163 } 12129 }
12164 12130
12165 /** 12131 /**
12166 * Promotes type information using given condition. 12132 * Promotes type information using given condition.
12167 */ 12133 */
12168 void _promoteTypes(Expression condition) { 12134 void _promoteTypes(Expression condition) {
12169 if (condition is BinaryExpression) { 12135 if (condition is BinaryExpression) {
12170 BinaryExpression binary = condition; 12136 BinaryExpression binary = condition;
12171 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { 12137 if (binary.operator.type == sc.TokenType.AMPERSAND_AMPERSAND) {
12172 Expression left = binary.leftOperand; 12138 Expression left = binary.leftOperand;
12173 Expression right = binary.rightOperand; 12139 Expression right = binary.rightOperand;
12174 _promoteTypes(left); 12140 _promoteTypes(left);
12175 _promoteTypes(right); 12141 _promoteTypes(right);
12176 _clearTypePromotionsIfPotentiallyMutatedIn(right); 12142 _clearTypePromotionsIfPotentiallyMutatedIn(right);
12177 } 12143 }
12178 } else if (condition is IsExpression) { 12144 } else if (condition is IsExpression) {
12179 IsExpression is2 = condition; 12145 IsExpression is2 = condition;
12180 if (is2.notOperator == null) { 12146 if (is2.notOperator == null) {
12181 _promote(is2.expression, is2.type.type); 12147 _promote(is2.expression, is2.type.type);
12182 } 12148 }
12183 } else if (condition is ParenthesizedExpression) { 12149 } else if (condition is ParenthesizedExpression) {
12184 _promoteTypes(condition.expression); 12150 _promoteTypes(condition.expression);
12185 } 12151 }
12186 } 12152 }
12187 12153
12188 /** 12154 /**
12189 * Propagate any type information that results from knowing that the given con dition will have 12155 * Propagate any type information that results from knowing that the given con dition will have
12190 * been evaluated to 'false'. 12156 * been evaluated to 'false'.
12191 * 12157 *
12192 * @param condition the condition that will have evaluated to 'false' 12158 * @param condition the condition that will have evaluated to 'false'
12193 */ 12159 */
12194 void _propagateFalseState(Expression condition) { 12160 void _propagateFalseState(Expression condition) {
12195 if (condition is BinaryExpression) { 12161 if (condition is BinaryExpression) {
12196 BinaryExpression binary = condition; 12162 BinaryExpression binary = condition;
12197 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { 12163 if (binary.operator.type == sc.TokenType.BAR_BAR) {
12198 _propagateFalseState(binary.leftOperand); 12164 _propagateFalseState(binary.leftOperand);
12199 _propagateFalseState(binary.rightOperand); 12165 _propagateFalseState(binary.rightOperand);
12200 } 12166 }
12201 } else if (condition is IsExpression) { 12167 } else if (condition is IsExpression) {
12202 IsExpression is2 = condition; 12168 IsExpression is2 = condition;
12203 if (is2.notOperator != null) { 12169 if (is2.notOperator != null) {
12204 overrideExpression(is2.expression, is2.type.type); 12170 overrideExpression(is2.expression, is2.type.type);
12205 } 12171 }
12206 } else if (condition is PrefixExpression) { 12172 } else if (condition is PrefixExpression) {
12207 PrefixExpression prefix = condition; 12173 PrefixExpression prefix = condition;
12208 if (identical(prefix.operator.type, sc.TokenType.BANG)) { 12174 if (prefix.operator.type == sc.TokenType.BANG) {
12209 _propagateTrueState(prefix.operand); 12175 _propagateTrueState(prefix.operand);
12210 } 12176 }
12211 } else if (condition is ParenthesizedExpression) { 12177 } else if (condition is ParenthesizedExpression) {
12212 _propagateFalseState(condition.expression); 12178 _propagateFalseState(condition.expression);
12213 } 12179 }
12214 } 12180 }
12215 12181
12216 /** 12182 /**
12217 * Propagate any type information that results from knowing that the given exp ression will have 12183 * Propagate any type information that results from knowing that the given exp ression will have
12218 * been evaluated without altering the flow of execution. 12184 * been evaluated without altering the flow of execution.
12219 * 12185 *
12220 * @param expression the expression that will have been evaluated 12186 * @param expression the expression that will have been evaluated
12221 */ 12187 */
12222 void _propagateState(Expression expression) { 12188 void _propagateState(Expression expression) {
12223 } 12189 }
12224 12190
12225 /** 12191 /**
12226 * Propagate any type information that results from knowing that the given con dition will have 12192 * Propagate any type information that results from knowing that the given con dition will have
12227 * been evaluated to 'true'. 12193 * been evaluated to 'true'.
12228 * 12194 *
12229 * @param condition the condition that will have evaluated to 'true' 12195 * @param condition the condition that will have evaluated to 'true'
12230 */ 12196 */
12231 void _propagateTrueState(Expression condition) { 12197 void _propagateTrueState(Expression condition) {
12232 if (condition is BinaryExpression) { 12198 if (condition is BinaryExpression) {
12233 BinaryExpression binary = condition; 12199 BinaryExpression binary = condition;
12234 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { 12200 if (binary.operator.type == sc.TokenType.AMPERSAND_AMPERSAND) {
12235 _propagateTrueState(binary.leftOperand); 12201 _propagateTrueState(binary.leftOperand);
12236 _propagateTrueState(binary.rightOperand); 12202 _propagateTrueState(binary.rightOperand);
12237 } 12203 }
12238 } else if (condition is IsExpression) { 12204 } else if (condition is IsExpression) {
12239 IsExpression is2 = condition; 12205 IsExpression is2 = condition;
12240 if (is2.notOperator == null) { 12206 if (is2.notOperator == null) {
12241 overrideExpression(is2.expression, is2.type.type); 12207 overrideExpression(is2.expression, is2.type.type);
12242 } 12208 }
12243 } else if (condition is PrefixExpression) { 12209 } else if (condition is PrefixExpression) {
12244 PrefixExpression prefix = condition; 12210 PrefixExpression prefix = condition;
12245 if (identical(prefix.operator.type, sc.TokenType.BANG)) { 12211 if (prefix.operator.type == sc.TokenType.BANG) {
12246 _propagateFalseState(prefix.operand); 12212 _propagateFalseState(prefix.operand);
12247 } 12213 }
12248 } else if (condition is ParenthesizedExpression) { 12214 } else if (condition is ParenthesizedExpression) {
12249 _propagateTrueState(condition.expression); 12215 _propagateTrueState(condition.expression);
12250 } 12216 }
12251 } 12217 }
12252 12218
12253 /** 12219 /**
12254 * Record that the propagated type of the given node is the given type. 12220 * Record that the propagated type of the given node is the given type.
12255 * 12221 *
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
12342 */ 12308 */
12343 abstract class ScopedVisitor extends UnifyingAstVisitor<Object> { 12309 abstract class ScopedVisitor extends UnifyingAstVisitor<Object> {
12344 /** 12310 /**
12345 * The element for the library containing the compilation unit being visited. 12311 * The element for the library containing the compilation unit being visited.
12346 */ 12312 */
12347 LibraryElement _definingLibrary; 12313 LibraryElement _definingLibrary;
12348 12314
12349 /** 12315 /**
12350 * The source representing the compilation unit being visited. 12316 * The source representing the compilation unit being visited.
12351 */ 12317 */
12352 Source source; 12318 final Source source;
12353 12319
12354 /** 12320 /**
12355 * The error listener that will be informed of any errors that are found durin g resolution. 12321 * The error listener that will be informed of any errors that are found durin g resolution.
12356 */ 12322 */
12357 AnalysisErrorListener _errorListener; 12323 AnalysisErrorListener _errorListener;
12358 12324
12359 /** 12325 /**
12360 * The scope used to resolve identifiers. 12326 * The scope used to resolve identifiers.
12361 */ 12327 */
12362 Scope _nameScope; 12328 Scope _nameScope;
12363 12329
12364 /** 12330 /**
12365 * The object used to access the types from the core library. 12331 * The object used to access the types from the core library.
12366 */ 12332 */
12367 TypeProvider typeProvider; 12333 final TypeProvider typeProvider;
12368 12334
12369 /** 12335 /**
12370 * The scope used to resolve labels for `break` and `continue` statements, or 12336 * The scope used to resolve labels for `break` and `continue` statements, or
12371 * `null` if no labels have been defined in the current context. 12337 * `null` if no labels have been defined in the current context.
12372 */ 12338 */
12373 LabelScope _labelScope; 12339 LabelScope _labelScope;
12374 12340
12375 /** 12341 /**
12376 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 12342 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
12377 * 12343 *
12378 * @param library the library containing the compilation unit being resolved 12344 * @param library the library containing the compilation unit being resolved
12379 * @param source the source representing the compilation unit being visited 12345 * @param source the source representing the compilation unit being visited
12380 * @param typeProvider the object used to access the types from the core libra ry 12346 * @param typeProvider the object used to access the types from the core libra ry
12381 */ 12347 */
12382 ScopedVisitor.con1(Library library, Source source, TypeProvider typeProvider) { 12348 ScopedVisitor.con1(Library library, this.source, this.typeProvider) {
12383 this._definingLibrary = library.libraryElement; 12349 this._definingLibrary = library.libraryElement;
12384 this.source = source;
12385 LibraryScope libraryScope = library.libraryScope; 12350 LibraryScope libraryScope = library.libraryScope;
12386 this._errorListener = libraryScope.errorListener; 12351 this._errorListener = libraryScope.errorListener;
12387 this._nameScope = libraryScope; 12352 this._nameScope = libraryScope;
12388 this.typeProvider = typeProvider;
12389 } 12353 }
12390 12354
12391 /** 12355 /**
12392 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 12356 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
12393 * 12357 *
12394 * @param definingLibrary the element for the library containing the compilati on unit being 12358 * @param definingLibrary the element for the library containing the compilati on unit being
12395 * visited 12359 * visited
12396 * @param source the source representing the compilation unit being visited 12360 * @param source the source representing the compilation unit being visited
12397 * @param typeProvider the object used to access the types from the core libra ry 12361 * @param typeProvider the object used to access the types from the core libra ry
12398 * @param errorListener the error listener that will be informed of any errors that are found 12362 * @param errorListener the error listener that will be informed of any errors that are found
12399 * during resolution 12363 * during resolution
12400 */ 12364 */
12401 ScopedVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, AnalysisErrorListener errorListener) { 12365 ScopedVisitor.con2(LibraryElement definingLibrary, this.source, this.typeProvi der, AnalysisErrorListener errorListener) {
12402 this._definingLibrary = definingLibrary; 12366 this._definingLibrary = definingLibrary;
12403 this.source = source;
12404 this._errorListener = errorListener; 12367 this._errorListener = errorListener;
12405 this._nameScope = new LibraryScope(definingLibrary, errorListener); 12368 this._nameScope = new LibraryScope(definingLibrary, errorListener);
12406 this.typeProvider = typeProvider;
12407 } 12369 }
12408 12370
12409 /** 12371 /**
12410 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 12372 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
12411 * 12373 *
12412 * @param definingLibrary the element for the library containing the compilati on unit being 12374 * @param definingLibrary the element for the library containing the compilati on unit being
12413 * visited 12375 * visited
12414 * @param source the source representing the compilation unit being visited 12376 * @param source the source representing the compilation unit being visited
12415 * @param typeProvider the object used to access the types from the core libra ry 12377 * @param typeProvider the object used to access the types from the core libra ry
12416 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited 12378 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
12417 * @param errorListener the error listener that will be informed of any errors that are found 12379 * @param errorListener the error listener that will be informed of any errors that are found
12418 * during resolution 12380 * during resolution
12419 */ 12381 */
12420 ScopedVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) { 12382 ScopedVisitor.con3(LibraryElement definingLibrary, this.source, this.typeProvi der, Scope nameScope, AnalysisErrorListener errorListener) {
12421 this._definingLibrary = definingLibrary; 12383 this._definingLibrary = definingLibrary;
12422 this.source = source;
12423 this._errorListener = errorListener; 12384 this._errorListener = errorListener;
12424 this._nameScope = nameScope; 12385 this._nameScope = nameScope;
12425 this.typeProvider = typeProvider;
12426 } 12386 }
12427 12387
12428 /** 12388 /**
12429 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 12389 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
12430 * 12390 *
12431 * @param library the library containing the compilation unit being resolved 12391 * @param library the library containing the compilation unit being resolved
12432 * @param source the source representing the compilation unit being visited 12392 * @param source the source representing the compilation unit being visited
12433 * @param typeProvider the object used to access the types from the core libra ry 12393 * @param typeProvider the object used to access the types from the core libra ry
12434 */ 12394 */
12435 ScopedVisitor.con4(ResolvableLibrary library, Source source, TypeProvider type Provider) { 12395 ScopedVisitor.con4(ResolvableLibrary library, this.source, this.typeProvider) {
12436 this._definingLibrary = library.libraryElement; 12396 this._definingLibrary = library.libraryElement;
12437 this.source = source;
12438 LibraryScope libraryScope = library.libraryScope; 12397 LibraryScope libraryScope = library.libraryScope;
12439 this._errorListener = libraryScope.errorListener; 12398 this._errorListener = libraryScope.errorListener;
12440 this._nameScope = libraryScope; 12399 this._nameScope = libraryScope;
12441 this.typeProvider = typeProvider;
12442 } 12400 }
12443 12401
12444 /** 12402 /**
12445 * Return the library element for the library containing the compilation unit being resolved. 12403 * Return the library element for the library containing the compilation unit being resolved.
12446 * 12404 *
12447 * @return the library element for the library containing the compilation unit being resolved 12405 * @return the library element for the library containing the compilation unit being resolved
12448 */ 12406 */
12449 LibraryElement get definingLibrary => _definingLibrary; 12407 LibraryElement get definingLibrary => _definingLibrary;
12450 12408
12451 /** 12409 /**
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
13040 map["title"] = "TitleElement"; 12998 map["title"] = "TitleElement";
13041 map["track"] = "TrackElement"; 12999 map["track"] = "TrackElement";
13042 map["ul"] = "UListElement"; 13000 map["ul"] = "UListElement";
13043 map["video"] = "VideoElement"; 13001 map["video"] = "VideoElement";
13044 return map; 13002 return map;
13045 } 13003 }
13046 13004
13047 /** 13005 /**
13048 * The resolver driving the resolution and type analysis. 13006 * The resolver driving the resolution and type analysis.
13049 */ 13007 */
13050 ResolverVisitor _resolver; 13008 final ResolverVisitor _resolver;
13051 13009
13052 /** 13010 /**
13053 * The object providing access to the types defined by the language. 13011 * The object providing access to the types defined by the language.
13054 */ 13012 */
13055 TypeProvider _typeProvider; 13013 TypeProvider _typeProvider;
13056 13014
13057 /** 13015 /**
13058 * The type representing the type 'dynamic'. 13016 * The type representing the type 'dynamic'.
13059 */ 13017 */
13060 DartType _dynamicType; 13018 DartType _dynamicType;
(...skipping 23 matching lines...) Expand all
13084 * A table mapping HTML tag names to the names of the classes (in 'dart:html') that implement 13042 * A table mapping HTML tag names to the names of the classes (in 'dart:html') that implement
13085 * those tags. 13043 * those tags.
13086 */ 13044 */
13087 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = _createHtmlTagToClassM ap(); 13045 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = _createHtmlTagToClassM ap();
13088 13046
13089 /** 13047 /**
13090 * Initialize a newly created type analyzer. 13048 * Initialize a newly created type analyzer.
13091 * 13049 *
13092 * @param resolver the resolver driving this participant 13050 * @param resolver the resolver driving this participant
13093 */ 13051 */
13094 StaticTypeAnalyzer(ResolverVisitor resolver) { 13052 StaticTypeAnalyzer(this._resolver) {
13095 this._resolver = resolver; 13053 _typeProvider = _resolver.typeProvider;
13096 _typeProvider = resolver.typeProvider;
13097 _dynamicType = _typeProvider.dynamicType; 13054 _dynamicType = _typeProvider.dynamicType;
13098 _overrideManager = resolver.overrideManager; 13055 _overrideManager = _resolver.overrideManager;
13099 _promoteManager = resolver.promoteManager; 13056 _promoteManager = _resolver.promoteManager;
13100 } 13057 }
13101 13058
13102 /** 13059 /**
13103 * Set the type of the class being analyzed to the given type. 13060 * Set the type of the class being analyzed to the given type.
13104 * 13061 *
13105 * @param thisType the type representing the class containing the nodes being analyzed 13062 * @param thisType the type representing the class containing the nodes being analyzed
13106 */ 13063 */
13107 void set thisType(InterfaceType thisType) { 13064 void set thisType(InterfaceType thisType) {
13108 this._thisType = thisType; 13065 this._thisType = thisType;
13109 } 13066 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
13177 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale nt to <i>((x) => x.v 13134 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale nt to <i>((x) => x.v
13178 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha t is not used in 13135 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha t is not used in
13179 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op= 13136 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op=
13180 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su b>)(e<sub>1</sub>, 13137 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su b>)(e<sub>1</sub>,
13181 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in 13138 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in
13182 * <i>e<sub>3</sub></i>.</blockquote> 13139 * <i>e<sub>3</sub></i>.</blockquote>
13183 */ 13140 */
13184 @override 13141 @override
13185 Object visitAssignmentExpression(AssignmentExpression node) { 13142 Object visitAssignmentExpression(AssignmentExpression node) {
13186 sc.TokenType operator = node.operator.type; 13143 sc.TokenType operator = node.operator.type;
13187 if (identical(operator, sc.TokenType.EQ)) { 13144 if (operator == sc.TokenType.EQ) {
13188 Expression rightHandSide = node.rightHandSide; 13145 Expression rightHandSide = node.rightHandSide;
13189 DartType staticType = _getStaticType(rightHandSide); 13146 DartType staticType = _getStaticType(rightHandSide);
13190 _recordStaticType(node, staticType); 13147 _recordStaticType(node, staticType);
13191 DartType overrideType = staticType; 13148 DartType overrideType = staticType;
13192 DartType propagatedType = rightHandSide.propagatedType; 13149 DartType propagatedType = rightHandSide.propagatedType;
13193 if (propagatedType != null) { 13150 if (propagatedType != null) {
13194 if (propagatedType.isMoreSpecificThan(staticType)) { 13151 if (propagatedType.isMoreSpecificThan(staticType)) {
13195 _recordPropagatedType(node, propagatedType); 13152 _recordPropagatedType(node, propagatedType);
13196 } 13153 }
13197 overrideType = propagatedType; 13154 overrideType = propagatedType;
13198 } 13155 }
13199 _resolver.overrideExpression(node.leftHandSide, overrideType); 13156 _resolver.overrideExpression(node.leftHandSide, overrideType);
13200 } else { 13157 } else {
13201 ExecutableElement staticMethodElement = node.staticElement; 13158 ExecutableElement staticMethodElement = node.staticElement;
13202 DartType staticType = _computeStaticReturnType(staticMethodElement); 13159 DartType staticType = _computeStaticReturnType(staticMethodElement);
13203 _recordStaticType(node, staticType); 13160 _recordStaticType(node, staticType);
13204 MethodElement propagatedMethodElement = node.propagatedElement; 13161 MethodElement propagatedMethodElement = node.propagatedElement;
13205 if (propagatedMethodElement != staticMethodElement) { 13162 if (!identical(propagatedMethodElement, staticMethodElement)) {
13206 DartType propagatedType = _computeStaticReturnType(propagatedMethodEleme nt); 13163 DartType propagatedType = _computeStaticReturnType(propagatedMethodEleme nt);
13207 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 13164 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
13208 _recordPropagatedType(node, propagatedType); 13165 _recordPropagatedType(node, propagatedType);
13209 } 13166 }
13210 } 13167 }
13211 } 13168 }
13212 return null; 13169 return null;
13213 } 13170 }
13214 13171
13215 /** 13172 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
13249 * e<sub>2</sub></i> is equivalent to the method invocation 13206 * e<sub>2</sub></i> is equivalent to the method invocation
13250 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 13207 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
13251 */ 13208 */
13252 @override 13209 @override
13253 Object visitBinaryExpression(BinaryExpression node) { 13210 Object visitBinaryExpression(BinaryExpression node) {
13254 ExecutableElement staticMethodElement = node.staticElement; 13211 ExecutableElement staticMethodElement = node.staticElement;
13255 DartType staticType = _computeStaticReturnType(staticMethodElement); 13212 DartType staticType = _computeStaticReturnType(staticMethodElement);
13256 staticType = _refineBinaryExpressionType(node, staticType); 13213 staticType = _refineBinaryExpressionType(node, staticType);
13257 _recordStaticType(node, staticType); 13214 _recordStaticType(node, staticType);
13258 MethodElement propagatedMethodElement = node.propagatedElement; 13215 MethodElement propagatedMethodElement = node.propagatedElement;
13259 if (propagatedMethodElement != staticMethodElement) { 13216 if (!identical(propagatedMethodElement, staticMethodElement)) {
13260 DartType propagatedType = _computeStaticReturnType(propagatedMethodElement ); 13217 DartType propagatedType = _computeStaticReturnType(propagatedMethodElement );
13261 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) { 13218 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) {
13262 _recordPropagatedType(node, propagatedType); 13219 _recordPropagatedType(node, propagatedType);
13263 } 13220 }
13264 } 13221 }
13265 return null; 13222 return null;
13266 } 13223 }
13267 13224
13268 /** 13225 /**
13269 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is 13226 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
13410 ExecutableElement staticMethodElement = node.staticElement; 13367 ExecutableElement staticMethodElement = node.staticElement;
13411 // Record static return type of the static element. 13368 // Record static return type of the static element.
13412 DartType staticStaticType = _computeStaticReturnType(staticMethodElement); 13369 DartType staticStaticType = _computeStaticReturnType(staticMethodElement);
13413 _recordStaticType(node, staticStaticType); 13370 _recordStaticType(node, staticStaticType);
13414 // Record propagated return type of the static element. 13371 // Record propagated return type of the static element.
13415 DartType staticPropagatedType = _computePropagatedReturnType(staticMethodEle ment); 13372 DartType staticPropagatedType = _computePropagatedReturnType(staticMethodEle ment);
13416 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) { 13373 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) {
13417 _recordPropagatedType(node, staticPropagatedType); 13374 _recordPropagatedType(node, staticPropagatedType);
13418 } 13375 }
13419 ExecutableElement propagatedMethodElement = node.propagatedElement; 13376 ExecutableElement propagatedMethodElement = node.propagatedElement;
13420 if (propagatedMethodElement != staticMethodElement) { 13377 if (!identical(propagatedMethodElement, staticMethodElement)) {
13421 // Record static return type of the propagated element. 13378 // Record static return type of the propagated element.
13422 DartType propagatedStaticType = _computeStaticReturnType(propagatedMethodE lement); 13379 DartType propagatedStaticType = _computeStaticReturnType(propagatedMethodE lement);
13423 if (propagatedStaticType != null && (staticStaticType == null || propagate dStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == nu ll || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) { 13380 if (propagatedStaticType != null && (staticStaticType == null || propagate dStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == nu ll || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) {
13424 _recordPropagatedType(node, propagatedStaticType); 13381 _recordPropagatedType(node, propagatedStaticType);
13425 } 13382 }
13426 // Record propagated return type of the propagated element. 13383 // Record propagated return type of the propagated element.
13427 DartType propagatedPropagatedType = _computePropagatedReturnType(propagate dMethodElement); 13384 DartType propagatedPropagatedType = _computePropagatedReturnType(propagate dMethodElement);
13428 if (propagatedPropagatedType != null && (staticStaticType == null || propa gatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedTy pe == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType)) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan (propagatedStaticType))) { 13385 if (propagatedPropagatedType != null && (staticStaticType == null || propa gatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedTy pe == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType)) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan (propagatedStaticType))) {
13429 _recordPropagatedType(node, propagatedPropagatedType); 13386 _recordPropagatedType(node, propagatedPropagatedType);
13430 } 13387 }
13431 } 13388 }
13432 return null; 13389 return null;
13433 } 13390 }
13434 13391
13435 /** 13392 /**
13436 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form 13393 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form
13437 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method 13394 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method
13438 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote> 13395 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote>
13439 */ 13396 */
13440 @override 13397 @override
13441 Object visitIndexExpression(IndexExpression node) { 13398 Object visitIndexExpression(IndexExpression node) {
13442 if (node.inSetterContext()) { 13399 if (node.inSetterContext()) {
13443 ExecutableElement staticMethodElement = node.staticElement; 13400 ExecutableElement staticMethodElement = node.staticElement;
13444 DartType staticType = _computeArgumentType(staticMethodElement); 13401 DartType staticType = _computeArgumentType(staticMethodElement);
13445 _recordStaticType(node, staticType); 13402 _recordStaticType(node, staticType);
13446 MethodElement propagatedMethodElement = node.propagatedElement; 13403 MethodElement propagatedMethodElement = node.propagatedElement;
13447 if (propagatedMethodElement != staticMethodElement) { 13404 if (!identical(propagatedMethodElement, staticMethodElement)) {
13448 DartType propagatedType = _computeArgumentType(propagatedMethodElement); 13405 DartType propagatedType = _computeArgumentType(propagatedMethodElement);
13449 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 13406 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
13450 _recordPropagatedType(node, propagatedType); 13407 _recordPropagatedType(node, propagatedType);
13451 } 13408 }
13452 } 13409 }
13453 } else { 13410 } else {
13454 ExecutableElement staticMethodElement = node.staticElement; 13411 ExecutableElement staticMethodElement = node.staticElement;
13455 DartType staticType = _computeStaticReturnType(staticMethodElement); 13412 DartType staticType = _computeStaticReturnType(staticMethodElement);
13456 _recordStaticType(node, staticType); 13413 _recordStaticType(node, staticType);
13457 MethodElement propagatedMethodElement = node.propagatedElement; 13414 MethodElement propagatedMethodElement = node.propagatedElement;
13458 if (propagatedMethodElement != staticMethodElement) { 13415 if (!identical(propagatedMethodElement, staticMethodElement)) {
13459 DartType propagatedType = _computeStaticReturnType(propagatedMethodEleme nt); 13416 DartType propagatedType = _computeStaticReturnType(propagatedMethodEleme nt);
13460 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 13417 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
13461 _recordPropagatedType(node, propagatedType); 13418 _recordPropagatedType(node, propagatedType);
13462 } 13419 }
13463 } 13420 }
13464 } 13421 }
13465 return null; 13422 return null;
13466 } 13423 }
13467 13424
13468 /** 13425 /**
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
13782 } 13739 }
13783 } 13740 }
13784 } 13741 }
13785 } else if (methodName == "JS") { 13742 } else if (methodName == "JS") {
13786 DartType returnType = _getFirstArgumentAsType(_typeProvider.objectType.ele ment.library, node.argumentList); 13743 DartType returnType = _getFirstArgumentAsType(_typeProvider.objectType.ele ment.library, node.argumentList);
13787 if (returnType != null) { 13744 if (returnType != null) {
13788 _recordPropagatedType(node, returnType); 13745 _recordPropagatedType(node, returnType);
13789 } 13746 }
13790 } else { 13747 } else {
13791 Element propagatedElement = methodNameNode.propagatedElement; 13748 Element propagatedElement = methodNameNode.propagatedElement;
13792 if (propagatedElement != staticMethodElement) { 13749 if (!identical(propagatedElement, staticMethodElement)) {
13793 // Record static return type of the propagated element. 13750 // Record static return type of the propagated element.
13794 DartType propagatedStaticType = _computeStaticReturnType(propagatedEleme nt); 13751 DartType propagatedStaticType = _computeStaticReturnType(propagatedEleme nt);
13795 if (propagatedStaticType != null && (staticStaticType == null || propaga tedStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) { 13752 if (propagatedStaticType != null && (staticStaticType == null || propaga tedStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) {
13796 _recordPropagatedType(node, propagatedStaticType); 13753 _recordPropagatedType(node, propagatedStaticType);
13797 } 13754 }
13798 // Record propagated return type of the propagated element. 13755 // Record propagated return type of the propagated element.
13799 DartType propagatedPropagatedType = _computePropagatedReturnType(propaga tedElement); 13756 DartType propagatedPropagatedType = _computePropagatedReturnType(propaga tedElement);
13800 if (propagatedPropagatedType != null && (staticStaticType == null || pro pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType )) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh an(propagatedStaticType))) { 13757 if (propagatedPropagatedType != null && (staticStaticType == null || pro pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType )) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh an(propagatedStaticType))) {
13801 _recordPropagatedType(node, propagatedPropagatedType); 13758 _recordPropagatedType(node, propagatedPropagatedType);
13802 } 13759 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
13855 * 1; return r}(e1)</i>. 13812 * 1; return r}(e1)</i>.
13856 * 13813 *
13857 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i] 13814 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i]
13858 * = r - 1; return r}(e1, e2)</i></blockquote> 13815 * = r - 1; return r}(e1, e2)</i></blockquote>
13859 */ 13816 */
13860 @override 13817 @override
13861 Object visitPostfixExpression(PostfixExpression node) { 13818 Object visitPostfixExpression(PostfixExpression node) {
13862 Expression operand = node.operand; 13819 Expression operand = node.operand;
13863 DartType staticType = _getStaticType(operand); 13820 DartType staticType = _getStaticType(operand);
13864 sc.TokenType operator = node.operator.type; 13821 sc.TokenType operator = node.operator.type;
13865 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc. TokenType.PLUS_PLUS)) { 13822 if (operator == sc.TokenType.MINUS_MINUS || operator == sc.TokenType.PLUS_PL US) {
13866 DartType intType = _typeProvider.intType; 13823 DartType intType = _typeProvider.intType;
13867 if (identical(_getStaticType(node.operand), intType)) { 13824 if (identical(_getStaticType(node.operand), intType)) {
13868 staticType = intType; 13825 staticType = intType;
13869 } 13826 }
13870 } 13827 }
13871 _recordStaticType(node, staticType); 13828 _recordStaticType(node, staticType);
13872 _recordPropagatedType(node, operand.propagatedType); 13829 _recordPropagatedType(node, operand.propagatedType);
13873 return null; 13830 return null;
13874 } 13831 }
13875 13832
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
13939 } 13896 }
13940 13897
13941 /** 13898 /**
13942 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form 13899 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form
13943 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the 13900 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the
13944 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote> 13901 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote>
13945 */ 13902 */
13946 @override 13903 @override
13947 Object visitPrefixExpression(PrefixExpression node) { 13904 Object visitPrefixExpression(PrefixExpression node) {
13948 sc.TokenType operator = node.operator.type; 13905 sc.TokenType operator = node.operator.type;
13949 if (identical(operator, sc.TokenType.BANG)) { 13906 if (operator == sc.TokenType.BANG) {
13950 _recordStaticType(node, _typeProvider.boolType); 13907 _recordStaticType(node, _typeProvider.boolType);
13951 } else { 13908 } else {
13952 // The other cases are equivalent to invoking a method. 13909 // The other cases are equivalent to invoking a method.
13953 ExecutableElement staticMethodElement = node.staticElement; 13910 ExecutableElement staticMethodElement = node.staticElement;
13954 DartType staticType = _computeStaticReturnType(staticMethodElement); 13911 DartType staticType = _computeStaticReturnType(staticMethodElement);
13955 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, s c.TokenType.PLUS_PLUS)) { 13912 if (operator == sc.TokenType.MINUS_MINUS || operator == sc.TokenType.PLUS_ PLUS) {
13956 DartType intType = _typeProvider.intType; 13913 DartType intType = _typeProvider.intType;
13957 if (identical(_getStaticType(node.operand), intType)) { 13914 if (identical(_getStaticType(node.operand), intType)) {
13958 staticType = intType; 13915 staticType = intType;
13959 } 13916 }
13960 } 13917 }
13961 _recordStaticType(node, staticType); 13918 _recordStaticType(node, staticType);
13962 MethodElement propagatedMethodElement = node.propagatedElement; 13919 MethodElement propagatedMethodElement = node.propagatedElement;
13963 if (propagatedMethodElement != staticMethodElement) { 13920 if (!identical(propagatedMethodElement, staticMethodElement)) {
13964 DartType propagatedType = _computeStaticReturnType(propagatedMethodEleme nt); 13921 DartType propagatedType = _computeStaticReturnType(propagatedMethodEleme nt);
13965 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 13922 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
13966 _recordPropagatedType(node, propagatedType); 13923 _recordPropagatedType(node, propagatedType);
13967 } 13924 }
13968 } 13925 }
13969 } 13926 }
13970 return null; 13927 return null;
13971 } 13928 }
13972 13929
13973 /** 13930 /**
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
14608 /** 14565 /**
14609 * Attempts to make a better guess for the static type of the given binary exp ression. 14566 * Attempts to make a better guess for the static type of the given binary exp ression.
14610 * 14567 *
14611 * @param node the binary expression to analyze 14568 * @param node the binary expression to analyze
14612 * @param staticType the static type of the expression as resolved 14569 * @param staticType the static type of the expression as resolved
14613 * @return the better type guess, or the same static type as given 14570 * @return the better type guess, or the same static type as given
14614 */ 14571 */
14615 DartType _refineBinaryExpressionType(BinaryExpression node, DartType staticTyp e) { 14572 DartType _refineBinaryExpressionType(BinaryExpression node, DartType staticTyp e) {
14616 sc.TokenType operator = node.operator.type; 14573 sc.TokenType operator = node.operator.type;
14617 // bool 14574 // bool
14618 if (identical(operator, sc.TokenType.AMPERSAND_AMPERSAND) || identical(opera tor, sc.TokenType.BAR_BAR) || identical(operator, sc.TokenType.EQ_EQ) || identic al(operator, sc.TokenType.BANG_EQ)) { 14575 if (operator == sc.TokenType.AMPERSAND_AMPERSAND || operator == sc.TokenType .BAR_BAR || operator == sc.TokenType.EQ_EQ || operator == sc.TokenType.BANG_EQ) {
14619 return _typeProvider.boolType; 14576 return _typeProvider.boolType;
14620 } 14577 }
14621 DartType intType = _typeProvider.intType; 14578 DartType intType = _typeProvider.intType;
14622 if (_getStaticType(node.leftOperand) == intType) { 14579 if (_getStaticType(node.leftOperand) == intType) {
14623 // int op double 14580 // int op double
14624 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.Toke nType.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc.TokenType.STAR)) { 14581 if (operator == sc.TokenType.MINUS || operator == sc.TokenType.PERCENT || operator == sc.TokenType.PLUS || operator == sc.TokenType.STAR) {
14625 DartType doubleType = _typeProvider.doubleType; 14582 DartType doubleType = _typeProvider.doubleType;
14626 if (_getStaticType(node.rightOperand) == doubleType) { 14583 if (_getStaticType(node.rightOperand) == doubleType) {
14627 return doubleType; 14584 return doubleType;
14628 } 14585 }
14629 } 14586 }
14630 // int op int 14587 // int op int
14631 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.Toke nType.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) { 14588 if (operator == sc.TokenType.MINUS || operator == sc.TokenType.PERCENT || operator == sc.TokenType.PLUS || operator == sc.TokenType.STAR || operator == sc .TokenType.TILDE_SLASH) {
14632 if (_getStaticType(node.rightOperand) == intType) { 14589 if (_getStaticType(node.rightOperand) == intType) {
14633 staticType = intType; 14590 staticType = intType;
14634 } 14591 }
14635 } 14592 }
14636 } 14593 }
14637 // default 14594 // default
14638 return staticType; 14595 return staticType;
14639 } 14596 }
14640 14597
14641 get thisType_J2DAccessor => _thisType; 14598 get thisType_J2DAccessor => _thisType;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
14918 } 14875 }
14919 14876
14920 /** 14877 /**
14921 * Instances of the class `TypeOverrideScope` represent a scope in which the typ es of 14878 * Instances of the class `TypeOverrideScope` represent a scope in which the typ es of
14922 * elements can be overridden. 14879 * elements can be overridden.
14923 */ 14880 */
14924 class TypeOverrideManager_TypeOverrideScope { 14881 class TypeOverrideManager_TypeOverrideScope {
14925 /** 14882 /**
14926 * The outer scope in which types might be overridden. 14883 * The outer scope in which types might be overridden.
14927 */ 14884 */
14928 TypeOverrideManager_TypeOverrideScope _outerScope; 14885 final TypeOverrideManager_TypeOverrideScope _outerScope;
14929 14886
14930 /** 14887 /**
14931 * A table mapping elements to the overridden type of that element. 14888 * A table mapping elements to the overridden type of that element.
14932 */ 14889 */
14933 Map<Element, DartType> _overridenTypes = new Map<Element, DartType>(); 14890 Map<Element, DartType> _overridenTypes = new Map<Element, DartType>();
14934 14891
14935 /** 14892 /**
14936 * Initialize a newly created scope to be an empty child of the given scope. 14893 * Initialize a newly created scope to be an empty child of the given scope.
14937 * 14894 *
14938 * @param outerScope the outer scope in which types might be overridden 14895 * @param outerScope the outer scope in which types might be overridden
14939 */ 14896 */
14940 TypeOverrideManager_TypeOverrideScope(TypeOverrideManager_TypeOverrideScope ou terScope) { 14897 TypeOverrideManager_TypeOverrideScope(this._outerScope);
14941 this._outerScope = outerScope;
14942 }
14943 14898
14944 /** 14899 /**
14945 * Apply a set of overrides that were previously captured. 14900 * Apply a set of overrides that were previously captured.
14946 * 14901 *
14947 * @param overrides the overrides to be applied 14902 * @param overrides the overrides to be applied
14948 */ 14903 */
14949 void applyOverrides(Map<Element, DartType> overrides) { 14904 void applyOverrides(Map<Element, DartType> overrides) {
14950 for (MapEntry<Element, DartType> entry in getMapEntrySet(overrides)) { 14905 for (MapEntry<Element, DartType> entry in getMapEntrySet(overrides)) {
14951 _overridenTypes[entry.getKey()] = entry.getValue(); 14906 _overridenTypes[entry.getKey()] = entry.getValue();
14952 } 14907 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
15088 } 15043 }
15089 15044
15090 /** 15045 /**
15091 * Instances of the class `TypePromoteScope` represent a scope in which the type s of 15046 * Instances of the class `TypePromoteScope` represent a scope in which the type s of
15092 * elements can be promoted. 15047 * elements can be promoted.
15093 */ 15048 */
15094 class TypePromotionManager_TypePromoteScope { 15049 class TypePromotionManager_TypePromoteScope {
15095 /** 15050 /**
15096 * The outer scope in which types might be promoter. 15051 * The outer scope in which types might be promoter.
15097 */ 15052 */
15098 TypePromotionManager_TypePromoteScope _outerScope; 15053 final TypePromotionManager_TypePromoteScope _outerScope;
15099 15054
15100 /** 15055 /**
15101 * A table mapping elements to the promoted type of that element. 15056 * A table mapping elements to the promoted type of that element.
15102 */ 15057 */
15103 Map<Element, DartType> _promotedTypes = new Map<Element, DartType>(); 15058 Map<Element, DartType> _promotedTypes = new Map<Element, DartType>();
15104 15059
15105 /** 15060 /**
15106 * Initialize a newly created scope to be an empty child of the given scope. 15061 * Initialize a newly created scope to be an empty child of the given scope.
15107 * 15062 *
15108 * @param outerScope the outer scope in which types might be promoted 15063 * @param outerScope the outer scope in which types might be promoted
15109 */ 15064 */
15110 TypePromotionManager_TypePromoteScope(TypePromotionManager_TypePromoteScope ou terScope) { 15065 TypePromotionManager_TypePromoteScope(this._outerScope);
15111 this._outerScope = outerScope;
15112 }
15113 15066
15114 /** 15067 /**
15115 * Returns the elements with promoted types. 15068 * Returns the elements with promoted types.
15116 */ 15069 */
15117 Iterable<Element> get promotedElements => _promotedTypes.keys.toSet(); 15070 Iterable<Element> get promotedElements => _promotedTypes.keys.toSet();
15118 15071
15119 /** 15072 /**
15120 * Return the promoted type of the given element, or `null` if the type of the element has 15073 * Return the promoted type of the given element, or `null` if the type of the element has
15121 * not been promoted. 15074 * not been promoted.
15122 * 15075 *
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
15455 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces, 15408 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces,
15456 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building 15409 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building
15457 * the type hierarchy. 15410 * the type hierarchy.
15458 */ 15411 */
15459 class TypeResolverVisitor extends ScopedVisitor { 15412 class TypeResolverVisitor extends ScopedVisitor {
15460 /** 15413 /**
15461 * @return `true` if the name of the given [TypeName] is an built-in identifie r. 15414 * @return `true` if the name of the given [TypeName] is an built-in identifie r.
15462 */ 15415 */
15463 static bool _isBuiltInIdentifier(TypeName node) { 15416 static bool _isBuiltInIdentifier(TypeName node) {
15464 sc.Token token = node.name.beginToken; 15417 sc.Token token = node.name.beginToken;
15465 return identical(token.type, sc.TokenType.KEYWORD); 15418 return token.type == sc.TokenType.KEYWORD;
15466 } 15419 }
15467 15420
15468 /** 15421 /**
15469 * @return `true` if given [TypeName] is used as a type annotation. 15422 * @return `true` if given [TypeName] is used as a type annotation.
15470 */ 15423 */
15471 static bool _isTypeAnnotation(TypeName node) { 15424 static bool _isTypeAnnotation(TypeName node) {
15472 AstNode parent = node.parent; 15425 AstNode parent = node.parent;
15473 if (parent is VariableDeclarationList) { 15426 if (parent is VariableDeclarationList) {
15474 return identical(parent.type, node); 15427 return identical(parent.type, node);
15475 } 15428 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
15573 @override 15526 @override
15574 Object visitClassDeclaration(ClassDeclaration node) { 15527 Object visitClassDeclaration(ClassDeclaration node) {
15575 _hasReferenceToSuper = false; 15528 _hasReferenceToSuper = false;
15576 super.visitClassDeclaration(node); 15529 super.visitClassDeclaration(node);
15577 ClassElementImpl classElement = _getClassElement(node.name); 15530 ClassElementImpl classElement = _getClassElement(node.name);
15578 InterfaceType superclassType = null; 15531 InterfaceType superclassType = null;
15579 ExtendsClause extendsClause = node.extendsClause; 15532 ExtendsClause extendsClause = node.extendsClause;
15580 if (extendsClause != null) { 15533 if (extendsClause != null) {
15581 ErrorCode errorCode = (node.withClause == null ? CompileTimeErrorCode.EXTE NDS_NON_CLASS : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS); 15534 ErrorCode errorCode = (node.withClause == null ? CompileTimeErrorCode.EXTE NDS_NON_CLASS : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS);
15582 superclassType = _resolveType(extendsClause.superclass, errorCode, errorCo de); 15535 superclassType = _resolveType(extendsClause.superclass, errorCode, errorCo de);
15583 if (superclassType != typeProvider.objectType) { 15536 if (!identical(superclassType, typeProvider.objectType)) {
15584 classElement.validMixin = false; 15537 classElement.validMixin = false;
15585 } 15538 }
15586 } 15539 }
15587 if (classElement != null) { 15540 if (classElement != null) {
15588 if (superclassType == null) { 15541 if (superclassType == null) {
15589 InterfaceType objectType = typeProvider.objectType; 15542 InterfaceType objectType = typeProvider.objectType;
15590 if (classElement.type != objectType) { 15543 if (!identical(classElement.type, objectType)) {
15591 superclassType = objectType; 15544 superclassType = objectType;
15592 } 15545 }
15593 } 15546 }
15594 classElement.supertype = superclassType; 15547 classElement.supertype = superclassType;
15595 classElement.hasReferenceToSuper = _hasReferenceToSuper; 15548 classElement.hasReferenceToSuper = _hasReferenceToSuper;
15596 } 15549 }
15597 _resolve(classElement, node.withClause, node.implementsClause); 15550 _resolve(classElement, node.withClause, node.implementsClause);
15598 return null; 15551 return null;
15599 } 15552 }
15600 15553
(...skipping 28 matching lines...) Expand all
15629 } 15582 }
15630 } 15583 }
15631 _resolve(classElement, node.withClause, node.implementsClause); 15584 _resolve(classElement, node.withClause, node.implementsClause);
15632 return null; 15585 return null;
15633 } 15586 }
15634 15587
15635 @override 15588 @override
15636 Object visitConstructorDeclaration(ConstructorDeclaration node) { 15589 Object visitConstructorDeclaration(ConstructorDeclaration node) {
15637 super.visitConstructorDeclaration(node); 15590 super.visitConstructorDeclaration(node);
15638 ExecutableElementImpl element = node.element as ExecutableElementImpl; 15591 ExecutableElementImpl element = node.element as ExecutableElementImpl;
15639 ClassElement definingClass = element.enclosingElement as ClassElement; 15592 if (element != null) {
15640 element.returnType = definingClass.type; 15593 // TODO(brianwilkerson) Figure out how the element could ever be null.
15641 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 15594 ClassElement definingClass = element.enclosingElement as ClassElement;
15642 type.typeArguments = definingClass.type.typeArguments; 15595 element.returnType = definingClass.type;
15643 element.type = type; 15596 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
15597 type.typeArguments = definingClass.type.typeArguments;
15598 element.type = type;
15599 }
15644 return null; 15600 return null;
15645 } 15601 }
15646 15602
15647 @override 15603 @override
15648 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 15604 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
15649 super.visitDeclaredIdentifier(node); 15605 super.visitDeclaredIdentifier(node);
15650 DartType declaredType; 15606 DartType declaredType;
15651 TypeName typeName = node.type; 15607 TypeName typeName = node.type;
15652 if (typeName == null) { 15608 if (typeName == null) {
15653 declaredType = _dynamicType; 15609 declaredType = _dynamicType;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
15867 reportErrorForNode(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typ eName, [typeName.name]); 15823 reportErrorForNode(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typ eName, [typeName.name]);
15868 } else if (typeNameSimple.name == "boolean") { 15824 } else if (typeNameSimple.name == "boolean") {
15869 reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSi mple, []); 15825 reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSi mple, []);
15870 } else if (_isTypeNameInCatchClause(node)) { 15826 } else if (_isTypeNameInCatchClause(node)) {
15871 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeName.name]); 15827 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeName.name]);
15872 } else if (_isTypeNameInAsExpression(node)) { 15828 } else if (_isTypeNameInAsExpression(node)) {
15873 reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeNa me.name]); 15829 reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeNa me.name]);
15874 } else if (_isTypeNameInIsExpression(node)) { 15830 } else if (_isTypeNameInIsExpression(node)) {
15875 reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [type Name.name]); 15831 reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [type Name.name]);
15876 } else if ((redirectingConstructorKind = _getRedirectingConstructorKind(no de)) != null) { 15832 } else if ((redirectingConstructorKind = _getRedirectingConstructorKind(no de)) != null) {
15877 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 15833 ErrorCode errorCode = (redirectingConstructorKind == RedirectingConstruc torKind.CONST ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarningCode.R EDIRECT_TO_NON_CLASS) as ErrorCode;
15878 reportErrorForNode(errorCode, typeName, [typeName.name]); 15834 reportErrorForNode(errorCode, typeName, [typeName.name]);
15879 } else if (_isTypeNameInTypeArgumentList(node)) { 15835 } else if (_isTypeNameInTypeArgumentList(node)) {
15880 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, type Name, [typeName.name]); 15836 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, type Name, [typeName.name]);
15881 } else { 15837 } else {
15882 reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeNam e.name]); 15838 reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeNam e.name]);
15883 } 15839 }
15884 elementValid = false; 15840 elementValid = false;
15885 } 15841 }
15886 if (!elementValid) { 15842 if (!elementValid) {
15887 if (element is MultiplyDefinedElement) { 15843 if (element is MultiplyDefinedElement) {
(...skipping 26 matching lines...) Expand all
15914 } else { 15870 } else {
15915 // The name does not represent a type. 15871 // The name does not represent a type.
15916 RedirectingConstructorKind redirectingConstructorKind; 15872 RedirectingConstructorKind redirectingConstructorKind;
15917 if (_isTypeNameInCatchClause(node)) { 15873 if (_isTypeNameInCatchClause(node)) {
15918 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeName.name]); 15874 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeName.name]);
15919 } else if (_isTypeNameInAsExpression(node)) { 15875 } else if (_isTypeNameInAsExpression(node)) {
15920 reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeNa me.name]); 15876 reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeNa me.name]);
15921 } else if (_isTypeNameInIsExpression(node)) { 15877 } else if (_isTypeNameInIsExpression(node)) {
15922 reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [type Name.name]); 15878 reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [type Name.name]);
15923 } else if ((redirectingConstructorKind = _getRedirectingConstructorKind(no de)) != null) { 15879 } else if ((redirectingConstructorKind = _getRedirectingConstructorKind(no de)) != null) {
15924 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 15880 ErrorCode errorCode = (redirectingConstructorKind == RedirectingConstruc torKind.CONST ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarningCode.R EDIRECT_TO_NON_CLASS) as ErrorCode;
15925 reportErrorForNode(errorCode, typeName, [typeName.name]); 15881 reportErrorForNode(errorCode, typeName, [typeName.name]);
15926 } else if (_isTypeNameInTypeArgumentList(node)) { 15882 } else if (_isTypeNameInTypeArgumentList(node)) {
15927 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, type Name, [typeName.name]); 15883 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, type Name, [typeName.name]);
15928 } else { 15884 } else {
15929 AstNode parent = typeName.parent; 15885 AstNode parent = typeName.parent;
15930 while (parent is TypeName) { 15886 while (parent is TypeName) {
15931 parent = parent.parent; 15887 parent = parent.parent;
15932 } 15888 }
15933 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) { 15889 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) {
15934 } else { 15890 } else {
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
16516 } 16472 }
16517 } 16473 }
16518 element.type = type; 16474 element.type = type;
16519 } 16475 }
16520 } 16476 }
16521 16477
16522 /** 16478 /**
16523 * Kind of the redirecting constructor. 16479 * Kind of the redirecting constructor.
16524 */ 16480 */
16525 class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> { 16481 class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> {
16526 static final RedirectingConstructorKind CONST = new RedirectingConstructorKind ('CONST', 0); 16482 static const RedirectingConstructorKind CONST = const RedirectingConstructorKi nd('CONST', 0);
16527 16483
16528 static final RedirectingConstructorKind NORMAL = new RedirectingConstructorKin d('NORMAL', 1); 16484 static const RedirectingConstructorKind NORMAL = const RedirectingConstructorK ind('NORMAL', 1);
16529 16485
16530 static final List<RedirectingConstructorKind> values = [CONST, NORMAL]; 16486 static const List<RedirectingConstructorKind> values = const [CONST, NORMAL];
16531 16487
16532 RedirectingConstructorKind(String name, int ordinal) : super(name, ordinal); 16488 const RedirectingConstructorKind(String name, int ordinal) : super(name, ordin al);
16533 } 16489 }
16534 16490
16535 class UnifyingAstVisitor_TypeResolverVisitor_visitClassDeclarationInScope extend s UnifyingAstVisitor<Object> { 16491 class UnifyingAstVisitor_TypeResolverVisitor_visitClassDeclarationInScope extend s UnifyingAstVisitor<Object> {
16536 final TypeResolverVisitor TypeResolverVisitor_this; 16492 final TypeResolverVisitor TypeResolverVisitor_this;
16537 16493
16538 List<ClassMember> nonFields; 16494 List<ClassMember> nonFields;
16539 16495
16540 UnifyingAstVisitor_TypeResolverVisitor_visitClassDeclarationInScope(this.TypeR esolverVisitor_this, this.nonFields) : super(); 16496 UnifyingAstVisitor_TypeResolverVisitor_visitClassDeclarationInScope(this.TypeR esolverVisitor_this, this.nonFields) : super();
16541 16497
16542 @override 16498 @override
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
16645 if (parent is Label) { 16601 if (parent is Label) {
16646 return null; 16602 return null;
16647 } 16603 }
16648 // Prepare VariableElement. 16604 // Prepare VariableElement.
16649 Element element = nameScope.lookup(node, definingLibrary); 16605 Element element = nameScope.lookup(node, definingLibrary);
16650 if (element is! VariableElement) { 16606 if (element is! VariableElement) {
16651 return null; 16607 return null;
16652 } 16608 }
16653 // Must be local or parameter. 16609 // Must be local or parameter.
16654 ElementKind kind = element.kind; 16610 ElementKind kind = element.kind;
16655 if (identical(kind, ElementKind.LOCAL_VARIABLE)) { 16611 if (kind == ElementKind.LOCAL_VARIABLE) {
16656 node.staticElement = element; 16612 node.staticElement = element;
16657 if (node.inSetterContext()) { 16613 if (node.inSetterContext()) {
16658 LocalVariableElementImpl variableImpl = element as LocalVariableElementI mpl; 16614 LocalVariableElementImpl variableImpl = element as LocalVariableElementI mpl;
16659 variableImpl.markPotentiallyMutatedInScope(); 16615 variableImpl.markPotentiallyMutatedInScope();
16660 if (element.enclosingElement != _enclosingFunction) { 16616 if (element.enclosingElement != _enclosingFunction) {
16661 variableImpl.markPotentiallyMutatedInClosure(); 16617 variableImpl.markPotentiallyMutatedInClosure();
16662 } 16618 }
16663 } 16619 }
16664 } else if (identical(kind, ElementKind.PARAMETER)) { 16620 } else if (kind == ElementKind.PARAMETER) {
16665 node.staticElement = element; 16621 node.staticElement = element;
16666 if (node.inSetterContext()) { 16622 if (node.inSetterContext()) {
16667 ParameterElementImpl parameterImpl = element as ParameterElementImpl; 16623 ParameterElementImpl parameterImpl = element as ParameterElementImpl;
16668 parameterImpl.markPotentiallyMutatedInScope(); 16624 parameterImpl.markPotentiallyMutatedInScope();
16669 // If we are in some closure, check if it is not the same as where varia ble is declared. 16625 // If we are in some closure, check if it is not the same as where varia ble is declared.
16670 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) { 16626 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) {
16671 parameterImpl.markPotentiallyMutatedInClosure(); 16627 parameterImpl.markPotentiallyMutatedInClosure();
16672 } 16628 }
16673 } 16629 }
16674 } 16630 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
16734 } 16690 }
16735 16691
16736 /** 16692 /**
16737 * Instances of the class `EnclosedScope` implement a scope that is lexically en closed in 16693 * Instances of the class `EnclosedScope` implement a scope that is lexically en closed in
16738 * another scope. 16694 * another scope.
16739 */ 16695 */
16740 class EnclosedScope extends Scope { 16696 class EnclosedScope extends Scope {
16741 /** 16697 /**
16742 * The scope in which this scope is lexically enclosed. 16698 * The scope in which this scope is lexically enclosed.
16743 */ 16699 */
16744 Scope enclosingScope; 16700 final Scope enclosingScope;
16745 16701
16746 /** 16702 /**
16747 * A table mapping names that will be defined in this scope, but right now are not initialized. 16703 * A table mapping names that will be defined in this scope, but right now are not initialized.
16748 * According to the scoping rules these names are hidden, even if they were de fined in an outer 16704 * According to the scoping rules these names are hidden, even if they were de fined in an outer
16749 * scope. 16705 * scope.
16750 */ 16706 */
16751 Map<String, Element> _hiddenElements = new Map<String, Element>(); 16707 Map<String, Element> _hiddenElements = new Map<String, Element>();
16752 16708
16753 /** 16709 /**
16754 * A flag indicating whether there are any names defined in this scope. 16710 * A flag indicating whether there are any names defined in this scope.
16755 */ 16711 */
16756 bool _hasHiddenName = false; 16712 bool _hasHiddenName = false;
16757 16713
16758 /** 16714 /**
16759 * Initialize a newly created scope enclosed within another scope. 16715 * Initialize a newly created scope enclosed within another scope.
16760 * 16716 *
16761 * @param enclosingScope the scope in which this scope is lexically enclosed 16717 * @param enclosingScope the scope in which this scope is lexically enclosed
16762 */ 16718 */
16763 EnclosedScope(Scope enclosingScope) { 16719 EnclosedScope(this.enclosingScope);
16764 this.enclosingScope = enclosingScope;
16765 }
16766 16720
16767 @override 16721 @override
16768 AnalysisErrorListener get errorListener => enclosingScope.errorListener; 16722 AnalysisErrorListener get errorListener => enclosingScope.errorListener;
16769 16723
16770 /** 16724 /**
16771 * Record that given element is declared in this scope, but hasn't been initia lized yet, so it is 16725 * Record that given element is declared in this scope, but hasn't been initia lized yet, so it is
16772 * error to use. If there is already an element with the given name defined in an outer scope, 16726 * error to use. If there is already an element with the given name defined in an outer scope,
16773 * then it will become unavailable. 16727 * then it will become unavailable.
16774 * 16728 *
16775 * @param element the element declared, but not initialized in this scope 16729 * @param element the element declared, but not initialized in this scope
(...skipping 24 matching lines...) Expand all
16800 } 16754 }
16801 // Check enclosing scope. 16755 // Check enclosing scope.
16802 return enclosingScope.internalLookup(identifier, name, referencingLibrary); 16756 return enclosingScope.internalLookup(identifier, name, referencingLibrary);
16803 } 16757 }
16804 } 16758 }
16805 16759
16806 /** 16760 /**
16807 * Instances of the class `FunctionScope` implement the scope defined by a funct ion. 16761 * Instances of the class `FunctionScope` implement the scope defined by a funct ion.
16808 */ 16762 */
16809 class FunctionScope extends EnclosedScope { 16763 class FunctionScope extends EnclosedScope {
16810 ExecutableElement _functionElement; 16764 final ExecutableElement _functionElement;
16811 16765
16812 bool _parametersDefined = false; 16766 bool _parametersDefined = false;
16813 16767
16814 /** 16768 /**
16815 * Initialize a newly created scope enclosed within another scope. 16769 * Initialize a newly created scope enclosed within another scope.
16816 * 16770 *
16817 * @param enclosingScope the scope in which this scope is lexically enclosed 16771 * @param enclosingScope the scope in which this scope is lexically enclosed
16818 * @param functionElement the element representing the type represented by thi s scope 16772 * @param functionElement the element representing the type represented by thi s scope
16819 */ 16773 */
16820 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) { 16774 FunctionScope(Scope enclosingScope, this._functionElement) : super(new Enclose dScope(enclosingScope)) {
16821 if (functionElement == null) { 16775 if (_functionElement == null) {
16822 throw new IllegalArgumentException("function element cannot be null"); 16776 throw new IllegalArgumentException("function element cannot be null");
16823 } 16777 }
16824 this._functionElement = functionElement;
16825 } 16778 }
16826 16779
16827 /** 16780 /**
16828 * Define the parameters for the given function in the scope that encloses thi s function. 16781 * Define the parameters for the given function in the scope that encloses thi s function.
16829 */ 16782 */
16830 void defineParameters() { 16783 void defineParameters() {
16831 if (_parametersDefined) { 16784 if (_parametersDefined) {
16832 return; 16785 return;
16833 } 16786 }
16834 _parametersDefined = true; 16787 _parametersDefined = true;
(...skipping 10 matching lines...) Expand all
16845 } 16798 }
16846 } 16799 }
16847 } 16800 }
16848 } 16801 }
16849 16802
16850 /** 16803 /**
16851 * Instances of the class `FunctionTypeScope` implement the scope defined by a f unction type 16804 * Instances of the class `FunctionTypeScope` implement the scope defined by a f unction type
16852 * alias. 16805 * alias.
16853 */ 16806 */
16854 class FunctionTypeScope extends EnclosedScope { 16807 class FunctionTypeScope extends EnclosedScope {
16855 FunctionTypeAliasElement _typeElement; 16808 final FunctionTypeAliasElement _typeElement;
16856 16809
16857 bool _parametersDefined = false; 16810 bool _parametersDefined = false;
16858 16811
16859 /** 16812 /**
16860 * Initialize a newly created scope enclosed within another scope. 16813 * Initialize a newly created scope enclosed within another scope.
16861 * 16814 *
16862 * @param enclosingScope the scope in which this scope is lexically enclosed 16815 * @param enclosingScope the scope in which this scope is lexically enclosed
16863 * @param typeElement the element representing the type alias represented by t his scope 16816 * @param typeElement the element representing the type alias represented by t his scope
16864 */ 16817 */
16865 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement) : super(new EnclosedScope(enclosingScope)) { 16818 FunctionTypeScope(Scope enclosingScope, this._typeElement) : super(new Enclose dScope(enclosingScope)) {
16866 this._typeElement = typeElement;
16867 _defineTypeParameters(); 16819 _defineTypeParameters();
16868 } 16820 }
16869 16821
16870 /** 16822 /**
16871 * Define the parameters for the function type alias. 16823 * Define the parameters for the function type alias.
16872 * 16824 *
16873 * @param typeElement the element representing the type represented by this sc ope 16825 * @param typeElement the element representing the type represented by this sc ope
16874 */ 16826 */
16875 void defineParameters() { 16827 void defineParameters() {
16876 if (_parametersDefined) { 16828 if (_parametersDefined) {
(...skipping 18 matching lines...) Expand all
16895 } 16847 }
16896 } 16848 }
16897 16849
16898 /** 16850 /**
16899 * Instances of the class `LabelScope` represent a scope in which a single label is defined. 16851 * Instances of the class `LabelScope` represent a scope in which a single label is defined.
16900 */ 16852 */
16901 class LabelScope { 16853 class LabelScope {
16902 /** 16854 /**
16903 * The label scope enclosing this label scope. 16855 * The label scope enclosing this label scope.
16904 */ 16856 */
16905 LabelScope _outerScope; 16857 final LabelScope _outerScope;
16906 16858
16907 /** 16859 /**
16908 * The label defined in this scope. 16860 * The label defined in this scope.
16909 */ 16861 */
16910 String _label; 16862 final String _label;
16911 16863
16912 /** 16864 /**
16913 * The element to which the label resolves. 16865 * The element to which the label resolves.
16914 */ 16866 */
16915 LabelElement _element; 16867 final LabelElement _element;
16916 16868
16917 /** 16869 /**
16918 * The marker used to look up a label element for an unlabeled `break` or `con tinue`. 16870 * The marker used to look up a label element for an unlabeled `break` or `con tinue`.
16919 */ 16871 */
16920 static String EMPTY_LABEL = ""; 16872 static String EMPTY_LABEL = "";
16921 16873
16922 /** 16874 /**
16923 * The label element returned for scopes that can be the target of an unlabele d `break` or 16875 * The label element returned for scopes that can be the target of an unlabele d `break` or
16924 * `continue`. 16876 * `continue`.
16925 */ 16877 */
(...skipping 10 matching lines...) Expand all
16936 */ 16888 */
16937 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) : this.con2(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMPTY_LABEL_IDE NTIFIER, onSwitchStatement, onSwitchMember)); 16889 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) : this.con2(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMPTY_LABEL_IDE NTIFIER, onSwitchStatement, onSwitchMember));
16938 16890
16939 /** 16891 /**
16940 * Initialize a newly created scope to represent the given label. 16892 * Initialize a newly created scope to represent the given label.
16941 * 16893 *
16942 * @param outerScope the label scope enclosing the new label scope 16894 * @param outerScope the label scope enclosing the new label scope
16943 * @param label the label defined in this scope 16895 * @param label the label defined in this scope
16944 * @param element the element to which the label resolves 16896 * @param element the element to which the label resolves
16945 */ 16897 */
16946 LabelScope.con2(LabelScope outerScope, String label, LabelElement element) { 16898 LabelScope.con2(this._outerScope, this._label, this._element);
16947 this._outerScope = outerScope;
16948 this._label = label;
16949 this._element = element;
16950 }
16951 16899
16952 /** 16900 /**
16953 * Return the label element corresponding to the given label, or `null` if the given label 16901 * Return the label element corresponding to the given label, or `null` if the given label
16954 * is not defined in this scope. 16902 * is not defined in this scope.
16955 * 16903 *
16956 * @param targetLabel the label being looked up 16904 * @param targetLabel the label being looked up
16957 * @return the label element corresponding to the given label 16905 * @return the label element corresponding to the given label
16958 */ 16906 */
16959 LabelElement lookup(String targetLabel) { 16907 LabelElement lookup(String targetLabel) {
16960 if (_label == targetLabel) { 16908 if (_label == targetLabel) {
16961 return _element; 16909 return _element;
16962 } else if (_outerScope != null) { 16910 } else if (_outerScope != null) {
16963 return _outerScope.lookup(targetLabel); 16911 return _outerScope.lookup(targetLabel);
16964 } else { 16912 } else {
16965 return null; 16913 return null;
16966 } 16914 }
16967 } 16915 }
16968 } 16916 }
16969 16917
16970 /** 16918 /**
16971 * Instances of the class `LibraryImportScope` represent the scope containing al l of the names 16919 * Instances of the class `LibraryImportScope` represent the scope containing al l of the names
16972 * available from imported libraries. 16920 * available from imported libraries.
16973 */ 16921 */
16974 class LibraryImportScope extends Scope { 16922 class LibraryImportScope extends Scope {
16975 /** 16923 /**
16976 * The element representing the library in which this scope is enclosed. 16924 * The element representing the library in which this scope is enclosed.
16977 */ 16925 */
16978 LibraryElement _definingLibrary; 16926 final LibraryElement _definingLibrary;
16979 16927
16980 /** 16928 /**
16981 * The listener that is to be informed when an error is encountered. 16929 * The listener that is to be informed when an error is encountered.
16982 */ 16930 */
16983 AnalysisErrorListener errorListener; 16931 final AnalysisErrorListener errorListener;
16984 16932
16985 /** 16933 /**
16986 * A list of the namespaces representing the names that are available in this scope from imported 16934 * A list of the namespaces representing the names that are available in this scope from imported
16987 * libraries. 16935 * libraries.
16988 */ 16936 */
16989 List<Namespace> _importedNamespaces; 16937 List<Namespace> _importedNamespaces;
16990 16938
16991 /** 16939 /**
16992 * Initialize a newly created scope representing the names imported into the g iven library. 16940 * Initialize a newly created scope representing the names imported into the g iven library.
16993 * 16941 *
16994 * @param definingLibrary the element representing the library that imports th e names defined in 16942 * @param definingLibrary the element representing the library that imports th e names defined in
16995 * this scope 16943 * this scope
16996 * @param errorListener the listener that is to be informed when an error is e ncountered 16944 * @param errorListener the listener that is to be informed when an error is e ncountered
16997 */ 16945 */
16998 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error Listener) { 16946 LibraryImportScope(this._definingLibrary, this.errorListener) {
16999 this._definingLibrary = definingLibrary; 16947 _createImportedNamespaces(_definingLibrary);
17000 this.errorListener = errorListener;
17001 _createImportedNamespaces(definingLibrary);
17002 } 16948 }
17003 16949
17004 @override 16950 @override
17005 void define(Element element) { 16951 void define(Element element) {
17006 if (!Scope.isPrivateName(element.displayName)) { 16952 if (!Scope.isPrivateName(element.displayName)) {
17007 super.define(element); 16953 super.define(element);
17008 } 16954 }
17009 } 16955 }
17010 16956
17011 @override 16957 @override
17012 Element internalLookup(Identifier identifier, String name, LibraryElement refe rencingLibrary) { 16958 Element internalLookup(Identifier identifier, String name, LibraryElement refe rencingLibrary) {
17013 Element foundElement = localLookup(name, referencingLibrary); 16959 Element foundElement = localLookup(name, referencingLibrary);
17014 if (foundElement != null) { 16960 if (foundElement != null) {
17015 return foundElement; 16961 return foundElement;
17016 } 16962 }
17017 for (Namespace nameSpace in _importedNamespaces) { 16963 for (Namespace nameSpace in _importedNamespaces) {
17018 Element element = nameSpace.get(name); 16964 Element element = nameSpace.get(name);
17019 if (element != null) { 16965 if (element != null) {
17020 if (foundElement == null) { 16966 if (foundElement == null) {
17021 foundElement = element; 16967 foundElement = element;
17022 } else if (foundElement != element) { 16968 } else if (!identical(foundElement, element)) {
17023 foundElement = MultiplyDefinedElementImpl.fromElements(_definingLibrar y.context, foundElement, element); 16969 foundElement = MultiplyDefinedElementImpl.fromElements(_definingLibrar y.context, foundElement, element);
17024 } 16970 }
17025 } 16971 }
17026 } 16972 }
17027 if (foundElement is MultiplyDefinedElementImpl) { 16973 if (foundElement is MultiplyDefinedElementImpl) {
17028 foundElement = _removeSdkElements(identifier, name, foundElement as Multip lyDefinedElementImpl); 16974 foundElement = _removeSdkElements(identifier, name, foundElement as Multip lyDefinedElementImpl);
17029 } 16975 }
17030 if (foundElement is MultiplyDefinedElementImpl) { 16976 if (foundElement is MultiplyDefinedElementImpl) {
17031 String foundEltName = foundElement.displayName; 16977 String foundEltName = foundElement.displayName;
17032 List<Element> conflictingMembers = (foundElement as MultiplyDefinedElement Impl).conflictingElements; 16978 List<Element> conflictingMembers = (foundElement as MultiplyDefinedElement Impl).conflictingElements;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
17194 17140
17195 /** 17141 /**
17196 * Instances of the class `Namespace` implement a mapping of identifiers to the elements 17142 * Instances of the class `Namespace` implement a mapping of identifiers to the elements
17197 * represented by those identifiers. Namespaces are the building blocks for scop es. 17143 * represented by those identifiers. Namespaces are the building blocks for scop es.
17198 */ 17144 */
17199 class Namespace { 17145 class Namespace {
17200 /** 17146 /**
17201 * A table mapping names that are defined in this namespace to the element rep resenting the thing 17147 * A table mapping names that are defined in this namespace to the element rep resenting the thing
17202 * declared with that name. 17148 * declared with that name.
17203 */ 17149 */
17204 Map<String, Element> _definedNames; 17150 final Map<String, Element> _definedNames;
17205 17151
17206 /** 17152 /**
17207 * An empty namespace. 17153 * An empty namespace.
17208 */ 17154 */
17209 static Namespace EMPTY = new Namespace(new Map<String, Element>()); 17155 static Namespace EMPTY = new Namespace(new Map<String, Element>());
17210 17156
17211 /** 17157 /**
17212 * Initialize a newly created namespace to have the given defined names. 17158 * Initialize a newly created namespace to have the given defined names.
17213 * 17159 *
17214 * @param definedNames the mapping from names that are defined in this namespa ce to the 17160 * @param definedNames the mapping from names that are defined in this namespa ce to the
17215 * corresponding elements 17161 * corresponding elements
17216 */ 17162 */
17217 Namespace(Map<String, Element> definedNames) { 17163 Namespace(this._definedNames);
17218 this._definedNames = definedNames;
17219 }
17220 17164
17221 /** 17165 /**
17222 * Return the element in this namespace that is available to the containing sc ope using the given 17166 * Return the element in this namespace that is available to the containing sc ope using the given
17223 * name. 17167 * name.
17224 * 17168 *
17225 * @param name the name used to reference the 17169 * @param name the name used to reference the
17226 * @return the element represented by the given identifier 17170 * @return the element represented by the given identifier
17227 */ 17171 */
17228 Element get(String name) => _definedNames[name]; 17172 Element get(String name) => _definedNames[name];
17229 17173
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
17682 if (parent == null) { 17626 if (parent == null) {
17683 throw new AnalysisException.con1("Cannot create scope: node is not part of a CompilationUnit"); 17627 throw new AnalysisException.con1("Cannot create scope: node is not part of a CompilationUnit");
17684 } 17628 }
17685 ScopeBuilder builder = new ScopeBuilder(errorListener); 17629 ScopeBuilder builder = new ScopeBuilder(errorListener);
17686 return builder._scopeForAstNode(parent); 17630 return builder._scopeForAstNode(parent);
17687 } 17631 }
17688 17632
17689 /** 17633 /**
17690 * The listener to which analysis errors will be reported. 17634 * The listener to which analysis errors will be reported.
17691 */ 17635 */
17692 AnalysisErrorListener _errorListener; 17636 final AnalysisErrorListener _errorListener;
17693 17637
17694 /** 17638 /**
17695 * Initialize a newly created scope builder to generate a scope that will repo rt errors to the 17639 * Initialize a newly created scope builder to generate a scope that will repo rt errors to the
17696 * given listener. 17640 * given listener.
17697 * 17641 *
17698 * @param errorListener the listener to which analysis errors will be reported 17642 * @param errorListener the listener to which analysis errors will be reported
17699 */ 17643 */
17700 ScopeBuilder(AnalysisErrorListener errorListener) { 17644 ScopeBuilder(this._errorListener);
17701 this._errorListener = errorListener;
17702 }
17703 17645
17704 /** 17646 /**
17705 * Return the scope in which the given AST structure should be resolved. 17647 * Return the scope in which the given AST structure should be resolved.
17706 * 17648 *
17707 * <b>Note:</b> This method needs to be kept in sync with 17649 * <b>Note:</b> This method needs to be kept in sync with
17708 * [IncrementalResolver#canBeResolved]. 17650 * [IncrementalResolver#canBeResolved].
17709 * 17651 *
17710 * @param node the root of the AST structure to be resolved 17652 * @param node the root of the AST structure to be resolved
17711 * @return the scope in which the given AST structure should be resolved 17653 * @return the scope in which the given AST structure should be resolved
17712 * @throws AnalysisException if the AST structure has not been resolved or is not part of a 17654 * @throws AnalysisException if the AST structure has not been resolved or is not part of a
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
17778 17720
17779 /** 17721 /**
17780 * Instances of the class `ConstantVerifier` traverse an AST structure looking f or additional 17722 * Instances of the class `ConstantVerifier` traverse an AST structure looking f or additional
17781 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors 17723 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors
17782 * and warnings related to constant expressions. 17724 * and warnings related to constant expressions.
17783 */ 17725 */
17784 class ConstantVerifier extends RecursiveAstVisitor<Object> { 17726 class ConstantVerifier extends RecursiveAstVisitor<Object> {
17785 /** 17727 /**
17786 * The error reporter by which errors will be reported. 17728 * The error reporter by which errors will be reported.
17787 */ 17729 */
17788 ErrorReporter _errorReporter; 17730 final ErrorReporter _errorReporter;
17789 17731
17790 /** 17732 /**
17791 * The type provider used to access the known types. 17733 * The type provider used to access the known types.
17792 */ 17734 */
17793 TypeProvider _typeProvider; 17735 final TypeProvider _typeProvider;
17794 17736
17795 /** 17737 /**
17796 * The type representing the type 'bool'. 17738 * The type representing the type 'bool'.
17797 */ 17739 */
17798 InterfaceType _boolType; 17740 InterfaceType _boolType;
17799 17741
17800 /** 17742 /**
17801 * The type representing the type 'int'. 17743 * The type representing the type 'int'.
17802 */ 17744 */
17803 InterfaceType _intType; 17745 InterfaceType _intType;
17804 17746
17805 /** 17747 /**
17806 * The type representing the type 'num'. 17748 * The type representing the type 'num'.
17807 */ 17749 */
17808 InterfaceType _numType; 17750 InterfaceType _numType;
17809 17751
17810 /** 17752 /**
17811 * The type representing the type 'string'. 17753 * The type representing the type 'string'.
17812 */ 17754 */
17813 InterfaceType _stringType; 17755 InterfaceType _stringType;
17814 17756
17815 /** 17757 /**
17816 * Initialize a newly created constant verifier. 17758 * Initialize a newly created constant verifier.
17817 * 17759 *
17818 * @param errorReporter the error reporter by which errors will be reported 17760 * @param errorReporter the error reporter by which errors will be reported
17819 */ 17761 */
17820 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) { 17762 ConstantVerifier(this._errorReporter, this._typeProvider) {
17821 this._errorReporter = errorReporter; 17763 this._boolType = _typeProvider.boolType;
17822 this._typeProvider = typeProvider; 17764 this._intType = _typeProvider.intType;
17823 this._boolType = typeProvider.boolType; 17765 this._numType = _typeProvider.numType;
17824 this._intType = typeProvider.intType; 17766 this._stringType = _typeProvider.stringType;
17825 this._numType = typeProvider.numType;
17826 this._stringType = typeProvider.stringType;
17827 } 17767 }
17828 17768
17829 @override 17769 @override
17830 Object visitAnnotation(Annotation node) { 17770 Object visitAnnotation(Annotation node) {
17831 super.visitAnnotation(node); 17771 super.visitAnnotation(node);
17832 // check annotation creation 17772 // check annotation creation
17833 Element element = node.element; 17773 Element element = node.element;
17834 if (element is ConstructorElement) { 17774 if (element is ConstructorElement) {
17835 ConstructorElement constructorElement = element; 17775 ConstructorElement constructorElement = element;
17836 // should 'const' constructor 17776 // should 'const' constructor
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
18141 } 18081 }
18142 18082
18143 /** 18083 /**
18144 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional 18084 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional
18145 * errors and warnings not covered by the parser and resolver. 18085 * errors and warnings not covered by the parser and resolver.
18146 */ 18086 */
18147 class ErrorVerifier extends RecursiveAstVisitor<Object> { 18087 class ErrorVerifier extends RecursiveAstVisitor<Object> {
18148 /** 18088 /**
18149 * The error reporter by which errors will be reported. 18089 * The error reporter by which errors will be reported.
18150 */ 18090 */
18151 ErrorReporter _errorReporter; 18091 final ErrorReporter _errorReporter;
18152 18092
18153 /** 18093 /**
18154 * The current library that is being analyzed. 18094 * The current library that is being analyzed.
18155 */ 18095 */
18156 LibraryElement _currentLibrary; 18096 final LibraryElement _currentLibrary;
18157 18097
18158 /** 18098 /**
18159 * The type representing the type 'dynamic'. 18099 * The type representing the type 'dynamic'.
18160 */ 18100 */
18161 DartType _dynamicType; 18101 DartType _dynamicType;
18162 18102
18163 /** 18103 /**
18164 * The type representing the type 'bool'. 18104 * The type representing the type 'bool'.
18165 */ 18105 */
18166 InterfaceType _boolType; 18106 InterfaceType _boolType;
18167 18107
18168 /** 18108 /**
18169 * The type representing the type 'int'. 18109 * The type representing the type 'int'.
18170 */ 18110 */
18171 InterfaceType _intType; 18111 InterfaceType _intType;
18172 18112
18173 /** 18113 /**
18174 * The object providing access to the types defined by the language. 18114 * The object providing access to the types defined by the language.
18175 */ 18115 */
18176 TypeProvider _typeProvider; 18116 final TypeProvider _typeProvider;
18177 18117
18178 /** 18118 /**
18179 * The manager for the inheritance mappings. 18119 * The manager for the inheritance mappings.
18180 */ 18120 */
18181 InheritanceManager _inheritanceManager; 18121 final InheritanceManager _inheritanceManager;
18182 18122
18183 /** 18123 /**
18184 * This is set to `true` iff the visitor is currently visiting children nodes of a 18124 * This is set to `true` iff the visitor is currently visiting children nodes of a
18185 * [ConstructorDeclaration] and the constructor is 'const'. 18125 * [ConstructorDeclaration] and the constructor is 'const'.
18186 * 18126 *
18187 * @see #visitConstructorDeclaration(ConstructorDeclaration) 18127 * @see #visitConstructorDeclaration(ConstructorDeclaration)
18188 */ 18128 */
18189 bool _isEnclosingConstructorConst = false; 18129 bool _isEnclosingConstructorConst = false;
18190 18130
18191 /** 18131 /**
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
18256 */ 18196 */
18257 bool _isInSystemLibrary = false; 18197 bool _isInSystemLibrary = false;
18258 18198
18259 /** 18199 /**
18260 * A flag indicating whether the current library contains at least one import directive with a URI 18200 * A flag indicating whether the current library contains at least one import directive with a URI
18261 * that uses the "dart-ext" scheme. 18201 * that uses the "dart-ext" scheme.
18262 */ 18202 */
18263 bool _hasExtUri = false; 18203 bool _hasExtUri = false;
18264 18204
18265 /** 18205 /**
18206 * This is set to `false` on the entry of every [BlockFunctionBody], and is re stored
18207 * to the enclosing value on exit. The value is used in
18208 * [checkForMixedReturns] to prevent both
18209 * [StaticWarningCode#MIXED_RETURN_TYPES] and [StaticWarningCode#RETURN_WITHOU T_VALUE]
18210 * from being generated in the same function body.
18211 */
18212 bool _hasReturnWithoutValue = false;
18213
18214 /**
18266 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of 18215 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
18267 * a class. 18216 * a class.
18268 */ 18217 */
18269 ClassElement _enclosingClass; 18218 ClassElement _enclosingClass;
18270 18219
18271 /** 18220 /**
18272 * The method or function that we are currently visiting, or `null` if we are not inside a 18221 * The method or function that we are currently visiting, or `null` if we are not inside a
18273 * method or function. 18222 * method or function.
18274 */ 18223 */
18275 ExecutableElement _enclosingFunction; 18224 ExecutableElement _enclosingFunction;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
18321 * A set of the names of the variable initializers we are visiting now. 18270 * A set of the names of the variable initializers we are visiting now.
18322 */ 18271 */
18323 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String >(); 18272 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String >();
18324 18273
18325 /** 18274 /**
18326 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS] and 18275 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS] and
18327 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. 18276 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes.
18328 */ 18277 */
18329 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 18278 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
18330 18279
18331 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider, InheritanceManager inheritanceManager) { 18280 /**
18332 this._errorReporter = errorReporter; 18281 * Static final string with value `"getter "` used in the construction of the
18333 this._currentLibrary = currentLibrary; 18282 * [StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], and si milar, error
18334 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; 18283 * code messages.
18335 this._hasExtUri = currentLibrary.hasExtUri; 18284 *
18336 this._typeProvider = typeProvider; 18285 * @see #checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration)
18337 this._inheritanceManager = inheritanceManager; 18286 */
18287 static String _GETTER_SPACE = "getter ";
18288
18289 /**
18290 * Static final string with value `"setter "` used in the construction of the
18291 * [StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE], and si milar, error
18292 * code messages.
18293 *
18294 * @see #checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration)
18295 */
18296 static String _SETTER_SPACE = "setter ";
18297
18298 /**
18299 * Initialize the [ErrorVerifier] visitor.
18300 */
18301 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, t his._inheritanceManager) {
18302 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary;
18303 this._hasExtUri = _currentLibrary.hasExtUri;
18338 _isEnclosingConstructorConst = false; 18304 _isEnclosingConstructorConst = false;
18339 _isInCatchClause = false; 18305 _isInCatchClause = false;
18340 _isInStaticVariableDeclaration = false; 18306 _isInStaticVariableDeclaration = false;
18341 _isInInstanceVariableDeclaration = false; 18307 _isInInstanceVariableDeclaration = false;
18342 _isInInstanceVariableInitializer = false; 18308 _isInInstanceVariableInitializer = false;
18343 _isInConstructorInitializer = false; 18309 _isInConstructorInitializer = false;
18344 _isInStaticMethod = false; 18310 _isInStaticMethod = false;
18345 _boolType = typeProvider.boolType; 18311 _dynamicType = _typeProvider.dynamicType;
18346 _intType = typeProvider.intType; 18312 _boolType = _typeProvider.boolType;
18347 _dynamicType = typeProvider.dynamicType; 18313 _intType = _typeProvider.intType;
18348 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ 18314 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [
18349 typeProvider.nullType, 18315 _typeProvider.nullType,
18350 typeProvider.numType, 18316 _typeProvider.numType,
18351 _intType, 18317 _intType,
18352 typeProvider.doubleType, 18318 _typeProvider.doubleType,
18353 _boolType, 18319 _boolType,
18354 typeProvider.stringType]; 18320 _typeProvider.stringType];
18355 } 18321 }
18356 18322
18357 @override 18323 @override
18358 Object visitArgumentList(ArgumentList node) { 18324 Object visitArgumentList(ArgumentList node) {
18359 _checkForArgumentTypesNotAssignableInList(node); 18325 _checkForArgumentTypesNotAssignableInList(node);
18360 return super.visitArgumentList(node); 18326 return super.visitArgumentList(node);
18361 } 18327 }
18362 18328
18363 @override 18329 @override
18364 Object visitAssertStatement(AssertStatement node) { 18330 Object visitAssertStatement(AssertStatement node) {
18365 _checkForNonBoolExpression(node); 18331 _checkForNonBoolExpression(node);
18366 return super.visitAssertStatement(node); 18332 return super.visitAssertStatement(node);
18367 } 18333 }
18368 18334
18369 @override 18335 @override
18370 Object visitAssignmentExpression(AssignmentExpression node) { 18336 Object visitAssignmentExpression(AssignmentExpression node) {
18371 sc.Token operator = node.operator; 18337 sc.Token operator = node.operator;
18372 sc.TokenType operatorType = operator.type; 18338 sc.TokenType operatorType = operator.type;
18373 if (identical(operatorType, sc.TokenType.EQ)) { 18339 if (operatorType == sc.TokenType.EQ) {
18374 _checkForInvalidAssignment(node.leftHandSide, node.rightHandSide); 18340 _checkForInvalidAssignment(node.leftHandSide, node.rightHandSide);
18375 } else { 18341 } else {
18376 _checkForInvalidCompoundAssignment(node); 18342 _checkForInvalidCompoundAssignment(node);
18377 } 18343 }
18378 _checkForAssignmentToFinal(node.leftHandSide); 18344 _checkForAssignmentToFinal(node.leftHandSide);
18379 _checkForArgumentTypeNotAssignableForArgument(node.rightHandSide); 18345 _checkForArgumentTypeNotAssignableForArgument(node.rightHandSide);
18380 return super.visitAssignmentExpression(node); 18346 return super.visitAssignmentExpression(node);
18381 } 18347 }
18382 18348
18383 @override 18349 @override
18384 Object visitBinaryExpression(BinaryExpression node) { 18350 Object visitBinaryExpression(BinaryExpression node) {
18385 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand); 18351 _checkForArgumentTypeNotAssignableForArgument(node.rightOperand);
18386 return super.visitBinaryExpression(node); 18352 return super.visitBinaryExpression(node);
18387 } 18353 }
18388 18354
18389 @override 18355 @override
18390 Object visitBlockFunctionBody(BlockFunctionBody node) { 18356 Object visitBlockFunctionBody(BlockFunctionBody node) {
18357 bool previousHasReturnWithoutValue = _hasReturnWithoutValue;
18358 _hasReturnWithoutValue = false;
18391 List<ReturnStatement> previousReturnsWith = _returnsWith; 18359 List<ReturnStatement> previousReturnsWith = _returnsWith;
18392 List<ReturnStatement> previousReturnsWithout = _returnsWithout; 18360 List<ReturnStatement> previousReturnsWithout = _returnsWithout;
18393 try { 18361 try {
18394 _returnsWith = new List<ReturnStatement>(); 18362 _returnsWith = new List<ReturnStatement>();
18395 _returnsWithout = new List<ReturnStatement>(); 18363 _returnsWithout = new List<ReturnStatement>();
18396 super.visitBlockFunctionBody(node); 18364 super.visitBlockFunctionBody(node);
18397 _checkForMixedReturns(node); 18365 _checkForMixedReturns(node);
18398 } finally { 18366 } finally {
18399 _returnsWith = previousReturnsWith; 18367 _returnsWith = previousReturnsWith;
18400 _returnsWithout = previousReturnsWithout; 18368 _returnsWithout = previousReturnsWithout;
18369 _hasReturnWithoutValue = previousHasReturnWithoutValue;
18401 } 18370 }
18402 return null; 18371 return null;
18403 } 18372 }
18404 18373
18405 @override 18374 @override
18406 Object visitBreakStatement(BreakStatement node) { 18375 Object visitBreakStatement(BreakStatement node) {
18407 SimpleIdentifier labelNode = node.label; 18376 SimpleIdentifier labelNode = node.label;
18408 if (labelNode != null) { 18377 if (labelNode != null) {
18409 Element labelElement = labelNode.staticElement; 18378 Element labelElement = labelNode.staticElement;
18410 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) { 18379 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
18778 _enclosingFunction = node.element; 18747 _enclosingFunction = node.element;
18779 SimpleIdentifier identifier = node.name; 18748 SimpleIdentifier identifier = node.name;
18780 String methodName = ""; 18749 String methodName = "";
18781 if (identifier != null) { 18750 if (identifier != null) {
18782 methodName = identifier.name; 18751 methodName = identifier.name;
18783 } 18752 }
18784 if (node.isSetter || node.isGetter) { 18753 if (node.isSetter || node.isGetter) {
18785 _checkForMismatchedAccessorTypes(node, methodName); 18754 _checkForMismatchedAccessorTypes(node, methodName);
18786 } 18755 }
18787 if (node.isGetter) { 18756 if (node.isGetter) {
18757 _checkForVoidReturnType(node);
18788 _checkForConflictingStaticGetterAndInstanceSetter(node); 18758 _checkForConflictingStaticGetterAndInstanceSetter(node);
18789 } else if (node.isSetter) { 18759 } else if (node.isSetter) {
18790 _checkForWrongNumberOfParametersForSetter(node.name, node.parameters); 18760 _checkForWrongNumberOfParametersForSetter(node.name, node.parameters);
18791 _checkForNonVoidReturnTypeForSetter(node.returnType); 18761 _checkForNonVoidReturnTypeForSetter(node.returnType);
18792 _checkForConflictingStaticSetterAndInstanceMember(node); 18762 _checkForConflictingStaticSetterAndInstanceMember(node);
18793 } else if (node.isOperator) { 18763 } else if (node.isOperator) {
18794 _checkForOptionalParameterInOperator(node); 18764 _checkForOptionalParameterInOperator(node);
18795 _checkForWrongNumberOfParametersForOperator(node); 18765 _checkForWrongNumberOfParametersForOperator(node);
18796 _checkForNonVoidReturnTypeForOperator(node); 18766 _checkForNonVoidReturnTypeForOperator(node);
18797 } 18767 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
18848 _checkForStaticAccessToInstanceMember(typeReference, name); 18818 _checkForStaticAccessToInstanceMember(typeReference, name);
18849 _checkForInstanceAccessToStaticMember(typeReference, name); 18819 _checkForInstanceAccessToStaticMember(typeReference, name);
18850 } 18820 }
18851 return super.visitPrefixedIdentifier(node); 18821 return super.visitPrefixedIdentifier(node);
18852 } 18822 }
18853 18823
18854 @override 18824 @override
18855 Object visitPrefixExpression(PrefixExpression node) { 18825 Object visitPrefixExpression(PrefixExpression node) {
18856 sc.TokenType operatorType = node.operator.type; 18826 sc.TokenType operatorType = node.operator.type;
18857 Expression operand = node.operand; 18827 Expression operand = node.operand;
18858 if (identical(operatorType, sc.TokenType.BANG)) { 18828 if (operatorType == sc.TokenType.BANG) {
18859 _checkForNonBoolNegationExpression(operand); 18829 _checkForNonBoolNegationExpression(operand);
18860 } else if (operatorType.isIncrementOperator) { 18830 } else if (operatorType.isIncrementOperator) {
18861 _checkForAssignmentToFinal(operand); 18831 _checkForAssignmentToFinal(operand);
18862 } 18832 }
18863 _checkForIntNotAssignable(operand); 18833 _checkForIntNotAssignable(operand);
18864 return super.visitPrefixExpression(node); 18834 return super.visitPrefixExpression(node);
18865 } 18835 }
18866 18836
18867 @override 18837 @override
18868 Object visitPropertyAccess(PropertyAccess node) { 18838 Object visitPropertyAccess(PropertyAccess node) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
19050 // Visit all of the field formal parameters 19020 // Visit all of the field formal parameters
19051 NodeList<FormalParameter> formalParameters = node.parameters.parameters; 19021 NodeList<FormalParameter> formalParameters = node.parameters.parameters;
19052 for (FormalParameter formalParameter in formalParameters) { 19022 for (FormalParameter formalParameter in formalParameters) {
19053 FormalParameter parameter = formalParameter; 19023 FormalParameter parameter = formalParameter;
19054 if (parameter is DefaultFormalParameter) { 19024 if (parameter is DefaultFormalParameter) {
19055 parameter = (parameter as DefaultFormalParameter).parameter; 19025 parameter = (parameter as DefaultFormalParameter).parameter;
19056 } 19026 }
19057 if (parameter is FieldFormalParameter) { 19027 if (parameter is FieldFormalParameter) {
19058 FieldElement fieldElement = (parameter.element as FieldFormalParameterEl ementImpl).field; 19028 FieldElement fieldElement = (parameter.element as FieldFormalParameterEl ementImpl).field;
19059 INIT_STATE state = fieldElementsMap[fieldElement]; 19029 INIT_STATE state = fieldElementsMap[fieldElement];
19060 if (identical(state, INIT_STATE.NOT_INIT)) { 19030 if (state == INIT_STATE.NOT_INIT) {
19061 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; 19031 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL;
19062 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { 19032 } else if (state == INIT_STATE.INIT_IN_DECLARATION) {
19063 if (fieldElement.isFinal || fieldElement.isConst) { 19033 if (fieldElement.isFinal || fieldElement.isConst) {
19064 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_INITIALIZE D_IN_DECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.disp layName]); 19034 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_INITIALIZE D_IN_DECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.disp layName]);
19065 foundError = true; 19035 foundError = true;
19066 } 19036 }
19067 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { 19037 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) {
19068 if (fieldElement.isFinal || fieldElement.isConst) { 19038 if (fieldElement.isFinal || fieldElement.isConst) {
19069 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FINAL_INITIAL IZED_MULTIPLE_TIMES, formalParameter.identifier, [fieldElement.displayName]); 19039 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FINAL_INITIAL IZED_MULTIPLE_TIMES, formalParameter.identifier, [fieldElement.displayName]);
19070 foundError = true; 19040 foundError = true;
19071 } 19041 }
19072 } 19042 }
19073 } 19043 }
19074 } 19044 }
19075 // Visit all of the initializers 19045 // Visit all of the initializers
19076 NodeList<ConstructorInitializer> initializers = node.initializers; 19046 NodeList<ConstructorInitializer> initializers = node.initializers;
19077 for (ConstructorInitializer constructorInitializer in initializers) { 19047 for (ConstructorInitializer constructorInitializer in initializers) {
19078 if (constructorInitializer is RedirectingConstructorInvocation) { 19048 if (constructorInitializer is RedirectingConstructorInvocation) {
19079 return false; 19049 return false;
19080 } 19050 }
19081 if (constructorInitializer is ConstructorFieldInitializer) { 19051 if (constructorInitializer is ConstructorFieldInitializer) {
19082 ConstructorFieldInitializer constructorFieldInitializer = constructorIni tializer; 19052 ConstructorFieldInitializer constructorFieldInitializer = constructorIni tializer;
19083 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; 19053 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName;
19084 Element element = fieldName.staticElement; 19054 Element element = fieldName.staticElement;
19085 if (element is FieldElement) { 19055 if (element is FieldElement) {
19086 FieldElement fieldElement = element; 19056 FieldElement fieldElement = element;
19087 INIT_STATE state = fieldElementsMap[fieldElement]; 19057 INIT_STATE state = fieldElementsMap[fieldElement];
19088 if (identical(state, INIT_STATE.NOT_INIT)) { 19058 if (state == INIT_STATE.NOT_INIT) {
19089 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; 19059 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS;
19090 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { 19060 } else if (state == INIT_STATE.INIT_IN_DECLARATION) {
19091 if (fieldElement.isFinal || fieldElement.isConst) { 19061 if (fieldElement.isFinal || fieldElement.isConst) {
19092 _errorReporter.reportErrorForNode(StaticWarningCode.FIELD_INITIALI ZED_IN_INITIALIZER_AND_DECLARATION, fieldName, []); 19062 _errorReporter.reportErrorForNode(StaticWarningCode.FIELD_INITIALI ZED_IN_INITIALIZER_AND_DECLARATION, fieldName, []);
19093 foundError = true; 19063 foundError = true;
19094 } 19064 }
19095 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { 19065 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) {
19096 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_IN_PARAMETER_AND_INITIALIZER, fieldName, []); 19066 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_IN_PARAMETER_AND_INITIALIZER, fieldName, []);
19097 foundError = true; 19067 foundError = true;
19098 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { 19068 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) {
19099 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_BY_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); 19069 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_BY_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]);
19100 foundError = true; 19070 foundError = true;
19101 } 19071 }
19102 } 19072 }
19103 } 19073 }
19104 } 19074 }
19105 // Visit all of the states in the map to ensure that none were never initial ized. 19075 // Visit all of the states in the map to ensure that none were never initial ized.
19106 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement sMap)) { 19076 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement sMap)) {
19107 if (identical(entry.getValue(), INIT_STATE.NOT_INIT)) { 19077 if (entry.getValue() == INIT_STATE.NOT_INIT) {
19108 FieldElement fieldElement = entry.getKey(); 19078 FieldElement fieldElement = entry.getKey();
19109 if (fieldElement.isConst) { 19079 if (fieldElement.isConst) {
19110 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_NOT_INITI ALIZED, node.returnType, [fieldElement.name]); 19080 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_NOT_INITI ALIZED, node.returnType, [fieldElement.name]);
19111 foundError = true; 19081 foundError = true;
19112 } else if (fieldElement.isFinal) { 19082 } else if (fieldElement.isFinal) {
19113 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_NOT_INITIALI ZED, node.returnType, [fieldElement.name]); 19083 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_NOT_INITIALI ZED, node.returnType, [fieldElement.name]);
19114 foundError = true; 19084 foundError = true;
19115 } 19085 }
19116 } 19086 }
19117 } 19087 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
19287 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been created above if 19257 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been created above if
19288 // this could be reached. 19258 // this could be reached.
19289 continue; 19259 continue;
19290 } 19260 }
19291 if (!overriddenNamedPTEntry.getValue().isAssignableTo(overridingType)) { 19261 if (!overriddenNamedPTEntry.getValue().isAssignableTo(overridingType)) {
19292 // lookup the parameter for the error to select 19262 // lookup the parameter for the error to select
19293 ParameterElement parameterToSelect = null; 19263 ParameterElement parameterToSelect = null;
19294 AstNode parameterLocationToSelect = null; 19264 AstNode parameterLocationToSelect = null;
19295 for (int i = 0; i < parameters.length; i++) { 19265 for (int i = 0; i < parameters.length; i++) {
19296 ParameterElement parameter = parameters[i]; 19266 ParameterElement parameter = parameters[i];
19297 if (identical(parameter.parameterKind, ParameterKind.NAMED) && overrid denNamedPTEntry.getKey() == parameter.name) { 19267 if (parameter.parameterKind == ParameterKind.NAMED && overriddenNamedP TEntry.getKey() == parameter.name) {
19298 parameterToSelect = parameter; 19268 parameterToSelect = parameter;
19299 parameterLocationToSelect = parameterLocations[i]; 19269 parameterLocationToSelect = parameterLocations[i];
19300 break; 19270 break;
19301 } 19271 }
19302 } 19272 }
19303 if (parameterToSelect != null) { 19273 if (parameterToSelect != null) {
19304 _errorReporter.reportErrorForNode(StaticWarningCode.INVALID_METHOD_OVE RRIDE_NAMED_PARAM_TYPE, parameterLocationToSelect, [ 19274 _errorReporter.reportErrorForNode(StaticWarningCode.INVALID_METHOD_OVE RRIDE_NAMED_PARAM_TYPE, parameterLocationToSelect, [
19305 overridingType.displayName, 19275 overridingType.displayName,
19306 overriddenNamedPTEntry.getValue().displayName, 19276 overriddenNamedPTEntry.getValue().displayName,
19307 overriddenExecutable.enclosingElement.displayName]); 19277 overriddenExecutable.enclosingElement.displayName]);
(...skipping 24 matching lines...) Expand all
19332 if (parameterElt is ParameterElementImpl) { 19302 if (parameterElt is ParameterElementImpl) {
19333 overriddenParameterElts.add(parameterElt); 19303 overriddenParameterElts.add(parameterElt);
19334 } 19304 }
19335 } 19305 }
19336 } 19306 }
19337 // 19307 //
19338 // Next compare the list of optional parameter elements to the list of overr idden optional 19308 // Next compare the list of optional parameter elements to the list of overr idden optional
19339 // parameter elements. 19309 // parameter elements.
19340 // 19310 //
19341 if (parameterElts.length > 0) { 19311 if (parameterElts.length > 0) {
19342 if (identical(parameterElts[0].parameterKind, ParameterKind.NAMED)) { 19312 if (parameterElts[0].parameterKind == ParameterKind.NAMED) {
19343 // Named parameters, consider the names when matching the parameterElts to the overriddenParameterElts 19313 // Named parameters, consider the names when matching the parameterElts to the overriddenParameterElts
19344 for (int i = 0; i < parameterElts.length; i++) { 19314 for (int i = 0; i < parameterElts.length; i++) {
19345 ParameterElementImpl parameterElt = parameterElts[i]; 19315 ParameterElementImpl parameterElt = parameterElts[i];
19346 EvaluationResultImpl result = parameterElt.evaluationResult; 19316 EvaluationResultImpl result = parameterElt.evaluationResult;
19347 // TODO (jwren) Ignore Object types, see Dart bug 11287 19317 // TODO (jwren) Ignore Object types, see Dart bug 11287
19348 if (_isUserDefinedObject(result)) { 19318 if (_isUserDefinedObject(result)) {
19349 continue; 19319 continue;
19350 } 19320 }
19351 String parameterName = parameterElt.name; 19321 String parameterName = parameterElt.name;
19352 for (int j = 0; j < overriddenParameterElts.length; j++) { 19322 for (int j = 0; j < overriddenParameterElts.length; j++) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
19607 return false; 19577 return false;
19608 } 19578 }
19609 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIV E_CONSTRUCTOR, returnExpression, []); 19579 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIV E_CONSTRUCTOR, returnExpression, []);
19610 return true; 19580 return true;
19611 } 19581 }
19612 // RETURN_WITHOUT_VALUE 19582 // RETURN_WITHOUT_VALUE
19613 if (returnExpression == null) { 19583 if (returnExpression == null) {
19614 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { 19584 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) {
19615 return false; 19585 return false;
19616 } 19586 }
19587 _hasReturnWithoutValue = true;
19617 _errorReporter.reportErrorForNode(StaticWarningCode.RETURN_WITHOUT_VALUE, node, []); 19588 _errorReporter.reportErrorForNode(StaticWarningCode.RETURN_WITHOUT_VALUE, node, []);
19618 return true; 19589 return true;
19619 } 19590 }
19620 // RETURN_OF_INVALID_TYPE 19591 // RETURN_OF_INVALID_TYPE
19621 return _checkForReturnOfInvalidType(returnExpression, expectedReturnType); 19592 return _checkForReturnOfInvalidType(returnExpression, expectedReturnType);
19622 } 19593 }
19623 19594
19624 /** 19595 /**
19625 * This verifies that the export namespace of the passed export directive does not export any name 19596 * This verifies that the export namespace of the passed export directive does not export any name
19626 * already exported by other export directive. 19597 * already exported by other export directive.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
19755 * 19726 *
19756 * @param node the expression to evaluate 19727 * @param node the expression to evaluate
19757 * @return `true` if and only if an error code is generated on the passed node 19728 * @return `true` if and only if an error code is generated on the passed node
19758 * @see StaticWarningCode#ASSIGNMENT_TO_CONST 19729 * @see StaticWarningCode#ASSIGNMENT_TO_CONST
19759 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL 19730 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL
19760 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD 19731 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD
19761 */ 19732 */
19762 bool _checkForAssignmentToFinal(Expression expression) { 19733 bool _checkForAssignmentToFinal(Expression expression) {
19763 // prepare element 19734 // prepare element
19764 Element element = null; 19735 Element element = null;
19736 AstNode highlightedNode = expression;
19765 if (expression is Identifier) { 19737 if (expression is Identifier) {
19766 element = expression.staticElement; 19738 element = expression.staticElement;
19767 } 19739 if (expression is PrefixedIdentifier) {
19768 if (expression is PropertyAccess) { 19740 highlightedNode = expression.identifier;
19769 element = expression.propertyName.staticElement; 19741 }
19742 } else if (expression is PropertyAccess) {
19743 PropertyAccess propertyAccess = expression;
19744 element = propertyAccess.propertyName.staticElement;
19745 highlightedNode = propertyAccess.propertyName;
19770 } 19746 }
19771 // check if element is assignable 19747 // check if element is assignable
19772 if (element is PropertyAccessorElement) { 19748 if (element is PropertyAccessorElement) {
19773 PropertyAccessorElement accessor = element as PropertyAccessorElement; 19749 PropertyAccessorElement accessor = element as PropertyAccessorElement;
19774 element = accessor.variable; 19750 element = accessor.variable;
19775 } 19751 }
19776 if (element is VariableElement) { 19752 if (element is VariableElement) {
19777 VariableElement variable = element as VariableElement; 19753 VariableElement variable = element as VariableElement;
19778 if (variable.isConst) { 19754 if (variable.isConst) {
19779 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST, expression, []); 19755 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST, expression, []);
19780 return true; 19756 return true;
19781 } 19757 }
19782 if (variable.isFinal) { 19758 if (variable.isFinal) {
19783 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, expression, [variable.name]); 19759 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, highlightedNode, [variable.name]);
19784 return true; 19760 return true;
19785 } 19761 }
19786 return false; 19762 return false;
19787 } 19763 }
19788 if (element is MethodElement) { 19764 if (element is MethodElement) {
19789 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_METHOD, expression, []); 19765 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_METHOD, expression, []);
19790 return true; 19766 return true;
19791 } 19767 }
19792 return false; 19768 return false;
19793 } 19769 }
19794 19770
19795 /** 19771 /**
19796 * This verifies that the passed identifier is not a keyword, and generates th e passed error code 19772 * This verifies that the passed identifier is not a keyword, and generates th e passed error code
19797 * on the identifier if it is a keyword. 19773 * on the identifier if it is a keyword.
19798 * 19774 *
19799 * @param identifier the identifier to check to ensure that it is not a keywor d 19775 * @param identifier the identifier to check to ensure that it is not a keywor d
19800 * @param errorCode if the passed identifier is a keyword then this error code is created on the 19776 * @param errorCode if the passed identifier is a keyword then this error code is created on the
19801 * identifier, the error code will be one of 19777 * identifier, the error code will be one of
19802 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME], 19778 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME],
19803 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME] or 19779 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME] or
19804 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] 19780 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]
19805 * @return `true` if and only if an error code is generated on the passed node 19781 * @return `true` if and only if an error code is generated on the passed node
19806 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME 19782 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME
19807 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME 19783 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME
19808 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME 19784 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME
19809 */ 19785 */
19810 bool _checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode e rrorCode) { 19786 bool _checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode e rrorCode) {
19811 sc.Token token = identifier.token; 19787 sc.Token token = identifier.token;
19812 if (identical(token.type, sc.TokenType.KEYWORD)) { 19788 if (token.type == sc.TokenType.KEYWORD) {
19813 _errorReporter.reportErrorForNode(errorCode, identifier, [identifier.name] ); 19789 _errorReporter.reportErrorForNode(errorCode, identifier, [identifier.name] );
19814 return true; 19790 return true;
19815 } 19791 }
19816 return false; 19792 return false;
19817 } 19793 }
19818 19794
19819 /** 19795 /**
19820 * This verifies that the given switch case is terminated with 'break', 'conti nue', 'return' or 19796 * This verifies that the given switch case is terminated with 'break', 'conti nue', 'return' or
19821 * 'throw'. 19797 * 'throw'.
19822 * 19798 *
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
20304 return false; 20280 return false;
20305 } 20281 }
20306 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor ; 20282 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor ;
20307 if (unnamedConstructor == null) { 20283 if (unnamedConstructor == null) {
20308 return false; 20284 return false;
20309 } 20285 }
20310 if (unnamedConstructor.isConst) { 20286 if (unnamedConstructor.isConst) {
20311 return false; 20287 return false;
20312 } 20288 }
20313 // default constructor is not 'const', report problem 20289 // default constructor is not 'const', report problem
20314 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_CONST_SUPER, node, []); 20290 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT H_NON_CONST_SUPER, node.returnType, []);
20315 return true; 20291 return true;
20316 } 20292 }
20317 20293
20318 /** 20294 /**
20319 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final 20295 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final
20320 * instance variable. 20296 * instance variable.
20321 * 20297 *
20322 * @param node the constructor declaration to evaluate 20298 * @param node the constructor declaration to evaluate
20323 * @return `true` if and only if an error code is generated on the passed node 20299 * @return `true` if and only if an error code is generated on the passed node
20324 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 20300 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
20404 * [InstanceCreationExpression], this is the AST node that the error is attached to 20380 * [InstanceCreationExpression], this is the AST node that the error is attached to
20405 * @param type the type being constructed with this [InstanceCreationExpressio n] 20381 * @param type the type being constructed with this [InstanceCreationExpressio n]
20406 * @return `true` if and only if an error code is generated on the passed node 20382 * @return `true` if and only if an error code is generated on the passed node
20407 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 20383 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS
20408 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 20384 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS
20409 */ 20385 */
20410 bool _checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Typ eName typeName, InterfaceType type) { 20386 bool _checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Typ eName typeName, InterfaceType type) {
20411 if (type.element.isAbstract) { 20387 if (type.element.isAbstract) {
20412 ConstructorElement element = node.staticElement; 20388 ConstructorElement element = node.staticElement;
20413 if (element != null && !element.isFactory) { 20389 if (element != null && !element.isFactory) {
20414 if (identical((node.keyword as sc.KeywordToken).keyword, sc.Keyword.CONS T)) { 20390 if ((node.keyword as sc.KeywordToken).keyword == sc.Keyword.CONST) {
20415 _errorReporter.reportErrorForNode(StaticWarningCode.CONST_WITH_ABSTRAC T_CLASS, typeName, []); 20391 _errorReporter.reportErrorForNode(StaticWarningCode.CONST_WITH_ABSTRAC T_CLASS, typeName, []);
20416 } else { 20392 } else {
20417 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_ABSTRACT_ CLASS, typeName, []); 20393 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_ABSTRACT_ CLASS, typeName, []);
20418 } 20394 }
20419 return true; 20395 return true;
20420 } 20396 }
20421 } 20397 }
20422 return false; 20398 return false;
20423 } 20399 }
20424 20400
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
21495 21471
21496 /** 21472 /**
21497 * This verifies that the given function body does not contain return statemen ts that both have 21473 * This verifies that the given function body does not contain return statemen ts that both have
21498 * and do not have return values. 21474 * and do not have return values.
21499 * 21475 *
21500 * @param node the function body being tested 21476 * @param node the function body being tested
21501 * @return `true` if and only if an error code is generated on the passed node 21477 * @return `true` if and only if an error code is generated on the passed node
21502 * @see StaticWarningCode#MIXED_RETURN_TYPES 21478 * @see StaticWarningCode#MIXED_RETURN_TYPES
21503 */ 21479 */
21504 bool _checkForMixedReturns(BlockFunctionBody node) { 21480 bool _checkForMixedReturns(BlockFunctionBody node) {
21481 if (_hasReturnWithoutValue) {
21482 return false;
21483 }
21505 int withCount = _returnsWith.length; 21484 int withCount = _returnsWith.length;
21506 int withoutCount = _returnsWithout.length; 21485 int withoutCount = _returnsWithout.length;
21507 if (withCount > 0 && withoutCount > 0) { 21486 if (withCount > 0 && withoutCount > 0) {
21508 for (int i = 0; i < withCount; i++) { 21487 for (int i = 0; i < withCount; i++) {
21509 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWith[i].keyword, []); 21488 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWith[i].keyword, []);
21510 } 21489 }
21511 for (int i = 0; i < withoutCount; i++) { 21490 for (int i = 0; i < withoutCount; i++) {
21512 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWithout[i].keyword, []); 21491 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES, _returnsWithout[i].keyword, []);
21513 } 21492 }
21514 return true; 21493 return true;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
21767 } 21746 }
21768 // Now that we have the set of missing overrides, generate a warning on this class 21747 // Now that we have the set of missing overrides, generate a warning on this class
21769 int missingOverridesSize = missingOverrides.length; 21748 int missingOverridesSize = missingOverrides.length;
21770 if (missingOverridesSize == 0) { 21749 if (missingOverridesSize == 0) {
21771 return false; 21750 return false;
21772 } 21751 }
21773 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid es); 21752 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid es);
21774 List<String> stringMembersArrayListSet = new List<String>(); 21753 List<String> stringMembersArrayListSet = new List<String>();
21775 for (int i = 0; i < missingOverridesArray.length; i++) { 21754 for (int i = 0; i < missingOverridesArray.length; i++) {
21776 String newStrMember; 21755 String newStrMember;
21777 if (missingOverridesArray[i].enclosingElement != null) { 21756 Element enclosingElement = missingOverridesArray[i].enclosingElement;
21778 newStrMember = "${missingOverridesArray[i].enclosingElement.displayName} .${missingOverridesArray[i].displayName}"; 21757 String prefix = StringUtilities.EMPTY;
21758 if (missingOverridesArray[i] is PropertyAccessorElement) {
21759 PropertyAccessorElement propertyAccessorElement = missingOverridesArray[ i] as PropertyAccessorElement;
21760 if (propertyAccessorElement.isGetter) {
21761 prefix = _GETTER_SPACE;
21762 } else {
21763 prefix = _SETTER_SPACE;
21764 }
21765 }
21766 if (enclosingElement != null) {
21767 newStrMember = "${prefix}'${enclosingElement.displayName}.${missingOverr idesArray[i].displayName}'";
21779 } else { 21768 } else {
21780 newStrMember = missingOverridesArray[i].displayName; 21769 newStrMember = "${prefix}'${missingOverridesArray[i].displayName}'";
21781 } 21770 }
21782 if (!stringMembersArrayListSet.contains(newStrMember)) { 21771 stringMembersArrayListSet.add(newStrMember);
21783 stringMembersArrayListSet.add(newStrMember);
21784 }
21785 } 21772 }
21786 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); 21773 List<String> stringMembersArray = new List.from(stringMembersArrayListSet);
21787 AnalysisErrorWithProperties analysisError; 21774 AnalysisErrorWithProperties analysisError;
21788 if (stringMembersArray.length == 1) { 21775 if (stringMembersArray.length == 1) {
21789 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringMembersArray[0] ]); 21776 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringMembersArray[0] ]);
21790 } else if (stringMembersArray.length == 2) { 21777 } else if (stringMembersArray.length == 2) {
21791 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringMembersArray[0] , stringMembersArray[1]]); 21778 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringMembersArray[0] , stringMembersArray[1]]);
21792 } else if (stringMembersArray.length == 3) { 21779 } else if (stringMembersArray.length == 3) {
21793 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [ 21780 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [
21794 stringMembersArray[0], 21781 stringMembersArray[0],
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
21889 // has type arguments 21876 // has type arguments
21890 if (node.typeArguments != null) { 21877 if (node.typeArguments != null) {
21891 return false; 21878 return false;
21892 } 21879 }
21893 // prepare statement 21880 // prepare statement
21894 Statement statement = node.getAncestor((node) => node is ExpressionStatement ); 21881 Statement statement = node.getAncestor((node) => node is ExpressionStatement );
21895 if (statement == null) { 21882 if (statement == null) {
21896 return false; 21883 return false;
21897 } 21884 }
21898 // OK, statement does not start with map 21885 // OK, statement does not start with map
21899 if (statement.beginToken != node.beginToken) { 21886 if (!identical(statement.beginToken, node.beginToken)) {
21900 return false; 21887 return false;
21901 } 21888 }
21902 // report problem 21889 // report problem
21903 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPR ESSION_STATEMENT, node, []); 21890 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPR ESSION_STATEMENT, node, []);
21904 return true; 21891 return true;
21905 } 21892 }
21906 21893
21907 /** 21894 /**
21908 * This verifies the passed method declaration of operator `[]=`, has `void` r eturn 21895 * This verifies the passed method declaration of operator `[]=`, has `void` r eturn
21909 * type. 21896 * type.
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
22531 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_NON_EXISTANT_FIELD, node, [node.identifier.name]); 22518 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_NON_EXISTANT_FIELD, node, [node.identifier.name]);
22532 } else if (fieldElement.isStatic) { 22519 } else if (fieldElement.isStatic) {
22533 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_STATIC_FIELD, node, [node.identifier.name]); 22520 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INITIALIZING_ FORMAL_FOR_STATIC_FIELD, node, [node.identifier.name]);
22534 } 22521 }
22535 } 22522 }
22536 } 22523 }
22537 } 22524 }
22538 } 22525 }
22539 22526
22540 /** 22527 /**
22528 * This verifies that the given getter does not have a return type of 'void'.
22529 *
22530 * @param node the method declaration to evaluate
22531 * @return `true` if and only if an error code is generated on the passed node
22532 * @see StaticWarningCode#VOID_RETURN_FOR_GETTER
22533 */
22534 bool _checkForVoidReturnType(MethodDeclaration node) {
22535 TypeName returnType = node.returnType;
22536 if (returnType == null || returnType.name.name != "void") {
22537 return false;
22538 }
22539 _errorReporter.reportErrorForNode(StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType, []);
22540 return true;
22541 }
22542
22543 /**
22541 * This verifies the passed operator-method declaration, has correct number of parameters. 22544 * This verifies the passed operator-method declaration, has correct number of parameters.
22542 * 22545 *
22543 * This method assumes that the method declaration was tested to be an operato r declaration before 22546 * This method assumes that the method declaration was tested to be an operato r declaration before
22544 * being called. 22547 * being called.
22545 * 22548 *
22546 * @param node the method declaration to evaluate 22549 * @param node the method declaration to evaluate
22547 * @return `true` if and only if an error code is generated on the passed node 22550 * @return `true` if and only if an error code is generated on the passed node
22548 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR 22551 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR
22549 */ 22552 */
22550 bool _checkForWrongNumberOfParametersForOperator(MethodDeclaration node) { 22553 bool _checkForWrongNumberOfParametersForOperator(MethodDeclaration node) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
22843 * 22846 *
22844 * By "match", only the name of the member is tested to match, it does not hav e to equal or be a 22847 * By "match", only the name of the member is tested to match, it does not hav e to equal or be a
22845 * subtype of the passed executable element, this is due to the specific use w here this method is 22848 * subtype of the passed executable element, this is due to the specific use w here this method is
22846 * used in [checkForNonAbstractClassInheritsAbstractMember]. 22849 * used in [checkForNonAbstractClassInheritsAbstractMember].
22847 * 22850 *
22848 * @param executableElt the executable to search for in the passed class eleme nt 22851 * @param executableElt the executable to search for in the passed class eleme nt
22849 * @param classElt the class method to search through the members of 22852 * @param classElt the class method to search through the members of
22850 * @return `true` iff the passed member is found in the passed class element 22853 * @return `true` iff the passed member is found in the passed class element
22851 */ 22854 */
22852 bool _isMemberInClassOrMixin(ExecutableElement executableElt, ClassElement cla ssElt) { 22855 bool _isMemberInClassOrMixin(ExecutableElement executableElt, ClassElement cla ssElt) {
22853 ExecutableElement foundElt; 22856 ExecutableElement foundElt = null;
22854 String executableName = executableElt.name; 22857 String executableName = executableElt.name;
22855 if (executableElt is MethodElement) { 22858 if (executableElt is MethodElement) {
22856 foundElt = classElt.getMethod(executableName); 22859 foundElt = classElt.getMethod(executableName);
22857 if (foundElt != null) { 22860 if (foundElt != null) {
22858 return true; 22861 return true;
22859 } 22862 }
22860 List<InterfaceType> mixins = classElt.mixins; 22863 List<InterfaceType> mixins = classElt.mixins;
22861 for (int i = 0; i < mixins.length && foundElt == null; i++) { 22864 for (int i = 0; i < mixins.length && foundElt == null; i++) {
22862 foundElt = mixins[i].getMethod(executableName); 22865 foundElt = mixins[i].getMethod(executableName);
22863 } 22866 }
22864 if (foundElt != null) { 22867 if (foundElt != null) {
22865 return true; 22868 return true;
22866 } 22869 }
22867 } else if (executableElt is PropertyAccessorElement) { 22870 } else if (executableElt is PropertyAccessorElement) {
22868 foundElt = classElt.getGetter(executableElt.name); 22871 PropertyAccessorElement propertyAccessorElement = executableElt;
22869 if (foundElt == null) { 22872 if (propertyAccessorElement.isGetter) {
22873 foundElt = classElt.getGetter(executableName);
22874 }
22875 if (foundElt == null && propertyAccessorElement.isSetter) {
22870 foundElt = classElt.getSetter(executableName); 22876 foundElt = classElt.getSetter(executableName);
22871 } 22877 }
22872 if (foundElt != null) { 22878 if (foundElt != null) {
22873 return true; 22879 return true;
22874 } 22880 }
22875 List<InterfaceType> mixins = classElt.mixins; 22881 List<InterfaceType> mixins = classElt.mixins;
22876 for (int i = 0; i < mixins.length && foundElt == null; i++) { 22882 for (int i = 0; i < mixins.length && foundElt == null; i++) {
22877 foundElt = mixins[i].getGetter(executableName); 22883 foundElt = mixins[i].getGetter(executableName);
22878 if (foundElt == null) { 22884 if (foundElt == null) {
22879 foundElt = mixins[i].getSetter(executableName); 22885 foundElt = mixins[i].getSetter(executableName);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
22998 return false; 23004 return false;
22999 } 23005 }
23000 } 23006 }
23001 23007
23002 /** 23008 /**
23003 * This enum holds one of four states of a field initialization state through a constructor 23009 * This enum holds one of four states of a field initialization state through a constructor
23004 * signature, not initialized, initialized in the field declaration, initialized in the field 23010 * signature, not initialized, initialized in the field declaration, initialized in the field
23005 * formal, and finally, initialized in the initializers list. 23011 * formal, and finally, initialized in the initializers list.
23006 */ 23012 */
23007 class INIT_STATE extends Enum<INIT_STATE> { 23013 class INIT_STATE extends Enum<INIT_STATE> {
23008 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); 23014 static const INIT_STATE NOT_INIT = const INIT_STATE('NOT_INIT', 0);
23009 23015
23010 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT ION', 1); 23016 static const INIT_STATE INIT_IN_DECLARATION = const INIT_STATE('INIT_IN_DECLAR ATION', 1);
23011 23017
23012 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2); 23018 static const INIT_STATE INIT_IN_FIELD_FORMAL = const INIT_STATE('INIT_IN_FIELD _FORMAL', 2);
23013 23019
23014 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 3); 23020 static const INIT_STATE INIT_IN_INITIALIZERS = const INIT_STATE('INIT_IN_INITI ALIZERS', 3);
23015 23021
23016 static final List<INIT_STATE> values = [ 23022 static const List<INIT_STATE> values = const [
23017 NOT_INIT, 23023 NOT_INIT,
23018 INIT_IN_DECLARATION, 23024 INIT_IN_DECLARATION,
23019 INIT_IN_FIELD_FORMAL, 23025 INIT_IN_FIELD_FORMAL,
23020 INIT_IN_INITIALIZERS]; 23026 INIT_IN_INITIALIZERS];
23021 23027
23022 INIT_STATE(String name, int ordinal) : super(name, ordinal); 23028 const INIT_STATE(String name, int ordinal) : super(name, ordinal);
23023 } 23029 }
23024 23030
23025 class GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference extends G eneralizingElementVisitor<Object> { 23031 class GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference extends G eneralizingElementVisitor<Object> {
23026 Element target; 23032 Element target;
23027 23033
23028 List<Element> toCheck; 23034 List<Element> toCheck;
23029 23035
23030 GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference(this.target, this.toCheck) : super(); 23036 GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelfReference(this.target, this.toCheck) : super();
23031 23037
23032 bool _inClass = false; 23038 bool _inClass = false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
23099 } 23105 }
23100 } 23106 }
23101 23107
23102 /** 23108 /**
23103 * The enumeration `ResolverErrorCode` defines the error codes used for errors d etected by the 23109 * The enumeration `ResolverErrorCode` defines the error codes used for errors d etected by the
23104 * resolver. The convention for this class is for the name of the error code to indicate the problem 23110 * resolver. The convention for this class is for the name of the error code to indicate the problem
23105 * that caused the error to be generated and for the error message to explain wh at is wrong and, 23111 * that caused the error to be generated and for the error message to explain wh at is wrong and,
23106 * when appropriate, how the problem can be corrected. 23112 * when appropriate, how the problem can be corrected.
23107 */ 23113 */
23108 class ResolverErrorCode extends Enum<ResolverErrorCode> implements ErrorCode { 23114 class ResolverErrorCode extends Enum<ResolverErrorCode> implements ErrorCode {
23109 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro rCode.con1('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Bre ak label resolves to case or default statement"); 23115 static const ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = const ResolverEr rorCode.con1('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "B reak label resolves to case or default statement");
23110 23116
23111 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod e.con1('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label resolves to switch, must be loop or switch member"); 23117 static const ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = const ResolverErrorC ode.con1('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continu e label resolves to switch, must be loop or switch member");
23112 23118
23113 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol verErrorCode.con1('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TI ME_ERROR, "Libraries that have parts must have a library directive"); 23119 static const ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = const Res olverErrorCode.con1('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_ TIME_ERROR, "Libraries that have parts must have a library directive");
23114 23120
23115 static final List<ResolverErrorCode> values = [ 23121 static const List<ResolverErrorCode> values = const [
23116 BREAK_LABEL_ON_SWITCH_MEMBER, 23122 BREAK_LABEL_ON_SWITCH_MEMBER,
23117 CONTINUE_LABEL_ON_SWITCH, 23123 CONTINUE_LABEL_ON_SWITCH,
23118 MISSING_LIBRARY_DIRECTIVE_WITH_PART]; 23124 MISSING_LIBRARY_DIRECTIVE_WITH_PART];
23119 23125
23120 /** 23126 /**
23121 * The type of this error. 23127 * The type of this error.
23122 */ 23128 */
23123 ErrorType type; 23129 final ErrorType type;
23124 23130
23125 /** 23131 /**
23126 * The template used to create the message to be displayed for this error. 23132 * The template used to create the message to be displayed for this error.
23127 */ 23133 */
23128 String message; 23134 final String message;
23129 23135
23130 /** 23136 /**
23131 * The template used to create the correction to be displayed for this error, or `null` if 23137 * The template used to create the correction to be displayed for this error, or `null` if
23132 * there is no correction information for this error. 23138 * there is no correction information for this error.
23133 */ 23139 */
23134 String correction9; 23140 final String correction;
23135 23141
23136 /** 23142 /**
23137 * Initialize a newly created error code to have the given type and message. 23143 * Initialize a newly created error code to have the given type and message.
23138 * 23144 *
23139 * @param type the type of this error 23145 * @param type the type of this error
23140 * @param message the message template used to create the message to be displa yed for the error 23146 * @param message the message template used to create the message to be displa yed for the error
23141 */ 23147 */
23142 ResolverErrorCode.con1(String name, int ordinal, ErrorType type, String messag e) : super(name, ordinal) { 23148 const ResolverErrorCode.con1(String name, int ordinal, ErrorType type, String message) : this.con2(name, ordinal, type, message, null);
23143 this.type = type;
23144 this.message = message;
23145 }
23146 23149
23147 /** 23150 /**
23148 * Initialize a newly created error code to have the given type, message and c orrection. 23151 * Initialize a newly created error code to have the given type, message and c orrection.
23149 * 23152 *
23150 * @param type the type of this error 23153 * @param type the type of this error
23151 * @param message the template used to create the message to be displayed for the error 23154 * @param message the template used to create the message to be displayed for the error
23152 * @param correction the template used to create the correction to be displaye d for the error 23155 * @param correction the template used to create the correction to be displaye d for the error
23153 */ 23156 */
23154 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) { 23157 const ResolverErrorCode.con2(String name, int ordinal, this.type, this.message , this.correction) : super(name, ordinal);
23155 this.type = type;
23156 this.message = message;
23157 this.correction9 = correction;
23158 }
23159
23160 @override
23161 String get correction => correction9;
23162 23158
23163 @override 23159 @override
23164 ErrorSeverity get errorSeverity => type.severity; 23160 ErrorSeverity get errorSeverity => type.severity;
23165 } 23161 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698