| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.incremental_resolver; | 5 library engine.incremental_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/error_verifier.dart'; | 10 import 'package:analyzer/src/generated/error_verifier.dart'; |
| 11 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 11 | 12 |
| 12 import 'ast.dart'; | 13 import 'ast.dart'; |
| 13 import 'element.dart'; | 14 import 'element.dart'; |
| 14 import 'engine.dart'; | 15 import 'engine.dart'; |
| 15 import 'error.dart'; | 16 import 'error.dart'; |
| 16 import 'java_engine.dart'; | 17 import 'java_engine.dart'; |
| 17 import 'parser.dart'; | 18 import 'parser.dart'; |
| 18 import 'resolver.dart'; | 19 import 'resolver.dart'; |
| 19 import 'scanner.dart'; | 20 import 'scanner.dart'; |
| 20 import 'source.dart'; | 21 import 'source.dart'; |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 _assertTrue(hideNames.remove(name)); | 375 _assertTrue(hideNames.remove(name)); |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 } | 378 } |
| 378 _assertTrue(showNames.isEmpty); | 379 _assertTrue(showNames.isEmpty); |
| 379 _assertTrue(hideNames.isEmpty); | 380 _assertTrue(hideNames.isEmpty); |
| 380 } | 381 } |
| 381 | 382 |
| 382 void _assertCompatibleParameter(FormalParameter node, | 383 void _assertCompatibleParameter(FormalParameter node, |
| 383 ParameterElement element) { | 384 ParameterElement element) { |
| 385 _assertEquals(node.kind, element.parameterKind); |
| 386 if (node.kind == ParameterKind.NAMED) { |
| 387 _assertEquals(node.identifier.name, element.name); |
| 388 } |
| 389 // check parameter type specific properties |
| 384 if (node is DefaultFormalParameter) { | 390 if (node is DefaultFormalParameter) { |
| 385 _assertTrue(element.isInitializingFormal); | 391 Expression nodeDefault = node.defaultValue; |
| 386 // TODO(scheglov) check default value | 392 if (nodeDefault == null) { |
| 393 _assertNull(element.defaultValueCode); |
| 394 } else { |
| 395 _assertEquals(nodeDefault.toSource(), element.defaultValueCode); |
| 396 } |
| 387 } else if (node is FieldFormalParameter) { | 397 } else if (node is FieldFormalParameter) { |
| 388 _assertTrue(element.isInitializingFormal); | 398 _assertTrue(element.isInitializingFormal); |
| 399 } else if (node is FunctionTypedFormalParameter) { |
| 400 _assertTrue(element.type is FunctionType); |
| 401 FunctionType elementType = element.type; |
| 402 _assertCompatibleParameters(node.parameters, element.parameters); |
| 403 _assertSameType(node.returnType, elementType.returnType); |
| 389 } else if (node is SimpleFormalParameter) { | 404 } else if (node is SimpleFormalParameter) { |
| 390 _assertSameType(node.type, element.type); | 405 _assertSameType(node.type, element.type); |
| 391 node.identifier.staticElement = element; | 406 node.identifier.staticElement = element; |
| 392 (element as ElementImpl).nameOffset = node.identifier.offset; | 407 (element as ElementImpl).nameOffset = node.identifier.offset; |
| 393 (element as ElementImpl).name = node.identifier.name; | 408 (element as ElementImpl).name = node.identifier.name; |
| 394 } else { | |
| 395 // TODO(scheglov) support other parameter types | |
| 396 // print('node: $node element: $element ${element.runtimeType}'); | |
| 397 _assertTrue(false); | |
| 398 } | 409 } |
| 399 // TODO(scheglov) check names of named parameters | |
| 400 } | 410 } |
| 401 | 411 |
| 402 void _assertCompatibleParameters(FormalParameterList nodes, | 412 void _assertCompatibleParameters(FormalParameterList nodes, |
| 403 List<ParameterElement> elements) { | 413 List<ParameterElement> elements) { |
| 404 if (nodes == null) { | 414 if (nodes == null) { |
| 405 return _assertEquals(elements.length, 0); | 415 return _assertEquals(elements.length, 0); |
| 406 } | 416 } |
| 407 List<FormalParameter> parameters = nodes.parameters; | 417 List<FormalParameter> parameters = nodes.parameters; |
| 408 int length = parameters.length; | 418 int length = parameters.length; |
| 409 _assertEquals(length, elements.length); | 419 _assertEquals(length, elements.length); |
| 410 for (int i = 0; i < length; i++) { | 420 for (int i = 0; i < length; i++) { |
| 411 _assertCompatibleParameter(parameters[i], elements[i]); | 421 _assertCompatibleParameter(parameters[i], elements[i]); |
| 412 } | 422 } |
| 413 } | 423 } |
| 414 | 424 |
| 415 void _assertEquals(Object a, Object b) { | 425 void _assertEquals(Object a, Object b) { |
| 416 if (a != b) { | 426 if (a != b) { |
| 417 throw new _DeclarationMismatchException(); | 427 throw new _DeclarationMismatchException(); |
| 418 } | 428 } |
| 419 } | 429 } |
| 420 | 430 |
| 421 void _assertFalse(bool condition) { | 431 void _assertFalse(bool condition) { |
| 422 if (condition) { | 432 if (condition) { |
| 423 throw new _DeclarationMismatchException(); | 433 throw new _DeclarationMismatchException(); |
| 424 } | 434 } |
| 425 } | 435 } |
| 426 | 436 |
| 427 void _assertNotNull(Element element) { | 437 void _assertNotNull(Object object) { |
| 428 if (element == null) { | 438 if (object == null) { |
| 429 throw new _DeclarationMismatchException(); | 439 throw new _DeclarationMismatchException(); |
| 430 } | 440 } |
| 431 } | 441 } |
| 432 | 442 |
| 433 void _assertNull(Element element) { | 443 void _assertNull(Object object) { |
| 434 if (element != null) { | 444 if (object != null) { |
| 435 throw new _DeclarationMismatchException(); | 445 throw new _DeclarationMismatchException(); |
| 436 } | 446 } |
| 437 } | 447 } |
| 438 | 448 |
| 439 void _assertSameType(TypeName node, DartType type) { | 449 void _assertSameType(TypeName node, DartType type) { |
| 440 // no return type == dynamic | 450 // no return type == dynamic |
| 441 if (node == null) { | 451 if (node == null) { |
| 442 return _assertTrue(type == null || type.isDynamic); | 452 return _assertTrue(type == null || type.isDynamic); |
| 443 } | 453 } |
| 444 if (type == null) { | 454 if (type == null) { |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 _elements[node] = node.staticElement; | 1437 _elements[node] = node.staticElement; |
| 1428 } | 1438 } |
| 1429 } | 1439 } |
| 1430 | 1440 |
| 1431 | 1441 |
| 1432 class _TokenPair { | 1442 class _TokenPair { |
| 1433 final Token oldToken; | 1443 final Token oldToken; |
| 1434 final Token newToken; | 1444 final Token newToken; |
| 1435 _TokenPair(this.oldToken, this.newToken); | 1445 _TokenPair(this.oldToken, this.newToken); |
| 1436 } | 1446 } |
| OLD | NEW |