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

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

Issue 229653004: New analyzer snapshot with MapIterator. (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';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_engine.dart'; 12 import 'java_engine.dart';
13 import 'instrumentation.dart'; 13 import 'instrumentation.dart';
14 import 'source.dart'; 14 import 'source.dart';
15 import 'error.dart'; 15 import 'error.dart';
16 import 'scanner.dart' as sc; 16 import 'scanner.dart' as sc;
17 import 'utilities_dart.dart'; 17 import 'utilities_dart.dart';
18 import 'utilities_general.dart'; 18 import 'utilities_general.dart';
19 import 'utilities_collection.dart';
19 import 'ast.dart'; 20 import 'ast.dart';
20 import 'parser.dart' show Parser, ParserErrorCode; 21 import 'parser.dart' show Parser, ParserErrorCode;
21 import 'sdk.dart' show DartSdk, SdkLibrary; 22 import 'sdk.dart' show DartSdk, SdkLibrary;
22 import 'element.dart'; 23 import 'element.dart';
23 import 'html.dart' as ht; 24 import 'html.dart' as ht;
24 import 'engine.dart'; 25 import 'engine.dart';
25 import 'constant.dart'; 26 import 'constant.dart';
26 27
27 /** 28 /**
28 * Instances of the class `AngularCompilationUnitBuilder` build an Angular speci fic element 29 * Instances of the class `AngularCompilationUnitBuilder` build an Angular speci fic element
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 * The [ClassDeclaration] that is currently being analyzed. 236 * The [ClassDeclaration] that is currently being analyzed.
236 */ 237 */
237 ClassDeclaration _classDeclaration; 238 ClassDeclaration _classDeclaration;
238 239
239 /** 240 /**
240 * The [ClassElementImpl] that is currently being analyzed. 241 * The [ClassElementImpl] that is currently being analyzed.
241 */ 242 */
242 ClassElementImpl _classElement; 243 ClassElementImpl _classElement;
243 244
244 /** 245 /**
245 * The [ToolkitObjectElement]s to set for [classElement].
246 */
247 List<ToolkitObjectElement> _classToolkitObjects = [];
248
249 /**
250 * The [Annotation] that is currently being analyzed. 246 * The [Annotation] that is currently being analyzed.
251 */ 247 */
252 Annotation _annotation; 248 Annotation _annotation;
253 249
254 /** 250 /**
255 * Initialize a newly created compilation unit element builder. 251 * Initialize a newly created compilation unit element builder.
256 * 252 *
257 * @param errorListener the listener to which errors will be reported. 253 * @param errorListener the listener to which errors will be reported.
258 * @param source the source containing the unit that will be analyzed 254 * @param source the source containing the unit that will be analyzed
259 * @param unit the compilation unit with built Dart element models 255 * @param unit the compilation unit with built Dart element models
260 */ 256 */
261 AngularCompilationUnitBuilder(this._errorListener, this._source, this._unit); 257 AngularCompilationUnitBuilder(this._errorListener, this._source, this._unit);
262 258
263 /** 259 /**
264 * Builds Angular specific element models and adds them to the existing Dart e lements. 260 * Builds Angular specific element models and adds them to the existing Dart e lements.
265 */ 261 */
266 void build() { 262 void build() {
267 _parseViews(); 263 _parseViews();
268 // process classes 264 // process classes
269 for (CompilationUnitMember unitMember in _unit.declarations) { 265 for (CompilationUnitMember unitMember in _unit.declarations) {
270 if (unitMember is ClassDeclaration) { 266 if (unitMember is ClassDeclaration) {
271 this._classDeclaration = unitMember; 267 this._classDeclaration = unitMember;
272 this._classElement = _classDeclaration.element as ClassElementImpl; 268 this._classElement = _classDeclaration.element as ClassElementImpl;
273 this._classToolkitObjects.clear();
274 // process annotations 269 // process annotations
275 NodeList<Annotation> annotations = _classDeclaration.metadata; 270 NodeList<Annotation> annotations = _classDeclaration.metadata;
276 for (Annotation annotation in annotations) { 271 for (Annotation annotation in annotations) {
277 // verify annotation 272 // verify annotation
278 if (annotation.arguments == null) { 273 if (annotation.arguments == null) {
279 continue; 274 continue;
280 } 275 }
281 this._annotation = annotation; 276 this._annotation = annotation;
282 // @NgFilter 277 // @NgFilter
283 if (_isAngularAnnotation(annotation, _NG_FILTER)) { 278 if (_isAngularAnnotation(annotation, _NG_FILTER)) {
284 _parseNgFilter(); 279 _parseNgFilter();
285 continue; 280 continue;
286 } 281 }
287 // @NgComponent 282 // @NgComponent
288 if (_isAngularAnnotation(annotation, _NG_COMPONENT)) { 283 if (_isAngularAnnotation(annotation, _NG_COMPONENT)) {
289 _parseNgComponent(); 284 _parseNgComponent();
290 continue; 285 continue;
291 } 286 }
292 // @NgController 287 // @NgController
293 if (_isAngularAnnotation(annotation, _NG_CONTROLLER)) { 288 if (_isAngularAnnotation(annotation, _NG_CONTROLLER)) {
294 _parseNgController(); 289 _parseNgController();
295 continue; 290 continue;
296 } 291 }
297 // @NgDirective 292 // @NgDirective
298 if (_isAngularAnnotation(annotation, _NG_DIRECTIVE)) { 293 if (_isAngularAnnotation(annotation, _NG_DIRECTIVE)) {
299 _parseNgDirective(); 294 _parseNgDirective();
300 continue; 295 continue;
301 } 296 }
302 } 297 }
303 // set toolkit objects
304 if (!_classToolkitObjects.isEmpty) {
305 List<ToolkitObjectElement> objects = _classToolkitObjects;
306 _classElement.toolkitObjects = new List.from(objects);
307 }
308 } 298 }
309 } 299 }
310 } 300 }
311 301
312 /** 302 /**
313 * @return the argument [Expression] with given name form [annotation], may be 303 * @return the argument [Expression] with given name form [annotation], may be
314 * `null` if not found. 304 * `null` if not found.
315 */ 305 */
316 Expression _getArgument(String name) { 306 Expression _getArgument(String name) {
317 List<Expression> arguments = _annotation.arguments.arguments; 307 List<Expression> arguments = _annotation.arguments.arguments;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 // create 397 // create
408 if (isValid) { 398 if (isValid) {
409 AngularComponentElementImpl element = new AngularComponentElementImpl(name , nameOffset, _annotation.offset); 399 AngularComponentElementImpl element = new AngularComponentElementImpl(name , nameOffset, _annotation.offset);
410 element.selector = selector; 400 element.selector = selector;
411 element.templateUri = templateUri; 401 element.templateUri = templateUri;
412 element.templateUriOffset = templateUriOffset; 402 element.templateUriOffset = templateUriOffset;
413 element.styleUri = styleUri; 403 element.styleUri = styleUri;
414 element.styleUriOffset = styleUriOffset; 404 element.styleUriOffset = styleUriOffset;
415 element.properties = _parseNgComponentProperties(); 405 element.properties = _parseNgComponentProperties();
416 element.scopeProperties = _parseScopeProperties(); 406 element.scopeProperties = _parseScopeProperties();
417 _classToolkitObjects.add(element); 407 _classElement.addToolkitObjects(element);
418 } 408 }
419 } 409 }
420 410
421 /** 411 /**
422 * Parses [AngularPropertyElement]s from [annotation] and [classDeclaration]. 412 * Parses [AngularPropertyElement]s from [annotation] and [classDeclaration].
423 */ 413 */
424 List<AngularPropertyElement> _parseNgComponentProperties() { 414 List<AngularPropertyElement> _parseNgComponentProperties() {
425 List<AngularPropertyElement> properties = []; 415 List<AngularPropertyElement> properties = [];
426 _parseNgComponentProperties_fromMap(properties); 416 _parseNgComponentProperties_fromMap(properties);
427 _parseNgComponentProperties_fromFields(properties); 417 _parseNgComponentProperties_fromFields(properties);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s electorLiteral]); 549 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s electorLiteral]);
560 isValid = false; 550 isValid = false;
561 } 551 }
562 } 552 }
563 // create 553 // create
564 if (isValid) { 554 if (isValid) {
565 String name = _getStringArgument(_PUBLISH_AS); 555 String name = _getStringArgument(_PUBLISH_AS);
566 int nameOffset = _getStringArgumentOffset(_PUBLISH_AS); 556 int nameOffset = _getStringArgumentOffset(_PUBLISH_AS);
567 AngularControllerElementImpl element = new AngularControllerElementImpl(na me, nameOffset); 557 AngularControllerElementImpl element = new AngularControllerElementImpl(na me, nameOffset);
568 element.selector = selector; 558 element.selector = selector;
569 _classToolkitObjects.add(element); 559 _classElement.addToolkitObjects(element);
570 } 560 }
571 } 561 }
572 562
573 void _parseNgDirective() { 563 void _parseNgDirective() {
574 bool isValid = true; 564 bool isValid = true;
575 // selector 565 // selector
576 AngularSelectorElement selector = null; 566 AngularSelectorElement selector = null;
577 if (!_hasStringArgument(_SELECTOR)) { 567 if (!_hasStringArgument(_SELECTOR)) {
578 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); 568 _reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []);
579 isValid = false; 569 isValid = false;
580 } else { 570 } else {
581 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR); 571 SimpleStringLiteral selectorLiteral = _getStringLiteral(_SELECTOR);
582 selector = _parseSelectorFromString(selectorLiteral); 572 selector = _parseSelectorFromString(selectorLiteral);
583 if (selector == null) { 573 if (selector == null) {
584 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s electorLiteral]); 574 _reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [s electorLiteral]);
585 isValid = false; 575 isValid = false;
586 } 576 }
587 } 577 }
588 // create 578 // create
589 if (isValid) { 579 if (isValid) {
590 int offset = _annotation.offset; 580 int offset = _annotation.offset;
591 AngularDirectiveElementImpl element = new AngularDirectiveElementImpl(offs et); 581 AngularDirectiveElementImpl element = new AngularDirectiveElementImpl(offs et);
592 element.selector = selector; 582 element.selector = selector;
593 element.properties = _parseNgComponentProperties(); 583 element.properties = _parseNgComponentProperties();
594 _classToolkitObjects.add(element); 584 _classElement.addToolkitObjects(element);
595 } 585 }
596 } 586 }
597 587
598 void _parseNgFilter() { 588 void _parseNgFilter() {
599 bool isValid = true; 589 bool isValid = true;
600 // name 590 // name
601 if (!_hasStringArgument(_NAME)) { 591 if (!_hasStringArgument(_NAME)) {
602 _reportErrorForAnnotation(AngularCode.MISSING_NAME, []); 592 _reportErrorForAnnotation(AngularCode.MISSING_NAME, []);
603 isValid = false; 593 isValid = false;
604 } 594 }
605 // create 595 // create
606 if (isValid) { 596 if (isValid) {
607 String name = _getStringArgument(_NAME); 597 String name = _getStringArgument(_NAME);
608 int nameOffset = _getStringArgumentOffset(_NAME); 598 int nameOffset = _getStringArgumentOffset(_NAME);
609 _classToolkitObjects.add(new AngularFilterElementImpl(name, nameOffset)); 599 _classElement.addToolkitObjects(new AngularFilterElementImpl(name, nameOff set));
610 } 600 }
611 } 601 }
612 602
613 List<AngularScopePropertyElement> _parseScopeProperties() { 603 List<AngularScopePropertyElement> _parseScopeProperties() {
614 List<AngularScopePropertyElement> properties = []; 604 List<AngularScopePropertyElement> properties = [];
615 _classDeclaration.accept(new RecursiveAstVisitor_AngularCompilationUnitBuild er_parseScopeProperties(properties)); 605 _classDeclaration.accept(new RecursiveAstVisitor_AngularCompilationUnitBuild er_parseScopeProperties(properties));
616 return new List.from(properties); 606 return new List.from(properties);
617 } 607 }
618 608
619 /** 609 /**
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 * @param arguments the arguments used to compose the error message 2189 * @param arguments the arguments used to compose the error message
2200 */ 2190 */
2201 void _reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, Lis t<Object> arguments) { 2191 void _reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, Lis t<Object> arguments) {
2202 int offset = attribute.valueToken.offset + 1; 2192 int offset = attribute.valueToken.offset + 1;
2203 int length = attribute.valueToken.length - 2; 2193 int length = attribute.valueToken.length - 2;
2204 _reportErrorForOffset(errorCode, offset, length, arguments); 2194 _reportErrorForOffset(errorCode, offset, length, arguments);
2205 } 2195 }
2206 } 2196 }
2207 2197
2208 /** 2198 /**
2199 * Instances of the class `PolymerCompilationUnitBuilder` build a Polymer specif ic element
2200 * model for a single compilation unit.
2201 */
2202 class PolymerCompilationUnitBuilder {
2203 static String _CUSTOM_TAG = "CustomTag";
2204
2205 static Element getElement(AstNode node, int offset) {
2206 // maybe node is not SimpleStringLiteral
2207 if (node is! SimpleStringLiteral) {
2208 return null;
2209 }
2210 SimpleStringLiteral literal = node as SimpleStringLiteral;
2211 // maybe has PolymerElement
2212 {
2213 Element element = literal.toolkitElement;
2214 if (element is PolymerElement) {
2215 return element;
2216 }
2217 }
2218 // no Element
2219 return null;
2220 }
2221
2222 /**
2223 * The compilation unit with built Dart element models.
2224 */
2225 final CompilationUnit _unit;
2226
2227 /**
2228 * The [ClassDeclaration] that is currently being analyzed.
2229 */
2230 ClassDeclaration _classDeclaration;
2231
2232 /**
2233 * The [ClassElementImpl] that is currently being analyzed.
2234 */
2235 ClassElementImpl _classElement;
2236
2237 /**
2238 * The [Annotation] that is currently being analyzed.
2239 */
2240 Annotation _annotation;
2241
2242 /**
2243 * Initialize a newly created compilation unit element builder.
2244 *
2245 * @param unit the compilation unit with built Dart element models
2246 */
2247 PolymerCompilationUnitBuilder(this._unit);
2248
2249 /**
2250 * Builds Polymer specific element models and adds them to the existing Dart e lements.
2251 */
2252 void build() {
2253 // process classes
2254 for (CompilationUnitMember unitMember in _unit.declarations) {
2255 if (unitMember is ClassDeclaration) {
2256 this._classDeclaration = unitMember;
2257 this._classElement = _classDeclaration.element as ClassElementImpl;
2258 // process annotations
2259 NodeList<Annotation> annotations = _classDeclaration.metadata;
2260 for (Annotation annotation in annotations) {
2261 // verify annotation
2262 if (annotation.arguments == null) {
2263 continue;
2264 }
2265 this._annotation = annotation;
2266 // @CustomTag
2267 if (_isAnnotation(annotation, _CUSTOM_TAG)) {
2268 _parseCustomTag();
2269 continue;
2270 }
2271 }
2272 }
2273 }
2274 }
2275
2276 /**
2277 * Checks if given [Annotation] is an annotation with required name.
2278 */
2279 bool _isAnnotation(Annotation annotation, String name) {
2280 Element element = annotation.element;
2281 if (element is ConstructorElement) {
2282 ConstructorElement constructorElement = element;
2283 return constructorElement.returnType.displayName == name;
2284 }
2285 return false;
2286 }
2287
2288 void _parseCustomTag() {
2289 List<Expression> arguments = _annotation.arguments.arguments;
2290 if (arguments.length == 1) {
2291 Expression nameExpression = arguments[0];
2292 if (nameExpression is SimpleStringLiteral) {
2293 SimpleStringLiteral nameLiteral = nameExpression;
2294 String name = nameLiteral.value;
2295 int nameOffset = nameLiteral.valueOffset;
2296 PolymerTagDartElementImpl element = new PolymerTagDartElementImpl(name, nameOffset, _classElement);
2297 _classElement.addToolkitObjects(element);
2298 nameLiteral.toolkitElement = element;
2299 }
2300 }
2301 }
2302 }
2303
2304 /**
2209 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 2305 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
2210 * violations of Dart best practices. 2306 * violations of Dart best practices.
2211 */ 2307 */
2212 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { 2308 class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
2213 static String _GETTER = "getter";
2214
2215 static String _HASHCODE_GETTER_NAME = "hashCode"; 2309 static String _HASHCODE_GETTER_NAME = "hashCode";
2216 2310
2217 static String _METHOD = "method";
2218
2219 static String _NULL_TYPE_NAME = "Null"; 2311 static String _NULL_TYPE_NAME = "Null";
2220 2312
2221 static String _SETTER = "setter";
2222
2223 static String _TO_INT_METHOD_NAME = "toInt"; 2313 static String _TO_INT_METHOD_NAME = "toInt";
2224 2314
2225 /** 2315 /**
2226 * Given a parenthesized expression, this returns the parent (or recursively g rand-parent) of the 2316 * Given a parenthesized expression, this returns the parent (or recursively g rand-parent) of the
2227 * expression that is a parenthesized expression, but whose parent is not a pa renthesized 2317 * expression that is a parenthesized expression, but whose parent is not a pa renthesized
2228 * expression. 2318 * expression.
2229 * 2319 *
2230 * For example given the code `(((e)))`: `(e) -> (((e)))`. 2320 * For example given the code `(((e)))`: `(e) -> (((e)))`.
2231 * 2321 *
2232 * @param parenthesizedExpression some expression whose parent is a parenthesi zed expression 2322 * @param parenthesizedExpression some expression whose parent is a parenthesi zed expression
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 2356
2267 @override 2357 @override
2268 Object visitAsExpression(AsExpression node) { 2358 Object visitAsExpression(AsExpression node) {
2269 _checkForUnnecessaryCast(node); 2359 _checkForUnnecessaryCast(node);
2270 return super.visitAsExpression(node); 2360 return super.visitAsExpression(node);
2271 } 2361 }
2272 2362
2273 @override 2363 @override
2274 Object visitAssignmentExpression(AssignmentExpression node) { 2364 Object visitAssignmentExpression(AssignmentExpression node) {
2275 sc.TokenType operatorType = node.operator.type; 2365 sc.TokenType operatorType = node.operator.type;
2276 if (operatorType != sc.TokenType.EQ) { 2366 if (operatorType == sc.TokenType.EQ) {
2367 _checkForUseOfVoidResult(node.rightHandSide);
2368 _checkForInvalidAssignment(node.leftHandSide, node.rightHandSide);
2369 } else {
2277 _checkForDeprecatedMemberUse(node.bestElement, node); 2370 _checkForDeprecatedMemberUse(node.bestElement, node);
2278 } else {
2279 _checkForUseOfVoidResult(node.rightHandSide);
2280 } 2371 }
2281 return super.visitAssignmentExpression(node); 2372 return super.visitAssignmentExpression(node);
2282 } 2373 }
2283 2374
2284 @override 2375 @override
2285 Object visitBinaryExpression(BinaryExpression node) { 2376 Object visitBinaryExpression(BinaryExpression node) {
2286 _checkForDivisionOptimizationHint(node); 2377 _checkForDivisionOptimizationHint(node);
2287 _checkForDeprecatedMemberUse(node.bestElement, node); 2378 _checkForDeprecatedMemberUse(node.bestElement, node);
2288 return super.visitBinaryExpression(node); 2379 return super.visitBinaryExpression(node);
2289 } 2380 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 2462
2372 @override 2463 @override
2373 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 2464 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2374 _checkForDeprecatedMemberUse(node.staticElement, node); 2465 _checkForDeprecatedMemberUse(node.staticElement, node);
2375 return super.visitSuperConstructorInvocation(node); 2466 return super.visitSuperConstructorInvocation(node);
2376 } 2467 }
2377 2468
2378 @override 2469 @override
2379 Object visitVariableDeclaration(VariableDeclaration node) { 2470 Object visitVariableDeclaration(VariableDeclaration node) {
2380 _checkForUseOfVoidResult(node.initializer); 2471 _checkForUseOfVoidResult(node.initializer);
2472 _checkForInvalidAssignment(node.name, node.initializer);
2381 return super.visitVariableDeclaration(node); 2473 return super.visitVariableDeclaration(node);
2382 } 2474 }
2383 2475
2384 /** 2476 /**
2385 * Check for the passed is expression for the unnecessary type check hint code s as well as null 2477 * Check for the passed is expression for the unnecessary type check hint code s as well as null
2386 * checks expressed using an is expression. 2478 * checks expressed using an is expression.
2387 * 2479 *
2388 * @param node the is expression to check 2480 * @param node the is expression to check
2389 * @return `true` if and only if a hint code is generated on the passed node 2481 * @return `true` if and only if a hint code is generated on the passed node
2390 * @see HintCode#TYPE_CHECK_IS_NOT_NULL 2482 * @see HintCode#TYPE_CHECK_IS_NOT_NULL
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2616 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv ocation.argumentList.arguments.isEmpty) { 2708 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv ocation.argumentList.arguments.isEmpty) {
2617 _errorReporter.reportErrorForNode(HintCode.DIVISION_OPTIMIZATION, meth odInvocation, []); 2709 _errorReporter.reportErrorForNode(HintCode.DIVISION_OPTIMIZATION, meth odInvocation, []);
2618 return true; 2710 return true;
2619 } 2711 }
2620 } 2712 }
2621 } 2713 }
2622 return false; 2714 return false;
2623 } 2715 }
2624 2716
2625 /** 2717 /**
2718 * This verifies that the passed left hand side and right hand side represent a valid assignment.
2719 *
2720 * This method corresponds to ErrorVerifier.checkForInvalidAssignment.
2721 *
2722 * @param lhs the left hand side expression
2723 * @param rhs the right hand side expression
2724 * @return `true` if and only if an error code is generated on the passed node
2725 * @see HintCode#INVALID_ASSIGNMENT
2726 */
2727 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) {
2728 if (lhs == null || rhs == null) {
2729 return false;
2730 }
2731 VariableElement leftElement = ErrorVerifier.getVariableElement(lhs);
2732 DartType leftType = (leftElement == null) ? ErrorVerifier.getStaticType(lhs) : leftElement.type;
2733 DartType staticRightType = ErrorVerifier.getStaticType(rhs);
2734 if (!staticRightType.isAssignableTo(leftType)) {
2735 // The warning was generated on this rhs
2736 return false;
2737 }
2738 // Test for, and then generate the hint
2739 DartType bestRightType = rhs.bestType;
2740 if (leftType != null && bestRightType != null) {
2741 if (!bestRightType.isAssignableTo(leftType)) {
2742 String leftName = leftType.displayName;
2743 String rightName = bestRightType.displayName;
2744 if (leftName == rightName) {
2745 leftName = ErrorVerifier.getExtendedDisplayName(leftType);
2746 rightName = ErrorVerifier.getExtendedDisplayName(bestRightType);
2747 }
2748 _errorReporter.reportErrorForNode(HintCode.INVALID_ASSIGNMENT, rhs, [rig htName, leftName]);
2749 return true;
2750 }
2751 }
2752 return false;
2753 }
2754
2755 /**
2626 * Generate a hint for functions or methods that have a return type, but do no t have a return 2756 * Generate a hint for functions or methods that have a return type, but do no t have a return
2627 * statement on all branches. At the end of blocks with no return, Dart implic itly returns 2757 * statement on all branches. At the end of blocks with no return, Dart implic itly returns
2628 * `null`, avoiding these implicit returns is considered a best practice. 2758 * `null`, avoiding these implicit returns is considered a best practice.
2629 * 2759 *
2630 * @param node the binary expression to check 2760 * @param node the binary expression to check
2631 * @param body the function body 2761 * @param body the function body
2632 * @return `true` if and only if a hint code is generated on the passed node 2762 * @return `true` if and only if a hint code is generated on the passed node
2633 * @see HintCode#MISSING_RETURN 2763 * @see HintCode#MISSING_RETURN
2634 */ 2764 */
2635 bool _checkForMissingReturn(TypeName returnType, FunctionBody body) { 2765 bool _checkForMissingReturn(TypeName returnType, FunctionBody body) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2673 PropertyAccessorElement hashCodeElement = classElement.getGetter(_HASHCODE _GETTER_NAME); 2803 PropertyAccessorElement hashCodeElement = classElement.getGetter(_HASHCODE _GETTER_NAME);
2674 if (hashCodeElement == null) { 2804 if (hashCodeElement == null) {
2675 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_ CODE, node.name, [classElement.displayName]); 2805 _errorReporter.reportErrorForNode(HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_ CODE, node.name, [classElement.displayName]);
2676 return true; 2806 return true;
2677 } 2807 }
2678 } 2808 }
2679 return false; 2809 return false;
2680 } 2810 }
2681 2811
2682 /** 2812 /**
2683 * Checks that if the passed method declaration is private, it does not overri de a private member
2684 * in a superclass.
2685 *
2686 * @param node the method declaration to check
2687 * @return `true` if and only if a hint code is generated on the passed node
2688 * @see HintCode#OVERRIDDING_PRIVATE_MEMBER
2689 */
2690 bool _checkForOverridingPrivateMember(MethodDeclaration node) {
2691 // If not in an enclosing class, return false
2692 if (_enclosingClass == null) {
2693 return false;
2694 }
2695 // If the member is not private, return false
2696 if (!Identifier.isPrivateName(node.name.name)) {
2697 return false;
2698 }
2699 // Get the element of the member, if null, return false
2700 ExecutableElement executableElement = node.element;
2701 if (executableElement == null) {
2702 return false;
2703 }
2704 // Loop through all of the superclasses looking for a matching method or acc essor
2705 // TODO(jwren) If the HintGenerator needs or has easy access to the Inherita nceManager in the
2706 // future then this could be refactored down to be more readable, however, s ince we are only
2707 // looking through super classes (and not the entire interface graph) there is no pressing need
2708 String elementName = executableElement.name;
2709 bool isGetterOrSetter = executableElement is PropertyAccessorElement;
2710 InterfaceType superType = _enclosingClass.supertype;
2711 if (superType == null) {
2712 return false;
2713 }
2714 ClassElement classElement = superType.element;
2715 while (classElement != null) {
2716 if (_enclosingClass.library != classElement.library) {
2717 if (isGetterOrSetter) {
2718 PropertyAccessorElement overriddenAccessor = null;
2719 List<PropertyAccessorElement> accessors = classElement.accessors;
2720 for (PropertyAccessorElement propertyAccessorElement in accessors) {
2721 if (elementName == propertyAccessorElement.name) {
2722 overriddenAccessor = propertyAccessorElement;
2723 break;
2724 }
2725 }
2726 if (overriddenAccessor != null) {
2727 String memberType = (executableElement as PropertyAccessorElement).i sGetter ? _GETTER : _SETTER;
2728 _errorReporter.reportErrorForNode(HintCode.OVERRIDDING_PRIVATE_MEMBE R, node.name, [
2729 memberType,
2730 executableElement.displayName,
2731 classElement.displayName]);
2732 return true;
2733 }
2734 } else {
2735 MethodElement overriddenMethod = classElement.getMethod(elementName);
2736 if (overriddenMethod != null) {
2737 _errorReporter.reportErrorForNode(HintCode.OVERRIDDING_PRIVATE_MEMBE R, node.name, [
2738 _METHOD,
2739 executableElement.displayName,
2740 classElement.displayName]);
2741 return true;
2742 }
2743 }
2744 }
2745 superType = classElement.supertype;
2746 classElement = superType != null ? superType.element : null;
2747 }
2748 return false;
2749 }
2750
2751 /**
2752 * Check for the passed as expression for the [HintCode#UNNECESSARY_CAST] hint code. 2813 * Check for the passed as expression for the [HintCode#UNNECESSARY_CAST] hint code.
2753 * 2814 *
2754 * @param node the as expression to check 2815 * @param node the as expression to check
2755 * @return `true` if and only if a hint code is generated on the passed node 2816 * @return `true` if and only if a hint code is generated on the passed node
2756 * @see HintCode#UNNECESSARY_CAST 2817 * @see HintCode#UNNECESSARY_CAST
2757 */ 2818 */
2758 bool _checkForUnnecessaryCast(AsExpression node) { 2819 bool _checkForUnnecessaryCast(AsExpression node) {
2759 Expression expression = node.expression; 2820 Expression expression = node.expression;
2760 TypeName typeName = node.type; 2821 TypeName typeName = node.type;
2761 DartType lhsType = expression.staticType; 2822 DartType lhsType = expression.staticType;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2993 CatchClause catchClause = catchClauses[i]; 3054 CatchClause catchClause = catchClauses[i];
2994 if (catchClause.onKeyword != null) { 3055 if (catchClause.onKeyword != null) {
2995 // on-catch clause found, verify that the exception type is not a subtyp e of a previous 3056 // on-catch clause found, verify that the exception type is not a subtyp e of a previous
2996 // on-catch exception type 3057 // on-catch exception type
2997 TypeName typeName = catchClause.exceptionType; 3058 TypeName typeName = catchClause.exceptionType;
2998 if (typeName != null && typeName.type != null) { 3059 if (typeName != null && typeName.type != null) {
2999 DartType currentType = typeName.type; 3060 DartType currentType = typeName.type;
3000 if (currentType.isObject) { 3061 if (currentType.isObject) {
3001 // Found catch clause clause that has Object as an exception type, t his is equivalent to 3062 // Found catch clause clause that has Object as an exception type, t his is equivalent to
3002 // having a catch clause that doesn't have an exception type, visit the block, but 3063 // having a catch clause that doesn't have an exception type, visit the block, but
3003 // generate an error on any following catch clauses (and don't visi t them). 3064 // generate an error on any following catch clauses (and don't visit them).
3004 _safelyVisit(catchClause); 3065 _safelyVisit(catchClause);
3005 if (i + 1 != numOfCatchClauses) { 3066 if (i + 1 != numOfCatchClauses) {
3006 // this catch clause is not the last in the try statement 3067 // this catch clause is not the last in the try statement
3007 CatchClause nextCatchClause = catchClauses[i + 1]; 3068 CatchClause nextCatchClause = catchClauses[i + 1];
3008 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 3069 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
3009 int offset = nextCatchClause.offset; 3070 int offset = nextCatchClause.offset;
3010 int length = lastCatchClause.end - offset; 3071 int length = lastCatchClause.end - offset;
3011 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLO WING_CATCH, offset, length, []); 3072 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLO WING_CATCH, offset, length, []);
3012 return null; 3073 return null;
3013 } 3074 }
3014 } 3075 }
3015 for (DartType type in visitedTypes) { 3076 for (DartType type in visitedTypes) {
3016 if (currentType.isSubtypeOf(type)) { 3077 if (currentType.isSubtypeOf(type)) {
3017 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 3078 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
3018 int offset = catchClause.offset; 3079 int offset = catchClause.offset;
3019 int length = lastCatchClause.end - offset; 3080 int length = lastCatchClause.end - offset;
3020 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_ON_CATCH_SU BTYPE, offset, length, [currentType.displayName, type.displayName]); 3081 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_ON_CATCH_SU BTYPE, offset, length, [currentType.displayName, type.displayName]);
3021 return null; 3082 return null;
3022 } 3083 }
3023 } 3084 }
3024 visitedTypes.add(currentType); 3085 visitedTypes.add(currentType);
3025 } 3086 }
3026 _safelyVisit(catchClause); 3087 _safelyVisit(catchClause);
3027 } else { 3088 } else {
3028 // Found catch clause clause that doesn't have an exception type, visit the block, but 3089 // Found catch clause clause that doesn't have an exception type, visit the block, but
3029 // generate an error on any following catch clauses (and don't visit the m). 3090 // generate an error on any following catch clauses (and don't visit the m).
3030 _safelyVisit(catchClause); 3091 _safelyVisit(catchClause);
3031 if (i + 1 != numOfCatchClauses) { 3092 if (i + 1 != numOfCatchClauses) {
3032 // this catch clause is not the last in the try statement 3093 // this catch clause is not the last in the try statement
3033 CatchClause nextCatchClause = catchClauses[i + 1]; 3094 CatchClause nextCatchClause = catchClauses[i + 1];
3034 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 3095 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
3035 int offset = nextCatchClause.offset; 3096 int offset = nextCatchClause.offset;
3036 int length = lastCatchClause.end - offset; 3097 int length = lastCatchClause.end - offset;
3037 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLOWING _CATCH, offset, length, []); 3098 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE_CATCH_FOLLOWING _CATCH, offset, length, []);
3038 return null; 3099 return null;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 ValidResult _getConstantBooleanValue(Expression expression) { 3134 ValidResult _getConstantBooleanValue(Expression expression) {
3074 if (expression is BooleanLiteral) { 3135 if (expression is BooleanLiteral) {
3075 if (expression.value) { 3136 if (expression.value) {
3076 return new ValidResult(new DartObjectImpl(null, BoolState.from(true))); 3137 return new ValidResult(new DartObjectImpl(null, BoolState.from(true)));
3077 } else { 3138 } else {
3078 return new ValidResult(new DartObjectImpl(null, BoolState.from(false))); 3139 return new ValidResult(new DartObjectImpl(null, BoolState.from(false)));
3079 } 3140 }
3080 } 3141 }
3081 // Don't consider situations where we could evaluate to a constant boolean e xpression with the 3142 // Don't consider situations where we could evaluate to a constant boolean e xpression with the
3082 // ConstantVisitor 3143 // ConstantVisitor
3083 // 3144 // else {
3084 // else { 3145 // EvaluationResultImpl result = expression.accept(new ConstantVisitor( ));
3085 // 3146 // if (result == ValidResult.RESULT_TRUE) {
3086 // EvaluationResultImpl result = expression.accept(new ConstantVisitor( )); 3147 // return ValidResult.RESULT_TRUE;
3087 // 3148 // } else if (result == ValidResult.RESULT_FALSE) {
3088 // if (result == ValidResult.RESULT_TRUE) { 3149 // return ValidResult.RESULT_FALSE;
3089 // 3150 // }
3090 // return ValidResult.RESULT_TRUE; 3151 // return null;
3091 // 3152 // }
3092 // } else if (result == ValidResult.RESULT_FALSE) {
3093 //
3094 // return ValidResult.RESULT_FALSE;
3095 //
3096 // }
3097 //
3098 // return null;
3099 //
3100 // }
3101 return null; 3153 return null;
3102 } 3154 }
3103 3155
3104 /** 3156 /**
3105 * Return `true` if and only if the passed expression is resolved to a constan t variable. 3157 * Return `true` if and only if the passed expression is resolved to a constan t variable.
3106 * 3158 *
3107 * @param expression some conditional expression 3159 * @param expression some conditional expression
3108 * @return `true` if and only if the passed expression is resolved to a consta nt variable 3160 * @return `true` if and only if the passed expression is resolved to a consta nt variable
3109 */ 3161 */
3110 bool _isDebugConstant(Expression expression) { 3162 bool _isDebugConstant(Expression expression) {
(...skipping 5463 matching lines...) Expand 10 before | Expand all | Expand 10 after
8574 } 8626 }
8575 if (!alreadyInList) { 8627 if (!alreadyInList) {
8576 list.add(newExecutableElementEntry); 8628 list.add(newExecutableElementEntry);
8577 } 8629 }
8578 } 8630 }
8579 } 8631 }
8580 } 8632 }
8581 // 8633 //
8582 // Loop through the entries in the unionMap, adding them to the resultMap ap propriately. 8634 // Loop through the entries in the unionMap, adding them to the resultMap ap propriately.
8583 // 8635 //
8584 for (MapEntry<String, List<ExecutableElement>> entry in getMapEntrySet(union Map)) { 8636 for (MapIterator<String, List<ExecutableElement>> iter = SingleMapIterator.f orMap(unionMap); iter.moveNext();) {
8585 String key = entry.getKey(); 8637 String key = iter.key;
8586 List<ExecutableElement> list = entry.getValue(); 8638 List<ExecutableElement> list = iter.value;
8587 int numOfEltsWithMatchingNames = list.length; 8639 int numOfEltsWithMatchingNames = list.length;
8588 if (numOfEltsWithMatchingNames == 1) { 8640 if (numOfEltsWithMatchingNames == 1) {
8589 // 8641 //
8590 // Example: class A inherits only 1 method named 'm'. Since it is the o nly such method, it 8642 // Example: class A inherits only 1 method named 'm'. Since it is the o nly such method, it
8591 // is inherited. 8643 // is inherited.
8592 // Another example: class A inherits 2 methods named 'm' from 2 differen t interfaces, but 8644 // Another example: class A inherits 2 methods named 'm' from 2 differen t interfaces, but
8593 // they both have the same signature, so it is the method inherited. 8645 // they both have the same signature, so it is the method inherited.
8594 // 8646 //
8595 resultMap.put(key, list[0]); 8647 resultMap.put(key, list[0]);
8596 } else { 8648 } else {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
8652 // 8704 //
8653 // Example: class A inherited only 2 method named 'm'. One has the f unction type 8705 // Example: class A inherited only 2 method named 'm'. One has the f unction type
8654 // '() -> dynamic' and one has the function type '([int]) -> dynamic '. Since the second 8706 // '() -> dynamic' and one has the function type '([int]) -> dynamic '. Since the second
8655 // method is a subtype of all the others, it is the inherited method . 8707 // method is a subtype of all the others, it is the inherited method .
8656 // Tests: InheritanceManagerTest.test_getMapOfMembersInheritedFromIn terfaces_union_oneSubtype_* 8708 // Tests: InheritanceManagerTest.test_getMapOfMembersInheritedFromIn terfaces_union_oneSubtype_*
8657 // 8709 //
8658 resultMap.put(key, elements[subtypesOfAllOtherTypesIndexes[0]]); 8710 resultMap.put(key, elements[subtypesOfAllOtherTypesIndexes[0]]);
8659 } else { 8711 } else {
8660 if (subtypesOfAllOtherTypesIndexes.isEmpty) { 8712 if (subtypesOfAllOtherTypesIndexes.isEmpty) {
8661 // 8713 //
8714 // Determine if the current class has a method or accessor with th e member name, if it
8715 // does then then this class does not "inherit" from any of the su pertypes.
8716 // See issue 16134.
8717 //
8718 bool classHasMember = false;
8719 if (allMethods) {
8720 classHasMember = classElt.getMethod(key) != null;
8721 } else {
8722 List<PropertyAccessorElement> accessors = classElt.accessors;
8723 for (int i = 0; i < accessors.length; i++) {
8724 if (accessors[i].name == key) {
8725 classHasMember = true;
8726 }
8727 }
8728 }
8729 //
8662 // Example: class A inherited only 2 method named 'm'. One has the function type 8730 // Example: class A inherited only 2 method named 'm'. One has the function type
8663 // '() -> int' and one has the function type '() -> String'. Since neither is a subtype 8731 // '() -> int' and one has the function type '() -> String'. Since neither is a subtype
8664 // of the other, we create a warning, and have this class inherit nothing. 8732 // of the other, we create a warning, and have this class inherit nothing.
8665 // 8733 //
8666 String firstTwoFuntionTypesStr = "${executableElementTypes[0].toSt ring()}, ${executableElementTypes[1].toString()}"; 8734 if (!classHasMember) {
8667 _reportError(classElt, classElt.nameOffset, classElt.displayName.l ength, StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, [key, firstTwoFunt ionTypesStr]); 8735 String firstTwoFuntionTypesStr = "${executableElementTypes[0].to String()}, ${executableElementTypes[1].toString()}";
8736 _reportError(classElt, classElt.nameOffset, classElt.displayName .length, StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, [key, firstTwoFu ntionTypesStr]);
8737 }
8668 } else { 8738 } else {
8669 // 8739 //
8670 // Example: class A inherits 2 methods named 'm'. One has the func tion type 8740 // Example: class A inherits 2 methods named 'm'. One has the func tion type
8671 // '(int) -> dynamic' and one has the function type '(num) -> dyna mic'. Since they are 8741 // '(int) -> dynamic' and one has the function type '(num) -> dyna mic'. Since they are
8672 // both a subtype of the other, a synthetic function '(dynamic) -> dynamic' is 8742 // both a subtype of the other, a synthetic function '(dynamic) -> dynamic' is
8673 // inherited. 8743 // inherited.
8674 // Tests: test_getMapOfMembersInheritedFromInterfaces_union_multip leSubtypes_* 8744 // Tests: test_getMapOfMembersInheritedFromInterfaces_union_multip leSubtypes_*
8675 // 8745 //
8676 List<ExecutableElement> elementArrayToMerge = new List<ExecutableE lement>(subtypesOfAllOtherTypesIndexes.length); 8746 List<ExecutableElement> elementArrayToMerge = new List<ExecutableE lement>(subtypesOfAllOtherTypesIndexes.length);
8677 for (int i = 0; i < elementArrayToMerge.length; i++) { 8747 for (int i = 0; i < elementArrayToMerge.length; i++) {
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
9718 Source importedSource = importDirective.source; 9788 Source importedSource = importDirective.source;
9719 if (importedSource != null) { 9789 if (importedSource != null) {
9720 // The imported source will be null if the URI in the import directi ve was invalid. 9790 // The imported source will be null if the URI in the import directi ve was invalid.
9721 Library importedLibrary = _libraryMap[importedSource]; 9791 Library importedLibrary = _libraryMap[importedSource];
9722 if (importedLibrary != null) { 9792 if (importedLibrary != null) {
9723 ImportElementImpl importElement = new ImportElementImpl(directive. offset); 9793 ImportElementImpl importElement = new ImportElementImpl(directive. offset);
9724 StringLiteral uriLiteral = importDirective.uri; 9794 StringLiteral uriLiteral = importDirective.uri;
9725 importElement.uriOffset = uriLiteral.offset; 9795 importElement.uriOffset = uriLiteral.offset;
9726 importElement.uriEnd = uriLiteral.end; 9796 importElement.uriEnd = uriLiteral.end;
9727 importElement.uri = uriContent; 9797 importElement.uri = uriContent;
9798 importElement.deferred = importDirective.deferredToken != null;
9728 importElement.combinators = _buildCombinators(importDirective); 9799 importElement.combinators = _buildCombinators(importDirective);
9729 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment; 9800 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment;
9730 if (importedLibraryElement != null) { 9801 if (importedLibraryElement != null) {
9731 importElement.importedLibrary = importedLibraryElement; 9802 importElement.importedLibrary = importedLibraryElement;
9732 } 9803 }
9733 SimpleIdentifier prefixNode = directive.prefix; 9804 SimpleIdentifier prefixNode = directive.prefix;
9734 if (prefixNode != null) { 9805 if (prefixNode != null) {
9735 importElement.prefixOffset = prefixNode.offset; 9806 importElement.prefixOffset = prefixNode.offset;
9736 String prefixName = prefixNode.name; 9807 String prefixName = prefixNode.name;
9737 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; 9808 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
10067 // Angular 10138 // Angular
10068 timeCounter = PerformanceStatistics.angular.start(); 10139 timeCounter = PerformanceStatistics.angular.start();
10069 try { 10140 try {
10070 for (Source source in library.compilationUnitSources) { 10141 for (Source source in library.compilationUnitSources) {
10071 CompilationUnit ast = library.getAST(source); 10142 CompilationUnit ast = library.getAST(source);
10072 new AngularCompilationUnitBuilder(_errorListener, source, ast).build(); 10143 new AngularCompilationUnitBuilder(_errorListener, source, ast).build();
10073 } 10144 }
10074 } finally { 10145 } finally {
10075 timeCounter.stop(); 10146 timeCounter.stop();
10076 } 10147 }
10148 // Polymer
10149 timeCounter = PerformanceStatistics.polymer.start();
10150 try {
10151 for (Source source in library.compilationUnitSources) {
10152 CompilationUnit ast = library.getAST(source);
10153 new PolymerCompilationUnitBuilder(ast).build();
10154 }
10155 } finally {
10156 timeCounter.stop();
10157 }
10077 } 10158 }
10078 10159
10079 /** 10160 /**
10080 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 10161 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
10081 * given library, or `null` if the URI is not valid. 10162 * given library, or `null` if the URI is not valid.
10082 * 10163 *
10083 * @param librarySource the source representing the library containing the dir ective 10164 * @param librarySource the source representing the library containing the dir ective
10084 * @param directive the directive which URI should be resolved 10165 * @param directive the directive which URI should be resolved
10085 * @return the result of resolving the URI against the URI of the library 10166 * @return the result of resolving the URI against the URI of the library
10086 */ 10167 */
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
10289 // The imported source will be null if the URI in the import directi ve was invalid. 10370 // The imported source will be null if the URI in the import directi ve was invalid.
10290 ResolvableLibrary importedLibrary = _libraryMap[importedSource]; 10371 ResolvableLibrary importedLibrary = _libraryMap[importedSource];
10291 if (importedLibrary != null) { 10372 if (importedLibrary != null) {
10292 ImportElementImpl importElement = new ImportElementImpl(directive. offset); 10373 ImportElementImpl importElement = new ImportElementImpl(directive. offset);
10293 StringLiteral uriLiteral = importDirective.uri; 10374 StringLiteral uriLiteral = importDirective.uri;
10294 if (uriLiteral != null) { 10375 if (uriLiteral != null) {
10295 importElement.uriOffset = uriLiteral.offset; 10376 importElement.uriOffset = uriLiteral.offset;
10296 importElement.uriEnd = uriLiteral.end; 10377 importElement.uriEnd = uriLiteral.end;
10297 } 10378 }
10298 importElement.uri = uriContent; 10379 importElement.uri = uriContent;
10380 importElement.deferred = importDirective.deferredToken != null;
10299 importElement.combinators = _buildCombinators(importDirective); 10381 importElement.combinators = _buildCombinators(importDirective);
10300 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment; 10382 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment;
10301 if (importedLibraryElement != null) { 10383 if (importedLibraryElement != null) {
10302 importElement.importedLibrary = importedLibraryElement; 10384 importElement.importedLibrary = importedLibraryElement;
10303 } 10385 }
10304 SimpleIdentifier prefixNode = directive.prefix; 10386 SimpleIdentifier prefixNode = directive.prefix;
10305 if (prefixNode != null) { 10387 if (prefixNode != null) {
10306 importElement.prefixOffset = prefixNode.offset; 10388 importElement.prefixOffset = prefixNode.offset;
10307 String prefixName = prefixNode.name; 10389 String prefixName = prefixNode.name;
10308 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; 10390 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
10498 timeCounter = PerformanceStatistics.angular.start(); 10580 timeCounter = PerformanceStatistics.angular.start();
10499 try { 10581 try {
10500 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) { 10582 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) {
10501 Source source = unit.source; 10583 Source source = unit.source;
10502 CompilationUnit ast = unit.compilationUnit; 10584 CompilationUnit ast = unit.compilationUnit;
10503 new AngularCompilationUnitBuilder(_errorListener, source, ast).build(); 10585 new AngularCompilationUnitBuilder(_errorListener, source, ast).build();
10504 } 10586 }
10505 } finally { 10587 } finally {
10506 timeCounter.stop(); 10588 timeCounter.stop();
10507 } 10589 }
10590 // Polymer
10591 timeCounter = PerformanceStatistics.polymer.start();
10592 try {
10593 for (Source source in library.compilationUnitSources) {
10594 CompilationUnit ast = library.getAST(source);
10595 new PolymerCompilationUnitBuilder(ast).build();
10596 }
10597 } finally {
10598 timeCounter.stop();
10599 }
10508 } 10600 }
10509 } 10601 }
10510 10602
10511 /** 10603 /**
10512 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as 10604 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as
10513 * performant as this class. 10605 * performant as this class.
10514 */ 10606 */
10515 class MemberMap { 10607 class MemberMap {
10516 /** 10608 /**
10517 * The current size of this map. 10609 * The current size of this map.
(...skipping 4377 matching lines...) Expand 10 before | Expand all | Expand 10 after
14895 * @param outerScope the outer scope in which types might be overridden 14987 * @param outerScope the outer scope in which types might be overridden
14896 */ 14988 */
14897 TypeOverrideManager_TypeOverrideScope(this._outerScope); 14989 TypeOverrideManager_TypeOverrideScope(this._outerScope);
14898 14990
14899 /** 14991 /**
14900 * Apply a set of overrides that were previously captured. 14992 * Apply a set of overrides that were previously captured.
14901 * 14993 *
14902 * @param overrides the overrides to be applied 14994 * @param overrides the overrides to be applied
14903 */ 14995 */
14904 void applyOverrides(Map<Element, DartType> overrides) { 14996 void applyOverrides(Map<Element, DartType> overrides) {
14905 for (MapEntry<Element, DartType> entry in getMapEntrySet(overrides)) { 14997 for (MapIterator<Element, DartType> iter = SingleMapIterator.forMap(override s); iter.moveNext();) {
14906 _overridenTypes[entry.getKey()] = entry.getValue(); 14998 _overridenTypes[iter.key] = iter.value;
14907 } 14999 }
14908 } 15000 }
14909 15001
14910 /** 15002 /**
14911 * Return a table mapping the elements whose type is overridden in the current scope to the 15003 * Return a table mapping the elements whose type is overridden in the current scope to the
14912 * overriding type. 15004 * overriding type.
14913 * 15005 *
14914 * @return the overrides in the current scope 15006 * @return the overrides in the current scope
14915 */ 15007 */
14916 Map<Element, DartType> captureLocalOverrides() => _overridenTypes; 15008 Map<Element, DartType> captureLocalOverrides() => _overridenTypes;
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after
17246 return new Namespace(definedNames); 17338 return new Namespace(definedNames);
17247 } 17339 }
17248 17340
17249 /** 17341 /**
17250 * Add all of the names in the given namespace to the given mapping table. 17342 * Add all of the names in the given namespace to the given mapping table.
17251 * 17343 *
17252 * @param definedNames the mapping table to which the names in the given names pace are to be added 17344 * @param definedNames the mapping table to which the names in the given names pace are to be added
17253 * @param namespace the namespace containing the names to be added to this nam espace 17345 * @param namespace the namespace containing the names to be added to this nam espace
17254 */ 17346 */
17255 void _addAllFromMap(Map<String, Element> definedNames, Map<String, Element> ne wNames) { 17347 void _addAllFromMap(Map<String, Element> definedNames, Map<String, Element> ne wNames) {
17256 for (MapEntry<String, Element> entry in getMapEntrySet(newNames)) { 17348 for (MapIterator<String, Element> iter = SingleMapIterator.forMap(newNames); iter.moveNext();) {
17257 definedNames[entry.getKey()] = entry.getValue(); 17349 definedNames[iter.key] = iter.value;
17258 } 17350 }
17259 } 17351 }
17260 17352
17261 /** 17353 /**
17262 * Add all of the names in the given namespace to the given mapping table. 17354 * Add all of the names in the given namespace to the given mapping table.
17263 * 17355 *
17264 * @param definedNames the mapping table to which the names in the given names pace are to be added 17356 * @param definedNames the mapping table to which the names in the given names pace are to be added
17265 * @param namespace the namespace containing the names to be added to this nam espace 17357 * @param namespace the namespace containing the names to be added to this nam espace
17266 */ 17358 */
17267 void _addAllFromNamespace(Map<String, Element> definedNames, Namespace namespa ce) { 17359 void _addAllFromNamespace(Map<String, Element> definedNames, Namespace namespa ce) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
17329 /** 17421 /**
17330 * Apply the given prefix to all of the names in the table of defined names. 17422 * Apply the given prefix to all of the names in the table of defined names.
17331 * 17423 *
17332 * @param definedNames the names that were defined before this operation 17424 * @param definedNames the names that were defined before this operation
17333 * @param prefixElement the element defining the prefix to be added to the nam es 17425 * @param prefixElement the element defining the prefix to be added to the nam es
17334 */ 17426 */
17335 Map<String, Element> _applyPrefix(Map<String, Element> definedNames, PrefixEle ment prefixElement) { 17427 Map<String, Element> _applyPrefix(Map<String, Element> definedNames, PrefixEle ment prefixElement) {
17336 if (prefixElement != null) { 17428 if (prefixElement != null) {
17337 String prefix = prefixElement.name; 17429 String prefix = prefixElement.name;
17338 Map<String, Element> newNames = new Map<String, Element>(); 17430 Map<String, Element> newNames = new Map<String, Element>();
17339 for (MapEntry<String, Element> entry in getMapEntrySet(definedNames)) { 17431 for (MapIterator<String, Element> iter = SingleMapIterator.forMap(definedN ames); iter.moveNext();) {
17340 newNames["${prefix}.${entry.getKey()}"] = entry.getValue(); 17432 newNames["${prefix}.${iter.key}"] = iter.value;
17341 } 17433 }
17342 return newNames; 17434 return newNames;
17343 } else { 17435 } else {
17344 return definedNames; 17436 return definedNames;
17345 } 17437 }
17346 } 17438 }
17347 17439
17348 /** 17440 /**
17349 * Create a mapping table representing the export namespace of the given libra ry. 17441 * Create a mapping table representing the export namespace of the given libra ry.
17350 * 17442 *
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
18079 return super.visitSimpleIdentifier(node); 18171 return super.visitSimpleIdentifier(node);
18080 } 18172 }
18081 } 18173 }
18082 18174
18083 /** 18175 /**
18084 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional 18176 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional
18085 * errors and warnings not covered by the parser and resolver. 18177 * errors and warnings not covered by the parser and resolver.
18086 */ 18178 */
18087 class ErrorVerifier extends RecursiveAstVisitor<Object> { 18179 class ErrorVerifier extends RecursiveAstVisitor<Object> {
18088 /** 18180 /**
18181 * Return a display name for the given type that includes the path to the comp ilation unit in
18182 * which the type is defined.
18183 *
18184 * @param type the type for which an extended display name is to be returned
18185 * @return a display name that can help distiguish between two types with the same name
18186 */
18187 static String getExtendedDisplayName(DartType type) {
18188 Element element = type.element;
18189 if (element != null) {
18190 Source source = element.source;
18191 if (source != null) {
18192 return "${type.displayName} (${source.fullName})";
18193 }
18194 }
18195 return type.displayName;
18196 }
18197
18198 /**
18199 * Return the static type of the given expression that is to be used for type analysis.
18200 *
18201 * @param expression the expression whose type is to be returned
18202 * @return the static type of the given expression
18203 */
18204 static DartType getStaticType(Expression expression) {
18205 DartType type = expression.staticType;
18206 if (type == null) {
18207 // TODO(brianwilkerson) This should never happen.
18208 return DynamicTypeImpl.instance;
18209 }
18210 return type;
18211 }
18212
18213 /**
18214 * Return the variable element represented by the given expression, or `null` if there is no
18215 * such element.
18216 *
18217 * @param expression the expression whose element is to be returned
18218 * @return the variable element represented by the expression
18219 */
18220 static VariableElement getVariableElement(Expression expression) {
18221 if (expression is Identifier) {
18222 Element element = expression.staticElement;
18223 if (element is VariableElement) {
18224 return element;
18225 }
18226 }
18227 return null;
18228 }
18229
18230 /**
18089 * The error reporter by which errors will be reported. 18231 * The error reporter by which errors will be reported.
18090 */ 18232 */
18091 final ErrorReporter _errorReporter; 18233 final ErrorReporter _errorReporter;
18092 18234
18093 /** 18235 /**
18094 * The current library that is being analyzed. 18236 * The current library that is being analyzed.
18095 */ 18237 */
18096 final LibraryElement _currentLibrary; 18238 final LibraryElement _currentLibrary;
18097 18239
18098 /** 18240 /**
18099 * The type representing the type 'dynamic'.
18100 */
18101 DartType _dynamicType;
18102
18103 /**
18104 * The type representing the type 'bool'. 18241 * The type representing the type 'bool'.
18105 */ 18242 */
18106 InterfaceType _boolType; 18243 InterfaceType _boolType;
18107 18244
18108 /** 18245 /**
18109 * The type representing the type 'int'. 18246 * The type representing the type 'int'.
18110 */ 18247 */
18111 InterfaceType _intType; 18248 InterfaceType _intType;
18112 18249
18113 /** 18250 /**
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
18301 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, t his._inheritanceManager) { 18438 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, t his._inheritanceManager) {
18302 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; 18439 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary;
18303 this._hasExtUri = _currentLibrary.hasExtUri; 18440 this._hasExtUri = _currentLibrary.hasExtUri;
18304 _isEnclosingConstructorConst = false; 18441 _isEnclosingConstructorConst = false;
18305 _isInCatchClause = false; 18442 _isInCatchClause = false;
18306 _isInStaticVariableDeclaration = false; 18443 _isInStaticVariableDeclaration = false;
18307 _isInInstanceVariableDeclaration = false; 18444 _isInInstanceVariableDeclaration = false;
18308 _isInInstanceVariableInitializer = false; 18445 _isInInstanceVariableInitializer = false;
18309 _isInConstructorInitializer = false; 18446 _isInConstructorInitializer = false;
18310 _isInStaticMethod = false; 18447 _isInStaticMethod = false;
18311 _dynamicType = _typeProvider.dynamicType;
18312 _boolType = _typeProvider.boolType; 18448 _boolType = _typeProvider.boolType;
18313 _intType = _typeProvider.intType; 18449 _intType = _typeProvider.intType;
18314 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ 18450 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [
18315 _typeProvider.nullType, 18451 _typeProvider.nullType,
18316 _typeProvider.numType, 18452 _typeProvider.numType,
18317 _intType, 18453 _intType,
18318 _typeProvider.doubleType, 18454 _typeProvider.doubleType,
18319 _boolType, 18455 _boolType,
18320 _typeProvider.stringType]; 18456 _typeProvider.stringType];
18321 } 18457 }
18322 18458
18323 @override 18459 @override
18324 Object visitArgumentList(ArgumentList node) { 18460 Object visitArgumentList(ArgumentList node) {
18325 _checkForArgumentTypesNotAssignableInList(node); 18461 _checkForArgumentTypesNotAssignableInList(node);
18326 return super.visitArgumentList(node); 18462 return super.visitArgumentList(node);
18327 } 18463 }
18328 18464
18329 @override 18465 @override
18330 Object visitAssertStatement(AssertStatement node) { 18466 Object visitAssertStatement(AssertStatement node) {
18331 _checkForNonBoolExpression(node); 18467 _checkForNonBoolExpression(node);
18332 return super.visitAssertStatement(node); 18468 return super.visitAssertStatement(node);
18333 } 18469 }
18334 18470
18335 @override 18471 @override
18336 Object visitAssignmentExpression(AssignmentExpression node) { 18472 Object visitAssignmentExpression(AssignmentExpression node) {
18337 sc.Token operator = node.operator; 18473 sc.TokenType operatorType = node.operator.type;
18338 sc.TokenType operatorType = operator.type;
18339 if (operatorType == sc.TokenType.EQ) { 18474 if (operatorType == sc.TokenType.EQ) {
18340 _checkForInvalidAssignment(node.leftHandSide, node.rightHandSide); 18475 _checkForInvalidAssignment(node.leftHandSide, node.rightHandSide);
18341 } else { 18476 } else {
18342 _checkForInvalidCompoundAssignment(node); 18477 _checkForInvalidCompoundAssignment(node);
18343 } 18478 }
18344 _checkForAssignmentToFinal(node.leftHandSide); 18479 _checkForAssignmentToFinal(node.leftHandSide);
18345 _checkForArgumentTypeNotAssignableForArgument(node.rightHandSide); 18480 _checkForArgumentTypeNotAssignableForArgument(node.rightHandSide);
18346 return super.visitAssignmentExpression(node); 18481 return super.visitAssignmentExpression(node);
18347 } 18482 }
18348 18483
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
18393 _isInCatchClause = previousIsInCatchClause; 18528 _isInCatchClause = previousIsInCatchClause;
18394 } 18529 }
18395 } 18530 }
18396 18531
18397 @override 18532 @override
18398 Object visitClassDeclaration(ClassDeclaration node) { 18533 Object visitClassDeclaration(ClassDeclaration node) {
18399 ClassElement outerClass = _enclosingClass; 18534 ClassElement outerClass = _enclosingClass;
18400 try { 18535 try {
18401 _isInNativeClass = node.nativeClause != null; 18536 _isInNativeClass = node.nativeClause != null;
18402 _enclosingClass = node.element; 18537 _enclosingClass = node.element;
18538 ExtendsClause extendsClause = node.extendsClause;
18539 ImplementsClause implementsClause = node.implementsClause;
18403 WithClause withClause = node.withClause; 18540 WithClause withClause = node.withClause;
18404 ImplementsClause implementsClause = node.implementsClause;
18405 ExtendsClause extendsClause = node.extendsClause;
18406 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ IDENTIFIER_AS_TYPE_NAME); 18541 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ IDENTIFIER_AS_TYPE_NAME);
18407 _checkForMemberWithClassName(); 18542 _checkForMemberWithClassName();
18408 _checkForNoDefaultSuperConstructorImplicit(node); 18543 _checkForNoDefaultSuperConstructorImplicit(node);
18409 _checkForConflictingTypeVariableErrorCodes(node); 18544 _checkForConflictingTypeVariableErrorCodes(node);
18410 // Only do error checks on the clause nodes if there is a non-null clause 18545 // Only do error checks on the clause nodes if there is a non-null clause
18411 if (implementsClause != null || extendsClause != null || withClause != nul l) { 18546 if (implementsClause != null || extendsClause != null || withClause != nul l) {
18412 // Only check for all of the inheritance logic around clauses if there i sn't an error code 18547 // Only check for all of the inheritance logic around clauses if there i sn't an error code
18413 // such as "Cannot extend double" already on the class. 18548 // such as "Cannot extend double" already on the class.
18414 if (!_checkForImplementsDisallowedClass(implementsClause) && !_checkForE xtendsDisallowedClass(extendsClause) && !_checkForAllMixinErrorCodes(withClause) ) { 18549 if (!_checkForImplementsDisallowedClass(implementsClause) && !_checkForE xtendsDisallowedClass(extendsClause) && !_checkForAllMixinErrorCodes(withClause) ) {
18415 _checkForNonAbstractClassInheritsAbstractMember(node); 18550 _checkForNonAbstractClassInheritsAbstractMember(node.name);
18416 _checkForInconsistentMethodInheritance(); 18551 _checkForInconsistentMethodInheritance();
18417 _checkForRecursiveInterfaceInheritance(_enclosingClass); 18552 _checkForRecursiveInterfaceInheritance(_enclosingClass);
18418 _checkForConflictingGetterAndMethod(); 18553 _checkForConflictingGetterAndMethod();
18419 _checkForConflictingInstanceGetterAndSuperclassMember(); 18554 _checkForConflictingInstanceGetterAndSuperclassMember();
18420 _checkImplementsSuperClass(node); 18555 _checkImplementsSuperClass(node);
18421 _checkImplementsFunctionWithoutCall(node); 18556 _checkImplementsFunctionWithoutCall(node);
18422 } 18557 }
18423 } 18558 }
18424 // initialize initialFieldElementsMap 18559 // initialize initialFieldElementsMap
18425 ClassElement classElement = node.element; 18560 ClassElement classElement = node.element;
(...skipping 13 matching lines...) Expand all
18439 } finally { 18574 } finally {
18440 _isInNativeClass = false; 18575 _isInNativeClass = false;
18441 _initialFieldElementsMap = null; 18576 _initialFieldElementsMap = null;
18442 _enclosingClass = outerClass; 18577 _enclosingClass = outerClass;
18443 } 18578 }
18444 } 18579 }
18445 18580
18446 @override 18581 @override
18447 Object visitClassTypeAlias(ClassTypeAlias node) { 18582 Object visitClassTypeAlias(ClassTypeAlias node) {
18448 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPEDEF_NAME); 18583 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID ENTIFIER_AS_TYPEDEF_NAME);
18449 _checkForExtendsDisallowedClassInTypeAlias(node);
18450 _checkForImplementsDisallowedClass(node.implementsClause);
18451 _checkForAllMixinErrorCodes(node.withClause);
18452 ClassElement outerClassElement = _enclosingClass; 18584 ClassElement outerClassElement = _enclosingClass;
18453 try { 18585 try {
18454 _enclosingClass = node.element; 18586 _enclosingClass = node.element;
18455 _checkForRecursiveInterfaceInheritance(node.element); 18587 // Only check for all of the inheritance logic around clauses if there isn 't an error code
18456 _checkForTypeAliasCannotReferenceItself_mixin(node); 18588 // such as "Cannot extend double" already on the class.
18589 if (!_checkForExtendsDisallowedClassInTypeAlias(node) && !_checkForImpleme ntsDisallowedClass(node.implementsClause) && !_checkForAllMixinErrorCodes(node.w ithClause)) {
18590 _checkForRecursiveInterfaceInheritance(node.element);
18591 _checkForTypeAliasCannotReferenceItself_mixin(node);
18592 _checkForNonAbstractClassInheritsAbstractMember(node.name);
18593 }
18457 } finally { 18594 } finally {
18458 _enclosingClass = outerClassElement; 18595 _enclosingClass = outerClassElement;
18459 } 18596 }
18460 return super.visitClassTypeAlias(node); 18597 return super.visitClassTypeAlias(node);
18461 } 18598 }
18462 18599
18463 @override 18600 @override
18464 Object visitComment(Comment node) { 18601 Object visitComment(Comment node) {
18465 _isInComment = true; 18602 _isInComment = true;
18466 try { 18603 try {
18467 return super.visitComment(node); 18604 return super.visitComment(node);
18468 } finally { 18605 } finally {
18469 _isInComment = false; 18606 _isInComment = false;
18470 } 18607 }
18471 } 18608 }
18472 18609
18473 @override 18610 @override
18611 Object visitCompilationUnit(CompilationUnit node) {
18612 _checkForDeferredPrefixCollisions(node);
18613 return super.visitCompilationUnit(node);
18614 }
18615
18616 @override
18474 Object visitConditionalExpression(ConditionalExpression node) { 18617 Object visitConditionalExpression(ConditionalExpression node) {
18475 _checkForNonBoolCondition(node.condition); 18618 _checkForNonBoolCondition(node.condition);
18476 return super.visitConditionalExpression(node); 18619 return super.visitConditionalExpression(node);
18477 } 18620 }
18478 18621
18479 @override 18622 @override
18480 Object visitConstructorDeclaration(ConstructorDeclaration node) { 18623 Object visitConstructorDeclaration(ConstructorDeclaration node) {
18481 ExecutableElement outerFunction = _enclosingFunction; 18624 ExecutableElement outerFunction = _enclosingFunction;
18482 try { 18625 try {
18483 _enclosingFunction = node.element; 18626 _enclosingFunction = node.element;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
18664 _checkForNonBoolCondition(node.condition); 18807 _checkForNonBoolCondition(node.condition);
18665 return super.visitIfStatement(node); 18808 return super.visitIfStatement(node);
18666 } 18809 }
18667 18810
18668 @override 18811 @override
18669 Object visitImportDirective(ImportDirective node) { 18812 Object visitImportDirective(ImportDirective node) {
18670 ImportElement importElement = node.element; 18813 ImportElement importElement = node.element;
18671 if (importElement != null) { 18814 if (importElement != null) {
18672 _checkForImportDuplicateLibraryName(node, importElement); 18815 _checkForImportDuplicateLibraryName(node, importElement);
18673 _checkForImportInternalLibrary(node, importElement); 18816 _checkForImportInternalLibrary(node, importElement);
18817 if (importElement.isDeferred) {
18818 _checkForLoadLibraryFunction(node, importElement);
18819 }
18674 } 18820 }
18675 return super.visitImportDirective(node); 18821 return super.visitImportDirective(node);
18676 } 18822 }
18677 18823
18678 @override 18824 @override
18679 Object visitIndexExpression(IndexExpression node) { 18825 Object visitIndexExpression(IndexExpression node) {
18680 _checkForArgumentTypeNotAssignableForArgument(node.index); 18826 _checkForArgumentTypeNotAssignableForArgument(node.index);
18681 return super.visitIndexExpression(node); 18827 return super.visitIndexExpression(node);
18682 } 18828 }
18683 18829
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
19066 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_IN_PARAMETER_AND_INITIALIZER, fieldName, []); 19212 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_IN_PARAMETER_AND_INITIALIZER, fieldName, []);
19067 foundError = true; 19213 foundError = true;
19068 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { 19214 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) {
19069 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_BY_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); 19215 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL IZED_BY_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]);
19070 foundError = true; 19216 foundError = true;
19071 } 19217 }
19072 } 19218 }
19073 } 19219 }
19074 } 19220 }
19075 // Visit all of the states in the map to ensure that none were never initial ized. 19221 // Visit all of the states in the map to ensure that none were never initial ized.
19076 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement sMap)) { 19222 for (MapIterator<FieldElement, INIT_STATE> iter = SingleMapIterator.forMap(f ieldElementsMap); iter.moveNext();) {
19077 if (entry.getValue() == INIT_STATE.NOT_INIT) { 19223 if (iter.value == INIT_STATE.NOT_INIT) {
19078 FieldElement fieldElement = entry.getKey(); 19224 FieldElement fieldElement = iter.key;
19079 if (fieldElement.isConst) { 19225 if (fieldElement.isConst) {
19080 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_NOT_INITI ALIZED, node.returnType, [fieldElement.name]); 19226 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_NOT_INITI ALIZED, node.returnType, [fieldElement.name]);
19081 foundError = true; 19227 foundError = true;
19082 } else if (fieldElement.isFinal) { 19228 } else if (fieldElement.isFinal) {
19083 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_NOT_INITIALI ZED, node.returnType, [fieldElement.name]); 19229 _errorReporter.reportErrorForNode(StaticWarningCode.FINAL_NOT_INITIALI ZED, node.returnType, [fieldElement.name]);
19084 foundError = true; 19230 foundError = true;
19085 } 19231 }
19086 } 19232 }
19087 } 19233 }
19088 return foundError; 19234 return foundError;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
19242 if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i])) { 19388 if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i])) {
19243 _errorReporter.reportErrorForNode(StaticWarningCode.INVALID_METHOD_OVERR IDE_OPTIONAL_PARAM_TYPE, parameterLocations[parameterIndex], [ 19389 _errorReporter.reportErrorForNode(StaticWarningCode.INVALID_METHOD_OVERR IDE_OPTIONAL_PARAM_TYPE, parameterLocations[parameterIndex], [
19244 overridingPositionalPT[i].displayName, 19390 overridingPositionalPT[i].displayName,
19245 overriddenPositionalPT[i].displayName, 19391 overriddenPositionalPT[i].displayName,
19246 overriddenExecutable.enclosingElement.displayName]); 19392 overriddenExecutable.enclosingElement.displayName]);
19247 return true; 19393 return true;
19248 } 19394 }
19249 parameterIndex++; 19395 parameterIndex++;
19250 } 19396 }
19251 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & SWC.INVALID_OVERRIDE_DIFFE RENT_DEFAULT_VALUES 19397 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & SWC.INVALID_OVERRIDE_DIFFE RENT_DEFAULT_VALUES
19252 JavaIterator<MapEntry<String, DartType>> overriddenNamedPTIterator = new Jav aIterator(getMapEntrySet(overriddenNamedPT)); 19398 MapIterator<String, DartType> overriddenNamedPTIterator = SingleMapIterator. forMap(overriddenNamedPT);
19253 while (overriddenNamedPTIterator.hasNext) { 19399 while (overriddenNamedPTIterator.moveNext()) {
19254 MapEntry<String, DartType> overriddenNamedPTEntry = overriddenNamedPTItera tor.next(); 19400 DartType overridingType = overridingNamedPT[overriddenNamedPTIterator.key] ;
19255 DartType overridingType = overridingNamedPT[overriddenNamedPTEntry.getKey( )];
19256 if (overridingType == null) { 19401 if (overridingType == null) {
19257 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been created above if 19402 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been created above if
19258 // this could be reached. 19403 // this could be reached.
19259 continue; 19404 continue;
19260 } 19405 }
19261 if (!overriddenNamedPTEntry.getValue().isAssignableTo(overridingType)) { 19406 if (!overriddenNamedPTIterator.value.isAssignableTo(overridingType)) {
19262 // lookup the parameter for the error to select 19407 // lookup the parameter for the error to select
19263 ParameterElement parameterToSelect = null; 19408 ParameterElement parameterToSelect = null;
19264 AstNode parameterLocationToSelect = null; 19409 AstNode parameterLocationToSelect = null;
19265 for (int i = 0; i < parameters.length; i++) { 19410 for (int i = 0; i < parameters.length; i++) {
19266 ParameterElement parameter = parameters[i]; 19411 ParameterElement parameter = parameters[i];
19267 if (parameter.parameterKind == ParameterKind.NAMED && overriddenNamedP TEntry.getKey() == parameter.name) { 19412 if (parameter.parameterKind == ParameterKind.NAMED && overriddenNamedP TIterator.key == parameter.name) {
19268 parameterToSelect = parameter; 19413 parameterToSelect = parameter;
19269 parameterLocationToSelect = parameterLocations[i]; 19414 parameterLocationToSelect = parameterLocations[i];
19270 break; 19415 break;
19271 } 19416 }
19272 } 19417 }
19273 if (parameterToSelect != null) { 19418 if (parameterToSelect != null) {
19274 _errorReporter.reportErrorForNode(StaticWarningCode.INVALID_METHOD_OVE RRIDE_NAMED_PARAM_TYPE, parameterLocationToSelect, [ 19419 _errorReporter.reportErrorForNode(StaticWarningCode.INVALID_METHOD_OVE RRIDE_NAMED_PARAM_TYPE, parameterLocationToSelect, [
19275 overridingType.displayName, 19420 overridingType.displayName,
19276 overriddenNamedPTEntry.getValue().displayName, 19421 overriddenNamedPTIterator.value.displayName,
19277 overriddenExecutable.enclosingElement.displayName]); 19422 overriddenExecutable.enclosingElement.displayName]);
19278 return true; 19423 return true;
19279 } 19424 }
19280 } 19425 }
19281 } 19426 }
19282 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES 19427 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES
19283 // 19428 //
19284 // Create three arrays: an array of the optional parameter ASTs (FormalParam eters), an array of 19429 // Create three arrays: an array of the optional parameter ASTs (FormalParam eters), an array of
19285 // the optional parameters elements from our method, and finally an array of the optional 19430 // the optional parameters elements from our method, and finally an array of the optional
19286 // parameter elements from the method we are overriding. 19431 // parameter elements from the method we are overriding.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
19604 */ 19749 */
19605 bool _checkForAmbiguousExport(ExportDirective node, ExportElement exportElemen t) { 19750 bool _checkForAmbiguousExport(ExportDirective node, ExportElement exportElemen t) {
19606 // prepare exported library 19751 // prepare exported library
19607 LibraryElement exportedLibrary = exportElement.exportedLibrary; 19752 LibraryElement exportedLibrary = exportElement.exportedLibrary;
19608 if (exportedLibrary == null) { 19753 if (exportedLibrary == null) {
19609 return false; 19754 return false;
19610 } 19755 }
19611 // check exported names 19756 // check exported names
19612 Namespace namespace = new NamespaceBuilder().createExportNamespaceForDirecti ve(exportElement); 19757 Namespace namespace = new NamespaceBuilder().createExportNamespaceForDirecti ve(exportElement);
19613 Map<String, Element> definedNames = namespace.definedNames; 19758 Map<String, Element> definedNames = namespace.definedNames;
19614 for (MapEntry<String, Element> definedEntry in getMapEntrySet(definedNames)) { 19759 for (MapIterator<String, Element> iter = SingleMapIterator.forMap(definedNam es); iter.moveNext();) {
19615 String name = definedEntry.getKey(); 19760 String name = iter.key;
19616 Element element = definedEntry.getValue(); 19761 Element element = iter.value;
19617 Element prevElement = _exportedElements[name]; 19762 Element prevElement = _exportedElements[name];
19618 if (element != null && prevElement != null && prevElement != element) { 19763 if (element != null && prevElement != null && prevElement != element) {
19619 _errorReporter.reportErrorForNode(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node, [ 19764 _errorReporter.reportErrorForNode(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node, [
19620 name, 19765 name,
19621 prevElement.library.definingCompilationUnit.displayName, 19766 prevElement.library.definingCompilationUnit.displayName,
19622 element.library.definingCompilationUnit.displayName]); 19767 element.library.definingCompilationUnit.displayName]);
19623 return true; 19768 return true;
19624 } else { 19769 } else {
19625 _exportedElements[name] = element; 19770 _exportedElements[name] = element;
19626 } 19771 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
19692 * @param expectedPropagatedType the expected propagated type, may be `null` 19837 * @param expectedPropagatedType the expected propagated type, may be `null`
19693 * @return `true` if and only if an error code is generated on the passed node 19838 * @return `true` if and only if an error code is generated on the passed node
19694 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 19839 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
19695 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 19840 * @see CompileTimeErrorCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE
19696 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE 19841 * @see StaticWarningCode#LIST_ELEMENT_TYPE_NOT_ASSIGNABLE
19697 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 19842 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE
19698 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 19843 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE
19699 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 19844 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE
19700 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 19845 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE
19701 */ 19846 */
19702 bool _checkForArgumentTypeNotAssignableWithExpectedTypes(Expression expression , DartType expectedStaticType, ErrorCode errorCode) => _checkForArgumentTypeNotA ssignable(expression, expectedStaticType, _getStaticType(expression), errorCode) ; 19847 bool _checkForArgumentTypeNotAssignableWithExpectedTypes(Expression expression , DartType expectedStaticType, ErrorCode errorCode) => _checkForArgumentTypeNotA ssignable(expression, expectedStaticType, getStaticType(expression), errorCode);
19703 19848
19704 /** 19849 /**
19705 * This verifies that the passed arguments can be assigned to their correspond ing parameters. 19850 * This verifies that the passed arguments can be assigned to their correspond ing parameters.
19706 * 19851 *
19707 * This method corresponds to BestPracticesVerifier.checkForArgumentTypesNotAs signableInList. 19852 * This method corresponds to BestPracticesVerifier.checkForArgumentTypesNotAs signableInList.
19708 * 19853 *
19709 * @param node the arguments to evaluate 19854 * @param node the arguments to evaluate
19710 * @return `true` if and only if an error code is generated on the passed node 19855 * @return `true` if and only if an error code is generated on the passed node
19711 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 19856 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
19712 */ 19857 */
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
20545 // OK, no default value. 20690 // OK, no default value.
20546 if (node.defaultValue == null) { 20691 if (node.defaultValue == null) {
20547 return false; 20692 return false;
20548 } 20693 }
20549 // Report problem. 20694 // Report problem.
20550 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPED_PARAMETER, node, []); 20695 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPED_PARAMETER, node, []);
20551 return true; 20696 return true;
20552 } 20697 }
20553 20698
20554 /** 20699 /**
20700 * This verifies that any deferred imports in the given compilation unit have a unique prefix.
20701 *
20702 * @param node the compilation unit containing the imports to be checked
20703 * @return `true` if an error was generated
20704 * @see CompileTimeErrorCode#SHARED_DEFERRED_PREFIX
20705 */
20706 bool _checkForDeferredPrefixCollisions(CompilationUnit node) {
20707 bool foundError = false;
20708 NodeList<Directive> directives = node.directives;
20709 int count = directives.length;
20710 if (count > 0) {
20711 Map<PrefixElement, List<ImportDirective>> prefixToDirectivesMap = new Map< PrefixElement, List<ImportDirective>>();
20712 for (int i = 0; i < count; i++) {
20713 Directive directive = directives[i];
20714 if (directive is ImportDirective) {
20715 ImportDirective importDirective = directive;
20716 SimpleIdentifier prefix = importDirective.prefix;
20717 if (prefix != null) {
20718 Element element = prefix.staticElement;
20719 if (element is PrefixElement) {
20720 PrefixElement prefixElement = element;
20721 List<ImportDirective> elements = prefixToDirectivesMap[prefixEleme nt];
20722 if (elements == null) {
20723 elements = new List<ImportDirective>();
20724 prefixToDirectivesMap[prefixElement] = elements;
20725 }
20726 elements.add(importDirective);
20727 }
20728 }
20729 }
20730 }
20731 for (List<ImportDirective> imports in prefixToDirectivesMap.values) {
20732 if (_hasDeferredPrefixCollision(imports)) {
20733 foundError = true;
20734 }
20735 }
20736 }
20737 return foundError;
20738 }
20739
20740 /**
20555 * This verifies that the enclosing class does not have an instance member wit h the given name of 20741 * This verifies that the enclosing class does not have an instance member wit h the given name of
20556 * the static member. 20742 * the static member.
20557 * 20743 *
20558 * @return `true` if and only if an error code is generated on the passed node 20744 * @return `true` if and only if an error code is generated on the passed node
20559 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE 20745 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE
20560 */ 20746 */
20561 bool _checkForDuplicateDefinitionInheritance() { 20747 bool _checkForDuplicateDefinitionInheritance() {
20562 if (_enclosingClass == null) { 20748 if (_enclosingClass == null) {
20563 return false; 20749 return false;
20564 } 20750 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
20778 } 20964 }
20779 FieldElement fieldElement = staticElement as FieldElement; 20965 FieldElement fieldElement = staticElement as FieldElement;
20780 // prepare field type 20966 // prepare field type
20781 DartType fieldType = fieldElement.type; 20967 DartType fieldType = fieldElement.type;
20782 // prepare expression type 20968 // prepare expression type
20783 Expression expression = node.expression; 20969 Expression expression = node.expression;
20784 if (expression == null) { 20970 if (expression == null) {
20785 return false; 20971 return false;
20786 } 20972 }
20787 // test the static type of the expression 20973 // test the static type of the expression
20788 DartType staticType = _getStaticType(expression); 20974 DartType staticType = getStaticType(expression);
20789 if (staticType == null) { 20975 if (staticType == null) {
20790 return false; 20976 return false;
20791 } 20977 }
20792 if (staticType.isAssignableTo(fieldType)) { 20978 if (staticType.isAssignableTo(fieldType)) {
20793 return false; 20979 return false;
20794 } 20980 }
20795 // report problem 20981 // report problem
20796 if (_isEnclosingConstructorConst) { 20982 if (_isEnclosingConstructorConst) {
20797 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FIELD_INITIAL IZER_NOT_ASSIGNABLE, expression, [staticType.displayName, fieldType.displayName] ); 20983 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FIELD_INITIAL IZER_NOT_ASSIGNABLE, expression, [staticType.displayName, fieldType.displayName] );
20798 } else { 20984 } else {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
21152 * 21338 *
21153 * @param lhs the left hand side expression 21339 * @param lhs the left hand side expression
21154 * @param rhs the right hand side expression 21340 * @param rhs the right hand side expression
21155 * @return `true` if and only if an error code is generated on the passed node 21341 * @return `true` if and only if an error code is generated on the passed node
21156 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 21342 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
21157 */ 21343 */
21158 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { 21344 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) {
21159 if (lhs == null || rhs == null) { 21345 if (lhs == null || rhs == null) {
21160 return false; 21346 return false;
21161 } 21347 }
21162 VariableElement leftElement = _getVariableElement(lhs); 21348 VariableElement leftElement = getVariableElement(lhs);
21163 DartType leftType = (leftElement == null) ? _getStaticType(lhs) : leftElemen t.type; 21349 DartType leftType = (leftElement == null) ? getStaticType(lhs) : leftElement .type;
21164 DartType staticRightType = _getStaticType(rhs); 21350 DartType staticRightType = getStaticType(rhs);
21165 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); 21351 if (!staticRightType.isAssignableTo(leftType)) {
21166 if (!isStaticAssignable) {
21167 String leftName = leftType.displayName; 21352 String leftName = leftType.displayName;
21168 String rightName = staticRightType.displayName; 21353 String rightName = staticRightType.displayName;
21169 if (leftName == rightName) { 21354 if (leftName == rightName) {
21170 leftName = _getExtendedDisplayName(leftType); 21355 leftName = getExtendedDisplayName(leftType);
21171 rightName = _getExtendedDisplayName(staticRightType); 21356 rightName = getExtendedDisplayName(staticRightType);
21172 } 21357 }
21173 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , rhs, [rightName, leftName]); 21358 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , rhs, [rightName, leftName]);
21174 return true; 21359 return true;
21175 } 21360 }
21176 // TODO(brianwilkerson) Define a hint corresponding to the warning and repor t it if appropriate.
21177 // Type propagatedRightType = rhs.getPropagatedType();
21178 // boolean isPropagatedAssignable = propagatedRightType.isAssignableTo(le ftType);
21179 // if (!isStaticAssignable && !isPropagatedAssignable) {
21180 // errorReporter.reportError(
21181 // StaticTypeWarningCode.INVALID_ASSIGNMENT,
21182 // rhs,
21183 // staticRightType.getDisplayName(),
21184 // leftType.getDisplayName());
21185 // return true;
21186 // }
21187 return false; 21361 return false;
21188 } 21362 }
21189 21363
21190 /** 21364 /**
21191 * Given an assignment using a compound assignment operator, this verifies tha t the given 21365 * Given an assignment using a compound assignment operator, this verifies tha t the given
21192 * assignment is valid. 21366 * assignment is valid.
21193 * 21367 *
21194 * @param node the assignment expression being tested 21368 * @param node the assignment expression being tested
21195 * @return `true` if and only if an error code is generated on the passed node 21369 * @return `true` if and only if an error code is generated on the passed node
21196 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 21370 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
21197 */ 21371 */
21198 bool _checkForInvalidCompoundAssignment(AssignmentExpression node) { 21372 bool _checkForInvalidCompoundAssignment(AssignmentExpression node) {
21199 Expression lhs = node.leftHandSide; 21373 Expression lhs = node.leftHandSide;
21200 if (lhs == null) { 21374 if (lhs == null) {
21201 return false; 21375 return false;
21202 } 21376 }
21203 VariableElement leftElement = _getVariableElement(lhs); 21377 VariableElement leftElement = getVariableElement(lhs);
21204 DartType leftType = (leftElement == null) ? _getStaticType(lhs) : leftElemen t.type; 21378 DartType leftType = (leftElement == null) ? getStaticType(lhs) : leftElement .type;
21205 MethodElement invokedMethod = node.staticElement; 21379 MethodElement invokedMethod = node.staticElement;
21206 if (invokedMethod == null) { 21380 if (invokedMethod == null) {
21207 return false; 21381 return false;
21208 } 21382 }
21209 DartType rightType = invokedMethod.type.returnType; 21383 DartType rightType = invokedMethod.type.returnType;
21210 if (leftType == null || rightType == null) { 21384 if (leftType == null || rightType == null) {
21211 return false; 21385 return false;
21212 } 21386 }
21213 if (!rightType.isAssignableTo(leftType)) { 21387 if (!rightType.isAssignableTo(leftType)) {
21214 String leftName = leftType.displayName; 21388 String leftName = leftType.displayName;
21215 String rightName = rightType.displayName; 21389 String rightName = rightType.displayName;
21216 if (leftName == rightName) { 21390 if (leftName == rightName) {
21217 leftName = _getExtendedDisplayName(leftType); 21391 leftName = getExtendedDisplayName(leftType);
21218 rightName = _getExtendedDisplayName(rightType); 21392 rightName = getExtendedDisplayName(rightType);
21219 } 21393 }
21220 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , node.rightHandSide, [rightName, leftName]); 21394 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVALID_ASSIGNMENT , node.rightHandSide, [rightName, leftName]);
21221 return true; 21395 return true;
21222 } 21396 }
21223 return false; 21397 return false;
21224 } 21398 }
21225 21399
21226 /** 21400 /**
21227 * Check the given initializer to ensure that the field being initialized is a valid field. 21401 * Check the given initializer to ensure that the field being initialized is a valid field.
21228 * 21402 *
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
21309 } 21483 }
21310 // Check every list element. 21484 // Check every list element.
21311 bool hasProblems = false; 21485 bool hasProblems = false;
21312 for (Expression element in node.elements) { 21486 for (Expression element in node.elements) {
21313 hasProblems = javaBooleanOr(hasProblems, _checkForArgumentTypeNotAssignabl eWithExpectedTypes(element, listElementType, errorCode)); 21487 hasProblems = javaBooleanOr(hasProblems, _checkForArgumentTypeNotAssignabl eWithExpectedTypes(element, listElementType, errorCode));
21314 } 21488 }
21315 return hasProblems; 21489 return hasProblems;
21316 } 21490 }
21317 21491
21318 /** 21492 /**
21493 * Check that the imported library does not define a loadLibrary function.
21494 *
21495 * @param node the import directive to evaluate
21496 * @param importElement the [ImportElement] retrieved from the node
21497 * @return `true` if and only if an error code is generated on the passed node
21498 * @see CompileTimeErrorCode#IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION
21499 */
21500 bool _checkForLoadLibraryFunction(ImportDirective node, ImportElement importEl ement) {
21501 LibraryElement importedLibrary = importElement.importedLibrary;
21502 if (importedLibrary == null) {
21503 return false;
21504 }
21505 if (importedLibrary.hasLoadLibraryFunction) {
21506 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPORT_DEFERRED_LIB RARY_WITH_LOAD_FUNCTION, node, [importedLibrary.name]);
21507 return true;
21508 }
21509 return false;
21510 }
21511
21512 /**
21319 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the 21513 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the
21320 * key/value types specified in the type arguments. 21514 * key/value types specified in the type arguments.
21321 * 21515 *
21322 * @param node the map literal to evaluate 21516 * @param node the map literal to evaluate
21323 * @return `true` if and only if an error code is generated on the passed node 21517 * @return `true` if and only if an error code is generated on the passed node
21324 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 21518 * @see CompileTimeErrorCode#MAP_KEY_TYPE_NOT_ASSIGNABLE
21325 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 21519 * @see CompileTimeErrorCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE
21326 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE 21520 * @see StaticWarningCode#MAP_KEY_TYPE_NOT_ASSIGNABLE
21327 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE 21521 * @see StaticWarningCode#MAP_VALUE_TYPE_NOT_ASSIGNABLE
21328 */ 21522 */
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
21650 } 21844 }
21651 // report problem 21845 // report problem
21652 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONS TRUCTOR_IMPLICIT, node.name, [superType.displayName]); 21846 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONS TRUCTOR_IMPLICIT, node.name, [superType.displayName]);
21653 return true; 21847 return true;
21654 } 21848 }
21655 21849
21656 /** 21850 /**
21657 * This checks that passed class declaration overrides all members required by its superclasses 21851 * This checks that passed class declaration overrides all members required by its superclasses
21658 * and interfaces. 21852 * and interfaces.
21659 * 21853 *
21660 * @param node the [ClassDeclaration] to evaluate 21854 * @param classNameNode the [SimpleIdentifier] to be used if there is a violat ion, this is
21855 * either the named from the [ClassDeclaration] or from the [ClassTyp eAlias].
21661 * @return `true` if and only if an error code is generated on the passed node 21856 * @return `true` if and only if an error code is generated on the passed node
21662 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE 21857 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE
21663 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO 21858 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO
21664 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE 21859 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE
21665 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR 21860 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR
21666 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU S 21861 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLU S
21667 */ 21862 */
21668 bool _checkForNonAbstractClassInheritsAbstractMember(ClassDeclaration node) { 21863 bool _checkForNonAbstractClassInheritsAbstractMember(SimpleIdentifier classNam eNode) {
21669 if (_enclosingClass.isAbstract) { 21864 if (_enclosingClass.isAbstract) {
21670 return false; 21865 return false;
21671 } 21866 }
21672 // 21867 //
21673 // Store in local sets the set of all method and accessor names 21868 // Store in local sets the set of all method and accessor names
21674 // 21869 //
21675 List<MethodElement> methods = _enclosingClass.methods; 21870 List<MethodElement> methods = _enclosingClass.methods;
21676 List<PropertyAccessorElement> accessors = _enclosingClass.accessors;
21677 Set<String> methodsInEnclosingClass = new Set<String>();
21678 for (MethodElement method in methods) { 21871 for (MethodElement method in methods) {
21679 String methodName = method.name; 21872 String methodName = method.name;
21680 // If the enclosing class declares the method noSuchMethod(), then return. 21873 // If the enclosing class declares the method noSuchMethod(), then return.
21681 // From Spec: It is a static warning if a concrete class does not have an implementation for 21874 // From Spec: It is a static warning if a concrete class does not have an implementation for
21682 // a method in any of its superinterfaces unless it declares its own noSuc hMethod 21875 // a method in any of its superinterfaces unless it declares its own noSuc hMethod
21683 // method (7.10). 21876 // method (7.10).
21684 if (methodName == ElementResolver.NO_SUCH_METHOD_METHOD_NAME) { 21877 if (methodName == ElementResolver.NO_SUCH_METHOD_METHOD_NAME) {
21685 return false; 21878 return false;
21686 } 21879 }
21687 methodsInEnclosingClass.add(methodName);
21688 }
21689 Set<String> accessorsInEnclosingClass = new Set<String>();
21690 for (PropertyAccessorElement accessor in accessors) {
21691 accessorsInEnclosingClass.add(accessor.name);
21692 } 21880 }
21693 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>(); 21881 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>();
21694 // 21882 //
21695 // Loop through the set of all executable elements declared in the implicit interface. 21883 // Loop through the set of all executable elements declared in the implicit interface.
21696 // 21884 //
21697 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass); 21885 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass);
21698 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass); 21886 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass);
21699 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) { 21887 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) {
21700 String memberName = membersInheritedFromInterfaces.getKey(i); 21888 String memberName = membersInheritedFromInterfaces.getKey(i);
21701 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i); 21889 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
21766 if (enclosingElement != null) { 21954 if (enclosingElement != null) {
21767 newStrMember = "${prefix}'${enclosingElement.displayName}.${missingOverr idesArray[i].displayName}'"; 21955 newStrMember = "${prefix}'${enclosingElement.displayName}.${missingOverr idesArray[i].displayName}'";
21768 } else { 21956 } else {
21769 newStrMember = "${prefix}'${missingOverridesArray[i].displayName}'"; 21957 newStrMember = "${prefix}'${missingOverridesArray[i].displayName}'";
21770 } 21958 }
21771 stringMembersArrayListSet.add(newStrMember); 21959 stringMembersArrayListSet.add(newStrMember);
21772 } 21960 }
21773 List<String> stringMembersArray = new List.from(stringMembersArrayListSet); 21961 List<String> stringMembersArray = new List.from(stringMembersArrayListSet);
21774 AnalysisErrorWithProperties analysisError; 21962 AnalysisErrorWithProperties analysisError;
21775 if (stringMembersArray.length == 1) { 21963 if (stringMembersArray.length == 1) {
21776 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, node.name, [stringMembersArray[0] ]); 21964 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE, classNameNode, [stringMembersArra y[0]]);
21777 } else if (stringMembersArray.length == 2) { 21965 } else if (stringMembersArray.length == 2) {
21778 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, node.name, [stringMembersArray[0] , stringMembersArray[1]]); 21966 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO, classNameNode, [stringMembersArra y[0], stringMembersArray[1]]);
21779 } else if (stringMembersArray.length == 3) { 21967 } else if (stringMembersArray.length == 3) {
21780 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, node.name, [ 21968 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE, classNameNode, [
21781 stringMembersArray[0], 21969 stringMembersArray[0],
21782 stringMembersArray[1], 21970 stringMembersArray[1],
21783 stringMembersArray[2]]); 21971 stringMembersArray[2]]);
21784 } else if (stringMembersArray.length == 4) { 21972 } else if (stringMembersArray.length == 4) {
21785 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, node.name, [ 21973 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR, classNameNode, [
21786 stringMembersArray[0], 21974 stringMembersArray[0],
21787 stringMembersArray[1], 21975 stringMembersArray[1],
21788 stringMembersArray[2], 21976 stringMembersArray[2],
21789 stringMembersArray[3]]); 21977 stringMembersArray[3]]);
21790 } else { 21978 } else {
21791 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, node.name, [ 21979 analysisError = _errorReporter.newErrorWithProperties(StaticWarningCode.NO N_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS, classNameNode, [
21792 stringMembersArray[0], 21980 stringMembersArray[0],
21793 stringMembersArray[1], 21981 stringMembersArray[1],
21794 stringMembersArray[2], 21982 stringMembersArray[2],
21795 stringMembersArray[3], 21983 stringMembersArray[3],
21796 stringMembersArray.length - 4]); 21984 stringMembersArray.length - 4]);
21797 } 21985 }
21798 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri desArray); 21986 analysisError.setProperty(ErrorProperty.UNIMPLEMENTED_METHODS, missingOverri desArray);
21799 _errorReporter.reportError(analysisError); 21987 _errorReporter.reportError(analysisError);
21800 return true; 21988 return true;
21801 } 21989 }
21802 21990
21803 /** 21991 /**
21804 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is 21992 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is
21805 * reported on the expression. 21993 * reported on the expression.
21806 * 21994 *
21807 * @param condition the conditional expression to test 21995 * @param condition the conditional expression to test
21808 * @return `true` if and only if an error code is generated on the passed node 21996 * @return `true` if and only if an error code is generated on the passed node
21809 * @see StaticTypeWarningCode#NON_BOOL_CONDITION 21997 * @see StaticTypeWarningCode#NON_BOOL_CONDITION
21810 */ 21998 */
21811 bool _checkForNonBoolCondition(Expression condition) { 21999 bool _checkForNonBoolCondition(Expression condition) {
21812 DartType conditionType = _getStaticType(condition); 22000 DartType conditionType = getStaticType(condition);
21813 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { 22001 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) {
21814 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_CONDITION , condition, []); 22002 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_CONDITION , condition, []);
21815 return true; 22003 return true;
21816 } 22004 }
21817 return false; 22005 return false;
21818 } 22006 }
21819 22007
21820 /** 22008 /**
21821 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input. 22009 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input.
21822 * 22010 *
21823 * @param node the assert statement to evaluate 22011 * @param node the assert statement to evaluate
21824 * @return `true` if and only if an error code is generated on the passed node 22012 * @return `true` if and only if an error code is generated on the passed node
21825 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION 22013 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION
21826 */ 22014 */
21827 bool _checkForNonBoolExpression(AssertStatement node) { 22015 bool _checkForNonBoolExpression(AssertStatement node) {
21828 Expression expression = node.condition; 22016 Expression expression = node.condition;
21829 DartType type = _getStaticType(expression); 22017 DartType type = getStaticType(expression);
21830 if (type is InterfaceType) { 22018 if (type is InterfaceType) {
21831 if (!type.isAssignableTo(_boolType)) { 22019 if (!type.isAssignableTo(_boolType)) {
21832 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []); 22020 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []);
21833 return true; 22021 return true;
21834 } 22022 }
21835 } else if (type is FunctionType) { 22023 } else if (type is FunctionType) {
21836 FunctionType functionType = type; 22024 FunctionType functionType = type;
21837 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_boolType)) { 22025 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_boolType)) {
21838 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []); 22026 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS ION, expression, []);
21839 return true; 22027 return true;
21840 } 22028 }
21841 } 22029 }
21842 return false; 22030 return false;
21843 } 22031 }
21844 22032
21845 /** 22033 /**
21846 * Checks to ensure that the given expression is assignable to bool. 22034 * Checks to ensure that the given expression is assignable to bool.
21847 * 22035 *
21848 * @param expression the expression expression to test 22036 * @param expression the expression expression to test
21849 * @return `true` if and only if an error code is generated on the passed node 22037 * @return `true` if and only if an error code is generated on the passed node
21850 * @see StaticTypeWarningCode#NON_BOOL_NEGATION_EXPRESSION 22038 * @see StaticTypeWarningCode#NON_BOOL_NEGATION_EXPRESSION
21851 */ 22039 */
21852 bool _checkForNonBoolNegationExpression(Expression expression) { 22040 bool _checkForNonBoolNegationExpression(Expression expression) {
21853 DartType conditionType = _getStaticType(expression); 22041 DartType conditionType = getStaticType(expression);
21854 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { 22042 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) {
21855 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_NEGATION_ EXPRESSION, expression, []); 22043 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_NEGATION_ EXPRESSION, expression, []);
21856 return true; 22044 return true;
21857 } 22045 }
21858 return false; 22046 return false;
21859 } 22047 }
21860 22048
21861 /** 22049 /**
21862 * This verifies the passed map literal either: 22050 * This verifies the passed map literal either:
21863 * * has `const modifier` 22051 * * has `const modifier`
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
22186 * 22374 *
22187 * This method is called both by [checkForAllReturnStatementErrorCodes] 22375 * This method is called both by [checkForAllReturnStatementErrorCodes]
22188 * and [visitExpressionFunctionBody]. 22376 * and [visitExpressionFunctionBody].
22189 * 22377 *
22190 * @param returnExpression the returned expression to evaluate 22378 * @param returnExpression the returned expression to evaluate
22191 * @param expectedReturnType the expressed return type by the enclosing method or function 22379 * @param expectedReturnType the expressed return type by the enclosing method or function
22192 * @return `true` if and only if an error code is generated on the passed node 22380 * @return `true` if and only if an error code is generated on the passed node
22193 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE 22381 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE
22194 */ 22382 */
22195 bool _checkForReturnOfInvalidType(Expression returnExpression, DartType expect edReturnType) { 22383 bool _checkForReturnOfInvalidType(Expression returnExpression, DartType expect edReturnType) {
22196 DartType staticReturnType = _getStaticType(returnExpression); 22384 DartType staticReturnType = getStaticType(returnExpression);
22197 if (expectedReturnType.isVoid) { 22385 if (expectedReturnType.isVoid) {
22198 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) { 22386 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) {
22199 return false; 22387 return false;
22200 } 22388 }
22201 _errorReporter.reportErrorForNode(StaticTypeWarningCode.RETURN_OF_INVALID_ TYPE, returnExpression, [ 22389 _errorReporter.reportErrorForNode(StaticTypeWarningCode.RETURN_OF_INVALID_ TYPE, returnExpression, [
22202 staticReturnType.displayName, 22390 staticReturnType.displayName,
22203 expectedReturnType.displayName, 22391 expectedReturnType.displayName,
22204 _enclosingFunction.displayName]); 22392 _enclosingFunction.displayName]);
22205 return true; 22393 return true;
22206 } 22394 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
22250 * This checks that the type of the passed 'switch' expression is assignable t o the type of the 22438 * This checks that the type of the passed 'switch' expression is assignable t o the type of the
22251 * 'case' members. 22439 * 'case' members.
22252 * 22440 *
22253 * @param node the 'switch' statement to evaluate 22441 * @param node the 'switch' statement to evaluate
22254 * @return `true` if and only if an error code is generated on the passed node 22442 * @return `true` if and only if an error code is generated on the passed node
22255 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE 22443 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE
22256 */ 22444 */
22257 bool _checkForSwitchExpressionNotAssignable(SwitchStatement node) { 22445 bool _checkForSwitchExpressionNotAssignable(SwitchStatement node) {
22258 // prepare 'switch' expression type 22446 // prepare 'switch' expression type
22259 Expression expression = node.expression; 22447 Expression expression = node.expression;
22260 DartType expressionType = _getStaticType(expression); 22448 DartType expressionType = getStaticType(expression);
22261 if (expressionType == null) { 22449 if (expressionType == null) {
22262 return false; 22450 return false;
22263 } 22451 }
22264 // compare with type of the first 'case' 22452 // compare with type of the first 'case'
22265 NodeList<SwitchMember> members = node.members; 22453 NodeList<SwitchMember> members = node.members;
22266 for (SwitchMember switchMember in members) { 22454 for (SwitchMember switchMember in members) {
22267 if (switchMember is! SwitchCase) { 22455 if (switchMember is! SwitchCase) {
22268 continue; 22456 continue;
22269 } 22457 }
22270 SwitchCase switchCase = switchMember as SwitchCase; 22458 SwitchCase switchCase = switchMember as SwitchCase;
22271 // prepare 'case' type 22459 // prepare 'case' type
22272 Expression caseExpression = switchCase.expression; 22460 Expression caseExpression = switchCase.expression;
22273 DartType caseType = _getStaticType(caseExpression); 22461 DartType caseType = getStaticType(caseExpression);
22274 // check types 22462 // check types
22275 if (expressionType.isAssignableTo(caseType)) { 22463 if (expressionType.isAssignableTo(caseType)) {
22276 return false; 22464 return false;
22277 } 22465 }
22278 // report problem 22466 // report problem
22279 _errorReporter.reportErrorForNode(StaticWarningCode.SWITCH_EXPRESSION_NOT_ ASSIGNABLE, expression, [expressionType, caseType]); 22467 _errorReporter.reportErrorForNode(StaticWarningCode.SWITCH_EXPRESSION_NOT_ ASSIGNABLE, expression, [expressionType, caseType]);
22280 return true; 22468 return true;
22281 } 22469 }
22282 return false; 22470 return false;
22283 } 22471 }
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
22660 if (interfaceNode.type == superType) { 22848 if (interfaceNode.type == superType) {
22661 hasProblem = true; 22849 hasProblem = true;
22662 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPLEMENTS_SUPER_ CLASS, interfaceNode, [superType.displayName]); 22850 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPLEMENTS_SUPER_ CLASS, interfaceNode, [superType.displayName]);
22663 } 22851 }
22664 } 22852 }
22665 // done 22853 // done
22666 return hasProblem; 22854 return hasProblem;
22667 } 22855 }
22668 22856
22669 /** 22857 /**
22670 * Return a display name for the given type that includes the path to the comp ilation unit in
22671 * which the type is defined.
22672 *
22673 * @param type the type for which an extended display name is to be returned
22674 * @return a display name that can help distiguish between two types with the same name
22675 */
22676 String _getExtendedDisplayName(DartType type) {
22677 Element element = type.element;
22678 if (element != null) {
22679 Source source = element.source;
22680 if (source != null) {
22681 return "${type.displayName} (${source.fullName})";
22682 }
22683 }
22684 return type.displayName;
22685 }
22686
22687 /**
22688 * Returns the Type (return type) for a given getter. 22858 * Returns the Type (return type) for a given getter.
22689 * 22859 *
22690 * @param propertyAccessorElement 22860 * @param propertyAccessorElement
22691 * @return The type of the given getter. 22861 * @return The type of the given getter.
22692 */ 22862 */
22693 DartType _getGetterType(PropertyAccessorElement propertyAccessorElement) { 22863 DartType _getGetterType(PropertyAccessorElement propertyAccessorElement) {
22694 FunctionType functionType = propertyAccessorElement.type; 22864 FunctionType functionType = propertyAccessorElement.type;
22695 if (functionType != null) { 22865 if (functionType != null) {
22696 return functionType.returnType; 22866 return functionType.returnType;
22697 } else { 22867 } else {
(...skipping 11 matching lines...) Expand all
22709 // Get the parameters for MethodDeclaration or FunctionDeclaration 22879 // Get the parameters for MethodDeclaration or FunctionDeclaration
22710 List<ParameterElement> setterParameters = propertyAccessorElement.parameters ; 22880 List<ParameterElement> setterParameters = propertyAccessorElement.parameters ;
22711 // If there are no setter parameters, return no type. 22881 // If there are no setter parameters, return no type.
22712 if (setterParameters.length == 0) { 22882 if (setterParameters.length == 0) {
22713 return null; 22883 return null;
22714 } 22884 }
22715 return setterParameters[0].type; 22885 return setterParameters[0].type;
22716 } 22886 }
22717 22887
22718 /** 22888 /**
22719 * Return the static type of the given expression that is to be used for type analysis. 22889 * Given a list of directives that have the same prefix, generate an error if there is more than
22890 * one import and any of those imports is deferred.
22720 * 22891 *
22721 * @param expression the expression whose type is to be returned 22892 * @param directives the list of directives that have the same prefix
22722 * @return the static type of the given expression 22893 * @return `true` if an error was generated
22894 * @see CompileTimeErrorCode#SHARED_DEFERRED_PREFIX
22723 */ 22895 */
22724 DartType _getStaticType(Expression expression) { 22896 bool _hasDeferredPrefixCollision(List<ImportDirective> directives) {
22725 DartType type = expression.staticType; 22897 bool foundError = false;
22726 if (type == null) { 22898 int count = directives.length;
22727 // TODO(brianwilkerson) This should never happen. 22899 if (count > 1) {
22728 return _dynamicType; 22900 for (int i = 0; i < count; i++) {
22901 sc.Token deferredToken = directives[i].deferredToken;
22902 if (deferredToken != null) {
22903 _errorReporter.reportErrorForToken(CompileTimeErrorCode.SHARED_DEFERRE D_PREFIX, deferredToken, []);
22904 foundError = true;
22905 }
22906 }
22729 } 22907 }
22730 return type; 22908 return foundError;
22731 } 22909 }
22732 22910
22733 /** 22911 /**
22734 * Return the variable element represented by the given expression, or `null` if there is no
22735 * such element.
22736 *
22737 * @param expression the expression whose element is to be returned
22738 * @return the variable element represented by the expression
22739 */
22740 VariableElement _getVariableElement(Expression expression) {
22741 if (expression is Identifier) {
22742 Element element = expression.staticElement;
22743 if (element is VariableElement) {
22744 return element;
22745 }
22746 }
22747 return null;
22748 }
22749
22750 /**
22751 * @return `true` if the given constructor redirects to itself, directly or in directly 22912 * @return `true` if the given constructor redirects to itself, directly or in directly
22752 */ 22913 */
22753 bool _hasRedirectingFactoryConstructorCycle(ConstructorElement element) { 22914 bool _hasRedirectingFactoryConstructorCycle(ConstructorElement element) {
22754 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); 22915 Set<ConstructorElement> constructors = new Set<ConstructorElement>();
22755 ConstructorElement current = element; 22916 ConstructorElement current = element;
22756 while (current != null) { 22917 while (current != null) {
22757 if (constructors.contains(current)) { 22918 if (constructors.contains(current)) {
22758 return identical(current, element); 22919 return identical(current, element);
22759 } 22920 }
22760 constructors.add(current); 22921 constructors.add(current);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
22835 } else if (type is InterfaceType) { 22996 } else if (type is InterfaceType) {
22836 MethodElement callMethod = type.lookUpMethod(ElementResolver.CALL_METHOD_N AME, _currentLibrary); 22997 MethodElement callMethod = type.lookUpMethod(ElementResolver.CALL_METHOD_N AME, _currentLibrary);
22837 return callMethod != null; 22998 return callMethod != null;
22838 } 22999 }
22839 return false; 23000 return false;
22840 } 23001 }
22841 23002
22842 /** 23003 /**
22843 * Return `true` iff the passed [ClassElement] has a method, getter or setter that 23004 * Return `true` iff the passed [ClassElement] has a method, getter or setter that
22844 * matches the name of the passed [ExecutableElement] in either the class itse lf, or one of 23005 * matches the name of the passed [ExecutableElement] in either the class itse lf, or one of
22845 * its' mixins. 23006 * its' mixins that is concrete.
22846 * 23007 *
22847 * By "match", only the name of the member is tested to match, it does not hav e to equal or be a 23008 * By "match", only the name of the member is tested to match, it does not hav e to equal or be a
22848 * subtype of the passed executable element, this is due to the specific use w here this method is 23009 * subtype of the passed executable element, this is due to the specific use w here this method is
22849 * used in [checkForNonAbstractClassInheritsAbstractMember]. 23010 * used in [checkForNonAbstractClassInheritsAbstractMember].
22850 * 23011 *
22851 * @param executableElt the executable to search for in the passed class eleme nt 23012 * @param executableElt the executable to search for in the passed class eleme nt
22852 * @param classElt the class method to search through the members of 23013 * @param classElt the class method to search through the members of
22853 * @return `true` iff the passed member is found in the passed class element 23014 * @return `true` iff the passed member is found in the passed class element
22854 */ 23015 */
22855 bool _isMemberInClassOrMixin(ExecutableElement executableElt, ClassElement cla ssElt) { 23016 bool _isMemberInClassOrMixin(ExecutableElement executableElt, ClassElement cla ssElt) {
22856 ExecutableElement foundElt = null; 23017 ExecutableElement foundElt = null;
22857 String executableName = executableElt.name; 23018 String executableName = executableElt.name;
22858 if (executableElt is MethodElement) { 23019 if (executableElt is MethodElement) {
22859 foundElt = classElt.getMethod(executableName); 23020 foundElt = classElt.getMethod(executableName);
22860 if (foundElt != null) { 23021 if (foundElt != null && !(foundElt as MethodElement).isAbstract) {
22861 return true; 23022 return true;
22862 } 23023 }
22863 List<InterfaceType> mixins = classElt.mixins; 23024 List<InterfaceType> mixins = classElt.mixins;
22864 for (int i = 0; i < mixins.length && foundElt == null; i++) { 23025 for (int i = 0; i < mixins.length && foundElt == null; i++) {
22865 foundElt = mixins[i].getMethod(executableName); 23026 foundElt = mixins[i].getMethod(executableName);
22866 } 23027 }
22867 if (foundElt != null) { 23028 if (foundElt != null && !(foundElt as MethodElement).isAbstract) {
22868 return true; 23029 return true;
22869 } 23030 }
22870 } else if (executableElt is PropertyAccessorElement) { 23031 } else if (executableElt is PropertyAccessorElement) {
22871 PropertyAccessorElement propertyAccessorElement = executableElt; 23032 PropertyAccessorElement propertyAccessorElement = executableElt;
22872 if (propertyAccessorElement.isGetter) { 23033 if (propertyAccessorElement.isGetter) {
22873 foundElt = classElt.getGetter(executableName); 23034 foundElt = classElt.getGetter(executableName);
22874 } 23035 }
22875 if (foundElt == null && propertyAccessorElement.isSetter) { 23036 if (foundElt == null && propertyAccessorElement.isSetter) {
22876 foundElt = classElt.getSetter(executableName); 23037 foundElt = classElt.getSetter(executableName);
22877 } 23038 }
22878 if (foundElt != null) { 23039 if (foundElt != null && !(foundElt as PropertyAccessorElement).isAbstract) {
22879 return true; 23040 return true;
22880 } 23041 }
22881 List<InterfaceType> mixins = classElt.mixins; 23042 List<InterfaceType> mixins = classElt.mixins;
22882 for (int i = 0; i < mixins.length && foundElt == null; i++) { 23043 for (int i = 0; i < mixins.length && foundElt == null; i++) {
22883 foundElt = mixins[i].getGetter(executableName); 23044 foundElt = mixins[i].getGetter(executableName);
22884 if (foundElt == null) { 23045 if (foundElt == null) {
22885 foundElt = mixins[i].getSetter(executableName); 23046 foundElt = mixins[i].getSetter(executableName);
22886 } 23047 }
22887 } 23048 }
22888 if (foundElt != null) { 23049 if (foundElt != null && !(foundElt as PropertyAccessorElement).isAbstract) {
22889 return true; 23050 return true;
22890 } 23051 }
22891 } 23052 }
22892 return false; 23053 return false;
22893 } 23054 }
22894 23055
22895 /** 23056 /**
22896 * @param node the 'this' expression to analyze 23057 * @param node the 'this' expression to analyze
22897 * @return `true` if the given 'this' expression is in the valid context 23058 * @return `true` if the given 'this' expression is in the valid context
22898 */ 23059 */
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
23152 * 23313 *
23153 * @param type the type of this error 23314 * @param type the type of this error
23154 * @param message the template used to create the message to be displayed for the error 23315 * @param message the template used to create the message to be displayed for the error
23155 * @param correction the template used to create the correction to be displaye d for the error 23316 * @param correction the template used to create the correction to be displaye d for the error
23156 */ 23317 */
23157 const ResolverErrorCode.con2(String name, int ordinal, this.type, this.message , this.correction) : super(name, ordinal); 23318 const ResolverErrorCode.con2(String name, int ordinal, this.type, this.message , this.correction) : super(name, ordinal);
23158 23319
23159 @override 23320 @override
23160 ErrorSeverity get errorSeverity => type.severity; 23321 ErrorSeverity get errorSeverity => type.severity;
23161 } 23322 }
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