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

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

Issue 14050010: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.resolver; 4 library engine.resolver;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:uri' show Uri;
7 import 'java_core.dart'; 8 import 'java_core.dart';
8 import 'java_engine.dart'; 9 import 'java_engine.dart';
9 import 'instrumentation.dart'; 10 import 'instrumentation.dart';
10 import 'source.dart'; 11 import 'source.dart';
11 import 'error.dart'; 12 import 'error.dart';
12 import 'scanner.dart' as sc; 13 import 'scanner.dart' as sc;
13 import 'utilities_dart.dart'; 14 import 'utilities_dart.dart';
14 import 'ast.dart'; 15 import 'ast.dart';
15 import 'parser.dart' show Parser, ParserErrorCode; 16 import 'parser.dart' show Parser, ParserErrorCode;
16 import 'sdk.dart' show DartSdk; 17 import 'sdk.dart' show DartSdk;
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 if (!isFinal) { 562 if (!isFinal) {
562 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable); 563 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable);
563 setter.setter = true; 564 setter.setter = true;
564 _currentHolder.addAccessor(setter); 565 _currentHolder.addAccessor(setter);
565 variable.setter = setter; 566 variable.setter = setter;
566 } 567 }
567 if (_inFieldContext) { 568 if (_inFieldContext) {
568 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).keyword, sc.Keyword.STATIC); 569 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).keyword, sc.Keyword.STATIC);
569 } 570 }
570 } 571 }
571 return super.visitVariableDeclaration(node); 572 return null;
572 } 573 }
573 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) { 574 List<Type2> createTypeVariableTypes(List<TypeVariableElement> typeVariables) {
574 int typeVariableCount = typeVariables.length; 575 int typeVariableCount = typeVariables.length;
575 List<Type2> typeArguments = new List<Type2>(typeVariableCount); 576 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
576 for (int i = 0; i < typeVariableCount; i++) { 577 for (int i = 0; i < typeVariableCount; i++) {
577 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle mentImpl; 578 TypeVariableElementImpl typeVariable = typeVariables[i] as TypeVariableEle mentImpl;
578 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ; 579 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
579 typeVariable.type = typeArgument; 580 typeVariable.type = typeArgument;
580 typeArguments[i] = typeArgument; 581 typeArguments[i] = typeArgument;
581 } 582 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; 787 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\"";
787 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; 788 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'";
788 static String _SCRIPT = "script"; 789 static String _SCRIPT = "script";
789 static String _SRC = "src"; 790 static String _SRC = "src";
790 static String _TYPE = "type"; 791 static String _TYPE = "type";
791 /** 792 /**
792 * The analysis context in which the element model will be built. 793 * The analysis context in which the element model will be built.
793 */ 794 */
794 InternalAnalysisContext _context; 795 InternalAnalysisContext _context;
795 /** 796 /**
797 * The error listener to which errors will be reported.
798 */
799 AnalysisErrorListener _errorListener;
800 /**
801 * The line information associated with the source for which an element is bei ng built, or{@code null} if we are not building an element.
802 */
803 LineInfo _lineInfo;
804 /**
796 * The HTML element being built. 805 * The HTML element being built.
797 */ 806 */
798 HtmlElementImpl _htmlElement; 807 HtmlElementImpl _htmlElement;
799 /** 808 /**
800 * The script elements being built. 809 * The script elements being built.
801 */ 810 */
802 List<HtmlScriptElement> _scripts; 811 List<HtmlScriptElement> _scripts;
803 /** 812 /**
804 * Initialize a newly created HTML unit builder. 813 * Initialize a newly created HTML unit builder.
805 * @param context the analysis context in which the element model will be buil t 814 * @param context the analysis context in which the element model will be buil t
815 * @param errorListener the error listener to which errors will be reported
806 */ 816 */
807 HtmlUnitBuilder(InternalAnalysisContext context) { 817 HtmlUnitBuilder(InternalAnalysisContext context, AnalysisErrorListener errorLi stener) {
808 this._context = context; 818 this._context = context;
819 this._errorListener = errorListener;
809 } 820 }
810 /** 821 /**
811 * Build the HTML element for the given source. 822 * Build the HTML element for the given source.
812 * @param source the source describing the compilation unit 823 * @param source the source describing the compilation unit
813 * @return the HTML element that was built 824 * @return the HTML element that was built
814 * @throws AnalysisException if the analysis could not be performed 825 * @throws AnalysisException if the analysis could not be performed
815 */ 826 */
816 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _ context.parseHtmlUnit(source)); 827 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _ context.parseHtmlUnit(source));
817 /** 828 /**
818 * Build the HTML element for the given source. 829 * Build the HTML element for the given source.
819 * @param source the source describing the compilation unit 830 * @param source the source describing the compilation unit
820 * @param unit the AST structure representing the HTML 831 * @param unit the AST structure representing the HTML
821 * @throws AnalysisException if the analysis could not be performed 832 * @throws AnalysisException if the analysis could not be performed
822 */ 833 */
823 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) { 834 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) {
835 _lineInfo = _context.computeLineInfo(source2);
824 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName); 836 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName);
825 result.source = source2; 837 result.source = source2;
826 _htmlElement = result; 838 _htmlElement = result;
827 unit.accept(this); 839 unit.accept(this);
828 _htmlElement = null; 840 _htmlElement = null;
829 unit.element = result; 841 unit.element = result;
830 return result; 842 return result;
831 } 843 }
832 Object visitHtmlUnit(ht.HtmlUnit node) { 844 Object visitHtmlUnit(ht.HtmlUnit node) {
833 _scripts = new List<HtmlScriptElement>(); 845 _scripts = new List<HtmlScriptElement>();
834 node.visitChildren(this); 846 node.visitChildren(this);
835 _htmlElement.scripts = new List.from(_scripts); 847 _htmlElement.scripts = new List.from(_scripts);
836 _scripts = null; 848 _scripts = null;
837 return null; 849 return null;
838 } 850 }
839 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null; 851 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null;
840 Object visitXmlTagNode(ht.XmlTagNode node) { 852 Object visitXmlTagNode(ht.XmlTagNode node) {
841 if (isScriptNode(node)) { 853 if (isScriptNode(node)) {
842 Source htmlSource = _htmlElement.source; 854 Source htmlSource = _htmlElement.source;
843 String scriptSourcePath = getScriptSourcePath(node); 855 ht.XmlAttributeNode scriptAttribute = getScriptSourcePath(node);
856 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribute .text;
844 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) { 857 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) {
845 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node); 858 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node);
846 String contents = node.content; 859 String contents = node.content;
847 AnalysisErrorListener errorListener = new AnalysisErrorListener_5(); 860 int attributeEnd2 = node.attributeEnd.end;
848 sc.StringScanner scanner = new sc.StringScanner(null, contents, errorLis tener); 861 LineInfo_Location location = _lineInfo.getLocation(attributeEnd2);
862 sc.StringScanner scanner = new sc.StringScanner(htmlSource, contents, _e rrorListener);
863 scanner.setSourceStart(location.lineNumber, location.columnNumber, attri buteEnd2);
849 sc.Token firstToken = scanner.tokenize(); 864 sc.Token firstToken = scanner.tokenize();
850 List<int> lineStarts2 = scanner.lineStarts; 865 List<int> lineStarts2 = scanner.lineStarts;
851 Parser parser = new Parser(null, errorListener); 866 Parser parser = new Parser(null, _errorListener);
852 CompilationUnit unit = parser.parseCompilationUnit(firstToken); 867 CompilationUnit unit = parser.parseCompilationUnit(firstToken);
868 unit.lineInfo = new LineInfo(lineStarts2);
853 try { 869 try {
854 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 870 CompilationUnitBuilder builder = new CompilationUnitBuilder();
855 CompilationUnitElementImpl elem = builder.buildCompilationUnit(htmlSou rce, unit); 871 CompilationUnitElementImpl elem = builder.buildCompilationUnit(htmlSou rce, unit);
856 LibraryElementImpl library = new LibraryElementImpl(_context, null); 872 LibraryElementImpl library = new LibraryElementImpl(_context, null);
857 library.definingCompilationUnit = elem; 873 library.definingCompilationUnit = elem;
858 script.scriptLibrary = library; 874 script.scriptLibrary = library;
859 } on AnalysisException catch (e) { 875 } on AnalysisException catch (exception) {
860 print(e); 876 print(exception);
861 } 877 }
862 _scripts.add(script); 878 _scripts.add(script);
863 } else { 879 } else {
864 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node); 880 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node);
865 if (scriptSourcePath != null) { 881 if (scriptSourcePath != null) {
866 script.scriptSource = _context.sourceFactory.resolveUri(htmlSource, sc riptSourcePath); 882 try {
883 new Uri(scriptSourcePath);
884 Source scriptSource = _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath);
885 script.scriptSource = scriptSource;
886 if (!scriptSource.exists()) {
887 reportError(HtmlWarningCode.URI_DOES_NOT_EXIST, scriptAttribute.of fset + 1, scriptSourcePath.length, []);
888 }
889 } on URISyntaxException catch (exception) {
890 reportError(HtmlWarningCode.INVALID_URI, scriptAttribute.offset + 1, scriptSourcePath.length, []);
891 }
867 } 892 }
868 _scripts.add(script); 893 _scripts.add(script);
869 } 894 }
870 } else { 895 } else {
871 node.visitChildren(this); 896 node.visitChildren(this);
872 } 897 }
873 return null; 898 return null;
874 } 899 }
875 /** 900 /**
876 * Return the value of the source attribute if it exists. 901 * Return the first source attribute for the given tag node, or {@code null} i f it does not exist.
877 * @param node the node containing attributes 902 * @param node the node containing attributes
878 * @return the source path or {@code null} if not defined 903 * @return the source attribute contained in the given tag
879 */ 904 */
880 String getScriptSourcePath(ht.XmlTagNode node) { 905 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) {
881 for (ht.XmlAttributeNode attribute in node.attributes) { 906 for (ht.XmlAttributeNode attribute in node.attributes) {
882 if (attribute.name.lexeme == _SRC) { 907 if (attribute.name.lexeme == _SRC) {
883 String text2 = attribute.text; 908 return attribute;
884 return text2 != null && text2.length > 0 ? text2 : null;
885 } 909 }
886 } 910 }
887 return null; 911 return null;
888 } 912 }
889 /** 913 /**
890 * Determine if the specified node is a Dart script. 914 * Determine if the specified node is a Dart script.
891 * @param node the node to be tested (not {@code null}) 915 * @param node the node to be tested (not {@code null})
892 * @return {@code true} if the node is a Dart script 916 * @return {@code true} if the node is a Dart script
893 */ 917 */
894 bool isScriptNode(ht.XmlTagNode node) { 918 bool isScriptNode(ht.XmlTagNode node) {
895 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) { 919 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) {
896 return false; 920 return false;
897 } 921 }
898 for (ht.XmlAttributeNode attribute in node.attributes) { 922 for (ht.XmlAttributeNode attribute in node.attributes) {
899 if (attribute.name.lexeme == _TYPE) { 923 if (attribute.name.lexeme == _TYPE) {
900 ht.Token valueToken = attribute.value; 924 ht.Token valueToken = attribute.value;
901 if (valueToken != null) { 925 if (valueToken != null) {
902 String value = valueToken.lexeme; 926 String value = valueToken.lexeme;
903 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI ON_DART_IN_SINGLE_QUOTES) { 927 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI ON_DART_IN_SINGLE_QUOTES) {
904 return true; 928 return true;
905 } 929 }
906 } 930 }
907 } 931 }
908 } 932 }
909 return false; 933 return false;
910 } 934 }
911 } 935 /**
912 class AnalysisErrorListener_5 implements AnalysisErrorListener { 936 * Report an error with the given error code at the given location. Use the gi ven arguments to
913 void onError(AnalysisError error) { 937 * compose the error message.
938 * @param errorCode the error code of the error to be reported
939 * @param offset the offset of the first character to be highlighted
940 * @param length the number of characters to be highlighted
941 * @param arguments the arguments used to compose the error message
942 */
943 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg uments) {
944 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l ength, errorCode, arguments));
914 } 945 }
915 } 946 }
916 /** 947 /**
917 * Instances of the class {@code DeclarationResolver} are used to resolve declar ations in an AST 948 * Instances of the class {@code DeclarationResolver} are used to resolve declar ations in an AST
918 * structure to already built elements. 949 * structure to already built elements.
919 */ 950 */
920 class DeclarationResolver extends RecursiveASTVisitor<Object> { 951 class DeclarationResolver extends RecursiveASTVisitor<Object> {
921 /** 952 /**
922 * The compilation unit containing the AST nodes being visited. 953 * The compilation unit containing the AST nodes being visited.
923 */ 954 */
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 return null; 1524 return null;
1494 } 1525 }
1495 Object visitBreakStatement(BreakStatement node) { 1526 Object visitBreakStatement(BreakStatement node) {
1496 SimpleIdentifier labelNode = node.label; 1527 SimpleIdentifier labelNode = node.label;
1497 LabelElementImpl labelElement = lookupLabel(node, labelNode); 1528 LabelElementImpl labelElement = lookupLabel(node, labelNode);
1498 if (labelElement != null && labelElement.isOnSwitchMember()) { 1529 if (labelElement != null && labelElement.isOnSwitchMember()) {
1499 _resolver.reportError(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labe lNode, []); 1530 _resolver.reportError(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labe lNode, []);
1500 } 1531 }
1501 return null; 1532 return null;
1502 } 1533 }
1534 Object visitCommentReference(CommentReference node) {
1535 Identifier identifier2 = node.identifier;
1536 if (identifier2 is SimpleIdentifier) {
1537 SimpleIdentifier simpleIdentifier = identifier2 as SimpleIdentifier;
1538 visitSimpleIdentifier(simpleIdentifier);
1539 Element element2 = simpleIdentifier.element;
1540 if (element2 != null) {
1541 if (element2.library != _resolver.definingLibrary) {
1542 }
1543 if (node.newKeyword != null) {
1544 if (element2 is ClassElement) {
1545 ConstructorElement constructor = ((element2 as ClassElement)).unname dConstructor;
1546 recordResolution(simpleIdentifier, constructor);
1547 } else {
1548 }
1549 }
1550 }
1551 } else if (identifier2 is PrefixedIdentifier) {
1552 PrefixedIdentifier prefixedIdentifier = identifier2 as PrefixedIdentifier;
1553 SimpleIdentifier prefix2 = prefixedIdentifier.prefix;
1554 SimpleIdentifier name = prefixedIdentifier.identifier;
1555 visitSimpleIdentifier(prefix2);
1556 Element element3 = prefix2.element;
1557 if (element3 != null) {
1558 if (element3 is PrefixElement) {
1559 element3 = _resolver.nameScope.lookup(identifier2, _resolver.definingL ibrary);
1560 recordResolution(name, element3);
1561 return null;
1562 }
1563 if (element3.library != _resolver.definingLibrary) {
1564 }
1565 if (node.newKeyword == null) {
1566 if (element3 is ClassElement) {
1567 Element memberElement = lookupGetterOrMethod(((element3 as ClassElem ent)).type, name.name);
1568 if (memberElement == null) {
1569 memberElement = ((element3 as ClassElement)).getNamedConstructor(n ame.name);
1570 }
1571 if (memberElement == null) {
1572 reportGetterOrSetterNotFound(prefixedIdentifier, name, element3.na me);
1573 } else {
1574 recordResolution(name, memberElement);
1575 }
1576 } else {
1577 }
1578 } else {
1579 if (element3 is ClassElement) {
1580 ConstructorElement constructor = ((element3 as ClassElement)).getNam edConstructor(name.name);
1581 if (constructor != null) {
1582 recordResolution(name, constructor);
1583 }
1584 } else {
1585 }
1586 }
1587 }
1588 }
1589 return null;
1590 }
1503 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 1591 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
1504 FieldElement fieldElement = null; 1592 FieldElement fieldElement = null;
1505 SimpleIdentifier fieldName2 = node.fieldName; 1593 SimpleIdentifier fieldName2 = node.fieldName;
1506 ClassElement enclosingClass2 = _resolver.enclosingClass; 1594 ClassElement enclosingClass2 = _resolver.enclosingClass;
1507 fieldElement = ((enclosingClass2 as ClassElementImpl)).getField(fieldName2.n ame); 1595 fieldElement = ((enclosingClass2 as ClassElementImpl)).getField(fieldName2.n ame);
1508 if (fieldElement == null) { 1596 if (fieldElement == null) {
1509 _resolver.reportError(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_FI ELD, node, [fieldName2]); 1597 _resolver.reportError(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_FI ELD, node, [fieldName2]);
1510 } else if (!fieldElement.isSynthetic()) { 1598 } else if (!fieldElement.isSynthetic()) {
1511 recordResolution(fieldName2, fieldElement); 1599 recordResolution(fieldName2, fieldElement);
1512 if (fieldElement.isStatic()) { 1600 if (fieldElement.isStatic()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 } 1646 }
1559 Object visitFieldFormalParameter(FieldFormalParameter node) { 1647 Object visitFieldFormalParameter(FieldFormalParameter node) {
1560 String fieldName = node.identifier.name; 1648 String fieldName = node.identifier.name;
1561 ClassElement classElement = _resolver.enclosingClass; 1649 ClassElement classElement = _resolver.enclosingClass;
1562 if (classElement != null) { 1650 if (classElement != null) {
1563 FieldElement fieldElement = ((classElement as ClassElementImpl)).getField( fieldName); 1651 FieldElement fieldElement = ((classElement as ClassElementImpl)).getField( fieldName);
1564 if (fieldElement != null) { 1652 if (fieldElement != null) {
1565 if (!fieldElement.isSynthetic()) { 1653 if (!fieldElement.isSynthetic()) {
1566 ParameterElement parameterElement = node.element; 1654 ParameterElement parameterElement = node.element;
1567 if (parameterElement is FieldFormalParameterElementImpl) { 1655 if (parameterElement is FieldFormalParameterElementImpl) {
1568 ((parameterElement as FieldFormalParameterElementImpl)).field = fiel dElement; 1656 FieldFormalParameterElementImpl fieldFormal = parameterElement as Fi eldFormalParameterElementImpl;
1657 fieldFormal.field = fieldElement;
1658 Type2 declaredType = fieldFormal.type;
1659 Type2 fieldType = fieldElement.type;
1660 if (node.type == null) {
1661 fieldFormal.type = fieldType;
1662 }
1569 if (fieldElement.isStatic()) { 1663 if (fieldElement.isStatic()) {
1570 _resolver.reportError(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR _STATIC_FIELD, node, [fieldName]); 1664 _resolver.reportError(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR _STATIC_FIELD, node, [fieldName]);
1665 } else if (declaredType != null && fieldType != null && !declaredTyp e.isAssignableTo(fieldType)) {
1666 _resolver.reportError(StaticWarningCode.FIELD_INITIALIZER_WITH_INV ALID_TYPE, node, [declaredType.name, fieldType.name]);
1571 } 1667 }
1572 } 1668 }
1573 } 1669 }
1574 } else { 1670 } else {
1575 _resolver.reportError(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_E XISTANT_FIELD, node, [fieldName]); 1671 _resolver.reportError(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_E XISTANT_FIELD, node, [fieldName]);
1576 } 1672 }
1577 } 1673 }
1578 return super.visitFieldFormalParameter(node); 1674 return super.visitFieldFormalParameter(node);
1579 } 1675 }
1580 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null; 1676 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, method Name2, [methodName2.name, enclosingClass3.name]); 1821 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, method Name2, [methodName2.name, enclosingClass3.name]);
1726 } else { 1822 } else {
1727 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]); 1823 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]);
1728 } 1824 }
1729 } else { 1825 } else {
1730 Type2 targetType = getType(target); 1826 Type2 targetType = getType(target);
1731 String targetTypeName = targetType == null ? null : targetType.name; 1827 String targetTypeName = targetType == null ? null : targetType.name;
1732 if (targetTypeName == null) { 1828 if (targetTypeName == null) {
1733 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, meth odName2, [methodName2.name]); 1829 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, meth odName2, [methodName2.name]);
1734 } else { 1830 } else {
1735 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, method Name2, [methodName2.name, targetTypeName]); 1831 if (!doesClassDeclareNoSuchMethod(targetType.element)) {
1832 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, meth odName2, [methodName2.name, targetTypeName]);
1833 }
1736 } 1834 }
1737 } 1835 }
1738 return null; 1836 return null;
1739 } 1837 }
1740 } 1838 }
1741 recordResolution(methodName2, invokedMethod); 1839 recordResolution(methodName2, invokedMethod);
1742 resolveNamedArguments(node.argumentList, invokedMethod); 1840 resolveNamedArguments(node.argumentList, invokedMethod);
1743 return null; 1841 return null;
1744 } 1842 }
1745 Object visitPostfixExpression(PostfixExpression node) { 1843 Object visitPostfixExpression(PostfixExpression node) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 memberElement = lookUpGetter(targetType, identifier.name); 1981 memberElement = lookUpGetter(targetType, identifier.name);
1884 } 1982 }
1885 if (memberElement == null) { 1983 if (memberElement == null) {
1886 MethodElement methodElement = lookUpMethod(targetType, identifier.name); 1984 MethodElement methodElement = lookUpMethod(targetType, identifier.name);
1887 if (methodElement != null) { 1985 if (methodElement != null) {
1888 recordResolution(identifier, methodElement); 1986 recordResolution(identifier, methodElement);
1889 return null; 1987 return null;
1890 } 1988 }
1891 } 1989 }
1892 if (memberElement == null) { 1990 if (memberElement == null) {
1893 if (identifier.inSetterContext()) { 1991 if (!doesClassDeclareNoSuchMethod(targetType.element)) {
1894 _resolver.reportError(StaticWarningCode.UNDEFINED_SETTER, identifier, [i dentifier.name, targetType.name]); 1992 if (identifier.inSetterContext()) {
1895 } else if (identifier.inGetterContext()) { 1993 _resolver.reportError(StaticWarningCode.UNDEFINED_SETTER, identifier, [identifier.name, targetType.name]);
1896 _resolver.reportError(StaticWarningCode.UNDEFINED_GETTER, identifier, [i dentifier.name, targetType.name]); 1994 } else if (identifier.inGetterContext()) {
1897 } else { 1995 _resolver.reportError(StaticWarningCode.UNDEFINED_GETTER, identifier, [identifier.name, targetType.name]);
1898 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, identifier , [identifier.name]); 1996 } else {
1997 System.out.println("two ${identifier.name}");
1998 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, identifi er, [identifier.name]);
1999 }
1899 } 2000 }
1900 } else { 2001 } else {
1901 recordResolution(identifier, memberElement); 2002 recordResolution(identifier, memberElement);
1902 } 2003 }
1903 return null; 2004 return null;
1904 } 2005 }
1905 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 2006 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
1906 ClassElement enclosingClass2 = _resolver.enclosingClass; 2007 ClassElement enclosingClass2 = _resolver.enclosingClass;
1907 if (enclosingClass2 == null) { 2008 if (enclosingClass2 == null) {
1908 return null; 2009 return null;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 element = lookUpSetter(enclosingType, node.name); 2046 element = lookUpSetter(enclosingType, node.name);
1946 } 2047 }
1947 if (element == null && node.inGetterContext()) { 2048 if (element == null && node.inGetterContext()) {
1948 element = lookUpGetter(enclosingType, node.name); 2049 element = lookUpGetter(enclosingType, node.name);
1949 } 2050 }
1950 if (element == null) { 2051 if (element == null) {
1951 element = lookUpMethod(enclosingType, node.name); 2052 element = lookUpMethod(enclosingType, node.name);
1952 } 2053 }
1953 } 2054 }
1954 if (element == null) { 2055 if (element == null) {
1955 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node. name]); 2056 if (!doesClassDeclareNoSuchMethod(enclosingClass2)) {
2057 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [nod e.name]);
2058 }
1956 } 2059 }
1957 recordResolution(node, element); 2060 recordResolution(node, element);
1958 return null; 2061 return null;
1959 } 2062 }
1960 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 2063 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
1961 ClassElement enclosingClass2 = _resolver.enclosingClass; 2064 ClassElement enclosingClass2 = _resolver.enclosingClass;
1962 if (enclosingClass2 == null) { 2065 if (enclosingClass2 == null) {
1963 return null; 2066 return null;
1964 } 2067 }
1965 ClassElement superclass = getSuperclass(enclosingClass2); 2068 ClassElement superclass = getSuperclass(enclosingClass2);
(...skipping 21 matching lines...) Expand all
1987 TypeName bound2 = node.bound; 2090 TypeName bound2 = node.bound;
1988 if (bound2 != null) { 2091 if (bound2 != null) {
1989 TypeVariableElementImpl variable = node.name.element as TypeVariableElemen tImpl; 2092 TypeVariableElementImpl variable = node.name.element as TypeVariableElemen tImpl;
1990 if (variable != null) { 2093 if (variable != null) {
1991 variable.bound = bound2.type; 2094 variable.bound = bound2.type;
1992 } 2095 }
1993 } 2096 }
1994 return null; 2097 return null;
1995 } 2098 }
1996 /** 2099 /**
2100 * Return {@code true} if the passed {@link Element} is a {@link ClassElement} that declares a
2101 * method "noSuchMethod".
2102 * @param element the {@link Element} to evaluate
2103 * @return {@code true} if the passed {@link Element} is a {@link ClassElement } that declares a
2104 * method "noSuchMethod"
2105 */
2106 bool doesClassDeclareNoSuchMethod(Element element) {
2107 if (element == null) {
2108 return false;
2109 }
2110 if (element is! ClassElementImpl) {
2111 return false;
2112 }
2113 ClassElementImpl classElement = element as ClassElementImpl;
2114 MethodElement method = classElement.lookUpMethod("noSuchMethod", _resolver.d efiningLibrary);
2115 if (method == null) {
2116 return false;
2117 }
2118 return true;
2119 }
2120 /**
1997 * Search through the array of parameters for a parameter whose name matches t he given name. 2121 * Search through the array of parameters for a parameter whose name matches t he given name.
1998 * Return the parameter with the given name, or {@code null} if there is no su ch parameter. 2122 * Return the parameter with the given name, or {@code null} if there is no su ch parameter.
1999 * @param parameters the parameters being searched 2123 * @param parameters the parameters being searched
2000 * @param name the name being searched for 2124 * @param name the name being searched for
2001 * @return the parameter with the given name 2125 * @return the parameter with the given name
2002 */ 2126 */
2003 ParameterElement findNamedParameter(List<ParameterElement> parameters, String name2) { 2127 ParameterElement findNamedParameter(List<ParameterElement> parameters, String name2) {
2004 for (ParameterElement parameter in parameters) { 2128 for (ParameterElement parameter in parameters) {
2005 if (identical(parameter.parameterKind, ParameterKind.NAMED)) { 2129 if (identical(parameter.parameterKind, ParameterKind.NAMED)) {
2006 String parameteName = parameter.name; 2130 String parameteName = parameter.name;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 return getter; 2218 return getter;
2095 } 2219 }
2096 } 2220 }
2097 InterfaceType superclass2 = targetType.superclass; 2221 InterfaceType superclass2 = targetType.superclass;
2098 if (superclass2 == null) { 2222 if (superclass2 == null) {
2099 return null; 2223 return null;
2100 } 2224 }
2101 return lookUpGetterInInterfaces(superclass2, getterName, visitedInterfaces); 2225 return lookUpGetterInInterfaces(superclass2, getterName, visitedInterfaces);
2102 } 2226 }
2103 /** 2227 /**
2228 * Look up the method or getter with the given name in the given type. Return the element
2229 * representing the method or getter that was found, or {@code null} if there is no method or
2230 * getter with the given name.
2231 * @param type the type in which the method or getter is defined
2232 * @param memberName the name of the method or getter being looked up
2233 * @return the element representing the method or getter that was found
2234 */
2235 ExecutableElement lookupGetterOrMethod(Type2 type, String memberName) {
2236 type = resolveTypeVariable(type);
2237 if (type is InterfaceType) {
2238 InterfaceType interfaceType = type as InterfaceType;
2239 ExecutableElement member = interfaceType.lookUpMethod(memberName, _resolve r.definingLibrary);
2240 if (member != null) {
2241 return member;
2242 }
2243 member = interfaceType.lookUpGetter(memberName, _resolver.definingLibrary) ;
2244 if (member != null) {
2245 return member;
2246 }
2247 return lookUpGetterOrMethodInInterfaces(interfaceType, memberName, new Set <ClassElement>());
2248 }
2249 return null;
2250 }
2251 /**
2252 * Look up the method or getter with the given name in the interfaces implemen ted by the given
2253 * type, either directly or indirectly. Return the element representing the me thod or getter that
2254 * was found, or {@code null} if there is no method or getter with the given n ame.
2255 * @param targetType the type in which the method or getter might be defined
2256 * @param memberName the name of the method or getter being looked up
2257 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
2258 * to prevent infinite recursion and to optimize the search
2259 * @return the element representing the method or getter that was found
2260 */
2261 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, S tring memberName, Set<ClassElement> visitedInterfaces) {
2262 ClassElement targetClass = targetType.element;
2263 if (visitedInterfaces.contains(targetClass)) {
2264 return null;
2265 }
2266 javaSetAdd(visitedInterfaces, targetClass);
2267 ExecutableElement member = targetType.getMethod(memberName);
2268 if (member != null) {
2269 return member;
2270 }
2271 member = targetType.getGetter(memberName);
2272 if (member != null) {
2273 return member;
2274 }
2275 for (InterfaceType interfaceType in targetType.interfaces) {
2276 member = lookUpGetterOrMethodInInterfaces(interfaceType, memberName, visit edInterfaces);
2277 if (member != null) {
2278 return member;
2279 }
2280 }
2281 InterfaceType superclass2 = targetType.superclass;
2282 if (superclass2 == null) {
2283 return null;
2284 }
2285 return lookUpGetterInInterfaces(superclass2, memberName, visitedInterfaces);
2286 }
2287 /**
2104 * Find the element corresponding to the given label node in the current label scope. 2288 * Find the element corresponding to the given label node in the current label scope.
2105 * @param parentNode the node containing the given label 2289 * @param parentNode the node containing the given label
2106 * @param labelNode the node representing the label being looked up 2290 * @param labelNode the node representing the label being looked up
2107 * @return the element corresponding to the given label node in the current sc ope 2291 * @return the element corresponding to the given label node in the current sc ope
2108 */ 2292 */
2109 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { 2293 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) {
2110 LabelScope labelScope2 = _resolver.labelScope; 2294 LabelScope labelScope2 = _resolver.labelScope;
2111 LabelElementImpl labelElement = null; 2295 LabelElementImpl labelElement = null;
2112 if (labelNode == null) { 2296 if (labelNode == null) {
2113 if (labelScope2 == null) { 2297 if (labelScope2 == null) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 * Record the fact that the given AST node was resolved to the given element. 2461 * Record the fact that the given AST node was resolved to the given element.
2278 * @param node the AST node that was resolved 2462 * @param node the AST node that was resolved
2279 * @param element the element to which the AST node was resolved 2463 * @param element the element to which the AST node was resolved
2280 */ 2464 */
2281 void recordResolution(SimpleIdentifier node, Element element2) { 2465 void recordResolution(SimpleIdentifier node, Element element2) {
2282 if (element2 != null) { 2466 if (element2 != null) {
2283 node.element = element2; 2467 node.element = element2;
2284 } 2468 }
2285 } 2469 }
2286 /** 2470 /**
2287 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and 2471 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and <code>UNDEFINED_GETTER</code>.
2288 * <code>UNDEFINED_GETTER</code>.
2289 * @param node the prefixed identifier that gives the context to determine if the error on the 2472 * @param node the prefixed identifier that gives the context to determine if the error on the
2290 * undefined identifier is a getter or a setter 2473 * undefined identifier is a getter or a setter
2291 * @param identifier the identifier in the passed prefix identifier 2474 * @param identifier the identifier in the passed prefix identifier
2292 * @param typeName the name of the type of the left hand side of the passed pr efixed identifier 2475 * @param typeName the name of the type of the left hand side of the passed pr efixed identifier
2293 */ 2476 */
2294 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id entifier2, String typeName) { 2477 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id entifier2, String typeName) {
2478 Type2 targetType = getType(node);
2479 if (targetType != null && doesClassDeclareNoSuchMethod(targetType.element)) {
2480 return;
2481 }
2295 bool isSetterContext = node.identifier.inSetterContext(); 2482 bool isSetterContext = node.identifier.inSetterContext();
2296 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT ER : StaticTypeWarningCode.UNDEFINED_GETTER; 2483 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT ER : StaticTypeWarningCode.UNDEFINED_GETTER;
2297 _resolver.reportError(errorCode, identifier2, [identifier2.name, typeName]); 2484 _resolver.reportError(errorCode, identifier2, [identifier2.name, typeName]);
2298 } 2485 }
2299 /** 2486 /**
2300 * Resolve the names in the given combinators in the scope of the given librar y. 2487 * Resolve the names in the given combinators in the scope of the given librar y.
2301 * @param library the library that defines the names 2488 * @param library the library that defines the names
2302 * @param combinators the combinators containing the names to be resolved 2489 * @param combinators the combinators containing the names to be resolved
2303 */ 2490 */
2304 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) { 2491 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) {
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2784 Map<Source, Library> _libraryMap = new Map<Source, Library>(); 2971 Map<Source, Library> _libraryMap = new Map<Source, Library>();
2785 /** 2972 /**
2786 * A collection containing the libraries that are being resolved together. 2973 * A collection containing the libraries that are being resolved together.
2787 */ 2974 */
2788 Set<Library> _librariesInCycles; 2975 Set<Library> _librariesInCycles;
2789 /** 2976 /**
2790 * Initialize a newly created library resolver to resolve libraries within the given context. 2977 * Initialize a newly created library resolver to resolve libraries within the given context.
2791 * @param analysisContext the analysis context in which the library is being a nalyzed 2978 * @param analysisContext the analysis context in which the library is being a nalyzed
2792 */ 2979 */
2793 LibraryResolver.con1(InternalAnalysisContext analysisContext) { 2980 LibraryResolver.con1(InternalAnalysisContext analysisContext) {
2794 _jtd_constructor_263_impl(analysisContext); 2981 _jtd_constructor_264_impl(analysisContext);
2795 } 2982 }
2796 _jtd_constructor_263_impl(InternalAnalysisContext analysisContext) { 2983 _jtd_constructor_264_impl(InternalAnalysisContext analysisContext) {
2797 _jtd_constructor_264_impl(analysisContext, null); 2984 _jtd_constructor_265_impl(analysisContext, null);
2798 } 2985 }
2799 /** 2986 /**
2800 * Initialize a newly created library resolver to resolve libraries within the given context. 2987 * Initialize a newly created library resolver to resolve libraries within the given context.
2801 * @param analysisContext the analysis context in which the library is being a nalyzed 2988 * @param analysisContext the analysis context in which the library is being a nalyzed
2802 * @param errorListener the listener to which analysis errors will be reported 2989 * @param errorListener the listener to which analysis errors will be reported
2803 */ 2990 */
2804 LibraryResolver.con2(InternalAnalysisContext analysisContext2, AnalysisErrorLi stener additionalAnalysisErrorListener) { 2991 LibraryResolver.con2(InternalAnalysisContext analysisContext2, AnalysisErrorLi stener additionalAnalysisErrorListener) {
2805 _jtd_constructor_264_impl(analysisContext2, additionalAnalysisErrorListener) ; 2992 _jtd_constructor_265_impl(analysisContext2, additionalAnalysisErrorListener) ;
2806 } 2993 }
2807 _jtd_constructor_264_impl(InternalAnalysisContext analysisContext2, AnalysisEr rorListener additionalAnalysisErrorListener) { 2994 _jtd_constructor_265_impl(InternalAnalysisContext analysisContext2, AnalysisEr rorListener additionalAnalysisErrorListener) {
2808 this._analysisContext = analysisContext2; 2995 this._analysisContext = analysisContext2;
2809 this._recordingErrorListener = new RecordingErrorListener(); 2996 this._recordingErrorListener = new RecordingErrorListener();
2810 if (additionalAnalysisErrorListener == null) { 2997 if (additionalAnalysisErrorListener == null) {
2811 this._errorListener = _recordingErrorListener; 2998 this._errorListener = _recordingErrorListener;
2812 } else { 2999 } else {
2813 this._errorListener = new AnalysisErrorListener_9(this, additionalAnalysis ErrorListener); 3000 this._errorListener = new AnalysisErrorListener_9(this, additionalAnalysis ErrorListener);
2814 } 3001 }
2815 _coreLibrarySource = analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE ); 3002 _coreLibrarySource = analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE );
2816 } 3003 }
2817 /** 3004 /**
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 * Record the results of resolution with the analysis context. This includes r ecording 3399 * Record the results of resolution with the analysis context. This includes r ecording
3213 * <ul> 3400 * <ul>
3214 * <li>the resolved AST associated with each compilation unit,</li> 3401 * <li>the resolved AST associated with each compilation unit,</li>
3215 * <li>the set of resolution errors produced for each compilation unit, and</l i> 3402 * <li>the set of resolution errors produced for each compilation unit, and</l i>
3216 * <li>the element models produced for each library.</li> 3403 * <li>the element models produced for each library.</li>
3217 * </ul> 3404 * </ul>
3218 */ 3405 */
3219 void recordResults() { 3406 void recordResults() {
3220 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>(); 3407 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>();
3221 for (Library library in _librariesInCycles) { 3408 for (Library library in _librariesInCycles) {
3222 recordResults2(library.librarySource, library.definingCompilationUnit); 3409 Source librarySource2 = library.librarySource;
3410 recordResults2(librarySource2, librarySource2, library.definingCompilation Unit);
3223 for (Source source in library.compilationUnitSources) { 3411 for (Source source in library.compilationUnitSources) {
3224 recordResults2(source, library.getAST(source)); 3412 recordResults2(source, librarySource2, library.getAST(source));
3225 } 3413 }
3226 elementMap[library.librarySource] = library.libraryElement; 3414 elementMap[library.librarySource] = library.libraryElement;
3227 } 3415 }
3228 _analysisContext.recordLibraryElements(elementMap); 3416 _analysisContext.recordLibraryElements(elementMap);
3229 } 3417 }
3230 void recordResults2(Source source, CompilationUnit unit) { 3418 void recordResults2(Source source, Source librarySource, CompilationUnit unit) {
3231 List<AnalysisError> errors = _recordingErrorListener.getErrors2(source); 3419 List<AnalysisError> errors = _recordingErrorListener.getErrors2(source);
3232 unit.resolutionErrors = errors; 3420 unit.resolutionErrors = errors;
3233 _analysisContext.recordResolvedCompilationUnit(source, unit); 3421 _analysisContext.recordResolvedCompilationUnit(source, librarySource, unit);
3234 _analysisContext.recordResolutionErrors(source, errors, unit.lineInfo); 3422 _analysisContext.recordResolutionErrors(source, librarySource, errors, unit. lineInfo);
3235 } 3423 }
3236 /** 3424 /**
3237 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle. 3425 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
3238 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the 3426 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the
3239 * libraries could not have their types analyzed 3427 * libraries could not have their types analyzed
3240 */ 3428 */
3241 void resolveReferencesAndTypes() { 3429 void resolveReferencesAndTypes() {
3242 for (Library library in _librariesInCycles) { 3430 for (Library library in _librariesInCycles) {
3243 resolveReferencesAndTypes2(library); 3431 resolveReferencesAndTypes2(library);
3244 } 3432 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3319 * The object keeping track of which elements have had their types overridden. 3507 * The object keeping track of which elements have had their types overridden.
3320 */ 3508 */
3321 TypeOverrideManager _overrideManager = new TypeOverrideManager(); 3509 TypeOverrideManager _overrideManager = new TypeOverrideManager();
3322 /** 3510 /**
3323 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 3511 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3324 * @param library the library containing the compilation unit being resolved 3512 * @param library the library containing the compilation unit being resolved
3325 * @param source the source representing the compilation unit being visited 3513 * @param source the source representing the compilation unit being visited
3326 * @param typeProvider the object used to access the types from the core libra ry 3514 * @param typeProvider the object used to access the types from the core libra ry
3327 */ 3515 */
3328 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider ) : super.con1(library, source, typeProvider) { 3516 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider ) : super.con1(library, source, typeProvider) {
3329 _jtd_constructor_265_impl(library, source, typeProvider); 3517 _jtd_constructor_266_impl(library, source, typeProvider);
3330 } 3518 }
3331 _jtd_constructor_265_impl(Library library, Source source, TypeProvider typePro vider) { 3519 _jtd_constructor_266_impl(Library library, Source source, TypeProvider typePro vider) {
3332 this._elementResolver = new ElementResolver(this); 3520 this._elementResolver = new ElementResolver(this);
3333 this._typeAnalyzer = new StaticTypeAnalyzer(this); 3521 this._typeAnalyzer = new StaticTypeAnalyzer(this);
3334 } 3522 }
3335 /** 3523 /**
3336 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 3524 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3337 * @param definingLibrary the element for the library containing the compilati on unit being 3525 * @param definingLibrary the element for the library containing the compilati on unit being
3338 * visited 3526 * visited
3339 * @param source the source representing the compilation unit being visited 3527 * @param source the source representing the compilation unit being visited
3340 * @param typeProvider the object used to access the types from the core libra ry 3528 * @param typeProvider the object used to access the types from the core libra ry
3341 * @param errorListener the error listener that will be informed of any errors that are found 3529 * @param errorListener the error listener that will be informed of any errors that are found
3342 * during resolution 3530 * during resolution
3343 */ 3531 */
3344 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra ry, source, typeProvider, errorListener) { 3532 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra ry, source, typeProvider, errorListener) {
3345 _jtd_constructor_266_impl(definingLibrary, source, typeProvider, errorListen er); 3533 _jtd_constructor_267_impl(definingLibrary, source, typeProvider, errorListen er);
3346 } 3534 }
3347 _jtd_constructor_266_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) { 3535 _jtd_constructor_267_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) {
3348 this._elementResolver = new ElementResolver(this); 3536 this._elementResolver = new ElementResolver(this);
3349 this._typeAnalyzer = new StaticTypeAnalyzer(this); 3537 this._typeAnalyzer = new StaticTypeAnalyzer(this);
3350 } 3538 }
3351 /** 3539 /**
3352 * Return the object keeping track of which elements have had their types over ridden. 3540 * Return the object keeping track of which elements have had their types over ridden.
3353 * @return the object keeping track of which elements have had their types ove rridden 3541 * @return the object keeping track of which elements have had their types ove rridden
3354 */ 3542 */
3355 TypeOverrideManager get overrideManager => _overrideManager; 3543 TypeOverrideManager get overrideManager => _overrideManager;
3356 Object visitAsExpression(AsExpression node) { 3544 Object visitAsExpression(AsExpression node) {
3357 super.visitAsExpression(node); 3545 super.visitAsExpression(node);
3358 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) { 3546 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3359 VariableElement element = getOverridableElement(node.expression); 3547 VariableElement element = getOverridableElement(node.expression);
3360 if (element != null) { 3548 if (element != null) {
3361 Type2 type2 = node.type.type; 3549 Type2 type2 = node.type.type;
3362 if (type2 != null) { 3550 if (type2 != null) {
3363 _overrideManager.setType(element, type2); 3551 override(element, getType(element), type2);
3364 } 3552 }
3365 } 3553 }
3366 } 3554 }
3367 return null; 3555 return null;
3368 } 3556 }
3369 Object visitAssertStatement(AssertStatement node) { 3557 Object visitAssertStatement(AssertStatement node) {
3370 Expression condition2 = node.condition; 3558 super.visitAssertStatement(node);
3371 condition2.accept(this); 3559 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3372 propagateTrueState(condition2); 3560 propagateTrueState(node.condition);
3561 }
3562 return null;
3563 }
3564 Object visitBinaryExpression(BinaryExpression node) {
3565 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3566 sc.TokenType operatorType = node.operator.type;
3567 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) {
3568 Expression leftOperand2 = node.leftOperand;
3569 leftOperand2.accept(this);
3570 Expression rightOperand2 = node.rightOperand;
3571 if (rightOperand2 != null) {
3572 try {
3573 _overrideManager.enterScope();
3574 propagateTrueState(leftOperand2);
3575 rightOperand2.accept(this);
3576 } finally {
3577 _overrideManager.exitScope();
3578 }
3579 }
3580 } else if (identical(operatorType, sc.TokenType.BAR_BAR)) {
3581 Expression leftOperand3 = node.leftOperand;
3582 leftOperand3.accept(this);
3583 Expression rightOperand3 = node.rightOperand;
3584 if (rightOperand3 != null) {
3585 try {
3586 _overrideManager.enterScope();
3587 propagateFalseState(leftOperand3);
3588 rightOperand3.accept(this);
3589 } finally {
3590 _overrideManager.exitScope();
3591 }
3592 }
3593 } else {
3594 node.leftOperand.accept(this);
3595 node.rightOperand.accept(this);
3596 }
3597 node.accept(_elementResolver);
3598 node.accept(_typeAnalyzer);
3599 } else {
3600 super.visitBinaryExpression(node);
3601 }
3373 return null; 3602 return null;
3374 } 3603 }
3375 Object visitBreakStatement(BreakStatement node) { 3604 Object visitBreakStatement(BreakStatement node) {
3376 node.accept(_elementResolver); 3605 node.accept(_elementResolver);
3377 node.accept(_typeAnalyzer); 3606 node.accept(_typeAnalyzer);
3378 return null; 3607 return null;
3379 } 3608 }
3380 Object visitClassDeclaration(ClassDeclaration node) { 3609 Object visitClassDeclaration(ClassDeclaration node) {
3381 ClassElement outerType = _enclosingClass; 3610 ClassElement outerType = _enclosingClass;
3382 try { 3611 try {
3383 _enclosingClass = node.element; 3612 _enclosingClass = node.element;
3384 _typeAnalyzer.thisType = _enclosingClass == null ? null : _enclosingClass. type; 3613 _typeAnalyzer.thisType = _enclosingClass == null ? null : _enclosingClass. type;
3385 super.visitClassDeclaration(node); 3614 super.visitClassDeclaration(node);
3386 } finally { 3615 } finally {
3387 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; 3616 _typeAnalyzer.thisType = outerType == null ? null : outerType.type;
3388 _enclosingClass = outerType; 3617 _enclosingClass = outerType;
3389 } 3618 }
3390 return null; 3619 return null;
3391 } 3620 }
3392 Object visitComment(Comment node) => null; 3621 Object visitCommentReference(CommentReference node) {
3622 node.accept(_elementResolver);
3623 node.accept(_typeAnalyzer);
3624 return null;
3625 }
3393 Object visitCompilationUnit(CompilationUnit node) { 3626 Object visitCompilationUnit(CompilationUnit node) {
3394 try { 3627 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3395 _overrideManager.enterScope(); 3628 try {
3396 for (Directive directive in node.directives) { 3629 _overrideManager.enterScope();
3397 directive.accept(this); 3630 for (Directive directive in node.directives) {
3398 } 3631 directive.accept(this);
3399 List<CompilationUnitMember> classes = new List<CompilationUnitMember>(); 3632 }
3400 for (CompilationUnitMember declaration in node.declarations) { 3633 List<CompilationUnitMember> classes = new List<CompilationUnitMember>();
3401 if (declaration is ClassDeclaration) { 3634 for (CompilationUnitMember declaration in node.declarations) {
3402 classes.add(declaration); 3635 if (declaration is ClassDeclaration) {
3403 } else { 3636 classes.add(declaration);
3637 } else {
3638 declaration.accept(this);
3639 }
3640 }
3641 for (CompilationUnitMember declaration in classes) {
3404 declaration.accept(this); 3642 declaration.accept(this);
3405 } 3643 }
3644 } finally {
3645 _overrideManager.exitScope();
3406 } 3646 }
3407 for (CompilationUnitMember declaration in classes) { 3647 node.accept(_elementResolver);
3408 declaration.accept(this); 3648 node.accept(_typeAnalyzer);
3409 } 3649 } else {
3410 } finally { 3650 super.visitCompilationUnit(node);
3411 _overrideManager.exitScope();
3412 } 3651 }
3413 return null; 3652 return null;
3414 } 3653 }
3415 Object visitConditionalExpression(ConditionalExpression node) { 3654 Object visitConditionalExpression(ConditionalExpression node) {
3416 Expression condition2 = node.condition; 3655 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3417 condition2.accept(this); 3656 Expression condition2 = node.condition;
3418 Expression thenExpression2 = node.thenExpression; 3657 condition2.accept(this);
3419 if (thenExpression2 != null) { 3658 Expression thenExpression2 = node.thenExpression;
3420 try { 3659 if (thenExpression2 != null) {
3421 _overrideManager.enterScope(); 3660 try {
3422 propagateTrueState(condition2); 3661 _overrideManager.enterScope();
3423 thenExpression2.accept(this); 3662 propagateTrueState(condition2);
3424 } finally { 3663 thenExpression2.accept(this);
3425 _overrideManager.exitScope(); 3664 } finally {
3665 _overrideManager.exitScope();
3666 }
3426 } 3667 }
3427 } 3668 Expression elseExpression2 = node.elseExpression;
3428 Expression elseExpression2 = node.elseExpression; 3669 if (elseExpression2 != null) {
3429 if (elseExpression2 != null) { 3670 try {
3430 try { 3671 _overrideManager.enterScope();
3431 _overrideManager.enterScope(); 3672 propagateFalseState(condition2);
3432 propagateFalseState(condition2); 3673 elseExpression2.accept(this);
3433 elseExpression2.accept(this); 3674 } finally {
3434 } finally { 3675 _overrideManager.exitScope();
3435 _overrideManager.exitScope(); 3676 }
3436 } 3677 }
3437 } 3678 node.accept(_elementResolver);
3438 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) { 3679 node.accept(_typeAnalyzer);
3439 bool thenIsAbrupt = thenExpression2 != null && isAbruptTermination(thenExp ression2); 3680 bool thenIsAbrupt = thenExpression2 != null && isAbruptTermination(thenExp ression2);
3440 bool elseIsAbrupt = elseExpression2 != null && isAbruptTermination(elseExp ression2); 3681 bool elseIsAbrupt = elseExpression2 != null && isAbruptTermination(elseExp ression2);
3441 if (elseIsAbrupt && !thenIsAbrupt) { 3682 if (elseIsAbrupt && !thenIsAbrupt) {
3442 propagateTrueState(condition2); 3683 propagateTrueState(condition2);
3443 } else if (thenIsAbrupt && !elseIsAbrupt) { 3684 } else if (thenIsAbrupt && !elseIsAbrupt) {
3444 propagateFalseState(condition2); 3685 propagateFalseState(condition2);
3445 } 3686 }
3687 } else {
3688 super.visitConditionalExpression(node);
3446 } 3689 }
3447 return null; 3690 return null;
3448 } 3691 }
3449 Object visitConstructorDeclaration(ConstructorDeclaration node) { 3692 Object visitConstructorDeclaration(ConstructorDeclaration node) {
3450 ExecutableElement outerFunction = _enclosingFunction; 3693 ExecutableElement outerFunction = _enclosingFunction;
3451 try { 3694 try {
3452 _enclosingFunction = node.element; 3695 _enclosingFunction = node.element;
3453 super.visitConstructorDeclaration(node); 3696 super.visitConstructorDeclaration(node);
3454 } finally { 3697 } finally {
3455 _enclosingFunction = outerFunction; 3698 _enclosingFunction = outerFunction;
(...skipping 10 matching lines...) Expand all
3466 node.accept(_elementResolver); 3709 node.accept(_elementResolver);
3467 node.accept(_typeAnalyzer); 3710 node.accept(_typeAnalyzer);
3468 return null; 3711 return null;
3469 } 3712 }
3470 Object visitContinueStatement(ContinueStatement node) { 3713 Object visitContinueStatement(ContinueStatement node) {
3471 node.accept(_elementResolver); 3714 node.accept(_elementResolver);
3472 node.accept(_typeAnalyzer); 3715 node.accept(_typeAnalyzer);
3473 return null; 3716 return null;
3474 } 3717 }
3475 Object visitFieldDeclaration(FieldDeclaration node) { 3718 Object visitFieldDeclaration(FieldDeclaration node) {
3476 try { 3719 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3477 _overrideManager.enterScope(); 3720 try {
3721 _overrideManager.enterScope();
3722 super.visitFieldDeclaration(node);
3723 } finally {
3724 Map<Element, Type2> overrides = captureOverrides(node.fields);
3725 _overrideManager.exitScope();
3726 applyOverrides(overrides);
3727 }
3728 } else {
3478 super.visitFieldDeclaration(node); 3729 super.visitFieldDeclaration(node);
3479 } finally { 3730 }
3480 Map<Element, Type2> overrides = captureOverrides(node.fields); 3731 return null;
3481 _overrideManager.exitScope(); 3732 }
3482 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) { 3733 Object visitForEachStatement(ForEachStatement node) {
3483 _overrideManager.setType(entry.getKey(), entry.getValue()); 3734 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3735 try {
3736 _overrideManager.enterScope();
3737 super.visitForEachStatement(node);
3738 } finally {
3739 _overrideManager.exitScope();
3484 } 3740 }
3741 } else {
3742 super.visitForEachStatement(node);
3485 } 3743 }
3486 return null; 3744 return null;
3487 } 3745 }
3488 Object visitForStatement(ForStatement node) { 3746 Object visitForStatement(ForStatement node) {
3489 try { 3747 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3490 _overrideManager.enterScope(); 3748 try {
3749 _overrideManager.enterScope();
3750 super.visitForStatement(node);
3751 } finally {
3752 _overrideManager.exitScope();
3753 }
3754 } else {
3491 super.visitForStatement(node); 3755 super.visitForStatement(node);
3492 } finally {
3493 _overrideManager.exitScope();
3494 } 3756 }
3495 return null; 3757 return null;
3496 } 3758 }
3497 Object visitFunctionBody(FunctionBody node) { 3759 Object visitFunctionBody(FunctionBody node) {
3498 try { 3760 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3499 _overrideManager.enterScope(); 3761 try {
3762 _overrideManager.enterScope();
3763 super.visitFunctionBody(node);
3764 } finally {
3765 _overrideManager.exitScope();
3766 }
3767 } else {
3500 super.visitFunctionBody(node); 3768 super.visitFunctionBody(node);
3501 } finally {
3502 _overrideManager.exitScope();
3503 } 3769 }
3504 return null; 3770 return null;
3505 } 3771 }
3506 Object visitFunctionDeclaration(FunctionDeclaration node) { 3772 Object visitFunctionDeclaration(FunctionDeclaration node) {
3507 ExecutableElement outerFunction = _enclosingFunction; 3773 ExecutableElement outerFunction = _enclosingFunction;
3508 try { 3774 try {
3509 SimpleIdentifier functionName = node.name; 3775 SimpleIdentifier functionName = node.name;
3510 _enclosingFunction = functionName.element as ExecutableElement; 3776 _enclosingFunction = functionName.element as ExecutableElement;
3511 super.visitFunctionDeclaration(node); 3777 super.visitFunctionDeclaration(node);
3512 } finally { 3778 } finally {
3513 _enclosingFunction = outerFunction; 3779 _enclosingFunction = outerFunction;
3514 } 3780 }
3515 return null; 3781 return null;
3516 } 3782 }
3517 Object visitFunctionExpression(FunctionExpression node) { 3783 Object visitFunctionExpression(FunctionExpression node) {
3518 ExecutableElement outerFunction = _enclosingFunction; 3784 ExecutableElement outerFunction = _enclosingFunction;
3519 try { 3785 try {
3520 _enclosingFunction = node.element; 3786 _enclosingFunction = node.element;
3521 _overrideManager.enterScope(); 3787 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3788 _overrideManager.enterScope();
3789 }
3522 super.visitFunctionExpression(node); 3790 super.visitFunctionExpression(node);
3523 } finally { 3791 } finally {
3524 _overrideManager.exitScope(); 3792 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3793 _overrideManager.exitScope();
3794 }
3525 _enclosingFunction = outerFunction; 3795 _enclosingFunction = outerFunction;
3526 } 3796 }
3527 return null; 3797 return null;
3528 } 3798 }
3529 Object visitHideCombinator(HideCombinator node) => null; 3799 Object visitHideCombinator(HideCombinator node) => null;
3530 Object visitIfStatement(IfStatement node) { 3800 Object visitIfStatement(IfStatement node) {
3531 Expression condition2 = node.condition; 3801 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3532 condition2.accept(this); 3802 Expression condition2 = node.condition;
3533 Statement thenStatement2 = node.thenStatement; 3803 condition2.accept(this);
3534 if (thenStatement2 != null) { 3804 Statement thenStatement2 = node.thenStatement;
3535 try { 3805 if (thenStatement2 != null) {
3536 _overrideManager.enterScope(); 3806 try {
3537 propagateTrueState(condition2); 3807 _overrideManager.enterScope();
3538 thenStatement2.accept(this); 3808 propagateTrueState(condition2);
3539 } finally { 3809 thenStatement2.accept(this);
3540 _overrideManager.exitScope(); 3810 } finally {
3811 _overrideManager.exitScope();
3812 }
3541 } 3813 }
3542 } 3814 Statement elseStatement2 = node.elseStatement;
3543 Statement elseStatement2 = node.elseStatement; 3815 if (elseStatement2 != null) {
3544 if (elseStatement2 != null) { 3816 try {
3545 try { 3817 _overrideManager.enterScope();
3546 _overrideManager.enterScope(); 3818 propagateFalseState(condition2);
3547 propagateFalseState(condition2); 3819 elseStatement2.accept(this);
3548 elseStatement2.accept(this); 3820 } finally {
3549 } finally { 3821 _overrideManager.exitScope();
3550 _overrideManager.exitScope(); 3822 }
3551 } 3823 }
3552 } 3824 node.accept(_elementResolver);
3553 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) { 3825 node.accept(_typeAnalyzer);
3554 bool thenIsAbrupt = thenStatement2 != null && isAbruptTermination2(thenSta tement2); 3826 bool thenIsAbrupt = thenStatement2 != null && isAbruptTermination2(thenSta tement2);
3555 bool elseIsAbrupt = elseStatement2 != null && isAbruptTermination2(elseSta tement2); 3827 bool elseIsAbrupt = elseStatement2 != null && isAbruptTermination2(elseSta tement2);
3556 if (elseIsAbrupt && !thenIsAbrupt) { 3828 if (elseIsAbrupt && !thenIsAbrupt) {
3557 propagateTrueState(condition2); 3829 propagateTrueState(condition2);
3558 } else if (thenIsAbrupt && !elseIsAbrupt) { 3830 } else if (thenIsAbrupt && !elseIsAbrupt) {
3559 propagateFalseState(condition2); 3831 propagateFalseState(condition2);
3560 } 3832 }
3833 } else {
3834 super.visitIfStatement(node);
3561 } 3835 }
3562 return null; 3836 return null;
3563 } 3837 }
3564 Object visitLabel(Label node) => null; 3838 Object visitLabel(Label node) => null;
3565 Object visitLibraryIdentifier(LibraryIdentifier node) => null; 3839 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
3566 Object visitMethodDeclaration(MethodDeclaration node) { 3840 Object visitMethodDeclaration(MethodDeclaration node) {
3567 ExecutableElement outerFunction = _enclosingFunction; 3841 ExecutableElement outerFunction = _enclosingFunction;
3568 try { 3842 try {
3569 _enclosingFunction = node.element; 3843 _enclosingFunction = node.element;
3570 super.visitMethodDeclaration(node); 3844 super.visitMethodDeclaration(node);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3605 return null; 3879 return null;
3606 } 3880 }
3607 Object visitShowCombinator(ShowCombinator node) => null; 3881 Object visitShowCombinator(ShowCombinator node) => null;
3608 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 3882 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
3609 safelyVisit(node.argumentList); 3883 safelyVisit(node.argumentList);
3610 node.accept(_elementResolver); 3884 node.accept(_elementResolver);
3611 node.accept(_typeAnalyzer); 3885 node.accept(_typeAnalyzer);
3612 return null; 3886 return null;
3613 } 3887 }
3614 Object visitSwitchCase(SwitchCase node) { 3888 Object visitSwitchCase(SwitchCase node) {
3615 try { 3889 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3616 _overrideManager.enterScope(); 3890 try {
3891 _overrideManager.enterScope();
3892 super.visitSwitchCase(node);
3893 } finally {
3894 _overrideManager.exitScope();
3895 }
3896 } else {
3617 super.visitSwitchCase(node); 3897 super.visitSwitchCase(node);
3618 } finally {
3619 _overrideManager.exitScope();
3620 } 3898 }
3621 return null; 3899 return null;
3622 } 3900 }
3623 Object visitSwitchDefault(SwitchDefault node) { 3901 Object visitSwitchDefault(SwitchDefault node) {
3624 try { 3902 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3625 _overrideManager.enterScope(); 3903 try {
3904 _overrideManager.enterScope();
3905 super.visitSwitchDefault(node);
3906 } finally {
3907 _overrideManager.exitScope();
3908 }
3909 } else {
3626 super.visitSwitchDefault(node); 3910 super.visitSwitchDefault(node);
3627 } finally {
3628 _overrideManager.exitScope();
3629 } 3911 }
3630 return null; 3912 return null;
3631 } 3913 }
3632 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 3914 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
3633 try { 3915 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3634 _overrideManager.enterScope(); 3916 try {
3917 _overrideManager.enterScope();
3918 super.visitTopLevelVariableDeclaration(node);
3919 } finally {
3920 Map<Element, Type2> overrides = captureOverrides(node.variables);
3921 _overrideManager.exitScope();
3922 applyOverrides(overrides);
3923 }
3924 } else {
3635 super.visitTopLevelVariableDeclaration(node); 3925 super.visitTopLevelVariableDeclaration(node);
3636 } finally {
3637 Map<Element, Type2> overrides = captureOverrides(node.variables);
3638 _overrideManager.exitScope();
3639 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) {
3640 _overrideManager.setType(entry.getKey(), entry.getValue());
3641 }
3642 } 3926 }
3643 return null; 3927 return null;
3644 } 3928 }
3645 Object visitTypeName(TypeName node) => null; 3929 Object visitTypeName(TypeName node) => null;
3930 Object visitWhileStatement(WhileStatement node) {
3931 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3932 Expression condition2 = node.condition;
3933 condition2.accept(this);
3934 Statement body2 = node.body;
3935 if (body2 != null) {
3936 try {
3937 _overrideManager.enterScope();
3938 propagateTrueState(condition2);
3939 body2.accept(this);
3940 } finally {
3941 _overrideManager.exitScope();
3942 }
3943 }
3944 node.accept(_elementResolver);
3945 node.accept(_typeAnalyzer);
3946 } else {
3947 super.visitWhileStatement(node);
3948 }
3949 return null;
3950 }
3646 /** 3951 /**
3647 * Return the class element representing the class containing the current node , or {@code null} if 3952 * Return the class element representing the class containing the current node , or {@code null} if
3648 * the current node is not contained in a class. 3953 * the current node is not contained in a class.
3649 * @return the class element representing the class containing the current nod e 3954 * @return the class element representing the class containing the current nod e
3650 */ 3955 */
3651 ClassElement get enclosingClass => _enclosingClass; 3956 ClassElement get enclosingClass => _enclosingClass;
3652 /** 3957 /**
3653 * Return the element representing the function containing the current node, o r {@code null} if 3958 * Return the element representing the function containing the current node, o r {@code null} if
3654 * the current node is not contained in a function. 3959 * the current node is not contained in a function.
3655 * @return the element representing the function containing the current node 3960 * @return the element representing the function containing the current node
3656 */ 3961 */
3657 ExecutableElement get enclosingFunction => _enclosingFunction; 3962 ExecutableElement get enclosingFunction => _enclosingFunction;
3658 /** 3963 /**
3659 * Return the element associated with the given expression whose type can be o verridden, or{@code null} if there is no element whose type can be overridden. 3964 * Return the element associated with the given expression whose type can be o verridden, or{@code null} if there is no element whose type can be overridden.
3660 * @param expression the expression with which the element is associated 3965 * @param expression the expression with which the element is associated
3661 * @return the element associated with the given expression 3966 * @return the element associated with the given expression
3662 */ 3967 */
3663 VariableElement getOverridableElement(Expression expression) { 3968 VariableElement getOverridableElement(Expression expression) {
3664 if (expression is SimpleIdentifier) { 3969 if (expression is SimpleIdentifier) {
3665 Element element2 = ((expression as SimpleIdentifier)).element; 3970 Element element2 = ((expression as SimpleIdentifier)).element;
3666 if (element2 is VariableElement) { 3971 if (element2 is VariableElement) {
3667 return element2 as VariableElement; 3972 return element2 as VariableElement;
3668 } 3973 }
3669 } 3974 }
3670 return null; 3975 return null;
3671 } 3976 }
3977 void visitForEachStatementInScope(ForEachStatement node) {
3978 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3979 DeclaredIdentifier loopVariable2 = node.loopVariable;
3980 safelyVisit(loopVariable2);
3981 Expression iterator2 = node.iterator;
3982 if (iterator2 != null) {
3983 iterator2.accept(this);
3984 if (loopVariable2 != null) {
3985 LocalVariableElement loopElement = loopVariable2.element;
3986 override(loopElement, loopElement.type, getIteratorElementType(iterato r2));
3987 }
3988 }
3989 safelyVisit(node.body);
3990 node.accept(_elementResolver);
3991 node.accept(_typeAnalyzer);
3992 } else {
3993 super.visitForEachStatementInScope(node);
3994 }
3995 }
3996 /**
3997 * Apply a set of overrides that were previously captured.
3998 * @param overrides the overrides to be applied
3999 */
4000 void applyOverrides(Map<Element, Type2> overrides) {
4001 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) {
4002 _overrideManager.setType(entry.getKey(), entry.getValue());
4003 }
4004 }
3672 /** 4005 /**
3673 * Return a map from the elements for the variables in the given list that hav e their types 4006 * Return a map from the elements for the variables in the given list that hav e their types
3674 * overridden to the overriding type. 4007 * overridden to the overriding type.
3675 * @param variableList the list of variables whose overriding types are to be captured 4008 * @param variableList the list of variables whose overriding types are to be captured
3676 * @return a table mapping elements to their overriding types 4009 * @return a table mapping elements to their overriding types
3677 */ 4010 */
3678 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) { 4011 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) {
3679 Map<Element, Type2> overrides = new Map<Element, Type2>(); 4012 Map<Element, Type2> overrides = new Map<Element, Type2>();
3680 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) { 4013 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3681 if (variableList.isConst() || variableList.isFinal()) { 4014 if (variableList.isConst() || variableList.isFinal()) {
3682 for (VariableDeclaration variable in variableList.variables) { 4015 for (VariableDeclaration variable in variableList.variables) {
3683 Element element2 = variable.element; 4016 Element element2 = variable.element;
3684 if (element2 != null) { 4017 if (element2 != null) {
3685 Type2 type = _overrideManager.getType(element2); 4018 Type2 type = _overrideManager.getType(element2);
3686 if (type != null) { 4019 if (type != null) {
3687 overrides[element2] = type; 4020 overrides[element2] = type;
3688 } 4021 }
3689 } 4022 }
3690 } 4023 }
3691 } 4024 }
3692 } 4025 }
3693 return overrides; 4026 return overrides;
3694 } 4027 }
3695 /** 4028 /**
4029 * The given expression is the expression used to compute the iterator for a f or-each statement.
4030 * Attempt to compute the type of objects that will be assigned to the loop va riable and return
4031 * that type. Return {@code null} if the type could not be determined.
4032 * @param iterator the iterator for a for-each statement
4033 * @return the type of objects that will be assigned to the loop variable
4034 */
4035 Type2 getIteratorElementType(Expression iteratorExpression) {
4036 Type2 expressionType = iteratorExpression.staticType;
4037 if (expressionType is InterfaceType) {
4038 PropertyAccessorElement iterator = ((expressionType as InterfaceType)).loo kUpGetter("iterator", definingLibrary);
4039 if (iterator == null) {
4040 return null;
4041 }
4042 Type2 iteratorType = iterator.type.returnType;
4043 if (iteratorType is InterfaceType) {
4044 PropertyAccessorElement current = ((iteratorType as InterfaceType)).look UpGetter("current", definingLibrary);
4045 if (current == null) {
4046 return null;
4047 }
4048 return current.type.returnType;
4049 }
4050 }
4051 return null;
4052 }
4053 /**
4054 * Return the type of the given (overridable) element.
4055 * @param element the element whose type is to be returned
4056 * @return the type of the given element
4057 */
4058 Type2 getType(Element element) {
4059 if (element is LocalVariableElement) {
4060 return ((element as LocalVariableElement)).type;
4061 } else if (element is ParameterElement) {
4062 return ((element as ParameterElement)).type;
4063 }
4064 return null;
4065 }
4066 /**
3696 * Return {@code true} if the given expression terminates abruptly (that is, i f any expression 4067 * Return {@code true} if the given expression terminates abruptly (that is, i f any expression
3697 * following the given expression will not be reached). 4068 * following the given expression will not be reached).
3698 * @param expression the expression being tested 4069 * @param expression the expression being tested
3699 * @return {@code true} if the given expression terminates abruptly 4070 * @return {@code true} if the given expression terminates abruptly
3700 */ 4071 */
3701 bool isAbruptTermination(Expression expression2) { 4072 bool isAbruptTermination(Expression expression2) {
3702 while (expression2 is ParenthesizedExpression) { 4073 while (expression2 is ParenthesizedExpression) {
3703 expression2 = ((expression2 as ParenthesizedExpression)).expression; 4074 expression2 = ((expression2 as ParenthesizedExpression)).expression;
3704 } 4075 }
3705 return expression2 is ThrowExpression || expression2 is RethrowExpression; 4076 return expression2 is ThrowExpression || expression2 is RethrowExpression;
(...skipping 13 matching lines...) Expand all
3719 NodeList<Statement> statements2 = ((statement as Block)).statements; 4090 NodeList<Statement> statements2 = ((statement as Block)).statements;
3720 int size2 = statements2.length; 4091 int size2 = statements2.length;
3721 if (size2 == 0) { 4092 if (size2 == 0) {
3722 return false; 4093 return false;
3723 } 4094 }
3724 return isAbruptTermination2(statements2[size2 - 1]); 4095 return isAbruptTermination2(statements2[size2 - 1]);
3725 } 4096 }
3726 return false; 4097 return false;
3727 } 4098 }
3728 /** 4099 /**
4100 * If it is appropriate to do so, override the type of the given element. Use the static type and
4101 * inferred type of the element to determine whether or not it is appropriate.
4102 * @param element the element whose type might be overridden
4103 * @param staticType the static type of the element
4104 * @param inferredType the inferred type of the element
4105 */
4106 void override(VariableElement element, Type2 staticType, Type2 inferredType) {
4107 if (identical(inferredType, BottomTypeImpl.instance)) {
4108 return;
4109 }
4110 if (element is PropertyInducingElement) {
4111 PropertyInducingElement variable = element as PropertyInducingElement;
4112 if (!variable.isConst() && !variable.isFinal()) {
4113 return;
4114 }
4115 }
4116 if (staticType == null || (inferredType != null && inferredType.isMoreSpecif icThan(staticType))) {
4117 _overrideManager.setType(element, inferredType);
4118 }
4119 }
4120 /**
3729 * Propagate any type information that results from knowing that the given con dition will have 4121 * Propagate any type information that results from knowing that the given con dition will have
3730 * evaluated to 'false'. 4122 * evaluated to 'false'.
3731 * @param condition the condition that will have evaluated to 'false' 4123 * @param condition the condition that will have evaluated to 'false'
3732 */ 4124 */
3733 void propagateFalseState(Expression condition) { 4125 void propagateFalseState(Expression condition) {
3734 while (condition is ParenthesizedExpression) { 4126 while (condition is ParenthesizedExpression) {
3735 condition = ((condition as ParenthesizedExpression)).expression; 4127 condition = ((condition as ParenthesizedExpression)).expression;
3736 } 4128 }
3737 if (condition is IsExpression) { 4129 if (condition is IsExpression) {
3738 IsExpression is2 = condition as IsExpression; 4130 IsExpression is2 = condition as IsExpression;
3739 if (is2.notOperator != null) { 4131 if (is2.notOperator != null) {
3740 Element element = getOverridableElement(is2.expression); 4132 VariableElement element = getOverridableElement(is2.expression);
3741 if (element != null) { 4133 if (element != null) {
3742 Type2 type2 = is2.type.type; 4134 Type2 type2 = is2.type.type;
3743 if (type2 != null) { 4135 if (type2 != null) {
3744 _overrideManager.setType(element, type2); 4136 override(element, getType(element), type2);
3745 } 4137 }
3746 } 4138 }
3747 } 4139 }
3748 } else if (condition is BinaryExpression) { 4140 } else if (condition is BinaryExpression) {
3749 BinaryExpression binary = condition as BinaryExpression; 4141 BinaryExpression binary = condition as BinaryExpression;
3750 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { 4142 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) {
3751 propagateFalseState(binary.leftOperand); 4143 propagateFalseState(binary.leftOperand);
3752 propagateFalseState(binary.rightOperand); 4144 propagateFalseState(binary.rightOperand);
3753 } 4145 }
3754 } 4146 }
3755 } 4147 }
3756 /** 4148 /**
3757 * Propagate any type information that results from knowing that the given con dition will have 4149 * Propagate any type information that results from knowing that the given con dition will have
3758 * evaluated to 'true'. 4150 * evaluated to 'true'.
3759 * @param condition the condition that will have evaluated to 'true' 4151 * @param condition the condition that will have evaluated to 'true'
3760 */ 4152 */
3761 void propagateTrueState(Expression condition) { 4153 void propagateTrueState(Expression condition) {
3762 while (condition is ParenthesizedExpression) { 4154 while (condition is ParenthesizedExpression) {
3763 condition = ((condition as ParenthesizedExpression)).expression; 4155 condition = ((condition as ParenthesizedExpression)).expression;
3764 } 4156 }
3765 if (condition is IsExpression) { 4157 if (condition is IsExpression) {
3766 IsExpression is2 = condition as IsExpression; 4158 IsExpression is2 = condition as IsExpression;
3767 if (is2.notOperator == null) { 4159 if (is2.notOperator == null) {
3768 Element element = getOverridableElement(is2.expression); 4160 VariableElement element = getOverridableElement(is2.expression);
3769 if (element != null) { 4161 if (element != null) {
3770 Type2 type2 = is2.type.type; 4162 Type2 type2 = is2.type.type;
3771 if (type2 != null) { 4163 if (type2 != null) {
3772 _overrideManager.setType(element, type2); 4164 override(element, getType(element), type2);
3773 } 4165 }
3774 } 4166 }
3775 } 4167 }
3776 } else if (condition is BinaryExpression) { 4168 } else if (condition is BinaryExpression) {
3777 BinaryExpression binary = condition as BinaryExpression; 4169 BinaryExpression binary = condition as BinaryExpression;
3778 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { 4170 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) {
3779 propagateTrueState(binary.leftOperand); 4171 propagateTrueState(binary.leftOperand);
3780 propagateTrueState(binary.rightOperand); 4172 propagateTrueState(binary.rightOperand);
3781 } 4173 }
3782 } 4174 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3831 * The scope used to resolve labels for {@code break} and {@code continue} sta tements, or{@code null} if no labels have been defined in the current context. 4223 * The scope used to resolve labels for {@code break} and {@code continue} sta tements, or{@code null} if no labels have been defined in the current context.
3832 */ 4224 */
3833 LabelScope _labelScope; 4225 LabelScope _labelScope;
3834 /** 4226 /**
3835 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 4227 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3836 * @param library the library containing the compilation unit being resolved 4228 * @param library the library containing the compilation unit being resolved
3837 * @param source the source representing the compilation unit being visited 4229 * @param source the source representing the compilation unit being visited
3838 * @param typeProvider the object used to access the types from the core libra ry 4230 * @param typeProvider the object used to access the types from the core libra ry
3839 */ 4231 */
3840 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2 ) { 4232 ScopedVisitor.con1(Library library, Source source2, TypeProvider typeProvider2 ) {
3841 _jtd_constructor_267_impl(library, source2, typeProvider2); 4233 _jtd_constructor_268_impl(library, source2, typeProvider2);
3842 } 4234 }
3843 _jtd_constructor_267_impl(Library library, Source source2, TypeProvider typePr ovider2) { 4235 _jtd_constructor_268_impl(Library library, Source source2, TypeProvider typePr ovider2) {
3844 this._definingLibrary = library.libraryElement; 4236 this._definingLibrary = library.libraryElement;
3845 this._source = source2; 4237 this._source = source2;
3846 LibraryScope libraryScope2 = library.libraryScope; 4238 LibraryScope libraryScope2 = library.libraryScope;
3847 this._errorListener = libraryScope2.errorListener; 4239 this._errorListener = libraryScope2.errorListener;
3848 this._nameScope = libraryScope2; 4240 this._nameScope = libraryScope2;
3849 this._typeProvider = typeProvider2; 4241 this._typeProvider = typeProvider2;
3850 } 4242 }
3851 /** 4243 /**
3852 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 4244 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3853 * @param definingLibrary the element for the library containing the compilati on unit being 4245 * @param definingLibrary the element for the library containing the compilati on unit being
3854 * visited 4246 * visited
3855 * @param source the source representing the compilation unit being visited 4247 * @param source the source representing the compilation unit being visited
3856 * @param typeProvider the object used to access the types from the core libra ry 4248 * @param typeProvider the object used to access the types from the core libra ry
3857 * @param errorListener the error listener that will be informed of any errors that are found 4249 * @param errorListener the error listener that will be informed of any errors that are found
3858 * during resolution 4250 * during resolution
3859 */ 4251 */
3860 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid er typeProvider2, AnalysisErrorListener errorListener2) { 4252 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source2, TypeProvid er typeProvider2, AnalysisErrorListener errorListener2) {
3861 _jtd_constructor_268_impl(definingLibrary2, source2, typeProvider2, errorLis tener2); 4253 _jtd_constructor_269_impl(definingLibrary2, source2, typeProvider2, errorLis tener2);
3862 } 4254 }
3863 _jtd_constructor_268_impl(LibraryElement definingLibrary2, Source source2, Typ eProvider typeProvider2, AnalysisErrorListener errorListener2) { 4255 _jtd_constructor_269_impl(LibraryElement definingLibrary2, Source source2, Typ eProvider typeProvider2, AnalysisErrorListener errorListener2) {
3864 this._definingLibrary = definingLibrary2; 4256 this._definingLibrary = definingLibrary2;
3865 this._source = source2; 4257 this._source = source2;
3866 this._errorListener = errorListener2; 4258 this._errorListener = errorListener2;
3867 this._nameScope = new LibraryScope(definingLibrary2, errorListener2); 4259 this._nameScope = new LibraryScope(definingLibrary2, errorListener2);
3868 this._typeProvider = typeProvider2; 4260 this._typeProvider = typeProvider2;
3869 } 4261 }
3870 /** 4262 /**
3871 * Return the library element for the library containing the compilation unit being resolved. 4263 * Return the library element for the library containing the compilation unit being resolved.
3872 * @return the library element for the library containing the compilation unit being resolved 4264 * @return the library element for the library containing the compilation unit being resolved
3873 */ 4265 */
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3952 _labelScope = outerScope; 4344 _labelScope = outerScope;
3953 } 4345 }
3954 return null; 4346 return null;
3955 } 4347 }
3956 Object visitForEachStatement(ForEachStatement node) { 4348 Object visitForEachStatement(ForEachStatement node) {
3957 LabelScope outerLabelScope = _labelScope; 4349 LabelScope outerLabelScope = _labelScope;
3958 _labelScope = new LabelScope.con1(outerLabelScope, false, false); 4350 _labelScope = new LabelScope.con1(outerLabelScope, false, false);
3959 Scope outerNameScope = _nameScope; 4351 Scope outerNameScope = _nameScope;
3960 _nameScope = new EnclosedScope(_nameScope); 4352 _nameScope = new EnclosedScope(_nameScope);
3961 try { 4353 try {
3962 super.visitForEachStatement(node); 4354 visitForEachStatementInScope(node);
3963 } finally { 4355 } finally {
3964 _nameScope = outerNameScope; 4356 _nameScope = outerNameScope;
3965 _labelScope = outerLabelScope; 4357 _labelScope = outerLabelScope;
3966 } 4358 }
3967 return null; 4359 return null;
3968 } 4360 }
3969 Object visitForStatement(ForStatement node) { 4361 Object visitForStatement(ForStatement node) {
3970 LabelScope outerLabelScope = _labelScope; 4362 LabelScope outerLabelScope = _labelScope;
3971 _labelScope = new LabelScope.con1(outerLabelScope, false, false); 4363 _labelScope = new LabelScope.con1(outerLabelScope, false, false);
3972 Scope outerNameScope = _nameScope; 4364 Scope outerNameScope = _nameScope;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
4108 * @return the name scope in which the current node is being resolved 4500 * @return the name scope in which the current node is being resolved
4109 */ 4501 */
4110 Scope get nameScope => _nameScope; 4502 Scope get nameScope => _nameScope;
4111 /** 4503 /**
4112 * Report an error with the given error code and arguments. 4504 * Report an error with the given error code and arguments.
4113 * @param errorCode the error code of the error to be reported 4505 * @param errorCode the error code of the error to be reported
4114 * @param node the node specifying the location of the error 4506 * @param node the node specifying the location of the error
4115 * @param arguments the arguments to the error, used to compose the error mess age 4507 * @param arguments the arguments to the error, used to compose the error mess age
4116 */ 4508 */
4117 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) { 4509 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) {
4118 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len gth, errorCode, [arguments])); 4510 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len gth, errorCode, arguments));
4119 } 4511 }
4120 /** 4512 /**
4121 * Report an error with the given error code and arguments. 4513 * Report an error with the given error code and arguments.
4122 * @param errorCode the error code of the error to be reported 4514 * @param errorCode the error code of the error to be reported
4123 * @param token the token specifying the location of the error 4515 * @param token the token specifying the location of the error
4124 * @param arguments the arguments to the error, used to compose the error mess age 4516 * @param arguments the arguments to the error, used to compose the error mess age
4125 */ 4517 */
4126 void reportError3(ErrorCode errorCode, sc.Token token, List<Object> arguments) { 4518 void reportError3(ErrorCode errorCode, sc.Token token, List<Object> arguments) {
4127 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l ength, errorCode, [arguments])); 4519 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l ength, errorCode, arguments));
4520 }
4521 /**
4522 * Visit the given statement after it's scope has been created. This replaces the normal call to
4523 * the inherited visit method so that ResolverVisitor can intervene when type propagation is
4524 * enabled.
4525 * @param node the statement to be visited
4526 */
4527 void visitForEachStatementInScope(ForEachStatement node) {
4528 super.visitForEachStatement(node);
4128 } 4529 }
4129 /** 4530 /**
4130 * Add scopes for each of the given labels. 4531 * Add scopes for each of the given labels.
4131 * @param labels the labels for which new scopes are to be added 4532 * @param labels the labels for which new scopes are to be added
4132 * @return the scope that was in effect before the new scopes were added 4533 * @return the scope that was in effect before the new scopes were added
4133 */ 4534 */
4134 LabelScope addScopesFor(NodeList<Label> labels) { 4535 LabelScope addScopesFor(NodeList<Label> labels) {
4135 LabelScope outerScope = _labelScope; 4536 LabelScope outerScope = _labelScope;
4136 for (Label label in labels) { 4537 for (Label label in labels) {
4137 SimpleIdentifier labelNameNode = label.label; 4538 SimpleIdentifier labelNameNode = label.label;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
4303 * <p> 4704 * <p>
4304 * ... an assignment of the form <i>e<sub>1</sub>.v = e<sub>2</sub></i> ... 4705 * ... an assignment of the form <i>e<sub>1</sub>.v = e<sub>2</sub></i> ...
4305 * <p> 4706 * <p>
4306 * Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static typ e warning if 4707 * Let <i>T</i> be the static type of <i>e<sub>1</sub></i>. It is a static typ e warning if
4307 * <i>T</i> does not have an accessible instance setter named <i>v=</i>. It is a static type 4708 * <i>T</i> does not have an accessible instance setter named <i>v=</i>. It is a static type
4308 * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to < i>T</i>. 4709 * warning if the static type of <i>e<sub>2</sub></i> may not be assigned to < i>T</i>.
4309 * <p> 4710 * <p>
4310 * The static type of the expression <i>e<sub>1</sub>.v = e<sub>2</sub></i> is the static type of 4711 * The static type of the expression <i>e<sub>1</sub>.v = e<sub>2</sub></i> is the static type of
4311 * <i>e<sub>2</sub></i>. 4712 * <i>e<sub>2</sub></i>.
4312 * <p> 4713 * <p>
4313 * ... an assignment of the form <i>e<sub>1</sub>[e<sub>2</sub>] = e<sub>3</su b></i> ... 4714 * ... an assignment of the form <i>e<sub>1</sub>[[e<sub>2</sub>]] = e<sub>3</ sub></i> ...
4314 * <p> 4715 * <p>
4315 * The static type of the expression <i>e<sub>1</sub>[e<sub>2</sub>] = e<sub>3 </sub></i> is the 4716 * The static type of the expression <i>e<sub>1</sub>[[e<sub>2</sub>]] = e<sub >3</sub></i> is the
4316 * static type of <i>e<sub>3</sub></i>. 4717 * static type of <i>e<sub>3</sub></i>.
4317 * <p> 4718 * <p>
4318 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v op e</i>. A compound 4719 * A compound assignment of the form <i>v op= e</i> is equivalent to <i>v = v op e</i>. A compound
4319 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e< /i>. A compound 4720 * assignment of the form <i>C.v op= e</i> is equivalent to <i>C.v = C.v op e< /i>. A compound
4320 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale nt to <i>((x) => x.v 4721 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale nt to <i>((x) => x.v
4321 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha t is not used in 4722 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha t is not used in
4322 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op= 4723 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[[e <sub>2</sub>]] op=
4323 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su b>)(e<sub>1</sub>, 4724 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[[i]] = a[[i]] op e<sub>3 </sub>)(e<sub>1</sub>,
4324 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in 4725 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in
4325 * <i>e<sub>3</sub></i>. </blockquote> 4726 * <i>e<sub>3</sub></i>. </blockquote>
4326 */ 4727 */
4327 Object visitAssignmentExpression(AssignmentExpression node) { 4728 Object visitAssignmentExpression(AssignmentExpression node) {
4328 sc.TokenType operator2 = node.operator.type; 4729 sc.TokenType operator2 = node.operator.type;
4329 if (operator2 != sc.TokenType.EQ) { 4730 if (operator2 != sc.TokenType.EQ) {
4330 return recordReturnType(node, node.element); 4731 return recordReturnType(node, node.element);
4331 } 4732 }
4332 Type2 rightType = getType2(node.rightHandSide); 4733 Type2 rightType = getType2(node.rightHandSide);
4333 if (USE_TYPE_PROPAGATION) { 4734 if (USE_TYPE_PROPAGATION) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
4428 */ 4829 */
4429 Object visitDoubleLiteral(DoubleLiteral node) => recordType(node, _typeProvide r.doubleType); 4830 Object visitDoubleLiteral(DoubleLiteral node) => recordType(node, _typeProvide r.doubleType);
4430 Object visitFunctionDeclaration(FunctionDeclaration node) { 4831 Object visitFunctionDeclaration(FunctionDeclaration node) {
4431 FunctionExpression function = node.functionExpression; 4832 FunctionExpression function = node.functionExpression;
4432 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl; 4833 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl;
4433 setTypeInformation(functionType, computeReturnType(node), function.parameter s); 4834 setTypeInformation(functionType, computeReturnType(node), function.parameter s);
4434 return recordType(function, functionType); 4835 return recordType(function, functionType);
4435 } 4836 }
4436 /** 4837 /**
4437 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun ction literal of the 4838 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun ction literal of the
4438 * form <i>(T<sub>1</sub> a<sub>1</sub>, &hellip;, T<sub>n</sub> a<sub>n</sub> , [T<sub>n+1</sub> 4839 * form <i>(T<sub>1</sub> a<sub>1</sub>, &hellip;, T<sub>n</sub> a<sub>n</sub> , [[T<sub>n+1</sub>
4439 * x<sub>n+1</sub> = d1, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub> = dk]) => e </i> is 4840 * x<sub>n+1</sub> = d1, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub> = dk]]) => e</i> is
4440 * <i>(T<sub>1</sub>, &hellip;, Tn, [T<sub>n+1</sub> x<sub>n+1</sub>, &hellip; , T<sub>n+k</sub> 4841 * <i>(T<sub>1</sub>, &hellip;, Tn, [[T<sub>n+1</sub> x<sub>n+1</sub>, &hellip ;, T<sub>n+k</sub>
4441 * x<sub>n+k</sub>]) &rarr; T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is t he static type of 4842 * x<sub>n+k</sub>]]) &rarr; T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is the static type of
4442 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is 4843 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is
4443 * considered to have been specified as dynamic. 4844 * considered to have been specified as dynamic.
4444 * <p> 4845 * <p>
4445 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;, 4846 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;,
4446 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip ;, T<sub>n+k</sub> 4847 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip ;, T<sub>n+k</sub>
4447 * x<sub>n+k</sub> : dk}) => e</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</su b>, {T<sub>n+1</sub> 4848 * x<sub>n+k</sub> : dk}) => e</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</su b>, {T<sub>n+1</sub>
4448 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; T<sub>0 </sub></i>, where 4849 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; T<sub>0 </sub></i>, where
4449 * <i>T<sub>0</sub></i> is the static type of <i>e</i>. In any case where <i>T <sub>i</sub>, 1 4850 * <i>T<sub>0</sub></i> is the static type of <i>e</i>. In any case where <i>T <sub>i</sub>, 1
4450 * &lt;= i &lt;= n</i>, is not specified, it is considered to have been specif ied as dynamic. 4851 * &lt;= i &lt;= n</i>, is not specified, it is considered to have been specif ied as dynamic.
4451 * <p> 4852 * <p>
4452 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;, 4853 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;,
4453 * T<sub>n</sub> a<sub>n</sub>, [T<sub>n+1</sub> x<sub>n+1</sub> = d1, &hellip ;, T<sub>n+k</sub> 4854 * T<sub>n</sub> a<sub>n</sub>, [[T<sub>n+1</sub> x<sub>n+1</sub> = d1, &helli p;, T<sub>n+k</sub>
4454 * x<sub>n+k</sub> = dk]) {s}</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub >, [T<sub>n+1</sub> 4855 * x<sub>n+k</sub> = dk]]) {s}</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</su b>, [[T<sub>n+1</sub>
4455 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>]) &rarr; dynamic </i>. In any case 4856 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>]]) &rarr; dynami c</i>. In any case
4456 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been 4857 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been
4457 * specified as dynamic. 4858 * specified as dynamic.
4458 * <p> 4859 * <p>
4459 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;, 4860 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;,
4460 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip ;, T<sub>n+k</sub> 4861 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip ;, T<sub>n+k</sub>
4461 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub >, {T<sub>n+1</sub> 4862 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub >, {T<sub>n+1</sub>
4462 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; dynamic </i>. In any case 4863 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; dynamic </i>. In any case
4463 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been 4864 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been
4464 * specified as dynamic.</blockquote> 4865 * specified as dynamic.</blockquote>
4465 */ 4866 */
(...skipping 13 matching lines...) Expand all
4479 * <p> 4880 * <p>
4480 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be 4881 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be
4481 * assigned to a function type. 4882 * assigned to a function type.
4482 * <p> 4883 * <p>
4483 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the 4884 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the
4484 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e> 4885 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e>
4485 */ 4886 */
4486 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => recordReturnType(node, node.element); 4887 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => recordReturnType(node, node.element);
4487 /** 4888 /**
4488 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form 4889 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form
4489 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method 4890 * <i>e<sub>1</sub>[[e<sub>2</sub>]]</i> is evaluated as a method invocation o f the operator method
4490 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote> 4891 * <i>[[]]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bl ockquote>
4491 */ 4892 */
4492 Object visitIndexExpression(IndexExpression node) { 4893 Object visitIndexExpression(IndexExpression node) {
4493 if (node.inSetterContext()) { 4894 if (node.inSetterContext()) {
4494 return recordArgumentType(node, node.element); 4895 return recordArgumentType(node, node.element);
4495 } 4896 }
4496 return recordReturnType(node, node.element); 4897 return recordReturnType(node, node.element);
4497 } 4898 }
4498 /** 4899 /**
4499 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of 4900 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of
4500 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new 4901 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new
(...skipping 24 matching lines...) Expand all
4525 Object visitIntegerLiteral(IntegerLiteral node) => recordType(node, _typeProvi der.intType); 4926 Object visitIntegerLiteral(IntegerLiteral node) => recordType(node, _typeProvi der.intType);
4526 /** 4927 /**
4527 * The Dart Language Specification, 12.31: <blockquote>It is a static warning if <i>T</i> does not 4928 * The Dart Language Specification, 12.31: <blockquote>It is a static warning if <i>T</i> does not
4528 * denote a type available in the current lexical scope. 4929 * denote a type available in the current lexical scope.
4529 * <p> 4930 * <p>
4530 * The static type of an is-expression is {@code bool}.</blockquote> 4931 * The static type of an is-expression is {@code bool}.</blockquote>
4531 */ 4932 */
4532 Object visitIsExpression(IsExpression node) => recordType(node, _typeProvider. boolType); 4933 Object visitIsExpression(IsExpression node) => recordType(node, _typeProvider. boolType);
4533 /** 4934 /**
4534 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis t literal of the 4935 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis t literal of the
4535 * form <i><b>const</b> &lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> or the form 4936 * form <i><b>const</b> &lt;E&gt;[[e<sub>1</sub>, &hellip;, e<sub>n</sub>]]</i > or the form
4536 * <i>&lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; E&gt;}. The static 4937 * <i>&lt;E&gt;[[e<sub>1</sub>, &hellip;, e<sub>n</sub>]]</i> is {@code List&l t;E&gt;}. The static
4537 * type a list literal of the form <i><b>const</b> [e<sub>1</sub>, &hellip;, e <sub>n</sub>]</i> or 4938 * type a list literal of the form <i><b>const</b> [[e<sub>1</sub>, &hellip;, e<sub>n</sub>]]</i> or
4538 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; dynamic&gt;}.</blockquote> 4939 * the form <i>[[e<sub>1</sub>, &hellip;, e<sub>n</sub>]]</i> is {@code List&l t;dynamic&gt;}.</blockquote>
4539 */ 4940 */
4540 Object visitListLiteral(ListLiteral node) { 4941 Object visitListLiteral(ListLiteral node) {
4541 TypeArgumentList typeArguments2 = node.typeArguments; 4942 TypeArgumentList typeArguments2 = node.typeArguments;
4542 if (typeArguments2 != null) { 4943 if (typeArguments2 != null) {
4543 NodeList<TypeName> arguments2 = typeArguments2.arguments; 4944 NodeList<TypeName> arguments2 = typeArguments2.arguments;
4544 if (arguments2 != null && arguments2.length == 1) { 4945 if (arguments2 != null && arguments2.length == 1) {
4545 TypeName argumentType = arguments2[0]; 4946 TypeName argumentType = arguments2[0];
4546 return recordType(node, _typeProvider.listType.substitute5(<Type2> [getT ype4(argumentType)])); 4947 return recordType(node, _typeProvider.listType.substitute5(<Type2> [getT ype4(argumentType)]));
4547 } 4948 }
4548 } 4949 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4672 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form 5073 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form
4673 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1; 5074 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1;
4674 * return r}()</i>. 5075 * return r}()</i>.
4675 * <p> 5076 * <p>
4676 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r = C.v; C.v = r + 1; 5077 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r = C.v; C.v = r + 1;
4677 * return r}()</i>. 5078 * return r}()</i>.
4678 * <p> 5079 * <p>
4679 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var r = x.v; x.v = r + 5080 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var r = x.v; x.v = r +
4680 * 1; return r}(e1)</i>. 5081 * 1; return r}(e1)</i>.
4681 * <p> 5082 * <p>
4682 * A postfix expression of the form <i>e1[e2]++</i> is equivalent to <i>(a, i) {var r = a[i]; a[i] 5083 * A postfix expression of the form <i>e1[[e2]]++</i> is equivalent to <i>(a, i){var r = a[[i]]; a[[i]]
4683 * = r + 1; return r}(e1, e2)</i> 5084 * = r + 1; return r}(e1, e2)</i>
4684 * <p> 5085 * <p>
4685 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie r, is equivalent to 5086 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie r, is equivalent to
4686 * <i>(){var r = v; v = r - 1; return r}()</i>. 5087 * <i>(){var r = v; v = r - 1; return r}()</i>.
4687 * <p> 5088 * <p>
4688 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r = C.v; C.v = r - 1; 5089 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r = C.v; C.v = r - 1;
4689 * return r}()</i>. 5090 * return r}()</i>.
4690 * <p> 5091 * <p>
4691 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var r = x.v; x.v = r - 5092 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var r = x.v; x.v = r -
4692 * 1; return r}(e1)</i>. 5093 * 1; return r}(e1)</i>.
4693 * <p> 5094 * <p>
4694 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i] 5095 * A postfix expression of the form <i>e1[[e2]]--</i> is equivalent to <i>(a, i){var r = a[[i]]; a[[i]]
4695 * = r - 1; return r}(e1, e2)</i></blockquote> 5096 * = r - 1; return r}(e1, e2)</i></blockquote>
4696 */ 5097 */
4697 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT ype2(node.operand)); 5098 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT ype2(node.operand));
4698 /** 5099 /**
4699 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. 5100 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}.
4700 */ 5101 */
4701 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 5102 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
4702 SimpleIdentifier prefixedIdentifier = node.identifier; 5103 SimpleIdentifier prefixedIdentifier = node.identifier;
4703 Element element2 = prefixedIdentifier.element; 5104 Element element2 = prefixedIdentifier.element;
4704 if (element2 == null) { 5105 if (element2 == null) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4751 * The Dart Language Specification, 12.13: <blockquote> Property extraction al lows for a member of 5152 * The Dart Language Specification, 12.13: <blockquote> Property extraction al lows for a member of
4752 * an object to be concisely extracted from the object. If <i>o</i> is an obje ct, and if <i>m</i> 5153 * an object to be concisely extracted from the object. If <i>o</i> is an obje ct, and if <i>m</i>
4753 * is the name of a method member of <i>o</i>, then 5154 * is the name of a method member of <i>o</i>, then
4754 * <ul> 5155 * <ul>
4755 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, &hellip;, r<sub>n</sub>, 5156 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, &hellip;, r<sub>n</sub>,
4756 * {p<sub>1</sub> : d<sub>1</sub>, &hellip;, p<sub>k</sub> : d<sub>k</sub>}){r eturn 5157 * {p<sub>1</sub> : d<sub>1</sub>, &hellip;, p<sub>k</sub> : d<sub>k</sub>}){r eturn
4757 * o.m(r<sub>1</sub>, &hellip;, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, & hellip;, 5158 * o.m(r<sub>1</sub>, &hellip;, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, & hellip;,
4758 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i> r<sub>1</sub>, 5159 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i> r<sub>1</sub>,
4759 * &hellip;, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> &hellip; p<sub>k</sub></i> 5160 * &hellip;, r<sub>n</sub></i>, and named parameters <i>p<sub>1</sub> &hellip; p<sub>k</sub></i>
4760 * with defaults <i>d<sub>1</sub>, &hellip;, d<sub>k</sub></i>.</li> 5161 * with defaults <i>d<sub>1</sub>, &hellip;, d<sub>k</sub></i>.</li>
4761 * <li><i>(r<sub>1</sub>, &hellip;, r<sub>n</sub>, [p<sub>1</sub> = d<sub>1</s ub>, &hellip;, 5162 * <li><i>(r<sub>1</sub>, &hellip;, r<sub>n</sub>, [[p<sub>1</sub> = d<sub>1</ sub>, &hellip;,
4762 * p<sub>k</sub> = d<sub>k</sub>]){return o.m(r<sub>1</sub>, &hellip;, r<sub>n </sub>, 5163 * p<sub>k</sub> = d<sub>k</sub>]]){return o.m(r<sub>1</sub>, &hellip;, r<sub> n</sub>,
4763 * p<sub>1</sub>, &hellip;, p<sub>k</sub>);}</i> if <i>m</i> has required para meters 5164 * p<sub>1</sub>, &hellip;, p<sub>k</sub>);}</i> if <i>m</i> has required para meters
4764 * <i>r<sub>1</sub>, &hellip;, r<sub>n</sub></i>, and optional positional para meters 5165 * <i>r<sub>1</sub>, &hellip;, r<sub>n</sub></i>, and optional positional para meters
4765 * <i>p<sub>1</sub> &hellip; p<sub>k</sub></i> with defaults <i>d<sub>1</sub>, &hellip;, 5166 * <i>p<sub>1</sub> &hellip; p<sub>k</sub></i> with defaults <i>d<sub>1</sub>, &hellip;,
4766 * d<sub>k</sub></i>.</li> 5167 * d<sub>k</sub></i>.</li>
4767 * </ul> 5168 * </ul>
4768 * Otherwise, if <i>m</i> is the name of a getter member of <i>o</i> (declared implicitly or 5169 * Otherwise, if <i>m</i> is the name of a getter member of <i>o</i> (declared implicitly or
4769 * explicitly) then <i>o.m</i> evaluates to the result of invoking the getter. </blockquote> 5170 * explicitly) then <i>o.m</i> evaluates to the result of invoking the getter. </blockquote>
4770 * <p> 5171 * <p>
4771 * The Dart Language Specification, 12.17: <blockquote> ... a getter invocatio n <i>i</i> of the 5172 * The Dart Language Specification, 12.17: <blockquote> ... a getter invocatio n <i>i</i> of the
4772 * form <i>e.m</i> ... 5173 * form <i>e.m</i> ...
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
5034 if (nameMap != null) { 5435 if (nameMap != null) {
5035 argumentValue = nameMap[argumentValue.toLowerCase()]; 5436 argumentValue = nameMap[argumentValue.toLowerCase()];
5036 } 5437 }
5037 ClassElement returnType = library.getType(argumentValue); 5438 ClassElement returnType = library.getType(argumentValue);
5038 if (returnType != null) { 5439 if (returnType != null) {
5039 return returnType.type; 5440 return returnType.type;
5040 } 5441 }
5041 } 5442 }
5042 return null; 5443 return null;
5043 } 5444 }
5445 /**
5446 * Return the type of the given (overridable) element.
5447 * @param element the element whose type is to be returned
5448 * @return the type of the given element
5449 */
5044 Type2 getType(Element element) { 5450 Type2 getType(Element element) {
5045 if (element is LocalVariableElement) { 5451 if (element is LocalVariableElement) {
5046 return ((element as LocalVariableElement)).type; 5452 return ((element as LocalVariableElement)).type;
5047 } else if (element is ParameterElement) { 5453 } else if (element is ParameterElement) {
5048 return ((element as ParameterElement)).type; 5454 return ((element as ParameterElement)).type;
5049 } 5455 }
5050 return null; 5456 return null;
5051 } 5457 }
5052 /** 5458 /**
5053 * Return the type of the given expression that is to be used for type analysi s. 5459 * Return the type of the given expression that is to be used for type analysi s.
5054 * @param expression the expression whose type is to be returned 5460 * @param expression the expression whose type is to be returned
5055 * @return the type of the given expression 5461 * @return the type of the given expression
5056 */ 5462 */
5057 Type2 getType2(Expression expression) { 5463 Type2 getType2(Expression expression) {
5058 Type2 type = expression.staticType; 5464 Type2 type = expression.staticType;
5059 if (type == null) { 5465 if (type == null) {
5060 return _dynamicType; 5466 return _dynamicType;
5061 } 5467 }
5062 return type; 5468 return type;
5063 } 5469 }
5064 /** 5470 /**
5065 * Return the type that should be recorded for a node that resolved to the giv en accessor. 5471 * Return the type that should be recorded for a node that resolved to the giv en accessor.
5066 * @param accessor the accessor that the node resolved to 5472 * @param accessor the accessor that the node resolved to
5067 * @param context if the accessor element has context [by being the RHS of a{@ link PrefixedIdentifier} or {@link PropertyAccess}], and the return type of the 5473 * @param context if the accessor element has context [[by being the RHS of a{ @link PrefixedIdentifier} or {@link PropertyAccess}]], and the return type of th e
5068 * accessor is a parameter type, then the type of the LHS can be used to get m ore 5474 * accessor is a parameter type, then the type of the LHS can be used to get m ore
5069 * specific type information 5475 * specific type information
5070 * @return the type that should be recorded for a node that resolved to the gi ven accessor 5476 * @return the type that should be recorded for a node that resolved to the gi ven accessor
5071 */ 5477 */
5072 Type2 getType3(PropertyAccessorElement accessor, Type2 context) { 5478 Type2 getType3(PropertyAccessorElement accessor, Type2 context) {
5073 FunctionType functionType = accessor.type; 5479 FunctionType functionType = accessor.type;
5074 if (functionType == null) { 5480 if (functionType == null) {
5075 return _dynamicType; 5481 return _dynamicType;
5076 } 5482 }
5077 if (accessor.isSetter()) { 5483 if (accessor.isSetter()) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5131 return parent2 is TypeName || (parent2 is PrefixedIdentifier && (parent2.par ent is TypeName || identical(((parent2 as PrefixedIdentifier)).prefix, node))) | | (parent2 is PropertyAccess && identical(((parent2 as PropertyAccess)).target, node)) || (parent2 is MethodInvocation && identical(node, ((parent2 as MethodInv ocation)).target)); 5537 return parent2 is TypeName || (parent2 is PrefixedIdentifier && (parent2.par ent is TypeName || identical(((parent2 as PrefixedIdentifier)).prefix, node))) | | (parent2 is PropertyAccess && identical(((parent2 as PropertyAccess)).target, node)) || (parent2 is MethodInvocation && identical(node, ((parent2 as MethodInv ocation)).target));
5132 } 5538 }
5133 /** 5539 /**
5134 * If it is appropriate to do so, override the type of the given element. Use the static type and 5540 * If it is appropriate to do so, override the type of the given element. Use the static type and
5135 * inferred type of the element to determine whether or not it is appropriate. 5541 * inferred type of the element to determine whether or not it is appropriate.
5136 * @param element the element whose type might be overridden 5542 * @param element the element whose type might be overridden
5137 * @param staticType the static type of the element 5543 * @param staticType the static type of the element
5138 * @param inferredType the inferred type of the element 5544 * @param inferredType the inferred type of the element
5139 */ 5545 */
5140 void override(VariableElement element, Type2 staticType, Type2 inferredType) { 5546 void override(VariableElement element, Type2 staticType, Type2 inferredType) {
5141 if (identical(inferredType, BottomTypeImpl.instance) || element is! Variable Element) { 5547 if (identical(inferredType, BottomTypeImpl.instance)) {
5142 return; 5548 return;
5143 } 5549 }
5144 if (element is PropertyInducingElement) { 5550 if (element is PropertyInducingElement) {
5145 PropertyInducingElement variable = element as PropertyInducingElement; 5551 PropertyInducingElement variable = element as PropertyInducingElement;
5146 if (!variable.isConst() && !variable.isFinal()) { 5552 if (!variable.isConst() && !variable.isFinal()) {
5147 return; 5553 return;
5148 } 5554 }
5149 } 5555 }
5150 if (staticType == null || (inferredType != null && inferredType.isMoreSpecif icThan(staticType))) { 5556 if (staticType == null || (inferredType != null && inferredType.isMoreSpecif icThan(staticType))) {
5151 _overrideManager.setType(element, inferredType); 5557 _overrideManager.setType(element, inferredType);
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
5546 * The type representing the type 'dynamic'. 5952 * The type representing the type 'dynamic'.
5547 */ 5953 */
5548 Type2 _dynamicType; 5954 Type2 _dynamicType;
5549 /** 5955 /**
5550 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 5956 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
5551 * @param library the library containing the compilation unit being resolved 5957 * @param library the library containing the compilation unit being resolved
5552 * @param source the source representing the compilation unit being visited 5958 * @param source the source representing the compilation unit being visited
5553 * @param typeProvider the object used to access the types from the core libra ry 5959 * @param typeProvider the object used to access the types from the core libra ry
5554 */ 5960 */
5555 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv ider) : super.con1(library, source, typeProvider) { 5961 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv ider) : super.con1(library, source, typeProvider) {
5556 _jtd_constructor_273_impl(library, source, typeProvider); 5962 _jtd_constructor_274_impl(library, source, typeProvider);
5557 } 5963 }
5558 _jtd_constructor_273_impl(Library library, Source source, TypeProvider typePro vider) { 5964 _jtd_constructor_274_impl(Library library, Source source, TypeProvider typePro vider) {
5559 _dynamicType = typeProvider.dynamicType; 5965 _dynamicType = typeProvider.dynamicType;
5560 } 5966 }
5561 /** 5967 /**
5562 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 5968 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
5563 * @param definingLibrary the element for the library containing the compilati on unit being 5969 * @param definingLibrary the element for the library containing the compilati on unit being
5564 * visited 5970 * visited
5565 * @param source the source representing the compilation unit being visited 5971 * @param source the source representing the compilation unit being visited
5566 * @param typeProvider the object used to access the types from the core libra ry 5972 * @param typeProvider the object used to access the types from the core libra ry
5567 * @param errorListener the error listener that will be informed of any errors that are found 5973 * @param errorListener the error listener that will be informed of any errors that are found
5568 * during resolution 5974 * during resolution
5569 */ 5975 */
5570 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) { 5976 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) {
5571 _jtd_constructor_274_impl(definingLibrary, source, typeProvider, errorListen er); 5977 _jtd_constructor_275_impl(definingLibrary, source, typeProvider, errorListen er);
5572 } 5978 }
5573 _jtd_constructor_274_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) { 5979 _jtd_constructor_275_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) {
5574 _dynamicType = typeProvider.dynamicType; 5980 _dynamicType = typeProvider.dynamicType;
5575 } 5981 }
5576 Object visitCatchClause(CatchClause node) { 5982 Object visitCatchClause(CatchClause node) {
5577 super.visitCatchClause(node); 5983 super.visitCatchClause(node);
5578 SimpleIdentifier exception = node.exceptionParameter; 5984 SimpleIdentifier exception = node.exceptionParameter;
5579 if (exception != null) { 5985 if (exception != null) {
5580 TypeName exceptionTypeName = node.exceptionType; 5986 TypeName exceptionTypeName = node.exceptionType;
5581 Type2 exceptionType; 5987 Type2 exceptionType;
5582 if (exceptionTypeName == null) { 5988 if (exceptionTypeName == null) {
5583 exceptionType = typeProvider.objectType; 5989 exceptionType = typeProvider.objectType;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
5774 } 6180 }
5775 } 6181 }
5776 } 6182 }
5777 if (element == null) { 6183 if (element == null) {
5778 Identifier simpleIdentifier; 6184 Identifier simpleIdentifier;
5779 if (typeName is SimpleIdentifier) { 6185 if (typeName is SimpleIdentifier) {
5780 simpleIdentifier = typeName; 6186 simpleIdentifier = typeName;
5781 } else { 6187 } else {
5782 simpleIdentifier = ((typeName as PrefixedIdentifier)).prefix; 6188 simpleIdentifier = ((typeName as PrefixedIdentifier)).prefix;
5783 } 6189 }
5784 reportError(StaticWarningCode.UNDEFINED_CLASS, simpleIdentifier, [simpleId entifier.name]); 6190 if (simpleIdentifier.name == "boolean") {
6191 reportError(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, simpleIdentifier, []);
6192 } else {
6193 reportError(StaticWarningCode.UNDEFINED_CLASS, simpleIdentifier, [simple Identifier.name]);
6194 }
5785 setElement(typeName, _dynamicType.element); 6195 setElement(typeName, _dynamicType.element);
5786 typeName.staticType = _dynamicType; 6196 typeName.staticType = _dynamicType;
5787 node.type = _dynamicType; 6197 node.type = _dynamicType;
5788 return null; 6198 return null;
5789 } 6199 }
5790 Type2 type = null; 6200 Type2 type = null;
5791 if (element is ClassElement) { 6201 if (element is ClassElement) {
5792 setElement(typeName, element); 6202 setElement(typeName, element);
5793 type = ((element as ClassElement)).type; 6203 type = ((element as ClassElement)).type;
5794 } else if (element is FunctionTypeAliasElement) { 6204 } else if (element is FunctionTypeAliasElement) {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
6245 * alias. 6655 * alias.
6246 * @coverage dart.engine.resolver 6656 * @coverage dart.engine.resolver
6247 */ 6657 */
6248 class FunctionTypeScope extends EnclosedScope { 6658 class FunctionTypeScope extends EnclosedScope {
6249 /** 6659 /**
6250 * Initialize a newly created scope enclosed within another scope. 6660 * Initialize a newly created scope enclosed within another scope.
6251 * @param enclosingScope the scope in which this scope is lexically enclosed 6661 * @param enclosingScope the scope in which this scope is lexically enclosed
6252 * @param typeElement the element representing the type alias represented by t his scope 6662 * @param typeElement the element representing the type alias represented by t his scope
6253 */ 6663 */
6254 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement) : super(new EnclosedScope(enclosingScope)) { 6664 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement) : super(new EnclosedScope(enclosingScope)) {
6255 defineTypeParameters(typeElement); 6665 defineTypeVariables(typeElement);
6666 defineParameters(typeElement);
6256 } 6667 }
6257 /** 6668 /**
6258 * Define the type parameters for the function type alias. 6669 * Define the parameters for the function type alias.
6259 * @param typeElement the element representing the type represented by this sc ope 6670 * @param typeElement the element representing the type represented by this sc ope
6260 */ 6671 */
6261 void defineTypeParameters(FunctionTypeAliasElement typeElement) { 6672 void defineParameters(FunctionTypeAliasElement typeElement) {
6262 Scope parameterScope = enclosingScope; 6673 for (ParameterElement parameter in typeElement.parameters) {
6263 for (TypeVariableElement parameter in typeElement.typeVariables) { 6674 define(parameter);
6264 parameterScope.define(parameter); 6675 }
6676 }
6677 /**
6678 * Define the type variables for the function type alias.
6679 * @param typeElement the element representing the type represented by this sc ope
6680 */
6681 void defineTypeVariables(FunctionTypeAliasElement typeElement) {
6682 Scope typeVariableScope = enclosingScope;
6683 for (TypeVariableElement typeVariable in typeElement.typeVariables) {
6684 typeVariableScope.define(typeVariable);
6265 } 6685 }
6266 } 6686 }
6267 } 6687 }
6268 /** 6688 /**
6269 * Instances of the class {@code LabelScope} represent a scope in which a single label is defined. 6689 * Instances of the class {@code LabelScope} represent a scope in which a single label is defined.
6270 * @coverage dart.engine.resolver 6690 * @coverage dart.engine.resolver
6271 */ 6691 */
6272 class LabelScope { 6692 class LabelScope {
6273 /** 6693 /**
6274 * The label scope enclosing this label scope. 6694 * The label scope enclosing this label scope.
(...skipping 15 matching lines...) Expand all
6290 * The label element returned for scopes that can be the target of an unlabele d {@code break} or{@code continue}. 6710 * The label element returned for scopes that can be the target of an unlabele d {@code break} or{@code continue}.
6291 */ 6711 */
6292 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); 6712 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0));
6293 /** 6713 /**
6294 * Initialize a newly created scope to represent the potential target of an un labeled{@code break} or {@code continue}. 6714 * Initialize a newly created scope to represent the potential target of an un labeled{@code break} or {@code continue}.
6295 * @param outerScope the label scope enclosing the new label scope 6715 * @param outerScope the label scope enclosing the new label scope
6296 * @param onSwitchStatement {@code true} if this label is associated with a {@ code switch}statement 6716 * @param onSwitchStatement {@code true} if this label is associated with a {@ code switch}statement
6297 * @param onSwitchMember {@code true} if this label is associated with a {@cod e switch} member 6717 * @param onSwitchMember {@code true} if this label is associated with a {@cod e switch} member
6298 */ 6718 */
6299 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) { 6719 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) {
6300 _jtd_constructor_279_impl(outerScope, onSwitchStatement, onSwitchMember); 6720 _jtd_constructor_280_impl(outerScope, onSwitchStatement, onSwitchMember);
6301 } 6721 }
6302 _jtd_constructor_279_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) { 6722 _jtd_constructor_280_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) {
6303 _jtd_constructor_280_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); 6723 _jtd_constructor_281_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember));
6304 } 6724 }
6305 /** 6725 /**
6306 * Initialize a newly created scope to represent the given label. 6726 * Initialize a newly created scope to represent the given label.
6307 * @param outerScope the label scope enclosing the new label scope 6727 * @param outerScope the label scope enclosing the new label scope
6308 * @param label the label defined in this scope 6728 * @param label the label defined in this scope
6309 * @param element the element to which the label resolves 6729 * @param element the element to which the label resolves
6310 */ 6730 */
6311 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2) { 6731 LabelScope.con2(LabelScope outerScope2, String label2, LabelElement element2) {
6312 _jtd_constructor_280_impl(outerScope2, label2, element2); 6732 _jtd_constructor_281_impl(outerScope2, label2, element2);
6313 } 6733 }
6314 _jtd_constructor_280_impl(LabelScope outerScope2, String label2, LabelElement element2) { 6734 _jtd_constructor_281_impl(LabelScope outerScope2, String label2, LabelElement element2) {
6315 this._outerScope = outerScope2; 6735 this._outerScope = outerScope2;
6316 this._label = label2; 6736 this._label = label2;
6317 this._element = element2; 6737 this._element = element2;
6318 } 6738 }
6319 /** 6739 /**
6320 * Return the label element corresponding to the given label, or {@code null} if the given label 6740 * Return the label element corresponding to the given label, or {@code null} if the given label
6321 * is not defined in this scope. 6741 * is not defined in this scope.
6322 * @param targetLabel the label being looked up 6742 * @param targetLabel the label being looked up
6323 * @return the label element corresponding to the given label 6743 * @return the label element corresponding to the given label
6324 */ 6744 */
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
6978 /** 7398 /**
6979 * This is set to {@code true} iff the visitor is currently visiting children nodes of a{@link CatchClause}. 7399 * This is set to {@code true} iff the visitor is currently visiting children nodes of a{@link CatchClause}.
6980 * @see #visitCatchClause(CatchClause) 7400 * @see #visitCatchClause(CatchClause)
6981 */ 7401 */
6982 bool _isInCatchClause = false; 7402 bool _isInCatchClause = false;
6983 /** 7403 /**
6984 * This is set to {@code true} iff the visitor is currently visiting code in t he SDK. 7404 * This is set to {@code true} iff the visitor is currently visiting code in t he SDK.
6985 */ 7405 */
6986 bool _isInSystemLibrary = false; 7406 bool _isInSystemLibrary = false;
6987 /** 7407 /**
7408 * The class containing the AST nodes being visited, or {@code null} if we are not in the scope of
7409 * a class.
7410 */
7411 ClassElement _enclosingClass;
7412 /**
6988 * The method or function that we are currently visiting, or {@code null} if w e are not inside a 7413 * The method or function that we are currently visiting, or {@code null} if w e are not inside a
6989 * method or function. 7414 * method or function.
6990 */ 7415 */
6991 ExecutableElement _enclosingFunction; 7416 ExecutableElement _enclosingFunction;
6992 /** 7417 /**
6993 * This map is initialized when visiting the contents of a class declaration. If the visitor is 7418 * This map is initialized when visiting the contents of a class declaration. If the visitor is
6994 * not in an enclosing class declaration, then the map is set to {@code null}. 7419 * not in an enclosing class declaration, then the map is set to {@code null}.
6995 * <p> 7420 * <p>
6996 * When set the map maps the set of {@link FieldElement}s in the class to an{@ link INIT_STATE#NOT_INIT} or {@link INIT_STATE#INIT_IN_DECLARATION}. <code>check For*</code> 7421 * When set the map maps the set of {@link FieldElement}s in the class to an{@ link INIT_STATE#NOT_INIT} or {@link INIT_STATE#INIT_IN_DECLARATION}. <code>check For*</code>
6997 * methods, specifically {@link #checkForAllFinalInitializedErrorCodes(Constru ctorDeclaration)}, 7422 * methods, specifically {@link #checkForAllFinalInitializedErrorCodes(Constru ctorDeclaration)},
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7030 Object visitCatchClause(CatchClause node) { 7455 Object visitCatchClause(CatchClause node) {
7031 bool previousIsInCatchClause = _isInCatchClause; 7456 bool previousIsInCatchClause = _isInCatchClause;
7032 try { 7457 try {
7033 _isInCatchClause = true; 7458 _isInCatchClause = true;
7034 return super.visitCatchClause(node); 7459 return super.visitCatchClause(node);
7035 } finally { 7460 } finally {
7036 _isInCatchClause = previousIsInCatchClause; 7461 _isInCatchClause = previousIsInCatchClause;
7037 } 7462 }
7038 } 7463 }
7039 Object visitClassDeclaration(ClassDeclaration node) { 7464 Object visitClassDeclaration(ClassDeclaration node) {
7465 ClassElement outerClass = _enclosingClass;
7040 try { 7466 try {
7467 _enclosingClass = node.element;
7041 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME); 7468 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME);
7042 ClassElement classElement = node.element; 7469 ClassElement classElement = node.element;
7043 if (classElement != null) { 7470 if (classElement != null) {
7044 List<FieldElement> fieldElements = classElement.fields; 7471 List<FieldElement> fieldElements = classElement.fields;
7045 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); 7472 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>();
7046 for (FieldElement fieldElement in fieldElements) { 7473 for (FieldElement fieldElement in fieldElements) {
7047 if (!fieldElement.isSynthetic()) { 7474 if (!fieldElement.isSynthetic()) {
7048 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; 7475 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION;
7049 } 7476 }
7050 } 7477 }
7051 } 7478 }
7052 checkForFinalNotInitialized(node); 7479 checkForFinalNotInitialized(node);
7053 return super.visitClassDeclaration(node); 7480 return super.visitClassDeclaration(node);
7054 } finally { 7481 } finally {
7055 _initialFieldElementsMap = null; 7482 _initialFieldElementsMap = null;
7483 _enclosingClass = outerClass;
7056 } 7484 }
7057 } 7485 }
7058 Object visitClassTypeAlias(ClassTypeAlias node) { 7486 Object visitClassTypeAlias(ClassTypeAlias node) {
7059 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 7487 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
7060 return super.visitClassTypeAlias(node); 7488 return super.visitClassTypeAlias(node);
7061 } 7489 }
7062 Object visitConditionalExpression(ConditionalExpression node) { 7490 Object visitConditionalExpression(ConditionalExpression node) {
7063 checkForNonBoolCondition(node.condition); 7491 checkForNonBoolCondition(node.condition);
7064 return super.visitConditionalExpression(node); 7492 return super.visitConditionalExpression(node);
7065 } 7493 }
7066 Object visitConstructorDeclaration(ConstructorDeclaration node) { 7494 Object visitConstructorDeclaration(ConstructorDeclaration node) {
7067 ExecutableElement outerFunction = _enclosingFunction; 7495 ExecutableElement outerFunction = _enclosingFunction;
7068 try { 7496 try {
7069 _enclosingFunction = node.element; 7497 _enclosingFunction = node.element;
7070 _isEnclosingConstructorConst = node.constKeyword != null; 7498 _isEnclosingConstructorConst = node.constKeyword != null;
7071 checkForConstConstructorWithNonFinalField(node); 7499 checkForConstConstructorWithNonFinalField(node);
7072 checkForConflictingConstructorNameAndMember(node); 7500 checkForConflictingConstructorNameAndMember(node);
7073 checkForAllFinalInitializedErrorCodes(node); 7501 checkForAllFinalInitializedErrorCodes(node);
7074 return super.visitConstructorDeclaration(node); 7502 return super.visitConstructorDeclaration(node);
7075 } finally { 7503 } finally {
7076 _isEnclosingConstructorConst = false; 7504 _isEnclosingConstructorConst = false;
7077 _enclosingFunction = outerFunction; 7505 _enclosingFunction = outerFunction;
7078 } 7506 }
7079 } 7507 }
7508 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
7509 checkForPrivateOptionalParameter(node);
7510 return super.visitDefaultFormalParameter(node);
7511 }
7080 Object visitDoStatement(DoStatement node) { 7512 Object visitDoStatement(DoStatement node) {
7081 checkForNonBoolCondition(node.condition); 7513 checkForNonBoolCondition(node.condition);
7082 return super.visitDoStatement(node); 7514 return super.visitDoStatement(node);
7083 } 7515 }
7084 Object visitExtendsClause(ExtendsClause node) { 7516 Object visitExtendsClause(ExtendsClause node) {
7085 checkForExtendsDisallowedClass(node); 7517 checkForExtendsDisallowedClass(node);
7086 return super.visitExtendsClause(node); 7518 return super.visitExtendsClause(node);
7087 } 7519 }
7088 Object visitFieldFormalParameter(FieldFormalParameter node) { 7520 Object visitFieldFormalParameter(FieldFormalParameter node) {
7089 checkForConstFormalParameter(node); 7521 checkForConstFormalParameter(node);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7126 TypeName typeName = constructorName2.type; 7558 TypeName typeName = constructorName2.type;
7127 Type2 type2 = typeName.type; 7559 Type2 type2 = typeName.type;
7128 if (type2 is InterfaceType) { 7560 if (type2 is InterfaceType) {
7129 InterfaceType interfaceType = type2 as InterfaceType; 7561 InterfaceType interfaceType = type2 as InterfaceType;
7130 checkForConstWithNonConst(node); 7562 checkForConstWithNonConst(node);
7131 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); 7563 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
7132 checkForTypeArgumentNotMatchingBounds(node, constructorName2.element, type Name); 7564 checkForTypeArgumentNotMatchingBounds(node, constructorName2.element, type Name);
7133 } 7565 }
7134 return super.visitInstanceCreationExpression(node); 7566 return super.visitInstanceCreationExpression(node);
7135 } 7567 }
7568 Object visitListLiteral(ListLiteral node) {
7569 if (node.modifier != null) {
7570 TypeArgumentList typeArguments2 = node.typeArguments;
7571 if (typeArguments2 != null) {
7572 NodeList<TypeName> arguments2 = typeArguments2.arguments;
7573 if (arguments2.length != 0) {
7574 checkForInvalidTypeArgumentInConstTypedLiteral(arguments2, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
7575 }
7576 }
7577 }
7578 return super.visitListLiteral(node);
7579 }
7136 Object visitMapLiteral(MapLiteral node) { 7580 Object visitMapLiteral(MapLiteral node) {
7137 checkForInvalidTypeArgumentForKey(node); 7581 TypeArgumentList typeArguments2 = node.typeArguments;
7582 if (typeArguments2 != null) {
7583 NodeList<TypeName> arguments2 = typeArguments2.arguments;
7584 if (arguments2.length != 0) {
7585 checkForInvalidTypeArgumentForKey(arguments2);
7586 if (node.modifier != null) {
7587 checkForInvalidTypeArgumentInConstTypedLiteral(arguments2, CompileTime ErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
7588 }
7589 }
7590 }
7138 return super.visitMapLiteral(node); 7591 return super.visitMapLiteral(node);
7139 } 7592 }
7140 Object visitMethodDeclaration(MethodDeclaration node) { 7593 Object visitMethodDeclaration(MethodDeclaration node) {
7141 ExecutableElement previousFunction = _enclosingFunction; 7594 ExecutableElement previousFunction = _enclosingFunction;
7142 try { 7595 try {
7143 _enclosingFunction = node.element; 7596 _enclosingFunction = node.element;
7597 if (node.isSetter()) {
7598 checkForWrongNumberOfParametersForSetter(node);
7599 } else if (node.isOperator()) {
7600 checkForOptionalParameterInOperator(node);
7601 }
7602 checkForConcreteClassWithAbstractMember(node);
7144 return super.visitMethodDeclaration(node); 7603 return super.visitMethodDeclaration(node);
7145 } finally { 7604 } finally {
7146 _enclosingFunction = previousFunction; 7605 _enclosingFunction = previousFunction;
7147 } 7606 }
7148 } 7607 }
7149 Object visitNativeFunctionBody(NativeFunctionBody node) { 7608 Object visitNativeFunctionBody(NativeFunctionBody node) {
7150 checkForNativeFunctionBodyInNonSDKCode(node); 7609 checkForNativeFunctionBodyInNonSDKCode(node);
7151 return super.visitNativeFunctionBody(node); 7610 return super.visitNativeFunctionBody(node);
7152 } 7611 }
7153 Object visitRethrowExpression(RethrowExpression node) { 7612 Object visitRethrowExpression(RethrowExpression node) {
7154 checkForRethrowOutsideCatch(node); 7613 checkForRethrowOutsideCatch(node);
7155 return super.visitRethrowExpression(node); 7614 return super.visitRethrowExpression(node);
7156 } 7615 }
7157 Object visitReturnStatement(ReturnStatement node) { 7616 Object visitReturnStatement(ReturnStatement node) {
7158 checkForReturnOfInvalidType(node); 7617 checkForAllReturnStatementErrorCodes(node);
7159 return super.visitReturnStatement(node); 7618 return super.visitReturnStatement(node);
7160 } 7619 }
7161 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 7620 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
7162 checkForConstFormalParameter(node); 7621 checkForConstFormalParameter(node);
7163 return super.visitSimpleFormalParameter(node); 7622 return super.visitSimpleFormalParameter(node);
7164 } 7623 }
7165 Object visitSwitchStatement(SwitchStatement node) { 7624 Object visitSwitchStatement(SwitchStatement node) {
7166 checkForCaseExpressionTypeImplementsEquals(node); 7625 checkForCaseExpressionTypeImplementsEquals(node);
7167 checkForInconsistentCaseExpressionTypes(node); 7626 checkForInconsistentCaseExpressionTypes(node);
7168 return super.visitSwitchStatement(node); 7627 return super.visitSwitchStatement(node);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
7252 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) { 7711 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) {
7253 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_BY _MULTIPLE_INITIALIZERS, fieldName2, [fieldElement.name]); 7712 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_BY _MULTIPLE_INITIALIZERS, fieldName2, [fieldElement.name]);
7254 foundError = true; 7713 foundError = true;
7255 } 7714 }
7256 } 7715 }
7257 } 7716 }
7258 } 7717 }
7259 return foundError; 7718 return foundError;
7260 } 7719 }
7261 /** 7720 /**
7721 * This checks that the return statement of the form <i>return e;</i> is not i n a generative
7722 * constructor.
7723 * <p>
7724 * This checks that return statements without expressions are not in a generat ive constructor and
7725 * the return type is not assignable to {@code null}; that is, we don't have { @code return;} if
7726 * the enclosing method has a return type.
7727 * <p>
7728 * This checks that the return type matches the type of the declared return ty pe in the enclosing
7729 * method or function.
7730 * @param node the return statement to evaluate
7731 * @return {@code true} if and only if an error code is generated on the passe d node
7732 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR
7733 * @see StaticWarningCode#RETURN_WITHOUT_VALUE
7734 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE
7735 */
7736 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) {
7737 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
7738 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType;
7739 Expression returnExpression = node.expression;
7740 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! ((_enclosingFunction as ConstructorElement)).isFactory();
7741 if (returnExpression != null) {
7742 if (isGenerativeConstructor) {
7743 _errorReporter.reportError(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CON STRUCTOR, returnExpression, []);
7744 return true;
7745 }
7746 if (!expectedReturnType.isVoid()) {
7747 Type2 actualReturnType = getType(returnExpression);
7748 if (!actualReturnType.isAssignableTo(expectedReturnType)) {
7749 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYP E, returnExpression, [actualReturnType.name, expectedReturnType.name, _enclosing Function.name]);
7750 return true;
7751 }
7752 }
7753 } else {
7754 if (!isGenerativeConstructor && !VoidTypeImpl.instance.isAssignableTo(expe ctedReturnType)) {
7755 _errorReporter.reportError(StaticWarningCode.RETURN_WITHOUT_VALUE, node, []);
7756 }
7757 }
7758 return false;
7759 }
7760 /**
7262 * This verifies that the passed argument definition test identifier is a para meter. 7761 * This verifies that the passed argument definition test identifier is a para meter.
7263 * @param node the {@link ArgumentDefinitionTest} to evaluate 7762 * @param node the {@link ArgumentDefinitionTest} to evaluate
7264 * @return return {@code true} if and only if an error code is generated on th e passed node 7763 * @return return {@code true} if and only if an error code is generated on th e passed node
7265 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER 7764 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER
7266 */ 7765 */
7267 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { 7766 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) {
7268 SimpleIdentifier identifier2 = node.identifier; 7767 SimpleIdentifier identifier2 = node.identifier;
7269 Element element2 = identifier2.element; 7768 Element element2 = identifier2.element;
7270 if (element2 != null && element2 is! ParameterElement) { 7769 if (element2 != null && element2 is! ParameterElement) {
7271 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N ON_PARAMETER, identifier2, [identifier2.name]); 7770 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N ON_PARAMETER, identifier2, [identifier2.name]);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
7331 ClassElement classElement = element2 as ClassElement; 7830 ClassElement classElement = element2 as ClassElement;
7332 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); 7831 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
7333 if (method != null && method.enclosingElement.type != _typeProvider.obje ctType) { 7832 if (method != null && method.enclosingElement.type != _typeProvider.obje ctType) {
7334 _errorReporter.reportError(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_I MPLEMENTS_EQUALS, expression2, [element2.name]); 7833 _errorReporter.reportError(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_I MPLEMENTS_EQUALS, expression2, [element2.name]);
7335 return true; 7834 return true;
7336 } 7835 }
7337 } 7836 }
7338 } 7837 }
7339 return false; 7838 return false;
7340 } 7839 }
7840 /**
7841 * This verifies that the passed method declaration is abstract only if the en closing class is
7842 * also abstract.
7843 * @param node the method declaration to evaluate
7844 * @return {@code true} if and only if an error code is generated on the passe d node
7845 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
7846 */
7847 bool checkForConcreteClassWithAbstractMember(MethodDeclaration node) {
7848 if (node.isAbstract() && _enclosingClass != null && !_enclosingClass.isAbstr act()) {
7849 SimpleIdentifier methodName = node.name;
7850 _errorReporter.reportError(StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_ MEMBER, methodName, [methodName.name, _enclosingClass.name]);
7851 return true;
7852 }
7853 return false;
7854 }
7341 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) { 7855 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) {
7342 ConstructorElement constructorElement = node.element; 7856 ConstructorElement constructorElement = node.element;
7343 SimpleIdentifier constructorName = node.name; 7857 SimpleIdentifier constructorName = node.name;
7344 if (constructorName != null && constructorElement != null && !constructorNam e.isSynthetic()) { 7858 if (constructorName != null && constructorElement != null && !constructorNam e.isSynthetic()) {
7345 String name2 = constructorName.name; 7859 String name2 = constructorName.name;
7346 ClassElement classElement = constructorElement.enclosingElement; 7860 ClassElement classElement = constructorElement.enclosingElement;
7347 List<FieldElement> fields2 = classElement.fields; 7861 List<FieldElement> fields2 = classElement.fields;
7348 for (FieldElement field in fields2) { 7862 for (FieldElement field in fields2) {
7349 if (field.name == name2) { 7863 if (field.name == name2) {
7350 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO R_NAME_AND_FIELD, node, [name2]); 7864 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO R_NAME_AND_FIELD, node, [name2]);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
7626 VariableElement leftElement = getVariableElement(lhs); 8140 VariableElement leftElement = getVariableElement(lhs);
7627 Type2 leftType = (leftElement == null) ? getType(lhs) : leftElement.type; 8141 Type2 leftType = (leftElement == null) ? getType(lhs) : leftElement.type;
7628 Type2 rightType = getType(rhs); 8142 Type2 rightType = getType(rhs);
7629 if (!rightType.isAssignableTo(leftType)) { 8143 if (!rightType.isAssignableTo(leftType)) {
7630 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType.name, leftType.name]); 8144 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType.name, leftType.name]);
7631 return true; 8145 return true;
7632 } 8146 }
7633 return false; 8147 return false;
7634 } 8148 }
7635 /** 8149 /**
7636 * Checks to ensure that native function bodies can only in SDK code. 8150 * Checks to ensure that first type argument to a map literal must be the 'Str ing' type.
7637 * @param node the map literal to test 8151 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f rom the respective{@link MapLiteral}
7638 * @return return {@code true} if and only if an error code is generated on th e passed node 8152 * @return return {@code true} if and only if an error code is generated on th e passed node
7639 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY 8153 * @see CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_FOR_KEY
7640 */ 8154 */
7641 bool checkForInvalidTypeArgumentForKey(MapLiteral node) { 8155 bool checkForInvalidTypeArgumentForKey(NodeList<TypeName> arguments) {
7642 TypeArgumentList typeArgumentList = node.typeArguments; 8156 TypeName firstArgument = arguments[0];
7643 if (typeArgumentList == null) {
7644 return false;
7645 }
7646 NodeList<TypeName> arguments2 = typeArgumentList.arguments;
7647 if (arguments2.length == 0) {
7648 return false;
7649 }
7650 TypeName firstArgument = arguments2[0];
7651 Type2 firstArgumentType = firstArgument.type; 8157 Type2 firstArgumentType = firstArgument.type;
7652 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy pe) { 8158 if (firstArgumentType != null && firstArgumentType != _typeProvider.stringTy pe) {
7653 _errorReporter.reportError(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR_ KEY, firstArgument, []); 8159 _errorReporter.reportError(CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR_ KEY, firstArgument, []);
7654 return true; 8160 return true;
7655 } 8161 }
7656 return false; 8162 return false;
7657 } 8163 }
7658 /** 8164 /**
8165 * Checks to ensure that the passed {@link ListLiteral} or {@link MapLiteral} does not have a type
8166 * parameter as a type argument.
8167 * @param arguments a non-{@code null}, non-empty {@link TypeName} node list f rom the respective{@link ListLiteral} or {@link MapLiteral}
8168 * @param errorCode either {@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_I N_CONST_LIST} or{@link CompileTimeErrorCode#INVALID_TYPE_ARGUMENT_IN_CONST_MAP}
8169 * @return {@code true} if and only if an error code is generated on the passe d node
8170 */
8171 bool checkForInvalidTypeArgumentInConstTypedLiteral(NodeList<TypeName> argumen ts, ErrorCode errorCode) {
8172 bool foundError = false;
8173 for (TypeName typeName in arguments) {
8174 if (typeName.type is TypeVariableType) {
8175 _errorReporter.reportError(errorCode, typeName, [typeName.name]);
8176 foundError = true;
8177 }
8178 }
8179 return foundError;
8180 }
8181 /**
7659 * Checks to ensure that native function bodies can only in SDK code. 8182 * Checks to ensure that native function bodies can only in SDK code.
7660 * @param node the native function body to test 8183 * @param node the native function body to test
7661 * @return return {@code true} if and only if an error code is generated on th e passed node 8184 * @return return {@code true} if and only if an error code is generated on th e passed node
7662 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE 8185 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE
7663 */ 8186 */
7664 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { 8187 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) {
7665 if (!_isInSystemLibrary) { 8188 if (!_isInSystemLibrary) {
7666 _errorReporter.reportError(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK _CODE, node, []); 8189 _errorReporter.reportError(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK _CODE, node, []);
7667 return true; 8190 return true;
7668 } 8191 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
7700 } else if (type is FunctionType) { 8223 } else if (type is FunctionType) {
7701 FunctionType functionType = type as FunctionType; 8224 FunctionType functionType = type as FunctionType;
7702 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_typeProvider.boolType)) { 8225 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_typeProvider.boolType)) {
7703 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []); 8226 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []);
7704 return true; 8227 return true;
7705 } 8228 }
7706 } 8229 }
7707 return false; 8230 return false;
7708 } 8231 }
7709 /** 8232 /**
8233 * This verifies the passed operator-method declaration, does not have an opti onal parameter.
8234 * <p>
8235 * This method assumes that the method declaration was tested to be an operato r declaration before
8236 * being called.
8237 * @param node the method declaration to evaluate
8238 * @return {@code true} if and only if an error code is generated on the passe d node
8239 * @see CompileTimeErrorCode#OPTIONAL_PARAMETER_IN_OPERATOR
8240 */
8241 bool checkForOptionalParameterInOperator(MethodDeclaration node) {
8242 FormalParameterList parameterList = node.parameters;
8243 if (parameterList == null) {
8244 return false;
8245 }
8246 bool foundError = false;
8247 NodeList<FormalParameter> formalParameters = parameterList.parameters;
8248 for (FormalParameter formalParameter in formalParameters) {
8249 if (formalParameter.kind.isOptional()) {
8250 _errorReporter.reportError(CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OP ERATOR, formalParameter, []);
8251 foundError = true;
8252 }
8253 }
8254 return foundError;
8255 }
8256 /**
8257 * This checks for named optional parameters that begin with '_'.
8258 * @param node the default formal parameter to evaluate
8259 * @return {@code true} if and only if an error code is generated on the passe d node
8260 * @see CompileTimeErrorCode#PRIVATE_OPTIONAL_PARAMETER
8261 */
8262 bool checkForPrivateOptionalParameter(DefaultFormalParameter node) {
8263 sc.Token separator2 = node.separator;
8264 if (separator2 != null && separator2.lexeme == ":") {
8265 NormalFormalParameter parameter2 = node.parameter;
8266 SimpleIdentifier name = parameter2.identifier;
8267 if (!name.isSynthetic() && name.name.startsWith("_")) {
8268 _errorReporter.reportError(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMET ER, node, []);
8269 return true;
8270 }
8271 }
8272 return false;
8273 }
8274 /**
7710 * This checks that the rethrow is inside of a catch clause. 8275 * This checks that the rethrow is inside of a catch clause.
7711 * @param node the rethrow expression to evaluate 8276 * @param node the rethrow expression to evaluate
7712 * @return {@code true} if and only if an error code is generated on the passe d node 8277 * @return {@code true} if and only if an error code is generated on the passe d node
7713 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH 8278 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH
7714 */ 8279 */
7715 bool checkForRethrowOutsideCatch(RethrowExpression node) { 8280 bool checkForRethrowOutsideCatch(RethrowExpression node) {
7716 if (!_isInCatchClause) { 8281 if (!_isInCatchClause) {
7717 _errorReporter.reportError(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, nod e, []); 8282 _errorReporter.reportError(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, nod e, []);
7718 return true; 8283 return true;
7719 } 8284 }
7720 return false; 8285 return false;
7721 } 8286 }
7722 /** 8287 /**
7723 * This checks that the return type matches the type of the declared return ty pe in the enclosing
7724 * method or function.
7725 * @param node the return statement to evaluate
7726 * @return return {@code true} if and only if an error code is generated on th e passed node
7727 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE
7728 */
7729 bool checkForReturnOfInvalidType(ReturnStatement node) {
7730 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
7731 Type2 expectedReturnType = functionType == null ? null : functionType.return Type;
7732 Expression returnExpression = node.expression;
7733 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr ession != null) {
7734 Type2 actualReturnType = getType(returnExpression);
7735 if (!actualReturnType.isAssignableTo(expectedReturnType)) {
7736 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [actualReturnType.name, expectedReturnType.name, _enclosingFu nction.name]);
7737 return true;
7738 }
7739 }
7740 return false;
7741 }
7742 /**
7743 * This verifies that the type arguments in the passed instance creation expre ssion are all within 8288 * This verifies that the type arguments in the passed instance creation expre ssion are all within
7744 * their bounds as specified by the class element where the constructor [that is being invoked] is 8289 * their bounds as specified by the class element where the constructor [[that is being invoked]] is
7745 * declared. 8290 * declared.
7746 * @param node the instance creation expression to evaluate 8291 * @param node the instance creation expression to evaluate
7747 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th e{@link InstanceCreationExpression}, this is the AST node that the error is atta ched to 8292 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th e{@link InstanceCreationExpression}, this is the AST node that the error is atta ched to
7748 * @param constructorElement the {@link ConstructorElement} from the instance creation expression 8293 * @param constructorElement the {@link ConstructorElement} from the instance creation expression
7749 * @return return {@code true} if and only if an error code is generated on th e passed node 8294 * @return return {@code true} if and only if an error code is generated on th e passed node
7750 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS 8295 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
7751 */ 8296 */
7752 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co nstructorElement constructorElement, TypeName typeName) { 8297 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co nstructorElement constructorElement, TypeName typeName) {
7753 if (typeName.typeArguments != null && constructorElement != null) { 8298 if (typeName.typeArguments != null && constructorElement != null) {
7754 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; 8299 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
7755 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme nt.typeVariables; 8300 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme nt.typeVariables;
7756 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt h); 8301 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt h);
7757 for (int i = 0; i < loopThroughIndex; i++) { 8302 for (int i = 0; i < loopThroughIndex; i++) {
7758 TypeName argTypeName = typeNameArgList[i]; 8303 TypeName argTypeName = typeNameArgList[i];
7759 Type2 argType = argTypeName.type; 8304 Type2 argType = argTypeName.type;
7760 Type2 boundType = boundingElts[i].bound; 8305 Type2 boundType = boundingElts[i].bound;
7761 if (argType != null && boundType != null) { 8306 if (argType != null && boundType != null) {
7762 if (!argType.isSubtypeOf(boundType)) { 8307 if (!argType.isSubtypeOf(boundType)) {
7763 _errorReporter.reportError(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_M ATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].name]); 8308 _errorReporter.reportError(StaticTypeWarningCode.TYPE_ARGUMENT_NOT_M ATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].name]);
7764 return true; 8309 return true;
7765 } 8310 }
7766 } 8311 }
7767 } 8312 }
7768 } 8313 }
7769 return false; 8314 return false;
7770 } 8315 }
7771 /** 8316 /**
8317 * This verifies if the passed setter method declaration, has only one paramet er.
8318 * <p>
8319 * This method assumes that the method declaration was tested to be a setter b efore being called.
8320 * @param node the method declaration to evaluate
8321 * @return return {@code true} if and only if an error code is generated on th e passed node
8322 * @see CompileTimeErrorCode#WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
8323 */
8324 bool checkForWrongNumberOfParametersForSetter(MethodDeclaration node) {
8325 FormalParameterList parameterList = node.parameters;
8326 if (parameterList == null) {
8327 return false;
8328 }
8329 NodeList<FormalParameter> formalParameters = parameterList.parameters;
8330 int numberOfParameters = formalParameters.length;
8331 if (numberOfParameters != 1) {
8332 _errorReporter.reportError(CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS _FOR_SETTER, node.name, [numberOfParameters]);
8333 return true;
8334 }
8335 return false;
8336 }
8337 /**
7772 * Return the type of the given expression that is to be used for type analysi s. 8338 * Return the type of the given expression that is to be used for type analysi s.
7773 * @param expression the expression whose type is to be returned 8339 * @param expression the expression whose type is to be returned
7774 * @return the type of the given expression 8340 * @return the type of the given expression
7775 */ 8341 */
7776 Type2 getType(Expression expression) { 8342 Type2 getType(Expression expression) {
7777 Type2 type = expression.staticType; 8343 Type2 type = expression.staticType;
7778 return type == null ? _dynamicType : type; 8344 return type == null ? _dynamicType : type;
7779 } 8345 }
7780 /** 8346 /**
7781 * Return the variable element represented by the given expression, or {@code null} if there is no 8347 * Return the variable element represented by the given expression, or {@code null} if there is no
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
7845 this._type = type; 8411 this._type = type;
7846 this._message = message; 8412 this._message = message;
7847 } 8413 }
7848 ErrorSeverity get errorSeverity => _type.severity; 8414 ErrorSeverity get errorSeverity => _type.severity;
7849 String get message => _message; 8415 String get message => _message;
7850 ErrorType get type => _type; 8416 ErrorType get type => _type;
7851 bool needsRecompilation() => true; 8417 bool needsRecompilation() => true;
7852 int compareTo(ResolverErrorCode other) => __ordinal - other.__ordinal; 8418 int compareTo(ResolverErrorCode other) => __ordinal - other.__ordinal;
7853 String toString() => __name; 8419 String toString() => __name;
7854 } 8420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698