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

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

Issue 23080005: New analysis_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 library engine.resolver; 3 library engine.resolver;
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'java_core.dart'; 5 import 'java_core.dart';
6 import 'java_engine.dart'; 6 import 'java_engine.dart';
7 import 'instrumentation.dart'; 7 import 'instrumentation.dart';
8 import 'source.dart'; 8 import 'source.dart';
9 import 'error.dart'; 9 import 'error.dart';
10 import 'scanner.dart' as sc; 10 import 'scanner.dart' as sc;
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 initializer.functions = holder.functions; 595 initializer.functions = holder.functions;
596 initializer.labels = holder.labels; 596 initializer.labels = holder.labels;
597 initializer.localVariables = holder.localVariables; 597 initializer.localVariables = holder.localVariables;
598 initializer.synthetic = true; 598 initializer.synthetic = true;
599 element.initializer = initializer; 599 element.initializer = initializer;
600 holder.validate(); 600 holder.validate();
601 } 601 }
602 if (element is PropertyInducingElementImpl) { 602 if (element is PropertyInducingElementImpl) {
603 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl; 603 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl;
604 if (_inFieldContext) { 604 if (_inFieldContext) {
605 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).keyword, sc.Keyword.STATIC); 605 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).staticKeyword, sc.Keyword.STATIC);
606 } 606 }
607 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable); 607 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable);
608 getter.getter = true; 608 getter.getter = true;
609 getter.static = variable.isStatic; 609 getter.static = variable.isStatic;
610 _currentHolder.addAccessor(getter); 610 _currentHolder.addAccessor(getter);
611 variable.getter = getter; 611 variable.getter = getter;
612 if (!isFinal) { 612 if (!isFinal) {
613 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable); 613 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable);
614 setter.setter = true; 614 setter.setter = true;
615 setter.static = variable.isStatic; 615 setter.static = variable.isStatic;
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 * The analysis context in which the element model will be built. 1024 * The analysis context in which the element model will be built.
1025 */ 1025 */
1026 InternalAnalysisContext _context; 1026 InternalAnalysisContext _context;
1027 1027
1028 /** 1028 /**
1029 * The error listener to which errors will be reported. 1029 * The error listener to which errors will be reported.
1030 */ 1030 */
1031 RecordingErrorListener _errorListener; 1031 RecordingErrorListener _errorListener;
1032 1032
1033 /** 1033 /**
1034 * The modification time of the source for which an element is being built.
1035 */
1036 int _modificationStamp = 0;
1037
1038 /**
1034 * The line information associated with the source for which an element is bei ng built, or 1039 * The line information associated with the source for which an element is bei ng built, or
1035 * `null` if we are not building an element. 1040 * `null` if we are not building an element.
1036 */ 1041 */
1037 LineInfo _lineInfo; 1042 LineInfo _lineInfo;
1038 1043
1039 /** 1044 /**
1040 * The HTML element being built. 1045 * The HTML element being built.
1041 */ 1046 */
1042 HtmlElementImpl _htmlElement; 1047 HtmlElementImpl _htmlElement;
1043 1048
(...skipping 22 matching lines...) Expand all
1066 this._errorListener = new RecordingErrorListener(); 1071 this._errorListener = new RecordingErrorListener();
1067 } 1072 }
1068 1073
1069 /** 1074 /**
1070 * Build the HTML element for the given source. 1075 * Build the HTML element for the given source.
1071 * 1076 *
1072 * @param source the source describing the compilation unit 1077 * @param source the source describing the compilation unit
1073 * @return the HTML element that was built 1078 * @return the HTML element that was built
1074 * @throws AnalysisException if the analysis could not be performed 1079 * @throws AnalysisException if the analysis could not be performed
1075 */ 1080 */
1076 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _ context.parseHtmlUnit(source)); 1081 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, s ource.modificationStamp, _context.parseHtmlUnit(source));
1077 1082
1078 /** 1083 /**
1079 * Build the HTML element for the given source. 1084 * Build the HTML element for the given source.
1080 * 1085 *
1081 * @param source the source describing the compilation unit 1086 * @param source the source describing the compilation unit
1087 * @param modificationStamp the modification time of the source for which an e lement is being
1088 * built
1082 * @param unit the AST structure representing the HTML 1089 * @param unit the AST structure representing the HTML
1083 * @throws AnalysisException if the analysis could not be performed 1090 * @throws AnalysisException if the analysis could not be performed
1084 */ 1091 */
1085 HtmlElementImpl buildHtmlElement2(Source source2, ht.HtmlUnit unit) { 1092 HtmlElementImpl buildHtmlElement2(Source source2, int modificationStamp2, ht.H tmlUnit unit) {
1093 this._modificationStamp = modificationStamp2;
1086 _lineInfo = _context.computeLineInfo(source2); 1094 _lineInfo = _context.computeLineInfo(source2);
1087 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName); 1095 HtmlElementImpl result = new HtmlElementImpl(_context, source2.shortName);
1088 result.source = source2; 1096 result.source = source2;
1089 _htmlElement = result; 1097 _htmlElement = result;
1090 unit.accept(this); 1098 unit.accept(this);
1091 _htmlElement = null; 1099 _htmlElement = null;
1092 unit.element = result; 1100 unit.element = result;
1093 return result; 1101 return result;
1094 } 1102 }
1095 1103
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 LineInfo_Location location = _lineInfo.getLocation(attributeEnd); 1163 LineInfo_Location location = _lineInfo.getLocation(attributeEnd);
1156 sc.StringScanner scanner = new sc.StringScanner(htmlSource, contents, _errorListener); 1164 sc.StringScanner scanner = new sc.StringScanner(htmlSource, contents, _errorListener);
1157 scanner.setSourceStart(location.lineNumber, location.columnNumber, att ributeEnd); 1165 scanner.setSourceStart(location.lineNumber, location.columnNumber, att ributeEnd);
1158 sc.Token firstToken = scanner.tokenize(); 1166 sc.Token firstToken = scanner.tokenize();
1159 List<int> lineStarts = scanner.lineStarts; 1167 List<int> lineStarts = scanner.lineStarts;
1160 Parser parser = new Parser(htmlSource, _errorListener); 1168 Parser parser = new Parser(htmlSource, _errorListener);
1161 CompilationUnit unit = parser.parseCompilationUnit(firstToken); 1169 CompilationUnit unit = parser.parseCompilationUnit(firstToken);
1162 unit.lineInfo = new LineInfo(lineStarts); 1170 unit.lineInfo = new LineInfo(lineStarts);
1163 try { 1171 try {
1164 LibraryResolver resolver = new LibraryResolver(_context); 1172 LibraryResolver resolver = new LibraryResolver(_context);
1165 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, unit, true) as LibraryElementImpl; 1173 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, _modificationStamp, unit, true) as LibraryElementImpl;
1166 script.scriptLibrary = library; 1174 script.scriptLibrary = library;
1167 _resolvedLibraries.addAll(resolver.resolvedLibraries); 1175 _resolvedLibraries.addAll(resolver.resolvedLibraries);
1168 _errorListener.addAll(resolver.errorListener); 1176 _errorListener.addAll(resolver.errorListener);
1169 } on AnalysisException catch (exception) { 1177 } on AnalysisException catch (exception) {
1170 AnalysisEngine.instance.logger.logError3(exception); 1178 AnalysisEngine.instance.logger.logError3(exception);
1171 } 1179 }
1172 _scripts.add(script); 1180 _scripts.add(script);
1173 } else { 1181 } else {
1174 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementIm pl(node); 1182 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementIm pl(node);
1175 if (scriptSourcePath != null) { 1183 if (scriptSourcePath != null) {
1176 try { 1184 try {
1185 scriptSourcePath = Uri.encodeFull(scriptSourcePath);
1177 parseUriWithException(scriptSourcePath); 1186 parseUriWithException(scriptSourcePath);
1178 Source scriptSource = _context.sourceFactory.resolveUri(htmlSource , scriptSourcePath); 1187 Source scriptSource = _context.sourceFactory.resolveUri(htmlSource , scriptSourcePath);
1179 script.scriptSource = scriptSource; 1188 script.scriptSource = scriptSource;
1180 if (!scriptSource.exists()) { 1189 if (scriptSource == null || !scriptSource.exists()) {
1181 reportError(HtmlWarningCode.URI_DOES_NOT_EXIST, scriptAttribute. offset + 1, scriptSourcePath.length, [scriptSourcePath]); 1190 reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST, scriptAttri bute, [scriptSourcePath]);
1182 } 1191 }
1183 } on URISyntaxException catch (exception) { 1192 } on URISyntaxException catch (exception) {
1184 reportError(HtmlWarningCode.INVALID_URI, scriptAttribute.offset + 1, scriptSourcePath.length, [scriptSourcePath]); 1193 reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute, [sc riptSourcePath]);
1185 } 1194 }
1186 } 1195 }
1187 _scripts.add(script); 1196 _scripts.add(script);
1188 } 1197 }
1189 } else { 1198 } else {
1190 node.visitChildren(this); 1199 node.visitChildren(this);
1191 } 1200 }
1192 } finally { 1201 } finally {
1193 _parentNodes.remove(node); 1202 _parentNodes.remove(node);
1194 } 1203 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 * compose the error message. 1248 * compose the error message.
1240 * 1249 *
1241 * @param errorCode the error code of the error to be reported 1250 * @param errorCode the error code of the error to be reported
1242 * @param offset the offset of the first character to be highlighted 1251 * @param offset the offset of the first character to be highlighted
1243 * @param length the number of characters to be highlighted 1252 * @param length the number of characters to be highlighted
1244 * @param arguments the arguments used to compose the error message 1253 * @param arguments the arguments used to compose the error message
1245 */ 1254 */
1246 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg uments) { 1255 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg uments) {
1247 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l ength, errorCode, arguments)); 1256 _errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, l ength, errorCode, arguments));
1248 } 1257 }
1258
1259 /**
1260 * Report an error with the given error code at the location of the value of t he given attribute.
1261 * Use the given arguments to compose the error message.
1262 *
1263 * @param errorCode the error code of the error to be reported
1264 * @param offset the offset of the first character to be highlighted
1265 * @param length the number of characters to be highlighted
1266 * @param arguments the arguments used to compose the error message
1267 */
1268 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) {
1269 int offset = attribute.value.offset + 1;
1270 int length = attribute.value.length - 2;
1271 reportError(errorCode, offset, length, arguments);
1272 }
1249 } 1273 }
1250 /** 1274 /**
1251 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of 1275 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of
1252 * [HintCode#DEAD_CODE]. 1276 * [HintCode#DEAD_CODE].
1253 * 1277 *
1254 * @coverage dart.engine.resolver 1278 * @coverage dart.engine.resolver
1255 */ 1279 */
1256 class DeadCodeVerifier extends RecursiveASTVisitor<Object> { 1280 class DeadCodeVerifier extends RecursiveASTVisitor<Object> {
1257 1281
1258 /** 1282 /**
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 } else { 1367 } else {
1344 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, []); 1368 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, []);
1345 safelyVisit(node.elseStatement); 1369 safelyVisit(node.elseStatement);
1346 return null; 1370 return null;
1347 } 1371 }
1348 } 1372 }
1349 return super.visitIfStatement(node); 1373 return super.visitIfStatement(node);
1350 } 1374 }
1351 Object visitTryStatement(TryStatement node) { 1375 Object visitTryStatement(TryStatement node) {
1352 safelyVisit(node.body); 1376 safelyVisit(node.body);
1353 safelyVisit(node.finallyClause); 1377 safelyVisit(node.finallyBlock);
1354 NodeList<CatchClause> catchClauses = node.catchClauses; 1378 NodeList<CatchClause> catchClauses = node.catchClauses;
1355 int numOfCatchClauses = catchClauses.length; 1379 int numOfCatchClauses = catchClauses.length;
1356 List<Type2> visitedTypes = new List<Type2>(); 1380 List<Type2> visitedTypes = new List<Type2>();
1357 for (int i = 0; i < numOfCatchClauses; i++) { 1381 for (int i = 0; i < numOfCatchClauses; i++) {
1358 CatchClause catchClause = catchClauses[i]; 1382 CatchClause catchClause = catchClauses[i];
1359 if (catchClause.onKeyword != null) { 1383 if (catchClause.onKeyword != null) {
1360 TypeName typeName = catchClause.exceptionType; 1384 TypeName typeName = catchClause.exceptionType;
1361 if (typeName != null && typeName.type != null) { 1385 if (typeName != null && typeName.type != null) {
1362 Type2 currentType = typeName.type; 1386 Type2 currentType = typeName.type;
1363 if (currentType.isObject) { 1387 if (currentType.isObject) {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 SimpleIdentifier prefixIdentifier = importDirective.prefix; 1619 SimpleIdentifier prefixIdentifier = importDirective.prefix;
1596 if (prefixIdentifier != null) { 1620 if (prefixIdentifier != null) {
1597 Element element = prefixIdentifier.element; 1621 Element element = prefixIdentifier.element;
1598 if (element is PrefixElement) { 1622 if (element is PrefixElement) {
1599 PrefixElement prefixElementKey = element as PrefixElement; 1623 PrefixElement prefixElementKey = element as PrefixElement;
1600 _prefixElementMap[prefixElementKey] = importDirective; 1624 _prefixElementMap[prefixElementKey] = importDirective;
1601 } 1625 }
1602 } 1626 }
1603 } 1627 }
1604 putIntoLibraryMap(libraryElement, importDirective); 1628 putIntoLibraryMap(libraryElement, importDirective);
1605 addAdditionalLibrariesForExports(_libraryMap, libraryElement, import Directive, new List<LibraryElement>()); 1629 addAdditionalLibrariesForExports(libraryElement, importDirective, ne w List<LibraryElement>());
1606 } 1630 }
1607 } 1631 }
1608 } 1632 }
1609 } 1633 }
1610 if (_unusedImports.isEmpty) { 1634 if (_unusedImports.isEmpty) {
1611 return null; 1635 return null;
1612 } 1636 }
1613 return super.visitCompilationUnit(node); 1637 return super.visitCompilationUnit(node);
1614 } 1638 }
1615 Object visitExportDirective(ExportDirective node) => null; 1639 Object visitExportDirective(ExportDirective node) => null;
1616 Object visitImportDirective(ImportDirective node) => null; 1640 Object visitImportDirective(ImportDirective node) => null;
1617 Object visitLibraryDirective(LibraryDirective node) => null; 1641 Object visitLibraryDirective(LibraryDirective node) => null;
1618 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 1642 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
1619 SimpleIdentifier prefixIdentifier = node.prefix; 1643 SimpleIdentifier prefixIdentifier = node.prefix;
1620 Element element = prefixIdentifier.element; 1644 Element element = prefixIdentifier.element;
1621 if (element is PrefixElement) { 1645 if (element is PrefixElement) {
1622 _unusedImports.remove(_prefixElementMap[element]); 1646 _unusedImports.remove(_prefixElementMap[element]);
1623 return null; 1647 return null;
1624 } 1648 }
1625 return visitIdentifier(element, prefixIdentifier.name); 1649 return visitIdentifier(element, prefixIdentifier.name);
1626 } 1650 }
1627 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.el ement, node.name); 1651 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.el ement, node.name);
1628 void set inDefiningCompilationUnit(bool inDefiningCompilationUnit2) { 1652 void set inDefiningCompilationUnit(bool inDefiningCompilationUnit2) {
1629 this._inDefiningCompilationUnit = inDefiningCompilationUnit2; 1653 this._inDefiningCompilationUnit = inDefiningCompilationUnit2;
1630 } 1654 }
1631 1655
1632 /** 1656 /**
1633 * Recursively add any exported library elements into the [libraryMap]. 1657 * Recursively add any exported library elements into the [libraryMap].
1634 */ 1658 */
1635 void addAdditionalLibrariesForExports(Map<LibraryElement, List<ImportDirective >> map, LibraryElement library, ImportDirective importDirective, List<LibraryEle ment> exportPath) { 1659 void addAdditionalLibrariesForExports(LibraryElement library, ImportDirective importDirective, List<LibraryElement> exportPath) {
1636 if (exportPath.contains(library)) { 1660 if (exportPath.contains(library)) {
1637 return; 1661 return;
1638 } 1662 }
1663 exportPath.add(library);
1639 for (LibraryElement exportedLibraryElt in library.exportedLibraries) { 1664 for (LibraryElement exportedLibraryElt in library.exportedLibraries) {
1640 putIntoLibraryMap(exportedLibraryElt, importDirective); 1665 putIntoLibraryMap(exportedLibraryElt, importDirective);
1641 exportPath.add(exportedLibraryElt); 1666 addAdditionalLibrariesForExports(exportedLibraryElt, importDirective, expo rtPath);
1642 addAdditionalLibrariesForExports(map, exportedLibraryElt, importDirective, exportPath);
1643 } 1667 }
1644 } 1668 }
1645 1669
1646 /** 1670 /**
1647 * Lookup and return the [Namespace] from the [namespaceMap], if the map does not 1671 * Lookup and return the [Namespace] from the [namespaceMap], if the map does not
1648 * have the computed namespace, compute it and cache it in the map. If the imp ort directive is not 1672 * have the computed namespace, compute it and cache it in the map. If the imp ort directive is not
1649 * resolved or is not resolvable, `null` is returned. 1673 * resolved or is not resolvable, `null` is returned.
1650 * 1674 *
1651 * @param importDirective the import directive used to compute the returned na mespace 1675 * @param importDirective the import directive used to compute the returned na mespace
1652 * @return the computed or looked up [Namespace] 1676 * @return the computed or looked up [Namespace]
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 int pathIndex = 0; 1779 int pathIndex = 0;
1756 int fullNameIndex = fullName.length; 1780 int fullNameIndex = fullName.length;
1757 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../", pathIndex)) { 1781 while (pathIndex < path.length && JavaString.startsWithBefore(path, "../", pathIndex)) {
1758 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); 1782 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex);
1759 if (fullNameIndex < 4) { 1783 if (fullNameIndex < 4) {
1760 return false; 1784 return false;
1761 } 1785 }
1762 if (JavaString.startsWithBefore(fullName, "/lib", fullNameIndex - 4)) { 1786 if (JavaString.startsWithBefore(fullName, "/lib", fullNameIndex - 4)) {
1763 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP EC_YAML; 1787 String relativePubspecPath = path.substring(0, pathIndex + 3) + _PUBSP EC_YAML;
1764 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat ivePubspecPath); 1788 Source pubspecSource = _context.sourceFactory.resolveUri(source, relat ivePubspecPath);
1765 if (pubspecSource.exists()) { 1789 if (pubspecSource != null && pubspecSource.exists()) {
1766 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB _REFERENCES_FILE_OUTSIDE, uriLiteral, []); 1790 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_INSIDE_LIB _REFERENCES_FILE_OUTSIDE, uriLiteral, []);
1767 } 1791 }
1768 return true; 1792 return true;
1769 } 1793 }
1770 pathIndex += 3; 1794 pathIndex += 3;
1771 } 1795 }
1772 } 1796 }
1773 return false; 1797 return false;
1774 } 1798 }
1775 1799
(...skipping 19 matching lines...) Expand all
1795 return true; 1819 return true;
1796 } 1820 }
1797 pathIndex = JavaString.indexOf(path, "/lib/", pathIndex + 4); 1821 pathIndex = JavaString.indexOf(path, "/lib/", pathIndex + 4);
1798 } 1822 }
1799 return false; 1823 return false;
1800 } 1824 }
1801 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera l, String path, int pathIndex) { 1825 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera l, String path, int pathIndex) {
1802 Source source = getSource(uriLiteral); 1826 Source source = getSource(uriLiteral);
1803 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; 1827 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML;
1804 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub specPath); 1828 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub specPath);
1805 if (!pubspecSource.exists()) { 1829 if (pubspecSource == null || !pubspecSource.exists()) {
1806 return false; 1830 return false;
1807 } 1831 }
1808 String fullName = getSourceFullName(source); 1832 String fullName = getSourceFullName(source);
1809 if (fullName != null) { 1833 if (fullName != null) {
1810 if (!fullName.contains("/lib/")) { 1834 if (!fullName.contains("/lib/")) {
1811 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE FERENCES_FILE_INSIDE, uriLiteral, []); 1835 _errorReporter.reportError2(PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_RE FERENCES_FILE_INSIDE, uriLiteral, []);
1812 return true; 1836 return true;
1813 } 1837 }
1814 } 1838 }
1815 return false; 1839 return false;
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 */ 2516 */
2493 ResolverVisitor _resolver; 2517 ResolverVisitor _resolver;
2494 2518
2495 /** 2519 /**
2496 * A flag indicating whether we are running in strict mode. In strict mode, er ror reporting is 2520 * A flag indicating whether we are running in strict mode. In strict mode, er ror reporting is
2497 * based exclusively on the static type information. 2521 * based exclusively on the static type information.
2498 */ 2522 */
2499 bool _strictMode = false; 2523 bool _strictMode = false;
2500 2524
2501 /** 2525 /**
2526 * The type representing the type 'dynamic'.
2527 */
2528 Type2 _dynamicType;
2529
2530 /**
2531 * The type representing the type 'type'.
2532 */
2533 Type2 _typeType;
2534
2535 /**
2502 * The name of the method that can be implemented by a class to allow its inst ances to be invoked 2536 * The name of the method that can be implemented by a class to allow its inst ances to be invoked
2503 * as if they were a function. 2537 * as if they were a function.
2504 */ 2538 */
2505 static String CALL_METHOD_NAME = "call"; 2539 static String CALL_METHOD_NAME = "call";
2506 2540
2507 /** 2541 /**
2508 * The name of the method that will be invoked if an attempt is made to invoke an undefined method 2542 * The name of the method that will be invoked if an attempt is made to invoke an undefined method
2509 * on an object. 2543 * on an object.
2510 */ 2544 */
2511 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod"; 2545 static String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
2512 2546
2513 /** 2547 /**
2514 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 2548 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
2515 * 2549 *
2516 * @param resolver the resolver driving this participant 2550 * @param resolver the resolver driving this participant
2517 */ 2551 */
2518 ElementResolver(ResolverVisitor resolver) { 2552 ElementResolver(ResolverVisitor resolver) {
2519 this._resolver = resolver; 2553 this._resolver = resolver;
2520 _strictMode = resolver.definingLibrary.context.analysisOptions.strictMode; 2554 _strictMode = resolver.definingLibrary.context.analysisOptions.strictMode;
2555 _dynamicType = resolver.typeProvider.dynamicType;
2556 _typeType = resolver.typeProvider.typeType;
2521 } 2557 }
2522 Object visitAssignmentExpression(AssignmentExpression node) { 2558 Object visitAssignmentExpression(AssignmentExpression node) {
2523 sc.Token operator = node.operator; 2559 sc.Token operator = node.operator;
2524 sc.TokenType operatorType = operator.type; 2560 sc.TokenType operatorType = operator.type;
2525 if (operatorType != sc.TokenType.EQ) { 2561 if (operatorType != sc.TokenType.EQ) {
2526 operatorType = operatorFromCompoundAssignment(operatorType); 2562 operatorType = operatorFromCompoundAssignment(operatorType);
2527 Expression leftHandSide = node.leftHandSide; 2563 Expression leftHandSide = node.leftHandSide;
2528 if (leftHandSide != null) { 2564 if (leftHandSide != null) {
2529 String methodName = operatorType.lexeme; 2565 String methodName = operatorType.lexeme;
2530 Type2 staticType = getStaticType(leftHandSide); 2566 Type2 staticType = getStaticType(leftHandSide);
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 } 2897 }
2862 if (propagatedElement != null) { 2898 if (propagatedElement != null) {
2863 List<ParameterElement> parameters = computeCorrespondingParameters(argumen tList, propagatedElement); 2899 List<ParameterElement> parameters = computeCorrespondingParameters(argumen tList, propagatedElement);
2864 if (parameters != null) { 2900 if (parameters != null) {
2865 argumentList.correspondingPropagatedParameters = parameters; 2901 argumentList.correspondingPropagatedParameters = parameters;
2866 } 2902 }
2867 } 2903 }
2868 ErrorCode errorCode = checkForInvocationError(target, staticElement); 2904 ErrorCode errorCode = checkForInvocationError(target, staticElement);
2869 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) { 2905 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) {
2870 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, me thodName, [methodName.name]); 2906 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, me thodName, [methodName.name]);
2871 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_FUNCTION)) { 2907 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) {
2872 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, methodName , [methodName.name]); 2908 _resolver.reportError(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName, [methodName.name]);
2873 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { 2909 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
2874 String targetTypeName; 2910 String targetTypeName;
2875 if (target == null) { 2911 if (target == null) {
2876 ClassElement enclosingClass = _resolver.enclosingClass; 2912 ClassElement enclosingClass = _resolver.enclosingClass;
2877 targetTypeName = enclosingClass.displayName; 2913 targetTypeName = enclosingClass.displayName;
2878 } else { 2914 } else {
2879 Type2 targetType = getStaticType(target); 2915 Type2 targetType = getStaticType(target);
2880 if (targetType != null && targetType.isDartCoreFunction && methodName.na me == CALL_METHOD_NAME) { 2916 if (targetType != null && targetType.isDartCoreFunction && methodName.na me == CALL_METHOD_NAME) {
2881 return null; 2917 return null;
2882 } 2918 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3000 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element); 3036 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element);
3001 if (parameters != null) { 3037 if (parameters != null) {
3002 argumentList.correspondingStaticParameters = parameters; 3038 argumentList.correspondingStaticParameters = parameters;
3003 } 3039 }
3004 return null; 3040 return null;
3005 } 3041 }
3006 Object visitSimpleIdentifier(SimpleIdentifier node) { 3042 Object visitSimpleIdentifier(SimpleIdentifier node) {
3007 if (node.staticElement != null || node.element != null) { 3043 if (node.staticElement != null || node.element != null) {
3008 return null; 3044 return null;
3009 } 3045 }
3046 if (node.name == _dynamicType.name) {
3047 recordResolution(node, _dynamicType.element);
3048 node.staticType = _typeType;
3049 return null;
3050 }
3010 Element element = resolveSimpleIdentifier(node); 3051 Element element = resolveSimpleIdentifier(node);
3011 if (isFactoryConstructorReturnType(node) && element != _resolver.enclosingCl ass) { 3052 if (isFactoryConstructorReturnType(node) && element != _resolver.enclosingCl ass) {
3012 _resolver.reportError(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLAS S, node, []); 3053 _resolver.reportError(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLAS S, node, []);
3013 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) { 3054 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) {
3014 if (isConstructorReturnType(node)) { 3055 if (isConstructorReturnType(node)) {
3015 _resolver.reportError(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, nod e, []); 3056 _resolver.reportError(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, nod e, []);
3016 } else { 3057 } else {
3017 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [nod e.name]); 3058 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [nod e.name]);
3018 } 3059 }
3019 } 3060 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
3104 3145
3105 /** 3146 /**
3106 * Given that we have found code to invoke the given element, return the error code that should be 3147 * Given that we have found code to invoke the given element, return the error code that should be
3107 * reported, or `null` if no error should be reported. 3148 * reported, or `null` if no error should be reported.
3108 * 3149 *
3109 * @param target the target of the invocation, or `null` if there was no targe t 3150 * @param target the target of the invocation, or `null` if there was no targe t
3110 * @param element the element to be invoked 3151 * @param element the element to be invoked
3111 * @return the error code that should be reported 3152 * @return the error code that should be reported
3112 */ 3153 */
3113 ErrorCode checkForInvocationError(Expression target, Element element) { 3154 ErrorCode checkForInvocationError(Expression target, Element element) {
3155 if (element is PrefixElement) {
3156 element = null;
3157 }
3114 if (element is PropertyAccessorElement) { 3158 if (element is PropertyAccessorElement) {
3115 FunctionType getterType = ((element as PropertyAccessorElement)).type; 3159 FunctionType getterType = ((element as PropertyAccessorElement)).type;
3116 if (getterType != null) { 3160 if (getterType != null) {
3117 Type2 returnType = getterType.returnType; 3161 Type2 returnType = getterType.returnType;
3118 if (!isExecutableType(returnType)) { 3162 if (!isExecutableType(returnType)) {
3119 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 3163 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3120 } 3164 }
3121 } 3165 }
3122 } else if (element is ExecutableElement) { 3166 } else if (element is ExecutableElement) {
3123 return null; 3167 return null;
(...skipping 10 matching lines...) Expand all
3134 } 3178 }
3135 } 3179 }
3136 } else if (element is VariableElement) { 3180 } else if (element is VariableElement) {
3137 Type2 variableType = ((element as VariableElement)).type; 3181 Type2 variableType = ((element as VariableElement)).type;
3138 if (!isExecutableType(variableType)) { 3182 if (!isExecutableType(variableType)) {
3139 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 3183 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3140 } 3184 }
3141 } else { 3185 } else {
3142 if (target == null) { 3186 if (target == null) {
3143 ClassElement enclosingClass = _resolver.enclosingClass; 3187 ClassElement enclosingClass = _resolver.enclosingClass;
3144 if (enclosingClass == null) { 3188 if (element == null) {
3145 return StaticTypeWarningCode.UNDEFINED_FUNCTION; 3189 if (enclosingClass == null) {
3146 } else if (element == null) { 3190 return CompileTimeErrorCode.UNDEFINED_FUNCTION;
3147 return StaticTypeWarningCode.UNDEFINED_METHOD; 3191 } else {
3192 return StaticTypeWarningCode.UNDEFINED_METHOD;
3193 }
3148 } else { 3194 } else {
3149 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 3195 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3150 } 3196 }
3151 } else { 3197 } else {
3152 Type2 targetType = getStaticType(target); 3198 Type2 targetType = getStaticType(target);
3153 if (targetType == null) { 3199 if (targetType == null) {
3154 return StaticTypeWarningCode.UNDEFINED_FUNCTION; 3200 return CompileTimeErrorCode.UNDEFINED_FUNCTION;
3155 } else if (!targetType.isDynamic) { 3201 } else if (!targetType.isDynamic) {
3156 return StaticTypeWarningCode.UNDEFINED_METHOD; 3202 return StaticTypeWarningCode.UNDEFINED_METHOD;
3157 } 3203 }
3158 } 3204 }
3159 } 3205 }
3160 } 3206 }
3161 return null; 3207 return null;
3162 } 3208 }
3163 3209
3164 /** 3210 /**
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
4441 return resultMap; 4487 return resultMap;
4442 } 4488 }
4443 if (superclassElt != null) { 4489 if (superclassElt != null) {
4444 if (!visitedClasses.contains(superclassElt)) { 4490 if (!visitedClasses.contains(superclassElt)) {
4445 javaSetAdd(visitedClasses, classElt); 4491 javaSetAdd(visitedClasses, classElt);
4446 resultMap = new Map<String, ExecutableElement>.from(computeClassChainLoo kupMap(superclassElt, visitedClasses)); 4492 resultMap = new Map<String, ExecutableElement>.from(computeClassChainLoo kupMap(superclassElt, visitedClasses));
4447 } else { 4493 } else {
4448 _classLookup[superclassElt] = resultMap; 4494 _classLookup[superclassElt] = resultMap;
4449 return resultMap; 4495 return resultMap;
4450 } 4496 }
4451 recordMapWithClassMembers(resultMap, superclassElt); 4497 recordMapWithClassMembers(resultMap, supertype);
4452 } 4498 }
4453 List<InterfaceType> mixins = classElt.mixins; 4499 List<InterfaceType> mixins = classElt.mixins;
4454 for (int i = mixins.length - 1; i >= 0; i--) { 4500 for (int i = mixins.length - 1; i >= 0; i--) {
4455 ClassElement mixinElement = mixins[i].element; 4501 recordMapWithClassMembers(resultMap, mixins[i]);
4456 if (mixinElement != null) {
4457 recordMapWithClassMembers(resultMap, mixinElement);
4458 }
4459 } 4502 }
4460 _classLookup[classElt] = resultMap; 4503 _classLookup[classElt] = resultMap;
4461 return resultMap; 4504 return resultMap;
4462 } 4505 }
4463 4506
4464 /** 4507 /**
4465 * Compute and return the inheritance path given the context of a type and a m ember that is 4508 * Compute and return the inheritance path given the context of a type and a m ember that is
4466 * overridden in the inheritance path (for which the type is in the path). 4509 * overridden in the inheritance path (for which the type is in the path).
4467 * 4510 *
4468 * @param chain the inheritance path that is built up as this method calls its elf recursively, 4511 * @param chain the inheritance path that is built up as this method calls its elf recursively,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt]; 4566 Map<String, ExecutableElement> resultMap = _interfaceLookup[classElt];
4524 if (resultMap != null) { 4567 if (resultMap != null) {
4525 return resultMap; 4568 return resultMap;
4526 } else { 4569 } else {
4527 resultMap = new Map<String, ExecutableElement>(); 4570 resultMap = new Map<String, ExecutableElement>();
4528 } 4571 }
4529 InterfaceType supertype = classElt.supertype; 4572 InterfaceType supertype = classElt.supertype;
4530 ClassElement superclassElement = supertype != null ? supertype.element : nul l; 4573 ClassElement superclassElement = supertype != null ? supertype.element : nul l;
4531 List<InterfaceType> mixins = classElt.mixins; 4574 List<InterfaceType> mixins = classElt.mixins;
4532 List<InterfaceType> interfaces = classElt.interfaces; 4575 List<InterfaceType> interfaces = classElt.interfaces;
4533 if ((superclassElement == null || supertype.isObject) && mixins.length == 0 && interfaces.length == 0) {
4534 _interfaceLookup[classElt] = resultMap;
4535 return resultMap;
4536 }
4537 List<Map<String, ExecutableElement>> lookupMaps = new List<Map<String, Execu tableElement>>(); 4576 List<Map<String, ExecutableElement>> lookupMaps = new List<Map<String, Execu tableElement>>();
4538 if (superclassElement != null) { 4577 if (superclassElement != null) {
4539 if (!visitedInterfaces.contains(superclassElement)) { 4578 if (!visitedInterfaces.contains(superclassElement)) {
4540 try { 4579 try {
4541 javaSetAdd(visitedInterfaces, superclassElement); 4580 javaSetAdd(visitedInterfaces, superclassElement);
4542 lookupMaps.add(computeInterfaceLookupMap(superclassElement, visitedInt erfaces)); 4581 Map<String, ExecutableElement> map = computeInterfaceLookupMap(supercl assElement, visitedInterfaces);
4582 map = new Map<String, ExecutableElement>.from(map);
4583 List<MethodElement> methods = supertype.methods;
4584 for (MethodElement method in methods) {
4585 if (method.isAccessibleIn(_library) && !method.isStatic) {
4586 map[method.name] = method;
4587 }
4588 }
4589 List<PropertyAccessorElement> accessors = supertype.accessors;
4590 for (PropertyAccessorElement accessor in accessors) {
4591 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) {
4592 map[accessor.name] = accessor;
4593 }
4594 }
4595 lookupMaps.add(map);
4543 } finally { 4596 } finally {
4544 visitedInterfaces.remove(superclassElement); 4597 visitedInterfaces.remove(superclassElement);
4545 } 4598 }
4546 } else { 4599 } else {
4547 Map<String, ExecutableElement> map = _interfaceLookup[classElt]; 4600 Map<String, ExecutableElement> map = _interfaceLookup[classElt];
4548 if (map != null) { 4601 if (map != null) {
4549 lookupMaps.add(map); 4602 lookupMaps.add(map);
4550 } else { 4603 } else {
4551 _interfaceLookup[superclassElement] = resultMap; 4604 _interfaceLookup[superclassElement] = resultMap;
4552 return resultMap; 4605 return resultMap;
4553 } 4606 }
4554 } 4607 }
4555 } 4608 }
4556 for (InterfaceType mixinType in mixins) { 4609 for (InterfaceType mixinType in mixins) {
4557 ClassElement mixinElement = mixinType.element;
4558 if (mixinElement == null) {
4559 continue;
4560 }
4561 Map<String, ExecutableElement> mapWithMixinMembers = new Map<String, Execu tableElement>(); 4610 Map<String, ExecutableElement> mapWithMixinMembers = new Map<String, Execu tableElement>();
4562 recordMapWithClassMembers(mapWithMixinMembers, mixinElement); 4611 recordMapWithClassMembers(mapWithMixinMembers, mixinType);
4563 lookupMaps.add(mapWithMixinMembers); 4612 lookupMaps.add(mapWithMixinMembers);
4564 } 4613 }
4565 for (InterfaceType interfaceType in interfaces) { 4614 for (InterfaceType interfaceType in interfaces) {
4566 ClassElement interfaceElement = interfaceType.element; 4615 ClassElement interfaceElement = interfaceType.element;
4567 if (interfaceElement != null) { 4616 if (interfaceElement != null) {
4568 if (!visitedInterfaces.contains(interfaceElement)) { 4617 if (!visitedInterfaces.contains(interfaceElement)) {
4569 try { 4618 try {
4570 javaSetAdd(visitedInterfaces, interfaceElement); 4619 javaSetAdd(visitedInterfaces, interfaceElement);
4571 lookupMaps.add(computeInterfaceLookupMap(interfaceElement, visitedIn terfaces)); 4620 Map<String, ExecutableElement> map = computeInterfaceLookupMap(inter faceElement, visitedInterfaces);
4621 map = new Map<String, ExecutableElement>.from(map);
4622 List<MethodElement> methods = interfaceType.methods;
4623 for (MethodElement method in methods) {
4624 if (method.isAccessibleIn(_library) && !method.isStatic) {
4625 map[method.name] = method;
4626 }
4627 }
4628 List<PropertyAccessorElement> accessors = interfaceType.accessors;
4629 for (PropertyAccessorElement accessor in accessors) {
4630 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) {
4631 map[accessor.name] = accessor;
4632 }
4633 }
4634 lookupMaps.add(map);
4572 } finally { 4635 } finally {
4573 visitedInterfaces.remove(interfaceElement); 4636 visitedInterfaces.remove(interfaceElement);
4574 } 4637 }
4575 } else { 4638 } else {
4576 Map<String, ExecutableElement> map = _interfaceLookup[classElt]; 4639 Map<String, ExecutableElement> map = _interfaceLookup[classElt];
4577 if (map != null) { 4640 if (map != null) {
4578 lookupMaps.add(map); 4641 lookupMaps.add(map);
4579 } else { 4642 } else {
4580 _interfaceLookup[interfaceElement] = resultMap; 4643 _interfaceLookup[interfaceElement] = resultMap;
4581 return resultMap; 4644 return resultMap;
4582 } 4645 }
4583 } 4646 }
4584 } 4647 }
4585 } 4648 }
4586 if (lookupMaps.length == 0) { 4649 if (lookupMaps.length == 0) {
4587 _interfaceLookup[classElt] = resultMap; 4650 _interfaceLookup[classElt] = resultMap;
4588 return resultMap; 4651 return resultMap;
4589 } 4652 }
4590 Map<String, Set<ExecutableElement>> unionMap = new Map<String, Set<Executabl eElement>>(); 4653 Map<String, Set<ExecutableElement>> unionMap = new Map<String, Set<Executabl eElement>>();
4591 for (Map<String, ExecutableElement> lookupMap in lookupMaps) { 4654 for (Map<String, ExecutableElement> lookupMap in lookupMaps) {
4592 for (MapEntry<String, ExecutableElement> entry in getMapEntrySet(lookupMap )) { 4655 for (MapEntry<String, ExecutableElement> entry in getMapEntrySet(lookupMap )) {
4593 String key = entry.getKey(); 4656 String key = entry.getKey();
4594 if (!unionMap.containsKey(key)) { 4657 Set<ExecutableElement> set = unionMap[key];
4595 Set<ExecutableElement> set = new Set<ExecutableElement>(); 4658 if (set == null) {
4596 javaSetAdd(set, entry.getValue()); 4659 set = new Set<ExecutableElement>();
4597 unionMap[key] = set; 4660 unionMap[key] = set;
4598 } else {
4599 javaSetAdd(unionMap[key], entry.getValue());
4600 } 4661 }
4601 } 4662 javaSetAdd(set, entry.getValue());
4602 }
4603 if (superclassElement != null) {
4604 List<MethodElement> methods = superclassElement.methods;
4605 for (MethodElement method in methods) {
4606 if (method.isAccessibleIn(_library) && !method.isStatic) {
4607 String key = method.name;
4608 if (!unionMap.containsKey(key)) {
4609 Set<ExecutableElement> set = new Set<ExecutableElement>();
4610 javaSetAdd(set, method);
4611 unionMap[key] = set;
4612 } else {
4613 javaSetAdd(unionMap[key], method);
4614 }
4615 }
4616 }
4617 List<PropertyAccessorElement> accessors = superclassElement.accessors;
4618 for (PropertyAccessorElement accessor in accessors) {
4619 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) {
4620 String key = accessor.name;
4621 if (!unionMap.containsKey(key)) {
4622 Set<ExecutableElement> set = new Set<ExecutableElement>();
4623 javaSetAdd(set, accessor);
4624 unionMap[key] = set;
4625 } else {
4626 javaSetAdd(unionMap[key], accessor);
4627 }
4628 }
4629 }
4630 }
4631 for (InterfaceType interfaceType in interfaces) {
4632 ClassElement interfaceElement = interfaceType.element;
4633 if (interfaceElement != null) {
4634 List<MethodElement> methods = interfaceElement.methods;
4635 for (MethodElement method in methods) {
4636 if (method.isAccessibleIn(_library) && !method.isStatic) {
4637 String key = method.name;
4638 if (!unionMap.containsKey(key)) {
4639 Set<ExecutableElement> set = new Set<ExecutableElement>();
4640 javaSetAdd(set, method);
4641 unionMap[key] = set;
4642 } else {
4643 javaSetAdd(unionMap[key], method);
4644 }
4645 }
4646 }
4647 List<PropertyAccessorElement> accessors = interfaceElement.accessors;
4648 for (PropertyAccessorElement accessor in accessors) {
4649 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) {
4650 String key = accessor.name;
4651 if (!unionMap.containsKey(key)) {
4652 Set<ExecutableElement> set = new Set<ExecutableElement>();
4653 javaSetAdd(set, accessor);
4654 unionMap[key] = set;
4655 } else {
4656 javaSetAdd(unionMap[key], accessor);
4657 }
4658 }
4659 }
4660 } 4663 }
4661 } 4664 }
4662 for (MapEntry<String, Set<ExecutableElement>> entry in getMapEntrySet(unionM ap)) { 4665 for (MapEntry<String, Set<ExecutableElement>> entry in getMapEntrySet(unionM ap)) {
4663 String key = entry.getKey(); 4666 String key = entry.getKey();
4664 Set<ExecutableElement> set = entry.getValue(); 4667 Set<ExecutableElement> set = entry.getValue();
4665 int numOfEltsWithMatchingNames = set.length; 4668 int numOfEltsWithMatchingNames = set.length;
4666 if (numOfEltsWithMatchingNames == 1) { 4669 if (numOfEltsWithMatchingNames == 1) {
4667 resultMap[key] = new JavaIterator(set).next(); 4670 resultMap[key] = new JavaIterator(set).next();
4668 } else { 4671 } else {
4669 bool allMethods = true; 4672 bool allMethods = true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4743 List<PropertyAccessorElement> accessors = classElt.accessors; 4746 List<PropertyAccessorElement> accessors = classElt.accessors;
4744 for (PropertyAccessorElement accessor in accessors) { 4747 for (PropertyAccessorElement accessor in accessors) {
4745 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a ccessor.isStatic) { 4748 if (memberName == accessor.name && accessor.isAccessibleIn(_library) && !a ccessor.isStatic) {
4746 return accessor; 4749 return accessor;
4747 } 4750 }
4748 } 4751 }
4749 return null; 4752 return null;
4750 } 4753 }
4751 4754
4752 /** 4755 /**
4753 * Record the passed map with the set of all members (methods, getters and set ters) in the class 4756 * Record the passed map with the set of all members (methods, getters and set ters) in the type
4754 * into the passed map. 4757 * into the passed map.
4755 * 4758 *
4756 * @param map some non-`null` map to put the methods and accessors from the pa ssed 4759 * @param map some non-`null` map to put the methods and accessors from the pa ssed
4757 * [ClassElement] into 4760 * [ClassElement] into
4758 * @param classElt the class element that will be recorded into the passed map 4761 * @param type the type that will be recorded into the passed map
4759 */ 4762 */
4760 void recordMapWithClassMembers(Map<String, ExecutableElement> map, ClassElemen t classElt) { 4763 void recordMapWithClassMembers(Map<String, ExecutableElement> map, InterfaceTy pe type) {
4761 List<MethodElement> methods = classElt.methods; 4764 List<MethodElement> methods = type.methods;
4762 for (MethodElement method in methods) { 4765 for (MethodElement method in methods) {
4763 if (method.isAccessibleIn(_library) && !method.isStatic) { 4766 if (method.isAccessibleIn(_library) && !method.isStatic) {
4764 map[method.name] = method; 4767 map[method.name] = method;
4765 } 4768 }
4766 } 4769 }
4767 List<PropertyAccessorElement> accessors = classElt.accessors; 4770 List<PropertyAccessorElement> accessors = type.accessors;
4768 for (PropertyAccessorElement accessor in accessors) { 4771 for (PropertyAccessorElement accessor in accessors) {
4769 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) { 4772 if (accessor.isAccessibleIn(_library) && !accessor.isStatic) {
4770 map[accessor.name] = accessor; 4773 map[accessor.name] = accessor;
4771 } 4774 }
4772 } 4775 }
4773 } 4776 }
4774 4777
4775 /** 4778 /**
4776 * This method is used to report errors on when they are found computing inher itance information. 4779 * This method is used to report errors on when they are found computing inher itance information.
4777 * See [ErrorVerifier#checkForInconsistentMethodInheritance] to see where thes e generated 4780 * See [ErrorVerifier#checkForInconsistentMethodInheritance] to see where thes e generated
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4843 4846
4844 /** 4847 /**
4845 * A list containing all of the libraries that are exported from this library. 4848 * A list containing all of the libraries that are exported from this library.
4846 */ 4849 */
4847 List<Library> _exportedLibraries = _EMPTY_ARRAY; 4850 List<Library> _exportedLibraries = _EMPTY_ARRAY;
4848 4851
4849 /** 4852 /**
4850 * A table mapping the sources for the compilation units in this library to th eir corresponding 4853 * A table mapping the sources for the compilation units in this library to th eir corresponding
4851 * AST structures. 4854 * AST structures.
4852 */ 4855 */
4853 Map<Source, CompilationUnit> _astMap = new Map<Source, CompilationUnit>(); 4856 Map<Source, ResolvableCompilationUnit> _astMap = new Map<Source, ResolvableCom pilationUnit>();
4854 4857
4855 /** 4858 /**
4856 * The library scope used when resolving elements within this library's compil ation units. 4859 * The library scope used when resolving elements within this library's compil ation units.
4857 */ 4860 */
4858 LibraryScope _libraryScope; 4861 LibraryScope _libraryScope;
4859 4862
4860 /** 4863 /**
4861 * An empty array that can be used to initialize lists of libraries. 4864 * An empty array that can be used to initialize lists of libraries.
4862 */ 4865 */
4863 static List<Library> _EMPTY_ARRAY = new List<Library>(0); 4866 static List<Library> _EMPTY_ARRAY = new List<Library>(0);
(...skipping 13 matching lines...) Expand all
4877 } 4880 }
4878 4881
4879 /** 4882 /**
4880 * Return the AST structure associated with the given source. 4883 * Return the AST structure associated with the given source.
4881 * 4884 *
4882 * @param source the source representing the compilation unit whose AST is to be returned 4885 * @param source the source representing the compilation unit whose AST is to be returned
4883 * @return the AST structure associated with the given source 4886 * @return the AST structure associated with the given source
4884 * @throws AnalysisException if an AST structure could not be created for the compilation unit 4887 * @throws AnalysisException if an AST structure could not be created for the compilation unit
4885 */ 4888 */
4886 CompilationUnit getAST(Source source) { 4889 CompilationUnit getAST(Source source) {
4887 CompilationUnit unit = _astMap[source]; 4890 ResolvableCompilationUnit holder = _astMap[source];
4888 if (unit == null) { 4891 if (holder == null) {
4889 unit = _analysisContext.computeResolvableCompilationUnit(source); 4892 holder = _analysisContext.computeResolvableCompilationUnit(source);
4890 _astMap[source] = unit; 4893 _astMap[source] = holder;
4891 } 4894 }
4892 return unit; 4895 return holder.compilationUnit;
4893 } 4896 }
4894 4897
4895 /** 4898 /**
4896 * Return an array of the [CompilationUnit]s that make up the library. The fir st unit is 4899 * Return an array of the [CompilationUnit]s that make up the library. The fir st unit is
4897 * always the defining unit. 4900 * always the defining unit.
4898 * 4901 *
4899 * @return an array of the [CompilationUnit]s that make up the library. The fi rst unit is 4902 * @return an array of the [CompilationUnit]s that make up the library. The fi rst unit is
4900 * always the defining unit 4903 * always the defining unit
4901 */ 4904 */
4902 List<CompilationUnit> get compilationUnits { 4905 List<CompilationUnit> get compilationUnits {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
5006 } 5009 }
5007 5010
5008 /** 5011 /**
5009 * Return the source specifying the defining compilation unit of this library. 5012 * Return the source specifying the defining compilation unit of this library.
5010 * 5013 *
5011 * @return the source specifying the defining compilation unit of this library 5014 * @return the source specifying the defining compilation unit of this library
5012 */ 5015 */
5013 Source get librarySource => _librarySource; 5016 Source get librarySource => _librarySource;
5014 5017
5015 /** 5018 /**
5019 * Return the modification stamp associated with the given source.
5020 *
5021 * @param source the source representing the compilation unit whose AST is to be returned
5022 * @return the AST structure associated with the given source
5023 * @throws AnalysisException if an AST structure could not be created for the compilation unit
5024 */
5025 int getModificationStamp(Source source) {
5026 ResolvableCompilationUnit holder = _astMap[source];
5027 if (holder == null) {
5028 holder = _analysisContext.computeResolvableCompilationUnit(source);
5029 _astMap[source] = holder;
5030 }
5031 return holder.modificationStamp;
5032 }
5033
5034 /**
5016 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 5035 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
5017 * library, or `null` if the URI is not valid. If the URI is not valid, report the error. 5036 * library, or `null` if the URI is not valid. If the URI is not valid, report the error.
5018 * 5037 *
5019 * @param directive the directive which URI should be resolved 5038 * @param directive the directive which URI should be resolved
5020 * @return the result of resolving the URI against the URI of the library 5039 * @return the result of resolving the URI against the URI of the library
5021 */ 5040 */
5022 Source getSource(UriBasedDirective directive) { 5041 Source getSource(UriBasedDirective directive) {
5023 StringLiteral uriLiteral = directive.uri; 5042 StringLiteral uriLiteral = directive.uri;
5024 if (uriLiteral is StringInterpolation) { 5043 if (uriLiteral is StringInterpolation) {
5025 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); 5044 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, []));
5026 return null; 5045 return null;
5027 } 5046 }
5028 String uriContent = uriLiteral.stringValue.trim(); 5047 String uriContent = uriLiteral.stringValue.trim();
5029 _directiveUris[directive] = uriContent; 5048 _directiveUris[directive] = uriContent;
5030 uriContent = Uri.encodeFull(uriContent); 5049 uriContent = Uri.encodeFull(uriContent);
5031 try { 5050 try {
5032 parseUriWithException(uriContent); 5051 parseUriWithException(uriContent);
5033 Source source = getSource2(uriContent); 5052 Source source = _analysisContext.sourceFactory.resolveUri(_librarySource, uriContent);
5034 if (source == null || !source.exists()) { 5053 if (source == null || !source.exists()) {
5035 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral .offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent ])); 5054 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral .offset, uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, [uriContent ]));
5036 } 5055 }
5037 return source; 5056 return source;
5038 } on URISyntaxException catch (exception) { 5057 } on URISyntaxException catch (exception) {
5039 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent])); 5058 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriContent]));
5040 } 5059 }
5041 return null; 5060 return null;
5042 } 5061 }
5043 5062
5044 /** 5063 /**
5045 * Returns the URI value of the given directive. 5064 * Returns the URI value of the given directive.
5046 */ 5065 */
5047 String getUri(UriBasedDirective directive) => _directiveUris[directive]; 5066 String getUri(UriBasedDirective directive) => _directiveUris[directive];
5048 5067
5049 /** 5068 /**
5050 * Set the AST structure associated with the defining compilation unit for thi s library to the 5069 * Set the AST structure associated with the defining compilation unit for thi s library to the
5051 * given AST structure. 5070 * given AST structure.
5052 * 5071 *
5072 * @param modificationStamp the modification time of the source from which the compilation unit
5073 * was created
5053 * @param unit the AST structure associated with the defining compilation unit for this library 5074 * @param unit the AST structure associated with the defining compilation unit for this library
5054 */ 5075 */
5055 void set definingCompilationUnit(CompilationUnit unit) { 5076 void setDefiningCompilationUnit(int modificationStamp, CompilationUnit unit) {
5056 _astMap[_librarySource] = unit; 5077 _astMap[_librarySource] = new ResolvableCompilationUnit(modificationStamp, u nit);
5057 } 5078 }
5058 5079
5059 /** 5080 /**
5060 * Set whether this library explicitly imports core to match the given value. 5081 * Set whether this library explicitly imports core to match the given value.
5061 * 5082 *
5062 * @param explicitlyImportsCore `true` if this library explicitly imports core 5083 * @param explicitlyImportsCore `true` if this library explicitly imports core
5063 */ 5084 */
5064 void set explicitlyImportsCore(bool explicitlyImportsCore2) { 5085 void set explicitlyImportsCore(bool explicitlyImportsCore2) {
5065 this._explicitlyImportsCore = explicitlyImportsCore2; 5086 this._explicitlyImportsCore = explicitlyImportsCore2;
5066 } 5087 }
(...skipping 21 matching lines...) Expand all
5088 * 5109 *
5089 * @param libraryElement the library element representing this library 5110 * @param libraryElement the library element representing this library
5090 */ 5111 */
5091 void set libraryElement(LibraryElementImpl libraryElement2) { 5112 void set libraryElement(LibraryElementImpl libraryElement2) {
5092 this._libraryElement = libraryElement2; 5113 this._libraryElement = libraryElement2;
5093 if (_inheritanceManager != null) { 5114 if (_inheritanceManager != null) {
5094 _inheritanceManager.libraryElement = libraryElement2; 5115 _inheritanceManager.libraryElement = libraryElement2;
5095 } 5116 }
5096 } 5117 }
5097 String toString() => _librarySource.shortName; 5118 String toString() => _librarySource.shortName;
5098
5099 /**
5100 * Return the result of resolving the given URI against the URI of the library , or `null` if
5101 * the URI is not valid.
5102 *
5103 * @param uri the URI to be resolved
5104 * @return the result of resolving the given URI against the URI of the librar y
5105 */
5106 Source getSource2(String uri) {
5107 if (uri == null) {
5108 return null;
5109 }
5110 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri);
5111 }
5112 } 5119 }
5113 /** 5120 /**
5114 * Instances of the class `LibraryElementBuilder` build an element model for a s ingle library. 5121 * Instances of the class `LibraryElementBuilder` build an element model for a s ingle library.
5115 * 5122 *
5116 * @coverage dart.engine.resolver 5123 * @coverage dart.engine.resolver
5117 */ 5124 */
5118 class LibraryElementBuilder { 5125 class LibraryElementBuilder {
5119 5126
5120 /** 5127 /**
5121 * The analysis context in which the element model will be built. 5128 * The analysis context in which the element model will be built.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
5381 * @return an array containing the libraries that were resolved 5388 * @return an array containing the libraries that were resolved
5382 */ 5389 */
5383 Set<Library> get resolvedLibraries => _librariesInCycles; 5390 Set<Library> get resolvedLibraries => _librariesInCycles;
5384 5391
5385 /** 5392 /**
5386 * Resolve the library specified by the given source in the given context. The library is assumed 5393 * Resolve the library specified by the given source in the given context. The library is assumed
5387 * to be embedded in the given source. 5394 * to be embedded in the given source.
5388 * 5395 *
5389 * @param librarySource the source specifying the defining compilation unit of the library to be 5396 * @param librarySource the source specifying the defining compilation unit of the library to be
5390 * resolved 5397 * resolved
5398 * @param modificationStamp the time stamp of the source from which the compil ation unit was
5399 * created
5391 * @param unit the compilation unit representing the embedded library 5400 * @param unit the compilation unit representing the embedded library
5392 * @param fullAnalysis `true` if a full analysis should be performed 5401 * @param fullAnalysis `true` if a full analysis should be performed
5393 * @return the element representing the resolved library 5402 * @return the element representing the resolved library
5394 * @throws AnalysisException if the library could not be resolved for some rea son 5403 * @throws AnalysisException if the library could not be resolved for some rea son
5395 */ 5404 */
5396 LibraryElement resolveEmbeddedLibrary(Source librarySource, CompilationUnit un it, bool fullAnalysis) { 5405 LibraryElement resolveEmbeddedLibrary(Source librarySource, int modificationSt amp, CompilationUnit unit, bool fullAnalysis) {
5397 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveEmbeddedLibrary"); 5406 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveEmbeddedLibrary");
5398 try { 5407 try {
5399 instrumentation.metric("fullAnalysis", fullAnalysis); 5408 instrumentation.metric("fullAnalysis", fullAnalysis);
5400 instrumentation.data3("fullName", librarySource.fullName); 5409 instrumentation.data3("fullName", librarySource.fullName);
5401 Library targetLibrary = createLibrary2(librarySource, unit); 5410 Library targetLibrary = createLibrary2(librarySource, modificationStamp, u nit);
5402 _coreLibrary = _libraryMap[_coreLibrarySource]; 5411 _coreLibrary = _libraryMap[_coreLibrarySource];
5403 if (_coreLibrary == null) { 5412 if (_coreLibrary == null) {
5404 _coreLibrary = createLibrary(_coreLibrarySource); 5413 _coreLibrary = createLibrary(_coreLibrarySource);
5405 } 5414 }
5406 instrumentation.metric3("createLibrary", "complete"); 5415 instrumentation.metric3("createLibrary", "complete");
5407 computeLibraryDependencies2(targetLibrary, unit); 5416 computeLibraryDependencies2(targetLibrary, unit);
5408 _librariesInCycles = computeLibrariesInCycles(targetLibrary); 5417 _librariesInCycles = computeLibrariesInCycles(targetLibrary);
5409 buildElementModels(); 5418 buildElementModels();
5410 instrumentation.metric3("buildElementModels", "complete"); 5419 instrumentation.metric3("buildElementModels", "complete");
5411 LibraryElement coreElement = _coreLibrary.libraryElement; 5420 LibraryElement coreElement = _coreLibrary.libraryElement;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
5813 library.definingCompilationUnit; 5822 library.definingCompilationUnit;
5814 _libraryMap[librarySource] = library; 5823 _libraryMap[librarySource] = library;
5815 return library; 5824 return library;
5816 } 5825 }
5817 5826
5818 /** 5827 /**
5819 * Create an object to represent the information about the library defined by the compilation unit 5828 * Create an object to represent the information about the library defined by the compilation unit
5820 * with the given source. 5829 * with the given source.
5821 * 5830 *
5822 * @param librarySource the source of the library's defining compilation unit 5831 * @param librarySource the source of the library's defining compilation unit
5832 * @param modificationStamp the modification time of the source from which the compilation unit
5833 * was created
5834 * @param unit the compilation unit that defines the library
5823 * @return the library object that was created 5835 * @return the library object that was created
5824 * @throws AnalysisException if the library source is not valid 5836 * @throws AnalysisException if the library source is not valid
5825 */ 5837 */
5826 Library createLibrary2(Source librarySource, CompilationUnit unit) { 5838 Library createLibrary2(Source librarySource, int modificationStamp, Compilatio nUnit unit) {
5827 Library library = new Library(_analysisContext, _errorListener, librarySourc e); 5839 Library library = new Library(_analysisContext, _errorListener, librarySourc e);
5828 library.definingCompilationUnit = unit; 5840 library.setDefiningCompilationUnit(modificationStamp, unit);
5829 _libraryMap[librarySource] = library; 5841 _libraryMap[librarySource] = library;
5830 return library; 5842 return library;
5831 } 5843 }
5832 5844
5833 /** 5845 /**
5834 * Create an object to represent the information about the library defined by the compilation unit 5846 * Create an object to represent the information about the library defined by the compilation unit
5835 * with the given source. Return the library object that was created, or `null ` if the 5847 * with the given source. Return the library object that was created, or `null ` if the
5836 * source is not valid. 5848 * source is not valid.
5837 * 5849 *
5838 * @param librarySource the source of the library's defining compilation unit 5850 * @param librarySource the source of the library's defining compilation unit
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
5936 * @param librarySource the source representing the library containing the dir ective 5948 * @param librarySource the source representing the library containing the dir ective
5937 * @param directive the directive which URI should be resolved 5949 * @param directive the directive which URI should be resolved
5938 * @return the result of resolving the URI against the URI of the library 5950 * @return the result of resolving the URI against the URI of the library
5939 */ 5951 */
5940 Source resolveSource(Source librarySource, UriBasedDirective directive) { 5952 Source resolveSource(Source librarySource, UriBasedDirective directive) {
5941 StringLiteral uriLiteral = directive.uri; 5953 StringLiteral uriLiteral = directive.uri;
5942 if (uriLiteral is StringInterpolation) { 5954 if (uriLiteral is StringInterpolation) {
5943 return null; 5955 return null;
5944 } 5956 }
5945 String uriContent = uriLiteral.stringValue.trim(); 5957 String uriContent = uriLiteral.stringValue.trim();
5946 if (uriContent == null) { 5958 if (uriContent == null || uriContent.isEmpty) {
5947 return null; 5959 return null;
5948 } 5960 }
5949 uriContent = Uri.encodeFull(uriContent); 5961 uriContent = Uri.encodeFull(uriContent);
5950 try { 5962 return _analysisContext.sourceFactory.resolveUri(librarySource, uriContent);
5951 parseUriWithException(uriContent);
5952 return _analysisContext.sourceFactory.resolveUri(librarySource, uriContent );
5953 } on URISyntaxException catch (exception) {
5954 return null;
5955 }
5956 } 5963 }
5957 5964
5958 /** 5965 /**
5959 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier] 5966 * Run additional analyses, such as the [ConstantVerifier] and [ErrorVerifier]
5960 * analysis in the current cycle. 5967 * analysis in the current cycle.
5961 * 5968 *
5962 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 5969 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
5963 * the library cannot be analyzed 5970 * the library cannot be analyzed
5964 */ 5971 */
5965 void runAdditionalAnalyses() { 5972 void runAdditionalAnalyses() {
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
6845 6852
6846 /** 6853 /**
6847 * Return the object used to access the types from the core library. 6854 * Return the object used to access the types from the core library.
6848 * 6855 *
6849 * @return the object used to access the types from the core library 6856 * @return the object used to access the types from the core library
6850 */ 6857 */
6851 TypeProvider get typeProvider => _typeProvider; 6858 TypeProvider get typeProvider => _typeProvider;
6852 Object visitBlock(Block node) { 6859 Object visitBlock(Block node) {
6853 Scope outerScope = _nameScope; 6860 Scope outerScope = _nameScope;
6854 try { 6861 try {
6855 _nameScope = new EnclosedScope(_nameScope); 6862 EnclosedScope enclosedScope = new EnclosedScope(_nameScope);
6863 hideNamesDefinedInBlock(enclosedScope, node);
6864 _nameScope = enclosedScope;
6856 super.visitBlock(node); 6865 super.visitBlock(node);
6857 } finally { 6866 } finally {
6858 _nameScope = outerScope; 6867 _nameScope = outerScope;
6859 } 6868 }
6860 return null; 6869 return null;
6861 } 6870 }
6862 Object visitCatchClause(CatchClause node) { 6871 Object visitCatchClause(CatchClause node) {
6863 SimpleIdentifier exception = node.exceptionParameter; 6872 SimpleIdentifier exception = node.exceptionParameter;
6864 if (exception != null) { 6873 if (exception != null) {
6865 Scope outerScope = _nameScope; 6874 Scope outerScope = _nameScope;
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
7195 LabelScope addScopesFor(NodeList<Label> labels) { 7204 LabelScope addScopesFor(NodeList<Label> labels) {
7196 LabelScope outerScope = _labelScope; 7205 LabelScope outerScope = _labelScope;
7197 for (Label label in labels) { 7206 for (Label label in labels) {
7198 SimpleIdentifier labelNameNode = label.label; 7207 SimpleIdentifier labelNameNode = label.label;
7199 String labelName = labelNameNode.name; 7208 String labelName = labelNameNode.name;
7200 LabelElement labelElement = labelNameNode.element as LabelElement; 7209 LabelElement labelElement = labelNameNode.element as LabelElement;
7201 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); 7210 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement);
7202 } 7211 }
7203 return outerScope; 7212 return outerScope;
7204 } 7213 }
7214
7215 /**
7216 * Marks the local declarations of the given [Block] hidden in the enclosing s cope.
7217 * According to the scoping rules name is hidden if block defines it, but name is defined after
7218 * its declaration statement.
7219 */
7220 void hideNamesDefinedInBlock(EnclosedScope scope, Block block) {
7221 for (Statement statement in block.statements) {
7222 if (statement is VariableDeclarationStatement) {
7223 VariableDeclarationStatement vds = statement as VariableDeclarationState ment;
7224 for (VariableDeclaration variableDeclaration in vds.variables.variables) {
7225 Element element = variableDeclaration.element;
7226 scope.hide(element);
7227 }
7228 }
7229 if (statement is FunctionDeclarationStatement) {
7230 FunctionDeclarationStatement fds = statement as FunctionDeclarationState ment;
7231 Element element = fds.functionDeclaration.element;
7232 scope.hide(element);
7233 }
7234 }
7235 }
7205 } 7236 }
7206 /** 7237 /**
7207 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F irst, they 7238 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F irst, they
7208 * compute the static type of every expression. Second, they look for any static type errors or 7239 * compute the static type of every expression. Second, they look for any static type errors or
7209 * warnings that might need to be generated. The requirements for the type analy zer are: 7240 * warnings that might need to be generated. The requirements for the type analy zer are:
7210 * <ol> 7241 * <ol>
7211 * * Every element that refers to types should be fully populated. 7242 * * Every element that refers to types should be fully populated.
7212 * * Every node representing an expression should be resolved to the Type of the expression. 7243 * * Every node representing an expression should be resolved to the Type of the expression.
7213 * </ol> 7244 * </ol>
7214 * 7245 *
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after
8959 } 8990 }
8960 /** 8991 /**
8961 * The interface `TypeProvider` defines the behavior of objects that provide acc ess to types 8992 * The interface `TypeProvider` defines the behavior of objects that provide acc ess to types
8962 * defined by the language. 8993 * defined by the language.
8963 * 8994 *
8964 * @coverage dart.engine.resolver 8995 * @coverage dart.engine.resolver
8965 */ 8996 */
8966 abstract class TypeProvider { 8997 abstract class TypeProvider {
8967 8998
8968 /** 8999 /**
9000 * Return the type representing the built-in type 'Null'.
9001 *
9002 * @return the type representing the built-in type 'null'
9003 */
9004 InterfaceType get nullType;
9005
9006 /**
8969 * Return the type representing the built-in type 'bool'. 9007 * Return the type representing the built-in type 'bool'.
8970 * 9008 *
8971 * @return the type representing the built-in type 'bool' 9009 * @return the type representing the built-in type 'bool'
8972 */ 9010 */
8973 InterfaceType get boolType; 9011 InterfaceType get boolType;
8974 9012
8975 /** 9013 /**
8976 * Return the type representing the type 'bottom'. 9014 * Return the type representing the type 'bottom'.
8977 * 9015 *
8978 * @return the type representing the type 'bottom' 9016 * @return the type representing the type 'bottom'
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
9105 * The type representing the built-in type 'List'. 9143 * The type representing the built-in type 'List'.
9106 */ 9144 */
9107 InterfaceType _listType; 9145 InterfaceType _listType;
9108 9146
9109 /** 9147 /**
9110 * The type representing the built-in type 'Map'. 9148 * The type representing the built-in type 'Map'.
9111 */ 9149 */
9112 InterfaceType _mapType; 9150 InterfaceType _mapType;
9113 9151
9114 /** 9152 /**
9153 * The type representing the type 'Null'.
9154 */
9155 InterfaceType _nullType;
9156
9157 /**
9115 * The type representing the built-in type 'num'. 9158 * The type representing the built-in type 'num'.
9116 */ 9159 */
9117 InterfaceType _numType; 9160 InterfaceType _numType;
9118 9161
9119 /** 9162 /**
9120 * The type representing the built-in type 'Object'. 9163 * The type representing the built-in type 'Object'.
9121 */ 9164 */
9122 InterfaceType _objectType; 9165 InterfaceType _objectType;
9123 9166
9124 /** 9167 /**
(...skipping 25 matching lines...) Expand all
9150 initializeFrom(coreLibrary); 9193 initializeFrom(coreLibrary);
9151 } 9194 }
9152 InterfaceType get boolType => _boolType; 9195 InterfaceType get boolType => _boolType;
9153 Type2 get bottomType => _bottomType; 9196 Type2 get bottomType => _bottomType;
9154 InterfaceType get doubleType => _doubleType; 9197 InterfaceType get doubleType => _doubleType;
9155 Type2 get dynamicType => _dynamicType; 9198 Type2 get dynamicType => _dynamicType;
9156 InterfaceType get functionType => _functionType; 9199 InterfaceType get functionType => _functionType;
9157 InterfaceType get intType => _intType; 9200 InterfaceType get intType => _intType;
9158 InterfaceType get listType => _listType; 9201 InterfaceType get listType => _listType;
9159 InterfaceType get mapType => _mapType; 9202 InterfaceType get mapType => _mapType;
9203 InterfaceType get nullType => _nullType;
9160 InterfaceType get numType => _numType; 9204 InterfaceType get numType => _numType;
9161 InterfaceType get objectType => _objectType; 9205 InterfaceType get objectType => _objectType;
9162 InterfaceType get stackTraceType => _stackTraceType; 9206 InterfaceType get stackTraceType => _stackTraceType;
9163 InterfaceType get stringType => _stringType; 9207 InterfaceType get stringType => _stringType;
9164 InterfaceType get symbolType => _symbolType; 9208 InterfaceType get symbolType => _symbolType;
9165 InterfaceType get typeType => _typeType; 9209 InterfaceType get typeType => _typeType;
9166 9210
9167 /** 9211 /**
9168 * Return the type with the given name from the given namespace, or `null` if there is no 9212 * Return the type with the given name from the given namespace, or `null` if there is no
9169 * class with the given name. 9213 * class with the given name.
(...skipping 19 matching lines...) Expand all
9189 void initializeFrom(LibraryElement library) { 9233 void initializeFrom(LibraryElement library) {
9190 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); 9234 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library);
9191 _boolType = getType(namespace, "bool"); 9235 _boolType = getType(namespace, "bool");
9192 _bottomType = BottomTypeImpl.instance; 9236 _bottomType = BottomTypeImpl.instance;
9193 _doubleType = getType(namespace, "double"); 9237 _doubleType = getType(namespace, "double");
9194 _dynamicType = DynamicTypeImpl.instance; 9238 _dynamicType = DynamicTypeImpl.instance;
9195 _functionType = getType(namespace, "Function"); 9239 _functionType = getType(namespace, "Function");
9196 _intType = getType(namespace, "int"); 9240 _intType = getType(namespace, "int");
9197 _listType = getType(namespace, "List"); 9241 _listType = getType(namespace, "List");
9198 _mapType = getType(namespace, "Map"); 9242 _mapType = getType(namespace, "Map");
9243 _nullType = getType(namespace, "Null");
9199 _numType = getType(namespace, "num"); 9244 _numType = getType(namespace, "num");
9200 _objectType = getType(namespace, "Object"); 9245 _objectType = getType(namespace, "Object");
9201 _stackTraceType = getType(namespace, "StackTrace"); 9246 _stackTraceType = getType(namespace, "StackTrace");
9202 _stringType = getType(namespace, "String"); 9247 _stringType = getType(namespace, "String");
9203 _symbolType = getType(namespace, "Symbol"); 9248 _symbolType = getType(namespace, "Symbol");
9204 _typeType = getType(namespace, "Type"); 9249 _typeType = getType(namespace, "Type");
9205 } 9250 }
9206 } 9251 }
9207 /** 9252 /**
9208 * Instances of the class `TypeResolverVisitor` are used to resolve the types as sociated with 9253 * Instances of the class `TypeResolverVisitor` are used to resolve the types as sociated with
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
10098 * @coverage dart.engine.resolver 10143 * @coverage dart.engine.resolver
10099 */ 10144 */
10100 class EnclosedScope extends Scope { 10145 class EnclosedScope extends Scope {
10101 10146
10102 /** 10147 /**
10103 * The scope in which this scope is lexically enclosed. 10148 * The scope in which this scope is lexically enclosed.
10104 */ 10149 */
10105 Scope _enclosingScope; 10150 Scope _enclosingScope;
10106 10151
10107 /** 10152 /**
10153 * A set of names that will be defined in this scope, but right now are not de fined. However
10154 * according to the scoping rules these names are hidden, even if they were de fined in an outer
10155 * scope.
10156 */
10157 Set<String> _hiddenNames = new Set<String>();
10158
10159 /**
10108 * Initialize a newly created scope enclosed within another scope. 10160 * Initialize a newly created scope enclosed within another scope.
10109 * 10161 *
10110 * @param enclosingScope the scope in which this scope is lexically enclosed 10162 * @param enclosingScope the scope in which this scope is lexically enclosed
10111 */ 10163 */
10112 EnclosedScope(Scope enclosingScope) { 10164 EnclosedScope(Scope enclosingScope) {
10113 this._enclosingScope = enclosingScope; 10165 this._enclosingScope = enclosingScope;
10114 } 10166 }
10115 LibraryElement get definingLibrary => _enclosingScope.definingLibrary; 10167 LibraryElement get definingLibrary => _enclosingScope.definingLibrary;
10116 AnalysisErrorListener get errorListener => _enclosingScope.errorListener; 10168 AnalysisErrorListener get errorListener => _enclosingScope.errorListener;
10117 10169
10118 /** 10170 /**
10171 * Hides the name of the given element in this scope. If there is already an e lement with the
10172 * given name defined in an outer scope, then it will become unavailable.
10173 *
10174 * @param element the element to be hidden in this scope
10175 */
10176 void hide(Element element) {
10177 if (element != null) {
10178 String name = element.name;
10179 if (name != null && !name.isEmpty) {
10180 javaSetAdd(_hiddenNames, name);
10181 }
10182 }
10183 }
10184
10185 /**
10119 * Return the scope in which this scope is lexically enclosed. 10186 * Return the scope in which this scope is lexically enclosed.
10120 * 10187 *
10121 * @return the scope in which this scope is lexically enclosed 10188 * @return the scope in which this scope is lexically enclosed
10122 */ 10189 */
10123 Scope get enclosingScope => _enclosingScope; 10190 Scope get enclosingScope => _enclosingScope;
10124 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) { 10191 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) {
10125 Element element = localLookup(name, referencingLibrary); 10192 Element element = localLookup(name, referencingLibrary);
10126 if (element != null) { 10193 if (element != null) {
10127 return element; 10194 return element;
10128 } 10195 }
10196 if (_hiddenNames.contains(name)) {
10197 return null;
10198 }
10129 return _enclosingScope.lookup3(identifier, name, referencingLibrary); 10199 return _enclosingScope.lookup3(identifier, name, referencingLibrary);
10130 } 10200 }
10131 } 10201 }
10132 /** 10202 /**
10133 * Instances of the class `FunctionScope` implement the scope defined by a funct ion. 10203 * Instances of the class `FunctionScope` implement the scope defined by a funct ion.
10134 * 10204 *
10135 * @coverage dart.engine.resolver 10205 * @coverage dart.engine.resolver
10136 */ 10206 */
10137 class FunctionScope extends EnclosedScope { 10207 class FunctionScope extends EnclosedScope {
10138 10208
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
10966 super.visitFunctionExpression(node); 11036 super.visitFunctionExpression(node);
10967 validateDefaultValues(node.parameters); 11037 validateDefaultValues(node.parameters);
10968 return null; 11038 return null;
10969 } 11039 }
10970 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 11040 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
10971 validateConstantArguments2(node); 11041 validateConstantArguments2(node);
10972 return super.visitInstanceCreationExpression(node); 11042 return super.visitInstanceCreationExpression(node);
10973 } 11043 }
10974 Object visitListLiteral(ListLiteral node) { 11044 Object visitListLiteral(ListLiteral node) {
10975 super.visitListLiteral(node); 11045 super.visitListLiteral(node);
10976 if (node.modifier != null) { 11046 if (node.constKeyword != null) {
10977 for (Expression element in node.elements) { 11047 for (Expression element in node.elements) {
10978 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); 11048 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT);
10979 } 11049 }
10980 } 11050 }
10981 return null; 11051 return null;
10982 } 11052 }
10983 Object visitMapLiteral(MapLiteral node) { 11053 Object visitMapLiteral(MapLiteral node) {
10984 super.visitMapLiteral(node); 11054 super.visitMapLiteral(node);
10985 bool isConst = node.modifier != null; 11055 bool isConst = node.constKeyword != null;
10986 bool reportEqualKeys = true; 11056 bool reportEqualKeys = true;
10987 Set<Object> keys = new Set<Object>(); 11057 Set<Object> keys = new Set<Object>();
10988 List<Expression> invalidKeys = new List<Expression>(); 11058 List<Expression> invalidKeys = new List<Expression>();
10989 for (MapLiteralEntry entry in node.entries) { 11059 for (MapLiteralEntry entry in node.entries) {
10990 Expression key = entry.key; 11060 Expression key = entry.key;
10991 if (isConst) { 11061 if (isConst) {
10992 EvaluationResultImpl result = validate(key, CompileTimeErrorCode.NON_CON STANT_MAP_KEY); 11062 EvaluationResultImpl result = validate(key, CompileTimeErrorCode.NON_CON STANT_MAP_KEY);
10993 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); 11063 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
10994 if (result is ValidResult) { 11064 if (result is ValidResult) {
10995 Object value = ((result as ValidResult)).value; 11065 Object value = ((result as ValidResult)).value;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
11293 /** 11363 /**
11294 * This is set to `true` iff the visitor is currently visiting children nodes of a 11364 * This is set to `true` iff the visitor is currently visiting children nodes of a
11295 * [CatchClause]. 11365 * [CatchClause].
11296 * 11366 *
11297 * @see #visitCatchClause(CatchClause) 11367 * @see #visitCatchClause(CatchClause)
11298 */ 11368 */
11299 bool _isInCatchClause = false; 11369 bool _isInCatchClause = false;
11300 11370
11301 /** 11371 /**
11302 * This is set to `true` iff the visitor is currently visiting children nodes of an 11372 * This is set to `true` iff the visitor is currently visiting children nodes of an
11373 * [Comment].
11374 */
11375 bool _isInComment = false;
11376
11377 /**
11378 * This is set to `true` iff the visitor is currently visiting children nodes of an
11303 * [InstanceCreationExpression]. 11379 * [InstanceCreationExpression].
11304 */ 11380 */
11305 bool _isInConstInstanceCreation = false; 11381 bool _isInConstInstanceCreation = false;
11306 11382
11307 /** 11383 /**
11308 * This is set to `true` iff the visitor is currently visiting children nodes of a native 11384 * This is set to `true` iff the visitor is currently visiting children nodes of a native
11309 * [ClassDeclaration]. 11385 * [ClassDeclaration].
11310 */ 11386 */
11311 bool _isInNativeClass = false; 11387 bool _isInNativeClass = false;
11312 11388
(...skipping 15 matching lines...) Expand all
11328 */ 11404 */
11329 bool _isInInstanceVariableInitializer = false; 11405 bool _isInInstanceVariableInitializer = false;
11330 11406
11331 /** 11407 /**
11332 * This is set to `true` iff the visitor is currently visiting a 11408 * This is set to `true` iff the visitor is currently visiting a
11333 * [ConstructorInitializer]. 11409 * [ConstructorInitializer].
11334 */ 11410 */
11335 bool _isInConstructorInitializer = false; 11411 bool _isInConstructorInitializer = false;
11336 11412
11337 /** 11413 /**
11414 * This is set to `true` iff the visitor is currently visiting a
11415 * [FunctionTypedFormalParameter].
11416 */
11417 bool _isInFunctionTypedFormalParameter = false;
11418
11419 /**
11338 * This is set to `true` iff the visitor is currently visiting a static method . By "method" 11420 * This is set to `true` iff the visitor is currently visiting a static method . By "method"
11339 * here getter, setter and operator declarations are also implied since they a re all represented 11421 * here getter, setter and operator declarations are also implied since they a re all represented
11340 * with a [MethodDeclaration] in the AST structure. 11422 * with a [MethodDeclaration] in the AST structure.
11341 */ 11423 */
11342 bool _isInStaticMethod = false; 11424 bool _isInStaticMethod = false;
11343 11425
11344 /** 11426 /**
11345 * This is set to `true` iff the visitor is currently visiting code in the SDK . 11427 * This is set to `true` iff the visitor is currently visiting code in the SDK .
11346 */ 11428 */
11347 bool _isInSystemLibrary = false; 11429 bool _isInSystemLibrary = false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
11408 _strictMode = currentLibrary.context.analysisOptions.strictMode; 11490 _strictMode = currentLibrary.context.analysisOptions.strictMode;
11409 _isEnclosingConstructorConst = false; 11491 _isEnclosingConstructorConst = false;
11410 _isInCatchClause = false; 11492 _isInCatchClause = false;
11411 _isInStaticVariableDeclaration = false; 11493 _isInStaticVariableDeclaration = false;
11412 _isInInstanceVariableDeclaration = false; 11494 _isInInstanceVariableDeclaration = false;
11413 _isInInstanceVariableInitializer = false; 11495 _isInInstanceVariableInitializer = false;
11414 _isInConstructorInitializer = false; 11496 _isInConstructorInitializer = false;
11415 _isInStaticMethod = false; 11497 _isInStaticMethod = false;
11416 _dynamicType = typeProvider.dynamicType; 11498 _dynamicType = typeProvider.dynamicType;
11417 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ 11499 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [
11500 typeProvider.nullType,
11418 typeProvider.numType, 11501 typeProvider.numType,
11419 typeProvider.intType, 11502 typeProvider.intType,
11420 typeProvider.doubleType, 11503 typeProvider.doubleType,
11421 typeProvider.boolType, 11504 typeProvider.boolType,
11422 typeProvider.stringType]; 11505 typeProvider.stringType];
11423 } 11506 }
11424 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { 11507 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
11425 checkForArgumentDefinitionTestNonParameter(node); 11508 checkForArgumentDefinitionTestNonParameter(node);
11426 return super.visitArgumentDefinitionTest(node); 11509 return super.visitArgumentDefinitionTest(node);
11427 } 11510 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
11504 ClassElement outerClassElement = _enclosingClass; 11587 ClassElement outerClassElement = _enclosingClass;
11505 try { 11588 try {
11506 _enclosingClass = node.element; 11589 _enclosingClass = node.element;
11507 checkForRecursiveInterfaceInheritance(node.element, new List<ClassElement> ()); 11590 checkForRecursiveInterfaceInheritance(node.element, new List<ClassElement> ());
11508 checkForTypeAliasCannotReferenceItself_mixin(node); 11591 checkForTypeAliasCannotReferenceItself_mixin(node);
11509 } finally { 11592 } finally {
11510 _enclosingClass = outerClassElement; 11593 _enclosingClass = outerClassElement;
11511 } 11594 }
11512 return super.visitClassTypeAlias(node); 11595 return super.visitClassTypeAlias(node);
11513 } 11596 }
11597 Object visitComment(Comment node) {
11598 _isInComment = true;
11599 try {
11600 return super.visitComment(node);
11601 } finally {
11602 _isInComment = false;
11603 }
11604 }
11514 Object visitConditionalExpression(ConditionalExpression node) { 11605 Object visitConditionalExpression(ConditionalExpression node) {
11515 checkForNonBoolCondition(node.condition); 11606 checkForNonBoolCondition(node.condition);
11516 return super.visitConditionalExpression(node); 11607 return super.visitConditionalExpression(node);
11517 } 11608 }
11518 Object visitConstructorDeclaration(ConstructorDeclaration node) { 11609 Object visitConstructorDeclaration(ConstructorDeclaration node) {
11519 ExecutableElement outerFunction = _enclosingFunction; 11610 ExecutableElement outerFunction = _enclosingFunction;
11520 try { 11611 try {
11521 _enclosingFunction = node.element; 11612 _enclosingFunction = node.element;
11522 _isEnclosingConstructorConst = node.constKeyword != null; 11613 _isEnclosingConstructorConst = node.constKeyword != null;
11523 checkForConstConstructorWithNonFinalField(node); 11614 checkForConstConstructorWithNonFinalField(node);
11615 checkForConstConstructorWithNonConstSuper(node);
11524 checkForConflictingConstructorNameAndMember(node); 11616 checkForConflictingConstructorNameAndMember(node);
11525 checkForAllFinalInitializedErrorCodes(node); 11617 checkForAllFinalInitializedErrorCodes(node);
11526 checkForRedirectingConstructorErrorCodes(node); 11618 checkForRedirectingConstructorErrorCodes(node);
11527 checkForMultipleSuperInitializers(node); 11619 checkForMultipleSuperInitializers(node);
11528 checkForRecursiveConstructorRedirect(node); 11620 checkForRecursiveConstructorRedirect(node);
11529 checkForRecursiveFactoryRedirect(node); 11621 if (!checkForRecursiveFactoryRedirect(node)) {
11530 checkForAllRedirectConstructorErrorCodes(node); 11622 checkForAllRedirectConstructorErrorCodes(node);
11623 }
11531 checkForUndefinedConstructorInInitializerImplicit(node); 11624 checkForUndefinedConstructorInInitializerImplicit(node);
11532 checkForRedirectToNonConstConstructor(node); 11625 checkForRedirectToNonConstConstructor(node);
11533 checkForReturnInGenerativeConstructor(node); 11626 checkForReturnInGenerativeConstructor(node);
11534 return super.visitConstructorDeclaration(node); 11627 return super.visitConstructorDeclaration(node);
11535 } finally { 11628 } finally {
11536 _isEnclosingConstructorConst = false; 11629 _isEnclosingConstructorConst = false;
11537 _enclosingFunction = outerFunction; 11630 _enclosingFunction = outerFunction;
11538 } 11631 }
11539 } 11632 }
11540 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 11633 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
11541 _isInConstructorInitializer = true; 11634 _isInConstructorInitializer = true;
11542 try { 11635 try {
11543 checkForFieldInitializerNotAssignable(node); 11636 checkForFieldInitializerNotAssignable(node);
11544 return super.visitConstructorFieldInitializer(node); 11637 return super.visitConstructorFieldInitializer(node);
11545 } finally { 11638 } finally {
11546 _isInConstructorInitializer = false; 11639 _isInConstructorInitializer = false;
11547 } 11640 }
11548 } 11641 }
11642 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
11643 checkForInvalidAssignment2(node.identifier, node.defaultValue);
11644 checkForDefaultValueInFunctionTypedParameter(node);
11645 return super.visitDefaultFormalParameter(node);
11646 }
11549 Object visitDoStatement(DoStatement node) { 11647 Object visitDoStatement(DoStatement node) {
11550 checkForNonBoolCondition(node.condition); 11648 checkForNonBoolCondition(node.condition);
11551 return super.visitDoStatement(node); 11649 return super.visitDoStatement(node);
11552 } 11650 }
11553 Object visitExportDirective(ExportDirective node) { 11651 Object visitExportDirective(ExportDirective node) {
11554 checkForAmbiguousExport(node); 11652 checkForAmbiguousExport(node);
11555 checkForExportDuplicateLibraryName(node); 11653 checkForExportDuplicateLibraryName(node);
11556 checkForExportInternalLibrary(node); 11654 checkForExportInternalLibrary(node);
11557 return super.visitExportDirective(node); 11655 return super.visitExportDirective(node);
11558 } 11656 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
11622 } else { 11720 } else {
11623 return super.visitFunctionExpression(node); 11721 return super.visitFunctionExpression(node);
11624 } 11722 }
11625 } 11723 }
11626 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 11724 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
11627 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 11725 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
11628 checkForDefaultValueInFunctionTypeAlias(node); 11726 checkForDefaultValueInFunctionTypeAlias(node);
11629 checkForTypeAliasCannotReferenceItself_function(node); 11727 checkForTypeAliasCannotReferenceItself_function(node);
11630 return super.visitFunctionTypeAlias(node); 11728 return super.visitFunctionTypeAlias(node);
11631 } 11729 }
11730 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
11731 bool old = _isInFunctionTypedFormalParameter;
11732 _isInFunctionTypedFormalParameter = true;
11733 try {
11734 return super.visitFunctionTypedFormalParameter(node);
11735 } finally {
11736 _isInFunctionTypedFormalParameter = old;
11737 }
11738 }
11632 Object visitIfStatement(IfStatement node) { 11739 Object visitIfStatement(IfStatement node) {
11633 checkForNonBoolCondition(node.condition); 11740 checkForNonBoolCondition(node.condition);
11634 return super.visitIfStatement(node); 11741 return super.visitIfStatement(node);
11635 } 11742 }
11636 Object visitImportDirective(ImportDirective node) { 11743 Object visitImportDirective(ImportDirective node) {
11637 checkForImportDuplicateLibraryName(node); 11744 checkForImportDuplicateLibraryName(node);
11638 checkForImportInternalLibrary(node); 11745 checkForImportInternalLibrary(node);
11639 return super.visitImportDirective(node); 11746 return super.visitImportDirective(node);
11640 } 11747 }
11641 Object visitIndexExpression(IndexExpression node) { 11748 Object visitIndexExpression(IndexExpression node) {
(...skipping 16 matching lines...) Expand all
11658 } else { 11765 } else {
11659 checkForNewWithUndefinedConstructor(node); 11766 checkForNewWithUndefinedConstructor(node);
11660 } 11767 }
11661 } 11768 }
11662 return super.visitInstanceCreationExpression(node); 11769 return super.visitInstanceCreationExpression(node);
11663 } finally { 11770 } finally {
11664 _isInConstInstanceCreation = false; 11771 _isInConstInstanceCreation = false;
11665 } 11772 }
11666 } 11773 }
11667 Object visitListLiteral(ListLiteral node) { 11774 Object visitListLiteral(ListLiteral node) {
11668 if (node.modifier != null) { 11775 if (node.constKeyword != null) {
11669 TypeArgumentList typeArguments = node.typeArguments; 11776 TypeArgumentList typeArguments = node.typeArguments;
11670 if (typeArguments != null) { 11777 if (typeArguments != null) {
11671 NodeList<TypeName> arguments = typeArguments.arguments; 11778 NodeList<TypeName> arguments = typeArguments.arguments;
11672 if (arguments.length != 0) { 11779 if (arguments.length != 0) {
11673 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 11780 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
11674 } 11781 }
11675 } 11782 }
11676 } 11783 }
11677 checkForListElementTypeNotAssignable(node); 11784 checkForListElementTypeNotAssignable(node);
11678 return super.visitListLiteral(node); 11785 return super.visitListLiteral(node);
11679 } 11786 }
11680 Object visitMapLiteral(MapLiteral node) { 11787 Object visitMapLiteral(MapLiteral node) {
11681 TypeArgumentList typeArguments = node.typeArguments; 11788 TypeArgumentList typeArguments = node.typeArguments;
11682 if (typeArguments != null) { 11789 if (typeArguments != null) {
11683 NodeList<TypeName> arguments = typeArguments.arguments; 11790 NodeList<TypeName> arguments = typeArguments.arguments;
11684 if (arguments.length != 0) { 11791 if (arguments.length != 0) {
11685 checkForInvalidTypeArgumentForKey(arguments); 11792 checkForInvalidTypeArgumentForKey(arguments);
11686 if (node.modifier != null) { 11793 if (node.constKeyword != null) {
11687 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 11794 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
11688 } 11795 }
11689 } 11796 }
11690 } 11797 }
11691 checkForNonConstMapAsExpressionStatement(node); 11798 checkForNonConstMapAsExpressionStatement(node);
11692 checkForMapTypeNotAssignable(node); 11799 checkForMapTypeNotAssignable(node);
11693 return super.visitMapLiteral(node); 11800 return super.visitMapLiteral(node);
11694 } 11801 }
11695 Object visitMethodDeclaration(MethodDeclaration node) { 11802 Object visitMethodDeclaration(MethodDeclaration node) {
11696 ExecutableElement previousFunction = _enclosingFunction; 11803 ExecutableElement previousFunction = _enclosingFunction;
(...skipping 22 matching lines...) Expand all
11719 } 11826 }
11720 checkForConcreteClassWithAbstractMember(node); 11827 checkForConcreteClassWithAbstractMember(node);
11721 checkForAllInvalidOverrideErrorCodes3(node); 11828 checkForAllInvalidOverrideErrorCodes3(node);
11722 return super.visitMethodDeclaration(node); 11829 return super.visitMethodDeclaration(node);
11723 } finally { 11830 } finally {
11724 _enclosingFunction = previousFunction; 11831 _enclosingFunction = previousFunction;
11725 _isInStaticMethod = false; 11832 _isInStaticMethod = false;
11726 } 11833 }
11727 } 11834 }
11728 Object visitMethodInvocation(MethodInvocation node) { 11835 Object visitMethodInvocation(MethodInvocation node) {
11729 checkForStaticAccessToInstanceMember(node.target, node.methodName); 11836 Expression target = node.realTarget;
11837 SimpleIdentifier methodName = node.methodName;
11838 checkForStaticAccessToInstanceMember(target, methodName);
11839 checkForInstanceAccessToStaticMember(target, methodName);
11730 return super.visitMethodInvocation(node); 11840 return super.visitMethodInvocation(node);
11731 } 11841 }
11732 Object visitNativeClause(NativeClause node) { 11842 Object visitNativeClause(NativeClause node) {
11733 if (!_isInSystemLibrary) { 11843 if (!_isInSystemLibrary) {
11734 _errorReporter.reportError2(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node, []); 11844 _errorReporter.reportError2(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node, []);
11735 } 11845 }
11736 return super.visitNativeClause(node); 11846 return super.visitNativeClause(node);
11737 } 11847 }
11738 Object visitNativeFunctionBody(NativeFunctionBody node) { 11848 Object visitNativeFunctionBody(NativeFunctionBody node) {
11739 checkForNativeFunctionBodyInNonSDKCode(node); 11849 checkForNativeFunctionBodyInNonSDKCode(node);
11740 return super.visitNativeFunctionBody(node); 11850 return super.visitNativeFunctionBody(node);
11741 } 11851 }
11742 Object visitPostfixExpression(PostfixExpression node) { 11852 Object visitPostfixExpression(PostfixExpression node) {
11743 checkForAssignmentToFinal2(node.operand); 11853 checkForAssignmentToFinal2(node.operand);
11744 checkForIntNotAssignable(node.operand); 11854 checkForIntNotAssignable(node.operand);
11745 return super.visitPostfixExpression(node); 11855 return super.visitPostfixExpression(node);
11746 } 11856 }
11747 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 11857 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
11748 if (node.parent is! Annotation) { 11858 if (node.parent is! Annotation) {
11749 checkForStaticAccessToInstanceMember(node.prefix, node.identifier); 11859 checkForStaticAccessToInstanceMember(node.prefix, node.identifier);
11860 checkForInstanceAccessToStaticMember(node.prefix, node.identifier);
11750 } 11861 }
11751 return super.visitPrefixedIdentifier(node); 11862 return super.visitPrefixedIdentifier(node);
11752 } 11863 }
11753 Object visitPrefixExpression(PrefixExpression node) { 11864 Object visitPrefixExpression(PrefixExpression node) {
11754 if (node.operator.type.isIncrementOperator) { 11865 if (node.operator.type.isIncrementOperator) {
11755 checkForAssignmentToFinal2(node.operand); 11866 checkForAssignmentToFinal2(node.operand);
11756 } 11867 }
11757 checkForIntNotAssignable(node.operand); 11868 checkForIntNotAssignable(node.operand);
11758 return super.visitPrefixExpression(node); 11869 return super.visitPrefixExpression(node);
11759 } 11870 }
11760 Object visitPropertyAccess(PropertyAccess node) { 11871 Object visitPropertyAccess(PropertyAccess node) {
11761 Expression target = node.realTarget; 11872 Expression target = node.realTarget;
11762 checkForStaticAccessToInstanceMember(target, node.propertyName); 11873 SimpleIdentifier propertyName = node.propertyName;
11874 checkForStaticAccessToInstanceMember(target, propertyName);
11875 checkForInstanceAccessToStaticMember(target, propertyName);
11763 return super.visitPropertyAccess(node); 11876 return super.visitPropertyAccess(node);
11764 } 11877 }
11765 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 11878 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
11766 _isInConstructorInitializer = true; 11879 _isInConstructorInitializer = true;
11767 try { 11880 try {
11768 return super.visitRedirectingConstructorInvocation(node); 11881 return super.visitRedirectingConstructorInvocation(node);
11769 } finally { 11882 } finally {
11770 _isInConstructorInitializer = false; 11883 _isInConstructorInitializer = false;
11771 } 11884 }
11772 } 11885 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
11934 foundError = true; 12047 foundError = true;
11935 } 12048 }
11936 } 12049 }
11937 } 12050 }
11938 return foundError; 12051 return foundError;
11939 } 12052 }
11940 12053
11941 /** 12054 /**
11942 * This checks the passed executable element against override-error codes. 12055 * This checks the passed executable element against override-error codes.
11943 * 12056 *
11944 * @param executableElement the [ExecutableElement] to evaluate 12057 * @param executableElement a non-null [ExecutableElement] to evaluate
11945 * @param parameters the parameters of the executable element 12058 * @param parameters the parameters of the executable element
11946 * @param errorNameTarget the node to report problems on 12059 * @param errorNameTarget the node to report problems on
11947 * @return `true` if and only if an error code is generated on the passed node 12060 * @return `true` if and only if an error code is generated on the passed node
11948 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC 12061 * @see StaticWarningCode#INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLASS_STATIC
11949 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED 12062 * @see CompileTimeErrorCode#INVALID_OVERRIDE_REQUIRED
11950 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL 12063 * @see CompileTimeErrorCode#INVALID_OVERRIDE_POSITIONAL
11951 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED 12064 * @see CompileTimeErrorCode#INVALID_OVERRIDE_NAMED
11952 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE 12065 * @see StaticWarningCode#INVALID_GETTER_OVERRIDE_RETURN_TYPE
11953 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE 12066 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_RETURN_TYPE
11954 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE 12067 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE
11955 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE 12068 * @see StaticWarningCode#INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE
11956 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE 12069 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE
11957 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE 12070 * @see StaticWarningCode#INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE
11958 * @see StaticWarningCode#INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES 12071 * @see StaticWarningCode#INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES
11959 */ 12072 */
11960 bool checkForAllInvalidOverrideErrorCodes(ExecutableElement executableElement, List<ParameterElement> parameters2, List<ASTNode> parameterLocations, SimpleIde ntifier errorNameTarget) { 12073 bool checkForAllInvalidOverrideErrorCodes(ExecutableElement executableElement, List<ParameterElement> parameters2, List<ASTNode> parameterLocations, SimpleIde ntifier errorNameTarget) {
11961 String executableElementName = executableElement.name; 12074 String executableElementName = executableElement.name;
11962 ExecutableElement overriddenExecutable = _inheritanceManager.lookupInheritan ce(_enclosingClass, executableElement.name); 12075 ExecutableElement overriddenExecutable = _inheritanceManager.lookupInheritan ce(_enclosingClass, executableElementName);
11963 bool isGetter = false; 12076 bool isGetter = false;
11964 bool isSetter = false; 12077 bool isSetter = false;
11965 if (executableElement is PropertyAccessorElement) { 12078 if (executableElement is PropertyAccessorElement) {
11966 PropertyAccessorElement accessorElement = executableElement as PropertyAcc essorElement; 12079 PropertyAccessorElement accessorElement = executableElement as PropertyAcc essorElement;
11967 isGetter = accessorElement.isGetter; 12080 isGetter = accessorElement.isGetter;
11968 isSetter = accessorElement.isSetter; 12081 isSetter = accessorElement.isSetter;
11969 } 12082 }
11970 if (overriddenExecutable == null) { 12083 if (overriddenExecutable == null) {
11971 if (!isGetter && !isSetter && !executableElement.isOperator) { 12084 if (!isGetter && !isSetter && !executableElement.isOperator) {
11972 Set<ClassElement> visitedClasses = new Set<ClassElement>(); 12085 Set<ClassElement> visitedClasses = new Set<ClassElement>();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
12007 } 12120 }
12008 Type2 overridingFTReturnType = overridingFT.returnType; 12121 Type2 overridingFTReturnType = overridingFT.returnType;
12009 Type2 overriddenFTReturnType = overriddenFT.returnType; 12122 Type2 overriddenFTReturnType = overriddenFT.returnType;
12010 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes; 12123 List<Type2> overridingNormalPT = overridingFT.normalParameterTypes;
12011 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes; 12124 List<Type2> overriddenNormalPT = overriddenFT.normalParameterTypes;
12012 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes; 12125 List<Type2> overridingPositionalPT = overridingFT.optionalParameterTypes;
12013 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes; 12126 List<Type2> overriddenPositionalPT = overriddenFT.optionalParameterTypes;
12014 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes; 12127 Map<String, Type2> overridingNamedPT = overridingFT.namedParameterTypes;
12015 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes; 12128 Map<String, Type2> overriddenNamedPT = overriddenFT.namedParameterTypes;
12016 if (overridingNormalPT.length != overriddenNormalPT.length) { 12129 if (overridingNormalPT.length != overriddenNormalPT.length) {
12017 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED , errorNameTarget, [ 12130 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_REQUIRED, e rrorNameTarget, [
12018 overriddenNormalPT.length, 12131 overriddenNormalPT.length,
12019 overriddenExecutable.enclosingElement.displayName]); 12132 overriddenExecutable.enclosingElement.displayName]);
12020 return true; 12133 return true;
12021 } 12134 }
12022 if (overridingPositionalPT.length < overriddenPositionalPT.length) { 12135 if (overridingPositionalPT.length < overriddenPositionalPT.length) {
12023 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_POSITION AL, errorNameTarget, [ 12136 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_POSITIONAL, errorNameTarget, [
12024 overriddenPositionalPT.length, 12137 overriddenPositionalPT.length,
12025 overriddenExecutable.enclosingElement.displayName]); 12138 overriddenExecutable.enclosingElement.displayName]);
12026 return true; 12139 return true;
12027 } 12140 }
12028 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet(); 12141 Set<String> overridingParameterNameSet = overridingNamedPT.keys.toSet();
12029 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over riddenNamedPT.keys.toSet()); 12142 JavaIterator<String> overriddenParameterNameIterator = new JavaIterator(over riddenNamedPT.keys.toSet());
12030 while (overriddenParameterNameIterator.hasNext) { 12143 while (overriddenParameterNameIterator.hasNext) {
12031 String overriddenParamName = overriddenParameterNameIterator.next(); 12144 String overriddenParamName = overriddenParameterNameIterator.next();
12032 if (!overridingParameterNameSet.contains(overriddenParamName)) { 12145 if (!overridingParameterNameSet.contains(overriddenParamName)) {
12033 _errorReporter.reportError2(CompileTimeErrorCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ 12146 _errorReporter.reportError2(StaticWarningCode.INVALID_OVERRIDE_NAMED, er rorNameTarget, [
12034 overriddenParamName, 12147 overriddenParamName,
12035 overriddenExecutable.enclosingElement.displayName]); 12148 overriddenExecutable.enclosingElement.displayName]);
12036 return true; 12149 return true;
12037 } 12150 }
12038 } 12151 }
12039 if (overriddenFTReturnType != VoidTypeImpl.instance && !overridingFTReturnTy pe.isAssignableTo(overriddenFTReturnType)) { 12152 if (overriddenFTReturnType != VoidTypeImpl.instance && !overridingFTReturnTy pe.isAssignableTo(overriddenFTReturnType)) {
12040 _errorReporter.reportError2(!isGetter ? StaticWarningCode.INVALID_METHOD_O VERRIDE_RETURN_TYPE : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, err orNameTarget, [ 12153 _errorReporter.reportError2(!isGetter ? StaticWarningCode.INVALID_METHOD_O VERRIDE_RETURN_TYPE : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, err orNameTarget, [
12041 overridingFTReturnType.displayName, 12154 overridingFTReturnType.displayName,
12042 overriddenFTReturnType.displayName, 12155 overriddenFTReturnType.displayName,
12043 overriddenExecutable.enclosingElement.displayName]); 12156 overriddenExecutable.enclosingElement.displayName]);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
12101 List<ParameterElement> overriddenPEs = overriddenExecutable.parameters; 12214 List<ParameterElement> overriddenPEs = overriddenExecutable.parameters;
12102 for (int i = 0; i < parameters2.length; i++) { 12215 for (int i = 0; i < parameters2.length; i++) {
12103 ParameterElement parameter = parameters2[i]; 12216 ParameterElement parameter = parameters2[i];
12104 if (parameter.parameterKind.isOptional) { 12217 if (parameter.parameterKind.isOptional) {
12105 formalParameters.add(parameterLocations[i]); 12218 formalParameters.add(parameterLocations[i]);
12106 parameterElts.add((parameter as ParameterElementImpl)); 12219 parameterElts.add((parameter as ParameterElementImpl));
12107 } 12220 }
12108 } 12221 }
12109 for (ParameterElement parameterElt in overriddenPEs) { 12222 for (ParameterElement parameterElt in overriddenPEs) {
12110 if (parameterElt.parameterKind.isOptional) { 12223 if (parameterElt.parameterKind.isOptional) {
12111 overriddenParameterElts.add((parameterElt as ParameterElementImpl)); 12224 if (parameterElt is ParameterElementImpl) {
12225 overriddenParameterElts.add((parameterElt as ParameterElementImpl));
12226 } else if (parameterElt is ParameterMember) {
12227 overriddenParameterElts.add((((parameterElt as ParameterMember)).baseE lement as ParameterElementImpl));
12228 }
12112 } 12229 }
12113 } 12230 }
12114 if (parameterElts.length > 0) { 12231 if (parameterElts.length > 0) {
12115 if (identical(parameterElts[0].parameterKind, ParameterKind.NAMED)) { 12232 if (identical(parameterElts[0].parameterKind, ParameterKind.NAMED)) {
12116 for (int i = 0; i < parameterElts.length; i++) { 12233 for (int i = 0; i < parameterElts.length; i++) {
12117 ParameterElementImpl parameterElt = parameterElts[i]; 12234 ParameterElementImpl parameterElt = parameterElts[i];
12118 EvaluationResultImpl result = parameterElt.evaluationResult; 12235 EvaluationResultImpl result = parameterElt.evaluationResult;
12119 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) { 12236 if (result == null || identical(result, ValidResult.RESULT_OBJECT)) {
12120 continue; 12237 continue;
12121 } 12238 }
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
12885 if (member.isStatic) { 13002 if (member.isStatic) {
12886 return false; 13003 return false;
12887 } 13004 }
12888 ClassElement memberClass = member.enclosingElement as ClassElement; 13005 ClassElement memberClass = member.enclosingElement as ClassElement;
12889 InterfaceType memberType = memberClass.type; 13006 InterfaceType memberType = memberClass.type;
12890 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_ INSTANCE_MEMBER, nameNode, [memberType.displayName]); 13007 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_ INSTANCE_MEMBER, nameNode, [memberType.displayName]);
12891 return true; 13008 return true;
12892 } 13009 }
12893 13010
12894 /** 13011 /**
12895 * This verifies that the passed constructor declaration is 'const' then there are no non-final 13012 * This verifies that if the passed constructor declaration is 'const' then th ere are no
13013 * invocations of non-'const' super constructors.
13014 *
13015 * @param node the constructor declaration to evaluate
13016 * @return `true` if and only if an error code is generated on the passed node
13017 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER
13018 */
13019 bool checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) {
13020 if (!_isEnclosingConstructorConst) {
13021 return false;
13022 }
13023 if (node.factoryKeyword != null) {
13024 return false;
13025 }
13026 for (ConstructorInitializer initializer in node.initializers) {
13027 if (initializer is SuperConstructorInvocation) {
13028 SuperConstructorInvocation superInvocation = initializer as SuperConstru ctorInvocation;
13029 ConstructorElement element = superInvocation.element;
13030 if (element.isConst) {
13031 return false;
13032 }
13033 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_ NON_CONST_SUPER, superInvocation, []);
13034 return true;
13035 }
13036 }
13037 InterfaceType supertype = _enclosingClass.supertype;
13038 if (supertype == null) {
13039 return false;
13040 }
13041 if (supertype.isObject) {
13042 return false;
13043 }
13044 ConstructorElement unnamedConstructor = supertype.element.unnamedConstructor ;
13045 if (unnamedConstructor == null) {
13046 return false;
13047 }
13048 if (unnamedConstructor.isConst) {
13049 return false;
13050 }
13051 _errorReporter.reportError2(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_ CONST_SUPER, node, []);
13052 return true;
13053 }
13054
13055 /**
13056 * This verifies that if the passed constructor declaration is 'const' then th ere are no non-final
12896 * instance variable. 13057 * instance variable.
12897 * 13058 *
12898 * @param node the constructor declaration to evaluate 13059 * @param node the constructor declaration to evaluate
12899 * @return `true` if and only if an error code is generated on the passed node 13060 * @return `true` if and only if an error code is generated on the passed node
12900 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 13061 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD
12901 */ 13062 */
12902 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { 13063 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) {
12903 if (!_isEnclosingConstructorConst) { 13064 if (!_isEnclosingConstructorConst) {
12904 return false; 13065 return false;
12905 } 13066 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
13087 if (defaultFormalParameter.defaultValue != null) { 13248 if (defaultFormalParameter.defaultValue != null) {
13088 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPE_ALIAS, node, []); 13249 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC TION_TYPE_ALIAS, node, []);
13089 result = true; 13250 result = true;
13090 } 13251 }
13091 } 13252 }
13092 } 13253 }
13093 return result; 13254 return result;
13094 } 13255 }
13095 13256
13096 /** 13257 /**
13258 * This verifies that the given default formal parameter is not part of a func tion typed
13259 * parameter.
13260 *
13261 * @param node the default formal parameter to evaluate
13262 * @return `true` if and only if an error code is generated on the passed node
13263 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER
13264 */
13265 bool checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node) {
13266 if (!_isInFunctionTypedFormalParameter) {
13267 return false;
13268 }
13269 if (node.defaultValue == null) {
13270 return false;
13271 }
13272 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_T YPED_PARAMETER, node, []);
13273 return true;
13274 }
13275
13276 /**
13097 * This verifies that the enclosing class does not have an instance member wit h the given name of 13277 * This verifies that the enclosing class does not have an instance member wit h the given name of
13098 * the static member. 13278 * the static member.
13099 * 13279 *
13100 * @return `true` if and only if an error code is generated on the passed node 13280 * @return `true` if and only if an error code is generated on the passed node
13101 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE 13281 * @see CompileTimeErrorCode#DUPLICATE_DEFINITION_INHERITANCE
13102 */ 13282 */
13103 bool checkForDuplicateDefinitionInheritance() { 13283 bool checkForDuplicateDefinitionInheritance() {
13104 if (_enclosingClass == null) { 13284 if (_enclosingClass == null) {
13105 return false; 13285 return false;
13106 } 13286 }
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
13562 if (errors == null || errors.isEmpty) { 13742 if (errors == null || errors.isEmpty) {
13563 return false; 13743 return false;
13564 } 13744 }
13565 for (AnalysisError error in errors) { 13745 for (AnalysisError error in errors) {
13566 _errorReporter.reportError(error); 13746 _errorReporter.reportError(error);
13567 } 13747 }
13568 return true; 13748 return true;
13569 } 13749 }
13570 13750
13571 /** 13751 /**
13752 * This checks that if the given "target" is not a type reference then the "na me" is reference to
13753 * a instance member.
13754 *
13755 * @param target the target of the name access to evaluate
13756 * @param name the accessed name to evaluate
13757 * @return `true` if and only if an error code is generated on the passed node
13758 * @see StaticTypeWarningCode#INSTANCE_ACCESS_TO_STATIC_MEMBER
13759 */
13760 bool checkForInstanceAccessToStaticMember(Expression target, SimpleIdentifier name2) {
13761 if (target == null) {
13762 return false;
13763 }
13764 if (_isInComment) {
13765 return false;
13766 }
13767 Element element = name2.element;
13768 if (element is! ExecutableElement) {
13769 return false;
13770 }
13771 ExecutableElement executableElement = element as ExecutableElement;
13772 if (executableElement.enclosingElement is! ClassElement) {
13773 return false;
13774 }
13775 if (!executableElement.isStatic) {
13776 return false;
13777 }
13778 if (isTypeReference(target)) {
13779 return false;
13780 }
13781 _errorReporter.reportError2(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_ MEMBER, name2, [name2.name]);
13782 return true;
13783 }
13784
13785 /**
13572 * This verifies that an 'int' can be assigned to the parameter corresponding to the given 13786 * This verifies that an 'int' can be assigned to the parameter corresponding to the given
13573 * expression. This is used for prefix and postfix expressions where the argum ent value is 13787 * expression. This is used for prefix and postfix expressions where the argum ent value is
13574 * implicit. 13788 * implicit.
13575 * 13789 *
13576 * @param argument the expression to which the operator is being applied 13790 * @param argument the expression to which the operator is being applied
13577 * @return `true` if and only if an error code is generated on the passed node 13791 * @return `true` if and only if an error code is generated on the passed node
13578 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 13792 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
13579 * @see CompileTimeErrorCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 13793 * @see CompileTimeErrorCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
13580 */ 13794 */
13581 bool checkForIntNotAssignable(Expression argument) { 13795 bool checkForIntNotAssignable(Expression argument) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
13724 TypeArgumentList typeArgumentList = node.typeArguments; 13938 TypeArgumentList typeArgumentList = node.typeArguments;
13725 if (typeArgumentList == null) { 13939 if (typeArgumentList == null) {
13726 return false; 13940 return false;
13727 } 13941 }
13728 NodeList<TypeName> typeArguments = typeArgumentList.arguments; 13942 NodeList<TypeName> typeArguments = typeArgumentList.arguments;
13729 if (typeArguments.length < 1) { 13943 if (typeArguments.length < 1) {
13730 return false; 13944 return false;
13731 } 13945 }
13732 Type2 listElementType = typeArguments[0].type; 13946 Type2 listElementType = typeArguments[0].type;
13733 ErrorCode errorCode; 13947 ErrorCode errorCode;
13734 if (node.modifier != null) { 13948 if (node.constKeyword != null) {
13735 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; 13949 errorCode = CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE;
13736 } else { 13950 } else {
13737 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE; 13951 errorCode = StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE;
13738 } 13952 }
13739 bool hasProblems = false; 13953 bool hasProblems = false;
13740 for (Expression element in node.elements) { 13954 for (Expression element in node.elements) {
13741 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable 3(element, listElementType, null, errorCode)); 13955 hasProblems = javaBooleanOr(hasProblems, checkForArgumentTypeNotAssignable 3(element, listElementType, null, errorCode));
13742 } 13956 }
13743 return hasProblems; 13957 return hasProblems;
13744 } 13958 }
(...skipping 15 matching lines...) Expand all
13760 return false; 13974 return false;
13761 } 13975 }
13762 NodeList<TypeName> typeArguments = typeArgumentList.arguments; 13976 NodeList<TypeName> typeArguments = typeArgumentList.arguments;
13763 if (typeArguments.length < 2) { 13977 if (typeArguments.length < 2) {
13764 return false; 13978 return false;
13765 } 13979 }
13766 Type2 keyType = typeArguments[0].type; 13980 Type2 keyType = typeArguments[0].type;
13767 Type2 valueType = typeArguments[1].type; 13981 Type2 valueType = typeArguments[1].type;
13768 ErrorCode keyErrorCode; 13982 ErrorCode keyErrorCode;
13769 ErrorCode valueErrorCode; 13983 ErrorCode valueErrorCode;
13770 if (node.modifier != null) { 13984 if (node.constKeyword != null) {
13771 keyErrorCode = CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; 13985 keyErrorCode = CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE;
13772 valueErrorCode = CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; 13986 valueErrorCode = CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE;
13773 } else { 13987 } else {
13774 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE; 13988 keyErrorCode = StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE;
13775 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE; 13989 valueErrorCode = StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE;
13776 } 13990 }
13777 bool hasProblems = false; 13991 bool hasProblems = false;
13778 NodeList<MapLiteralEntry> entries = node.entries; 13992 NodeList<MapLiteralEntry> entries = node.entries;
13779 for (MapLiteralEntry entry in entries) { 13993 for (MapLiteralEntry entry in entries) {
13780 Expression key = entry.key; 13994 Expression key = entry.key;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
14149 * * has `const modifier` 14363 * * has `const modifier`
14150 * * has explicit type arguments 14364 * * has explicit type arguments
14151 * * is not start of the statement 14365 * * is not start of the statement
14152 * 14366 *
14153 * 14367 *
14154 * @param node the map literal to evaluate 14368 * @param node the map literal to evaluate
14155 * @return `true` if and only if an error code is generated on the passed node 14369 * @return `true` if and only if an error code is generated on the passed node
14156 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT 14370 * @see CompileTimeErrorCode#NON_CONST_MAP_AS_EXPRESSION_STATEMENT
14157 */ 14371 */
14158 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) { 14372 bool checkForNonConstMapAsExpressionStatement(MapLiteral node) {
14159 if (node.modifier != null) { 14373 if (node.constKeyword != null) {
14160 return false; 14374 return false;
14161 } 14375 }
14162 if (node.typeArguments != null) { 14376 if (node.typeArguments != null) {
14163 return false; 14377 return false;
14164 } 14378 }
14165 Statement statement = node.getAncestor(ExpressionStatement); 14379 Statement statement = node.getAncestor(ExpressionStatement);
14166 if (statement == null) { 14380 if (statement == null) {
14167 return false; 14381 return false;
14168 } 14382 }
14169 if (statement.beginToken != node.beginToken) { 14383 if (statement.beginToken != node.beginToken) {
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
14685 Type2 argType = argTypeName.type; 14899 Type2 argType = argTypeName.type;
14686 Type2 boundType = boundingElts[i].bound; 14900 Type2 boundType = boundingElts[i].bound;
14687 if (argType != null && boundType != null) { 14901 if (argType != null && boundType != null) {
14688 if (!argType.isSubtypeOf(boundType)) { 14902 if (!argType.isSubtypeOf(boundType)) {
14689 ErrorCode errorCode; 14903 ErrorCode errorCode;
14690 if (isInConstConstructorInvocation(node)) { 14904 if (isInConstConstructorInvocation(node)) {
14691 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 14905 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
14692 } else { 14906 } else {
14693 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 14907 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
14694 } 14908 }
14695 _errorReporter.reportError2(errorCode, argTypeName, [argTypeName.name, boundType.displayName]); 14909 _errorReporter.reportError2(errorCode, argTypeName, [argType.displayNa me, boundType.displayName]);
14696 foundError = true; 14910 foundError = true;
14697 } 14911 }
14698 } 14912 }
14699 } 14913 }
14700 return foundError; 14914 return foundError;
14701 } 14915 }
14702 14916
14703 /** 14917 /**
14704 * This checks that if the passed type name is a type parameter being used to define a static 14918 * This checks that if the passed type name is a type parameter being used to define a static
14705 * member. 14919 * member.
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
15214 this._type = type; 15428 this._type = type;
15215 this._message = message; 15429 this._message = message;
15216 } 15430 }
15217 ErrorSeverity get errorSeverity => _type.severity; 15431 ErrorSeverity get errorSeverity => _type.severity;
15218 String get message => _message; 15432 String get message => _message;
15219 ErrorType get type => _type; 15433 ErrorType get type => _type;
15220 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal; 15434 int compareTo(ResolverErrorCode other) => ordinal - other.ordinal;
15221 int get hashCode => ordinal; 15435 int get hashCode => ordinal;
15222 String toString() => name; 15436 String toString() => name;
15223 } 15437 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/parser.dart ('k') | pkg/analyzer_experimental/lib/src/generated/sdk_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698