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

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

Issue 186153005: New analzyer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use meaningful name instead of '_' in predicate. Created 6 years, 9 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.resolver; 8 library engine.resolver;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 SimpleStringLiteral literal = node as SimpleStringLiteral; 65 SimpleStringLiteral literal = node as SimpleStringLiteral;
66 // maybe has AngularElement 66 // maybe has AngularElement
67 { 67 {
68 Element element = literal.toolkitElement; 68 Element element = literal.toolkitElement;
69 if (element is AngularElement) { 69 if (element is AngularElement) {
70 return element; 70 return element;
71 } 71 }
72 } 72 }
73 // prepare enclosing ClassDeclaration 73 // prepare enclosing ClassDeclaration
74 ClassDeclaration classDeclaration = node.getAncestor(ClassDeclaration); 74 ClassDeclaration classDeclaration = node.getAncestor((node) => node is Class Declaration);
75 if (classDeclaration == null) { 75 if (classDeclaration == null) {
76 return null; 76 return null;
77 } 77 }
78 // prepare ClassElement 78 // prepare ClassElement
79 ClassElement classElement = classDeclaration.element; 79 ClassElement classElement = classDeclaration.element;
80 if (classElement == null) { 80 if (classElement == null) {
81 return null; 81 return null;
82 } 82 }
83 // check toolkit objects 83 // check toolkit objects
84 for (ToolkitObjectElement toolkitObject in classElement.toolkitObjects) { 84 for (ToolkitObjectElement toolkitObject in classElement.toolkitObjects) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 int nameEnd = nameOffset + name.length; 203 int nameEnd = nameOffset + name.length;
204 return node.offset <= nameOffset && nameEnd < node.end; 204 return node.offset <= nameOffset && nameEnd < node.end;
205 } 205 }
206 } 206 }
207 return false; 207 return false;
208 } 208 }
209 209
210 /** 210 /**
211 * Parses given [SimpleStringLiteral] using [parseSelector]. 211 * Parses given [SimpleStringLiteral] using [parseSelector].
212 */ 212 */
213 static AngularSelectorElement parseSelector2(SimpleStringLiteral literal) { 213 static AngularSelectorElement parseSelectorFromString(SimpleStringLiteral lite ral) {
214 int offset = literal.valueOffset; 214 int offset = literal.valueOffset;
215 String text = literal.stringValue; 215 String text = literal.stringValue;
216 return parseSelector(offset, text); 216 return parseSelector(offset, text);
217 } 217 }
218 218
219 /** 219 /**
220 * The listener to which errors will be reported. 220 * The listener to which errors will be reported.
221 */ 221 */
222 AnalysisErrorListener _errorListener; 222 AnalysisErrorListener _errorListener;
223 223
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 this._classToolkitObjects.clear(); 277 this._classToolkitObjects.clear();
278 // process annotations 278 // process annotations
279 NodeList<Annotation> annotations = _classDeclaration.metadata; 279 NodeList<Annotation> annotations = _classDeclaration.metadata;
280 for (Annotation annotation in annotations) { 280 for (Annotation annotation in annotations) {
281 // verify annotation 281 // verify annotation
282 if (annotation.arguments == null) { 282 if (annotation.arguments == null) {
283 continue; 283 continue;
284 } 284 }
285 this._annotation = annotation; 285 this._annotation = annotation;
286 // @NgFilter 286 // @NgFilter
287 if (isAngularAnnotation2(_NG_FILTER)) { 287 if (isAngularAnnotation(annotation, _NG_FILTER)) {
288 parseNgFilter(); 288 parseNgFilter();
289 continue; 289 continue;
290 } 290 }
291 // @NgComponent 291 // @NgComponent
292 if (isAngularAnnotation2(_NG_COMPONENT)) { 292 if (isAngularAnnotation(annotation, _NG_COMPONENT)) {
293 parseNgComponent(); 293 parseNgComponent();
294 continue; 294 continue;
295 } 295 }
296 // @NgController 296 // @NgController
297 if (isAngularAnnotation2(_NG_CONTROLLER)) { 297 if (isAngularAnnotation(annotation, _NG_CONTROLLER)) {
298 parseNgController(); 298 parseNgController();
299 continue; 299 continue;
300 } 300 }
301 // @NgDirective 301 // @NgDirective
302 if (isAngularAnnotation2(_NG_DIRECTIVE)) { 302 if (isAngularAnnotation(annotation, _NG_DIRECTIVE)) {
303 parseNgDirective(); 303 parseNgDirective();
304 continue; 304 continue;
305 } 305 }
306 } 306 }
307 // set toolkit objects 307 // set toolkit objects
308 if (!_classToolkitObjects.isEmpty) { 308 if (!_classToolkitObjects.isEmpty) {
309 List<ToolkitObjectElement> objects = _classToolkitObjects; 309 List<ToolkitObjectElement> objects = _classToolkitObjects;
310 _classElement.toolkitObjects = new List.from(objects); 310 _classElement.toolkitObjects = new List.from(objects);
311 } 311 }
312 } 312 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 */ 365 */
366 bool isAngularAnnotation(Annotation annotation, String name) { 366 bool isAngularAnnotation(Annotation annotation, String name) {
367 Element element = annotation.element; 367 Element element = annotation.element;
368 if (element is ConstructorElement) { 368 if (element is ConstructorElement) {
369 ConstructorElement constructorElement = element; 369 ConstructorElement constructorElement = element;
370 return constructorElement.returnType.displayName == name; 370 return constructorElement.returnType.displayName == name;
371 } 371 }
372 return false; 372 return false;
373 } 373 }
374 374
375 /**
376 * Checks if [annotation] is an annotation with required name.
377 */
378 bool isAngularAnnotation2(String name) => isAngularAnnotation(_annotation, nam e);
379
380 void parseNgComponent() { 375 void parseNgComponent() {
381 bool isValid = true; 376 bool isValid = true;
382 // publishAs 377 // publishAs
383 String name = null; 378 String name = null;
384 int nameOffset = -1; 379 int nameOffset = -1;
385 if (hasStringArgument(_PUBLISH_AS)) { 380 if (hasStringArgument(_PUBLISH_AS)) {
386 name = getStringArgument(_PUBLISH_AS); 381 name = getStringArgument(_PUBLISH_AS);
387 nameOffset = getStringArgumentOffset(_PUBLISH_AS); 382 nameOffset = getStringArgumentOffset(_PUBLISH_AS);
388 } 383 }
389 // selector 384 // selector
390 AngularSelectorElement selector = null; 385 AngularSelectorElement selector = null;
391 if (!hasStringArgument(_SELECTOR)) { 386 if (!hasStringArgument(_SELECTOR)) {
392 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); 387 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []);
393 isValid = false; 388 isValid = false;
394 } else { 389 } else {
395 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR); 390 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR);
396 selector = parseSelector2(selectorLiteral); 391 selector = parseSelectorFromString(selectorLiteral);
397 if (selector == null) { 392 if (selector == null) {
398 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se lectorLiteral]); 393 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se lectorLiteral]);
399 isValid = false; 394 isValid = false;
400 } 395 }
401 } 396 }
402 // templateUrl 397 // templateUrl
403 String templateUri = null; 398 String templateUri = null;
404 int templateUriOffset = -1; 399 int templateUriOffset = -1;
405 if (hasStringArgument(_TEMPLATE_URL)) { 400 if (hasStringArgument(_TEMPLATE_URL)) {
406 templateUri = getStringArgument(_TEMPLATE_URL); 401 templateUri = getStringArgument(_TEMPLATE_URL);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 * Parses [AngularPropertyElement]s from [annotation]. 474 * Parses [AngularPropertyElement]s from [annotation].
480 */ 475 */
481 void parseNgComponentProperties_fromMap(List<AngularPropertyElement> propertie s) { 476 void parseNgComponentProperties_fromMap(List<AngularPropertyElement> propertie s) {
482 Expression mapExpression = getArgument("map"); 477 Expression mapExpression = getArgument("map");
483 // may be not properties 478 // may be not properties
484 if (mapExpression == null) { 479 if (mapExpression == null) {
485 return; 480 return;
486 } 481 }
487 // prepare map literal 482 // prepare map literal
488 if (mapExpression is! MapLiteral) { 483 if (mapExpression is! MapLiteral) {
489 reportError(mapExpression, AngularCode.INVALID_PROPERTY_MAP, []); 484 reportErrorForNode(AngularCode.INVALID_PROPERTY_MAP, mapExpression, []);
490 return; 485 return;
491 } 486 }
492 MapLiteral mapLiteral = mapExpression as MapLiteral; 487 MapLiteral mapLiteral = mapExpression as MapLiteral;
493 // analyze map entries 488 // analyze map entries
494 for (MapLiteralEntry entry in mapLiteral.entries) { 489 for (MapLiteralEntry entry in mapLiteral.entries) {
495 // prepare property name 490 // prepare property name
496 Expression nameExpression = entry.key; 491 Expression nameExpression = entry.key;
497 if (nameExpression is! SimpleStringLiteral) { 492 if (nameExpression is! SimpleStringLiteral) {
498 reportError(nameExpression, AngularCode.INVALID_PROPERTY_NAME, []); 493 reportErrorForNode(AngularCode.INVALID_PROPERTY_NAME, nameExpression, [] );
499 continue; 494 continue;
500 } 495 }
501 SimpleStringLiteral nameLiteral = nameExpression as SimpleStringLiteral; 496 SimpleStringLiteral nameLiteral = nameExpression as SimpleStringLiteral;
502 String name = nameLiteral.value; 497 String name = nameLiteral.value;
503 int nameOffset = nameLiteral.valueOffset; 498 int nameOffset = nameLiteral.valueOffset;
504 // prepare field specification 499 // prepare field specification
505 Expression specExpression = entry.value; 500 Expression specExpression = entry.value;
506 if (specExpression is! SimpleStringLiteral) { 501 if (specExpression is! SimpleStringLiteral) {
507 reportError(specExpression, AngularCode.INVALID_PROPERTY_SPEC, []); 502 reportErrorForNode(AngularCode.INVALID_PROPERTY_SPEC, specExpression, [] );
508 continue; 503 continue;
509 } 504 }
510 SimpleStringLiteral specLiteral = specExpression as SimpleStringLiteral; 505 SimpleStringLiteral specLiteral = specExpression as SimpleStringLiteral;
511 String spec = specLiteral.value; 506 String spec = specLiteral.value;
512 // parse binding kind and field name 507 // parse binding kind and field name
513 AngularPropertyKind kind; 508 AngularPropertyKind kind;
514 int fieldNameOffset; 509 int fieldNameOffset;
515 if (StringUtilities.startsWithChar(spec, 0x40)) { 510 if (StringUtilities.startsWithChar(spec, 0x40)) {
516 kind = AngularPropertyKind.ATTR; 511 kind = AngularPropertyKind.ATTR;
517 fieldNameOffset = 1; 512 fieldNameOffset = 1;
518 } else if (StringUtilities.startsWithChar(spec, 0x26)) { 513 } else if (StringUtilities.startsWithChar(spec, 0x26)) {
519 kind = AngularPropertyKind.CALLBACK; 514 kind = AngularPropertyKind.CALLBACK;
520 fieldNameOffset = 1; 515 fieldNameOffset = 1;
521 } else if (StringUtilities.startsWith3(spec, 0, 0x3D, 0x3E, 0x21)) { 516 } else if (StringUtilities.startsWith3(spec, 0, 0x3D, 0x3E, 0x21)) {
522 kind = AngularPropertyKind.ONE_WAY_ONE_TIME; 517 kind = AngularPropertyKind.ONE_WAY_ONE_TIME;
523 fieldNameOffset = 3; 518 fieldNameOffset = 3;
524 } else if (StringUtilities.startsWith2(spec, 0, 0x3D, 0x3E)) { 519 } else if (StringUtilities.startsWith2(spec, 0, 0x3D, 0x3E)) {
525 kind = AngularPropertyKind.ONE_WAY; 520 kind = AngularPropertyKind.ONE_WAY;
526 fieldNameOffset = 2; 521 fieldNameOffset = 2;
527 } else if (StringUtilities.startsWith3(spec, 0, 0x3C, 0x3D, 0x3E)) { 522 } else if (StringUtilities.startsWith3(spec, 0, 0x3C, 0x3D, 0x3E)) {
528 kind = AngularPropertyKind.TWO_WAY; 523 kind = AngularPropertyKind.TWO_WAY;
529 fieldNameOffset = 3; 524 fieldNameOffset = 3;
530 } else { 525 } else {
531 reportError(specLiteral, AngularCode.INVALID_PROPERTY_KIND, [spec]); 526 reportErrorForNode(AngularCode.INVALID_PROPERTY_KIND, specLiteral, [spec ]);
532 continue; 527 continue;
533 } 528 }
534 String fieldName = spec.substring(fieldNameOffset); 529 String fieldName = spec.substring(fieldNameOffset);
535 fieldNameOffset += specLiteral.valueOffset; 530 fieldNameOffset += specLiteral.valueOffset;
536 // prepare field 531 // prepare field
537 PropertyAccessorElement setter = _classElement.type.lookUpSetter(fieldName , _classElement.library); 532 PropertyAccessorElement setter = _classElement.type.lookUpSetter(fieldName , _classElement.library);
538 if (setter == null) { 533 if (setter == null) {
539 reportError2(fieldNameOffset, fieldName.length, AngularCode.INVALID_PROP ERTY_FIELD, [fieldName]); 534 reportErrorForOffset(AngularCode.INVALID_PROPERTY_FIELD, fieldNameOffset , fieldName.length, [fieldName]);
540 continue; 535 continue;
541 } 536 }
542 FieldElement field = setter.variable as FieldElement; 537 FieldElement field = setter.variable as FieldElement;
543 // add property 538 // add property
544 AngularPropertyElementImpl property = new AngularPropertyElementImpl(name, nameOffset); 539 AngularPropertyElementImpl property = new AngularPropertyElementImpl(name, nameOffset);
545 property.field = field; 540 property.field = field;
546 property.propertyKind = kind; 541 property.propertyKind = kind;
547 property.fieldNameOffset = fieldNameOffset; 542 property.fieldNameOffset = fieldNameOffset;
548 properties.add(property); 543 properties.add(property);
549 } 544 }
550 } 545 }
551 546
552 void parseNgController() { 547 void parseNgController() {
553 bool isValid = true; 548 bool isValid = true;
554 // publishAs 549 // publishAs
555 if (!hasStringArgument(_PUBLISH_AS)) { 550 if (!hasStringArgument(_PUBLISH_AS)) {
556 reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS, []); 551 reportErrorForAnnotation(AngularCode.MISSING_PUBLISH_AS, []);
557 isValid = false; 552 isValid = false;
558 } 553 }
559 // selector 554 // selector
560 AngularSelectorElement selector = null; 555 AngularSelectorElement selector = null;
561 if (!hasStringArgument(_SELECTOR)) { 556 if (!hasStringArgument(_SELECTOR)) {
562 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); 557 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []);
563 isValid = false; 558 isValid = false;
564 } else { 559 } else {
565 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR); 560 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR);
566 selector = parseSelector2(selectorLiteral); 561 selector = parseSelectorFromString(selectorLiteral);
567 if (selector == null) { 562 if (selector == null) {
568 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se lectorLiteral]); 563 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se lectorLiteral]);
569 isValid = false; 564 isValid = false;
570 } 565 }
571 } 566 }
572 // create 567 // create
573 if (isValid) { 568 if (isValid) {
574 String name = getStringArgument(_PUBLISH_AS); 569 String name = getStringArgument(_PUBLISH_AS);
575 int nameOffset = getStringArgumentOffset(_PUBLISH_AS); 570 int nameOffset = getStringArgumentOffset(_PUBLISH_AS);
576 AngularControllerElementImpl element = new AngularControllerElementImpl(na me, nameOffset); 571 AngularControllerElementImpl element = new AngularControllerElementImpl(na me, nameOffset);
577 element.selector = selector; 572 element.selector = selector;
578 _classToolkitObjects.add(element); 573 _classToolkitObjects.add(element);
579 } 574 }
580 } 575 }
581 576
582 void parseNgDirective() { 577 void parseNgDirective() {
583 bool isValid = true; 578 bool isValid = true;
584 // selector 579 // selector
585 AngularSelectorElement selector = null; 580 AngularSelectorElement selector = null;
586 if (!hasStringArgument(_SELECTOR)) { 581 if (!hasStringArgument(_SELECTOR)) {
587 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []); 582 reportErrorForAnnotation(AngularCode.MISSING_SELECTOR, []);
588 isValid = false; 583 isValid = false;
589 } else { 584 } else {
590 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR); 585 SimpleStringLiteral selectorLiteral = getStringLiteral(_SELECTOR);
591 selector = parseSelector2(selectorLiteral); 586 selector = parseSelectorFromString(selectorLiteral);
592 if (selector == null) { 587 if (selector == null) {
593 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se lectorLiteral]); 588 reportErrorForArgument(_SELECTOR, AngularCode.CANNOT_PARSE_SELECTOR, [se lectorLiteral]);
594 isValid = false; 589 isValid = false;
595 } 590 }
596 } 591 }
597 // create 592 // create
598 if (isValid) { 593 if (isValid) {
599 int offset = _annotation.offset; 594 int offset = _annotation.offset;
600 AngularDirectiveElementImpl element = new AngularDirectiveElementImpl(offs et); 595 AngularDirectiveElementImpl element = new AngularDirectiveElementImpl(offs et);
601 element.selector = selector; 596 element.selector = selector;
(...skipping 29 matching lines...) Expand all
631 */ 626 */
632 void parseViews() { 627 void parseViews() {
633 List<AngularViewElement> views = []; 628 List<AngularViewElement> views = [];
634 _unit.accept(new RecursiveAstVisitor_AngularCompilationUnitBuilder_parseView s(views)); 629 _unit.accept(new RecursiveAstVisitor_AngularCompilationUnitBuilder_parseView s(views));
635 if (!views.isEmpty) { 630 if (!views.isEmpty) {
636 List<AngularViewElement> viewArray = new List.from(views); 631 List<AngularViewElement> viewArray = new List.from(views);
637 (_unit.element as CompilationUnitElementImpl).angularViews = viewArray; 632 (_unit.element as CompilationUnitElementImpl).angularViews = viewArray;
638 } 633 }
639 } 634 }
640 635
641 void reportError(AstNode node, ErrorCode errorCode, List<Object> arguments) {
642 int offset = node.offset;
643 int length = node.length;
644 reportError2(offset, length, errorCode, arguments);
645 }
646
647 void reportError2(int offset, int length, ErrorCode errorCode, List<Object> ar guments) {
648 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments));
649 }
650
651 void reportErrorForAnnotation(ErrorCode errorCode, List<Object> arguments) { 636 void reportErrorForAnnotation(ErrorCode errorCode, List<Object> arguments) {
652 reportError(_annotation, errorCode, arguments); 637 reportErrorForNode(errorCode, _annotation, arguments);
653 } 638 }
654 639
655 void reportErrorForArgument(String argumentName, ErrorCode errorCode, List<Obj ect> arguments) { 640 void reportErrorForArgument(String argumentName, ErrorCode errorCode, List<Obj ect> arguments) {
656 Expression argument = getArgument(argumentName); 641 Expression argument = getArgument(argumentName);
657 reportError(argument, errorCode, arguments); 642 reportErrorForNode(errorCode, argument, arguments);
643 }
644
645 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts) {
646 int offset = node.offset;
647 int length = node.length;
648 reportErrorForOffset(errorCode, offset, length, arguments);
649 }
650
651 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) {
652 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments));
658 } 653 }
659 } 654 }
660 655
661 class RecursiveAstVisitor_AngularCompilationUnitBuilder_parseScopeProperties ext ends RecursiveAstVisitor<Object> { 656 class RecursiveAstVisitor_AngularCompilationUnitBuilder_parseScopeProperties ext ends RecursiveAstVisitor<Object> {
662 List<AngularScopePropertyElement> properties; 657 List<AngularScopePropertyElement> properties;
663 658
664 RecursiveAstVisitor_AngularCompilationUnitBuilder_parseScopeProperties(this.pr operties) : super(); 659 RecursiveAstVisitor_AngularCompilationUnitBuilder_parseScopeProperties(this.pr operties) : super();
665 660
666 Object visitAssignmentExpression(AssignmentExpression node) { 661 Object visitAssignmentExpression(AssignmentExpression node) {
667 addProperty(node); 662 addProperty(node);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 } 1104 }
1110 sc.Token property = node.propertyKeyword; 1105 sc.Token property = node.propertyKeyword;
1111 if (property == null) { 1106 if (property == null) {
1112 SimpleIdentifier functionName = node.name; 1107 SimpleIdentifier functionName = node.name;
1113 FunctionElementImpl element = new FunctionElementImpl.con1(functionName) ; 1108 FunctionElementImpl element = new FunctionElementImpl.con1(functionName) ;
1114 element.functions = holder.functions; 1109 element.functions = holder.functions;
1115 element.labels = holder.labels; 1110 element.labels = holder.labels;
1116 element.localVariables = holder.localVariables; 1111 element.localVariables = holder.localVariables;
1117 element.parameters = holder.parameters; 1112 element.parameters = holder.parameters;
1118 if (_inFunction) { 1113 if (_inFunction) {
1119 Block enclosingBlock = node.getAncestor(Block); 1114 Block enclosingBlock = node.getAncestor((node) => node is Block);
1120 if (enclosingBlock != null) { 1115 if (enclosingBlock != null) {
1121 int functionEnd = node.offset + node.length; 1116 int functionEnd = node.offset + node.length;
1122 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 1117 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
1123 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 1118 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
1124 } 1119 }
1125 } 1120 }
1126 _currentHolder.addFunction(element); 1121 _currentHolder.addFunction(element);
1127 expression.element = element; 1122 expression.element = element;
1128 functionName.staticElement = element; 1123 functionName.staticElement = element;
1129 } else { 1124 } else {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 visitChildren(holder, node); 1176 visitChildren(holder, node);
1182 } finally { 1177 } finally {
1183 _inFunction = wasInFunction; 1178 _inFunction = wasInFunction;
1184 } 1179 }
1185 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o ffset); 1180 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o ffset);
1186 element.functions = holder.functions; 1181 element.functions = holder.functions;
1187 element.labels = holder.labels; 1182 element.labels = holder.labels;
1188 element.localVariables = holder.localVariables; 1183 element.localVariables = holder.localVariables;
1189 element.parameters = holder.parameters; 1184 element.parameters = holder.parameters;
1190 if (_inFunction) { 1185 if (_inFunction) {
1191 Block enclosingBlock = node.getAncestor(Block); 1186 Block enclosingBlock = node.getAncestor((node) => node is Block);
1192 if (enclosingBlock != null) { 1187 if (enclosingBlock != null) {
1193 int functionEnd = node.offset + node.length; 1188 int functionEnd = node.offset + node.length;
1194 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 1189 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
1195 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 1190 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
1196 } 1191 }
1197 } 1192 }
1198 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 1193 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
1199 if (_functionTypesToFix != null) { 1194 if (_functionTypesToFix != null) {
1200 _functionTypesToFix.add(type); 1195 _functionTypesToFix.add(type);
1201 } 1196 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 fieldName.staticElement = field; 1386 fieldName.staticElement = field;
1392 } else if (_inFunction) { 1387 } else if (_inFunction) {
1393 SimpleIdentifier variableName = node.name; 1388 SimpleIdentifier variableName = node.name;
1394 LocalVariableElementImpl variable; 1389 LocalVariableElementImpl variable;
1395 if (isConst && hasInitializer) { 1390 if (isConst && hasInitializer) {
1396 variable = new ConstLocalVariableElementImpl(variableName); 1391 variable = new ConstLocalVariableElementImpl(variableName);
1397 } else { 1392 } else {
1398 variable = new LocalVariableElementImpl(variableName); 1393 variable = new LocalVariableElementImpl(variableName);
1399 } 1394 }
1400 element = variable; 1395 element = variable;
1401 Block enclosingBlock = node.getAncestor(Block); 1396 Block enclosingBlock = node.getAncestor((node) => node is Block);
1402 int functionEnd = node.offset + node.length; 1397 int functionEnd = node.offset + node.length;
1403 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 1398 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
1404 // TODO(brianwilkerson) This isn't right for variables declared in a for l oop. 1399 // TODO(brianwilkerson) This isn't right for variables declared in a for l oop.
1405 variable.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 1400 variable.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
1406 _currentHolder.addLocalVariable(variable); 1401 _currentHolder.addLocalVariable(variable);
1407 variableName.staticElement = element; 1402 variableName.staticElement = element;
1408 } else { 1403 } else {
1409 SimpleIdentifier variableName = node.name; 1404 SimpleIdentifier variableName = node.name;
1410 TopLevelVariableElementImpl variable; 1405 TopLevelVariableElementImpl variable;
1411 if (isConst && hasInitializer) { 1406 if (isConst && hasInitializer) {
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 2162
2168 /** 2163 /**
2169 * Report an error with the given error code at the given location. Use the gi ven arguments to 2164 * Report an error with the given error code at the given location. Use the gi ven arguments to
2170 * compose the error message. 2165 * compose the error message.
2171 * 2166 *
2172 * @param errorCode the error code of the error to be reported 2167 * @param errorCode the error code of the error to be reported
2173 * @param offset the offset of the first character to be highlighted 2168 * @param offset the offset of the first character to be highlighted
2174 * @param length the number of characters to be highlighted 2169 * @param length the number of characters to be highlighted
2175 * @param arguments the arguments used to compose the error message 2170 * @param arguments the arguments used to compose the error message
2176 */ 2171 */
2177 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg uments) { 2172 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) {
2178 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l ength, errorCode, arguments)); 2173 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l ength, errorCode, arguments));
2179 } 2174 }
2180 2175
2181 /** 2176 /**
2182 * Report an error with the given error code at the location of the value of t he given attribute. 2177 * Report an error with the given error code at the location of the value of t he given attribute.
2183 * Use the given arguments to compose the error message. 2178 * Use the given arguments to compose the error message.
2184 * 2179 *
2185 * @param errorCode the error code of the error to be reported 2180 * @param errorCode the error code of the error to be reported
2186 * @param offset the offset of the first character to be highlighted 2181 * @param offset the offset of the first character to be highlighted
2187 * @param length the number of characters to be highlighted 2182 * @param length the number of characters to be highlighted
2188 * @param arguments the arguments used to compose the error message 2183 * @param arguments the arguments used to compose the error message
2189 */ 2184 */
2190 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) { 2185 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) {
2191 int offset = attribute.valueToken.offset + 1; 2186 int offset = attribute.valueToken.offset + 1;
2192 int length = attribute.valueToken.length - 2; 2187 int length = attribute.valueToken.length - 2;
2193 reportError(errorCode, offset, length, arguments); 2188 reportErrorForOffset(errorCode, offset, length, arguments);
2194 } 2189 }
2195 } 2190 }
2196 2191
2197 /** 2192 /**
2198 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 2193 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
2199 * violations of Dart best practices. 2194 * violations of Dart best practices.
2200 */ 2195 */
2201 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { 2196 class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
2202 static String _GETTER = "getter"; 2197 static String _GETTER = "getter";
2203 2198
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 checkForDeprecatedMemberUse(node.bestElement, node); 2323 checkForDeprecatedMemberUse(node.bestElement, node);
2329 return super.visitPrefixExpression(node); 2324 return super.visitPrefixExpression(node);
2330 } 2325 }
2331 2326
2332 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 2327 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
2333 checkForDeprecatedMemberUse(node.staticElement, node); 2328 checkForDeprecatedMemberUse(node.staticElement, node);
2334 return super.visitRedirectingConstructorInvocation(node); 2329 return super.visitRedirectingConstructorInvocation(node);
2335 } 2330 }
2336 2331
2337 Object visitSimpleIdentifier(SimpleIdentifier node) { 2332 Object visitSimpleIdentifier(SimpleIdentifier node) {
2338 checkForDeprecatedMemberUse2(node); 2333 checkForDeprecatedMemberUseAtIdentifier(node);
2339 return super.visitSimpleIdentifier(node); 2334 return super.visitSimpleIdentifier(node);
2340 } 2335 }
2341 2336
2342 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 2337 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2343 checkForDeprecatedMemberUse(node.staticElement, node); 2338 checkForDeprecatedMemberUse(node.staticElement, node);
2344 return super.visitSuperConstructorInvocation(node); 2339 return super.visitSuperConstructorInvocation(node);
2345 } 2340 }
2346 2341
2347 Object visitVariableDeclaration(VariableDeclaration node) { 2342 Object visitVariableDeclaration(VariableDeclaration node) {
2348 checkForUseOfVoidResult(node.initializer); 2343 checkForUseOfVoidResult(node.initializer);
(...skipping 17 matching lines...) Expand all
2366 Type2 lhsType = expression.staticType; 2361 Type2 lhsType = expression.staticType;
2367 Type2 rhsType = typeName.type; 2362 Type2 rhsType = typeName.type;
2368 if (lhsType == null || rhsType == null) { 2363 if (lhsType == null || rhsType == null) {
2369 return false; 2364 return false;
2370 } 2365 }
2371 String rhsNameStr = typeName.name.name; 2366 String rhsNameStr = typeName.name.name;
2372 // if x is dynamic 2367 // if x is dynamic
2373 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) { 2368 if (rhsType.isDynamic && rhsNameStr == sc.Keyword.DYNAMIC.syntax) {
2374 if (node.notOperator == null) { 2369 if (node.notOperator == null) {
2375 // the is case 2370 // the is case
2376 _errorReporter.reportError3(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node, []); 2371 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node, []);
2377 } else { 2372 } else {
2378 // the is not case 2373 // the is not case
2379 _errorReporter.reportError3(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node, []); 2374 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, node, []);
2380 } 2375 }
2381 return true; 2376 return true;
2382 } 2377 }
2383 Element rhsElement = rhsType.element; 2378 Element rhsElement = rhsType.element;
2384 LibraryElement libraryElement = rhsElement != null ? rhsElement.library : nu ll; 2379 LibraryElement libraryElement = rhsElement != null ? rhsElement.library : nu ll;
2385 if (libraryElement != null && libraryElement.isDartCore) { 2380 if (libraryElement != null && libraryElement.isDartCore) {
2386 // if x is Object or null is Null 2381 // if x is Object or null is Null
2387 if (rhsType.isObject || (expression is NullLiteral && rhsNameStr == _NULL_ TYPE_NAME)) { 2382 if (rhsType.isObject || (expression is NullLiteral && rhsNameStr == _NULL_ TYPE_NAME)) {
2388 if (node.notOperator == null) { 2383 if (node.notOperator == null) {
2389 // the is case 2384 // the is case
2390 _errorReporter.reportError3(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node , []); 2385 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_TRUE, node , []);
2391 } else { 2386 } else {
2392 // the is not case 2387 // the is not case
2393 _errorReporter.reportError3(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, nod e, []); 2388 _errorReporter.reportError2(HintCode.UNNECESSARY_TYPE_CHECK_FALSE, nod e, []);
2394 } 2389 }
2395 return true; 2390 return true;
2396 } else if (rhsNameStr == _NULL_TYPE_NAME) { 2391 } else if (rhsNameStr == _NULL_TYPE_NAME) {
2397 if (node.notOperator == null) { 2392 if (node.notOperator == null) {
2398 // the is case 2393 // the is case
2399 _errorReporter.reportError3(HintCode.TYPE_CHECK_IS_NULL, node, []); 2394 _errorReporter.reportError2(HintCode.TYPE_CHECK_IS_NULL, node, []);
2400 } else { 2395 } else {
2401 // the is not case 2396 // the is not case
2402 _errorReporter.reportError3(HintCode.TYPE_CHECK_IS_NOT_NULL, node, []) ; 2397 _errorReporter.reportError2(HintCode.TYPE_CHECK_IS_NOT_NULL, node, []) ;
2403 } 2398 }
2404 return true; 2399 return true;
2405 } 2400 }
2406 } 2401 }
2407 return false; 2402 return false;
2408 } 2403 }
2409 2404
2410 /** 2405 /**
2411 * Given some [Element], look at the associated metadata and report the use of the member if 2406 * Given some [Element], look at the associated metadata and report the use of the member if
2412 * it is declared as deprecated. 2407 * it is declared as deprecated.
2413 * 2408 *
2414 * @param element some element to check for deprecated use of 2409 * @param element some element to check for deprecated use of
2415 * @param node the node use for the location of the error 2410 * @param node the node use for the location of the error
2416 * @return `true` if and only if a hint code is generated on the passed node 2411 * @return `true` if and only if a hint code is generated on the passed node
2417 * @see HintCode#DEPRECATED_MEMBER_USE 2412 * @see HintCode#DEPRECATED_MEMBER_USE
2418 */ 2413 */
2419 bool checkForDeprecatedMemberUse(Element element, AstNode node) { 2414 bool checkForDeprecatedMemberUse(Element element, AstNode node) {
2420 if (element != null && element.isDeprecated) { 2415 if (element != null && element.isDeprecated) {
2421 String displayName = element.displayName; 2416 String displayName = element.displayName;
2422 if (element is ConstructorElement) { 2417 if (element is ConstructorElement) {
2423 // TODO(jwren) We should modify ConstructorElement.getDisplayName(), or have the logic 2418 // TODO(jwren) We should modify ConstructorElement.getDisplayName(), or have the logic
2424 // centralized elsewhere, instead of doing this logic here. 2419 // centralized elsewhere, instead of doing this logic here.
2425 ConstructorElement constructorElement = element; 2420 ConstructorElement constructorElement = element;
2426 displayName = constructorElement.enclosingElement.displayName; 2421 displayName = constructorElement.enclosingElement.displayName;
2427 if (!constructorElement.displayName.isEmpty) { 2422 if (!constructorElement.displayName.isEmpty) {
2428 displayName = "${displayName}.${constructorElement.displayName}"; 2423 displayName = "${displayName}.${constructorElement.displayName}";
2429 } 2424 }
2430 } 2425 }
2431 _errorReporter.reportError3(HintCode.DEPRECATED_MEMBER_USE, node, [display Name]); 2426 _errorReporter.reportError2(HintCode.DEPRECATED_MEMBER_USE, node, [display Name]);
2432 return true; 2427 return true;
2433 } 2428 }
2434 return false; 2429 return false;
2435 } 2430 }
2436 2431
2437 /** 2432 /**
2438 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse] 2433 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse]
2439 * if the node is not in a declaration context. 2434 * if the node is not in a declaration context.
2440 * 2435 *
2441 * Also, if the identifier is a constructor name in a constructor invocation, then calls to the 2436 * Also, if the identifier is a constructor name in a constructor invocation, then calls to the
2442 * deprecated constructor will be caught by 2437 * deprecated constructor will be caught by
2443 * [visitInstanceCreationExpression] and 2438 * [visitInstanceCreationExpression] and
2444 * [visitSuperConstructorInvocation], and can be ignored by 2439 * [visitSuperConstructorInvocation], and can be ignored by
2445 * this visit method. 2440 * this visit method.
2446 * 2441 *
2447 * @param identifier some simple identifier to check for deprecated use of 2442 * @param identifier some simple identifier to check for deprecated use of
2448 * @return `true` if and only if a hint code is generated on the passed node 2443 * @return `true` if and only if a hint code is generated on the passed node
2449 * @see HintCode#DEPRECATED_MEMBER_USE 2444 * @see HintCode#DEPRECATED_MEMBER_USE
2450 */ 2445 */
2451 bool checkForDeprecatedMemberUse2(SimpleIdentifier identifier) { 2446 bool checkForDeprecatedMemberUseAtIdentifier(SimpleIdentifier identifier) {
2452 if (identifier.inDeclarationContext()) { 2447 if (identifier.inDeclarationContext()) {
2453 return false; 2448 return false;
2454 } 2449 }
2455 AstNode parent = identifier.parent; 2450 AstNode parent = identifier.parent;
2456 if ((parent is ConstructorName && identical(identifier, parent.name)) || (pa rent is SuperConstructorInvocation && identical(identifier, parent.constructorNa me)) || parent is HideCombinator) { 2451 if ((parent is ConstructorName && identical(identifier, parent.name)) || (pa rent is SuperConstructorInvocation && identical(identifier, parent.constructorNa me)) || parent is HideCombinator) {
2457 return false; 2452 return false;
2458 } 2453 }
2459 return checkForDeprecatedMemberUse(identifier.bestElement, identifier); 2454 return checkForDeprecatedMemberUse(identifier.bestElement, identifier);
2460 } 2455 }
2461 2456
(...skipping 17 matching lines...) Expand all
2479 LibraryElement libraryElement = methodElement.library; 2474 LibraryElement libraryElement = methodElement.library;
2480 if (libraryElement != null && !libraryElement.isDartCore) { 2475 if (libraryElement != null && !libraryElement.isDartCore) {
2481 return false; 2476 return false;
2482 } 2477 }
2483 // Report error if the (x/y) has toInt() invoked on it 2478 // Report error if the (x/y) has toInt() invoked on it
2484 if (node.parent is ParenthesizedExpression) { 2479 if (node.parent is ParenthesizedExpression) {
2485 ParenthesizedExpression parenthesizedExpression = wrapParenthesizedExpress ion(node.parent as ParenthesizedExpression); 2480 ParenthesizedExpression parenthesizedExpression = wrapParenthesizedExpress ion(node.parent as ParenthesizedExpression);
2486 if (parenthesizedExpression.parent is MethodInvocation) { 2481 if (parenthesizedExpression.parent is MethodInvocation) {
2487 MethodInvocation methodInvocation = parenthesizedExpression.parent as Me thodInvocation; 2482 MethodInvocation methodInvocation = parenthesizedExpression.parent as Me thodInvocation;
2488 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv ocation.argumentList.arguments.isEmpty) { 2483 if (_TO_INT_METHOD_NAME == methodInvocation.methodName.name && methodInv ocation.argumentList.arguments.isEmpty) {
2489 _errorReporter.reportError3(HintCode.DIVISION_OPTIMIZATION, methodInvo cation, []); 2484 _errorReporter.reportError2(HintCode.DIVISION_OPTIMIZATION, methodInvo cation, []);
2490 return true; 2485 return true;
2491 } 2486 }
2492 } 2487 }
2493 } 2488 }
2494 return false; 2489 return false;
2495 } 2490 }
2496 2491
2497 /** 2492 /**
2498 * Generate a hint for functions or methods that have a return type, but do no t have a return 2493 * Generate a hint for functions or methods that have a return type, but do no t have a return
2499 * statement on all branches. At the end of blocks with no return, Dart implic itly returns 2494 * statement on all branches. At the end of blocks with no return, Dart implic itly returns
(...skipping 14 matching lines...) Expand all
2514 return false; 2509 return false;
2515 } 2510 }
2516 // Check that the type is resolvable, and is not "void" 2511 // Check that the type is resolvable, and is not "void"
2517 Type2 returnTypeType = returnType.type; 2512 Type2 returnTypeType = returnType.type;
2518 if (returnTypeType == null || returnTypeType.isVoid) { 2513 if (returnTypeType == null || returnTypeType.isVoid) {
2519 return false; 2514 return false;
2520 } 2515 }
2521 // Check the block for a return statement, if not, create the hint 2516 // Check the block for a return statement, if not, create the hint
2522 BlockFunctionBody blockFunctionBody = body as BlockFunctionBody; 2517 BlockFunctionBody blockFunctionBody = body as BlockFunctionBody;
2523 if (!blockFunctionBody.accept(new ExitDetector())) { 2518 if (!blockFunctionBody.accept(new ExitDetector())) {
2524 _errorReporter.reportError3(HintCode.MISSING_RETURN, returnType, [returnTy peType.displayName]); 2519 _errorReporter.reportError2(HintCode.MISSING_RETURN, returnType, [returnTy peType.displayName]);
2525 return true; 2520 return true;
2526 } 2521 }
2527 return false; 2522 return false;
2528 } 2523 }
2529 2524
2530 /** 2525 /**
2531 * Check for the passed class declaration for the 2526 * Check for the passed class declaration for the
2532 * [HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. 2527 * [HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code.
2533 * 2528 *
2534 * @param node the class declaration to check 2529 * @param node the class declaration to check
2535 * @return `true` if and only if a hint code is generated on the passed node 2530 * @return `true` if and only if a hint code is generated on the passed node
2536 * @see HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE 2531 * @see HintCode#OVERRIDE_EQUALS_BUT_NOT_HASH_CODE
2537 */ 2532 */
2538 bool checkForOverrideEqualsButNotHashCode(ClassDeclaration node) { 2533 bool checkForOverrideEqualsButNotHashCode(ClassDeclaration node) {
2539 ClassElement classElement = node.element; 2534 ClassElement classElement = node.element;
2540 if (classElement == null) { 2535 if (classElement == null) {
2541 return false; 2536 return false;
2542 } 2537 }
2543 MethodElement equalsOperatorMethodElement = classElement.getMethod(sc.TokenT ype.EQ_EQ.lexeme); 2538 MethodElement equalsOperatorMethodElement = classElement.getMethod(sc.TokenT ype.EQ_EQ.lexeme);
2544 if (equalsOperatorMethodElement != null) { 2539 if (equalsOperatorMethodElement != null) {
2545 PropertyAccessorElement hashCodeElement = classElement.getGetter(_HASHCODE _GETTER_NAME); 2540 PropertyAccessorElement hashCodeElement = classElement.getGetter(_HASHCODE _GETTER_NAME);
2546 if (hashCodeElement == null) { 2541 if (hashCodeElement == null) {
2547 _errorReporter.reportError3(HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE, node.name, [classElement.displayName]); 2542 _errorReporter.reportError2(HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE, node.name, [classElement.displayName]);
2548 return true; 2543 return true;
2549 } 2544 }
2550 } 2545 }
2551 return false; 2546 return false;
2552 } 2547 }
2553 2548
2554 /** 2549 /**
2555 * Checks that if the passed method declaration is private, it does not overri de a private member 2550 * Checks that if the passed method declaration is private, it does not overri de a private member
2556 * in a superclass. 2551 * in a superclass.
2557 * 2552 *
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 PropertyAccessorElement overriddenAccessor = null; 2585 PropertyAccessorElement overriddenAccessor = null;
2591 List<PropertyAccessorElement> accessors = classElement.accessors; 2586 List<PropertyAccessorElement> accessors = classElement.accessors;
2592 for (PropertyAccessorElement propertyAccessorElement in accessors) { 2587 for (PropertyAccessorElement propertyAccessorElement in accessors) {
2593 if (elementName == propertyAccessorElement.name) { 2588 if (elementName == propertyAccessorElement.name) {
2594 overriddenAccessor = propertyAccessorElement; 2589 overriddenAccessor = propertyAccessorElement;
2595 break; 2590 break;
2596 } 2591 }
2597 } 2592 }
2598 if (overriddenAccessor != null) { 2593 if (overriddenAccessor != null) {
2599 String memberType = (executableElement as PropertyAccessorElement).i sGetter ? _GETTER : _SETTER; 2594 String memberType = (executableElement as PropertyAccessorElement).i sGetter ? _GETTER : _SETTER;
2600 _errorReporter.reportError3(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [ 2595 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [
2601 memberType, 2596 memberType,
2602 executableElement.displayName, 2597 executableElement.displayName,
2603 classElement.displayName]); 2598 classElement.displayName]);
2604 return true; 2599 return true;
2605 } 2600 }
2606 } else { 2601 } else {
2607 MethodElement overriddenMethod = classElement.getMethod(elementName); 2602 MethodElement overriddenMethod = classElement.getMethod(elementName);
2608 if (overriddenMethod != null) { 2603 if (overriddenMethod != null) {
2609 _errorReporter.reportError3(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [ 2604 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [
2610 _METHOD, 2605 _METHOD,
2611 executableElement.displayName, 2606 executableElement.displayName,
2612 classElement.displayName]); 2607 classElement.displayName]);
2613 return true; 2608 return true;
2614 } 2609 }
2615 } 2610 }
2616 } 2611 }
2617 superType = classElement.supertype; 2612 superType = classElement.supertype;
2618 classElement = superType != null ? superType.element : null; 2613 classElement = superType != null ? superType.element : null;
2619 } 2614 }
2620 return false; 2615 return false;
2621 } 2616 }
2622 2617
2623 /** 2618 /**
2624 * Check for the passed as expression for the [HintCode#UNNECESSARY_CAST] hint code. 2619 * Check for the passed as expression for the [HintCode#UNNECESSARY_CAST] hint code.
2625 * 2620 *
2626 * @param node the as expression to check 2621 * @param node the as expression to check
2627 * @return `true` if and only if a hint code is generated on the passed node 2622 * @return `true` if and only if a hint code is generated on the passed node
2628 * @see HintCode#UNNECESSARY_CAST 2623 * @see HintCode#UNNECESSARY_CAST
2629 */ 2624 */
2630 bool checkForUnnecessaryCast(AsExpression node) { 2625 bool checkForUnnecessaryCast(AsExpression node) {
2631 Expression expression = node.expression; 2626 Expression expression = node.expression;
2632 TypeName typeName = node.type; 2627 TypeName typeName = node.type;
2633 Type2 lhsType = expression.staticType; 2628 Type2 lhsType = expression.staticType;
2634 Type2 rhsType = typeName.type; 2629 Type2 rhsType = typeName.type;
2635 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to r emove the 2630 // TODO(jwren) After dartbug.com/13732, revisit this, we should be able to r emove the
2636 // !(x instanceof TypeParameterType) checks. 2631 // !(x instanceof TypeParameterType) checks.
2637 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT ype.isSubtypeOf(rhsType)) { 2632 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT ype.isSubtypeOf(rhsType)) {
2638 _errorReporter.reportError3(HintCode.UNNECESSARY_CAST, node, []); 2633 _errorReporter.reportError2(HintCode.UNNECESSARY_CAST, node, []);
2639 return true; 2634 return true;
2640 } 2635 }
2641 return false; 2636 return false;
2642 } 2637 }
2643 2638
2644 /** 2639 /**
2645 * Check for situations where the result of a method or function is used, when it returns 'void'. 2640 * Check for situations where the result of a method or function is used, when it returns 'void'.
2646 * 2641 *
2647 * TODO(jwren) Many other situations of use could be covered. We currently cov er the cases var x = 2642 * TODO(jwren) Many other situations of use could be covered. We currently cov er the cases var x =
2648 * m() and x = m(), but we could also cover cases such as m().x, m()[k], a + m (), f(m()), return 2643 * m() and x = m(), but we could also cover cases such as m().x, m()[k], a + m (), f(m()), return
2649 * m(). 2644 * m().
2650 * 2645 *
2651 * @param node expression on the RHS of some assignment 2646 * @param node expression on the RHS of some assignment
2652 * @return `true` if and only if a hint code is generated on the passed node 2647 * @return `true` if and only if a hint code is generated on the passed node
2653 * @see HintCode#USE_OF_VOID_RESULT 2648 * @see HintCode#USE_OF_VOID_RESULT
2654 */ 2649 */
2655 bool checkForUseOfVoidResult(Expression expression) { 2650 bool checkForUseOfVoidResult(Expression expression) {
2656 if (expression == null || expression is! MethodInvocation) { 2651 if (expression == null || expression is! MethodInvocation) {
2657 return false; 2652 return false;
2658 } 2653 }
2659 MethodInvocation methodInvocation = expression as MethodInvocation; 2654 MethodInvocation methodInvocation = expression as MethodInvocation;
2660 if (identical(methodInvocation.staticType, VoidTypeImpl.instance)) { 2655 if (identical(methodInvocation.staticType, VoidTypeImpl.instance)) {
2661 SimpleIdentifier methodName = methodInvocation.methodName; 2656 SimpleIdentifier methodName = methodInvocation.methodName;
2662 _errorReporter.reportError3(HintCode.USE_OF_VOID_RESULT, methodName, [meth odName.name]); 2657 _errorReporter.reportError2(HintCode.USE_OF_VOID_RESULT, methodName, [meth odName.name]);
2663 return true; 2658 return true;
2664 } 2659 }
2665 return false; 2660 return false;
2666 } 2661 }
2667 } 2662 }
2668 2663
2669 /** 2664 /**
2670 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for 2665 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for
2671 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE]. 2666 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE].
2672 */ 2667 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 // && libraryElement.isDartCore()) { 2712 // && libraryElement.isDartCore()) {
2718 // if (node.getNotOperator() == null) { 2713 // if (node.getNotOperator() == null) {
2719 // errorReporter.reportError(HintCode.IS_INT, node); 2714 // errorReporter.reportError(HintCode.IS_INT, node);
2720 // } else { 2715 // } else {
2721 // errorReporter.reportError(HintCode.IS_NOT_INT, node); 2716 // errorReporter.reportError(HintCode.IS_NOT_INT, node);
2722 // } 2717 // }
2723 // return true; 2718 // return true;
2724 // } else 2719 // } else
2725 if (typeNameStr == _DOUBLE_TYPE_NAME && libraryElement != null && libraryE lement.isDartCore) { 2720 if (typeNameStr == _DOUBLE_TYPE_NAME && libraryElement != null && libraryE lement.isDartCore) {
2726 if (node.notOperator == null) { 2721 if (node.notOperator == null) {
2727 _errorReporter.reportError3(HintCode.IS_DOUBLE, node, []); 2722 _errorReporter.reportError2(HintCode.IS_DOUBLE, node, []);
2728 } else { 2723 } else {
2729 _errorReporter.reportError3(HintCode.IS_NOT_DOUBLE, node, []); 2724 _errorReporter.reportError2(HintCode.IS_NOT_DOUBLE, node, []);
2730 } 2725 }
2731 return true; 2726 return true;
2732 } 2727 }
2733 } 2728 }
2734 return false; 2729 return false;
2735 } 2730 }
2736 } 2731 }
2737 2732
2738 /** 2733 /**
2739 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of 2734 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of
(...skipping 18 matching lines...) Expand all
2758 sc.Token operator = node.operator; 2753 sc.Token operator = node.operator;
2759 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND); 2754 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND);
2760 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR); 2755 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR);
2761 if (isAmpAmp || isBarBar) { 2756 if (isAmpAmp || isBarBar) {
2762 Expression lhsCondition = node.leftOperand; 2757 Expression lhsCondition = node.leftOperand;
2763 if (!isDebugConstant(lhsCondition)) { 2758 if (!isDebugConstant(lhsCondition)) {
2764 ValidResult lhsResult = getConstantBooleanValue(lhsCondition); 2759 ValidResult lhsResult = getConstantBooleanValue(lhsCondition);
2765 if (lhsResult != null) { 2760 if (lhsResult != null) {
2766 if (lhsResult.isTrue && isBarBar) { 2761 if (lhsResult.isTrue && isBarBar) {
2767 // report error on else block: true || !e! 2762 // report error on else block: true || !e!
2768 _errorReporter.reportError3(HintCode.DEAD_CODE, node.rightOperand, [ ]); 2763 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, [ ]);
2769 // only visit the LHS: 2764 // only visit the LHS:
2770 safelyVisit(lhsCondition); 2765 safelyVisit(lhsCondition);
2771 return null; 2766 return null;
2772 } else if (lhsResult.isFalse && isAmpAmp) { 2767 } else if (lhsResult.isFalse && isAmpAmp) {
2773 // report error on if block: false && !e! 2768 // report error on if block: false && !e!
2774 _errorReporter.reportError3(HintCode.DEAD_CODE, node.rightOperand, [ ]); 2769 _errorReporter.reportError2(HintCode.DEAD_CODE, node.rightOperand, [ ]);
2775 // only visit the LHS: 2770 // only visit the LHS:
2776 safelyVisit(lhsCondition); 2771 safelyVisit(lhsCondition);
2777 return null; 2772 return null;
2778 } 2773 }
2779 } 2774 }
2780 } 2775 }
2781 } 2776 }
2782 return super.visitBinaryExpression(node); 2777 return super.visitBinaryExpression(node);
2783 } 2778 }
2784 2779
2785 /** 2780 /**
2786 * For each [Block], this method reports and error on all statements between t he end of the 2781 * For each [Block], this method reports and error on all statements between t he end of the
2787 * block and the first return statement (assuming there it is not at the end o f the block.) 2782 * block and the first return statement (assuming there it is not at the end o f the block.)
2788 * 2783 *
2789 * @param node the block to evaluate 2784 * @param node the block to evaluate
2790 */ 2785 */
2791 Object visitBlock(Block node) { 2786 Object visitBlock(Block node) {
2792 NodeList<Statement> statements = node.statements; 2787 NodeList<Statement> statements = node.statements;
2793 int size = statements.length; 2788 int size = statements.length;
2794 for (int i = 0; i < size; i++) { 2789 for (int i = 0; i < size; i++) {
2795 Statement currentStatement = statements[i]; 2790 Statement currentStatement = statements[i];
2796 safelyVisit(currentStatement); 2791 safelyVisit(currentStatement);
2797 if (currentStatement is ReturnStatement && i != size - 1) { 2792 if (currentStatement is ReturnStatement && i != size - 1) {
2798 Statement nextStatement = statements[i + 1]; 2793 Statement nextStatement = statements[i + 1];
2799 Statement lastStatement = statements[size - 1]; 2794 Statement lastStatement = statements[size - 1];
2800 int offset = nextStatement.offset; 2795 int offset = nextStatement.offset;
2801 int length = lastStatement.end - offset; 2796 int length = lastStatement.end - offset;
2802 _errorReporter.reportError5(HintCode.DEAD_CODE, offset, length, []); 2797 _errorReporter.reportError4(HintCode.DEAD_CODE, offset, length, []);
2803 return null; 2798 return null;
2804 } 2799 }
2805 } 2800 }
2806 return null; 2801 return null;
2807 } 2802 }
2808 2803
2809 Object visitConditionalExpression(ConditionalExpression node) { 2804 Object visitConditionalExpression(ConditionalExpression node) {
2810 Expression conditionExpression = node.condition; 2805 Expression conditionExpression = node.condition;
2811 safelyVisit(conditionExpression); 2806 safelyVisit(conditionExpression);
2812 if (!isDebugConstant(conditionExpression)) { 2807 if (!isDebugConstant(conditionExpression)) {
2813 ValidResult result = getConstantBooleanValue(conditionExpression); 2808 ValidResult result = getConstantBooleanValue(conditionExpression);
2814 if (result != null) { 2809 if (result != null) {
2815 if (result.isTrue) { 2810 if (result.isTrue) {
2816 // report error on else block: true ? 1 : !2! 2811 // report error on else block: true ? 1 : !2!
2817 _errorReporter.reportError3(HintCode.DEAD_CODE, node.elseExpression, [ ]); 2812 _errorReporter.reportError2(HintCode.DEAD_CODE, node.elseExpression, [ ]);
2818 safelyVisit(node.thenExpression); 2813 safelyVisit(node.thenExpression);
2819 return null; 2814 return null;
2820 } else { 2815 } else {
2821 // report error on if block: false ? !1! : 2 2816 // report error on if block: false ? !1! : 2
2822 _errorReporter.reportError3(HintCode.DEAD_CODE, node.thenExpression, [ ]); 2817 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenExpression, [ ]);
2823 safelyVisit(node.elseExpression); 2818 safelyVisit(node.elseExpression);
2824 return null; 2819 return null;
2825 } 2820 }
2826 } 2821 }
2827 } 2822 }
2828 return super.visitConditionalExpression(node); 2823 return super.visitConditionalExpression(node);
2829 } 2824 }
2830 2825
2831 Object visitIfStatement(IfStatement node) { 2826 Object visitIfStatement(IfStatement node) {
2832 Expression conditionExpression = node.condition; 2827 Expression conditionExpression = node.condition;
2833 safelyVisit(conditionExpression); 2828 safelyVisit(conditionExpression);
2834 if (!isDebugConstant(conditionExpression)) { 2829 if (!isDebugConstant(conditionExpression)) {
2835 ValidResult result = getConstantBooleanValue(conditionExpression); 2830 ValidResult result = getConstantBooleanValue(conditionExpression);
2836 if (result != null) { 2831 if (result != null) {
2837 if (result.isTrue) { 2832 if (result.isTrue) {
2838 // report error on else block: if(true) {} else {!} 2833 // report error on else block: if(true) {} else {!}
2839 Statement elseStatement = node.elseStatement; 2834 Statement elseStatement = node.elseStatement;
2840 if (elseStatement != null) { 2835 if (elseStatement != null) {
2841 _errorReporter.reportError3(HintCode.DEAD_CODE, elseStatement, []); 2836 _errorReporter.reportError2(HintCode.DEAD_CODE, elseStatement, []);
2842 safelyVisit(node.thenStatement); 2837 safelyVisit(node.thenStatement);
2843 return null; 2838 return null;
2844 } 2839 }
2845 } else { 2840 } else {
2846 // report error on if block: if (false) {!} else {} 2841 // report error on if block: if (false) {!} else {}
2847 _errorReporter.reportError3(HintCode.DEAD_CODE, node.thenStatement, [] ); 2842 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, [] );
2848 safelyVisit(node.elseStatement); 2843 safelyVisit(node.elseStatement);
2849 return null; 2844 return null;
2850 } 2845 }
2851 } 2846 }
2852 } 2847 }
2853 return super.visitIfStatement(node); 2848 return super.visitIfStatement(node);
2854 } 2849 }
2855 2850
2856 Object visitTryStatement(TryStatement node) { 2851 Object visitTryStatement(TryStatement node) {
2857 safelyVisit(node.body); 2852 safelyVisit(node.body);
(...skipping 13 matching lines...) Expand all
2871 // Found catch clause clause that has Object as an exception type, t his is equivalent to 2866 // Found catch clause clause that has Object as an exception type, t his is equivalent to
2872 // having a catch clause that doesn't have an exception type, visit the block, but 2867 // having a catch clause that doesn't have an exception type, visit the block, but
2873 // generate an error on any following catch clauses (and don't visi t them). 2868 // generate an error on any following catch clauses (and don't visi t them).
2874 safelyVisit(catchClause); 2869 safelyVisit(catchClause);
2875 if (i + 1 != numOfCatchClauses) { 2870 if (i + 1 != numOfCatchClauses) {
2876 // this catch clause is not the last in the try statement 2871 // this catch clause is not the last in the try statement
2877 CatchClause nextCatchClause = catchClauses[i + 1]; 2872 CatchClause nextCatchClause = catchClauses[i + 1];
2878 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 2873 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
2879 int offset = nextCatchClause.offset; 2874 int offset = nextCatchClause.offset;
2880 int length = lastCatchClause.end - offset; 2875 int length = lastCatchClause.end - offset;
2881 _errorReporter.reportError5(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT CH, offset, length, []); 2876 _errorReporter.reportError4(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT CH, offset, length, []);
2882 return null; 2877 return null;
2883 } 2878 }
2884 } 2879 }
2885 for (Type2 type in visitedTypes) { 2880 for (Type2 type in visitedTypes) {
2886 if (currentType.isSubtypeOf(type)) { 2881 if (currentType.isSubtypeOf(type)) {
2887 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 2882 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
2888 int offset = catchClause.offset; 2883 int offset = catchClause.offset;
2889 int length = lastCatchClause.end - offset; 2884 int length = lastCatchClause.end - offset;
2890 _errorReporter.reportError5(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, o ffset, length, [currentType.displayName, type.displayName]); 2885 _errorReporter.reportError4(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, o ffset, length, [currentType.displayName, type.displayName]);
2891 return null; 2886 return null;
2892 } 2887 }
2893 } 2888 }
2894 visitedTypes.add(currentType); 2889 visitedTypes.add(currentType);
2895 } 2890 }
2896 safelyVisit(catchClause); 2891 safelyVisit(catchClause);
2897 } else { 2892 } else {
2898 // Found catch clause clause that doesn't have an exception type, visit the block, but 2893 // Found catch clause clause that doesn't have an exception type, visit the block, but
2899 // generate an error on any following catch clauses (and don't visit the m). 2894 // generate an error on any following catch clauses (and don't visit the m).
2900 safelyVisit(catchClause); 2895 safelyVisit(catchClause);
2901 if (i + 1 != numOfCatchClauses) { 2896 if (i + 1 != numOfCatchClauses) {
2902 // this catch clause is not the last in the try statement 2897 // this catch clause is not the last in the try statement
2903 CatchClause nextCatchClause = catchClauses[i + 1]; 2898 CatchClause nextCatchClause = catchClauses[i + 1];
2904 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 2899 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
2905 int offset = nextCatchClause.offset; 2900 int offset = nextCatchClause.offset;
2906 int length = lastCatchClause.end - offset; 2901 int length = lastCatchClause.end - offset;
2907 _errorReporter.reportError5(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length, []); 2902 _errorReporter.reportError4(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length, []);
2908 return null; 2903 return null;
2909 } 2904 }
2910 } 2905 }
2911 } 2906 }
2912 return null; 2907 return null;
2913 } 2908 }
2914 2909
2915 Object visitWhileStatement(WhileStatement node) { 2910 Object visitWhileStatement(WhileStatement node) {
2916 Expression conditionExpression = node.condition; 2911 Expression conditionExpression = node.condition;
2917 safelyVisit(conditionExpression); 2912 safelyVisit(conditionExpression);
2918 if (!isDebugConstant(conditionExpression)) { 2913 if (!isDebugConstant(conditionExpression)) {
2919 ValidResult result = getConstantBooleanValue(conditionExpression); 2914 ValidResult result = getConstantBooleanValue(conditionExpression);
2920 if (result != null) { 2915 if (result != null) {
2921 if (result.isFalse) { 2916 if (result.isFalse) {
2922 // report error on if block: while (false) {!} 2917 // report error on if block: while (false) {!}
2923 _errorReporter.reportError3(HintCode.DEAD_CODE, node.body, []); 2918 _errorReporter.reportError2(HintCode.DEAD_CODE, node.body, []);
2924 return null; 2919 return null;
2925 } 2920 }
2926 } 2921 }
2927 } 2922 }
2928 safelyVisit(node.body); 2923 safelyVisit(node.body);
2929 return null; 2924 return null;
2930 } 2925 }
2931 2926
2932 /** 2927 /**
2933 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is 2928 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
3523 /** 3518 /**
3524 * Any time after the defining compilation unit has been visited by this visit or, this method can 3519 * Any time after the defining compilation unit has been visited by this visit or, this method can
3525 * be called to report an [HintCode#DUPLICATE_IMPORT] hint for each of the imp ort directives 3520 * be called to report an [HintCode#DUPLICATE_IMPORT] hint for each of the imp ort directives
3526 * in the [duplicateImports] list. 3521 * in the [duplicateImports] list.
3527 * 3522 *
3528 * @param errorReporter the error reporter to report the set of [HintCode#DUPL ICATE_IMPORT] 3523 * @param errorReporter the error reporter to report the set of [HintCode#DUPL ICATE_IMPORT]
3529 * hints to 3524 * hints to
3530 */ 3525 */
3531 void generateDuplicateImportHints(ErrorReporter errorReporter) { 3526 void generateDuplicateImportHints(ErrorReporter errorReporter) {
3532 for (ImportDirective duplicateImport in _duplicateImports) { 3527 for (ImportDirective duplicateImport in _duplicateImports) {
3533 errorReporter.reportError3(HintCode.DUPLICATE_IMPORT, duplicateImport.uri, []); 3528 errorReporter.reportError2(HintCode.DUPLICATE_IMPORT, duplicateImport.uri, []);
3534 } 3529 }
3535 } 3530 }
3536 3531
3537 /** 3532 /**
3538 * After all of the compilation units have been visited by this visitor, this method can be called 3533 * After all of the compilation units have been visited by this visitor, this method can be called
3539 * to report an [HintCode#UNUSED_IMPORT] hint for each of the import directive s in the 3534 * to report an [HintCode#UNUSED_IMPORT] hint for each of the import directive s in the
3540 * [unusedImports] list. 3535 * [unusedImports] list.
3541 * 3536 *
3542 * @param errorReporter the error reporter to report the set of [HintCode#UNUS ED_IMPORT] 3537 * @param errorReporter the error reporter to report the set of [HintCode#UNUS ED_IMPORT]
3543 * hints to 3538 * hints to
3544 */ 3539 */
3545 void generateUnusedImportHints(ErrorReporter errorReporter) { 3540 void generateUnusedImportHints(ErrorReporter errorReporter) {
3546 for (ImportDirective unusedImport in _unusedImports) { 3541 for (ImportDirective unusedImport in _unusedImports) {
3547 // Check that the import isn't dart:core 3542 // Check that the import isn't dart:core
3548 ImportElement importElement = unusedImport.element; 3543 ImportElement importElement = unusedImport.element;
3549 if (importElement != null) { 3544 if (importElement != null) {
3550 LibraryElement libraryElement = importElement.importedLibrary; 3545 LibraryElement libraryElement = importElement.importedLibrary;
3551 if (libraryElement != null && libraryElement.isDartCore) { 3546 if (libraryElement != null && libraryElement.isDartCore) {
3552 continue; 3547 continue;
3553 } 3548 }
3554 } 3549 }
3555 errorReporter.reportError3(HintCode.UNUSED_IMPORT, unusedImport.uri, []); 3550 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []);
3556 } 3551 }
3557 } 3552 }
3558 3553
3559 Object visitCompilationUnit(CompilationUnit node) { 3554 Object visitCompilationUnit(CompilationUnit node) {
3560 if (_inDefiningCompilationUnit) { 3555 if (_inDefiningCompilationUnit) {
3561 NodeList<Directive> directives = node.directives; 3556 NodeList<Directive> directives = node.directives;
3562 for (Directive directive in directives) { 3557 for (Directive directive in directives) {
3563 if (directive is ImportDirective) { 3558 if (directive is ImportDirective) {
3564 ImportDirective importDirective = directive; 3559 ImportDirective importDirective = directive;
3565 LibraryElement libraryElement = importDirective.uriElement; 3560 LibraryElement libraryElement = importDirective.uriElement;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3801 OverrideVerifier(InheritanceManager manager, ErrorReporter errorReporter) { 3796 OverrideVerifier(InheritanceManager manager, ErrorReporter errorReporter) {
3802 this._manager = manager; 3797 this._manager = manager;
3803 this._errorReporter = errorReporter; 3798 this._errorReporter = errorReporter;
3804 } 3799 }
3805 3800
3806 Object visitMethodDeclaration(MethodDeclaration node) { 3801 Object visitMethodDeclaration(MethodDeclaration node) {
3807 ExecutableElement element = node.element; 3802 ExecutableElement element = node.element;
3808 if (isOverride(element)) { 3803 if (isOverride(element)) {
3809 if (getOverriddenMember(element) == null) { 3804 if (getOverriddenMember(element) == null) {
3810 if (element is MethodElement) { 3805 if (element is MethodElement) {
3811 _errorReporter.reportError3(HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD , node.name, []); 3806 _errorReporter.reportError2(HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD , node.name, []);
3812 } else if (element is PropertyAccessorElement) { 3807 } else if (element is PropertyAccessorElement) {
3813 if (element.isGetter) { 3808 if (element.isGetter) {
3814 _errorReporter.reportError3(HintCode.OVERRIDE_ON_NON_OVERRIDING_GETT ER, node.name, []); 3809 _errorReporter.reportError2(HintCode.OVERRIDE_ON_NON_OVERRIDING_GETT ER, node.name, []);
3815 } else { 3810 } else {
3816 _errorReporter.reportError3(HintCode.OVERRIDE_ON_NON_OVERRIDING_SETT ER, node.name, []); 3811 _errorReporter.reportError2(HintCode.OVERRIDE_ON_NON_OVERRIDING_SETT ER, node.name, []);
3817 } 3812 }
3818 } 3813 }
3819 } 3814 }
3820 } 3815 }
3821 return super.visitMethodDeclaration(node); 3816 return super.visitMethodDeclaration(node);
3822 } 3817 }
3823 3818
3824 /** 3819 /**
3825 * Return the member that overrides the given member. 3820 * Return the member that overrides the given member.
3826 * 3821 *
3827 * @param member the member that overrides the returned member 3822 * @param member the member that overrides the returned member
3828 * @return the member that overrides the given member 3823 * @return the member that overrides the given member
3829 */ 3824 */
3830 ExecutableElement getOverriddenMember(ExecutableElement member) { 3825 ExecutableElement getOverriddenMember(ExecutableElement member) {
3831 LibraryElement library = member.library; 3826 LibraryElement library = member.library;
3832 if (library == null) { 3827 if (library == null) {
3833 return null; 3828 return null;
3834 } 3829 }
3835 ClassElement classElement = member.getAncestor(ClassElement); 3830 ClassElement classElement = member.getAncestor((element) => element is Class Element);
3836 if (classElement == null) { 3831 if (classElement == null) {
3837 return null; 3832 return null;
3838 } 3833 }
3839 return _manager.lookupInheritance(classElement, member.name); 3834 return _manager.lookupInheritance(classElement, member.name);
3840 } 3835 }
3841 3836
3842 /** 3837 /**
3843 * Return `true` if the given element has an override annotation associated wi th it. 3838 * Return `true` if the given element has an override annotation associated wi th it.
3844 * 3839 *
3845 * @param element the element being tested 3840 * @param element the element being tested
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3894 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); 3889 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex);
3895 if (fullNameIndex < 4) { 3890 if (fullNameIndex < 4) {
3896 return false; 3891 return false;
3897 } 3892 }
3898 // Check for "/lib" at a specified place in the fullName 3893 // Check for "/lib" at a specified place in the fullName
3899 if (StringUtilities.startsWith4(fullName, fullNameIndex - 4, 0x2F, 0x6C, 0x69, 0x62)) { 3894 if (StringUtilities.startsWith4(fullName, fullNameIndex - 4, 0x2F, 0x6C, 0x69, 0x62)) {
3900 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP EC_YAML; 3895 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP EC_YAML;
3901 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat ivePubspecPath); 3896 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat ivePubspecPath);
3902 if (_context.exists(pubspecSource)) { 3897 if (_context.exists(pubspecSource)) {
3903 // Files inside the lib directory hierarchy should not reference fil es outside 3898 // Files inside the lib directory hierarchy should not reference fil es outside
3904 _errorReporter.reportError3(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB _REFERENCES_FILE_OUTSIDE, uriLiteral, []); 3899 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB _REFERENCES_FILE_OUTSIDE, uriLiteral, []);
3905 } 3900 }
3906 return true; 3901 return true;
3907 } 3902 }
3908 pathIndex += 3; 3903 pathIndex += 3;
3909 } 3904 }
3910 } 3905 }
3911 return false; 3906 return false;
3912 } 3907 }
3913 3908
3914 /** 3909 /**
3915 * This verifies that the passed file import directive is not contained in a s ource outside a 3910 * This verifies that the passed file import directive is not contained in a s ource outside a
3916 * package "lib" directory hierarchy referencing a source inside that package "lib" directory 3911 * package "lib" directory hierarchy referencing a source inside that package "lib" directory
3917 * hierarchy. 3912 * hierarchy.
3918 * 3913 *
3919 * @param uriLiteral the import URL (not `null`) 3914 * @param uriLiteral the import URL (not `null`)
3920 * @param path the file path being verified (not `null`) 3915 * @param path the file path being verified (not `null`)
3921 * @return `true` if and only if an error code is generated on the passed node 3916 * @return `true` if and only if an error code is generated on the passed node
3922 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE 3917 * @see PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE
3923 */ 3918 */
3924 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral , String path) { 3919 bool checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral , String path) {
3925 if (StringUtilities.startsWith4(path, 0, 0x6C, 0x69, 0x62, 0x2F)) { 3920 if (StringUtilities.startsWith4(path, 0, 0x6C, 0x69, 0x62, 0x2F)) {
3926 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, 0) ) { 3921 if (checkForFileImportOutsideLibReferencesFileInsideAtIndex(uriLiteral, pa th, 0)) {
3927 return true; 3922 return true;
3928 } 3923 }
3929 } 3924 }
3930 int pathIndex = StringUtilities.indexOf5(path, 0, 0x2F, 0x6C, 0x69, 0x62, 0x 2F); 3925 int pathIndex = StringUtilities.indexOf5(path, 0, 0x2F, 0x6C, 0x69, 0x62, 0x 2F);
3931 while (pathIndex != -1) { 3926 while (pathIndex != -1) {
3932 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, pa thIndex + 1)) { 3927 if (checkForFileImportOutsideLibReferencesFileInsideAtIndex(uriLiteral, pa th, pathIndex + 1)) {
3933 return true; 3928 return true;
3934 } 3929 }
3935 pathIndex = StringUtilities.indexOf5(path, pathIndex + 4, 0x2F, 0x6C, 0x69 , 0x62, 0x2F); 3930 pathIndex = StringUtilities.indexOf5(path, pathIndex + 4, 0x2F, 0x6C, 0x69 , 0x62, 0x2F);
3936 } 3931 }
3937 return false; 3932 return false;
3938 } 3933 }
3939 3934
3940 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera l, String path, int pathIndex) { 3935 bool checkForFileImportOutsideLibReferencesFileInsideAtIndex(StringLiteral uri Literal, String path, int pathIndex) {
3941 Source source = getSource(uriLiteral); 3936 Source source = getSource(uriLiteral);
3942 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; 3937 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML;
3943 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub specPath); 3938 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub specPath);
3944 if (!_context.exists(pubspecSource)) { 3939 if (!_context.exists(pubspecSource)) {
3945 return false; 3940 return false;
3946 } 3941 }
3947 String fullName = getSourceFullName(source); 3942 String fullName = getSourceFullName(source);
3948 if (fullName != null) { 3943 if (fullName != null) {
3949 if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) < 0) { 3944 if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) < 0) {
3950 // Files outside the lib directory hierarchy should not reference files inside 3945 // Files outside the lib directory hierarchy should not reference files inside
3951 // ... use package: url instead 3946 // ... use package: url instead
3952 _errorReporter.reportError3(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE FERENCES_FILE_INSIDE, uriLiteral, []); 3947 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE FERENCES_FILE_INSIDE, uriLiteral, []);
3953 return true; 3948 return true;
3954 } 3949 }
3955 } 3950 }
3956 return false; 3951 return false;
3957 } 3952 }
3958 3953
3959 /** 3954 /**
3960 * This verifies that the passed package import directive does not contain ".. " 3955 * This verifies that the passed package import directive does not contain ".. "
3961 * 3956 *
3962 * @param uriLiteral the import URL (not `null`) 3957 * @param uriLiteral the import URL (not `null`)
3963 * @param path the path to be validated (not `null`) 3958 * @param path the path to be validated (not `null`)
3964 * @return `true` if and only if an error code is generated on the passed node 3959 * @return `true` if and only if an error code is generated on the passed node
3965 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT 3960 * @see PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT
3966 */ 3961 */
3967 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path ) { 3962 bool checkForPackageImportContainsDotDot(StringLiteral uriLiteral, String path ) {
3968 if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || StringUtilitie s.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) { 3963 if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || StringUtilitie s.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) {
3969 // Package import should not to contain ".." 3964 // Package import should not to contain ".."
3970 _errorReporter.reportError3(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_ DOT, uriLiteral, []); 3965 _errorReporter.reportError2(PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_ DOT, uriLiteral, []);
3971 return true; 3966 return true;
3972 } 3967 }
3973 return false; 3968 return false;
3974 } 3969 }
3975 3970
3976 /** 3971 /**
3977 * Answer the source associated with the compilation unit containing the given AST node. 3972 * Answer the source associated with the compilation unit containing the given AST node.
3978 * 3973 *
3979 * @param node the node (not `null`) 3974 * @param node the node (not `null`)
3980 * @return the source or `null` if it could not be determined 3975 * @return the source or `null` if it could not be determined
3981 */ 3976 */
3982 Source getSource(AstNode node) { 3977 Source getSource(AstNode node) {
3983 Source source = null; 3978 Source source = null;
3984 CompilationUnit unit = node.getAncestor(CompilationUnit); 3979 CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit);
3985 if (unit != null) { 3980 if (unit != null) {
3986 CompilationUnitElement element = unit.element; 3981 CompilationUnitElement element = unit.element;
3987 if (element != null) { 3982 if (element != null) {
3988 source = element.source; 3983 source = element.source;
3989 } 3984 }
3990 } 3985 }
3991 return source; 3986 return source;
3992 } 3987 }
3993 3988
3994 /** 3989 /**
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4059 /** 4054 /**
4060 * Look for user defined tasks in comments and convert them into info level an alysis issues. 4055 * Look for user defined tasks in comments and convert them into info level an alysis issues.
4061 * 4056 *
4062 * @param commentToken the comment token to analyze 4057 * @param commentToken the comment token to analyze
4063 */ 4058 */
4064 void scrapeTodoComment(sc.Token commentToken) { 4059 void scrapeTodoComment(sc.Token commentToken) {
4065 JavaPatternMatcher matcher = new JavaPatternMatcher(TodoCode.TODO_REGEX, com mentToken.lexeme); 4060 JavaPatternMatcher matcher = new JavaPatternMatcher(TodoCode.TODO_REGEX, com mentToken.lexeme);
4066 if (matcher.find()) { 4061 if (matcher.find()) {
4067 int offset = commentToken.offset + matcher.start() + matcher.group(1).leng th; 4062 int offset = commentToken.offset + matcher.start() + matcher.group(1).leng th;
4068 int length = matcher.group(2).length; 4063 int length = matcher.group(2).length;
4069 _errorReporter.reportError5(TodoCode.TODO, offset, length, [matcher.group( 2)]); 4064 _errorReporter.reportError4(TodoCode.TODO, offset, length, [matcher.group( 2)]);
4070 } 4065 }
4071 } 4066 }
4072 } 4067 }
4073 4068
4074 /** 4069 /**
4075 * Instances of the class `DeclarationMatcher` determine whether the element mod el defined by 4070 * Instances of the class `DeclarationMatcher` determine whether the element mod el defined by
4076 * a given AST structure matches an existing element model. 4071 * a given AST structure matches an existing element model.
4077 */ 4072 */
4078 class DeclarationMatcher extends RecursiveAstVisitor<Object> { 4073 class DeclarationMatcher extends RecursiveAstVisitor<Object> {
4079 /** 4074 /**
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 } on DeclarationMatcher_DeclarationMismatchException catch (exception) { 4130 } on DeclarationMatcher_DeclarationMismatchException catch (exception) {
4136 return false; 4131 return false;
4137 } 4132 }
4138 return _unmatchedElements.isEmpty; 4133 return _unmatchedElements.isEmpty;
4139 } 4134 }
4140 4135
4141 Object visitCatchClause(CatchClause node) { 4136 Object visitCatchClause(CatchClause node) {
4142 SimpleIdentifier exceptionParameter = node.exceptionParameter; 4137 SimpleIdentifier exceptionParameter = node.exceptionParameter;
4143 if (exceptionParameter != null) { 4138 if (exceptionParameter != null) {
4144 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables; 4139 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables;
4145 LocalVariableElement exceptionElement = find3(localVariables, exceptionPar ameter); 4140 LocalVariableElement exceptionElement = findIdentifier(localVariables, exc eptionParameter);
4146 processElement(exceptionElement); 4141 processElement(exceptionElement);
4147 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; 4142 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
4148 if (stackTraceParameter != null) { 4143 if (stackTraceParameter != null) {
4149 LocalVariableElement stackTraceElement = find3(localVariables, stackTrac eParameter); 4144 LocalVariableElement stackTraceElement = findIdentifier(localVariables, stackTraceParameter);
4150 processElement(stackTraceElement); 4145 processElement(stackTraceElement);
4151 } 4146 }
4152 } 4147 }
4153 return super.visitCatchClause(node); 4148 return super.visitCatchClause(node);
4154 } 4149 }
4155 4150
4156 Object visitClassDeclaration(ClassDeclaration node) { 4151 Object visitClassDeclaration(ClassDeclaration node) {
4157 ClassElement outerClass = _enclosingClass; 4152 ClassElement outerClass = _enclosingClass;
4158 try { 4153 try {
4159 SimpleIdentifier className = node.name; 4154 SimpleIdentifier className = node.name;
4160 _enclosingClass = find3(_enclosingUnit.types, className); 4155 _enclosingClass = findIdentifier(_enclosingUnit.types, className);
4161 processElement(_enclosingClass); 4156 processElement(_enclosingClass);
4162 if (!hasConstructor(node)) { 4157 if (!hasConstructor(node)) {
4163 ConstructorElement constructor = _enclosingClass.unnamedConstructor; 4158 ConstructorElement constructor = _enclosingClass.unnamedConstructor;
4164 if (constructor.isSynthetic) { 4159 if (constructor.isSynthetic) {
4165 processElement(constructor); 4160 processElement(constructor);
4166 } 4161 }
4167 } 4162 }
4168 return super.visitClassDeclaration(node); 4163 return super.visitClassDeclaration(node);
4169 } finally { 4164 } finally {
4170 _enclosingClass = outerClass; 4165 _enclosingClass = outerClass;
4171 } 4166 }
4172 } 4167 }
4173 4168
4174 Object visitClassTypeAlias(ClassTypeAlias node) { 4169 Object visitClassTypeAlias(ClassTypeAlias node) {
4175 ClassElement outerClass = _enclosingClass; 4170 ClassElement outerClass = _enclosingClass;
4176 try { 4171 try {
4177 SimpleIdentifier className = node.name; 4172 SimpleIdentifier className = node.name;
4178 _enclosingClass = find3(_enclosingUnit.types, className); 4173 _enclosingClass = findIdentifier(_enclosingUnit.types, className);
4179 processElement(_enclosingClass); 4174 processElement(_enclosingClass);
4180 return super.visitClassTypeAlias(node); 4175 return super.visitClassTypeAlias(node);
4181 } finally { 4176 } finally {
4182 _enclosingClass = outerClass; 4177 _enclosingClass = outerClass;
4183 } 4178 }
4184 } 4179 }
4185 4180
4186 Object visitCompilationUnit(CompilationUnit node) { 4181 Object visitCompilationUnit(CompilationUnit node) {
4187 processElement(_enclosingUnit); 4182 processElement(_enclosingUnit);
4188 return super.visitCompilationUnit(node); 4183 return super.visitCompilationUnit(node);
(...skipping 10 matching lines...) Expand all
4199 } 4194 }
4200 processElement(_enclosingExecutable); 4195 processElement(_enclosingExecutable);
4201 return super.visitConstructorDeclaration(node); 4196 return super.visitConstructorDeclaration(node);
4202 } finally { 4197 } finally {
4203 _enclosingExecutable = outerExecutable; 4198 _enclosingExecutable = outerExecutable;
4204 } 4199 }
4205 } 4200 }
4206 4201
4207 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 4202 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
4208 SimpleIdentifier variableName = node.identifier; 4203 SimpleIdentifier variableName = node.identifier;
4209 LocalVariableElement element = find3(_enclosingExecutable.localVariables, va riableName); 4204 LocalVariableElement element = findIdentifier(_enclosingExecutable.localVari ables, variableName);
4210 processElement(element); 4205 processElement(element);
4211 return super.visitDeclaredIdentifier(node); 4206 return super.visitDeclaredIdentifier(node);
4212 } 4207 }
4213 4208
4214 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 4209 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
4215 SimpleIdentifier parameterName = node.parameter.identifier; 4210 SimpleIdentifier parameterName = node.parameter.identifier;
4216 ParameterElement element = getElementForParameter(node, parameterName); 4211 ParameterElement element = getElementForParameter(node, parameterName);
4217 Expression defaultValue = node.defaultValue; 4212 Expression defaultValue = node.defaultValue;
4218 if (defaultValue != null) { 4213 if (defaultValue != null) {
4219 ExecutableElement outerExecutable = _enclosingExecutable; 4214 ExecutableElement outerExecutable = _enclosingExecutable;
(...skipping 15 matching lines...) Expand all
4235 return super.visitDefaultFormalParameter(node); 4230 return super.visitDefaultFormalParameter(node);
4236 } finally { 4231 } finally {
4237 _enclosingParameter = outerParameter; 4232 _enclosingParameter = outerParameter;
4238 } 4233 }
4239 } 4234 }
4240 4235
4241 Object visitExportDirective(ExportDirective node) { 4236 Object visitExportDirective(ExportDirective node) {
4242 String uri = getStringValue(node.uri); 4237 String uri = getStringValue(node.uri);
4243 if (uri != null) { 4238 if (uri != null) {
4244 LibraryElement library = _enclosingUnit.library; 4239 LibraryElement library = _enclosingUnit.library;
4245 ExportElement exportElement = find5(library.exports, _enclosingUnit.contex t.sourceFactory.resolveUri(_enclosingUnit.source, uri)); 4240 ExportElement exportElement = findExport(library.exports, _enclosingUnit.c ontext.sourceFactory.resolveUri(_enclosingUnit.source, uri));
4246 processElement(exportElement); 4241 processElement(exportElement);
4247 } 4242 }
4248 return super.visitExportDirective(node); 4243 return super.visitExportDirective(node);
4249 } 4244 }
4250 4245
4251 Object visitFieldFormalParameter(FieldFormalParameter node) { 4246 Object visitFieldFormalParameter(FieldFormalParameter node) {
4252 if (node.parent is! DefaultFormalParameter) { 4247 if (node.parent is! DefaultFormalParameter) {
4253 SimpleIdentifier parameterName = node.identifier; 4248 SimpleIdentifier parameterName = node.identifier;
4254 ParameterElement element = getElementForParameter(node, parameterName); 4249 ParameterElement element = getElementForParameter(node, parameterName);
4255 ParameterElement outerParameter = _enclosingParameter; 4250 ParameterElement outerParameter = _enclosingParameter;
4256 try { 4251 try {
4257 _enclosingParameter = element; 4252 _enclosingParameter = element;
4258 processElement(_enclosingParameter); 4253 processElement(_enclosingParameter);
4259 return super.visitFieldFormalParameter(node); 4254 return super.visitFieldFormalParameter(node);
4260 } finally { 4255 } finally {
4261 _enclosingParameter = outerParameter; 4256 _enclosingParameter = outerParameter;
4262 } 4257 }
4263 } else { 4258 } else {
4264 return super.visitFieldFormalParameter(node); 4259 return super.visitFieldFormalParameter(node);
4265 } 4260 }
4266 } 4261 }
4267 4262
4268 Object visitFunctionDeclaration(FunctionDeclaration node) { 4263 Object visitFunctionDeclaration(FunctionDeclaration node) {
4269 ExecutableElement outerExecutable = _enclosingExecutable; 4264 ExecutableElement outerExecutable = _enclosingExecutable;
4270 try { 4265 try {
4271 SimpleIdentifier functionName = node.name; 4266 SimpleIdentifier functionName = node.name;
4272 sc.Token property = node.propertyKeyword; 4267 sc.Token property = node.propertyKeyword;
4273 if (property == null) { 4268 if (property == null) {
4274 if (_enclosingExecutable != null) { 4269 if (_enclosingExecutable != null) {
4275 _enclosingExecutable = find3(_enclosingExecutable.functions, functionN ame); 4270 _enclosingExecutable = findIdentifier(_enclosingExecutable.functions, functionName);
4276 } else { 4271 } else {
4277 _enclosingExecutable = find3(_enclosingUnit.functions, functionName); 4272 _enclosingExecutable = findIdentifier(_enclosingUnit.functions, functi onName);
4278 } 4273 }
4279 } else { 4274 } else {
4280 PropertyAccessorElement accessor = find3(_enclosingUnit.accessors, funct ionName); 4275 PropertyAccessorElement accessor = findIdentifier(_enclosingUnit.accesso rs, functionName);
4281 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 4276 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
4282 accessor = accessor.variable.setter; 4277 accessor = accessor.variable.setter;
4283 } 4278 }
4284 _enclosingExecutable = accessor; 4279 _enclosingExecutable = accessor;
4285 } 4280 }
4286 processElement(_enclosingExecutable); 4281 processElement(_enclosingExecutable);
4287 return super.visitFunctionDeclaration(node); 4282 return super.visitFunctionDeclaration(node);
4288 } finally { 4283 } finally {
4289 _enclosingExecutable = outerExecutable; 4284 _enclosingExecutable = outerExecutable;
4290 } 4285 }
4291 } 4286 }
4292 4287
4293 Object visitFunctionExpression(FunctionExpression node) { 4288 Object visitFunctionExpression(FunctionExpression node) {
4294 if (node.parent is! FunctionDeclaration) { 4289 if (node.parent is! FunctionDeclaration) {
4295 FunctionElement element = find2(_enclosingExecutable.functions, node.begin Token.offset); 4290 FunctionElement element = findAtOffset(_enclosingExecutable.functions, nod e.beginToken.offset);
4296 processElement(element); 4291 processElement(element);
4297 } 4292 }
4298 ExecutableElement outerExecutable = _enclosingExecutable; 4293 ExecutableElement outerExecutable = _enclosingExecutable;
4299 try { 4294 try {
4300 _enclosingExecutable = node.element; 4295 _enclosingExecutable = node.element;
4301 processElement(_enclosingExecutable); 4296 processElement(_enclosingExecutable);
4302 return super.visitFunctionExpression(node); 4297 return super.visitFunctionExpression(node);
4303 } finally { 4298 } finally {
4304 _enclosingExecutable = outerExecutable; 4299 _enclosingExecutable = outerExecutable;
4305 } 4300 }
4306 } 4301 }
4307 4302
4308 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 4303 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
4309 FunctionTypeAliasElement outerAlias = _enclosingAlias; 4304 FunctionTypeAliasElement outerAlias = _enclosingAlias;
4310 try { 4305 try {
4311 SimpleIdentifier aliasName = node.name; 4306 SimpleIdentifier aliasName = node.name;
4312 _enclosingAlias = find3(_enclosingUnit.functionTypeAliases, aliasName); 4307 _enclosingAlias = findIdentifier(_enclosingUnit.functionTypeAliases, alias Name);
4313 processElement(_enclosingAlias); 4308 processElement(_enclosingAlias);
4314 return super.visitFunctionTypeAlias(node); 4309 return super.visitFunctionTypeAlias(node);
4315 } finally { 4310 } finally {
4316 _enclosingAlias = outerAlias; 4311 _enclosingAlias = outerAlias;
4317 } 4312 }
4318 } 4313 }
4319 4314
4320 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 4315 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
4321 if (node.parent is! DefaultFormalParameter) { 4316 if (node.parent is! DefaultFormalParameter) {
4322 SimpleIdentifier parameterName = node.identifier; 4317 SimpleIdentifier parameterName = node.identifier;
4323 ParameterElement element = getElementForParameter(node, parameterName); 4318 ParameterElement element = getElementForParameter(node, parameterName);
4324 ParameterElement outerParameter = _enclosingParameter; 4319 ParameterElement outerParameter = _enclosingParameter;
4325 try { 4320 try {
4326 _enclosingParameter = element; 4321 _enclosingParameter = element;
4327 processElement(_enclosingParameter); 4322 processElement(_enclosingParameter);
4328 return super.visitFunctionTypedFormalParameter(node); 4323 return super.visitFunctionTypedFormalParameter(node);
4329 } finally { 4324 } finally {
4330 _enclosingParameter = outerParameter; 4325 _enclosingParameter = outerParameter;
4331 } 4326 }
4332 } else { 4327 } else {
4333 return super.visitFunctionTypedFormalParameter(node); 4328 return super.visitFunctionTypedFormalParameter(node);
4334 } 4329 }
4335 } 4330 }
4336 4331
4337 Object visitImportDirective(ImportDirective node) { 4332 Object visitImportDirective(ImportDirective node) {
4338 String uri = getStringValue(node.uri); 4333 String uri = getStringValue(node.uri);
4339 if (uri != null) { 4334 if (uri != null) {
4340 LibraryElement library = _enclosingUnit.library; 4335 LibraryElement library = _enclosingUnit.library;
4341 ImportElement importElement = find6(library.imports, _enclosingUnit.contex t.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix); 4336 ImportElement importElement = findImport(library.imports, _enclosingUnit.c ontext.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix);
4342 processElement(importElement); 4337 processElement(importElement);
4343 } 4338 }
4344 return super.visitImportDirective(node); 4339 return super.visitImportDirective(node);
4345 } 4340 }
4346 4341
4347 Object visitLabeledStatement(LabeledStatement node) { 4342 Object visitLabeledStatement(LabeledStatement node) {
4348 for (Label label in node.labels) { 4343 for (Label label in node.labels) {
4349 SimpleIdentifier labelName = label.label; 4344 SimpleIdentifier labelName = label.label;
4350 LabelElement element = find3(_enclosingExecutable.labels, labelName); 4345 LabelElement element = findIdentifier(_enclosingExecutable.labels, labelNa me);
4351 processElement(element); 4346 processElement(element);
4352 } 4347 }
4353 return super.visitLabeledStatement(node); 4348 return super.visitLabeledStatement(node);
4354 } 4349 }
4355 4350
4356 Object visitMethodDeclaration(MethodDeclaration node) { 4351 Object visitMethodDeclaration(MethodDeclaration node) {
4357 ExecutableElement outerExecutable = _enclosingExecutable; 4352 ExecutableElement outerExecutable = _enclosingExecutable;
4358 try { 4353 try {
4359 sc.Token property = node.propertyKeyword; 4354 sc.Token property = node.propertyKeyword;
4360 SimpleIdentifier methodName = node.name; 4355 SimpleIdentifier methodName = node.name;
4361 String nameOfMethod = methodName.name; 4356 String nameOfMethod = methodName.name;
4362 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) { 4357 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
4363 nameOfMethod = "unary-"; 4358 nameOfMethod = "unary-";
4364 } 4359 }
4365 if (property == null) { 4360 if (property == null) {
4366 _enclosingExecutable = find4(_enclosingClass.methods, nameOfMethod, meth odName.offset); 4361 _enclosingExecutable = findWithNameAndOffset(_enclosingClass.methods, na meOfMethod, methodName.offset);
4367 methodName.staticElement = _enclosingExecutable; 4362 methodName.staticElement = _enclosingExecutable;
4368 } else { 4363 } else {
4369 PropertyAccessorElement accessor = find3(_enclosingClass.accessors, meth odName); 4364 PropertyAccessorElement accessor = findIdentifier(_enclosingClass.access ors, methodName);
4370 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 4365 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
4371 accessor = accessor.variable.setter; 4366 accessor = accessor.variable.setter;
4372 methodName.staticElement = accessor; 4367 methodName.staticElement = accessor;
4373 } 4368 }
4374 _enclosingExecutable = accessor; 4369 _enclosingExecutable = accessor;
4375 } 4370 }
4376 processElement(_enclosingExecutable); 4371 processElement(_enclosingExecutable);
4377 return super.visitMethodDeclaration(node); 4372 return super.visitMethodDeclaration(node);
4378 } finally { 4373 } finally {
4379 _enclosingExecutable = outerExecutable; 4374 _enclosingExecutable = outerExecutable;
4380 } 4375 }
4381 } 4376 }
4382 4377
4383 Object visitPartDirective(PartDirective node) { 4378 Object visitPartDirective(PartDirective node) {
4384 String uri = getStringValue(node.uri); 4379 String uri = getStringValue(node.uri);
4385 if (uri != null) { 4380 if (uri != null) {
4386 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri); 4381 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri);
4387 CompilationUnitElement element = find(_enclosingUnit.library.parts, partSo urce); 4382 CompilationUnitElement element = findPart(_enclosingUnit.library.parts, pa rtSource);
4388 processElement(element); 4383 processElement(element);
4389 } 4384 }
4390 return super.visitPartDirective(node); 4385 return super.visitPartDirective(node);
4391 } 4386 }
4392 4387
4393 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 4388 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
4394 if (node.parent is! DefaultFormalParameter) { 4389 if (node.parent is! DefaultFormalParameter) {
4395 SimpleIdentifier parameterName = node.identifier; 4390 SimpleIdentifier parameterName = node.identifier;
4396 ParameterElement element = getElementForParameter(node, parameterName); 4391 ParameterElement element = getElementForParameter(node, parameterName);
4397 ParameterElement outerParameter = _enclosingParameter; 4392 ParameterElement outerParameter = _enclosingParameter;
4398 try { 4393 try {
4399 _enclosingParameter = element; 4394 _enclosingParameter = element;
4400 processElement(_enclosingParameter); 4395 processElement(_enclosingParameter);
4401 return super.visitSimpleFormalParameter(node); 4396 return super.visitSimpleFormalParameter(node);
4402 } finally { 4397 } finally {
4403 _enclosingParameter = outerParameter; 4398 _enclosingParameter = outerParameter;
4404 } 4399 }
4405 } else { 4400 } else {
4406 } 4401 }
4407 return super.visitSimpleFormalParameter(node); 4402 return super.visitSimpleFormalParameter(node);
4408 } 4403 }
4409 4404
4410 Object visitSwitchCase(SwitchCase node) { 4405 Object visitSwitchCase(SwitchCase node) {
4411 for (Label label in node.labels) { 4406 for (Label label in node.labels) {
4412 SimpleIdentifier labelName = label.label; 4407 SimpleIdentifier labelName = label.label;
4413 LabelElement element = find3(_enclosingExecutable.labels, labelName); 4408 LabelElement element = findIdentifier(_enclosingExecutable.labels, labelNa me);
4414 processElement(element); 4409 processElement(element);
4415 } 4410 }
4416 return super.visitSwitchCase(node); 4411 return super.visitSwitchCase(node);
4417 } 4412 }
4418 4413
4419 Object visitSwitchDefault(SwitchDefault node) { 4414 Object visitSwitchDefault(SwitchDefault node) {
4420 for (Label label in node.labels) { 4415 for (Label label in node.labels) {
4421 SimpleIdentifier labelName = label.label; 4416 SimpleIdentifier labelName = label.label;
4422 LabelElement element = find3(_enclosingExecutable.labels, labelName); 4417 LabelElement element = findIdentifier(_enclosingExecutable.labels, labelNa me);
4423 processElement(element); 4418 processElement(element);
4424 } 4419 }
4425 return super.visitSwitchDefault(node); 4420 return super.visitSwitchDefault(node);
4426 } 4421 }
4427 4422
4428 Object visitTypeParameter(TypeParameter node) { 4423 Object visitTypeParameter(TypeParameter node) {
4429 SimpleIdentifier parameterName = node.name; 4424 SimpleIdentifier parameterName = node.name;
4430 TypeParameterElement element = null; 4425 TypeParameterElement element = null;
4431 if (_enclosingClass != null) { 4426 if (_enclosingClass != null) {
4432 element = find3(_enclosingClass.typeParameters, parameterName); 4427 element = findIdentifier(_enclosingClass.typeParameters, parameterName);
4433 } else if (_enclosingAlias != null) { 4428 } else if (_enclosingAlias != null) {
4434 element = find3(_enclosingAlias.typeParameters, parameterName); 4429 element = findIdentifier(_enclosingAlias.typeParameters, parameterName);
4435 } 4430 }
4436 processElement(element); 4431 processElement(element);
4437 return super.visitTypeParameter(node); 4432 return super.visitTypeParameter(node);
4438 } 4433 }
4439 4434
4440 Object visitVariableDeclaration(VariableDeclaration node) { 4435 Object visitVariableDeclaration(VariableDeclaration node) {
4441 VariableElement element = null; 4436 VariableElement element = null;
4442 SimpleIdentifier variableName = node.name; 4437 SimpleIdentifier variableName = node.name;
4443 if (_enclosingExecutable != null) { 4438 if (_enclosingExecutable != null) {
4444 element = find3(_enclosingExecutable.localVariables, variableName); 4439 element = findIdentifier(_enclosingExecutable.localVariables, variableName );
4445 } 4440 }
4446 if (element == null && _enclosingClass != null) { 4441 if (element == null && _enclosingClass != null) {
4447 element = find3(_enclosingClass.fields, variableName); 4442 element = findIdentifier(_enclosingClass.fields, variableName);
4448 } 4443 }
4449 if (element == null && _enclosingUnit != null) { 4444 if (element == null && _enclosingUnit != null) {
4450 element = find3(_enclosingUnit.topLevelVariables, variableName); 4445 element = findIdentifier(_enclosingUnit.topLevelVariables, variableName);
4451 } 4446 }
4452 Expression initializer = node.initializer; 4447 Expression initializer = node.initializer;
4453 if (initializer != null) { 4448 if (initializer != null) {
4454 ExecutableElement outerExecutable = _enclosingExecutable; 4449 ExecutableElement outerExecutable = _enclosingExecutable;
4455 try { 4450 try {
4456 if (element == null) { 4451 if (element == null) {
4457 } else { 4452 } else {
4458 _enclosingExecutable = element.initializer; 4453 _enclosingExecutable = element.initializer;
4459 } 4454 }
4460 processElement(element); 4455 processElement(element);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4503 } else if (parent is ParameterElement) { 4498 } else if (parent is ParameterElement) {
4504 if (_enclosingParameter == null) { 4499 if (_enclosingParameter == null) {
4505 _enclosingParameter = parent as ParameterElement; 4500 _enclosingParameter = parent as ParameterElement;
4506 } 4501 }
4507 } 4502 }
4508 parent = parent.enclosingElement; 4503 parent = parent.enclosingElement;
4509 } 4504 }
4510 } 4505 }
4511 4506
4512 /** 4507 /**
4513 * Return the element for the part with the given source, or `null` if there i s no element
4514 * for the given source.
4515 *
4516 * @param parts the elements for the parts
4517 * @param partSource the source for the part whose element is to be returned
4518 * @return the element for the part with the given source
4519 */
4520 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou rce) {
4521 for (CompilationUnitElement part in parts) {
4522 if (part.source == partSource) {
4523 return part;
4524 }
4525 }
4526 return null;
4527 }
4528
4529 /**
4530 * Return the element in the given array of elements that was created for the declaration at the 4508 * Return the element in the given array of elements that was created for the declaration at the
4531 * given offset. This method should only be used when there is no name 4509 * given offset. This method should only be used when there is no name
4532 * 4510 *
4533 * @param elements the elements of the appropriate kind that exist in the curr ent context 4511 * @param elements the elements of the appropriate kind that exist in the curr ent context
4534 * @param offset the offset of the name of the element to be returned 4512 * @param offset the offset of the name of the element to be returned
4535 * @return the element at the given offset 4513 * @return the element at the given offset
4536 */ 4514 */
4537 Element find2(List<Element> elements, int offset) => find4(elements, "", offse t); 4515 Element findAtOffset(List<Element> elements, int offset) => findWithNameAndOff set(elements, "", offset);
4538
4539 /**
4540 * Return the element in the given array of elements that was created for the declaration with the
4541 * given name.
4542 *
4543 * @param elements the elements of the appropriate kind that exist in the curr ent context
4544 * @param identifier the name node in the declaration of the element to be ret urned
4545 * @return the element created for the declaration with the given name
4546 */
4547 Element find3(List<Element> elements, SimpleIdentifier identifier) => find4(el ements, identifier.name, identifier.offset);
4548
4549 /**
4550 * Return the element in the given array of elements that was created for the declaration with the
4551 * given name at the given offset.
4552 *
4553 * @param elements the elements of the appropriate kind that exist in the curr ent context
4554 * @param name the name of the element to be returned
4555 * @param offset the offset of the name of the element to be returned
4556 * @return the element with the given name and offset
4557 */
4558 Element find4(List<Element> elements, String name, int offset) {
4559 for (Element element in elements) {
4560 if (element.displayName == name && element.nameOffset == offset) {
4561 return element;
4562 }
4563 }
4564 return null;
4565 }
4566 4516
4567 /** 4517 /**
4568 * Return the export element from the given array whose library has the given source, or 4518 * Return the export element from the given array whose library has the given source, or
4569 * `null` if there is no such export. 4519 * `null` if there is no such export.
4570 * 4520 *
4571 * @param exports the export elements being searched 4521 * @param exports the export elements being searched
4572 * @param source the source of the library associated with the export element to being searched 4522 * @param source the source of the library associated with the export element to being searched
4573 * for 4523 * for
4574 * @return the export element whose library has the given source 4524 * @return the export element whose library has the given source
4575 */ 4525 */
4576 ExportElement find5(List<ExportElement> exports, Source source) { 4526 ExportElement findExport(List<ExportElement> exports, Source source) {
4577 for (ExportElement export in exports) { 4527 for (ExportElement export in exports) {
4578 if (export.exportedLibrary.source == source) { 4528 if (export.exportedLibrary.source == source) {
4579 return export; 4529 return export;
4580 } 4530 }
4581 } 4531 }
4582 return null; 4532 return null;
4583 } 4533 }
4584 4534
4585 /** 4535 /**
4536 * Return the element in the given array of elements that was created for the declaration with the
4537 * given name.
4538 *
4539 * @param elements the elements of the appropriate kind that exist in the curr ent context
4540 * @param identifier the name node in the declaration of the element to be ret urned
4541 * @return the element created for the declaration with the given name
4542 */
4543 Element findIdentifier(List<Element> elements, SimpleIdentifier identifier) => findWithNameAndOffset(elements, identifier.name, identifier.offset);
4544
4545 /**
4586 * Return the import element from the given array whose library has the given source and that has 4546 * Return the import element from the given array whose library has the given source and that has
4587 * the given prefix, or `null` if there is no such import. 4547 * the given prefix, or `null` if there is no such import.
4588 * 4548 *
4589 * @param imports the import elements being searched 4549 * @param imports the import elements being searched
4590 * @param source the source of the library associated with the import element to being searched 4550 * @param source the source of the library associated with the import element to being searched
4591 * for 4551 * for
4592 * @param prefix the prefix with which the library was imported 4552 * @param prefix the prefix with which the library was imported
4593 * @return the import element whose library has the given source and prefix 4553 * @return the import element whose library has the given source and prefix
4594 */ 4554 */
4595 ImportElement find6(List<ImportElement> imports, Source source, SimpleIdentifi er prefix) { 4555 ImportElement findImport(List<ImportElement> imports, Source source, SimpleIde ntifier prefix) {
4596 for (ImportElement element in imports) { 4556 for (ImportElement element in imports) {
4597 if (element.importedLibrary.source == source) { 4557 if (element.importedLibrary.source == source) {
4598 PrefixElement prefixElement = element.prefix; 4558 PrefixElement prefixElement = element.prefix;
4599 if (prefix == null) { 4559 if (prefix == null) {
4600 if (prefixElement == null) { 4560 if (prefixElement == null) {
4601 return element; 4561 return element;
4602 } 4562 }
4603 } else { 4563 } else {
4604 if (prefixElement != null && prefix.name == prefixElement.displayName) { 4564 if (prefixElement != null && prefix.name == prefixElement.displayName) {
4605 return element; 4565 return element;
4606 } 4566 }
4607 } 4567 }
4608 } 4568 }
4609 } 4569 }
4610 return null; 4570 return null;
4611 } 4571 }
4612 4572
4573 /**
4574 * Return the element for the part with the given source, or `null` if there i s no element
4575 * for the given source.
4576 *
4577 * @param parts the elements for the parts
4578 * @param partSource the source for the part whose element is to be returned
4579 * @return the element for the part with the given source
4580 */
4581 CompilationUnitElement findPart(List<CompilationUnitElement> parts, Source par tSource) {
4582 for (CompilationUnitElement part in parts) {
4583 if (part.source == partSource) {
4584 return part;
4585 }
4586 }
4587 return null;
4588 }
4589
4590 /**
4591 * Return the element in the given array of elements that was created for the declaration with the
4592 * given name at the given offset.
4593 *
4594 * @param elements the elements of the appropriate kind that exist in the curr ent context
4595 * @param name the name of the element to be returned
4596 * @param offset the offset of the name of the element to be returned
4597 * @return the element with the given name and offset
4598 */
4599 Element findWithNameAndOffset(List<Element> elements, String name, int offset) {
4600 for (Element element in elements) {
4601 if (element.displayName == name && element.nameOffset == offset) {
4602 return element;
4603 }
4604 }
4605 return null;
4606 }
4607
4613 void gatherElements(Element element) { 4608 void gatherElements(Element element) {
4614 element.accept(new GeneralizingElementVisitor_DeclarationMatcher_gatherEleme nts(this)); 4609 element.accept(new GeneralizingElementVisitor_DeclarationMatcher_gatherEleme nts(this));
4615 } 4610 }
4616 4611
4617 /** 4612 /**
4618 * Search the most closely enclosing list of parameters for a parameter with t he given name. 4613 * Search the most closely enclosing list of parameters for a parameter with t he given name.
4619 * 4614 *
4620 * @param node the node defining the parameter with the given name 4615 * @param node the node defining the parameter with the given name
4621 * @param parameterName the name of the parameter being searched for 4616 * @param parameterName the name of the parameter being searched for
4622 * @return the element representing the parameter with that name 4617 * @return the element representing the parameter with that name
4623 */ 4618 */
4624 ParameterElement getElementForParameter(FormalParameter node, SimpleIdentifier parameterName) { 4619 ParameterElement getElementForParameter(FormalParameter node, SimpleIdentifier parameterName) {
4625 List<ParameterElement> parameters = null; 4620 List<ParameterElement> parameters = null;
4626 if (_enclosingParameter != null) { 4621 if (_enclosingParameter != null) {
4627 parameters = _enclosingParameter.parameters; 4622 parameters = _enclosingParameter.parameters;
4628 } 4623 }
4629 if (parameters == null && _enclosingExecutable != null) { 4624 if (parameters == null && _enclosingExecutable != null) {
4630 parameters = _enclosingExecutable.parameters; 4625 parameters = _enclosingExecutable.parameters;
4631 } 4626 }
4632 if (parameters == null && _enclosingAlias != null) { 4627 if (parameters == null && _enclosingAlias != null) {
4633 parameters = _enclosingAlias.parameters; 4628 parameters = _enclosingAlias.parameters;
4634 } 4629 }
4635 return parameters == null ? null : find3(parameters, parameterName); 4630 return parameters == null ? null : findIdentifier(parameters, parameterName) ;
4636 } 4631 }
4637 4632
4638 /** 4633 /**
4639 * Return the value of the given string literal, or `null` if the string is no t a constant 4634 * Return the value of the given string literal, or `null` if the string is no t a constant
4640 * string without any string interpolation. 4635 * string without any string interpolation.
4641 * 4636 *
4642 * @param literal the string literal whose value is to be returned 4637 * @param literal the string literal whose value is to be returned
4643 * @return the value of the given string literal 4638 * @return the value of the given string literal
4644 */ 4639 */
4645 String getStringValue(StringLiteral literal) { 4640 String getStringValue(StringLiteral literal) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4729 void resolve(CompilationUnit unit, CompilationUnitElement element) { 4724 void resolve(CompilationUnit unit, CompilationUnitElement element) {
4730 _enclosingUnit = element; 4725 _enclosingUnit = element;
4731 unit.element = element; 4726 unit.element = element;
4732 unit.accept(this); 4727 unit.accept(this);
4733 } 4728 }
4734 4729
4735 Object visitCatchClause(CatchClause node) { 4730 Object visitCatchClause(CatchClause node) {
4736 SimpleIdentifier exceptionParameter = node.exceptionParameter; 4731 SimpleIdentifier exceptionParameter = node.exceptionParameter;
4737 if (exceptionParameter != null) { 4732 if (exceptionParameter != null) {
4738 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables; 4733 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables;
4739 find8(localVariables, exceptionParameter); 4734 findIdentifier(localVariables, exceptionParameter);
4740 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; 4735 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
4741 if (stackTraceParameter != null) { 4736 if (stackTraceParameter != null) {
4742 find8(localVariables, stackTraceParameter); 4737 findIdentifier(localVariables, stackTraceParameter);
4743 } 4738 }
4744 } 4739 }
4745 return super.visitCatchClause(node); 4740 return super.visitCatchClause(node);
4746 } 4741 }
4747 4742
4748 Object visitClassDeclaration(ClassDeclaration node) { 4743 Object visitClassDeclaration(ClassDeclaration node) {
4749 ClassElement outerClass = _enclosingClass; 4744 ClassElement outerClass = _enclosingClass;
4750 try { 4745 try {
4751 SimpleIdentifier className = node.name; 4746 SimpleIdentifier className = node.name;
4752 _enclosingClass = find8(_enclosingUnit.types, className); 4747 _enclosingClass = findIdentifier(_enclosingUnit.types, className);
4753 return super.visitClassDeclaration(node); 4748 return super.visitClassDeclaration(node);
4754 } finally { 4749 } finally {
4755 _enclosingClass = outerClass; 4750 _enclosingClass = outerClass;
4756 } 4751 }
4757 } 4752 }
4758 4753
4759 Object visitClassTypeAlias(ClassTypeAlias node) { 4754 Object visitClassTypeAlias(ClassTypeAlias node) {
4760 ClassElement outerClass = _enclosingClass; 4755 ClassElement outerClass = _enclosingClass;
4761 try { 4756 try {
4762 SimpleIdentifier className = node.name; 4757 SimpleIdentifier className = node.name;
4763 _enclosingClass = find8(_enclosingUnit.types, className); 4758 _enclosingClass = findIdentifier(_enclosingUnit.types, className);
4764 return super.visitClassTypeAlias(node); 4759 return super.visitClassTypeAlias(node);
4765 } finally { 4760 } finally {
4766 _enclosingClass = outerClass; 4761 _enclosingClass = outerClass;
4767 } 4762 }
4768 } 4763 }
4769 4764
4770 Object visitConstructorDeclaration(ConstructorDeclaration node) { 4765 Object visitConstructorDeclaration(ConstructorDeclaration node) {
4771 ExecutableElement outerExecutable = _enclosingExecutable; 4766 ExecutableElement outerExecutable = _enclosingExecutable;
4772 try { 4767 try {
4773 SimpleIdentifier constructorName = node.name; 4768 SimpleIdentifier constructorName = node.name;
4774 if (constructorName == null) { 4769 if (constructorName == null) {
4775 _enclosingExecutable = _enclosingClass.unnamedConstructor; 4770 _enclosingExecutable = _enclosingClass.unnamedConstructor;
4776 } else { 4771 } else {
4777 _enclosingExecutable = _enclosingClass.getNamedConstructor(constructorNa me.name); 4772 _enclosingExecutable = _enclosingClass.getNamedConstructor(constructorNa me.name);
4778 constructorName.staticElement = _enclosingExecutable; 4773 constructorName.staticElement = _enclosingExecutable;
4779 } 4774 }
4780 node.element = _enclosingExecutable as ConstructorElement; 4775 node.element = _enclosingExecutable as ConstructorElement;
4781 return super.visitConstructorDeclaration(node); 4776 return super.visitConstructorDeclaration(node);
4782 } finally { 4777 } finally {
4783 _enclosingExecutable = outerExecutable; 4778 _enclosingExecutable = outerExecutable;
4784 } 4779 }
4785 } 4780 }
4786 4781
4787 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 4782 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
4788 SimpleIdentifier variableName = node.identifier; 4783 SimpleIdentifier variableName = node.identifier;
4789 find8(_enclosingExecutable.localVariables, variableName); 4784 findIdentifier(_enclosingExecutable.localVariables, variableName);
4790 return super.visitDeclaredIdentifier(node); 4785 return super.visitDeclaredIdentifier(node);
4791 } 4786 }
4792 4787
4793 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 4788 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
4794 SimpleIdentifier parameterName = node.parameter.identifier; 4789 SimpleIdentifier parameterName = node.parameter.identifier;
4795 ParameterElement element = getElementForParameter(node, parameterName); 4790 ParameterElement element = getElementForParameter(node, parameterName);
4796 Expression defaultValue = node.defaultValue; 4791 Expression defaultValue = node.defaultValue;
4797 if (defaultValue != null) { 4792 if (defaultValue != null) {
4798 ExecutableElement outerExecutable = _enclosingExecutable; 4793 ExecutableElement outerExecutable = _enclosingExecutable;
4799 try { 4794 try {
(...skipping 12 matching lines...) Expand all
4812 return super.visitDefaultFormalParameter(node); 4807 return super.visitDefaultFormalParameter(node);
4813 } finally { 4808 } finally {
4814 _enclosingParameter = outerParameter; 4809 _enclosingParameter = outerParameter;
4815 } 4810 }
4816 } 4811 }
4817 4812
4818 Object visitExportDirective(ExportDirective node) { 4813 Object visitExportDirective(ExportDirective node) {
4819 String uri = getStringValue(node.uri); 4814 String uri = getStringValue(node.uri);
4820 if (uri != null) { 4815 if (uri != null) {
4821 LibraryElement library = _enclosingUnit.library; 4816 LibraryElement library = _enclosingUnit.library;
4822 ExportElement exportElement = find10(library.exports, _enclosingUnit.conte xt.sourceFactory.resolveUri(_enclosingUnit.source, uri)); 4817 ExportElement exportElement = findExport(library.exports, _enclosingUnit.c ontext.sourceFactory.resolveUri(_enclosingUnit.source, uri));
4823 node.element = exportElement; 4818 node.element = exportElement;
4824 } 4819 }
4825 return super.visitExportDirective(node); 4820 return super.visitExportDirective(node);
4826 } 4821 }
4827 4822
4828 Object visitFieldFormalParameter(FieldFormalParameter node) { 4823 Object visitFieldFormalParameter(FieldFormalParameter node) {
4829 if (node.parent is! DefaultFormalParameter) { 4824 if (node.parent is! DefaultFormalParameter) {
4830 SimpleIdentifier parameterName = node.identifier; 4825 SimpleIdentifier parameterName = node.identifier;
4831 ParameterElement element = getElementForParameter(node, parameterName); 4826 ParameterElement element = getElementForParameter(node, parameterName);
4832 ParameterElement outerParameter = _enclosingParameter; 4827 ParameterElement outerParameter = _enclosingParameter;
4833 try { 4828 try {
4834 _enclosingParameter = element; 4829 _enclosingParameter = element;
4835 return super.visitFieldFormalParameter(node); 4830 return super.visitFieldFormalParameter(node);
4836 } finally { 4831 } finally {
4837 _enclosingParameter = outerParameter; 4832 _enclosingParameter = outerParameter;
4838 } 4833 }
4839 } else { 4834 } else {
4840 return super.visitFieldFormalParameter(node); 4835 return super.visitFieldFormalParameter(node);
4841 } 4836 }
4842 } 4837 }
4843 4838
4844 Object visitFunctionDeclaration(FunctionDeclaration node) { 4839 Object visitFunctionDeclaration(FunctionDeclaration node) {
4845 ExecutableElement outerExecutable = _enclosingExecutable; 4840 ExecutableElement outerExecutable = _enclosingExecutable;
4846 try { 4841 try {
4847 SimpleIdentifier functionName = node.name; 4842 SimpleIdentifier functionName = node.name;
4848 sc.Token property = node.propertyKeyword; 4843 sc.Token property = node.propertyKeyword;
4849 if (property == null) { 4844 if (property == null) {
4850 if (_enclosingExecutable != null) { 4845 if (_enclosingExecutable != null) {
4851 _enclosingExecutable = find8(_enclosingExecutable.functions, functionN ame); 4846 _enclosingExecutable = findIdentifier(_enclosingExecutable.functions, functionName);
4852 } else { 4847 } else {
4853 _enclosingExecutable = find8(_enclosingUnit.functions, functionName); 4848 _enclosingExecutable = findIdentifier(_enclosingUnit.functions, functi onName);
4854 } 4849 }
4855 } else { 4850 } else {
4856 PropertyAccessorElement accessor = find8(_enclosingUnit.accessors, funct ionName); 4851 PropertyAccessorElement accessor = findIdentifier(_enclosingUnit.accesso rs, functionName);
4857 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 4852 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
4858 accessor = accessor.variable.setter; 4853 accessor = accessor.variable.setter;
4859 functionName.staticElement = accessor; 4854 functionName.staticElement = accessor;
4860 } 4855 }
4861 _enclosingExecutable = accessor; 4856 _enclosingExecutable = accessor;
4862 } 4857 }
4863 node.functionExpression.element = _enclosingExecutable; 4858 node.functionExpression.element = _enclosingExecutable;
4864 return super.visitFunctionDeclaration(node); 4859 return super.visitFunctionDeclaration(node);
4865 } finally { 4860 } finally {
4866 _enclosingExecutable = outerExecutable; 4861 _enclosingExecutable = outerExecutable;
4867 } 4862 }
4868 } 4863 }
4869 4864
4870 Object visitFunctionExpression(FunctionExpression node) { 4865 Object visitFunctionExpression(FunctionExpression node) {
4871 if (node.parent is! FunctionDeclaration) { 4866 if (node.parent is! FunctionDeclaration) {
4872 FunctionElement element = find7(_enclosingExecutable.functions, node.begin Token.offset); 4867 FunctionElement element = findAtOffset(_enclosingExecutable.functions, nod e.beginToken.offset);
4873 node.element = element; 4868 node.element = element;
4874 } 4869 }
4875 ExecutableElement outerExecutable = _enclosingExecutable; 4870 ExecutableElement outerExecutable = _enclosingExecutable;
4876 try { 4871 try {
4877 _enclosingExecutable = node.element; 4872 _enclosingExecutable = node.element;
4878 return super.visitFunctionExpression(node); 4873 return super.visitFunctionExpression(node);
4879 } finally { 4874 } finally {
4880 _enclosingExecutable = outerExecutable; 4875 _enclosingExecutable = outerExecutable;
4881 } 4876 }
4882 } 4877 }
4883 4878
4884 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 4879 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
4885 FunctionTypeAliasElement outerAlias = _enclosingAlias; 4880 FunctionTypeAliasElement outerAlias = _enclosingAlias;
4886 try { 4881 try {
4887 SimpleIdentifier aliasName = node.name; 4882 SimpleIdentifier aliasName = node.name;
4888 _enclosingAlias = find8(_enclosingUnit.functionTypeAliases, aliasName); 4883 _enclosingAlias = findIdentifier(_enclosingUnit.functionTypeAliases, alias Name);
4889 return super.visitFunctionTypeAlias(node); 4884 return super.visitFunctionTypeAlias(node);
4890 } finally { 4885 } finally {
4891 _enclosingAlias = outerAlias; 4886 _enclosingAlias = outerAlias;
4892 } 4887 }
4893 } 4888 }
4894 4889
4895 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 4890 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
4896 if (node.parent is! DefaultFormalParameter) { 4891 if (node.parent is! DefaultFormalParameter) {
4897 SimpleIdentifier parameterName = node.identifier; 4892 SimpleIdentifier parameterName = node.identifier;
4898 ParameterElement element = getElementForParameter(node, parameterName); 4893 ParameterElement element = getElementForParameter(node, parameterName);
4899 ParameterElement outerParameter = _enclosingParameter; 4894 ParameterElement outerParameter = _enclosingParameter;
4900 try { 4895 try {
4901 _enclosingParameter = element; 4896 _enclosingParameter = element;
4902 return super.visitFunctionTypedFormalParameter(node); 4897 return super.visitFunctionTypedFormalParameter(node);
4903 } finally { 4898 } finally {
4904 _enclosingParameter = outerParameter; 4899 _enclosingParameter = outerParameter;
4905 } 4900 }
4906 } else { 4901 } else {
4907 return super.visitFunctionTypedFormalParameter(node); 4902 return super.visitFunctionTypedFormalParameter(node);
4908 } 4903 }
4909 } 4904 }
4910 4905
4911 Object visitImportDirective(ImportDirective node) { 4906 Object visitImportDirective(ImportDirective node) {
4912 String uri = getStringValue(node.uri); 4907 String uri = getStringValue(node.uri);
4913 if (uri != null) { 4908 if (uri != null) {
4914 LibraryElement library = _enclosingUnit.library; 4909 LibraryElement library = _enclosingUnit.library;
4915 ImportElement importElement = find11(library.imports, _enclosingUnit.conte xt.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix); 4910 ImportElement importElement = findImport(library.imports, _enclosingUnit.c ontext.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix);
4916 node.element = importElement; 4911 node.element = importElement;
4917 } 4912 }
4918 return super.visitImportDirective(node); 4913 return super.visitImportDirective(node);
4919 } 4914 }
4920 4915
4921 Object visitLabeledStatement(LabeledStatement node) { 4916 Object visitLabeledStatement(LabeledStatement node) {
4922 for (Label label in node.labels) { 4917 for (Label label in node.labels) {
4923 SimpleIdentifier labelName = label.label; 4918 SimpleIdentifier labelName = label.label;
4924 find8(_enclosingExecutable.labels, labelName); 4919 findIdentifier(_enclosingExecutable.labels, labelName);
4925 } 4920 }
4926 return super.visitLabeledStatement(node); 4921 return super.visitLabeledStatement(node);
4927 } 4922 }
4928 4923
4929 Object visitLibraryDirective(LibraryDirective node) { 4924 Object visitLibraryDirective(LibraryDirective node) {
4930 node.element = _enclosingUnit.library; 4925 node.element = _enclosingUnit.library;
4931 return super.visitLibraryDirective(node); 4926 return super.visitLibraryDirective(node);
4932 } 4927 }
4933 4928
4934 Object visitMethodDeclaration(MethodDeclaration node) { 4929 Object visitMethodDeclaration(MethodDeclaration node) {
4935 ExecutableElement outerExecutable = _enclosingExecutable; 4930 ExecutableElement outerExecutable = _enclosingExecutable;
4936 try { 4931 try {
4937 sc.Token property = node.propertyKeyword; 4932 sc.Token property = node.propertyKeyword;
4938 SimpleIdentifier methodName = node.name; 4933 SimpleIdentifier methodName = node.name;
4939 String nameOfMethod = methodName.name; 4934 String nameOfMethod = methodName.name;
4940 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) { 4935 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
4941 nameOfMethod = "unary-"; 4936 nameOfMethod = "unary-";
4942 } 4937 }
4943 if (property == null) { 4938 if (property == null) {
4944 _enclosingExecutable = find9(_enclosingClass.methods, nameOfMethod, meth odName.offset); 4939 _enclosingExecutable = findWithNameAndOffset(_enclosingClass.methods, na meOfMethod, methodName.offset);
4945 methodName.staticElement = _enclosingExecutable; 4940 methodName.staticElement = _enclosingExecutable;
4946 } else { 4941 } else {
4947 PropertyAccessorElement accessor = find8(_enclosingClass.accessors, meth odName); 4942 PropertyAccessorElement accessor = findIdentifier(_enclosingClass.access ors, methodName);
4948 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) { 4943 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
4949 accessor = accessor.variable.setter; 4944 accessor = accessor.variable.setter;
4950 methodName.staticElement = accessor; 4945 methodName.staticElement = accessor;
4951 } 4946 }
4952 _enclosingExecutable = accessor; 4947 _enclosingExecutable = accessor;
4953 } 4948 }
4954 return super.visitMethodDeclaration(node); 4949 return super.visitMethodDeclaration(node);
4955 } finally { 4950 } finally {
4956 _enclosingExecutable = outerExecutable; 4951 _enclosingExecutable = outerExecutable;
4957 } 4952 }
4958 } 4953 }
4959 4954
4960 Object visitPartDirective(PartDirective node) { 4955 Object visitPartDirective(PartDirective node) {
4961 String uri = getStringValue(node.uri); 4956 String uri = getStringValue(node.uri);
4962 if (uri != null) { 4957 if (uri != null) {
4963 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri); 4958 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri);
4964 node.element = find(_enclosingUnit.library.parts, partSource); 4959 node.element = findPart(_enclosingUnit.library.parts, partSource);
4965 } 4960 }
4966 return super.visitPartDirective(node); 4961 return super.visitPartDirective(node);
4967 } 4962 }
4968 4963
4969 Object visitPartOfDirective(PartOfDirective node) { 4964 Object visitPartOfDirective(PartOfDirective node) {
4970 node.element = _enclosingUnit.library; 4965 node.element = _enclosingUnit.library;
4971 return super.visitPartOfDirective(node); 4966 return super.visitPartOfDirective(node);
4972 } 4967 }
4973 4968
4974 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 4969 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
4975 if (node.parent is! DefaultFormalParameter) { 4970 if (node.parent is! DefaultFormalParameter) {
4976 SimpleIdentifier parameterName = node.identifier; 4971 SimpleIdentifier parameterName = node.identifier;
4977 ParameterElement element = getElementForParameter(node, parameterName); 4972 ParameterElement element = getElementForParameter(node, parameterName);
4978 ParameterElement outerParameter = _enclosingParameter; 4973 ParameterElement outerParameter = _enclosingParameter;
4979 try { 4974 try {
4980 _enclosingParameter = element; 4975 _enclosingParameter = element;
4981 return super.visitSimpleFormalParameter(node); 4976 return super.visitSimpleFormalParameter(node);
4982 } finally { 4977 } finally {
4983 _enclosingParameter = outerParameter; 4978 _enclosingParameter = outerParameter;
4984 } 4979 }
4985 } else { 4980 } else {
4986 } 4981 }
4987 return super.visitSimpleFormalParameter(node); 4982 return super.visitSimpleFormalParameter(node);
4988 } 4983 }
4989 4984
4990 Object visitSwitchCase(SwitchCase node) { 4985 Object visitSwitchCase(SwitchCase node) {
4991 for (Label label in node.labels) { 4986 for (Label label in node.labels) {
4992 SimpleIdentifier labelName = label.label; 4987 SimpleIdentifier labelName = label.label;
4993 find8(_enclosingExecutable.labels, labelName); 4988 findIdentifier(_enclosingExecutable.labels, labelName);
4994 } 4989 }
4995 return super.visitSwitchCase(node); 4990 return super.visitSwitchCase(node);
4996 } 4991 }
4997 4992
4998 Object visitSwitchDefault(SwitchDefault node) { 4993 Object visitSwitchDefault(SwitchDefault node) {
4999 for (Label label in node.labels) { 4994 for (Label label in node.labels) {
5000 SimpleIdentifier labelName = label.label; 4995 SimpleIdentifier labelName = label.label;
5001 find8(_enclosingExecutable.labels, labelName); 4996 findIdentifier(_enclosingExecutable.labels, labelName);
5002 } 4997 }
5003 return super.visitSwitchDefault(node); 4998 return super.visitSwitchDefault(node);
5004 } 4999 }
5005 5000
5006 Object visitTypeParameter(TypeParameter node) { 5001 Object visitTypeParameter(TypeParameter node) {
5007 SimpleIdentifier parameterName = node.name; 5002 SimpleIdentifier parameterName = node.name;
5008 if (_enclosingClass != null) { 5003 if (_enclosingClass != null) {
5009 find8(_enclosingClass.typeParameters, parameterName); 5004 findIdentifier(_enclosingClass.typeParameters, parameterName);
5010 } else if (_enclosingAlias != null) { 5005 } else if (_enclosingAlias != null) {
5011 find8(_enclosingAlias.typeParameters, parameterName); 5006 findIdentifier(_enclosingAlias.typeParameters, parameterName);
5012 } 5007 }
5013 return super.visitTypeParameter(node); 5008 return super.visitTypeParameter(node);
5014 } 5009 }
5015 5010
5016 Object visitVariableDeclaration(VariableDeclaration node) { 5011 Object visitVariableDeclaration(VariableDeclaration node) {
5017 VariableElement element = null; 5012 VariableElement element = null;
5018 SimpleIdentifier variableName = node.name; 5013 SimpleIdentifier variableName = node.name;
5019 if (_enclosingExecutable != null) { 5014 if (_enclosingExecutable != null) {
5020 element = find8(_enclosingExecutable.localVariables, variableName); 5015 element = findIdentifier(_enclosingExecutable.localVariables, variableName );
5021 } 5016 }
5022 if (element == null && _enclosingClass != null) { 5017 if (element == null && _enclosingClass != null) {
5023 element = find8(_enclosingClass.fields, variableName); 5018 element = findIdentifier(_enclosingClass.fields, variableName);
5024 } 5019 }
5025 if (element == null && _enclosingUnit != null) { 5020 if (element == null && _enclosingUnit != null) {
5026 element = find8(_enclosingUnit.topLevelVariables, variableName); 5021 element = findIdentifier(_enclosingUnit.topLevelVariables, variableName);
5027 } 5022 }
5028 Expression initializer = node.initializer; 5023 Expression initializer = node.initializer;
5029 if (initializer != null) { 5024 if (initializer != null) {
5030 ExecutableElement outerExecutable = _enclosingExecutable; 5025 ExecutableElement outerExecutable = _enclosingExecutable;
5031 try { 5026 try {
5032 if (element == null) { 5027 if (element == null) {
5033 } else { 5028 } else {
5034 _enclosingExecutable = element.initializer; 5029 _enclosingExecutable = element.initializer;
5035 } 5030 }
5036 return super.visitVariableDeclaration(node); 5031 return super.visitVariableDeclaration(node);
5037 } finally { 5032 } finally {
5038 _enclosingExecutable = outerExecutable; 5033 _enclosingExecutable = outerExecutable;
5039 } 5034 }
5040 } 5035 }
5041 return super.visitVariableDeclaration(node); 5036 return super.visitVariableDeclaration(node);
5042 } 5037 }
5043 5038
5044 /** 5039 /**
5045 * Return the element for the part with the given source, or `null` if there i s no element
5046 * for the given source.
5047 *
5048 * @param parts the elements for the parts
5049 * @param partSource the source for the part whose element is to be returned
5050 * @return the element for the part with the given source
5051 */
5052 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou rce) {
5053 for (CompilationUnitElement part in parts) {
5054 if (part.source == partSource) {
5055 return part;
5056 }
5057 }
5058 return null;
5059 }
5060
5061 /**
5062 * Return the element in the given array of elements that was created for the declaration at the 5040 * Return the element in the given array of elements that was created for the declaration at the
5063 * given offset. This method should only be used when there is no name 5041 * given offset. This method should only be used when there is no name
5064 * 5042 *
5065 * @param elements the elements of the appropriate kind that exist in the curr ent context 5043 * @param elements the elements of the appropriate kind that exist in the curr ent context
5066 * @param offset the offset of the name of the element to be returned 5044 * @param offset the offset of the name of the element to be returned
5067 * @return the element at the given offset 5045 * @return the element at the given offset
5068 */ 5046 */
5069 Element find7(List<Element> elements, int offset) => find9(elements, "", offse t); 5047 Element findAtOffset(List<Element> elements, int offset) => findWithNameAndOff set(elements, "", offset);
5070
5071 /**
5072 * Return the element in the given array of elements that was created for the declaration with the
5073 * given name.
5074 *
5075 * @param elements the elements of the appropriate kind that exist in the curr ent context
5076 * @param identifier the name node in the declaration of the element to be ret urned
5077 * @return the element created for the declaration with the given name
5078 */
5079 Element find8(List<Element> elements, SimpleIdentifier identifier) {
5080 Element element = find9(elements, identifier.name, identifier.offset);
5081 identifier.staticElement = element;
5082 return element;
5083 }
5084
5085 /**
5086 * Return the element in the given array of elements that was created for the declaration with the
5087 * given name at the given offset.
5088 *
5089 * @param elements the elements of the appropriate kind that exist in the curr ent context
5090 * @param name the name of the element to be returned
5091 * @param offset the offset of the name of the element to be returned
5092 * @return the element with the given name and offset
5093 */
5094 Element find9(List<Element> elements, String name, int offset) {
5095 for (Element element in elements) {
5096 if (element.displayName == name && element.nameOffset == offset) {
5097 return element;
5098 }
5099 }
5100 return null;
5101 }
5102 5048
5103 /** 5049 /**
5104 * Return the export element from the given array whose library has the given source, or 5050 * Return the export element from the given array whose library has the given source, or
5105 * `null` if there is no such export. 5051 * `null` if there is no such export.
5106 * 5052 *
5107 * @param exports the export elements being searched 5053 * @param exports the export elements being searched
5108 * @param source the source of the library associated with the export element to being searched 5054 * @param source the source of the library associated with the export element to being searched
5109 * for 5055 * for
5110 * @return the export element whose library has the given source 5056 * @return the export element whose library has the given source
5111 */ 5057 */
5112 ExportElement find10(List<ExportElement> exports, Source source) { 5058 ExportElement findExport(List<ExportElement> exports, Source source) {
5113 for (ExportElement export in exports) { 5059 for (ExportElement export in exports) {
5114 if (export.exportedLibrary.source == source) { 5060 if (export.exportedLibrary.source == source) {
5115 return export; 5061 return export;
5116 } 5062 }
5117 } 5063 }
5118 return null; 5064 return null;
5119 } 5065 }
5120 5066
5121 /** 5067 /**
5068 * Return the element in the given array of elements that was created for the declaration with the
5069 * given name.
5070 *
5071 * @param elements the elements of the appropriate kind that exist in the curr ent context
5072 * @param identifier the name node in the declaration of the element to be ret urned
5073 * @return the element created for the declaration with the given name
5074 */
5075 Element findIdentifier(List<Element> elements, SimpleIdentifier identifier) {
5076 Element element = findWithNameAndOffset(elements, identifier.name, identifie r.offset);
5077 identifier.staticElement = element;
5078 return element;
5079 }
5080
5081 /**
5122 * Return the import element from the given array whose library has the given source and that has 5082 * Return the import element from the given array whose library has the given source and that has
5123 * the given prefix, or `null` if there is no such import. 5083 * the given prefix, or `null` if there is no such import.
5124 * 5084 *
5125 * @param imports the import elements being searched 5085 * @param imports the import elements being searched
5126 * @param source the source of the library associated with the import element to being searched 5086 * @param source the source of the library associated with the import element to being searched
5127 * for 5087 * for
5128 * @param prefix the prefix with which the library was imported 5088 * @param prefix the prefix with which the library was imported
5129 * @return the import element whose library has the given source and prefix 5089 * @return the import element whose library has the given source and prefix
5130 */ 5090 */
5131 ImportElement find11(List<ImportElement> imports, Source source, SimpleIdentif ier prefix) { 5091 ImportElement findImport(List<ImportElement> imports, Source source, SimpleIde ntifier prefix) {
5132 for (ImportElement element in imports) { 5092 for (ImportElement element in imports) {
5133 if (element.importedLibrary.source == source) { 5093 if (element.importedLibrary.source == source) {
5134 PrefixElement prefixElement = element.prefix; 5094 PrefixElement prefixElement = element.prefix;
5135 if (prefix == null) { 5095 if (prefix == null) {
5136 if (prefixElement == null) { 5096 if (prefixElement == null) {
5137 return element; 5097 return element;
5138 } 5098 }
5139 } else { 5099 } else {
5140 if (prefixElement != null && prefix.name == prefixElement.displayName) { 5100 if (prefixElement != null && prefix.name == prefixElement.displayName) {
5141 return element; 5101 return element;
5142 } 5102 }
5143 } 5103 }
5144 } 5104 }
5145 } 5105 }
5146 return null; 5106 return null;
5147 } 5107 }
5148 5108
5149 /** 5109 /**
5110 * Return the element for the part with the given source, or `null` if there i s no element
5111 * for the given source.
5112 *
5113 * @param parts the elements for the parts
5114 * @param partSource the source for the part whose element is to be returned
5115 * @return the element for the part with the given source
5116 */
5117 CompilationUnitElement findPart(List<CompilationUnitElement> parts, Source par tSource) {
5118 for (CompilationUnitElement part in parts) {
5119 if (part.source == partSource) {
5120 return part;
5121 }
5122 }
5123 return null;
5124 }
5125
5126 /**
5127 * Return the element in the given array of elements that was created for the declaration with the
5128 * given name at the given offset.
5129 *
5130 * @param elements the elements of the appropriate kind that exist in the curr ent context
5131 * @param name the name of the element to be returned
5132 * @param offset the offset of the name of the element to be returned
5133 * @return the element with the given name and offset
5134 */
5135 Element findWithNameAndOffset(List<Element> elements, String name, int offset) {
5136 for (Element element in elements) {
5137 if (element.displayName == name && element.nameOffset == offset) {
5138 return element;
5139 }
5140 }
5141 return null;
5142 }
5143
5144 /**
5150 * Search the most closely enclosing list of parameters for a parameter with t he given name. 5145 * Search the most closely enclosing list of parameters for a parameter with t he given name.
5151 * 5146 *
5152 * @param node the node defining the parameter with the given name 5147 * @param node the node defining the parameter with the given name
5153 * @param parameterName the name of the parameter being searched for 5148 * @param parameterName the name of the parameter being searched for
5154 * @return the element representing the parameter with that name 5149 * @return the element representing the parameter with that name
5155 */ 5150 */
5156 ParameterElement getElementForParameter(FormalParameter node, SimpleIdentifier parameterName) { 5151 ParameterElement getElementForParameter(FormalParameter node, SimpleIdentifier parameterName) {
5157 List<ParameterElement> parameters = null; 5152 List<ParameterElement> parameters = null;
5158 if (_enclosingParameter != null) { 5153 if (_enclosingParameter != null) {
5159 parameters = _enclosingParameter.parameters; 5154 parameters = _enclosingParameter.parameters;
5160 } 5155 }
5161 if (parameters == null && _enclosingExecutable != null) { 5156 if (parameters == null && _enclosingExecutable != null) {
5162 parameters = _enclosingExecutable.parameters; 5157 parameters = _enclosingExecutable.parameters;
5163 } 5158 }
5164 if (parameters == null && _enclosingAlias != null) { 5159 if (parameters == null && _enclosingAlias != null) {
5165 parameters = _enclosingAlias.parameters; 5160 parameters = _enclosingAlias.parameters;
5166 } 5161 }
5167 ParameterElement element = parameters == null ? null : find8(parameters, par ameterName); 5162 ParameterElement element = parameters == null ? null : findIdentifier(parame ters, parameterName);
5168 if (element == null) { 5163 if (element == null) {
5169 PrintStringWriter writer = new PrintStringWriter(); 5164 PrintStringWriter writer = new PrintStringWriter();
5170 writer.println("Invalid state found in the Analysis Engine:"); 5165 writer.println("Invalid state found in the Analysis Engine:");
5171 writer.println("DeclarationResolver.getElementForParameter() is visiting a parameter that does not appear to be in a method or function."); 5166 writer.println("DeclarationResolver.getElementForParameter() is visiting a parameter that does not appear to be in a method or function.");
5172 writer.println("Ancestors:"); 5167 writer.println("Ancestors:");
5173 AstNode parent = node.parent; 5168 AstNode parent = node.parent;
5174 while (parent != null) { 5169 while (parent != null) {
5175 writer.println(parent.runtimeType.toString()); 5170 writer.println(parent.runtimeType.toString());
5176 writer.println("---------"); 5171 writer.println("---------");
5177 parent = parent.parent; 5172 parent = parent.parent;
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
5605 // The element is null when the URI is invalid 5600 // The element is null when the URI is invalid
5606 // TODO(brianwilkerson) Figure out whether the element can ever be somethi ng other than an 5601 // TODO(brianwilkerson) Figure out whether the element can ever be somethi ng other than an
5607 // ExportElement 5602 // ExportElement
5608 resolveCombinators(element.exportedLibrary, node.combinators); 5603 resolveCombinators(element.exportedLibrary, node.combinators);
5609 setMetadata(element, node); 5604 setMetadata(element, node);
5610 } 5605 }
5611 return null; 5606 return null;
5612 } 5607 }
5613 5608
5614 Object visitFieldFormalParameter(FieldFormalParameter node) { 5609 Object visitFieldFormalParameter(FieldFormalParameter node) {
5615 setMetadata2(node.element, node); 5610 setMetadataForParameter(node.element, node);
5616 return super.visitFieldFormalParameter(node); 5611 return super.visitFieldFormalParameter(node);
5617 } 5612 }
5618 5613
5619 Object visitFunctionDeclaration(FunctionDeclaration node) { 5614 Object visitFunctionDeclaration(FunctionDeclaration node) {
5620 setMetadata(node.element, node); 5615 setMetadata(node.element, node);
5621 return null; 5616 return null;
5622 } 5617 }
5623 5618
5624 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 5619 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
5625 // TODO(brianwilkerson) Can we ever resolve the function being invoked? 5620 // TODO(brianwilkerson) Can we ever resolve the function being invoked?
5626 Expression expression = node.function; 5621 Expression expression = node.function;
5627 if (expression is FunctionExpression) { 5622 if (expression is FunctionExpression) {
5628 FunctionExpression functionExpression = expression; 5623 FunctionExpression functionExpression = expression;
5629 ExecutableElement functionElement = functionExpression.element; 5624 ExecutableElement functionElement = functionExpression.element;
5630 ArgumentList argumentList = node.argumentList; 5625 ArgumentList argumentList = node.argumentList;
5631 List<ParameterElement> parameters = resolveArgumentsToParameters(false, ar gumentList, functionElement); 5626 List<ParameterElement> parameters = resolveArgumentsToFunction(false, argu mentList, functionElement);
5632 if (parameters != null) { 5627 if (parameters != null) {
5633 argumentList.correspondingStaticParameters = parameters; 5628 argumentList.correspondingStaticParameters = parameters;
5634 } 5629 }
5635 } 5630 }
5636 return null; 5631 return null;
5637 } 5632 }
5638 5633
5639 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 5634 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
5640 setMetadata(node.element, node); 5635 setMetadata(node.element, node);
5641 return null; 5636 return null;
5642 } 5637 }
5643 5638
5644 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 5639 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
5645 setMetadata2(node.element, node); 5640 setMetadataForParameter(node.element, node);
5646 return null; 5641 return null;
5647 } 5642 }
5648 5643
5649 Object visitImportDirective(ImportDirective node) { 5644 Object visitImportDirective(ImportDirective node) {
5650 SimpleIdentifier prefixNode = node.prefix; 5645 SimpleIdentifier prefixNode = node.prefix;
5651 if (prefixNode != null) { 5646 if (prefixNode != null) {
5652 String prefixName = prefixNode.name; 5647 String prefixName = prefixNode.name;
5653 for (PrefixElement prefixElement in _definingLibrary.prefixes) { 5648 for (PrefixElement prefixElement in _definingLibrary.prefixes) {
5654 if (prefixElement.displayName == prefixName) { 5649 if (prefixElement.displayName == prefixName) {
5655 prefixNode.staticElement = prefixElement; 5650 prefixNode.staticElement = prefixElement;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
5713 // generate undefined method warning 5708 // generate undefined method warning
5714 checkForUndefinedIndexOperator(node, target, setterMethodName, staticMetho d, propagatedMethod, staticType, propagatedType); 5709 checkForUndefinedIndexOperator(node, target, setterMethodName, staticMetho d, propagatedMethod, staticType, propagatedType);
5715 } 5710 }
5716 return null; 5711 return null;
5717 } 5712 }
5718 5713
5719 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 5714 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
5720 ConstructorElement invokedConstructor = node.constructorName.staticElement; 5715 ConstructorElement invokedConstructor = node.constructorName.staticElement;
5721 node.staticElement = invokedConstructor; 5716 node.staticElement = invokedConstructor;
5722 ArgumentList argumentList = node.argumentList; 5717 ArgumentList argumentList = node.argumentList;
5723 List<ParameterElement> parameters = resolveArgumentsToParameters(node.isCons t, argumentList, invokedConstructor); 5718 List<ParameterElement> parameters = resolveArgumentsToFunction(node.isConst, argumentList, invokedConstructor);
5724 if (parameters != null) { 5719 if (parameters != null) {
5725 argumentList.correspondingStaticParameters = parameters; 5720 argumentList.correspondingStaticParameters = parameters;
5726 } 5721 }
5727 return null; 5722 return null;
5728 } 5723 }
5729 5724
5730 Object visitLibraryDirective(LibraryDirective node) { 5725 Object visitLibraryDirective(LibraryDirective node) {
5731 setMetadata(node.element, node); 5726 setMetadata(node.element, node);
5732 return null; 5727 return null;
5733 } 5728 }
(...skipping 16 matching lines...) Expand all
5750 // first step is to figure out which executable is being invoked, using both the static and the 5745 // first step is to figure out which executable is being invoked, using both the static and the
5751 // propagated type information. 5746 // propagated type information.
5752 // 5747 //
5753 Expression target = node.realTarget; 5748 Expression target = node.realTarget;
5754 if (target is SuperExpression && !isSuperInValidContext(target)) { 5749 if (target is SuperExpression && !isSuperInValidContext(target)) {
5755 return null; 5750 return null;
5756 } 5751 }
5757 Element staticElement; 5752 Element staticElement;
5758 Element propagatedElement; 5753 Element propagatedElement;
5759 if (target == null) { 5754 if (target == null) {
5760 staticElement = resolveInvokedElement2(methodName); 5755 staticElement = resolveInvokedElement(methodName);
5761 propagatedElement = null; 5756 propagatedElement = null;
5762 } else { 5757 } else {
5763 Type2 staticType = getStaticType(target); 5758 Type2 staticType = getStaticType(target);
5764 // 5759 //
5765 // If this method invocation is of the form 'C.m' where 'C' is a class, th en we don't call 5760 // If this method invocation is of the form 'C.m' where 'C' is a class, th en we don't call
5766 // resolveInvokedElement(..) which walks up the class hierarchy, instead w e just look for the 5761 // resolveInvokedElement(..) which walks up the class hierarchy, instead w e just look for the
5767 // member in the type only. 5762 // member in the type only.
5768 // 5763 //
5769 ClassElementImpl typeReference = getTypeReference(target); 5764 ClassElementImpl typeReference = getTypeReference(target);
5770 if (typeReference != null) { 5765 if (typeReference != null) {
5771 staticElement = propagatedElement = resolveElement(typeReference, method Name); 5766 staticElement = propagatedElement = resolveElement(typeReference, method Name);
5772 } else { 5767 } else {
5773 staticElement = resolveInvokedElement(target, staticType, methodName); 5768 staticElement = resolveInvokedElementWithTarget(target, staticType, meth odName);
5774 propagatedElement = resolveInvokedElement(target, getPropagatedType(targ et), methodName); 5769 propagatedElement = resolveInvokedElementWithTarget(target, getPropagate dType(target), methodName);
5775 } 5770 }
5776 } 5771 }
5777 staticElement = convertSetterToGetter(staticElement); 5772 staticElement = convertSetterToGetter(staticElement);
5778 propagatedElement = convertSetterToGetter(propagatedElement); 5773 propagatedElement = convertSetterToGetter(propagatedElement);
5779 // 5774 //
5780 // Record the results. 5775 // Record the results.
5781 // 5776 //
5782 methodName.staticElement = staticElement; 5777 methodName.staticElement = staticElement;
5783 methodName.propagatedElement = propagatedElement; 5778 methodName.propagatedElement = propagatedElement;
5784 ArgumentList argumentList = node.argumentList; 5779 ArgumentList argumentList = node.argumentList;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5822 } 5817 }
5823 } 5818 }
5824 } 5819 }
5825 } 5820 }
5826 generatedWithTypePropagation = true; 5821 generatedWithTypePropagation = true;
5827 } 5822 }
5828 if (errorCode == null) { 5823 if (errorCode == null) {
5829 return null; 5824 return null;
5830 } 5825 }
5831 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) { 5826 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) {
5832 _resolver.reportError9(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]); 5827 _resolver.reportErrorForNode(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCT ION, methodName, [methodName.name]);
5833 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { 5828 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) {
5834 _resolver.reportError9(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]); 5829 _resolver.reportErrorForNode(CompileTimeErrorCode.UNDEFINED_FUNCTION, meth odName, [methodName.name]);
5835 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { 5830 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
5836 String targetTypeName; 5831 String targetTypeName;
5837 if (target == null) { 5832 if (target == null) {
5838 ClassElement enclosingClass = _resolver.enclosingClass; 5833 ClassElement enclosingClass = _resolver.enclosingClass;
5839 targetTypeName = enclosingClass.displayName; 5834 targetTypeName = enclosingClass.displayName;
5840 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; 5835 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode;
5841 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]); 5836 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]);
5842 } else { 5837 } else {
5843 // ignore Function "call" 5838 // ignore Function "call"
5844 // (if we are about to create a hint using type propagation, then we can use type 5839 // (if we are about to create a hint using type propagation, then we can use type
(...skipping 15 matching lines...) Expand all
5860 } 5855 }
5861 targetTypeName = targetType == null ? null : targetType.displayName; 5856 targetTypeName = targetType == null ? null : targetType.displayName;
5862 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; 5857 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode;
5863 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p roxyErrorCode, methodName, [methodName.name, targetTypeName]); 5858 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p roxyErrorCode, methodName, [methodName.name, targetTypeName]);
5864 } 5859 }
5865 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD )) { 5860 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD )) {
5866 // Generate the type name. 5861 // Generate the type name.
5867 // The error code will never be generated via type propagation 5862 // The error code will never be generated via type propagation
5868 Type2 targetType = getStaticType(target); 5863 Type2 targetType = getStaticType(target);
5869 String targetTypeName = targetType == null ? null : targetType.name; 5864 String targetTypeName = targetType == null ? null : targetType.name;
5870 _resolver.reportError9(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho dName, [methodName.name, targetTypeName]); 5865 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, methodName, [methodName.name, targetTypeName]);
5871 } 5866 }
5872 return null; 5867 return null;
5873 } 5868 }
5874 5869
5875 Object visitPartDirective(PartDirective node) { 5870 Object visitPartDirective(PartDirective node) {
5876 setMetadata(node.element, node); 5871 setMetadata(node.element, node);
5877 return null; 5872 return null;
5878 } 5873 }
5879 5874
5880 Object visitPartOfDirective(PartOfDirective node) { 5875 Object visitPartOfDirective(PartOfDirective node) {
(...skipping 25 matching lines...) Expand all
5906 // First, check to see whether the prefix is really a prefix. 5901 // First, check to see whether the prefix is really a prefix.
5907 // 5902 //
5908 Element prefixElement = prefix.staticElement; 5903 Element prefixElement = prefix.staticElement;
5909 if (prefixElement is PrefixElement) { 5904 if (prefixElement is PrefixElement) {
5910 Element element = _resolver.nameScope.lookup(node, _definingLibrary); 5905 Element element = _resolver.nameScope.lookup(node, _definingLibrary);
5911 if (element == null && identifier.inSetterContext()) { 5906 if (element == null && identifier.inSetterContext()) {
5912 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary); 5907 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary);
5913 } 5908 }
5914 if (element == null) { 5909 if (element == null) {
5915 if (identifier.inSetterContext()) { 5910 if (identifier.inSetterContext()) {
5916 _resolver.reportError9(StaticWarningCode.UNDEFINED_SETTER, identifier, [identifier.name, prefixElement.name]); 5911 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident ifier, [identifier.name, prefixElement.name]);
5917 } else if (node.parent is Annotation) { 5912 } else if (node.parent is Annotation) {
5918 Annotation annotation = node.parent as Annotation; 5913 Annotation annotation = node.parent as Annotation;
5919 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annota tion, []); 5914 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, annotation, []);
5920 return null; 5915 return null;
5921 } else { 5916 } else {
5922 _resolver.reportError9(StaticWarningCode.UNDEFINED_GETTER, identifier, [identifier.name, prefixElement.name]); 5917 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_GETTER, ident ifier, [identifier.name, prefixElement.name]);
5923 } 5918 }
5924 return null; 5919 return null;
5925 } 5920 }
5926 if (element is PropertyAccessorElement && identifier.inSetterContext()) { 5921 if (element is PropertyAccessorElement && identifier.inSetterContext()) {
5927 PropertyInducingElement variable = (element as PropertyAccessorElement). variable; 5922 PropertyInducingElement variable = (element as PropertyAccessorElement). variable;
5928 if (variable != null) { 5923 if (variable != null) {
5929 PropertyAccessorElement setter = variable.setter; 5924 PropertyAccessorElement setter = variable.setter;
5930 if (setter != null) { 5925 if (setter != null) {
5931 element = setter; 5926 element = setter;
5932 } 5927 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
6002 } 5997 }
6003 if (element == null) { 5998 if (element == null) {
6004 // TODO(brianwilkerson) Report this error and decide what element to assoc iate with the node. 5999 // TODO(brianwilkerson) Report this error and decide what element to assoc iate with the node.
6005 return null; 6000 return null;
6006 } 6001 }
6007 if (name != null) { 6002 if (name != null) {
6008 name.staticElement = element; 6003 name.staticElement = element;
6009 } 6004 }
6010 node.staticElement = element; 6005 node.staticElement = element;
6011 ArgumentList argumentList = node.argumentList; 6006 ArgumentList argumentList = node.argumentList;
6012 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element); 6007 List<ParameterElement> parameters = resolveArgumentsToFunction(false, argume ntList, element);
6013 if (parameters != null) { 6008 if (parameters != null) {
6014 argumentList.correspondingStaticParameters = parameters; 6009 argumentList.correspondingStaticParameters = parameters;
6015 } 6010 }
6016 return null; 6011 return null;
6017 } 6012 }
6018 6013
6019 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 6014 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
6020 setMetadata2(node.element, node); 6015 setMetadataForParameter(node.element, node);
6021 return null; 6016 return null;
6022 } 6017 }
6023 6018
6024 Object visitSimpleIdentifier(SimpleIdentifier node) { 6019 Object visitSimpleIdentifier(SimpleIdentifier node) {
6025 // 6020 //
6026 // Synthetic identifiers have been already reported during parsing. 6021 // Synthetic identifiers have been already reported during parsing.
6027 // 6022 //
6028 if (node.isSynthetic) { 6023 if (node.isSynthetic) {
6029 return null; 6024 return null;
6030 } 6025 }
(...skipping 11 matching lines...) Expand all
6042 node.staticElement = _dynamicType.element; 6037 node.staticElement = _dynamicType.element;
6043 node.staticType = _typeType; 6038 node.staticType = _typeType;
6044 return null; 6039 return null;
6045 } 6040 }
6046 // 6041 //
6047 // Otherwise, the node should be resolved. 6042 // Otherwise, the node should be resolved.
6048 // 6043 //
6049 Element element = resolveSimpleIdentifier(node); 6044 Element element = resolveSimpleIdentifier(node);
6050 ClassElement enclosingClass = _resolver.enclosingClass; 6045 ClassElement enclosingClass = _resolver.enclosingClass;
6051 if (isFactoryConstructorReturnType(node) && element != enclosingClass) { 6046 if (isFactoryConstructorReturnType(node) && element != enclosingClass) {
6052 _resolver.reportError9(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA SS, node, []); 6047 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT _A_CLASS, node, []);
6053 } else if (isConstructorReturnType(node) && element != enclosingClass) { 6048 } else if (isConstructorReturnType(node) && element != enclosingClass) {
6054 _resolver.reportError9(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node , []); 6049 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME , node, []);
6055 element = null; 6050 element = null;
6056 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) { 6051 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) {
6057 // TODO(brianwilkerson) Recover from this error. 6052 // TODO(brianwilkerson) Recover from this error.
6058 if (isConstructorReturnType(node)) { 6053 if (isConstructorReturnType(node)) {
6059 _resolver.reportError9(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no de, []); 6054 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NA ME, node, []);
6060 } else if (node.parent is Annotation) { 6055 } else if (node.parent is Annotation) {
6061 Annotation annotation = node.parent as Annotation; 6056 Annotation annotation = node.parent as Annotation;
6062 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []); 6057 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, an notation, []);
6063 } else { 6058 } else {
6064 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); 6059 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]);
6065 } 6060 }
6066 } 6061 }
6067 node.staticElement = element; 6062 node.staticElement = element;
6068 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu ll) { 6063 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu ll) {
6069 InterfaceType enclosingType = enclosingClass.type; 6064 InterfaceType enclosingType = enclosingClass.type;
6070 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n ull, enclosingType, node.name), null); 6065 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n ull, enclosingType, node.name), null);
6071 node.auxiliaryElements = auxiliaryElements; 6066 node.auxiliaryElements = auxiliaryElements;
6072 } 6067 }
(...skipping 16 matching lines...) Expand all
6089 InterfaceType superType = enclosingClass.supertype; 6084 InterfaceType superType = enclosingClass.supertype;
6090 if (superType == null) { 6085 if (superType == null) {
6091 // TODO(brianwilkerson) Report this error. 6086 // TODO(brianwilkerson) Report this error.
6092 return null; 6087 return null;
6093 } 6088 }
6094 SimpleIdentifier name = node.constructorName; 6089 SimpleIdentifier name = node.constructorName;
6095 String superName = name != null ? name.name : null; 6090 String superName = name != null ? name.name : null;
6096 ConstructorElement element = superType.lookUpConstructor(superName, _definin gLibrary); 6091 ConstructorElement element = superType.lookUpConstructor(superName, _definin gLibrary);
6097 if (element == null) { 6092 if (element == null) {
6098 if (name != null) { 6093 if (name != null) {
6099 _resolver.reportError9(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superType.displayName, name]); 6094 _resolver.reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_ IN_INITIALIZER, node, [superType.displayName, name]);
6100 } else { 6095 } else {
6101 _resolver.reportError9(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superType.displayName]); 6096 _resolver.reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_ IN_INITIALIZER_DEFAULT, node, [superType.displayName]);
6102 } 6097 }
6103 return null; 6098 return null;
6104 } else { 6099 } else {
6105 if (element.isFactory) { 6100 if (element.isFactory) {
6106 _resolver.reportError9(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); 6101 _resolver.reportErrorForNode(CompileTimeErrorCode.NON_GENERATIVE_CONSTRU CTOR, node, [element]);
6107 } 6102 }
6108 } 6103 }
6109 if (name != null) { 6104 if (name != null) {
6110 name.staticElement = element; 6105 name.staticElement = element;
6111 } 6106 }
6112 node.staticElement = element; 6107 node.staticElement = element;
6113 ArgumentList argumentList = node.argumentList; 6108 ArgumentList argumentList = node.argumentList;
6114 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo nstructor, argumentList, element); 6109 List<ParameterElement> parameters = resolveArgumentsToFunction(isInConstCons tructor, argumentList, element);
6115 if (parameters != null) { 6110 if (parameters != null) {
6116 argumentList.correspondingStaticParameters = parameters; 6111 argumentList.correspondingStaticParameters = parameters;
6117 } 6112 }
6118 return null; 6113 return null;
6119 } 6114 }
6120 6115
6121 Object visitSuperExpression(SuperExpression node) { 6116 Object visitSuperExpression(SuperExpression node) {
6122 if (!isSuperInValidContext(node)) { 6117 if (!isSuperInValidContext(node)) {
6123 _resolver.reportError9(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node , []); 6118 _resolver.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT , node, []);
6124 } 6119 }
6125 return super.visitSuperExpression(node); 6120 return super.visitSuperExpression(node);
6126 } 6121 }
6127 6122
6128 Object visitTypeParameter(TypeParameter node) { 6123 Object visitTypeParameter(TypeParameter node) {
6129 setMetadata(node.element, node); 6124 setMetadata(node.element, node);
6130 return null; 6125 return null;
6131 } 6126 }
6132 6127
6133 Object visitVariableDeclaration(VariableDeclaration node) { 6128 Object visitVariableDeclaration(VariableDeclaration node) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
6282 if (element is PropertyAccessorElement) { 6277 if (element is PropertyAccessorElement) {
6283 // 6278 //
6284 // This is an invocation of the call method defined on the value returned by the getter. 6279 // This is an invocation of the call method defined on the value returned by the getter.
6285 // 6280 //
6286 FunctionType getterType = element.type; 6281 FunctionType getterType = element.type;
6287 if (getterType != null) { 6282 if (getterType != null) {
6288 Type2 getterReturnType = getterType.returnType; 6283 Type2 getterReturnType = getterType.returnType;
6289 if (getterReturnType is InterfaceType) { 6284 if (getterReturnType is InterfaceType) {
6290 MethodElement callMethod = getterReturnType.lookUpMethod(CALL_METHOD_N AME, _definingLibrary); 6285 MethodElement callMethod = getterReturnType.lookUpMethod(CALL_METHOD_N AME, _definingLibrary);
6291 if (callMethod != null) { 6286 if (callMethod != null) {
6292 return resolveArgumentsToParameters(false, argumentList, callMethod) ; 6287 return resolveArgumentsToFunction(false, argumentList, callMethod);
6293 } 6288 }
6294 } else if (getterReturnType is FunctionType) { 6289 } else if (getterReturnType is FunctionType) {
6295 Element functionElement = getterReturnType.element; 6290 Element functionElement = getterReturnType.element;
6296 if (functionElement is ExecutableElement) { 6291 if (functionElement is ExecutableElement) {
6297 return resolveArgumentsToParameters(false, argumentList, functionEle ment); 6292 return resolveArgumentsToFunction(false, argumentList, functionEleme nt);
6298 } 6293 }
6299 } 6294 }
6300 } 6295 }
6301 } else if (element is ExecutableElement) { 6296 } else if (element is ExecutableElement) {
6302 return resolveArgumentsToParameters(false, argumentList, element); 6297 return resolveArgumentsToFunction(false, argumentList, element);
6303 } else if (element is VariableElement) { 6298 } else if (element is VariableElement) {
6304 VariableElement variable = element; 6299 VariableElement variable = element;
6305 Type2 type = _promoteManager.getStaticType(variable); 6300 Type2 type = _promoteManager.getStaticType(variable);
6306 if (type is FunctionType) { 6301 if (type is FunctionType) {
6307 FunctionType functionType = type; 6302 FunctionType functionType = type;
6308 List<ParameterElement> parameters = functionType.parameters; 6303 List<ParameterElement> parameters = functionType.parameters;
6309 return resolveArgumentsToParameters2(false, argumentList, parameters); 6304 return resolveArgumentsToParameters(false, argumentList, parameters);
6310 } else if (type is InterfaceType) { 6305 } else if (type is InterfaceType) {
6311 // "call" invocation 6306 // "call" invocation
6312 MethodElement callMethod = type.lookUpMethod(CALL_METHOD_NAME, _defining Library); 6307 MethodElement callMethod = type.lookUpMethod(CALL_METHOD_NAME, _defining Library);
6313 if (callMethod != null) { 6308 if (callMethod != null) {
6314 List<ParameterElement> parameters = callMethod.parameters; 6309 List<ParameterElement> parameters = callMethod.parameters;
6315 return resolveArgumentsToParameters2(false, argumentList, parameters); 6310 return resolveArgumentsToParameters(false, argumentList, parameters);
6316 } 6311 }
6317 } 6312 }
6318 } 6313 }
6319 return null; 6314 return null;
6320 } 6315 }
6321 6316
6322 /** 6317 /**
6323 * If the given element is a setter, return the getter associated with it. Oth erwise, return the 6318 * If the given element is a setter, return the getter associated with it. Oth erwise, return the
6324 * element unchanged. 6319 * element unchanged.
6325 * 6320 *
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
6658 if (labelElement == null) { 6653 if (labelElement == null) {
6659 } 6654 }
6660 // 6655 //
6661 // The label element that was returned was a marker for look-up and isn' t stored in the 6656 // The label element that was returned was a marker for look-up and isn' t stored in the
6662 // element model. 6657 // element model.
6663 // 6658 //
6664 labelElement = null; 6659 labelElement = null;
6665 } 6660 }
6666 } else { 6661 } else {
6667 if (labelScope == null) { 6662 if (labelScope == null) {
6668 _resolver.reportError9(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); 6663 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_UNDEFINED, label Node, [labelNode.name]);
6669 } else { 6664 } else {
6670 labelElement = labelScope.lookup(labelNode) as LabelElementImpl; 6665 labelElement = labelScope.lookup(labelNode) as LabelElementImpl;
6671 if (labelElement == null) { 6666 if (labelElement == null) {
6672 _resolver.reportError9(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode , [labelNode.name]); 6667 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_UNDEFINED, lab elNode, [labelNode.name]);
6673 } else { 6668 } else {
6674 labelNode.staticElement = labelElement; 6669 labelNode.staticElement = labelElement;
6675 } 6670 }
6676 } 6671 }
6677 } 6672 }
6678 if (labelElement != null) { 6673 if (labelElement != null) {
6679 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent); 6674 ExecutableElement labelContainer = labelElement.getAncestor((element) => e lement is ExecutableElement);
6680 if (labelContainer != _resolver.enclosingFunction) { 6675 if (labelContainer != _resolver.enclosingFunction) {
6681 _resolver.reportError9(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN ode, [labelNode.name]); 6676 _resolver.reportErrorForNode(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNode, [labelNode.name]);
6682 labelElement = null; 6677 labelElement = null;
6683 } 6678 }
6684 } 6679 }
6685 return labelElement; 6680 return labelElement;
6686 } 6681 }
6687 6682
6688 /** 6683 /**
6689 * Look up the method with the given name in the given type. Return the elemen t representing the 6684 * Look up the method with the given name in the given type. Return the elemen t representing the
6690 * method that was found, or `null` if there is no method with the given name. 6685 * method that was found, or `null` if there is no method with the given name.
6691 * 6686 *
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
6900 } 6895 }
6901 } 6896 }
6902 6897
6903 void resolveAnnotationConstructorInvocationArguments(Annotation annotation, Co nstructorElement constructor) { 6898 void resolveAnnotationConstructorInvocationArguments(Annotation annotation, Co nstructorElement constructor) {
6904 ArgumentList argumentList = annotation.arguments; 6899 ArgumentList argumentList = annotation.arguments;
6905 // error will be reported in ConstantVerifier 6900 // error will be reported in ConstantVerifier
6906 if (argumentList == null) { 6901 if (argumentList == null) {
6907 return; 6902 return;
6908 } 6903 }
6909 // resolve arguments to parameters 6904 // resolve arguments to parameters
6910 List<ParameterElement> parameters = resolveArgumentsToParameters(true, argum entList, constructor); 6905 List<ParameterElement> parameters = resolveArgumentsToFunction(true, argumen tList, constructor);
6911 if (parameters != null) { 6906 if (parameters != null) {
6912 argumentList.correspondingStaticParameters = parameters; 6907 argumentList.correspondingStaticParameters = parameters;
6913 } 6908 }
6914 } 6909 }
6915 6910
6916 /** 6911 /**
6917 * Continues resolution of the given [Annotation]. 6912 * Continues resolution of the given [Annotation].
6918 * 6913 *
6919 * @param annotation the [Annotation] to resolve 6914 * @param annotation the [Annotation] to resolve
6920 */ 6915 */
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
6997 resolveAnnotationElementGetter(annotation, getter); 6992 resolveAnnotationElementGetter(annotation, getter);
6998 return; 6993 return;
6999 } 6994 }
7000 // prefix.Class.constructor(args) 6995 // prefix.Class.constructor(args)
7001 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (name3, _definingLibrary); 6996 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (name3, _definingLibrary);
7002 nameNode3.staticElement = constructor; 6997 nameNode3.staticElement = constructor;
7003 } 6998 }
7004 } 6999 }
7005 // we need constructor 7000 // we need constructor
7006 if (constructor == null) { 7001 if (constructor == null) {
7007 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 7002 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno tation, []);
7008 return; 7003 return;
7009 } 7004 }
7010 // record element 7005 // record element
7011 annotation.element = constructor; 7006 annotation.element = constructor;
7012 // resolve arguments 7007 // resolve arguments
7013 resolveAnnotationConstructorInvocationArguments(annotation, constructor); 7008 resolveAnnotationConstructorInvocationArguments(annotation, constructor);
7014 } 7009 }
7015 7010
7016 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle ment accessorElement) { 7011 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle ment accessorElement) {
7017 // accessor should be synthetic 7012 // accessor should be synthetic
7018 if (!accessorElement.isSynthetic) { 7013 if (!accessorElement.isSynthetic) {
7019 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 7014 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno tation, []);
7020 return; 7015 return;
7021 } 7016 }
7022 // variable should be constant 7017 // variable should be constant
7023 VariableElement variableElement = accessorElement.variable; 7018 VariableElement variableElement = accessorElement.variable;
7024 if (!variableElement.isConst) { 7019 if (!variableElement.isConst) {
7025 _resolver.reportError9(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 7020 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION, anno tation, []);
7026 } 7021 }
7027 // OK 7022 // OK
7028 return; 7023 return;
7029 } 7024 }
7030 7025
7031 /** 7026 /**
7032 * Given a list of arguments and the element that will be invoked using those argument, compute 7027 * Given a list of arguments and the element that will be invoked using those argument, compute
7033 * the list of parameters that correspond to the list of arguments. Return the parameters that 7028 * the list of parameters that correspond to the list of arguments. Return the parameters that
7034 * correspond to the arguments, or `null` if no correspondence could be comput ed. 7029 * correspond to the arguments, or `null` if no correspondence could be comput ed.
7035 * 7030 *
7036 * @param reportError if `true` then compile-time error should be reported; if `false` 7031 * @param reportError if `true` then compile-time error should be reported; if `false`
7037 * then compile-time warning 7032 * then compile-time warning
7038 * @param argumentList the list of arguments being passed to the element 7033 * @param argumentList the list of arguments being passed to the element
7039 * @param executableElement the element that will be invoked with the argument s 7034 * @param executableElement the element that will be invoked with the argument s
7040 * @return the parameters that correspond to the arguments 7035 * @return the parameters that correspond to the arguments
7041 */ 7036 */
7042 List<ParameterElement> resolveArgumentsToParameters(bool reportError, Argument List argumentList, ExecutableElement executableElement) { 7037 List<ParameterElement> resolveArgumentsToFunction(bool reportError, ArgumentLi st argumentList, ExecutableElement executableElement) {
7043 if (executableElement == null) { 7038 if (executableElement == null) {
7044 return null; 7039 return null;
7045 } 7040 }
7046 List<ParameterElement> parameters = executableElement.parameters; 7041 List<ParameterElement> parameters = executableElement.parameters;
7047 return resolveArgumentsToParameters2(reportError, argumentList, parameters); 7042 return resolveArgumentsToParameters(reportError, argumentList, parameters);
7048 } 7043 }
7049 7044
7050 /** 7045 /**
7051 * Given a list of arguments and the parameters related to the element that wi ll be invoked using 7046 * Given a list of arguments and the parameters related to the element that wi ll be invoked using
7052 * those argument, compute the list of parameters that correspond to the list of arguments. Return 7047 * those argument, compute the list of parameters that correspond to the list of arguments. Return
7053 * the parameters that correspond to the arguments. 7048 * the parameters that correspond to the arguments.
7054 * 7049 *
7055 * @param reportError if `true` then compile-time error should be reported; if `false` 7050 * @param reportError if `true` then compile-time error should be reported; if `false`
7056 * then compile-time warning 7051 * then compile-time warning
7057 * @param argumentList the list of arguments being passed to the element 7052 * @param argumentList the list of arguments being passed to the element
7058 * @param parameters the of the function that will be invoked with the argumen ts 7053 * @param parameters the of the function that will be invoked with the argumen ts
7059 * @return the parameters that correspond to the arguments 7054 * @return the parameters that correspond to the arguments
7060 */ 7055 */
7061 List<ParameterElement> resolveArgumentsToParameters2(bool reportError, Argumen tList argumentList, List<ParameterElement> parameters) { 7056 List<ParameterElement> resolveArgumentsToParameters(bool reportError, Argument List argumentList, List<ParameterElement> parameters) {
7062 List<ParameterElement> requiredParameters = new List<ParameterElement>(); 7057 List<ParameterElement> requiredParameters = new List<ParameterElement>();
7063 List<ParameterElement> positionalParameters = new List<ParameterElement>(); 7058 List<ParameterElement> positionalParameters = new List<ParameterElement>();
7064 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle ment>(); 7059 Map<String, ParameterElement> namedParameters = new Map<String, ParameterEle ment>();
7065 for (ParameterElement parameter in parameters) { 7060 for (ParameterElement parameter in parameters) {
7066 ParameterKind kind = parameter.parameterKind; 7061 ParameterKind kind = parameter.parameterKind;
7067 if (identical(kind, ParameterKind.REQUIRED)) { 7062 if (identical(kind, ParameterKind.REQUIRED)) {
7068 requiredParameters.add(parameter); 7063 requiredParameters.add(parameter);
7069 } else if (identical(kind, ParameterKind.POSITIONAL)) { 7064 } else if (identical(kind, ParameterKind.POSITIONAL)) {
7070 positionalParameters.add(parameter); 7065 positionalParameters.add(parameter);
7071 } else { 7066 } else {
(...skipping 10 matching lines...) Expand all
7082 int positionalArgumentCount = 0; 7077 int positionalArgumentCount = 0;
7083 Set<String> usedNames = new Set<String>(); 7078 Set<String> usedNames = new Set<String>();
7084 for (int i = 0; i < argumentCount; i++) { 7079 for (int i = 0; i < argumentCount; i++) {
7085 Expression argument = arguments[i]; 7080 Expression argument = arguments[i];
7086 if (argument is NamedExpression) { 7081 if (argument is NamedExpression) {
7087 SimpleIdentifier nameNode = argument.name.label; 7082 SimpleIdentifier nameNode = argument.name.label;
7088 String name = nameNode.name; 7083 String name = nameNode.name;
7089 ParameterElement element = namedParameters[name]; 7084 ParameterElement element = namedParameters[name];
7090 if (element == null) { 7085 if (element == null) {
7091 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode; 7086 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode;
7092 _resolver.reportError9(errorCode, nameNode, [name]); 7087 _resolver.reportErrorForNode(errorCode, nameNode, [name]);
7093 } else { 7088 } else {
7094 resolvedParameters[i] = element; 7089 resolvedParameters[i] = element;
7095 nameNode.staticElement = element; 7090 nameNode.staticElement = element;
7096 } 7091 }
7097 if (!usedNames.add(name)) { 7092 if (!usedNames.add(name)) {
7098 _resolver.reportError9(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]); 7093 _resolver.reportErrorForNode(CompileTimeErrorCode.DUPLICATE_NAMED_ARGU MENT, nameNode, [name]);
7099 } 7094 }
7100 } else { 7095 } else {
7101 positionalArgumentCount++; 7096 positionalArgumentCount++;
7102 if (unnamedIndex < unnamedParameterCount) { 7097 if (unnamedIndex < unnamedParameterCount) {
7103 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; 7098 resolvedParameters[i] = unnamedParameters[unnamedIndex++];
7104 } 7099 }
7105 } 7100 }
7106 } 7101 }
7107 if (positionalArgumentCount < requiredParameters.length) { 7102 if (positionalArgumentCount < requiredParameters.length) {
7108 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode; 7103 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode;
7109 _resolver.reportError9(errorCode, argumentList, [requiredParameters.length , positionalArgumentCount]); 7104 _resolver.reportErrorForNode(errorCode, argumentList, [requiredParameters. length, positionalArgumentCount]);
7110 } else if (positionalArgumentCount > unnamedParameterCount) { 7105 } else if (positionalArgumentCount > unnamedParameterCount) {
7111 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL _ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode; 7106 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL _ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode;
7112 _resolver.reportError9(errorCode, argumentList, [unnamedParameterCount, po sitionalArgumentCount]); 7107 _resolver.reportErrorForNode(errorCode, argumentList, [unnamedParameterCou nt, positionalArgumentCount]);
7113 } 7108 }
7114 return resolvedParameters; 7109 return resolvedParameters;
7115 } 7110 }
7116 7111
7117 /** 7112 /**
7118 * Resolve the names in the given combinators in the scope of the given librar y. 7113 * Resolve the names in the given combinators in the scope of the given librar y.
7119 * 7114 *
7120 * @param library the library that defines the names 7115 * @param library the library that defines the names
7121 * @param combinators the combinators containing the names to be resolved 7116 * @param combinators the combinators containing the names to be resolved
7122 */ 7117 */
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7162 if (element == null && nameNode.inGetterContext()) { 7157 if (element == null && nameNode.inGetterContext()) {
7163 element = classElement.getGetter(name); 7158 element = classElement.getGetter(name);
7164 } 7159 }
7165 if (element != null && element.isAccessibleIn(_definingLibrary)) { 7160 if (element != null && element.isAccessibleIn(_definingLibrary)) {
7166 return element; 7161 return element;
7167 } 7162 }
7168 return null; 7163 return null;
7169 } 7164 }
7170 7165
7171 /** 7166 /**
7167 * Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the elemen t being invoked. If
7168 * the returned element is a method, then the method will be invoked. If the r eturned element is a
7169 * getter, the getter will be invoked without arguments and the result of that invocation will
7170 * then be invoked with the arguments.
7171 *
7172 * @param methodName the name of the method being invoked ('m')
7173 * @return the element being invoked
7174 */
7175 Element resolveInvokedElement(SimpleIdentifier methodName) {
7176 //
7177 // Look first in the lexical scope.
7178 //
7179 Element element = _resolver.nameScope.lookup(methodName, _definingLibrary);
7180 if (element == null) {
7181 //
7182 // If it isn't defined in the lexical scope, and the invocation is within a class, then look
7183 // in the inheritance scope.
7184 //
7185 ClassElement enclosingClass = _resolver.enclosingClass;
7186 if (enclosingClass != null) {
7187 InterfaceType enclosingType = enclosingClass.type;
7188 element = lookUpMethod(null, enclosingType, methodName.name);
7189 if (element == null) {
7190 //
7191 // If there's no method, then it's possible that 'm' is a getter that returns a function.
7192 //
7193 element = lookUpGetter(null, enclosingType, methodName.name);
7194 }
7195 }
7196 }
7197 // TODO(brianwilkerson) Report this error.
7198 return element;
7199 }
7200
7201 /**
7172 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el ement being invoked. 7202 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el ement being invoked.
7173 * If the returned element is a method, then the method will be invoked. If th e returned element 7203 * If the returned element is a method, then the method will be invoked. If th e returned element
7174 * is a getter, the getter will be invoked without arguments and the result of that invocation 7204 * is a getter, the getter will be invoked without arguments and the result of that invocation
7175 * will then be invoked with the arguments. 7205 * will then be invoked with the arguments.
7176 * 7206 *
7177 * @param target the target of the invocation ('e') 7207 * @param target the target of the invocation ('e')
7178 * @param targetType the type of the target 7208 * @param targetType the type of the target
7179 * @param methodName the name of the method being invoked ('m') 7209 * @param methodName the name of the method being invoked ('m')
7180 * @return the element being invoked 7210 * @return the element being invoked
7181 */ 7211 */
7182 Element resolveInvokedElement(Expression target, Type2 targetType, SimpleIdent ifier methodName) { 7212 Element resolveInvokedElementWithTarget(Expression target, Type2 targetType, S impleIdentifier methodName) {
7183 if (targetType is InterfaceType) { 7213 if (targetType is InterfaceType) {
7184 InterfaceType classType = targetType; 7214 InterfaceType classType = targetType;
7185 Element element = lookUpMethod(target, classType, methodName.name); 7215 Element element = lookUpMethod(target, classType, methodName.name);
7186 if (element == null) { 7216 if (element == null) {
7187 // 7217 //
7188 // If there's no method, then it's possible that 'm' is a getter that re turns a function. 7218 // If there's no method, then it's possible that 'm' is a getter that re turns a function.
7189 // 7219 //
7190 element = lookUpGetter(target, classType, methodName.name); 7220 element = lookUpGetter(target, classType, methodName.name);
7191 } 7221 }
7192 return element; 7222 return element;
(...skipping 12 matching lines...) Expand all
7205 // the function name is a prefixed identifier. Consider re-writing the AST. 7235 // the function name is a prefixed identifier. Consider re-writing the AST.
7206 return element; 7236 return element;
7207 } 7237 }
7208 } 7238 }
7209 } 7239 }
7210 // TODO(brianwilkerson) Report this error. 7240 // TODO(brianwilkerson) Report this error.
7211 return null; 7241 return null;
7212 } 7242 }
7213 7243
7214 /** 7244 /**
7215 * Given an invocation of the form 'm(a1, ..., an)', resolve 'm' to the elemen t being invoked. If
7216 * the returned element is a method, then the method will be invoked. If the r eturned element is a
7217 * getter, the getter will be invoked without arguments and the result of that invocation will
7218 * then be invoked with the arguments.
7219 *
7220 * @param methodName the name of the method being invoked ('m')
7221 * @return the element being invoked
7222 */
7223 Element resolveInvokedElement2(SimpleIdentifier methodName) {
7224 //
7225 // Look first in the lexical scope.
7226 //
7227 Element element = _resolver.nameScope.lookup(methodName, _definingLibrary);
7228 if (element == null) {
7229 //
7230 // If it isn't defined in the lexical scope, and the invocation is within a class, then look
7231 // in the inheritance scope.
7232 //
7233 ClassElement enclosingClass = _resolver.enclosingClass;
7234 if (enclosingClass != null) {
7235 InterfaceType enclosingType = enclosingClass.type;
7236 element = lookUpMethod(null, enclosingType, methodName.name);
7237 if (element == null) {
7238 //
7239 // If there's no method, then it's possible that 'm' is a getter that returns a function.
7240 //
7241 element = lookUpGetter(null, enclosingType, methodName.name);
7242 }
7243 }
7244 }
7245 // TODO(brianwilkerson) Report this error.
7246 return element;
7247 }
7248
7249 /**
7250 * Given that we are accessing a property of the given type with the given nam e, return the 7245 * Given that we are accessing a property of the given type with the given nam e, return the
7251 * element that represents the property. 7246 * element that represents the property.
7252 * 7247 *
7253 * @param target the target of the invocation ('e') 7248 * @param target the target of the invocation ('e')
7254 * @param targetType the type in which the search for the property should begi n 7249 * @param targetType the type in which the search for the property should begi n
7255 * @param propertyName the name of the property being accessed 7250 * @param propertyName the name of the property being accessed
7256 * @return the element that represents the property 7251 * @return the element that represents the property
7257 */ 7252 */
7258 ExecutableElement resolveProperty(Expression target, Type2 targetType, SimpleI dentifier propertyName) { 7253 ExecutableElement resolveProperty(Expression target, Type2 targetType, SimpleI dentifier propertyName) {
7259 ExecutableElement memberElement = null; 7254 ExecutableElement memberElement = null;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7302 // that the member is not in a subtype of the propagated type. 7297 // that the member is not in a subtype of the propagated type.
7303 if (shouldReportMissingMember_propagated) { 7298 if (shouldReportMissingMember_propagated) {
7304 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) { 7299 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) {
7305 shouldReportMissingMember_propagated = false; 7300 shouldReportMissingMember_propagated = false;
7306 } 7301 }
7307 } 7302 }
7308 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 7303 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
7309 if (staticType.isVoid) { 7304 if (staticType.isVoid) {
7310 if (propertyName.inSetterContext()) { 7305 if (propertyName.inSetterContext()) {
7311 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; 7306 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
7312 _resolver.reportError9(errorCode, propertyName, [propertyName.name, st aticType.displayName]); 7307 _resolver.reportErrorForNode(errorCode, propertyName, [propertyName.na me, staticType.displayName]);
7313 } else if (propertyName.inGetterContext()) { 7308 } else if (propertyName.inGetterContext()) {
7314 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode; 7309 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_GETTER : HintCode.UNDEFINED_GETTER) as ErrorCode;
7315 _resolver.reportError9(errorCode, propertyName, [propertyName.name, st aticType.displayName]); 7310 _resolver.reportErrorForNode(errorCode, propertyName, [propertyName.na me, staticType.displayName]);
7316 } else { 7311 } else {
7317 _resolver.reportError9(StaticWarningCode.UNDEFINED_IDENTIFIER, propert yName, [propertyName.name]); 7312 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_IDENTIFIER, p ropertyName, [propertyName.name]);
7318 } 7313 }
7319 } 7314 }
7320 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element; 7315 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element;
7321 if (staticOrPropagatedEnclosingElt != null) { 7316 if (staticOrPropagatedEnclosingElt != null) {
7322 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt); 7317 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt);
7323 if (propertyName.inSetterContext()) { 7318 if (propertyName.inSetterContext()) {
7324 if (isStaticProperty) { 7319 if (isStaticProperty) {
7325 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarn ingCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode; 7320 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticWarn ingCode.UNDEFINED_SETTER : HintCode.UNDEFINED_SETTER) as ErrorCode;
7326 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagate dEnclosingElt, errorCode, propertyName, [ 7321 _resolver.reportErrorProxyConditionalAnalysisError(staticOrPropagate dEnclosingElt, errorCode, propertyName, [
7327 propertyName.name, 7322 propertyName.name,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
7447 } 7442 }
7448 7443
7449 /** 7444 /**
7450 * Given a node that can have annotations associated with it and the element t o which that node 7445 * Given a node that can have annotations associated with it and the element t o which that node
7451 * has been resolved, create the annotations in the element model representing the annotations on 7446 * has been resolved, create the annotations in the element model representing the annotations on
7452 * the node. 7447 * the node.
7453 * 7448 *
7454 * @param element the element to which the node has been resolved 7449 * @param element the element to which the node has been resolved
7455 * @param node the node that can have annotations associated with it 7450 * @param node the node that can have annotations associated with it
7456 */ 7451 */
7457 void setMetadata2(Element element, NormalFormalParameter node) { 7452 void setMetadataForParameter(Element element, NormalFormalParameter node) {
7458 if (element is! ElementImpl) { 7453 if (element is! ElementImpl) {
7459 return; 7454 return;
7460 } 7455 }
7461 List<ElementAnnotationImpl> annotationList = new List<ElementAnnotationImpl> (); 7456 List<ElementAnnotationImpl> annotationList = new List<ElementAnnotationImpl> ();
7462 addAnnotations(annotationList, node.metadata); 7457 addAnnotations(annotationList, node.metadata);
7463 if (!annotationList.isEmpty) { 7458 if (!annotationList.isEmpty) {
7464 (element as ElementImpl).metadata = new List.from(annotationList); 7459 (element as ElementImpl).metadata = new List.from(annotationList);
7465 } 7460 }
7466 } 7461 }
7467 7462
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
7788 * Note: by positional we mean [ParameterKind#REQUIRED] or [ParameterKind#POSI TIONAL]. 7783 * Note: by positional we mean [ParameterKind#REQUIRED] or [ParameterKind#POSI TIONAL].
7789 */ 7784 */
7790 static int getNumOfPositionalParameters(ExecutableElement executableElement) = > getNumOfParameters(executableElement, ParameterKind.REQUIRED) + getNumOfParame ters(executableElement, ParameterKind.POSITIONAL); 7785 static int getNumOfPositionalParameters(ExecutableElement executableElement) = > getNumOfParameters(executableElement, ParameterKind.REQUIRED) + getNumOfParame ters(executableElement, ParameterKind.POSITIONAL);
7791 7786
7792 /** 7787 /**
7793 * Given some [ExecutableElement] return the number of required parameters. 7788 * Given some [ExecutableElement] return the number of required parameters.
7794 */ 7789 */
7795 static int getNumOfRequiredParameters(ExecutableElement executableElement) => getNumOfParameters(executableElement, ParameterKind.REQUIRED); 7790 static int getNumOfRequiredParameters(ExecutableElement executableElement) => getNumOfParameters(executableElement, ParameterKind.REQUIRED);
7796 7791
7797 /** 7792 /**
7793 * Given some [ExecutableElement] returns `true` if it is an abstract member o f a
7794 * class.
7795 *
7796 * @param executableElement some [ExecutableElement] to evaluate
7797 * @return `true` if the given element is an abstract member of a class
7798 */
7799 static bool isAbstract(ExecutableElement executableElement) {
7800 if (executableElement is MethodElement) {
7801 return executableElement.isAbstract;
7802 } else if (executableElement is PropertyAccessorElement) {
7803 return executableElement.isAbstract;
7804 }
7805 return false;
7806 }
7807
7808 /**
7798 * The [LibraryElement] that is managed by this manager. 7809 * The [LibraryElement] that is managed by this manager.
7799 */ 7810 */
7800 LibraryElement _library; 7811 LibraryElement _library;
7801 7812
7802 /** 7813 /**
7803 * This is a mapping between each [ClassElement] and a map between the [String ] member 7814 * This is a mapping between each [ClassElement] and a map between the [String ] member
7804 * names and the associated [ExecutableElement] in the mixin and superclass ch ain. 7815 * names and the associated [ExecutableElement] in the mixin and superclass ch ain.
7805 */ 7816 */
7806 Map<ClassElement, MemberMap> _classLookup; 7817 Map<ClassElement, MemberMap> _classLookup;
7807 7818
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
7980 InterfaceType supertype = classElt.supertype; 7991 InterfaceType supertype = classElt.supertype;
7981 if (supertype != null) { 7992 if (supertype != null) {
7982 superclassElt = supertype.element; 7993 superclassElt = supertype.element;
7983 } else { 7994 } else {
7984 // classElt is Object 7995 // classElt is Object
7985 _classLookup[classElt] = resultMap; 7996 _classLookup[classElt] = resultMap;
7986 return resultMap; 7997 return resultMap;
7987 } 7998 }
7988 if (superclassElt != null) { 7999 if (superclassElt != null) {
7989 if (!visitedClasses.contains(superclassElt)) { 8000 if (!visitedClasses.contains(superclassElt)) {
7990 visitedClasses.add(classElt); 8001 visitedClasses.add(superclassElt);
7991 resultMap = new MemberMap.con2(computeClassChainLookupMap(superclassElt, visitedClasses)); 8002 try {
8003 resultMap = new MemberMap.con2(computeClassChainLookupMap(superclassEl t, visitedClasses));
8004 //
8005 // Substitute the super types down the hierarchy.
8006 //
8007 substituteTypeParametersDownHierarchy(supertype, resultMap);
8008 //
8009 // Include the members from the superclass in the resultMap.
8010 //
8011 recordMapWithClassMembers(resultMap, supertype);
8012 } finally {
8013 visitedClasses.remove(superclassElt);
8014 }
7992 } else { 8015 } else {
7993 // This case happens only when the superclass was previously visited and not in the lookup, 8016 // This case happens only when the superclass was previously visited and not in the lookup,
7994 // meaning this is meant to shorten the compute for recursive cases. 8017 // meaning this is meant to shorten the compute for recursive cases.
7995 _classLookup[superclassElt] = resultMap; 8018 _classLookup[superclassElt] = resultMap;
7996 return resultMap; 8019 return resultMap;
7997 } 8020 }
7998 //
7999 // Substitute the supertypes down the hierarchy
8000 //
8001 substituteTypeParametersDownHierarchy(supertype, resultMap);
8002 //
8003 // Include the members from the superclass in the resultMap
8004 //
8005 recordMapWithClassMembers(resultMap, supertype);
8006 } 8021 }
8007 // 8022 //
8008 // Include the members from the mixins in the resultMap 8023 // Include the members from the mixins in the resultMap
8009 // 8024 //
8010 List<InterfaceType> mixins = classElt.mixins; 8025 List<InterfaceType> mixins = classElt.mixins;
8011 for (int i = mixins.length - 1; i >= 0; i--) { 8026 for (int i = mixins.length - 1; i >= 0; i--) {
8012 recordMapWithClassMembersFromMixin(resultMap, mixins[i]); 8027 ClassElement mixinElement = mixins[i].element;
8028 if (mixinElement != null) {
8029 if (!visitedClasses.contains(mixinElement)) {
8030 visitedClasses.add(mixinElement);
8031 try {
8032 MemberMap map = new MemberMap.con2(computeClassChainLookupMap(mixinE lement, visitedClasses));
8033 //
8034 // Substitute the super types down the hierarchy.
8035 //
8036 substituteTypeParametersDownHierarchy(mixins[i], map);
8037 //
8038 // Include the members from the superclass in the resultMap.
8039 //
8040 recordMapWithClassMembersFromMixin(map, mixins[i]);
8041 //
8042 // Add the members from map into result map.
8043 //
8044 for (int j = 0; j < map.size; j++) {
8045 String key = map.getKey(j);
8046 ExecutableElement value = map.getValue(j);
8047 if (key != null) {
8048 if (resultMap.get(key) == null || (resultMap.get(key) != null && !isAbstract(value))) {
8049 resultMap.put(key, value);
8050 }
8051 }
8052 }
8053 } finally {
8054 visitedClasses.remove(mixinElement);
8055 }
8056 } else {
8057 // This case happens only when the superclass was previously visited a nd not in the lookup,
8058 // meaning this is meant to shorten the compute for recursive cases.
8059 _classLookup[mixinElement] = resultMap;
8060 return resultMap;
8061 }
8062 }
8013 } 8063 }
8014 _classLookup[classElt] = resultMap; 8064 _classLookup[classElt] = resultMap;
8015 return resultMap; 8065 return resultMap;
8016 } 8066 }
8017 8067
8018 /** 8068 /**
8019 * Compute and return the inheritance path given the context of a type and a m ember that is 8069 * Compute and return the inheritance path given the context of a type and a m ember that is
8020 * overridden in the inheritance path (for which the type is in the path). 8070 * overridden in the inheritance path (for which the type is in the path).
8021 * 8071 *
8022 * @param chain the inheritance path that is built up as this method calls its elf recursively, 8072 * @param chain the inheritance path that is built up as this method calls its elf recursively,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
8092 return resultMap; 8142 return resultMap;
8093 } else { 8143 } else {
8094 resultMap = new MemberMap(); 8144 resultMap = new MemberMap();
8095 } 8145 }
8096 InterfaceType supertype = classElt.supertype; 8146 InterfaceType supertype = classElt.supertype;
8097 ClassElement superclassElement = supertype != null ? supertype.element : nul l; 8147 ClassElement superclassElement = supertype != null ? supertype.element : nul l;
8098 List<InterfaceType> mixins = classElt.mixins; 8148 List<InterfaceType> mixins = classElt.mixins;
8099 List<InterfaceType> interfaces = classElt.interfaces; 8149 List<InterfaceType> interfaces = classElt.interfaces;
8100 // Recursively collect the list of mappings from all of the interface types 8150 // Recursively collect the list of mappings from all of the interface types
8101 List<MemberMap> lookupMaps = new List<MemberMap>(); 8151 List<MemberMap> lookupMaps = new List<MemberMap>();
8152 //
8102 // Superclass element 8153 // Superclass element
8154 //
8103 if (superclassElement != null) { 8155 if (superclassElement != null) {
8104 if (!visitedInterfaces.contains(superclassElement)) { 8156 if (!visitedInterfaces.contains(superclassElement)) {
8105 try { 8157 try {
8106 visitedInterfaces.add(superclassElement); 8158 visitedInterfaces.add(superclassElement);
8107 // 8159 //
8108 // Recursively compute the map for the supertype. 8160 // Recursively compute the map for the super type.
8109 // 8161 //
8110 MemberMap map = computeInterfaceLookupMap(superclassElement, visitedIn terfaces); 8162 MemberMap map = computeInterfaceLookupMap(superclassElement, visitedIn terfaces);
8111 map = new MemberMap.con2(map); 8163 map = new MemberMap.con2(map);
8112 // 8164 //
8113 // Substitute the supertypes down the hierarchy 8165 // Substitute the super type down the hierarchy.
8114 // 8166 //
8115 substituteTypeParametersDownHierarchy(supertype, map); 8167 substituteTypeParametersDownHierarchy(supertype, map);
8116 // 8168 //
8117 // Add any members from the supertype into the map as well. 8169 // Add any members from the super type into the map as well.
8118 // 8170 //
8119 recordMapWithClassMembers(map, supertype); 8171 recordMapWithClassMembers(map, supertype);
8120 lookupMaps.add(map); 8172 lookupMaps.add(map);
8121 } finally { 8173 } finally {
8122 visitedInterfaces.remove(superclassElement); 8174 visitedInterfaces.remove(superclassElement);
8123 } 8175 }
8124 } else { 8176 } else {
8125 MemberMap map = _interfaceLookup[classElt]; 8177 MemberMap map = _interfaceLookup[classElt];
8126 if (map != null) { 8178 if (map != null) {
8127 lookupMaps.add(map); 8179 lookupMaps.add(map);
8128 } else { 8180 } else {
8129 _interfaceLookup[superclassElement] = resultMap; 8181 _interfaceLookup[superclassElement] = resultMap;
8130 return resultMap; 8182 return resultMap;
8131 } 8183 }
8132 } 8184 }
8133 } 8185 }
8186 //
8134 // Mixin elements 8187 // Mixin elements
8135 for (InterfaceType mixinType in mixins) { 8188 //
8136 MemberMap mapWithMixinMembers = new MemberMap(); 8189 for (int i = mixins.length - 1; i >= 0; i--) {
8137 recordMapWithClassMembers(mapWithMixinMembers, mixinType); 8190 InterfaceType mixinType = mixins[i];
8138 lookupMaps.add(mapWithMixinMembers); 8191 ClassElement mixinElement = mixinType.element;
8192 if (mixinElement != null) {
8193 if (!visitedInterfaces.contains(mixinElement)) {
8194 try {
8195 visitedInterfaces.add(mixinElement);
8196 //
8197 // Recursively compute the map for the mixin.
8198 //
8199 MemberMap map = computeInterfaceLookupMap(mixinElement, visitedInter faces);
8200 map = new MemberMap.con2(map);
8201 //
8202 // Substitute the mixin type down the hierarchy.
8203 //
8204 substituteTypeParametersDownHierarchy(mixinType, map);
8205 //
8206 // Add any members from the mixin type into the map as well.
8207 //
8208 recordMapWithClassMembers(map, mixinType);
8209 lookupMaps.add(map);
8210 } finally {
8211 visitedInterfaces.remove(mixinElement);
8212 }
8213 } else {
8214 MemberMap map = _interfaceLookup[classElt];
8215 if (map != null) {
8216 lookupMaps.add(map);
8217 } else {
8218 _interfaceLookup[mixinElement] = resultMap;
8219 return resultMap;
8220 }
8221 }
8222 }
8139 } 8223 }
8224 //
8140 // Interface elements 8225 // Interface elements
8226 //
8141 for (InterfaceType interfaceType in interfaces) { 8227 for (InterfaceType interfaceType in interfaces) {
8142 ClassElement interfaceElement = interfaceType.element; 8228 ClassElement interfaceElement = interfaceType.element;
8143 if (interfaceElement != null) { 8229 if (interfaceElement != null) {
8144 if (!visitedInterfaces.contains(interfaceElement)) { 8230 if (!visitedInterfaces.contains(interfaceElement)) {
8145 try { 8231 try {
8146 visitedInterfaces.add(interfaceElement); 8232 visitedInterfaces.add(interfaceElement);
8147 // 8233 //
8148 // Recursively compute the map for the interfaces. 8234 // Recursively compute the map for the interfaces.
8149 // 8235 //
8150 MemberMap map = computeInterfaceLookupMap(interfaceElement, visitedI nterfaces); 8236 MemberMap map = computeInterfaceLookupMap(interfaceElement, visitedI nterfaces);
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
9043 * @throws AnalysisException if the library could not be resolved for some rea son 9129 * @throws AnalysisException if the library could not be resolved for some rea son
9044 */ 9130 */
9045 LibraryElement resolveEmbeddedLibrary(Source librarySource, int modificationSt amp, CompilationUnit unit, bool fullAnalysis) { 9131 LibraryElement resolveEmbeddedLibrary(Source librarySource, int modificationSt amp, CompilationUnit unit, bool fullAnalysis) {
9046 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveEmbeddedLibrary"); 9132 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveEmbeddedLibrary");
9047 try { 9133 try {
9048 instrumentation.metric("fullAnalysis", fullAnalysis); 9134 instrumentation.metric("fullAnalysis", fullAnalysis);
9049 instrumentation.data3("fullName", librarySource.fullName); 9135 instrumentation.data3("fullName", librarySource.fullName);
9050 // 9136 //
9051 // Create the objects representing the library being resolved and the core library. 9137 // Create the objects representing the library being resolved and the core library.
9052 // 9138 //
9053 Library targetLibrary = createLibrary2(librarySource, modificationStamp, u nit); 9139 Library targetLibrary = createLibraryWithUnit(librarySource, modificationS tamp, unit);
9054 _coreLibrary = _libraryMap[_coreLibrarySource]; 9140 _coreLibrary = _libraryMap[_coreLibrarySource];
9055 if (_coreLibrary == null) { 9141 if (_coreLibrary == null) {
9056 // This will be true unless the library being analyzed is the core libra ry. 9142 // This will be true unless the library being analyzed is the core libra ry.
9057 _coreLibrary = createLibrary(_coreLibrarySource); 9143 _coreLibrary = createLibrary(_coreLibrarySource);
9058 } 9144 }
9059 instrumentation.metric3("createLibrary", "complete"); 9145 instrumentation.metric3("createLibrary", "complete");
9060 // 9146 //
9061 // Compute the set of libraries that need to be resolved together. 9147 // Compute the set of libraries that need to be resolved together.
9062 // 9148 //
9063 computeLibraryDependencies2(targetLibrary, unit); 9149 computeEmbeddedLibraryDependencies(targetLibrary, unit);
9064 _librariesInCycles = computeLibrariesInCycles(targetLibrary); 9150 _librariesInCycles = computeLibrariesInCycles(targetLibrary);
9065 // 9151 //
9066 // Build the element models representing the libraries being resolved. Thi s is done in three 9152 // Build the element models representing the libraries being resolved. Thi s is done in three
9067 // steps: 9153 // steps:
9068 // 9154 //
9069 // 1. Build the basic element models without making any connections betwee n elements other than 9155 // 1. Build the basic element models without making any connections betwee n elements other than
9070 // the basic parent/child relationships. This includes building the ele ments representing the 9156 // the basic parent/child relationships. This includes building the ele ments representing the
9071 // libraries. 9157 // libraries.
9072 // 2. Build the elements for the import and export directives. This requir es that we have the 9158 // 2. Build the elements for the import and export directives. This requir es that we have the
9073 // elements built for the referenced libraries, but because of the poss ibility of circular 9159 // elements built for the referenced libraries, but because of the poss ibility of circular
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
9418 * 9504 *
9419 * @param library the library currently being added to the dependency map 9505 * @param library the library currently being added to the dependency map
9420 */ 9506 */
9421 Map<Library, List<Library>> computeDependencyMap(Library library) { 9507 Map<Library, List<Library>> computeDependencyMap(Library library) {
9422 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>( ); 9508 Map<Library, List<Library>> dependencyMap = new Map<Library, List<Library>>( );
9423 addToDependencyMap(library, dependencyMap, new Set<Library>()); 9509 addToDependencyMap(library, dependencyMap, new Set<Library>());
9424 return dependencyMap; 9510 return dependencyMap;
9425 } 9511 }
9426 9512
9427 /** 9513 /**
9514 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
9515 * class [Library] to represent them, and record the references in the library objects.
9516 *
9517 * @param library the library to be processed to find libraries that have not yet been traversed
9518 * @throws AnalysisException if some portion of the library graph could not be traversed
9519 */
9520 void computeEmbeddedLibraryDependencies(Library library, CompilationUnit unit) {
9521 Source librarySource = library.librarySource;
9522 Set<Source> exportedSources = new Set<Source>();
9523 Set<Source> importedSources = new Set<Source>();
9524 for (Directive directive in unit.directives) {
9525 if (directive is ExportDirective) {
9526 Source exportSource = resolveSource(librarySource, directive);
9527 if (exportSource != null) {
9528 exportedSources.add(exportSource);
9529 }
9530 } else if (directive is ImportDirective) {
9531 Source importSource = resolveSource(librarySource, directive);
9532 if (importSource != null) {
9533 importedSources.add(importSource);
9534 }
9535 }
9536 }
9537 computeLibraryDependenciesFromDirectives(library, new List.from(importedSour ces), new List.from(exportedSources));
9538 }
9539
9540 /**
9428 * Return a collection containing all of the libraries reachable from the give n library that are 9541 * Return a collection containing all of the libraries reachable from the give n library that are
9429 * contained in a cycle that includes the given library. 9542 * contained in a cycle that includes the given library.
9430 * 9543 *
9431 * @param library the library that must be included in any cycles whose member s are to be returned 9544 * @param library the library that must be included in any cycles whose member s are to be returned
9432 * @return all of the libraries referenced by the given library that have a ci rcular reference 9545 * @return all of the libraries referenced by the given library that have a ci rcular reference
9433 * back to the given library 9546 * back to the given library
9434 */ 9547 */
9435 Set<Library> computeLibrariesInCycles(Library library) { 9548 Set<Library> computeLibrariesInCycles(Library library) {
9436 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); 9549 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library);
9437 Set<Library> librariesInCycle = new Set<Library>(); 9550 Set<Library> librariesInCycle = new Set<Library>();
9438 addLibrariesInCycle(library, librariesInCycle, dependencyMap); 9551 addLibrariesInCycle(library, librariesInCycle, dependencyMap);
9439 return librariesInCycle; 9552 return librariesInCycle;
9440 } 9553 }
9441 9554
9442 /** 9555 /**
9443 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 9556 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
9444 * class [Library] to represent them, and record the references in the library objects. 9557 * class [Library] to represent them, and record the references in the library objects.
9445 * 9558 *
9446 * @param library the library to be processed to find libraries that have not yet been traversed 9559 * @param library the library to be processed to find libraries that have not yet been traversed
9447 * @throws AnalysisException if some portion of the library graph could not be traversed 9560 * @throws AnalysisException if some portion of the library graph could not be traversed
9448 */ 9561 */
9449 void computeLibraryDependencies(Library library) { 9562 void computeLibraryDependencies(Library library) {
9450 Source librarySource = library.librarySource; 9563 Source librarySource = library.librarySource;
9451 computeLibraryDependencies3(library, analysisContext.computeImportedLibrarie s(librarySource), analysisContext.computeExportedLibraries(librarySource)); 9564 computeLibraryDependenciesFromDirectives(library, analysisContext.computeImp ortedLibraries(librarySource), analysisContext.computeExportedLibraries(libraryS ource));
9452 } 9565 }
9453 9566
9454 /** 9567 /**
9455 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
9456 * class [Library] to represent them, and record the references in the library objects.
9457 *
9458 * @param library the library to be processed to find libraries that have not yet been traversed
9459 * @throws AnalysisException if some portion of the library graph could not be traversed
9460 */
9461 void computeLibraryDependencies2(Library library, CompilationUnit unit) {
9462 Source librarySource = library.librarySource;
9463 Set<Source> exportedSources = new Set<Source>();
9464 Set<Source> importedSources = new Set<Source>();
9465 for (Directive directive in unit.directives) {
9466 if (directive is ExportDirective) {
9467 Source exportSource = resolveSource(librarySource, directive);
9468 if (exportSource != null) {
9469 exportedSources.add(exportSource);
9470 }
9471 } else if (directive is ImportDirective) {
9472 Source importSource = resolveSource(librarySource, directive);
9473 if (importSource != null) {
9474 importedSources.add(importSource);
9475 }
9476 }
9477 }
9478 computeLibraryDependencies3(library, new List.from(importedSources), new Lis t.from(exportedSources));
9479 }
9480
9481 /**
9482 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 9568 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
9483 * class [Library] to represent them, and record the references in the library objects. 9569 * class [Library] to represent them, and record the references in the library objects.
9484 * 9570 *
9485 * @param library the library to be processed to find libraries that have not yet been traversed 9571 * @param library the library to be processed to find libraries that have not yet been traversed
9486 * @param importedSources an array containing the sources that are imported in to the given library 9572 * @param importedSources an array containing the sources that are imported in to the given library
9487 * @param exportedSources an array containing the sources that are exported fr om the given library 9573 * @param exportedSources an array containing the sources that are exported fr om the given library
9488 * @throws AnalysisException if some portion of the library graph could not be traversed 9574 * @throws AnalysisException if some portion of the library graph could not be traversed
9489 */ 9575 */
9490 void computeLibraryDependencies3(Library library, List<Source> importedSources , List<Source> exportedSources) { 9576 void computeLibraryDependenciesFromDirectives(Library library, List<Source> im portedSources, List<Source> exportedSources) {
9491 List<Library> importedLibraries = new List<Library>(); 9577 List<Library> importedLibraries = new List<Library>();
9492 bool explicitlyImportsCore = false; 9578 bool explicitlyImportsCore = false;
9493 for (Source importedSource in importedSources) { 9579 for (Source importedSource in importedSources) {
9494 if (importedSource == _coreLibrarySource) { 9580 if (importedSource == _coreLibrarySource) {
9495 explicitlyImportsCore = true; 9581 explicitlyImportsCore = true;
9496 } 9582 }
9497 Library importedLibrary = _libraryMap[importedSource]; 9583 Library importedLibrary = _libraryMap[importedSource];
9498 if (importedLibrary == null) { 9584 if (importedLibrary == null) {
9499 importedLibrary = createLibraryOrNull(importedSource); 9585 importedLibrary = createLibraryOrNull(importedSource);
9500 if (importedLibrary != null) { 9586 if (importedLibrary != null) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
9541 * @throws AnalysisException if the library source is not valid 9627 * @throws AnalysisException if the library source is not valid
9542 */ 9628 */
9543 Library createLibrary(Source librarySource) { 9629 Library createLibrary(Source librarySource) {
9544 Library library = new Library(analysisContext, _errorListener, librarySource ); 9630 Library library = new Library(analysisContext, _errorListener, librarySource );
9545 _libraryMap[librarySource] = library; 9631 _libraryMap[librarySource] = library;
9546 return library; 9632 return library;
9547 } 9633 }
9548 9634
9549 /** 9635 /**
9550 * Create an object to represent the information about the library defined by the compilation unit 9636 * Create an object to represent the information about the library defined by the compilation unit
9551 * with the given source.
9552 *
9553 * @param librarySource the source of the library's defining compilation unit
9554 * @param modificationStamp the modification time of the source from which the compilation unit
9555 * was created
9556 * @param unit the compilation unit that defines the library
9557 * @return the library object that was created
9558 * @throws AnalysisException if the library source is not valid
9559 */
9560 Library createLibrary2(Source librarySource, int modificationStamp, Compilatio nUnit unit) {
9561 Library library = new Library(analysisContext, _errorListener, librarySource );
9562 library.setDefiningCompilationUnit(modificationStamp, unit);
9563 _libraryMap[librarySource] = library;
9564 return library;
9565 }
9566
9567 /**
9568 * Create an object to represent the information about the library defined by the compilation unit
9569 * with the given source. Return the library object that was created, or `null ` if the 9637 * with the given source. Return the library object that was created, or `null ` if the
9570 * source is not valid. 9638 * source is not valid.
9571 * 9639 *
9572 * @param librarySource the source of the library's defining compilation unit 9640 * @param librarySource the source of the library's defining compilation unit
9573 * @return the library object that was created 9641 * @return the library object that was created
9574 */ 9642 */
9575 Library createLibraryOrNull(Source librarySource) { 9643 Library createLibraryOrNull(Source librarySource) {
9576 if (!analysisContext.exists(librarySource)) { 9644 if (!analysisContext.exists(librarySource)) {
9577 return null; 9645 return null;
9578 } 9646 }
9579 Library library = new Library(analysisContext, _errorListener, librarySource ); 9647 Library library = new Library(analysisContext, _errorListener, librarySource );
9580 _libraryMap[librarySource] = library; 9648 _libraryMap[librarySource] = library;
9581 return library; 9649 return library;
9582 } 9650 }
9651
9652 /**
9653 * Create an object to represent the information about the library defined by the compilation unit
9654 * with the given source.
9655 *
9656 * @param librarySource the source of the library's defining compilation unit
9657 * @param modificationStamp the modification time of the source from which the compilation unit
9658 * was created
9659 * @param unit the compilation unit that defines the library
9660 * @return the library object that was created
9661 * @throws AnalysisException if the library source is not valid
9662 */
9663 Library createLibraryWithUnit(Source librarySource, int modificationStamp, Com pilationUnit unit) {
9664 Library library = new Library(analysisContext, _errorListener, librarySource );
9665 library.setDefiningCompilationUnit(modificationStamp, unit);
9666 _libraryMap[librarySource] = library;
9667 return library;
9668 }
9583 9669
9584 /** 9670 /**
9585 * Return an array containing the lexical identifiers associated with the node s in the given list. 9671 * Return an array containing the lexical identifiers associated with the node s in the given list.
9586 * 9672 *
9587 * @param names the AST nodes representing the identifiers 9673 * @param names the AST nodes representing the identifiers
9588 * @return the lexical identifiers associated with the nodes in the list 9674 * @return the lexical identifiers associated with the nodes in the list
9589 */ 9675 */
9590 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { 9676 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) {
9591 int count = names.length; 9677 int count = names.length;
9592 List<String> identifiers = new List<String>(count); 9678 List<String> identifiers = new List<String>(count);
(...skipping 29 matching lines...) Expand all
9622 } 9708 }
9623 9709
9624 /** 9710 /**
9625 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle. 9711 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
9626 * 9712 *
9627 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the 9713 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the
9628 * libraries could not have their types analyzed 9714 * libraries could not have their types analyzed
9629 */ 9715 */
9630 void resolveReferencesAndTypes() { 9716 void resolveReferencesAndTypes() {
9631 for (Library library in _librariesInCycles) { 9717 for (Library library in _librariesInCycles) {
9632 resolveReferencesAndTypes2(library); 9718 resolveReferencesAndTypesInLibrary(library);
9633 } 9719 }
9634 } 9720 }
9635 9721
9636 /** 9722 /**
9637 * Resolve the identifiers and perform type analysis in the given library. 9723 * Resolve the identifiers and perform type analysis in the given library.
9638 * 9724 *
9639 * @param library the library to be resolved 9725 * @param library the library to be resolved
9640 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 9726 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
9641 * the library cannot be analyzed 9727 * the library cannot be analyzed
9642 */ 9728 */
9643 void resolveReferencesAndTypes2(Library library) { 9729 void resolveReferencesAndTypesInLibrary(Library library) {
9644 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art(); 9730 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
9645 try { 9731 try {
9646 for (Source source in library.compilationUnitSources) { 9732 for (Source source in library.compilationUnitSources) {
9647 CompilationUnit ast = library.getAST(source); 9733 CompilationUnit ast = library.getAST(source);
9648 ast.accept(new VariableResolverVisitor.con1(library, source, _typeProvid er)); 9734 ast.accept(new VariableResolverVisitor.con1(library, source, _typeProvid er));
9649 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typ eProvider); 9735 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typ eProvider);
9650 ast.accept(visitor); 9736 ast.accept(visitor);
9651 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) { 9737 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) {
9652 if (conditionalCode.shouldIncludeErrorCode()) { 9738 if (conditionalCode.shouldIncludeErrorCode()) {
9653 visitor.reportError(conditionalCode.analysisError); 9739 visitor.reportError(conditionalCode.analysisError);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
9812 _keys = keys_new_array; 9898 _keys = keys_new_array;
9813 _values = values_new_array; 9899 _values = values_new_array;
9814 } 9900 }
9815 // Put new value at end of array 9901 // Put new value at end of array
9816 _keys[_size] = key; 9902 _keys[_size] = key;
9817 _values[_size] = value; 9903 _values[_size] = value;
9818 _size++; 9904 _size++;
9819 } 9905 }
9820 9906
9821 /** 9907 /**
9822 * Given some String key, this method replaces the associated key and value pa ir with `null` 9908 * Given some [String] key, this method replaces the associated key and value pair with
9823 * . The size is not decremented with this call, instead it is expected that t he users check for 9909 * `null`. The size is not decremented with this call, instead it is expected that the users
9824 * `null`. 9910 * check for `null`.
9825 * 9911 *
9826 * @param key the key of the key/value pair to remove from the map 9912 * @param key the key of the key/value pair to remove from the map
9827 */ 9913 */
9828 void remove(String key) { 9914 void remove(String key) {
9829 for (int i = 0; i < _size; i++) { 9915 for (int i = 0; i < _size; i++) {
9830 if (_keys[i] == key) { 9916 if (_keys[i] == key) {
9831 _keys[i] = null; 9917 _keys[i] = null;
9832 _values[i] = null; 9918 _values[i] = null;
9833 return; 9919 return;
9834 } 9920 }
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after
11560 */ 11646 */
11561 Scope get nameScope => _nameScope; 11647 Scope get nameScope => _nameScope;
11562 11648
11563 /** 11649 /**
11564 * Report an error with the given error code and arguments. 11650 * Report an error with the given error code and arguments.
11565 * 11651 *
11566 * @param errorCode the error code of the error to be reported 11652 * @param errorCode the error code of the error to be reported
11567 * @param node the node specifying the location of the error 11653 * @param node the node specifying the location of the error
11568 * @param arguments the arguments to the error, used to compose the error mess age 11654 * @param arguments the arguments to the error, used to compose the error mess age
11569 */ 11655 */
11570 void reportError9(ErrorCode errorCode, AstNode node, List<Object> arguments) { 11656 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts) {
11571 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng th, errorCode, arguments)); 11657 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng th, errorCode, arguments));
11572 } 11658 }
11573 11659
11574 /** 11660 /**
11575 * Report an error with the given error code and arguments. 11661 * Report an error with the given error code and arguments.
11576 * 11662 *
11577 * @param errorCode the error code of the error to be reported 11663 * @param errorCode the error code of the error to be reported
11578 * @param offset the offset of the location of the error 11664 * @param offset the offset of the location of the error
11579 * @param length the length of the location of the error 11665 * @param length the length of the location of the error
11580 * @param arguments the arguments to the error, used to compose the error mess age 11666 * @param arguments the arguments to the error, used to compose the error mess age
11581 */ 11667 */
11582 void reportError10(ErrorCode errorCode, int offset, int length, List<Object> a rguments) { 11668 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) {
11583 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC ode, arguments)); 11669 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC ode, arguments));
11584 } 11670 }
11585 11671
11586 /** 11672 /**
11587 * Report an error with the given error code and arguments. 11673 * Report an error with the given error code and arguments.
11588 * 11674 *
11589 * @param errorCode the error code of the error to be reported 11675 * @param errorCode the error code of the error to be reported
11590 * @param token the token specifying the location of the error 11676 * @param token the token specifying the location of the error
11591 * @param arguments the arguments to the error, used to compose the error mess age 11677 * @param arguments the arguments to the error, used to compose the error mess age
11592 */ 11678 */
11593 void reportError11(ErrorCode errorCode, sc.Token token, List<Object> arguments ) { 11679 void reportErrorForToken(ErrorCode errorCode, sc.Token token, List<Object> arg uments) {
11594 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le ngth, errorCode, arguments)); 11680 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le ngth, errorCode, arguments));
11595 } 11681 }
11596 11682
11597 /** 11683 /**
11598 * Visit the given AST node if it is not null. 11684 * Visit the given AST node if it is not null.
11599 * 11685 *
11600 * @param node the node to be visited 11686 * @param node the node to be visited
11601 */ 11687 */
11602 void safelyVisit(AstNode node) { 11688 void safelyVisit(AstNode node) {
11603 if (node != null) { 11689 if (node != null) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
11868 11954
11869 /** 11955 /**
11870 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ... 11956 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ...
11871 * 11957 *
11872 * It is a static warning if <i>T</i> does not denote a type available in the current lexical 11958 * It is a static warning if <i>T</i> does not denote a type available in the current lexical
11873 * scope. 11959 * scope.
11874 * 11960 *
11875 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote > 11961 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote >
11876 */ 11962 */
11877 Object visitAsExpression(AsExpression node) { 11963 Object visitAsExpression(AsExpression node) {
11878 recordStaticType(node, getType2(node.type)); 11964 recordStaticType(node, getType(node.type));
11879 return null; 11965 return null;
11880 } 11966 }
11881 11967
11882 /** 11968 /**
11883 * The Dart Language Specification, 12.18: <blockquote>... an assignment <i>a< /i> of the form <i>v 11969 * The Dart Language Specification, 12.18: <blockquote>... an assignment <i>a< /i> of the form <i>v
11884 * = e</i> ... 11970 * = e</i> ...
11885 * 11971 *
11886 * It is a static type warning if the static type of <i>e</i> may not be assig ned to the static 11972 * It is a static type warning if the static type of <i>e</i> may not be assig ned to the static
11887 * type of <i>v</i>. 11973 * type of <i>v</i>.
11888 * 11974 *
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
11921 Object visitAssignmentExpression(AssignmentExpression node) { 12007 Object visitAssignmentExpression(AssignmentExpression node) {
11922 sc.TokenType operator = node.operator.type; 12008 sc.TokenType operator = node.operator.type;
11923 if (identical(operator, sc.TokenType.EQ)) { 12009 if (identical(operator, sc.TokenType.EQ)) {
11924 Expression rightHandSide = node.rightHandSide; 12010 Expression rightHandSide = node.rightHandSide;
11925 Type2 staticType = getStaticType(rightHandSide); 12011 Type2 staticType = getStaticType(rightHandSide);
11926 recordStaticType(node, staticType); 12012 recordStaticType(node, staticType);
11927 Type2 overrideType = staticType; 12013 Type2 overrideType = staticType;
11928 Type2 propagatedType = rightHandSide.propagatedType; 12014 Type2 propagatedType = rightHandSide.propagatedType;
11929 if (propagatedType != null) { 12015 if (propagatedType != null) {
11930 if (propagatedType.isMoreSpecificThan(staticType)) { 12016 if (propagatedType.isMoreSpecificThan(staticType)) {
11931 recordPropagatedType2(node, propagatedType); 12017 recordPropagatedType(node, propagatedType);
11932 } 12018 }
11933 overrideType = propagatedType; 12019 overrideType = propagatedType;
11934 } 12020 }
11935 _resolver.override(node.leftHandSide, overrideType); 12021 _resolver.override(node.leftHandSide, overrideType);
11936 } else { 12022 } else {
11937 ExecutableElement staticMethodElement = node.staticElement; 12023 ExecutableElement staticMethodElement = node.staticElement;
11938 Type2 staticType = computeStaticReturnType(staticMethodElement); 12024 Type2 staticType = computeStaticReturnType(staticMethodElement);
11939 recordStaticType(node, staticType); 12025 recordStaticType(node, staticType);
11940 MethodElement propagatedMethodElement = node.propagatedElement; 12026 MethodElement propagatedMethodElement = node.propagatedElement;
11941 if (propagatedMethodElement != staticMethodElement) { 12027 if (propagatedMethodElement != staticMethodElement) {
11942 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); 12028 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement);
11943 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 12029 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
11944 recordPropagatedType2(node, propagatedType); 12030 recordPropagatedType(node, propagatedType);
11945 } 12031 }
11946 } 12032 }
11947 } 12033 }
11948 return null; 12034 return null;
11949 } 12035 }
11950 12036
11951 /** 12037 /**
11952 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean 12038 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean
11953 * expression is `bool`.</blockquote> 12039 * expression is `bool`.</blockquote>
11954 * 12040 *
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
11987 */ 12073 */
11988 Object visitBinaryExpression(BinaryExpression node) { 12074 Object visitBinaryExpression(BinaryExpression node) {
11989 ExecutableElement staticMethodElement = node.staticElement; 12075 ExecutableElement staticMethodElement = node.staticElement;
11990 Type2 staticType = computeStaticReturnType(staticMethodElement); 12076 Type2 staticType = computeStaticReturnType(staticMethodElement);
11991 staticType = refineBinaryExpressionType(node, staticType); 12077 staticType = refineBinaryExpressionType(node, staticType);
11992 recordStaticType(node, staticType); 12078 recordStaticType(node, staticType);
11993 MethodElement propagatedMethodElement = node.propagatedElement; 12079 MethodElement propagatedMethodElement = node.propagatedElement;
11994 if (propagatedMethodElement != staticMethodElement) { 12080 if (propagatedMethodElement != staticMethodElement) {
11995 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); 12081 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement);
11996 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) { 12082 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) {
11997 recordPropagatedType2(node, propagatedType); 12083 recordPropagatedType(node, propagatedType);
11998 } 12084 }
11999 } 12085 }
12000 return null; 12086 return null;
12001 } 12087 }
12002 12088
12003 /** 12089 /**
12004 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is 12090 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is
12005 * bool.</blockquote> 12091 * bool.</blockquote>
12006 */ 12092 */
12007 Object visitBooleanLiteral(BooleanLiteral node) { 12093 Object visitBooleanLiteral(BooleanLiteral node) {
12008 recordStaticType(node, _typeProvider.boolType); 12094 recordStaticType(node, _typeProvider.boolType);
12009 return null; 12095 return null;
12010 } 12096 }
12011 12097
12012 /** 12098 /**
12013 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv ocation expression 12099 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv ocation expression
12014 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff ix; return 12100 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff ix; return
12015 * t;}(e)</i>.</blockquote> 12101 * t;}(e)</i>.</blockquote>
12016 */ 12102 */
12017 Object visitCascadeExpression(CascadeExpression node) { 12103 Object visitCascadeExpression(CascadeExpression node) {
12018 recordStaticType(node, getStaticType(node.target)); 12104 recordStaticType(node, getStaticType(node.target));
12019 recordPropagatedType2(node, node.target.propagatedType); 12105 recordPropagatedType(node, node.target.propagatedType);
12020 return null; 12106 return null;
12021 } 12107 }
12022 12108
12023 /** 12109 /**
12024 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr ession <i>c</i> of 12110 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr ession <i>c</i> of
12025 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... 12111 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ...
12026 * 12112 *
12027 * It is a static type warning if the type of e<sub>1</sub> may not be assigne d to `bool`. 12113 * It is a static type warning if the type of e<sub>1</sub> may not be assigne d to `bool`.
12028 * 12114 *
12029 * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i> 12115 * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i>
(...skipping 19 matching lines...) Expand all
12049 Type2 propagatedElseType = node.elseExpression.propagatedType; 12135 Type2 propagatedElseType = node.elseExpression.propagatedType;
12050 if (propagatedThenType != null || propagatedElseType != null) { 12136 if (propagatedThenType != null || propagatedElseType != null) {
12051 if (propagatedThenType == null) { 12137 if (propagatedThenType == null) {
12052 propagatedThenType = staticThenType; 12138 propagatedThenType = staticThenType;
12053 } 12139 }
12054 if (propagatedElseType == null) { 12140 if (propagatedElseType == null) {
12055 propagatedElseType = staticElseType; 12141 propagatedElseType = staticElseType;
12056 } 12142 }
12057 Type2 propagatedType = propagatedThenType.getLeastUpperBound(propagatedEls eType); 12143 Type2 propagatedType = propagatedThenType.getLeastUpperBound(propagatedEls eType);
12058 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) { 12144 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) {
12059 recordPropagatedType2(node, propagatedType); 12145 recordPropagatedType(node, propagatedType);
12060 } 12146 }
12061 } 12147 }
12062 return null; 12148 return null;
12063 } 12149 }
12064 12150
12065 /** 12151 /**
12066 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is 12152 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is
12067 * double.</blockquote> 12153 * double.</blockquote>
12068 */ 12154 */
12069 Object visitDoubleLiteral(DoubleLiteral node) { 12155 Object visitDoubleLiteral(DoubleLiteral node) {
12070 recordStaticType(node, _typeProvider.doubleType); 12156 recordStaticType(node, _typeProvider.doubleType);
12071 return null; 12157 return null;
12072 } 12158 }
12073 12159
12074 Object visitFunctionDeclaration(FunctionDeclaration node) { 12160 Object visitFunctionDeclaration(FunctionDeclaration node) {
12075 FunctionExpression function = node.functionExpression; 12161 FunctionExpression function = node.functionExpression;
12076 ExecutableElementImpl functionElement = node.element as ExecutableElementImp l; 12162 ExecutableElementImpl functionElement = node.element as ExecutableElementImp l;
12077 functionElement.returnType = computeStaticReturnType2(node); 12163 functionElement.returnType = computeStaticReturnTypeOfFunctionDeclaration(no de);
12078 recordPropagatedType(functionElement, function.body); 12164 recordPropagatedTypeOfFunction(functionElement, function.body);
12079 recordStaticType(function, functionElement.type); 12165 recordStaticType(function, functionElement.type);
12080 return null; 12166 return null;
12081 } 12167 }
12082 12168
12083 /** 12169 /**
12084 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun ction literal of the 12170 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun ction literal of the
12085 * form <i>(T<sub>1</sub> a<sub>1</sub>, &hellip;, T<sub>n</sub> a<sub>n</sub> , [T<sub>n+1</sub> 12171 * form <i>(T<sub>1</sub> a<sub>1</sub>, &hellip;, T<sub>n</sub> a<sub>n</sub> , [T<sub>n+1</sub>
12086 * x<sub>n+1</sub> = d1, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub> = dk]) => e </i> is 12172 * x<sub>n+1</sub> = d1, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub> = dk]) => e </i> is
12087 * <i>(T<sub>1</sub>, &hellip;, Tn, [T<sub>n+1</sub> x<sub>n+1</sub>, &hellip; , T<sub>n+k</sub> 12173 * <i>(T<sub>1</sub>, &hellip;, Tn, [T<sub>n+1</sub> x<sub>n+1</sub>, &hellip; , T<sub>n+k</sub>
12088 * x<sub>n+k</sub>]) &rarr; T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is t he static type of 12174 * x<sub>n+k</sub>]) &rarr; T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is t he static type of
(...skipping 20 matching lines...) Expand all
12109 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; dynamic </i>. In any case 12195 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; dynamic </i>. In any case
12110 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been 12196 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been
12111 * specified as dynamic.</blockquote> 12197 * specified as dynamic.</blockquote>
12112 */ 12198 */
12113 Object visitFunctionExpression(FunctionExpression node) { 12199 Object visitFunctionExpression(FunctionExpression node) {
12114 if (node.parent is FunctionDeclaration) { 12200 if (node.parent is FunctionDeclaration) {
12115 // The function type will be resolved and set when we visit the parent nod e. 12201 // The function type will be resolved and set when we visit the parent nod e.
12116 return null; 12202 return null;
12117 } 12203 }
12118 ExecutableElementImpl functionElement = node.element as ExecutableElementImp l; 12204 ExecutableElementImpl functionElement = node.element as ExecutableElementImp l;
12119 functionElement.returnType = computeStaticReturnType3(node); 12205 functionElement.returnType = computeStaticReturnTypeOfFunctionExpression(nod e);
12120 recordPropagatedType(functionElement, node.body); 12206 recordPropagatedTypeOfFunction(functionElement, node.body);
12121 recordStaticType(node, node.element.type); 12207 recordStaticType(node, node.element.type);
12122 return null; 12208 return null;
12123 } 12209 }
12124 12210
12125 /** 12211 /**
12126 * The Dart Language Specification, 12.14.4: <blockquote>A function expression invocation <i>i</i> 12212 * The Dart Language Specification, 12.14.4: <blockquote>A function expression invocation <i>i</i>
12127 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub >n+1</sub>: 12213 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub >n+1</sub>:
12128 * a<sub>n+1</sub>, &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i> e<sub>f</sub></i> is 12214 * a<sub>n+1</sub>, &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i> e<sub>f</sub></i> is
12129 * an expression. 12215 * an expression.
12130 * 12216 *
12131 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be 12217 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be
12132 * assigned to a function type. 12218 * assigned to a function type.
12133 * 12219 *
12134 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the 12220 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the
12135 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e> 12221 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e>
12136 */ 12222 */
12137 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 12223 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
12138 ExecutableElement staticMethodElement = node.staticElement; 12224 ExecutableElement staticMethodElement = node.staticElement;
12139 // Record static return type of the static element. 12225 // Record static return type of the static element.
12140 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); 12226 Type2 staticStaticType = computeStaticReturnType(staticMethodElement);
12141 recordStaticType(node, staticStaticType); 12227 recordStaticType(node, staticStaticType);
12142 // Record propagated return type of the static element. 12228 // Record propagated return type of the static element.
12143 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement ); 12229 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement );
12144 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) { 12230 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) {
12145 recordPropagatedType2(node, staticPropagatedType); 12231 recordPropagatedType(node, staticPropagatedType);
12146 } 12232 }
12147 ExecutableElement propagatedMethodElement = node.propagatedElement; 12233 ExecutableElement propagatedMethodElement = node.propagatedElement;
12148 if (propagatedMethodElement != staticMethodElement) { 12234 if (propagatedMethodElement != staticMethodElement) {
12149 // Record static return type of the propagated element. 12235 // Record static return type of the propagated element.
12150 Type2 propagatedStaticType = computeStaticReturnType(propagatedMethodEleme nt); 12236 Type2 propagatedStaticType = computeStaticReturnType(propagatedMethodEleme nt);
12151 if (propagatedStaticType != null && (staticStaticType == null || propagate dStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == nu ll || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) { 12237 if (propagatedStaticType != null && (staticStaticType == null || propagate dStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == nu ll || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) {
12152 recordPropagatedType2(node, propagatedStaticType); 12238 recordPropagatedType(node, propagatedStaticType);
12153 } 12239 }
12154 // Record propagated return type of the propagated element. 12240 // Record propagated return type of the propagated element.
12155 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedMet hodElement); 12241 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedMet hodElement);
12156 if (propagatedPropagatedType != null && (staticStaticType == null || propa gatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedTy pe == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType)) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan (propagatedStaticType))) { 12242 if (propagatedPropagatedType != null && (staticStaticType == null || propa gatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedTy pe == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType)) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificThan (propagatedStaticType))) {
12157 recordPropagatedType2(node, propagatedPropagatedType); 12243 recordPropagatedType(node, propagatedPropagatedType);
12158 } 12244 }
12159 } 12245 }
12160 return null; 12246 return null;
12161 } 12247 }
12162 12248
12163 /** 12249 /**
12164 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form 12250 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form
12165 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method 12251 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method
12166 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote> 12252 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote>
12167 */ 12253 */
12168 Object visitIndexExpression(IndexExpression node) { 12254 Object visitIndexExpression(IndexExpression node) {
12169 if (node.inSetterContext()) { 12255 if (node.inSetterContext()) {
12170 ExecutableElement staticMethodElement = node.staticElement; 12256 ExecutableElement staticMethodElement = node.staticElement;
12171 Type2 staticType = computeArgumentType(staticMethodElement); 12257 Type2 staticType = computeArgumentType(staticMethodElement);
12172 recordStaticType(node, staticType); 12258 recordStaticType(node, staticType);
12173 MethodElement propagatedMethodElement = node.propagatedElement; 12259 MethodElement propagatedMethodElement = node.propagatedElement;
12174 if (propagatedMethodElement != staticMethodElement) { 12260 if (propagatedMethodElement != staticMethodElement) {
12175 Type2 propagatedType = computeArgumentType(propagatedMethodElement); 12261 Type2 propagatedType = computeArgumentType(propagatedMethodElement);
12176 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 12262 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
12177 recordPropagatedType2(node, propagatedType); 12263 recordPropagatedType(node, propagatedType);
12178 } 12264 }
12179 } 12265 }
12180 } else { 12266 } else {
12181 ExecutableElement staticMethodElement = node.staticElement; 12267 ExecutableElement staticMethodElement = node.staticElement;
12182 Type2 staticType = computeStaticReturnType(staticMethodElement); 12268 Type2 staticType = computeStaticReturnType(staticMethodElement);
12183 recordStaticType(node, staticType); 12269 recordStaticType(node, staticType);
12184 MethodElement propagatedMethodElement = node.propagatedElement; 12270 MethodElement propagatedMethodElement = node.propagatedElement;
12185 if (propagatedMethodElement != staticMethodElement) { 12271 if (propagatedMethodElement != staticMethodElement) {
12186 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); 12272 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement);
12187 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 12273 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
12188 recordPropagatedType2(node, propagatedType); 12274 recordPropagatedType(node, propagatedType);
12189 } 12275 }
12190 } 12276 }
12191 } 12277 }
12192 return null; 12278 return null;
12193 } 12279 }
12194 12280
12195 /** 12281 /**
12196 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of 12282 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of
12197 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new 12283 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new
12198 * T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> 12284 * T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>.</blockquote>
12199 * 12285 *
12200 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a constant object 12286 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a constant object
12201 * expression of either the form <i>const T.id(a<sub>1</sub>, &hellip;, a<sub> n</sub>)</i> or the 12287 * expression of either the form <i>const T.id(a<sub>1</sub>, &hellip;, a<sub> n</sub>)</i> or the
12202 * form <i>const T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>. </ blockquote> 12288 * form <i>const T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>. </ blockquote>
12203 */ 12289 */
12204 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 12290 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
12205 recordStaticType(node, node.constructorName.type.type); 12291 recordStaticType(node, node.constructorName.type.type);
12206 ConstructorElement element = node.staticElement; 12292 ConstructorElement element = node.staticElement;
12207 if (element != null && "Element" == element.enclosingElement.name) { 12293 if (element != null && "Element" == element.enclosingElement.name) {
12208 LibraryElement library = element.library; 12294 LibraryElement library = element.library;
12209 if (isHtmlLibrary(library)) { 12295 if (isHtmlLibrary(library)) {
12210 String constructorName = element.name; 12296 String constructorName = element.name;
12211 if ("tag" == constructorName) { 12297 if ("tag" == constructorName) {
12212 Type2 returnType = getFirstArgumentAsType2(library, node.argumentList, _HTML_ELEMENT_TO_CLASS_MAP); 12298 Type2 returnType = getFirstArgumentAsTypeWithMap(library, node.argumen tList, _HTML_ELEMENT_TO_CLASS_MAP);
12213 if (returnType != null) { 12299 if (returnType != null) {
12214 recordPropagatedType2(node, returnType); 12300 recordPropagatedType(node, returnType);
12215 } 12301 }
12216 } else { 12302 } else {
12217 Type2 returnType = getElementNameAsType(library, constructorName, _HTM L_ELEMENT_TO_CLASS_MAP); 12303 Type2 returnType = getElementNameAsType(library, constructorName, _HTM L_ELEMENT_TO_CLASS_MAP);
12218 if (returnType != null) { 12304 if (returnType != null) {
12219 recordPropagatedType2(node, returnType); 12305 recordPropagatedType(node, returnType);
12220 } 12306 }
12221 } 12307 }
12222 } 12308 }
12223 } 12309 }
12224 return null; 12310 return null;
12225 } 12311 }
12226 12312
12227 /** 12313 /**
12228 * The Dart Language Specification, 12.3: <blockquote>The static type of an in teger literal is 12314 * The Dart Language Specification, 12.3: <blockquote>The static type of an in teger literal is
12229 * `int`.</blockquote> 12315 * `int`.</blockquote>
(...skipping 22 matching lines...) Expand all
12252 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is `List&lt;dynami c&gt;` 12338 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is `List&lt;dynami c&gt;`
12253 * .</blockquote> 12339 * .</blockquote>
12254 */ 12340 */
12255 Object visitListLiteral(ListLiteral node) { 12341 Object visitListLiteral(ListLiteral node) {
12256 Type2 staticType = _dynamicType; 12342 Type2 staticType = _dynamicType;
12257 TypeArgumentList typeArguments = node.typeArguments; 12343 TypeArgumentList typeArguments = node.typeArguments;
12258 if (typeArguments != null) { 12344 if (typeArguments != null) {
12259 NodeList<TypeName> arguments = typeArguments.arguments; 12345 NodeList<TypeName> arguments = typeArguments.arguments;
12260 if (arguments != null && arguments.length == 1) { 12346 if (arguments != null && arguments.length == 1) {
12261 TypeName argumentTypeName = arguments[0]; 12347 TypeName argumentTypeName = arguments[0];
12262 Type2 argumentType = getType2(argumentTypeName); 12348 Type2 argumentType = getType(argumentTypeName);
12263 if (argumentType != null) { 12349 if (argumentType != null) {
12264 staticType = argumentType; 12350 staticType = argumentType;
12265 } 12351 }
12266 } 12352 }
12267 } 12353 }
12268 recordStaticType(node, _typeProvider.listType.substitute4(<Type2> [staticTyp e])); 12354 recordStaticType(node, _typeProvider.listType.substitute4(<Type2> [staticTyp e]));
12269 NodeList<Expression> elements = node.elements; 12355 NodeList<Expression> elements = node.elements;
12270 int count = elements.length; 12356 int count = elements.length;
12271 if (count > 0) { 12357 if (count > 0) {
12272 Type2 propagatedType = elements[0].bestType; 12358 Type2 propagatedType = elements[0].bestType;
12273 for (int i = 1; i < count; i++) { 12359 for (int i = 1; i < count; i++) {
12274 Type2 elementType = elements[i].bestType; 12360 Type2 elementType = elements[i].bestType;
12275 if (propagatedType != elementType) { 12361 if (propagatedType != elementType) {
12276 propagatedType = _dynamicType; 12362 propagatedType = _dynamicType;
12277 } else { 12363 } else {
12278 propagatedType = propagatedType.getLeastUpperBound(elementType); 12364 propagatedType = propagatedType.getLeastUpperBound(elementType);
12279 if (propagatedType == null) { 12365 if (propagatedType == null) {
12280 propagatedType = _dynamicType; 12366 propagatedType = _dynamicType;
12281 } 12367 }
12282 } 12368 }
12283 } 12369 }
12284 if (propagatedType.isMoreSpecificThan(staticType)) { 12370 if (propagatedType.isMoreSpecificThan(staticType)) {
12285 recordPropagatedType2(node, _typeProvider.listType.substitute4(<Type2> [ propagatedType])); 12371 recordPropagatedType(node, _typeProvider.listType.substitute4(<Type2> [p ropagatedType]));
12286 } 12372 }
12287 } 12373 }
12288 return null; 12374 return null;
12289 } 12375 }
12290 12376
12291 /** 12377 /**
12292 * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form 12378 * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form
12293 * <i><b>const</b> &lt;String, V&gt; {k<sub>1</sub>:e<sub>1</sub>, &hellip;, 12379 * <i><b>const</b> &lt;String, V&gt; {k<sub>1</sub>:e<sub>1</sub>, &hellip;,
12294 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>&lt;String, V&gt; {k<sub>1< /sub>:e<sub>1</sub>, 12380 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>&lt;String, V&gt; {k<sub>1< /sub>:e<sub>1</sub>,
12295 * &hellip;, k<sub>n</sub>:e<sub>n</sub>}</i> is `Map&lt;String, V&gt;`. The s tatic type a 12381 * &hellip;, k<sub>n</sub>:e<sub>n</sub>}</i> is `Map&lt;String, V&gt;`. The s tatic type a
12296 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell ip;, 12382 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell ip;,
12297 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub >, &hellip;, 12383 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub >, &hellip;,
12298 * k<sub>n</sub>:e<sub>n</sub>}</i> is `Map&lt;String, dynamic&gt;`. 12384 * k<sub>n</sub>:e<sub>n</sub>}</i> is `Map&lt;String, dynamic&gt;`.
12299 * 12385 *
12300 * It is a compile-time error if the first type argument to a map literal is n ot 12386 * It is a compile-time error if the first type argument to a map literal is n ot
12301 * <i>String</i>.</blockquote> 12387 * <i>String</i>.</blockquote>
12302 */ 12388 */
12303 Object visitMapLiteral(MapLiteral node) { 12389 Object visitMapLiteral(MapLiteral node) {
12304 Type2 staticKeyType = _dynamicType; 12390 Type2 staticKeyType = _dynamicType;
12305 Type2 staticValueType = _dynamicType; 12391 Type2 staticValueType = _dynamicType;
12306 TypeArgumentList typeArguments = node.typeArguments; 12392 TypeArgumentList typeArguments = node.typeArguments;
12307 if (typeArguments != null) { 12393 if (typeArguments != null) {
12308 NodeList<TypeName> arguments = typeArguments.arguments; 12394 NodeList<TypeName> arguments = typeArguments.arguments;
12309 if (arguments != null && arguments.length == 2) { 12395 if (arguments != null && arguments.length == 2) {
12310 TypeName entryKeyTypeName = arguments[0]; 12396 TypeName entryKeyTypeName = arguments[0];
12311 Type2 entryKeyType = getType2(entryKeyTypeName); 12397 Type2 entryKeyType = getType(entryKeyTypeName);
12312 if (entryKeyType != null) { 12398 if (entryKeyType != null) {
12313 staticKeyType = entryKeyType; 12399 staticKeyType = entryKeyType;
12314 } 12400 }
12315 TypeName entryValueTypeName = arguments[1]; 12401 TypeName entryValueTypeName = arguments[1];
12316 Type2 entryValueType = getType2(entryValueTypeName); 12402 Type2 entryValueType = getType(entryValueTypeName);
12317 if (entryValueType != null) { 12403 if (entryValueType != null) {
12318 staticValueType = entryValueType; 12404 staticValueType = entryValueType;
12319 } 12405 }
12320 } 12406 }
12321 } 12407 }
12322 recordStaticType(node, _typeProvider.mapType.substitute4(<Type2> [staticKeyT ype, staticValueType])); 12408 recordStaticType(node, _typeProvider.mapType.substitute4(<Type2> [staticKeyT ype, staticValueType]));
12323 NodeList<MapLiteralEntry> entries = node.entries; 12409 NodeList<MapLiteralEntry> entries = node.entries;
12324 int count = entries.length; 12410 int count = entries.length;
12325 if (count > 0) { 12411 if (count > 0) {
12326 MapLiteralEntry entry = entries[0]; 12412 MapLiteralEntry entry = entries[0];
(...skipping 22 matching lines...) Expand all
12349 } 12435 }
12350 bool betterKey = propagatedKeyType != null && propagatedKeyType.isMoreSpec ificThan(staticKeyType); 12436 bool betterKey = propagatedKeyType != null && propagatedKeyType.isMoreSpec ificThan(staticKeyType);
12351 bool betterValue = propagatedValueType != null && propagatedValueType.isMo reSpecificThan(staticValueType); 12437 bool betterValue = propagatedValueType != null && propagatedValueType.isMo reSpecificThan(staticValueType);
12352 if (betterKey || betterValue) { 12438 if (betterKey || betterValue) {
12353 if (!betterKey) { 12439 if (!betterKey) {
12354 propagatedKeyType = staticKeyType; 12440 propagatedKeyType = staticKeyType;
12355 } 12441 }
12356 if (!betterValue) { 12442 if (!betterValue) {
12357 propagatedValueType = staticValueType; 12443 propagatedValueType = staticValueType;
12358 } 12444 }
12359 recordPropagatedType2(node, _typeProvider.mapType.substitute4(<Type2> [p ropagatedKeyType, propagatedValueType])); 12445 recordPropagatedType(node, _typeProvider.mapType.substitute4(<Type2> [pr opagatedKeyType, propagatedValueType]));
12360 } 12446 }
12361 } 12447 }
12362 return null; 12448 return null;
12363 } 12449 }
12364 12450
12365 /** 12451 /**
12366 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in vocation <i>i</i> 12452 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in vocation <i>i</i>
12367 * has the form <i>o.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub> : a<sub>n+1</sub>, 12453 * has the form <i>o.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub> : a<sub>n+1</sub>,
12368 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. 12454 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
12369 * 12455 *
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
12401 Object visitMethodInvocation(MethodInvocation node) { 12487 Object visitMethodInvocation(MethodInvocation node) {
12402 SimpleIdentifier methodNameNode = node.methodName; 12488 SimpleIdentifier methodNameNode = node.methodName;
12403 Element staticMethodElement = methodNameNode.staticElement; 12489 Element staticMethodElement = methodNameNode.staticElement;
12404 // Record types of the local variable invoked as a function. 12490 // Record types of the local variable invoked as a function.
12405 if (staticMethodElement is LocalVariableElement) { 12491 if (staticMethodElement is LocalVariableElement) {
12406 LocalVariableElement variable = staticMethodElement; 12492 LocalVariableElement variable = staticMethodElement;
12407 Type2 staticType = variable.type; 12493 Type2 staticType = variable.type;
12408 recordStaticType(methodNameNode, staticType); 12494 recordStaticType(methodNameNode, staticType);
12409 Type2 propagatedType = _overrideManager.getType(variable); 12495 Type2 propagatedType = _overrideManager.getType(variable);
12410 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) { 12496 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) {
12411 recordPropagatedType2(methodNameNode, propagatedType); 12497 recordPropagatedType(methodNameNode, propagatedType);
12412 } 12498 }
12413 } 12499 }
12414 // Record static return type of the static element. 12500 // Record static return type of the static element.
12415 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); 12501 Type2 staticStaticType = computeStaticReturnType(staticMethodElement);
12416 recordStaticType(node, staticStaticType); 12502 recordStaticType(node, staticStaticType);
12417 // Record propagated return type of the static element. 12503 // Record propagated return type of the static element.
12418 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement ); 12504 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement );
12419 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) { 12505 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) {
12420 recordPropagatedType2(node, staticPropagatedType); 12506 recordPropagatedType(node, staticPropagatedType);
12421 } 12507 }
12422 String methodName = methodNameNode.name; 12508 String methodName = methodNameNode.name;
12423 // Future.then(closure) return type is: 12509 // Future.then(closure) return type is:
12424 // 1) the returned Future type, if the closure returns a Future; 12510 // 1) the returned Future type, if the closure returns a Future;
12425 // 2) Future<valueType>, if the closure returns a value. 12511 // 2) Future<valueType>, if the closure returns a value.
12426 if (methodName == "then") { 12512 if (methodName == "then") {
12427 Expression target = node.realTarget; 12513 Expression target = node.realTarget;
12428 Type2 targetType = target == null ? null : target.bestType; 12514 Type2 targetType = target == null ? null : target.bestType;
12429 if (isAsyncFutureType(targetType)) { 12515 if (isAsyncFutureType(targetType)) {
12430 NodeList<Expression> arguments = node.argumentList.arguments; 12516 NodeList<Expression> arguments = node.argumentList.arguments;
12431 if (arguments.length == 1) { 12517 if (arguments.length == 1) {
12432 // TODO(brianwilkerson) Handle the case where both arguments are provi ded. 12518 // TODO(brianwilkerson) Handle the case where both arguments are provi ded.
12433 Expression closureArg = arguments[0]; 12519 Expression closureArg = arguments[0];
12434 if (closureArg is FunctionExpression) { 12520 if (closureArg is FunctionExpression) {
12435 FunctionExpression closureExpr = closureArg; 12521 FunctionExpression closureExpr = closureArg;
12436 Type2 returnType = computePropagatedReturnType(closureExpr.element); 12522 Type2 returnType = computePropagatedReturnType(closureExpr.element);
12437 if (returnType != null) { 12523 if (returnType != null) {
12438 // prepare the type of the returned Future 12524 // prepare the type of the returned Future
12439 InterfaceTypeImpl newFutureType; 12525 InterfaceTypeImpl newFutureType;
12440 if (isAsyncFutureType(returnType)) { 12526 if (isAsyncFutureType(returnType)) {
12441 newFutureType = returnType as InterfaceTypeImpl; 12527 newFutureType = returnType as InterfaceTypeImpl;
12442 } else { 12528 } else {
12443 InterfaceType futureType = targetType as InterfaceType; 12529 InterfaceType futureType = targetType as InterfaceType;
12444 newFutureType = new InterfaceTypeImpl.con1(futureType.element); 12530 newFutureType = new InterfaceTypeImpl.con1(futureType.element);
12445 newFutureType.typeArguments = <Type2> [returnType]; 12531 newFutureType.typeArguments = <Type2> [returnType];
12446 } 12532 }
12447 // set the 'then' invocation type 12533 // set the 'then' invocation type
12448 recordPropagatedType2(node, newFutureType); 12534 recordPropagatedType(node, newFutureType);
12449 return null; 12535 return null;
12450 } 12536 }
12451 } 12537 }
12452 } 12538 }
12453 } 12539 }
12454 } 12540 }
12455 if (methodName == "\$dom_createEvent") { 12541 if (methodName == "\$dom_createEvent") {
12456 Expression target = node.realTarget; 12542 Expression target = node.realTarget;
12457 if (target != null) { 12543 if (target != null) {
12458 Type2 targetType = target.bestType; 12544 Type2 targetType = target.bestType;
12459 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || targetType.name == "Document")) { 12545 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || targetType.name == "Document")) {
12460 LibraryElement library = targetType.element.library; 12546 LibraryElement library = targetType.element.library;
12461 if (isHtmlLibrary(library)) { 12547 if (isHtmlLibrary(library)) {
12462 Type2 returnType = getFirstArgumentAsType(library, node.argumentList ); 12548 Type2 returnType = getFirstArgumentAsType(library, node.argumentList );
12463 if (returnType != null) { 12549 if (returnType != null) {
12464 recordPropagatedType2(node, returnType); 12550 recordPropagatedType(node, returnType);
12465 } 12551 }
12466 } 12552 }
12467 } 12553 }
12468 } 12554 }
12469 } else if (methodName == "query") { 12555 } else if (methodName == "query") {
12470 Expression target = node.realTarget; 12556 Expression target = node.realTarget;
12471 if (target == null) { 12557 if (target == null) {
12472 Element methodElement = methodNameNode.bestElement; 12558 Element methodElement = methodNameNode.bestElement;
12473 if (methodElement != null) { 12559 if (methodElement != null) {
12474 LibraryElement library = methodElement.library; 12560 LibraryElement library = methodElement.library;
12475 if (isHtmlLibrary(library)) { 12561 if (isHtmlLibrary(library)) {
12476 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis t); 12562 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis t);
12477 if (returnType != null) { 12563 if (returnType != null) {
12478 recordPropagatedType2(node, returnType); 12564 recordPropagatedType(node, returnType);
12479 } 12565 }
12480 } 12566 }
12481 } 12567 }
12482 } else { 12568 } else {
12483 Type2 targetType = target.bestType; 12569 Type2 targetType = target.bestType;
12484 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || targetType.name == "Document")) { 12570 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || targetType.name == "Document")) {
12485 LibraryElement library = targetType.element.library; 12571 LibraryElement library = targetType.element.library;
12486 if (isHtmlLibrary(library)) { 12572 if (isHtmlLibrary(library)) {
12487 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis t); 12573 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentLis t);
12488 if (returnType != null) { 12574 if (returnType != null) {
12489 recordPropagatedType2(node, returnType); 12575 recordPropagatedType(node, returnType);
12490 } 12576 }
12491 } 12577 }
12492 } 12578 }
12493 } 12579 }
12494 } else if (methodName == "\$dom_createElement") { 12580 } else if (methodName == "\$dom_createElement") {
12495 Expression target = node.realTarget; 12581 Expression target = node.realTarget;
12496 Type2 targetType = target.bestType; 12582 Type2 targetType = target.bestType;
12497 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || t argetType.name == "Document")) { 12583 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || t argetType.name == "Document")) {
12498 LibraryElement library = targetType.element.library; 12584 LibraryElement library = targetType.element.library;
12499 if (isHtmlLibrary(library)) { 12585 if (isHtmlLibrary(library)) {
12500 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentList) ; 12586 Type2 returnType = getFirstArgumentAsQuery(library, node.argumentList) ;
12501 if (returnType != null) { 12587 if (returnType != null) {
12502 recordPropagatedType2(node, returnType); 12588 recordPropagatedType(node, returnType);
12503 } 12589 }
12504 } 12590 }
12505 } 12591 }
12506 } else if (methodName == "JS") { 12592 } else if (methodName == "JS") {
12507 Type2 returnType = getFirstArgumentAsType(_typeProvider.objectType.element .library, node.argumentList); 12593 Type2 returnType = getFirstArgumentAsType(_typeProvider.objectType.element .library, node.argumentList);
12508 if (returnType != null) { 12594 if (returnType != null) {
12509 recordPropagatedType2(node, returnType); 12595 recordPropagatedType(node, returnType);
12510 } 12596 }
12511 } else { 12597 } else {
12512 Element propagatedElement = methodNameNode.propagatedElement; 12598 Element propagatedElement = methodNameNode.propagatedElement;
12513 if (propagatedElement != staticMethodElement) { 12599 if (propagatedElement != staticMethodElement) {
12514 // Record static return type of the propagated element. 12600 // Record static return type of the propagated element.
12515 Type2 propagatedStaticType = computeStaticReturnType(propagatedElement); 12601 Type2 propagatedStaticType = computeStaticReturnType(propagatedElement);
12516 if (propagatedStaticType != null && (staticStaticType == null || propaga tedStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) { 12602 if (propagatedStaticType != null && (staticStaticType == null || propaga tedStaticType.isMoreSpecificThan(staticStaticType)) && (staticPropagatedType == null || propagatedStaticType.isMoreSpecificThan(staticPropagatedType))) {
12517 recordPropagatedType2(node, propagatedStaticType); 12603 recordPropagatedType(node, propagatedStaticType);
12518 } 12604 }
12519 // Record propagated return type of the propagated element. 12605 // Record propagated return type of the propagated element.
12520 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedE lement); 12606 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedE lement);
12521 if (propagatedPropagatedType != null && (staticStaticType == null || pro pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType )) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh an(propagatedStaticType))) { 12607 if (propagatedPropagatedType != null && (staticStaticType == null || pro pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType )) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh an(propagatedStaticType))) {
12522 recordPropagatedType2(node, propagatedPropagatedType); 12608 recordPropagatedType(node, propagatedPropagatedType);
12523 } 12609 }
12524 } 12610 }
12525 } 12611 }
12526 return null; 12612 return null;
12527 } 12613 }
12528 12614
12529 Object visitNamedExpression(NamedExpression node) { 12615 Object visitNamedExpression(NamedExpression node) {
12530 Expression expression = node.expression; 12616 Expression expression = node.expression;
12531 recordStaticType(node, getStaticType(expression)); 12617 recordStaticType(node, getStaticType(expression));
12532 recordPropagatedType2(node, expression.propagatedType); 12618 recordPropagatedType(node, expression.propagatedType);
12533 return null; 12619 return null;
12534 } 12620 }
12535 12621
12536 /** 12622 /**
12537 * The Dart Language Specification, 12.2: <blockquote>The static type of `null ` is bottom. 12623 * The Dart Language Specification, 12.2: <blockquote>The static type of `null ` is bottom.
12538 * </blockquote> 12624 * </blockquote>
12539 */ 12625 */
12540 Object visitNullLiteral(NullLiteral node) { 12626 Object visitNullLiteral(NullLiteral node) {
12541 recordStaticType(node, _typeProvider.bottomType); 12627 recordStaticType(node, _typeProvider.bottomType);
12542 return null; 12628 return null;
12543 } 12629 }
12544 12630
12545 Object visitParenthesizedExpression(ParenthesizedExpression node) { 12631 Object visitParenthesizedExpression(ParenthesizedExpression node) {
12546 Expression expression = node.expression; 12632 Expression expression = node.expression;
12547 recordStaticType(node, getStaticType(expression)); 12633 recordStaticType(node, getStaticType(expression));
12548 recordPropagatedType2(node, expression.propagatedType); 12634 recordPropagatedType(node, expression.propagatedType);
12549 return null; 12635 return null;
12550 } 12636 }
12551 12637
12552 /** 12638 /**
12553 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form 12639 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form
12554 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1; 12640 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1;
12555 * return r}()</i>. 12641 * return r}()</i>.
12556 * 12642 *
12557 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r = C.v; C.v = r + 1; 12643 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r = C.v; C.v = r + 1;
12558 * return r}()</i>. 12644 * return r}()</i>.
(...skipping 20 matching lines...) Expand all
12579 Expression operand = node.operand; 12665 Expression operand = node.operand;
12580 Type2 staticType = getStaticType(operand); 12666 Type2 staticType = getStaticType(operand);
12581 sc.TokenType operator = node.operator.type; 12667 sc.TokenType operator = node.operator.type;
12582 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc. TokenType.PLUS_PLUS)) { 12668 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, sc. TokenType.PLUS_PLUS)) {
12583 Type2 intType = _typeProvider.intType; 12669 Type2 intType = _typeProvider.intType;
12584 if (identical(getStaticType(node.operand), intType)) { 12670 if (identical(getStaticType(node.operand), intType)) {
12585 staticType = intType; 12671 staticType = intType;
12586 } 12672 }
12587 } 12673 }
12588 recordStaticType(node, staticType); 12674 recordStaticType(node, staticType);
12589 recordPropagatedType2(node, operand.propagatedType); 12675 recordPropagatedType(node, operand.propagatedType);
12590 return null; 12676 return null;
12591 } 12677 }
12592 12678
12593 /** 12679 /**
12594 * See [visitSimpleIdentifier]. 12680 * See [visitSimpleIdentifier].
12595 */ 12681 */
12596 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 12682 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
12597 SimpleIdentifier prefixedIdentifier = node.identifier; 12683 SimpleIdentifier prefixedIdentifier = node.identifier;
12598 Element staticElement = prefixedIdentifier.staticElement; 12684 Element staticElement = prefixedIdentifier.staticElement;
12599 Type2 staticType = _dynamicType; 12685 Type2 staticType = _dynamicType;
12600 if (staticElement is ClassElement) { 12686 if (staticElement is ClassElement) {
12601 if (isNotTypeLiteral(node)) { 12687 if (isNotTypeLiteral(node)) {
12602 staticType = staticElement.type; 12688 staticType = staticElement.type;
12603 } else { 12689 } else {
12604 staticType = _typeProvider.typeType; 12690 staticType = _typeProvider.typeType;
12605 } 12691 }
12606 } else if (staticElement is FunctionTypeAliasElement) { 12692 } else if (staticElement is FunctionTypeAliasElement) {
12607 if (isNotTypeLiteral(node)) { 12693 if (isNotTypeLiteral(node)) {
12608 staticType = staticElement.type; 12694 staticType = staticElement.type;
12609 } else { 12695 } else {
12610 staticType = _typeProvider.typeType; 12696 staticType = _typeProvider.typeType;
12611 } 12697 }
12612 } else if (staticElement is MethodElement) { 12698 } else if (staticElement is MethodElement) {
12613 staticType = staticElement.type; 12699 staticType = staticElement.type;
12614 } else if (staticElement is PropertyAccessorElement) { 12700 } else if (staticElement is PropertyAccessorElement) {
12615 staticType = getType(staticElement, node.prefix.staticType); 12701 staticType = getTypeOfProperty(staticElement, node.prefix.staticType);
12616 } else if (staticElement is ExecutableElement) { 12702 } else if (staticElement is ExecutableElement) {
12617 staticType = staticElement.type; 12703 staticType = staticElement.type;
12618 } else if (staticElement is TypeParameterElement) { 12704 } else if (staticElement is TypeParameterElement) {
12619 staticType = staticElement.type; 12705 staticType = staticElement.type;
12620 } else if (staticElement is VariableElement) { 12706 } else if (staticElement is VariableElement) {
12621 staticType = staticElement.type; 12707 staticType = staticElement.type;
12622 } 12708 }
12623 recordStaticType(prefixedIdentifier, staticType); 12709 recordStaticType(prefixedIdentifier, staticType);
12624 recordStaticType(node, staticType); 12710 recordStaticType(node, staticType);
12625 Element propagatedElement = prefixedIdentifier.propagatedElement; 12711 Element propagatedElement = prefixedIdentifier.propagatedElement;
12626 Type2 propagatedType = null; 12712 Type2 propagatedType = null;
12627 if (propagatedElement is ClassElement) { 12713 if (propagatedElement is ClassElement) {
12628 if (isNotTypeLiteral(node)) { 12714 if (isNotTypeLiteral(node)) {
12629 propagatedType = propagatedElement.type; 12715 propagatedType = propagatedElement.type;
12630 } else { 12716 } else {
12631 propagatedType = _typeProvider.typeType; 12717 propagatedType = _typeProvider.typeType;
12632 } 12718 }
12633 } else if (propagatedElement is FunctionTypeAliasElement) { 12719 } else if (propagatedElement is FunctionTypeAliasElement) {
12634 propagatedType = propagatedElement.type; 12720 propagatedType = propagatedElement.type;
12635 } else if (propagatedElement is MethodElement) { 12721 } else if (propagatedElement is MethodElement) {
12636 propagatedType = propagatedElement.type; 12722 propagatedType = propagatedElement.type;
12637 } else if (propagatedElement is PropertyAccessorElement) { 12723 } else if (propagatedElement is PropertyAccessorElement) {
12638 propagatedType = getType(propagatedElement, node.prefix.staticType); 12724 propagatedType = getTypeOfProperty(propagatedElement, node.prefix.staticTy pe);
12639 } else if (propagatedElement is ExecutableElement) { 12725 } else if (propagatedElement is ExecutableElement) {
12640 propagatedType = propagatedElement.type; 12726 propagatedType = propagatedElement.type;
12641 } else if (propagatedElement is TypeParameterElement) { 12727 } else if (propagatedElement is TypeParameterElement) {
12642 propagatedType = propagatedElement.type; 12728 propagatedType = propagatedElement.type;
12643 } else if (propagatedElement is VariableElement) { 12729 } else if (propagatedElement is VariableElement) {
12644 propagatedType = propagatedElement.type; 12730 propagatedType = propagatedElement.type;
12645 } 12731 }
12646 Type2 overriddenType = _overrideManager.getType(propagatedElement); 12732 Type2 overriddenType = _overrideManager.getType(propagatedElement);
12647 if (propagatedType == null || (overriddenType != null && overriddenType.isMo reSpecificThan(propagatedType))) { 12733 if (propagatedType == null || (overriddenType != null && overriddenType.isMo reSpecificThan(propagatedType))) {
12648 propagatedType = overriddenType; 12734 propagatedType = overriddenType;
12649 } 12735 }
12650 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 12736 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
12651 recordPropagatedType2(prefixedIdentifier, propagatedType); 12737 recordPropagatedType(prefixedIdentifier, propagatedType);
12652 recordPropagatedType2(node, propagatedType); 12738 recordPropagatedType(node, propagatedType);
12653 } 12739 }
12654 return null; 12740 return null;
12655 } 12741 }
12656 12742
12657 /** 12743 /**
12658 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form 12744 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form
12659 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the 12745 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the
12660 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote> 12746 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote>
12661 */ 12747 */
12662 Object visitPrefixExpression(PrefixExpression node) { 12748 Object visitPrefixExpression(PrefixExpression node) {
12663 sc.TokenType operator = node.operator.type; 12749 sc.TokenType operator = node.operator.type;
12664 if (identical(operator, sc.TokenType.BANG)) { 12750 if (identical(operator, sc.TokenType.BANG)) {
12665 recordStaticType(node, _typeProvider.boolType); 12751 recordStaticType(node, _typeProvider.boolType);
12666 } else { 12752 } else {
12667 // The other cases are equivalent to invoking a method. 12753 // The other cases are equivalent to invoking a method.
12668 ExecutableElement staticMethodElement = node.staticElement; 12754 ExecutableElement staticMethodElement = node.staticElement;
12669 Type2 staticType = computeStaticReturnType(staticMethodElement); 12755 Type2 staticType = computeStaticReturnType(staticMethodElement);
12670 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, s c.TokenType.PLUS_PLUS)) { 12756 if (identical(operator, sc.TokenType.MINUS_MINUS) || identical(operator, s c.TokenType.PLUS_PLUS)) {
12671 Type2 intType = _typeProvider.intType; 12757 Type2 intType = _typeProvider.intType;
12672 if (identical(getStaticType(node.operand), intType)) { 12758 if (identical(getStaticType(node.operand), intType)) {
12673 staticType = intType; 12759 staticType = intType;
12674 } 12760 }
12675 } 12761 }
12676 recordStaticType(node, staticType); 12762 recordStaticType(node, staticType);
12677 MethodElement propagatedMethodElement = node.propagatedElement; 12763 MethodElement propagatedMethodElement = node.propagatedElement;
12678 if (propagatedMethodElement != staticMethodElement) { 12764 if (propagatedMethodElement != staticMethodElement) {
12679 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement); 12765 Type2 propagatedType = computeStaticReturnType(propagatedMethodElement);
12680 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 12766 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
12681 recordPropagatedType2(node, propagatedType); 12767 recordPropagatedType(node, propagatedType);
12682 } 12768 }
12683 } 12769 }
12684 } 12770 }
12685 return null; 12771 return null;
12686 } 12772 }
12687 12773
12688 /** 12774 /**
12689 * The Dart Language Specification, 12.13: <blockquote> Property extraction al lows for a member of 12775 * The Dart Language Specification, 12.13: <blockquote> Property extraction al lows for a member of
12690 * an object to be concisely extracted from the object. If <i>o</i> is an obje ct, and if <i>m</i> 12776 * an object to be concisely extracted from the object. If <i>o</i> is an obje ct, and if <i>m</i>
12691 * is the name of a method member of <i>o</i>, then 12777 * is the name of a method member of <i>o</i>, then
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
12727 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote> 12813 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote>
12728 */ 12814 */
12729 Object visitPropertyAccess(PropertyAccess node) { 12815 Object visitPropertyAccess(PropertyAccess node) {
12730 SimpleIdentifier propertyName = node.propertyName; 12816 SimpleIdentifier propertyName = node.propertyName;
12731 Element staticElement = propertyName.staticElement; 12817 Element staticElement = propertyName.staticElement;
12732 Type2 staticType = _dynamicType; 12818 Type2 staticType = _dynamicType;
12733 if (staticElement is MethodElement) { 12819 if (staticElement is MethodElement) {
12734 staticType = staticElement.type; 12820 staticType = staticElement.type;
12735 } else if (staticElement is PropertyAccessorElement) { 12821 } else if (staticElement is PropertyAccessorElement) {
12736 Expression realTarget = node.realTarget; 12822 Expression realTarget = node.realTarget;
12737 staticType = getType(staticElement, realTarget != null ? getStaticType(rea lTarget) : null); 12823 staticType = getTypeOfProperty(staticElement, realTarget != null ? getStat icType(realTarget) : null);
12738 } else { 12824 } else {
12739 } 12825 }
12740 recordStaticType(propertyName, staticType); 12826 recordStaticType(propertyName, staticType);
12741 recordStaticType(node, staticType); 12827 recordStaticType(node, staticType);
12742 Element propagatedElement = propertyName.propagatedElement; 12828 Element propagatedElement = propertyName.propagatedElement;
12743 Type2 propagatedType = _overrideManager.getType(propagatedElement); 12829 Type2 propagatedType = _overrideManager.getType(propagatedElement);
12744 if (propagatedElement is MethodElement) { 12830 if (propagatedElement is MethodElement) {
12745 propagatedType = propagatedElement.type; 12831 propagatedType = propagatedElement.type;
12746 } else if (propagatedElement is PropertyAccessorElement) { 12832 } else if (propagatedElement is PropertyAccessorElement) {
12747 Expression realTarget = node.realTarget; 12833 Expression realTarget = node.realTarget;
12748 propagatedType = getType(propagatedElement, realTarget != null ? realTarge t.bestType : null); 12834 propagatedType = getTypeOfProperty(propagatedElement, realTarget != null ? realTarget.bestType : null);
12749 } else { 12835 } else {
12750 } 12836 }
12751 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 12837 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
12752 recordPropagatedType2(propertyName, propagatedType); 12838 recordPropagatedType(propertyName, propagatedType);
12753 recordPropagatedType2(node, propagatedType); 12839 recordPropagatedType(node, propagatedType);
12754 } 12840 }
12755 return null; 12841 return null;
12756 } 12842 }
12757 12843
12758 /** 12844 /**
12759 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret hrow expression is 12845 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret hrow expression is
12760 * bottom.</blockquote> 12846 * bottom.</blockquote>
12761 */ 12847 */
12762 Object visitRethrowExpression(RethrowExpression node) { 12848 Object visitRethrowExpression(RethrowExpression node) {
12763 recordStaticType(node, _typeProvider.bottomType); 12849 recordStaticType(node, _typeProvider.bottomType);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
12813 } 12899 }
12814 } else if (element is FunctionTypeAliasElement) { 12900 } else if (element is FunctionTypeAliasElement) {
12815 if (isNotTypeLiteral(node)) { 12901 if (isNotTypeLiteral(node)) {
12816 staticType = element.type; 12902 staticType = element.type;
12817 } else { 12903 } else {
12818 staticType = _typeProvider.typeType; 12904 staticType = _typeProvider.typeType;
12819 } 12905 }
12820 } else if (element is MethodElement) { 12906 } else if (element is MethodElement) {
12821 staticType = element.type; 12907 staticType = element.type;
12822 } else if (element is PropertyAccessorElement) { 12908 } else if (element is PropertyAccessorElement) {
12823 staticType = getType(element, null); 12909 staticType = getTypeOfProperty(element, null);
12824 } else if (element is ExecutableElement) { 12910 } else if (element is ExecutableElement) {
12825 staticType = element.type; 12911 staticType = element.type;
12826 } else if (element is TypeParameterElement) { 12912 } else if (element is TypeParameterElement) {
12827 // if (isTypeName(node)) { 12913 // if (isTypeName(node)) {
12828 staticType = element.type; 12914 staticType = element.type;
12829 } else if (element is VariableElement) { 12915 } else if (element is VariableElement) {
12830 VariableElement variable = element; 12916 VariableElement variable = element;
12831 staticType = _promoteManager.getStaticType(variable); 12917 staticType = _promoteManager.getStaticType(variable);
12832 } else if (element is PrefixElement) { 12918 } else if (element is PrefixElement) {
12833 return null; 12919 return null;
12834 } else { 12920 } else {
12835 staticType = _dynamicType; 12921 staticType = _dynamicType;
12836 } 12922 }
12837 recordStaticType(node, staticType); 12923 recordStaticType(node, staticType);
12838 // TODO(brianwilkerson) I think we want to repeat the logic above using the propagated element 12924 // TODO(brianwilkerson) I think we want to repeat the logic above using the propagated element
12839 // to get another candidate for the propagated type. 12925 // to get another candidate for the propagated type.
12840 Type2 propagatedType = _overrideManager.getType(element); 12926 Type2 propagatedType = _overrideManager.getType(element);
12841 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 12927 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
12842 recordPropagatedType2(node, propagatedType); 12928 recordPropagatedType(node, propagatedType);
12843 } 12929 }
12844 return null; 12930 return null;
12845 } 12931 }
12846 12932
12847 /** 12933 /**
12848 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is 12934 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is
12849 * `String`.</blockquote> 12935 * `String`.</blockquote>
12850 */ 12936 */
12851 Object visitSimpleStringLiteral(SimpleStringLiteral node) { 12937 Object visitSimpleStringLiteral(SimpleStringLiteral node) {
12852 recordStaticType(node, _typeProvider.stringType); 12938 recordStaticType(node, _typeProvider.stringType);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
12898 Object visitThrowExpression(ThrowExpression node) { 12984 Object visitThrowExpression(ThrowExpression node) {
12899 recordStaticType(node, _typeProvider.bottomType); 12985 recordStaticType(node, _typeProvider.bottomType);
12900 return null; 12986 return null;
12901 } 12987 }
12902 12988
12903 Object visitVariableDeclaration(VariableDeclaration node) { 12989 Object visitVariableDeclaration(VariableDeclaration node) {
12904 Expression initializer = node.initializer; 12990 Expression initializer = node.initializer;
12905 if (initializer != null) { 12991 if (initializer != null) {
12906 Type2 rightType = initializer.bestType; 12992 Type2 rightType = initializer.bestType;
12907 SimpleIdentifier name = node.name; 12993 SimpleIdentifier name = node.name;
12908 recordPropagatedType2(name, rightType); 12994 recordPropagatedType(name, rightType);
12909 VariableElement element = name.staticElement as VariableElement; 12995 VariableElement element = name.staticElement as VariableElement;
12910 if (element != null) { 12996 if (element != null) {
12911 _resolver.override2(element, rightType); 12997 _resolver.override2(element, rightType);
12912 } 12998 }
12913 } 12999 }
12914 return null; 13000 return null;
12915 } 13001 }
12916 13002
12917 /** 13003 /**
12918 * Record that the static type of the given node is the type of the second arg ument to the method 13004 * Record that the static type of the given node is the type of the second arg ument to the method
(...skipping 25 matching lines...) Expand all
12944 } 13030 }
12945 13031
12946 /** 13032 /**
12947 * Given a function body, compute the propagated return type of the function. The propagated 13033 * Given a function body, compute the propagated return type of the function. The propagated
12948 * return type of functions with a block body is the least upper bound of all 13034 * return type of functions with a block body is the least upper bound of all
12949 * [ReturnStatement] expressions, with an expression body it is the type of th e expression. 13035 * [ReturnStatement] expressions, with an expression body it is the type of th e expression.
12950 * 13036 *
12951 * @param body the boy of the function whose propagated return type is to be c omputed 13037 * @param body the boy of the function whose propagated return type is to be c omputed
12952 * @return the propagated return type that was computed 13038 * @return the propagated return type that was computed
12953 */ 13039 */
12954 Type2 computePropagatedReturnType2(FunctionBody body) { 13040 Type2 computePropagatedReturnTypeOfFunction(FunctionBody body) {
12955 if (body is ExpressionFunctionBody) { 13041 if (body is ExpressionFunctionBody) {
12956 ExpressionFunctionBody expressionBody = body; 13042 ExpressionFunctionBody expressionBody = body;
12957 return expressionBody.expression.bestType; 13043 return expressionBody.expression.bestType;
12958 } 13044 }
12959 if (body is BlockFunctionBody) { 13045 if (body is BlockFunctionBody) {
12960 List<Type2> result = [null]; 13046 List<Type2> result = [null];
12961 body.accept(new GeneralizingAstVisitor_StaticTypeAnalyzer_computePropagate dReturnType2(result)); 13047 body.accept(new GeneralizingAstVisitor_StaticTypeAnalyzer_computePropagate dReturnTypeOfFunction(result));
12962 return result[0]; 13048 return result[0];
12963 } 13049 }
12964 return null; 13050 return null;
12965 } 13051 }
12966 13052
12967 /** 13053 /**
12968 * Compute the static return type of the method or function represented by the given element. 13054 * Compute the static return type of the method or function represented by the given element.
12969 * 13055 *
12970 * @param element the element representing the method or function invoked by t he given node 13056 * @param element the element representing the method or function invoked by t he given node
12971 * @return the static return type that was computed 13057 * @return the static return type that was computed
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
13013 } 13099 }
13014 13100
13015 /** 13101 /**
13016 * Given a function declaration, compute the return static type of the functio n. The return type 13102 * Given a function declaration, compute the return static type of the functio n. The return type
13017 * of functions with a block body is `dynamicType`, with an expression body it is the type 13103 * of functions with a block body is `dynamicType`, with an expression body it is the type
13018 * of the expression. 13104 * of the expression.
13019 * 13105 *
13020 * @param node the function expression whose static return type is to be compu ted 13106 * @param node the function expression whose static return type is to be compu ted
13021 * @return the static return type that was computed 13107 * @return the static return type that was computed
13022 */ 13108 */
13023 Type2 computeStaticReturnType2(FunctionDeclaration node) { 13109 Type2 computeStaticReturnTypeOfFunctionDeclaration(FunctionDeclaration node) {
13024 TypeName returnType = node.returnType; 13110 TypeName returnType = node.returnType;
13025 if (returnType == null) { 13111 if (returnType == null) {
13026 return _dynamicType; 13112 return _dynamicType;
13027 } 13113 }
13028 return returnType.type; 13114 return returnType.type;
13029 } 13115 }
13030 13116
13031 /** 13117 /**
13032 * Given a function expression, compute the return type of the function. The r eturn type of 13118 * Given a function expression, compute the return type of the function. The r eturn type of
13033 * functions with a block body is `dynamicType`, with an expression body it is the type of 13119 * functions with a block body is `dynamicType`, with an expression body it is the type of
13034 * the expression. 13120 * the expression.
13035 * 13121 *
13036 * @param node the function expression whose return type is to be computed 13122 * @param node the function expression whose return type is to be computed
13037 * @return the return type that was computed 13123 * @return the return type that was computed
13038 */ 13124 */
13039 Type2 computeStaticReturnType3(FunctionExpression node) { 13125 Type2 computeStaticReturnTypeOfFunctionExpression(FunctionExpression node) {
13040 FunctionBody body = node.body; 13126 FunctionBody body = node.body;
13041 if (body is ExpressionFunctionBody) { 13127 if (body is ExpressionFunctionBody) {
13042 return getStaticType(body.expression); 13128 return getStaticType(body.expression);
13043 } 13129 }
13044 return _dynamicType; 13130 return _dynamicType;
13045 } 13131 }
13046 13132
13047 /** 13133 /**
13048 * If the given element name can be mapped to the name of a class defined with in the given 13134 * If the given element name can be mapped to the name of a class defined with in the given
13049 * library, return the type specified by the argument. 13135 * library, return the type specified by the argument.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
13122 13208
13123 /** 13209 /**
13124 * If the given argument list contains at least one argument, and if the argum ent is a simple 13210 * If the given argument list contains at least one argument, and if the argum ent is a simple
13125 * string literal, and if the value of the argument is the name of a class def ined within the 13211 * string literal, and if the value of the argument is the name of a class def ined within the
13126 * given library, return the type specified by the argument. 13212 * given library, return the type specified by the argument.
13127 * 13213 *
13128 * @param library the library in which the specified type would be defined 13214 * @param library the library in which the specified type would be defined
13129 * @param argumentList the list of arguments from which a type is to be extrac ted 13215 * @param argumentList the list of arguments from which a type is to be extrac ted
13130 * @return the type specified by the first argument in the argument list 13216 * @return the type specified by the first argument in the argument list
13131 */ 13217 */
13132 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList ) => getFirstArgumentAsType2(library, argumentList, null); 13218 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList ) => getFirstArgumentAsTypeWithMap(library, argumentList, null);
13133 13219
13134 /** 13220 /**
13135 * If the given argument list contains at least one argument, and if the argum ent is a simple 13221 * If the given argument list contains at least one argument, and if the argum ent is a simple
13136 * string literal, and if the value of the argument is the name of a class def ined within the 13222 * string literal, and if the value of the argument is the name of a class def ined within the
13137 * given library, return the type specified by the argument. 13223 * given library, return the type specified by the argument.
13138 * 13224 *
13139 * @param library the library in which the specified type would be defined 13225 * @param library the library in which the specified type would be defined
13140 * @param argumentList the list of arguments from which a type is to be extrac ted 13226 * @param argumentList the list of arguments from which a type is to be extrac ted
13141 * @param nameMap an optional map used to map the element name to a type name 13227 * @param nameMap an optional map used to map the element name to a type name
13142 * @return the type specified by the first argument in the argument list 13228 * @return the type specified by the first argument in the argument list
13143 */ 13229 */
13144 Type2 getFirstArgumentAsType2(LibraryElement library, ArgumentList argumentLis t, Map<String, String> nameMap) => getElementNameAsType(library, getFirstArgumen tAsString(argumentList), nameMap); 13230 Type2 getFirstArgumentAsTypeWithMap(LibraryElement library, ArgumentList argum entList, Map<String, String> nameMap) => getElementNameAsType(library, getFirstA rgumentAsString(argumentList), nameMap);
13145 13231
13146 /** 13232 /**
13147 * Return the static type of the given expression. 13233 * Return the static type of the given expression.
13148 * 13234 *
13149 * @param expression the expression whose type is to be returned 13235 * @param expression the expression whose type is to be returned
13150 * @return the static type of the given expression 13236 * @return the static type of the given expression
13151 */ 13237 */
13152 Type2 getStaticType(Expression expression) { 13238 Type2 getStaticType(Expression expression) {
13153 Type2 type = expression.staticType; 13239 Type2 type = expression.staticType;
13154 if (type == null) { 13240 if (type == null) {
13155 // TODO(brianwilkerson) Determine the conditions for which the static type is null. 13241 // TODO(brianwilkerson) Determine the conditions for which the static type is null.
13156 return _dynamicType; 13242 return _dynamicType;
13157 } 13243 }
13158 return type; 13244 return type;
13159 } 13245 }
13160 13246
13161 /** 13247 /**
13248 * Return the type represented by the given type name.
13249 *
13250 * @param typeName the type name representing the type to be returned
13251 * @return the type represented by the type name
13252 */
13253 Type2 getType(TypeName typeName) {
13254 Type2 type = typeName.type;
13255 if (type == null) {
13256 //TODO(brianwilkerson) Determine the conditions for which the type is null .
13257 return _dynamicType;
13258 }
13259 return type;
13260 }
13261
13262 /**
13162 * Return the type that should be recorded for a node that resolved to the giv en accessor. 13263 * Return the type that should be recorded for a node that resolved to the giv en accessor.
13163 * 13264 *
13164 * @param accessor the accessor that the node resolved to 13265 * @param accessor the accessor that the node resolved to
13165 * @param context if the accessor element has context [by being the RHS of a 13266 * @param context if the accessor element has context [by being the RHS of a
13166 * [PrefixedIdentifier] or [PropertyAccess]], and the return type of the 13267 * [PrefixedIdentifier] or [PropertyAccess]], and the return type of the
13167 * accessor is a parameter type, then the type of the LHS can be used to get more 13268 * accessor is a parameter type, then the type of the LHS can be used to get more
13168 * specific type information 13269 * specific type information
13169 * @return the type that should be recorded for a node that resolved to the gi ven accessor 13270 * @return the type that should be recorded for a node that resolved to the gi ven accessor
13170 */ 13271 */
13171 Type2 getType(PropertyAccessorElement accessor, Type2 context) { 13272 Type2 getTypeOfProperty(PropertyAccessorElement accessor, Type2 context) {
13172 FunctionType functionType = accessor.type; 13273 FunctionType functionType = accessor.type;
13173 if (functionType == null) { 13274 if (functionType == null) {
13174 // TODO(brianwilkerson) Report this internal error. This happens when we a re analyzing a 13275 // TODO(brianwilkerson) Report this internal error. This happens when we a re analyzing a
13175 // reference to a property before we have analyzed the declaration of the property or when 13276 // reference to a property before we have analyzed the declaration of the property or when
13176 // the property does not have a defined type. 13277 // the property does not have a defined type.
13177 return _dynamicType; 13278 return _dynamicType;
13178 } 13279 }
13179 if (accessor.isSetter) { 13280 if (accessor.isSetter) {
13180 List<Type2> parameterTypes = functionType.normalParameterTypes; 13281 List<Type2> parameterTypes = functionType.normalParameterTypes;
13181 if (parameterTypes != null && parameterTypes.length > 0) { 13282 if (parameterTypes != null && parameterTypes.length > 0) {
(...skipping 21 matching lines...) Expand all
13203 if (returnType.name == typeParameterElement.name) { 13304 if (returnType.name == typeParameterElement.name) {
13204 return interfaceTypeContext.typeArguments[i]; 13305 return interfaceTypeContext.typeArguments[i];
13205 } 13306 }
13206 } 13307 }
13207 } 13308 }
13208 } 13309 }
13209 return returnType; 13310 return returnType;
13210 } 13311 }
13211 13312
13212 /** 13313 /**
13213 * Return the type represented by the given type name.
13214 *
13215 * @param typeName the type name representing the type to be returned
13216 * @return the type represented by the type name
13217 */
13218 Type2 getType2(TypeName typeName) {
13219 Type2 type = typeName.type;
13220 if (type == null) {
13221 //TODO(brianwilkerson) Determine the conditions for which the type is null .
13222 return _dynamicType;
13223 }
13224 return type;
13225 }
13226
13227 /**
13228 * Return `true` if the given [Type] is the `Future` form the 'dart:async' 13314 * Return `true` if the given [Type] is the `Future` form the 'dart:async'
13229 * library. 13315 * library.
13230 */ 13316 */
13231 bool isAsyncFutureType(Type2 type) => type is InterfaceType && type.name == "F uture" && isAsyncLibrary(type.element.library); 13317 bool isAsyncFutureType(Type2 type) => type is InterfaceType && type.name == "F uture" && isAsyncLibrary(type.element.library);
13232 13318
13233 /** 13319 /**
13234 * Return `true` if the given library is the 'dart:async' library. 13320 * Return `true` if the given library is the 'dart:async' library.
13235 * 13321 *
13236 * @param library the library being tested 13322 * @param library the library being tested
13237 * @return `true` if the library is 'dart:async' 13323 * @return `true` if the library is 'dart:async'
(...skipping 13 matching lines...) Expand all
13251 * 13337 *
13252 * @param node the node being tested 13338 * @param node the node being tested
13253 * @return `true` if the given node is not a type literal 13339 * @return `true` if the given node is not a type literal
13254 */ 13340 */
13255 bool isNotTypeLiteral(Identifier node) { 13341 bool isNotTypeLiteral(Identifier node) {
13256 AstNode parent = node.parent; 13342 AstNode parent = node.parent;
13257 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent is TypeName || identical(parent.prefix, node))) || (parent is PropertyAccess && identical(parent.target, node)) || (parent is MethodInvocation && identical(nod e, parent.target)); 13343 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent is TypeName || identical(parent.prefix, node))) || (parent is PropertyAccess && identical(parent.target, node)) || (parent is MethodInvocation && identical(nod e, parent.target));
13258 } 13344 }
13259 13345
13260 /** 13346 /**
13347 * Record that the propagated type of the given node is the given type.
13348 *
13349 * @param expression the node whose type is to be recorded
13350 * @param type the propagated type of the node
13351 */
13352 void recordPropagatedType(Expression expression, Type2 type) {
13353 if (type != null && !type.isDynamic) {
13354 expression.propagatedType = type;
13355 }
13356 }
13357
13358 /**
13261 * Given a function element and its body, compute and record the propagated re turn type of the 13359 * Given a function element and its body, compute and record the propagated re turn type of the
13262 * function. 13360 * function.
13263 * 13361 *
13264 * @param functionElement the function element to record propagated return typ e for 13362 * @param functionElement the function element to record propagated return typ e for
13265 * @param body the boy of the function whose propagated return type is to be c omputed 13363 * @param body the boy of the function whose propagated return type is to be c omputed
13266 * @return the propagated return type that was computed, may be `null` if it i s not more 13364 * @return the propagated return type that was computed, may be `null` if it i s not more
13267 * specific than the static return type. 13365 * specific than the static return type.
13268 */ 13366 */
13269 void recordPropagatedType(ExecutableElement functionElement, FunctionBody body ) { 13367 void recordPropagatedTypeOfFunction(ExecutableElement functionElement, Functio nBody body) {
13270 Type2 propagatedReturnType = computePropagatedReturnType2(body); 13368 Type2 propagatedReturnType = computePropagatedReturnTypeOfFunction(body);
13271 if (propagatedReturnType == null) { 13369 if (propagatedReturnType == null) {
13272 return; 13370 return;
13273 } 13371 }
13274 // Ignore 'bottom' type. 13372 // Ignore 'bottom' type.
13275 if (propagatedReturnType.isBottom) { 13373 if (propagatedReturnType.isBottom) {
13276 return; 13374 return;
13277 } 13375 }
13278 // Record only if we inferred more specific type. 13376 // Record only if we inferred more specific type.
13279 Type2 staticReturnType = functionElement.returnType; 13377 Type2 staticReturnType = functionElement.returnType;
13280 if (!propagatedReturnType.isMoreSpecificThan(staticReturnType)) { 13378 if (!propagatedReturnType.isMoreSpecificThan(staticReturnType)) {
13281 return; 13379 return;
13282 } 13380 }
13283 // OK, do record. 13381 // OK, do record.
13284 _propagatedReturnTypes[functionElement] = propagatedReturnType; 13382 _propagatedReturnTypes[functionElement] = propagatedReturnType;
13285 } 13383 }
13286 13384
13287 /** 13385 /**
13288 * Record that the propagated type of the given node is the given type.
13289 *
13290 * @param expression the node whose type is to be recorded
13291 * @param type the propagated type of the node
13292 */
13293 void recordPropagatedType2(Expression expression, Type2 type) {
13294 if (type != null && !type.isDynamic) {
13295 expression.propagatedType = type;
13296 }
13297 }
13298
13299 /**
13300 * Record that the static type of the given node is the given type. 13386 * Record that the static type of the given node is the given type.
13301 * 13387 *
13302 * @param expression the node whose type is to be recorded 13388 * @param expression the node whose type is to be recorded
13303 * @param type the static type of the node 13389 * @param type the static type of the node
13304 */ 13390 */
13305 void recordStaticType(Expression expression, Type2 type) { 13391 void recordStaticType(Expression expression, Type2 type) {
13306 if (type == null) { 13392 if (type == null) {
13307 expression.staticType = _dynamicType; 13393 expression.staticType = _dynamicType;
13308 } else { 13394 } else {
13309 expression.staticType = type; 13395 expression.staticType = type;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
13341 } 13427 }
13342 // default 13428 // default
13343 return staticType; 13429 return staticType;
13344 } 13430 }
13345 13431
13346 get thisType_J2DAccessor => _thisType; 13432 get thisType_J2DAccessor => _thisType;
13347 13433
13348 set thisType_J2DAccessor(__v) => _thisType = __v; 13434 set thisType_J2DAccessor(__v) => _thisType = __v;
13349 } 13435 }
13350 13436
13351 class GeneralizingAstVisitor_StaticTypeAnalyzer_computePropagatedReturnType2 ext ends GeneralizingAstVisitor<Object> { 13437 class GeneralizingAstVisitor_StaticTypeAnalyzer_computePropagatedReturnTypeOfFun ction extends GeneralizingAstVisitor<Object> {
13352 List<Type2> result; 13438 List<Type2> result;
13353 13439
13354 GeneralizingAstVisitor_StaticTypeAnalyzer_computePropagatedReturnType2(this.re sult) : super(); 13440 GeneralizingAstVisitor_StaticTypeAnalyzer_computePropagatedReturnTypeOfFunctio n(this.result) : super();
13355 13441
13356 Object visitExpression(Expression node) => null; 13442 Object visitExpression(Expression node) => null;
13357 13443
13358 Object visitReturnStatement(ReturnStatement node) { 13444 Object visitReturnStatement(ReturnStatement node) {
13359 // prepare this 'return' type 13445 // prepare this 'return' type
13360 Type2 type; 13446 Type2 type;
13361 Expression expression = node.expression; 13447 Expression expression = node.expression;
13362 if (expression != null) { 13448 if (expression != null) {
13363 type = expression.bestType; 13449 type = expression.bestType;
13364 } else { 13450 } else {
(...skipping 29 matching lines...) Expand all
13394 /** 13480 /**
13395 * Given some [ClassElement], return the set of all subtypes, and subtypes of subtypes. 13481 * Given some [ClassElement], return the set of all subtypes, and subtypes of subtypes.
13396 * 13482 *
13397 * @param classElement the class to recursively return the set of subtypes of 13483 * @param classElement the class to recursively return the set of subtypes of
13398 */ 13484 */
13399 Set<ClassElement> computeAllSubtypes(ClassElement classElement) { 13485 Set<ClassElement> computeAllSubtypes(ClassElement classElement) {
13400 // Ensure that we have generated the subtype map for the library 13486 // Ensure that we have generated the subtype map for the library
13401 computeSubtypesInLibrary(classElement.library); 13487 computeSubtypesInLibrary(classElement.library);
13402 // use the subtypeMap to compute the set of all subtypes and subtype's subty pes 13488 // use the subtypeMap to compute the set of all subtypes and subtype's subty pes
13403 Set<ClassElement> allSubtypes = new Set<ClassElement>(); 13489 Set<ClassElement> allSubtypes = new Set<ClassElement>();
13404 computeAllSubtypes2(classElement, new Set<ClassElement>(), allSubtypes); 13490 safelyComputeAllSubtypes(classElement, new Set<ClassElement>(), allSubtypes) ;
13405 return allSubtypes; 13491 return allSubtypes;
13406 } 13492 }
13407 13493
13408 /** 13494 /**
13409 * Given some [LibraryElement], visit all of the types in the library, the pas sed library, 13495 * Given some [LibraryElement], visit all of the types in the library, the pas sed library,
13410 * and any imported libraries, will be in the [visitedLibraries] set. 13496 * and any imported libraries, will be in the [visitedLibraries] set.
13411 * 13497 *
13412 * @param libraryElement the library to visit, it it hasn't been visited alrea dy 13498 * @param libraryElement the library to visit, it it hasn't been visited alrea dy
13413 */ 13499 */
13414 void ensureLibraryVisited(LibraryElement libraryElement) { 13500 void ensureLibraryVisited(LibraryElement libraryElement) {
13415 computeSubtypesInLibrary(libraryElement); 13501 computeSubtypesInLibrary(libraryElement);
13416 } 13502 }
13417 13503
13418 /** 13504 /**
13419 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively
13420 * adds all of the subtypes of the [ClassElement] to the passed array.
13421 *
13422 * @param classElement the type to compute the set of subtypes of
13423 * @param visitedClasses the set of class elements that this method has alread y recursively seen
13424 * @param allSubtypes the computed set of subtypes of the passed class element
13425 */
13426 void computeAllSubtypes2(ClassElement classElement, Set<ClassElement> visitedC lasses, Set<ClassElement> allSubtypes) {
13427 if (!visitedClasses.add(classElement)) {
13428 // if this class has already been called on this class element
13429 return;
13430 }
13431 Set<ClassElement> subtypes = _subtypeMap[classElement];
13432 if (subtypes == null) {
13433 return;
13434 }
13435 for (ClassElement subtype in subtypes) {
13436 computeAllSubtypes2(subtype, visitedClasses, allSubtypes);
13437 }
13438 allSubtypes.addAll(subtypes);
13439 }
13440
13441 /**
13442 * Given some [ClassElement], this method adds all of the pairs combinations o f itself and 13505 * Given some [ClassElement], this method adds all of the pairs combinations o f itself and
13443 * all of its supertypes to the [subtypeMap] map. 13506 * all of its supertypes to the [subtypeMap] map.
13444 * 13507 *
13445 * @param classElement the class element 13508 * @param classElement the class element
13446 */ 13509 */
13447 void computeSubtypesInClass(ClassElement classElement) { 13510 void computeSubtypesInClass(ClassElement classElement) {
13448 InterfaceType supertypeType = classElement.supertype; 13511 InterfaceType supertypeType = classElement.supertype;
13449 if (supertypeType != null) { 13512 if (supertypeType != null) {
13450 ClassElement supertypeElement = supertypeType.element; 13513 ClassElement supertypeElement = supertypeType.element;
13451 if (supertypeElement != null) { 13514 if (supertypeElement != null) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
13517 * @param subtypeElement the value for the [subtypeMap] map 13580 * @param subtypeElement the value for the [subtypeMap] map
13518 */ 13581 */
13519 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) { 13582 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) {
13520 Set<ClassElement> subtypes = _subtypeMap[supertypeElement]; 13583 Set<ClassElement> subtypes = _subtypeMap[supertypeElement];
13521 if (subtypes == null) { 13584 if (subtypes == null) {
13522 subtypes = new Set<ClassElement>(); 13585 subtypes = new Set<ClassElement>();
13523 _subtypeMap[supertypeElement] = subtypes; 13586 _subtypeMap[supertypeElement] = subtypes;
13524 } 13587 }
13525 subtypes.add(subtypeElement); 13588 subtypes.add(subtypeElement);
13526 } 13589 }
13590
13591 /**
13592 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively
13593 * adds all of the subtypes of the [ClassElement] to the passed array.
13594 *
13595 * @param classElement the type to compute the set of subtypes of
13596 * @param visitedClasses the set of class elements that this method has alread y recursively seen
13597 * @param allSubtypes the computed set of subtypes of the passed class element
13598 */
13599 void safelyComputeAllSubtypes(ClassElement classElement, Set<ClassElement> vis itedClasses, Set<ClassElement> allSubtypes) {
13600 if (!visitedClasses.add(classElement)) {
13601 // if this class has already been called on this class element
13602 return;
13603 }
13604 Set<ClassElement> subtypes = _subtypeMap[classElement];
13605 if (subtypes == null) {
13606 return;
13607 }
13608 for (ClassElement subtype in subtypes) {
13609 safelyComputeAllSubtypes(subtype, visitedClasses, allSubtypes);
13610 }
13611 allSubtypes.addAll(subtypes);
13612 }
13527 } 13613 }
13528 13614
13529 /** 13615 /**
13530 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an 13616 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an
13531 * element within a given context. 13617 * element within a given context.
13532 */ 13618 */
13533 class TypeOverrideManager { 13619 class TypeOverrideManager {
13534 /** 13620 /**
13535 * The current override scope, or `null` if no scope has been entered. 13621 * The current override scope, or `null` if no scope has been entered.
13536 */ 13622 */
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
14222 super.visitCatchClause(node); 14308 super.visitCatchClause(node);
14223 SimpleIdentifier exception = node.exceptionParameter; 14309 SimpleIdentifier exception = node.exceptionParameter;
14224 if (exception != null) { 14310 if (exception != null) {
14225 // If an 'on' clause is provided the type of the exception parameter is th e type in the 'on' 14311 // If an 'on' clause is provided the type of the exception parameter is th e type in the 'on'
14226 // clause. Otherwise, the type of the exception parameter is 'Object'. 14312 // clause. Otherwise, the type of the exception parameter is 'Object'.
14227 TypeName exceptionTypeName = node.exceptionType; 14313 TypeName exceptionTypeName = node.exceptionType;
14228 Type2 exceptionType; 14314 Type2 exceptionType;
14229 if (exceptionTypeName == null) { 14315 if (exceptionTypeName == null) {
14230 exceptionType = typeProvider.dynamicType; 14316 exceptionType = typeProvider.dynamicType;
14231 } else { 14317 } else {
14232 exceptionType = getType3(exceptionTypeName); 14318 exceptionType = getType(exceptionTypeName);
14233 } 14319 }
14234 recordType(exception, exceptionType); 14320 recordType(exception, exceptionType);
14235 Element element = exception.staticElement; 14321 Element element = exception.staticElement;
14236 if (element is VariableElementImpl) { 14322 if (element is VariableElementImpl) {
14237 element.type = exceptionType; 14323 element.type = exceptionType;
14238 } else { 14324 } else {
14239 } 14325 }
14240 } 14326 }
14241 SimpleIdentifier stackTrace = node.stackTraceParameter; 14327 SimpleIdentifier stackTrace = node.stackTraceParameter;
14242 if (stackTrace != null) { 14328 if (stackTrace != null) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
14316 return null; 14402 return null;
14317 } 14403 }
14318 14404
14319 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 14405 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
14320 super.visitDeclaredIdentifier(node); 14406 super.visitDeclaredIdentifier(node);
14321 Type2 declaredType; 14407 Type2 declaredType;
14322 TypeName typeName = node.type; 14408 TypeName typeName = node.type;
14323 if (typeName == null) { 14409 if (typeName == null) {
14324 declaredType = _dynamicType; 14410 declaredType = _dynamicType;
14325 } else { 14411 } else {
14326 declaredType = getType3(typeName); 14412 declaredType = getType(typeName);
14327 } 14413 }
14328 LocalVariableElementImpl element = node.element as LocalVariableElementImpl; 14414 LocalVariableElementImpl element = node.element as LocalVariableElementImpl;
14329 element.type = declaredType; 14415 element.type = declaredType;
14330 return null; 14416 return null;
14331 } 14417 }
14332 14418
14333 Object visitFieldFormalParameter(FieldFormalParameter node) { 14419 Object visitFieldFormalParameter(FieldFormalParameter node) {
14334 super.visitFieldFormalParameter(node); 14420 super.visitFieldFormalParameter(node);
14335 Element element = node.identifier.staticElement; 14421 Element element = node.identifier.staticElement;
14336 if (element is ParameterElementImpl) { 14422 if (element is ParameterElementImpl) {
14337 ParameterElementImpl parameter = element; 14423 ParameterElementImpl parameter = element;
14338 FormalParameterList parameterList = node.parameters; 14424 FormalParameterList parameterList = node.parameters;
14339 if (parameterList == null) { 14425 if (parameterList == null) {
14340 Type2 type; 14426 Type2 type;
14341 TypeName typeName = node.type; 14427 TypeName typeName = node.type;
14342 if (typeName == null) { 14428 if (typeName == null) {
14343 type = _dynamicType; 14429 type = _dynamicType;
14344 if (parameter is FieldFormalParameterElement) { 14430 if (parameter is FieldFormalParameterElement) {
14345 FieldElement fieldElement = (parameter as FieldFormalParameterElemen t).field; 14431 FieldElement fieldElement = (parameter as FieldFormalParameterElemen t).field;
14346 if (fieldElement != null) { 14432 if (fieldElement != null) {
14347 type = fieldElement.type; 14433 type = fieldElement.type;
14348 } 14434 }
14349 } 14435 }
14350 } else { 14436 } else {
14351 type = getType3(typeName); 14437 type = getType(typeName);
14352 } 14438 }
14353 parameter.type = type; 14439 parameter.type = type;
14354 } else { 14440 } else {
14355 setFunctionTypedParameterType(parameter, node.type, node.parameters); 14441 setFunctionTypedParameterType(parameter, node.type, node.parameters);
14356 } 14442 }
14357 } else { 14443 } else {
14358 } 14444 }
14359 return null; 14445 return null;
14360 } 14446 }
14361 14447
14362 Object visitFunctionDeclaration(FunctionDeclaration node) { 14448 Object visitFunctionDeclaration(FunctionDeclaration node) {
14363 super.visitFunctionDeclaration(node); 14449 super.visitFunctionDeclaration(node);
14364 ExecutableElementImpl element = node.element as ExecutableElementImpl; 14450 ExecutableElementImpl element = node.element as ExecutableElementImpl;
14365 element.returnType = computeReturnType(node.returnType); 14451 element.returnType = computeReturnType(node.returnType);
14366 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 14452 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
14367 ClassElement definingClass = element.getAncestor(ClassElement); 14453 ClassElement definingClass = element.getAncestor((element) => element is Cla ssElement);
14368 if (definingClass != null) { 14454 if (definingClass != null) {
14369 type.typeArguments = definingClass.type.typeArguments; 14455 type.typeArguments = definingClass.type.typeArguments;
14370 } 14456 }
14371 element.type = type; 14457 element.type = type;
14372 return null; 14458 return null;
14373 } 14459 }
14374 14460
14375 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 14461 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
14376 super.visitFunctionTypeAlias(node); 14462 super.visitFunctionTypeAlias(node);
14377 FunctionTypeAliasElementImpl element = node.element as FunctionTypeAliasElem entImpl; 14463 FunctionTypeAliasElementImpl element = node.element as FunctionTypeAliasElem entImpl;
14378 element.returnType = computeReturnType(node.returnType); 14464 element.returnType = computeReturnType(node.returnType);
14379 return null; 14465 return null;
14380 } 14466 }
14381 14467
14382 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 14468 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
14383 super.visitFunctionTypedFormalParameter(node); 14469 super.visitFunctionTypedFormalParameter(node);
14384 Element element = node.identifier.staticElement; 14470 Element element = node.identifier.staticElement;
14385 if (element is ParameterElementImpl) { 14471 if (element is ParameterElementImpl) {
14386 setFunctionTypedParameterType(element, node.returnType, node.parameters); 14472 setFunctionTypedParameterType(element, node.returnType, node.parameters);
14387 } else { 14473 } else {
14388 } 14474 }
14389 return null; 14475 return null;
14390 } 14476 }
14391 14477
14392 Object visitMethodDeclaration(MethodDeclaration node) { 14478 Object visitMethodDeclaration(MethodDeclaration node) {
14393 super.visitMethodDeclaration(node); 14479 super.visitMethodDeclaration(node);
14394 ExecutableElementImpl element = node.element as ExecutableElementImpl; 14480 ExecutableElementImpl element = node.element as ExecutableElementImpl;
14395 element.returnType = computeReturnType(node.returnType); 14481 element.returnType = computeReturnType(node.returnType);
14396 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 14482 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
14397 ClassElement definingClass = element.getAncestor(ClassElement); 14483 ClassElement definingClass = element.getAncestor((element) => element is Cla ssElement);
14398 if (definingClass != null) { 14484 if (definingClass != null) {
14399 type.typeArguments = definingClass.type.typeArguments; 14485 type.typeArguments = definingClass.type.typeArguments;
14400 } 14486 }
14401 element.type = type; 14487 element.type = type;
14402 if (element is PropertyAccessorElement) { 14488 if (element is PropertyAccessorElement) {
14403 PropertyAccessorElement accessor = element as PropertyAccessorElement; 14489 PropertyAccessorElement accessor = element as PropertyAccessorElement;
14404 PropertyInducingElementImpl variable = accessor.variable as PropertyInduci ngElementImpl; 14490 PropertyInducingElementImpl variable = accessor.variable as PropertyInduci ngElementImpl;
14405 if (accessor.isGetter) { 14491 if (accessor.isGetter) {
14406 variable.type = type.returnType; 14492 variable.type = type.returnType;
14407 } else if (variable.type == null) { 14493 } else if (variable.type == null) {
14408 List<Type2> parameterTypes = type.normalParameterTypes; 14494 List<Type2> parameterTypes = type.normalParameterTypes;
14409 if (parameterTypes != null && parameterTypes.length > 0) { 14495 if (parameterTypes != null && parameterTypes.length > 0) {
14410 variable.type = parameterTypes[0]; 14496 variable.type = parameterTypes[0];
14411 } 14497 }
14412 } 14498 }
14413 } 14499 }
14414 return null; 14500 return null;
14415 } 14501 }
14416 14502
14417 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 14503 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
14418 super.visitSimpleFormalParameter(node); 14504 super.visitSimpleFormalParameter(node);
14419 Type2 declaredType; 14505 Type2 declaredType;
14420 TypeName typeName = node.type; 14506 TypeName typeName = node.type;
14421 if (typeName == null) { 14507 if (typeName == null) {
14422 declaredType = _dynamicType; 14508 declaredType = _dynamicType;
14423 } else { 14509 } else {
14424 declaredType = getType3(typeName); 14510 declaredType = getType(typeName);
14425 } 14511 }
14426 Element element = node.identifier.staticElement; 14512 Element element = node.identifier.staticElement;
14427 if (element is ParameterElement) { 14513 if (element is ParameterElement) {
14428 (element as ParameterElementImpl).type = declaredType; 14514 (element as ParameterElementImpl).type = declaredType;
14429 } else { 14515 } else {
14430 } 14516 }
14431 return null; 14517 return null;
14432 } 14518 }
14433 14519
14434 Object visitSuperExpression(SuperExpression node) { 14520 Object visitSuperExpression(SuperExpression node) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
14471 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen tList == null) { 14557 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen tList == null) {
14472 ConstructorName name = parent; 14558 ConstructorName name = parent;
14473 if (name.name == null) { 14559 if (name.name == null) {
14474 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier ; 14560 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier ;
14475 SimpleIdentifier prefix = prefixedIdentifier.prefix; 14561 SimpleIdentifier prefix = prefixedIdentifier.prefix;
14476 element = nameScope.lookup(prefix, definingLibrary); 14562 element = nameScope.lookup(prefix, definingLibrary);
14477 if (element is PrefixElement) { 14563 if (element is PrefixElement) {
14478 if (parent.parent is InstanceCreationExpression && (parent.parent as InstanceCreationExpression).isConst) { 14564 if (parent.parent is InstanceCreationExpression && (parent.parent as InstanceCreationExpression).isConst) {
14479 // If, if this is a const expression, then generate a 14565 // If, if this is a const expression, then generate a
14480 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. 14566 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
14481 reportError9(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde ntifier.identifier, [prefixedIdentifier.identifier.name]); 14567 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefi xedIdentifier.identifier, [prefixedIdentifier.identifier.name]);
14482 } else { 14568 } else {
14483 // Else, if this expression is a new expression, report a NEW_WITH _NON_TYPE warning. 14569 // Else, if this expression is a new expression, report a NEW_WITH _NON_TYPE warning.
14484 reportError9(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi er.identifier, [prefixedIdentifier.identifier.name]); 14570 reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedId entifier.identifier, [prefixedIdentifier.identifier.name]);
14485 } 14571 }
14486 setElement(prefix, element); 14572 setElement(prefix, element);
14487 return null; 14573 return null;
14488 } else if (element != null) { 14574 } else if (element != null) {
14489 // 14575 //
14490 // Rewrite the constructor name. The parser, when it sees a construc tor named "a.b", 14576 // Rewrite the constructor name. The parser, when it sees a construc tor named "a.b",
14491 // cannot tell whether "a" is a prefix and "b" is a class name, or w hether "a" is a 14577 // cannot tell whether "a" is a prefix and "b" is a class name, or w hether "a" is a
14492 // class name and "b" is a constructor name. It arbitrarily chooses the former, but 14578 // class name and "b" is a constructor name. It arbitrarily chooses the former, but
14493 // in this case was wrong. 14579 // in this case was wrong.
14494 // 14580 //
14495 name.name = prefixedIdentifier.identifier; 14581 name.name = prefixedIdentifier.identifier;
14496 name.period = prefixedIdentifier.period; 14582 name.period = prefixedIdentifier.period;
14497 node.name = prefix; 14583 node.name = prefix;
14498 typeName = prefix; 14584 typeName = prefix;
14499 } 14585 }
14500 } 14586 }
14501 } 14587 }
14502 } 14588 }
14503 // check element 14589 // check element
14504 bool elementValid = element is! MultiplyDefinedElement; 14590 bool elementValid = element is! MultiplyDefinedElement;
14505 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation Expression(node)) { 14591 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation Expression(node)) {
14506 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); 14592 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
14507 InstanceCreationExpression creation = node.parent.parent as InstanceCreati onExpression; 14593 InstanceCreationExpression creation = node.parent.parent as InstanceCreati onExpression;
14508 if (creation.isConst) { 14594 if (creation.isConst) {
14509 if (element == null) { 14595 if (element == null) {
14510 reportError9(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty peName]); 14596 reportErrorForNode(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimpl e, [typeName]);
14511 } else { 14597 } else {
14512 reportError9(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, [typeName]); 14598 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameS imple, [typeName]);
14513 } 14599 }
14514 elementValid = false; 14600 elementValid = false;
14515 } else { 14601 } else {
14516 if (element != null) { 14602 if (element != null) {
14517 reportError9(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ eName]); 14603 reportErrorForNode(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple , [typeName]);
14518 elementValid = false; 14604 elementValid = false;
14519 } 14605 }
14520 } 14606 }
14521 } 14607 }
14522 if (elementValid && element == null) { 14608 if (elementValid && element == null) {
14523 // We couldn't resolve the type name. 14609 // We couldn't resolve the type name.
14524 // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN _IDENTIFIER_AS_TYPE 14610 // TODO(jwren) Consider moving the check for CompileTimeErrorCode.BUILT_IN _IDENTIFIER_AS_TYPE
14525 // from the ErrorVerifier, so that we don't have two errors on a built in identifier being 14611 // from the ErrorVerifier, so that we don't have two errors on a built in identifier being
14526 // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifi erAsType(). 14612 // used as a class name. See CompileTimeErrorCodeTest.test_builtInIdentifi erAsType().
14527 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); 14613 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
14528 RedirectingConstructorKind redirectingConstructorKind; 14614 RedirectingConstructorKind redirectingConstructorKind;
14529 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) { 14615 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) {
14530 reportError9(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName, [typeName.name]); 14616 reportErrorForNode(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typ eName, [typeName.name]);
14531 } else if (typeNameSimple.name == "boolean") { 14617 } else if (typeNameSimple.name == "boolean") {
14532 reportError9(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []); 14618 reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSi mple, []);
14533 } else if (isTypeNameInCatchClause(node)) { 14619 } else if (isTypeNameInCatchClause(node)) {
14534 reportError9(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]); 14620 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeName.name]);
14535 } else if (isTypeNameInAsExpression(node)) { 14621 } else if (isTypeNameInAsExpression(node)) {
14536 reportError9(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]); 14622 reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeNa me.name]);
14537 } else if (isTypeNameInIsExpression(node)) { 14623 } else if (isTypeNameInIsExpression(node)) {
14538 reportError9(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]); 14624 reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [type Name.name]);
14539 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) { 14625 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) {
14540 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 14626 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode;
14541 reportError9(errorCode, typeName, [typeName.name]); 14627 reportErrorForNode(errorCode, typeName, [typeName.name]);
14542 } else if (isTypeNameInTypeArgumentList(node)) { 14628 } else if (isTypeNameInTypeArgumentList(node)) {
14543 reportError9(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]); 14629 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, type Name, [typeName.name]);
14544 } else { 14630 } else {
14545 reportError9(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name ]); 14631 reportErrorForNode(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeNam e.name]);
14546 } 14632 }
14547 elementValid = false; 14633 elementValid = false;
14548 } 14634 }
14549 if (!elementValid) { 14635 if (!elementValid) {
14550 if (element is MultiplyDefinedElement) { 14636 if (element is MultiplyDefinedElement) {
14551 setElement(typeName, element); 14637 setElement(typeName, element);
14552 } else { 14638 } else {
14553 setElement(typeName, this._dynamicType.element); 14639 setElement(typeName, this._dynamicType.element);
14554 } 14640 }
14555 typeName.staticType = this._dynamicType; 14641 typeName.staticType = this._dynamicType;
14556 node.type = this._dynamicType; 14642 node.type = this._dynamicType;
14557 return null; 14643 return null;
14558 } 14644 }
14559 Type2 type = null; 14645 Type2 type = null;
14560 if (element is ClassElement) { 14646 if (element is ClassElement) {
14561 setElement(typeName, element); 14647 setElement(typeName, element);
14562 type = (element as ClassElement).type; 14648 type = (element as ClassElement).type;
14563 } else if (element is FunctionTypeAliasElement) { 14649 } else if (element is FunctionTypeAliasElement) {
14564 setElement(typeName, element); 14650 setElement(typeName, element);
14565 type = (element as FunctionTypeAliasElement).type; 14651 type = (element as FunctionTypeAliasElement).type;
14566 } else if (element is TypeParameterElement) { 14652 } else if (element is TypeParameterElement) {
14567 setElement(typeName, element); 14653 setElement(typeName, element);
14568 type = (element as TypeParameterElement).type; 14654 type = (element as TypeParameterElement).type;
14569 if (argumentList != null) { 14655 if (argumentList != null) {
14570 } 14656 }
14571 } else if (element is MultiplyDefinedElement) { 14657 } else if (element is MultiplyDefinedElement) {
14572 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl ements; 14658 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl ements;
14573 type = getType(elements); 14659 type = getTypeWhenMultiplyDefined(elements);
14574 if (type != null) { 14660 if (type != null) {
14575 node.type = type; 14661 node.type = type;
14576 } 14662 }
14577 } else { 14663 } else {
14578 // The name does not represent a type. 14664 // The name does not represent a type.
14579 RedirectingConstructorKind redirectingConstructorKind; 14665 RedirectingConstructorKind redirectingConstructorKind;
14580 if (isTypeNameInCatchClause(node)) { 14666 if (isTypeNameInCatchClause(node)) {
14581 reportError9(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]); 14667 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [typeName.name]);
14582 } else if (isTypeNameInAsExpression(node)) { 14668 } else if (isTypeNameInAsExpression(node)) {
14583 reportError9(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]); 14669 reportErrorForNode(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeNa me.name]);
14584 } else if (isTypeNameInIsExpression(node)) { 14670 } else if (isTypeNameInIsExpression(node)) {
14585 reportError9(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]); 14671 reportErrorForNode(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [type Name.name]);
14586 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) { 14672 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) {
14587 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 14673 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode;
14588 reportError9(errorCode, typeName, [typeName.name]); 14674 reportErrorForNode(errorCode, typeName, [typeName.name]);
14589 } else if (isTypeNameInTypeArgumentList(node)) { 14675 } else if (isTypeNameInTypeArgumentList(node)) {
14590 reportError9(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]); 14676 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, type Name, [typeName.name]);
14591 } else { 14677 } else {
14592 AstNode parent = typeName.parent; 14678 AstNode parent = typeName.parent;
14593 while (parent is TypeName) { 14679 while (parent is TypeName) {
14594 parent = parent.parent; 14680 parent = parent.parent;
14595 } 14681 }
14596 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) { 14682 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) {
14597 } else { 14683 } else {
14598 reportError9(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); 14684 reportErrorForNode(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.n ame]);
14599 } 14685 }
14600 } 14686 }
14601 setElement(typeName, this._dynamicType.element); 14687 setElement(typeName, this._dynamicType.element);
14602 typeName.staticType = this._dynamicType; 14688 typeName.staticType = this._dynamicType;
14603 node.type = this._dynamicType; 14689 node.type = this._dynamicType;
14604 return null; 14690 return null;
14605 } 14691 }
14606 if (argumentList != null) { 14692 if (argumentList != null) {
14607 NodeList<TypeName> arguments = argumentList.arguments; 14693 NodeList<TypeName> arguments = argumentList.arguments;
14608 int argumentCount = arguments.length; 14694 int argumentCount = arguments.length;
14609 List<Type2> parameters = getTypeArguments(type); 14695 List<Type2> parameters = getTypeArguments(type);
14610 int parameterCount = parameters.length; 14696 int parameterCount = parameters.length;
14611 int count = Math.min(argumentCount, parameterCount); 14697 int count = Math.min(argumentCount, parameterCount);
14612 List<Type2> typeArguments = new List<Type2>(); 14698 List<Type2> typeArguments = new List<Type2>();
14613 for (int i = 0; i < count; i++) { 14699 for (int i = 0; i < count; i++) {
14614 Type2 argumentType = getType3(arguments[i]); 14700 Type2 argumentType = getType(arguments[i]);
14615 if (argumentType != null) { 14701 if (argumentType != null) {
14616 typeArguments.add(argumentType); 14702 typeArguments.add(argumentType);
14617 } 14703 }
14618 } 14704 }
14619 if (argumentCount != parameterCount) { 14705 if (argumentCount != parameterCount) {
14620 reportError9(getInvalidTypeParametersErrorCode(node), node, [typeName.na me, parameterCount, argumentCount]); 14706 reportErrorForNode(getInvalidTypeParametersErrorCode(node), node, [typeN ame.name, parameterCount, argumentCount]);
14621 } 14707 }
14622 argumentCount = typeArguments.length; 14708 argumentCount = typeArguments.length;
14623 if (argumentCount < parameterCount) { 14709 if (argumentCount < parameterCount) {
14624 // 14710 //
14625 // If there were too many arguments, we already handled it by not adding the values of the 14711 // If there were too many arguments, we already handled it by not adding the values of the
14626 // extra arguments to the list. If there are too few, we handle it by ad ding 'dynamic' 14712 // extra arguments to the list. If there are too few, we handle it by ad ding 'dynamic'
14627 // enough times to make the count equal. 14713 // enough times to make the count equal.
14628 // 14714 //
14629 for (int i = argumentCount; i < parameterCount; i++) { 14715 for (int i = argumentCount; i < parameterCount; i++) {
14630 typeArguments.add(this._dynamicType); 14716 typeArguments.add(this._dynamicType);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
14670 return null; 14756 return null;
14671 } 14757 }
14672 14758
14673 Object visitVariableDeclaration(VariableDeclaration node) { 14759 Object visitVariableDeclaration(VariableDeclaration node) {
14674 super.visitVariableDeclaration(node); 14760 super.visitVariableDeclaration(node);
14675 Type2 declaredType; 14761 Type2 declaredType;
14676 TypeName typeName = (node.parent as VariableDeclarationList).type; 14762 TypeName typeName = (node.parent as VariableDeclarationList).type;
14677 if (typeName == null) { 14763 if (typeName == null) {
14678 declaredType = _dynamicType; 14764 declaredType = _dynamicType;
14679 } else { 14765 } else {
14680 declaredType = getType3(typeName); 14766 declaredType = getType(typeName);
14681 } 14767 }
14682 Element element = node.name.staticElement; 14768 Element element = node.name.staticElement;
14683 if (element is VariableElement) { 14769 if (element is VariableElement) {
14684 (element as VariableElementImpl).type = declaredType; 14770 (element as VariableElementImpl).type = declaredType;
14685 if (element is PropertyInducingElement) { 14771 if (element is PropertyInducingElement) {
14686 PropertyInducingElement variableElement = element; 14772 PropertyInducingElement variableElement = element;
14687 PropertyAccessorElementImpl getter = variableElement.getter as PropertyA ccessorElementImpl; 14773 PropertyAccessorElementImpl getter = variableElement.getter as PropertyA ccessorElementImpl;
14688 getter.returnType = declaredType; 14774 getter.returnType = declaredType;
14689 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); 14775 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
14690 ClassElement definingClass = element.getAncestor(ClassElement); 14776 ClassElement definingClass = element.getAncestor((element) => element is ClassElement);
14691 if (definingClass != null) { 14777 if (definingClass != null) {
14692 getterType.typeArguments = definingClass.type.typeArguments; 14778 getterType.typeArguments = definingClass.type.typeArguments;
14693 } 14779 }
14694 getter.type = getterType; 14780 getter.type = getterType;
14695 PropertyAccessorElementImpl setter = variableElement.setter as PropertyA ccessorElementImpl; 14781 PropertyAccessorElementImpl setter = variableElement.setter as PropertyA ccessorElementImpl;
14696 if (setter != null) { 14782 if (setter != null) {
14697 List<ParameterElement> parameters = setter.parameters; 14783 List<ParameterElement> parameters = setter.parameters;
14698 if (parameters.length > 0) { 14784 if (parameters.length > 0) {
14699 (parameters[0] as ParameterElementImpl).type = declaredType; 14785 (parameters[0] as ParameterElementImpl).type = declaredType;
14700 } 14786 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
14890 return RedirectingConstructorKind.CONST; 14976 return RedirectingConstructorKind.CONST;
14891 } 14977 }
14892 return RedirectingConstructorKind.NORMAL; 14978 return RedirectingConstructorKind.NORMAL;
14893 } 14979 }
14894 } 14980 }
14895 } 14981 }
14896 return null; 14982 return null;
14897 } 14983 }
14898 14984
14899 /** 14985 /**
14900 * Given the multiple elements to which a single name could potentially be res olved, return the
14901 * single interface type that should be used, or `null` if there is no clear c hoice.
14902 *
14903 * @param elements the elements to which a single name could potentially be re solved
14904 * @return the single interface type that should be used for the type name
14905 */
14906 InterfaceType getType(List<Element> elements) {
14907 InterfaceType type = null;
14908 for (Element element in elements) {
14909 if (element is ClassElement) {
14910 if (type != null) {
14911 return null;
14912 }
14913 type = element.type;
14914 }
14915 }
14916 return type;
14917 }
14918
14919 /**
14920 * Return the type represented by the given type name. 14986 * Return the type represented by the given type name.
14921 * 14987 *
14922 * @param typeName the type name representing the type to be returned 14988 * @param typeName the type name representing the type to be returned
14923 * @return the type represented by the type name 14989 * @return the type represented by the type name
14924 */ 14990 */
14925 Type2 getType3(TypeName typeName) { 14991 Type2 getType(TypeName typeName) {
14926 Type2 type = typeName.type; 14992 Type2 type = typeName.type;
14927 if (type == null) { 14993 if (type == null) {
14928 return _dynamicType; 14994 return _dynamicType;
14929 } 14995 }
14930 return type; 14996 return type;
14931 } 14997 }
14932 14998
14933 /** 14999 /**
14934 * Return the type arguments associated with the given type. 15000 * Return the type arguments associated with the given type.
14935 * 15001 *
(...skipping 17 matching lines...) Expand all
14953 */ 15019 */
14954 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { 15020 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) {
14955 if (typeName is SimpleIdentifier) { 15021 if (typeName is SimpleIdentifier) {
14956 return typeName; 15022 return typeName;
14957 } else { 15023 } else {
14958 return (typeName as PrefixedIdentifier).identifier; 15024 return (typeName as PrefixedIdentifier).identifier;
14959 } 15025 }
14960 } 15026 }
14961 15027
14962 /** 15028 /**
15029 * Given the multiple elements to which a single name could potentially be res olved, return the
15030 * single interface type that should be used, or `null` if there is no clear c hoice.
15031 *
15032 * @param elements the elements to which a single name could potentially be re solved
15033 * @return the single interface type that should be used for the type name
15034 */
15035 InterfaceType getTypeWhenMultiplyDefined(List<Element> elements) {
15036 InterfaceType type = null;
15037 for (Element element in elements) {
15038 if (element is ClassElement) {
15039 if (type != null) {
15040 return null;
15041 }
15042 type = element.type;
15043 }
15044 }
15045 return type;
15046 }
15047
15048 /**
14963 * Checks if the given type name is used as the type in an as expression. 15049 * Checks if the given type name is used as the type in an as expression.
14964 * 15050 *
14965 * @param typeName the type name to analyzer 15051 * @param typeName the type name to analyzer
14966 * @return `true` if the given type name is used as the type in an as expressi on 15052 * @return `true` if the given type name is used as the type in an as expressi on
14967 */ 15053 */
14968 bool isTypeNameInAsExpression(TypeName typeName) { 15054 bool isTypeNameInAsExpression(TypeName typeName) {
14969 AstNode parent = typeName.parent; 15055 AstNode parent = typeName.parent;
14970 if (parent is AsExpression) { 15056 if (parent is AsExpression) {
14971 AsExpression asExpression = parent; 15057 AsExpression asExpression = parent;
14972 return identical(asExpression.type, typeName); 15058 return identical(asExpression.type, typeName);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
15075 TypeName typeName = typeNames[i]; 15161 TypeName typeName = typeNames[i];
15076 if (!detectedRepeatOnIndex[i]) { 15162 if (!detectedRepeatOnIndex[i]) {
15077 Element element = typeName.name.staticElement; 15163 Element element = typeName.name.staticElement;
15078 for (int j = i + 1; j < typeNames.length; j++) { 15164 for (int j = i + 1; j < typeNames.length; j++) {
15079 TypeName typeName2 = typeNames[j]; 15165 TypeName typeName2 = typeNames[j];
15080 Identifier identifier2 = typeName2.name; 15166 Identifier identifier2 = typeName2.name;
15081 String name2 = identifier2.name; 15167 String name2 = identifier2.name;
15082 Element element2 = identifier2.staticElement; 15168 Element element2 = identifier2.staticElement;
15083 if (element != null && element == element2) { 15169 if (element != null && element == element2) {
15084 detectedRepeatOnIndex[j] = true; 15170 detectedRepeatOnIndex[j] = true;
15085 reportError9(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]); 15171 reportErrorForNode(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeN ame2, [name2]);
15086 } 15172 }
15087 } 15173 }
15088 } 15174 }
15089 } 15175 }
15090 } 15176 }
15091 } 15177 }
15092 15178
15093 /** 15179 /**
15094 * Return the type specified by the given name. 15180 * Return the type specified by the given name.
15095 * 15181 *
15096 * @param typeName the type name specifying the type to be returned 15182 * @param typeName the type name specifying the type to be returned
15097 * @param nonTypeError the error to produce if the type name is defined to be something other than 15183 * @param nonTypeError the error to produce if the type name is defined to be something other than
15098 * a type 15184 * a type
15099 * @param dynamicTypeError the error to produce if the type name is "dynamic" 15185 * @param dynamicTypeError the error to produce if the type name is "dynamic"
15100 * @return the type specified by the type name 15186 * @return the type specified by the type name
15101 */ 15187 */
15102 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode dynamicTypeError) { 15188 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode dynamicTypeError) {
15103 Type2 type = typeName.type; 15189 Type2 type = typeName.type;
15104 if (type is InterfaceType) { 15190 if (type is InterfaceType) {
15105 return type; 15191 return type;
15106 } 15192 }
15107 // If the type is not an InterfaceType, then visitTypeName() sets the type t o be a DynamicTypeImpl 15193 // If the type is not an InterfaceType, then visitTypeName() sets the type t o be a DynamicTypeImpl
15108 Identifier name = typeName.name; 15194 Identifier name = typeName.name;
15109 if (name.name == sc.Keyword.DYNAMIC.syntax) { 15195 if (name.name == sc.Keyword.DYNAMIC.syntax) {
15110 reportError9(dynamicTypeError, name, [name.name]); 15196 reportErrorForNode(dynamicTypeError, name, [name.name]);
15111 } else { 15197 } else {
15112 reportError9(nonTypeError, name, [name.name]); 15198 reportErrorForNode(nonTypeError, name, [name.name]);
15113 } 15199 }
15114 return null; 15200 return null;
15115 } 15201 }
15116 15202
15117 /** 15203 /**
15118 * Resolve the types in the given list of type names. 15204 * Resolve the types in the given list of type names.
15119 * 15205 *
15120 * @param typeNames the type names to be resolved 15206 * @param typeNames the type names to be resolved
15121 * @param nonTypeError the error to produce if the type name is defined to be something other than 15207 * @param nonTypeError the error to produce if the type name is defined to be something other than
15122 * a type 15208 * a type
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
15158 * @param returnType the (possibly `null`) return type of the function 15244 * @param returnType the (possibly `null`) return type of the function
15159 * @param parameterList the list of parameters to the function 15245 * @param parameterList the list of parameters to the function
15160 */ 15246 */
15161 void setFunctionTypedParameterType(ParameterElementImpl element, TypeName retu rnType, FormalParameterList parameterList) { 15247 void setFunctionTypedParameterType(ParameterElementImpl element, TypeName retu rnType, FormalParameterList parameterList) {
15162 List<ParameterElement> parameters = getElements(parameterList); 15248 List<ParameterElement> parameters = getElements(parameterList);
15163 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl (null); 15249 FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl (null);
15164 aliasElement.synthetic = true; 15250 aliasElement.synthetic = true;
15165 aliasElement.shareParameters(parameters); 15251 aliasElement.shareParameters(parameters);
15166 aliasElement.returnType = computeReturnType(returnType); 15252 aliasElement.returnType = computeReturnType(returnType);
15167 FunctionTypeImpl type = new FunctionTypeImpl.con2(aliasElement); 15253 FunctionTypeImpl type = new FunctionTypeImpl.con2(aliasElement);
15168 ClassElement definingClass = element.getAncestor(ClassElement); 15254 ClassElement definingClass = element.getAncestor((element) => element is Cla ssElement);
15169 if (definingClass != null) { 15255 if (definingClass != null) {
15170 aliasElement.shareTypeParameters(definingClass.typeParameters); 15256 aliasElement.shareTypeParameters(definingClass.typeParameters);
15171 type.typeArguments = definingClass.type.typeArguments; 15257 type.typeArguments = definingClass.type.typeArguments;
15172 } else { 15258 } else {
15173 FunctionTypeAliasElement alias = element.getAncestor(FunctionTypeAliasElem ent); 15259 FunctionTypeAliasElement alias = element.getAncestor((element) => element is FunctionTypeAliasElement);
15174 while (alias != null && alias.isSynthetic) { 15260 while (alias != null && alias.isSynthetic) {
15175 alias = alias.getAncestor(FunctionTypeAliasElement); 15261 alias = alias.getAncestor((element) => element is FunctionTypeAliasEleme nt);
15176 } 15262 }
15177 if (alias != null) { 15263 if (alias != null) {
15178 aliasElement.typeParameters = alias.typeParameters; 15264 aliasElement.typeParameters = alias.typeParameters;
15179 type.typeArguments = alias.type.typeArguments; 15265 type.typeArguments = alias.type.typeArguments;
15180 } else { 15266 } else {
15181 type.typeArguments = TypeImpl.EMPTY_ARRAY; 15267 type.typeArguments = TypeImpl.EMPTY_ARRAY;
15182 } 15268 }
15183 } 15269 }
15184 element.type = type; 15270 element.type = type;
15185 } 15271 }
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
16238 AnalysisErrorListener get errorListener; 16324 AnalysisErrorListener get errorListener;
16239 16325
16240 /** 16326 /**
16241 * Return the source that contains the given identifier, or the source associa ted with this scope 16327 * Return the source that contains the given identifier, or the source associa ted with this scope
16242 * if the source containing the identifier could not be determined. 16328 * if the source containing the identifier could not be determined.
16243 * 16329 *
16244 * @param identifier the identifier whose source is to be returned 16330 * @param identifier the identifier whose source is to be returned
16245 * @return the source that contains the given identifier 16331 * @return the source that contains the given identifier
16246 */ 16332 */
16247 Source getSource(AstNode node) { 16333 Source getSource(AstNode node) {
16248 CompilationUnit unit = node.getAncestor(CompilationUnit); 16334 CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit);
16249 if (unit != null) { 16335 if (unit != null) {
16250 CompilationUnitElement unitElement = unit.element; 16336 CompilationUnitElement unitElement = unit.element;
16251 if (unitElement != null) { 16337 if (unitElement != null) {
16252 return unitElement.source; 16338 return unitElement.source;
16253 } 16339 }
16254 } 16340 }
16255 return null; 16341 return null;
16256 } 16342 }
16257 16343
16258 /** 16344 /**
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
16452 } 16538 }
16453 16539
16454 Object visitAnnotation(Annotation node) { 16540 Object visitAnnotation(Annotation node) {
16455 super.visitAnnotation(node); 16541 super.visitAnnotation(node);
16456 // check annotation creation 16542 // check annotation creation
16457 Element element = node.element; 16543 Element element = node.element;
16458 if (element is ConstructorElement) { 16544 if (element is ConstructorElement) {
16459 ConstructorElement constructorElement = element; 16545 ConstructorElement constructorElement = element;
16460 // should 'const' constructor 16546 // should 'const' constructor
16461 if (!constructorElement.isConst) { 16547 if (!constructorElement.isConst) {
16462 _errorReporter.reportError3(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION _CONSTRUCTOR, node, []); 16548 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION _CONSTRUCTOR, node, []);
16463 return null; 16549 return null;
16464 } 16550 }
16465 // should have arguments 16551 // should have arguments
16466 ArgumentList argumentList = node.arguments; 16552 ArgumentList argumentList = node.arguments;
16467 if (argumentList == null) { 16553 if (argumentList == null) {
16468 _errorReporter.reportError3(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCT OR_ARGUMENTS, node, []); 16554 _errorReporter.reportError2(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCT OR_ARGUMENTS, node, []);
16469 return null; 16555 return null;
16470 } 16556 }
16471 // arguments should be constants 16557 // arguments should be constants
16472 validateConstantArguments(argumentList); 16558 validateConstantArguments(argumentList);
16473 } 16559 }
16474 return null; 16560 return null;
16475 } 16561 }
16476 16562
16477 Object visitConstructorDeclaration(ConstructorDeclaration node) { 16563 Object visitConstructorDeclaration(ConstructorDeclaration node) {
16478 if (node.constKeyword != null) { 16564 if (node.constKeyword != null) {
16479 validateInitializers(node); 16565 validateInitializers(node);
16480 } 16566 }
16481 validateDefaultValues(node.parameters); 16567 validateDefaultValues(node.parameters);
16482 return super.visitConstructorDeclaration(node); 16568 return super.visitConstructorDeclaration(node);
16483 } 16569 }
16484 16570
16485 Object visitFunctionExpression(FunctionExpression node) { 16571 Object visitFunctionExpression(FunctionExpression node) {
16486 super.visitFunctionExpression(node); 16572 super.visitFunctionExpression(node);
16487 validateDefaultValues(node.parameters); 16573 validateDefaultValues(node.parameters);
16488 return null; 16574 return null;
16489 } 16575 }
16490 16576
16491 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 16577 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
16492 validateConstantArguments2(node); 16578 validateInstanceCreationArguments(node);
16493 return super.visitInstanceCreationExpression(node); 16579 return super.visitInstanceCreationExpression(node);
16494 } 16580 }
16495 16581
16496 Object visitListLiteral(ListLiteral node) { 16582 Object visitListLiteral(ListLiteral node) {
16497 super.visitListLiteral(node); 16583 super.visitListLiteral(node);
16498 if (node.constKeyword != null) { 16584 if (node.constKeyword != null) {
16499 for (Expression element in node.elements) { 16585 for (Expression element in node.elements) {
16500 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); 16586 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT);
16501 } 16587 }
16502 } 16588 }
(...skipping 28 matching lines...) Expand all
16531 } else { 16617 } else {
16532 keys.add(value); 16618 keys.add(value);
16533 } 16619 }
16534 } else { 16620 } else {
16535 reportEqualKeys = false; 16621 reportEqualKeys = false;
16536 } 16622 }
16537 } 16623 }
16538 } 16624 }
16539 if (reportEqualKeys) { 16625 if (reportEqualKeys) {
16540 for (Expression key in invalidKeys) { 16626 for (Expression key in invalidKeys) {
16541 _errorReporter.reportError3(StaticWarningCode.EQUAL_KEYS_IN_MAP, key, [] ); 16627 _errorReporter.reportError2(StaticWarningCode.EQUAL_KEYS_IN_MAP, key, [] );
16542 } 16628 }
16543 } 16629 }
16544 return null; 16630 return null;
16545 } 16631 }
16546 16632
16547 Object visitMethodDeclaration(MethodDeclaration node) { 16633 Object visitMethodDeclaration(MethodDeclaration node) {
16548 super.visitMethodDeclaration(node); 16634 super.visitMethodDeclaration(node);
16549 validateDefaultValues(node.parameters); 16635 validateDefaultValues(node.parameters);
16550 return null; 16636 return null;
16551 } 16637 }
(...skipping 30 matching lines...) Expand all
16582 * cases, use the given error code rather than the one reported in the error. 16668 * cases, use the given error code rather than the one reported in the error.
16583 * 16669 *
16584 * @param result the result containing any errors that need to be reported 16670 * @param result the result containing any errors that need to be reported
16585 * @param errorCode the error code to be used if the result represents an erro r 16671 * @param errorCode the error code to be used if the result represents an erro r
16586 */ 16672 */
16587 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode) { 16673 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode) {
16588 if (result is ErrorResult) { 16674 if (result is ErrorResult) {
16589 for (ErrorResult_ErrorData data in result.errorData) { 16675 for (ErrorResult_ErrorData data in result.errorData) {
16590 ErrorCode dataErrorCode = data.errorCode; 16676 ErrorCode dataErrorCode = data.errorCode;
16591 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRIN G) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || ide ntical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identical(dat aErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) { 16677 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRIN G) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || ide ntical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identical(dat aErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) {
16592 _errorReporter.reportError3(dataErrorCode, data.node, []); 16678 _errorReporter.reportError2(dataErrorCode, data.node, []);
16593 } else { 16679 } else {
16594 _errorReporter.reportError3(errorCode, data.node, []); 16680 _errorReporter.reportError2(errorCode, data.node, []);
16595 } 16681 }
16596 } 16682 }
16597 } 16683 }
16598 } 16684 }
16599 16685
16600 ValidResult valid(InterfaceType type, InstanceState state) => new ValidResult( new DartObjectImpl(type, state)); 16686 ValidResult valid(InterfaceType type, InstanceState state) => new ValidResult( new DartObjectImpl(type, state));
16601 16687
16602 /** 16688 /**
16603 * Validate that the given expression is a compile time constant. Return the v alue of the compile 16689 * Validate that the given expression is a compile time constant. Return the v alue of the compile
16604 * time constant, or `null` if the expression is not a compile time constant. 16690 * time constant, or `null` if the expression is not a compile time constant.
(...skipping 16 matching lines...) Expand all
16621 void validateConstantArguments(ArgumentList argumentList) { 16707 void validateConstantArguments(ArgumentList argumentList) {
16622 for (Expression argument in argumentList.arguments) { 16708 for (Expression argument in argumentList.arguments) {
16623 if (argument is NamedExpression) { 16709 if (argument is NamedExpression) {
16624 argument = (argument as NamedExpression).expression; 16710 argument = (argument as NamedExpression).expression;
16625 } 16711 }
16626 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT); 16712 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT);
16627 } 16713 }
16628 } 16714 }
16629 16715
16630 /** 16716 /**
16631 * Validate that if the passed instance creation is 'const' then all its argum ents are constant
16632 * expressions.
16633 *
16634 * @param node the instance creation evaluate
16635 */
16636 void validateConstantArguments2(InstanceCreationExpression node) {
16637 if (!node.isConst) {
16638 return;
16639 }
16640 ArgumentList argumentList = node.argumentList;
16641 if (argumentList == null) {
16642 return;
16643 }
16644 validateConstantArguments(argumentList);
16645 }
16646
16647 /**
16648 * Validate that the default value associated with each of the parameters in t he given list is a 16717 * Validate that the default value associated with each of the parameters in t he given list is a
16649 * compile time constant. 16718 * compile time constant.
16650 * 16719 *
16651 * @param parameters the list of parameters to be validated 16720 * @param parameters the list of parameters to be validated
16652 */ 16721 */
16653 void validateDefaultValues(FormalParameterList parameters) { 16722 void validateDefaultValues(FormalParameterList parameters) {
16654 if (parameters == null) { 16723 if (parameters == null) {
16655 return; 16724 return;
16656 } 16725 }
16657 for (FormalParameter parameter in parameters.parameters) { 16726 for (FormalParameter parameter in parameters.parameters) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
16712 if (initializer is RedirectingConstructorInvocation) { 16781 if (initializer is RedirectingConstructorInvocation) {
16713 RedirectingConstructorInvocation invocation = initializer; 16782 RedirectingConstructorInvocation invocation = initializer;
16714 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 16783 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
16715 } 16784 }
16716 if (initializer is SuperConstructorInvocation) { 16785 if (initializer is SuperConstructorInvocation) {
16717 SuperConstructorInvocation invocation = initializer; 16786 SuperConstructorInvocation invocation = initializer;
16718 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 16787 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
16719 } 16788 }
16720 } 16789 }
16721 } 16790 }
16791
16792 /**
16793 * Validate that if the passed instance creation is 'const' then all its argum ents are constant
16794 * expressions.
16795 *
16796 * @param node the instance creation evaluate
16797 */
16798 void validateInstanceCreationArguments(InstanceCreationExpression node) {
16799 if (!node.isConst) {
16800 return;
16801 }
16802 ArgumentList argumentList = node.argumentList;
16803 if (argumentList == null) {
16804 return;
16805 }
16806 validateConstantArguments(argumentList);
16807 }
16722 } 16808 }
16723 16809
16724 class ConstantVisitor_ConstantVerifier_validateInitializerExpression extends Con stantVisitor { 16810 class ConstantVisitor_ConstantVerifier_validateInitializerExpression extends Con stantVisitor {
16725 final ConstantVerifier ConstantVerifier_this; 16811 final ConstantVerifier ConstantVerifier_this;
16726 16812
16727 List<ParameterElement> parameterElements; 16813 List<ParameterElement> parameterElements;
16728 16814
16729 ConstantVisitor_ConstantVerifier_validateInitializerExpression(TypeProvider ar g0, this.ConstantVerifier_this, this.parameterElements) : super(arg0); 16815 ConstantVisitor_ConstantVerifier_validateInitializerExpression(TypeProvider ar g0, this.ConstantVerifier_this, this.parameterElements) : super(arg0);
16730 16816
16731 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { 16817 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
16962 _boolType, 17048 _boolType,
16963 typeProvider.stringType]; 17049 typeProvider.stringType];
16964 } 17050 }
16965 17051
16966 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { 17052 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
16967 checkForArgumentDefinitionTestNonParameter(node); 17053 checkForArgumentDefinitionTestNonParameter(node);
16968 return super.visitArgumentDefinitionTest(node); 17054 return super.visitArgumentDefinitionTest(node);
16969 } 17055 }
16970 17056
16971 Object visitArgumentList(ArgumentList node) { 17057 Object visitArgumentList(ArgumentList node) {
16972 checkForArgumentTypeNotAssignable(node); 17058 checkForArgumentTypesNotAssignableInList(node);
16973 return super.visitArgumentList(node); 17059 return super.visitArgumentList(node);
16974 } 17060 }
16975 17061
16976 Object visitAssertStatement(AssertStatement node) { 17062 Object visitAssertStatement(AssertStatement node) {
16977 checkForNonBoolExpression(node); 17063 checkForNonBoolExpression(node);
16978 return super.visitAssertStatement(node); 17064 return super.visitAssertStatement(node);
16979 } 17065 }
16980 17066
16981 Object visitAssignmentExpression(AssignmentExpression node) { 17067 Object visitAssignmentExpression(AssignmentExpression node) {
16982 sc.Token operator = node.operator; 17068 sc.Token operator = node.operator;
16983 sc.TokenType operatorType = operator.type; 17069 sc.TokenType operatorType = operator.type;
16984 if (identical(operatorType, sc.TokenType.EQ)) { 17070 if (identical(operatorType, sc.TokenType.EQ)) {
16985 checkForInvalidAssignment2(node.leftHandSide, node.rightHandSide); 17071 checkForInvalidAssignment(node.leftHandSide, node.rightHandSide);
16986 } else { 17072 } else {
16987 checkForInvalidAssignment(node); 17073 checkForInvalidCompoundAssignment(node);
16988 } 17074 }
16989 checkForAssignmentToFinal(node); 17075 checkForAssignmentToFinal(node.leftHandSide);
16990 checkForArgumentTypeNotAssignable2(node.rightHandSide); 17076 checkForArgumentTypeNotAssignableForArgument(node.rightHandSide);
16991 return super.visitAssignmentExpression(node); 17077 return super.visitAssignmentExpression(node);
16992 } 17078 }
16993 17079
16994 Object visitBinaryExpression(BinaryExpression node) { 17080 Object visitBinaryExpression(BinaryExpression node) {
16995 checkForArgumentTypeNotAssignable2(node.rightOperand); 17081 checkForArgumentTypeNotAssignableForArgument(node.rightOperand);
16996 return super.visitBinaryExpression(node); 17082 return super.visitBinaryExpression(node);
16997 } 17083 }
16998 17084
16999 Object visitBlockFunctionBody(BlockFunctionBody node) { 17085 Object visitBlockFunctionBody(BlockFunctionBody node) {
17000 List<ReturnStatement> previousReturnsWith = _returnsWith; 17086 List<ReturnStatement> previousReturnsWith = _returnsWith;
17001 List<ReturnStatement> previousReturnsWithout = _returnsWithout; 17087 List<ReturnStatement> previousReturnsWithout = _returnsWithout;
17002 try { 17088 try {
17003 _returnsWith = new List<ReturnStatement>(); 17089 _returnsWith = new List<ReturnStatement>();
17004 _returnsWithout = new List<ReturnStatement>(); 17090 _returnsWithout = new List<ReturnStatement>();
17005 super.visitBlockFunctionBody(node); 17091 super.visitBlockFunctionBody(node);
17006 checkForMixedReturns(node); 17092 checkForMixedReturns(node);
17007 } finally { 17093 } finally {
17008 _returnsWith = previousReturnsWith; 17094 _returnsWith = previousReturnsWith;
17009 _returnsWithout = previousReturnsWithout; 17095 _returnsWithout = previousReturnsWithout;
17010 } 17096 }
17011 return null; 17097 return null;
17012 } 17098 }
17013 17099
17014 Object visitBreakStatement(BreakStatement node) { 17100 Object visitBreakStatement(BreakStatement node) {
17015 SimpleIdentifier labelNode = node.label; 17101 SimpleIdentifier labelNode = node.label;
17016 if (labelNode != null) { 17102 if (labelNode != null) {
17017 Element labelElement = labelNode.staticElement; 17103 Element labelElement = labelNode.staticElement;
17018 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) { 17104 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) {
17019 _errorReporter.reportError3(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMB ER, labelNode, []); 17105 _errorReporter.reportError2(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMB ER, labelNode, []);
17020 } 17106 }
17021 } 17107 }
17022 return null; 17108 return null;
17023 } 17109 }
17024 17110
17025 Object visitCatchClause(CatchClause node) { 17111 Object visitCatchClause(CatchClause node) {
17026 bool previousIsInCatchClause = _isInCatchClause; 17112 bool previousIsInCatchClause = _isInCatchClause;
17027 try { 17113 try {
17028 _isInCatchClause = true; 17114 _isInCatchClause = true;
17029 return super.visitCatchClause(node); 17115 return super.visitCatchClause(node);
17030 } finally { 17116 } finally {
17031 _isInCatchClause = previousIsInCatchClause; 17117 _isInCatchClause = previousIsInCatchClause;
17032 } 17118 }
17033 } 17119 }
17034 17120
17035 Object visitClassDeclaration(ClassDeclaration node) { 17121 Object visitClassDeclaration(ClassDeclaration node) {
17036 ClassElement outerClass = _enclosingClass; 17122 ClassElement outerClass = _enclosingClass;
17037 try { 17123 try {
17038 _isInNativeClass = node.nativeClause != null; 17124 _isInNativeClass = node.nativeClause != null;
17039 _enclosingClass = node.element; 17125 _enclosingClass = node.element;
17040 WithClause withClause = node.withClause; 17126 WithClause withClause = node.withClause;
17041 ImplementsClause implementsClause = node.implementsClause; 17127 ImplementsClause implementsClause = node.implementsClause;
17042 ExtendsClause extendsClause = node.extendsClause; 17128 ExtendsClause extendsClause = node.extendsClause;
17043 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME); 17129 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME);
17044 checkForMemberWithClassName(); 17130 checkForMemberWithClassName();
17045 checkForNoDefaultSuperConstructorImplicit(node); 17131 checkForNoDefaultSuperConstructorImplicit(node);
17046 checkForAllMixinErrorCodes(withClause);
17047 checkForConflictingTypeVariableErrorCodes(node); 17132 checkForConflictingTypeVariableErrorCodes(node);
17048 if (implementsClause != null || extendsClause != null) { 17133 // Only do error checks on the clause nodes if there is a non-null clause
17049 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt endsDisallowedClass(extendsClause)) { 17134 if (implementsClause != null || extendsClause != null || withClause != nul l) {
17135 // Only check for all of the inheritance logic around clauses if there i sn't an error code
17136 // such as "Cannot extend double" already on the class.
17137 if (!checkForImplementsDisallowedClass(implementsClause) && !checkForExt endsDisallowedClass(extendsClause) && !checkForAllMixinErrorCodes(withClause)) {
17050 checkForNonAbstractClassInheritsAbstractMember(node); 17138 checkForNonAbstractClassInheritsAbstractMember(node);
17051 checkForInconsistentMethodInheritance(); 17139 checkForInconsistentMethodInheritance();
17052 checkForRecursiveInterfaceInheritance(_enclosingClass); 17140 checkForRecursiveInterfaceInheritance(_enclosingClass);
17053 } 17141 }
17054 } 17142 }
17055 // initialize initialFieldElementsMap 17143 // initialize initialFieldElementsMap
17056 ClassElement classElement = node.element; 17144 ClassElement classElement = node.element;
17057 if (classElement != null) { 17145 if (classElement != null) {
17058 List<FieldElement> fieldElements = classElement.fields; 17146 List<FieldElement> fieldElements = classElement.fields;
17059 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); 17147 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>();
17060 for (FieldElement fieldElement in fieldElements) { 17148 for (FieldElement fieldElement in fieldElements) {
17061 if (!fieldElement.isSynthetic) { 17149 if (!fieldElement.isSynthetic) {
17062 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; 17150 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION;
17063 } 17151 }
17064 } 17152 }
17065 } 17153 }
17066 checkForFinalNotInitialized(node); 17154 checkForFinalNotInitializedInClass(node);
17067 checkForDuplicateDefinitionInheritance(); 17155 checkForDuplicateDefinitionInheritance();
17068 checkForConflictingGetterAndMethod(); 17156 checkForConflictingGetterAndMethod();
17069 checkForConflictingInstanceGetterAndSuperclassMember(); 17157 checkForConflictingInstanceGetterAndSuperclassMember();
17070 checkImplementsSuperClass(node); 17158 checkImplementsSuperClass(node);
17071 checkImplementsFunctionWithoutCall(node); 17159 checkImplementsFunctionWithoutCall(node);
17072 return super.visitClassDeclaration(node); 17160 return super.visitClassDeclaration(node);
17073 } finally { 17161 } finally {
17074 _isInNativeClass = false; 17162 _isInNativeClass = false;
17075 _initialFieldElementsMap = null; 17163 _initialFieldElementsMap = null;
17076 _enclosingClass = outerClass; 17164 _enclosingClass = outerClass;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
17139 } finally { 17227 } finally {
17140 _isInConstructorInitializer = false; 17228 _isInConstructorInitializer = false;
17141 } 17229 }
17142 } 17230 }
17143 17231
17144 Object visitContinueStatement(ContinueStatement node) { 17232 Object visitContinueStatement(ContinueStatement node) {
17145 SimpleIdentifier labelNode = node.label; 17233 SimpleIdentifier labelNode = node.label;
17146 if (labelNode != null) { 17234 if (labelNode != null) {
17147 Element labelElement = labelNode.staticElement; 17235 Element labelElement = labelNode.staticElement;
17148 if (labelElement is LabelElementImpl && labelElement.isOnSwitchStatement) { 17236 if (labelElement is LabelElementImpl && labelElement.isOnSwitchStatement) {
17149 _errorReporter.reportError3(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNode, []); 17237 _errorReporter.reportError2(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNode, []);
17150 } 17238 }
17151 } 17239 }
17152 return null; 17240 return null;
17153 } 17241 }
17154 17242
17155 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 17243 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
17156 checkForInvalidAssignment2(node.identifier, node.defaultValue); 17244 checkForInvalidAssignment(node.identifier, node.defaultValue);
17157 checkForDefaultValueInFunctionTypedParameter(node); 17245 checkForDefaultValueInFunctionTypedParameter(node);
17158 return super.visitDefaultFormalParameter(node); 17246 return super.visitDefaultFormalParameter(node);
17159 } 17247 }
17160 17248
17161 Object visitDoStatement(DoStatement node) { 17249 Object visitDoStatement(DoStatement node) {
17162 checkForNonBoolCondition(node.condition); 17250 checkForNonBoolCondition(node.condition);
17163 return super.visitDoStatement(node); 17251 return super.visitDoStatement(node);
17164 } 17252 }
17165 17253
17166 Object visitExportDirective(ExportDirective node) { 17254 Object visitExportDirective(ExportDirective node) {
17167 checkForAmbiguousExport(node); 17255 checkForAmbiguousExport(node);
17168 checkForExportDuplicateLibraryName(node); 17256 checkForExportDuplicateLibraryName(node);
17169 checkForExportInternalLibrary(node); 17257 checkForExportInternalLibrary(node);
17170 return super.visitExportDirective(node); 17258 return super.visitExportDirective(node);
17171 } 17259 }
17172 17260
17173 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 17261 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
17174 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type; 17262 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
17175 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType; 17263 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType;
17176 checkForReturnOfInvalidType(node.expression, expectedReturnType); 17264 checkForReturnOfInvalidType(node.expression, expectedReturnType);
17177 return super.visitExpressionFunctionBody(node); 17265 return super.visitExpressionFunctionBody(node);
17178 } 17266 }
17179 17267
17180 Object visitFieldDeclaration(FieldDeclaration node) { 17268 Object visitFieldDeclaration(FieldDeclaration node) {
17181 if (!node.isStatic) { 17269 if (!node.isStatic) {
17182 VariableDeclarationList variables = node.fields; 17270 VariableDeclarationList variables = node.fields;
17183 if (variables.isConst) { 17271 if (variables.isConst) {
17184 _errorReporter.reportError6(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v ariables.keyword, []); 17272 _errorReporter.reportError5(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v ariables.keyword, []);
17185 } 17273 }
17186 } 17274 }
17187 _isInStaticVariableDeclaration = node.isStatic; 17275 _isInStaticVariableDeclaration = node.isStatic;
17188 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; 17276 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration;
17189 try { 17277 try {
17190 checkForAllInvalidOverrideErrorCodes3(node); 17278 checkForAllInvalidOverrideErrorCodesForField(node);
17191 return super.visitFieldDeclaration(node); 17279 return super.visitFieldDeclaration(node);
17192 } finally { 17280 } finally {
17193 _isInStaticVariableDeclaration = false; 17281 _isInStaticVariableDeclaration = false;
17194 _isInInstanceVariableDeclaration = false; 17282 _isInInstanceVariableDeclaration = false;
17195 } 17283 }
17196 } 17284 }
17197 17285
17198 Object visitFieldFormalParameter(FieldFormalParameter node) { 17286 Object visitFieldFormalParameter(FieldFormalParameter node) {
17199 checkForValidField(node); 17287 checkForValidField(node);
17200 checkForConstFormalParameter(node); 17288 checkForConstFormalParameter(node);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
17242 } 17330 }
17243 } else { 17331 } else {
17244 return super.visitFunctionExpression(node); 17332 return super.visitFunctionExpression(node);
17245 } 17333 }
17246 } 17334 }
17247 17335
17248 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 17336 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
17249 Expression functionExpression = node.function; 17337 Expression functionExpression = node.function;
17250 Type2 expressionType = functionExpression.staticType; 17338 Type2 expressionType = functionExpression.staticType;
17251 if (!isFunctionType(expressionType)) { 17339 if (!isFunctionType(expressionType)) {
17252 _errorReporter.reportError3(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON_EXPRESSION, functionExpression, []); 17340 _errorReporter.reportError2(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON_EXPRESSION, functionExpression, []);
17253 } 17341 }
17254 return super.visitFunctionExpressionInvocation(node); 17342 return super.visitFunctionExpressionInvocation(node);
17255 } 17343 }
17256 17344
17257 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 17345 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
17258 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 17346 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
17259 checkForDefaultValueInFunctionTypeAlias(node); 17347 checkForDefaultValueInFunctionTypeAlias(node);
17260 checkForTypeAliasCannotReferenceItself_function(node); 17348 checkForTypeAliasCannotReferenceItself_function(node);
17261 return super.visitFunctionTypeAlias(node); 17349 return super.visitFunctionTypeAlias(node);
17262 } 17350 }
(...skipping 13 matching lines...) Expand all
17276 return super.visitIfStatement(node); 17364 return super.visitIfStatement(node);
17277 } 17365 }
17278 17366
17279 Object visitImportDirective(ImportDirective node) { 17367 Object visitImportDirective(ImportDirective node) {
17280 checkForImportDuplicateLibraryName(node); 17368 checkForImportDuplicateLibraryName(node);
17281 checkForImportInternalLibrary(node); 17369 checkForImportInternalLibrary(node);
17282 return super.visitImportDirective(node); 17370 return super.visitImportDirective(node);
17283 } 17371 }
17284 17372
17285 Object visitIndexExpression(IndexExpression node) { 17373 Object visitIndexExpression(IndexExpression node) {
17286 checkForArgumentTypeNotAssignable2(node.index); 17374 checkForArgumentTypeNotAssignableForArgument(node.index);
17287 return super.visitIndexExpression(node); 17375 return super.visitIndexExpression(node);
17288 } 17376 }
17289 17377
17290 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 17378 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
17291 _isInConstInstanceCreation = node.isConst; 17379 _isInConstInstanceCreation = node.isConst;
17292 try { 17380 try {
17293 ConstructorName constructorName = node.constructorName; 17381 ConstructorName constructorName = node.constructorName;
17294 TypeName typeName = constructorName.type; 17382 TypeName typeName = constructorName.type;
17295 Type2 type = typeName.type; 17383 Type2 type = typeName.type;
17296 if (type is InterfaceType) { 17384 if (type is InterfaceType) {
17297 InterfaceType interfaceType = type; 17385 InterfaceType interfaceType = type;
17298 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); 17386 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
17299 if (_isInConstInstanceCreation) { 17387 if (_isInConstInstanceCreation) {
17300 checkForConstWithNonConst(node); 17388 checkForConstWithNonConst(node);
17301 checkForConstWithUndefinedConstructor(node); 17389 checkForConstWithUndefinedConstructor(node);
17302 checkForConstWithTypeParameters(node); 17390 checkForConstWithTypeParametersInCreation(node);
17303 } else { 17391 } else {
17304 checkForNewWithUndefinedConstructor(node); 17392 checkForNewWithUndefinedConstructor(node);
17305 } 17393 }
17306 } 17394 }
17307 return super.visitInstanceCreationExpression(node); 17395 return super.visitInstanceCreationExpression(node);
17308 } finally { 17396 } finally {
17309 _isInConstInstanceCreation = false; 17397 _isInConstInstanceCreation = false;
17310 } 17398 }
17311 } 17399 }
17312 17400
(...skipping 18 matching lines...) Expand all
17331 NodeList<TypeName> arguments = typeArguments.arguments; 17419 NodeList<TypeName> arguments = typeArguments.arguments;
17332 if (arguments.length != 0) { 17420 if (arguments.length != 0) {
17333 if (node.constKeyword != null) { 17421 if (node.constKeyword != null) {
17334 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 17422 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
17335 } 17423 }
17336 } 17424 }
17337 } 17425 }
17338 checkExpectedTwoMapTypeArguments(typeArguments); 17426 checkExpectedTwoMapTypeArguments(typeArguments);
17339 checkForNonConstMapAsExpressionStatement(node); 17427 checkForNonConstMapAsExpressionStatement(node);
17340 checkForMapTypeNotAssignable(node); 17428 checkForMapTypeNotAssignable(node);
17341 checkForConstMapKeyExpressionTypeImplementsEquals2(node); 17429 checkForConstMapKeyExpressionTypeImplementsEquals(node);
17342 return super.visitMapLiteral(node); 17430 return super.visitMapLiteral(node);
17343 } 17431 }
17344 17432
17345 Object visitMethodDeclaration(MethodDeclaration node) { 17433 Object visitMethodDeclaration(MethodDeclaration node) {
17346 ExecutableElement previousFunction = _enclosingFunction; 17434 ExecutableElement previousFunction = _enclosingFunction;
17347 try { 17435 try {
17348 _isInStaticMethod = node.isStatic; 17436 _isInStaticMethod = node.isStatic;
17349 _enclosingFunction = node.element; 17437 _enclosingFunction = node.element;
17350 SimpleIdentifier identifier = node.name; 17438 SimpleIdentifier identifier = node.name;
17351 String methodName = ""; 17439 String methodName = "";
(...skipping 10 matching lines...) Expand all
17362 checkForNonVoidReturnTypeForSetter(node.returnType); 17450 checkForNonVoidReturnTypeForSetter(node.returnType);
17363 checkForConflictingStaticSetterAndInstanceMember(node); 17451 checkForConflictingStaticSetterAndInstanceMember(node);
17364 } else if (node.isOperator) { 17452 } else if (node.isOperator) {
17365 checkForOptionalParameterInOperator(node); 17453 checkForOptionalParameterInOperator(node);
17366 checkForWrongNumberOfParametersForOperator(node); 17454 checkForWrongNumberOfParametersForOperator(node);
17367 checkForNonVoidReturnTypeForOperator(node); 17455 checkForNonVoidReturnTypeForOperator(node);
17368 } else { 17456 } else {
17369 checkForConflictingInstanceMethodSetter(node); 17457 checkForConflictingInstanceMethodSetter(node);
17370 } 17458 }
17371 checkForConcreteClassWithAbstractMember(node); 17459 checkForConcreteClassWithAbstractMember(node);
17372 checkForAllInvalidOverrideErrorCodes4(node); 17460 checkForAllInvalidOverrideErrorCodesForMethod(node);
17373 return super.visitMethodDeclaration(node); 17461 return super.visitMethodDeclaration(node);
17374 } finally { 17462 } finally {
17375 _enclosingFunction = previousFunction; 17463 _enclosingFunction = previousFunction;
17376 _isInStaticMethod = false; 17464 _isInStaticMethod = false;
17377 } 17465 }
17378 } 17466 }
17379 17467
17380 Object visitMethodInvocation(MethodInvocation node) { 17468 Object visitMethodInvocation(MethodInvocation node) {
17381 Expression target = node.realTarget; 17469 Expression target = node.realTarget;
17382 SimpleIdentifier methodName = node.methodName; 17470 SimpleIdentifier methodName = node.methodName;
17383 if (target != null) { 17471 if (target != null) {
17384 ClassElement typeReference = ElementResolver.getTypeReference(target); 17472 ClassElement typeReference = ElementResolver.getTypeReference(target);
17385 checkForStaticAccessToInstanceMember(typeReference, methodName); 17473 checkForStaticAccessToInstanceMember(typeReference, methodName);
17386 checkForInstanceAccessToStaticMember(typeReference, methodName); 17474 checkForInstanceAccessToStaticMember(typeReference, methodName);
17387 } else { 17475 } else {
17388 checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); 17476 checkForUnqualifiedReferenceToNonLocalStaticMember(methodName);
17389 } 17477 }
17390 return super.visitMethodInvocation(node); 17478 return super.visitMethodInvocation(node);
17391 } 17479 }
17392 17480
17393 Object visitNativeClause(NativeClause node) { 17481 Object visitNativeClause(NativeClause node) {
17394 // TODO(brianwilkerson) Figure out the right rule for when 'native' is allow ed. 17482 // TODO(brianwilkerson) Figure out the right rule for when 'native' is allow ed.
17395 if (!_isInSystemLibrary) { 17483 if (!_isInSystemLibrary) {
17396 _errorReporter.reportError3(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node, []); 17484 _errorReporter.reportError2(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node, []);
17397 } 17485 }
17398 return super.visitNativeClause(node); 17486 return super.visitNativeClause(node);
17399 } 17487 }
17400 17488
17401 Object visitNativeFunctionBody(NativeFunctionBody node) { 17489 Object visitNativeFunctionBody(NativeFunctionBody node) {
17402 checkForNativeFunctionBodyInNonSDKCode(node); 17490 checkForNativeFunctionBodyInNonSDKCode(node);
17403 return super.visitNativeFunctionBody(node); 17491 return super.visitNativeFunctionBody(node);
17404 } 17492 }
17405 17493
17406 Object visitPostfixExpression(PostfixExpression node) { 17494 Object visitPostfixExpression(PostfixExpression node) {
17407 checkForAssignmentToFinal2(node.operand); 17495 checkForAssignmentToFinal(node.operand);
17408 checkForIntNotAssignable(node.operand); 17496 checkForIntNotAssignable(node.operand);
17409 return super.visitPostfixExpression(node); 17497 return super.visitPostfixExpression(node);
17410 } 17498 }
17411 17499
17412 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 17500 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
17413 if (node.parent is! Annotation) { 17501 if (node.parent is! Annotation) {
17414 ClassElement typeReference = ElementResolver.getTypeReference(node.prefix) ; 17502 ClassElement typeReference = ElementResolver.getTypeReference(node.prefix) ;
17415 SimpleIdentifier name = node.identifier; 17503 SimpleIdentifier name = node.identifier;
17416 checkForStaticAccessToInstanceMember(typeReference, name); 17504 checkForStaticAccessToInstanceMember(typeReference, name);
17417 checkForInstanceAccessToStaticMember(typeReference, name); 17505 checkForInstanceAccessToStaticMember(typeReference, name);
17418 } 17506 }
17419 return super.visitPrefixedIdentifier(node); 17507 return super.visitPrefixedIdentifier(node);
17420 } 17508 }
17421 17509
17422 Object visitPrefixExpression(PrefixExpression node) { 17510 Object visitPrefixExpression(PrefixExpression node) {
17423 sc.TokenType operatorType = node.operator.type; 17511 sc.TokenType operatorType = node.operator.type;
17424 Expression operand = node.operand; 17512 Expression operand = node.operand;
17425 if (identical(operatorType, sc.TokenType.BANG)) { 17513 if (identical(operatorType, sc.TokenType.BANG)) {
17426 checkForNonBoolNegationExpression(operand); 17514 checkForNonBoolNegationExpression(operand);
17427 } else if (operatorType.isIncrementOperator) { 17515 } else if (operatorType.isIncrementOperator) {
17428 checkForAssignmentToFinal2(operand); 17516 checkForAssignmentToFinal(operand);
17429 } 17517 }
17430 checkForIntNotAssignable(operand); 17518 checkForIntNotAssignable(operand);
17431 return super.visitPrefixExpression(node); 17519 return super.visitPrefixExpression(node);
17432 } 17520 }
17433 17521
17434 Object visitPropertyAccess(PropertyAccess node) { 17522 Object visitPropertyAccess(PropertyAccess node) {
17435 ClassElement typeReference = ElementResolver.getTypeReference(node.realTarge t); 17523 ClassElement typeReference = ElementResolver.getTypeReference(node.realTarge t);
17436 SimpleIdentifier propertyName = node.propertyName; 17524 SimpleIdentifier propertyName = node.propertyName;
17437 checkForStaticAccessToInstanceMember(typeReference, propertyName); 17525 checkForStaticAccessToInstanceMember(typeReference, propertyName);
17438 checkForInstanceAccessToStaticMember(typeReference, propertyName); 17526 checkForInstanceAccessToStaticMember(typeReference, propertyName);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
17497 checkForInvalidReferenceToThis(node); 17585 checkForInvalidReferenceToThis(node);
17498 return super.visitThisExpression(node); 17586 return super.visitThisExpression(node);
17499 } 17587 }
17500 17588
17501 Object visitThrowExpression(ThrowExpression node) { 17589 Object visitThrowExpression(ThrowExpression node) {
17502 checkForConstEvalThrowsException(node); 17590 checkForConstEvalThrowsException(node);
17503 return super.visitThrowExpression(node); 17591 return super.visitThrowExpression(node);
17504 } 17592 }
17505 17593
17506 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 17594 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
17507 checkForFinalNotInitialized2(node.variables); 17595 checkForFinalNotInitialized(node.variables);
17508 return super.visitTopLevelVariableDeclaration(node); 17596 return super.visitTopLevelVariableDeclaration(node);
17509 } 17597 }
17510 17598
17511 Object visitTypeName(TypeName node) { 17599 Object visitTypeName(TypeName node) {
17512 checkForTypeArgumentNotMatchingBounds(node); 17600 checkForTypeArgumentNotMatchingBounds(node);
17513 checkForTypeParameterReferencedByStatic(node); 17601 checkForTypeParameterReferencedByStatic(node);
17514 return super.visitTypeName(node); 17602 return super.visitTypeName(node);
17515 } 17603 }
17516 17604
17517 Object visitTypeParameter(TypeParameter node) { 17605 Object visitTypeParameter(TypeParameter node) {
17518 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_PARAMETER_NAME); 17606 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_PARAMETER_NAME);
17519 checkForTypeParameterSupertypeOfItsBound(node); 17607 checkForTypeParameterSupertypeOfItsBound(node);
17520 return super.visitTypeParameter(node); 17608 return super.visitTypeParameter(node);
17521 } 17609 }
17522 17610
17523 Object visitVariableDeclaration(VariableDeclaration node) { 17611 Object visitVariableDeclaration(VariableDeclaration node) {
17524 SimpleIdentifier nameNode = node.name; 17612 SimpleIdentifier nameNode = node.name;
17525 Expression initializerNode = node.initializer; 17613 Expression initializerNode = node.initializer;
17526 // do checks 17614 // do checks
17527 checkForInvalidAssignment2(nameNode, initializerNode); 17615 checkForInvalidAssignment(nameNode, initializerNode);
17528 // visit name 17616 // visit name
17529 nameNode.accept(this); 17617 nameNode.accept(this);
17530 // visit initializer 17618 // visit initializer
17531 String name = nameNode.name; 17619 String name = nameNode.name;
17532 _namesForReferenceToDeclaredVariableInInitializer.add(name); 17620 _namesForReferenceToDeclaredVariableInInitializer.add(name);
17533 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; 17621 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration;
17534 try { 17622 try {
17535 if (initializerNode != null) { 17623 if (initializerNode != null) {
17536 initializerNode.accept(this); 17624 initializerNode.accept(this);
17537 } 17625 }
17538 } finally { 17626 } finally {
17539 _isInInstanceVariableInitializer = false; 17627 _isInInstanceVariableInitializer = false;
17540 _namesForReferenceToDeclaredVariableInInitializer.remove(name); 17628 _namesForReferenceToDeclaredVariableInInitializer.remove(name);
17541 } 17629 }
17542 // done 17630 // done
17543 return null; 17631 return null;
17544 } 17632 }
17545 17633
17546 Object visitVariableDeclarationList(VariableDeclarationList node) => super.vis itVariableDeclarationList(node); 17634 Object visitVariableDeclarationList(VariableDeclarationList node) => super.vis itVariableDeclarationList(node);
17547 17635
17548 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { 17636 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
17549 checkForFinalNotInitialized2(node.variables); 17637 checkForFinalNotInitialized(node.variables);
17550 return super.visitVariableDeclarationStatement(node); 17638 return super.visitVariableDeclarationStatement(node);
17551 } 17639 }
17552 17640
17553 Object visitWhileStatement(WhileStatement node) { 17641 Object visitWhileStatement(WhileStatement node) {
17554 checkForNonBoolCondition(node.condition); 17642 checkForNonBoolCondition(node.condition);
17555 return super.visitWhileStatement(node); 17643 return super.visitWhileStatement(node);
17556 } 17644 }
17557 17645
17558 /** 17646 /**
17559 * This verifies if the passed map literal has type arguments then there is ex actly two. 17647 * This verifies if the passed map literal has type arguments then there is ex actly two.
17560 * 17648 *
17561 * @param node the map literal to evaluate 17649 * @param node the map literal to evaluate
17562 * @return `true` if and only if an error code is generated on the passed node 17650 * @return `true` if and only if an error code is generated on the passed node
17563 * @see StaticTypeWarningCode#EXPECTED_TWO_MAP_TYPE_ARGUMENTS 17651 * @see StaticTypeWarningCode#EXPECTED_TWO_MAP_TYPE_ARGUMENTS
17564 */ 17652 */
17565 bool checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { 17653 bool checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) {
17566 // has type arguments 17654 // has type arguments
17567 if (typeArguments == null) { 17655 if (typeArguments == null) {
17568 return false; 17656 return false;
17569 } 17657 }
17570 // check number of type arguments 17658 // check number of type arguments
17571 int num = typeArguments.arguments.length; 17659 int num = typeArguments.arguments.length;
17572 if (num == 2) { 17660 if (num == 2) {
17573 return false; 17661 return false;
17574 } 17662 }
17575 // report problem 17663 // report problem
17576 _errorReporter.reportError3(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGU MENTS, typeArguments, [num]); 17664 _errorReporter.reportError2(StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGU MENTS, typeArguments, [num]);
17577 return true; 17665 return true;
17578 } 17666 }
17579 17667
17580 /** 17668 /**
17581 * This verifies that the passed constructor declaration does not violate any of the error codes 17669 * This verifies that the passed constructor declaration does not violate any of the error codes
17582 * relating to the initialization of fields in the enclosing class. 17670 * relating to the initialization of fields in the enclosing class.
17583 * 17671 *
17584 * @param node the [ConstructorDeclaration] to evaluate 17672 * @param node the [ConstructorDeclaration] to evaluate
17585 * @return `true` if and only if an error code is generated on the passed node 17673 * @return `true` if and only if an error code is generated on the passed node
17586 * @see #initialFieldElementsMap 17674 * @see #initialFieldElementsMap
(...skipping 17 matching lines...) Expand all
17604 if (parameter is DefaultFormalParameter) { 17692 if (parameter is DefaultFormalParameter) {
17605 parameter = (parameter as DefaultFormalParameter).parameter; 17693 parameter = (parameter as DefaultFormalParameter).parameter;
17606 } 17694 }
17607 if (parameter is FieldFormalParameter) { 17695 if (parameter is FieldFormalParameter) {
17608 FieldElement fieldElement = (parameter.element as FieldFormalParameterEl ementImpl).field; 17696 FieldElement fieldElement = (parameter.element as FieldFormalParameterEl ementImpl).field;
17609 INIT_STATE state = fieldElementsMap[fieldElement]; 17697 INIT_STATE state = fieldElementsMap[fieldElement];
17610 if (identical(state, INIT_STATE.NOT_INIT)) { 17698 if (identical(state, INIT_STATE.NOT_INIT)) {
17611 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; 17699 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL;
17612 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { 17700 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) {
17613 if (fieldElement.isFinal || fieldElement.isConst) { 17701 if (fieldElement.isFinal || fieldElement.isConst) {
17614 _errorReporter.reportError3(StaticWarningCode.FINAL_INITIALIZED_IN_D ECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.displayNam e]); 17702 _errorReporter.reportError2(StaticWarningCode.FINAL_INITIALIZED_IN_D ECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.displayNam e]);
17615 foundError = true; 17703 foundError = true;
17616 } 17704 }
17617 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { 17705 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) {
17618 if (fieldElement.isFinal || fieldElement.isConst) { 17706 if (fieldElement.isFinal || fieldElement.isConst) {
17619 _errorReporter.reportError3(CompileTimeErrorCode.FINAL_INITIALIZED_M ULTIPLE_TIMES, formalParameter.identifier, [fieldElement.displayName]); 17707 _errorReporter.reportError2(CompileTimeErrorCode.FINAL_INITIALIZED_M ULTIPLE_TIMES, formalParameter.identifier, [fieldElement.displayName]);
17620 foundError = true; 17708 foundError = true;
17621 } 17709 }
17622 } 17710 }
17623 } 17711 }
17624 } 17712 }
17625 // Visit all of the initializers 17713 // Visit all of the initializers
17626 NodeList<ConstructorInitializer> initializers = node.initializers; 17714 NodeList<ConstructorInitializer> initializers = node.initializers;
17627 for (ConstructorInitializer constructorInitializer in initializers) { 17715 for (ConstructorInitializer constructorInitializer in initializers) {
17628 if (constructorInitializer is RedirectingConstructorInvocation) { 17716 if (constructorInitializer is RedirectingConstructorInvocation) {
17629 return false; 17717 return false;
17630 } 17718 }
17631 if (constructorInitializer is ConstructorFieldInitializer) { 17719 if (constructorInitializer is ConstructorFieldInitializer) {
17632 ConstructorFieldInitializer constructorFieldInitializer = constructorIni tializer; 17720 ConstructorFieldInitializer constructorFieldInitializer = constructorIni tializer;
17633 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; 17721 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName;
17634 Element element = fieldName.staticElement; 17722 Element element = fieldName.staticElement;
17635 if (element is FieldElement) { 17723 if (element is FieldElement) {
17636 FieldElement fieldElement = element; 17724 FieldElement fieldElement = element;
17637 INIT_STATE state = fieldElementsMap[fieldElement]; 17725 INIT_STATE state = fieldElementsMap[fieldElement];
17638 if (identical(state, INIT_STATE.NOT_INIT)) { 17726 if (identical(state, INIT_STATE.NOT_INIT)) {
17639 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; 17727 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS;
17640 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { 17728 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) {
17641 if (fieldElement.isFinal || fieldElement.isConst) { 17729 if (fieldElement.isFinal || fieldElement.isConst) {
17642 _errorReporter.reportError3(StaticWarningCode.FIELD_INITIALIZED_IN _INITIALIZER_AND_DECLARATION, fieldName, []); 17730 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZED_IN _INITIALIZER_AND_DECLARATION, fieldName, []);
17643 foundError = true; 17731 foundError = true;
17644 } 17732 }
17645 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { 17733 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) {
17646 _errorReporter.reportError3(CompileTimeErrorCode.FIELD_INITIALIZED_I N_PARAMETER_AND_INITIALIZER, fieldName, []); 17734 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_I N_PARAMETER_AND_INITIALIZER, fieldName, []);
17647 foundError = true; 17735 foundError = true;
17648 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { 17736 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) {
17649 _errorReporter.reportError3(CompileTimeErrorCode.FIELD_INITIALIZED_B Y_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); 17737 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZED_B Y_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]);
17650 foundError = true; 17738 foundError = true;
17651 } 17739 }
17652 } 17740 }
17653 } 17741 }
17654 } 17742 }
17655 // Visit all of the states in the map to ensure that none were never initial ized. 17743 // Visit all of the states in the map to ensure that none were never initial ized.
17656 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement sMap)) { 17744 for (MapEntry<FieldElement, INIT_STATE> entry in getMapEntrySet(fieldElement sMap)) {
17657 if (identical(entry.getValue(), INIT_STATE.NOT_INIT)) { 17745 if (identical(entry.getValue(), INIT_STATE.NOT_INIT)) {
17658 FieldElement fieldElement = entry.getKey(); 17746 FieldElement fieldElement = entry.getKey();
17659 if (fieldElement.isConst) { 17747 if (fieldElement.isConst) {
17660 _errorReporter.reportError3(CompileTimeErrorCode.CONST_NOT_INITIALIZED , node.returnType, [fieldElement.name]); 17748 _errorReporter.reportError2(CompileTimeErrorCode.CONST_NOT_INITIALIZED , node.returnType, [fieldElement.name]);
17661 foundError = true; 17749 foundError = true;
17662 } else if (fieldElement.isFinal) { 17750 } else if (fieldElement.isFinal) {
17663 _errorReporter.reportError3(StaticWarningCode.FINAL_NOT_INITIALIZED, n ode.returnType, [fieldElement.name]); 17751 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, n ode.returnType, [fieldElement.name]);
17664 foundError = true; 17752 foundError = true;
17665 } 17753 }
17666 } 17754 }
17667 } 17755 }
17668 return foundError; 17756 return foundError;
17669 } 17757 }
17670 17758
17671 /** 17759 /**
17672 * This checks the passed executable element against override-error codes. 17760 * This checks the passed executable element against override-error codes.
17673 * 17761 *
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
17713 // We need the same name. 17801 // We need the same name.
17714 if (fieldElt.name != executableElementName) { 17802 if (fieldElt.name != executableElementName) {
17715 continue; 17803 continue;
17716 } 17804 }
17717 // Ignore if private in a different library - cannot collide. 17805 // Ignore if private in a different library - cannot collide.
17718 if (executableElementPrivate && _currentLibrary != superclassLibrary ) { 17806 if (executableElementPrivate && _currentLibrary != superclassLibrary ) {
17719 continue; 17807 continue;
17720 } 17808 }
17721 // instance vs. static 17809 // instance vs. static
17722 if (fieldElt.isStatic) { 17810 if (fieldElt.isStatic) {
17723 _errorReporter.reportError3(StaticWarningCode.INSTANCE_METHOD_NAME _COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [ 17811 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME _COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [
17724 executableElementName, 17812 executableElementName,
17725 fieldElt.enclosingElement.displayName]); 17813 fieldElt.enclosingElement.displayName]);
17726 return true; 17814 return true;
17727 } 17815 }
17728 } 17816 }
17729 // Check methods. 17817 // Check methods.
17730 List<MethodElement> methodElements = superclassElement.methods; 17818 List<MethodElement> methodElements = superclassElement.methods;
17731 for (MethodElement methodElement in methodElements) { 17819 for (MethodElement methodElement in methodElements) {
17732 // We need the same name. 17820 // We need the same name.
17733 if (methodElement.name != executableElementName) { 17821 if (methodElement.name != executableElementName) {
17734 continue; 17822 continue;
17735 } 17823 }
17736 // Ignore if private in a different library - cannot collide. 17824 // Ignore if private in a different library - cannot collide.
17737 if (executableElementPrivate && _currentLibrary != superclassLibrary ) { 17825 if (executableElementPrivate && _currentLibrary != superclassLibrary ) {
17738 continue; 17826 continue;
17739 } 17827 }
17740 // instance vs. static 17828 // instance vs. static
17741 if (methodElement.isStatic) { 17829 if (methodElement.isStatic) {
17742 _errorReporter.reportError3(StaticWarningCode.INSTANCE_METHOD_NAME _COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [ 17830 _errorReporter.reportError2(StaticWarningCode.INSTANCE_METHOD_NAME _COLLIDES_WITH_SUPERCLASS_STATIC, errorNameTarget, [
17743 executableElementName, 17831 executableElementName,
17744 methodElement.enclosingElement.displayName]); 17832 methodElement.enclosingElement.displayName]);
17745 return true; 17833 return true;
17746 } 17834 }
17747 } 17835 }
17748 superclassType = superclassElement.supertype; 17836 superclassType = superclassElement.supertype;
17749 superclassElement = superclassType == null ? null : superclassType.ele ment; 17837 superclassElement = superclassType == null ? null : superclassType.ele ment;
17750 } 17838 }
17751 } 17839 }
17752 return false; 17840 return false;
17753 } 17841 }
17754 FunctionType overridingFT = executableElement.type; 17842 FunctionType overridingFT = executableElement.type;
17755 FunctionType overriddenFT = overriddenExecutable.type; 17843 FunctionType overriddenFT = overriddenExecutable.type;
17756 InterfaceType enclosingType = _enclosingClass.type; 17844 InterfaceType enclosingType = _enclosingClass.type;
17757 overriddenFT = _inheritanceManager.substituteTypeArgumentsInMemberFromInheri tance(overriddenFT, executableElementName, enclosingType); 17845 overriddenFT = _inheritanceManager.substituteTypeArgumentsInMemberFromInheri tance(overriddenFT, executableElementName, enclosingType);
17758 if (overridingFT == null || overriddenFT == null) { 17846 if (overridingFT == null || overriddenFT == null) {
17759 return false; 17847 return false;
17760 } 17848 }
17761 Type2 overridingFTReturnType = overridingFT.returnType; 17849 Type2 overridingFTReturnType = overridingFT.returnType;
17762 Type2 overriddenFTReturnType = overriddenFT.returnType; 17850 Type2 overriddenFTReturnType = overriddenFT.returnType;
17763 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes; 17851 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes;
17764 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes; 17852 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes;
17765 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; 17853 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes;
17766 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; 17854 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes;
17767 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; 17855 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes;
17768 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; 17856 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes;
17769 // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and CTEC .INVALID_OVERRIDE_NAMED 17857 // CTEC.INVALID_OVERRIDE_REQUIRED, CTEC.INVALID_OVERRIDE_POSITIONAL and CTEC .INVALID_OVERRIDE_NAMED
17770 if (overridingNormalPT.length > overriddenNormalPT.length) { 17858 if (overridingNormalPT.length > overriddenNormalPT.length) {
17771 _errorReporter.reportError3(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e rrorNameTarget, [ 17859 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e rrorNameTarget, [
17772 overriddenNormalPT.length, 17860 overriddenNormalPT.length,
17773 overriddenExecutable.enclosingElement.displayName]); 17861 overriddenExecutable.enclosingElement.displayName]);
17774 return true; 17862 return true;
17775 } 17863 }
17776 if (overridingNormalPT.length + overridingPositionalPT.length < overriddenPo sitionalPT.length + overriddenNormalPT.length) { 17864 if (overridingNormalPT.length + overridingPositionalPT.length < overriddenPo sitionalPT.length + overriddenNormalPT.length) {
17777 _errorReporter.reportError3(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL, errorNameTarget, [ 17865 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL, errorNameTarget, [
17778 overriddenPositionalPT.length + overriddenNormalPT.length, 17866 overriddenPositionalPT.length + overriddenNormalPT.length,
17779 overriddenExecutable.enclosingElement.displayName]); 17867 overriddenExecutable.enclosingElement.displayName]);
17780 return true; 17868 return true;
17781 } 17869 }
17782 // For each named parameter in the overridden method, verify that there is t he same name in 17870 // For each named parameter in the overridden method, verify that there is t he same name in
17783 // the overriding method, and in the same order. 17871 // the overriding method, and in the same order.
17784 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet(); 17872 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet();
17785 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over riddenNamedPT.keys.toSet()); 17873 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over riddenNamedPT.keys.toSet());
17786 while (overriddenParameterNameIterator.hasNext) { 17874 while (overriddenParameterNameIterator.hasNext) {
17787 String overriddenParamName = overriddenParameterNameIterator.next(); 17875 String overriddenParamName = overriddenParameterNameIterator.next();
17788 if (!overridingParameterNameSet.contains(overriddenParamName)) { 17876 if (!overridingParameterNameSet.contains(overriddenParamName)) {
17789 // The overridden method expected the overriding method to have overridi ngParamName, 17877 // The overridden method expected the overriding method to have overridi ngParamName,
17790 // but it does not. 17878 // but it does not.
17791 _errorReporter.reportError3(StaticWarningCode.INVALID_OVERRIDE_NAMED, er rorNameTarget, [ 17879 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_NAMED, er rorNameTarget, [
17792 overriddenParamName, 17880 overriddenParamName,
17793 overriddenExecutable.enclosingElement.displayName]); 17881 overriddenExecutable.enclosingElement.displayName]);
17794 return true; 17882 return true;
17795 } 17883 }
17796 } 17884 }
17797 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE 17885 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE
17798 if (overriddenFTReturnType != VoidTypeImpl.instance && !overridingFTReturnTy pe.isAssignableTo(overriddenFTReturnType)) { 17886 if (overriddenFTReturnType != VoidTypeImpl.instance && !overridingFTReturnTy pe.isAssignableTo(overriddenFTReturnType)) {
17799 _errorReporter.reportError3(!isGetter ? StaticWarningCode.INVALID_METHOD_O VERRIDE_RETURN_TYPE : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, err orNameTarget, [ 17887 _errorReporter.reportError2(!isGetter ? StaticWarningCode.INVALID_METHOD_O VERRIDE_RETURN_TYPE : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, err orNameTarget, [
17800 overridingFTReturnType.displayName, 17888 overridingFTReturnType.displayName,
17801 overriddenFTReturnType.displayName, 17889 overriddenFTReturnType.displayName,
17802 overriddenExecutable.enclosingElement.displayName]); 17890 overriddenExecutable.enclosingElement.displayName]);
17803 return true; 17891 return true;
17804 } 17892 }
17805 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE 17893 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE
17806 if (parameterLocations == null) { 17894 if (parameterLocations == null) {
17807 return false; 17895 return false;
17808 } 17896 }
17809 int parameterIndex = 0; 17897 int parameterIndex = 0;
17810 for (int i = 0; i < overridingNormalPT.length; i++) { 17898 for (int i = 0; i < overridingNormalPT.length; i++) {
17811 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { 17899 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) {
17812 _errorReporter.reportError3(!isSetter ? StaticWarningCode.INVALID_METHOD _OVERRIDE_NORMAL_PARAM_TYPE : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_P ARAM_TYPE, parameterLocations[parameterIndex], [ 17900 _errorReporter.reportError2(!isSetter ? StaticWarningCode.INVALID_METHOD _OVERRIDE_NORMAL_PARAM_TYPE : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_P ARAM_TYPE, parameterLocations[parameterIndex], [
17813 overridingNormalPT[i].displayName, 17901 overridingNormalPT[i].displayName,
17814 overriddenNormalPT[i].displayName, 17902 overriddenNormalPT[i].displayName,
17815 overriddenExecutable.enclosingElement.displayName]); 17903 overriddenExecutable.enclosingElement.displayName]);
17816 return true; 17904 return true;
17817 } 17905 }
17818 parameterIndex++; 17906 parameterIndex++;
17819 } 17907 }
17820 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE 17908 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE
17821 for (int i = 0; i < overriddenPositionalPT.length; i++) { 17909 for (int i = 0; i < overriddenPositionalPT.length; i++) {
17822 if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i])) { 17910 if (!overridingPositionalPT[i].isAssignableTo(overriddenPositionalPT[i])) {
17823 _errorReporter.reportError3(StaticWarningCode.INVALID_METHOD_OVERRIDE_OP TIONAL_PARAM_TYPE, parameterLocations[parameterIndex], [ 17911 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_OP TIONAL_PARAM_TYPE, parameterLocations[parameterIndex], [
17824 overridingPositionalPT[i].displayName, 17912 overridingPositionalPT[i].displayName,
17825 overriddenPositionalPT[i].displayName, 17913 overriddenPositionalPT[i].displayName,
17826 overriddenExecutable.enclosingElement.displayName]); 17914 overriddenExecutable.enclosingElement.displayName]);
17827 return true; 17915 return true;
17828 } 17916 }
17829 parameterIndex++; 17917 parameterIndex++;
17830 } 17918 }
17831 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & SWC.INVALID_OVERRIDE_DIFFE RENT_DEFAULT_VALUES 17919 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & SWC.INVALID_OVERRIDE_DIFFE RENT_DEFAULT_VALUES
17832 JavaIterator<MapEntry<String, Type2>> overriddenNamedPTIterator = new JavaIt erator(getMapEntrySet(overriddenNamedPT)); 17920 JavaIterator<MapEntry<String, Type2>> overriddenNamedPTIterator = new JavaIt erator(getMapEntrySet(overriddenNamedPT));
17833 while (overriddenNamedPTIterator.hasNext) { 17921 while (overriddenNamedPTIterator.hasNext) {
(...skipping 10 matching lines...) Expand all
17844 AstNode parameterLocationToSelect = null; 17932 AstNode parameterLocationToSelect = null;
17845 for (int i = 0; i < parameters.length; i++) { 17933 for (int i = 0; i < parameters.length; i++) {
17846 ParameterElement parameter = parameters[i]; 17934 ParameterElement parameter = parameters[i];
17847 if (identical(parameter.parameterKind, ParameterKind.NAMED) && overrid denNamedPTEntry.getKey() == parameter.name) { 17935 if (identical(parameter.parameterKind, ParameterKind.NAMED) && overrid denNamedPTEntry.getKey() == parameter.name) {
17848 parameterToSelect = parameter; 17936 parameterToSelect = parameter;
17849 parameterLocationToSelect = parameterLocations[i]; 17937 parameterLocationToSelect = parameterLocations[i];
17850 break; 17938 break;
17851 } 17939 }
17852 } 17940 }
17853 if (parameterToSelect != null) { 17941 if (parameterToSelect != null) {
17854 _errorReporter.reportError3(StaticWarningCode.INVALID_METHOD_OVERRIDE_ NAMED_PARAM_TYPE, parameterLocationToSelect, [ 17942 _errorReporter.reportError2(StaticWarningCode.INVALID_METHOD_OVERRIDE_ NAMED_PARAM_TYPE, parameterLocationToSelect, [
17855 overridingType.displayName, 17943 overridingType.displayName,
17856 overriddenNamedPTEntry.getValue().displayName, 17944 overriddenNamedPTEntry.getValue().displayName,
17857 overriddenExecutable.enclosingElement.displayName]); 17945 overriddenExecutable.enclosingElement.displayName]);
17858 return true; 17946 return true;
17859 } 17947 }
17860 } 17948 }
17861 } 17949 }
17862 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES 17950 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES
17863 // 17951 //
17864 // Create three arrays: an array of the optional parameter ASTs (FormalParam eters), an array of 17952 // Create three arrays: an array of the optional parameter ASTs (FormalParam eters), an array of
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
17901 String parameterName = parameterElt.name; 17989 String parameterName = parameterElt.name;
17902 for (int j = 0; j < overriddenParameterElts.length; j++) { 17990 for (int j = 0; j < overriddenParameterElts.length; j++) {
17903 ParameterElementImpl overriddenParameterElt = overriddenParameterElt s[j]; 17991 ParameterElementImpl overriddenParameterElt = overriddenParameterElt s[j];
17904 String overriddenParameterName = overriddenParameterElt.name; 17992 String overriddenParameterName = overriddenParameterElt.name;
17905 if (parameterName != null && parameterName == overriddenParameterNam e) { 17993 if (parameterName != null && parameterName == overriddenParameterNam e) {
17906 EvaluationResultImpl overriddenResult = overriddenParameterElt.eva luationResult; 17994 EvaluationResultImpl overriddenResult = overriddenParameterElt.eva luationResult;
17907 if (isUserDefinedObject(overriddenResult)) { 17995 if (isUserDefinedObject(overriddenResult)) {
17908 break; 17996 break;
17909 } 17997 }
17910 if (!result.equalValues(_typeProvider, overriddenResult)) { 17998 if (!result.equalValues(_typeProvider, overriddenResult)) {
17911 _errorReporter.reportError3(StaticWarningCode.INVALID_OVERRIDE_D IFFERENT_DEFAULT_VALUES_NAMED, formalParameters[i], [ 17999 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_D IFFERENT_DEFAULT_VALUES_NAMED, formalParameters[i], [
17912 overriddenExecutable.enclosingElement.displayName, 18000 overriddenExecutable.enclosingElement.displayName,
17913 overriddenExecutable.displayName, 18001 overriddenExecutable.displayName,
17914 parameterName]); 18002 parameterName]);
17915 foundError = true; 18003 foundError = true;
17916 } 18004 }
17917 } 18005 }
17918 } 18006 }
17919 } 18007 }
17920 } else { 18008 } else {
17921 // Positional parameters, consider the positions when matching the param eterElts to the overriddenParameterElts 18009 // Positional parameters, consider the positions when matching the param eterElts to the overriddenParameterElts
17922 for (int i = 0; i < parameterElts.length && i < overriddenParameterElts. length; i++) { 18010 for (int i = 0; i < parameterElts.length && i < overriddenParameterElts. length; i++) {
17923 ParameterElementImpl parameterElt = parameterElts[i]; 18011 ParameterElementImpl parameterElt = parameterElts[i];
17924 EvaluationResultImpl result = parameterElt.evaluationResult; 18012 EvaluationResultImpl result = parameterElt.evaluationResult;
17925 // TODO (jwren) Ignore Object types, see Dart bug 11287 18013 // TODO (jwren) Ignore Object types, see Dart bug 11287
17926 if (isUserDefinedObject(result)) { 18014 if (isUserDefinedObject(result)) {
17927 continue; 18015 continue;
17928 } 18016 }
17929 ParameterElementImpl overriddenParameterElt = overriddenParameterElts[ i]; 18017 ParameterElementImpl overriddenParameterElt = overriddenParameterElts[ i];
17930 EvaluationResultImpl overriddenResult = overriddenParameterElt.evaluat ionResult; 18018 EvaluationResultImpl overriddenResult = overriddenParameterElt.evaluat ionResult;
17931 if (isUserDefinedObject(overriddenResult)) { 18019 if (isUserDefinedObject(overriddenResult)) {
17932 continue; 18020 continue;
17933 } 18021 }
17934 if (!result.equalValues(_typeProvider, overriddenResult)) { 18022 if (!result.equalValues(_typeProvider, overriddenResult)) {
17935 _errorReporter.reportError3(StaticWarningCode.INVALID_OVERRIDE_DIFFE RENT_DEFAULT_VALUES_POSITIONAL, formalParameters[i], [ 18023 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_DIFFE RENT_DEFAULT_VALUES_POSITIONAL, formalParameters[i], [
17936 overriddenExecutable.enclosingElement.displayName, 18024 overriddenExecutable.enclosingElement.displayName,
17937 overriddenExecutable.displayName]); 18025 overriddenExecutable.displayName]);
17938 foundError = true; 18026 foundError = true;
17939 } 18027 }
17940 } 18028 }
17941 } 18029 }
17942 } 18030 }
17943 return foundError; 18031 return foundError;
17944 } 18032 }
17945 18033
17946 /** 18034 /**
17947 * This checks the passed executable element against override-error codes. Thi s method computes 18035 * This checks the passed executable element against override-error codes. Thi s method computes
17948 * the passed executableElement is overriding and calls 18036 * the passed executableElement is overriding and calls
17949 * [checkForAllInvalidOverrideErrorCodes] 18037 * [checkForAllInvalidOverrideErrorCodes]
17950 * when the [InheritanceManager] returns a [MultiplyInheritedExecutableElement ], this 18038 * when the [InheritanceManager] returns a [MultiplyInheritedExecutableElement ], this
17951 * method loops through the array in the [MultiplyInheritedExecutableElement]. 18039 * method loops through the array in the [MultiplyInheritedExecutableElement].
17952 * 18040 *
17953 * @param executableElement a non-null [ExecutableElement] to evaluate 18041 * @param executableElement a non-null [ExecutableElement] to evaluate
17954 * @param parameters the parameters of the executable element 18042 * @param parameters the parameters of the executable element
17955 * @param errorNameTarget the node to report problems on 18043 * @param errorNameTarget the node to report problems on
17956 * @return `true` if and only if an error code is generated on the passed node 18044 * @return `true` if and only if an error code is generated on the passed node
17957 */ 18045 */
17958 bool checkForAllInvalidOverrideErrorCodes2(ExecutableElement executableElement , List<ParameterElement> parameters, List<AstNode> parameterLocations, SimpleIde ntifier errorNameTarget) { 18046 bool checkForAllInvalidOverrideErrorCodesForExecutable(ExecutableElement execu tableElement, List<ParameterElement> parameters, List<AstNode> parameterLocation s, SimpleIdentifier errorNameTarget) {
17959 // 18047 //
17960 // Compute the overridden executable from the InheritanceManager 18048 // Compute the overridden executable from the InheritanceManager
17961 // 18049 //
17962 ExecutableElement overriddenExecutable = _inheritanceManager.lookupInheritan ce(_enclosingClass, executableElement.name); 18050 ExecutableElement overriddenExecutable = _inheritanceManager.lookupInheritan ce(_enclosingClass, executableElement.name);
17963 // 18051 //
17964 // If the result is a MultiplyInheritedExecutableElement call 18052 // If the result is a MultiplyInheritedExecutableElement call
17965 // checkForAllInvalidOverrideErrorCodes on all of the elements, until an err or is found. 18053 // checkForAllInvalidOverrideErrorCodes on all of the elements, until an err or is found.
17966 // 18054 //
17967 if (overriddenExecutable is MultiplyInheritedExecutableElement) { 18055 if (overriddenExecutable is MultiplyInheritedExecutableElement) {
17968 MultiplyInheritedExecutableElement multiplyInheritedElement = overriddenEx ecutable; 18056 MultiplyInheritedExecutableElement multiplyInheritedElement = overriddenEx ecutable;
(...skipping 11 matching lines...) Expand all
17980 return checkForAllInvalidOverrideErrorCodes(executableElement, overriddenExe cutable, parameters, parameterLocations, errorNameTarget); 18068 return checkForAllInvalidOverrideErrorCodes(executableElement, overriddenExe cutable, parameters, parameterLocations, errorNameTarget);
17981 } 18069 }
17982 18070
17983 /** 18071 /**
17984 * This checks the passed field declaration against override-error codes. 18072 * This checks the passed field declaration against override-error codes.
17985 * 18073 *
17986 * @param node the [MethodDeclaration] to evaluate 18074 * @param node the [MethodDeclaration] to evaluate
17987 * @return `true` if and only if an error code is generated on the passed node 18075 * @return `true` if and only if an error code is generated on the passed node
17988 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement) 18076 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement)
17989 */ 18077 */
17990 bool checkForAllInvalidOverrideErrorCodes3(FieldDeclaration node) { 18078 bool checkForAllInvalidOverrideErrorCodesForField(FieldDeclaration node) {
17991 if (_enclosingClass == null || node.isStatic) { 18079 if (_enclosingClass == null || node.isStatic) {
17992 return false; 18080 return false;
17993 } 18081 }
17994 bool hasProblems = false; 18082 bool hasProblems = false;
17995 VariableDeclarationList fields = node.fields; 18083 VariableDeclarationList fields = node.fields;
17996 for (VariableDeclaration field in fields.variables) { 18084 for (VariableDeclaration field in fields.variables) {
17997 FieldElement element = field.element as FieldElement; 18085 FieldElement element = field.element as FieldElement;
17998 if (element == null) { 18086 if (element == null) {
17999 continue; 18087 continue;
18000 } 18088 }
18001 PropertyAccessorElement getter = element.getter; 18089 PropertyAccessorElement getter = element.getter;
18002 PropertyAccessorElement setter = element.setter; 18090 PropertyAccessorElement setter = element.setter;
18003 SimpleIdentifier fieldName = field.name; 18091 SimpleIdentifier fieldName = field.name;
18004 if (getter != null) { 18092 if (getter != null) {
18005 hasProblems = javaBooleanOr(hasProblems, checkForAllInvalidOverrideError Codes2(getter, ParameterElementImpl.EMPTY_ARRAY, AstNode.EMPTY_ARRAY, fieldName) ); 18093 hasProblems = javaBooleanOr(hasProblems, checkForAllInvalidOverrideError CodesForExecutable(getter, ParameterElementImpl.EMPTY_ARRAY, AstNode.EMPTY_ARRAY , fieldName));
18006 } 18094 }
18007 if (setter != null) { 18095 if (setter != null) {
18008 hasProblems = javaBooleanOr(hasProblems, checkForAllInvalidOverrideError Codes2(setter, setter.parameters, <AstNode> [fieldName], fieldName)); 18096 hasProblems = javaBooleanOr(hasProblems, checkForAllInvalidOverrideError CodesForExecutable(setter, setter.parameters, <AstNode> [fieldName], fieldName)) ;
18009 } 18097 }
18010 } 18098 }
18011 return hasProblems; 18099 return hasProblems;
18012 } 18100 }
18013 18101
18014 /** 18102 /**
18015 * This checks the passed method declaration against override-error codes. 18103 * This checks the passed method declaration against override-error codes.
18016 * 18104 *
18017 * @param node the [MethodDeclaration] to evaluate 18105 * @param node the [MethodDeclaration] to evaluate
18018 * @return `true` if and only if an error code is generated on the passed node 18106 * @return `true` if and only if an error code is generated on the passed node
18019 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement) 18107 * @see #checkForAllInvalidOverrideErrorCodes(ExecutableElement)
18020 */ 18108 */
18021 bool checkForAllInvalidOverrideErrorCodes4(MethodDeclaration node) { 18109 bool checkForAllInvalidOverrideErrorCodesForMethod(MethodDeclaration node) {
18022 if (_enclosingClass == null || node.isStatic || node.body is NativeFunctionB ody) { 18110 if (_enclosingClass == null || node.isStatic || node.body is NativeFunctionB ody) {
18023 return false; 18111 return false;
18024 } 18112 }
18025 ExecutableElement executableElement = node.element; 18113 ExecutableElement executableElement = node.element;
18026 if (executableElement == null) { 18114 if (executableElement == null) {
18027 return false; 18115 return false;
18028 } 18116 }
18029 SimpleIdentifier methodName = node.name; 18117 SimpleIdentifier methodName = node.name;
18030 if (methodName.isSynthetic) { 18118 if (methodName.isSynthetic) {
18031 return false; 18119 return false;
18032 } 18120 }
18033 FormalParameterList formalParameterList = node.parameters; 18121 FormalParameterList formalParameterList = node.parameters;
18034 NodeList<FormalParameter> parameterList = formalParameterList != null ? form alParameterList.parameters : null; 18122 NodeList<FormalParameter> parameterList = formalParameterList != null ? form alParameterList.parameters : null;
18035 List<AstNode> parameters = parameterList != null ? new List.from(parameterLi st) : null; 18123 List<AstNode> parameters = parameterList != null ? new List.from(parameterLi st) : null;
18036 return checkForAllInvalidOverrideErrorCodes2(executableElement, executableEl ement.parameters, parameters, methodName); 18124 return checkForAllInvalidOverrideErrorCodesForExecutable(executableElement, executableElement.parameters, parameters, methodName);
18037 } 18125 }
18038 18126
18039 /** 18127 /**
18040 * This verifies that all classes of the passed 'with' clause are valid. 18128 * This verifies that all classes of the passed 'with' clause are valid.
18041 * 18129 *
18042 * @param node the 'with' clause to evaluate 18130 * @param node the 'with' clause to evaluate
18043 * @return `true` if and only if an error code is generated on the passed node 18131 * @return `true` if and only if an error code is generated on the passed node
18044 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR 18132 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR
18045 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT 18133 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT
18046 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER 18134 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
18096 Type2 redirectedType = constructorTypeName.type; 18184 Type2 redirectedType = constructorTypeName.type;
18097 if (redirectedType != null && redirectedType.element != null && !redirecte dType.isDynamic) { 18185 if (redirectedType != null && redirectedType.element != null && !redirecte dType.isDynamic) {
18098 // 18186 //
18099 // Prepare the constructor name 18187 // Prepare the constructor name
18100 // 18188 //
18101 String constructorStrName = constructorTypeName.name.name; 18189 String constructorStrName = constructorTypeName.name.name;
18102 if (redirectedConstructor.name != null) { 18190 if (redirectedConstructor.name != null) {
18103 constructorStrName += ".${redirectedConstructor.name.name}"; 18191 constructorStrName += ".${redirectedConstructor.name.name}";
18104 } 18192 }
18105 ErrorCode errorCode = (node.constKeyword != null ? CompileTimeErrorCode. REDIRECT_TO_MISSING_CONSTRUCTOR : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUC TOR) as ErrorCode; 18193 ErrorCode errorCode = (node.constKeyword != null ? CompileTimeErrorCode. REDIRECT_TO_MISSING_CONSTRUCTOR : StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUC TOR) as ErrorCode;
18106 _errorReporter.reportError3(errorCode, redirectedConstructor, [construct orStrName, redirectedType.displayName]); 18194 _errorReporter.reportError2(errorCode, redirectedConstructor, [construct orStrName, redirectedType.displayName]);
18107 return true; 18195 return true;
18108 } 18196 }
18109 return false; 18197 return false;
18110 } 18198 }
18111 FunctionType redirectedType = redirectedElement.type; 18199 FunctionType redirectedType = redirectedElement.type;
18112 Type2 redirectedReturnType = redirectedType.returnType; 18200 Type2 redirectedReturnType = redirectedType.returnType;
18113 // 18201 //
18114 // Report specific problem when return type is incompatible 18202 // Report specific problem when return type is incompatible
18115 // 18203 //
18116 FunctionType constructorType = node.element.type; 18204 FunctionType constructorType = node.element.type;
18117 Type2 constructorReturnType = constructorType.returnType; 18205 Type2 constructorReturnType = constructorType.returnType;
18118 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { 18206 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) {
18119 _errorReporter.reportError3(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T YPE, redirectedConstructor, [redirectedReturnType, constructorReturnType]); 18207 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_RETURN_T YPE, redirectedConstructor, [redirectedReturnType, constructorReturnType]);
18120 return true; 18208 return true;
18121 } 18209 }
18122 // 18210 //
18123 // Check parameters 18211 // Check parameters
18124 // 18212 //
18125 if (!redirectedType.isSubtypeOf(constructorType)) { 18213 if (!redirectedType.isSubtypeOf(constructorType)) {
18126 _errorReporter.reportError3(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION _TYPE, redirectedConstructor, [redirectedType, constructorType]); 18214 _errorReporter.reportError2(StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION _TYPE, redirectedConstructor, [redirectedType, constructorType]);
18127 return true; 18215 return true;
18128 } 18216 }
18129 return false; 18217 return false;
18130 } 18218 }
18131 18219
18132 /** 18220 /**
18133 * This checks that the return statement of the form <i>return e;</i> is not i n a generative 18221 * This checks that the return statement of the form <i>return e;</i> is not i n a generative
18134 * constructor. 18222 * constructor.
18135 * 18223 *
18136 * This checks that return statements without expressions are not in a generat ive constructor and 18224 * This checks that return statements without expressions are not in a generat ive constructor and
(...skipping 12 matching lines...) Expand all
18149 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) { 18237 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) {
18150 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type; 18238 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
18151 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType; 18239 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType;
18152 Expression returnExpression = node.expression; 18240 Expression returnExpression = node.expression;
18153 // RETURN_IN_GENERATIVE_CONSTRUCTOR 18241 // RETURN_IN_GENERATIVE_CONSTRUCTOR
18154 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! (_enclosingFunction as ConstructorElement).isFactory; 18242 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! (_enclosingFunction as ConstructorElement).isFactory;
18155 if (isGenerativeConstructor) { 18243 if (isGenerativeConstructor) {
18156 if (returnExpression == null) { 18244 if (returnExpression == null) {
18157 return false; 18245 return false;
18158 } 18246 }
18159 _errorReporter.reportError3(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONS TRUCTOR, returnExpression, []); 18247 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONS TRUCTOR, returnExpression, []);
18160 return true; 18248 return true;
18161 } 18249 }
18162 // RETURN_WITHOUT_VALUE 18250 // RETURN_WITHOUT_VALUE
18163 if (returnExpression == null) { 18251 if (returnExpression == null) {
18164 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { 18252 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) {
18165 return false; 18253 return false;
18166 } 18254 }
18167 _errorReporter.reportError3(StaticWarningCode.RETURN_WITHOUT_VALUE, node, []); 18255 _errorReporter.reportError2(StaticWarningCode.RETURN_WITHOUT_VALUE, node, []);
18168 return true; 18256 return true;
18169 } 18257 }
18170 // RETURN_OF_INVALID_TYPE 18258 // RETURN_OF_INVALID_TYPE
18171 return checkForReturnOfInvalidType(returnExpression, expectedReturnType); 18259 return checkForReturnOfInvalidType(returnExpression, expectedReturnType);
18172 } 18260 }
18173 18261
18174 /** 18262 /**
18175 * This verifies that the export namespace of the passed export directive does not export any name 18263 * This verifies that the export namespace of the passed export directive does not export any name
18176 * already exported by other export directive. 18264 * already exported by other export directive.
18177 * 18265 *
(...skipping 13 matching lines...) Expand all
18191 return false; 18279 return false;
18192 } 18280 }
18193 // check exported names 18281 // check exported names
18194 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle ment); 18282 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle ment);
18195 Map<String, Element> definedNames = namespace.definedNames; 18283 Map<String, Element> definedNames = namespace.definedNames;
18196 for (MapEntry<String, Element> definedEntry in getMapEntrySet(definedNames)) { 18284 for (MapEntry<String, Element> definedEntry in getMapEntrySet(definedNames)) {
18197 String name = definedEntry.getKey(); 18285 String name = definedEntry.getKey();
18198 Element element = definedEntry.getValue(); 18286 Element element = definedEntry.getValue();
18199 Element prevElement = _exportedElements[name]; 18287 Element prevElement = _exportedElements[name];
18200 if (element != null && prevElement != null && prevElement != element) { 18288 if (element != null && prevElement != null && prevElement != element) {
18201 _errorReporter.reportError3(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node, [ 18289 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node, [
18202 name, 18290 name,
18203 prevElement.library.definingCompilationUnit.displayName, 18291 prevElement.library.definingCompilationUnit.displayName,
18204 element.library.definingCompilationUnit.displayName]); 18292 element.library.definingCompilationUnit.displayName]);
18205 return true; 18293 return true;
18206 } else { 18294 } else {
18207 _exportedElements[name] = element; 18295 _exportedElements[name] = element;
18208 } 18296 }
18209 } 18297 }
18210 return false; 18298 return false;
18211 } 18299 }
18212 18300
18213 /** 18301 /**
18214 * This verifies that the passed argument definition test identifier is a para meter. 18302 * This verifies that the passed argument definition test identifier is a para meter.
18215 * 18303 *
18216 * @param node the [ArgumentDefinitionTest] to evaluate 18304 * @param node the [ArgumentDefinitionTest] to evaluate
18217 * @return `true` if and only if an error code is generated on the passed node 18305 * @return `true` if and only if an error code is generated on the passed node
18218 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER 18306 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER
18219 */ 18307 */
18220 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { 18308 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) {
18221 SimpleIdentifier identifier = node.identifier; 18309 SimpleIdentifier identifier = node.identifier;
18222 Element element = identifier.staticElement; 18310 Element element = identifier.staticElement;
18223 if (element != null && element is! ParameterElement) { 18311 if (element != null && element is! ParameterElement) {
18224 _errorReporter.reportError3(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_ NON_PARAMETER, identifier, [identifier.name]); 18312 _errorReporter.reportError2(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_ NON_PARAMETER, identifier, [identifier.name]);
18225 return true; 18313 return true;
18226 } 18314 }
18227 return false; 18315 return false;
18228 } 18316 }
18229 18317
18230 /** 18318 /**
18231 * This verifies that the passed arguments can be assigned to their correspond ing parameters. 18319 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
18232 * 18320 *
18233 * @param node the arguments to evaluate 18321 * @param expression the expression to evaluate
18322 * @param expectedStaticType the expected static type of the parameter
18323 * @param actualStaticType the actual static type of the argument
18324 * @param expectedPropagatedType the expected propagated type of the parameter , may be
18325 * `null`
18326 * @param actualPropagatedType the expected propagated type of the parameter, may be `null`
18234 * @return `true` if and only if an error code is generated on the passed node 18327 * @return `true` if and only if an error code is generated on the passed node
18235 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 18328 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
18236 */ 18329 */
18237 bool checkForArgumentTypeNotAssignable(ArgumentList argumentList) { 18330 bool checkForArgumentTypeNotAssignable(Expression expression, Type2 expectedSt aticType, Type2 actualStaticType, Type2 expectedPropagatedType, Type2 actualProp agatedType, ErrorCode errorCode) {
18238 if (argumentList == null) { 18331 //
18332 // Test static type information
18333 //
18334 if (actualStaticType == null || expectedStaticType == null) {
18239 return false; 18335 return false;
18240 } 18336 }
18241 bool problemReported = false; 18337 if (actualStaticType.isAssignableTo(expectedStaticType)) {
18242 for (Expression argument in argumentList.arguments) { 18338 return false;
18243 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs signable2(argument));
18244 } 18339 }
18245 // done 18340 _errorReporter.reportError2(errorCode, expression, [
18246 return problemReported; 18341 actualStaticType.displayName,
18342 expectedStaticType.displayName]);
18343 return true;
18247 } 18344 }
18248 18345
18249 /** 18346 /**
18250 * This verifies that the passed argument can be assigned to its corresponding parameter. 18347 * This verifies that the passed argument can be assigned to its corresponding parameter.
18251 * 18348 *
18252 * @param argument the argument to evaluate 18349 * @param argument the argument to evaluate
18253 * @return `true` if and only if an error code is generated on the passed node 18350 * @return `true` if and only if an error code is generated on the passed node
18254 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 18351 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
18255 */ 18352 */
18256 bool checkForArgumentTypeNotAssignable2(Expression argument) { 18353 bool checkForArgumentTypeNotAssignableForArgument(Expression argument) {
18257 if (argument == null) { 18354 if (argument == null) {
18258 return false; 18355 return false;
18259 } 18356 }
18260 ParameterElement staticParameterElement = argument.staticParameterElement; 18357 ParameterElement staticParameterElement = argument.staticParameterElement;
18261 Type2 staticParameterType = staticParameterElement == null ? null : staticPa rameterElement.type; 18358 Type2 staticParameterType = staticParameterElement == null ? null : staticPa rameterElement.type;
18262 ParameterElement propagatedParameterElement = argument.propagatedParameterEl ement; 18359 ParameterElement propagatedParameterElement = argument.propagatedParameterEl ement;
18263 Type2 propagatedParameterType = propagatedParameterElement == null ? null : propagatedParameterElement.type; 18360 Type2 propagatedParameterType = propagatedParameterElement == null ? null : propagatedParameterElement.type;
18264 return checkForArgumentTypeNotAssignable3(argument, staticParameterType, pro pagatedParameterType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); 18361 return checkForArgumentTypeNotAssignableWithExpectedTypes(argument, staticPa rameterType, propagatedParameterType, StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGN ABLE);
18265 } 18362 }
18266 18363
18267 /** 18364 /**
18268 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 18365 * This verifies that the passed expression can be assigned to its correspondi ng parameters.
18269 * 18366 *
18270 * @param expression the expression to evaluate 18367 * @param expression the expression to evaluate
18271 * @param expectedStaticType the expected static type 18368 * @param expectedStaticType the expected static type
18272 * @param expectedPropagatedType the expected propagated type, may be `null` 18369 * @param expectedPropagatedType the expected propagated type, may be `null`
18273 * @return `true` if and only if an error code is generated on the passed node 18370 * @return `true` if and only if an error code is generated on the passed node
18274 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 18371 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
18275 */ 18372 */
18276 bool checkForArgumentTypeNotAssignable3(Expression expression, Type2 expectedS taticType, Type2 expectedPropagatedType, ErrorCode errorCode) => checkForArgumen tTypeNotAssignable4(expression, expectedStaticType, getStaticType(expression), e xpectedPropagatedType, expression.propagatedType, errorCode); 18373 bool checkForArgumentTypeNotAssignableWithExpectedTypes(Expression expression, Type2 expectedStaticType, Type2 expectedPropagatedType, ErrorCode errorCode) => checkForArgumentTypeNotAssignable(expression, expectedStaticType, getStaticType (expression), expectedPropagatedType, expression.propagatedType, errorCode);
18277 18374
18278 /** 18375 /**
18279 * This verifies that the passed expression can be assigned to its correspondi ng parameters. 18376 * This verifies that the passed arguments can be assigned to their correspond ing parameters.
18280 * 18377 *
18281 * @param expression the expression to evaluate 18378 * @param node the arguments to evaluate
18282 * @param expectedStaticType the expected static type of the parameter
18283 * @param actualStaticType the actual static type of the argument
18284 * @param expectedPropagatedType the expected propagated type of the parameter , may be
18285 * `null`
18286 * @param actualPropagatedType the expected propagated type of the parameter, may be `null`
18287 * @return `true` if and only if an error code is generated on the passed node 18379 * @return `true` if and only if an error code is generated on the passed node
18288 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 18380 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
18289 */ 18381 */
18290 bool checkForArgumentTypeNotAssignable4(Expression expression, Type2 expectedS taticType, Type2 actualStaticType, Type2 expectedPropagatedType, Type2 actualPro pagatedType, ErrorCode errorCode) { 18382 bool checkForArgumentTypesNotAssignableInList(ArgumentList argumentList) {
18291 // 18383 if (argumentList == null) {
18292 // Test static type information
18293 //
18294 if (actualStaticType == null || expectedStaticType == null) {
18295 return false; 18384 return false;
18296 } 18385 }
18297 if (actualStaticType.isAssignableTo(expectedStaticType)) { 18386 bool problemReported = false;
18298 return false; 18387 for (Expression argument in argumentList.arguments) {
18388 problemReported = javaBooleanOr(problemReported, checkForArgumentTypeNotAs signableForArgument(argument));
18299 } 18389 }
18300 _errorReporter.reportError3(errorCode, expression, [ 18390 // done
18301 actualStaticType.displayName, 18391 return problemReported;
18302 expectedStaticType.displayName]);
18303 return true;
18304 } 18392 }
18305 18393
18306 /** 18394 /**
18307 * This verifies that left hand side of the passed assignment expression is no t final.
18308 *
18309 * @param node the assignment expression to evaluate
18310 * @return `true` if and only if an error code is generated on the passed node
18311 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL
18312 */
18313 bool checkForAssignmentToFinal(AssignmentExpression node) {
18314 Expression leftExpression = node.leftHandSide;
18315 return checkForAssignmentToFinal2(leftExpression);
18316 }
18317
18318 /**
18319 * This verifies that the passed expression is not final. 18395 * This verifies that the passed expression is not final.
18320 * 18396 *
18321 * @param node the expression to evaluate 18397 * @param node the expression to evaluate
18322 * @return `true` if and only if an error code is generated on the passed node 18398 * @return `true` if and only if an error code is generated on the passed node
18323 * @see StaticWarningCode#ASSIGNMENT_TO_CONST 18399 * @see StaticWarningCode#ASSIGNMENT_TO_CONST
18324 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL 18400 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL
18325 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD 18401 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD
18326 */ 18402 */
18327 bool checkForAssignmentToFinal2(Expression expression) { 18403 bool checkForAssignmentToFinal(Expression expression) {
18328 // prepare element 18404 // prepare element
18329 Element element = null; 18405 Element element = null;
18330 if (expression is Identifier) { 18406 if (expression is Identifier) {
18331 element = expression.staticElement; 18407 element = expression.staticElement;
18332 } 18408 }
18333 if (expression is PropertyAccess) { 18409 if (expression is PropertyAccess) {
18334 element = expression.propertyName.staticElement; 18410 element = expression.propertyName.staticElement;
18335 } 18411 }
18336 // check if element is assignable 18412 // check if element is assignable
18337 if (element is PropertyAccessorElement) { 18413 if (element is PropertyAccessorElement) {
18338 PropertyAccessorElement accessor = element as PropertyAccessorElement; 18414 PropertyAccessorElement accessor = element as PropertyAccessorElement;
18339 element = accessor.variable; 18415 element = accessor.variable;
18340 } 18416 }
18341 if (element is VariableElement) { 18417 if (element is VariableElement) {
18342 VariableElement variable = element as VariableElement; 18418 VariableElement variable = element as VariableElement;
18343 if (variable.isConst) { 18419 if (variable.isConst) {
18344 _errorReporter.reportError3(StaticWarningCode.ASSIGNMENT_TO_CONST, expre ssion, []); 18420 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_CONST, expre ssion, []);
18345 return true; 18421 return true;
18346 } 18422 }
18347 if (variable.isFinal) { 18423 if (variable.isFinal) {
18348 _errorReporter.reportError3(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre ssion, [variable.name]); 18424 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_FINAL, expre ssion, [variable.name]);
18349 return true; 18425 return true;
18350 } 18426 }
18351 return false; 18427 return false;
18352 } 18428 }
18353 if (element is MethodElement) { 18429 if (element is MethodElement) {
18354 _errorReporter.reportError3(StaticWarningCode.ASSIGNMENT_TO_METHOD, expres sion, []); 18430 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_METHOD, expres sion, []);
18355 return true; 18431 return true;
18356 } 18432 }
18357 return false; 18433 return false;
18358 } 18434 }
18359 18435
18360 /** 18436 /**
18361 * This verifies that the passed identifier is not a keyword, and generates th e passed error code 18437 * This verifies that the passed identifier is not a keyword, and generates th e passed error code
18362 * on the identifier if it is a keyword. 18438 * on the identifier if it is a keyword.
18363 * 18439 *
18364 * @param identifier the identifier to check to ensure that it is not a keywor d 18440 * @param identifier the identifier to check to ensure that it is not a keywor d
18365 * @param errorCode if the passed identifier is a keyword then this error code is created on the 18441 * @param errorCode if the passed identifier is a keyword then this error code is created on the
18366 * identifier, the error code will be one of 18442 * identifier, the error code will be one of
18367 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME], 18443 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME],
18368 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME] or 18444 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME] or
18369 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME] 18445 * [CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]
18370 * @return `true` if and only if an error code is generated on the passed node 18446 * @return `true` if and only if an error code is generated on the passed node
18371 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME 18447 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME
18372 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME 18448 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME
18373 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME 18449 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME
18374 */ 18450 */
18375 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er rorCode) { 18451 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er rorCode) {
18376 sc.Token token = identifier.token; 18452 sc.Token token = identifier.token;
18377 if (identical(token.type, sc.TokenType.KEYWORD)) { 18453 if (identical(token.type, sc.TokenType.KEYWORD)) {
18378 _errorReporter.reportError3(errorCode, identifier, [identifier.name]); 18454 _errorReporter.reportError2(errorCode, identifier, [identifier.name]);
18379 return true; 18455 return true;
18380 } 18456 }
18381 return false; 18457 return false;
18382 } 18458 }
18383 18459
18384 /** 18460 /**
18385 * This verifies that the given switch case is terminated with 'break', 'conti nue', 'return' or 18461 * This verifies that the given switch case is terminated with 'break', 'conti nue', 'return' or
18386 * 'throw'. 18462 * 'throw'.
18387 * 18463 *
18388 * @param node the switch case to evaluate 18464 * @param node the switch case to evaluate
(...skipping 21 matching lines...) Expand all
18410 } 18486 }
18411 // terminated with 'throw' expression 18487 // terminated with 'throw' expression
18412 if (statement is ExpressionStatement) { 18488 if (statement is ExpressionStatement) {
18413 Expression expression = statement.expression; 18489 Expression expression = statement.expression;
18414 if (expression is ThrowExpression) { 18490 if (expression is ThrowExpression) {
18415 return false; 18491 return false;
18416 } 18492 }
18417 } 18493 }
18418 } 18494 }
18419 // report error 18495 // report error
18420 _errorReporter.reportError6(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod e.keyword, []); 18496 _errorReporter.reportError5(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod e.keyword, []);
18421 return true; 18497 return true;
18422 } 18498 }
18423 18499
18424 /** 18500 /**
18425 * This verifies that the switch cases in the given switch statement is termin ated with 'break', 18501 * This verifies that the switch cases in the given switch statement is termin ated with 'break',
18426 * 'continue', 'return' or 'throw'. 18502 * 'continue', 'return' or 'throw'.
18427 * 18503 *
18428 * @param node the switch statement containing the cases to be checked 18504 * @param node the switch statement containing the cases to be checked
18429 * @return `true` if and only if an error code is generated on the passed node 18505 * @return `true` if and only if an error code is generated on the passed node
18430 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED 18506 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED
(...skipping 18 matching lines...) Expand all
18449 * @param node the switch statement to evaluate 18525 * @param node the switch statement to evaluate
18450 * @param type the common type of all 'case' expressions 18526 * @param type the common type of all 'case' expressions
18451 * @return `true` if and only if an error code is generated on the passed node 18527 * @return `true` if and only if an error code is generated on the passed node
18452 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS 18528 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
18453 */ 18529 */
18454 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty pe) { 18530 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty pe) {
18455 if (!implementsEqualsWhenNotAllowed(type)) { 18531 if (!implementsEqualsWhenNotAllowed(type)) {
18456 return false; 18532 return false;
18457 } 18533 }
18458 // report error 18534 // report error
18459 _errorReporter.reportError6(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM ENTS_EQUALS, node.keyword, [type.displayName]); 18535 _errorReporter.reportError5(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM ENTS_EQUALS, node.keyword, [type.displayName]);
18460 return true; 18536 return true;
18461 } 18537 }
18462 18538
18463 /** 18539 /**
18464 * This verifies that the passed method declaration is abstract only if the en closing class is 18540 * This verifies that the passed method declaration is abstract only if the en closing class is
18465 * also abstract. 18541 * also abstract.
18466 * 18542 *
18467 * @param node the method declaration to evaluate 18543 * @param node the method declaration to evaluate
18468 * @return `true` if and only if an error code is generated on the passed node 18544 * @return `true` if and only if an error code is generated on the passed node
18469 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER 18545 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
18470 */ 18546 */
18471 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) { 18547 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) {
18472 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac t) { 18548 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac t) {
18473 SimpleIdentifier methodName = node.name; 18549 SimpleIdentifier methodName = node.name;
18474 _errorReporter.reportError3(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT _MEMBER, methodName, [methodName.name, _enclosingClass.displayName]); 18550 _errorReporter.reportError2(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT _MEMBER, methodName, [methodName.name, _enclosingClass.displayName]);
18475 return true; 18551 return true;
18476 } 18552 }
18477 return false; 18553 return false;
18478 } 18554 }
18479 18555
18480 /** 18556 /**
18481 * This verifies all possible conflicts of the constructor name with other con structors and 18557 * This verifies all possible conflicts of the constructor name with other con structors and
18482 * members of the same class. 18558 * members of the same class.
18483 * 18559 *
18484 * @param node the constructor declaration to evaluate 18560 * @param node the constructor declaration to evaluate
18485 * @return `true` if and only if an error code is generated on the passed node 18561 * @return `true` if and only if an error code is generated on the passed node
18486 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT 18562 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_DEFAULT
18487 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME 18563 * @see CompileTimeErrorCode#DUPLICATE_CONSTRUCTOR_NAME
18488 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD 18564 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD
18489 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD 18565 * @see CompileTimeErrorCode#CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD
18490 */ 18566 */
18491 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) { 18567 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) {
18492 ConstructorElement constructorElement = node.element; 18568 ConstructorElement constructorElement = node.element;
18493 SimpleIdentifier constructorName = node.name; 18569 SimpleIdentifier constructorName = node.name;
18494 String name = constructorElement.name; 18570 String name = constructorElement.name;
18495 ClassElement classElement = constructorElement.enclosingElement; 18571 ClassElement classElement = constructorElement.enclosingElement;
18496 // constructors 18572 // constructors
18497 List<ConstructorElement> constructors = classElement.constructors; 18573 List<ConstructorElement> constructors = classElement.constructors;
18498 for (ConstructorElement otherConstructor in constructors) { 18574 for (ConstructorElement otherConstructor in constructors) {
18499 if (identical(otherConstructor, constructorElement)) { 18575 if (identical(otherConstructor, constructorElement)) {
18500 continue; 18576 continue;
18501 } 18577 }
18502 if (name == otherConstructor.name) { 18578 if (name == otherConstructor.name) {
18503 if (name == null || name.length == 0) { 18579 if (name == null || name.length == 0) {
18504 _errorReporter.reportError3(CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR _DEFAULT, node, []); 18580 _errorReporter.reportError2(CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR _DEFAULT, node, []);
18505 } else { 18581 } else {
18506 _errorReporter.reportError3(CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR _NAME, node, [name]); 18582 _errorReporter.reportError2(CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR _NAME, node, [name]);
18507 } 18583 }
18508 return true; 18584 return true;
18509 } 18585 }
18510 } 18586 }
18511 // conflict with class member 18587 // conflict with class member
18512 if (constructorName != null && constructorElement != null && !constructorNam e.isSynthetic) { 18588 if (constructorName != null && constructorElement != null && !constructorNam e.isSynthetic) {
18513 // fields 18589 // fields
18514 FieldElement field = classElement.getField(name); 18590 FieldElement field = classElement.getField(name);
18515 if (field != null) { 18591 if (field != null) {
18516 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR _NAME_AND_FIELD, node, [name]); 18592 _errorReporter.reportError2(CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR _NAME_AND_FIELD, node, [name]);
18517 return true; 18593 return true;
18518 } 18594 }
18519 // methods 18595 // methods
18520 MethodElement method = classElement.getMethod(name); 18596 MethodElement method = classElement.getMethod(name);
18521 if (method != null) { 18597 if (method != null) {
18522 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR _NAME_AND_METHOD, node, [name]); 18598 _errorReporter.reportError2(CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR _NAME_AND_METHOD, node, [name]);
18523 return true; 18599 return true;
18524 } 18600 }
18525 } 18601 }
18526 return false; 18602 return false;
18527 } 18603 }
18528 18604
18529 /** 18605 /**
18530 * This verifies that the [enclosingClass] does not have method and getter wit h the same 18606 * This verifies that the [enclosingClass] does not have method and getter wit h the same
18531 * names. 18607 * names.
18532 * 18608 *
18533 * @return `true` if and only if an error code is generated on the passed node 18609 * @return `true` if and only if an error code is generated on the passed node
18534 * @see CompileTimeErrorCode#CONFLICTING_GETTER_AND_METHOD 18610 * @see CompileTimeErrorCode#CONFLICTING_GETTER_AND_METHOD
18535 * @see CompileTimeErrorCode#CONFLICTING_METHOD_AND_GETTER 18611 * @see CompileTimeErrorCode#CONFLICTING_METHOD_AND_GETTER
18536 */ 18612 */
18537 bool checkForConflictingGetterAndMethod() { 18613 bool checkForConflictingGetterAndMethod() {
18538 if (_enclosingClass == null) { 18614 if (_enclosingClass == null) {
18539 return false; 18615 return false;
18540 } 18616 }
18541 bool hasProblem = false; 18617 bool hasProblem = false;
18542 // method declared in the enclosing class vs. inherited getter 18618 // method declared in the enclosing class vs. inherited getter
18543 for (MethodElement method in _enclosingClass.methods) { 18619 for (MethodElement method in _enclosingClass.methods) {
18544 String name = method.name; 18620 String name = method.name;
18545 // find inherited property accessor (and can be only getter) 18621 // find inherited property accessor (and can be only getter)
18546 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name); 18622 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name);
18547 if (inherited is! PropertyAccessorElement) { 18623 if (inherited is! PropertyAccessorElement) {
18548 continue; 18624 continue;
18549 } 18625 }
18550 // report problem 18626 // report problem
18551 hasProblem = true; 18627 hasProblem = true;
18552 _errorReporter.reportError5(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME THOD, method.nameOffset, name.length, [ 18628 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME THOD, method.nameOffset, name.length, [
18553 _enclosingClass.displayName, 18629 _enclosingClass.displayName,
18554 inherited.enclosingElement.displayName, 18630 inherited.enclosingElement.displayName,
18555 name]); 18631 name]);
18556 } 18632 }
18557 // getter declared in the enclosing class vs. inherited method 18633 // getter declared in the enclosing class vs. inherited method
18558 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 18634 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
18559 if (!accessor.isGetter) { 18635 if (!accessor.isGetter) {
18560 continue; 18636 continue;
18561 } 18637 }
18562 String name = accessor.name; 18638 String name = accessor.name;
18563 // find inherited method 18639 // find inherited method
18564 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name); 18640 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name);
18565 if (inherited is! MethodElement) { 18641 if (inherited is! MethodElement) {
18566 continue; 18642 continue;
18567 } 18643 }
18568 // report problem 18644 // report problem
18569 hasProblem = true; 18645 hasProblem = true;
18570 _errorReporter.reportError5(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE TTER, accessor.nameOffset, name.length, [ 18646 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE TTER, accessor.nameOffset, name.length, [
18571 _enclosingClass.displayName, 18647 _enclosingClass.displayName,
18572 inherited.enclosingElement.displayName, 18648 inherited.enclosingElement.displayName,
18573 name]); 18649 name]);
18574 } 18650 }
18575 // done 18651 // done
18576 return hasProblem; 18652 return hasProblem;
18577 } 18653 }
18578 18654
18579 /** 18655 /**
18580 * This verifies that the superclass of the [enclosingClass] does not declare accessible 18656 * This verifies that the superclass of the [enclosingClass] does not declare accessible
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
18620 // OK, not static 18696 // OK, not static
18621 if (!superElement.isStatic) { 18697 if (!superElement.isStatic) {
18622 continue; 18698 continue;
18623 } 18699 }
18624 // prepare "super" type to report its name 18700 // prepare "super" type to report its name
18625 ClassElement superElementClass = superElement.enclosingElement as ClassEle ment; 18701 ClassElement superElementClass = superElement.enclosingElement as ClassEle ment;
18626 InterfaceType superElementType = superElementClass.type; 18702 InterfaceType superElementType = superElementClass.type;
18627 // report problem 18703 // report problem
18628 hasProblem = true; 18704 hasProblem = true;
18629 if (getter) { 18705 if (getter) {
18630 _errorReporter.reportError4(StaticWarningCode.CONFLICTING_INSTANCE_GETTE R_AND_SUPERCLASS_MEMBER, accessor, [superElementType.displayName]); 18706 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_INSTANCE_GETTE R_AND_SUPERCLASS_MEMBER, accessor, [superElementType.displayName]);
18631 } else { 18707 } else {
18632 _errorReporter.reportError4(StaticWarningCode.CONFLICTING_INSTANCE_SETTE R_AND_SUPERCLASS_MEMBER, accessor, [superElementType.displayName]); 18708 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_INSTANCE_SETTE R_AND_SUPERCLASS_MEMBER, accessor, [superElementType.displayName]);
18633 } 18709 }
18634 } 18710 }
18635 // done 18711 // done
18636 return hasProblem; 18712 return hasProblem;
18637 } 18713 }
18638 18714
18639 /** 18715 /**
18640 * This verifies that the enclosing class does not have a setter with the same name as the passed 18716 * This verifies that the enclosing class does not have a setter with the same name as the passed
18641 * instance method declaration. 18717 * instance method declaration.
18642 * 18718 *
(...skipping 14 matching lines...) Expand all
18657 // ensure that we have enclosing class 18733 // ensure that we have enclosing class
18658 if (_enclosingClass == null) { 18734 if (_enclosingClass == null) {
18659 return false; 18735 return false;
18660 } 18736 }
18661 // try to find setter 18737 // try to find setter
18662 ExecutableElement setter = _inheritanceManager.lookupMember(_enclosingClass, "${name}="); 18738 ExecutableElement setter = _inheritanceManager.lookupMember(_enclosingClass, "${name}=");
18663 if (setter == null) { 18739 if (setter == null) {
18664 return false; 18740 return false;
18665 } 18741 }
18666 // report problem 18742 // report problem
18667 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SE TTER, nameNode, [ 18743 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SE TTER, nameNode, [
18668 _enclosingClass.displayName, 18744 _enclosingClass.displayName,
18669 name, 18745 name,
18670 setter.enclosingElement.displayName]); 18746 setter.enclosingElement.displayName]);
18671 return true; 18747 return true;
18672 } 18748 }
18673 18749
18674 /** 18750 /**
18675 * This verifies that the enclosing class does not have an instance member wit h the same name as 18751 * This verifies that the enclosing class does not have an instance member wit h the same name as
18676 * the passed static getter method declaration. 18752 * the passed static getter method declaration.
18677 * 18753 *
(...skipping 22 matching lines...) Expand all
18700 return false; 18776 return false;
18701 } 18777 }
18702 // OK, also static 18778 // OK, also static
18703 if (setter.isStatic) { 18779 if (setter.isStatic) {
18704 return false; 18780 return false;
18705 } 18781 }
18706 // prepare "setter" type to report its name 18782 // prepare "setter" type to report its name
18707 ClassElement setterClass = setter.enclosingElement as ClassElement; 18783 ClassElement setterClass = setter.enclosingElement as ClassElement;
18708 InterfaceType setterType = setterClass.type; 18784 InterfaceType setterType = setterClass.type;
18709 // report problem 18785 // report problem
18710 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_ INSTANCE_SETTER, nameNode, [setterType.displayName]); 18786 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_ INSTANCE_SETTER, nameNode, [setterType.displayName]);
18711 return true; 18787 return true;
18712 } 18788 }
18713 18789
18714 /** 18790 /**
18715 * This verifies that the enclosing class does not have an instance member wit h the same name as 18791 * This verifies that the enclosing class does not have an instance member wit h the same name as
18716 * the passed static getter method declaration. 18792 * the passed static getter method declaration.
18717 * 18793 *
18718 * @param node the method declaration to evaluate 18794 * @param node the method declaration to evaluate
18719 * @return `true` if and only if an error code is generated on the passed node 18795 * @return `true` if and only if an error code is generated on the passed node
18720 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER 18796 * @see StaticWarningCode#CONFLICTING_STATIC_SETTER_AND_INSTANCE_MEMBER
(...skipping 26 matching lines...) Expand all
18747 return false; 18823 return false;
18748 } 18824 }
18749 // OK, also static 18825 // OK, also static
18750 if (member.isStatic) { 18826 if (member.isStatic) {
18751 return false; 18827 return false;
18752 } 18828 }
18753 // prepare "member" type to report its name 18829 // prepare "member" type to report its name
18754 ClassElement memberClass = member.enclosingElement as ClassElement; 18830 ClassElement memberClass = member.enclosingElement as ClassElement;
18755 InterfaceType memberType = memberClass.type; 18831 InterfaceType memberType = memberClass.type;
18756 // report problem 18832 // report problem
18757 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_ INSTANCE_MEMBER, nameNode, [memberType.displayName]); 18833 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_ INSTANCE_MEMBER, nameNode, [memberType.displayName]);
18758 return true; 18834 return true;
18759 } 18835 }
18760 18836
18761 /** 18837 /**
18762 * This verifies all conflicts between type variable and enclosing class. TODO (scheglov) 18838 * This verifies all conflicts between type variable and enclosing class. TODO (scheglov)
18763 * 18839 *
18764 * @param node the class declaration to evaluate 18840 * @param node the class declaration to evaluate
18765 * @return `true` if and only if an error code is generated on the passed node 18841 * @return `true` if and only if an error code is generated on the passed node
18766 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_CLASS 18842 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_CLASS
18767 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_MEMBER 18843 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_MEMBER
18768 */ 18844 */
18769 bool checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) { 18845 bool checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) {
18770 bool problemReported = false; 18846 bool problemReported = false;
18771 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { 18847 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) {
18772 String name = typeParameter.name; 18848 String name = typeParameter.name;
18773 // name is same as the name of the enclosing class 18849 // name is same as the name of the enclosing class
18774 if (_enclosingClass.name == name) { 18850 if (_enclosingClass.name == name) {
18775 _errorReporter.reportError5(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_CLASS, typeParameter.nameOffset, name.length, [name]); 18851 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_CLASS, typeParameter.nameOffset, name.length, [name]);
18776 problemReported = true; 18852 problemReported = true;
18777 } 18853 }
18778 // check members 18854 // check members
18779 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) { 18855 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) {
18780 _errorReporter.reportError5(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]); 18856 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]);
18781 problemReported = true; 18857 problemReported = true;
18782 } 18858 }
18783 } 18859 }
18784 return problemReported; 18860 return problemReported;
18785 } 18861 }
18786 18862
18787 /** 18863 /**
18788 * This verifies that if the passed constructor declaration is 'const' then th ere are no 18864 * This verifies that if the passed constructor declaration is 'const' then th ere are no
18789 * invocations of non-'const' super constructors. 18865 * invocations of non-'const' super constructors.
18790 * 18866 *
(...skipping 10 matching lines...) Expand all
18801 return false; 18877 return false;
18802 } 18878 }
18803 // try to find and check super constructor invocation 18879 // try to find and check super constructor invocation
18804 for (ConstructorInitializer initializer in node.initializers) { 18880 for (ConstructorInitializer initializer in node.initializers) {
18805 if (initializer is SuperConstructorInvocation) { 18881 if (initializer is SuperConstructorInvocation) {
18806 SuperConstructorInvocation superInvocation = initializer; 18882 SuperConstructorInvocation superInvocation = initializer;
18807 ConstructorElement element = superInvocation.staticElement; 18883 ConstructorElement element = superInvocation.staticElement;
18808 if (element == null || element.isConst) { 18884 if (element == null || element.isConst) {
18809 return false; 18885 return false;
18810 } 18886 }
18811 _errorReporter.reportError3(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_ NON_CONST_SUPER, superInvocation, []); 18887 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_ NON_CONST_SUPER, superInvocation, []);
18812 return true; 18888 return true;
18813 } 18889 }
18814 } 18890 }
18815 // no explicit super constructor invocation, check default constructor 18891 // no explicit super constructor invocation, check default constructor
18816 InterfaceType supertype = _enclosingClass.supertype; 18892 InterfaceType supertype = _enclosingClass.supertype;
18817 if (supertype == null) { 18893 if (supertype == null) {
18818 return false; 18894 return false;
18819 } 18895 }
18820 if (supertype.isObject) { 18896 if (supertype.isObject) {
18821 return false; 18897 return false;
18822 } 18898 }
18823 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor ; 18899 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor ;
18824 if (unnamedConstructor == null) { 18900 if (unnamedConstructor == null) {
18825 return false; 18901 return false;
18826 } 18902 }
18827 if (unnamedConstructor.isConst) { 18903 if (unnamedConstructor.isConst) {
18828 return false; 18904 return false;
18829 } 18905 }
18830 // default constructor is not 'const', report problem 18906 // default constructor is not 'const', report problem
18831 _errorReporter.reportError3(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_ CONST_SUPER, node, []); 18907 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_ CONST_SUPER, node, []);
18832 return true; 18908 return true;
18833 } 18909 }
18834 18910
18835 /** 18911 /**
18836 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final 18912 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final
18837 * instance variable. 18913 * instance variable.
18838 * 18914 *
18839 * @param node the constructor declaration to evaluate 18915 * @param node the constructor declaration to evaluate
18840 * @return `true` if and only if an error code is generated on the passed node 18916 * @return `true` if and only if an error code is generated on the passed node
18841 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 18917 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD
18842 */ 18918 */
18843 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { 18919 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) {
18844 if (!_isEnclosingConstructorConst) { 18920 if (!_isEnclosingConstructorConst) {
18845 return false; 18921 return false;
18846 } 18922 }
18847 // check if there is non-final field 18923 // check if there is non-final field
18848 ConstructorElement constructorElement = node.element; 18924 ConstructorElement constructorElement = node.element;
18849 ClassElement classElement = constructorElement.enclosingElement; 18925 ClassElement classElement = constructorElement.enclosingElement;
18850 if (!classElement.hasNonFinalField()) { 18926 if (!classElement.hasNonFinalField()) {
18851 return false; 18927 return false;
18852 } 18928 }
18853 // report problem 18929 // report problem
18854 _errorReporter.reportError3(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_ FINAL_FIELD, node, []); 18930 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_ FINAL_FIELD, node, []);
18855 return true; 18931 return true;
18856 } 18932 }
18857 18933
18858 /** 18934 /**
18859 * This verifies that the passed throw expression is not enclosed in a 'const' constructor 18935 * This verifies that the passed throw expression is not enclosed in a 'const' constructor
18860 * declaration. 18936 * declaration.
18861 * 18937 *
18862 * @param node the throw expression expression to evaluate 18938 * @param node the throw expression expression to evaluate
18863 * @return `true` if and only if an error code is generated on the passed node 18939 * @return `true` if and only if an error code is generated on the passed node
18864 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION 18940 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_THROWS_EXCEPTION
18865 */ 18941 */
18866 bool checkForConstEvalThrowsException(ThrowExpression node) { 18942 bool checkForConstEvalThrowsException(ThrowExpression node) {
18867 if (_isEnclosingConstructorConst) { 18943 if (_isEnclosingConstructorConst) {
18868 _errorReporter.reportError3(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_ EXCEPTION, node, []); 18944 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_ EXCEPTION, node, []);
18869 return true; 18945 return true;
18870 } 18946 }
18871 return false; 18947 return false;
18872 } 18948 }
18873 18949
18874 /** 18950 /**
18875 * This verifies that the passed normal formal parameter is not 'const'. 18951 * This verifies that the passed normal formal parameter is not 'const'.
18876 * 18952 *
18877 * @param node the normal formal parameter to evaluate 18953 * @param node the normal formal parameter to evaluate
18878 * @return `true` if and only if an error code is generated on the passed node 18954 * @return `true` if and only if an error code is generated on the passed node
18879 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER 18955 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER
18880 */ 18956 */
18881 bool checkForConstFormalParameter(NormalFormalParameter node) { 18957 bool checkForConstFormalParameter(NormalFormalParameter node) {
18882 if (node.isConst) { 18958 if (node.isConst) {
18883 _errorReporter.reportError3(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n ode, []); 18959 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, n ode, []);
18884 return true; 18960 return true;
18885 } 18961 }
18886 return false; 18962 return false;
18887 } 18963 }
18888 18964
18889 /** 18965 /**
18890 * This verifies that the passed expression (used as a key in constant map) ha s class type that
18891 * does not declare operator <i>==<i>.
18892 *
18893 * @param key the expression to evaluate
18894 * @return `true` if and only if an error code is generated on the passed node
18895 * @see CompileTimeErrorCode#CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
18896 */
18897 bool checkForConstMapKeyExpressionTypeImplementsEquals(Expression key) {
18898 Type2 type = key.staticType;
18899 if (!implementsEqualsWhenNotAllowed(type)) {
18900 return false;
18901 }
18902 // report error
18903 _errorReporter.reportError3(CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSION_TY PE_IMPLEMENTS_EQUALS, key, [type.displayName]);
18904 return true;
18905 }
18906
18907 /**
18908 * This verifies that the all keys of the passed map literal have class type t hat does not declare 18966 * This verifies that the all keys of the passed map literal have class type t hat does not declare
18909 * operator <i>==<i>. 18967 * operator <i>==<i>.
18910 * 18968 *
18911 * @param key the map literal to evaluate 18969 * @param key the map literal to evaluate
18912 * @return `true` if and only if an error code is generated on the passed node 18970 * @return `true` if and only if an error code is generated on the passed node
18913 * @see CompileTimeErrorCode#CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS 18971 * @see CompileTimeErrorCode#CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
18914 */ 18972 */
18915 bool checkForConstMapKeyExpressionTypeImplementsEquals2(MapLiteral node) { 18973 bool checkForConstMapKeyExpressionTypeImplementsEquals(MapLiteral node) {
18916 // OK, not const. 18974 // OK, not const.
18917 if (node.constKeyword == null) { 18975 if (node.constKeyword == null) {
18918 return false; 18976 return false;
18919 } 18977 }
18920 // Check every map entry. 18978 // Check every map entry.
18921 bool hasProblems = false; 18979 bool hasProblems = false;
18922 for (MapLiteralEntry entry in node.entries) { 18980 for (MapLiteralEntry entry in node.entries) {
18923 Expression key = entry.key; 18981 Expression key = entry.key;
18924 hasProblems = javaBooleanOr(hasProblems, checkForConstMapKeyExpressionType ImplementsEquals(key)); 18982 Type2 type = key.staticType;
18983 if (implementsEqualsWhenNotAllowed(type)) {
18984 _errorReporter.reportError2(CompileTimeErrorCode.CONST_MAP_KEY_EXPRESSIO N_TYPE_IMPLEMENTS_EQUALS, key, [type.displayName]);
18985 hasProblems = true;
18986 }
18925 } 18987 }
18926 return hasProblems; 18988 return hasProblems;
18927 } 18989 }
18928 18990
18929 /** 18991 /**
18930 * This verifies that the passed instance creation expression is not being inv oked on an abstract 18992 * This verifies that the passed instance creation expression is not being inv oked on an abstract
18931 * class. 18993 * class.
18932 * 18994 *
18933 * @param node the instance creation expression to evaluate 18995 * @param node the instance creation expression to evaluate
18934 * @param typeName the [TypeName] of the [ConstructorName] from the 18996 * @param typeName the [TypeName] of the [ConstructorName] from the
18935 * [InstanceCreationExpression], this is the AST node that the error is attached to 18997 * [InstanceCreationExpression], this is the AST node that the error is attached to
18936 * @param type the type being constructed with this [InstanceCreationExpressio n] 18998 * @param type the type being constructed with this [InstanceCreationExpressio n]
18937 * @return `true` if and only if an error code is generated on the passed node 18999 * @return `true` if and only if an error code is generated on the passed node
18938 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 19000 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS
18939 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 19001 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS
18940 */ 19002 */
18941 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type Name typeName, InterfaceType type) { 19003 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type Name typeName, InterfaceType type) {
18942 if (type.element.isAbstract) { 19004 if (type.element.isAbstract) {
18943 ConstructorElement element = node.staticElement; 19005 ConstructorElement element = node.staticElement;
18944 if (element != null && !element.isFactory) { 19006 if (element != null && !element.isFactory) {
18945 if (identical((node.keyword as sc.KeywordToken).keyword, sc.Keyword.CONS T)) { 19007 if (identical((node.keyword as sc.KeywordToken).keyword, sc.Keyword.CONS T)) {
18946 _errorReporter.reportError3(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS S, typeName, []); 19008 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS S, typeName, []);
18947 } else { 19009 } else {
18948 _errorReporter.reportError3(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS, typeName, []); 19010 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS, typeName, []);
18949 } 19011 }
18950 return true; 19012 return true;
18951 } 19013 }
18952 } 19014 }
18953 return false; 19015 return false;
18954 } 19016 }
18955 19017
18956 /** 19018 /**
18957 * This verifies that the passed 'const' instance creation expression is not b eing invoked on a 19019 * This verifies that the passed 'const' instance creation expression is not b eing invoked on a
18958 * constructor that is not 'const'. 19020 * constructor that is not 'const'.
18959 * 19021 *
18960 * This method assumes that the instance creation was tested to be 'const' bef ore being called. 19022 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
18961 * 19023 *
18962 * @param node the instance creation expression to evaluate 19024 * @param node the instance creation expression to evaluate
18963 * @return `true` if and only if an error code is generated on the passed node 19025 * @return `true` if and only if an error code is generated on the passed node
18964 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST 19026 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST
18965 */ 19027 */
18966 bool checkForConstWithNonConst(InstanceCreationExpression node) { 19028 bool checkForConstWithNonConst(InstanceCreationExpression node) {
18967 ConstructorElement constructorElement = node.staticElement; 19029 ConstructorElement constructorElement = node.staticElement;
18968 if (constructorElement != null && !constructorElement.isConst) { 19030 if (constructorElement != null && !constructorElement.isConst) {
18969 _errorReporter.reportError3(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod e, []); 19031 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_NON_CONST, nod e, []);
18970 return true; 19032 return true;
18971 } 19033 }
18972 return false; 19034 return false;
18973 } 19035 }
18974 19036
18975 /** 19037 /**
18976 * This verifies that the passed 'const' instance creation expression does not reference any type
18977 * parameters.
18978 *
18979 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
18980 *
18981 * @param node the instance creation expression to evaluate
18982 * @return `true` if and only if an error code is generated on the passed node
18983 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS
18984 */
18985 bool checkForConstWithTypeParameters(InstanceCreationExpression node) {
18986 ConstructorName constructorName = node.constructorName;
18987 if (constructorName == null) {
18988 return false;
18989 }
18990 TypeName typeName = constructorName.type;
18991 return checkForConstWithTypeParameters2(typeName);
18992 }
18993
18994 /**
18995 * This verifies that the passed type name does not reference any type paramet ers. 19038 * This verifies that the passed type name does not reference any type paramet ers.
18996 * 19039 *
18997 * @param typeName the type name to evaluate 19040 * @param typeName the type name to evaluate
18998 * @return `true` if and only if an error code is generated on the passed node 19041 * @return `true` if and only if an error code is generated on the passed node
18999 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS 19042 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS
19000 */ 19043 */
19001 bool checkForConstWithTypeParameters2(TypeName typeName) { 19044 bool checkForConstWithTypeParameters(TypeName typeName) {
19002 // something wrong with AST 19045 // something wrong with AST
19003 if (typeName == null) { 19046 if (typeName == null) {
19004 return false; 19047 return false;
19005 } 19048 }
19006 Identifier name = typeName.name; 19049 Identifier name = typeName.name;
19007 if (name == null) { 19050 if (name == null) {
19008 return false; 19051 return false;
19009 } 19052 }
19010 // should not be a type parameter 19053 // should not be a type parameter
19011 if (name.staticElement is TypeParameterElement) { 19054 if (name.staticElement is TypeParameterElement) {
19012 _errorReporter.reportError3(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER S, name, []); 19055 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETER S, name, []);
19013 } 19056 }
19014 // check type arguments 19057 // check type arguments
19015 TypeArgumentList typeArguments = typeName.typeArguments; 19058 TypeArgumentList typeArguments = typeName.typeArguments;
19016 if (typeArguments != null) { 19059 if (typeArguments != null) {
19017 bool hasError = false; 19060 bool hasError = false;
19018 for (TypeName argument in typeArguments.arguments) { 19061 for (TypeName argument in typeArguments.arguments) {
19019 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters2(argu ment)); 19062 hasError = javaBooleanOr(hasError, checkForConstWithTypeParameters(argum ent));
19020 } 19063 }
19021 return hasError; 19064 return hasError;
19022 } 19065 }
19023 // OK 19066 // OK
19024 return false; 19067 return false;
19025 } 19068 }
19026 19069
19027 /** 19070 /**
19071 * This verifies that the passed 'const' instance creation expression does not reference any type
19072 * parameters.
19073 *
19074 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
19075 *
19076 * @param node the instance creation expression to evaluate
19077 * @return `true` if and only if an error code is generated on the passed node
19078 * @see CompileTimeErrorCode#CONST_WITH_TYPE_PARAMETERS
19079 */
19080 bool checkForConstWithTypeParametersInCreation(InstanceCreationExpression node ) {
19081 ConstructorName constructorName = node.constructorName;
19082 if (constructorName == null) {
19083 return false;
19084 }
19085 TypeName typeName = constructorName.type;
19086 return checkForConstWithTypeParameters(typeName);
19087 }
19088
19089 /**
19028 * This verifies that if the passed 'const' instance creation expression is be ing invoked on the 19090 * This verifies that if the passed 'const' instance creation expression is be ing invoked on the
19029 * resolved constructor. 19091 * resolved constructor.
19030 * 19092 *
19031 * This method assumes that the instance creation was tested to be 'const' bef ore being called. 19093 * This method assumes that the instance creation was tested to be 'const' bef ore being called.
19032 * 19094 *
19033 * @param node the instance creation expression to evaluate 19095 * @param node the instance creation expression to evaluate
19034 * @return `true` if and only if an error code is generated on the passed node 19096 * @return `true` if and only if an error code is generated on the passed node
19035 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR 19097 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR
19036 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT 19098 * @see CompileTimeErrorCode#CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT
19037 */ 19099 */
19038 bool checkForConstWithUndefinedConstructor(InstanceCreationExpression node) { 19100 bool checkForConstWithUndefinedConstructor(InstanceCreationExpression node) {
19039 // OK if resolved 19101 // OK if resolved
19040 if (node.staticElement != null) { 19102 if (node.staticElement != null) {
19041 return false; 19103 return false;
19042 } 19104 }
19043 // prepare constructor name 19105 // prepare constructor name
19044 ConstructorName constructorName = node.constructorName; 19106 ConstructorName constructorName = node.constructorName;
19045 if (constructorName == null) { 19107 if (constructorName == null) {
19046 return false; 19108 return false;
19047 } 19109 }
19048 // prepare class name 19110 // prepare class name
19049 TypeName type = constructorName.type; 19111 TypeName type = constructorName.type;
19050 if (type == null) { 19112 if (type == null) {
19051 return false; 19113 return false;
19052 } 19114 }
19053 Identifier className = type.name; 19115 Identifier className = type.name;
19054 // report as named or default constructor absence 19116 // report as named or default constructor absence
19055 SimpleIdentifier name = constructorName.name; 19117 SimpleIdentifier name = constructorName.name;
19056 if (name != null) { 19118 if (name != null) {
19057 _errorReporter.reportError3(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS TRUCTOR, name, [className, name]); 19119 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS TRUCTOR, name, [className, name]);
19058 } else { 19120 } else {
19059 _errorReporter.reportError3(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS TRUCTOR_DEFAULT, constructorName, [className]); 19121 _errorReporter.reportError2(CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONS TRUCTOR_DEFAULT, constructorName, [className]);
19060 } 19122 }
19061 return true; 19123 return true;
19062 } 19124 }
19063 19125
19064 /** 19126 /**
19065 * This verifies that there are no default parameters in the passed function t ype alias. 19127 * This verifies that there are no default parameters in the passed function t ype alias.
19066 * 19128 *
19067 * @param node the function type alias to evaluate 19129 * @param node the function type alias to evaluate
19068 * @return `true` if and only if an error code is generated on the passed node 19130 * @return `true` if and only if an error code is generated on the passed node
19069 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS 19131 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS
19070 */ 19132 */
19071 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { 19133 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) {
19072 bool result = false; 19134 bool result = false;
19073 FormalParameterList formalParameterList = node.parameters; 19135 FormalParameterList formalParameterList = node.parameters;
19074 NodeList<FormalParameter> parameters = formalParameterList.parameters; 19136 NodeList<FormalParameter> parameters = formalParameterList.parameters;
19075 for (FormalParameter formalParameter in parameters) { 19137 for (FormalParameter formalParameter in parameters) {
19076 if (formalParameter is DefaultFormalParameter) { 19138 if (formalParameter is DefaultFormalParameter) {
19077 DefaultFormalParameter defaultFormalParameter = formalParameter; 19139 DefaultFormalParameter defaultFormalParameter = formalParameter;
19078 if (defaultFormalParameter.defaultValue != null) { 19140 if (defaultFormalParameter.defaultValue != null) {
19079 _errorReporter.reportError3(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPE_ALIAS, node, []); 19141 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPE_ALIAS, node, []);
19080 result = true; 19142 result = true;
19081 } 19143 }
19082 } 19144 }
19083 } 19145 }
19084 return result; 19146 return result;
19085 } 19147 }
19086 19148
19087 /** 19149 /**
19088 * This verifies that the given default formal parameter is not part of a func tion typed 19150 * This verifies that the given default formal parameter is not part of a func tion typed
19089 * parameter. 19151 * parameter.
19090 * 19152 *
19091 * @param node the default formal parameter to evaluate 19153 * @param node the default formal parameter to evaluate
19092 * @return `true` if and only if an error code is generated on the passed node 19154 * @return `true` if and only if an error code is generated on the passed node
19093 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER 19155 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER
19094 */ 19156 */
19095 bool checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node) { 19157 bool checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node) {
19096 // OK, not in a function typed parameter. 19158 // OK, not in a function typed parameter.
19097 if (!_isInFunctionTypedFormalParameter) { 19159 if (!_isInFunctionTypedFormalParameter) {
19098 return false; 19160 return false;
19099 } 19161 }
19100 // OK, no default value. 19162 // OK, no default value.
19101 if (node.defaultValue == null) { 19163 if (node.defaultValue == null) {
19102 return false; 19164 return false;
19103 } 19165 }
19104 // Report problem. 19166 // Report problem.
19105 _errorReporter.reportError3(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_T YPED_PARAMETER, node, []); 19167 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_T YPED_PARAMETER, node, []);
19106 return true; 19168 return true;
19107 } 19169 }
19108 19170
19109 /** 19171 /**
19110 * This verifies that the enclosing class does not have an instance member wit h the given name of 19172 * This verifies that the enclosing class does not have an instance member wit h the given name of
19111 * the static member. 19173 * the static member.
19112 * 19174 *
19113 * @return `true` if and only if an error code is generated on the passed node 19175 * @return `true` if and only if an error code is generated on the passed node
19114 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE 19176 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE
19115 */ 19177 */
19116 bool checkForDuplicateDefinitionInheritance() { 19178 bool checkForDuplicateDefinitionInheritance() {
19117 if (_enclosingClass == null) { 19179 if (_enclosingClass == null) {
19118 return false; 19180 return false;
19119 } 19181 }
19120 bool hasProblem = false; 19182 bool hasProblem = false;
19121 for (ExecutableElement member in _enclosingClass.methods) { 19183 for (ExecutableElement member in _enclosingClass.methods) {
19122 if (!member.isStatic) { 19184 if (!member.isStatic) {
19123 continue; 19185 continue;
19124 } 19186 }
19125 hasProblem = javaBooleanOr(hasProblem, checkForDuplicateDefinitionInherita nce2(member)); 19187 hasProblem = javaBooleanOr(hasProblem, checkForDuplicateDefinitionOfMember (member));
19126 } 19188 }
19127 for (ExecutableElement member in _enclosingClass.accessors) { 19189 for (ExecutableElement member in _enclosingClass.accessors) {
19128 if (!member.isStatic) { 19190 if (!member.isStatic) {
19129 continue; 19191 continue;
19130 } 19192 }
19131 hasProblem = javaBooleanOr(hasProblem, checkForDuplicateDefinitionInherita nce2(member)); 19193 hasProblem = javaBooleanOr(hasProblem, checkForDuplicateDefinitionOfMember (member));
19132 } 19194 }
19133 return hasProblem; 19195 return hasProblem;
19134 } 19196 }
19135 19197
19136 /** 19198 /**
19137 * This verifies that the enclosing class does not have an instance member wit h the given name of 19199 * This verifies that the enclosing class does not have an instance member wit h the given name of
19138 * the static member. 19200 * the static member.
19139 * 19201 *
19140 * @param staticMember the static member to check conflict for 19202 * @param staticMember the static member to check conflict for
19141 * @return `true` if and only if an error code is generated on the passed node 19203 * @return `true` if and only if an error code is generated on the passed node
19142 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE 19204 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE
19143 */ 19205 */
19144 bool checkForDuplicateDefinitionInheritance2(ExecutableElement staticMember) { 19206 bool checkForDuplicateDefinitionOfMember(ExecutableElement staticMember) {
19145 // prepare name 19207 // prepare name
19146 String name = staticMember.name; 19208 String name = staticMember.name;
19147 if (name == null) { 19209 if (name == null) {
19148 return false; 19210 return false;
19149 } 19211 }
19150 // try to find member 19212 // try to find member
19151 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name); 19213 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name);
19152 if (inheritedMember == null) { 19214 if (inheritedMember == null) {
19153 return false; 19215 return false;
19154 } 19216 }
19155 // OK, also static 19217 // OK, also static
19156 if (inheritedMember.isStatic) { 19218 if (inheritedMember.isStatic) {
19157 return false; 19219 return false;
19158 } 19220 }
19159 // report problem 19221 // report problem
19160 _errorReporter.reportError5(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle ment.displayName]); 19222 _errorReporter.reportError4(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle ment.displayName]);
19161 return true; 19223 return true;
19162 } 19224 }
19163 19225
19164 /** 19226 /**
19165 * This verifies if the passed list literal has type arguments then there is e xactly one. 19227 * This verifies if the passed list literal has type arguments then there is e xactly one.
19166 * 19228 *
19167 * @param node the list literal to evaluate 19229 * @param node the list literal to evaluate
19168 * @return `true` if and only if an error code is generated on the passed node 19230 * @return `true` if and only if an error code is generated on the passed node
19169 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS 19231 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS
19170 */ 19232 */
19171 bool checkForExpectedOneListTypeArgument(ListLiteral node) { 19233 bool checkForExpectedOneListTypeArgument(ListLiteral node) {
19172 // prepare type arguments 19234 // prepare type arguments
19173 TypeArgumentList typeArguments = node.typeArguments; 19235 TypeArgumentList typeArguments = node.typeArguments;
19174 if (typeArguments == null) { 19236 if (typeArguments == null) {
19175 return false; 19237 return false;
19176 } 19238 }
19177 // check number of type arguments 19239 // check number of type arguments
19178 int num = typeArguments.arguments.length; 19240 int num = typeArguments.arguments.length;
19179 if (num == 1) { 19241 if (num == 1) {
19180 return false; 19242 return false;
19181 } 19243 }
19182 // report problem 19244 // report problem
19183 _errorReporter.reportError3(StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARG UMENTS, typeArguments, [num]); 19245 _errorReporter.reportError2(StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARG UMENTS, typeArguments, [num]);
19184 return true; 19246 return true;
19185 } 19247 }
19186 19248
19187 /** 19249 /**
19188 * This verifies the passed import has unique name among other exported librar ies. 19250 * This verifies the passed import has unique name among other exported librar ies.
19189 * 19251 *
19190 * @param node the export directive to evaluate 19252 * @param node the export directive to evaluate
19191 * @return `true` if and only if an error code is generated on the passed node 19253 * @return `true` if and only if an error code is generated on the passed node
19192 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME 19254 * @see CompileTimeErrorCode#EXPORT_DUPLICATED_LIBRARY_NAME
19193 */ 19255 */
19194 bool checkForExportDuplicateLibraryName(ExportDirective node) { 19256 bool checkForExportDuplicateLibraryName(ExportDirective node) {
19195 // prepare import element 19257 // prepare import element
19196 Element nodeElement = node.element; 19258 Element nodeElement = node.element;
19197 if (nodeElement is! ExportElement) { 19259 if (nodeElement is! ExportElement) {
19198 return false; 19260 return false;
19199 } 19261 }
19200 ExportElement nodeExportElement = nodeElement as ExportElement; 19262 ExportElement nodeExportElement = nodeElement as ExportElement;
19201 // prepare exported library 19263 // prepare exported library
19202 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary; 19264 LibraryElement nodeLibrary = nodeExportElement.exportedLibrary;
19203 if (nodeLibrary == null) { 19265 if (nodeLibrary == null) {
19204 return false; 19266 return false;
19205 } 19267 }
19206 String name = nodeLibrary.name; 19268 String name = nodeLibrary.name;
19207 // check if there is other exported library with the same name 19269 // check if there is other exported library with the same name
19208 LibraryElement prevLibrary = _nameToExportElement[name]; 19270 LibraryElement prevLibrary = _nameToExportElement[name];
19209 if (prevLibrary != null) { 19271 if (prevLibrary != null) {
19210 if (prevLibrary != nodeLibrary) { 19272 if (prevLibrary != nodeLibrary) {
19211 _errorReporter.reportError3(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_ NAME, node, [ 19273 _errorReporter.reportError2(StaticWarningCode.EXPORT_DUPLICATED_LIBRARY_ NAME, node, [
19212 prevLibrary.definingCompilationUnit.displayName, 19274 prevLibrary.definingCompilationUnit.displayName,
19213 nodeLibrary.definingCompilationUnit.displayName, 19275 nodeLibrary.definingCompilationUnit.displayName,
19214 name]); 19276 name]);
19215 return true; 19277 return true;
19216 } 19278 }
19217 } else { 19279 } else {
19218 _nameToExportElement[name] = nodeLibrary; 19280 _nameToExportElement[name] = nodeLibrary;
19219 } 19281 }
19220 // OK 19282 // OK
19221 return false; 19283 return false;
(...skipping 21 matching lines...) Expand all
19243 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; 19305 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk;
19244 String uri = exportElement.uri; 19306 String uri = exportElement.uri;
19245 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 19307 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
19246 if (sdkLibrary == null) { 19308 if (sdkLibrary == null) {
19247 return false; 19309 return false;
19248 } 19310 }
19249 if (!sdkLibrary.isInternal) { 19311 if (!sdkLibrary.isInternal) {
19250 return false; 19312 return false;
19251 } 19313 }
19252 // report problem 19314 // report problem
19253 _errorReporter.reportError3(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no de, [node.uri]); 19315 _errorReporter.reportError2(CompileTimeErrorCode.EXPORT_INTERNAL_LIBRARY, no de, [node.uri]);
19254 return true; 19316 return true;
19255 } 19317 }
19256 19318
19257 /** 19319 /**
19258 * This verifies that the passed extends clause does not extend classes such a s num or String. 19320 * This verifies that the passed extends clause does not extend classes such a s num or String.
19259 * 19321 *
19260 * @param node the extends clause to test 19322 * @param node the extends clause to test
19261 * @return `true` if and only if an error code is generated on the passed node 19323 * @return `true` if and only if an error code is generated on the passed node
19262 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 19324 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS
19263 */ 19325 */
19264 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) { 19326 bool checkForExtendsDisallowedClass(ExtendsClause node) {
19265 if (extendsClause == null) { 19327 if (node == null) {
19266 return false; 19328 return false;
19267 } 19329 }
19268 return checkForExtendsOrImplementsDisallowedClass(extendsClause.superclass, CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS); 19330 return checkForExtendsOrImplementsDisallowedClass(node.superclass, CompileTi meErrorCode.EXTENDS_DISALLOWED_CLASS);
19269 } 19331 }
19270 19332
19271 /** 19333 /**
19272 * This verifies that the passed type name does not extend or implement classe s such as 'num' or 19334 * This verifies that the passed type name does not extend or implement classe s such as 'num' or
19273 * 'String'. 19335 * 'String'.
19274 * 19336 *
19275 * @param node the type name to test 19337 * @param node the type name to test
19276 * @return `true` if and only if an error code is generated on the passed node 19338 * @return `true` if and only if an error code is generated on the passed node
19277 * @see #checkForExtendsDisallowedClass(ExtendsClause) 19339 * @see #checkForExtendsDisallowedClass(ExtendsClause)
19278 * @see #checkForImplementsDisallowedClass(ImplementsClause) 19340 * @see #checkForImplementsDisallowedClass(ImplementsClause)
(...skipping 17 matching lines...) Expand all
19296 // grandparent node 19358 // grandparent node
19297 if (grandParent is ClassDeclaration) { 19359 if (grandParent is ClassDeclaration) {
19298 ClassElement classElement = grandParent.element; 19360 ClassElement classElement = grandParent.element;
19299 Type2 classType = classElement.type; 19361 Type2 classType = classElement.type;
19300 if (classType != null && (classType == _typeProvider.intType || clas sType == _typeProvider.doubleType)) { 19362 if (classType != null && (classType == _typeProvider.intType || clas sType == _typeProvider.doubleType)) {
19301 return false; 19363 return false;
19302 } 19364 }
19303 } 19365 }
19304 } 19366 }
19305 // otherwise, report the error 19367 // otherwise, report the error
19306 _errorReporter.reportError3(errorCode, typeName, [disallowedType.display Name]); 19368 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display Name]);
19307 return true; 19369 return true;
19308 } 19370 }
19309 } 19371 }
19310 return false; 19372 return false;
19311 } 19373 }
19312 19374
19313 /** 19375 /**
19314 * This verifies that the passed constructor field initializer has compatible field and 19376 * This verifies that the passed constructor field initializer has compatible field and
19315 * initializer expression types. 19377 * initializer expression types.
19316 * 19378 *
(...skipping 19 matching lines...) Expand all
19336 // test the static type of the expression 19398 // test the static type of the expression
19337 Type2 staticType = getStaticType(expression); 19399 Type2 staticType = getStaticType(expression);
19338 if (staticType == null) { 19400 if (staticType == null) {
19339 return false; 19401 return false;
19340 } 19402 }
19341 if (staticType.isAssignableTo(fieldType)) { 19403 if (staticType.isAssignableTo(fieldType)) {
19342 return false; 19404 return false;
19343 } 19405 }
19344 // report problem 19406 // report problem
19345 if (_isEnclosingConstructorConst) { 19407 if (_isEnclosingConstructorConst) {
19346 _errorReporter.reportError3(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N OT_ASSIGNABLE, expression, [staticType.displayName, fieldType.displayName]); 19408 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N OT_ASSIGNABLE, expression, [staticType.displayName, fieldType.displayName]);
19347 } else { 19409 } else {
19348 _errorReporter.reportError3(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN ABLE, expression, [staticType.displayName, fieldType.displayName]); 19410 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN ABLE, expression, [staticType.displayName, fieldType.displayName]);
19349 } 19411 }
19350 return true; 19412 return true;
19351 } 19413 }
19352 19414
19353 /** 19415 /**
19354 * This verifies that the passed field formal parameter is in a constructor de claration. 19416 * This verifies that the passed field formal parameter is in a constructor de claration.
19355 * 19417 *
19356 * @param node the field formal parameter to test 19418 * @param node the field formal parameter to test
19357 * @return `true` if and only if an error code is generated on the passed node 19419 * @return `true` if and only if an error code is generated on the passed node
19358 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR 19420 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
19359 */ 19421 */
19360 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete r node) { 19422 bool checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamete r node) {
19361 ConstructorDeclaration constructor = node.getAncestor(ConstructorDeclaration ); 19423 ConstructorDeclaration constructor = node.getAncestor((node) => node is Cons tructorDeclaration);
19362 if (constructor == null) { 19424 if (constructor == null) {
19363 _errorReporter.reportError3(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE _CONSTRUCTOR, node, []); 19425 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE _CONSTRUCTOR, node, []);
19364 return true; 19426 return true;
19365 } 19427 }
19366 // constructor cannot be a factory 19428 // constructor cannot be a factory
19367 if (constructor.factoryKeyword != null) { 19429 if (constructor.factoryKeyword != null) {
19368 _errorReporter.reportError3(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY _CONSTRUCTOR, node, []); 19430 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY _CONSTRUCTOR, node, []);
19369 return true; 19431 return true;
19370 } 19432 }
19371 // constructor cannot have a redirection 19433 // constructor cannot have a redirection
19372 for (ConstructorInitializer initializer in constructor.initializers) { 19434 for (ConstructorInitializer initializer in constructor.initializers) {
19373 if (initializer is RedirectingConstructorInvocation) { 19435 if (initializer is RedirectingConstructorInvocation) {
19374 _errorReporter.reportError3(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR ECTING_CONSTRUCTOR, node, []); 19436 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_REDIR ECTING_CONSTRUCTOR, node, []);
19375 return true; 19437 return true;
19376 } 19438 }
19377 } 19439 }
19378 // OK 19440 // OK
19379 return false; 19441 return false;
19380 } 19442 }
19381 19443
19382 /** 19444 /**
19383 * This verifies that final fields that are declared, without any constructors in the enclosing
19384 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end
19385 * of [checkForAllFinalInitializedErrorCodes].
19386 *
19387 * @param node the class declaration to test
19388 * @return `true` if and only if an error code is generated on the passed node
19389 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED
19390 * @see StaticWarningCode#FINAL_NOT_INITIALIZED
19391 */
19392 bool checkForFinalNotInitialized(ClassDeclaration node) {
19393 NodeList<ClassMember> classMembers = node.members;
19394 for (ClassMember classMember in classMembers) {
19395 if (classMember is ConstructorDeclaration) {
19396 return false;
19397 }
19398 }
19399 bool foundError = false;
19400 for (ClassMember classMember in classMembers) {
19401 if (classMember is FieldDeclaration) {
19402 FieldDeclaration field = classMember;
19403 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel d.fields));
19404 }
19405 }
19406 return foundError;
19407 }
19408
19409 /**
19410 * This verifies that the passed variable declaration list has only initialize d variables if the 19445 * This verifies that the passed variable declaration list has only initialize d variables if the
19411 * list is final or const. This method is called by 19446 * list is final or const. This method is called by
19412 * [checkForFinalNotInitialized], 19447 * [checkForFinalNotInitializedInClass],
19413 * [visitTopLevelVariableDeclaration] and 19448 * [visitTopLevelVariableDeclaration] and
19414 * [visitVariableDeclarationStatement]. 19449 * [visitVariableDeclarationStatement].
19415 * 19450 *
19416 * @param node the class declaration to test 19451 * @param node the class declaration to test
19417 * @return `true` if and only if an error code is generated on the passed node 19452 * @return `true` if and only if an error code is generated on the passed node
19418 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED 19453 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED
19419 * @see StaticWarningCode#FINAL_NOT_INITIALIZED 19454 * @see StaticWarningCode#FINAL_NOT_INITIALIZED
19420 */ 19455 */
19421 bool checkForFinalNotInitialized2(VariableDeclarationList node) { 19456 bool checkForFinalNotInitialized(VariableDeclarationList node) {
19422 if (_isInNativeClass) { 19457 if (_isInNativeClass) {
19423 return false; 19458 return false;
19424 } 19459 }
19425 bool foundError = false; 19460 bool foundError = false;
19426 if (!node.isSynthetic) { 19461 if (!node.isSynthetic) {
19427 NodeList<VariableDeclaration> variables = node.variables; 19462 NodeList<VariableDeclaration> variables = node.variables;
19428 for (VariableDeclaration variable in variables) { 19463 for (VariableDeclaration variable in variables) {
19429 if (variable.initializer == null) { 19464 if (variable.initializer == null) {
19430 if (node.isConst) { 19465 if (node.isConst) {
19431 _errorReporter.reportError3(CompileTimeErrorCode.CONST_NOT_INITIALIZ ED, variable.name, [variable.name.name]); 19466 _errorReporter.reportError2(CompileTimeErrorCode.CONST_NOT_INITIALIZ ED, variable.name, [variable.name.name]);
19432 } else if (node.isFinal) { 19467 } else if (node.isFinal) {
19433 _errorReporter.reportError3(StaticWarningCode.FINAL_NOT_INITIALIZED, variable.name, [variable.name.name]); 19468 _errorReporter.reportError2(StaticWarningCode.FINAL_NOT_INITIALIZED, variable.name, [variable.name.name]);
19434 } 19469 }
19435 foundError = true; 19470 foundError = true;
19436 } 19471 }
19437 } 19472 }
19438 } 19473 }
19439 return foundError; 19474 return foundError;
19440 } 19475 }
19441 19476
19442 /** 19477 /**
19478 * This verifies that final fields that are declared, without any constructors in the enclosing
19479 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end
19480 * of [checkForAllFinalInitializedErrorCodes].
19481 *
19482 * @param node the class declaration to test
19483 * @return `true` if and only if an error code is generated on the passed node
19484 * @see CompileTimeErrorCode#CONST_NOT_INITIALIZED
19485 * @see StaticWarningCode#FINAL_NOT_INITIALIZED
19486 */
19487 bool checkForFinalNotInitializedInClass(ClassDeclaration node) {
19488 NodeList<ClassMember> classMembers = node.members;
19489 for (ClassMember classMember in classMembers) {
19490 if (classMember is ConstructorDeclaration) {
19491 return false;
19492 }
19493 }
19494 bool foundError = false;
19495 for (ClassMember classMember in classMembers) {
19496 if (classMember is FieldDeclaration) {
19497 FieldDeclaration field = classMember;
19498 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized(field .fields));
19499 }
19500 }
19501 return foundError;
19502 }
19503
19504 /**
19443 * This verifies that the passed implements clause does not implement classes such as 'num' or 19505 * This verifies that the passed implements clause does not implement classes such as 'num' or
19444 * 'String'. 19506 * 'String'.
19445 * 19507 *
19446 * @param node the implements clause to test 19508 * @param node the implements clause to test
19447 * @return `true` if and only if an error code is generated on the passed node 19509 * @return `true` if and only if an error code is generated on the passed node
19448 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 19510 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS
19449 */ 19511 */
19450 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { 19512 bool checkForImplementsDisallowedClass(ImplementsClause node) {
19451 if (implementsClause == null) { 19513 if (node == null) {
19452 return false; 19514 return false;
19453 } 19515 }
19454 bool foundError = false; 19516 bool foundError = false;
19455 for (TypeName type in implementsClause.interfaces) { 19517 for (TypeName type in node.interfaces) {
19456 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); 19518 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS));
19457 } 19519 }
19458 return foundError; 19520 return foundError;
19459 } 19521 }
19460 19522
19461 /** 19523 /**
19462 * This verifies that if the passed identifier is part of constructor initiali zer, then it does 19524 * This verifies that if the passed identifier is part of constructor initiali zer, then it does
19463 * not reference implicitly 'this' expression. 19525 * not reference implicitly 'this' expression.
19464 * 19526 *
19465 * @param node the simple identifier to test 19527 * @param node the simple identifier to test
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
19506 } 19568 }
19507 } 19569 }
19508 if (parent is PrefixedIdentifier) { 19570 if (parent is PrefixedIdentifier) {
19509 PrefixedIdentifier prefixed = parent; 19571 PrefixedIdentifier prefixed = parent;
19510 if (identical(prefixed.identifier, node)) { 19572 if (identical(prefixed.identifier, node)) {
19511 return false; 19573 return false;
19512 } 19574 }
19513 } 19575 }
19514 // report problem 19576 // report problem
19515 if (_isInStaticMethod) { 19577 if (_isInStaticMethod) {
19516 _errorReporter.reportError3(CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FR OM_STATIC, node, []); 19578 _errorReporter.reportError2(CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FR OM_STATIC, node, []);
19517 } else { 19579 } else {
19518 _errorReporter.reportError3(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_I N_INITIALIZER, node, []); 19580 _errorReporter.reportError2(CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_I N_INITIALIZER, node, []);
19519 } 19581 }
19520 return true; 19582 return true;
19521 } 19583 }
19522 19584
19523 /** 19585 /**
19524 * This verifies the passed import has unique name among other imported librar ies. 19586 * This verifies the passed import has unique name among other imported librar ies.
19525 * 19587 *
19526 * @param node the import directive to evaluate 19588 * @param node the import directive to evaluate
19527 * @return `true` if and only if an error code is generated on the passed node 19589 * @return `true` if and only if an error code is generated on the passed node
19528 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME 19590 * @see CompileTimeErrorCode#IMPORT_DUPLICATED_LIBRARY_NAME
19529 */ 19591 */
19530 bool checkForImportDuplicateLibraryName(ImportDirective node) { 19592 bool checkForImportDuplicateLibraryName(ImportDirective node) {
19531 // prepare import element 19593 // prepare import element
19532 ImportElement nodeImportElement = node.element; 19594 ImportElement nodeImportElement = node.element;
19533 if (nodeImportElement == null) { 19595 if (nodeImportElement == null) {
19534 return false; 19596 return false;
19535 } 19597 }
19536 // prepare imported library 19598 // prepare imported library
19537 LibraryElement nodeLibrary = nodeImportElement.importedLibrary; 19599 LibraryElement nodeLibrary = nodeImportElement.importedLibrary;
19538 if (nodeLibrary == null) { 19600 if (nodeLibrary == null) {
19539 return false; 19601 return false;
19540 } 19602 }
19541 String name = nodeLibrary.name; 19603 String name = nodeLibrary.name;
19542 // check if there is other imported library with the same name 19604 // check if there is other imported library with the same name
19543 LibraryElement prevLibrary = _nameToImportElement[name]; 19605 LibraryElement prevLibrary = _nameToImportElement[name];
19544 if (prevLibrary != null) { 19606 if (prevLibrary != null) {
19545 if (prevLibrary != nodeLibrary) { 19607 if (prevLibrary != nodeLibrary) {
19546 _errorReporter.reportError3(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_ NAME, node, [ 19608 _errorReporter.reportError2(StaticWarningCode.IMPORT_DUPLICATED_LIBRARY_ NAME, node, [
19547 prevLibrary.definingCompilationUnit.displayName, 19609 prevLibrary.definingCompilationUnit.displayName,
19548 nodeLibrary.definingCompilationUnit.displayName, 19610 nodeLibrary.definingCompilationUnit.displayName,
19549 name]); 19611 name]);
19550 return true; 19612 return true;
19551 } 19613 }
19552 } else { 19614 } else {
19553 _nameToImportElement[name] = nodeLibrary; 19615 _nameToImportElement[name] = nodeLibrary;
19554 } 19616 }
19555 // OK 19617 // OK
19556 return false; 19618 return false;
(...skipping 20 matching lines...) Expand all
19577 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk; 19639 DartSdk sdk = _currentLibrary.context.sourceFactory.dartSdk;
19578 String uri = importElement.uri; 19640 String uri = importElement.uri;
19579 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri); 19641 SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
19580 if (sdkLibrary == null) { 19642 if (sdkLibrary == null) {
19581 return false; 19643 return false;
19582 } 19644 }
19583 if (!sdkLibrary.isInternal) { 19645 if (!sdkLibrary.isInternal) {
19584 return false; 19646 return false;
19585 } 19647 }
19586 // report problem 19648 // report problem
19587 _errorReporter.reportError3(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no de, [node.uri]); 19649 _errorReporter.reportError2(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, no de, [node.uri]);
19588 return true; 19650 return true;
19589 } 19651 }
19590 19652
19591 /** 19653 /**
19592 * This verifies that the passed switch statement case expressions all have th e same type. 19654 * This verifies that the passed switch statement case expressions all have th e same type.
19593 * 19655 *
19594 * @param node the switch statement to evaluate 19656 * @param node the switch statement to evaluate
19595 * @return `true` if and only if an error code is generated on the passed node 19657 * @return `true` if and only if an error code is generated on the passed node
19596 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES 19658 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES
19597 */ 19659 */
19598 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) { 19660 bool checkForInconsistentCaseExpressionTypes(SwitchStatement node) {
19599 // TODO(jwren) Revisit this algorithm, should there up to n-1 errors? 19661 // TODO(jwren) Revisit this algorithm, should there up to n-1 errors?
19600 NodeList<SwitchMember> switchMembers = node.members; 19662 NodeList<SwitchMember> switchMembers = node.members;
19601 bool foundError = false; 19663 bool foundError = false;
19602 Type2 firstType = null; 19664 Type2 firstType = null;
19603 for (SwitchMember switchMember in switchMembers) { 19665 for (SwitchMember switchMember in switchMembers) {
19604 if (switchMember is SwitchCase) { 19666 if (switchMember is SwitchCase) {
19605 SwitchCase switchCase = switchMember; 19667 SwitchCase switchCase = switchMember;
19606 Expression expression = switchCase.expression; 19668 Expression expression = switchCase.expression;
19607 if (firstType == null) { 19669 if (firstType == null) {
19608 // TODO(brianwilkerson) This is failing with const variables whose dec lared type is 19670 // TODO(brianwilkerson) This is failing with const variables whose dec lared type is
19609 // dynamic. The problem is that we don't have any way to propagate typ e information for 19671 // dynamic. The problem is that we don't have any way to propagate typ e information for
19610 // the variable. 19672 // the variable.
19611 firstType = expression.bestType; 19673 firstType = expression.bestType;
19612 } else { 19674 } else {
19613 Type2 nType = expression.bestType; 19675 Type2 nType = expression.bestType;
19614 if (firstType != nType) { 19676 if (firstType != nType) {
19615 _errorReporter.reportError3(CompileTimeErrorCode.INCONSISTENT_CASE_E XPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName]); 19677 _errorReporter.reportError2(CompileTimeErrorCode.INCONSISTENT_CASE_E XPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName]);
19616 foundError = true; 19678 foundError = true;
19617 } 19679 }
19618 } 19680 }
19619 } 19681 }
19620 } 19682 }
19621 if (!foundError) { 19683 if (!foundError) {
19622 checkForCaseExpressionTypeImplementsEquals(node, firstType); 19684 checkForCaseExpressionTypeImplementsEquals(node, firstType);
19623 } 19685 }
19624 return foundError; 19686 return foundError;
19625 } 19687 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
19673 ExecutableElement executableElement = element as ExecutableElement; 19735 ExecutableElement executableElement = element as ExecutableElement;
19674 // OK, top-level element 19736 // OK, top-level element
19675 if (executableElement.enclosingElement is! ClassElement) { 19737 if (executableElement.enclosingElement is! ClassElement) {
19676 return false; 19738 return false;
19677 } 19739 }
19678 // OK, instance member 19740 // OK, instance member
19679 if (!executableElement.isStatic) { 19741 if (!executableElement.isStatic) {
19680 return false; 19742 return false;
19681 } 19743 }
19682 // report problem 19744 // report problem
19683 _errorReporter.reportError3(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_ MEMBER, name, [name.name]); 19745 _errorReporter.reportError2(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_ MEMBER, name, [name.name]);
19684 return true; 19746 return true;
19685 } 19747 }
19686 19748
19687 /** 19749 /**
19688 * This verifies that an 'int' can be assigned to the parameter corresponding to the given 19750 * This verifies that an 'int' can be assigned to the parameter corresponding to the given
19689 * expression. This is used for prefix and postfix expressions where the argum ent value is 19751 * expression. This is used for prefix and postfix expressions where the argum ent value is
19690 * implicit. 19752 * implicit.
19691 * 19753 *
19692 * @param argument the expression to which the operator is being applied 19754 * @param argument the expression to which the operator is being applied
19693 * @return `true` if and only if an error code is generated on the passed node 19755 * @return `true` if and only if an error code is generated on the passed node
19694 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 19756 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
19695 */ 19757 */
19696 bool checkForIntNotAssignable(Expression argument) { 19758 bool checkForIntNotAssignable(Expression argument) {
19697 if (argument == null) { 19759 if (argument == null) {
19698 return false; 19760 return false;
19699 } 19761 }
19700 ParameterElement staticParameterElement = argument.staticParameterElement; 19762 ParameterElement staticParameterElement = argument.staticParameterElement;
19701 Type2 staticParameterType = staticParameterElement == null ? null : staticPa rameterElement.type; 19763 Type2 staticParameterType = staticParameterElement == null ? null : staticPa rameterElement.type;
19702 ParameterElement propagatedParameterElement = argument.propagatedParameterEl ement; 19764 ParameterElement propagatedParameterElement = argument.propagatedParameterEl ement;
19703 Type2 propagatedParameterType = propagatedParameterElement == null ? null : propagatedParameterElement.type; 19765 Type2 propagatedParameterType = propagatedParameterElement == null ? null : propagatedParameterElement.type;
19704 return checkForArgumentTypeNotAssignable4(argument, staticParameterType, _ty peProvider.intType, propagatedParameterType, _typeProvider.intType, StaticWarnin gCode.ARGUMENT_TYPE_NOT_ASSIGNABLE); 19766 return checkForArgumentTypeNotAssignable(argument, staticParameterType, _typ eProvider.intType, propagatedParameterType, _typeProvider.intType, StaticWarning Code.ARGUMENT_TYPE_NOT_ASSIGNABLE);
19705 } 19767 }
19706 19768
19707 /** 19769 /**
19708 * Given an assignment using a compound assignment operator, this verifies tha t the given
19709 * assignment is valid.
19710 *
19711 * @param node the assignment expression being tested
19712 * @return `true` if and only if an error code is generated on the passed node
19713 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
19714 */
19715 bool checkForInvalidAssignment(AssignmentExpression node) {
19716 Expression lhs = node.leftHandSide;
19717 if (lhs == null) {
19718 return false;
19719 }
19720 VariableElement leftElement = getVariableElement(lhs);
19721 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty pe;
19722 MethodElement invokedMethod = node.staticElement;
19723 if (invokedMethod == null) {
19724 return false;
19725 }
19726 Type2 rightType = invokedMethod.type.returnType;
19727 if (leftType == null || rightType == null) {
19728 return false;
19729 }
19730 if (!rightType.isAssignableTo(leftType)) {
19731 String leftName = leftType.displayName;
19732 String rightName = rightType.displayName;
19733 if (leftName == rightName) {
19734 leftName = getExtendedDisplayName(leftType);
19735 rightName = getExtendedDisplayName(rightType);
19736 }
19737 _errorReporter.reportError3(StaticTypeWarningCode.INVALID_ASSIGNMENT, node .rightHandSide, [rightName, leftName]);
19738 return true;
19739 }
19740 return false;
19741 }
19742
19743 /**
19744 * This verifies that the passed left hand side and right hand side represent a valid assignment. 19770 * This verifies that the passed left hand side and right hand side represent a valid assignment.
19745 * 19771 *
19746 * @param lhs the left hand side expression 19772 * @param lhs the left hand side expression
19747 * @param rhs the right hand side expression 19773 * @param rhs the right hand side expression
19748 * @return `true` if and only if an error code is generated on the passed node 19774 * @return `true` if and only if an error code is generated on the passed node
19749 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 19775 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
19750 */ 19776 */
19751 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { 19777 bool checkForInvalidAssignment(Expression lhs, Expression rhs) {
19752 if (lhs == null || rhs == null) { 19778 if (lhs == null || rhs == null) {
19753 return false; 19779 return false;
19754 } 19780 }
19755 VariableElement leftElement = getVariableElement(lhs); 19781 VariableElement leftElement = getVariableElement(lhs);
19756 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty pe; 19782 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty pe;
19757 Type2 staticRightType = getStaticType(rhs); 19783 Type2 staticRightType = getStaticType(rhs);
19758 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); 19784 bool isStaticAssignable = staticRightType.isAssignableTo(leftType);
19759 if (!isStaticAssignable) { 19785 if (!isStaticAssignable) {
19760 String leftName = leftType.displayName; 19786 String leftName = leftType.displayName;
19761 String rightName = staticRightType.displayName; 19787 String rightName = staticRightType.displayName;
19762 if (leftName == rightName) { 19788 if (leftName == rightName) {
19763 leftName = getExtendedDisplayName(leftType); 19789 leftName = getExtendedDisplayName(leftType);
19764 rightName = getExtendedDisplayName(staticRightType); 19790 rightName = getExtendedDisplayName(staticRightType);
19765 } 19791 }
19766 _errorReporter.reportError3(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightName, leftName]); 19792 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightName, leftName]);
19767 return true; 19793 return true;
19768 } 19794 }
19769 // TODO(brianwilkerson) Define a hint corresponding to the warning and repor t it if appropriate. 19795 // TODO(brianwilkerson) Define a hint corresponding to the warning and repor t it if appropriate.
19770 // Type propagatedRightType = rhs.getPropagatedType(); 19796 // Type propagatedRightType = rhs.getPropagatedType();
19771 // boolean isPropagatedAssignable = propagatedRightType.isAssignableTo(le ftType); 19797 // boolean isPropagatedAssignable = propagatedRightType.isAssignableTo(le ftType);
19772 // if (!isStaticAssignable && !isPropagatedAssignable) { 19798 // if (!isStaticAssignable && !isPropagatedAssignable) {
19773 // errorReporter.reportError( 19799 // errorReporter.reportError(
19774 // StaticTypeWarningCode.INVALID_ASSIGNMENT, 19800 // StaticTypeWarningCode.INVALID_ASSIGNMENT,
19775 // rhs, 19801 // rhs,
19776 // staticRightType.getDisplayName(), 19802 // staticRightType.getDisplayName(),
19777 // leftType.getDisplayName()); 19803 // leftType.getDisplayName());
19778 // return true; 19804 // return true;
19779 // } 19805 // }
19780 return false; 19806 return false;
19781 } 19807 }
19782 19808
19783 /** 19809 /**
19810 * Given an assignment using a compound assignment operator, this verifies tha t the given
19811 * assignment is valid.
19812 *
19813 * @param node the assignment expression being tested
19814 * @return `true` if and only if an error code is generated on the passed node
19815 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
19816 */
19817 bool checkForInvalidCompoundAssignment(AssignmentExpression node) {
19818 Expression lhs = node.leftHandSide;
19819 if (lhs == null) {
19820 return false;
19821 }
19822 VariableElement leftElement = getVariableElement(lhs);
19823 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty pe;
19824 MethodElement invokedMethod = node.staticElement;
19825 if (invokedMethod == null) {
19826 return false;
19827 }
19828 Type2 rightType = invokedMethod.type.returnType;
19829 if (leftType == null || rightType == null) {
19830 return false;
19831 }
19832 if (!rightType.isAssignableTo(leftType)) {
19833 String leftName = leftType.displayName;
19834 String rightName = rightType.displayName;
19835 if (leftName == rightName) {
19836 leftName = getExtendedDisplayName(leftType);
19837 rightName = getExtendedDisplayName(rightType);
19838 }
19839 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, node .rightHandSide, [rightName, leftName]);
19840 return true;
19841 }
19842 return false;
19843 }
19844
19845 /**
19784 * Check the given initializer to ensure that the field being initialized is a valid field. 19846 * Check the given initializer to ensure that the field being initialized is a valid field.
19785 * 19847 *
19786 * @param node the field initializer being checked 19848 * @param node the field initializer being checked
19787 */ 19849 */
19788 void checkForInvalidField(ConstructorFieldInitializer node) { 19850 void checkForInvalidField(ConstructorFieldInitializer node) {
19789 SimpleIdentifier fieldName = node.fieldName; 19851 SimpleIdentifier fieldName = node.fieldName;
19790 Element staticElement = fieldName.staticElement; 19852 Element staticElement = fieldName.staticElement;
19791 if (staticElement is FieldElement) { 19853 if (staticElement is FieldElement) {
19792 FieldElement fieldElement = staticElement; 19854 FieldElement fieldElement = staticElement;
19793 if (fieldElement.isSynthetic) { 19855 if (fieldElement.isSynthetic) {
19794 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXI STANT_FIELD, node, [fieldName]); 19856 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXI STANT_FIELD, node, [fieldName]);
19795 } else if (fieldElement.isStatic) { 19857 } else if (fieldElement.isStatic) {
19796 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_ FIELD, node, [fieldName]); 19858 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_ FIELD, node, [fieldName]);
19797 } 19859 }
19798 } else { 19860 } else {
19799 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXIST ANT_FIELD, node, [fieldName]); 19861 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXIST ANT_FIELD, node, [fieldName]);
19800 return; 19862 return;
19801 } 19863 }
19802 } 19864 }
19803 19865
19804 /** 19866 /**
19805 * This verifies that the usage of the passed 'this' is valid. 19867 * This verifies that the usage of the passed 'this' is valid.
19806 * 19868 *
19807 * @param node the 'this' expression to evaluate 19869 * @param node the 'this' expression to evaluate
19808 * @return `true` if and only if an error code is generated on the passed node 19870 * @return `true` if and only if an error code is generated on the passed node
19809 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS 19871 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS
19810 */ 19872 */
19811 bool checkForInvalidReferenceToThis(ThisExpression node) { 19873 bool checkForInvalidReferenceToThis(ThisExpression node) {
19812 if (!isThisInValidContext(node)) { 19874 if (!isThisInValidContext(node)) {
19813 _errorReporter.reportError3(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS , node, []); 19875 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS , node, []);
19814 return true; 19876 return true;
19815 } 19877 }
19816 return false; 19878 return false;
19817 } 19879 }
19818 19880
19819 /** 19881 /**
19820 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav e a type 19882 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav e a type
19821 * parameter as a type argument. 19883 * parameter as a type argument.
19822 * 19884 *
19823 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp ective 19885 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp ective
19824 * [ListLiteral] or [MapLiteral] 19886 * [ListLiteral] or [MapLiteral]
19825 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS T_LIST] or 19887 * @param errorCode either [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONS T_LIST] or
19826 * [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP] 19888 * [CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP]
19827 * @return `true` if and only if an error code is generated on the passed node 19889 * @return `true` if and only if an error code is generated on the passed node
19828 */ 19890 */
19829 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen ts, ErrorCode errorCode) { 19891 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen ts, ErrorCode errorCode) {
19830 bool foundError = false; 19892 bool foundError = false;
19831 for (TypeName typeName in arguments) { 19893 for (TypeName typeName in arguments) {
19832 if (typeName.type is TypeParameterType) { 19894 if (typeName.type is TypeParameterType) {
19833 _errorReporter.reportError3(errorCode, typeName, [typeName.name]); 19895 _errorReporter.reportError2(errorCode, typeName, [typeName.name]);
19834 foundError = true; 19896 foundError = true;
19835 } 19897 }
19836 } 19898 }
19837 return foundError; 19899 return foundError;
19838 } 19900 }
19839 19901
19840 /** 19902 /**
19841 * This verifies that the elements given [ListLiteral] are subtypes of the spe cified element 19903 * This verifies that the elements given [ListLiteral] are subtypes of the spe cified element
19842 * type. 19904 * type.
19843 * 19905 *
(...skipping 16 matching lines...) Expand all
19860 // Prepare problem to report. 19922 // Prepare problem to report.
19861 ErrorCode errorCode; 19923 ErrorCode errorCode;
19862 if (node.constKeyword != null) { 19924 if (node.constKeyword != null) {
19863 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; 19925 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE;
19864 } else { 19926 } else {
19865 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; 19927 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE;
19866 } 19928 }
19867 // Check every list element. 19929 // Check every list element.
19868 bool hasProblems = false; 19930 bool hasProblems = false;
19869 for (Expression element in node.elements) { 19931 for (Expression element in node.elements) {
19870 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable 3(element, listElementType, null, errorCode)); 19932 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable WithExpectedTypes(element, listElementType, null, errorCode));
19871 } 19933 }
19872 return hasProblems; 19934 return hasProblems;
19873 } 19935 }
19874 19936
19875 /** 19937 /**
19876 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the 19938 * This verifies that the key/value of entries of the given [MapLiteral] are s ubtypes of the
19877 * key/value types specified in the type arguments. 19939 * key/value types specified in the type arguments.
19878 * 19940 *
19879 * @param node the map literal to evaluate 19941 * @param node the map literal to evaluate
19880 * @return `true` if and only if an error code is generated on the passed node 19942 * @return `true` if and only if an error code is generated on the passed node
(...skipping 23 matching lines...) Expand all
19904 } else { 19966 } else {
19905 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; 19967 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE;
19906 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; 19968 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE;
19907 } 19969 }
19908 // Check every map entry. 19970 // Check every map entry.
19909 bool hasProblems = false; 19971 bool hasProblems = false;
19910 NodeList<MapLiteralEntry> entries = node.entries; 19972 NodeList<MapLiteralEntry> entries = node.entries;
19911 for (MapLiteralEntry entry in entries) { 19973 for (MapLiteralEntry entry in entries) {
19912 Expression key = entry.key; 19974 Expression key = entry.key;
19913 Expression value = entry.value; 19975 Expression value = entry.value;
19914 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable 3(key, keyType, null, keyErrorCode)); 19976 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable WithExpectedTypes(key, keyType, null, keyErrorCode));
19915 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable 3(value, valueType, null, valueErrorCode)); 19977 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable WithExpectedTypes(value, valueType, null, valueErrorCode));
19916 } 19978 }
19917 return hasProblems; 19979 return hasProblems;
19918 } 19980 }
19919 19981
19920 /** 19982 /**
19921 * This verifies that the [enclosingClass] does not define members with the sa me name as 19983 * This verifies that the [enclosingClass] does not define members with the sa me name as
19922 * the enclosing class. 19984 * the enclosing class.
19923 * 19985 *
19924 * @return `true` if and only if an error code is generated on the passed node 19986 * @return `true` if and only if an error code is generated on the passed node
19925 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME 19987 * @see CompileTimeErrorCode#MEMBER_WITH_CLASS_NAME
19926 */ 19988 */
19927 bool checkForMemberWithClassName() { 19989 bool checkForMemberWithClassName() {
19928 if (_enclosingClass == null) { 19990 if (_enclosingClass == null) {
19929 return false; 19991 return false;
19930 } 19992 }
19931 String className = _enclosingClass.name; 19993 String className = _enclosingClass.name;
19932 if (className == null) { 19994 if (className == null) {
19933 return false; 19995 return false;
19934 } 19996 }
19935 bool problemReported = false; 19997 bool problemReported = false;
19936 // check accessors 19998 // check accessors
19937 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 19999 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
19938 if (className == accessor.name) { 20000 if (className == accessor.name) {
19939 _errorReporter.reportError5(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, className.length, []); 20001 _errorReporter.reportError4(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, className.length, []);
19940 problemReported = true; 20002 problemReported = true;
19941 } 20003 }
19942 } 20004 }
19943 // don't check methods, they would be constructors 20005 // don't check methods, they would be constructors
19944 // done 20006 // done
19945 return problemReported; 20007 return problemReported;
19946 } 20008 }
19947 20009
19948 /** 20010 /**
19949 * Check to make sure that all similarly typed accessors are of the same type (including inherited 20011 * Check to make sure that all similarly typed accessors are of the same type (including inherited
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
20003 getterType = getGetterType(propertyAccessorElement); 20065 getterType = getGetterType(propertyAccessorElement);
20004 setterType = getSetterType(counterpartAccessor); 20066 setterType = getSetterType(counterpartAccessor);
20005 } else if (propertyAccessorElement.isSetter) { 20067 } else if (propertyAccessorElement.isSetter) {
20006 setterType = getSetterType(propertyAccessorElement); 20068 setterType = getSetterType(propertyAccessorElement);
20007 getterType = getGetterType(counterpartAccessor); 20069 getterType = getGetterType(counterpartAccessor);
20008 } 20070 }
20009 // If either types are not assignable to each other, report an error (if the getter is null, 20071 // If either types are not assignable to each other, report an error (if the getter is null,
20010 // it is dynamic which is assignable to everything). 20072 // it is dynamic which is assignable to everything).
20011 if (setterType != null && getterType != null && !getterType.isAssignableTo(s etterType)) { 20073 if (setterType != null && getterType != null && !getterType.isAssignableTo(s etterType)) {
20012 if (enclosingClassForCounterpart == null) { 20074 if (enclosingClassForCounterpart == null) {
20013 _errorReporter.reportError3(StaticWarningCode.MISMATCHED_GETTER_AND_SETT ER_TYPES, accessorDeclaration, [ 20075 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETT ER_TYPES, accessorDeclaration, [
20014 accessorTextName, 20076 accessorTextName,
20015 setterType.displayName, 20077 setterType.displayName,
20016 getterType.displayName]); 20078 getterType.displayName]);
20017 return true; 20079 return true;
20018 } else { 20080 } else {
20019 _errorReporter.reportError3(StaticWarningCode.MISMATCHED_GETTER_AND_SETT ER_TYPES_FROM_SUPERTYPE, accessorDeclaration, [ 20081 _errorReporter.reportError2(StaticWarningCode.MISMATCHED_GETTER_AND_SETT ER_TYPES_FROM_SUPERTYPE, accessorDeclaration, [
20020 accessorTextName, 20082 accessorTextName,
20021 setterType.displayName, 20083 setterType.displayName,
20022 getterType.displayName, 20084 getterType.displayName,
20023 enclosingClassForCounterpart.displayName]); 20085 enclosingClassForCounterpart.displayName]);
20024 } 20086 }
20025 } 20087 }
20026 return false; 20088 return false;
20027 } 20089 }
20028 20090
20029 /** 20091 /**
20030 * This verifies that the given function body does not contain return statemen ts that both have 20092 * This verifies that the given function body does not contain return statemen ts that both have
20031 * and do not have return values. 20093 * and do not have return values.
20032 * 20094 *
20033 * @param node the function body being tested 20095 * @param node the function body being tested
20034 * @return `true` if and only if an error code is generated on the passed node 20096 * @return `true` if and only if an error code is generated on the passed node
20035 * @see StaticWarningCode#MIXED_RETURN_TYPES 20097 * @see StaticWarningCode#MIXED_RETURN_TYPES
20036 */ 20098 */
20037 bool checkForMixedReturns(BlockFunctionBody node) { 20099 bool checkForMixedReturns(BlockFunctionBody node) {
20038 int withCount = _returnsWith.length; 20100 int withCount = _returnsWith.length;
20039 int withoutCount = _returnsWithout.length; 20101 int withoutCount = _returnsWithout.length;
20040 if (withCount > 0 && withoutCount > 0) { 20102 if (withCount > 0 && withoutCount > 0) {
20041 for (int i = 0; i < withCount; i++) { 20103 for (int i = 0; i < withCount; i++) {
20042 _errorReporter.reportError6(StaticWarningCode.MIXED_RETURN_TYPES, _retur nsWith[i].keyword, []); 20104 _errorReporter.reportError5(StaticWarningCode.MIXED_RETURN_TYPES, _retur nsWith[i].keyword, []);
20043 } 20105 }
20044 for (int i = 0; i < withoutCount; i++) { 20106 for (int i = 0; i < withoutCount; i++) {
20045 _errorReporter.reportError6(StaticWarningCode.MIXED_RETURN_TYPES, _retur nsWithout[i].keyword, []); 20107 _errorReporter.reportError5(StaticWarningCode.MIXED_RETURN_TYPES, _retur nsWithout[i].keyword, []);
20046 } 20108 }
20047 return true; 20109 return true;
20048 } 20110 }
20049 return false; 20111 return false;
20050 } 20112 }
20051 20113
20052 /** 20114 /**
20053 * This verifies that the passed mixin does not have an explicitly declared co nstructor. 20115 * This verifies that the passed mixin does not have an explicitly declared co nstructor.
20054 * 20116 *
20055 * @param mixinName the node to report problem on 20117 * @param mixinName the node to report problem on
20056 * @param mixinElement the mixing to evaluate 20118 * @param mixinElement the mixing to evaluate
20057 * @return `true` if and only if an error code is generated on the passed node 20119 * @return `true` if and only if an error code is generated on the passed node
20058 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR 20120 * @see CompileTimeErrorCode#MIXIN_DECLARES_CONSTRUCTOR
20059 */ 20121 */
20060 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl ement) { 20122 bool checkForMixinDeclaresConstructor(TypeName mixinName, ClassElement mixinEl ement) {
20061 for (ConstructorElement constructor in mixinElement.constructors) { 20123 for (ConstructorElement constructor in mixinElement.constructors) {
20062 if (!constructor.isSynthetic && !constructor.isFactory) { 20124 if (!constructor.isSynthetic && !constructor.isFactory) {
20063 _errorReporter.reportError3(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC TOR, mixinName, [mixinElement.name]); 20125 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUC TOR, mixinName, [mixinElement.name]);
20064 return true; 20126 return true;
20065 } 20127 }
20066 } 20128 }
20067 return false; 20129 return false;
20068 } 20130 }
20069 20131
20070 /** 20132 /**
20071 * This verifies that the passed mixin has the 'Object' superclass. 20133 * This verifies that the passed mixin has the 'Object' superclass.
20072 * 20134 *
20073 * @param mixinName the node to report problem on 20135 * @param mixinName the node to report problem on
20074 * @param mixinElement the mixing to evaluate 20136 * @param mixinElement the mixing to evaluate
20075 * @return `true` if and only if an error code is generated on the passed node 20137 * @return `true` if and only if an error code is generated on the passed node
20076 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT 20138 * @see CompileTimeErrorCode#MIXIN_INHERITS_FROM_NOT_OBJECT
20077 */ 20139 */
20078 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin Element) { 20140 bool checkForMixinInheritsNotFromObject(TypeName mixinName, ClassElement mixin Element) {
20079 InterfaceType mixinSupertype = mixinElement.supertype; 20141 InterfaceType mixinSupertype = mixinElement.supertype;
20080 if (mixinSupertype != null) { 20142 if (mixinSupertype != null) {
20081 if (!mixinSupertype.isObject || !mixinElement.isTypedef && mixinElement.mi xins.length != 0) { 20143 if (!mixinSupertype.isObject || !mixinElement.isTypedef && mixinElement.mi xins.length != 0) {
20082 _errorReporter.reportError3(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT _OBJECT, mixinName, [mixinElement.name]); 20144 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT _OBJECT, mixinName, [mixinElement.name]);
20083 return true; 20145 return true;
20084 } 20146 }
20085 } 20147 }
20086 return false; 20148 return false;
20087 } 20149 }
20088 20150
20089 /** 20151 /**
20090 * This verifies that the passed mixin does not reference 'super'. 20152 * This verifies that the passed mixin does not reference 'super'.
20091 * 20153 *
20092 * @param mixinName the node to report problem on 20154 * @param mixinName the node to report problem on
20093 * @param mixinElement the mixing to evaluate 20155 * @param mixinElement the mixing to evaluate
20094 * @return `true` if and only if an error code is generated on the passed node 20156 * @return `true` if and only if an error code is generated on the passed node
20095 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER 20157 * @see CompileTimeErrorCode#MIXIN_REFERENCES_SUPER
20096 */ 20158 */
20097 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen t) { 20159 bool checkForMixinReferencesSuper(TypeName mixinName, ClassElement mixinElemen t) {
20098 if (mixinElement.hasReferenceToSuper()) { 20160 if (mixinElement.hasReferenceToSuper()) {
20099 _errorReporter.reportError3(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m ixinName, [mixinElement.name]); 20161 _errorReporter.reportError2(CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, m ixinName, [mixinElement.name]);
20100 } 20162 }
20101 return false; 20163 return false;
20102 } 20164 }
20103 20165
20104 /** 20166 /**
20105 * This verifies that the passed constructor has at most one 'super' initializ er. 20167 * This verifies that the passed constructor has at most one 'super' initializ er.
20106 * 20168 *
20107 * @param node the constructor declaration to evaluate 20169 * @param node the constructor declaration to evaluate
20108 * @return `true` if and only if an error code is generated on the passed node 20170 * @return `true` if and only if an error code is generated on the passed node
20109 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS 20171 * @see CompileTimeErrorCode#MULTIPLE_SUPER_INITIALIZERS
20110 */ 20172 */
20111 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) { 20173 bool checkForMultipleSuperInitializers(ConstructorDeclaration node) {
20112 int numSuperInitializers = 0; 20174 int numSuperInitializers = 0;
20113 for (ConstructorInitializer initializer in node.initializers) { 20175 for (ConstructorInitializer initializer in node.initializers) {
20114 if (initializer is SuperConstructorInvocation) { 20176 if (initializer is SuperConstructorInvocation) {
20115 numSuperInitializers++; 20177 numSuperInitializers++;
20116 if (numSuperInitializers > 1) { 20178 if (numSuperInitializers > 1) {
20117 _errorReporter.reportError3(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA LIZERS, initializer, []); 20179 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_SUPER_INITIA LIZERS, initializer, []);
20118 } 20180 }
20119 } 20181 }
20120 } 20182 }
20121 return numSuperInitializers > 0; 20183 return numSuperInitializers > 0;
20122 } 20184 }
20123 20185
20124 /** 20186 /**
20125 * Checks to ensure that native function bodies can only in SDK code. 20187 * Checks to ensure that native function bodies can only in SDK code.
20126 * 20188 *
20127 * @param node the native function body to test 20189 * @param node the native function body to test
20128 * @return `true` if and only if an error code is generated on the passed node 20190 * @return `true` if and only if an error code is generated on the passed node
20129 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE 20191 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE
20130 */ 20192 */
20131 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { 20193 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) {
20132 if (!_isInSystemLibrary && !_hasExtUri) { 20194 if (!_isInSystemLibrary && !_hasExtUri) {
20133 _errorReporter.reportError3(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD K_CODE, node, []); 20195 _errorReporter.reportError2(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SD K_CODE, node, []);
20134 return true; 20196 return true;
20135 } 20197 }
20136 return false; 20198 return false;
20137 } 20199 }
20138 20200
20139 /** 20201 /**
20140 * This verifies that the passed 'new' instance creation expression invokes ex isting constructor. 20202 * This verifies that the passed 'new' instance creation expression invokes ex isting constructor.
20141 * 20203 *
20142 * This method assumes that the instance creation was tested to be 'new' befor e being called. 20204 * This method assumes that the instance creation was tested to be 'new' befor e being called.
20143 * 20205 *
(...skipping 13 matching lines...) Expand all
20157 } 20219 }
20158 // prepare class name 20220 // prepare class name
20159 TypeName type = constructorName.type; 20221 TypeName type = constructorName.type;
20160 if (type == null) { 20222 if (type == null) {
20161 return false; 20223 return false;
20162 } 20224 }
20163 Identifier className = type.name; 20225 Identifier className = type.name;
20164 // report as named or default constructor absence 20226 // report as named or default constructor absence
20165 SimpleIdentifier name = constructorName.name; 20227 SimpleIdentifier name = constructorName.name;
20166 if (name != null) { 20228 if (name != null) {
20167 _errorReporter.reportError3(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT OR, name, [className, name]); 20229 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT OR, name, [className, name]);
20168 } else { 20230 } else {
20169 _errorReporter.reportError3(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT OR_DEFAULT, constructorName, [className]); 20231 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCT OR_DEFAULT, constructorName, [className]);
20170 } 20232 }
20171 return true; 20233 return true;
20172 } 20234 }
20173 20235
20174 /** 20236 /**
20175 * This checks that if the passed class declaration implicitly calls default c onstructor of its 20237 * This checks that if the passed class declaration implicitly calls default c onstructor of its
20176 * superclass, there should be such default constructor - implicit or explicit . 20238 * superclass, there should be such default constructor - implicit or explicit .
20177 * 20239 *
20178 * @param node the [ClassDeclaration] to evaluate 20240 * @param node the [ClassDeclaration] to evaluate
20179 * @return `true` if and only if an error code is generated on the passed node 20241 * @return `true` if and only if an error code is generated on the passed node
20180 * @see CompileTimeErrorCode#NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT 20242 * @see CompileTimeErrorCode#NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT
20181 */ 20243 */
20182 bool checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) { 20244 bool checkForNoDefaultSuperConstructorImplicit(ClassDeclaration node) {
20183 // do nothing if there is explicit constructor 20245 // do nothing if there is explicit constructor
20184 List<ConstructorElement> constructors = _enclosingClass.constructors; 20246 List<ConstructorElement> constructors = _enclosingClass.constructors;
20185 if (!constructors[0].isSynthetic) { 20247 if (!constructors[0].isSynthetic) {
20186 return false; 20248 return false;
20187 } 20249 }
20188 // prepare super 20250 // prepare super
20189 InterfaceType superType = _enclosingClass.supertype; 20251 InterfaceType superType = _enclosingClass.supertype;
20190 if (superType == null) { 20252 if (superType == null) {
20191 return false; 20253 return false;
20192 } 20254 }
20193 ClassElement superElement = superType.element; 20255 ClassElement superElement = superType.element;
20194 // try to find default generative super constructor 20256 // try to find default generative super constructor
20195 ConstructorElement superUnnamedConstructor = superElement.unnamedConstructor ; 20257 ConstructorElement superUnnamedConstructor = superElement.unnamedConstructor ;
20196 if (superUnnamedConstructor != null) { 20258 if (superUnnamedConstructor != null) {
20197 if (superUnnamedConstructor.isFactory) { 20259 if (superUnnamedConstructor.isFactory) {
20198 _errorReporter.reportError3(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC TOR, node.name, [superUnnamedConstructor]); 20260 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC TOR, node.name, [superUnnamedConstructor]);
20199 return true; 20261 return true;
20200 } 20262 }
20201 if (superUnnamedConstructor.isDefaultConstructor) { 20263 if (superUnnamedConstructor.isDefaultConstructor) {
20202 return true; 20264 return true;
20203 } 20265 }
20204 } 20266 }
20205 // report problem 20267 // report problem
20206 _errorReporter.reportError3(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTO R_IMPLICIT, node.name, [superType.displayName]); 20268 _errorReporter.reportError2(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTO R_IMPLICIT, node.name, [superType.displayName]);
20207 return true; 20269 return true;
20208 } 20270 }
20209 20271
20210 /** 20272 /**
20211 * This checks that passed class declaration overrides all members required by its superclasses 20273 * This checks that passed class declaration overrides all members required by its superclasses
20212 * and interfaces. 20274 * and interfaces.
20213 * 20275 *
20214 * @param node the [ClassDeclaration] to evaluate 20276 * @param node the [ClassDeclaration] to evaluate
20215 * @return `true` if and only if an error code is generated on the passed node 20277 * @return `true` if and only if an error code is generated on the passed node
20216 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE 20278 * @see StaticWarningCode#NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
20345 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is 20407 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is
20346 * reported on the expression. 20408 * reported on the expression.
20347 * 20409 *
20348 * @param condition the conditional expression to test 20410 * @param condition the conditional expression to test
20349 * @return `true` if and only if an error code is generated on the passed node 20411 * @return `true` if and only if an error code is generated on the passed node
20350 * @see StaticTypeWarningCode#NON_BOOL_CONDITION 20412 * @see StaticTypeWarningCode#NON_BOOL_CONDITION
20351 */ 20413 */
20352 bool checkForNonBoolCondition(Expression condition) { 20414 bool checkForNonBoolCondition(Expression condition) {
20353 Type2 conditionType = getStaticType(condition); 20415 Type2 conditionType = getStaticType(condition);
20354 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { 20416 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) {
20355 _errorReporter.reportError3(StaticTypeWarningCode.NON_BOOL_CONDITION, cond ition, []); 20417 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_CONDITION, cond ition, []);
20356 return true; 20418 return true;
20357 } 20419 }
20358 return false; 20420 return false;
20359 } 20421 }
20360 20422
20361 /** 20423 /**
20362 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input. 20424 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input.
20363 * 20425 *
20364 * @param node the assert statement to evaluate 20426 * @param node the assert statement to evaluate
20365 * @return `true` if and only if an error code is generated on the passed node 20427 * @return `true` if and only if an error code is generated on the passed node
20366 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION 20428 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION
20367 */ 20429 */
20368 bool checkForNonBoolExpression(AssertStatement node) { 20430 bool checkForNonBoolExpression(AssertStatement node) {
20369 Expression expression = node.condition; 20431 Expression expression = node.condition;
20370 Type2 type = getStaticType(expression); 20432 Type2 type = getStaticType(expression);
20371 if (type is InterfaceType) { 20433 if (type is InterfaceType) {
20372 if (!type.isAssignableTo(_boolType)) { 20434 if (!type.isAssignableTo(_boolType)) {
20373 _errorReporter.reportError3(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e xpression, []); 20435 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e xpression, []);
20374 return true; 20436 return true;
20375 } 20437 }
20376 } else if (type is FunctionType) { 20438 } else if (type is FunctionType) {
20377 FunctionType functionType = type; 20439 FunctionType functionType = type;
20378 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_boolType)) { 20440 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_boolType)) {
20379 _errorReporter.reportError3(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e xpression, []); 20441 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_EXPRESSION, e xpression, []);
20380 return true; 20442 return true;
20381 } 20443 }
20382 } 20444 }
20383 return false; 20445 return false;
20384 } 20446 }
20385 20447
20386 /** 20448 /**
20387 * Checks to ensure that the given expression is assignable to bool. 20449 * Checks to ensure that the given expression is assignable to bool.
20388 * 20450 *
20389 * @param expression the expression expression to test 20451 * @param expression the expression expression to test
20390 * @return `true` if and only if an error code is generated on the passed node 20452 * @return `true` if and only if an error code is generated on the passed node
20391 * @see StaticTypeWarningCode#NON_BOOL_NEGATION_EXPRESSION 20453 * @see StaticTypeWarningCode#NON_BOOL_NEGATION_EXPRESSION
20392 */ 20454 */
20393 bool checkForNonBoolNegationExpression(Expression expression) { 20455 bool checkForNonBoolNegationExpression(Expression expression) {
20394 Type2 conditionType = getStaticType(expression); 20456 Type2 conditionType = getStaticType(expression);
20395 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { 20457 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) {
20396 _errorReporter.reportError3(StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRES SION, expression, []); 20458 _errorReporter.reportError2(StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRES SION, expression, []);
20397 return true; 20459 return true;
20398 } 20460 }
20399 return false; 20461 return false;
20400 } 20462 }
20401 20463
20402 /** 20464 /**
20403 * This verifies the passed map literal either: 20465 * This verifies the passed map literal either:
20404 * * has `const modifier` 20466 * * has `const modifier`
20405 * * has explicit type arguments 20467 * * has explicit type arguments
20406 * * is not start of the statement 20468 * * is not start of the statement
20407 * 20469 *
20408 * @param node the map literal to evaluate 20470 * @param node the map literal to evaluate
20409 * @return `true` if and only if an error code is generated on the passed node 20471 * @return `true` if and only if an error code is generated on the passed node
20410 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT 20472 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT
20411 */ 20473 */
20412 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { 20474 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) {
20413 // "const" 20475 // "const"
20414 if (node.constKeyword != null) { 20476 if (node.constKeyword != null) {
20415 return false; 20477 return false;
20416 } 20478 }
20417 // has type arguments 20479 // has type arguments
20418 if (node.typeArguments != null) { 20480 if (node.typeArguments != null) {
20419 return false; 20481 return false;
20420 } 20482 }
20421 // prepare statement 20483 // prepare statement
20422 Statement statement = node.getAncestor(ExpressionStatement); 20484 Statement statement = node.getAncestor((node) => node is ExpressionStatement );
20423 if (statement == null) { 20485 if (statement == null) {
20424 return false; 20486 return false;
20425 } 20487 }
20426 // OK, statement does not start with map 20488 // OK, statement does not start with map
20427 if (statement.beginToken != node.beginToken) { 20489 if (statement.beginToken != node.beginToken) {
20428 return false; 20490 return false;
20429 } 20491 }
20430 // report problem 20492 // report problem
20431 _errorReporter.reportError3(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION _STATEMENT, node, []); 20493 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION _STATEMENT, node, []);
20432 return true; 20494 return true;
20433 } 20495 }
20434 20496
20435 /** 20497 /**
20436 * This verifies the passed method declaration of operator `[]=`, has `void` r eturn 20498 * This verifies the passed method declaration of operator `[]=`, has `void` r eturn
20437 * type. 20499 * type.
20438 * 20500 *
20439 * @param node the method declaration to evaluate 20501 * @param node the method declaration to evaluate
20440 * @return `true` if and only if an error code is generated on the passed node 20502 * @return `true` if and only if an error code is generated on the passed node
20441 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR 20503 * @see StaticWarningCode#NON_VOID_RETURN_FOR_OPERATOR
20442 */ 20504 */
20443 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { 20505 bool checkForNonVoidReturnTypeForOperator(MethodDeclaration node) {
20444 // check that []= operator 20506 // check that []= operator
20445 SimpleIdentifier name = node.name; 20507 SimpleIdentifier name = node.name;
20446 if (name.name != "[]=") { 20508 if (name.name != "[]=") {
20447 return false; 20509 return false;
20448 } 20510 }
20449 // check return type 20511 // check return type
20450 TypeName typeName = node.returnType; 20512 TypeName typeName = node.returnType;
20451 if (typeName != null) { 20513 if (typeName != null) {
20452 Type2 type = typeName.type; 20514 Type2 type = typeName.type;
20453 if (type != null && !type.isVoid) { 20515 if (type != null && !type.isVoid) {
20454 _errorReporter.reportError3(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT OR, typeName, []); 20516 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_OPERAT OR, typeName, []);
20455 } 20517 }
20456 } 20518 }
20457 // no warning 20519 // no warning
20458 return false; 20520 return false;
20459 } 20521 }
20460 20522
20461 /** 20523 /**
20462 * This verifies the passed setter has no return type or the `void` return typ e. 20524 * This verifies the passed setter has no return type or the `void` return typ e.
20463 * 20525 *
20464 * @param typeName the type name to evaluate 20526 * @param typeName the type name to evaluate
20465 * @return `true` if and only if an error code is generated on the passed node 20527 * @return `true` if and only if an error code is generated on the passed node
20466 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER 20528 * @see StaticWarningCode#NON_VOID_RETURN_FOR_SETTER
20467 */ 20529 */
20468 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) { 20530 bool checkForNonVoidReturnTypeForSetter(TypeName typeName) {
20469 if (typeName != null) { 20531 if (typeName != null) {
20470 Type2 type = typeName.type; 20532 Type2 type = typeName.type;
20471 if (type != null && !type.isVoid) { 20533 if (type != null && !type.isVoid) {
20472 _errorReporter.reportError3(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER , typeName, []); 20534 _errorReporter.reportError2(StaticWarningCode.NON_VOID_RETURN_FOR_SETTER , typeName, []);
20473 } 20535 }
20474 } 20536 }
20475 return false; 20537 return false;
20476 } 20538 }
20477 20539
20478 /** 20540 /**
20479 * This verifies the passed operator-method declaration, does not have an opti onal parameter. 20541 * This verifies the passed operator-method declaration, does not have an opti onal parameter.
20480 * 20542 *
20481 * This method assumes that the method declaration was tested to be an operato r declaration before 20543 * This method assumes that the method declaration was tested to be an operato r declaration before
20482 * being called. 20544 * being called.
20483 * 20545 *
20484 * @param node the method declaration to evaluate 20546 * @param node the method declaration to evaluate
20485 * @return `true` if and only if an error code is generated on the passed node 20547 * @return `true` if and only if an error code is generated on the passed node
20486 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR 20548 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR
20487 */ 20549 */
20488 bool checkForOptionalParameterInOperator(MethodDeclaration node) { 20550 bool checkForOptionalParameterInOperator(MethodDeclaration node) {
20489 FormalParameterList parameterList = node.parameters; 20551 FormalParameterList parameterList = node.parameters;
20490 if (parameterList == null) { 20552 if (parameterList == null) {
20491 return false; 20553 return false;
20492 } 20554 }
20493 bool foundError = false; 20555 bool foundError = false;
20494 NodeList<FormalParameter> formalParameters = parameterList.parameters; 20556 NodeList<FormalParameter> formalParameters = parameterList.parameters;
20495 for (FormalParameter formalParameter in formalParameters) { 20557 for (FormalParameter formalParameter in formalParameters) {
20496 if (formalParameter.kind.isOptional) { 20558 if (formalParameter.kind.isOptional) {
20497 _errorReporter.reportError3(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O PERATOR, formalParameter, []); 20559 _errorReporter.reportError2(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_O PERATOR, formalParameter, []);
20498 foundError = true; 20560 foundError = true;
20499 } 20561 }
20500 } 20562 }
20501 return foundError; 20563 return foundError;
20502 } 20564 }
20503 20565
20504 /** 20566 /**
20505 * This checks for named optional parameters that begin with '_'. 20567 * This checks for named optional parameters that begin with '_'.
20506 * 20568 *
20507 * @param node the default formal parameter to evaluate 20569 * @param node the default formal parameter to evaluate
20508 * @return `true` if and only if an error code is generated on the passed node 20570 * @return `true` if and only if an error code is generated on the passed node
20509 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER 20571 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER
20510 */ 20572 */
20511 bool checkForPrivateOptionalParameter(FormalParameter node) { 20573 bool checkForPrivateOptionalParameter(FormalParameter node) {
20512 // should be named parameter 20574 // should be named parameter
20513 if (node.kind != ParameterKind.NAMED) { 20575 if (node.kind != ParameterKind.NAMED) {
20514 return false; 20576 return false;
20515 } 20577 }
20516 // name should start with '_' 20578 // name should start with '_'
20517 SimpleIdentifier name = node.identifier; 20579 SimpleIdentifier name = node.identifier;
20518 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) { 20580 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) {
20519 return false; 20581 return false;
20520 } 20582 }
20521 // report problem 20583 // report problem
20522 _errorReporter.reportError3(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, node, []); 20584 _errorReporter.reportError2(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER, node, []);
20523 return true; 20585 return true;
20524 } 20586 }
20525 20587
20526 /** 20588 /**
20527 * This checks if the passed constructor declaration is the redirecting genera tive constructor and 20589 * This checks if the passed constructor declaration is the redirecting genera tive constructor and
20528 * references itself directly or indirectly. 20590 * references itself directly or indirectly.
20529 * 20591 *
20530 * @param node the constructor declaration to evaluate 20592 * @param node the constructor declaration to evaluate
20531 * @return `true` if and only if an error code is generated on the passed node 20593 * @return `true` if and only if an error code is generated on the passed node
20532 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT 20594 * @see CompileTimeErrorCode#RECURSIVE_CONSTRUCTOR_REDIRECT
20533 */ 20595 */
20534 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) { 20596 bool checkForRecursiveConstructorRedirect(ConstructorDeclaration node) {
20535 // we check generative constructor here 20597 // we check generative constructor here
20536 if (node.factoryKeyword != null) { 20598 if (node.factoryKeyword != null) {
20537 return false; 20599 return false;
20538 } 20600 }
20539 // try to find redirecting constructor invocation and analyzer it for recurs ion 20601 // try to find redirecting constructor invocation and analyzer it for recurs ion
20540 for (ConstructorInitializer initializer in node.initializers) { 20602 for (ConstructorInitializer initializer in node.initializers) {
20541 if (initializer is RedirectingConstructorInvocation) { 20603 if (initializer is RedirectingConstructorInvocation) {
20542 // OK if no cycle 20604 // OK if no cycle
20543 ConstructorElement element = node.element; 20605 ConstructorElement element = node.element;
20544 if (!hasRedirectingFactoryConstructorCycle(element)) { 20606 if (!hasRedirectingFactoryConstructorCycle(element)) {
20545 return false; 20607 return false;
20546 } 20608 }
20547 // report error 20609 // report error
20548 _errorReporter.reportError3(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R EDIRECT, initializer, []); 20610 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_R EDIRECT, initializer, []);
20549 return true; 20611 return true;
20550 } 20612 }
20551 } 20613 }
20552 // OK, no redirecting constructor invocation 20614 // OK, no redirecting constructor invocation
20553 return false; 20615 return false;
20554 } 20616 }
20555 20617
20556 /** 20618 /**
20557 * This checks if the passed constructor declaration has redirected constructo r and references 20619 * This checks if the passed constructor declaration has redirected constructo r and references
20558 * itself directly or indirectly. 20620 * itself directly or indirectly.
20559 * 20621 *
20560 * @param node the constructor declaration to evaluate 20622 * @param node the constructor declaration to evaluate
20561 * @return `true` if and only if an error code is generated on the passed node 20623 * @return `true` if and only if an error code is generated on the passed node
20562 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT 20624 * @see CompileTimeErrorCode#RECURSIVE_FACTORY_REDIRECT
20563 */ 20625 */
20564 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) { 20626 bool checkForRecursiveFactoryRedirect(ConstructorDeclaration node) {
20565 // prepare redirected constructor 20627 // prepare redirected constructor
20566 ConstructorName redirectedConstructorNode = node.redirectedConstructor; 20628 ConstructorName redirectedConstructorNode = node.redirectedConstructor;
20567 if (redirectedConstructorNode == null) { 20629 if (redirectedConstructorNode == null) {
20568 return false; 20630 return false;
20569 } 20631 }
20570 // OK if no cycle 20632 // OK if no cycle
20571 ConstructorElement element = node.element; 20633 ConstructorElement element = node.element;
20572 if (!hasRedirectingFactoryConstructorCycle(element)) { 20634 if (!hasRedirectingFactoryConstructorCycle(element)) {
20573 return false; 20635 return false;
20574 } 20636 }
20575 // report error 20637 // report error
20576 _errorReporter.reportError3(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, redirectedConstructorNode, []); 20638 _errorReporter.reportError2(CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT, redirectedConstructorNode, []);
20577 return true; 20639 return true;
20578 } 20640 }
20579 20641
20580 /** 20642 /**
20581 * This checks the class declaration is not a superinterface to itself. 20643 * This checks the class declaration is not a superinterface to itself.
20582 * 20644 *
20583 * @param classElt the class element to test 20645 * @param classElt the class element to test
20584 * @return `true` if and only if an error code is generated on the passed elem ent 20646 * @return `true` if and only if an error code is generated on the passed elem ent
20585 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE 20647 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE
20586 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS 20648 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
20587 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS 20649 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS
20588 */ 20650 */
20589 bool checkForRecursiveInterfaceInheritance(ClassElement classElt) { 20651 bool checkForRecursiveInterfaceInheritance(ClassElement classElt) {
20590 if (classElt == null) { 20652 if (classElt == null) {
20591 return false; 20653 return false;
20592 } 20654 }
20593 return checkForRecursiveInterfaceInheritance2(classElt, new List<ClassElemen t>()); 20655 return safeCheckForRecursiveInterfaceInheritance(classElt, new List<ClassEle ment>());
20594 } 20656 }
20595 20657
20596 /** 20658 /**
20597 * This checks the class declaration is not a superinterface to itself.
20598 *
20599 * @param classElt the class element to test
20600 * @param path a list containing the potentially cyclic implements path
20601 * @return `true` if and only if an error code is generated on the passed elem ent
20602 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE
20603 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
20604 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS
20605 */
20606 bool checkForRecursiveInterfaceInheritance2(ClassElement classElt, List<ClassE lement> path) {
20607 // Detect error condition.
20608 int size = path.length;
20609 // If this is not the base case (size > 0), and the enclosing class is the p assed class
20610 // element then an error an error.
20611 if (size > 0 && _enclosingClass == classElt) {
20612 String enclosingClassName = _enclosingClass.displayName;
20613 if (size > 1) {
20614 // Construct a string showing the cyclic implements path: "A, B, C, D, A "
20615 String separator = ", ";
20616 JavaStringBuilder builder = new JavaStringBuilder();
20617 for (int i = 0; i < size; i++) {
20618 builder.append(path[i].displayName);
20619 builder.append(separator);
20620 }
20621 builder.append(classElt.displayName);
20622 _errorReporter.reportError5(CompileTimeErrorCode.RECURSIVE_INTERFACE_INH ERITANCE, _enclosingClass.nameOffset, enclosingClassName.length, [enclosingClass Name, builder.toString()]);
20623 return true;
20624 } else {
20625 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or RECURSIVE_INT ERFACE_INHERITANCE_BASE_CASE_EXTENDS
20626 InterfaceType supertype = classElt.supertype;
20627 ErrorCode errorCode = (supertype != null && _enclosingClass == supertype .element ? CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTEND S : CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS);
20628 _errorReporter.reportError5(errorCode, _enclosingClass.nameOffset, enclo singClassName.length, [enclosingClassName]);
20629 return true;
20630 }
20631 }
20632 if (path.indexOf(classElt) > 0) {
20633 return false;
20634 }
20635 path.add(classElt);
20636 // n-case
20637 InterfaceType supertype = classElt.supertype;
20638 if (supertype != null && checkForRecursiveInterfaceInheritance2(supertype.el ement, path)) {
20639 return true;
20640 }
20641 List<InterfaceType> interfaceTypes = classElt.interfaces;
20642 for (InterfaceType interfaceType in interfaceTypes) {
20643 if (checkForRecursiveInterfaceInheritance2(interfaceType.element, path)) {
20644 return true;
20645 }
20646 }
20647 path.removeAt(path.length - 1);
20648 return false;
20649 }
20650
20651 /**
20652 * This checks the passed constructor declaration has a valid combination of r edirected 20659 * This checks the passed constructor declaration has a valid combination of r edirected
20653 * constructor invocation(s), super constructor invocations and field initiali zers. 20660 * constructor invocation(s), super constructor invocations and field initiali zers.
20654 * 20661 *
20655 * @param node the constructor declaration to evaluate 20662 * @param node the constructor declaration to evaluate
20656 * @return `true` if and only if an error code is generated on the passed node 20663 * @return `true` if and only if an error code is generated on the passed node
20657 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR 20664 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
20658 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR 20665 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR
20659 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS 20666 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS
20660 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR 20667 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR
20661 */ 20668 */
20662 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { 20669 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) {
20663 bool errorReported = false; 20670 bool errorReported = false;
20664 // 20671 //
20665 // Check for default values in the parameters 20672 // Check for default values in the parameters
20666 // 20673 //
20667 ConstructorName redirectedConstructor = node.redirectedConstructor; 20674 ConstructorName redirectedConstructor = node.redirectedConstructor;
20668 if (redirectedConstructor != null) { 20675 if (redirectedConstructor != null) {
20669 for (FormalParameter parameter in node.parameters.parameters) { 20676 for (FormalParameter parameter in node.parameters.parameters) {
20670 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul l) { 20677 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul l) {
20671 _errorReporter.reportError3(CompileTimeErrorCode.DEFAULT_VALUE_IN_REDI RECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []); 20678 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_REDI RECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []);
20672 errorReported = true; 20679 errorReported = true;
20673 } 20680 }
20674 } 20681 }
20675 } 20682 }
20676 // check if there are redirected invocations 20683 // check if there are redirected invocations
20677 int numRedirections = 0; 20684 int numRedirections = 0;
20678 for (ConstructorInitializer initializer in node.initializers) { 20685 for (ConstructorInitializer initializer in node.initializers) {
20679 if (initializer is RedirectingConstructorInvocation) { 20686 if (initializer is RedirectingConstructorInvocation) {
20680 if (numRedirections > 0) { 20687 if (numRedirections > 0) {
20681 _errorReporter.reportError3(CompileTimeErrorCode.MULTIPLE_REDIRECTING_ CONSTRUCTOR_INVOCATIONS, initializer, []); 20688 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_REDIRECTING_ CONSTRUCTOR_INVOCATIONS, initializer, []);
20682 errorReported = true; 20689 errorReported = true;
20683 } 20690 }
20684 numRedirections++; 20691 numRedirections++;
20685 } 20692 }
20686 } 20693 }
20687 // check for other initializers 20694 // check for other initializers
20688 if (numRedirections > 0) { 20695 if (numRedirections > 0) {
20689 for (ConstructorInitializer initializer in node.initializers) { 20696 for (ConstructorInitializer initializer in node.initializers) {
20690 if (initializer is SuperConstructorInvocation) { 20697 if (initializer is SuperConstructorInvocation) {
20691 _errorReporter.reportError3(CompileTimeErrorCode.SUPER_IN_REDIRECTING_ CONSTRUCTOR, initializer, []); 20698 _errorReporter.reportError2(CompileTimeErrorCode.SUPER_IN_REDIRECTING_ CONSTRUCTOR, initializer, []);
20692 errorReported = true; 20699 errorReported = true;
20693 } 20700 }
20694 if (initializer is ConstructorFieldInitializer) { 20701 if (initializer is ConstructorFieldInitializer) {
20695 _errorReporter.reportError3(CompileTimeErrorCode.FIELD_INITIALIZER_RED IRECTING_CONSTRUCTOR, initializer, []); 20702 _errorReporter.reportError2(CompileTimeErrorCode.FIELD_INITIALIZER_RED IRECTING_CONSTRUCTOR, initializer, []);
20696 errorReported = true; 20703 errorReported = true;
20697 } 20704 }
20698 } 20705 }
20699 } 20706 }
20700 // done 20707 // done
20701 return errorReported; 20708 return errorReported;
20702 } 20709 }
20703 20710
20704 /** 20711 /**
20705 * This checks if the passed constructor declaration has redirected constructo r and references 20712 * This checks if the passed constructor declaration has redirected constructo r and references
(...skipping 21 matching lines...) Expand all
20727 // prepare redirected constructor 20734 // prepare redirected constructor
20728 ConstructorElement redirectedConstructor = element.redirectedConstructor; 20735 ConstructorElement redirectedConstructor = element.redirectedConstructor;
20729 if (redirectedConstructor == null) { 20736 if (redirectedConstructor == null) {
20730 return false; 20737 return false;
20731 } 20738 }
20732 // OK, it is also 'const' 20739 // OK, it is also 'const'
20733 if (redirectedConstructor.isConst) { 20740 if (redirectedConstructor.isConst) {
20734 return false; 20741 return false;
20735 } 20742 }
20736 // report error 20743 // report error
20737 _errorReporter.reportError3(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST RUCTOR, redirectedConstructorNode, []); 20744 _errorReporter.reportError2(CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONST RUCTOR, redirectedConstructorNode, []);
20738 return true; 20745 return true;
20739 } 20746 }
20740 20747
20741 /** 20748 /**
20742 * This checks that the rethrow is inside of a catch clause. 20749 * This checks that the rethrow is inside of a catch clause.
20743 * 20750 *
20744 * @param node the rethrow expression to evaluate 20751 * @param node the rethrow expression to evaluate
20745 * @return `true` if and only if an error code is generated on the passed node 20752 * @return `true` if and only if an error code is generated on the passed node
20746 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH 20753 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH
20747 */ 20754 */
20748 bool checkForRethrowOutsideCatch(RethrowExpression node) { 20755 bool checkForRethrowOutsideCatch(RethrowExpression node) {
20749 if (!_isInCatchClause) { 20756 if (!_isInCatchClause) {
20750 _errorReporter.reportError3(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no de, []); 20757 _errorReporter.reportError2(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, no de, []);
20751 return true; 20758 return true;
20752 } 20759 }
20753 return false; 20760 return false;
20754 } 20761 }
20755 20762
20756 /** 20763 /**
20757 * This checks that if the the given constructor declaration is generative, th en it does not have 20764 * This checks that if the the given constructor declaration is generative, th en it does not have
20758 * an expression function body. 20765 * an expression function body.
20759 * 20766 *
20760 * @param node the constructor to evaluate 20767 * @param node the constructor to evaluate
20761 * @return `true` if and only if an error code is generated on the passed node 20768 * @return `true` if and only if an error code is generated on the passed node
20762 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR 20769 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR
20763 */ 20770 */
20764 bool checkForReturnInGenerativeConstructor(ConstructorDeclaration node) { 20771 bool checkForReturnInGenerativeConstructor(ConstructorDeclaration node) {
20765 // ignore factory 20772 // ignore factory
20766 if (node.factoryKeyword != null) { 20773 if (node.factoryKeyword != null) {
20767 return false; 20774 return false;
20768 } 20775 }
20769 // block body (with possible return statement) is checked elsewhere 20776 // block body (with possible return statement) is checked elsewhere
20770 FunctionBody body = node.body; 20777 FunctionBody body = node.body;
20771 if (body is! ExpressionFunctionBody) { 20778 if (body is! ExpressionFunctionBody) {
20772 return false; 20779 return false;
20773 } 20780 }
20774 // report error 20781 // report error
20775 _errorReporter.reportError3(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTR UCTOR, body, []); 20782 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTR UCTOR, body, []);
20776 return true; 20783 return true;
20777 } 20784 }
20778 20785
20779 /** 20786 /**
20780 * This checks that a type mis-match between the return type and the expressed return type by the 20787 * This checks that a type mis-match between the return type and the expressed return type by the
20781 * enclosing method or function. 20788 * enclosing method or function.
20782 * 20789 *
20783 * This method is called both by [checkForAllReturnStatementErrorCodes] 20790 * This method is called both by [checkForAllReturnStatementErrorCodes]
20784 * and [visitExpressionFunctionBody]. 20791 * and [visitExpressionFunctionBody].
20785 * 20792 *
20786 * @param returnExpression the returned expression to evaluate 20793 * @param returnExpression the returned expression to evaluate
20787 * @param expectedReturnType the expressed return type by the enclosing method or function 20794 * @param expectedReturnType the expressed return type by the enclosing method or function
20788 * @return `true` if and only if an error code is generated on the passed node 20795 * @return `true` if and only if an error code is generated on the passed node
20789 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE 20796 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE
20790 */ 20797 */
20791 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe turnType) { 20798 bool checkForReturnOfInvalidType(Expression returnExpression, Type2 expectedRe turnType) {
20792 Type2 staticReturnType = getStaticType(returnExpression); 20799 Type2 staticReturnType = getStaticType(returnExpression);
20793 if (expectedReturnType.isVoid) { 20800 if (expectedReturnType.isVoid) {
20794 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) { 20801 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) {
20795 return false; 20802 return false;
20796 } 20803 }
20797 _errorReporter.reportError3(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ 20804 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [
20798 staticReturnType.displayName, 20805 staticReturnType.displayName,
20799 expectedReturnType.displayName, 20806 expectedReturnType.displayName,
20800 _enclosingFunction.displayName]); 20807 _enclosingFunction.displayName]);
20801 return true; 20808 return true;
20802 } 20809 }
20803 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType ); 20810 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType );
20804 if (isStaticAssignable) { 20811 if (isStaticAssignable) {
20805 return false; 20812 return false;
20806 } 20813 }
20807 _errorReporter.reportError3(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, re turnExpression, [ 20814 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, re turnExpression, [
20808 staticReturnType.displayName, 20815 staticReturnType.displayName,
20809 expectedReturnType.displayName, 20816 expectedReturnType.displayName,
20810 _enclosingFunction.displayName]); 20817 _enclosingFunction.displayName]);
20811 return true; 20818 return true;
20812 } 20819 }
20813 20820
20814 /** 20821 /**
20815 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance 20822 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance
20816 * member. 20823 * member.
20817 * 20824 *
(...skipping 13 matching lines...) Expand all
20831 Element element = name.staticElement; 20838 Element element = name.staticElement;
20832 if (element is! ExecutableElement) { 20839 if (element is! ExecutableElement) {
20833 return false; 20840 return false;
20834 } 20841 }
20835 ExecutableElement memberElement = element as ExecutableElement; 20842 ExecutableElement memberElement = element as ExecutableElement;
20836 // OK, static 20843 // OK, static
20837 if (memberElement.isStatic) { 20844 if (memberElement.isStatic) {
20838 return false; 20845 return false;
20839 } 20846 }
20840 // report problem 20847 // report problem
20841 _errorReporter.reportError3(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB ER, name, [name.name]); 20848 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB ER, name, [name.name]);
20842 return true; 20849 return true;
20843 } 20850 }
20844 20851
20845 /** 20852 /**
20846 * This checks that the type of the passed 'switch' expression is assignable t o the type of the 20853 * This checks that the type of the passed 'switch' expression is assignable t o the type of the
20847 * 'case' members. 20854 * 'case' members.
20848 * 20855 *
20849 * @param node the 'switch' statement to evaluate 20856 * @param node the 'switch' statement to evaluate
20850 * @return `true` if and only if an error code is generated on the passed node 20857 * @return `true` if and only if an error code is generated on the passed node
20851 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE 20858 * @see StaticWarningCode#SWITCH_EXPRESSION_NOT_ASSIGNABLE
(...skipping 13 matching lines...) Expand all
20865 } 20872 }
20866 SwitchCase switchCase = switchMember as SwitchCase; 20873 SwitchCase switchCase = switchMember as SwitchCase;
20867 // prepare 'case' type 20874 // prepare 'case' type
20868 Expression caseExpression = switchCase.expression; 20875 Expression caseExpression = switchCase.expression;
20869 Type2 caseType = getStaticType(caseExpression); 20876 Type2 caseType = getStaticType(caseExpression);
20870 // check types 20877 // check types
20871 if (expressionType.isAssignableTo(caseType)) { 20878 if (expressionType.isAssignableTo(caseType)) {
20872 return false; 20879 return false;
20873 } 20880 }
20874 // report problem 20881 // report problem
20875 _errorReporter.reportError3(StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGN ABLE, expression, [expressionType, caseType]); 20882 _errorReporter.reportError2(StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGN ABLE, expression, [expressionType, caseType]);
20876 return true; 20883 return true;
20877 } 20884 }
20878 return false; 20885 return false;
20879 } 20886 }
20880 20887
20881 /** 20888 /**
20882 * This verifies that the passed function type alias does not reference itself directly. 20889 * This verifies that the passed function type alias does not reference itself directly.
20883 * 20890 *
20884 * @param node the function type alias to evaluate 20891 * @param node the function type alias to evaluate
20885 * @return `true` if and only if an error code is generated on the passed node 20892 * @return `true` if and only if an error code is generated on the passed node
20886 * @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF 20893 * @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
20887 */ 20894 */
20888 bool checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node) { 20895 bool checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node) {
20889 FunctionTypeAliasElement element = node.element; 20896 FunctionTypeAliasElement element = node.element;
20890 if (!hasTypedefSelfReference(element)) { 20897 if (!hasTypedefSelfReference(element)) {
20891 return false; 20898 return false;
20892 } 20899 }
20893 _errorReporter.reportError3(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE _ITSELF, node, []); 20900 _errorReporter.reportError2(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE _ITSELF, node, []);
20894 return true; 20901 return true;
20895 } 20902 }
20896 20903
20897 /** 20904 /**
20898 * This verifies that the given class type alias does not reference itself. 20905 * This verifies that the given class type alias does not reference itself.
20899 * 20906 *
20900 * @return `true` if and only if an error code is generated on the passed node 20907 * @return `true` if and only if an error code is generated on the passed node
20901 * @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF 20908 * @see CompileTimeErrorCode#TYPE_ALIAS_CANNOT_REFERENCE_ITSELF
20902 */ 20909 */
20903 bool checkForTypeAliasCannotReferenceItself_mixin(ClassTypeAlias node) { 20910 bool checkForTypeAliasCannotReferenceItself_mixin(ClassTypeAlias node) {
20904 ClassElement element = node.element; 20911 ClassElement element = node.element;
20905 if (!hasTypedefSelfReference(element)) { 20912 if (!hasTypedefSelfReference(element)) {
20906 return false; 20913 return false;
20907 } 20914 }
20908 _errorReporter.reportError3(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE _ITSELF, node, []); 20915 _errorReporter.reportError2(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE _ITSELF, node, []);
20909 return true; 20916 return true;
20910 } 20917 }
20911 20918
20912 /** 20919 /**
20913 * This verifies that the type arguments in the passed type name are all withi n their bounds. 20920 * This verifies that the type arguments in the passed type name are all withi n their bounds.
20914 * 20921 *
20915 * @param node the [TypeName] to evaluate 20922 * @param node the [TypeName] to evaluate
20916 * @return `true` if and only if an error code is generated on the passed node 20923 * @return `true` if and only if an error code is generated on the passed node
20917 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS 20924 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
20918 */ 20925 */
(...skipping 26 matching lines...) Expand all
20945 Type2 boundType = boundingElts[i].bound; 20952 Type2 boundType = boundingElts[i].bound;
20946 if (argType != null && boundType != null) { 20953 if (argType != null && boundType != null) {
20947 boundType = boundType.substitute2(typeArguments, typeParameters); 20954 boundType = boundType.substitute2(typeArguments, typeParameters);
20948 if (!argType.isSubtypeOf(boundType)) { 20955 if (!argType.isSubtypeOf(boundType)) {
20949 ErrorCode errorCode; 20956 ErrorCode errorCode;
20950 if (isInConstConstructorInvocation(node)) { 20957 if (isInConstConstructorInvocation(node)) {
20951 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 20958 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
20952 } else { 20959 } else {
20953 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 20960 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
20954 } 20961 }
20955 _errorReporter.reportError3(errorCode, argTypeName, [argType.displayNa me, boundType.displayName]); 20962 _errorReporter.reportError2(errorCode, argTypeName, [argType.displayNa me, boundType.displayName]);
20956 foundError = true; 20963 foundError = true;
20957 } 20964 }
20958 } 20965 }
20959 } 20966 }
20960 return foundError; 20967 return foundError;
20961 } 20968 }
20962 20969
20963 /** 20970 /**
20964 * This checks that if the passed type name is a type parameter being used to define a static 20971 * This checks that if the passed type name is a type parameter being used to define a static
20965 * member. 20972 * member.
20966 * 20973 *
20967 * @param node the type name to evaluate 20974 * @param node the type name to evaluate
20968 * @return `true` if and only if an error code is generated on the passed node 20975 * @return `true` if and only if an error code is generated on the passed node
20969 * @see StaticWarningCode#TYPE_PARAMETER_REFERENCED_BY_STATIC 20976 * @see StaticWarningCode#TYPE_PARAMETER_REFERENCED_BY_STATIC
20970 */ 20977 */
20971 bool checkForTypeParameterReferencedByStatic(TypeName node) { 20978 bool checkForTypeParameterReferencedByStatic(TypeName node) {
20972 if (_isInStaticMethod || _isInStaticVariableDeclaration) { 20979 if (_isInStaticMethod || _isInStaticVariableDeclaration) {
20973 Type2 type = node.type; 20980 Type2 type = node.type;
20974 if (type is TypeParameterType) { 20981 if (type is TypeParameterType) {
20975 _errorReporter.reportError3(StaticWarningCode.TYPE_PARAMETER_REFERENCED_ BY_STATIC, node, []); 20982 _errorReporter.reportError2(StaticWarningCode.TYPE_PARAMETER_REFERENCED_ BY_STATIC, node, []);
20976 return true; 20983 return true;
20977 } 20984 }
20978 } 20985 }
20979 return false; 20986 return false;
20980 } 20987 }
20981 20988
20982 /** 20989 /**
20983 * This checks that if the passed type parameter is a supertype of its bound. 20990 * This checks that if the passed type parameter is a supertype of its bound.
20984 * 20991 *
20985 * @param node the type parameter to evaluate 20992 * @param node the type parameter to evaluate
20986 * @return `true` if and only if an error code is generated on the passed node 20993 * @return `true` if and only if an error code is generated on the passed node
20987 * @see StaticTypeWarningCode#TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND 20994 * @see StaticTypeWarningCode#TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND
20988 */ 20995 */
20989 bool checkForTypeParameterSupertypeOfItsBound(TypeParameter node) { 20996 bool checkForTypeParameterSupertypeOfItsBound(TypeParameter node) {
20990 TypeParameterElement element = node.element; 20997 TypeParameterElement element = node.element;
20991 // prepare bound 20998 // prepare bound
20992 Type2 bound = element.bound; 20999 Type2 bound = element.bound;
20993 if (bound == null) { 21000 if (bound == null) {
20994 return false; 21001 return false;
20995 } 21002 }
20996 // OK, type parameter is not supertype of its bound 21003 // OK, type parameter is not supertype of its bound
20997 if (!bound.isMoreSpecificThan(element.type)) { 21004 if (!bound.isMoreSpecificThan(element.type)) {
20998 return false; 21005 return false;
20999 } 21006 }
21000 // report problem 21007 // report problem
21001 _errorReporter.reportError3(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_O F_ITS_BOUND, node, [element.displayName]); 21008 _errorReporter.reportError2(StaticTypeWarningCode.TYPE_PARAMETER_SUPERTYPE_O F_ITS_BOUND, node, [element.displayName]);
21002 return true; 21009 return true;
21003 } 21010 }
21004 21011
21005 /** 21012 /**
21006 * This checks that if the passed generative constructor has neither an explic it super constructor 21013 * This checks that if the passed generative constructor has neither an explic it super constructor
21007 * invocation nor a redirecting constructor invocation, that the superclass ha s a default 21014 * invocation nor a redirecting constructor invocation, that the superclass ha s a default
21008 * generative constructor. 21015 * generative constructor.
21009 * 21016 *
21010 * @param node the constructor declaration to evaluate 21017 * @param node the constructor declaration to evaluate
21011 * @return `true` if and only if an error code is generated on the passed node 21018 * @return `true` if and only if an error code is generated on the passed node
(...skipping 24 matching lines...) Expand all
21036 return false; 21043 return false;
21037 } 21044 }
21038 InterfaceType superType = _enclosingClass.supertype; 21045 InterfaceType superType = _enclosingClass.supertype;
21039 if (superType == null) { 21046 if (superType == null) {
21040 return false; 21047 return false;
21041 } 21048 }
21042 ClassElement superElement = superType.element; 21049 ClassElement superElement = superType.element;
21043 ConstructorElement superUnnamedConstructor = superElement.unnamedConstructor ; 21050 ConstructorElement superUnnamedConstructor = superElement.unnamedConstructor ;
21044 if (superUnnamedConstructor != null) { 21051 if (superUnnamedConstructor != null) {
21045 if (superUnnamedConstructor.isFactory) { 21052 if (superUnnamedConstructor.isFactory) {
21046 _errorReporter.reportError3(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC TOR, node.returnType, [superUnnamedConstructor]); 21053 _errorReporter.reportError2(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUC TOR, node.returnType, [superUnnamedConstructor]);
21047 return true; 21054 return true;
21048 } 21055 }
21049 if (!superUnnamedConstructor.isDefaultConstructor) { 21056 if (!superUnnamedConstructor.isDefaultConstructor) {
21050 int offset; 21057 int offset;
21051 int length; 21058 int length;
21052 { 21059 {
21053 Identifier returnType = node.returnType; 21060 Identifier returnType = node.returnType;
21054 SimpleIdentifier name = node.name; 21061 SimpleIdentifier name = node.name;
21055 offset = returnType.offset; 21062 offset = returnType.offset;
21056 length = (name != null ? name.end : returnType.end) - offset; 21063 length = (name != null ? name.end : returnType.end) - offset;
21057 } 21064 }
21058 _errorReporter.reportError5(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTR UCTOR_EXPLICIT, offset, length, [superType.displayName]); 21065 _errorReporter.reportError4(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTR UCTOR_EXPLICIT, offset, length, [superType.displayName]);
21059 } 21066 }
21060 return false; 21067 return false;
21061 } 21068 }
21062 _errorReporter.reportError3(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN ITIALIZER_DEFAULT, node.returnType, [superElement.name]); 21069 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN ITIALIZER_DEFAULT, node.returnType, [superElement.name]);
21063 return true; 21070 return true;
21064 } 21071 }
21065 21072
21066 /** 21073 /**
21067 * This checks that if the given name is a reference to a static member it is defined in the 21074 * This checks that if the given name is a reference to a static member it is defined in the
21068 * enclosing class rather than in a superclass. 21075 * enclosing class rather than in a superclass.
21069 * 21076 *
21070 * @param name the name to be evaluated 21077 * @param name the name to be evaluated
21071 * @return `true` if and only if an error code is generated on the passed node 21078 * @return `true` if and only if an error code is generated on the passed node
21072 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER 21079 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
21073 */ 21080 */
21074 bool checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name) { 21081 bool checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name) {
21075 Element element = name.staticElement; 21082 Element element = name.staticElement;
21076 if (element == null || element is TypeParameterElement) { 21083 if (element == null || element is TypeParameterElement) {
21077 return false; 21084 return false;
21078 } 21085 }
21079 Element enclosingElement = element.enclosingElement; 21086 Element enclosingElement = element.enclosingElement;
21080 if (enclosingElement is! ClassElement) { 21087 if (enclosingElement is! ClassElement) {
21081 return false; 21088 return false;
21082 } 21089 }
21083 if ((element is MethodElement && !element.isStatic) || (element is PropertyA ccessorElement && !element.isStatic)) { 21090 if ((element is MethodElement && !element.isStatic) || (element is PropertyA ccessorElement && !element.isStatic)) {
21084 return false; 21091 return false;
21085 } 21092 }
21086 if (identical(enclosingElement, _enclosingClass)) { 21093 if (identical(enclosingElement, _enclosingClass)) {
21087 return false; 21094 return false;
21088 } 21095 }
21089 _errorReporter.reportError3(StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_N ON_LOCAL_STATIC_MEMBER, name, [name.name]); 21096 _errorReporter.reportError2(StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_N ON_LOCAL_STATIC_MEMBER, name, [name.name]);
21090 return true; 21097 return true;
21091 } 21098 }
21092 21099
21093 void checkForValidField(FieldFormalParameter node) { 21100 void checkForValidField(FieldFormalParameter node) {
21094 ParameterElement element = node.element; 21101 ParameterElement element = node.element;
21095 if (element is FieldFormalParameterElement) { 21102 if (element is FieldFormalParameterElement) {
21096 FieldElement fieldElement = element.field; 21103 FieldElement fieldElement = element.field;
21097 if (fieldElement == null || fieldElement.isSynthetic) { 21104 if (fieldElement == null || fieldElement.isSynthetic) {
21098 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR _NON_EXISTANT_FIELD, node, [node.identifier.name]); 21105 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR _NON_EXISTANT_FIELD, node, [node.identifier.name]);
21099 } else { 21106 } else {
21100 ParameterElement parameterElement = node.element; 21107 ParameterElement parameterElement = node.element;
21101 if (parameterElement is FieldFormalParameterElementImpl) { 21108 if (parameterElement is FieldFormalParameterElementImpl) {
21102 FieldFormalParameterElementImpl fieldFormal = parameterElement; 21109 FieldFormalParameterElementImpl fieldFormal = parameterElement;
21103 Type2 declaredType = fieldFormal.type; 21110 Type2 declaredType = fieldFormal.type;
21104 Type2 fieldType = fieldElement.type; 21111 Type2 fieldType = fieldElement.type;
21105 if (fieldElement.isSynthetic) { 21112 if (fieldElement.isSynthetic) {
21106 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_NON_EXISTANT_FIELD, node, [node.identifier.name]); 21113 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_NON_EXISTANT_FIELD, node, [node.identifier.name]);
21107 } else if (fieldElement.isStatic) { 21114 } else if (fieldElement.isStatic) {
21108 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_STATIC_FIELD, node, [node.identifier.name]); 21115 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_STATIC_FIELD, node, [node.identifier.name]);
21109 } else if (declaredType != null && fieldType != null && !declaredType. isAssignableTo(fieldType)) { 21116 } else if (declaredType != null && fieldType != null && !declaredType. isAssignableTo(fieldType)) {
21110 _errorReporter.reportError3(StaticWarningCode.FIELD_INITIALIZING_FOR MAL_NOT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]); 21117 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZING_FOR MAL_NOT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]);
21111 } 21118 }
21112 } else { 21119 } else {
21113 if (fieldElement.isSynthetic) { 21120 if (fieldElement.isSynthetic) {
21114 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_NON_EXISTANT_FIELD, node, [node.identifier.name]); 21121 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_NON_EXISTANT_FIELD, node, [node.identifier.name]);
21115 } else if (fieldElement.isStatic) { 21122 } else if (fieldElement.isStatic) {
21116 _errorReporter.reportError3(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_STATIC_FIELD, node, [node.identifier.name]); 21123 _errorReporter.reportError2(CompileTimeErrorCode.INITIALIZING_FORMAL _FOR_STATIC_FIELD, node, [node.identifier.name]);
21117 } 21124 }
21118 } 21125 }
21119 } 21126 }
21120 } 21127 }
21121 } 21128 }
21122 21129
21123 /** 21130 /**
21124 * This verifies the passed operator-method declaration, has correct number of parameters. 21131 * This verifies the passed operator-method declaration, has correct number of parameters.
21125 * 21132 *
21126 * This method assumes that the method declaration was tested to be an operato r declaration before 21133 * This method assumes that the method declaration was tested to be an operato r declaration before
(...skipping 19 matching lines...) Expand all
21146 // check for exact number of parameters 21153 // check for exact number of parameters
21147 int expected = -1; 21154 int expected = -1;
21148 if ("[]=" == name) { 21155 if ("[]=" == name) {
21149 expected = 2; 21156 expected = 2;
21150 } else if ("<" == name || ">" == name || "<=" == name || ">=" == name || "== " == name || "+" == name || "/" == name || "~/" == name || "*" == name || "%" == name || "|" == name || "^" == name || "&" == name || "<<" == name || ">>" == na me || "[]" == name) { 21157 } else if ("<" == name || ">" == name || "<=" == name || ">=" == name || "== " == name || "+" == name || "/" == name || "~/" == name || "*" == name || "%" == name || "|" == name || "^" == name || "&" == name || "<<" == name || ">>" == na me || "[]" == name) {
21151 expected = 1; 21158 expected = 1;
21152 } else if ("~" == name) { 21159 } else if ("~" == name) {
21153 expected = 0; 21160 expected = 0;
21154 } 21161 }
21155 if (expected != -1 && numParameters != expected) { 21162 if (expected != -1 && numParameters != expected) {
21156 _errorReporter.reportError3(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER S_FOR_OPERATOR, nameNode, [name, expected, numParameters]); 21163 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER S_FOR_OPERATOR, nameNode, [name, expected, numParameters]);
21157 return true; 21164 return true;
21158 } 21165 }
21159 // check for operator "-" 21166 // check for operator "-"
21160 if ("-" == name && numParameters > 1) { 21167 if ("-" == name && numParameters > 1) {
21161 _errorReporter.reportError3(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER S_FOR_OPERATOR_MINUS, nameNode, [numParameters]); 21168 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER S_FOR_OPERATOR_MINUS, nameNode, [numParameters]);
21162 return true; 21169 return true;
21163 } 21170 }
21164 // OK 21171 // OK
21165 return false; 21172 return false;
21166 } 21173 }
21167 21174
21168 /** 21175 /**
21169 * This verifies if the passed setter parameter list have only one required pa rameter. 21176 * This verifies if the passed setter parameter list have only one required pa rameter.
21170 * 21177 *
21171 * This method assumes that the method declaration was tested to be a setter b efore being called. 21178 * This method assumes that the method declaration was tested to be a setter b efore being called.
21172 * 21179 *
21173 * @param setterName the name of the setter to report problems on 21180 * @param setterName the name of the setter to report problems on
21174 * @param parameterList the parameter list to evaluate 21181 * @param parameterList the parameter list to evaluate
21175 * @return `true` if and only if an error code is generated on the passed node 21182 * @return `true` if and only if an error code is generated on the passed node
21176 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER 21183 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
21177 */ 21184 */
21178 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For malParameterList parameterList) { 21185 bool checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, For malParameterList parameterList) {
21179 if (setterName == null) { 21186 if (setterName == null) {
21180 return false; 21187 return false;
21181 } 21188 }
21182 if (parameterList == null) { 21189 if (parameterList == null) {
21183 return false; 21190 return false;
21184 } 21191 }
21185 NodeList<FormalParameter> parameters = parameterList.parameters; 21192 NodeList<FormalParameter> parameters = parameterList.parameters;
21186 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED) { 21193 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED) {
21187 _errorReporter.reportError3(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER S_FOR_SETTER, setterName, []); 21194 _errorReporter.reportError2(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETER S_FOR_SETTER, setterName, []);
21188 return true; 21195 return true;
21189 } 21196 }
21190 return false; 21197 return false;
21191 } 21198 }
21192 21199
21193 /** 21200 /**
21194 * This verifies that if the given class declaration implements the class Func tion that it has a 21201 * This verifies that if the given class declaration implements the class Func tion that it has a
21195 * concrete implementation of the call method. 21202 * concrete implementation of the call method.
21196 * 21203 *
21197 * @return `true` if and only if an error code is generated on the passed node 21204 * @return `true` if and only if an error code is generated on the passed node
21198 * @see StaticWarningCode#FUNCTION_WITHOUT_CALL 21205 * @see StaticWarningCode#FUNCTION_WITHOUT_CALL
21199 */ 21206 */
21200 bool checkImplementsFunctionWithoutCall(ClassDeclaration node) { 21207 bool checkImplementsFunctionWithoutCall(ClassDeclaration node) {
21201 if (node.abstractKeyword != null) { 21208 if (node.abstractKeyword != null) {
21202 return false; 21209 return false;
21203 } 21210 }
21204 ClassElement classElement = node.element; 21211 ClassElement classElement = node.element;
21205 if (classElement == null) { 21212 if (classElement == null) {
21206 return false; 21213 return false;
21207 } 21214 }
21208 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { 21215 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) {
21209 return false; 21216 return false;
21210 } 21217 }
21211 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call"); 21218 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call");
21212 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) { 21219 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) {
21213 _errorReporter.reportError3(StaticWarningCode.FUNCTION_WITHOUT_CALL, node. name, []); 21220 _errorReporter.reportError2(StaticWarningCode.FUNCTION_WITHOUT_CALL, node. name, []);
21214 return true; 21221 return true;
21215 } 21222 }
21216 return false; 21223 return false;
21217 } 21224 }
21218 21225
21219 /** 21226 /**
21220 * This verifies that the given class declaration does not have the same class in the 'extends' 21227 * This verifies that the given class declaration does not have the same class in the 'extends'
21221 * and 'implements' clauses. 21228 * and 'implements' clauses.
21222 * 21229 *
21223 * @return `true` if and only if an error code is generated on the passed node 21230 * @return `true` if and only if an error code is generated on the passed node
21224 * @see CompileTimeErrorCode#IMPLEMENTS_SUPER_CLASS 21231 * @see CompileTimeErrorCode#IMPLEMENTS_SUPER_CLASS
21225 */ 21232 */
21226 bool checkImplementsSuperClass(ClassDeclaration node) { 21233 bool checkImplementsSuperClass(ClassDeclaration node) {
21227 // prepare super type 21234 // prepare super type
21228 InterfaceType superType = _enclosingClass.supertype; 21235 InterfaceType superType = _enclosingClass.supertype;
21229 if (superType == null) { 21236 if (superType == null) {
21230 return false; 21237 return false;
21231 } 21238 }
21232 // prepare interfaces 21239 // prepare interfaces
21233 ImplementsClause implementsClause = node.implementsClause; 21240 ImplementsClause implementsClause = node.implementsClause;
21234 if (implementsClause == null) { 21241 if (implementsClause == null) {
21235 return false; 21242 return false;
21236 } 21243 }
21237 // check interfaces 21244 // check interfaces
21238 bool hasProblem = false; 21245 bool hasProblem = false;
21239 for (TypeName interfaceNode in implementsClause.interfaces) { 21246 for (TypeName interfaceNode in implementsClause.interfaces) {
21240 if (interfaceNode.type == superType) { 21247 if (interfaceNode.type == superType) {
21241 hasProblem = true; 21248 hasProblem = true;
21242 _errorReporter.reportError3(CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, interfaceNode, [superType.displayName]); 21249 _errorReporter.reportError2(CompileTimeErrorCode.IMPLEMENTS_SUPER_CLASS, interfaceNode, [superType.displayName]);
21243 } 21250 }
21244 } 21251 }
21245 // done 21252 // done
21246 return hasProblem; 21253 return hasProblem;
21247 } 21254 }
21248 21255
21249 /** 21256 /**
21250 * Return a display name for the given type that includes the path to the comp ilation unit in 21257 * Return a display name for the given type that includes the path to the comp ilation unit in
21251 * which the type is defined. 21258 * which the type is defined.
21252 * 21259 *
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
21417 return callMethod != null; 21424 return callMethod != null;
21418 } 21425 }
21419 return false; 21426 return false;
21420 } 21427 }
21421 21428
21422 /** 21429 /**
21423 * @return `true` if the given [AstNode] is the part of constant constructor 21430 * @return `true` if the given [AstNode] is the part of constant constructor
21424 * invocation. 21431 * invocation.
21425 */ 21432 */
21426 bool isInConstConstructorInvocation(AstNode node) { 21433 bool isInConstConstructorInvocation(AstNode node) {
21427 InstanceCreationExpression creation = node.getAncestor(InstanceCreationExpre ssion); 21434 InstanceCreationExpression creation = node.getAncestor((node) => node is Ins tanceCreationExpression);
21428 if (creation == null) { 21435 if (creation == null) {
21429 return false; 21436 return false;
21430 } 21437 }
21431 return creation.isConst; 21438 return creation.isConst;
21432 } 21439 }
21433 21440
21434 /** 21441 /**
21435 * Return `true` iff the passed [ClassElement] has a method, getter or setter that 21442 * Return `true` iff the passed [ClassElement] has a method, getter or setter that
21436 * matches the name of the passed [ExecutableElement] in either the class itse lf, or one of 21443 * matches the name of the passed [ExecutableElement] in either the class itse lf, or one of
21437 * its' mixins. 21444 * its' mixins.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
21530 if (parent is CommentReference) { 21537 if (parent is CommentReference) {
21531 CommentReference commentReference = parent; 21538 CommentReference commentReference = parent;
21532 if (commentReference.newKeyword != null) { 21539 if (commentReference.newKeyword != null) {
21533 return true; 21540 return true;
21534 } 21541 }
21535 } 21542 }
21536 return false; 21543 return false;
21537 } 21544 }
21538 21545
21539 bool isUserDefinedObject(EvaluationResultImpl result) => result == null || (re sult is ValidResult && result.isUserDefinedObject); 21546 bool isUserDefinedObject(EvaluationResultImpl result) => result == null || (re sult is ValidResult && result.isUserDefinedObject);
21547
21548 /**
21549 * This checks the class declaration is not a superinterface to itself.
21550 *
21551 * @param classElt the class element to test
21552 * @param path a list containing the potentially cyclic implements path
21553 * @return `true` if and only if an error code is generated on the passed elem ent
21554 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE
21555 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS
21556 * @see CompileTimeErrorCode#RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEME NTS
21557 */
21558 bool safeCheckForRecursiveInterfaceInheritance(ClassElement classElt, List<Cla ssElement> path) {
21559 // Detect error condition.
21560 int size = path.length;
21561 // If this is not the base case (size > 0), and the enclosing class is the p assed class
21562 // element then an error an error.
21563 if (size > 0 && _enclosingClass == classElt) {
21564 String enclosingClassName = _enclosingClass.displayName;
21565 if (size > 1) {
21566 // Construct a string showing the cyclic implements path: "A, B, C, D, A "
21567 String separator = ", ";
21568 JavaStringBuilder builder = new JavaStringBuilder();
21569 for (int i = 0; i < size; i++) {
21570 builder.append(path[i].displayName);
21571 builder.append(separator);
21572 }
21573 builder.append(classElt.displayName);
21574 _errorReporter.reportError4(CompileTimeErrorCode.RECURSIVE_INTERFACE_INH ERITANCE, _enclosingClass.nameOffset, enclosingClassName.length, [enclosingClass Name, builder.toString()]);
21575 return true;
21576 } else {
21577 // RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS or RECURSIVE_INT ERFACE_INHERITANCE_BASE_CASE_EXTENDS
21578 InterfaceType supertype = classElt.supertype;
21579 ErrorCode errorCode = (supertype != null && _enclosingClass == supertype .element ? CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTEND S : CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS);
21580 _errorReporter.reportError4(errorCode, _enclosingClass.nameOffset, enclo singClassName.length, [enclosingClassName]);
21581 return true;
21582 }
21583 }
21584 if (path.indexOf(classElt) > 0) {
21585 return false;
21586 }
21587 path.add(classElt);
21588 // n-case
21589 InterfaceType supertype = classElt.supertype;
21590 if (supertype != null && safeCheckForRecursiveInterfaceInheritance(supertype .element, path)) {
21591 return true;
21592 }
21593 List<InterfaceType> interfaceTypes = classElt.interfaces;
21594 for (InterfaceType interfaceType in interfaceTypes) {
21595 if (safeCheckForRecursiveInterfaceInheritance(interfaceType.element, path) ) {
21596 return true;
21597 }
21598 }
21599 path.removeAt(path.length - 1);
21600 return false;
21601 }
21540 } 21602 }
21541 21603
21542 /** 21604 /**
21543 * This enum holds one of four states of a field initialization state through a constructor 21605 * This enum holds one of four states of a field initialization state through a constructor
21544 * signature, not initialized, initialized in the field declaration, initialized in the field 21606 * signature, not initialized, initialized in the field declaration, initialized in the field
21545 * formal, and finally, initialized in the initializers list. 21607 * formal, and finally, initialized in the initializers list.
21546 */ 21608 */
21547 class INIT_STATE extends Enum<INIT_STATE> { 21609 class INIT_STATE extends Enum<INIT_STATE> {
21548 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); 21610 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0);
21549 21611
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
21683 * @param correction the template used to create the correction to be displaye d for the error 21745 * @param correction the template used to create the correction to be displaye d for the error
21684 */ 21746 */
21685 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri ng correction) : super(name, ordinal) { 21747 ResolverErrorCode.con2(String name, int ordinal, this.type, this.message, Stri ng correction) : super(name, ordinal) {
21686 this.correction9 = correction; 21748 this.correction9 = correction;
21687 } 21749 }
21688 21750
21689 String get correction => correction9; 21751 String get correction => correction9;
21690 21752
21691 ErrorSeverity get errorSeverity => type.severity; 21753 ErrorSeverity get errorSeverity => type.severity;
21692 } 21754 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/source_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698