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

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

Issue 103233003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.resolver; 4 library engine.resolver;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'java_core.dart'; 7 import 'java_core.dart';
8 import 'java_engine.dart'; 8 import 'java_engine.dart';
9 import 'instrumentation.dart'; 9 import 'instrumentation.dart';
10 import 'source.dart'; 10 import 'source.dart';
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (constructors.length == 0) { 145 if (constructors.length == 0) {
146 constructors = createDefaultConstructors(interfaceType); 146 constructors = createDefaultConstructors(interfaceType);
147 } 147 }
148 element.abstract = node.abstractKeyword != null; 148 element.abstract = node.abstractKeyword != null;
149 element.accessors = holder.accessors; 149 element.accessors = holder.accessors;
150 element.constructors = constructors; 150 element.constructors = constructors;
151 element.fields = holder.fields; 151 element.fields = holder.fields;
152 element.methods = holder.methods; 152 element.methods = holder.methods;
153 element.typeParameters = typeParameters; 153 element.typeParameters = typeParameters;
154 element.validMixin = _isValidMixin; 154 element.validMixin = _isValidMixin;
155 for (FunctionTypeImpl functionType in _functionTypesToFix) { 155 int functionTypeCount = _functionTypesToFix.length;
156 functionType.typeArguments = typeArguments; 156 for (int i = 0; i < functionTypeCount; i++) {
157 _functionTypesToFix[i].typeArguments = typeArguments;
157 } 158 }
158 _functionTypesToFix = null; 159 _functionTypesToFix = null;
159 _currentHolder.addType(element); 160 _currentHolder.addType(element);
160 className.staticElement = element; 161 className.staticElement = element;
161 holder.validate(); 162 holder.validate();
162 return null; 163 return null;
163 } 164 }
164 165
165 Object visitClassTypeAlias(ClassTypeAlias node) { 166 Object visitClassTypeAlias(ClassTypeAlias node) {
166 ElementHolder holder = new ElementHolder(); 167 ElementHolder holder = new ElementHolder();
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 if (builder.length > 0) { 1102 if (builder.length > 0) {
1102 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui lder.toString()}"); 1103 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui lder.toString()}");
1103 } 1104 }
1104 } 1105 }
1105 } 1106 }
1106 1107
1107 /** 1108 /**
1108 * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit. 1109 * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit.
1109 */ 1110 */
1110 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { 1111 class HtmlUnitBuilder implements ht.XmlVisitor<Object> {
1111 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\"";
1112
1113 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'";
1114
1115 static String _SCRIPT = "script";
1116
1117 static String _SRC = "src"; 1112 static String _SRC = "src";
1118 1113
1119 static String _TYPE = "type";
1120
1121 /** 1114 /**
1122 * The analysis context in which the element model will be built. 1115 * The analysis context in which the element model will be built.
1123 */ 1116 */
1124 InternalAnalysisContext _context; 1117 InternalAnalysisContext _context;
1125 1118
1126 /** 1119 /**
1127 * The error listener to which errors will be reported. 1120 * The error listener to which errors will be reported.
1128 */ 1121 */
1129 RecordingErrorListener errorListener; 1122 RecordingErrorListener errorListener;
1130 1123
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 _lineInfo = _context.computeLineInfo(source); 1185 _lineInfo = _context.computeLineInfo(source);
1193 HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName); 1186 HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName);
1194 result.source = source; 1187 result.source = source;
1195 _htmlElement = result; 1188 _htmlElement = result;
1196 unit.accept(this); 1189 unit.accept(this);
1197 _htmlElement = null; 1190 _htmlElement = null;
1198 unit.element = result; 1191 unit.element = result;
1199 return result; 1192 return result;
1200 } 1193 }
1201 1194
1195 Object visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) {
1196 if (_parentNodes.contains(node)) {
1197 return reportCircularity(node);
1198 }
1199 _parentNodes.add(node);
1200 try {
1201 Source htmlSource = _htmlElement.source;
1202 ht.XmlAttributeNode scriptAttribute = getScriptSourcePath(node);
1203 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribute .text;
1204 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) {
1205 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node);
1206 try {
1207 LibraryResolver resolver = new LibraryResolver(_context);
1208 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSourc e, _modificationStamp, node.script, true) as LibraryElementImpl;
1209 script.scriptLibrary = library;
1210 resolvedLibraries.addAll(resolver.resolvedLibraries);
1211 errorListener.addAll(resolver.errorListener);
1212 } on AnalysisException catch (exception) {
1213 AnalysisEngine.instance.logger.logError3(exception);
1214 }
1215 node.scriptElement = script;
1216 _scripts.add(script);
1217 } else {
1218 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node);
1219 if (scriptSourcePath != null) {
1220 try {
1221 scriptSourcePath = Uri.encodeFull(scriptSourcePath);
1222 parseUriWithException(scriptSourcePath);
1223 Source scriptSource = _context.sourceFactory.resolveUri(htmlSource, scriptSourcePath);
1224 script.scriptSource = scriptSource;
1225 if (scriptSource == null || !scriptSource.exists()) {
1226 reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST, scriptAttribu te, [scriptSourcePath]);
1227 }
1228 } on URISyntaxException catch (exception) {
1229 reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute, [scri ptSourcePath]);
1230 }
1231 }
1232 node.scriptElement = script;
1233 _scripts.add(script);
1234 }
1235 } finally {
1236 _parentNodes.remove(node);
1237 }
1238 return null;
1239 }
1240
1202 Object visitHtmlUnit(ht.HtmlUnit node) { 1241 Object visitHtmlUnit(ht.HtmlUnit node) {
1203 _parentNodes = new List<ht.XmlTagNode>(); 1242 _parentNodes = new List<ht.XmlTagNode>();
1204 _scripts = new List<HtmlScriptElement>(); 1243 _scripts = new List<HtmlScriptElement>();
1205 try { 1244 try {
1206 node.visitChildren(this); 1245 node.visitChildren(this);
1207 _htmlElement.scripts = new List.from(_scripts); 1246 _htmlElement.scripts = new List.from(_scripts);
1208 } finally { 1247 } finally {
1209 _scripts = null; 1248 _scripts = null;
1210 _parentNodes = null; 1249 _parentNodes = null;
1211 } 1250 }
1212 return null; 1251 return null;
1213 } 1252 }
1214 1253
1215 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null; 1254 Object visitXmlAttributeNode(ht.XmlAttributeNode node) {
1255 for (ht.EmbeddedExpression expression in node.expressions) {
1256 resolveExpression(expression.expression);
1257 }
1258 return null;
1259 }
1216 1260
1217 Object visitXmlTagNode(ht.XmlTagNode node) { 1261 Object visitXmlTagNode(ht.XmlTagNode node) {
1218 if (_parentNodes.contains(node)) { 1262 if (_parentNodes.contains(node)) {
1219 JavaStringBuilder builder = new JavaStringBuilder(); 1263 return reportCircularity(node);
1220 builder.append("Found circularity in XML nodes: ");
1221 bool first = true;
1222 for (ht.XmlTagNode pathNode in _parentNodes) {
1223 if (first) {
1224 first = false;
1225 } else {
1226 builder.append(", ");
1227 }
1228 String tagName = pathNode.tag.lexeme;
1229 if (identical(pathNode, node)) {
1230 builder.append("*");
1231 builder.append(tagName);
1232 builder.append("*");
1233 } else {
1234 builder.append(tagName);
1235 }
1236 }
1237 AnalysisEngine.instance.logger.logError(builder.toString());
1238 return null;
1239 } 1264 }
1240 _parentNodes.add(node); 1265 _parentNodes.add(node);
1241 try { 1266 try {
1242 if (isScriptNode(node)) { 1267 for (ht.EmbeddedExpression expression in node.expressions) {
1243 Source htmlSource = _htmlElement.source; 1268 resolveExpression(expression.expression);
1244 ht.XmlAttributeNode scriptAttribute = getScriptSourcePath(node);
1245 String scriptSourcePath = scriptAttribute == null ? null : scriptAttribu te.text;
1246 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePa th == null) {
1247 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementIm pl(node);
1248 String contents = node.content;
1249 int attributeEnd = node.attributeEnd.end;
1250 LineInfo_Location location = _lineInfo.getLocation(attributeEnd);
1251 sc.Scanner scanner = new sc.Scanner(htmlSource, new sc.SubSequenceRead er(new CharSequence(contents), attributeEnd), errorListener);
1252 scanner.setSourceStart(location.lineNumber, location.columnNumber);
1253 sc.Token firstToken = scanner.tokenize();
1254 List<int> lineStarts = scanner.lineStarts;
1255 Parser parser = new Parser(htmlSource, errorListener);
1256 CompilationUnit unit = parser.parseCompilationUnit(firstToken);
1257 try {
1258 LibraryResolver resolver = new LibraryResolver(_context);
1259 LibraryElementImpl library = resolver.resolveEmbeddedLibrary(htmlSou rce, _modificationStamp, unit, true) as LibraryElementImpl;
1260 script.scriptLibrary = library;
1261 resolvedLibraries.addAll(resolver.resolvedLibraries);
1262 errorListener.addAll(resolver.errorListener);
1263 } on AnalysisException catch (exception) {
1264 AnalysisEngine.instance.logger.logError3(exception);
1265 }
1266 _scripts.add(script);
1267 } else {
1268 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementIm pl(node);
1269 if (scriptSourcePath != null) {
1270 try {
1271 scriptSourcePath = Uri.encodeFull(scriptSourcePath);
1272 parseUriWithException(scriptSourcePath);
1273 Source scriptSource = _context.sourceFactory.resolveUri(htmlSource , scriptSourcePath);
1274 script.scriptSource = scriptSource;
1275 if (scriptSource == null || !scriptSource.exists()) {
1276 reportValueError(HtmlWarningCode.URI_DOES_NOT_EXIST, scriptAttri bute, [scriptSourcePath]);
1277 }
1278 } on URISyntaxException catch (exception) {
1279 reportValueError(HtmlWarningCode.INVALID_URI, scriptAttribute, [sc riptSourcePath]);
1280 }
1281 }
1282 _scripts.add(script);
1283 }
1284 } else {
1285 node.visitChildren(this);
1286 } 1269 }
1270 node.visitChildren(this);
1287 } finally { 1271 } finally {
1288 _parentNodes.remove(node); 1272 _parentNodes.remove(node);
1289 } 1273 }
1290 return null; 1274 return null;
1291 } 1275 }
1292 1276
1293 /** 1277 /**
1294 * Return the first source attribute for the given tag node, or `null` if it d oes not exist. 1278 * Return the first source attribute for the given tag node, or `null` if it d oes not exist.
1295 * 1279 *
1296 * @param node the node containing attributes 1280 * @param node the node containing attributes
1297 * @return the source attribute contained in the given tag 1281 * @return the source attribute contained in the given tag
1298 */ 1282 */
1299 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) { 1283 ht.XmlAttributeNode getScriptSourcePath(ht.XmlTagNode node) {
1300 for (ht.XmlAttributeNode attribute in node.attributes) { 1284 for (ht.XmlAttributeNode attribute in node.attributes) {
1301 if (attribute.name.lexeme == _SRC) { 1285 if (attribute.name.lexeme == _SRC) {
1302 return attribute; 1286 return attribute;
1303 } 1287 }
1304 } 1288 }
1305 return null; 1289 return null;
1306 } 1290 }
1307 1291
1292 Object reportCircularity(ht.XmlTagNode node) {
1293 JavaStringBuilder builder = new JavaStringBuilder();
1294 builder.append("Found circularity in XML nodes: ");
1295 bool first = true;
1296 for (ht.XmlTagNode pathNode in _parentNodes) {
1297 if (first) {
1298 first = false;
1299 } else {
1300 builder.append(", ");
1301 }
1302 String tagName = pathNode.tag.lexeme;
1303 if (identical(pathNode, node)) {
1304 builder.append("*");
1305 builder.append(tagName);
1306 builder.append("*");
1307 } else {
1308 builder.append(tagName);
1309 }
1310 }
1311 AnalysisEngine.instance.logger.logError(builder.toString());
1312 return null;
1313 }
1314
1308 /** 1315 /**
1309 * Determine if the specified node is a Dart script.
1310 *
1311 * @param node the node to be tested (not `null`)
1312 * @return `true` if the node is a Dart script
1313 */
1314 bool isScriptNode(ht.XmlTagNode node) {
1315 if (node.tagNodes.length != 0 || node.tag.lexeme != _SCRIPT) {
1316 return false;
1317 }
1318 for (ht.XmlAttributeNode attribute in node.attributes) {
1319 if (attribute.name.lexeme == _TYPE) {
1320 ht.Token valueToken = attribute.value;
1321 if (valueToken != null) {
1322 String value = valueToken.lexeme;
1323 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI ON_DART_IN_SINGLE_QUOTES) {
1324 return true;
1325 }
1326 }
1327 }
1328 }
1329 return false;
1330 }
1331
1332 /**
1333 * Report an error with the given error code at the given location. Use the gi ven arguments to 1316 * Report an error with the given error code at the given location. Use the gi ven arguments to
1334 * compose the error message. 1317 * compose the error message.
1335 * 1318 *
1336 * @param errorCode the error code of the error to be reported 1319 * @param errorCode the error code of the error to be reported
1337 * @param offset the offset of the first character to be highlighted 1320 * @param offset the offset of the first character to be highlighted
1338 * @param length the number of characters to be highlighted 1321 * @param length the number of characters to be highlighted
1339 * @param arguments the arguments used to compose the error message 1322 * @param arguments the arguments used to compose the error message
1340 */ 1323 */
1341 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg uments) { 1324 void reportError(ErrorCode errorCode, int offset, int length, List<Object> arg uments) {
1342 errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, le ngth, errorCode, arguments)); 1325 errorListener.onError(new AnalysisError.con2(_htmlElement.source, offset, le ngth, errorCode, arguments));
1343 } 1326 }
1344 1327
1345 /** 1328 /**
1346 * Report an error with the given error code at the location of the value of t he given attribute. 1329 * Report an error with the given error code at the location of the value of t he given attribute.
1347 * Use the given arguments to compose the error message. 1330 * Use the given arguments to compose the error message.
1348 * 1331 *
1349 * @param errorCode the error code of the error to be reported 1332 * @param errorCode the error code of the error to be reported
1350 * @param offset the offset of the first character to be highlighted 1333 * @param offset the offset of the first character to be highlighted
1351 * @param length the number of characters to be highlighted 1334 * @param length the number of characters to be highlighted
1352 * @param arguments the arguments used to compose the error message 1335 * @param arguments the arguments used to compose the error message
1353 */ 1336 */
1354 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) { 1337 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) {
1355 int offset = attribute.value.offset + 1; 1338 int offset = attribute.value.offset + 1;
1356 int length = attribute.value.length - 2; 1339 int length = attribute.value.length - 2;
1357 reportError(errorCode, offset, length, arguments); 1340 reportError(errorCode, offset, length, arguments);
1358 } 1341 }
1342
1343 void resolveExpression(Expression expression) {
1344 }
1359 } 1345 }
1360 1346
1361 /** 1347 /**
1362 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 1348 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
1363 * violations of Dart best practices. 1349 * violations of Dart best practices.
1364 * 1350 *
1365 * @coverage dart.engine.resolver 1351 * @coverage dart.engine.resolver
1366 */ 1352 */
1367 class BestPracticesVerifier extends RecursiveASTVisitor<Object> { 1353 class BestPracticesVerifier extends RecursiveASTVisitor<Object> {
1368 static String _GETTER = "getter"; 1354 static String _GETTER = "getter";
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 * deprecated constructor will be caught by 1568 * deprecated constructor will be caught by
1583 * [visitInstanceCreationExpression] and 1569 * [visitInstanceCreationExpression] and
1584 * [visitSuperConstructorInvocation], and can be ignored by 1570 * [visitSuperConstructorInvocation], and can be ignored by
1585 * this visit method. 1571 * this visit method.
1586 * 1572 *
1587 * @param identifier some simple identifier to check for deprecated use of 1573 * @param identifier some simple identifier to check for deprecated use of
1588 * @return `true` if and only if a hint code is generated on the passed node 1574 * @return `true` if and only if a hint code is generated on the passed node
1589 * @see HintCode#DEPRECATED_MEMBER_USE 1575 * @see HintCode#DEPRECATED_MEMBER_USE
1590 */ 1576 */
1591 bool checkForDeprecatedMemberUse2(SimpleIdentifier identifier) { 1577 bool checkForDeprecatedMemberUse2(SimpleIdentifier identifier) {
1592 if (identifier.inDeclarationContext() || (identifier.parent is ConstructorNa me && identical(identifier, (identifier.parent as ConstructorName).name)) || (id entifier.parent is SuperConstructorInvocation && identical(identifier, (identifi er.parent as SuperConstructorInvocation).constructorName))) { 1578 if (identifier.inDeclarationContext()) {
1579 return false;
1580 }
1581 ASTNode parent = identifier.parent;
1582 if ((parent is ConstructorName && identical(identifier, (parent as Construct orName).name)) || (parent is SuperConstructorInvocation && identical(identifier, (parent as SuperConstructorInvocation).constructorName)) || parent is HideCombi nator) {
1593 return false; 1583 return false;
1594 } 1584 }
1595 return checkForDeprecatedMemberUse(identifier.bestElement, identifier); 1585 return checkForDeprecatedMemberUse(identifier.bestElement, identifier);
1596 } 1586 }
1597 1587
1598 /** 1588 /**
1599 * Check for the passed binary expression for the [HintCode#DIVISION_OPTIMIZAT ION]. 1589 * Check for the passed binary expression for the [HintCode#DIVISION_OPTIMIZAT ION].
1600 * 1590 *
1601 * @param node the binary expression to check 1591 * @param node the binary expression to check
1602 * @return `true` if and only if a hint code is generated on the passed node 1592 * @return `true` if and only if a hint code is generated on the passed node
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 } 2070 }
2081 2071
2082 void generateForCompilationUnit(CompilationUnit unit, Source source) { 2072 void generateForCompilationUnit(CompilationUnit unit, Source source) {
2083 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 2073 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
2084 _importsVerifier.visitCompilationUnit(unit); 2074 _importsVerifier.visitCompilationUnit(unit);
2085 new DeadCodeVerifier(errorReporter).visitCompilationUnit(unit); 2075 new DeadCodeVerifier(errorReporter).visitCompilationUnit(unit);
2086 if (_enableDart2JSHints) { 2076 if (_enableDart2JSHints) {
2087 new Dart2JSVerifier(errorReporter).visitCompilationUnit(unit); 2077 new Dart2JSVerifier(errorReporter).visitCompilationUnit(unit);
2088 } 2078 }
2089 new BestPracticesVerifier(errorReporter).visitCompilationUnit(unit); 2079 new BestPracticesVerifier(errorReporter).visitCompilationUnit(unit);
2080 new ToDoFinder(errorReporter).findIn(unit);
2090 } 2081 }
2091 } 2082 }
2092 2083
2093 /** 2084 /**
2094 * Instances of the class `ImportsVerifier` visit all of the referenced librarie s in the 2085 * Instances of the class `ImportsVerifier` visit all of the referenced librarie s in the
2095 * source code verifying that all of the imports are used, otherwise a 2086 * source code verifying that all of the imports are used, otherwise a
2096 * [HintCode#UNUSED_IMPORT] is generated with 2087 * [HintCode#UNUSED_IMPORT] is generated with
2097 * [generateUnusedImportHints]. 2088 * [generateUnusedImportHints].
2098 * 2089 *
2099 * While this class does not yet have support for an "Organize Imports" action, this logic built up 2090 * While this class does not yet have support for an "Organize Imports" action, this logic built up
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 String fullName = source.fullName; 2531 String fullName = source.fullName;
2541 if (fullName != null) { 2532 if (fullName != null) {
2542 return fullName.replaceAll(r'\', '/'); 2533 return fullName.replaceAll(r'\', '/');
2543 } 2534 }
2544 } 2535 }
2545 return null; 2536 return null;
2546 } 2537 }
2547 } 2538 }
2548 2539
2549 /** 2540 /**
2541 * Instances of the class `ToDoFinder` find to-do comments in Dart code.
2542 */
2543 class ToDoFinder {
2544 /**
2545 * The error reporter by which to-do comments will be reported.
2546 */
2547 ErrorReporter _errorReporter;
2548
2549 /**
2550 * Initialize a newly created to-do finder to report to-do comments to the giv en reporter.
2551 *
2552 * @param errorReporter the error reporter by which to-do comments will be rep orted
2553 */
2554 ToDoFinder(ErrorReporter errorReporter) {
2555 this._errorReporter = errorReporter;
2556 }
2557
2558 /**
2559 * Search the comments in the given compilation unit for to-do comments and re port an error for
2560 * each.
2561 *
2562 * @param unit the compilation unit containing the to-do comments
2563 */
2564 void findIn(CompilationUnit unit) {
2565 gatherTodoComments(unit.beginToken);
2566 }
2567
2568 /**
2569 * Search the comment tokens reachable from the given token and create errors for each to-do
2570 * comment.
2571 *
2572 * @param token the head of the list of tokens being searched
2573 */
2574 void gatherTodoComments(sc.Token token) {
2575 while (token != null && token.type != sc.TokenType.EOF) {
2576 sc.Token commentToken = token.precedingComments;
2577 while (commentToken != null) {
2578 if (identical(commentToken.type, sc.TokenType.SINGLE_LINE_COMMENT) || id entical(commentToken.type, sc.TokenType.MULTI_LINE_COMMENT)) {
2579 scrapeTodoComment(commentToken);
2580 }
2581 commentToken = commentToken.next;
2582 }
2583 token = token.next;
2584 }
2585 }
2586
2587 /**
2588 * Look for user defined tasks in comments and convert them into info level an alysis issues.
2589 *
2590 * @param commentToken the comment token to analyze
2591 */
2592 void scrapeTodoComment(sc.Token commentToken) {
2593 JavaPatternMatcher matcher = new JavaPatternMatcher(TodoCode.TODO_REGEX, com mentToken.lexeme);
2594 if (matcher.find()) {
2595 int offset = commentToken.offset + matcher.start() + matcher.group(1).leng th;
2596 int length = matcher.group(2).length;
2597 _errorReporter.reportError4(TodoCode.TODO, offset, length, [matcher.group( 2)]);
2598 }
2599 }
2600 }
2601
2602 /**
2550 * Instances of the class `DeclarationMatcher` determine whether the element mod el defined by 2603 * Instances of the class `DeclarationMatcher` determine whether the element mod el defined by
2551 * a given AST structure matches an existing element model. 2604 * a given AST structure matches an existing element model.
2552 */ 2605 */
2553 class DeclarationMatcher extends RecursiveASTVisitor<Object> { 2606 class DeclarationMatcher extends RecursiveASTVisitor<Object> {
2554 /** 2607 /**
2555 * The compilation unit containing the AST nodes being visited. 2608 * The compilation unit containing the AST nodes being visited.
2556 */ 2609 */
2557 CompilationUnitElement _enclosingUnit; 2610 CompilationUnitElement _enclosingUnit;
2558 2611
2559 /** 2612 /**
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
3147 */ 3200 */
3148 class DeclarationMatcher_DeclarationMismatchException extends RuntimeException { 3201 class DeclarationMatcher_DeclarationMismatchException extends RuntimeException {
3149 } 3202 }
3150 3203
3151 class GeneralizingElementVisitor_7 extends GeneralizingElementVisitor<Object> { 3204 class GeneralizingElementVisitor_7 extends GeneralizingElementVisitor<Object> {
3152 final DeclarationMatcher DeclarationMatcher_this; 3205 final DeclarationMatcher DeclarationMatcher_this;
3153 3206
3154 GeneralizingElementVisitor_7(this.DeclarationMatcher_this) : super(); 3207 GeneralizingElementVisitor_7(this.DeclarationMatcher_this) : super();
3155 3208
3156 Object visitElement(Element element) { 3209 Object visitElement(Element element) {
3157 javaSetAdd(DeclarationMatcher_this._allElements, element); 3210 DeclarationMatcher_this._allElements.add(element);
3158 javaSetAdd(DeclarationMatcher_this._unmatchedElements, element); 3211 DeclarationMatcher_this._unmatchedElements.add(element);
3159 return super.visitElement(element); 3212 return super.visitElement(element);
3160 } 3213 }
3161 } 3214 }
3162 3215
3163 /** 3216 /**
3164 * Instances of the class `DeclarationResolver` are used to resolve declarations in an AST 3217 * Instances of the class `DeclarationResolver` are used to resolve declarations in an AST
3165 * structure to already built elements. 3218 * structure to already built elements.
3166 */ 3219 */
3167 class DeclarationResolver extends RecursiveASTVisitor<Object> { 3220 class DeclarationResolver extends RecursiveASTVisitor<Object> {
3168 /** 3221 /**
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 * The resolver driving this participant. 3852 * The resolver driving this participant.
3800 */ 3853 */
3801 ResolverVisitor _resolver; 3854 ResolverVisitor _resolver;
3802 3855
3803 /** 3856 /**
3804 * The element for the library containing the compilation unit being visited. 3857 * The element for the library containing the compilation unit being visited.
3805 */ 3858 */
3806 LibraryElement _definingLibrary; 3859 LibraryElement _definingLibrary;
3807 3860
3808 /** 3861 /**
3809 * A flag indicating whether we are running in strict mode. In strict mode, er ror reporting is
3810 * based exclusively on the static type information.
3811 */
3812 bool _strictMode = false;
3813
3814 /**
3815 * A flag indicating whether we should generate hints. 3862 * A flag indicating whether we should generate hints.
3816 */ 3863 */
3817 bool _enableHints = false; 3864 bool _enableHints = false;
3818 3865
3819 /** 3866 /**
3820 * The type representing the type 'dynamic'. 3867 * The type representing the type 'dynamic'.
3821 */ 3868 */
3822 Type2 _dynamicType; 3869 Type2 _dynamicType;
3823 3870
3824 /** 3871 /**
(...skipping 25 matching lines...) Expand all
3850 3897
3851 /** 3898 /**
3852 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 3899 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3853 * 3900 *
3854 * @param resolver the resolver driving this participant 3901 * @param resolver the resolver driving this participant
3855 */ 3902 */
3856 ElementResolver(ResolverVisitor resolver) { 3903 ElementResolver(ResolverVisitor resolver) {
3857 this._resolver = resolver; 3904 this._resolver = resolver;
3858 this._definingLibrary = resolver.definingLibrary; 3905 this._definingLibrary = resolver.definingLibrary;
3859 AnalysisOptions options = _definingLibrary.context.analysisOptions; 3906 AnalysisOptions options = _definingLibrary.context.analysisOptions;
3860 _strictMode = options.strictMode;
3861 _enableHints = options.hint; 3907 _enableHints = options.hint;
3862 _dynamicType = resolver.typeProvider.dynamicType; 3908 _dynamicType = resolver.typeProvider.dynamicType;
3863 _typeType = resolver.typeProvider.typeType; 3909 _typeType = resolver.typeProvider.typeType;
3864 _subtypeManager = new SubtypeManager(); 3910 _subtypeManager = new SubtypeManager();
3865 _promoteManager = resolver.promoteManager; 3911 _promoteManager = resolver.promoteManager;
3866 } 3912 }
3867 3913
3868 Object visitAssignmentExpression(AssignmentExpression node) { 3914 Object visitAssignmentExpression(AssignmentExpression node) {
3869 sc.Token operator = node.operator; 3915 sc.Token operator = node.operator;
3870 sc.TokenType operatorType = operator.type; 3916 sc.TokenType operatorType = operator.type;
3871 if (operatorType != sc.TokenType.EQ) { 3917 if (operatorType != sc.TokenType.EQ) {
3872 operatorType = operatorFromCompoundAssignment(operatorType); 3918 operatorType = operatorFromCompoundAssignment(operatorType);
3873 Expression leftHandSide = node.leftHandSide; 3919 Expression leftHandSide = node.leftHandSide;
3874 if (leftHandSide != null) { 3920 if (leftHandSide != null) {
3875 String methodName = operatorType.lexeme; 3921 String methodName = operatorType.lexeme;
3876 Type2 staticType = getStaticType(leftHandSide); 3922 Type2 staticType = getStaticType(leftHandSide);
3877 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName); 3923 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName);
3878 node.staticElement = staticMethod; 3924 node.staticElement = staticMethod;
3879 Type2 propagatedType = getPropagatedType(leftHandSide); 3925 Type2 propagatedType = getPropagatedType(leftHandSide);
3880 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy pe, methodName); 3926 MethodElement propagatedMethod = lookUpMethod(leftHandSide, propagatedTy pe, methodName);
3881 node.propagatedElement = propagatedMethod; 3927 node.propagatedElement = propagatedMethod;
3882 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3928 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod);
3883 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false; 3929 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3884 if (shouldReportMissingMember_propagated) { 3930 if (shouldReportMissingMember_propagated) {
3885 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) { 3931 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3886 shouldReportMissingMember_propagated = false; 3932 shouldReportMissingMember_propagated = false;
3887 } 3933 }
3888 } 3934 }
3889 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3935 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3890 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode; 3936 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode;
3891 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [ 3937 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [
3892 methodName, 3938 methodName,
3893 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3939 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3894 } 3940 }
3895 } 3941 }
3896 } 3942 }
3897 return null; 3943 return null;
3898 } 3944 }
3899 3945
3900 Object visitBinaryExpression(BinaryExpression node) { 3946 Object visitBinaryExpression(BinaryExpression node) {
3901 sc.Token operator = node.operator; 3947 sc.Token operator = node.operator;
3902 if (operator.isUserDefinableOperator) { 3948 if (operator.isUserDefinableOperator) {
3903 Expression leftOperand = node.leftOperand; 3949 Expression leftOperand = node.leftOperand;
3904 if (leftOperand != null) { 3950 if (leftOperand != null) {
3905 String methodName = operator.lexeme; 3951 String methodName = operator.lexeme;
3906 Type2 staticType = getStaticType(leftOperand); 3952 Type2 staticType = getStaticType(leftOperand);
3907 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName); 3953 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName);
3908 node.staticElement = staticMethod; 3954 node.staticElement = staticMethod;
3909 Type2 propagatedType = getPropagatedType(leftOperand); 3955 Type2 propagatedType = getPropagatedType(leftOperand);
3910 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName); 3956 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName);
3911 node.propagatedElement = propagatedMethod; 3957 node.propagatedElement = propagatedMethod;
3912 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3958 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod);
3913 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false; 3959 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3914 if (shouldReportMissingMember_propagated) { 3960 if (shouldReportMissingMember_propagated) {
3915 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) { 3961 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3916 shouldReportMissingMember_propagated = false; 3962 shouldReportMissingMember_propagated = false;
3917 } 3963 }
3918 } 3964 }
3919 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3965 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3920 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3966 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3921 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [ 3967 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [
3922 methodName, 3968 methodName,
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
4239 return null; 4285 return null;
4240 } 4286 }
4241 4287
4242 Object visitMethodDeclaration(MethodDeclaration node) { 4288 Object visitMethodDeclaration(MethodDeclaration node) {
4243 setMetadata(node.element, node); 4289 setMetadata(node.element, node);
4244 return null; 4290 return null;
4245 } 4291 }
4246 4292
4247 Object visitMethodInvocation(MethodInvocation node) { 4293 Object visitMethodInvocation(MethodInvocation node) {
4248 SimpleIdentifier methodName = node.methodName; 4294 SimpleIdentifier methodName = node.methodName;
4295 if (methodName.isSynthetic) {
4296 return null;
4297 }
4249 Expression target = node.realTarget; 4298 Expression target = node.realTarget;
4250 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) { 4299 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) {
4251 return null; 4300 return null;
4252 } 4301 }
4253 Element staticElement; 4302 Element staticElement;
4254 Element propagatedElement; 4303 Element propagatedElement;
4255 if (target == null) { 4304 if (target == null) {
4256 staticElement = resolveInvokedElement2(methodName); 4305 staticElement = resolveInvokedElement2(methodName);
4257 propagatedElement = null; 4306 propagatedElement = null;
4258 } else { 4307 } else {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
4361 4410
4362 Object visitPostfixExpression(PostfixExpression node) { 4411 Object visitPostfixExpression(PostfixExpression node) {
4363 Expression operand = node.operand; 4412 Expression operand = node.operand;
4364 String methodName = getPostfixOperator(node); 4413 String methodName = getPostfixOperator(node);
4365 Type2 staticType = getStaticType(operand); 4414 Type2 staticType = getStaticType(operand);
4366 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName); 4415 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName);
4367 node.staticElement = staticMethod; 4416 node.staticElement = staticMethod;
4368 Type2 propagatedType = getPropagatedType(operand); 4417 Type2 propagatedType = getPropagatedType(operand);
4369 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho dName); 4418 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho dName);
4370 node.propagatedElement = propagatedMethod; 4419 node.propagatedElement = propagatedMethod;
4371 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod)); 4420 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod);
4372 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false; 4421 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false;
4373 if (shouldReportMissingMember_propagated) { 4422 if (shouldReportMissingMember_propagated) {
4374 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) { 4423 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
4375 shouldReportMissingMember_propagated = false; 4424 shouldReportMissingMember_propagated = false;
4376 } 4425 }
4377 } 4426 }
4378 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 4427 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
4379 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 4428 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
4380 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingMem ber_static ? staticType.element : propagatedType.element, errorCode, node.operat or, [ 4429 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingMem ber_static ? staticType.element : propagatedType.element, errorCode, node.operat or, [
4381 methodName, 4430 methodName,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4435 sc.TokenType operatorType = operator.type; 4484 sc.TokenType operatorType = operator.type;
4436 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { 4485 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) {
4437 Expression operand = node.operand; 4486 Expression operand = node.operand;
4438 String methodName = getPrefixOperator(node); 4487 String methodName = getPrefixOperator(node);
4439 Type2 staticType = getStaticType(operand); 4488 Type2 staticType = getStaticType(operand);
4440 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName) ; 4489 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName) ;
4441 node.staticElement = staticMethod; 4490 node.staticElement = staticMethod;
4442 Type2 propagatedType = getPropagatedType(operand); 4491 Type2 propagatedType = getPropagatedType(operand);
4443 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met hodName); 4492 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met hodName);
4444 node.propagatedElement = propagatedMethod; 4493 node.propagatedElement = propagatedMethod;
4445 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod)); 4494 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod);
4446 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false; 4495 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false;
4447 if (shouldReportMissingMember_propagated) { 4496 if (shouldReportMissingMember_propagated) {
4448 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) { 4497 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) {
4449 shouldReportMissingMember_propagated = false; 4498 shouldReportMissingMember_propagated = false;
4450 } 4499 }
4451 } 4500 }
4452 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) { 4501 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) {
4453 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 4502 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
4454 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingM ember_static ? staticType.element : propagatedType.element, errorCode, operator, [ 4503 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingM ember_static ? staticType.element : propagatedType.element, errorCode, operator, [
4455 methodName, 4504 methodName,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4490 node.staticElement = element; 4539 node.staticElement = element;
4491 ArgumentList argumentList = node.argumentList; 4540 ArgumentList argumentList = node.argumentList;
4492 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element); 4541 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element);
4493 if (parameters != null) { 4542 if (parameters != null) {
4494 argumentList.correspondingStaticParameters = parameters; 4543 argumentList.correspondingStaticParameters = parameters;
4495 } 4544 }
4496 return null; 4545 return null;
4497 } 4546 }
4498 4547
4499 Object visitSimpleIdentifier(SimpleIdentifier node) { 4548 Object visitSimpleIdentifier(SimpleIdentifier node) {
4549 if (node.isSynthetic) {
4550 return null;
4551 }
4500 if (node.staticElement != null) { 4552 if (node.staticElement != null) {
4501 return null; 4553 return null;
4502 } 4554 }
4503 if (node.name == _dynamicType.name) { 4555 if (node.name == _dynamicType.name) {
4504 node.staticElement = _dynamicType.element; 4556 node.staticElement = _dynamicType.element;
4505 node.staticType = _typeType; 4557 node.staticType = _typeType;
4506 return null; 4558 return null;
4507 } 4559 }
4508 Element element = resolveSimpleIdentifier(node); 4560 Element element = resolveSimpleIdentifier(node);
4509 ClassElement enclosingClass = _resolver.enclosingClass; 4561 ClassElement enclosingClass = _resolver.enclosingClass;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
4596 } 4648 }
4597 4649
4598 /** 4650 /**
4599 * Generate annotation elements for each of the annotations in the given node list and add them to 4651 * Generate annotation elements for each of the annotations in the given node list and add them to
4600 * the given list of elements. 4652 * the given list of elements.
4601 * 4653 *
4602 * @param annotationList the list of elements to which new elements are to be added 4654 * @param annotationList the list of elements to which new elements are to be added
4603 * @param annotations the AST nodes used to generate new elements 4655 * @param annotations the AST nodes used to generate new elements
4604 */ 4656 */
4605 void addAnnotations(List<ElementAnnotationImpl> annotationList, NodeList<Annot ation> annotations) { 4657 void addAnnotations(List<ElementAnnotationImpl> annotationList, NodeList<Annot ation> annotations) {
4606 for (Annotation annotationNode in annotations) { 4658 int annotationCount = annotations.length;
4607 Element resolvedElement = annotationNode.element; 4659 for (int i = 0; i < annotationCount; i++) {
4660 Element resolvedElement = annotations[i].element;
4608 if (resolvedElement != null) { 4661 if (resolvedElement != null) {
4609 annotationList.add(new ElementAnnotationImpl(resolvedElement)); 4662 annotationList.add(new ElementAnnotationImpl(resolvedElement));
4610 } 4663 }
4611 } 4664 }
4612 } 4665 }
4613 4666
4614 /** 4667 /**
4615 * Given that we have found code to invoke the given element, return the error code that should be 4668 * Given that we have found code to invoke the given element, return the error code that should be
4616 * reported, or `null` if no error should be reported. 4669 * reported, or `null` if no error should be reported.
4617 * 4670 *
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4683 * Check that the for some index expression that the method element was resolv ed, otherwise a 4736 * Check that the for some index expression that the method element was resolv ed, otherwise a
4684 * [StaticWarningCode#UNDEFINED_OPERATOR] is generated. 4737 * [StaticWarningCode#UNDEFINED_OPERATOR] is generated.
4685 * 4738 *
4686 * @param node the index expression to resolve 4739 * @param node the index expression to resolve
4687 * @param target the target of the expression 4740 * @param target the target of the expression
4688 * @param methodName the name of the operator associated with the context of u sing of the given 4741 * @param methodName the name of the operator associated with the context of u sing of the given
4689 * index expression 4742 * index expression
4690 * @return `true` if and only if an error code is generated on the passed node 4743 * @return `true` if and only if an error code is generated on the passed node
4691 */ 4744 */
4692 bool checkForUndefinedIndexOperator(IndexExpression node, Expression target, S tring methodName, MethodElement staticMethod, MethodElement propagatedMethod, Ty pe2 staticType, Type2 propagatedType) { 4745 bool checkForUndefinedIndexOperator(IndexExpression node, Expression target, S tring methodName, MethodElement staticMethod, MethodElement propagatedMethod, Ty pe2 staticType, Type2 propagatedType) {
4693 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod)); 4746 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod);
4694 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false; 4747 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false;
4695 if (shouldReportMissingMember_propagated) { 4748 if (shouldReportMissingMember_propagated) {
4696 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) { 4749 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
4697 shouldReportMissingMember_propagated = false; 4750 shouldReportMissingMember_propagated = false;
4698 } 4751 }
4699 } 4752 }
4700 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 4753 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
4701 sc.Token leftBracket = node.leftBracket; 4754 sc.Token leftBracket = node.leftBracket;
4702 sc.Token rightBracket = node.rightBracket; 4755 sc.Token rightBracket = node.rightBracket;
4703 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 4756 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
4966 * @param getterName the name of the getter being looked up 5019 * @param getterName the name of the getter being looked up
4967 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 5020 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
4968 * to prevent infinite recursion and to optimize the search 5021 * to prevent infinite recursion and to optimize the search
4969 * @return the element representing the getter that was found 5022 * @return the element representing the getter that was found
4970 */ 5023 */
4971 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) { 5024 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String getterName, Set<ClassElement> visitedInterfaces) {
4972 ClassElement targetClass = targetType.element; 5025 ClassElement targetClass = targetType.element;
4973 if (visitedInterfaces.contains(targetClass)) { 5026 if (visitedInterfaces.contains(targetClass)) {
4974 return null; 5027 return null;
4975 } 5028 }
4976 javaSetAdd(visitedInterfaces, targetClass); 5029 visitedInterfaces.add(targetClass);
4977 if (includeTargetType) { 5030 if (includeTargetType) {
4978 PropertyAccessorElement getter = targetType.getGetter(getterName); 5031 PropertyAccessorElement getter = targetType.getGetter(getterName);
4979 if (getter != null && getter.isAccessibleIn(_definingLibrary)) { 5032 if (getter != null && getter.isAccessibleIn(_definingLibrary)) {
4980 return getter; 5033 return getter;
4981 } 5034 }
4982 } 5035 }
4983 for (InterfaceType interfaceType in targetType.interfaces) { 5036 for (InterfaceType interfaceType in targetType.interfaces) {
4984 PropertyAccessorElement getter = lookUpGetterInInterfaces(interfaceType, t rue, getterName, visitedInterfaces); 5037 PropertyAccessorElement getter = lookUpGetterInInterfaces(interfaceType, t rue, getterName, visitedInterfaces);
4985 if (getter != null) { 5038 if (getter != null) {
4986 return getter; 5039 return getter;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5035 * @param memberName the name of the method or getter being looked up 5088 * @param memberName the name of the method or getter being looked up
5036 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 5089 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
5037 * to prevent infinite recursion and to optimize the search 5090 * to prevent infinite recursion and to optimize the search
5038 * @return the element representing the method or getter that was found 5091 * @return the element representing the method or getter that was found
5039 */ 5092 */
5040 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, b ool includeTargetType, String memberName, Set<ClassElement> visitedInterfaces) { 5093 ExecutableElement lookUpGetterOrMethodInInterfaces(InterfaceType targetType, b ool includeTargetType, String memberName, Set<ClassElement> visitedInterfaces) {
5041 ClassElement targetClass = targetType.element; 5094 ClassElement targetClass = targetType.element;
5042 if (visitedInterfaces.contains(targetClass)) { 5095 if (visitedInterfaces.contains(targetClass)) {
5043 return null; 5096 return null;
5044 } 5097 }
5045 javaSetAdd(visitedInterfaces, targetClass); 5098 visitedInterfaces.add(targetClass);
5046 if (includeTargetType) { 5099 if (includeTargetType) {
5047 ExecutableElement member = targetType.getMethod(memberName); 5100 ExecutableElement member = targetType.getMethod(memberName);
5048 if (member != null) { 5101 if (member != null) {
5049 return member; 5102 return member;
5050 } 5103 }
5051 member = targetType.getGetter(memberName); 5104 member = targetType.getGetter(memberName);
5052 if (member != null) { 5105 if (member != null) {
5053 return member; 5106 return member;
5054 } 5107 }
5055 } 5108 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
5149 * @param methodName the name of the method being looked up 5202 * @param methodName the name of the method being looked up
5150 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 5203 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
5151 * to prevent infinite recursion and to optimize the search 5204 * to prevent infinite recursion and to optimize the search
5152 * @return the element representing the method that was found 5205 * @return the element representing the method that was found
5153 */ 5206 */
5154 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT argetType, String methodName, Set<ClassElement> visitedInterfaces) { 5207 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, bool includeT argetType, String methodName, Set<ClassElement> visitedInterfaces) {
5155 ClassElement targetClass = targetType.element; 5208 ClassElement targetClass = targetType.element;
5156 if (visitedInterfaces.contains(targetClass)) { 5209 if (visitedInterfaces.contains(targetClass)) {
5157 return null; 5210 return null;
5158 } 5211 }
5159 javaSetAdd(visitedInterfaces, targetClass); 5212 visitedInterfaces.add(targetClass);
5160 if (includeTargetType) { 5213 if (includeTargetType) {
5161 MethodElement method = targetType.getMethod(methodName); 5214 MethodElement method = targetType.getMethod(methodName);
5162 if (method != null && method.isAccessibleIn(_definingLibrary)) { 5215 if (method != null && method.isAccessibleIn(_definingLibrary)) {
5163 return method; 5216 return method;
5164 } 5217 }
5165 } 5218 }
5166 for (InterfaceType interfaceType in targetType.interfaces) { 5219 for (InterfaceType interfaceType in targetType.interfaces) {
5167 MethodElement method = lookUpMethodInInterfaces(interfaceType, true, metho dName, visitedInterfaces); 5220 MethodElement method = lookUpMethodInInterfaces(interfaceType, true, metho dName, visitedInterfaces);
5168 if (method != null) { 5221 if (method != null) {
5169 return method; 5222 return method;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5219 * @param setterName the name of the setter being looked up 5272 * @param setterName the name of the setter being looked up
5220 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 5273 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
5221 * to prevent infinite recursion and to optimize the search 5274 * to prevent infinite recursion and to optimize the search
5222 * @return the element representing the setter that was found 5275 * @return the element representing the setter that was found
5223 */ 5276 */
5224 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) { 5277 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, boo l includeTargetType, String setterName, Set<ClassElement> visitedInterfaces) {
5225 ClassElement targetClass = targetType.element; 5278 ClassElement targetClass = targetType.element;
5226 if (visitedInterfaces.contains(targetClass)) { 5279 if (visitedInterfaces.contains(targetClass)) {
5227 return null; 5280 return null;
5228 } 5281 }
5229 javaSetAdd(visitedInterfaces, targetClass); 5282 visitedInterfaces.add(targetClass);
5230 if (includeTargetType) { 5283 if (includeTargetType) {
5231 PropertyAccessorElement setter = targetType.getSetter(setterName); 5284 PropertyAccessorElement setter = targetType.getSetter(setterName);
5232 if (setter != null && setter.isAccessibleIn(_definingLibrary)) { 5285 if (setter != null && setter.isAccessibleIn(_definingLibrary)) {
5233 return setter; 5286 return setter;
5234 } 5287 }
5235 } 5288 }
5236 for (InterfaceType interfaceType in targetType.interfaces) { 5289 for (InterfaceType interfaceType in targetType.interfaces) {
5237 PropertyAccessorElement setter = lookUpSetterInInterfaces(interfaceType, t rue, setterName, visitedInterfaces); 5290 PropertyAccessorElement setter = lookUpSetterInInterfaces(interfaceType, t rue, setterName, visitedInterfaces);
5238 if (setter != null) { 5291 if (setter != null) {
5239 return setter; 5292 return setter;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
5478 SimpleIdentifier nameNode = (argument as NamedExpression).name.label; 5531 SimpleIdentifier nameNode = (argument as NamedExpression).name.label;
5479 String name = nameNode.name; 5532 String name = nameNode.name;
5480 ParameterElement element = namedParameters[name]; 5533 ParameterElement element = namedParameters[name];
5481 if (element == null) { 5534 if (element == null) {
5482 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode; 5535 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode;
5483 _resolver.reportError6(errorCode, nameNode, [name]); 5536 _resolver.reportError6(errorCode, nameNode, [name]);
5484 } else { 5537 } else {
5485 resolvedParameters[i] = element; 5538 resolvedParameters[i] = element;
5486 nameNode.staticElement = element; 5539 nameNode.staticElement = element;
5487 } 5540 }
5488 if (!javaSetAdd(usedNames, name)) { 5541 if (!usedNames.add(name)) {
5489 _resolver.reportError6(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]); 5542 _resolver.reportError6(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]);
5490 } 5543 }
5491 } else { 5544 } else {
5492 positionalArgumentCount++; 5545 positionalArgumentCount++;
5493 if (unnamedIndex < unnamedParameterCount) { 5546 if (unnamedIndex < unnamedParameterCount) {
5494 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; 5547 resolvedParameters[i] = unnamedParameters[unnamedIndex++];
5495 } 5548 }
5496 } 5549 }
5497 } 5550 }
5498 if (positionalArgumentCount < requiredParameters.length) { 5551 if (positionalArgumentCount < requiredParameters.length) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
5648 propagatedElement = resolveProperty(target, propagatedType, propertyName); 5701 propagatedElement = resolveProperty(target, propagatedType, propertyName);
5649 } 5702 }
5650 if (target.parent.parent is Annotation) { 5703 if (target.parent.parent is Annotation) {
5651 if (staticElement != null) { 5704 if (staticElement != null) {
5652 propertyName.staticElement = staticElement; 5705 propertyName.staticElement = staticElement;
5653 } 5706 }
5654 return; 5707 return;
5655 } 5708 }
5656 propertyName.staticElement = staticElement; 5709 propertyName.staticElement = staticElement;
5657 propertyName.propagatedElement = propagatedElement; 5710 propertyName.propagatedElement = propagatedElement;
5658 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement)); 5711 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement);
5659 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false; 5712 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false;
5660 if (shouldReportMissingMember_propagated) { 5713 if (shouldReportMissingMember_propagated) {
5661 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) { 5714 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) {
5662 shouldReportMissingMember_propagated = false; 5715 shouldReportMissingMember_propagated = false;
5663 } 5716 }
5664 } 5717 }
5665 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 5718 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
5666 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element; 5719 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element;
5667 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt); 5720 bool isStaticProperty = isStatic(staticOrPropagatedEnclosingElt);
5668 if (propertyName.inSetterContext()) { 5721 if (propertyName.inSetterContext()) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
5751 Type2 bound = (type as TypeParameterType).element.bound; 5804 Type2 bound = (type as TypeParameterType).element.bound;
5752 if (bound == null) { 5805 if (bound == null) {
5753 return _resolver.typeProvider.objectType; 5806 return _resolver.typeProvider.objectType;
5754 } 5807 }
5755 return bound; 5808 return bound;
5756 } 5809 }
5757 return type; 5810 return type;
5758 } 5811 }
5759 5812
5760 /** 5813 /**
5761 * Return the propagated element if it is not `null`, or the static element if it is.
5762 *
5763 * @param staticElement the element computed using static type information
5764 * @param propagatedElement the element computed using propagated type informa tion
5765 * @return the more specific of the two elements
5766 */
5767 ExecutableElement select(ExecutableElement staticElement, ExecutableElement pr opagatedElement) => propagatedElement != null ? propagatedElement : staticElemen t;
5768
5769 /**
5770 * Given a node that can have annotations associated with it and the element t o which that node 5814 * Given a node that can have annotations associated with it and the element t o which that node
5771 * has been resolved, create the annotations in the element model representing the annotations on 5815 * has been resolved, create the annotations in the element model representing the annotations on
5772 * the node. 5816 * the node.
5773 * 5817 *
5774 * @param element the element to which the node has been resolved 5818 * @param element the element to which the node has been resolved
5775 * @param node the node that can have annotations associated with it 5819 * @param node the node that can have annotations associated with it
5776 */ 5820 */
5777 void setMetadata(Element element, AnnotatedNode node) { 5821 void setMetadata(Element element, AnnotatedNode node) {
5778 if (element is! ElementImpl) { 5822 if (element is! ElementImpl) {
5779 return; 5823 return;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
5836 accept(ASTVisitor visitor) => null; 5880 accept(ASTVisitor visitor) => null;
5837 5881
5838 sc.Token get beginToken => null; 5882 sc.Token get beginToken => null;
5839 5883
5840 Element get bestElement => null; 5884 Element get bestElement => null;
5841 5885
5842 sc.Token get endToken => null; 5886 sc.Token get endToken => null;
5843 5887
5844 String get name => _name; 5888 String get name => _name;
5845 5889
5890 int get precedence => 16;
5891
5846 Element get propagatedElement => null; 5892 Element get propagatedElement => null;
5847 5893
5848 Element get staticElement => null; 5894 Element get staticElement => null;
5849 5895
5850 void visitChildren(ASTVisitor visitor) { 5896 void visitChildren(ASTVisitor visitor) {
5851 } 5897 }
5852 } 5898 }
5853 5899
5854 /** 5900 /**
5855 * Instances of the class `IncrementalResolver` resolve the smallest portion of an AST 5901 * Instances of the class `IncrementalResolver` resolve the smallest portion of an AST
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
6184 ClassElement superclassElt = null; 6230 ClassElement superclassElt = null;
6185 InterfaceType supertype = classElt.supertype; 6231 InterfaceType supertype = classElt.supertype;
6186 if (supertype != null) { 6232 if (supertype != null) {
6187 superclassElt = supertype.element; 6233 superclassElt = supertype.element;
6188 } else { 6234 } else {
6189 _classLookup[classElt] = resultMap; 6235 _classLookup[classElt] = resultMap;
6190 return resultMap; 6236 return resultMap;
6191 } 6237 }
6192 if (superclassElt != null) { 6238 if (superclassElt != null) {
6193 if (!visitedClasses.contains(superclassElt)) { 6239 if (!visitedClasses.contains(superclassElt)) {
6194 javaSetAdd(visitedClasses, classElt); 6240 visitedClasses.add(classElt);
6195 resultMap = new MemberMap.con2(computeClassChainLookupMap(superclassElt, visitedClasses)); 6241 resultMap = new MemberMap.con2(computeClassChainLookupMap(superclassElt, visitedClasses));
6196 } else { 6242 } else {
6197 _classLookup[superclassElt] = resultMap; 6243 _classLookup[superclassElt] = resultMap;
6198 return resultMap; 6244 return resultMap;
6199 } 6245 }
6200 substituteTypeParametersDownHierarchy(supertype, resultMap); 6246 substituteTypeParametersDownHierarchy(supertype, resultMap);
6201 recordMapWithClassMembers(resultMap, supertype); 6247 recordMapWithClassMembers(resultMap, supertype);
6202 } 6248 }
6203 List<InterfaceType> mixins = classElt.mixins; 6249 List<InterfaceType> mixins = classElt.mixins;
6204 for (int i = mixins.length - 1; i >= 0; i--) { 6250 for (int i = mixins.length - 1; i >= 0; i--) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
6274 resultMap = new MemberMap(); 6320 resultMap = new MemberMap();
6275 } 6321 }
6276 InterfaceType supertype = classElt.supertype; 6322 InterfaceType supertype = classElt.supertype;
6277 ClassElement superclassElement = supertype != null ? supertype.element : nul l; 6323 ClassElement superclassElement = supertype != null ? supertype.element : nul l;
6278 List<InterfaceType> mixins = classElt.mixins; 6324 List<InterfaceType> mixins = classElt.mixins;
6279 List<InterfaceType> interfaces = classElt.interfaces; 6325 List<InterfaceType> interfaces = classElt.interfaces;
6280 List<MemberMap> lookupMaps = new List<MemberMap>(); 6326 List<MemberMap> lookupMaps = new List<MemberMap>();
6281 if (superclassElement != null) { 6327 if (superclassElement != null) {
6282 if (!visitedInterfaces.contains(superclassElement)) { 6328 if (!visitedInterfaces.contains(superclassElement)) {
6283 try { 6329 try {
6284 javaSetAdd(visitedInterfaces, superclassElement); 6330 visitedInterfaces.add(superclassElement);
6285 MemberMap map = computeInterfaceLookupMap(superclassElement, visitedIn terfaces); 6331 MemberMap map = computeInterfaceLookupMap(superclassElement, visitedIn terfaces);
6286 map = new MemberMap.con2(map); 6332 map = new MemberMap.con2(map);
6287 substituteTypeParametersDownHierarchy(supertype, map); 6333 substituteTypeParametersDownHierarchy(supertype, map);
6288 recordMapWithClassMembers(map, supertype); 6334 recordMapWithClassMembers(map, supertype);
6289 lookupMaps.add(map); 6335 lookupMaps.add(map);
6290 } finally { 6336 } finally {
6291 visitedInterfaces.remove(superclassElement); 6337 visitedInterfaces.remove(superclassElement);
6292 } 6338 }
6293 } else { 6339 } else {
6294 MemberMap map = _interfaceLookup[classElt]; 6340 MemberMap map = _interfaceLookup[classElt];
6295 if (map != null) { 6341 if (map != null) {
6296 lookupMaps.add(map); 6342 lookupMaps.add(map);
6297 } else { 6343 } else {
6298 _interfaceLookup[superclassElement] = resultMap; 6344 _interfaceLookup[superclassElement] = resultMap;
6299 return resultMap; 6345 return resultMap;
6300 } 6346 }
6301 } 6347 }
6302 } 6348 }
6303 for (InterfaceType mixinType in mixins) { 6349 for (InterfaceType mixinType in mixins) {
6304 MemberMap mapWithMixinMembers = new MemberMap(); 6350 MemberMap mapWithMixinMembers = new MemberMap();
6305 recordMapWithClassMembers(mapWithMixinMembers, mixinType); 6351 recordMapWithClassMembers(mapWithMixinMembers, mixinType);
6306 lookupMaps.add(mapWithMixinMembers); 6352 lookupMaps.add(mapWithMixinMembers);
6307 } 6353 }
6308 for (InterfaceType interfaceType in interfaces) { 6354 for (InterfaceType interfaceType in interfaces) {
6309 ClassElement interfaceElement = interfaceType.element; 6355 ClassElement interfaceElement = interfaceType.element;
6310 if (interfaceElement != null) { 6356 if (interfaceElement != null) {
6311 if (!visitedInterfaces.contains(interfaceElement)) { 6357 if (!visitedInterfaces.contains(interfaceElement)) {
6312 try { 6358 try {
6313 javaSetAdd(visitedInterfaces, interfaceElement); 6359 visitedInterfaces.add(interfaceElement);
6314 MemberMap map = computeInterfaceLookupMap(interfaceElement, visitedI nterfaces); 6360 MemberMap map = computeInterfaceLookupMap(interfaceElement, visitedI nterfaces);
6315 map = new MemberMap.con2(map); 6361 map = new MemberMap.con2(map);
6316 substituteTypeParametersDownHierarchy(interfaceType, map); 6362 substituteTypeParametersDownHierarchy(interfaceType, map);
6317 recordMapWithClassMembers(map, interfaceType); 6363 recordMapWithClassMembers(map, interfaceType);
6318 lookupMaps.add(map); 6364 lookupMaps.add(map);
6319 } finally { 6365 } finally {
6320 visitedInterfaces.remove(interfaceElement); 6366 visitedInterfaces.remove(interfaceElement);
6321 } 6367 }
6322 } else { 6368 } else {
6323 MemberMap map = _interfaceLookup[classElt]; 6369 MemberMap map = _interfaceLookup[classElt];
(...skipping 15 matching lines...) Expand all
6339 for (int i = 0; i < lookupMap.size; i++) { 6385 for (int i = 0; i < lookupMap.size; i++) {
6340 String key = lookupMap.getKey(i); 6386 String key = lookupMap.getKey(i);
6341 if (key == null) { 6387 if (key == null) {
6342 break; 6388 break;
6343 } 6389 }
6344 Set<ExecutableElement> set = unionMap[key]; 6390 Set<ExecutableElement> set = unionMap[key];
6345 if (set == null) { 6391 if (set == null) {
6346 set = new Set<ExecutableElement>(); 6392 set = new Set<ExecutableElement>();
6347 unionMap[key] = set; 6393 unionMap[key] = set;
6348 } 6394 }
6349 javaSetAdd(set, lookupMap.getValue(i)); 6395 set.add(lookupMap.getValue(i));
6350 } 6396 }
6351 } 6397 }
6352 for (MapEntry<String, Set<ExecutableElement>> entry in getMapEntrySet(unionM ap)) { 6398 for (MapEntry<String, Set<ExecutableElement>> entry in getMapEntrySet(unionM ap)) {
6353 String key = entry.getKey(); 6399 String key = entry.getKey();
6354 Set<ExecutableElement> set = entry.getValue(); 6400 Set<ExecutableElement> set = entry.getValue();
6355 int numOfEltsWithMatchingNames = set.length; 6401 int numOfEltsWithMatchingNames = set.length;
6356 if (numOfEltsWithMatchingNames == 1) { 6402 if (numOfEltsWithMatchingNames == 1) {
6357 resultMap.put(key, new JavaIterator(set).next()); 6403 resultMap.put(key, new JavaIterator(set).next());
6358 } else { 6404 } else {
6359 bool allMethods = true; 6405 bool allMethods = true;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
6472 * @param length the length of the location of the error 6518 * @param length the length of the location of the error
6473 * @param errorCode the error code to be associated with this error 6519 * @param errorCode the error code to be associated with this error
6474 * @param arguments the arguments used to build the error message 6520 * @param arguments the arguments used to build the error message
6475 */ 6521 */
6476 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro rCode, List<Object> arguments) { 6522 void reportError(ClassElement classElt, int offset, int length, ErrorCode erro rCode, List<Object> arguments) {
6477 Set<AnalysisError> errorSet = _errorsInClassElement[classElt]; 6523 Set<AnalysisError> errorSet = _errorsInClassElement[classElt];
6478 if (errorSet == null) { 6524 if (errorSet == null) {
6479 errorSet = new Set<AnalysisError>(); 6525 errorSet = new Set<AnalysisError>();
6480 _errorsInClassElement[classElt] = errorSet; 6526 _errorsInClassElement[classElt] = errorSet;
6481 } 6527 }
6482 javaSetAdd(errorSet, new AnalysisError.con2(classElt.source, offset, length, errorCode, arguments)); 6528 errorSet.add(new AnalysisError.con2(classElt.source, offset, length, errorCo de, arguments));
6483 } 6529 }
6484 6530
6485 /** 6531 /**
6486 * Loop through all of the members in some [MemberMap], performing type parame ter 6532 * Loop through all of the members in some [MemberMap], performing type parame ter
6487 * substitutions using a passed supertype. 6533 * substitutions using a passed supertype.
6488 * 6534 *
6489 * @param superType the supertype to substitute into the members of the [Membe rMap] 6535 * @param superType the supertype to substitute into the members of the [Membe rMap]
6490 * @param map the MemberMap to perform the substitutions on 6536 * @param map the MemberMap to perform the substitutions on
6491 */ 6537 */
6492 void substituteTypeParametersDownHierarchy(InterfaceType superType, MemberMap map) { 6538 void substituteTypeParametersDownHierarchy(InterfaceType superType, MemberMap map) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
6639 6685
6640 /** 6686 /**
6641 * Return an array containing the libraries that are either imported or export ed from this 6687 * Return an array containing the libraries that are either imported or export ed from this
6642 * library. 6688 * library.
6643 * 6689 *
6644 * @return the libraries that are either imported or exported from this librar y 6690 * @return the libraries that are either imported or exported from this librar y
6645 */ 6691 */
6646 List<Library> get importsAndExports { 6692 List<Library> get importsAndExports {
6647 Set<Library> libraries = new Set<Library>(); 6693 Set<Library> libraries = new Set<Library>();
6648 for (Library library in imports) { 6694 for (Library library in imports) {
6649 javaSetAdd(libraries, library); 6695 libraries.add(library);
6650 } 6696 }
6651 for (Library library in exports) { 6697 for (Library library in exports) {
6652 javaSetAdd(libraries, library); 6698 libraries.add(library);
6653 } 6699 }
6654 return new List.from(libraries); 6700 return new List.from(libraries);
6655 } 6701 }
6656 6702
6657 /** 6703 /**
6658 * Return the inheritance manager for this library. 6704 * Return the inheritance manager for this library.
6659 * 6705 *
6660 * @return the inheritance manager for this library 6706 * @return the inheritance manager for this library
6661 */ 6707 */
6662 InheritanceManager get inheritanceManager { 6708 InheritanceManager get inheritanceManager {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
7094 * @throws AnalysisException if the library could not be resolved for some rea son 7140 * @throws AnalysisException if the library could not be resolved for some rea son
7095 */ 7141 */
7096 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) { 7142 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) {
7097 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveLibrary"); 7143 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveLibrary");
7098 try { 7144 try {
7099 instrumentation.metric("fullAnalysis", fullAnalysis); 7145 instrumentation.metric("fullAnalysis", fullAnalysis);
7100 instrumentation.data3("fullName", librarySource.fullName); 7146 instrumentation.data3("fullName", librarySource.fullName);
7101 Library targetLibrary = createLibrary(librarySource); 7147 Library targetLibrary = createLibrary(librarySource);
7102 _coreLibrary = _libraryMap[_coreLibrarySource]; 7148 _coreLibrary = _libraryMap[_coreLibrarySource];
7103 if (_coreLibrary == null) { 7149 if (_coreLibrary == null) {
7104 _coreLibrary = createLibrary(_coreLibrarySource); 7150 _coreLibrary = createLibraryOrNull(_coreLibrarySource);
7151 if (_coreLibrary == null) {
7152 throw new AnalysisException.con1("Core library does not exist");
7153 }
7105 } 7154 }
7106 instrumentation.metric3("createLibrary", "complete"); 7155 instrumentation.metric3("createLibrary", "complete");
7107 computeLibraryDependencies(targetLibrary); 7156 computeLibraryDependencies(targetLibrary);
7108 resolvedLibraries = computeLibrariesInCycles(targetLibrary); 7157 resolvedLibraries = computeLibrariesInCycles(targetLibrary);
7109 buildElementModels(); 7158 buildElementModels();
7110 instrumentation.metric3("buildElementModels", "complete"); 7159 instrumentation.metric3("buildElementModels", "complete");
7111 LibraryElement coreElement = _coreLibrary.libraryElement; 7160 LibraryElement coreElement = _coreLibrary.libraryElement;
7112 if (coreElement == null) { 7161 if (coreElement == null) {
7113 throw new AnalysisException.con1("Could not resolve dart:core"); 7162 throw new AnalysisException.con1("Could not resolve dart:core");
7114 } 7163 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7151 * Given a library that is part of a cycle that includes the root library, add to the given set of 7200 * Given a library that is part of a cycle that includes the root library, add to the given set of
7152 * libraries all of the libraries reachable from the root library that are als o included in the 7201 * libraries all of the libraries reachable from the root library that are als o included in the
7153 * cycle. 7202 * cycle.
7154 * 7203 *
7155 * @param library the library to be added to the collection of libraries in cy cles 7204 * @param library the library to be added to the collection of libraries in cy cles
7156 * @param librariesInCycle a collection of the libraries that are in the cycle 7205 * @param librariesInCycle a collection of the libraries that are in the cycle
7157 * @param dependencyMap a table mapping libraries to the collection of librari es from which those 7206 * @param dependencyMap a table mapping libraries to the collection of librari es from which those
7158 * libraries are referenced 7207 * libraries are referenced
7159 */ 7208 */
7160 void addLibrariesInCycle(Library library, Set<Library> librariesInCycle, Map<L ibrary, List<Library>> dependencyMap) { 7209 void addLibrariesInCycle(Library library, Set<Library> librariesInCycle, Map<L ibrary, List<Library>> dependencyMap) {
7161 if (javaSetAdd(librariesInCycle, library)) { 7210 if (librariesInCycle.add(library)) {
7162 List<Library> dependentLibraries = dependencyMap[library]; 7211 List<Library> dependentLibraries = dependencyMap[library];
7163 if (dependentLibraries != null) { 7212 if (dependentLibraries != null) {
7164 for (Library dependentLibrary in dependentLibraries) { 7213 for (Library dependentLibrary in dependentLibraries) {
7165 addLibrariesInCycle(dependentLibrary, librariesInCycle, dependencyMap) ; 7214 addLibrariesInCycle(dependentLibrary, librariesInCycle, dependencyMap) ;
7166 } 7215 }
7167 } 7216 }
7168 } 7217 }
7169 } 7218 }
7170 7219
7171 /** 7220 /**
7172 * Add the given library, and all libraries reachable from it that have not al ready been visited, 7221 * Add the given library, and all libraries reachable from it that have not al ready been visited,
7173 * to the given dependency map. 7222 * to the given dependency map.
7174 * 7223 *
7175 * @param library the library currently being added to the dependency map 7224 * @param library the library currently being added to the dependency map
7176 * @param dependencyMap the dependency map being computed 7225 * @param dependencyMap the dependency map being computed
7177 * @param visitedLibraries the libraries that have already been visited, used to prevent infinite 7226 * @param visitedLibraries the libraries that have already been visited, used to prevent infinite
7178 * recursion 7227 * recursion
7179 */ 7228 */
7180 void addToDependencyMap(Library library, Map<Library, List<Library>> dependenc yMap, Set<Library> visitedLibraries) { 7229 void addToDependencyMap(Library library, Map<Library, List<Library>> dependenc yMap, Set<Library> visitedLibraries) {
7181 if (javaSetAdd(visitedLibraries, library)) { 7230 if (visitedLibraries.add(library)) {
7182 for (Library referencedLibrary in library.importsAndExports) { 7231 for (Library referencedLibrary in library.importsAndExports) {
7183 addDependencyToMap(dependencyMap, library, referencedLibrary); 7232 addDependencyToMap(dependencyMap, library, referencedLibrary);
7184 addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries); 7233 addToDependencyMap(referencedLibrary, dependencyMap, visitedLibraries);
7185 } 7234 }
7186 if (!library.explicitlyImportsCore && library != _coreLibrary) { 7235 if (!library.explicitlyImportsCore && library != _coreLibrary) {
7187 addDependencyToMap(dependencyMap, library, _coreLibrary); 7236 addDependencyToMap(dependencyMap, library, _coreLibrary);
7188 } 7237 }
7189 } 7238 }
7190 } 7239 }
7191 7240
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
7251 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; 7300 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
7252 if (prefix == null) { 7301 if (prefix == null) {
7253 prefix = new PrefixElementImpl(prefixNode); 7302 prefix = new PrefixElementImpl(prefixNode);
7254 nameToPrefixMap[prefixName] = prefix; 7303 nameToPrefixMap[prefixName] = prefix;
7255 } 7304 }
7256 importElement.prefix = prefix; 7305 importElement.prefix = prefix;
7257 prefixNode.staticElement = prefix; 7306 prefixNode.staticElement = prefix;
7258 } 7307 }
7259 directive.element = importElement; 7308 directive.element = importElement;
7260 imports.add(importElement); 7309 imports.add(importElement);
7261 if (doesCompilationUnitHavePartOfDirective(importedLibrary.getAST( importedSource))) { 7310 if (analysisContext.computeKindOf(importedSource) != SourceKind.LI BRARY) {
7262 errorListener.onError(new AnalysisError.con2(library.librarySour ce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LIB RARY, [uriLiteral.toSource()])); 7311 errorListener.onError(new AnalysisError.con2(library.librarySour ce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LIB RARY, [uriLiteral.toSource()]));
7263 } 7312 }
7264 } 7313 }
7265 } 7314 }
7266 } else if (directive is ExportDirective) { 7315 } else if (directive is ExportDirective) {
7267 ExportDirective exportDirective = directive as ExportDirective; 7316 ExportDirective exportDirective = directive as ExportDirective;
7268 Source exportedSource = library.getSource(exportDirective); 7317 Source exportedSource = library.getSource(exportDirective);
7269 if (exportedSource != null) { 7318 if (exportedSource != null) {
7270 Library exportedLibrary = _libraryMap[exportedSource]; 7319 Library exportedLibrary = _libraryMap[exportedSource];
7271 if (exportedLibrary != null) { 7320 if (exportedLibrary != null) {
7272 ExportElementImpl exportElement = new ExportElementImpl(); 7321 ExportElementImpl exportElement = new ExportElementImpl();
7273 exportElement.uri = library.getUri(exportDirective); 7322 exportElement.uri = library.getUri(exportDirective);
7274 exportElement.combinators = buildCombinators(exportDirective); 7323 exportElement.combinators = buildCombinators(exportDirective);
7275 LibraryElement exportedLibraryElement = exportedLibrary.libraryEle ment; 7324 LibraryElement exportedLibraryElement = exportedLibrary.libraryEle ment;
7276 if (exportedLibraryElement != null) { 7325 if (exportedLibraryElement != null) {
7277 exportElement.exportedLibrary = exportedLibraryElement; 7326 exportElement.exportedLibrary = exportedLibraryElement;
7278 } 7327 }
7279 directive.element = exportElement; 7328 directive.element = exportElement;
7280 exports.add(exportElement); 7329 exports.add(exportElement);
7281 if (doesCompilationUnitHavePartOfDirective(exportedLibrary.getAST( exportedSource))) { 7330 if (analysisContext.computeKindOf(exportedSource) != SourceKind.LI BRARY) {
7282 StringLiteral uriLiteral = exportDirective.uri; 7331 StringLiteral uriLiteral = exportDirective.uri;
7283 errorListener.onError(new AnalysisError.con2(library.librarySour ce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LIB RARY, [uriLiteral.toSource()])); 7332 errorListener.onError(new AnalysisError.con2(library.librarySour ce, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LIB RARY, [uriLiteral.toSource()]));
7284 } 7333 }
7285 } 7334 }
7286 } 7335 }
7287 } 7336 }
7288 } 7337 }
7289 Source librarySource = library.librarySource; 7338 Source librarySource = library.librarySource;
7290 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource) { 7339 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource) {
7291 ImportElementImpl importElement = new ImportElementImpl(); 7340 ImportElementImpl importElement = new ImportElementImpl();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
7384 * @throws AnalysisException if some portion of the library graph could not be traversed 7433 * @throws AnalysisException if some portion of the library graph could not be traversed
7385 */ 7434 */
7386 void computeLibraryDependencies2(Library library, CompilationUnit unit) { 7435 void computeLibraryDependencies2(Library library, CompilationUnit unit) {
7387 Source librarySource = library.librarySource; 7436 Source librarySource = library.librarySource;
7388 Set<Source> exportedSources = new Set<Source>(); 7437 Set<Source> exportedSources = new Set<Source>();
7389 Set<Source> importedSources = new Set<Source>(); 7438 Set<Source> importedSources = new Set<Source>();
7390 for (Directive directive in unit.directives) { 7439 for (Directive directive in unit.directives) {
7391 if (directive is ExportDirective) { 7440 if (directive is ExportDirective) {
7392 Source exportSource = resolveSource(librarySource, directive as ExportDi rective); 7441 Source exportSource = resolveSource(librarySource, directive as ExportDi rective);
7393 if (exportSource != null) { 7442 if (exportSource != null) {
7394 javaSetAdd(exportedSources, exportSource); 7443 exportedSources.add(exportSource);
7395 } 7444 }
7396 } else if (directive is ImportDirective) { 7445 } else if (directive is ImportDirective) {
7397 Source importSource = resolveSource(librarySource, directive as ImportDi rective); 7446 Source importSource = resolveSource(librarySource, directive as ImportDi rective);
7398 if (importSource != null) { 7447 if (importSource != null) {
7399 javaSetAdd(importedSources, importSource); 7448 importedSources.add(importSource);
7400 } 7449 }
7401 } 7450 }
7402 } 7451 }
7403 computeLibraryDependencies3(library, new List.from(importedSources), new Lis t.from(exportedSources)); 7452 computeLibraryDependencies3(library, new List.from(importedSources), new Lis t.from(exportedSources));
7404 } 7453 }
7405 7454
7406 /** 7455 /**
7407 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 7456 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
7408 * class [Library] to represent them, and record the references in the library objects. 7457 * class [Library] to represent them, and record the references in the library objects.
7409 * 7458 *
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
7501 Library createLibraryOrNull(Source librarySource) { 7550 Library createLibraryOrNull(Source librarySource) {
7502 if (!librarySource.exists()) { 7551 if (!librarySource.exists()) {
7503 return null; 7552 return null;
7504 } 7553 }
7505 Library library = new Library(analysisContext, errorListener, librarySource) ; 7554 Library library = new Library(analysisContext, errorListener, librarySource) ;
7506 _libraryMap[librarySource] = library; 7555 _libraryMap[librarySource] = library;
7507 return library; 7556 return library;
7508 } 7557 }
7509 7558
7510 /** 7559 /**
7511 * Return `true` if and only if the passed [CompilationUnit] has a part-of dir ective.
7512 *
7513 * @param node the [CompilationUnit] to test
7514 * @return `true` if and only if the passed [CompilationUnit] has a part-of di rective
7515 */
7516 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) {
7517 NodeList<Directive> directives = node.directives;
7518 for (Directive directive in directives) {
7519 if (directive is PartOfDirective) {
7520 return true;
7521 }
7522 }
7523 return false;
7524 }
7525
7526 /**
7527 * Return an array containing the lexical identifiers associated with the node s in the given list. 7560 * Return an array containing the lexical identifiers associated with the node s in the given list.
7528 * 7561 *
7529 * @param names the AST nodes representing the identifiers 7562 * @param names the AST nodes representing the identifiers
7530 * @return the lexical identifiers associated with the nodes in the list 7563 * @return the lexical identifiers associated with the nodes in the list
7531 */ 7564 */
7532 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { 7565 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) {
7533 int count = names.length; 7566 int count = names.length;
7534 List<String> identifiers = new List<String>(count); 7567 List<String> identifiers = new List<String>(count);
7535 for (int i = 0; i < count; i++) { 7568 for (int i = 0; i < count; i++) {
7536 identifiers[i] = names[i].name; 7569 identifiers[i] = names[i].name;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
7780 * This class is a wrapper for an [AnalysisError] which can also be queried afte r resolution 7813 * This class is a wrapper for an [AnalysisError] which can also be queried afte r resolution
7781 * to find out if the error should actually be reported. In this case, these err ors are conditional 7814 * to find out if the error should actually be reported. In this case, these err ors are conditional
7782 * on the non-existence of an `@proxy` annotation. 7815 * on the non-existence of an `@proxy` annotation.
7783 * 7816 *
7784 * If we have other conditional error codes in the future, we should have this c lass implement some 7817 * If we have other conditional error codes in the future, we should have this c lass implement some
7785 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode can be visited 7818 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode can be visited
7786 * instead of multiple lists of *ConditionalErrorCodes. 7819 * instead of multiple lists of *ConditionalErrorCodes.
7787 */ 7820 */
7788 class ProxyConditionalAnalysisError { 7821 class ProxyConditionalAnalysisError {
7789 /** 7822 /**
7790 * The name of the proxy annotation, from dart:core.
7791 */
7792 static String _PROXY_ANNOTATION_NAME = "proxy";
7793
7794 /**
7795 * Return `true` if the given element represents a class that has the proxy an notation. 7823 * Return `true` if the given element represents a class that has the proxy an notation.
7796 * 7824 *
7797 * @param element the class being tested 7825 * @param element the class being tested
7798 * @return `true` if the given element represents a class that has the proxy a nnotation 7826 * @return `true` if the given element represents a class that has the proxy a nnotation
7799 */ 7827 */
7800 static bool classHasProxyAnnotation(Element element) { 7828 static bool classHasProxyAnnotation(Element element) => (element is ClassEleme nt) && (element as ClassElement).isProxy;
7801 if (element is ClassElement) {
7802 ClassElement classElement = element as ClassElement;
7803 List<ElementAnnotation> annotations = classElement.metadata;
7804 for (ElementAnnotation annotation in annotations) {
7805 Element elementAnnotation = annotation.element;
7806 if (elementAnnotation != null) {
7807 LibraryElement lib = elementAnnotation.library;
7808 if (lib != null && lib.isDartCore && elementAnnotation.name == _PROXY_ ANNOTATION_NAME) {
7809 return true;
7810 }
7811 }
7812 }
7813 }
7814 return false;
7815 }
7816 7829
7817 /** 7830 /**
7818 * The enclosing [ClassElement], this is what will determine if the error code should, or 7831 * The enclosing [ClassElement], this is what will determine if the error code should, or
7819 * should not, be generated on the source. 7832 * should not, be generated on the source.
7820 */ 7833 */
7821 Element _enclosingElement; 7834 Element _enclosingElement;
7822 7835
7823 /** 7836 /**
7824 * The conditional analysis error. 7837 * The conditional analysis error.
7825 */ 7838 */
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
8023 8036
8024 Object visitCommentReference(CommentReference node) { 8037 Object visitCommentReference(CommentReference node) {
8025 node.accept(_elementResolver); 8038 node.accept(_elementResolver);
8026 node.accept(_typeAnalyzer); 8039 node.accept(_typeAnalyzer);
8027 return null; 8040 return null;
8028 } 8041 }
8029 8042
8030 Object visitCompilationUnit(CompilationUnit node) { 8043 Object visitCompilationUnit(CompilationUnit node) {
8031 try { 8044 try {
8032 overrideManager.enterScope(); 8045 overrideManager.enterScope();
8033 for (Directive directive in node.directives) { 8046 NodeList<Directive> directives = node.directives;
8034 directive.accept(this); 8047 int directiveCount = directives.length;
8048 for (int i = 0; i < directiveCount; i++) {
8049 directives[i].accept(this);
8035 } 8050 }
8036 List<CompilationUnitMember> classes = new List<CompilationUnitMember>(); 8051 NodeList<CompilationUnitMember> declarations = node.declarations;
8037 for (CompilationUnitMember declaration in node.declarations) { 8052 int declarationCount = declarations.length;
8038 if (declaration is ClassDeclaration) { 8053 for (int i = 0; i < declarationCount; i++) {
8039 classes.add(declaration); 8054 CompilationUnitMember declaration = declarations[i];
8040 } else { 8055 if (declaration is! ClassDeclaration) {
8041 declaration.accept(this); 8056 declaration.accept(this);
8042 } 8057 }
8043 } 8058 }
8044 for (CompilationUnitMember declaration in classes) { 8059 for (int i = 0; i < declarationCount; i++) {
8045 declaration.accept(this); 8060 CompilationUnitMember declaration = declarations[i];
8061 if (declaration is ClassDeclaration) {
8062 declaration.accept(this);
8063 }
8046 } 8064 }
8047 } finally { 8065 } finally {
8048 overrideManager.exitScope(); 8066 overrideManager.exitScope();
8049 } 8067 }
8050 node.accept(_elementResolver); 8068 node.accept(_elementResolver);
8051 node.accept(_typeAnalyzer); 8069 node.accept(_typeAnalyzer);
8052 return null; 8070 return null;
8053 } 8071 }
8054 8072
8055 Object visitConditionalExpression(ConditionalExpression node) { 8073 Object visitConditionalExpression(ConditionalExpression node) {
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
9442 } 9460 }
9443 return outerScope; 9461 return outerScope;
9444 } 9462 }
9445 9463
9446 /** 9464 /**
9447 * Marks the local declarations of the given [Block] hidden in the enclosing s cope. 9465 * Marks the local declarations of the given [Block] hidden in the enclosing s cope.
9448 * According to the scoping rules name is hidden if block defines it, but name is defined after 9466 * According to the scoping rules name is hidden if block defines it, but name is defined after
9449 * its declaration statement. 9467 * its declaration statement.
9450 */ 9468 */
9451 void hideNamesDefinedInBlock(EnclosedScope scope, Block block) { 9469 void hideNamesDefinedInBlock(EnclosedScope scope, Block block) {
9452 for (Statement statement in block.statements) { 9470 NodeList<Statement> statements = block.statements;
9471 int statementCount = statements.length;
9472 for (int i = 0; i < statementCount; i++) {
9473 Statement statement = statements[i];
9453 if (statement is VariableDeclarationStatement) { 9474 if (statement is VariableDeclarationStatement) {
9454 VariableDeclarationStatement vds = statement as VariableDeclarationState ment; 9475 VariableDeclarationStatement vds = statement as VariableDeclarationState ment;
9455 for (VariableDeclaration variableDeclaration in vds.variables.variables) { 9476 NodeList<VariableDeclaration> variables = vds.variables.variables;
9456 Element element = variableDeclaration.element; 9477 int variableCount = variables.length;
9457 scope.hide(element); 9478 for (int j = 0; j < variableCount; j++) {
9479 scope.hide(variables[j].element);
9458 } 9480 }
9459 } 9481 } else if (statement is FunctionDeclarationStatement) {
9460 if (statement is FunctionDeclarationStatement) {
9461 FunctionDeclarationStatement fds = statement as FunctionDeclarationState ment; 9482 FunctionDeclarationStatement fds = statement as FunctionDeclarationState ment;
9462 Element element = fds.functionDeclaration.element; 9483 scope.hide(fds.functionDeclaration.element);
9463 scope.hide(element);
9464 } 9484 }
9465 } 9485 }
9466 } 9486 }
9467 } 9487 }
9468 9488
9469 /** 9489 /**
9470 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F irst, they 9490 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F irst, they
9471 * compute the static type of every expression. Second, they look for any static type errors or 9491 * compute the static type of every expression. Second, they look for any static type errors or
9472 * warnings that might need to be generated. The requirements for the type analy zer are: 9492 * warnings that might need to be generated. The requirements for the type analy zer are:
9473 * <ol> 9493 * <ol>
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
10150 * <i>S.m</i> exists, it is a static warning if the type <i>F</i> of <i>S.m</i > may not be 10170 * <i>S.m</i> exists, it is a static warning if the type <i>F</i> of <i>S.m</i > may not be
10151 * assigned to a function type. 10171 * assigned to a function type.
10152 * 10172 *
10153 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st atic type of 10173 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st atic type of
10154 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared return type of 10174 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared return type of
10155 * <i>F</i>.</blockquote> 10175 * <i>F</i>.</blockquote>
10156 */ 10176 */
10157 Object visitMethodInvocation(MethodInvocation node) { 10177 Object visitMethodInvocation(MethodInvocation node) {
10158 SimpleIdentifier methodNameNode = node.methodName; 10178 SimpleIdentifier methodNameNode = node.methodName;
10159 Element staticMethodElement = methodNameNode.staticElement; 10179 Element staticMethodElement = methodNameNode.staticElement;
10180 if (staticMethodElement is LocalVariableElement) {
10181 LocalVariableElement variable = staticMethodElement as LocalVariableElemen t;
10182 Type2 staticType = variable.type;
10183 recordStaticType(methodNameNode, staticType);
10184 Type2 propagatedType = _overrideManager.getType(variable);
10185 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) {
10186 recordPropagatedType2(methodNameNode, propagatedType);
10187 }
10188 }
10160 Type2 staticStaticType = computeStaticReturnType(staticMethodElement); 10189 Type2 staticStaticType = computeStaticReturnType(staticMethodElement);
10161 recordStaticType(node, staticStaticType); 10190 recordStaticType(node, staticStaticType);
10162 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement ); 10191 Type2 staticPropagatedType = computePropagatedReturnType(staticMethodElement );
10163 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) { 10192 if (staticPropagatedType != null && (staticStaticType == null || staticPropa gatedType.isMoreSpecificThan(staticStaticType))) {
10164 recordPropagatedType2(node, staticPropagatedType); 10193 recordPropagatedType2(node, staticPropagatedType);
10165 } 10194 }
10166 String methodName = methodNameNode.name; 10195 String methodName = methodNameNode.name;
10167 if (methodName == "then") { 10196 if (methodName == "then") {
10168 Expression target = node.realTarget; 10197 Expression target = node.realTarget;
10169 Type2 targetType = target == null ? null : target.bestType; 10198 Type2 targetType = target == null ? null : target.bestType;
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
11112 11141
11113 /** 11142 /**
11114 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively 11143 * Given some [ClassElement] and a [HashSet<ClassElement>], this method recurs ively
11115 * adds all of the subtypes of the [ClassElement] to the passed array. 11144 * adds all of the subtypes of the [ClassElement] to the passed array.
11116 * 11145 *
11117 * @param classElement the type to compute the set of subtypes of 11146 * @param classElement the type to compute the set of subtypes of
11118 * @param visitedClasses the set of class elements that this method has alread y recursively seen 11147 * @param visitedClasses the set of class elements that this method has alread y recursively seen
11119 * @param allSubtypes the computed set of subtypes of the passed class element 11148 * @param allSubtypes the computed set of subtypes of the passed class element
11120 */ 11149 */
11121 void computeAllSubtypes2(ClassElement classElement, Set<ClassElement> visitedC lasses, Set<ClassElement> allSubtypes) { 11150 void computeAllSubtypes2(ClassElement classElement, Set<ClassElement> visitedC lasses, Set<ClassElement> allSubtypes) {
11122 if (!javaSetAdd(visitedClasses, classElement)) { 11151 if (!visitedClasses.add(classElement)) {
11123 return; 11152 return;
11124 } 11153 }
11125 Set<ClassElement> subtypes = _subtypeMap[classElement]; 11154 Set<ClassElement> subtypes = _subtypeMap[classElement];
11126 if (subtypes == null) { 11155 if (subtypes == null) {
11127 return; 11156 return;
11128 } 11157 }
11129 for (ClassElement subtype in subtypes) { 11158 for (ClassElement subtype in subtypes) {
11130 computeAllSubtypes2(subtype, visitedClasses, allSubtypes); 11159 computeAllSubtypes2(subtype, visitedClasses, allSubtypes);
11131 } 11160 }
11132 allSubtypes.addAll(subtypes); 11161 allSubtypes.addAll(subtypes);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
11181 * [computeAllSubtypes] on all of the [ClassElement]s in the 11210 * [computeAllSubtypes] on all of the [ClassElement]s in the
11182 * compilation unit, and itself for all imported and exported libraries. All v isited libraries are 11211 * compilation unit, and itself for all imported and exported libraries. All v isited libraries are
11183 * added to the [visitedLibraries] set. 11212 * added to the [visitedLibraries] set.
11184 * 11213 *
11185 * @param libraryElement the library element 11214 * @param libraryElement the library element
11186 */ 11215 */
11187 void computeSubtypesInLibrary(LibraryElement libraryElement) { 11216 void computeSubtypesInLibrary(LibraryElement libraryElement) {
11188 if (libraryElement == null || _visitedLibraries.contains(libraryElement)) { 11217 if (libraryElement == null || _visitedLibraries.contains(libraryElement)) {
11189 return; 11218 return;
11190 } 11219 }
11191 javaSetAdd(_visitedLibraries, libraryElement); 11220 _visitedLibraries.add(libraryElement);
11192 computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit); 11221 computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit);
11193 List<CompilationUnitElement> parts = libraryElement.parts; 11222 List<CompilationUnitElement> parts = libraryElement.parts;
11194 for (CompilationUnitElement part in parts) { 11223 for (CompilationUnitElement part in parts) {
11195 computeSubtypesInCompilationUnit(part); 11224 computeSubtypesInCompilationUnit(part);
11196 } 11225 }
11197 List<LibraryElement> imports = libraryElement.importedLibraries; 11226 List<LibraryElement> imports = libraryElement.importedLibraries;
11198 for (LibraryElement importElt in imports) { 11227 for (LibraryElement importElt in imports) {
11199 computeSubtypesInLibrary(importElt.library); 11228 computeSubtypesInLibrary(importElt.library);
11200 } 11229 }
11201 List<LibraryElement> exports = libraryElement.exportedLibraries; 11230 List<LibraryElement> exports = libraryElement.exportedLibraries;
11202 for (LibraryElement exportElt in exports) { 11231 for (LibraryElement exportElt in exports) {
11203 computeSubtypesInLibrary(exportElt.library); 11232 computeSubtypesInLibrary(exportElt.library);
11204 } 11233 }
11205 } 11234 }
11206 11235
11207 /** 11236 /**
11208 * Add some key/ value pair into the [subtypeMap] map. 11237 * Add some key/ value pair into the [subtypeMap] map.
11209 * 11238 *
11210 * @param supertypeElement the key for the [subtypeMap] map 11239 * @param supertypeElement the key for the [subtypeMap] map
11211 * @param subtypeElement the value for the [subtypeMap] map 11240 * @param subtypeElement the value for the [subtypeMap] map
11212 */ 11241 */
11213 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) { 11242 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) {
11214 Set<ClassElement> subtypes = _subtypeMap[supertypeElement]; 11243 Set<ClassElement> subtypes = _subtypeMap[supertypeElement];
11215 if (subtypes == null) { 11244 if (subtypes == null) {
11216 subtypes = new Set<ClassElement>(); 11245 subtypes = new Set<ClassElement>();
11217 _subtypeMap[supertypeElement] = subtypes; 11246 _subtypeMap[supertypeElement] = subtypes;
11218 } 11247 }
11219 javaSetAdd(subtypes, subtypeElement); 11248 subtypes.add(subtypeElement);
11220 } 11249 }
11221 } 11250 }
11222 11251
11223 /** 11252 /**
11224 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an 11253 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an
11225 * element within a given context. 11254 * element within a given context.
11226 */ 11255 */
11227 class TypeOverrideManager { 11256 class TypeOverrideManager {
11228 /** 11257 /**
11229 * The current override scope, or `null` if no scope has been entered. 11258 * The current override scope, or `null` if no scope has been entered.
(...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after
13158 13187
13159 /** 13188 /**
13160 * The listener that is to be informed when an error is encountered. 13189 * The listener that is to be informed when an error is encountered.
13161 */ 13190 */
13162 AnalysisErrorListener _errorListener; 13191 AnalysisErrorListener _errorListener;
13163 13192
13164 /** 13193 /**
13165 * A list of the namespaces representing the names that are available in this scope from imported 13194 * A list of the namespaces representing the names that are available in this scope from imported
13166 * libraries. 13195 * libraries.
13167 */ 13196 */
13168 List<Namespace> _importedNamespaces = new List<Namespace>(); 13197 List<Namespace> _importedNamespaces;
13169 13198
13170 /** 13199 /**
13171 * Initialize a newly created scope representing the names imported into the g iven library. 13200 * Initialize a newly created scope representing the names imported into the g iven library.
13172 * 13201 *
13173 * @param definingLibrary the element representing the library that imports th e names defined in 13202 * @param definingLibrary the element representing the library that imports th e names defined in
13174 * this scope 13203 * this scope
13175 * @param errorListener the listener that is to be informed when an error is e ncountered 13204 * @param errorListener the listener that is to be informed when an error is e ncountered
13176 */ 13205 */
13177 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error Listener) { 13206 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error Listener) {
13178 this._definingLibrary = definingLibrary; 13207 this._definingLibrary = definingLibrary;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
13222 13251
13223 /** 13252 /**
13224 * Create all of the namespaces associated with the libraries imported into th is library. The 13253 * Create all of the namespaces associated with the libraries imported into th is library. The
13225 * names are not added to this scope, but are stored for later reference. 13254 * names are not added to this scope, but are stored for later reference.
13226 * 13255 *
13227 * @param definingLibrary the element representing the library that imports th e libraries for 13256 * @param definingLibrary the element representing the library that imports th e libraries for
13228 * which namespaces will be created 13257 * which namespaces will be created
13229 */ 13258 */
13230 void createImportedNamespaces(LibraryElement definingLibrary) { 13259 void createImportedNamespaces(LibraryElement definingLibrary) {
13231 NamespaceBuilder builder = new NamespaceBuilder(); 13260 NamespaceBuilder builder = new NamespaceBuilder();
13232 for (ImportElement element in definingLibrary.imports) { 13261 List<ImportElement> imports = definingLibrary.imports;
13233 _importedNamespaces.add(builder.createImportNamespace(element)); 13262 int count = imports.length;
13263 _importedNamespaces = new List<Namespace>(count);
13264 for (int i = 0; i < count; i++) {
13265 _importedNamespaces[i] = builder.createImportNamespace(imports[i]);
13234 } 13266 }
13235 } 13267 }
13236 13268
13237 /** 13269 /**
13238 * Returns the name of the library that defines given element. 13270 * Returns the name of the library that defines given element.
13239 * 13271 *
13240 * @param element the element to get library name 13272 * @param element the element to get library name
13241 * @param def the default name to use 13273 * @param def the default name to use
13242 * @return the name of the library that defines given element 13274 * @return the name of the library that defines given element
13243 */ 13275 */
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
13572 /** 13604 /**
13573 * Create a mapping table representing the export namespace of the given libra ry. 13605 * Create a mapping table representing the export namespace of the given libra ry.
13574 * 13606 *
13575 * @param library the library whose public namespace is to be created 13607 * @param library the library whose public namespace is to be created
13576 * @param visitedElements a set of libraries that do not need to be visited wh en processing the 13608 * @param visitedElements a set of libraries that do not need to be visited wh en processing the
13577 * export directives of the given library because all of the names de fined by them will 13609 * export directives of the given library because all of the names de fined by them will
13578 * be added by another library 13610 * be added by another library
13579 * @return the mapping table that was created 13611 * @return the mapping table that was created
13580 */ 13612 */
13581 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl ement> visitedElements) { 13613 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl ement> visitedElements) {
13582 javaSetAdd(visitedElements, library); 13614 visitedElements.add(library);
13583 try { 13615 try {
13584 Map<String, Element> definedNames = new Map<String, Element>(); 13616 Map<String, Element> definedNames = new Map<String, Element>();
13585 for (ExportElement element in library.exports) { 13617 for (ExportElement element in library.exports) {
13586 LibraryElement exportedLibrary = element.exportedLibrary; 13618 LibraryElement exportedLibrary = element.exportedLibrary;
13587 if (exportedLibrary != null && !visitedElements.contains(exportedLibrary )) { 13619 if (exportedLibrary != null && !visitedElements.contains(exportedLibrary )) {
13588 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry, visitedElements); 13620 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry, visitedElements);
13589 exportedNames = apply(exportedNames, element.combinators); 13621 exportedNames = apply(exportedNames, element.combinators);
13590 addAll(definedNames, exportedNames); 13622 addAll(definedNames, exportedNames);
13591 } 13623 }
13592 } 13624 }
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
14010 for (MapLiteralEntry entry in node.entries) { 14042 for (MapLiteralEntry entry in node.entries) {
14011 Expression key = entry.key; 14043 Expression key = entry.key;
14012 if (isConst) { 14044 if (isConst) {
14013 EvaluationResultImpl result = validate(key, CompileTimeErrorCode.NON_CON STANT_MAP_KEY); 14045 EvaluationResultImpl result = validate(key, CompileTimeErrorCode.NON_CON STANT_MAP_KEY);
14014 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); 14046 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
14015 if (result is ValidResult) { 14047 if (result is ValidResult) {
14016 Object value = (result as ValidResult).value; 14048 Object value = (result as ValidResult).value;
14017 if (keys.contains(value)) { 14049 if (keys.contains(value)) {
14018 invalidKeys.add(key); 14050 invalidKeys.add(key);
14019 } else { 14051 } else {
14020 javaSetAdd(keys, value); 14052 keys.add(value);
14021 } 14053 }
14022 } 14054 }
14023 } else { 14055 } else {
14024 EvaluationResultImpl result = key.accept(new ConstantVisitor()); 14056 EvaluationResultImpl result = key.accept(new ConstantVisitor());
14025 if (result is ValidResult) { 14057 if (result is ValidResult) {
14026 Object value = (result as ValidResult).value; 14058 Object value = (result as ValidResult).value;
14027 if (keys.contains(value)) { 14059 if (keys.contains(value)) {
14028 invalidKeys.add(key); 14060 invalidKeys.add(key);
14029 } else { 14061 } else {
14030 javaSetAdd(keys, value); 14062 keys.add(value);
14031 } 14063 }
14032 } else { 14064 } else {
14033 reportEqualKeys = false; 14065 reportEqualKeys = false;
14034 } 14066 }
14035 } 14067 }
14036 } 14068 }
14037 if (reportEqualKeys) { 14069 if (reportEqualKeys) {
14038 for (Expression key in invalidKeys) { 14070 for (Expression key in invalidKeys) {
14039 _errorReporter.reportError2(StaticWarningCode.EQUAL_KEYS_IN_MAP, key, [] ); 14071 _errorReporter.reportError2(StaticWarningCode.EQUAL_KEYS_IN_MAP, key, [] );
14040 } 14072 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
14159 } 14191 }
14160 14192
14161 /** 14193 /**
14162 * Validates that the given expression is a compile time constant. 14194 * Validates that the given expression is a compile time constant.
14163 * 14195 *
14164 * @param parameterElements the elements of parameters of constant constructor , they are 14196 * @param parameterElements the elements of parameters of constant constructor , they are
14165 * considered as a valid potentially constant expressions 14197 * considered as a valid potentially constant expressions
14166 * @param expression the expression to validate 14198 * @param expression the expression to validate
14167 */ 14199 */
14168 void validateInitializerExpression(List<ParameterElement> parameterElements, E xpression expression) { 14200 void validateInitializerExpression(List<ParameterElement> parameterElements, E xpression expression) {
14169 EvaluationResultImpl result = expression.accept(new ConstantVisitor_14(this, parameterElements)); 14201 EvaluationResultImpl result = expression.accept(new ConstantVisitor_13(this, parameterElements));
14170 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER) ; 14202 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER) ;
14171 } 14203 }
14172 14204
14173 /** 14205 /**
14174 * Validates that all of the arguments of a constructor initializer are compil e time constants. 14206 * Validates that all of the arguments of a constructor initializer are compil e time constants.
14175 * 14207 *
14176 * @param parameterElements the elements of parameters of constant constructor , they are 14208 * @param parameterElements the elements of parameters of constant constructor , they are
14177 * considered as a valid potentially constant expressions 14209 * considered as a valid potentially constant expressions
14178 * @param argumentList the argument list to validate 14210 * @param argumentList the argument list to validate
14179 */ 14211 */
(...skipping 25 matching lines...) Expand all
14205 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 14237 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
14206 } 14238 }
14207 if (initializer is SuperConstructorInvocation) { 14239 if (initializer is SuperConstructorInvocation) {
14208 SuperConstructorInvocation invocation = initializer as SuperConstructorI nvocation; 14240 SuperConstructorInvocation invocation = initializer as SuperConstructorI nvocation;
14209 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 14241 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
14210 } 14242 }
14211 } 14243 }
14212 } 14244 }
14213 } 14245 }
14214 14246
14215 class ConstantVisitor_14 extends ConstantVisitor { 14247 class ConstantVisitor_13 extends ConstantVisitor {
14216 final ConstantVerifier ConstantVerifier_this; 14248 final ConstantVerifier ConstantVerifier_this;
14217 14249
14218 List<ParameterElement> parameterElements; 14250 List<ParameterElement> parameterElements;
14219 14251
14220 ConstantVisitor_14(this.ConstantVerifier_this, this.parameterElements) : super (); 14252 ConstantVisitor_13(this.ConstantVerifier_this, this.parameterElements) : super ();
14221 14253
14222 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { 14254 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) {
14223 Element element = node.staticElement; 14255 Element element = node.staticElement;
14224 for (ParameterElement parameterElement in parameterElements) { 14256 for (ParameterElement parameterElement in parameterElements) {
14225 if (identical(parameterElement, element) && parameterElement != null) { 14257 if (identical(parameterElement, element) && parameterElement != null) {
14226 Type2 type = parameterElement.type; 14258 Type2 type = parameterElement.type;
14227 if (type != null) { 14259 if (type != null) {
14228 if (type.isDynamic) { 14260 if (type.isDynamic) {
14229 return ValidResult.RESULT_DYNAMIC; 14261 return ValidResult.RESULT_DYNAMIC;
14230 } 14262 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
14279 * The object providing access to the types defined by the language. 14311 * The object providing access to the types defined by the language.
14280 */ 14312 */
14281 TypeProvider _typeProvider; 14313 TypeProvider _typeProvider;
14282 14314
14283 /** 14315 /**
14284 * The manager for the inheritance mappings. 14316 * The manager for the inheritance mappings.
14285 */ 14317 */
14286 InheritanceManager _inheritanceManager; 14318 InheritanceManager _inheritanceManager;
14287 14319
14288 /** 14320 /**
14289 * A flag indicating whether we are running in strict mode. In strict mode, er ror reporting is
14290 * based exclusively on the static type information.
14291 */
14292 bool _strictMode = false;
14293
14294 /**
14295 * This is set to `true` iff the visitor is currently visiting children nodes of a 14321 * This is set to `true` iff the visitor is currently visiting children nodes of a
14296 * [ConstructorDeclaration] and the constructor is 'const'. 14322 * [ConstructorDeclaration] and the constructor is 'const'.
14297 * 14323 *
14298 * @see #visitConstructorDeclaration(ConstructorDeclaration) 14324 * @see #visitConstructorDeclaration(ConstructorDeclaration)
14299 */ 14325 */
14300 bool _isEnclosingConstructorConst = false; 14326 bool _isEnclosingConstructorConst = false;
14301 14327
14302 /** 14328 /**
14303 * This is set to `true` iff the visitor is currently visiting children nodes of a 14329 * This is set to `true` iff the visitor is currently visiting children nodes of a
14304 * [CatchClause]. 14330 * [CatchClause].
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
14432 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. 14458 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes.
14433 */ 14459 */
14434 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 14460 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
14435 14461
14436 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider, InheritanceManager inheritanceManager) { 14462 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider, InheritanceManager inheritanceManager) {
14437 this._errorReporter = errorReporter; 14463 this._errorReporter = errorReporter;
14438 this._currentLibrary = currentLibrary; 14464 this._currentLibrary = currentLibrary;
14439 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; 14465 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary;
14440 this._typeProvider = typeProvider; 14466 this._typeProvider = typeProvider;
14441 this._inheritanceManager = inheritanceManager; 14467 this._inheritanceManager = inheritanceManager;
14442 _strictMode = currentLibrary.context.analysisOptions.strictMode;
14443 _isEnclosingConstructorConst = false; 14468 _isEnclosingConstructorConst = false;
14444 _isInCatchClause = false; 14469 _isInCatchClause = false;
14445 _isInStaticVariableDeclaration = false; 14470 _isInStaticVariableDeclaration = false;
14446 _isInInstanceVariableDeclaration = false; 14471 _isInInstanceVariableDeclaration = false;
14447 _isInInstanceVariableInitializer = false; 14472 _isInInstanceVariableInitializer = false;
14448 _isInConstructorInitializer = false; 14473 _isInConstructorInitializer = false;
14449 _isInStaticMethod = false; 14474 _isInStaticMethod = false;
14450 _boolType = typeProvider.boolType; 14475 _boolType = typeProvider.boolType;
14451 _dynamicType = typeProvider.dynamicType; 14476 _dynamicType = typeProvider.dynamicType;
14452 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ 14477 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
14986 checkForTypeParameterSupertypeOfItsBound(node); 15011 checkForTypeParameterSupertypeOfItsBound(node);
14987 return super.visitTypeParameter(node); 15012 return super.visitTypeParameter(node);
14988 } 15013 }
14989 15014
14990 Object visitVariableDeclaration(VariableDeclaration node) { 15015 Object visitVariableDeclaration(VariableDeclaration node) {
14991 SimpleIdentifier nameNode = node.name; 15016 SimpleIdentifier nameNode = node.name;
14992 Expression initializerNode = node.initializer; 15017 Expression initializerNode = node.initializer;
14993 checkForInvalidAssignment2(nameNode, initializerNode); 15018 checkForInvalidAssignment2(nameNode, initializerNode);
14994 nameNode.accept(this); 15019 nameNode.accept(this);
14995 String name = nameNode.name; 15020 String name = nameNode.name;
14996 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); 15021 _namesForReferenceToDeclaredVariableInInitializer.add(name);
14997 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; 15022 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration;
14998 try { 15023 try {
14999 if (initializerNode != null) { 15024 if (initializerNode != null) {
15000 initializerNode.accept(this); 15025 initializerNode.accept(this);
15001 } 15026 }
15002 } finally { 15027 } finally {
15003 _isInInstanceVariableInitializer = false; 15028 _isInInstanceVariableInitializer = false;
15004 _namesForReferenceToDeclaredVariableInInitializer.remove(name); 15029 _namesForReferenceToDeclaredVariableInInitializer.remove(name);
15005 } 15030 }
15006 return null; 15031 return null;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
15153 PropertyAccessorElement accessorElement = executableElement as PropertyAcc essorElement; 15178 PropertyAccessorElement accessorElement = executableElement as PropertyAcc essorElement;
15154 isGetter = accessorElement.isGetter; 15179 isGetter = accessorElement.isGetter;
15155 isSetter = accessorElement.isSetter; 15180 isSetter = accessorElement.isSetter;
15156 } 15181 }
15157 if (overriddenExecutable == null) { 15182 if (overriddenExecutable == null) {
15158 if (!isGetter && !isSetter && !executableElement.isOperator) { 15183 if (!isGetter && !isSetter && !executableElement.isOperator) {
15159 Set<ClassElement> visitedClasses = new Set<ClassElement>(); 15184 Set<ClassElement> visitedClasses = new Set<ClassElement>();
15160 InterfaceType superclassType = _enclosingClass.supertype; 15185 InterfaceType superclassType = _enclosingClass.supertype;
15161 ClassElement superclassElement = superclassType == null ? null : supercl assType.element; 15186 ClassElement superclassElement = superclassType == null ? null : supercl assType.element;
15162 while (superclassElement != null && !visitedClasses.contains(superclassE lement)) { 15187 while (superclassElement != null && !visitedClasses.contains(superclassE lement)) {
15163 javaSetAdd(visitedClasses, superclassElement); 15188 visitedClasses.add(superclassElement);
15164 LibraryElement superclassLibrary = superclassElement.library; 15189 LibraryElement superclassLibrary = superclassElement.library;
15165 List<FieldElement> fieldElts = superclassElement.fields; 15190 List<FieldElement> fieldElts = superclassElement.fields;
15166 for (FieldElement fieldElt in fieldElts) { 15191 for (FieldElement fieldElt in fieldElts) {
15167 if (fieldElt.name != executableElementName) { 15192 if (fieldElt.name != executableElementName) {
15168 continue; 15193 continue;
15169 } 15194 }
15170 if (executableElementPrivate && _currentLibrary != superclassLibrary ) { 15195 if (executableElementPrivate && _currentLibrary != superclassLibrary ) {
15171 continue; 15196 continue;
15172 } 15197 }
15173 if (fieldElt.isStatic) { 15198 if (fieldElt.isStatic) {
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
15643 * @param expectedPropagatedType the expected propagated type of the parameter , may be 15668 * @param expectedPropagatedType the expected propagated type of the parameter , may be
15644 * `null` 15669 * `null`
15645 * @param actualPropagatedType the expected propagated type of the parameter, may be `null` 15670 * @param actualPropagatedType the expected propagated type of the parameter, may be `null`
15646 * @return `true` if and only if an error code is generated on the passed node 15671 * @return `true` if and only if an error code is generated on the passed node
15647 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE 15672 * @see StaticWarningCode#ARGUMENT_TYPE_NOT_ASSIGNABLE
15648 */ 15673 */
15649 bool checkForArgumentTypeNotAssignable4(Expression expression, Type2 expectedS taticType, Type2 actualStaticType, Type2 expectedPropagatedType, Type2 actualPro pagatedType, ErrorCode errorCode) { 15674 bool checkForArgumentTypeNotAssignable4(Expression expression, Type2 expectedS taticType, Type2 actualStaticType, Type2 expectedPropagatedType, Type2 actualPro pagatedType, ErrorCode errorCode) {
15650 if (actualStaticType == null || expectedStaticType == null) { 15675 if (actualStaticType == null || expectedStaticType == null) {
15651 return false; 15676 return false;
15652 } 15677 }
15653 if (_strictMode) { 15678 if (actualStaticType.isAssignableTo(expectedStaticType)) {
15654 if (actualStaticType.isAssignableTo(expectedStaticType)) {
15655 return false;
15656 }
15657 _errorReporter.reportError2(errorCode, expression, [
15658 actualStaticType.displayName,
15659 expectedStaticType.displayName]);
15660 return true;
15661 }
15662 if (actualPropagatedType == null || expectedPropagatedType == null) {
15663 if (actualStaticType.isAssignableTo(expectedStaticType)) {
15664 return false;
15665 }
15666 _errorReporter.reportError2(errorCode, expression, [
15667 actualStaticType.displayName,
15668 expectedStaticType.displayName]);
15669 return true;
15670 }
15671 if (actualStaticType.isAssignableTo(expectedStaticType) || actualStaticType. isAssignableTo(expectedPropagatedType) || actualPropagatedType.isAssignableTo(ex pectedStaticType) || actualPropagatedType.isAssignableTo(expectedPropagatedType) ) {
15672 return false; 15679 return false;
15673 } 15680 }
15674 _errorReporter.reportError2(errorCode, expression, [ 15681 _errorReporter.reportError2(errorCode, expression, [
15675 (actualPropagatedType == null ? actualStaticType : actualPropagatedType) .displayName, 15682 actualStaticType.displayName,
15676 (expectedPropagatedType == null ? expectedStaticType : expectedPropagate dType).displayName]); 15683 expectedStaticType.displayName]);
15677 return true; 15684 return true;
15678 } 15685 }
15679 15686
15680 /** 15687 /**
15681 * This verifies that left hand side of the passed assignment expression is no t final. 15688 * This verifies that left hand side of the passed assignment expression is no t final.
15682 * 15689 *
15683 * @param node the assignment expression to evaluate 15690 * @param node the assignment expression to evaluate
15684 * @return `true` if and only if an error code is generated on the passed node 15691 * @return `true` if and only if an error code is generated on the passed node
15685 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL 15692 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL
15686 */ 15693 */
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
16621 Expression expression = node.expression; 16628 Expression expression = node.expression;
16622 if (expression == null) { 16629 if (expression == null) {
16623 return false; 16630 return false;
16624 } 16631 }
16625 Type2 staticType = getStaticType(expression); 16632 Type2 staticType = getStaticType(expression);
16626 if (staticType == null) { 16633 if (staticType == null) {
16627 return false; 16634 return false;
16628 } 16635 }
16629 if (staticType.isAssignableTo(fieldType)) { 16636 if (staticType.isAssignableTo(fieldType)) {
16630 return false; 16637 return false;
16631 } else if (_strictMode) {
16632 if (_isEnclosingConstructorConst) {
16633 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER _NOT_ASSIGNABLE, expression, [staticType.displayName, fieldType.displayName]);
16634 } else {
16635 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSI GNABLE, expression, [staticType.displayName, fieldType.displayName]);
16636 }
16637 return true;
16638 }
16639 Type2 propagatedType = expression.propagatedType;
16640 if (propagatedType != null && propagatedType.isAssignableTo(fieldType)) {
16641 return false;
16642 } 16638 }
16643 if (_isEnclosingConstructorConst) { 16639 if (_isEnclosingConstructorConst) {
16644 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N OT_ASSIGNABLE, expression, [ 16640 _errorReporter.reportError2(CompileTimeErrorCode.CONST_FIELD_INITIALIZER_N OT_ASSIGNABLE, expression, [staticType.displayName, fieldType.displayName]);
16645 (propagatedType == null ? staticType : propagatedType).displayName,
16646 fieldType.displayName]);
16647 } else { 16641 } else {
16648 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN ABLE, expression, [ 16642 _errorReporter.reportError2(StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGN ABLE, expression, [staticType.displayName, fieldType.displayName]);
16649 (propagatedType == null ? staticType : propagatedType).displayName,
16650 fieldType.displayName]);
16651 } 16643 }
16652 return true; 16644 return true;
16653 } 16645 }
16654 16646
16655 /** 16647 /**
16656 * This verifies that the passed field formal parameter is in a constructor de claration. 16648 * This verifies that the passed field formal parameter is in a constructor de claration.
16657 * 16649 *
16658 * @param node the field formal parameter to test 16650 * @param node the field formal parameter to test
16659 * @return `true` if and only if an error code is generated on the passed node 16651 * @return `true` if and only if an error code is generated on the passed node
16660 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR 16652 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
17016 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 17008 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
17017 */ 17009 */
17018 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) { 17010 bool checkForInvalidAssignment2(Expression lhs, Expression rhs) {
17019 if (lhs == null || rhs == null) { 17011 if (lhs == null || rhs == null) {
17020 return false; 17012 return false;
17021 } 17013 }
17022 VariableElement leftElement = getVariableElement(lhs); 17014 VariableElement leftElement = getVariableElement(lhs);
17023 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty pe; 17015 Type2 leftType = (leftElement == null) ? getStaticType(lhs) : leftElement.ty pe;
17024 Type2 staticRightType = getStaticType(rhs); 17016 Type2 staticRightType = getStaticType(rhs);
17025 bool isStaticAssignable = staticRightType.isAssignableTo(leftType); 17017 bool isStaticAssignable = staticRightType.isAssignableTo(leftType);
17026 Type2 propagatedRightType = rhs.propagatedType; 17018 if (!isStaticAssignable) {
17027 if (_strictMode || propagatedRightType == null) { 17019 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [staticRightType.displayName, leftType.displayName]);
17028 if (!isStaticAssignable) { 17020 return true;
17029 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh s, [staticRightType.displayName, leftType.displayName]);
17030 return true;
17031 }
17032 } else {
17033 bool isPropagatedAssignable = propagatedRightType.isAssignableTo(leftType) ;
17034 if (!isStaticAssignable && !isPropagatedAssignable) {
17035 _errorReporter.reportError2(StaticTypeWarningCode.INVALID_ASSIGNMENT, rh s, [staticRightType.displayName, leftType.displayName]);
17036 return true;
17037 }
17038 } 17021 }
17039 return false; 17022 return false;
17040 } 17023 }
17041 17024
17042 /** 17025 /**
17043 * This verifies that the usage of the passed 'this' is valid. 17026 * This verifies that the usage of the passed 'this' is valid.
17044 * 17027 *
17045 * @param node the 'this' expression to evaluate 17028 * @param node the 'this' expression to evaluate
17046 * @return `true` if and only if an error code is generated on the passed node 17029 * @return `true` if and only if an error code is generated on the passed node
17047 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS 17030 * @see CompileTimeErrorCode#INVALID_REFERENCE_TO_THIS
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
17427 return false; 17410 return false;
17428 } 17411 }
17429 List<MethodElement> methods = _enclosingClass.methods; 17412 List<MethodElement> methods = _enclosingClass.methods;
17430 List<PropertyAccessorElement> accessors = _enclosingClass.accessors; 17413 List<PropertyAccessorElement> accessors = _enclosingClass.accessors;
17431 Set<String> methodsInEnclosingClass = new Set<String>(); 17414 Set<String> methodsInEnclosingClass = new Set<String>();
17432 for (MethodElement method in methods) { 17415 for (MethodElement method in methods) {
17433 String methodName = method.name; 17416 String methodName = method.name;
17434 if (methodName == ElementResolver.NO_SUCH_METHOD_METHOD_NAME) { 17417 if (methodName == ElementResolver.NO_SUCH_METHOD_METHOD_NAME) {
17435 return false; 17418 return false;
17436 } 17419 }
17437 javaSetAdd(methodsInEnclosingClass, methodName); 17420 methodsInEnclosingClass.add(methodName);
17438 } 17421 }
17439 Set<String> accessorsInEnclosingClass = new Set<String>(); 17422 Set<String> accessorsInEnclosingClass = new Set<String>();
17440 for (PropertyAccessorElement accessor in accessors) { 17423 for (PropertyAccessorElement accessor in accessors) {
17441 javaSetAdd(accessorsInEnclosingClass, accessor.name); 17424 accessorsInEnclosingClass.add(accessor.name);
17442 } 17425 }
17443 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>(); 17426 Set<ExecutableElement> missingOverrides = new Set<ExecutableElement>();
17444 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass); 17427 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass);
17445 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass); 17428 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass);
17446 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) { 17429 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) {
17447 String memberName = membersInheritedFromInterfaces.getKey(i); 17430 String memberName = membersInheritedFromInterfaces.getKey(i);
17448 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i); 17431 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i);
17449 if (memberName == null) { 17432 if (memberName == null) {
17450 break; 17433 break;
17451 } 17434 }
17452 ExecutableElement elt = membersInheritedFromSuperclasses.get(executableElt .name); 17435 ExecutableElement elt = membersInheritedFromSuperclasses.get(executableElt .name);
17453 if (elt != null) { 17436 if (elt != null) {
17454 if (elt is MethodElement && !(elt as MethodElement).isAbstract) { 17437 if (elt is MethodElement && !(elt as MethodElement).isAbstract) {
17455 continue; 17438 continue;
17456 } else if (elt is PropertyAccessorElement && !(elt as PropertyAccessorEl ement).isAbstract) { 17439 } else if (elt is PropertyAccessorElement && !(elt as PropertyAccessorEl ement).isAbstract) {
17457 continue; 17440 continue;
17458 } 17441 }
17459 } 17442 }
17460 if (executableElt is MethodElement) { 17443 if (executableElt is MethodElement) {
17461 if (!methodsInEnclosingClass.contains(memberName) && !memberHasConcreteM ethodImplementationInSuperclassChain(_enclosingClass, memberName, new List<Class Element>())) { 17444 if (!methodsInEnclosingClass.contains(memberName) && !memberHasConcreteM ethodImplementationInSuperclassChain(_enclosingClass, memberName, new List<Class Element>())) {
17462 javaSetAdd(missingOverrides, executableElt); 17445 missingOverrides.add(executableElt);
17463 } 17446 }
17464 } else if (executableElt is PropertyAccessorElement) { 17447 } else if (executableElt is PropertyAccessorElement) {
17465 if (!accessorsInEnclosingClass.contains(memberName) && !memberHasConcret eAccessorImplementationInSuperclassChain(_enclosingClass, memberName, new List<C lassElement>())) { 17448 if (!accessorsInEnclosingClass.contains(memberName) && !memberHasConcret eAccessorImplementationInSuperclassChain(_enclosingClass, memberName, new List<C lassElement>())) {
17466 javaSetAdd(missingOverrides, executableElt); 17449 missingOverrides.add(executableElt);
17467 } 17450 }
17468 } 17451 }
17469 } 17452 }
17470 int missingOverridesSize = missingOverrides.length; 17453 int missingOverridesSize = missingOverrides.length;
17471 if (missingOverridesSize == 0) { 17454 if (missingOverridesSize == 0) {
17472 return false; 17455 return false;
17473 } 17456 }
17474 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid es); 17457 List<ExecutableElement> missingOverridesArray = new List.from(missingOverrid es);
17475 List<String> stringMembersArrayListSet = new List<String>(); 17458 List<String> stringMembersArrayListSet = new List<String>();
17476 for (int i = 0; i < missingOverridesArray.length; i++) { 17459 for (int i = 0; i < missingOverridesArray.length; i++) {
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
17924 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) { 17907 if (staticReturnType.isVoid || staticReturnType.isDynamic || staticReturnT ype.isBottom) {
17925 return false; 17908 return false;
17926 } 17909 }
17927 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ 17910 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [
17928 staticReturnType.displayName, 17911 staticReturnType.displayName,
17929 expectedReturnType.displayName, 17912 expectedReturnType.displayName,
17930 _enclosingFunction.displayName]); 17913 _enclosingFunction.displayName]);
17931 return true; 17914 return true;
17932 } 17915 }
17933 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType ); 17916 bool isStaticAssignable = staticReturnType.isAssignableTo(expectedReturnType );
17934 Type2 propagatedReturnType = returnExpression.propagatedType; 17917 if (isStaticAssignable) {
17935 if (_strictMode || propagatedReturnType == null) { 17918 return false;
17936 if (isStaticAssignable) {
17937 return false;
17938 }
17939 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [
17940 staticReturnType.displayName,
17941 expectedReturnType.displayName,
17942 _enclosingFunction.displayName]);
17943 return true;
17944 } else {
17945 bool isPropagatedAssignable = propagatedReturnType.isAssignableTo(expected ReturnType);
17946 if (isStaticAssignable || isPropagatedAssignable) {
17947 return false;
17948 }
17949 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [
17950 staticReturnType.displayName,
17951 expectedReturnType.displayName,
17952 _enclosingFunction.displayName]);
17953 return true;
17954 } 17919 }
17920 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, re turnExpression, [
17921 staticReturnType.displayName,
17922 expectedReturnType.displayName,
17923 _enclosingFunction.displayName]);
17924 return true;
17955 } 17925 }
17956 17926
17957 /** 17927 /**
17958 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance 17928 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance
17959 * member. 17929 * member.
17960 * 17930 *
17961 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression, 17931 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression,
17962 * or `null`, aka, the class element of 'C' in 'C.x', see 17932 * or `null`, aka, the class element of 'C' in 'C.x', see
17963 * [getTypeReference] 17933 * [getTypeReference]
17964 * @param name the accessed name to evaluate 17934 * @param name the accessed name to evaluate
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
18387 /** 18357 /**
18388 * @return `true` if the given constructor redirects to itself, directly or in directly 18358 * @return `true` if the given constructor redirects to itself, directly or in directly
18389 */ 18359 */
18390 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) { 18360 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) {
18391 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); 18361 Set<ConstructorElement> constructors = new Set<ConstructorElement>();
18392 ConstructorElement current = element; 18362 ConstructorElement current = element;
18393 while (current != null) { 18363 while (current != null) {
18394 if (constructors.contains(current)) { 18364 if (constructors.contains(current)) {
18395 return identical(current, element); 18365 return identical(current, element);
18396 } 18366 }
18397 javaSetAdd(constructors, current); 18367 constructors.add(current);
18398 current = current.redirectedConstructor; 18368 current = current.redirectedConstructor;
18399 if (current is ConstructorMember) { 18369 if (current is ConstructorMember) {
18400 current = (current as ConstructorMember).baseElement; 18370 current = (current as ConstructorMember).baseElement;
18401 } 18371 }
18402 } 18372 }
18403 return false; 18373 return false;
18404 } 18374 }
18405 18375
18406 /** 18376 /**
18407 * @return <code>true</code> if given [Element] has direct or indirect referen ce to itself 18377 * @return <code>true</code> if given [Element] has direct or indirect referen ce to itself
(...skipping 16 matching lines...) Expand all
18424 firstIteration = false; 18394 firstIteration = false;
18425 break; 18395 break;
18426 } else { 18396 } else {
18427 return true; 18397 return true;
18428 } 18398 }
18429 } 18399 }
18430 if (current != null && !checked.contains(current)) { 18400 if (current != null && !checked.contains(current)) {
18431 break; 18401 break;
18432 } 18402 }
18433 } 18403 }
18434 current.accept(new GeneralizingElementVisitor_15(target, toCheck)); 18404 current.accept(new GeneralizingElementVisitor_14(target, toCheck));
18435 javaSetAdd(checked, current); 18405 checked.add(current);
18436 } 18406 }
18437 } 18407 }
18438 18408
18439 /** 18409 /**
18440 * @return `true` if given [Type] implements operator <i>==</i>, and it is not 18410 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
18441 * <i>int</i> or <i>String</i>. 18411 * <i>int</i> or <i>String</i>.
18442 */ 18412 */
18443 bool implementsEqualsWhenNotAllowed(Type2 type) { 18413 bool implementsEqualsWhenNotAllowed(Type2 type) {
18444 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) { 18414 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) {
18445 return false; 18415 return false;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
18634 18604
18635 static final List<INIT_STATE> values = [ 18605 static final List<INIT_STATE> values = [
18636 NOT_INIT, 18606 NOT_INIT,
18637 INIT_IN_DECLARATION, 18607 INIT_IN_DECLARATION,
18638 INIT_IN_FIELD_FORMAL, 18608 INIT_IN_FIELD_FORMAL,
18639 INIT_IN_INITIALIZERS]; 18609 INIT_IN_INITIALIZERS];
18640 18610
18641 INIT_STATE(String name, int ordinal) : super(name, ordinal); 18611 INIT_STATE(String name, int ordinal) : super(name, ordinal);
18642 } 18612 }
18643 18613
18644 class GeneralizingElementVisitor_15 extends GeneralizingElementVisitor<Object> { 18614 class GeneralizingElementVisitor_14 extends GeneralizingElementVisitor<Object> {
18645 Element target; 18615 Element target;
18646 18616
18647 List<Element> toCheck; 18617 List<Element> toCheck;
18648 18618
18649 GeneralizingElementVisitor_15(this.target, this.toCheck) : super(); 18619 GeneralizingElementVisitor_14(this.target, this.toCheck) : super();
18650 18620
18651 bool _inClass = false; 18621 bool _inClass = false;
18652 18622
18653 Object visitClassElement(ClassElement element) { 18623 Object visitClassElement(ClassElement element) {
18654 addTypeToCheck(element.supertype); 18624 addTypeToCheck(element.supertype);
18655 for (InterfaceType mixin in element.mixins) { 18625 for (InterfaceType mixin in element.mixins) {
18656 addTypeToCheck(mixin); 18626 addTypeToCheck(mixin);
18657 } 18627 }
18658 _inClass = !element.isTypedef; 18628 _inClass = !element.isTypedef;
18659 try { 18629 try {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
18770 } 18740 }
18771 18741
18772 String get correction => correction9; 18742 String get correction => correction9;
18773 18743
18774 ErrorSeverity get errorSeverity => _type.severity; 18744 ErrorSeverity get errorSeverity => _type.severity;
18775 18745
18776 String get message => _message; 18746 String get message => _message;
18777 18747
18778 ErrorType get type => _type; 18748 ErrorType get type => _type;
18779 } 18749 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698