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

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

Issue 267293006: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.resolver; 8 library engine.resolver;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 * The type representing the type 'num'. 1347 * The type representing the type 'num'.
1348 */ 1348 */
1349 InterfaceType _numType; 1349 InterfaceType _numType;
1350 1350
1351 /** 1351 /**
1352 * The type representing the type 'string'. 1352 * The type representing the type 'string'.
1353 */ 1353 */
1354 InterfaceType _stringType; 1354 InterfaceType _stringType;
1355 1355
1356 /** 1356 /**
1357 * The current library that is being analyzed.
1358 */
1359 final LibraryElement _currentLibrary;
1360
1361 /**
1357 * Initialize a newly created constant verifier. 1362 * Initialize a newly created constant verifier.
1358 * 1363 *
1359 * @param errorReporter the error reporter by which errors will be reported 1364 * @param errorReporter the error reporter by which errors will be reported
1360 */ 1365 */
1361 ConstantVerifier(this._errorReporter, this._typeProvider) { 1366 ConstantVerifier(this._errorReporter, this._currentLibrary, this._typeProvider ) {
1362 this._boolType = _typeProvider.boolType; 1367 this._boolType = _typeProvider.boolType;
1363 this._intType = _typeProvider.intType; 1368 this._intType = _typeProvider.intType;
1364 this._numType = _typeProvider.numType; 1369 this._numType = _typeProvider.numType;
1365 this._stringType = _typeProvider.stringType; 1370 this._stringType = _typeProvider.stringType;
1366 } 1371 }
1367 1372
1368 @override 1373 @override
1369 Object visitAnnotation(Annotation node) { 1374 Object visitAnnotation(Annotation node) {
1370 super.visitAnnotation(node); 1375 super.visitAnnotation(node);
1371 // check annotation creation 1376 // check annotation creation
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 @override 1413 @override
1409 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 1414 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
1410 _validateInstanceCreationArguments(node); 1415 _validateInstanceCreationArguments(node);
1411 return super.visitInstanceCreationExpression(node); 1416 return super.visitInstanceCreationExpression(node);
1412 } 1417 }
1413 1418
1414 @override 1419 @override
1415 Object visitListLiteral(ListLiteral node) { 1420 Object visitListLiteral(ListLiteral node) {
1416 super.visitListLiteral(node); 1421 super.visitListLiteral(node);
1417 if (node.constKeyword != null) { 1422 if (node.constKeyword != null) {
1423 EvaluationResultImpl result;
1418 for (Expression element in node.elements) { 1424 for (Expression element in node.elements) {
1419 _validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); 1425 result = _validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEME NT);
1426 if (result is ValidResult) {
1427 _reportErrorIfFromDeferredLibrary(element, CompileTimeErrorCode.NON_CO NSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY);
1428 }
1420 } 1429 }
1421 } 1430 }
1422 return null; 1431 return null;
1423 } 1432 }
1424 1433
1425 @override 1434 @override
1426 Object visitMapLiteral(MapLiteral node) { 1435 Object visitMapLiteral(MapLiteral node) {
1427 super.visitMapLiteral(node); 1436 super.visitMapLiteral(node);
1428 bool isConst = node.constKeyword != null; 1437 bool isConst = node.constKeyword != null;
1429 bool reportEqualKeys = true; 1438 bool reportEqualKeys = true;
1430 Set<DartObject> keys = new Set<DartObject>(); 1439 Set<DartObject> keys = new Set<DartObject>();
1431 List<Expression> invalidKeys = new List<Expression>(); 1440 List<Expression> invalidKeys = new List<Expression>();
1432 for (MapLiteralEntry entry in node.entries) { 1441 for (MapLiteralEntry entry in node.entries) {
1433 Expression key = entry.key; 1442 Expression key = entry.key;
1434 if (isConst) { 1443 if (isConst) {
1435 EvaluationResultImpl result = _validate(key, CompileTimeErrorCode.NON_CO NSTANT_MAP_KEY); 1444 EvaluationResultImpl keyResult = _validate(key, CompileTimeErrorCode.NON _CONSTANT_MAP_KEY);
1436 _validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); 1445 Expression valueExpression = entry.value;
1437 if (result is ValidResult) { 1446 EvaluationResultImpl valueResult = _validate(valueExpression, CompileTim eErrorCode.NON_CONSTANT_MAP_VALUE);
1438 DartObject value = result.value; 1447 if (valueResult is ValidResult) {
1448 _reportErrorIfFromDeferredLibrary(valueExpression, CompileTimeErrorCod e.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY);
1449 }
1450 if (keyResult is ValidResult) {
1451 _reportErrorIfFromDeferredLibrary(key, CompileTimeErrorCode.NON_CONSTA NT_MAP_KEY_FROM_DEFERRED_LIBRARY);
1452 DartObject value = keyResult.value;
1439 if (keys.contains(value)) { 1453 if (keys.contains(value)) {
1440 invalidKeys.add(key); 1454 invalidKeys.add(key);
1441 } else { 1455 } else {
1442 keys.add(value); 1456 keys.add(value);
1443 } 1457 }
1458 DartType type = value.type;
1459 if (_implementsEqualsWhenNotAllowed(type)) {
1460 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_MAP_KEY _EXPRESSION_TYPE_IMPLEMENTS_EQUALS, key, [type.displayName]);
1461 }
1444 } 1462 }
1445 } else { 1463 } else {
1446 EvaluationResultImpl result = key.accept(new ConstantVisitor(_typeProvid er)); 1464 EvaluationResultImpl result = key.accept(new ConstantVisitor(_typeProvid er));
1447 if (result is ValidResult) { 1465 if (result is ValidResult) {
1448 DartObject value = result.value; 1466 DartObject value = result.value;
1449 if (keys.contains(value)) { 1467 if (keys.contains(value)) {
1450 invalidKeys.add(key); 1468 invalidKeys.add(key);
1451 } else { 1469 } else {
1452 keys.add(value); 1470 keys.add(value);
1453 } 1471 }
(...skipping 11 matching lines...) Expand all
1465 } 1483 }
1466 1484
1467 @override 1485 @override
1468 Object visitMethodDeclaration(MethodDeclaration node) { 1486 Object visitMethodDeclaration(MethodDeclaration node) {
1469 super.visitMethodDeclaration(node); 1487 super.visitMethodDeclaration(node);
1470 _validateDefaultValues(node.parameters); 1488 _validateDefaultValues(node.parameters);
1471 return null; 1489 return null;
1472 } 1490 }
1473 1491
1474 @override 1492 @override
1475 Object visitSwitchCase(SwitchCase node) { 1493 Object visitSwitchStatement(SwitchStatement node) {
1476 super.visitSwitchCase(node); 1494 // TODO(paulberry): to minimize error messages, it would be nice to
1477 _validate(node.expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION ); 1495 // compare all types with the most popular type rather than the first
1478 return null; 1496 // type.
1497 NodeList<SwitchMember> switchMembers = node.members;
1498 bool foundError = false;
1499 DartType firstType = null;
1500 for (SwitchMember switchMember in switchMembers) {
1501 if (switchMember is SwitchCase) {
1502 SwitchCase switchCase = switchMember;
1503 Expression expression = switchCase.expression;
1504 EvaluationResultImpl caseResult = _validate(expression, CompileTimeError Code.NON_CONSTANT_CASE_EXPRESSION);
1505 if (caseResult is ValidResult) {
1506 _reportErrorIfFromDeferredLibrary(expression, CompileTimeErrorCode.NON _CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY);
1507 DartObject value = caseResult.value;
1508 if (firstType == null) {
1509 firstType = value.type;
1510 } else {
1511 DartType nType = value.type;
1512 if (firstType != nType) {
1513 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INCONSISTEN T_CASE_EXPRESSION_TYPES, expression, [expression.toSource(), firstType.displayNa me]);
1514 foundError = true;
1515 }
1516 }
1517 }
1518 }
1519 }
1520 if (!foundError) {
1521 _checkForCaseExpressionTypeImplementsEquals(node, firstType);
1522 }
1523 return super.visitSwitchStatement(node);
1479 } 1524 }
1480 1525
1481 @override 1526 @override
1482 Object visitVariableDeclaration(VariableDeclaration node) { 1527 Object visitVariableDeclaration(VariableDeclaration node) {
1483 super.visitVariableDeclaration(node); 1528 super.visitVariableDeclaration(node);
1484 Expression initializer = node.initializer; 1529 Expression initializer = node.initializer;
1485 if (initializer != null && node.isConst) { 1530 if (initializer != null && node.isConst) {
1486 VariableElementImpl element = node.element as VariableElementImpl; 1531 VariableElementImpl element = node.element as VariableElementImpl;
1487 EvaluationResultImpl result = element.evaluationResult; 1532 EvaluationResultImpl result = element.evaluationResult;
1488 if (result == null) { 1533 if (result == null) {
1489 // 1534 //
1490 // Normally we don't need to visit const variable declarations because w e have already 1535 // Normally we don't need to visit const variable declarations because w e have already
1491 // computed their values. But if we missed it for some reason, this give s us a second 1536 // computed their values. But if we missed it for some reason, this give s us a second
1492 // chance. 1537 // chance.
1493 // 1538 //
1494 result = _validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_W ITH_NON_CONSTANT_VALUE); 1539 result = _validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_W ITH_NON_CONSTANT_VALUE);
1495 element.evaluationResult = result; 1540 element.evaluationResult = result;
1496 return null; 1541 return null;
1497 } else if (result is ErrorResult) { 1542 } else if (result is ErrorResult) {
1498 _reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CO NSTANT_VALUE); 1543 _reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CO NSTANT_VALUE);
1499 return null; 1544 return null;
1500 } 1545 }
1501 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibraryRe ferenceDetector(); 1546 _reportErrorIfFromDeferredLibrary(initializer, CompileTimeErrorCode.CONST_ INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY);
1502 initializer.accept(referenceDetector);
1503 if (referenceDetector.result) {
1504 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_INITIALIZED _WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY, initializer, []);
1505 return null;
1506 }
1507 } 1547 }
1508 return null; 1548 return null;
1509 } 1549 }
1510 1550
1511 /** 1551 /**
1552 * This verifies that the passed switch statement does not have a case express ion with the
1553 * operator '==' overridden.
1554 *
1555 * @param node the switch statement to evaluate
1556 * @param type the common type of all 'case' expressions
1557 * @return `true` if and only if an error code is generated on the passed node
1558 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
1559 */
1560 bool _checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, DartTyp e type) {
1561 if (!_implementsEqualsWhenNotAllowed(type)) {
1562 return false;
1563 }
1564 // report error
1565 _errorReporter.reportErrorForToken(CompileTimeErrorCode.CASE_EXPRESSION_TYPE _IMPLEMENTS_EQUALS, node.keyword, [type.displayName]);
1566 return true;
1567 }
1568
1569 /**
1570 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
1571 * <i>int</i> or <i>String</i>.
1572 */
1573 bool _implementsEqualsWhenNotAllowed(DartType type) {
1574 // ignore int or String
1575 if (type == null || type == _intType || type == _typeProvider.stringType) {
1576 return false;
1577 } else if (type == _typeProvider.doubleType) {
1578 return true;
1579 }
1580 // prepare ClassElement
1581 Element element = type.element;
1582 if (element is! ClassElement) {
1583 return false;
1584 }
1585 ClassElement classElement = element as ClassElement;
1586 // lookup for ==
1587 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
1588 while (method != null && method.isAbstract) {
1589 ClassElement definingClass = method.enclosingElement;
1590 if (definingClass == null) {
1591 return false;
1592 }
1593 method = definingClass.lookUpInheritedMethod("==", _currentLibrary);
1594 }
1595 if (method == null || method.enclosingElement.type.isObject) {
1596 return false;
1597 }
1598 // there is == that we don't like
1599 return true;
1600 }
1601
1602 /**
1603 * Given some computed [Expression], this method generates the passed [ErrorCo de] on
1604 * the node if its' value consists of information from a deferred library.
1605 *
1606 * @param expression the expression to be tested for a deferred library refere nce
1607 * @param errorCode the error code to be used if the expression is or consists of a reference to a
1608 * deferred library
1609 */
1610 void _reportErrorIfFromDeferredLibrary(Expression expression, ErrorCode errorC ode) {
1611 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibraryRefe renceDetector();
1612 expression.accept(referenceDetector);
1613 if (referenceDetector.result) {
1614 _errorReporter.reportErrorForNode(errorCode, expression, []);
1615 }
1616 }
1617
1618 /**
1512 * If the given result represents one or more errors, report those errors. Exc ept for special 1619 * If the given result represents one or more errors, report those errors. Exc ept for special
1513 * cases, use the given error code rather than the one reported in the error. 1620 * cases, use the given error code rather than the one reported in the error.
1514 * 1621 *
1515 * @param result the result containing any errors that need to be reported 1622 * @param result the result containing any errors that need to be reported
1516 * @param errorCode the error code to be used if the result represents an erro r 1623 * @param errorCode the error code to be used if the result represents an erro r
1517 */ 1624 */
1518 void _reportErrors(EvaluationResultImpl result, ErrorCode errorCode) { 1625 void _reportErrors(EvaluationResultImpl result, ErrorCode errorCode) {
1519 if (result is ErrorResult) { 1626 if (result is ErrorResult) {
1520 for (ErrorResult_ErrorData data in result.errorData) { 1627 for (ErrorResult_ErrorData data in result.errorData) {
1521 ErrorCode dataErrorCode = data.errorCode; 1628 ErrorCode dataErrorCode = data.errorCode;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 return; 1676 return;
1570 } 1677 }
1571 for (FormalParameter parameter in parameters.parameters) { 1678 for (FormalParameter parameter in parameters.parameters) {
1572 if (parameter is DefaultFormalParameter) { 1679 if (parameter is DefaultFormalParameter) {
1573 DefaultFormalParameter defaultParameter = parameter; 1680 DefaultFormalParameter defaultParameter = parameter;
1574 Expression defaultValue = defaultParameter.defaultValue; 1681 Expression defaultValue = defaultParameter.defaultValue;
1575 if (defaultValue != null) { 1682 if (defaultValue != null) {
1576 EvaluationResultImpl result = _validate(defaultValue, CompileTimeError Code.NON_CONSTANT_DEFAULT_VALUE); 1683 EvaluationResultImpl result = _validate(defaultValue, CompileTimeError Code.NON_CONSTANT_DEFAULT_VALUE);
1577 VariableElementImpl element = parameter.element as VariableElementImpl ; 1684 VariableElementImpl element = parameter.element as VariableElementImpl ;
1578 element.evaluationResult = result; 1685 element.evaluationResult = result;
1579 DeferredLibraryReferenceDetector referenceDetector = new DeferredLibra ryReferenceDetector(); 1686 if (result is ValidResult) {
1580 defaultValue.accept(referenceDetector); 1687 _reportErrorIfFromDeferredLibrary(defaultValue, CompileTimeErrorCode .NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LIBRARY);
1581 if (result is ValidResult && referenceDetector.result) {
1582 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONSTANT_ DEFAULT_VALUE_FROM_DEFERRED_LIBRARY, defaultValue, []);
1583 } 1688 }
1584 } 1689 }
1585 } 1690 }
1586 } 1691 }
1587 } 1692 }
1588 1693
1589 /** 1694 /**
1590 * Validates that the given expression is a compile time constant. 1695 * Validates that the given expression is a compile time constant.
1591 * 1696 *
1592 * @param parameterElements the elements of parameters of constant constructor , they are 1697 * @param parameterElements the elements of parameters of constant constructor , they are
1593 * considered as a valid potentially constant expressions 1698 * considered as a valid potentially constant expressions
1594 * @param expression the expression to validate 1699 * @param expression the expression to validate
1595 */ 1700 */
1596 void _validateInitializerExpression(List<ParameterElement> parameterElements, Expression expression) { 1701 void _validateInitializerExpression(List<ParameterElement> parameterElements, Expression expression) {
1597 EvaluationResultImpl result = expression.accept(new ConstantVisitor_Constant Verifier_validateInitializerExpression(_typeProvider, this, parameterElements)); 1702 EvaluationResultImpl result = expression.accept(new ConstantVisitor_Constant Verifier_validateInitializerExpression(_typeProvider, this, parameterElements));
1598 _reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER ); 1703 _reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER );
1704 if (result is ValidResult) {
1705 _reportErrorIfFromDeferredLibrary(expression, CompileTimeErrorCode.NON_CON STANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY);
1706 }
1599 } 1707 }
1600 1708
1601 /** 1709 /**
1602 * Validates that all of the arguments of a constructor initializer are compil e time constants. 1710 * Validates that all of the arguments of a constructor initializer are compil e time constants.
1603 * 1711 *
1604 * @param parameterElements the elements of parameters of constant constructor , they are 1712 * @param parameterElements the elements of parameters of constant constructor , they are
1605 * considered as a valid potentially constant expressions 1713 * considered as a valid potentially constant expressions
1606 * @param argumentList the argument list to validate 1714 * @param argumentList the argument list to validate
1607 */ 1715 */
1608 void _validateInitializerInvocationArguments(List<ParameterElement> parameterE lements, ArgumentList argumentList) { 1716 void _validateInitializerInvocationArguments(List<ParameterElement> parameterE lements, ArgumentList argumentList) {
(...skipping 3893 matching lines...) Expand 10 before | Expand all | Expand 10 after
5502 // 5610 //
5503 FunctionType getterType = element.type; 5611 FunctionType getterType = element.type;
5504 if (getterType != null) { 5612 if (getterType != null) {
5505 DartType getterReturnType = getterType.returnType; 5613 DartType getterReturnType = getterType.returnType;
5506 if (getterReturnType is InterfaceType) { 5614 if (getterReturnType is InterfaceType) {
5507 MethodElement callMethod = getterReturnType.lookUpMethod(FunctionEleme nt.CALL_METHOD_NAME, _definingLibrary); 5615 MethodElement callMethod = getterReturnType.lookUpMethod(FunctionEleme nt.CALL_METHOD_NAME, _definingLibrary);
5508 if (callMethod != null) { 5616 if (callMethod != null) {
5509 return _resolveArgumentsToFunction(false, argumentList, callMethod); 5617 return _resolveArgumentsToFunction(false, argumentList, callMethod);
5510 } 5618 }
5511 } else if (getterReturnType is FunctionType) { 5619 } else if (getterReturnType is FunctionType) {
5512 Element functionElement = getterReturnType.element; 5620 List<ParameterElement> parameters = getterReturnType.parameters;
5513 if (functionElement is ExecutableElement) { 5621 return _resolveArgumentsToParameters(false, argumentList, parameters);
5514 return _resolveArgumentsToFunction(false, argumentList, functionElem ent);
5515 }
5516 } 5622 }
5517 } 5623 }
5518 } else if (element is ExecutableElement) { 5624 } else if (element is ExecutableElement) {
5519 return _resolveArgumentsToFunction(false, argumentList, element); 5625 return _resolveArgumentsToFunction(false, argumentList, element);
5520 } else if (element is VariableElement) { 5626 } else if (element is VariableElement) {
5521 VariableElement variable = element; 5627 VariableElement variable = element;
5522 DartType type = _promoteManager.getStaticType(variable); 5628 DartType type = _promoteManager.getStaticType(variable);
5523 if (type is FunctionType) { 5629 if (type is FunctionType) {
5524 FunctionType functionType = type; 5630 FunctionType functionType = type;
5525 List<ParameterElement> parameters = functionType.parameters; 5631 List<ParameterElement> parameters = functionType.parameters;
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
6655 // 6761 //
6656 ClassElement enclosingClass = _resolver.enclosingClass; 6762 ClassElement enclosingClass = _resolver.enclosingClass;
6657 if (enclosingClass != null) { 6763 if (enclosingClass != null) {
6658 setter = _lookUpSetter(null, enclosingClass.type, node.name); 6764 setter = _lookUpSetter(null, enclosingClass.type, node.name);
6659 } 6765 }
6660 } 6766 }
6661 if (setter != null) { 6767 if (setter != null) {
6662 element = setter; 6768 element = setter;
6663 } 6769 }
6664 } 6770 }
6665 } else if (element == null && node.inSetterContext()) { 6771 } else if (element == null && (node.inSetterContext() || node.parent is Comm entReference)) {
6666 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdentifi er("${node.name}="), _definingLibrary); 6772 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdentifi er("${node.name}="), _definingLibrary);
6667 } 6773 }
6668 ClassElement enclosingClass = _resolver.enclosingClass; 6774 ClassElement enclosingClass = _resolver.enclosingClass;
6669 if (element == null && enclosingClass != null) { 6775 if (element == null && enclosingClass != null) {
6670 InterfaceType enclosingType = enclosingClass.type; 6776 InterfaceType enclosingType = enclosingClass.type;
6671 if (element == null && node.inSetterContext()) { 6777 if (element == null && (node.inSetterContext() || node.parent is CommentRe ference)) {
6672 element = _lookUpSetter(null, enclosingType, node.name); 6778 element = _lookUpSetter(null, enclosingType, node.name);
6673 } 6779 }
6674 if (element == null && node.inGetterContext()) { 6780 if (element == null && node.inGetterContext()) {
6675 element = _lookUpGetter(null, enclosingType, node.name); 6781 element = _lookUpGetter(null, enclosingType, node.name);
6676 } 6782 }
6677 if (element == null) { 6783 if (element == null) {
6678 element = _lookUpMethod(null, enclosingType, node.name); 6784 element = _lookUpMethod(null, enclosingType, node.name);
6679 } 6785 }
6680 } 6786 }
6681 return element; 6787 return element;
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
7579 NodeList<TypeName> arguments = typeArguments.arguments; 7685 NodeList<TypeName> arguments = typeArguments.arguments;
7580 if (arguments.length != 0) { 7686 if (arguments.length != 0) {
7581 if (node.constKeyword != null) { 7687 if (node.constKeyword != null) {
7582 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 7688 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
7583 } 7689 }
7584 } 7690 }
7585 _checkExpectedTwoMapTypeArguments(typeArguments); 7691 _checkExpectedTwoMapTypeArguments(typeArguments);
7586 _checkForMapTypeNotAssignable(node, typeArguments); 7692 _checkForMapTypeNotAssignable(node, typeArguments);
7587 } 7693 }
7588 _checkForNonConstMapAsExpressionStatement(node); 7694 _checkForNonConstMapAsExpressionStatement(node);
7589 _checkForConstMapKeyExpressionTypeImplementsEquals(node);
7590 return super.visitMapLiteral(node); 7695 return super.visitMapLiteral(node);
7591 } 7696 }
7592 7697
7593 @override 7698 @override
7594 Object visitMethodDeclaration(MethodDeclaration node) { 7699 Object visitMethodDeclaration(MethodDeclaration node) {
7595 ExecutableElement previousFunction = _enclosingFunction; 7700 ExecutableElement previousFunction = _enclosingFunction;
7596 try { 7701 try {
7597 _isInStaticMethod = node.isStatic; 7702 _isInStaticMethod = node.isStatic;
7598 _enclosingFunction = node.element; 7703 _enclosingFunction = node.element;
7599 SimpleIdentifier identifier = node.name; 7704 SimpleIdentifier identifier = node.name;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
7745 _isInConstructorInitializer = true; 7850 _isInConstructorInitializer = true;
7746 try { 7851 try {
7747 return super.visitSuperConstructorInvocation(node); 7852 return super.visitSuperConstructorInvocation(node);
7748 } finally { 7853 } finally {
7749 _isInConstructorInitializer = false; 7854 _isInConstructorInitializer = false;
7750 } 7855 }
7751 } 7856 }
7752 7857
7753 @override 7858 @override
7754 Object visitSwitchStatement(SwitchStatement node) { 7859 Object visitSwitchStatement(SwitchStatement node) {
7755 _checkForInconsistentCaseExpressionTypes(node);
7756 _checkForSwitchExpressionNotAssignable(node); 7860 _checkForSwitchExpressionNotAssignable(node);
7757 _checkForCaseBlocksNotTerminated(node); 7861 _checkForCaseBlocksNotTerminated(node);
7758 return super.visitSwitchStatement(node); 7862 return super.visitSwitchStatement(node);
7759 } 7863 }
7760 7864
7761 @override 7865 @override
7762 Object visitThisExpression(ThisExpression node) { 7866 Object visitThisExpression(ThisExpression node) {
7763 _checkForInvalidReferenceToThis(node); 7867 _checkForInvalidReferenceToThis(node);
7764 return super.visitThisExpression(node); 7868 return super.visitThisExpression(node);
7765 } 7869 }
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
8617 if (variable.isConst) { 8721 if (variable.isConst) {
8618 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST, expression, []); 8722 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST, expression, []);
8619 return true; 8723 return true;
8620 } 8724 }
8621 if (variable.isFinal) { 8725 if (variable.isFinal) {
8622 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, highlightedNode, [variable.name]); 8726 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL, highlightedNode, [variable.name]);
8623 return true; 8727 return true;
8624 } 8728 }
8625 return false; 8729 return false;
8626 } 8730 }
8731 if (element is FunctionElement) {
8732 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FUNCTION , expression, []);
8733 return true;
8734 }
8627 if (element is MethodElement) { 8735 if (element is MethodElement) {
8628 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_METHOD, expression, []); 8736 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_METHOD, expression, []);
8629 return true; 8737 return true;
8630 } 8738 }
8631 return false; 8739 return false;
8632 } 8740 }
8633 8741
8634 /** 8742 /**
8635 * This verifies that the passed identifier is not a keyword, and generates th e passed error code 8743 * This verifies that the passed identifier is not a keyword, and generates th e passed error code
8636 * on the identifier if it is a keyword. 8744 * on the identifier if it is a keyword.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
8710 for (int i = 0; i < lastMember; i++) { 8818 for (int i = 0; i < lastMember; i++) {
8711 SwitchMember member = members[i]; 8819 SwitchMember member = members[i];
8712 if (member is SwitchCase) { 8820 if (member is SwitchCase) {
8713 foundError = javaBooleanOr(foundError, _checkForCaseBlockNotTerminated(m ember)); 8821 foundError = javaBooleanOr(foundError, _checkForCaseBlockNotTerminated(m ember));
8714 } 8822 }
8715 } 8823 }
8716 return foundError; 8824 return foundError;
8717 } 8825 }
8718 8826
8719 /** 8827 /**
8720 * This verifies that the passed switch statement does not have a case express ion with the
8721 * operator '==' overridden.
8722 *
8723 * @param node the switch statement to evaluate
8724 * @param type the common type of all 'case' expressions
8725 * @return `true` if and only if an error code is generated on the passed node
8726 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
8727 */
8728 bool _checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, DartTyp e type) {
8729 if (!_implementsEqualsWhenNotAllowed(type)) {
8730 return false;
8731 }
8732 // report error
8733 _errorReporter.reportErrorForToken(CompileTimeErrorCode.CASE_EXPRESSION_TYPE _IMPLEMENTS_EQUALS, node.keyword, [type.displayName]);
8734 return true;
8735 }
8736
8737 /**
8738 * This verifies that the passed method declaration is abstract only if the en closing class is 8828 * This verifies that the passed method declaration is abstract only if the en closing class is
8739 * also abstract. 8829 * also abstract.
8740 * 8830 *
8741 * @param node the method declaration to evaluate 8831 * @param node the method declaration to evaluate
8742 * @return `true` if and only if an error code is generated on the passed node 8832 * @return `true` if and only if an error code is generated on the passed node
8743 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER 8833 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
8744 */ 8834 */
8745 bool _checkForConcreteClassWithAbstractMember(MethodDeclaration node) { 8835 bool _checkForConcreteClassWithAbstractMember(MethodDeclaration node) {
8746 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac t) { 8836 if (node.isAbstract && _enclosingClass != null && !_enclosingClass.isAbstrac t) {
8747 SimpleIdentifier methodName = node.name; 8837 SimpleIdentifier methodName = node.name;
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
9220 */ 9310 */
9221 bool _checkForConstFormalParameter(NormalFormalParameter node) { 9311 bool _checkForConstFormalParameter(NormalFormalParameter node) {
9222 if (node.isConst) { 9312 if (node.isConst) {
9223 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FORMAL_PARAME TER, node, []); 9313 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FORMAL_PARAME TER, node, []);
9224 return true; 9314 return true;
9225 } 9315 }
9226 return false; 9316 return false;
9227 } 9317 }
9228 9318
9229 /** 9319 /**
9230 * This verifies that the all keys of the passed map literal have class type t hat does not declare
9231 * operator <i>==<i>.
9232 *
9233 * @param key the map literal to evaluate
9234 * @return `true` if and only if an error code is generated on the passed node
9235 * @see CompileTimeErrorCode#CONST_MAP_KEY_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
9236 */
9237 bool _checkForConstMapKeyExpressionTypeImplementsEquals(MapLiteral node) {
9238 // OK, not const.
9239 if (node.constKeyword == null) {
9240 return false;
9241 }
9242 // Check every map entry.
9243 bool hasProblems = false;
9244 for (MapLiteralEntry entry in node.entries) {
9245 Expression key = entry.key;
9246 DartType type = key.staticType;
9247 if (_implementsEqualsWhenNotAllowed(type)) {
9248 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_MAP_KEY_EXP RESSION_TYPE_IMPLEMENTS_EQUALS, key, [type.displayName]);
9249 hasProblems = true;
9250 }
9251 }
9252 return hasProblems;
9253 }
9254
9255 /**
9256 * This verifies that the passed instance creation expression is not being inv oked on an abstract 9320 * This verifies that the passed instance creation expression is not being inv oked on an abstract
9257 * class. 9321 * class.
9258 * 9322 *
9259 * @param node the instance creation expression to evaluate 9323 * @param node the instance creation expression to evaluate
9260 * @param typeName the [TypeName] of the [ConstructorName] from the 9324 * @param typeName the [TypeName] of the [ConstructorName] from the
9261 * [InstanceCreationExpression], this is the AST node that the error is attached to 9325 * [InstanceCreationExpression], this is the AST node that the error is attached to
9262 * @param type the type being constructed with this [InstanceCreationExpressio n] 9326 * @param type the type being constructed with this [InstanceCreationExpressio n]
9263 * @return `true` if and only if an error code is generated on the passed node 9327 * @return `true` if and only if an error code is generated on the passed node
9264 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 9328 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS
9265 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 9329 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
10001 } 10065 }
10002 if (!sdkLibrary.isInternal) { 10066 if (!sdkLibrary.isInternal) {
10003 return false; 10067 return false;
10004 } 10068 }
10005 // report problem 10069 // report problem
10006 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRA RY, node, [node.uri]); 10070 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRA RY, node, [node.uri]);
10007 return true; 10071 return true;
10008 } 10072 }
10009 10073
10010 /** 10074 /**
10011 * This verifies that the passed switch statement case expressions all have th e same type.
10012 *
10013 * @param node the switch statement to evaluate
10014 * @return `true` if and only if an error code is generated on the passed node
10015 * @see CompileTimeErrorCode#INCONSISTENT_CASE_EXPRESSION_TYPES
10016 */
10017 bool _checkForInconsistentCaseExpressionTypes(SwitchStatement node) {
10018 // TODO(jwren) Revisit this algorithm, should there up to n-1 errors?
10019 NodeList<SwitchMember> switchMembers = node.members;
10020 bool foundError = false;
10021 DartType firstType = null;
10022 for (SwitchMember switchMember in switchMembers) {
10023 if (switchMember is SwitchCase) {
10024 SwitchCase switchCase = switchMember;
10025 Expression expression = switchCase.expression;
10026 if (firstType == null) {
10027 // TODO(brianwilkerson) This is failing with const variables whose dec lared type is
10028 // dynamic. The problem is that we don't have any way to propagate typ e information for
10029 // the variable.
10030 firstType = expression.bestType;
10031 } else {
10032 DartType nType = expression.bestType;
10033 if (firstType != nType) {
10034 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INCONSISTENT_ CASE_EXPRESSION_TYPES, expression, [expression.toSource(), firstType.displayName ]);
10035 foundError = true;
10036 }
10037 }
10038 }
10039 }
10040 if (!foundError) {
10041 _checkForCaseExpressionTypeImplementsEquals(node, firstType);
10042 }
10043 return foundError;
10044 }
10045
10046 /**
10047 * For each class declaration, this method is called which verifies that all i nherited members are 10075 * For each class declaration, this method is called which verifies that all i nherited members are
10048 * inherited consistently. 10076 * inherited consistently.
10049 * 10077 *
10050 * @return `true` if and only if an error code is generated on the passed node 10078 * @return `true` if and only if an error code is generated on the passed node
10051 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE 10079 * @see StaticTypeWarningCode#INCONSISTENT_METHOD_INHERITANCE
10052 */ 10080 */
10053 bool _checkForInconsistentMethodInheritance() { 10081 bool _checkForInconsistentMethodInheritance() {
10054 // Ensure that the inheritance manager has a chance to generate all errors w e may care about, 10082 // Ensure that the inheritance manager has a chance to generate all errors w e may care about,
10055 // note that we ensure that the interfaces data since there are no errors. 10083 // note that we ensure that the interfaces data since there are no errors.
10056 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass); 10084 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(_enclosingClass);
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
11025 /** 11053 /**
11026 * This checks the passed constructor declaration has a valid combination of r edirected 11054 * This checks the passed constructor declaration has a valid combination of r edirected
11027 * constructor invocation(s), super constructor invocations and field initiali zers. 11055 * constructor invocation(s), super constructor invocations and field initiali zers.
11028 * 11056 *
11029 * @param node the constructor declaration to evaluate 11057 * @param node the constructor declaration to evaluate
11030 * @return `true` if and only if an error code is generated on the passed node 11058 * @return `true` if and only if an error code is generated on the passed node
11031 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR 11059 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
11032 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR 11060 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR
11033 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS 11061 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS
11034 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR 11062 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR
11063 * @see CompileTimeErrorCode#REDIRECT_GENERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR
11035 */ 11064 */
11036 bool _checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { 11065 bool _checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) {
11037 bool errorReported = false; 11066 bool errorReported = false;
11038 // 11067 //
11039 // Check for default values in the parameters 11068 // Check for default values in the parameters
11040 // 11069 //
11041 ConstructorName redirectedConstructor = node.redirectedConstructor; 11070 ConstructorName redirectedConstructor = node.redirectedConstructor;
11042 if (redirectedConstructor != null) { 11071 if (redirectedConstructor != null) {
11043 for (FormalParameter parameter in node.parameters.parameters) { 11072 for (FormalParameter parameter in node.parameters.parameters) {
11044 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul l) { 11073 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul l) {
11045 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I N_REDIRECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []); 11074 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I N_REDIRECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []);
11046 errorReported = true; 11075 errorReported = true;
11047 } 11076 }
11048 } 11077 }
11049 } 11078 }
11050 // check if there are redirected invocations 11079 // check if there are redirected invocations
11051 int numRedirections = 0; 11080 int numRedirections = 0;
11052 for (ConstructorInitializer initializer in node.initializers) { 11081 for (ConstructorInitializer initializer in node.initializers) {
11053 if (initializer is RedirectingConstructorInvocation) { 11082 if (initializer is RedirectingConstructorInvocation) {
11054 if (numRedirections > 0) { 11083 if (numRedirections > 0) {
11055 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_REDIRE CTING_CONSTRUCTOR_INVOCATIONS, initializer, []); 11084 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_REDIRE CTING_CONSTRUCTOR_INVOCATIONS, initializer, []);
11056 errorReported = true; 11085 errorReported = true;
11057 } 11086 }
11087 if (node.factoryKeyword == null) {
11088 RedirectingConstructorInvocation invocation = initializer;
11089 ConstructorElement redirectingElement = invocation.staticElement;
11090 if (redirectingElement == null) {
11091 String enclosingTypeName = _enclosingClass.displayName;
11092 String constructorStrName = enclosingTypeName;
11093 if (invocation.constructorName != null) {
11094 constructorStrName += ".${invocation.constructorName.name}";
11095 }
11096 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_GENE RATIVE_TO_MISSING_CONSTRUCTOR, invocation, [constructorStrName, enclosingTypeNam e]);
11097 } else {
11098 if (redirectingElement.isFactory) {
11099 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_GE NERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR, initializer, []);
11100 }
11101 }
11102 }
11058 numRedirections++; 11103 numRedirections++;
11059 } 11104 }
11060 } 11105 }
11061 // check for other initializers 11106 // check for other initializers
11062 if (numRedirections > 0) { 11107 if (numRedirections > 0) {
11063 for (ConstructorInitializer initializer in node.initializers) { 11108 for (ConstructorInitializer initializer in node.initializers) {
11064 if (initializer is SuperConstructorInvocation) { 11109 if (initializer is SuperConstructorInvocation) {
11065 _errorReporter.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_REDIRE CTING_CONSTRUCTOR, initializer, []); 11110 _errorReporter.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_REDIRE CTING_CONSTRUCTOR, initializer, []);
11066 errorReported = true; 11111 errorReported = true;
11067 } 11112 }
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
11759 if (current != null && !checked.contains(current)) { 11804 if (current != null && !checked.contains(current)) {
11760 break; 11805 break;
11761 } 11806 }
11762 } 11807 }
11763 // check current element 11808 // check current element
11764 current.accept(new GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelf Reference(target, toCheck)); 11809 current.accept(new GeneralizingElementVisitor_ErrorVerifier_hasTypedefSelf Reference(target, toCheck));
11765 checked.add(current); 11810 checked.add(current);
11766 } 11811 }
11767 } 11812 }
11768 11813
11769 /**
11770 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
11771 * <i>int</i> or <i>String</i>.
11772 */
11773 bool _implementsEqualsWhenNotAllowed(DartType type) {
11774 // ignore int or String
11775 if (type == null || type == _intType || type == _typeProvider.stringType) {
11776 return false;
11777 }
11778 // prepare ClassElement
11779 Element element = type.element;
11780 if (element is! ClassElement) {
11781 return false;
11782 }
11783 ClassElement classElement = element as ClassElement;
11784 // lookup for ==
11785 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
11786 if (method == null || method.enclosingElement.type.isObject) {
11787 return false;
11788 }
11789 // there is == that we don't like
11790 return true;
11791 }
11792
11793 bool _isFunctionType(DartType type) { 11814 bool _isFunctionType(DartType type) {
11794 if (type.isDynamic || type.isBottom) { 11815 if (type.isDynamic || type.isBottom) {
11795 return true; 11816 return true;
11796 } else if (type is FunctionType || type.isDartCoreFunction) { 11817 } else if (type is FunctionType || type.isDartCoreFunction) {
11797 return true; 11818 return true;
11798 } else if (type is InterfaceType) { 11819 } else if (type is InterfaceType) {
11799 MethodElement callMethod = type.lookUpMethod(FunctionElement.CALL_METHOD_N AME, _currentLibrary); 11820 MethodElement callMethod = type.lookUpMethod(FunctionElement.CALL_METHOD_N AME, _currentLibrary);
11800 return callMethod != null; 11821 return callMethod != null;
11801 } 11822 }
11802 return false; 11823 return false;
(...skipping 5812 matching lines...) Expand 10 before | Expand all | Expand 10 after
17615 */ 17636 */
17616 StaticTypeAnalyzer _typeAnalyzer; 17637 StaticTypeAnalyzer _typeAnalyzer;
17617 17638
17618 /** 17639 /**
17619 * The class element representing the class containing the current node, or `n ull` if the 17640 * The class element representing the class containing the current node, or `n ull` if the
17620 * current node is not contained in a class. 17641 * current node is not contained in a class.
17621 */ 17642 */
17622 ClassElement _enclosingClass = null; 17643 ClassElement _enclosingClass = null;
17623 17644
17624 /** 17645 /**
17646 * The class declaration representing the class containing the current node, o r `null` if
17647 * the current node is not contained in a class.
17648 */
17649 ClassDeclaration _enclosingClassDeclaration = null;
17650
17651 /**
17625 * The element representing the function containing the current node, or `null ` if the 17652 * The element representing the function containing the current node, or `null ` if the
17626 * current node is not contained in a function. 17653 * current node is not contained in a function.
17627 */ 17654 */
17628 ExecutableElement _enclosingFunction = null; 17655 ExecutableElement _enclosingFunction = null;
17629 17656
17630 /** 17657 /**
17631 * The [Comment] before a [FunctionDeclaration] or a [MethodDeclaration] that 17658 * The [Comment] before a [FunctionDeclaration] or a [MethodDeclaration] that
17632 * cannot be resolved where we visited it, because it should be resolved in th e scope of the body. 17659 * cannot be resolved where we visited it, because it should be resolved in th e scope of the body.
17633 */ 17660 */
17634 Comment _commentBeforeFunction = null; 17661 Comment _commentBeforeFunction = null;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
17709 TypeOverrideManager get overrideManager => _overrideManager; 17736 TypeOverrideManager get overrideManager => _overrideManager;
17710 17737
17711 /** 17738 /**
17712 * Return the object keeping track of which elements have had their types prom oted. 17739 * Return the object keeping track of which elements have had their types prom oted.
17713 * 17740 *
17714 * @return the object keeping track of which elements have had their types pro moted 17741 * @return the object keeping track of which elements have had their types pro moted
17715 */ 17742 */
17716 TypePromotionManager get promoteManager => _promoteManager; 17743 TypePromotionManager get promoteManager => _promoteManager;
17717 17744
17718 @override 17745 @override
17746 Object visitAnnotation(Annotation node) {
17747 if (identical(node.parent, _enclosingClassDeclaration)) {
17748 return null;
17749 }
17750 return super.visitAnnotation(node);
17751 }
17752
17753 @override
17719 Object visitAsExpression(AsExpression node) { 17754 Object visitAsExpression(AsExpression node) {
17720 super.visitAsExpression(node); 17755 super.visitAsExpression(node);
17721 overrideExpression(node.expression, node.type.type); 17756 overrideExpression(node.expression, node.type.type);
17722 return null; 17757 return null;
17723 } 17758 }
17724 17759
17725 @override 17760 @override
17726 Object visitAssertStatement(AssertStatement node) { 17761 Object visitAssertStatement(AssertStatement node) {
17727 super.visitAssertStatement(node); 17762 super.visitAssertStatement(node);
17728 _propagateTrueState(node.condition); 17763 _propagateTrueState(node.condition);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
17793 // 17828 //
17794 // We do not visit the label because it needs to be visited in the context o f the statement. 17829 // We do not visit the label because it needs to be visited in the context o f the statement.
17795 // 17830 //
17796 node.accept(_elementResolver); 17831 node.accept(_elementResolver);
17797 node.accept(_typeAnalyzer); 17832 node.accept(_typeAnalyzer);
17798 return null; 17833 return null;
17799 } 17834 }
17800 17835
17801 @override 17836 @override
17802 Object visitClassDeclaration(ClassDeclaration node) { 17837 Object visitClassDeclaration(ClassDeclaration node) {
17838 // Resolve the class metadata in the library scope.
17839 if (node.metadata != null) {
17840 node.metadata.accept(this);
17841 }
17842 _enclosingClassDeclaration = node;
17843 // Continue the class resolution.
17803 ClassElement outerType = _enclosingClass; 17844 ClassElement outerType = _enclosingClass;
17804 try { 17845 try {
17805 _enclosingClass = node.element; 17846 _enclosingClass = node.element;
17806 _typeAnalyzer.thisType = _enclosingClass == null ? null : _enclosingClass. type; 17847 _typeAnalyzer.thisType = _enclosingClass == null ? null : _enclosingClass. type;
17807 super.visitClassDeclaration(node); 17848 super.visitClassDeclaration(node);
17808 } finally { 17849 } finally {
17809 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; 17850 _typeAnalyzer.thisType = outerType == null ? null : outerType.type;
17810 _enclosingClass = outerType; 17851 _enclosingClass = outerType;
17852 _enclosingClassDeclaration = null;
17811 } 17853 }
17812 return null; 17854 return null;
17813 } 17855 }
17814 17856
17815 @override 17857 @override
17816 Object visitComment(Comment node) { 17858 Object visitComment(Comment node) {
17817 if (node.parent is FunctionDeclaration || node.parent is ConstructorDeclarat ion || node.parent is MethodDeclaration) { 17859 if (node.parent is FunctionDeclaration || node.parent is ConstructorDeclarat ion || node.parent is MethodDeclaration) {
17818 if (!identical(node, _commentBeforeFunction)) { 17860 if (!identical(node, _commentBeforeFunction)) {
17819 _commentBeforeFunction = node; 17861 _commentBeforeFunction = node;
17820 return null; 17862 return null;
(...skipping 5632 matching lines...) Expand 10 before | Expand all | Expand 10 after
23453 parameterImpl.markPotentiallyMutatedInScope(); 23495 parameterImpl.markPotentiallyMutatedInScope();
23454 // If we are in some closure, check if it is not the same as where varia ble is declared. 23496 // If we are in some closure, check if it is not the same as where varia ble is declared.
23455 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) { 23497 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) {
23456 parameterImpl.markPotentiallyMutatedInClosure(); 23498 parameterImpl.markPotentiallyMutatedInClosure();
23457 } 23499 }
23458 } 23500 }
23459 } 23501 }
23460 return null; 23502 return null;
23461 } 23503 }
23462 } 23504 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698