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

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

Issue 68233003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 library engine.resolver; 4 library engine.resolver;
5
4 import 'dart:collection'; 6 import 'dart:collection';
5 import 'java_core.dart'; 7 import 'java_core.dart';
6 import 'java_engine.dart'; 8 import 'java_engine.dart';
7 import 'instrumentation.dart'; 9 import 'instrumentation.dart';
8 import 'source.dart'; 10 import 'source.dart';
9 import 'error.dart'; 11 import 'error.dart';
10 import 'scanner.dart' as sc; 12 import 'scanner.dart' as sc;
11 import 'utilities_dart.dart'; 13 import 'utilities_dart.dart';
12 import 'utilities_general.dart'; 14 import 'utilities_general.dart';
13 import 'ast.dart'; 15 import 'ast.dart';
14 import 'parser.dart' show Parser, ParserErrorCode; 16 import 'parser.dart' show Parser, ParserErrorCode;
15 import 'sdk.dart' show DartSdk, SdkLibrary; 17 import 'sdk.dart' show DartSdk, SdkLibrary;
16 import 'element.dart'; 18 import 'element.dart';
17 import 'html.dart' as ht; 19 import 'html.dart' as ht;
18 import 'engine.dart'; 20 import 'engine.dart';
19 import 'constant.dart'; 21 import 'constant.dart';
22
20 /** 23 /**
21 * Instances of the class `CompilationUnitBuilder` build an element model for a single 24 * Instances of the class `CompilationUnitBuilder` build an element model for a single
22 * compilation unit. 25 * compilation unit.
23 * 26 *
24 * @coverage dart.engine.resolver 27 * @coverage dart.engine.resolver
25 */ 28 */
26 class CompilationUnitBuilder { 29 class CompilationUnitBuilder {
27
28 /** 30 /**
29 * Build the compilation unit element for the given source. 31 * Build the compilation unit element for the given source.
30 * 32 *
31 * @param source the source describing the compilation unit 33 * @param source the source describing the compilation unit
32 * @param unit the AST structure representing the compilation unit 34 * @param unit the AST structure representing the compilation unit
33 * @return the compilation unit element that was built 35 * @return the compilation unit element that was built
34 * @throws AnalysisException if the analysis could not be performed 36 * @throws AnalysisException if the analysis could not be performed
35 */ 37 */
36 CompilationUnitElementImpl buildCompilationUnit(Source source, CompilationUnit unit) { 38 CompilationUnitElementImpl buildCompilationUnit(Source source, CompilationUnit unit) {
37 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art(); 39 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
(...skipping 11 matching lines...) Expand all
49 element.typeAliases = holder.typeAliases; 51 element.typeAliases = holder.typeAliases;
50 element.types = holder.types; 52 element.types = holder.types;
51 element.topLevelVariables = holder.topLevelVariables; 53 element.topLevelVariables = holder.topLevelVariables;
52 unit.element = element; 54 unit.element = element;
53 return element; 55 return element;
54 } finally { 56 } finally {
55 timeCounter.stop(); 57 timeCounter.stop();
56 } 58 }
57 } 59 }
58 } 60 }
61
59 /** 62 /**
60 * Instances of the class `ElementBuilder` traverse an AST structure and build t he element 63 * Instances of the class `ElementBuilder` traverse an AST structure and build t he element
61 * model representing the AST structure. 64 * model representing the AST structure.
62 * 65 *
63 * @coverage dart.engine.resolver 66 * @coverage dart.engine.resolver
64 */ 67 */
65 class ElementBuilder extends RecursiveASTVisitor<Object> { 68 class ElementBuilder extends RecursiveASTVisitor<Object> {
66
67 /** 69 /**
68 * The element holder associated with the element that is currently being buil t. 70 * The element holder associated with the element that is currently being buil t.
69 */ 71 */
70 ElementHolder _currentHolder; 72 ElementHolder _currentHolder;
71 73
72 /** 74 /**
73 * A flag indicating whether a variable declaration is in the context of a fie ld declaration. 75 * A flag indicating whether a variable declaration is in the context of a fie ld declaration.
74 */ 76 */
75 bool _inFieldContext = false; 77 bool _inFieldContext = false;
76 78
(...skipping 15 matching lines...) Expand all
92 List<FunctionTypeImpl> _functionTypesToFix = null; 94 List<FunctionTypeImpl> _functionTypesToFix = null;
93 95
94 /** 96 /**
95 * Initialize a newly created element builder to build the elements for a comp ilation unit. 97 * Initialize a newly created element builder to build the elements for a comp ilation unit.
96 * 98 *
97 * @param initialHolder the element holder associated with the compilation uni t being built 99 * @param initialHolder the element holder associated with the compilation uni t being built
98 */ 100 */
99 ElementBuilder(ElementHolder initialHolder) { 101 ElementBuilder(ElementHolder initialHolder) {
100 _currentHolder = initialHolder; 102 _currentHolder = initialHolder;
101 } 103 }
104
102 Object visitBlock(Block node) { 105 Object visitBlock(Block node) {
103 bool wasInField = _inFieldContext; 106 bool wasInField = _inFieldContext;
104 _inFieldContext = false; 107 _inFieldContext = false;
105 try { 108 try {
106 node.visitChildren(this); 109 node.visitChildren(this);
107 } finally { 110 } finally {
108 _inFieldContext = wasInField; 111 _inFieldContext = wasInField;
109 } 112 }
110 return null; 113 return null;
111 } 114 }
115
112 Object visitCatchClause(CatchClause node) { 116 Object visitCatchClause(CatchClause node) {
113 SimpleIdentifier exceptionParameter = node.exceptionParameter; 117 SimpleIdentifier exceptionParameter = node.exceptionParameter;
114 if (exceptionParameter != null) { 118 if (exceptionParameter != null) {
115 LocalVariableElementImpl exception = new LocalVariableElementImpl(exceptio nParameter); 119 LocalVariableElementImpl exception = new LocalVariableElementImpl(exceptio nParameter);
116 _currentHolder.addLocalVariable(exception); 120 _currentHolder.addLocalVariable(exception);
117 exceptionParameter.staticElement = exception; 121 exceptionParameter.staticElement = exception;
118 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; 122 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
119 if (stackTraceParameter != null) { 123 if (stackTraceParameter != null) {
120 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack TraceParameter); 124 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack TraceParameter);
121 _currentHolder.addLocalVariable(stackTrace); 125 _currentHolder.addLocalVariable(stackTrace);
122 stackTraceParameter.staticElement = stackTrace; 126 stackTraceParameter.staticElement = stackTrace;
123 } 127 }
124 } 128 }
125 return super.visitCatchClause(node); 129 return super.visitCatchClause(node);
126 } 130 }
131
127 Object visitClassDeclaration(ClassDeclaration node) { 132 Object visitClassDeclaration(ClassDeclaration node) {
128 ElementHolder holder = new ElementHolder(); 133 ElementHolder holder = new ElementHolder();
129 _isValidMixin = true; 134 _isValidMixin = true;
130 _functionTypesToFix = new List<FunctionTypeImpl>(); 135 _functionTypesToFix = new List<FunctionTypeImpl>();
131 visitChildren(holder, node); 136 visitChildren(holder, node);
132 SimpleIdentifier className = node.name; 137 SimpleIdentifier className = node.name;
133 ClassElementImpl element = new ClassElementImpl(className); 138 ClassElementImpl element = new ClassElementImpl(className);
134 List<TypeParameterElement> typeParameters = holder.typeParameters; 139 List<TypeParameterElement> typeParameters = holder.typeParameters;
135 List<Type2> typeArguments = createTypeParameterTypes(typeParameters); 140 List<Type2> typeArguments = createTypeParameterTypes(typeParameters);
136 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 141 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
(...skipping 12 matching lines...) Expand all
149 element.validMixin = _isValidMixin; 154 element.validMixin = _isValidMixin;
150 for (FunctionTypeImpl functionType in _functionTypesToFix) { 155 for (FunctionTypeImpl functionType in _functionTypesToFix) {
151 functionType.typeArguments = typeArguments; 156 functionType.typeArguments = typeArguments;
152 } 157 }
153 _functionTypesToFix = null; 158 _functionTypesToFix = null;
154 _currentHolder.addType(element); 159 _currentHolder.addType(element);
155 className.staticElement = element; 160 className.staticElement = element;
156 holder.validate(); 161 holder.validate();
157 return null; 162 return null;
158 } 163 }
164
159 Object visitClassTypeAlias(ClassTypeAlias node) { 165 Object visitClassTypeAlias(ClassTypeAlias node) {
160 ElementHolder holder = new ElementHolder(); 166 ElementHolder holder = new ElementHolder();
161 _functionTypesToFix = new List<FunctionTypeImpl>(); 167 _functionTypesToFix = new List<FunctionTypeImpl>();
162 visitChildren(holder, node); 168 visitChildren(holder, node);
163 SimpleIdentifier className = node.name; 169 SimpleIdentifier className = node.name;
164 ClassElementImpl element = new ClassElementImpl(className); 170 ClassElementImpl element = new ClassElementImpl(className);
165 element.abstract = node.abstractKeyword != null; 171 element.abstract = node.abstractKeyword != null;
166 element.typedef = true; 172 element.typedef = true;
167 List<TypeParameterElement> typeParameters = holder.typeParameters; 173 List<TypeParameterElement> typeParameters = holder.typeParameters;
168 element.typeParameters = typeParameters; 174 element.typeParameters = typeParameters;
169 List<Type2> typeArguments = createTypeParameterTypes(typeParameters); 175 List<Type2> typeArguments = createTypeParameterTypes(typeParameters);
170 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 176 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
171 interfaceType.typeArguments = typeArguments; 177 interfaceType.typeArguments = typeArguments;
172 element.type = interfaceType; 178 element.type = interfaceType;
173 element.constructors = createDefaultConstructors(interfaceType); 179 element.constructors = createDefaultConstructors(interfaceType);
174 for (FunctionTypeImpl functionType in _functionTypesToFix) { 180 for (FunctionTypeImpl functionType in _functionTypesToFix) {
175 functionType.typeArguments = typeArguments; 181 functionType.typeArguments = typeArguments;
176 } 182 }
177 _functionTypesToFix = null; 183 _functionTypesToFix = null;
178 _currentHolder.addType(element); 184 _currentHolder.addType(element);
179 className.staticElement = element; 185 className.staticElement = element;
180 holder.validate(); 186 holder.validate();
181 return null; 187 return null;
182 } 188 }
189
183 Object visitConstructorDeclaration(ConstructorDeclaration node) { 190 Object visitConstructorDeclaration(ConstructorDeclaration node) {
184 _isValidMixin = false; 191 _isValidMixin = false;
185 ElementHolder holder = new ElementHolder(); 192 ElementHolder holder = new ElementHolder();
186 bool wasInFunction = _inFunction; 193 bool wasInFunction = _inFunction;
187 _inFunction = true; 194 _inFunction = true;
188 try { 195 try {
189 visitChildren(holder, node); 196 visitChildren(holder, node);
190 } finally { 197 } finally {
191 _inFunction = wasInFunction; 198 _inFunction = wasInFunction;
192 } 199 }
(...skipping 13 matching lines...) Expand all
206 Identifier returnType = node.returnType; 213 Identifier returnType = node.returnType;
207 if (returnType != null) { 214 if (returnType != null) {
208 element.nameOffset = returnType.offset; 215 element.nameOffset = returnType.offset;
209 } 216 }
210 } else { 217 } else {
211 constructorName.staticElement = element; 218 constructorName.staticElement = element;
212 } 219 }
213 holder.validate(); 220 holder.validate();
214 return null; 221 return null;
215 } 222 }
223
216 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 224 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
217 SimpleIdentifier variableName = node.identifier; 225 SimpleIdentifier variableName = node.identifier;
218 sc.Token keyword = node.keyword; 226 sc.Token keyword = node.keyword;
219 LocalVariableElementImpl element = new LocalVariableElementImpl(variableName ); 227 LocalVariableElementImpl element = new LocalVariableElementImpl(variableName );
220 ForEachStatement statement = node.parent as ForEachStatement; 228 ForEachStatement statement = node.parent as ForEachStatement;
221 int declarationEnd = node.offset + node.length; 229 int declarationEnd = node.offset + node.length;
222 int statementEnd = statement.offset + statement.length; 230 int statementEnd = statement.offset + statement.length;
223 element.setVisibleRange(declarationEnd, statementEnd - declarationEnd - 1); 231 element.setVisibleRange(declarationEnd, statementEnd - declarationEnd - 1);
224 element.const3 = matches(keyword, sc.Keyword.CONST); 232 element.const3 = matches(keyword, sc.Keyword.CONST);
225 element.final2 = matches(keyword, sc.Keyword.FINAL); 233 element.final2 = matches(keyword, sc.Keyword.FINAL);
226 _currentHolder.addLocalVariable(element); 234 _currentHolder.addLocalVariable(element);
227 variableName.staticElement = element; 235 variableName.staticElement = element;
228 return super.visitDeclaredIdentifier(node); 236 return super.visitDeclaredIdentifier(node);
229 } 237 }
238
230 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 239 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
231 ElementHolder holder = new ElementHolder(); 240 ElementHolder holder = new ElementHolder();
232 visit(holder, node.defaultValue); 241 visit(holder, node.defaultValue);
233 FunctionElementImpl initializer = new FunctionElementImpl(); 242 FunctionElementImpl initializer = new FunctionElementImpl();
234 initializer.functions = holder.functions; 243 initializer.functions = holder.functions;
235 initializer.labels = holder.labels; 244 initializer.labels = holder.labels;
236 initializer.localVariables = holder.localVariables; 245 initializer.localVariables = holder.localVariables;
237 initializer.parameters = holder.parameters; 246 initializer.parameters = holder.parameters;
238 SimpleIdentifier parameterName = node.parameter.identifier; 247 SimpleIdentifier parameterName = node.parameter.identifier;
239 ParameterElementImpl parameter; 248 ParameterElementImpl parameter;
(...skipping 10 matching lines...) Expand all
250 if (defaultValue != null) { 259 if (defaultValue != null) {
251 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length); 260 parameter.setDefaultValueRange(defaultValue.offset, defaultValue.length);
252 } 261 }
253 setParameterVisibleRange(node, parameter); 262 setParameterVisibleRange(node, parameter);
254 _currentHolder.addParameter(parameter); 263 _currentHolder.addParameter(parameter);
255 parameterName.staticElement = parameter; 264 parameterName.staticElement = parameter;
256 node.parameter.accept(this); 265 node.parameter.accept(this);
257 holder.validate(); 266 holder.validate();
258 return null; 267 return null;
259 } 268 }
269
260 Object visitFieldDeclaration(FieldDeclaration node) { 270 Object visitFieldDeclaration(FieldDeclaration node) {
261 bool wasInField = _inFieldContext; 271 bool wasInField = _inFieldContext;
262 _inFieldContext = true; 272 _inFieldContext = true;
263 try { 273 try {
264 node.visitChildren(this); 274 node.visitChildren(this);
265 } finally { 275 } finally {
266 _inFieldContext = wasInField; 276 _inFieldContext = wasInField;
267 } 277 }
268 return null; 278 return null;
269 } 279 }
280
270 Object visitFieldFormalParameter(FieldFormalParameter node) { 281 Object visitFieldFormalParameter(FieldFormalParameter node) {
271 if (node.parent is! DefaultFormalParameter) { 282 if (node.parent is! DefaultFormalParameter) {
272 SimpleIdentifier parameterName = node.identifier; 283 SimpleIdentifier parameterName = node.identifier;
273 FieldFormalParameterElementImpl parameter = new FieldFormalParameterElemen tImpl(parameterName); 284 FieldFormalParameterElementImpl parameter = new FieldFormalParameterElemen tImpl(parameterName);
274 parameter.const3 = node.isConst; 285 parameter.const3 = node.isConst;
275 parameter.final2 = node.isFinal; 286 parameter.final2 = node.isFinal;
276 parameter.parameterKind = node.kind; 287 parameter.parameterKind = node.kind;
277 _currentHolder.addParameter(parameter); 288 _currentHolder.addParameter(parameter);
278 parameterName.staticElement = parameter; 289 parameterName.staticElement = parameter;
279 } 290 }
280 ElementHolder holder = new ElementHolder(); 291 ElementHolder holder = new ElementHolder();
281 visitChildren(holder, node); 292 visitChildren(holder, node);
282 ((node.element as ParameterElementImpl)).parameters = holder.parameters; 293 (node.element as ParameterElementImpl).parameters = holder.parameters;
283 holder.validate(); 294 holder.validate();
284 return null; 295 return null;
285 } 296 }
297
286 Object visitFunctionDeclaration(FunctionDeclaration node) { 298 Object visitFunctionDeclaration(FunctionDeclaration node) {
287 FunctionExpression expression = node.functionExpression; 299 FunctionExpression expression = node.functionExpression;
288 if (expression != null) { 300 if (expression != null) {
289 ElementHolder holder = new ElementHolder(); 301 ElementHolder holder = new ElementHolder();
290 bool wasInFunction = _inFunction; 302 bool wasInFunction = _inFunction;
291 _inFunction = true; 303 _inFunction = true;
292 try { 304 try {
293 visitChildren(holder, expression); 305 visitChildren(holder, expression);
294 } finally { 306 } finally {
295 _inFunction = wasInFunction; 307 _inFunction = wasInFunction;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 variable.final2 = false; 363 variable.final2 = false;
352 _currentHolder.addAccessor(setter); 364 _currentHolder.addAccessor(setter);
353 expression.element = setter; 365 expression.element = setter;
354 propertyNameNode.staticElement = setter; 366 propertyNameNode.staticElement = setter;
355 } 367 }
356 } 368 }
357 holder.validate(); 369 holder.validate();
358 } 370 }
359 return null; 371 return null;
360 } 372 }
373
361 Object visitFunctionExpression(FunctionExpression node) { 374 Object visitFunctionExpression(FunctionExpression node) {
362 ElementHolder holder = new ElementHolder(); 375 ElementHolder holder = new ElementHolder();
363 bool wasInFunction = _inFunction; 376 bool wasInFunction = _inFunction;
364 _inFunction = true; 377 _inFunction = true;
365 try { 378 try {
366 visitChildren(holder, node); 379 visitChildren(holder, node);
367 } finally { 380 } finally {
368 _inFunction = wasInFunction; 381 _inFunction = wasInFunction;
369 } 382 }
370 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o ffset); 383 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o ffset);
(...skipping 12 matching lines...) Expand all
383 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 396 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
384 if (_functionTypesToFix != null) { 397 if (_functionTypesToFix != null) {
385 _functionTypesToFix.add(type); 398 _functionTypesToFix.add(type);
386 } 399 }
387 element.type = type; 400 element.type = type;
388 _currentHolder.addFunction(element); 401 _currentHolder.addFunction(element);
389 node.element = element; 402 node.element = element;
390 holder.validate(); 403 holder.validate();
391 return null; 404 return null;
392 } 405 }
406
393 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 407 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
394 ElementHolder holder = new ElementHolder(); 408 ElementHolder holder = new ElementHolder();
395 visitChildren(holder, node); 409 visitChildren(holder, node);
396 SimpleIdentifier aliasName = node.name; 410 SimpleIdentifier aliasName = node.name;
397 List<ParameterElement> parameters = holder.parameters; 411 List<ParameterElement> parameters = holder.parameters;
398 List<TypeParameterElement> typeParameters = holder.typeParameters; 412 List<TypeParameterElement> typeParameters = holder.typeParameters;
399 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia sName); 413 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia sName);
400 element.parameters = parameters; 414 element.parameters = parameters;
401 element.typeParameters = typeParameters; 415 element.typeParameters = typeParameters;
402 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); 416 FunctionTypeImpl type = new FunctionTypeImpl.con2(element);
403 type.typeArguments = createTypeParameterTypes(typeParameters); 417 type.typeArguments = createTypeParameterTypes(typeParameters);
404 element.type = type; 418 element.type = type;
405 _currentHolder.addTypeAlias(element); 419 _currentHolder.addTypeAlias(element);
406 aliasName.staticElement = element; 420 aliasName.staticElement = element;
407 holder.validate(); 421 holder.validate();
408 return null; 422 return null;
409 } 423 }
424
410 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 425 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
411 if (node.parent is! DefaultFormalParameter) { 426 if (node.parent is! DefaultFormalParameter) {
412 SimpleIdentifier parameterName = node.identifier; 427 SimpleIdentifier parameterName = node.identifier;
413 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa me); 428 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa me);
414 parameter.parameterKind = node.kind; 429 parameter.parameterKind = node.kind;
415 setParameterVisibleRange(node, parameter); 430 setParameterVisibleRange(node, parameter);
416 _currentHolder.addParameter(parameter); 431 _currentHolder.addParameter(parameter);
417 parameterName.staticElement = parameter; 432 parameterName.staticElement = parameter;
418 } 433 }
419 ElementHolder holder = new ElementHolder(); 434 ElementHolder holder = new ElementHolder();
420 visitChildren(holder, node); 435 visitChildren(holder, node);
421 ((node.element as ParameterElementImpl)).parameters = holder.parameters; 436 (node.element as ParameterElementImpl).parameters = holder.parameters;
422 holder.validate(); 437 holder.validate();
423 return null; 438 return null;
424 } 439 }
440
425 Object visitLabeledStatement(LabeledStatement node) { 441 Object visitLabeledStatement(LabeledStatement node) {
426 bool onSwitchStatement = node.statement is SwitchStatement; 442 bool onSwitchStatement = node.statement is SwitchStatement;
427 for (Label label in node.labels) { 443 for (Label label in node.labels) {
428 SimpleIdentifier labelName = label.label; 444 SimpleIdentifier labelName = label.label;
429 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme nt, false); 445 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme nt, false);
430 _currentHolder.addLabel(element); 446 _currentHolder.addLabel(element);
431 labelName.staticElement = element; 447 labelName.staticElement = element;
432 } 448 }
433 return super.visitLabeledStatement(node); 449 return super.visitLabeledStatement(node);
434 } 450 }
451
435 Object visitMethodDeclaration(MethodDeclaration node) { 452 Object visitMethodDeclaration(MethodDeclaration node) {
436 ElementHolder holder = new ElementHolder(); 453 ElementHolder holder = new ElementHolder();
437 bool wasInFunction = _inFunction; 454 bool wasInFunction = _inFunction;
438 _inFunction = true; 455 _inFunction = true;
439 try { 456 try {
440 visitChildren(holder, node); 457 visitChildren(holder, node);
441 } finally { 458 } finally {
442 _inFunction = wasInFunction; 459 _inFunction = wasInFunction;
443 } 460 }
444 bool isStatic = node.isStatic; 461 bool isStatic = node.isStatic;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 setter.static = isStatic; 510 setter.static = isStatic;
494 field.setter = setter; 511 field.setter = setter;
495 field.final2 = false; 512 field.final2 = false;
496 _currentHolder.addAccessor(setter); 513 _currentHolder.addAccessor(setter);
497 propertyNameNode.staticElement = setter; 514 propertyNameNode.staticElement = setter;
498 } 515 }
499 } 516 }
500 holder.validate(); 517 holder.validate();
501 return null; 518 return null;
502 } 519 }
520
503 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 521 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
504 if (node.parent is! DefaultFormalParameter) { 522 if (node.parent is! DefaultFormalParameter) {
505 SimpleIdentifier parameterName = node.identifier; 523 SimpleIdentifier parameterName = node.identifier;
506 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa me); 524 ParameterElementImpl parameter = new ParameterElementImpl.con1(parameterNa me);
507 parameter.const3 = node.isConst; 525 parameter.const3 = node.isConst;
508 parameter.final2 = node.isFinal; 526 parameter.final2 = node.isFinal;
509 parameter.parameterKind = node.kind; 527 parameter.parameterKind = node.kind;
510 setParameterVisibleRange(node, parameter); 528 setParameterVisibleRange(node, parameter);
511 _currentHolder.addParameter(parameter); 529 _currentHolder.addParameter(parameter);
512 parameterName.staticElement = parameter; 530 parameterName.staticElement = parameter;
513 } 531 }
514 return super.visitSimpleFormalParameter(node); 532 return super.visitSimpleFormalParameter(node);
515 } 533 }
534
516 Object visitSuperExpression(SuperExpression node) { 535 Object visitSuperExpression(SuperExpression node) {
517 _isValidMixin = false; 536 _isValidMixin = false;
518 return super.visitSuperExpression(node); 537 return super.visitSuperExpression(node);
519 } 538 }
539
520 Object visitSwitchCase(SwitchCase node) { 540 Object visitSwitchCase(SwitchCase node) {
521 for (Label label in node.labels) { 541 for (Label label in node.labels) {
522 SimpleIdentifier labelName = label.label; 542 SimpleIdentifier labelName = label.label;
523 LabelElementImpl element = new LabelElementImpl(labelName, false, true); 543 LabelElementImpl element = new LabelElementImpl(labelName, false, true);
524 _currentHolder.addLabel(element); 544 _currentHolder.addLabel(element);
525 labelName.staticElement = element; 545 labelName.staticElement = element;
526 } 546 }
527 return super.visitSwitchCase(node); 547 return super.visitSwitchCase(node);
528 } 548 }
549
529 Object visitSwitchDefault(SwitchDefault node) { 550 Object visitSwitchDefault(SwitchDefault node) {
530 for (Label label in node.labels) { 551 for (Label label in node.labels) {
531 SimpleIdentifier labelName = label.label; 552 SimpleIdentifier labelName = label.label;
532 LabelElementImpl element = new LabelElementImpl(labelName, false, true); 553 LabelElementImpl element = new LabelElementImpl(labelName, false, true);
533 _currentHolder.addLabel(element); 554 _currentHolder.addLabel(element);
534 labelName.staticElement = element; 555 labelName.staticElement = element;
535 } 556 }
536 return super.visitSwitchDefault(node); 557 return super.visitSwitchDefault(node);
537 } 558 }
559
538 Object visitTypeParameter(TypeParameter node) { 560 Object visitTypeParameter(TypeParameter node) {
539 SimpleIdentifier parameterName = node.name; 561 SimpleIdentifier parameterName = node.name;
540 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl(parame terName); 562 TypeParameterElementImpl typeParameter = new TypeParameterElementImpl(parame terName);
541 TypeParameterTypeImpl typeParameterType = new TypeParameterTypeImpl(typePara meter); 563 TypeParameterTypeImpl typeParameterType = new TypeParameterTypeImpl(typePara meter);
542 typeParameter.type = typeParameterType; 564 typeParameter.type = typeParameterType;
543 _currentHolder.addTypeParameter(typeParameter); 565 _currentHolder.addTypeParameter(typeParameter);
544 parameterName.staticElement = typeParameter; 566 parameterName.staticElement = typeParameter;
545 return super.visitTypeParameter(node); 567 return super.visitTypeParameter(node);
546 } 568 }
569
547 Object visitVariableDeclaration(VariableDeclaration node) { 570 Object visitVariableDeclaration(VariableDeclaration node) {
548 sc.Token keyword = ((node.parent as VariableDeclarationList)).keyword; 571 sc.Token keyword = (node.parent as VariableDeclarationList).keyword;
549 bool isConst = matches(keyword, sc.Keyword.CONST); 572 bool isConst = matches(keyword, sc.Keyword.CONST);
550 bool isFinal = matches(keyword, sc.Keyword.FINAL); 573 bool isFinal = matches(keyword, sc.Keyword.FINAL);
551 bool hasInitializer = node.initializer != null; 574 bool hasInitializer = node.initializer != null;
552 VariableElementImpl element; 575 VariableElementImpl element;
553 if (_inFieldContext) { 576 if (_inFieldContext) {
554 SimpleIdentifier fieldName = node.name; 577 SimpleIdentifier fieldName = node.name;
555 FieldElementImpl field; 578 FieldElementImpl field;
556 if (isConst && hasInitializer) { 579 if (isConst && hasInitializer) {
557 field = new ConstFieldElementImpl(fieldName); 580 field = new ConstFieldElementImpl(fieldName);
558 } else { 581 } else {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 initializer.functions = holder.functions; 626 initializer.functions = holder.functions;
604 initializer.labels = holder.labels; 627 initializer.labels = holder.labels;
605 initializer.localVariables = holder.localVariables; 628 initializer.localVariables = holder.localVariables;
606 initializer.synthetic = true; 629 initializer.synthetic = true;
607 element.initializer = initializer; 630 element.initializer = initializer;
608 holder.validate(); 631 holder.validate();
609 } 632 }
610 if (element is PropertyInducingElementImpl) { 633 if (element is PropertyInducingElementImpl) {
611 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl; 634 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl;
612 if (_inFieldContext) { 635 if (_inFieldContext) {
613 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).staticKeyword, sc.Keyword.STATIC); 636 (variable as FieldElementImpl).static = matches((node.parent.parent as F ieldDeclaration).staticKeyword, sc.Keyword.STATIC);
614 } 637 }
615 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable); 638 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable);
616 getter.getter = true; 639 getter.getter = true;
617 getter.static = variable.isStatic; 640 getter.static = variable.isStatic;
618 _currentHolder.addAccessor(getter); 641 _currentHolder.addAccessor(getter);
619 variable.getter = getter; 642 variable.getter = getter;
620 if (!isFinal) { 643 if (!isFinal) {
621 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable); 644 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable);
622 setter.setter = true; 645 setter.setter = true;
623 setter.static = variable.isStatic; 646 setter.static = variable.isStatic;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 * Return the body of the function that contains the given parameter, or `null ` if no 694 * Return the body of the function that contains the given parameter, or `null ` if no
672 * function body could be found. 695 * function body could be found.
673 * 696 *
674 * @param node the parameter contained in the function whose body is to be ret urned 697 * @param node the parameter contained in the function whose body is to be ret urned
675 * @return the body of the function that contains the given parameter 698 * @return the body of the function that contains the given parameter
676 */ 699 */
677 FunctionBody getFunctionBody(FormalParameter node) { 700 FunctionBody getFunctionBody(FormalParameter node) {
678 ASTNode parent = node.parent; 701 ASTNode parent = node.parent;
679 while (parent != null) { 702 while (parent != null) {
680 if (parent is ConstructorDeclaration) { 703 if (parent is ConstructorDeclaration) {
681 return ((parent as ConstructorDeclaration)).body; 704 return (parent as ConstructorDeclaration).body;
682 } else if (parent is FunctionExpression) { 705 } else if (parent is FunctionExpression) {
683 return ((parent as FunctionExpression)).body; 706 return (parent as FunctionExpression).body;
684 } else if (parent is MethodDeclaration) { 707 } else if (parent is MethodDeclaration) {
685 return ((parent as MethodDeclaration)).body; 708 return (parent as MethodDeclaration).body;
686 } 709 }
687 parent = parent.parent; 710 parent = parent.parent;
688 } 711 }
689 return null; 712 return null;
690 } 713 }
691 714
692 /** 715 /**
693 * Return `true` if the given token is a token for the given keyword. 716 * Return `true` if the given token is a token for the given keyword.
694 * 717 *
695 * @param token the token being tested 718 * @param token the token being tested
696 * @param keyword the keyword being tested for 719 * @param keyword the keyword being tested for
697 * @return `true` if the given token is a token for the given keyword 720 * @return `true` if the given token is a token for the given keyword
698 */ 721 */
699 bool matches(sc.Token token, sc.Keyword keyword) => token != null && identical (token.type, sc.TokenType.KEYWORD) && identical(((token as sc.KeywordToken)).key word, keyword); 722 bool matches(sc.Token token, sc.Keyword keyword) => token != null && identical (token.type, sc.TokenType.KEYWORD) && identical((token as sc.KeywordToken).keywo rd, keyword);
700 723
701 /** 724 /**
702 * Sets the visible source range for formal parameter. 725 * Sets the visible source range for formal parameter.
703 */ 726 */
704 void setParameterVisibleRange(FormalParameter node, ParameterElementImpl eleme nt) { 727 void setParameterVisibleRange(FormalParameter node, ParameterElementImpl eleme nt) {
705 FunctionBody body = getFunctionBody(node); 728 FunctionBody body = getFunctionBody(node);
706 if (body != null) { 729 if (body != null) {
707 element.setVisibleRange(body.offset, body.length); 730 element.setVisibleRange(body.offset, body.length);
708 } 731 }
709 } 732 }
(...skipping 27 matching lines...) Expand all
737 ElementHolder previousHolder = _currentHolder; 760 ElementHolder previousHolder = _currentHolder;
738 _currentHolder = holder; 761 _currentHolder = holder;
739 try { 762 try {
740 node.visitChildren(this); 763 node.visitChildren(this);
741 } finally { 764 } finally {
742 _currentHolder = previousHolder; 765 _currentHolder = previousHolder;
743 } 766 }
744 } 767 }
745 } 768 }
746 } 769 }
770
747 /** 771 /**
748 * Instances of the class `ElementHolder` hold on to elements created while trav ersing an AST 772 * Instances of the class `ElementHolder` hold on to elements created while trav ersing an AST
749 * structure so that they can be accessed when creating their enclosing element. 773 * structure so that they can be accessed when creating their enclosing element.
750 * 774 *
751 * @coverage dart.engine.resolver 775 * @coverage dart.engine.resolver
752 */ 776 */
753 class ElementHolder { 777 class ElementHolder {
754 List<PropertyAccessorElement> _accessors; 778 List<PropertyAccessorElement> _accessors;
779
755 List<ConstructorElement> _constructors; 780 List<ConstructorElement> _constructors;
781
756 List<FieldElement> _fields; 782 List<FieldElement> _fields;
783
757 List<FunctionElement> _functions; 784 List<FunctionElement> _functions;
785
758 List<LabelElement> _labels; 786 List<LabelElement> _labels;
787
759 List<VariableElement> _localVariables; 788 List<VariableElement> _localVariables;
789
760 List<MethodElement> _methods; 790 List<MethodElement> _methods;
791
761 List<ParameterElement> _parameters; 792 List<ParameterElement> _parameters;
793
762 List<TopLevelVariableElement> _topLevelVariables; 794 List<TopLevelVariableElement> _topLevelVariables;
795
763 List<ClassElement> _types; 796 List<ClassElement> _types;
797
764 List<FunctionTypeAliasElement> _typeAliases; 798 List<FunctionTypeAliasElement> _typeAliases;
799
765 List<TypeParameterElement> _typeParameters; 800 List<TypeParameterElement> _typeParameters;
801
766 void addAccessor(PropertyAccessorElement element) { 802 void addAccessor(PropertyAccessorElement element) {
767 if (_accessors == null) { 803 if (_accessors == null) {
768 _accessors = new List<PropertyAccessorElement>(); 804 _accessors = new List<PropertyAccessorElement>();
769 } 805 }
770 _accessors.add(element); 806 _accessors.add(element);
771 } 807 }
808
772 void addConstructor(ConstructorElement element) { 809 void addConstructor(ConstructorElement element) {
773 if (_constructors == null) { 810 if (_constructors == null) {
774 _constructors = new List<ConstructorElement>(); 811 _constructors = new List<ConstructorElement>();
775 } 812 }
776 _constructors.add(element); 813 _constructors.add(element);
777 } 814 }
815
778 void addField(FieldElement element) { 816 void addField(FieldElement element) {
779 if (_fields == null) { 817 if (_fields == null) {
780 _fields = new List<FieldElement>(); 818 _fields = new List<FieldElement>();
781 } 819 }
782 _fields.add(element); 820 _fields.add(element);
783 } 821 }
822
784 void addFunction(FunctionElement element) { 823 void addFunction(FunctionElement element) {
785 if (_functions == null) { 824 if (_functions == null) {
786 _functions = new List<FunctionElement>(); 825 _functions = new List<FunctionElement>();
787 } 826 }
788 _functions.add(element); 827 _functions.add(element);
789 } 828 }
829
790 void addLabel(LabelElement element) { 830 void addLabel(LabelElement element) {
791 if (_labels == null) { 831 if (_labels == null) {
792 _labels = new List<LabelElement>(); 832 _labels = new List<LabelElement>();
793 } 833 }
794 _labels.add(element); 834 _labels.add(element);
795 } 835 }
836
796 void addLocalVariable(LocalVariableElement element) { 837 void addLocalVariable(LocalVariableElement element) {
797 if (_localVariables == null) { 838 if (_localVariables == null) {
798 _localVariables = new List<VariableElement>(); 839 _localVariables = new List<VariableElement>();
799 } 840 }
800 _localVariables.add(element); 841 _localVariables.add(element);
801 } 842 }
843
802 void addMethod(MethodElement element) { 844 void addMethod(MethodElement element) {
803 if (_methods == null) { 845 if (_methods == null) {
804 _methods = new List<MethodElement>(); 846 _methods = new List<MethodElement>();
805 } 847 }
806 _methods.add(element); 848 _methods.add(element);
807 } 849 }
850
808 void addParameter(ParameterElement element) { 851 void addParameter(ParameterElement element) {
809 if (_parameters == null) { 852 if (_parameters == null) {
810 _parameters = new List<ParameterElement>(); 853 _parameters = new List<ParameterElement>();
811 } 854 }
812 _parameters.add(element); 855 _parameters.add(element);
813 } 856 }
857
814 void addTopLevelVariable(TopLevelVariableElement element) { 858 void addTopLevelVariable(TopLevelVariableElement element) {
815 if (_topLevelVariables == null) { 859 if (_topLevelVariables == null) {
816 _topLevelVariables = new List<TopLevelVariableElement>(); 860 _topLevelVariables = new List<TopLevelVariableElement>();
817 } 861 }
818 _topLevelVariables.add(element); 862 _topLevelVariables.add(element);
819 } 863 }
864
820 void addType(ClassElement element) { 865 void addType(ClassElement element) {
821 if (_types == null) { 866 if (_types == null) {
822 _types = new List<ClassElement>(); 867 _types = new List<ClassElement>();
823 } 868 }
824 _types.add(element); 869 _types.add(element);
825 } 870 }
871
826 void addTypeAlias(FunctionTypeAliasElement element) { 872 void addTypeAlias(FunctionTypeAliasElement element) {
827 if (_typeAliases == null) { 873 if (_typeAliases == null) {
828 _typeAliases = new List<FunctionTypeAliasElement>(); 874 _typeAliases = new List<FunctionTypeAliasElement>();
829 } 875 }
830 _typeAliases.add(element); 876 _typeAliases.add(element);
831 } 877 }
878
832 void addTypeParameter(TypeParameterElement element) { 879 void addTypeParameter(TypeParameterElement element) {
833 if (_typeParameters == null) { 880 if (_typeParameters == null) {
834 _typeParameters = new List<TypeParameterElement>(); 881 _typeParameters = new List<TypeParameterElement>();
835 } 882 }
836 _typeParameters.add(element); 883 _typeParameters.add(element);
837 } 884 }
885
838 List<PropertyAccessorElement> get accessors { 886 List<PropertyAccessorElement> get accessors {
839 if (_accessors == null) { 887 if (_accessors == null) {
840 return PropertyAccessorElementImpl.EMPTY_ARRAY; 888 return PropertyAccessorElementImpl.EMPTY_ARRAY;
841 } 889 }
842 List<PropertyAccessorElement> result = new List.from(_accessors); 890 List<PropertyAccessorElement> result = new List.from(_accessors);
843 _accessors = null; 891 _accessors = null;
844 return result; 892 return result;
845 } 893 }
894
846 List<ConstructorElement> get constructors { 895 List<ConstructorElement> get constructors {
847 if (_constructors == null) { 896 if (_constructors == null) {
848 return ConstructorElementImpl.EMPTY_ARRAY; 897 return ConstructorElementImpl.EMPTY_ARRAY;
849 } 898 }
850 List<ConstructorElement> result = new List.from(_constructors); 899 List<ConstructorElement> result = new List.from(_constructors);
851 _constructors = null; 900 _constructors = null;
852 return result; 901 return result;
853 } 902 }
903
854 FieldElement getField(String fieldName) { 904 FieldElement getField(String fieldName) {
855 if (_fields == null) { 905 if (_fields == null) {
856 return null; 906 return null;
857 } 907 }
858 for (FieldElement field in _fields) { 908 for (FieldElement field in _fields) {
859 if (field.name == fieldName) { 909 if (field.name == fieldName) {
860 return field; 910 return field;
861 } 911 }
862 } 912 }
863 return null; 913 return null;
864 } 914 }
915
865 List<FieldElement> get fields { 916 List<FieldElement> get fields {
866 if (_fields == null) { 917 if (_fields == null) {
867 return FieldElementImpl.EMPTY_ARRAY; 918 return FieldElementImpl.EMPTY_ARRAY;
868 } 919 }
869 List<FieldElement> result = new List.from(_fields); 920 List<FieldElement> result = new List.from(_fields);
870 _fields = null; 921 _fields = null;
871 return result; 922 return result;
872 } 923 }
924
873 List<FunctionElement> get functions { 925 List<FunctionElement> get functions {
874 if (_functions == null) { 926 if (_functions == null) {
875 return FunctionElementImpl.EMPTY_ARRAY; 927 return FunctionElementImpl.EMPTY_ARRAY;
876 } 928 }
877 List<FunctionElement> result = new List.from(_functions); 929 List<FunctionElement> result = new List.from(_functions);
878 _functions = null; 930 _functions = null;
879 return result; 931 return result;
880 } 932 }
933
881 List<LabelElement> get labels { 934 List<LabelElement> get labels {
882 if (_labels == null) { 935 if (_labels == null) {
883 return LabelElementImpl.EMPTY_ARRAY; 936 return LabelElementImpl.EMPTY_ARRAY;
884 } 937 }
885 List<LabelElement> result = new List.from(_labels); 938 List<LabelElement> result = new List.from(_labels);
886 _labels = null; 939 _labels = null;
887 return result; 940 return result;
888 } 941 }
942
889 List<LocalVariableElement> get localVariables { 943 List<LocalVariableElement> get localVariables {
890 if (_localVariables == null) { 944 if (_localVariables == null) {
891 return LocalVariableElementImpl.EMPTY_ARRAY; 945 return LocalVariableElementImpl.EMPTY_ARRAY;
892 } 946 }
893 List<LocalVariableElement> result = new List.from(_localVariables); 947 List<LocalVariableElement> result = new List.from(_localVariables);
894 _localVariables = null; 948 _localVariables = null;
895 return result; 949 return result;
896 } 950 }
951
897 List<MethodElement> get methods { 952 List<MethodElement> get methods {
898 if (_methods == null) { 953 if (_methods == null) {
899 return MethodElementImpl.EMPTY_ARRAY; 954 return MethodElementImpl.EMPTY_ARRAY;
900 } 955 }
901 List<MethodElement> result = new List.from(_methods); 956 List<MethodElement> result = new List.from(_methods);
902 _methods = null; 957 _methods = null;
903 return result; 958 return result;
904 } 959 }
960
905 List<ParameterElement> get parameters { 961 List<ParameterElement> get parameters {
906 if (_parameters == null) { 962 if (_parameters == null) {
907 return ParameterElementImpl.EMPTY_ARRAY; 963 return ParameterElementImpl.EMPTY_ARRAY;
908 } 964 }
909 List<ParameterElement> result = new List.from(_parameters); 965 List<ParameterElement> result = new List.from(_parameters);
910 _parameters = null; 966 _parameters = null;
911 return result; 967 return result;
912 } 968 }
969
913 TopLevelVariableElement getTopLevelVariable(String variableName) { 970 TopLevelVariableElement getTopLevelVariable(String variableName) {
914 if (_topLevelVariables == null) { 971 if (_topLevelVariables == null) {
915 return null; 972 return null;
916 } 973 }
917 for (TopLevelVariableElement variable in _topLevelVariables) { 974 for (TopLevelVariableElement variable in _topLevelVariables) {
918 if (variable.name == variableName) { 975 if (variable.name == variableName) {
919 return variable; 976 return variable;
920 } 977 }
921 } 978 }
922 return null; 979 return null;
923 } 980 }
981
924 List<TopLevelVariableElement> get topLevelVariables { 982 List<TopLevelVariableElement> get topLevelVariables {
925 if (_topLevelVariables == null) { 983 if (_topLevelVariables == null) {
926 return TopLevelVariableElementImpl.EMPTY_ARRAY; 984 return TopLevelVariableElementImpl.EMPTY_ARRAY;
927 } 985 }
928 List<TopLevelVariableElement> result = new List.from(_topLevelVariables); 986 List<TopLevelVariableElement> result = new List.from(_topLevelVariables);
929 _topLevelVariables = null; 987 _topLevelVariables = null;
930 return result; 988 return result;
931 } 989 }
990
932 List<FunctionTypeAliasElement> get typeAliases { 991 List<FunctionTypeAliasElement> get typeAliases {
933 if (_typeAliases == null) { 992 if (_typeAliases == null) {
934 return FunctionTypeAliasElementImpl.EMPTY_ARRAY; 993 return FunctionTypeAliasElementImpl.EMPTY_ARRAY;
935 } 994 }
936 List<FunctionTypeAliasElement> result = new List.from(_typeAliases); 995 List<FunctionTypeAliasElement> result = new List.from(_typeAliases);
937 _typeAliases = null; 996 _typeAliases = null;
938 return result; 997 return result;
939 } 998 }
999
940 List<TypeParameterElement> get typeParameters { 1000 List<TypeParameterElement> get typeParameters {
941 if (_typeParameters == null) { 1001 if (_typeParameters == null) {
942 return TypeParameterElementImpl.EMPTY_ARRAY; 1002 return TypeParameterElementImpl.EMPTY_ARRAY;
943 } 1003 }
944 List<TypeParameterElement> result = new List.from(_typeParameters); 1004 List<TypeParameterElement> result = new List.from(_typeParameters);
945 _typeParameters = null; 1005 _typeParameters = null;
946 return result; 1006 return result;
947 } 1007 }
1008
948 List<ClassElement> get types { 1009 List<ClassElement> get types {
949 if (_types == null) { 1010 if (_types == null) {
950 return ClassElementImpl.EMPTY_ARRAY; 1011 return ClassElementImpl.EMPTY_ARRAY;
951 } 1012 }
952 List<ClassElement> result = new List.from(_types); 1013 List<ClassElement> result = new List.from(_types);
953 _types = null; 1014 _types = null;
954 return result; 1015 return result;
955 } 1016 }
1017
956 void validate() { 1018 void validate() {
957 JavaStringBuilder builder = new JavaStringBuilder(); 1019 JavaStringBuilder builder = new JavaStringBuilder();
958 if (_accessors != null) { 1020 if (_accessors != null) {
959 builder.append(_accessors.length); 1021 builder.append(_accessors.length);
960 builder.append(" accessors"); 1022 builder.append(" accessors");
961 } 1023 }
962 if (_constructors != null) { 1024 if (_constructors != null) {
963 if (builder.length > 0) { 1025 if (builder.length > 0) {
964 builder.append("; "); 1026 builder.append("; ");
965 } 1027 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 builder.append("; "); 1096 builder.append("; ");
1035 } 1097 }
1036 builder.append(_typeParameters.length); 1098 builder.append(_typeParameters.length);
1037 builder.append(" type parameters"); 1099 builder.append(" type parameters");
1038 } 1100 }
1039 if (builder.length > 0) { 1101 if (builder.length > 0) {
1040 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui lder.toString()}"); 1102 AnalysisEngine.instance.logger.logError("Failed to capture elements: ${bui lder.toString()}");
1041 } 1103 }
1042 } 1104 }
1043 } 1105 }
1106
1044 /** 1107 /**
1045 * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit. 1108 * Instances of the class `HtmlUnitBuilder` build an element model for a single HTML unit.
1046 */ 1109 */
1047 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { 1110 class HtmlUnitBuilder implements ht.XmlVisitor<Object> {
1048 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; 1111 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\"";
1112
1049 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; 1113 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'";
1114
1050 static String _SCRIPT = "script"; 1115 static String _SCRIPT = "script";
1116
1051 static String _SRC = "src"; 1117 static String _SRC = "src";
1118
1052 static String _TYPE = "type"; 1119 static String _TYPE = "type";
1053 1120
1054 /** 1121 /**
1055 * The analysis context in which the element model will be built. 1122 * The analysis context in which the element model will be built.
1056 */ 1123 */
1057 InternalAnalysisContext _context; 1124 InternalAnalysisContext _context;
1058 1125
1059 /** 1126 /**
1060 * The error listener to which errors will be reported. 1127 * The error listener to which errors will be reported.
1061 */ 1128 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 this._modificationStamp = modificationStamp; 1191 this._modificationStamp = modificationStamp;
1125 _lineInfo = _context.computeLineInfo(source); 1192 _lineInfo = _context.computeLineInfo(source);
1126 HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName); 1193 HtmlElementImpl result = new HtmlElementImpl(_context, source.shortName);
1127 result.source = source; 1194 result.source = source;
1128 _htmlElement = result; 1195 _htmlElement = result;
1129 unit.accept(this); 1196 unit.accept(this);
1130 _htmlElement = null; 1197 _htmlElement = null;
1131 unit.element = result; 1198 unit.element = result;
1132 return result; 1199 return result;
1133 } 1200 }
1201
1134 Object visitHtmlUnit(ht.HtmlUnit node) { 1202 Object visitHtmlUnit(ht.HtmlUnit node) {
1135 _parentNodes = new List<ht.XmlTagNode>(); 1203 _parentNodes = new List<ht.XmlTagNode>();
1136 _scripts = new List<HtmlScriptElement>(); 1204 _scripts = new List<HtmlScriptElement>();
1137 try { 1205 try {
1138 node.visitChildren(this); 1206 node.visitChildren(this);
1139 _htmlElement.scripts = new List.from(_scripts); 1207 _htmlElement.scripts = new List.from(_scripts);
1140 } finally { 1208 } finally {
1141 _scripts = null; 1209 _scripts = null;
1142 _parentNodes = null; 1210 _parentNodes = null;
1143 } 1211 }
1144 return null; 1212 return null;
1145 } 1213 }
1214
1146 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null; 1215 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null;
1216
1147 Object visitXmlTagNode(ht.XmlTagNode node) { 1217 Object visitXmlTagNode(ht.XmlTagNode node) {
1148 if (_parentNodes.contains(node)) { 1218 if (_parentNodes.contains(node)) {
1149 JavaStringBuilder builder = new JavaStringBuilder(); 1219 JavaStringBuilder builder = new JavaStringBuilder();
1150 builder.append("Found circularity in XML nodes: "); 1220 builder.append("Found circularity in XML nodes: ");
1151 bool first = true; 1221 bool first = true;
1152 for (ht.XmlTagNode pathNode in _parentNodes) { 1222 for (ht.XmlTagNode pathNode in _parentNodes) {
1153 if (first) { 1223 if (first) {
1154 first = false; 1224 first = false;
1155 } else { 1225 } else {
1156 builder.append(", "); 1226 builder.append(", ");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 * @param offset the offset of the first character to be highlighted 1350 * @param offset the offset of the first character to be highlighted
1281 * @param length the number of characters to be highlighted 1351 * @param length the number of characters to be highlighted
1282 * @param arguments the arguments used to compose the error message 1352 * @param arguments the arguments used to compose the error message
1283 */ 1353 */
1284 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) { 1354 void reportValueError(ErrorCode errorCode, ht.XmlAttributeNode attribute, List <Object> arguments) {
1285 int offset = attribute.value.offset + 1; 1355 int offset = attribute.value.offset + 1;
1286 int length = attribute.value.length - 2; 1356 int length = attribute.value.length - 2;
1287 reportError(errorCode, offset, length, arguments); 1357 reportError(errorCode, offset, length, arguments);
1288 } 1358 }
1289 } 1359 }
1360
1290 /** 1361 /**
1291 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 1362 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
1292 * violations of Dart best practices. 1363 * violations of Dart best practices.
1293 * 1364 *
1294 * @coverage dart.engine.resolver 1365 * @coverage dart.engine.resolver
1295 */ 1366 */
1296 class BestPracticesVerifier extends RecursiveASTVisitor<Object> { 1367 class BestPracticesVerifier extends RecursiveASTVisitor<Object> {
1297 static String _GETTER = "getter"; 1368 static String _GETTER = "getter";
1369
1298 static String _HASHCODE_GETTER_NAME = "hashCode"; 1370 static String _HASHCODE_GETTER_NAME = "hashCode";
1371
1299 static String _METHOD = "method"; 1372 static String _METHOD = "method";
1373
1300 static String _NULL_TYPE_NAME = "Null"; 1374 static String _NULL_TYPE_NAME = "Null";
1375
1301 static String _SETTER = "setter"; 1376 static String _SETTER = "setter";
1377
1302 static String _TO_INT_METHOD_NAME = "toInt"; 1378 static String _TO_INT_METHOD_NAME = "toInt";
1303 1379
1304 /** 1380 /**
1305 * Given a parenthesized expression, this returns the parent (or recursively g rand-parent) of the 1381 * Given a parenthesized expression, this returns the parent (or recursively g rand-parent) of the
1306 * expression that is a parenthesized expression, but whose parent is not a pa renthesized 1382 * expression that is a parenthesized expression, but whose parent is not a pa renthesized
1307 * expression. 1383 * expression.
1308 * 1384 *
1309 * For example given the code `(((e)))`: `(e) -> (((e)))`. 1385 * For example given the code `(((e)))`: `(e) -> (((e)))`.
1310 * 1386 *
1311 * @param parenthesizedExpression some expression whose parent is a parenthesi zed expression 1387 * @param parenthesizedExpression some expression whose parent is a parenthesi zed expression
(...skipping 19 matching lines...) Expand all
1331 ErrorReporter _errorReporter; 1407 ErrorReporter _errorReporter;
1332 1408
1333 /** 1409 /**
1334 * Create a new instance of the [BestPracticesVerifier]. 1410 * Create a new instance of the [BestPracticesVerifier].
1335 * 1411 *
1336 * @param errorReporter the error reporter 1412 * @param errorReporter the error reporter
1337 */ 1413 */
1338 BestPracticesVerifier(ErrorReporter errorReporter) { 1414 BestPracticesVerifier(ErrorReporter errorReporter) {
1339 this._errorReporter = errorReporter; 1415 this._errorReporter = errorReporter;
1340 } 1416 }
1417
1341 Object visitAsExpression(AsExpression node) { 1418 Object visitAsExpression(AsExpression node) {
1342 checkForUnnecessaryCast(node); 1419 checkForUnnecessaryCast(node);
1343 return super.visitAsExpression(node); 1420 return super.visitAsExpression(node);
1344 } 1421 }
1422
1423 Object visitAssignmentExpression(AssignmentExpression node) {
1424 sc.TokenType operatorType = node.operator.type;
1425 if (operatorType != sc.TokenType.EQ) {
1426 checkForDeprecatedMemberUse(node.bestElement, node);
1427 }
1428 return super.visitAssignmentExpression(node);
1429 }
1430
1345 Object visitBinaryExpression(BinaryExpression node) { 1431 Object visitBinaryExpression(BinaryExpression node) {
1346 checkForDivisionOptimizationHint(node); 1432 checkForDivisionOptimizationHint(node);
1433 checkForDeprecatedMemberUse(node.bestElement, node);
1347 return super.visitBinaryExpression(node); 1434 return super.visitBinaryExpression(node);
1348 } 1435 }
1436
1349 Object visitClassDeclaration(ClassDeclaration node) { 1437 Object visitClassDeclaration(ClassDeclaration node) {
1350 ClassElement outerClass = _enclosingClass; 1438 ClassElement outerClass = _enclosingClass;
1351 try { 1439 try {
1352 _enclosingClass = node.element; 1440 _enclosingClass = node.element;
1353 return super.visitClassDeclaration(node); 1441 return super.visitClassDeclaration(node);
1354 } finally { 1442 } finally {
1355 _enclosingClass = outerClass; 1443 _enclosingClass = outerClass;
1356 } 1444 }
1357 } 1445 }
1446
1447 Object visitExportDirective(ExportDirective node) {
1448 checkForDeprecatedMemberUse(node.uriElement, node);
1449 return super.visitExportDirective(node);
1450 }
1451
1452 Object visitImportDirective(ImportDirective node) {
1453 checkForDeprecatedMemberUse(node.uriElement, node);
1454 return super.visitImportDirective(node);
1455 }
1456
1457 Object visitIndexExpression(IndexExpression node) {
1458 checkForDeprecatedMemberUse(node.bestElement, node);
1459 return super.visitIndexExpression(node);
1460 }
1461
1462 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
1463 checkForDeprecatedMemberUse(node.staticElement, node);
1464 return super.visitInstanceCreationExpression(node);
1465 }
1466
1358 Object visitIsExpression(IsExpression node) { 1467 Object visitIsExpression(IsExpression node) {
1359 checkAllTypeChecks(node); 1468 checkAllTypeChecks(node);
1360 return super.visitIsExpression(node); 1469 return super.visitIsExpression(node);
1361 } 1470 }
1471
1362 Object visitMethodDeclaration(MethodDeclaration node) { 1472 Object visitMethodDeclaration(MethodDeclaration node) {
1363 checkForOverridingPrivateMember(node); 1473 checkForOverridingPrivateMember(node);
1364 return super.visitMethodDeclaration(node); 1474 return super.visitMethodDeclaration(node);
1365 } 1475 }
1366 1476
1477 Object visitPostfixExpression(PostfixExpression node) {
1478 checkForDeprecatedMemberUse(node.bestElement, node);
1479 return super.visitPostfixExpression(node);
1480 }
1481
1482 Object visitPrefixExpression(PrefixExpression node) {
1483 checkForDeprecatedMemberUse(node.bestElement, node);
1484 return super.visitPrefixExpression(node);
1485 }
1486
1487 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
1488 checkForDeprecatedMemberUse(node.staticElement, node);
1489 return super.visitRedirectingConstructorInvocation(node);
1490 }
1491
1492 Object visitSimpleIdentifier(SimpleIdentifier node) {
1493 checkForDeprecatedMemberUse2(node);
1494 return super.visitSimpleIdentifier(node);
1495 }
1496
1497 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
1498 checkForDeprecatedMemberUse(node.staticElement, node);
1499 return super.visitSuperConstructorInvocation(node);
1500 }
1501
1367 /** 1502 /**
1368 * Check for the passed is expression for the unnecessary type check hint code s as well as null 1503 * Check for the passed is expression for the unnecessary type check hint code s as well as null
1369 * checks expressed using an is expression. 1504 * checks expressed using an is expression.
1370 * 1505 *
1371 * @param node the is expression to check 1506 * @param node the is expression to check
1372 * @return `true` if and only if a hint code is generated on the passed node 1507 * @return `true` if and only if a hint code is generated on the passed node
1373 * @see HintCode#TYPE_CHECK_IS_NOT_NULL 1508 * @see HintCode#TYPE_CHECK_IS_NOT_NULL
1374 * @see HintCode#TYPE_CHECK_IS_NULL 1509 * @see HintCode#TYPE_CHECK_IS_NULL
1375 * @see HintCode#UNNECESSARY_TYPE_CHECK_TRUE 1510 * @see HintCode#UNNECESSARY_TYPE_CHECK_TRUE
1376 * @see HintCode#UNNECESSARY_TYPE_CHECK_FALSE 1511 * @see HintCode#UNNECESSARY_TYPE_CHECK_FALSE
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 } else { 1543 } else {
1409 _errorReporter.reportError2(HintCode.TYPE_CHECK_IS_NOT_NULL, node, []) ; 1544 _errorReporter.reportError2(HintCode.TYPE_CHECK_IS_NOT_NULL, node, []) ;
1410 } 1545 }
1411 return true; 1546 return true;
1412 } 1547 }
1413 } 1548 }
1414 return false; 1549 return false;
1415 } 1550 }
1416 1551
1417 /** 1552 /**
1553 * Given some [Element], look at the associated metadata and report the use of the member if
1554 * it is declared as deprecated.
1555 *
1556 * @param element some element to check for deprecated use of
1557 * @param node the node use for the location of the error
1558 * @return `true` if and only if a hint code is generated on the passed node
1559 * @see HintCode#DEPRECATED_MEMBER_USE
1560 */
1561 bool checkForDeprecatedMemberUse(Element element, ASTNode node) {
1562 if (element != null && element.isDeprecated) {
1563 String displayName = element.displayName;
1564 if (element is ConstructorElement) {
1565 ConstructorElement constructorElement = element as ConstructorElement;
1566 displayName = constructorElement.enclosingElement.displayName;
1567 if (!constructorElement.displayName.isEmpty) {
1568 displayName = "${displayName}.${constructorElement.displayName}";
1569 }
1570 }
1571 _errorReporter.reportError2(HintCode.DEPRECATED_MEMBER_USE, node, [display Name]);
1572 return true;
1573 }
1574 return false;
1575 }
1576
1577 /**
1578 * For [SimpleIdentifier]s, only call [checkForDeprecatedMemberUse]
1579 * if the node is not in a declaration context.
1580 *
1581 * Also, if the identifier is a constructor name in a constructor invocation, then calls to the
1582 * deprecated constructor will be caught by
1583 * [visitInstanceCreationExpression] and
1584 * [visitSuperConstructorInvocation], and can be ignored by
1585 * this visit method.
1586 *
1587 * @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
1589 * @see HintCode#DEPRECATED_MEMBER_USE
1590 */
1591 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))) {
1593 return false;
1594 }
1595 return checkForDeprecatedMemberUse(identifier.bestElement, identifier);
1596 }
1597
1598 /**
1418 * Check for the passed binary expression for the [HintCode#DIVISION_OPTIMIZAT ION]. 1599 * Check for the passed binary expression for the [HintCode#DIVISION_OPTIMIZAT ION].
1419 * 1600 *
1420 * @param node the binary expression to check 1601 * @param node the binary expression to check
1421 * @return `true` if and only if a hint code is generated on the passed node 1602 * @return `true` if and only if a hint code is generated on the passed node
1422 * @see HintCode#DIVISION_OPTIMIZATION 1603 * @see HintCode#DIVISION_OPTIMIZATION
1423 */ 1604 */
1424 bool checkForDivisionOptimizationHint(BinaryExpression node) { 1605 bool checkForDivisionOptimizationHint(BinaryExpression node) {
1425 if (node.operator.type != sc.TokenType.SLASH) { 1606 if (node.operator.type != sc.TokenType.SLASH) {
1426 return false; 1607 return false;
1427 } 1608 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 if (isGetterOrSetter) { 1682 if (isGetterOrSetter) {
1502 PropertyAccessorElement overriddenAccessor = null; 1683 PropertyAccessorElement overriddenAccessor = null;
1503 List<PropertyAccessorElement> accessors = classElement.accessors; 1684 List<PropertyAccessorElement> accessors = classElement.accessors;
1504 for (PropertyAccessorElement propertyAccessorElement in accessors) { 1685 for (PropertyAccessorElement propertyAccessorElement in accessors) {
1505 if (elementName == propertyAccessorElement.name) { 1686 if (elementName == propertyAccessorElement.name) {
1506 overriddenAccessor = propertyAccessorElement; 1687 overriddenAccessor = propertyAccessorElement;
1507 break; 1688 break;
1508 } 1689 }
1509 } 1690 }
1510 if (overriddenAccessor != null) { 1691 if (overriddenAccessor != null) {
1511 String memberType = ((executableElement as PropertyAccessorElement)) .isGetter ? _GETTER : _SETTER; 1692 String memberType = (executableElement as PropertyAccessorElement).i sGetter ? _GETTER : _SETTER;
1512 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [ 1693 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [
1513 memberType, 1694 memberType,
1514 executableElement.displayName, 1695 executableElement.displayName,
1515 classElement.displayName]); 1696 classElement.displayName]);
1516 return true; 1697 return true;
1517 } 1698 }
1518 } else { 1699 } else {
1519 MethodElement overriddenMethod = classElement.getMethod(elementName); 1700 MethodElement overriddenMethod = classElement.getMethod(elementName);
1520 if (overriddenMethod != null) { 1701 if (overriddenMethod != null) {
1521 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [ 1702 _errorReporter.reportError2(HintCode.OVERRIDDING_PRIVATE_MEMBER, nod e.name, [
(...skipping 22 matching lines...) Expand all
1544 TypeName typeName = node.type; 1725 TypeName typeName = node.type;
1545 Type2 lhsType = expression.staticType; 1726 Type2 lhsType = expression.staticType;
1546 Type2 rhsType = typeName.type; 1727 Type2 rhsType = typeName.type;
1547 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT ype.isSubtypeOf(rhsType)) { 1728 if (lhsType != null && rhsType != null && !lhsType.isDynamic && !rhsType.isD ynamic && lhsType is! TypeParameterType && rhsType is! TypeParameterType && lhsT ype.isSubtypeOf(rhsType)) {
1548 _errorReporter.reportError2(HintCode.UNNECESSARY_CAST, node, []); 1729 _errorReporter.reportError2(HintCode.UNNECESSARY_CAST, node, []);
1549 return true; 1730 return true;
1550 } 1731 }
1551 return false; 1732 return false;
1552 } 1733 }
1553 } 1734 }
1735
1554 /** 1736 /**
1555 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for 1737 * Instances of the class `Dart2JSVerifier` traverse an AST structure looking fo r hints for
1556 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE]. 1738 * code that will be compiled to JS, such as [HintCode#IS_DOUBLE].
1557 * 1739 *
1558 * @coverage dart.engine.resolver 1740 * @coverage dart.engine.resolver
1559 */ 1741 */
1560 class Dart2JSVerifier extends RecursiveASTVisitor<Object> { 1742 class Dart2JSVerifier extends RecursiveASTVisitor<Object> {
1561
1562 /** 1743 /**
1563 * The error reporter by which errors will be reported. 1744 * The error reporter by which errors will be reported.
1564 */ 1745 */
1565 ErrorReporter _errorReporter; 1746 ErrorReporter _errorReporter;
1566 1747
1567 /** 1748 /**
1568 * The name of the `double` type. 1749 * The name of the `double` type.
1569 */ 1750 */
1570 static String _DOUBLE_TYPE_NAME = "double"; 1751 static String _DOUBLE_TYPE_NAME = "double";
1571 1752
1572 /** 1753 /**
1573 * Create a new instance of the [Dart2JSVerifier]. 1754 * Create a new instance of the [Dart2JSVerifier].
1574 * 1755 *
1575 * @param errorReporter the error reporter 1756 * @param errorReporter the error reporter
1576 */ 1757 */
1577 Dart2JSVerifier(ErrorReporter errorReporter) { 1758 Dart2JSVerifier(ErrorReporter errorReporter) {
1578 this._errorReporter = errorReporter; 1759 this._errorReporter = errorReporter;
1579 } 1760 }
1761
1580 Object visitIsExpression(IsExpression node) { 1762 Object visitIsExpression(IsExpression node) {
1581 checkForIsDoubleHints(node); 1763 checkForIsDoubleHints(node);
1582 return super.visitIsExpression(node); 1764 return super.visitIsExpression(node);
1583 } 1765 }
1584 1766
1585 /** 1767 /**
1586 * Check for instances of `x is double`, `x is int`, `x is! double` and 1768 * Check for instances of `x is double`, `x is int`, `x is! double` and
1587 * `x is! int`. 1769 * `x is! int`.
1588 * 1770 *
1589 * @param node the is expression to check 1771 * @param node the is expression to check
(...skipping 15 matching lines...) Expand all
1605 _errorReporter.reportError2(HintCode.IS_DOUBLE, node, []); 1787 _errorReporter.reportError2(HintCode.IS_DOUBLE, node, []);
1606 } else { 1788 } else {
1607 _errorReporter.reportError2(HintCode.IS_NOT_DOUBLE, node, []); 1789 _errorReporter.reportError2(HintCode.IS_NOT_DOUBLE, node, []);
1608 } 1790 }
1609 return true; 1791 return true;
1610 } 1792 }
1611 } 1793 }
1612 return false; 1794 return false;
1613 } 1795 }
1614 } 1796 }
1797
1615 /** 1798 /**
1616 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of 1799 * Instances of the class `DeadCodeVerifier` traverse an AST structure looking f or cases of
1617 * [HintCode#DEAD_CODE]. 1800 * [HintCode#DEAD_CODE].
1618 * 1801 *
1619 * @coverage dart.engine.resolver 1802 * @coverage dart.engine.resolver
1620 */ 1803 */
1621 class DeadCodeVerifier extends RecursiveASTVisitor<Object> { 1804 class DeadCodeVerifier extends RecursiveASTVisitor<Object> {
1622
1623 /** 1805 /**
1624 * The error reporter by which errors will be reported. 1806 * The error reporter by which errors will be reported.
1625 */ 1807 */
1626 ErrorReporter _errorReporter; 1808 ErrorReporter _errorReporter;
1627 1809
1628 /** 1810 /**
1629 * Create a new instance of the [DeadCodeVerifier]. 1811 * Create a new instance of the [DeadCodeVerifier].
1630 * 1812 *
1631 * @param errorReporter the error reporter 1813 * @param errorReporter the error reporter
1632 */ 1814 */
1633 DeadCodeVerifier(ErrorReporter errorReporter) { 1815 DeadCodeVerifier(ErrorReporter errorReporter) {
1634 this._errorReporter = errorReporter; 1816 this._errorReporter = errorReporter;
1635 } 1817 }
1818
1636 Object visitBinaryExpression(BinaryExpression node) { 1819 Object visitBinaryExpression(BinaryExpression node) {
1637 sc.Token operator = node.operator; 1820 sc.Token operator = node.operator;
1638 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND); 1821 bool isAmpAmp = identical(operator.type, sc.TokenType.AMPERSAND_AMPERSAND);
1639 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR); 1822 bool isBarBar = identical(operator.type, sc.TokenType.BAR_BAR);
1640 if (isAmpAmp || isBarBar) { 1823 if (isAmpAmp || isBarBar) {
1641 Expression lhsCondition = node.leftOperand; 1824 Expression lhsCondition = node.leftOperand;
1642 if (!isDebugConstant(lhsCondition)) { 1825 if (!isDebugConstant(lhsCondition)) {
1643 ValidResult lhsResult = getConstantBooleanValue(lhsCondition); 1826 ValidResult lhsResult = getConstantBooleanValue(lhsCondition);
1644 if (lhsResult != null) { 1827 if (lhsResult != null) {
1645 if (identical(lhsResult, ValidResult.RESULT_TRUE) && isBarBar) { 1828 if (identical(lhsResult, ValidResult.RESULT_TRUE) && isBarBar) {
(...skipping 21 matching lines...) Expand all
1667 NodeList<Statement> statements = node.statements; 1850 NodeList<Statement> statements = node.statements;
1668 int size = statements.length; 1851 int size = statements.length;
1669 for (int i = 0; i < size; i++) { 1852 for (int i = 0; i < size; i++) {
1670 Statement currentStatement = statements[i]; 1853 Statement currentStatement = statements[i];
1671 safelyVisit(currentStatement); 1854 safelyVisit(currentStatement);
1672 if (currentStatement is ReturnStatement && i != size - 1) { 1855 if (currentStatement is ReturnStatement && i != size - 1) {
1673 Statement nextStatement = statements[i + 1]; 1856 Statement nextStatement = statements[i + 1];
1674 Statement lastStatement = statements[size - 1]; 1857 Statement lastStatement = statements[size - 1];
1675 int offset = nextStatement.offset; 1858 int offset = nextStatement.offset;
1676 int length = lastStatement.end - offset; 1859 int length = lastStatement.end - offset;
1677 _errorReporter.reportError3(HintCode.DEAD_CODE, offset, length, []); 1860 _errorReporter.reportError4(HintCode.DEAD_CODE, offset, length, []);
1678 return null; 1861 return null;
1679 } 1862 }
1680 } 1863 }
1681 return null; 1864 return null;
1682 } 1865 }
1866
1683 Object visitConditionalExpression(ConditionalExpression node) { 1867 Object visitConditionalExpression(ConditionalExpression node) {
1684 Expression conditionExpression = node.condition; 1868 Expression conditionExpression = node.condition;
1685 safelyVisit(conditionExpression); 1869 safelyVisit(conditionExpression);
1686 if (!isDebugConstant(conditionExpression)) { 1870 if (!isDebugConstant(conditionExpression)) {
1687 ValidResult result = getConstantBooleanValue(conditionExpression); 1871 ValidResult result = getConstantBooleanValue(conditionExpression);
1688 if (result != null) { 1872 if (result != null) {
1689 if (identical(result, ValidResult.RESULT_TRUE)) { 1873 if (identical(result, ValidResult.RESULT_TRUE)) {
1690 _errorReporter.reportError2(HintCode.DEAD_CODE, node.elseExpression, [ ]); 1874 _errorReporter.reportError2(HintCode.DEAD_CODE, node.elseExpression, [ ]);
1691 safelyVisit(node.thenExpression); 1875 safelyVisit(node.thenExpression);
1692 return null; 1876 return null;
1693 } else { 1877 } else {
1694 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenExpression, [ ]); 1878 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenExpression, [ ]);
1695 safelyVisit(node.elseExpression); 1879 safelyVisit(node.elseExpression);
1696 return null; 1880 return null;
1697 } 1881 }
1698 } 1882 }
1699 } 1883 }
1700 return super.visitConditionalExpression(node); 1884 return super.visitConditionalExpression(node);
1701 } 1885 }
1886
1702 Object visitIfStatement(IfStatement node) { 1887 Object visitIfStatement(IfStatement node) {
1703 Expression conditionExpression = node.condition; 1888 Expression conditionExpression = node.condition;
1704 safelyVisit(conditionExpression); 1889 safelyVisit(conditionExpression);
1705 if (!isDebugConstant(conditionExpression)) { 1890 if (!isDebugConstant(conditionExpression)) {
1706 ValidResult result = getConstantBooleanValue(conditionExpression); 1891 ValidResult result = getConstantBooleanValue(conditionExpression);
1707 if (result != null) { 1892 if (result != null) {
1708 if (identical(result, ValidResult.RESULT_TRUE)) { 1893 if (identical(result, ValidResult.RESULT_TRUE)) {
1709 Statement elseStatement = node.elseStatement; 1894 Statement elseStatement = node.elseStatement;
1710 if (elseStatement != null) { 1895 if (elseStatement != null) {
1711 _errorReporter.reportError2(HintCode.DEAD_CODE, elseStatement, []); 1896 _errorReporter.reportError2(HintCode.DEAD_CODE, elseStatement, []);
1712 safelyVisit(node.thenStatement); 1897 safelyVisit(node.thenStatement);
1713 return null; 1898 return null;
1714 } 1899 }
1715 } else { 1900 } else {
1716 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, [] ); 1901 _errorReporter.reportError2(HintCode.DEAD_CODE, node.thenStatement, [] );
1717 safelyVisit(node.elseStatement); 1902 safelyVisit(node.elseStatement);
1718 return null; 1903 return null;
1719 } 1904 }
1720 } 1905 }
1721 } 1906 }
1722 return super.visitIfStatement(node); 1907 return super.visitIfStatement(node);
1723 } 1908 }
1909
1724 Object visitTryStatement(TryStatement node) { 1910 Object visitTryStatement(TryStatement node) {
1725 safelyVisit(node.body); 1911 safelyVisit(node.body);
1726 safelyVisit(node.finallyBlock); 1912 safelyVisit(node.finallyBlock);
1727 NodeList<CatchClause> catchClauses = node.catchClauses; 1913 NodeList<CatchClause> catchClauses = node.catchClauses;
1728 int numOfCatchClauses = catchClauses.length; 1914 int numOfCatchClauses = catchClauses.length;
1729 List<Type2> visitedTypes = new List<Type2>(); 1915 List<Type2> visitedTypes = new List<Type2>();
1730 for (int i = 0; i < numOfCatchClauses; i++) { 1916 for (int i = 0; i < numOfCatchClauses; i++) {
1731 CatchClause catchClause = catchClauses[i]; 1917 CatchClause catchClause = catchClauses[i];
1732 if (catchClause.onKeyword != null) { 1918 if (catchClause.onKeyword != null) {
1733 TypeName typeName = catchClause.exceptionType; 1919 TypeName typeName = catchClause.exceptionType;
1734 if (typeName != null && typeName.type != null) { 1920 if (typeName != null && typeName.type != null) {
1735 Type2 currentType = typeName.type; 1921 Type2 currentType = typeName.type;
1736 if (currentType.isObject) { 1922 if (currentType.isObject) {
1737 safelyVisit(catchClause); 1923 safelyVisit(catchClause);
1738 if (i + 1 != numOfCatchClauses) { 1924 if (i + 1 != numOfCatchClauses) {
1739 CatchClause nextCatchClause = catchClauses[i + 1]; 1925 CatchClause nextCatchClause = catchClauses[i + 1];
1740 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1926 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1741 int offset = nextCatchClause.offset; 1927 int offset = nextCatchClause.offset;
1742 int length = lastCatchClause.end - offset; 1928 int length = lastCatchClause.end - offset;
1743 _errorReporter.reportError3(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT CH, offset, length, []); 1929 _errorReporter.reportError4(HintCode.DEAD_CODE_CATCH_FOLLOWING_CAT CH, offset, length, []);
1744 return null; 1930 return null;
1745 } 1931 }
1746 } 1932 }
1747 for (Type2 type in visitedTypes) { 1933 for (Type2 type in visitedTypes) {
1748 if (currentType.isSubtypeOf(type)) { 1934 if (currentType.isSubtypeOf(type)) {
1749 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1935 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1750 int offset = catchClause.offset; 1936 int offset = catchClause.offset;
1751 int length = lastCatchClause.end - offset; 1937 int length = lastCatchClause.end - offset;
1752 _errorReporter.reportError3(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, o ffset, length, [currentType.displayName, type.displayName]); 1938 _errorReporter.reportError4(HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, o ffset, length, [currentType.displayName, type.displayName]);
1753 return null; 1939 return null;
1754 } 1940 }
1755 } 1941 }
1756 visitedTypes.add(currentType); 1942 visitedTypes.add(currentType);
1757 } 1943 }
1758 safelyVisit(catchClause); 1944 safelyVisit(catchClause);
1759 } else { 1945 } else {
1760 safelyVisit(catchClause); 1946 safelyVisit(catchClause);
1761 if (i + 1 != numOfCatchClauses) { 1947 if (i + 1 != numOfCatchClauses) {
1762 CatchClause nextCatchClause = catchClauses[i + 1]; 1948 CatchClause nextCatchClause = catchClauses[i + 1];
1763 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1]; 1949 CatchClause lastCatchClause = catchClauses[numOfCatchClauses - 1];
1764 int offset = nextCatchClause.offset; 1950 int offset = nextCatchClause.offset;
1765 int length = lastCatchClause.end - offset; 1951 int length = lastCatchClause.end - offset;
1766 _errorReporter.reportError3(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length, []); 1952 _errorReporter.reportError4(HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, offset, length, []);
1767 return null; 1953 return null;
1768 } 1954 }
1769 } 1955 }
1770 } 1956 }
1771 return null; 1957 return null;
1772 } 1958 }
1959
1773 Object visitWhileStatement(WhileStatement node) { 1960 Object visitWhileStatement(WhileStatement node) {
1774 Expression conditionExpression = node.condition; 1961 Expression conditionExpression = node.condition;
1775 safelyVisit(conditionExpression); 1962 safelyVisit(conditionExpression);
1776 if (!isDebugConstant(conditionExpression)) { 1963 if (!isDebugConstant(conditionExpression)) {
1777 ValidResult result = getConstantBooleanValue(conditionExpression); 1964 ValidResult result = getConstantBooleanValue(conditionExpression);
1778 if (result != null) { 1965 if (result != null) {
1779 if (identical(result, ValidResult.RESULT_FALSE)) { 1966 if (identical(result, ValidResult.RESULT_FALSE)) {
1780 _errorReporter.reportError2(HintCode.DEAD_CODE, node.body, []); 1967 _errorReporter.reportError2(HintCode.DEAD_CODE, node.body, []);
1781 return null; 1968 return null;
1782 } 1969 }
1783 } 1970 }
1784 } 1971 }
1785 safelyVisit(node.body); 1972 safelyVisit(node.body);
1786 return null; 1973 return null;
1787 } 1974 }
1788 1975
1789 /** 1976 /**
1790 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is 1977 * Given some [Expression], this method returns [ValidResult#RESULT_TRUE] if i t is
1791 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the 1978 * `true`, [ValidResult#RESULT_FALSE] if it is `false`, or `null` if the
1792 * expression is not a constant boolean value. 1979 * expression is not a constant boolean value.
1793 * 1980 *
1794 * @param expression the expression to evaluate 1981 * @param expression the expression to evaluate
1795 * @return [ValidResult#RESULT_TRUE] if it is `true`, [ValidResult#RESULT_FALS E] 1982 * @return [ValidResult#RESULT_TRUE] if it is `true`, [ValidResult#RESULT_FALS E]
1796 * if it is `false`, or `null` if the expression is not a constant boo lean 1983 * if it is `false`, or `null` if the expression is not a constant boo lean
1797 * value 1984 * value
1798 */ 1985 */
1799 ValidResult getConstantBooleanValue(Expression expression) { 1986 ValidResult getConstantBooleanValue(Expression expression) {
1800 if (expression is BooleanLiteral) { 1987 if (expression is BooleanLiteral) {
1801 if (((expression as BooleanLiteral)).value) { 1988 if ((expression as BooleanLiteral).value) {
1802 return ValidResult.RESULT_TRUE; 1989 return ValidResult.RESULT_TRUE;
1803 } else { 1990 } else {
1804 return ValidResult.RESULT_FALSE; 1991 return ValidResult.RESULT_FALSE;
1805 } 1992 }
1806 } 1993 }
1807 return null; 1994 return null;
1808 } 1995 }
1809 1996
1810 /** 1997 /**
1811 * Return `true` if and only if the passed expression is resolved to a constan t variable. 1998 * Return `true` if and only if the passed expression is resolved to a constan t variable.
(...skipping 22 matching lines...) Expand all
1834 * If the given node is not `null`, visit this instance of the dead code verif ier. 2021 * If the given node is not `null`, visit this instance of the dead code verif ier.
1835 * 2022 *
1836 * @param node the node to be visited 2023 * @param node the node to be visited
1837 */ 2024 */
1838 void safelyVisit(ASTNode node) { 2025 void safelyVisit(ASTNode node) {
1839 if (node != null) { 2026 if (node != null) {
1840 node.accept(this); 2027 node.accept(this);
1841 } 2028 }
1842 } 2029 }
1843 } 2030 }
2031
1844 /** 2032 /**
1845 * Instances of the class `HintGenerator` traverse a library's worth of dart cod e at a time to 2033 * Instances of the class `HintGenerator` traverse a library's worth of dart cod e at a time to
1846 * generate hints over the set of sources. 2034 * generate hints over the set of sources.
1847 * 2035 *
1848 * @see HintCode 2036 * @see HintCode
1849 * @coverage dart.engine.resolver 2037 * @coverage dart.engine.resolver
1850 */ 2038 */
1851 class HintGenerator { 2039 class HintGenerator {
1852 List<CompilationUnit> _compilationUnits; 2040 List<CompilationUnit> _compilationUnits;
2041
1853 AnalysisContext _context; 2042 AnalysisContext _context;
2043
1854 AnalysisErrorListener _errorListener; 2044 AnalysisErrorListener _errorListener;
2045
1855 ImportsVerifier _importsVerifier; 2046 ImportsVerifier _importsVerifier;
2047
1856 bool _enableDart2JSHints = false; 2048 bool _enableDart2JSHints = false;
2049
1857 HintGenerator(List<CompilationUnit> compilationUnits, AnalysisContext context, AnalysisErrorListener errorListener) { 2050 HintGenerator(List<CompilationUnit> compilationUnits, AnalysisContext context, AnalysisErrorListener errorListener) {
1858 this._compilationUnits = compilationUnits; 2051 this._compilationUnits = compilationUnits;
1859 this._context = context; 2052 this._context = context;
1860 this._errorListener = errorListener; 2053 this._errorListener = errorListener;
1861 LibraryElement library = compilationUnits[0].element.library; 2054 LibraryElement library = compilationUnits[0].element.library;
1862 _importsVerifier = new ImportsVerifier(library); 2055 _importsVerifier = new ImportsVerifier(library);
1863 _enableDart2JSHints = context.analysisOptions.dart2jsHint; 2056 _enableDart2JSHints = context.analysisOptions.dart2jsHint;
1864 } 2057 }
2058
1865 void generateForLibrary() { 2059 void generateForLibrary() {
1866 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.hints.star t(); 2060 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.hints.star t();
1867 try { 2061 try {
1868 for (int i = 0; i < _compilationUnits.length; i++) { 2062 for (int i = 0; i < _compilationUnits.length; i++) {
1869 CompilationUnitElement element = _compilationUnits[i].element; 2063 CompilationUnitElement element = _compilationUnits[i].element;
1870 if (element != null) { 2064 if (element != null) {
1871 if (i == 0) { 2065 if (i == 0) {
1872 _importsVerifier.inDefiningCompilationUnit = true; 2066 _importsVerifier.inDefiningCompilationUnit = true;
1873 generateForCompilationUnit(_compilationUnits[i], element.source); 2067 generateForCompilationUnit(_compilationUnits[i], element.source);
1874 _importsVerifier.inDefiningCompilationUnit = false; 2068 _importsVerifier.inDefiningCompilationUnit = false;
1875 } else { 2069 } else {
1876 generateForCompilationUnit(_compilationUnits[i], element.source); 2070 generateForCompilationUnit(_compilationUnits[i], element.source);
1877 } 2071 }
1878 } 2072 }
1879 } 2073 }
1880 ErrorReporter definingCompilationUnitErrorReporter = new ErrorReporter(_er rorListener, _compilationUnits[0].element.source); 2074 ErrorReporter definingCompilationUnitErrorReporter = new ErrorReporter(_er rorListener, _compilationUnits[0].element.source);
1881 _importsVerifier.generateDuplicateImportHints(definingCompilationUnitError Reporter); 2075 _importsVerifier.generateDuplicateImportHints(definingCompilationUnitError Reporter);
1882 _importsVerifier.generateUnusedImportHints(definingCompilationUnitErrorRep orter); 2076 _importsVerifier.generateUnusedImportHints(definingCompilationUnitErrorRep orter);
1883 } finally { 2077 } finally {
1884 timeCounter.stop(); 2078 timeCounter.stop();
1885 } 2079 }
1886 } 2080 }
2081
1887 void generateForCompilationUnit(CompilationUnit unit, Source source) { 2082 void generateForCompilationUnit(CompilationUnit unit, Source source) {
1888 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 2083 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
1889 _importsVerifier.visitCompilationUnit(unit); 2084 _importsVerifier.visitCompilationUnit(unit);
1890 new DeadCodeVerifier(errorReporter).visitCompilationUnit(unit); 2085 new DeadCodeVerifier(errorReporter).visitCompilationUnit(unit);
1891 if (_enableDart2JSHints) { 2086 if (_enableDart2JSHints) {
1892 new Dart2JSVerifier(errorReporter).visitCompilationUnit(unit); 2087 new Dart2JSVerifier(errorReporter).visitCompilationUnit(unit);
1893 } 2088 }
1894 new BestPracticesVerifier(errorReporter).visitCompilationUnit(unit); 2089 new BestPracticesVerifier(errorReporter).visitCompilationUnit(unit);
1895 } 2090 }
1896 } 2091 }
2092
1897 /** 2093 /**
1898 * Instances of the class `ImportsVerifier` visit all of the referenced librarie s in the 2094 * Instances of the class `ImportsVerifier` visit all of the referenced librarie s in the
1899 * source code verifying that all of the imports are used, otherwise a 2095 * source code verifying that all of the imports are used, otherwise a
1900 * [HintCode#UNUSED_IMPORT] is generated with 2096 * [HintCode#UNUSED_IMPORT] is generated with
1901 * [generateUnusedImportHints]. 2097 * [generateUnusedImportHints].
1902 * 2098 *
1903 * While this class does not yet have support for an "Organize Imports" action, this logic built up 2099 * While this class does not yet have support for an "Organize Imports" action, this logic built up
1904 * in this class could be used for such an action in the future. 2100 * in this class could be used for such an action in the future.
1905 * 2101 *
1906 * @coverage dart.engine.resolver 2102 * @coverage dart.engine.resolver
1907 */ 2103 */
1908 class ImportsVerifier extends RecursiveASTVisitor<Object> { 2104 class ImportsVerifier extends RecursiveASTVisitor<Object> {
1909
1910 /** 2105 /**
1911 * This is set to `true` if the current compilation unit which is being visite d is the 2106 * This is set to `true` if the current compilation unit which is being visite d is the
1912 * defining compilation unit for the library, its value can be set with 2107 * defining compilation unit for the library, its value can be set with
1913 * [setInDefiningCompilationUnit]. 2108 * [setInDefiningCompilationUnit].
1914 */ 2109 */
1915 bool _inDefiningCompilationUnit = false; 2110 bool _inDefiningCompilationUnit = false;
1916 2111
1917 /** 2112 /**
1918 * The current library. 2113 * The current library.
1919 */ 2114 */
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 ImportElement importElement = unusedImport.element; 2200 ImportElement importElement = unusedImport.element;
2006 if (importElement != null) { 2201 if (importElement != null) {
2007 LibraryElement libraryElement = importElement.importedLibrary; 2202 LibraryElement libraryElement = importElement.importedLibrary;
2008 if (libraryElement != null && libraryElement.isDartCore) { 2203 if (libraryElement != null && libraryElement.isDartCore) {
2009 continue; 2204 continue;
2010 } 2205 }
2011 } 2206 }
2012 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []); 2207 errorReporter.reportError2(HintCode.UNUSED_IMPORT, unusedImport.uri, []);
2013 } 2208 }
2014 } 2209 }
2210
2015 Object visitCompilationUnit(CompilationUnit node) { 2211 Object visitCompilationUnit(CompilationUnit node) {
2016 if (_inDefiningCompilationUnit) { 2212 if (_inDefiningCompilationUnit) {
2017 NodeList<Directive> directives = node.directives; 2213 NodeList<Directive> directives = node.directives;
2018 for (Directive directive in directives) { 2214 for (Directive directive in directives) {
2019 if (directive is ImportDirective) { 2215 if (directive is ImportDirective) {
2020 ImportDirective importDirective = directive as ImportDirective; 2216 ImportDirective importDirective = directive as ImportDirective;
2021 LibraryElement libraryElement = importDirective.uriElement; 2217 LibraryElement libraryElement = importDirective.uriElement;
2022 if (libraryElement != null) { 2218 if (libraryElement != null) {
2023 _unusedImports.add(importDirective); 2219 _unusedImports.add(importDirective);
2024 if (importDirective.asToken != null) { 2220 if (importDirective.asToken != null) {
(...skipping 26 matching lines...) Expand all
2051 _duplicateImports.add(nextDirective); 2247 _duplicateImports.add(nextDirective);
2052 } else { 2248 } else {
2053 _duplicateImports.add(currentDirective); 2249 _duplicateImports.add(currentDirective);
2054 } 2250 }
2055 } 2251 }
2056 currentDirective = nextDirective; 2252 currentDirective = nextDirective;
2057 } 2253 }
2058 } 2254 }
2059 return super.visitCompilationUnit(node); 2255 return super.visitCompilationUnit(node);
2060 } 2256 }
2257
2061 Object visitExportDirective(ExportDirective node) { 2258 Object visitExportDirective(ExportDirective node) {
2062 visitMetadata(node.metadata); 2259 visitMetadata(node.metadata);
2063 return null; 2260 return null;
2064 } 2261 }
2262
2065 Object visitImportDirective(ImportDirective node) { 2263 Object visitImportDirective(ImportDirective node) {
2066 visitMetadata(node.metadata); 2264 visitMetadata(node.metadata);
2067 return null; 2265 return null;
2068 } 2266 }
2267
2069 Object visitLibraryDirective(LibraryDirective node) { 2268 Object visitLibraryDirective(LibraryDirective node) {
2070 visitMetadata(node.metadata); 2269 visitMetadata(node.metadata);
2071 return null; 2270 return null;
2072 } 2271 }
2272
2073 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 2273 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
2074 SimpleIdentifier prefixIdentifier = node.prefix; 2274 SimpleIdentifier prefixIdentifier = node.prefix;
2075 Element element = prefixIdentifier.staticElement; 2275 Element element = prefixIdentifier.staticElement;
2076 if (element is PrefixElement) { 2276 if (element is PrefixElement) {
2077 _unusedImports.remove(_prefixElementMap[element]); 2277 _unusedImports.remove(_prefixElementMap[element]);
2078 return null; 2278 return null;
2079 } 2279 }
2080 return visitIdentifier(element, prefixIdentifier.name); 2280 return visitIdentifier(element, prefixIdentifier.name);
2081 } 2281 }
2282
2082 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.st aticElement, node.name); 2283 Object visitSimpleIdentifier(SimpleIdentifier node) => visitIdentifier(node.st aticElement, node.name);
2284
2083 void set inDefiningCompilationUnit(bool inDefiningCompilationUnit) { 2285 void set inDefiningCompilationUnit(bool inDefiningCompilationUnit) {
2084 this._inDefiningCompilationUnit = inDefiningCompilationUnit; 2286 this._inDefiningCompilationUnit = inDefiningCompilationUnit;
2085 } 2287 }
2086 2288
2087 /** 2289 /**
2088 * Recursively add any exported library elements into the [libraryMap]. 2290 * Recursively add any exported library elements into the [libraryMap].
2089 */ 2291 */
2090 void addAdditionalLibrariesForExports(LibraryElement library, ImportDirective importDirective, List<LibraryElement> exportPath) { 2292 void addAdditionalLibrariesForExports(LibraryElement library, ImportDirective importDirective, List<LibraryElement> exportPath) {
2091 if (exportPath.contains(library)) { 2293 if (exportPath.contains(library)) {
2092 return; 2294 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 * needing to check to see if a list needs to be created. 2328 * needing to check to see if a list needs to be created.
2127 */ 2329 */
2128 void putIntoLibraryMap(LibraryElement libraryElement, ImportDirective importDi rective) { 2330 void putIntoLibraryMap(LibraryElement libraryElement, ImportDirective importDi rective) {
2129 List<ImportDirective> importList = _libraryMap[libraryElement]; 2331 List<ImportDirective> importList = _libraryMap[libraryElement];
2130 if (importList == null) { 2332 if (importList == null) {
2131 importList = new List<ImportDirective>(); 2333 importList = new List<ImportDirective>();
2132 _libraryMap[libraryElement] = importList; 2334 _libraryMap[libraryElement] = importList;
2133 } 2335 }
2134 importList.add(importDirective); 2336 importList.add(importDirective);
2135 } 2337 }
2338
2136 Object visitIdentifier(Element element, String name) { 2339 Object visitIdentifier(Element element, String name) {
2137 if (element == null) { 2340 if (element == null) {
2138 return null; 2341 return null;
2139 } 2342 }
2140 if (element is MultiplyDefinedElement) { 2343 if (element is MultiplyDefinedElement) {
2141 MultiplyDefinedElement multiplyDefinedElement = element as MultiplyDefined Element; 2344 MultiplyDefinedElement multiplyDefinedElement = element as MultiplyDefined Element;
2142 for (Element elt in multiplyDefinedElement.conflictingElements) { 2345 for (Element elt in multiplyDefinedElement.conflictingElements) {
2143 visitIdentifier(elt, name); 2346 visitIdentifier(elt, name);
2144 } 2347 }
2145 return null; 2348 return null;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 * 2382 *
2180 * @param annotations the list of annotations to visit 2383 * @param annotations the list of annotations to visit
2181 */ 2384 */
2182 void visitMetadata(NodeList<Annotation> annotations) { 2385 void visitMetadata(NodeList<Annotation> annotations) {
2183 for (Annotation annotation in annotations) { 2386 for (Annotation annotation in annotations) {
2184 Identifier name = annotation.name; 2387 Identifier name = annotation.name;
2185 visitIdentifier(name.staticElement, name.name); 2388 visitIdentifier(name.staticElement, name.name);
2186 } 2389 }
2187 } 2390 }
2188 } 2391 }
2392
2189 /** 2393 /**
2190 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from 2394 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from
2191 * pub best practices. 2395 * pub best practices.
2192 */ 2396 */
2193 class PubVerifier extends RecursiveASTVisitor<Object> { 2397 class PubVerifier extends RecursiveASTVisitor<Object> {
2194 static String _PUBSPEC_YAML = "pubspec.yaml"; 2398 static String _PUBSPEC_YAML = "pubspec.yaml";
2195 2399
2196 /** 2400 /**
2197 * The analysis context containing the sources to be analyzed 2401 * The analysis context containing the sources to be analyzed
2198 */ 2402 */
2199 AnalysisContext _context; 2403 AnalysisContext _context;
2200 2404
2201 /** 2405 /**
2202 * The error reporter by which errors will be reported. 2406 * The error reporter by which errors will be reported.
2203 */ 2407 */
2204 ErrorReporter _errorReporter; 2408 ErrorReporter _errorReporter;
2409
2205 PubVerifier(AnalysisContext context, ErrorReporter errorReporter) { 2410 PubVerifier(AnalysisContext context, ErrorReporter errorReporter) {
2206 this._context = context; 2411 this._context = context;
2207 this._errorReporter = errorReporter; 2412 this._errorReporter = errorReporter;
2208 } 2413 }
2414
2209 Object visitImportDirective(ImportDirective directive) { 2415 Object visitImportDirective(ImportDirective directive) {
2210 return null; 2416 return null;
2211 } 2417 }
2212 2418
2213 /** 2419 /**
2214 * This verifies that the passed file import directive is not contained in a s ource inside a 2420 * This verifies that the passed file import directive is not contained in a s ource inside a
2215 * package "lib" directory hierarchy referencing a source outside that package "lib" directory 2421 * package "lib" directory hierarchy referencing a source outside that package "lib" directory
2216 * hierarchy. 2422 * hierarchy.
2217 * 2423 *
2218 * @param uriLiteral the import URL (not `null`) 2424 * @param uriLiteral the import URL (not `null`)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 } 2469 }
2264 int pathIndex = path.indexOf("/lib/"); 2470 int pathIndex = path.indexOf("/lib/");
2265 while (pathIndex != -1) { 2471 while (pathIndex != -1) {
2266 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, pa thIndex + 1)) { 2472 if (checkForFileImportOutsideLibReferencesFileInside2(uriLiteral, path, pa thIndex + 1)) {
2267 return true; 2473 return true;
2268 } 2474 }
2269 pathIndex = JavaString.indexOf(path, "/lib/", pathIndex + 4); 2475 pathIndex = JavaString.indexOf(path, "/lib/", pathIndex + 4);
2270 } 2476 }
2271 return false; 2477 return false;
2272 } 2478 }
2479
2273 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera l, String path, int pathIndex) { 2480 bool checkForFileImportOutsideLibReferencesFileInside2(StringLiteral uriLitera l, String path, int pathIndex) {
2274 Source source = getSource(uriLiteral); 2481 Source source = getSource(uriLiteral);
2275 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; 2482 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML;
2276 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub specPath); 2483 Source pubspecSource = _context.sourceFactory.resolveUri(source, relativePub specPath);
2277 if (pubspecSource == null || !pubspecSource.exists()) { 2484 if (pubspecSource == null || !pubspecSource.exists()) {
2278 return false; 2485 return false;
2279 } 2486 }
2280 String fullName = getSourceFullName(source); 2487 String fullName = getSourceFullName(source);
2281 if (fullName != null) { 2488 if (fullName != null) {
2282 if (!fullName.contains("/lib/")) { 2489 if (!fullName.contains("/lib/")) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 String getSourceFullName(Source source) { 2538 String getSourceFullName(Source source) {
2332 if (source != null) { 2539 if (source != null) {
2333 String fullName = source.fullName; 2540 String fullName = source.fullName;
2334 if (fullName != null) { 2541 if (fullName != null) {
2335 return fullName.replaceAll(r'\', '/'); 2542 return fullName.replaceAll(r'\', '/');
2336 } 2543 }
2337 } 2544 }
2338 return null; 2545 return null;
2339 } 2546 }
2340 } 2547 }
2548
2549 /**
2550 * Instances of the class `DeclarationMatcher` determine whether the element mod el defined by
2551 * a given AST structure matches an existing element model.
2552 */
2553 class DeclarationMatcher extends RecursiveASTVisitor<Object> {
2554 /**
2555 * The compilation unit containing the AST nodes being visited.
2556 */
2557 CompilationUnitElement _enclosingUnit;
2558
2559 /**
2560 * The function type alias containing the AST nodes being visited, or `null` i f we are not
2561 * in the scope of a function type alias.
2562 */
2563 FunctionTypeAliasElement _enclosingAlias;
2564
2565 /**
2566 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
2567 * a class.
2568 */
2569 ClassElement _enclosingClass;
2570
2571 /**
2572 * The method or function containing the AST nodes being visited, or `null` if we are not in
2573 * the scope of a method or function.
2574 */
2575 ExecutableElement _enclosingExecutable;
2576
2577 /**
2578 * The parameter containing the AST nodes being visited, or `null` if we are n ot in the
2579 * scope of a parameter.
2580 */
2581 ParameterElement _enclosingParameter;
2582
2583 /**
2584 * A set containing all of the elements in the element model that were defined by the old AST node
2585 * corresponding to the AST node being visited.
2586 */
2587 Set<Element> _allElements = new Set<Element>();
2588
2589 /**
2590 * A set containing all of the elements in the element model that were defined by the old AST node
2591 * corresponding to the AST node being visited that have not already been matc hed to nodes in the
2592 * AST structure being visited.
2593 */
2594 Set<Element> _unmatchedElements = new Set<Element>();
2595
2596 /**
2597 * Return `true` if the declarations within the given AST structure define an element model
2598 * that is equivalent to the corresponding elements rooted at the given elemen t.
2599 *
2600 * @param node the AST structure being compared to the element model
2601 * @param element the root of the element model being compared to the AST stru cture
2602 * @return `true` if the AST structure defines the same elements as those in t he given
2603 * element model
2604 */
2605 bool matches(ASTNode node, Element element) {
2606 captureEnclosingElements(element);
2607 gatherElements(element);
2608 try {
2609 node.accept(this);
2610 } on DeclarationMatcher_DeclarationMismatchException catch (exception) {
2611 return false;
2612 }
2613 return _unmatchedElements.isEmpty;
2614 }
2615
2616 Object visitCatchClause(CatchClause node) {
2617 SimpleIdentifier exceptionParameter = node.exceptionParameter;
2618 if (exceptionParameter != null) {
2619 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables;
2620 LocalVariableElement exceptionElement = find3(localVariables, exceptionPar ameter);
2621 processElement(exceptionElement);
2622 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
2623 if (stackTraceParameter != null) {
2624 LocalVariableElement stackTraceElement = find3(localVariables, stackTrac eParameter);
2625 processElement(stackTraceElement);
2626 }
2627 }
2628 return super.visitCatchClause(node);
2629 }
2630
2631 Object visitClassDeclaration(ClassDeclaration node) {
2632 ClassElement outerClass = _enclosingClass;
2633 try {
2634 SimpleIdentifier className = node.name;
2635 _enclosingClass = find3(_enclosingUnit.types, className);
2636 processElement(_enclosingClass);
2637 if (!hasConstructor(node)) {
2638 ConstructorElement constructor = _enclosingClass.unnamedConstructor;
2639 if (constructor.isSynthetic) {
2640 processElement(constructor);
2641 }
2642 }
2643 return super.visitClassDeclaration(node);
2644 } finally {
2645 _enclosingClass = outerClass;
2646 }
2647 }
2648
2649 Object visitClassTypeAlias(ClassTypeAlias node) {
2650 ClassElement outerClass = _enclosingClass;
2651 try {
2652 SimpleIdentifier className = node.name;
2653 _enclosingClass = find3(_enclosingUnit.types, className);
2654 processElement(_enclosingClass);
2655 return super.visitClassTypeAlias(node);
2656 } finally {
2657 _enclosingClass = outerClass;
2658 }
2659 }
2660
2661 Object visitCompilationUnit(CompilationUnit node) {
2662 processElement(_enclosingUnit);
2663 return super.visitCompilationUnit(node);
2664 }
2665
2666 Object visitConstructorDeclaration(ConstructorDeclaration node) {
2667 ExecutableElement outerExecutable = _enclosingExecutable;
2668 try {
2669 SimpleIdentifier constructorName = node.name;
2670 if (constructorName == null) {
2671 _enclosingExecutable = _enclosingClass.unnamedConstructor;
2672 } else {
2673 _enclosingExecutable = _enclosingClass.getNamedConstructor(constructorNa me.name);
2674 }
2675 processElement(_enclosingExecutable);
2676 return super.visitConstructorDeclaration(node);
2677 } finally {
2678 _enclosingExecutable = outerExecutable;
2679 }
2680 }
2681
2682 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
2683 SimpleIdentifier variableName = node.identifier;
2684 LocalVariableElement element = find3(_enclosingExecutable.localVariables, va riableName);
2685 processElement(element);
2686 return super.visitDeclaredIdentifier(node);
2687 }
2688
2689 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
2690 SimpleIdentifier parameterName = node.parameter.identifier;
2691 ParameterElement element = getElementForParameter(node, parameterName);
2692 Expression defaultValue = node.defaultValue;
2693 if (defaultValue != null) {
2694 ExecutableElement outerExecutable = _enclosingExecutable;
2695 try {
2696 if (element == null) {
2697 } else {
2698 _enclosingExecutable = element.initializer;
2699 }
2700 defaultValue.accept(this);
2701 } finally {
2702 _enclosingExecutable = outerExecutable;
2703 }
2704 processElement(_enclosingExecutable);
2705 }
2706 ParameterElement outerParameter = _enclosingParameter;
2707 try {
2708 _enclosingParameter = element;
2709 processElement(_enclosingParameter);
2710 return super.visitDefaultFormalParameter(node);
2711 } finally {
2712 _enclosingParameter = outerParameter;
2713 }
2714 }
2715
2716 Object visitExportDirective(ExportDirective node) {
2717 String uri = getStringValue(node.uri);
2718 if (uri != null) {
2719 LibraryElement library = _enclosingUnit.library;
2720 ExportElement exportElement = find5(library.exports, _enclosingUnit.contex t.sourceFactory.resolveUri(_enclosingUnit.source, uri));
2721 processElement(exportElement);
2722 }
2723 return super.visitExportDirective(node);
2724 }
2725
2726 Object visitFieldFormalParameter(FieldFormalParameter node) {
2727 if (node.parent is! DefaultFormalParameter) {
2728 SimpleIdentifier parameterName = node.identifier;
2729 ParameterElement element = getElementForParameter(node, parameterName);
2730 ParameterElement outerParameter = _enclosingParameter;
2731 try {
2732 _enclosingParameter = element;
2733 processElement(_enclosingParameter);
2734 return super.visitFieldFormalParameter(node);
2735 } finally {
2736 _enclosingParameter = outerParameter;
2737 }
2738 } else {
2739 return super.visitFieldFormalParameter(node);
2740 }
2741 }
2742
2743 Object visitFunctionDeclaration(FunctionDeclaration node) {
2744 ExecutableElement outerExecutable = _enclosingExecutable;
2745 try {
2746 SimpleIdentifier functionName = node.name;
2747 sc.Token property = node.propertyKeyword;
2748 if (property == null) {
2749 if (_enclosingExecutable != null) {
2750 _enclosingExecutable = find3(_enclosingExecutable.functions, functionN ame);
2751 } else {
2752 _enclosingExecutable = find3(_enclosingUnit.functions, functionName);
2753 }
2754 } else {
2755 PropertyAccessorElement accessor = find3(_enclosingUnit.accessors, funct ionName);
2756 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
2757 accessor = accessor.variable.setter;
2758 }
2759 _enclosingExecutable = accessor;
2760 }
2761 processElement(_enclosingExecutable);
2762 return super.visitFunctionDeclaration(node);
2763 } finally {
2764 _enclosingExecutable = outerExecutable;
2765 }
2766 }
2767
2768 Object visitFunctionExpression(FunctionExpression node) {
2769 if (node.parent is! FunctionDeclaration) {
2770 FunctionElement element = find2(_enclosingExecutable.functions, node.begin Token.offset);
2771 processElement(element);
2772 }
2773 ExecutableElement outerExecutable = _enclosingExecutable;
2774 try {
2775 _enclosingExecutable = node.element;
2776 processElement(_enclosingExecutable);
2777 return super.visitFunctionExpression(node);
2778 } finally {
2779 _enclosingExecutable = outerExecutable;
2780 }
2781 }
2782
2783 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
2784 FunctionTypeAliasElement outerAlias = _enclosingAlias;
2785 try {
2786 SimpleIdentifier aliasName = node.name;
2787 _enclosingAlias = find3(_enclosingUnit.functionTypeAliases, aliasName);
2788 processElement(_enclosingAlias);
2789 return super.visitFunctionTypeAlias(node);
2790 } finally {
2791 _enclosingAlias = outerAlias;
2792 }
2793 }
2794
2795 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
2796 if (node.parent is! DefaultFormalParameter) {
2797 SimpleIdentifier parameterName = node.identifier;
2798 ParameterElement element = getElementForParameter(node, parameterName);
2799 ParameterElement outerParameter = _enclosingParameter;
2800 try {
2801 _enclosingParameter = element;
2802 processElement(_enclosingParameter);
2803 return super.visitFunctionTypedFormalParameter(node);
2804 } finally {
2805 _enclosingParameter = outerParameter;
2806 }
2807 } else {
2808 return super.visitFunctionTypedFormalParameter(node);
2809 }
2810 }
2811
2812 Object visitImportDirective(ImportDirective node) {
2813 String uri = getStringValue(node.uri);
2814 if (uri != null) {
2815 LibraryElement library = _enclosingUnit.library;
2816 ImportElement importElement = find6(library.imports, _enclosingUnit.contex t.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix);
2817 processElement(importElement);
2818 }
2819 return super.visitImportDirective(node);
2820 }
2821
2822 Object visitLabeledStatement(LabeledStatement node) {
2823 for (Label label in node.labels) {
2824 SimpleIdentifier labelName = label.label;
2825 LabelElement element = find3(_enclosingExecutable.labels, labelName);
2826 processElement(element);
2827 }
2828 return super.visitLabeledStatement(node);
2829 }
2830
2831 Object visitMethodDeclaration(MethodDeclaration node) {
2832 ExecutableElement outerExecutable = _enclosingExecutable;
2833 try {
2834 sc.Token property = node.propertyKeyword;
2835 SimpleIdentifier methodName = node.name;
2836 String nameOfMethod = methodName.name;
2837 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
2838 nameOfMethod = "unary-";
2839 }
2840 if (property == null) {
2841 _enclosingExecutable = find4(_enclosingClass.methods, nameOfMethod, meth odName.offset);
2842 methodName.staticElement = _enclosingExecutable;
2843 } else {
2844 PropertyAccessorElement accessor = find3(_enclosingClass.accessors, meth odName);
2845 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
2846 accessor = accessor.variable.setter;
2847 methodName.staticElement = accessor;
2848 }
2849 _enclosingExecutable = accessor;
2850 }
2851 processElement(_enclosingExecutable);
2852 return super.visitMethodDeclaration(node);
2853 } finally {
2854 _enclosingExecutable = outerExecutable;
2855 }
2856 }
2857
2858 Object visitPartDirective(PartDirective node) {
2859 String uri = getStringValue(node.uri);
2860 if (uri != null) {
2861 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri);
2862 CompilationUnitElement element = find(_enclosingUnit.library.parts, partSo urce);
2863 processElement(element);
2864 }
2865 return super.visitPartDirective(node);
2866 }
2867
2868 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
2869 if (node.parent is! DefaultFormalParameter) {
2870 SimpleIdentifier parameterName = node.identifier;
2871 ParameterElement element = getElementForParameter(node, parameterName);
2872 ParameterElement outerParameter = _enclosingParameter;
2873 try {
2874 _enclosingParameter = element;
2875 processElement(_enclosingParameter);
2876 return super.visitSimpleFormalParameter(node);
2877 } finally {
2878 _enclosingParameter = outerParameter;
2879 }
2880 } else {
2881 }
2882 return super.visitSimpleFormalParameter(node);
2883 }
2884
2885 Object visitSwitchCase(SwitchCase node) {
2886 for (Label label in node.labels) {
2887 SimpleIdentifier labelName = label.label;
2888 LabelElement element = find3(_enclosingExecutable.labels, labelName);
2889 processElement(element);
2890 }
2891 return super.visitSwitchCase(node);
2892 }
2893
2894 Object visitSwitchDefault(SwitchDefault node) {
2895 for (Label label in node.labels) {
2896 SimpleIdentifier labelName = label.label;
2897 LabelElement element = find3(_enclosingExecutable.labels, labelName);
2898 processElement(element);
2899 }
2900 return super.visitSwitchDefault(node);
2901 }
2902
2903 Object visitTypeParameter(TypeParameter node) {
2904 SimpleIdentifier parameterName = node.name;
2905 TypeParameterElement element = null;
2906 if (_enclosingClass != null) {
2907 element = find3(_enclosingClass.typeParameters, parameterName);
2908 } else if (_enclosingAlias != null) {
2909 element = find3(_enclosingAlias.typeParameters, parameterName);
2910 }
2911 processElement(element);
2912 return super.visitTypeParameter(node);
2913 }
2914
2915 Object visitVariableDeclaration(VariableDeclaration node) {
2916 VariableElement element = null;
2917 SimpleIdentifier variableName = node.name;
2918 if (_enclosingExecutable != null) {
2919 element = find3(_enclosingExecutable.localVariables, variableName);
2920 }
2921 if (element == null && _enclosingClass != null) {
2922 element = find3(_enclosingClass.fields, variableName);
2923 }
2924 if (element == null && _enclosingUnit != null) {
2925 element = find3(_enclosingUnit.topLevelVariables, variableName);
2926 }
2927 Expression initializer = node.initializer;
2928 if (initializer != null) {
2929 ExecutableElement outerExecutable = _enclosingExecutable;
2930 try {
2931 if (element == null) {
2932 } else {
2933 _enclosingExecutable = element.initializer;
2934 }
2935 processElement(element);
2936 processElement(_enclosingExecutable);
2937 return super.visitVariableDeclaration(node);
2938 } finally {
2939 _enclosingExecutable = outerExecutable;
2940 }
2941 }
2942 return super.visitVariableDeclaration(node);
2943 }
2944
2945 void processElement(Element element) {
2946 if (element == null) {
2947 throw new DeclarationMatcher_DeclarationMismatchException();
2948 }
2949 if (!_allElements.contains(element)) {
2950 throw new DeclarationMatcher_DeclarationMismatchException();
2951 }
2952 _unmatchedElements.remove(element);
2953 }
2954
2955 /**
2956 * Given that the comparison is to begin with the given element, capture the e nclosing elements
2957 * that might be used while performing the comparison.
2958 *
2959 * @param element the element corresponding to the AST structure to be compare d
2960 */
2961 void captureEnclosingElements(Element element) {
2962 Element parent = element is CompilationUnitElement ? element : element.enclo singElement;
2963 while (parent != null) {
2964 if (parent is CompilationUnitElement) {
2965 _enclosingUnit = parent as CompilationUnitElement;
2966 } else if (parent is ClassElement) {
2967 if (_enclosingClass == null) {
2968 _enclosingClass = parent as ClassElement;
2969 }
2970 } else if (parent is FunctionTypeAliasElement) {
2971 if (_enclosingAlias == null) {
2972 _enclosingAlias = parent as FunctionTypeAliasElement;
2973 }
2974 } else if (parent is ExecutableElement) {
2975 if (_enclosingExecutable == null) {
2976 _enclosingExecutable = parent as ExecutableElement;
2977 }
2978 } else if (parent is ParameterElement) {
2979 if (_enclosingParameter == null) {
2980 _enclosingParameter = parent as ParameterElement;
2981 }
2982 }
2983 parent = parent.enclosingElement;
2984 }
2985 }
2986
2987 /**
2988 * Return the element for the part with the given source, or `null` if there i s no element
2989 * for the given source.
2990 *
2991 * @param parts the elements for the parts
2992 * @param partSource the source for the part whose element is to be returned
2993 * @return the element for the part with the given source
2994 */
2995 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou rce) {
2996 for (CompilationUnitElement part in parts) {
2997 if (part.source == partSource) {
2998 return part;
2999 }
3000 }
3001 return null;
3002 }
3003
3004 /**
3005 * Return the element in the given array of elements that was created for the declaration at the
3006 * given offset. This method should only be used when there is no name
3007 *
3008 * @param elements the elements of the appropriate kind that exist in the curr ent context
3009 * @param offset the offset of the name of the element to be returned
3010 * @return the element at the given offset
3011 */
3012 Element find2(List<Element> elements, int offset) => find4(elements, "", offse t);
3013
3014 /**
3015 * Return the element in the given array of elements that was created for the declaration with the
3016 * given name.
3017 *
3018 * @param elements the elements of the appropriate kind that exist in the curr ent context
3019 * @param identifier the name node in the declaration of the element to be ret urned
3020 * @return the element created for the declaration with the given name
3021 */
3022 Element find3(List<Element> elements, SimpleIdentifier identifier) => find4(el ements, identifier.name, identifier.offset);
3023
3024 /**
3025 * Return the element in the given array of elements that was created for the declaration with the
3026 * given name at the given offset.
3027 *
3028 * @param elements the elements of the appropriate kind that exist in the curr ent context
3029 * @param name the name of the element to be returned
3030 * @param offset the offset of the name of the element to be returned
3031 * @return the element with the given name and offset
3032 */
3033 Element find4(List<Element> elements, String name, int offset) {
3034 for (Element element in elements) {
3035 if (element.displayName == name && element.nameOffset == offset) {
3036 return element;
3037 }
3038 }
3039 return null;
3040 }
3041
3042 /**
3043 * Return the export element from the given array whose library has the given source, or
3044 * `null` if there is no such export.
3045 *
3046 * @param exports the export elements being searched
3047 * @param source the source of the library associated with the export element to being searched
3048 * for
3049 * @return the export element whose library has the given source
3050 */
3051 ExportElement find5(List<ExportElement> exports, Source source) {
3052 for (ExportElement export in exports) {
3053 if (export.exportedLibrary.source == source) {
3054 return export;
3055 }
3056 }
3057 return null;
3058 }
3059
3060 /**
3061 * Return the import element from the given array whose library has the given source and that has
3062 * the given prefix, or `null` if there is no such import.
3063 *
3064 * @param imports the import elements being searched
3065 * @param source the source of the library associated with the import element to being searched
3066 * for
3067 * @param prefix the prefix with which the library was imported
3068 * @return the import element whose library has the given source and prefix
3069 */
3070 ImportElement find6(List<ImportElement> imports, Source source, SimpleIdentifi er prefix) {
3071 for (ImportElement element in imports) {
3072 if (element.importedLibrary.source == source) {
3073 PrefixElement prefixElement = element.prefix;
3074 if (prefix == null) {
3075 if (prefixElement == null) {
3076 return element;
3077 }
3078 } else {
3079 if (prefixElement != null && prefix.name == prefixElement.displayName) {
3080 return element;
3081 }
3082 }
3083 }
3084 }
3085 return null;
3086 }
3087
3088 void gatherElements(Element element) {
3089 element.accept(new GeneralizingElementVisitor_7(this));
3090 }
3091
3092 /**
3093 * Search the most closely enclosing list of parameters for a parameter with t he given name.
3094 *
3095 * @param node the node defining the parameter with the given name
3096 * @param parameterName the name of the parameter being searched for
3097 * @return the element representing the parameter with that name
3098 */
3099 ParameterElement getElementForParameter(FormalParameter node, SimpleIdentifier parameterName) {
3100 List<ParameterElement> parameters = null;
3101 if (_enclosingParameter != null) {
3102 parameters = _enclosingParameter.parameters;
3103 }
3104 if (parameters == null && _enclosingExecutable != null) {
3105 parameters = _enclosingExecutable.parameters;
3106 }
3107 if (parameters == null && _enclosingAlias != null) {
3108 parameters = _enclosingAlias.parameters;
3109 }
3110 return parameters == null ? null : find3(parameters, parameterName);
3111 }
3112
3113 /**
3114 * Return the value of the given string literal, or `null` if the string is no t a constant
3115 * string without any string interpolation.
3116 *
3117 * @param literal the string literal whose value is to be returned
3118 * @return the value of the given string literal
3119 */
3120 String getStringValue(StringLiteral literal) {
3121 if (literal is StringInterpolation) {
3122 return null;
3123 }
3124 return literal.stringValue;
3125 }
3126
3127 /**
3128 * Return `true` if the given class defines at least one constructor.
3129 *
3130 * @param node the class being tested
3131 * @return `true` if the class defines at least one constructor
3132 */
3133 bool hasConstructor(ClassDeclaration node) {
3134 for (ClassMember member in node.members) {
3135 if (member is ConstructorDeclaration) {
3136 return true;
3137 }
3138 }
3139 return false;
3140 }
3141 }
3142
3143 /**
3144 * Instances of the class `DeclarationMismatchException` represent an exception that is
3145 * thrown when the element model defined by a given AST structure does not match an existing
3146 * element model.
3147 */
3148 class DeclarationMatcher_DeclarationMismatchException extends RuntimeException {
3149 }
3150
3151 class GeneralizingElementVisitor_7 extends GeneralizingElementVisitor<Object> {
3152 final DeclarationMatcher DeclarationMatcher_this;
3153
3154 GeneralizingElementVisitor_7(this.DeclarationMatcher_this) : super();
3155
3156 Object visitElement(Element element) {
3157 javaSetAdd(DeclarationMatcher_this._allElements, element);
3158 javaSetAdd(DeclarationMatcher_this._unmatchedElements, element);
3159 return super.visitElement(element);
3160 }
3161 }
3162
2341 /** 3163 /**
2342 * Instances of the class `DeclarationResolver` are used to resolve declarations in an AST 3164 * Instances of the class `DeclarationResolver` are used to resolve declarations in an AST
2343 * structure to already built elements. 3165 * structure to already built elements.
2344 */ 3166 */
2345 class DeclarationResolver extends RecursiveASTVisitor<Object> { 3167 class DeclarationResolver extends RecursiveASTVisitor<Object> {
2346
2347 /** 3168 /**
2348 * The compilation unit containing the AST nodes being visited. 3169 * The compilation unit containing the AST nodes being visited.
2349 */ 3170 */
2350 CompilationUnitElement _enclosingUnit; 3171 CompilationUnitElement _enclosingUnit;
2351 3172
2352 /** 3173 /**
2353 * The function type alias containing the AST nodes being visited, or `null` i f we are not 3174 * The function type alias containing the AST nodes being visited, or `null` i f we are not
2354 * in the scope of a function type alias. 3175 * in the scope of a function type alias.
2355 */ 3176 */
2356 FunctionTypeAliasElement _enclosingAlias; 3177 FunctionTypeAliasElement _enclosingAlias;
(...skipping 21 matching lines...) Expand all
2378 * element. 3199 * element.
2379 * 3200 *
2380 * @param unit the compilation unit to be resolved 3201 * @param unit the compilation unit to be resolved
2381 * @param element the root of the element model used to resolve the AST nodes 3202 * @param element the root of the element model used to resolve the AST nodes
2382 */ 3203 */
2383 void resolve(CompilationUnit unit, CompilationUnitElement element) { 3204 void resolve(CompilationUnit unit, CompilationUnitElement element) {
2384 _enclosingUnit = element; 3205 _enclosingUnit = element;
2385 unit.element = element; 3206 unit.element = element;
2386 unit.accept(this); 3207 unit.accept(this);
2387 } 3208 }
3209
2388 Object visitCatchClause(CatchClause node) { 3210 Object visitCatchClause(CatchClause node) {
2389 SimpleIdentifier exceptionParameter = node.exceptionParameter; 3211 SimpleIdentifier exceptionParameter = node.exceptionParameter;
2390 if (exceptionParameter != null) { 3212 if (exceptionParameter != null) {
2391 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables; 3213 List<LocalVariableElement> localVariables = _enclosingExecutable.localVari ables;
2392 find3(localVariables, exceptionParameter); 3214 find8(localVariables, exceptionParameter);
2393 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; 3215 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
2394 if (stackTraceParameter != null) { 3216 if (stackTraceParameter != null) {
2395 find3(localVariables, stackTraceParameter); 3217 find8(localVariables, stackTraceParameter);
2396 } 3218 }
2397 } 3219 }
2398 return super.visitCatchClause(node); 3220 return super.visitCatchClause(node);
2399 } 3221 }
3222
2400 Object visitClassDeclaration(ClassDeclaration node) { 3223 Object visitClassDeclaration(ClassDeclaration node) {
2401 ClassElement outerClass = _enclosingClass; 3224 ClassElement outerClass = _enclosingClass;
2402 try { 3225 try {
2403 SimpleIdentifier className = node.name; 3226 SimpleIdentifier className = node.name;
2404 _enclosingClass = find3(_enclosingUnit.types, className); 3227 _enclosingClass = find8(_enclosingUnit.types, className);
2405 return super.visitClassDeclaration(node); 3228 return super.visitClassDeclaration(node);
2406 } finally { 3229 } finally {
2407 _enclosingClass = outerClass; 3230 _enclosingClass = outerClass;
2408 } 3231 }
2409 } 3232 }
3233
2410 Object visitClassTypeAlias(ClassTypeAlias node) { 3234 Object visitClassTypeAlias(ClassTypeAlias node) {
2411 ClassElement outerClass = _enclosingClass; 3235 ClassElement outerClass = _enclosingClass;
2412 try { 3236 try {
2413 SimpleIdentifier className = node.name; 3237 SimpleIdentifier className = node.name;
2414 _enclosingClass = find3(_enclosingUnit.types, className); 3238 _enclosingClass = find8(_enclosingUnit.types, className);
2415 return super.visitClassTypeAlias(node); 3239 return super.visitClassTypeAlias(node);
2416 } finally { 3240 } finally {
2417 _enclosingClass = outerClass; 3241 _enclosingClass = outerClass;
2418 } 3242 }
2419 } 3243 }
3244
2420 Object visitConstructorDeclaration(ConstructorDeclaration node) { 3245 Object visitConstructorDeclaration(ConstructorDeclaration node) {
2421 ExecutableElement outerExecutable = _enclosingExecutable; 3246 ExecutableElement outerExecutable = _enclosingExecutable;
2422 try { 3247 try {
2423 SimpleIdentifier constructorName = node.name; 3248 SimpleIdentifier constructorName = node.name;
2424 if (constructorName == null) { 3249 if (constructorName == null) {
2425 _enclosingExecutable = _enclosingClass.unnamedConstructor; 3250 _enclosingExecutable = _enclosingClass.unnamedConstructor;
2426 } else { 3251 } else {
2427 _enclosingExecutable = _enclosingClass.getNamedConstructor(constructorNa me.name); 3252 _enclosingExecutable = _enclosingClass.getNamedConstructor(constructorNa me.name);
2428 constructorName.staticElement = _enclosingExecutable; 3253 constructorName.staticElement = _enclosingExecutable;
2429 } 3254 }
2430 node.element = _enclosingExecutable as ConstructorElement; 3255 node.element = _enclosingExecutable as ConstructorElement;
2431 return super.visitConstructorDeclaration(node); 3256 return super.visitConstructorDeclaration(node);
2432 } finally { 3257 } finally {
2433 _enclosingExecutable = outerExecutable; 3258 _enclosingExecutable = outerExecutable;
2434 } 3259 }
2435 } 3260 }
3261
2436 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 3262 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
2437 SimpleIdentifier variableName = node.identifier; 3263 SimpleIdentifier variableName = node.identifier;
2438 find3(_enclosingExecutable.localVariables, variableName); 3264 find8(_enclosingExecutable.localVariables, variableName);
2439 return super.visitDeclaredIdentifier(node); 3265 return super.visitDeclaredIdentifier(node);
2440 } 3266 }
3267
2441 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 3268 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
2442 SimpleIdentifier parameterName = node.parameter.identifier; 3269 SimpleIdentifier parameterName = node.parameter.identifier;
2443 ParameterElement element = getElementForParameter(node, parameterName); 3270 ParameterElement element = getElementForParameter(node, parameterName);
2444 Expression defaultValue = node.defaultValue; 3271 Expression defaultValue = node.defaultValue;
2445 if (defaultValue != null) { 3272 if (defaultValue != null) {
2446 ExecutableElement outerExecutable = _enclosingExecutable; 3273 ExecutableElement outerExecutable = _enclosingExecutable;
2447 try { 3274 try {
2448 if (element == null) { 3275 if (element == null) {
2449 } else { 3276 } else {
2450 _enclosingExecutable = element.initializer; 3277 _enclosingExecutable = element.initializer;
2451 } 3278 }
2452 defaultValue.accept(this); 3279 defaultValue.accept(this);
2453 } finally { 3280 } finally {
2454 _enclosingExecutable = outerExecutable; 3281 _enclosingExecutable = outerExecutable;
2455 } 3282 }
2456 } 3283 }
2457 ParameterElement outerParameter = _enclosingParameter; 3284 ParameterElement outerParameter = _enclosingParameter;
2458 try { 3285 try {
2459 _enclosingParameter = element; 3286 _enclosingParameter = element;
2460 return super.visitDefaultFormalParameter(node); 3287 return super.visitDefaultFormalParameter(node);
2461 } finally { 3288 } finally {
2462 _enclosingParameter = outerParameter; 3289 _enclosingParameter = outerParameter;
2463 } 3290 }
2464 } 3291 }
3292
2465 Object visitExportDirective(ExportDirective node) { 3293 Object visitExportDirective(ExportDirective node) {
2466 String uri = getStringValue(node.uri); 3294 String uri = getStringValue(node.uri);
2467 if (uri != null) { 3295 if (uri != null) {
2468 LibraryElement library = _enclosingUnit.library; 3296 LibraryElement library = _enclosingUnit.library;
2469 ExportElement exportElement = find5(library.exports, _enclosingUnit.contex t.sourceFactory.resolveUri(_enclosingUnit.source, uri)); 3297 ExportElement exportElement = find10(library.exports, _enclosingUnit.conte xt.sourceFactory.resolveUri(_enclosingUnit.source, uri));
2470 node.element = exportElement; 3298 node.element = exportElement;
2471 } 3299 }
2472 return super.visitExportDirective(node); 3300 return super.visitExportDirective(node);
2473 } 3301 }
3302
2474 Object visitFieldFormalParameter(FieldFormalParameter node) { 3303 Object visitFieldFormalParameter(FieldFormalParameter node) {
2475 if (node.parent is! DefaultFormalParameter) { 3304 if (node.parent is! DefaultFormalParameter) {
2476 SimpleIdentifier parameterName = node.identifier; 3305 SimpleIdentifier parameterName = node.identifier;
2477 ParameterElement element = getElementForParameter(node, parameterName); 3306 ParameterElement element = getElementForParameter(node, parameterName);
2478 ParameterElement outerParameter = _enclosingParameter; 3307 ParameterElement outerParameter = _enclosingParameter;
2479 try { 3308 try {
2480 _enclosingParameter = element; 3309 _enclosingParameter = element;
2481 return super.visitFieldFormalParameter(node); 3310 return super.visitFieldFormalParameter(node);
2482 } finally { 3311 } finally {
2483 _enclosingParameter = outerParameter; 3312 _enclosingParameter = outerParameter;
2484 } 3313 }
2485 } else { 3314 } else {
2486 return super.visitFieldFormalParameter(node); 3315 return super.visitFieldFormalParameter(node);
2487 } 3316 }
2488 } 3317 }
3318
2489 Object visitFunctionDeclaration(FunctionDeclaration node) { 3319 Object visitFunctionDeclaration(FunctionDeclaration node) {
2490 ExecutableElement outerExecutable = _enclosingExecutable; 3320 ExecutableElement outerExecutable = _enclosingExecutable;
2491 try { 3321 try {
2492 SimpleIdentifier functionName = node.name; 3322 SimpleIdentifier functionName = node.name;
2493 sc.Token property = node.propertyKeyword; 3323 sc.Token property = node.propertyKeyword;
2494 if (property == null) { 3324 if (property == null) {
2495 if (_enclosingExecutable != null) { 3325 if (_enclosingExecutable != null) {
2496 _enclosingExecutable = find3(_enclosingExecutable.functions, functionN ame); 3326 _enclosingExecutable = find8(_enclosingExecutable.functions, functionN ame);
2497 } else { 3327 } else {
2498 _enclosingExecutable = find3(_enclosingUnit.functions, functionName); 3328 _enclosingExecutable = find8(_enclosingUnit.functions, functionName);
2499 } 3329 }
2500 } else { 3330 } else {
2501 PropertyAccessorElement accessor = find3(_enclosingUnit.accessors, funct ionName); 3331 PropertyAccessorElement accessor = find8(_enclosingUnit.accessors, funct ionName);
2502 if (identical(((property as sc.KeywordToken)).keyword, sc.Keyword.SET)) { 3332 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
2503 accessor = accessor.variable.setter; 3333 accessor = accessor.variable.setter;
2504 functionName.staticElement = accessor; 3334 functionName.staticElement = accessor;
2505 } 3335 }
2506 _enclosingExecutable = accessor; 3336 _enclosingExecutable = accessor;
2507 } 3337 }
2508 node.functionExpression.element = _enclosingExecutable; 3338 node.functionExpression.element = _enclosingExecutable;
2509 return super.visitFunctionDeclaration(node); 3339 return super.visitFunctionDeclaration(node);
2510 } finally { 3340 } finally {
2511 _enclosingExecutable = outerExecutable; 3341 _enclosingExecutable = outerExecutable;
2512 } 3342 }
2513 } 3343 }
3344
2514 Object visitFunctionExpression(FunctionExpression node) { 3345 Object visitFunctionExpression(FunctionExpression node) {
2515 if (node.parent is! FunctionDeclaration) { 3346 if (node.parent is! FunctionDeclaration) {
2516 FunctionElement element = find2(_enclosingExecutable.functions, node.begin Token.offset); 3347 FunctionElement element = find7(_enclosingExecutable.functions, node.begin Token.offset);
2517 node.element = element; 3348 node.element = element;
2518 } 3349 }
2519 ExecutableElement outerExecutable = _enclosingExecutable; 3350 ExecutableElement outerExecutable = _enclosingExecutable;
2520 try { 3351 try {
2521 _enclosingExecutable = node.element; 3352 _enclosingExecutable = node.element;
2522 return super.visitFunctionExpression(node); 3353 return super.visitFunctionExpression(node);
2523 } finally { 3354 } finally {
2524 _enclosingExecutable = outerExecutable; 3355 _enclosingExecutable = outerExecutable;
2525 } 3356 }
2526 } 3357 }
3358
2527 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 3359 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
2528 FunctionTypeAliasElement outerAlias = _enclosingAlias; 3360 FunctionTypeAliasElement outerAlias = _enclosingAlias;
2529 try { 3361 try {
2530 SimpleIdentifier aliasName = node.name; 3362 SimpleIdentifier aliasName = node.name;
2531 _enclosingAlias = find3(_enclosingUnit.functionTypeAliases, aliasName); 3363 _enclosingAlias = find8(_enclosingUnit.functionTypeAliases, aliasName);
2532 return super.visitFunctionTypeAlias(node); 3364 return super.visitFunctionTypeAlias(node);
2533 } finally { 3365 } finally {
2534 _enclosingAlias = outerAlias; 3366 _enclosingAlias = outerAlias;
2535 } 3367 }
2536 } 3368 }
3369
2537 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 3370 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
2538 if (node.parent is! DefaultFormalParameter) { 3371 if (node.parent is! DefaultFormalParameter) {
2539 SimpleIdentifier parameterName = node.identifier; 3372 SimpleIdentifier parameterName = node.identifier;
2540 ParameterElement element = getElementForParameter(node, parameterName); 3373 ParameterElement element = getElementForParameter(node, parameterName);
2541 ParameterElement outerParameter = _enclosingParameter; 3374 ParameterElement outerParameter = _enclosingParameter;
2542 try { 3375 try {
2543 _enclosingParameter = element; 3376 _enclosingParameter = element;
2544 return super.visitFunctionTypedFormalParameter(node); 3377 return super.visitFunctionTypedFormalParameter(node);
2545 } finally { 3378 } finally {
2546 _enclosingParameter = outerParameter; 3379 _enclosingParameter = outerParameter;
2547 } 3380 }
2548 } else { 3381 } else {
2549 return super.visitFunctionTypedFormalParameter(node); 3382 return super.visitFunctionTypedFormalParameter(node);
2550 } 3383 }
2551 } 3384 }
3385
2552 Object visitImportDirective(ImportDirective node) { 3386 Object visitImportDirective(ImportDirective node) {
2553 String uri = getStringValue(node.uri); 3387 String uri = getStringValue(node.uri);
2554 if (uri != null) { 3388 if (uri != null) {
2555 LibraryElement library = _enclosingUnit.library; 3389 LibraryElement library = _enclosingUnit.library;
2556 ImportElement importElement = find6(library.imports, _enclosingUnit.contex t.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix); 3390 ImportElement importElement = find11(library.imports, _enclosingUnit.conte xt.sourceFactory.resolveUri(_enclosingUnit.source, uri), node.prefix);
2557 node.element = importElement; 3391 node.element = importElement;
2558 } 3392 }
2559 return super.visitImportDirective(node); 3393 return super.visitImportDirective(node);
2560 } 3394 }
3395
2561 Object visitLabeledStatement(LabeledStatement node) { 3396 Object visitLabeledStatement(LabeledStatement node) {
2562 for (Label label in node.labels) { 3397 for (Label label in node.labels) {
2563 SimpleIdentifier labelName = label.label; 3398 SimpleIdentifier labelName = label.label;
2564 find3(_enclosingExecutable.labels, labelName); 3399 find8(_enclosingExecutable.labels, labelName);
2565 } 3400 }
2566 return super.visitLabeledStatement(node); 3401 return super.visitLabeledStatement(node);
2567 } 3402 }
3403
2568 Object visitLibraryDirective(LibraryDirective node) { 3404 Object visitLibraryDirective(LibraryDirective node) {
2569 node.element = _enclosingUnit.library; 3405 node.element = _enclosingUnit.library;
2570 return super.visitLibraryDirective(node); 3406 return super.visitLibraryDirective(node);
2571 } 3407 }
3408
2572 Object visitMethodDeclaration(MethodDeclaration node) { 3409 Object visitMethodDeclaration(MethodDeclaration node) {
2573 ExecutableElement outerExecutable = _enclosingExecutable; 3410 ExecutableElement outerExecutable = _enclosingExecutable;
2574 try { 3411 try {
2575 sc.Token property = node.propertyKeyword; 3412 sc.Token property = node.propertyKeyword;
2576 SimpleIdentifier methodName = node.name; 3413 SimpleIdentifier methodName = node.name;
2577 String nameOfMethod = methodName.name; 3414 String nameOfMethod = methodName.name;
2578 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) { 3415 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
2579 nameOfMethod = "unary-"; 3416 nameOfMethod = "unary-";
2580 } 3417 }
2581 if (property == null) { 3418 if (property == null) {
2582 _enclosingExecutable = find4(_enclosingClass.methods, nameOfMethod, meth odName.offset); 3419 _enclosingExecutable = find9(_enclosingClass.methods, nameOfMethod, meth odName.offset);
2583 methodName.staticElement = _enclosingExecutable; 3420 methodName.staticElement = _enclosingExecutable;
2584 } else { 3421 } else {
2585 PropertyAccessorElement accessor = find3(_enclosingClass.accessors, meth odName); 3422 PropertyAccessorElement accessor = find8(_enclosingClass.accessors, meth odName);
2586 if (identical(((property as sc.KeywordToken)).keyword, sc.Keyword.SET)) { 3423 if (identical((property as sc.KeywordToken).keyword, sc.Keyword.SET)) {
2587 accessor = accessor.variable.setter; 3424 accessor = accessor.variable.setter;
2588 methodName.staticElement = accessor; 3425 methodName.staticElement = accessor;
2589 } 3426 }
2590 _enclosingExecutable = accessor; 3427 _enclosingExecutable = accessor;
2591 } 3428 }
2592 return super.visitMethodDeclaration(node); 3429 return super.visitMethodDeclaration(node);
2593 } finally { 3430 } finally {
2594 _enclosingExecutable = outerExecutable; 3431 _enclosingExecutable = outerExecutable;
2595 } 3432 }
2596 } 3433 }
3434
2597 Object visitPartDirective(PartDirective node) { 3435 Object visitPartDirective(PartDirective node) {
2598 String uri = getStringValue(node.uri); 3436 String uri = getStringValue(node.uri);
2599 if (uri != null) { 3437 if (uri != null) {
2600 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri); 3438 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri);
2601 node.element = find(_enclosingUnit.library.parts, partSource); 3439 node.element = find(_enclosingUnit.library.parts, partSource);
2602 } 3440 }
2603 return super.visitPartDirective(node); 3441 return super.visitPartDirective(node);
2604 } 3442 }
3443
2605 Object visitPartOfDirective(PartOfDirective node) { 3444 Object visitPartOfDirective(PartOfDirective node) {
2606 node.element = _enclosingUnit.library; 3445 node.element = _enclosingUnit.library;
2607 return super.visitPartOfDirective(node); 3446 return super.visitPartOfDirective(node);
2608 } 3447 }
3448
2609 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 3449 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
2610 if (node.parent is! DefaultFormalParameter) { 3450 if (node.parent is! DefaultFormalParameter) {
2611 SimpleIdentifier parameterName = node.identifier; 3451 SimpleIdentifier parameterName = node.identifier;
2612 ParameterElement element = getElementForParameter(node, parameterName); 3452 ParameterElement element = getElementForParameter(node, parameterName);
2613 ParameterElement outerParameter = _enclosingParameter; 3453 ParameterElement outerParameter = _enclosingParameter;
2614 try { 3454 try {
2615 _enclosingParameter = element; 3455 _enclosingParameter = element;
2616 return super.visitSimpleFormalParameter(node); 3456 return super.visitSimpleFormalParameter(node);
2617 } finally { 3457 } finally {
2618 _enclosingParameter = outerParameter; 3458 _enclosingParameter = outerParameter;
2619 } 3459 }
2620 } else { 3460 } else {
2621 } 3461 }
2622 return super.visitSimpleFormalParameter(node); 3462 return super.visitSimpleFormalParameter(node);
2623 } 3463 }
3464
2624 Object visitSwitchCase(SwitchCase node) { 3465 Object visitSwitchCase(SwitchCase node) {
2625 for (Label label in node.labels) { 3466 for (Label label in node.labels) {
2626 SimpleIdentifier labelName = label.label; 3467 SimpleIdentifier labelName = label.label;
2627 find3(_enclosingExecutable.labels, labelName); 3468 find8(_enclosingExecutable.labels, labelName);
2628 } 3469 }
2629 return super.visitSwitchCase(node); 3470 return super.visitSwitchCase(node);
2630 } 3471 }
3472
2631 Object visitSwitchDefault(SwitchDefault node) { 3473 Object visitSwitchDefault(SwitchDefault node) {
2632 for (Label label in node.labels) { 3474 for (Label label in node.labels) {
2633 SimpleIdentifier labelName = label.label; 3475 SimpleIdentifier labelName = label.label;
2634 find3(_enclosingExecutable.labels, labelName); 3476 find8(_enclosingExecutable.labels, labelName);
2635 } 3477 }
2636 return super.visitSwitchDefault(node); 3478 return super.visitSwitchDefault(node);
2637 } 3479 }
3480
2638 Object visitTypeParameter(TypeParameter node) { 3481 Object visitTypeParameter(TypeParameter node) {
2639 SimpleIdentifier parameterName = node.name; 3482 SimpleIdentifier parameterName = node.name;
2640 if (_enclosingClass != null) { 3483 if (_enclosingClass != null) {
2641 find3(_enclosingClass.typeParameters, parameterName); 3484 find8(_enclosingClass.typeParameters, parameterName);
2642 } else if (_enclosingAlias != null) { 3485 } else if (_enclosingAlias != null) {
2643 find3(_enclosingAlias.typeParameters, parameterName); 3486 find8(_enclosingAlias.typeParameters, parameterName);
2644 } 3487 }
2645 return super.visitTypeParameter(node); 3488 return super.visitTypeParameter(node);
2646 } 3489 }
3490
2647 Object visitVariableDeclaration(VariableDeclaration node) { 3491 Object visitVariableDeclaration(VariableDeclaration node) {
2648 VariableElement element = null; 3492 VariableElement element = null;
2649 SimpleIdentifier variableName = node.name; 3493 SimpleIdentifier variableName = node.name;
2650 if (_enclosingExecutable != null) { 3494 if (_enclosingExecutable != null) {
2651 element = find3(_enclosingExecutable.localVariables, variableName); 3495 element = find8(_enclosingExecutable.localVariables, variableName);
2652 } 3496 }
2653 if (element == null && _enclosingClass != null) { 3497 if (element == null && _enclosingClass != null) {
2654 element = find3(_enclosingClass.fields, variableName); 3498 element = find8(_enclosingClass.fields, variableName);
2655 } 3499 }
2656 if (element == null && _enclosingUnit != null) { 3500 if (element == null && _enclosingUnit != null) {
2657 element = find3(_enclosingUnit.topLevelVariables, variableName); 3501 element = find8(_enclosingUnit.topLevelVariables, variableName);
2658 } 3502 }
2659 Expression initializer = node.initializer; 3503 Expression initializer = node.initializer;
2660 if (initializer != null) { 3504 if (initializer != null) {
2661 ExecutableElement outerExecutable = _enclosingExecutable; 3505 ExecutableElement outerExecutable = _enclosingExecutable;
2662 try { 3506 try {
2663 if (element == null) { 3507 if (element == null) {
2664 } else { 3508 } else {
2665 _enclosingExecutable = element.initializer; 3509 _enclosingExecutable = element.initializer;
2666 } 3510 }
2667 return super.visitVariableDeclaration(node); 3511 return super.visitVariableDeclaration(node);
(...skipping 22 matching lines...) Expand all
2690 } 3534 }
2691 3535
2692 /** 3536 /**
2693 * Return the element in the given array of elements that was created for the declaration at the 3537 * Return the element in the given array of elements that was created for the declaration at the
2694 * given offset. This method should only be used when there is no name 3538 * given offset. This method should only be used when there is no name
2695 * 3539 *
2696 * @param elements the elements of the appropriate kind that exist in the curr ent context 3540 * @param elements the elements of the appropriate kind that exist in the curr ent context
2697 * @param offset the offset of the name of the element to be returned 3541 * @param offset the offset of the name of the element to be returned
2698 * @return the element at the given offset 3542 * @return the element at the given offset
2699 */ 3543 */
2700 Element find2(List<Element> elements, int offset) => find4(elements, "", offse t); 3544 Element find7(List<Element> elements, int offset) => find9(elements, "", offse t);
2701 3545
2702 /** 3546 /**
2703 * Return the element in the given array of elements that was created for the declaration with the 3547 * Return the element in the given array of elements that was created for the declaration with the
2704 * given name. 3548 * given name.
2705 * 3549 *
2706 * @param elements the elements of the appropriate kind that exist in the curr ent context 3550 * @param elements the elements of the appropriate kind that exist in the curr ent context
2707 * @param identifier the name node in the declaration of the element to be ret urned 3551 * @param identifier the name node in the declaration of the element to be ret urned
2708 * @return the element created for the declaration with the given name 3552 * @return the element created for the declaration with the given name
2709 */ 3553 */
2710 Element find3(List<Element> elements, SimpleIdentifier identifier) { 3554 Element find8(List<Element> elements, SimpleIdentifier identifier) {
2711 Element element = find4(elements, identifier.name, identifier.offset); 3555 Element element = find9(elements, identifier.name, identifier.offset);
2712 identifier.staticElement = element; 3556 identifier.staticElement = element;
2713 return element; 3557 return element;
2714 } 3558 }
2715 3559
2716 /** 3560 /**
2717 * Return the element in the given array of elements that was created for the declaration with the 3561 * Return the element in the given array of elements that was created for the declaration with the
2718 * given name at the given offset. 3562 * given name at the given offset.
2719 * 3563 *
2720 * @param elements the elements of the appropriate kind that exist in the curr ent context 3564 * @param elements the elements of the appropriate kind that exist in the curr ent context
2721 * @param name the name of the element to be returned 3565 * @param name the name of the element to be returned
2722 * @param offset the offset of the name of the element to be returned 3566 * @param offset the offset of the name of the element to be returned
2723 * @return the element with the given name and offset 3567 * @return the element with the given name and offset
2724 */ 3568 */
2725 Element find4(List<Element> elements, String name, int offset) { 3569 Element find9(List<Element> elements, String name, int offset) {
2726 for (Element element in elements) { 3570 for (Element element in elements) {
2727 if (element.displayName == name && element.nameOffset == offset) { 3571 if (element.displayName == name && element.nameOffset == offset) {
2728 return element; 3572 return element;
2729 } 3573 }
2730 } 3574 }
2731 return null; 3575 return null;
2732 } 3576 }
2733 3577
2734 /** 3578 /**
2735 * Return the export element from the given array whose library has the given source, or 3579 * Return the export element from the given array whose library has the given source, or
2736 * `null` if there is no such export. 3580 * `null` if there is no such export.
2737 * 3581 *
2738 * @param exports the export elements being searched 3582 * @param exports the export elements being searched
2739 * @param source the source of the library associated with the export element to being searched 3583 * @param source the source of the library associated with the export element to being searched
2740 * for 3584 * for
2741 * @return the export element whose library has the given source 3585 * @return the export element whose library has the given source
2742 */ 3586 */
2743 ExportElement find5(List<ExportElement> exports, Source source) { 3587 ExportElement find10(List<ExportElement> exports, Source source) {
2744 for (ExportElement export in exports) { 3588 for (ExportElement export in exports) {
2745 if (export.exportedLibrary.source == source) { 3589 if (export.exportedLibrary.source == source) {
2746 return export; 3590 return export;
2747 } 3591 }
2748 } 3592 }
2749 return null; 3593 return null;
2750 } 3594 }
2751 3595
2752 /** 3596 /**
2753 * Return the import element from the given array whose library has the given source and that has 3597 * Return the import element from the given array whose library has the given source and that has
2754 * the given prefix, or `null` if there is no such import. 3598 * the given prefix, or `null` if there is no such import.
2755 * 3599 *
2756 * @param imports the import elements being searched 3600 * @param imports the import elements being searched
2757 * @param source the source of the library associated with the import element to being searched 3601 * @param source the source of the library associated with the import element to being searched
2758 * for 3602 * for
2759 * @param prefix the prefix with which the library was imported 3603 * @param prefix the prefix with which the library was imported
2760 * @return the import element whose library has the given source and prefix 3604 * @return the import element whose library has the given source and prefix
2761 */ 3605 */
2762 ImportElement find6(List<ImportElement> imports, Source source, SimpleIdentifi er prefix) { 3606 ImportElement find11(List<ImportElement> imports, Source source, SimpleIdentif ier prefix) {
2763 for (ImportElement element in imports) { 3607 for (ImportElement element in imports) {
2764 if (element.importedLibrary.source == source) { 3608 if (element.importedLibrary.source == source) {
2765 PrefixElement prefixElement = element.prefix; 3609 PrefixElement prefixElement = element.prefix;
2766 if (prefix == null) { 3610 if (prefix == null) {
2767 if (prefixElement == null) { 3611 if (prefixElement == null) {
2768 return element; 3612 return element;
2769 } 3613 }
2770 } else { 3614 } else {
2771 if (prefixElement != null && prefix.name == prefixElement.displayName) { 3615 if (prefixElement != null && prefix.name == prefixElement.displayName) {
2772 return element; 3616 return element;
(...skipping 15 matching lines...) Expand all
2788 List<ParameterElement> parameters = null; 3632 List<ParameterElement> parameters = null;
2789 if (_enclosingParameter != null) { 3633 if (_enclosingParameter != null) {
2790 parameters = _enclosingParameter.parameters; 3634 parameters = _enclosingParameter.parameters;
2791 } 3635 }
2792 if (parameters == null && _enclosingExecutable != null) { 3636 if (parameters == null && _enclosingExecutable != null) {
2793 parameters = _enclosingExecutable.parameters; 3637 parameters = _enclosingExecutable.parameters;
2794 } 3638 }
2795 if (parameters == null && _enclosingAlias != null) { 3639 if (parameters == null && _enclosingAlias != null) {
2796 parameters = _enclosingAlias.parameters; 3640 parameters = _enclosingAlias.parameters;
2797 } 3641 }
2798 ParameterElement element = parameters == null ? null : find3(parameters, par ameterName); 3642 ParameterElement element = parameters == null ? null : find8(parameters, par ameterName);
2799 if (element == null) { 3643 if (element == null) {
2800 PrintStringWriter writer = new PrintStringWriter(); 3644 PrintStringWriter writer = new PrintStringWriter();
2801 writer.println("Invalid state found in the Analysis Engine:"); 3645 writer.println("Invalid state found in the Analysis Engine:");
2802 writer.println("DeclarationResolver.getElementForParameter() is visiting a parameter that does not appear to be in a method or function."); 3646 writer.println("DeclarationResolver.getElementForParameter() is visiting a parameter that does not appear to be in a method or function.");
2803 writer.println("Ancestors:"); 3647 writer.println("Ancestors:");
2804 ASTNode parent = node.parent; 3648 ASTNode parent = node.parent;
2805 while (parent != null) { 3649 while (parent != null) {
2806 writer.println(parent.runtimeType.toString()); 3650 writer.println(parent.runtimeType.toString());
2807 writer.println("---------"); 3651 writer.println("---------");
2808 parent = parent.parent; 3652 parent = parent.parent;
(...skipping 10 matching lines...) Expand all
2819 * @param literal the string literal whose value is to be returned 3663 * @param literal the string literal whose value is to be returned
2820 * @return the value of the given string literal 3664 * @return the value of the given string literal
2821 */ 3665 */
2822 String getStringValue(StringLiteral literal) { 3666 String getStringValue(StringLiteral literal) {
2823 if (literal is StringInterpolation) { 3667 if (literal is StringInterpolation) {
2824 return null; 3668 return null;
2825 } 3669 }
2826 return literal.stringValue; 3670 return literal.stringValue;
2827 } 3671 }
2828 } 3672 }
3673
2829 /** 3674 /**
2830 * Instances of the class `ElementResolver` are used by instances of [ResolverVi sitor] 3675 * Instances of the class `ElementResolver` are used by instances of [ResolverVi sitor]
2831 * to resolve references within the AST structure to the elements being referenc ed. The requirements 3676 * to resolve references within the AST structure to the elements being referenc ed. The requirements
2832 * for the element resolver are: 3677 * for the element resolver are:
2833 * <ol> 3678 * <ol>
2834 * * Every [SimpleIdentifier] should be resolved to the element to which it refe rs. 3679 * * Every [SimpleIdentifier] should be resolved to the element to which it refe rs.
2835 * Specifically: 3680 * Specifically:
2836 * 3681 *
2837 * * An identifier within the declaration of that name should resolve to the ele ment being 3682 * * An identifier within the declaration of that name should resolve to the ele ment being
2838 * declared. 3683 * declared.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 * [CompilationUnitElement]). 3719 * [CompilationUnitElement]).
2875 * </ol> 3720 * </ol>
2876 * Note that AST nodes that would represent elements that are not defined are no t resolved to 3721 * Note that AST nodes that would represent elements that are not defined are no t resolved to
2877 * anything. This includes such things as references to undeclared variables (wh ich is an error) and 3722 * anything. This includes such things as references to undeclared variables (wh ich is an error) and
2878 * names in hide and show combinators that are not defined in the imported libra ry (which is not an 3723 * names in hide and show combinators that are not defined in the imported libra ry (which is not an
2879 * error). 3724 * error).
2880 * 3725 *
2881 * @coverage dart.engine.resolver 3726 * @coverage dart.engine.resolver
2882 */ 3727 */
2883 class ElementResolver extends SimpleASTVisitor<Object> { 3728 class ElementResolver extends SimpleASTVisitor<Object> {
3729 /**
3730 * Checks if the given expression is the reference to the type, if it is then the
3731 * [ClassElement] is returned, otherwise `null` is returned.
3732 *
3733 * @param expr the expression to evaluate
3734 * @return the [ClassElement] if the given expression is the reference to the type, and
3735 * `null` otherwise
3736 */
3737 static ClassElementImpl getTypeReference(Expression expr) {
3738 if (expr is Identifier) {
3739 Identifier identifier = expr as Identifier;
3740 if (identifier.staticElement is ClassElementImpl) {
3741 return identifier.staticElement as ClassElementImpl;
3742 }
3743 }
3744 return null;
3745 }
2884 3746
2885 /** 3747 /**
2886 * @return `true` if the given identifier is the return type of a constructor declaration. 3748 * @return `true` if the given identifier is the return type of a constructor declaration.
2887 */ 3749 */
2888 static bool isConstructorReturnType(SimpleIdentifier node) { 3750 static bool isConstructorReturnType(SimpleIdentifier node) {
2889 ASTNode parent = node.parent; 3751 ASTNode parent = node.parent;
2890 if (parent is ConstructorDeclaration) { 3752 if (parent is ConstructorDeclaration) {
2891 ConstructorDeclaration constructor = parent as ConstructorDeclaration; 3753 ConstructorDeclaration constructor = parent as ConstructorDeclaration;
2892 return identical(constructor.returnType, node); 3754 return identical(constructor.returnType, node);
2893 } 3755 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2995 this._resolver = resolver; 3857 this._resolver = resolver;
2996 this._definingLibrary = resolver.definingLibrary; 3858 this._definingLibrary = resolver.definingLibrary;
2997 AnalysisOptions options = _definingLibrary.context.analysisOptions; 3859 AnalysisOptions options = _definingLibrary.context.analysisOptions;
2998 _strictMode = options.strictMode; 3860 _strictMode = options.strictMode;
2999 _enableHints = options.hint; 3861 _enableHints = options.hint;
3000 _dynamicType = resolver.typeProvider.dynamicType; 3862 _dynamicType = resolver.typeProvider.dynamicType;
3001 _typeType = resolver.typeProvider.typeType; 3863 _typeType = resolver.typeProvider.typeType;
3002 _subtypeManager = new SubtypeManager(); 3864 _subtypeManager = new SubtypeManager();
3003 _promoteManager = resolver.promoteManager; 3865 _promoteManager = resolver.promoteManager;
3004 } 3866 }
3867
3005 Object visitAssignmentExpression(AssignmentExpression node) { 3868 Object visitAssignmentExpression(AssignmentExpression node) {
3006 sc.Token operator = node.operator; 3869 sc.Token operator = node.operator;
3007 sc.TokenType operatorType = operator.type; 3870 sc.TokenType operatorType = operator.type;
3008 if (operatorType != sc.TokenType.EQ) { 3871 if (operatorType != sc.TokenType.EQ) {
3009 operatorType = operatorFromCompoundAssignment(operatorType); 3872 operatorType = operatorFromCompoundAssignment(operatorType);
3010 Expression leftHandSide = node.leftHandSide; 3873 Expression leftHandSide = node.leftHandSide;
3011 if (leftHandSide != null) { 3874 if (leftHandSide != null) {
3012 String methodName = operatorType.lexeme; 3875 String methodName = operatorType.lexeme;
3013 Type2 staticType = getStaticType(leftHandSide); 3876 Type2 staticType = getStaticType(leftHandSide);
3014 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName); 3877 MethodElement staticMethod = lookUpMethod(leftHandSide, staticType, meth odName);
(...skipping 11 matching lines...) Expand all
3026 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3889 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3027 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode; 3890 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_METHOD : HintCode.UNDEFINED_METHOD) as ErrorCode;
3028 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [ 3891 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [
3029 methodName, 3892 methodName,
3030 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3893 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3031 } 3894 }
3032 } 3895 }
3033 } 3896 }
3034 return null; 3897 return null;
3035 } 3898 }
3899
3036 Object visitBinaryExpression(BinaryExpression node) { 3900 Object visitBinaryExpression(BinaryExpression node) {
3037 sc.Token operator = node.operator; 3901 sc.Token operator = node.operator;
3038 if (operator.isUserDefinableOperator) { 3902 if (operator.isUserDefinableOperator) {
3039 Expression leftOperand = node.leftOperand; 3903 Expression leftOperand = node.leftOperand;
3040 if (leftOperand != null) { 3904 if (leftOperand != null) {
3041 String methodName = operator.lexeme; 3905 String methodName = operator.lexeme;
3042 Type2 staticType = getStaticType(leftOperand); 3906 Type2 staticType = getStaticType(leftOperand);
3043 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName); 3907 MethodElement staticMethod = lookUpMethod(leftOperand, staticType, metho dName);
3044 node.staticElement = staticMethod; 3908 node.staticElement = staticMethod;
3045 Type2 propagatedType = getPropagatedType(leftOperand); 3909 Type2 propagatedType = getPropagatedType(leftOperand);
3046 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName); 3910 MethodElement propagatedMethod = lookUpMethod(leftOperand, propagatedTyp e, methodName);
3047 node.propagatedElement = propagatedMethod; 3911 node.propagatedElement = propagatedMethod;
3048 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod)); 3912 bool shouldReportMissingMember_static = shouldReportMissingMember(static Type, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, propagatedMethod));
3049 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false; 3913 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_s tatic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMeth od) : false;
3050 if (shouldReportMissingMember_propagated) { 3914 if (shouldReportMissingMember_propagated) {
3051 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) { 3915 if (memberFoundInSubclass(propagatedType.element, methodName, true, fa lse)) {
3052 shouldReportMissingMember_propagated = false; 3916 shouldReportMissingMember_propagated = false;
3053 } 3917 }
3054 } 3918 }
3055 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) { 3919 if (shouldReportMissingMember_static || shouldReportMissingMember_propag ated) {
3056 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 3920 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWa rningCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3057 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [ 3921 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissin gMember_static ? staticType.element : propagatedType.element, errorCode, operato r, [
3058 methodName, 3922 methodName,
3059 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]); 3923 shouldReportMissingMember_static ? staticType.displayName : propag atedType.displayName]);
3060 } 3924 }
3061 } 3925 }
3062 } 3926 }
3063 return null; 3927 return null;
3064 } 3928 }
3929
3065 Object visitBreakStatement(BreakStatement node) { 3930 Object visitBreakStatement(BreakStatement node) {
3066 SimpleIdentifier labelNode = node.label; 3931 SimpleIdentifier labelNode = node.label;
3067 LabelElementImpl labelElement = lookupLabel(node, labelNode); 3932 LabelElementImpl labelElement = lookupLabel(node, labelNode);
3068 if (labelElement != null && labelElement.isOnSwitchMember) { 3933 if (labelElement != null && labelElement.isOnSwitchMember) {
3069 _resolver.reportError5(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab elNode, []); 3934 _resolver.reportError6(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, lab elNode, []);
3070 } 3935 }
3071 return null; 3936 return null;
3072 } 3937 }
3938
3073 Object visitClassDeclaration(ClassDeclaration node) { 3939 Object visitClassDeclaration(ClassDeclaration node) {
3074 setMetadata(node.element, node); 3940 setMetadata(node.element, node);
3075 return null; 3941 return null;
3076 } 3942 }
3943
3077 Object visitClassTypeAlias(ClassTypeAlias node) { 3944 Object visitClassTypeAlias(ClassTypeAlias node) {
3078 setMetadata(node.element, node); 3945 setMetadata(node.element, node);
3079 return null; 3946 return null;
3080 } 3947 }
3948
3081 Object visitCommentReference(CommentReference node) { 3949 Object visitCommentReference(CommentReference node) {
3082 Identifier identifier = node.identifier; 3950 Identifier identifier = node.identifier;
3083 if (identifier is SimpleIdentifier) { 3951 if (identifier is SimpleIdentifier) {
3084 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; 3952 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier;
3085 Element element = resolveSimpleIdentifier(simpleIdentifier); 3953 Element element = resolveSimpleIdentifier(simpleIdentifier);
3086 if (element == null) { 3954 if (element == null) {
3087 element = findImportWithoutPrefix(simpleIdentifier); 3955 element = findImportWithoutPrefix(simpleIdentifier);
3088 if (element is MultiplyDefinedElement) { 3956 if (element is MultiplyDefinedElement) {
3089 element = null; 3957 element = null;
3090 } 3958 }
3091 } 3959 }
3092 if (element == null) { 3960 if (element == null) {
3093 } else { 3961 } else {
3094 if (element.library == null || element.library != _definingLibrary) { 3962 if (element.library == null || element.library != _definingLibrary) {
3095 } 3963 }
3096 simpleIdentifier.staticElement = element; 3964 simpleIdentifier.staticElement = element;
3097 if (node.newKeyword != null) { 3965 if (node.newKeyword != null) {
3098 if (element is ClassElement) { 3966 if (element is ClassElement) {
3099 ConstructorElement constructor = ((element as ClassElement)).unnamed Constructor; 3967 ConstructorElement constructor = (element as ClassElement).unnamedCo nstructor;
3100 if (constructor == null) { 3968 if (constructor == null) {
3101 } else { 3969 } else {
3102 simpleIdentifier.staticElement = constructor; 3970 simpleIdentifier.staticElement = constructor;
3103 } 3971 }
3104 } else { 3972 } else {
3105 } 3973 }
3106 } 3974 }
3107 } 3975 }
3108 } else if (identifier is PrefixedIdentifier) { 3976 } else if (identifier is PrefixedIdentifier) {
3109 PrefixedIdentifier prefixedIdentifier = identifier as PrefixedIdentifier; 3977 PrefixedIdentifier prefixedIdentifier = identifier as PrefixedIdentifier;
3110 SimpleIdentifier prefix = prefixedIdentifier.prefix; 3978 SimpleIdentifier prefix = prefixedIdentifier.prefix;
3111 SimpleIdentifier name = prefixedIdentifier.identifier; 3979 SimpleIdentifier name = prefixedIdentifier.identifier;
3112 Element element = resolveSimpleIdentifier(prefix); 3980 Element element = resolveSimpleIdentifier(prefix);
3113 if (element == null) { 3981 if (element == null) {
3114 } else { 3982 } else {
3115 if (element is PrefixElement) { 3983 if (element is PrefixElement) {
3116 prefix.staticElement = element; 3984 prefix.staticElement = element;
3117 element = _resolver.nameScope.lookup(identifier, _definingLibrary); 3985 element = _resolver.nameScope.lookup(identifier, _definingLibrary);
3118 name.staticElement = element; 3986 name.staticElement = element;
3119 return null; 3987 return null;
3120 } 3988 }
3121 LibraryElement library = element.library; 3989 LibraryElement library = element.library;
3122 if (library == null) { 3990 if (library == null) {
3123 AnalysisEngine.instance.logger.logError("Found element with null libra ry: ${element.name}"); 3991 AnalysisEngine.instance.logger.logError("Found element with null libra ry: ${element.name}");
3124 } else if (library != _definingLibrary) { 3992 } else if (library != _definingLibrary) {
3125 } 3993 }
3126 name.staticElement = element; 3994 name.staticElement = element;
3127 if (node.newKeyword == null) { 3995 if (node.newKeyword == null) {
3128 if (element is ClassElement) { 3996 if (element is ClassElement) {
3129 Element memberElement = lookupGetterOrMethod(((element as ClassEleme nt)).type, name.name); 3997 Element memberElement = lookupGetterOrMethod((element as ClassElemen t).type, name.name);
3130 if (memberElement == null) { 3998 if (memberElement == null) {
3131 memberElement = ((element as ClassElement)).getNamedConstructor(na me.name); 3999 memberElement = (element as ClassElement).getNamedConstructor(name .name);
3132 if (memberElement == null) { 4000 if (memberElement == null) {
3133 memberElement = lookUpSetter(prefix, ((element as ClassElement)) .type, name.name); 4001 memberElement = lookUpSetter(prefix, (element as ClassElement).t ype, name.name);
3134 } 4002 }
3135 } 4003 }
3136 if (memberElement == null) { 4004 if (memberElement == null) {
3137 } else { 4005 } else {
3138 name.staticElement = memberElement; 4006 name.staticElement = memberElement;
3139 } 4007 }
3140 } else { 4008 } else {
3141 } 4009 }
3142 } else { 4010 } else {
3143 if (element is ClassElement) { 4011 if (element is ClassElement) {
3144 ConstructorElement constructor = ((element as ClassElement)).getName dConstructor(name.name); 4012 ConstructorElement constructor = (element as ClassElement).getNamedC onstructor(name.name);
3145 if (constructor == null) { 4013 if (constructor == null) {
3146 } else { 4014 } else {
3147 name.staticElement = constructor; 4015 name.staticElement = constructor;
3148 } 4016 }
3149 } else { 4017 } else {
3150 } 4018 }
3151 } 4019 }
3152 } 4020 }
3153 } 4021 }
3154 return null; 4022 return null;
3155 } 4023 }
4024
3156 Object visitConstructorDeclaration(ConstructorDeclaration node) { 4025 Object visitConstructorDeclaration(ConstructorDeclaration node) {
3157 super.visitConstructorDeclaration(node); 4026 super.visitConstructorDeclaration(node);
3158 ConstructorElement element = node.element; 4027 ConstructorElement element = node.element;
3159 if (element is ConstructorElementImpl) { 4028 if (element is ConstructorElementImpl) {
3160 ConstructorElementImpl constructorElement = element as ConstructorElementI mpl; 4029 ConstructorElementImpl constructorElement = element as ConstructorElementI mpl;
3161 ConstructorName redirectedNode = node.redirectedConstructor; 4030 ConstructorName redirectedNode = node.redirectedConstructor;
3162 if (redirectedNode != null) { 4031 if (redirectedNode != null) {
3163 ConstructorElement redirectedElement = redirectedNode.staticElement; 4032 ConstructorElement redirectedElement = redirectedNode.staticElement;
3164 constructorElement.redirectedConstructor = redirectedElement; 4033 constructorElement.redirectedConstructor = redirectedElement;
3165 } 4034 }
3166 for (ConstructorInitializer initializer in node.initializers) { 4035 for (ConstructorInitializer initializer in node.initializers) {
3167 if (initializer is RedirectingConstructorInvocation) { 4036 if (initializer is RedirectingConstructorInvocation) {
3168 ConstructorElement redirectedElement = ((initializer as RedirectingCon structorInvocation)).staticElement; 4037 ConstructorElement redirectedElement = (initializer as RedirectingCons tructorInvocation).staticElement;
3169 constructorElement.redirectedConstructor = redirectedElement; 4038 constructorElement.redirectedConstructor = redirectedElement;
3170 } 4039 }
3171 } 4040 }
3172 setMetadata(constructorElement, node); 4041 setMetadata(constructorElement, node);
3173 } 4042 }
3174 return null; 4043 return null;
3175 } 4044 }
4045
3176 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 4046 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
3177 SimpleIdentifier fieldName = node.fieldName; 4047 SimpleIdentifier fieldName = node.fieldName;
3178 ClassElement enclosingClass = _resolver.enclosingClass; 4048 ClassElement enclosingClass = _resolver.enclosingClass;
3179 FieldElement fieldElement = ((enclosingClass as ClassElementImpl)).getField( fieldName.name); 4049 FieldElement fieldElement = (enclosingClass as ClassElementImpl).getField(fi eldName.name);
3180 fieldName.staticElement = fieldElement; 4050 fieldName.staticElement = fieldElement;
3181 if (fieldElement == null || fieldElement.isSynthetic) { 4051 if (fieldElement == null || fieldElement.isSynthetic) {
3182 _resolver.reportError5(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_F IELD, node, [fieldName]); 4052 _resolver.reportError6(CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_F IELD, node, [fieldName]);
3183 } else if (fieldElement.isStatic) { 4053 } else if (fieldElement.isStatic) {
3184 _resolver.reportError5(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, node, [fieldName]); 4054 _resolver.reportError6(CompileTimeErrorCode.INITIALIZER_FOR_STATIC_FIELD, node, [fieldName]);
3185 } 4055 }
3186 return null; 4056 return null;
3187 } 4057 }
4058
3188 Object visitConstructorName(ConstructorName node) { 4059 Object visitConstructorName(ConstructorName node) {
3189 Type2 type = node.type.type; 4060 Type2 type = node.type.type;
3190 if (type != null && type.isDynamic) { 4061 if (type != null && type.isDynamic) {
3191 return null; 4062 return null;
3192 } else if (type is! InterfaceType) { 4063 } else if (type is! InterfaceType) {
3193 ASTNode parent = node.parent; 4064 ASTNode parent = node.parent;
3194 if (parent is InstanceCreationExpression) { 4065 if (parent is InstanceCreationExpression) {
3195 if (((parent as InstanceCreationExpression)).isConst) { 4066 if ((parent as InstanceCreationExpression).isConst) {
3196 } else { 4067 } else {
3197 } 4068 }
3198 } else { 4069 } else {
3199 } 4070 }
3200 return null; 4071 return null;
3201 } 4072 }
3202 ConstructorElement constructor; 4073 ConstructorElement constructor;
3203 SimpleIdentifier name = node.name; 4074 SimpleIdentifier name = node.name;
3204 InterfaceType interfaceType = type as InterfaceType; 4075 InterfaceType interfaceType = type as InterfaceType;
3205 if (name == null) { 4076 if (name == null) {
3206 constructor = interfaceType.lookUpConstructor(null, _definingLibrary); 4077 constructor = interfaceType.lookUpConstructor(null, _definingLibrary);
3207 } else { 4078 } else {
3208 constructor = interfaceType.lookUpConstructor(name.name, _definingLibrary) ; 4079 constructor = interfaceType.lookUpConstructor(name.name, _definingLibrary) ;
3209 name.staticElement = constructor; 4080 name.staticElement = constructor;
3210 } 4081 }
3211 node.staticElement = constructor; 4082 node.staticElement = constructor;
3212 return null; 4083 return null;
3213 } 4084 }
4085
3214 Object visitContinueStatement(ContinueStatement node) { 4086 Object visitContinueStatement(ContinueStatement node) {
3215 SimpleIdentifier labelNode = node.label; 4087 SimpleIdentifier labelNode = node.label;
3216 LabelElementImpl labelElement = lookupLabel(node, labelNode); 4088 LabelElementImpl labelElement = lookupLabel(node, labelNode);
3217 if (labelElement != null && labelElement.isOnSwitchStatement) { 4089 if (labelElement != null && labelElement.isOnSwitchStatement) {
3218 _resolver.reportError5(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNo de, []); 4090 _resolver.reportError6(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNo de, []);
3219 } 4091 }
3220 return null; 4092 return null;
3221 } 4093 }
4094
3222 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 4095 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
3223 setMetadata(node.element, node); 4096 setMetadata(node.element, node);
3224 return null; 4097 return null;
3225 } 4098 }
4099
3226 Object visitExportDirective(ExportDirective node) { 4100 Object visitExportDirective(ExportDirective node) {
3227 Element element = node.element; 4101 Element element = node.element;
3228 if (element is ExportElement) { 4102 if (element is ExportElement) {
3229 resolveCombinators(((element as ExportElement)).exportedLibrary, node.comb inators); 4103 resolveCombinators((element as ExportElement).exportedLibrary, node.combin ators);
3230 setMetadata(element, node); 4104 setMetadata(element, node);
3231 } 4105 }
3232 return null; 4106 return null;
3233 } 4107 }
4108
3234 Object visitFieldFormalParameter(FieldFormalParameter node) { 4109 Object visitFieldFormalParameter(FieldFormalParameter node) {
3235 String fieldName = node.identifier.name; 4110 String fieldName = node.identifier.name;
3236 ClassElement classElement = _resolver.enclosingClass; 4111 ClassElement classElement = _resolver.enclosingClass;
3237 if (classElement != null) { 4112 if (classElement != null) {
3238 FieldElement fieldElement = ((classElement as ClassElementImpl)).getField( fieldName); 4113 FieldElement fieldElement = (classElement as ClassElementImpl).getField(fi eldName);
3239 if (fieldElement == null) { 4114 if (fieldElement == null) {
3240 _resolver.reportError5(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_ EXISTANT_FIELD, node, [fieldName]); 4115 _resolver.reportError6(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_ EXISTANT_FIELD, node, [fieldName]);
3241 } else { 4116 } else {
3242 ParameterElement parameterElement = node.element; 4117 ParameterElement parameterElement = node.element;
3243 if (parameterElement is FieldFormalParameterElementImpl) { 4118 if (parameterElement is FieldFormalParameterElementImpl) {
3244 FieldFormalParameterElementImpl fieldFormal = parameterElement as Fiel dFormalParameterElementImpl; 4119 FieldFormalParameterElementImpl fieldFormal = parameterElement as Fiel dFormalParameterElementImpl;
3245 fieldFormal.field = fieldElement; 4120 fieldFormal.field = fieldElement;
3246 Type2 declaredType = fieldFormal.type; 4121 Type2 declaredType = fieldFormal.type;
3247 Type2 fieldType = fieldElement.type; 4122 Type2 fieldType = fieldElement.type;
3248 if (node.type == null) { 4123 if (node.type == null) {
3249 fieldFormal.type = fieldType; 4124 fieldFormal.type = fieldType;
3250 } 4125 }
3251 if (fieldElement.isSynthetic) { 4126 if (fieldElement.isSynthetic) {
3252 _resolver.reportError5(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]); 4127 _resolver.reportError6(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]);
3253 } else if (fieldElement.isStatic) { 4128 } else if (fieldElement.isStatic) {
3254 _resolver.reportError5(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]); 4129 _resolver.reportError6(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]);
3255 } else if (declaredType != null && fieldType != null && !declaredType. isAssignableTo(fieldType)) { 4130 } else if (declaredType != null && fieldType != null && !declaredType. isAssignableTo(fieldType)) {
3256 _resolver.reportError5(StaticWarningCode.FIELD_INITIALIZING_FORMAL_N OT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]); 4131 _resolver.reportError6(StaticWarningCode.FIELD_INITIALIZING_FORMAL_N OT_ASSIGNABLE, node, [declaredType.displayName, fieldType.displayName]);
3257 } 4132 }
3258 } else { 4133 } else {
3259 if (fieldElement.isSynthetic) { 4134 if (fieldElement.isSynthetic) {
3260 _resolver.reportError5(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]); 4135 _resolver.reportError6(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ NON_EXISTANT_FIELD, node, [fieldName]);
3261 } else if (fieldElement.isStatic) { 4136 } else if (fieldElement.isStatic) {
3262 _resolver.reportError5(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]); 4137 _resolver.reportError6(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_ STATIC_FIELD, node, [fieldName]);
3263 } 4138 }
3264 } 4139 }
3265 } 4140 }
3266 } 4141 }
3267 return super.visitFieldFormalParameter(node); 4142 return super.visitFieldFormalParameter(node);
3268 } 4143 }
4144
3269 Object visitFunctionDeclaration(FunctionDeclaration node) { 4145 Object visitFunctionDeclaration(FunctionDeclaration node) {
3270 setMetadata(node.element, node); 4146 setMetadata(node.element, node);
3271 return null; 4147 return null;
3272 } 4148 }
4149
3273 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 4150 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
3274 Expression expression = node.function; 4151 Expression expression = node.function;
3275 if (expression is FunctionExpression) { 4152 if (expression is FunctionExpression) {
3276 FunctionExpression functionExpression = expression as FunctionExpression; 4153 FunctionExpression functionExpression = expression as FunctionExpression;
3277 ExecutableElement functionElement = functionExpression.element; 4154 ExecutableElement functionElement = functionExpression.element;
3278 ArgumentList argumentList = node.argumentList; 4155 ArgumentList argumentList = node.argumentList;
3279 List<ParameterElement> parameters = resolveArgumentsToParameters(false, ar gumentList, functionElement); 4156 List<ParameterElement> parameters = resolveArgumentsToParameters(false, ar gumentList, functionElement);
3280 if (parameters != null) { 4157 if (parameters != null) {
3281 argumentList.correspondingStaticParameters = parameters; 4158 argumentList.correspondingStaticParameters = parameters;
3282 } 4159 }
3283 } 4160 }
3284 return null; 4161 return null;
3285 } 4162 }
4163
3286 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 4164 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
3287 setMetadata(node.element, node); 4165 setMetadata(node.element, node);
3288 return null; 4166 return null;
3289 } 4167 }
4168
3290 Object visitImportDirective(ImportDirective node) { 4169 Object visitImportDirective(ImportDirective node) {
3291 SimpleIdentifier prefixNode = node.prefix; 4170 SimpleIdentifier prefixNode = node.prefix;
3292 if (prefixNode != null) { 4171 if (prefixNode != null) {
3293 String prefixName = prefixNode.name; 4172 String prefixName = prefixNode.name;
3294 for (PrefixElement prefixElement in _definingLibrary.prefixes) { 4173 for (PrefixElement prefixElement in _definingLibrary.prefixes) {
3295 if (prefixElement.displayName == prefixName) { 4174 if (prefixElement.displayName == prefixName) {
3296 prefixNode.staticElement = prefixElement; 4175 prefixNode.staticElement = prefixElement;
3297 break; 4176 break;
3298 } 4177 }
3299 } 4178 }
3300 } 4179 }
3301 ImportElement importElement = node.element; 4180 ImportElement importElement = node.element;
3302 if (importElement != null) { 4181 if (importElement != null) {
3303 LibraryElement library = importElement.importedLibrary; 4182 LibraryElement library = importElement.importedLibrary;
3304 if (library != null) { 4183 if (library != null) {
3305 resolveCombinators(library, node.combinators); 4184 resolveCombinators(library, node.combinators);
3306 } 4185 }
3307 setMetadata(importElement, node); 4186 setMetadata(importElement, node);
3308 } 4187 }
3309 return null; 4188 return null;
3310 } 4189 }
4190
3311 Object visitIndexExpression(IndexExpression node) { 4191 Object visitIndexExpression(IndexExpression node) {
3312 Expression target = node.realTarget; 4192 Expression target = node.realTarget;
3313 Type2 staticType = getStaticType(target); 4193 Type2 staticType = getStaticType(target);
3314 Type2 propagatedType = getPropagatedType(target); 4194 Type2 propagatedType = getPropagatedType(target);
3315 String getterMethodName = sc.TokenType.INDEX.lexeme; 4195 String getterMethodName = sc.TokenType.INDEX.lexeme;
3316 String setterMethodName = sc.TokenType.INDEX_EQ.lexeme; 4196 String setterMethodName = sc.TokenType.INDEX_EQ.lexeme;
3317 bool isInGetterContext = node.inGetterContext(); 4197 bool isInGetterContext = node.inGetterContext();
3318 bool isInSetterContext = node.inSetterContext(); 4198 bool isInSetterContext = node.inSetterContext();
3319 if (isInGetterContext && isInSetterContext) { 4199 if (isInGetterContext && isInSetterContext) {
3320 MethodElement setterStaticMethod = lookUpMethod(target, staticType, setter MethodName); 4200 MethodElement setterStaticMethod = lookUpMethod(target, staticType, setter MethodName);
(...skipping 14 matching lines...) Expand all
3335 checkForUndefinedIndexOperator(node, target, getterMethodName, staticMetho d, propagatedMethod, staticType, propagatedType); 4215 checkForUndefinedIndexOperator(node, target, getterMethodName, staticMetho d, propagatedMethod, staticType, propagatedType);
3336 } else if (isInSetterContext) { 4216 } else if (isInSetterContext) {
3337 MethodElement staticMethod = lookUpMethod(target, staticType, setterMethod Name); 4217 MethodElement staticMethod = lookUpMethod(target, staticType, setterMethod Name);
3338 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, sett erMethodName); 4218 MethodElement propagatedMethod = lookUpMethod(target, propagatedType, sett erMethodName);
3339 node.staticElement = staticMethod; 4219 node.staticElement = staticMethod;
3340 node.propagatedElement = propagatedMethod; 4220 node.propagatedElement = propagatedMethod;
3341 checkForUndefinedIndexOperator(node, target, setterMethodName, staticMetho d, propagatedMethod, staticType, propagatedType); 4221 checkForUndefinedIndexOperator(node, target, setterMethodName, staticMetho d, propagatedMethod, staticType, propagatedType);
3342 } 4222 }
3343 return null; 4223 return null;
3344 } 4224 }
4225
3345 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 4226 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
3346 ConstructorElement invokedConstructor = node.constructorName.staticElement; 4227 ConstructorElement invokedConstructor = node.constructorName.staticElement;
3347 node.staticElement = invokedConstructor; 4228 node.staticElement = invokedConstructor;
3348 ArgumentList argumentList = node.argumentList; 4229 ArgumentList argumentList = node.argumentList;
3349 List<ParameterElement> parameters = resolveArgumentsToParameters(node.isCons t, argumentList, invokedConstructor); 4230 List<ParameterElement> parameters = resolveArgumentsToParameters(node.isCons t, argumentList, invokedConstructor);
3350 if (parameters != null) { 4231 if (parameters != null) {
3351 argumentList.correspondingStaticParameters = parameters; 4232 argumentList.correspondingStaticParameters = parameters;
3352 } 4233 }
3353 return null; 4234 return null;
3354 } 4235 }
4236
3355 Object visitLibraryDirective(LibraryDirective node) { 4237 Object visitLibraryDirective(LibraryDirective node) {
3356 setMetadata(node.element, node); 4238 setMetadata(node.element, node);
3357 return null; 4239 return null;
3358 } 4240 }
4241
3359 Object visitMethodDeclaration(MethodDeclaration node) { 4242 Object visitMethodDeclaration(MethodDeclaration node) {
3360 setMetadata(node.element, node); 4243 setMetadata(node.element, node);
3361 return null; 4244 return null;
3362 } 4245 }
4246
3363 Object visitMethodInvocation(MethodInvocation node) { 4247 Object visitMethodInvocation(MethodInvocation node) {
3364 SimpleIdentifier methodName = node.methodName; 4248 SimpleIdentifier methodName = node.methodName;
3365 Expression target = node.realTarget; 4249 Expression target = node.realTarget;
3366 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) { 4250 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) {
3367 return null; 4251 return null;
3368 } 4252 }
3369 Element staticElement; 4253 Element staticElement;
3370 Element propagatedElement; 4254 Element propagatedElement;
3371 if (target == null) { 4255 if (target == null) {
3372 staticElement = resolveInvokedElement2(methodName); 4256 staticElement = resolveInvokedElement2(methodName);
3373 propagatedElement = null; 4257 propagatedElement = null;
3374 } else { 4258 } else {
3375 Type2 staticType = getStaticType(target); 4259 Type2 staticType = getStaticType(target);
3376 staticElement = resolveInvokedElement(target, staticType, methodName); 4260 ClassElementImpl typeReference = getTypeReference(target);
3377 propagatedElement = resolveInvokedElement(target, getPropagatedType(target ), methodName); 4261 if (typeReference != null) {
4262 staticElement = propagatedElement = resolveElement(typeReference, method Name.name);
4263 } else {
4264 staticElement = resolveInvokedElement(target, staticType, methodName);
4265 propagatedElement = resolveInvokedElement(target, getPropagatedType(targ et), methodName);
4266 }
3378 } 4267 }
3379 staticElement = convertSetterToGetter(staticElement); 4268 staticElement = convertSetterToGetter(staticElement);
3380 propagatedElement = convertSetterToGetter(propagatedElement); 4269 propagatedElement = convertSetterToGetter(propagatedElement);
3381 methodName.staticElement = staticElement; 4270 methodName.staticElement = staticElement;
3382 methodName.propagatedElement = propagatedElement; 4271 methodName.propagatedElement = propagatedElement;
3383 ArgumentList argumentList = node.argumentList; 4272 ArgumentList argumentList = node.argumentList;
3384 if (staticElement != null) { 4273 if (staticElement != null) {
3385 List<ParameterElement> parameters = computeCorrespondingParameters(argumen tList, staticElement); 4274 List<ParameterElement> parameters = computeCorrespondingParameters(argumen tList, staticElement);
3386 if (parameters != null) { 4275 if (parameters != null) {
3387 argumentList.correspondingStaticParameters = parameters; 4276 argumentList.correspondingStaticParameters = parameters;
(...skipping 30 matching lines...) Expand all
3418 } 4307 }
3419 } 4308 }
3420 } 4309 }
3421 } 4310 }
3422 generatedWithTypePropagation = true; 4311 generatedWithTypePropagation = true;
3423 } 4312 }
3424 if (errorCode == null) { 4313 if (errorCode == null) {
3425 return null; 4314 return null;
3426 } 4315 }
3427 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) { 4316 if (identical(errorCode, StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION)) {
3428 _resolver.reportError5(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]); 4317 _resolver.reportError6(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, m ethodName, [methodName.name]);
3429 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) { 4318 } else if (identical(errorCode, CompileTimeErrorCode.UNDEFINED_FUNCTION)) {
3430 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]); 4319 _resolver.reportError6(CompileTimeErrorCode.UNDEFINED_FUNCTION, methodName , [methodName.name]);
3431 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) { 4320 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_METHOD)) {
3432 String targetTypeName; 4321 String targetTypeName;
3433 if (target == null) { 4322 if (target == null) {
3434 ClassElement enclosingClass = _resolver.enclosingClass; 4323 ClassElement enclosingClass = _resolver.enclosingClass;
3435 targetTypeName = enclosingClass.displayName; 4324 targetTypeName = enclosingClass.displayName;
3436 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; 4325 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode;
3437 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]); 4326 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, proxyErrorCode, methodName, [methodName.name, targetTypeName]);
3438 } else { 4327 } else {
3439 Type2 targetType = null; 4328 Type2 targetType = null;
3440 if (!generatedWithTypePropagation) { 4329 if (!generatedWithTypePropagation) {
3441 targetType = getStaticType(target); 4330 targetType = getStaticType(target);
3442 } else { 4331 } else {
3443 targetType = getPropagatedType(target); 4332 targetType = getPropagatedType(target);
3444 if (targetType == null) { 4333 if (targetType == null) {
3445 targetType = getStaticType(target); 4334 targetType = getStaticType(target);
3446 } 4335 }
3447 } 4336 }
3448 if (targetType != null && targetType.isDartCoreFunction && methodName.na me == CALL_METHOD_NAME) { 4337 if (targetType != null && targetType.isDartCoreFunction && methodName.na me == CALL_METHOD_NAME) {
3449 return null; 4338 return null;
3450 } 4339 }
3451 targetTypeName = targetType == null ? null : targetType.displayName; 4340 targetTypeName = targetType == null ? null : targetType.displayName;
3452 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode; 4341 ErrorCode proxyErrorCode = (generatedWithTypePropagation ? HintCode.UNDE FINED_METHOD : StaticTypeWarningCode.UNDEFINED_METHOD) as ErrorCode;
3453 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p roxyErrorCode, methodName, [methodName.name, targetTypeName]); 4342 _resolver.reportErrorProxyConditionalAnalysisError(targetType.element, p roxyErrorCode, methodName, [methodName.name, targetTypeName]);
3454 } 4343 }
3455 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD )) { 4344 } else if (identical(errorCode, StaticTypeWarningCode.UNDEFINED_SUPER_METHOD )) {
3456 Type2 targetType = getStaticType(target); 4345 Type2 targetType = getStaticType(target);
3457 String targetTypeName = targetType == null ? null : targetType.name; 4346 String targetTypeName = targetType == null ? null : targetType.name;
3458 _resolver.reportError5(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho dName, [methodName.name, targetTypeName]); 4347 _resolver.reportError6(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, metho dName, [methodName.name, targetTypeName]);
3459 } 4348 }
3460 return null; 4349 return null;
3461 } 4350 }
4351
3462 Object visitPartDirective(PartDirective node) { 4352 Object visitPartDirective(PartDirective node) {
3463 setMetadata(node.element, node); 4353 setMetadata(node.element, node);
3464 return null; 4354 return null;
3465 } 4355 }
4356
3466 Object visitPartOfDirective(PartOfDirective node) { 4357 Object visitPartOfDirective(PartOfDirective node) {
3467 setMetadata(node.element, node); 4358 setMetadata(node.element, node);
3468 return null; 4359 return null;
3469 } 4360 }
4361
3470 Object visitPostfixExpression(PostfixExpression node) { 4362 Object visitPostfixExpression(PostfixExpression node) {
3471 Expression operand = node.operand; 4363 Expression operand = node.operand;
3472 String methodName = getPostfixOperator(node); 4364 String methodName = getPostfixOperator(node);
3473 Type2 staticType = getStaticType(operand); 4365 Type2 staticType = getStaticType(operand);
3474 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName); 4366 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName);
3475 node.staticElement = staticMethod; 4367 node.staticElement = staticMethod;
3476 Type2 propagatedType = getPropagatedType(operand); 4368 Type2 propagatedType = getPropagatedType(operand);
3477 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho dName); 4369 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, metho dName);
3478 node.propagatedElement = propagatedMethod; 4370 node.propagatedElement = propagatedMethod;
3479 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod)); 4371 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, pro pagatedMethod));
3480 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false; 4372 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod) : false;
3481 if (shouldReportMissingMember_propagated) { 4373 if (shouldReportMissingMember_propagated) {
3482 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) { 4374 if (memberFoundInSubclass(propagatedType.element, methodName, true, false) ) {
3483 shouldReportMissingMember_propagated = false; 4375 shouldReportMissingMember_propagated = false;
3484 } 4376 }
3485 } 4377 }
3486 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 4378 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
3487 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 4379 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarnin gCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3488 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingMem ber_static ? staticType.element : propagatedType.element, errorCode, node.operat or, [ 4380 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingMem ber_static ? staticType.element : propagatedType.element, errorCode, node.operat or, [
3489 methodName, 4381 methodName,
3490 shouldReportMissingMember_static ? staticType.displayName : propagated Type.displayName]); 4382 shouldReportMissingMember_static ? staticType.displayName : propagated Type.displayName]);
3491 } 4383 }
3492 return null; 4384 return null;
3493 } 4385 }
4386
3494 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 4387 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
3495 SimpleIdentifier prefix = node.prefix; 4388 SimpleIdentifier prefix = node.prefix;
3496 SimpleIdentifier identifier = node.identifier; 4389 SimpleIdentifier identifier = node.identifier;
3497 Element prefixElement = prefix.staticElement; 4390 Element prefixElement = prefix.staticElement;
3498 if (prefixElement is PrefixElement) { 4391 if (prefixElement is PrefixElement) {
3499 Element element = _resolver.nameScope.lookup(node, _definingLibrary); 4392 Element element = _resolver.nameScope.lookup(node, _definingLibrary);
3500 if (element == null && identifier.inSetterContext()) { 4393 if (element == null && identifier.inSetterContext()) {
3501 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary); 4394 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti fier("${node.name}="), _definingLibrary);
3502 } 4395 }
3503 if (element == null) { 4396 if (element == null) {
3504 if (identifier.inSetterContext()) { 4397 if (identifier.inSetterContext()) {
3505 _resolver.reportError5(StaticWarningCode.UNDEFINED_SETTER, identifier, [identifier.name, prefixElement.name]); 4398 _resolver.reportError6(StaticWarningCode.UNDEFINED_SETTER, identifier, [identifier.name, prefixElement.name]);
3506 } else if (node.parent is Annotation) { 4399 } else if (node.parent is Annotation) {
3507 Annotation annotation = node.parent as Annotation; 4400 Annotation annotation = node.parent as Annotation;
3508 _resolver.reportError5(CompileTimeErrorCode.INVALID_ANNOTATION, annota tion, []); 4401 _resolver.reportError6(CompileTimeErrorCode.INVALID_ANNOTATION, annota tion, []);
3509 return null; 4402 return null;
3510 } else { 4403 } else {
3511 _resolver.reportError5(StaticWarningCode.UNDEFINED_GETTER, identifier, [identifier.name, prefixElement.name]); 4404 _resolver.reportError6(StaticWarningCode.UNDEFINED_GETTER, identifier, [identifier.name, prefixElement.name]);
3512 } 4405 }
3513 return null; 4406 return null;
3514 } 4407 }
3515 if (element is PropertyAccessorElement && identifier.inSetterContext()) { 4408 if (element is PropertyAccessorElement && identifier.inSetterContext()) {
3516 PropertyInducingElement variable = ((element as PropertyAccessorElement) ).variable; 4409 PropertyInducingElement variable = (element as PropertyAccessorElement). variable;
3517 if (variable != null) { 4410 if (variable != null) {
3518 PropertyAccessorElement setter = variable.setter; 4411 PropertyAccessorElement setter = variable.setter;
3519 if (setter != null) { 4412 if (setter != null) {
3520 element = setter; 4413 element = setter;
3521 } 4414 }
3522 } 4415 }
3523 } 4416 }
3524 identifier.staticElement = element; 4417 identifier.staticElement = element;
3525 if (node.parent is Annotation) { 4418 if (node.parent is Annotation) {
3526 Annotation annotation = node.parent as Annotation; 4419 Annotation annotation = node.parent as Annotation;
3527 resolveAnnotationElement(annotation, element, null); 4420 resolveAnnotationElement(annotation);
3528 return null; 4421 return null;
3529 } 4422 }
3530 return null; 4423 return null;
3531 } 4424 }
3532 if (node.parent is Annotation) { 4425 if (node.parent is Annotation) {
3533 Annotation annotation = node.parent as Annotation; 4426 Annotation annotation = node.parent as Annotation;
3534 resolveAnnotationElement(annotation, prefixElement, identifier); 4427 resolveAnnotationElement(annotation);
3535 } 4428 }
3536 resolvePropertyAccess(prefix, identifier); 4429 resolvePropertyAccess(prefix, identifier);
3537 return null; 4430 return null;
3538 } 4431 }
4432
3539 Object visitPrefixExpression(PrefixExpression node) { 4433 Object visitPrefixExpression(PrefixExpression node) {
3540 sc.Token operator = node.operator; 4434 sc.Token operator = node.operator;
3541 sc.TokenType operatorType = operator.type; 4435 sc.TokenType operatorType = operator.type;
3542 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { 4436 if (operatorType.isUserDefinableOperator || identical(operatorType, sc.Token Type.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) {
3543 Expression operand = node.operand; 4437 Expression operand = node.operand;
3544 String methodName = getPrefixOperator(node); 4438 String methodName = getPrefixOperator(node);
3545 Type2 staticType = getStaticType(operand); 4439 Type2 staticType = getStaticType(operand);
3546 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName) ; 4440 MethodElement staticMethod = lookUpMethod(operand, staticType, methodName) ;
3547 node.staticElement = staticMethod; 4441 node.staticElement = staticMethod;
3548 Type2 propagatedType = getPropagatedType(operand); 4442 Type2 propagatedType = getPropagatedType(operand);
3549 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met hodName); 4443 MethodElement propagatedMethod = lookUpMethod(operand, propagatedType, met hodName);
3550 node.propagatedElement = propagatedMethod; 4444 node.propagatedElement = propagatedMethod;
3551 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod)); 4445 bool shouldReportMissingMember_static = shouldReportMissingMember(staticTy pe, staticMethod) && (_strictMode || shouldReportMissingMember(propagatedType, p ropagatedMethod));
3552 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false; 4446 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_sta tic && _enableHints ? shouldReportMissingMember(propagatedType, propagatedMethod ) : false;
3553 if (shouldReportMissingMember_propagated) { 4447 if (shouldReportMissingMember_propagated) {
3554 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) { 4448 if (memberFoundInSubclass(propagatedType.element, methodName, true, fals e)) {
3555 shouldReportMissingMember_propagated = false; 4449 shouldReportMissingMember_propagated = false;
3556 } 4450 }
3557 } 4451 }
3558 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) { 4452 if (shouldReportMissingMember_static || shouldReportMissingMember_propagat ed) {
3559 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode; 4453 ErrorCode errorCode = (shouldReportMissingMember_static ? StaticTypeWarn ingCode.UNDEFINED_OPERATOR : HintCode.UNDEFINED_OPERATOR) as ErrorCode;
3560 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingM ember_static ? staticType.element : propagatedType.element, errorCode, operator, [ 4454 _resolver.reportErrorProxyConditionalAnalysisError3(shouldReportMissingM ember_static ? staticType.element : propagatedType.element, errorCode, operator, [
3561 methodName, 4455 methodName,
3562 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]); 4456 shouldReportMissingMember_static ? staticType.displayName : propagat edType.displayName]);
3563 } 4457 }
3564 } 4458 }
3565 return null; 4459 return null;
3566 } 4460 }
4461
3567 Object visitPropertyAccess(PropertyAccess node) { 4462 Object visitPropertyAccess(PropertyAccess node) {
3568 Expression target = node.realTarget; 4463 Expression target = node.realTarget;
3569 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) { 4464 if (target is SuperExpression && !isSuperInValidContext(target as SuperExpre ssion)) {
3570 return null; 4465 return null;
3571 } 4466 }
3572 SimpleIdentifier propertyName = node.propertyName; 4467 SimpleIdentifier propertyName = node.propertyName;
3573 resolvePropertyAccess(target, propertyName); 4468 resolvePropertyAccess(target, propertyName);
3574 return null; 4469 return null;
3575 } 4470 }
4471
3576 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 4472 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
3577 ClassElement enclosingClass = _resolver.enclosingClass; 4473 ClassElement enclosingClass = _resolver.enclosingClass;
3578 if (enclosingClass == null) { 4474 if (enclosingClass == null) {
3579 return null; 4475 return null;
3580 } 4476 }
3581 SimpleIdentifier name = node.constructorName; 4477 SimpleIdentifier name = node.constructorName;
3582 ConstructorElement element; 4478 ConstructorElement element;
3583 if (name == null) { 4479 if (name == null) {
3584 element = enclosingClass.unnamedConstructor; 4480 element = enclosingClass.unnamedConstructor;
3585 } else { 4481 } else {
3586 element = enclosingClass.getNamedConstructor(name.name); 4482 element = enclosingClass.getNamedConstructor(name.name);
3587 } 4483 }
3588 if (element == null) { 4484 if (element == null) {
3589 return null; 4485 return null;
3590 } 4486 }
3591 if (name != null) { 4487 if (name != null) {
3592 name.staticElement = element; 4488 name.staticElement = element;
3593 } 4489 }
3594 node.staticElement = element; 4490 node.staticElement = element;
3595 ArgumentList argumentList = node.argumentList; 4491 ArgumentList argumentList = node.argumentList;
3596 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element); 4492 List<ParameterElement> parameters = resolveArgumentsToParameters(false, argu mentList, element);
3597 if (parameters != null) { 4493 if (parameters != null) {
3598 argumentList.correspondingStaticParameters = parameters; 4494 argumentList.correspondingStaticParameters = parameters;
3599 } 4495 }
3600 return null; 4496 return null;
3601 } 4497 }
4498
3602 Object visitSimpleIdentifier(SimpleIdentifier node) { 4499 Object visitSimpleIdentifier(SimpleIdentifier node) {
3603 if (node.staticElement != null) { 4500 if (node.staticElement != null) {
3604 return null; 4501 return null;
3605 } 4502 }
3606 if (node.name == _dynamicType.name) { 4503 if (node.name == _dynamicType.name) {
3607 node.staticElement = _dynamicType.element; 4504 node.staticElement = _dynamicType.element;
3608 node.staticType = _typeType; 4505 node.staticType = _typeType;
3609 return null; 4506 return null;
3610 } 4507 }
3611 Element element = resolveSimpleIdentifier(node); 4508 Element element = resolveSimpleIdentifier(node);
3612 ClassElement enclosingClass = _resolver.enclosingClass; 4509 ClassElement enclosingClass = _resolver.enclosingClass;
3613 if (isFactoryConstructorReturnType(node) && element != enclosingClass) { 4510 if (isFactoryConstructorReturnType(node) && element != enclosingClass) {
3614 _resolver.reportError5(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA SS, node, []); 4511 _resolver.reportError6(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLA SS, node, []);
3615 } else if (isConstructorReturnType(node) && element != enclosingClass) { 4512 } else if (isConstructorReturnType(node) && element != enclosingClass) {
3616 _resolver.reportError5(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node , []); 4513 _resolver.reportError6(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, node , []);
3617 element = null; 4514 element = null;
3618 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) { 4515 } else if (element == null || (element is PrefixElement && !isValidAsPrefix( node))) {
3619 if (isConstructorReturnType(node)) { 4516 if (isConstructorReturnType(node)) {
3620 _resolver.reportError5(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no de, []); 4517 _resolver.reportError6(CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME, no de, []);
3621 } else if (node.parent is Annotation) { 4518 } else if (node.parent is Annotation) {
3622 Annotation annotation = node.parent as Annotation; 4519 Annotation annotation = node.parent as Annotation;
3623 _resolver.reportError5(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []); 4520 _resolver.reportError6(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []);
3624 } else { 4521 } else {
3625 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]); 4522 _resolver.reportErrorProxyConditionalAnalysisError(_resolver.enclosingCl ass, StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node.name]);
3626 } 4523 }
3627 } 4524 }
3628 node.staticElement = element; 4525 node.staticElement = element;
3629 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu ll) { 4526 if (node.inSetterContext() && node.inGetterContext() && enclosingClass != nu ll) {
3630 InterfaceType enclosingType = enclosingClass.type; 4527 InterfaceType enclosingType = enclosingClass.type;
3631 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n ull, enclosingType, node.name), null); 4528 AuxiliaryElements auxiliaryElements = new AuxiliaryElements(lookUpGetter(n ull, enclosingType, node.name), null);
3632 node.auxiliaryElements = auxiliaryElements; 4529 node.auxiliaryElements = auxiliaryElements;
3633 } 4530 }
3634 if (node.parent is Annotation) { 4531 if (node.parent is Annotation) {
3635 Annotation annotation = node.parent as Annotation; 4532 Annotation annotation = node.parent as Annotation;
3636 resolveAnnotationElement(annotation, element, null); 4533 resolveAnnotationElement(annotation);
3637 } 4534 }
3638 return null; 4535 return null;
3639 } 4536 }
4537
3640 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 4538 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
3641 ClassElement enclosingClass = _resolver.enclosingClass; 4539 ClassElement enclosingClass = _resolver.enclosingClass;
3642 if (enclosingClass == null) { 4540 if (enclosingClass == null) {
3643 return null; 4541 return null;
3644 } 4542 }
3645 InterfaceType superType = enclosingClass.supertype; 4543 InterfaceType superType = enclosingClass.supertype;
3646 if (superType == null) { 4544 if (superType == null) {
3647 return null; 4545 return null;
3648 } 4546 }
3649 SimpleIdentifier name = node.constructorName; 4547 SimpleIdentifier name = node.constructorName;
3650 String superName = name != null ? name.name : null; 4548 String superName = name != null ? name.name : null;
3651 ConstructorElement element = superType.lookUpConstructor(superName, _definin gLibrary); 4549 ConstructorElement element = superType.lookUpConstructor(superName, _definin gLibrary);
3652 if (element == null) { 4550 if (element == null) {
3653 if (name != null) { 4551 if (name != null) {
3654 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superType.displayName, name]); 4552 _resolver.reportError6(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER, node, [superType.displayName, name]);
3655 } else { 4553 } else {
3656 _resolver.reportError5(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superType.displayName]); 4554 _resolver.reportError6(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INI TIALIZER_DEFAULT, node, [superType.displayName]);
3657 } 4555 }
3658 return null; 4556 return null;
3659 } else { 4557 } else {
3660 if (element.isFactory) { 4558 if (element.isFactory) {
3661 _resolver.reportError5(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]); 4559 _resolver.reportError6(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, node, [element]);
3662 } 4560 }
3663 } 4561 }
3664 if (name != null) { 4562 if (name != null) {
3665 name.staticElement = element; 4563 name.staticElement = element;
3666 } 4564 }
3667 node.staticElement = element; 4565 node.staticElement = element;
3668 ArgumentList argumentList = node.argumentList; 4566 ArgumentList argumentList = node.argumentList;
3669 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo nstructor, argumentList, element); 4567 List<ParameterElement> parameters = resolveArgumentsToParameters(isInConstCo nstructor, argumentList, element);
3670 if (parameters != null) { 4568 if (parameters != null) {
3671 argumentList.correspondingStaticParameters = parameters; 4569 argumentList.correspondingStaticParameters = parameters;
3672 } 4570 }
3673 return null; 4571 return null;
3674 } 4572 }
4573
3675 Object visitSuperExpression(SuperExpression node) { 4574 Object visitSuperExpression(SuperExpression node) {
3676 if (!isSuperInValidContext(node)) { 4575 if (!isSuperInValidContext(node)) {
3677 _resolver.reportError5(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node , []); 4576 _resolver.reportError6(CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node , []);
3678 } 4577 }
3679 return super.visitSuperExpression(node); 4578 return super.visitSuperExpression(node);
3680 } 4579 }
4580
3681 Object visitTypeParameter(TypeParameter node) { 4581 Object visitTypeParameter(TypeParameter node) {
3682 TypeName bound = node.bound; 4582 TypeName bound = node.bound;
3683 if (bound != null) { 4583 if (bound != null) {
3684 TypeParameterElementImpl typeParameter = node.name.staticElement as TypePa rameterElementImpl; 4584 TypeParameterElementImpl typeParameter = node.name.staticElement as TypePa rameterElementImpl;
3685 if (typeParameter != null) { 4585 if (typeParameter != null) {
3686 typeParameter.bound = bound.type; 4586 typeParameter.bound = bound.type;
3687 } 4587 }
3688 } 4588 }
3689 setMetadata(node.element, node); 4589 setMetadata(node.element, node);
3690 return null; 4590 return null;
3691 } 4591 }
4592
3692 Object visitVariableDeclaration(VariableDeclaration node) { 4593 Object visitVariableDeclaration(VariableDeclaration node) {
3693 setMetadata(node.element, node); 4594 setMetadata(node.element, node);
3694 return null; 4595 return null;
3695 } 4596 }
3696 4597
3697 /** 4598 /**
3698 * Generate annotation elements for each of the annotations in the given node list and add them to 4599 * Generate annotation elements for each of the annotations in the given node list and add them to
3699 * the given list of elements. 4600 * the given list of elements.
3700 * 4601 *
3701 * @param annotationList the list of elements to which new elements are to be added 4602 * @param annotationList the list of elements to which new elements are to be added
(...skipping 15 matching lines...) Expand all
3717 * @param target the target of the invocation, or `null` if there was no targe t 4618 * @param target the target of the invocation, or `null` if there was no targe t
3718 * @param useStaticContext 4619 * @param useStaticContext
3719 * @param element the element to be invoked 4620 * @param element the element to be invoked
3720 * @return the error code that should be reported 4621 * @return the error code that should be reported
3721 */ 4622 */
3722 ErrorCode checkForInvocationError(Expression target, bool useStaticContext, El ement element) { 4623 ErrorCode checkForInvocationError(Expression target, bool useStaticContext, El ement element) {
3723 if (element is PrefixElement) { 4624 if (element is PrefixElement) {
3724 element = null; 4625 element = null;
3725 } 4626 }
3726 if (element is PropertyAccessorElement) { 4627 if (element is PropertyAccessorElement) {
3727 FunctionType getterType = ((element as PropertyAccessorElement)).type; 4628 FunctionType getterType = (element as PropertyAccessorElement).type;
3728 if (getterType != null) { 4629 if (getterType != null) {
3729 Type2 returnType = getterType.returnType; 4630 Type2 returnType = getterType.returnType;
3730 if (!isExecutableType(returnType)) { 4631 if (!isExecutableType(returnType)) {
3731 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 4632 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3732 } 4633 }
3733 } 4634 }
3734 } else if (element is ExecutableElement) { 4635 } else if (element is ExecutableElement) {
3735 return null; 4636 return null;
3736 } else if (element == null && target is SuperExpression) { 4637 } else if (element == null && target is SuperExpression) {
3737 return StaticTypeWarningCode.UNDEFINED_SUPER_METHOD; 4638 return StaticTypeWarningCode.UNDEFINED_SUPER_METHOD;
3738 } else { 4639 } else {
3739 if (element is PropertyInducingElement) { 4640 if (element is PropertyInducingElement) {
3740 PropertyAccessorElement getter = ((element as PropertyInducingElement)). getter; 4641 PropertyAccessorElement getter = (element as PropertyInducingElement).ge tter;
3741 FunctionType getterType = getter.type; 4642 FunctionType getterType = getter.type;
3742 if (getterType != null) { 4643 if (getterType != null) {
3743 Type2 returnType = getterType.returnType; 4644 Type2 returnType = getterType.returnType;
3744 if (!isExecutableType(returnType)) { 4645 if (!isExecutableType(returnType)) {
3745 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 4646 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3746 } 4647 }
3747 } 4648 }
3748 } else if (element is VariableElement) { 4649 } else if (element is VariableElement) {
3749 Type2 variableType = ((element as VariableElement)).type; 4650 Type2 variableType = (element as VariableElement).type;
3750 if (!isExecutableType(variableType)) { 4651 if (!isExecutableType(variableType)) {
3751 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION; 4652 return StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION;
3752 } 4653 }
3753 } else { 4654 } else {
3754 if (target == null) { 4655 if (target == null) {
3755 ClassElement enclosingClass = _resolver.enclosingClass; 4656 ClassElement enclosingClass = _resolver.enclosingClass;
3756 if (enclosingClass == null) { 4657 if (enclosingClass == null) {
3757 return CompileTimeErrorCode.UNDEFINED_FUNCTION; 4658 return CompileTimeErrorCode.UNDEFINED_FUNCTION;
3758 } else if (element == null) { 4659 } else if (element == null) {
3759 return StaticTypeWarningCode.UNDEFINED_METHOD; 4660 return StaticTypeWarningCode.UNDEFINED_METHOD;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3820 * Given a list of arguments and the element that will be invoked using those argument, compute 4721 * Given a list of arguments and the element that will be invoked using those argument, compute
3821 * the list of parameters that correspond to the list of arguments. Return the parameters that 4722 * the list of parameters that correspond to the list of arguments. Return the parameters that
3822 * correspond to the arguments, or `null` if no correspondence could be comput ed. 4723 * correspond to the arguments, or `null` if no correspondence could be comput ed.
3823 * 4724 *
3824 * @param argumentList the list of arguments being passed to the element 4725 * @param argumentList the list of arguments being passed to the element
3825 * @param executableElement the element that will be invoked with the argument s 4726 * @param executableElement the element that will be invoked with the argument s
3826 * @return the parameters that correspond to the arguments 4727 * @return the parameters that correspond to the arguments
3827 */ 4728 */
3828 List<ParameterElement> computeCorrespondingParameters(ArgumentList argumentLis t, Element element) { 4729 List<ParameterElement> computeCorrespondingParameters(ArgumentList argumentLis t, Element element) {
3829 if (element is PropertyAccessorElement) { 4730 if (element is PropertyAccessorElement) {
3830 FunctionType getterType = ((element as PropertyAccessorElement)).type; 4731 FunctionType getterType = (element as PropertyAccessorElement).type;
3831 if (getterType != null) { 4732 if (getterType != null) {
3832 Type2 getterReturnType = getterType.returnType; 4733 Type2 getterReturnType = getterType.returnType;
3833 if (getterReturnType is InterfaceType) { 4734 if (getterReturnType is InterfaceType) {
3834 MethodElement callMethod = ((getterReturnType as InterfaceType)).lookU pMethod(CALL_METHOD_NAME, _definingLibrary); 4735 MethodElement callMethod = (getterReturnType as InterfaceType).lookUpM ethod(CALL_METHOD_NAME, _definingLibrary);
3835 if (callMethod != null) { 4736 if (callMethod != null) {
3836 return resolveArgumentsToParameters(false, argumentList, callMethod) ; 4737 return resolveArgumentsToParameters(false, argumentList, callMethod) ;
3837 } 4738 }
3838 } else if (getterReturnType is FunctionType) { 4739 } else if (getterReturnType is FunctionType) {
3839 Element functionElement = ((getterReturnType as FunctionType)).element ; 4740 Element functionElement = (getterReturnType as FunctionType).element;
3840 if (functionElement is ExecutableElement) { 4741 if (functionElement is ExecutableElement) {
3841 return resolveArgumentsToParameters(false, argumentList, functionEle ment as ExecutableElement); 4742 return resolveArgumentsToParameters(false, argumentList, functionEle ment as ExecutableElement);
3842 } 4743 }
3843 } 4744 }
3844 } 4745 }
3845 } else if (element is ExecutableElement) { 4746 } else if (element is ExecutableElement) {
3846 return resolveArgumentsToParameters(false, argumentList, element as Execut ableElement); 4747 return resolveArgumentsToParameters(false, argumentList, element as Execut ableElement);
3847 } else if (element is VariableElement) { 4748 } else if (element is VariableElement) {
3848 VariableElement variable = element as VariableElement; 4749 VariableElement variable = element as VariableElement;
3849 Type2 type = _promoteManager.getStaticType(variable); 4750 Type2 type = _promoteManager.getStaticType(variable);
3850 if (type is FunctionType) { 4751 if (type is FunctionType) {
3851 FunctionType functionType = type as FunctionType; 4752 FunctionType functionType = type as FunctionType;
3852 List<ParameterElement> parameters = functionType.parameters; 4753 List<ParameterElement> parameters = functionType.parameters;
3853 return resolveArgumentsToParameters2(false, argumentList, parameters); 4754 return resolveArgumentsToParameters2(false, argumentList, parameters);
3854 } else if (type is InterfaceType) { 4755 } else if (type is InterfaceType) {
3855 MethodElement callMethod = ((type as InterfaceType)).lookUpMethod(CALL_M ETHOD_NAME, _definingLibrary); 4756 MethodElement callMethod = (type as InterfaceType).lookUpMethod(CALL_MET HOD_NAME, _definingLibrary);
3856 if (callMethod != null) { 4757 if (callMethod != null) {
3857 List<ParameterElement> parameters = callMethod.parameters; 4758 List<ParameterElement> parameters = callMethod.parameters;
3858 return resolveArgumentsToParameters2(false, argumentList, parameters); 4759 return resolveArgumentsToParameters2(false, argumentList, parameters);
3859 } 4760 }
3860 } 4761 }
3861 } 4762 }
3862 return null; 4763 return null;
3863 } 4764 }
3864 4765
3865 /** 4766 /**
3866 * If the given element is a setter, return the getter associated with it. Oth erwise, return the 4767 * If the given element is a setter, return the getter associated with it. Oth erwise, return the
3867 * element unchanged. 4768 * element unchanged.
3868 * 4769 *
3869 * @param element the element to be normalized 4770 * @param element the element to be normalized
3870 * @return a non-setter element derived from the given element 4771 * @return a non-setter element derived from the given element
3871 */ 4772 */
3872 Element convertSetterToGetter(Element element) { 4773 Element convertSetterToGetter(Element element) {
3873 if (element is PropertyAccessorElement) { 4774 if (element is PropertyAccessorElement) {
3874 return ((element as PropertyAccessorElement)).variable.getter; 4775 return (element as PropertyAccessorElement).variable.getter;
3875 } 4776 }
3876 return element; 4777 return element;
3877 } 4778 }
3878 4779
3879 /** 4780 /**
3880 * Look for any declarations of the given identifier that are imported using a prefix. Return the 4781 * Look for any declarations of the given identifier that are imported using a prefix. Return the
3881 * element that was found, or `null` if the name is not imported using a prefi x. 4782 * element that was found, or `null` if the name is not imported using a prefi x.
3882 * 4783 *
3883 * @param identifier the identifier that might have been imported using a pref ix 4784 * @param identifier the identifier that might have been imported using a pref ix
3884 * @return the element that was found 4785 * @return the element that was found
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3966 * Return `true` if the given type represents an object that could be invoked using the call 4867 * Return `true` if the given type represents an object that could be invoked using the call
3967 * operator '()'. 4868 * operator '()'.
3968 * 4869 *
3969 * @param type the type being tested 4870 * @param type the type being tested
3970 * @return `true` if the given type represents an object that could be invoked 4871 * @return `true` if the given type represents an object that could be invoked
3971 */ 4872 */
3972 bool isExecutableType(Type2 type) { 4873 bool isExecutableType(Type2 type) {
3973 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t ype.isObject) { 4874 if (type.isDynamic || (type is FunctionType) || type.isDartCoreFunction || t ype.isObject) {
3974 return true; 4875 return true;
3975 } else if (type is InterfaceType) { 4876 } else if (type is InterfaceType) {
3976 ClassElement classElement = ((type as InterfaceType)).element; 4877 ClassElement classElement = (type as InterfaceType).element;
3977 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME, _definingLibrary); 4878 MethodElement methodElement = classElement.lookUpMethod(CALL_METHOD_NAME, _definingLibrary);
3978 return methodElement != null; 4879 return methodElement != null;
3979 } 4880 }
3980 return false; 4881 return false;
3981 } 4882 }
3982 4883
3983 /** 4884 /**
3984 * @return `true` iff current enclosing function is constant constructor decla ration. 4885 * @return `true` iff current enclosing function is constant constructor decla ration.
3985 */ 4886 */
3986 bool get isInConstConstructor { 4887 bool get isInConstConstructor {
3987 ExecutableElement function = _resolver.enclosingFunction; 4888 ExecutableElement function = _resolver.enclosingFunction;
3988 if (function is ConstructorElement) { 4889 if (function is ConstructorElement) {
3989 return ((function as ConstructorElement)).isConst; 4890 return (function as ConstructorElement).isConst;
3990 } 4891 }
3991 return false; 4892 return false;
3992 } 4893 }
3993 4894
3994 /** 4895 /**
3995 * Return `true` if the given element is a static element. 4896 * Return `true` if the given element is a static element.
3996 * 4897 *
3997 * @param element the element being tested 4898 * @param element the element being tested
3998 * @return `true` if the given element is a static element 4899 * @return `true` if the given element is a static element
3999 */ 4900 */
4000 bool isStatic(Element element) { 4901 bool isStatic(Element element) {
4001 if (element is ExecutableElement) { 4902 if (element is ExecutableElement) {
4002 return ((element as ExecutableElement)).isStatic; 4903 return (element as ExecutableElement).isStatic;
4003 } else if (element is PropertyInducingElement) { 4904 } else if (element is PropertyInducingElement) {
4004 return ((element as PropertyInducingElement)).isStatic; 4905 return (element as PropertyInducingElement).isStatic;
4005 } 4906 }
4006 return false; 4907 return false;
4007 } 4908 }
4008 4909
4009 /** 4910 /**
4010 * Return `true` if the given node can validly be resolved to a prefix: 4911 * Return `true` if the given node can validly be resolved to a prefix:
4011 * 4912 *
4012 * * it is the prefix in an import directive, or 4913 * * it is the prefix in an import directive, or
4013 * * it is the prefix in a prefixed identifier. 4914 * * it is the prefix in a prefixed identifier.
4014 * 4915 *
4015 * 4916 *
4016 * @param node the node being tested 4917 * @param node the node being tested
4017 * @return `true` if the given node is the prefix in an import directive 4918 * @return `true` if the given node is the prefix in an import directive
4018 */ 4919 */
4019 bool isValidAsPrefix(SimpleIdentifier node) { 4920 bool isValidAsPrefix(SimpleIdentifier node) {
4020 ASTNode parent = node.parent; 4921 ASTNode parent = node.parent;
4021 if (parent is ImportDirective) { 4922 if (parent is ImportDirective) {
4022 return identical(((parent as ImportDirective)).prefix, node); 4923 return identical((parent as ImportDirective).prefix, node);
4023 } else if (parent is PrefixedIdentifier) { 4924 } else if (parent is PrefixedIdentifier) {
4024 return true; 4925 return true;
4025 } else if (parent is MethodInvocation) { 4926 } else if (parent is MethodInvocation) {
4026 return identical(((parent as MethodInvocation)).target, node); 4927 return identical((parent as MethodInvocation).target, node);
4027 } 4928 }
4028 return false; 4929 return false;
4029 } 4930 }
4030 4931
4031 /** 4932 /**
4032 * Look up the getter with the given name in the given type. Return the elemen t representing the 4933 * Look up the getter with the given name in the given type. Return the elemen t representing the
4033 * getter that was found, or `null` if there is no getter with the given name. 4934 * getter that was found, or `null` if there is no getter with the given name.
4034 * 4935 *
4035 * @param target the target of the invocation, or `null` if there is no target 4936 * @param target the target of the invocation, or `null` if there is no target
4036 * @param type the type in which the getter is defined 4937 * @param type the type in which the getter is defined
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
4184 if (labelNode == null) { 5085 if (labelNode == null) {
4185 if (labelScope == null) { 5086 if (labelScope == null) {
4186 } else { 5087 } else {
4187 labelElement = labelScope.lookup2(LabelScope.EMPTY_LABEL) as LabelElemen tImpl; 5088 labelElement = labelScope.lookup2(LabelScope.EMPTY_LABEL) as LabelElemen tImpl;
4188 if (labelElement == null) { 5089 if (labelElement == null) {
4189 } 5090 }
4190 labelElement = null; 5091 labelElement = null;
4191 } 5092 }
4192 } else { 5093 } else {
4193 if (labelScope == null) { 5094 if (labelScope == null) {
4194 _resolver.reportError5(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]); 5095 _resolver.reportError6(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]);
4195 } else { 5096 } else {
4196 labelElement = labelScope.lookup(labelNode) as LabelElementImpl; 5097 labelElement = labelScope.lookup(labelNode) as LabelElementImpl;
4197 if (labelElement == null) { 5098 if (labelElement == null) {
4198 _resolver.reportError5(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode , [labelNode.name]); 5099 _resolver.reportError6(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode , [labelNode.name]);
4199 } else { 5100 } else {
4200 labelNode.staticElement = labelElement; 5101 labelNode.staticElement = labelElement;
4201 } 5102 }
4202 } 5103 }
4203 } 5104 }
4204 if (labelElement != null) { 5105 if (labelElement != null) {
4205 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent); 5106 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent);
4206 if (labelContainer != _resolver.enclosingFunction) { 5107 if (labelContainer != _resolver.enclosingFunction) {
4207 _resolver.reportError5(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN ode, [labelNode.name]); 5108 _resolver.reportError6(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelN ode, [labelNode.name]);
4208 labelElement = null; 5109 labelElement = null;
4209 } 5110 }
4210 } 5111 }
4211 return labelElement; 5112 return labelElement;
4212 } 5113 }
4213 5114
4214 /** 5115 /**
4215 * Look up the method with the given name in the given type. Return the elemen t representing the 5116 * Look up the method with the given name in the given type. Return the elemen t representing the
4216 * method that was found, or `null` if there is no method with the given name. 5117 * method that was found, or `null` if there is no method with the given name.
4217 * 5118 *
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
4408 } else if (operator == sc.TokenType.STAR_EQ) { 5309 } else if (operator == sc.TokenType.STAR_EQ) {
4409 return sc.TokenType.STAR; 5310 return sc.TokenType.STAR;
4410 } else if (operator == sc.TokenType.TILDE_SLASH_EQ) { 5311 } else if (operator == sc.TokenType.TILDE_SLASH_EQ) {
4411 return sc.TokenType.TILDE_SLASH; 5312 return sc.TokenType.TILDE_SLASH;
4412 } 5313 }
4413 break; 5314 break;
4414 } 5315 }
4415 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to it's corresponding operator"); 5316 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to it's corresponding operator");
4416 return operator; 5317 return operator;
4417 } 5318 }
5319
4418 void resolveAnnotationConstructorInvocationArguments(Annotation annotation, Co nstructorElement constructor) { 5320 void resolveAnnotationConstructorInvocationArguments(Annotation annotation, Co nstructorElement constructor) {
4419 ArgumentList argumentList = annotation.arguments; 5321 ArgumentList argumentList = annotation.arguments;
4420 if (argumentList == null) { 5322 if (argumentList == null) {
4421 return; 5323 return;
4422 } 5324 }
4423 List<ParameterElement> parameters = resolveArgumentsToParameters(true, argum entList, constructor); 5325 List<ParameterElement> parameters = resolveArgumentsToParameters(true, argum entList, constructor);
4424 if (parameters != null) { 5326 if (parameters != null) {
4425 argumentList.correspondingStaticParameters = parameters; 5327 argumentList.correspondingStaticParameters = parameters;
4426 } 5328 }
4427 } 5329 }
4428 5330
4429 /** 5331 /**
4430 * Validates that the given [Element] is the constant variable; or resolves it as a 5332 * Continues resolution of the given [Annotation].
4431 * constructor invocation.
4432 * 5333 *
4433 * @param annotation the [Annotation] to resolve 5334 * @param annotation the [Annotation] to resolve
4434 * @param element the current known [Element] of the annotation, or [ClassElem ent]
4435 * @param nameNode the name of the invoked constructor, may be `null` if unnam ed constructor
4436 * or not a constructor invocation
4437 */ 5335 */
4438 void resolveAnnotationElement(Annotation annotation, Element element, SimpleId entifier nameNode) { 5336 void resolveAnnotationElement(Annotation annotation) {
4439 if (element is PropertyAccessorElement) { 5337 SimpleIdentifier nameNode1;
4440 PropertyAccessorElement accessorElement = element as PropertyAccessorEleme nt; 5338 SimpleIdentifier nameNode2;
4441 if (!accessorElement.isSynthetic) { 5339 {
4442 _resolver.reportError5(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []); 5340 Identifier annName = annotation.name;
5341 if (annName is PrefixedIdentifier) {
5342 PrefixedIdentifier prefixed = annName as PrefixedIdentifier;
5343 nameNode1 = prefixed.prefix;
5344 nameNode2 = prefixed.identifier;
5345 } else {
5346 nameNode1 = annName as SimpleIdentifier;
5347 nameNode2 = null;
5348 }
5349 }
5350 SimpleIdentifier nameNode3 = annotation.constructorName;
5351 ConstructorElement constructor = null;
5352 if (nameNode1 != null && nameNode2 == null && nameNode3 == null) {
5353 Element element1 = nameNode1.staticElement;
5354 if (element1 is PropertyAccessorElement) {
5355 resolveAnnotationElementGetter(annotation, element1 as PropertyAccessorE lement);
4443 return; 5356 return;
4444 } 5357 }
4445 VariableElement variableElement = accessorElement.variable; 5358 if (element1 is ClassElement) {
4446 if (!variableElement.isConst) { 5359 ClassElement classElement = element1 as ClassElement;
4447 _resolver.reportError5(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []); 5360 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (null, _definingLibrary);
4448 } 5361 }
5362 }
5363 if (nameNode1 != null && nameNode2 != null && nameNode3 == null) {
5364 Element element1 = nameNode1.staticElement;
5365 Element element2 = nameNode2.staticElement;
5366 if (element1 is ClassElement) {
5367 ClassElement classElement = element1 as ClassElement;
5368 element2 = classElement.lookUpGetter(nameNode2.name, _definingLibrary);
5369 }
5370 if (element2 is PropertyAccessorElement) {
5371 nameNode2.staticElement = element2;
5372 annotation.element = element2;
5373 resolveAnnotationElementGetter(annotation, element2 as PropertyAccessorE lement);
5374 return;
5375 }
5376 if (element2 is ClassElement) {
5377 ClassElement classElement = element2 as ClassElement;
5378 constructor = classElement.unnamedConstructor;
5379 }
5380 if (element1 is ClassElement) {
5381 ClassElement classElement = element1 as ClassElement;
5382 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (nameNode2.name, _definingLibrary);
5383 nameNode2.staticElement = constructor;
5384 }
5385 }
5386 if (nameNode1 != null && nameNode2 != null && nameNode3 != null) {
5387 Element element2 = nameNode2.staticElement;
5388 if (element2 is ClassElement) {
5389 ClassElement classElement = element2 as ClassElement;
5390 String name3 = nameNode3.name;
5391 PropertyAccessorElement getter = classElement.lookUpGetter(name3, _defin ingLibrary);
5392 if (getter != null) {
5393 nameNode3.staticElement = getter;
5394 annotation.element = element2;
5395 resolveAnnotationElementGetter(annotation, getter);
5396 return;
5397 }
5398 constructor = new InterfaceTypeImpl.con1(classElement).lookUpConstructor (name3, _definingLibrary);
5399 nameNode3.staticElement = constructor;
5400 }
5401 }
5402 if (constructor == null) {
5403 _resolver.reportError6(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []);
4449 return; 5404 return;
4450 } 5405 }
4451 if (element is ClassElement) { 5406 annotation.element = constructor;
4452 if (nameNode == null) { 5407 resolveAnnotationConstructorInvocationArguments(annotation, constructor);
4453 nameNode = annotation.constructorName; 5408 }
4454 } 5409
4455 String name = nameNode != null ? nameNode.name : null; 5410 void resolveAnnotationElementGetter(Annotation annotation, PropertyAccessorEle ment accessorElement) {
4456 ConstructorElement constructor; 5411 if (!accessorElement.isSynthetic) {
4457 { 5412 _resolver.reportError6(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []);
4458 InterfaceType interfaceType = new InterfaceTypeImpl.con1(element as Clas sElement);
4459 constructor = interfaceType.lookUpConstructor(name, _definingLibrary);
4460 }
4461 if (constructor == null) {
4462 _resolver.reportError5(CompileTimeErrorCode.INVALID_ANNOTATION, annotati on, []);
4463 return;
4464 }
4465 annotation.element = constructor;
4466 if (nameNode != null) {
4467 nameNode.staticElement = constructor;
4468 }
4469 resolveAnnotationConstructorInvocationArguments(annotation, constructor);
4470 return; 5413 return;
4471 } 5414 }
4472 if (element != null) { 5415 VariableElement variableElement = accessorElement.variable;
4473 _resolver.reportError5(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []); 5416 if (!variableElement.isConst) {
5417 _resolver.reportError6(CompileTimeErrorCode.INVALID_ANNOTATION, annotation , []);
4474 } 5418 }
5419 return;
4475 } 5420 }
4476 5421
4477 /** 5422 /**
4478 * Given a list of arguments and the element that will be invoked using those argument, compute 5423 * Given a list of arguments and the element that will be invoked using those argument, compute
4479 * the list of parameters that correspond to the list of arguments. Return the parameters that 5424 * the list of parameters that correspond to the list of arguments. Return the parameters that
4480 * correspond to the arguments, or `null` if no correspondence could be comput ed. 5425 * correspond to the arguments, or `null` if no correspondence could be comput ed.
4481 * 5426 *
4482 * @param reportError if `true` then compile-time error should be reported; if `false` 5427 * @param reportError if `true` then compile-time error should be reported; if `false`
4483 * then compile-time warning 5428 * then compile-time warning
4484 * @param argumentList the list of arguments being passed to the element 5429 * @param argumentList the list of arguments being passed to the element
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 int unnamedParameterCount = unnamedParameters.length; 5468 int unnamedParameterCount = unnamedParameters.length;
4524 int unnamedIndex = 0; 5469 int unnamedIndex = 0;
4525 NodeList<Expression> arguments = argumentList.arguments; 5470 NodeList<Expression> arguments = argumentList.arguments;
4526 int argumentCount = arguments.length; 5471 int argumentCount = arguments.length;
4527 List<ParameterElement> resolvedParameters = new List<ParameterElement>(argum entCount); 5472 List<ParameterElement> resolvedParameters = new List<ParameterElement>(argum entCount);
4528 int positionalArgumentCount = 0; 5473 int positionalArgumentCount = 0;
4529 Set<String> usedNames = new Set<String>(); 5474 Set<String> usedNames = new Set<String>();
4530 for (int i = 0; i < argumentCount; i++) { 5475 for (int i = 0; i < argumentCount; i++) {
4531 Expression argument = arguments[i]; 5476 Expression argument = arguments[i];
4532 if (argument is NamedExpression) { 5477 if (argument is NamedExpression) {
4533 SimpleIdentifier nameNode = ((argument as NamedExpression)).name.label; 5478 SimpleIdentifier nameNode = (argument as NamedExpression).name.label;
4534 String name = nameNode.name; 5479 String name = nameNode.name;
4535 ParameterElement element = namedParameters[name]; 5480 ParameterElement element = namedParameters[name];
4536 if (element == null) { 5481 if (element == null) {
4537 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode; 5482 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.UNDEFINED_NA MED_PARAMETER : StaticWarningCode.UNDEFINED_NAMED_PARAMETER) as ErrorCode;
4538 _resolver.reportError5(errorCode, nameNode, [name]); 5483 _resolver.reportError6(errorCode, nameNode, [name]);
4539 } else { 5484 } else {
4540 resolvedParameters[i] = element; 5485 resolvedParameters[i] = element;
4541 nameNode.staticElement = element; 5486 nameNode.staticElement = element;
4542 } 5487 }
4543 if (!javaSetAdd(usedNames, name)) { 5488 if (!javaSetAdd(usedNames, name)) {
4544 _resolver.reportError5(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]); 5489 _resolver.reportError6(CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT, nameNode, [name]);
4545 } 5490 }
4546 } else { 5491 } else {
4547 positionalArgumentCount++; 5492 positionalArgumentCount++;
4548 if (unnamedIndex < unnamedParameterCount) { 5493 if (unnamedIndex < unnamedParameterCount) {
4549 resolvedParameters[i] = unnamedParameters[unnamedIndex++]; 5494 resolvedParameters[i] = unnamedParameters[unnamedIndex++];
4550 } 5495 }
4551 } 5496 }
4552 } 5497 }
4553 if (positionalArgumentCount < requiredParameters.length) { 5498 if (positionalArgumentCount < requiredParameters.length) {
4554 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode; 5499 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.NOT_ENOUGH_REQUI RED_ARGUMENTS : StaticWarningCode.NOT_ENOUGH_REQUIRED_ARGUMENTS) as ErrorCode;
4555 _resolver.reportError5(errorCode, argumentList, [requiredParameters.length , positionalArgumentCount]); 5500 _resolver.reportError6(errorCode, argumentList, [requiredParameters.length , positionalArgumentCount]);
4556 } else if (positionalArgumentCount > unnamedParameterCount) { 5501 } else if (positionalArgumentCount > unnamedParameterCount) {
4557 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL _ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode; 5502 ErrorCode errorCode = (reportError ? CompileTimeErrorCode.EXTRA_POSITIONAL _ARGUMENTS : StaticWarningCode.EXTRA_POSITIONAL_ARGUMENTS) as ErrorCode;
4558 _resolver.reportError5(errorCode, argumentList, [unnamedParameterCount, po sitionalArgumentCount]); 5503 _resolver.reportError6(errorCode, argumentList, [unnamedParameterCount, po sitionalArgumentCount]);
4559 } 5504 }
4560 return resolvedParameters; 5505 return resolvedParameters;
4561 } 5506 }
4562 5507
4563 /** 5508 /**
4564 * Resolve the names in the given combinators in the scope of the given librar y. 5509 * Resolve the names in the given combinators in the scope of the given librar y.
4565 * 5510 *
4566 * @param library the library that defines the names 5511 * @param library the library that defines the names
4567 * @param combinators the combinators containing the names to be resolved 5512 * @param combinators the combinators containing the names to be resolved
4568 */ 5513 */
4569 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) { 5514 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) {
4570 if (library == null) { 5515 if (library == null) {
4571 return; 5516 return;
4572 } 5517 }
4573 Namespace namespace = new NamespaceBuilder().createExportNamespace2(library) ; 5518 Namespace namespace = new NamespaceBuilder().createExportNamespace2(library) ;
4574 for (Combinator combinator in combinators) { 5519 for (Combinator combinator in combinators) {
4575 NodeList<SimpleIdentifier> names; 5520 NodeList<SimpleIdentifier> names;
4576 if (combinator is HideCombinator) { 5521 if (combinator is HideCombinator) {
4577 names = ((combinator as HideCombinator)).hiddenNames; 5522 names = (combinator as HideCombinator).hiddenNames;
4578 } else { 5523 } else {
4579 names = ((combinator as ShowCombinator)).shownNames; 5524 names = (combinator as ShowCombinator).shownNames;
4580 } 5525 }
4581 for (SimpleIdentifier name in names) { 5526 for (SimpleIdentifier name in names) {
4582 Element element = namespace.get(name.name); 5527 Element element = namespace.get(name.name);
4583 if (element != null) { 5528 if (element != null) {
4584 name.staticElement = element; 5529 name.staticElement = element;
4585 } 5530 }
4586 } 5531 }
4587 } 5532 }
4588 } 5533 }
4589 5534
4590 /** 5535 /**
5536 * Given an invocation of the form 'C.x()' where 'C' is a class, find and retu rn the element 'x'
5537 * in 'C'.
5538 *
5539 * @param classElement the class element
5540 * @param memberName the member name
5541 */
5542 Element resolveElement(ClassElementImpl classElement, String memberName) {
5543 Element element = null;
5544 String methodNameStr = memberName;
5545 element = classElement.getMethod(methodNameStr);
5546 if (element == null) {
5547 element = classElement.getSetter(memberName);
5548 if (element == null) {
5549 element = classElement.getGetter(memberName);
5550 }
5551 }
5552 if (element != null && element.isAccessibleIn(_definingLibrary)) {
5553 return element;
5554 }
5555 return null;
5556 }
5557
5558 /**
4591 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el ement being invoked. 5559 * Given an invocation of the form 'e.m(a1, ..., an)', resolve 'e.m' to the el ement being invoked.
4592 * If the returned element is a method, then the method will be invoked. If th e returned element 5560 * If the returned element is a method, then the method will be invoked. If th e returned element
4593 * is a getter, the getter will be invoked without arguments and the result of that invocation 5561 * is a getter, the getter will be invoked without arguments and the result of that invocation
4594 * will then be invoked with the arguments. 5562 * will then be invoked with the arguments.
4595 * 5563 *
4596 * @param target the target of the invocation ('e') 5564 * @param target the target of the invocation ('e')
4597 * @param targetType the type of the target 5565 * @param targetType the type of the target
4598 * @param methodName the name of the method being invoked ('m') 5566 * @param methodName the name of the method being invoked ('m')
4599 * @return the element being invoked 5567 * @return the element being invoked
4600 */ 5568 */
4601 Element resolveInvokedElement(Expression target, Type2 targetType, SimpleIdent ifier methodName) { 5569 Element resolveInvokedElement(Expression target, Type2 targetType, SimpleIdent ifier methodName) {
4602 if (targetType is InterfaceType) { 5570 if (targetType is InterfaceType) {
4603 InterfaceType classType = targetType as InterfaceType; 5571 InterfaceType classType = targetType as InterfaceType;
4604 Element element = lookUpMethod(target, classType, methodName.name); 5572 Element element = lookUpMethod(target, classType, methodName.name);
4605 if (element == null) { 5573 if (element == null) {
4606 element = lookUpGetter(target, classType, methodName.name); 5574 element = lookUpGetter(target, classType, methodName.name);
4607 } 5575 }
4608 return element; 5576 return element;
4609 } else if (target is SimpleIdentifier) { 5577 } else if (target is SimpleIdentifier) {
4610 Element targetElement = ((target as SimpleIdentifier)).staticElement; 5578 Element targetElement = (target as SimpleIdentifier).staticElement;
4611 if (targetElement is PrefixElement) { 5579 if (targetElement is PrefixElement) {
4612 String name = "${((target as SimpleIdentifier)).name}.${methodName}"; 5580 String name = "${(target as SimpleIdentifier).name}.${methodName}";
4613 Identifier functionName = new ElementResolver_SyntheticIdentifier(name); 5581 Identifier functionName = new ElementResolver_SyntheticIdentifier(name);
4614 Element element = _resolver.nameScope.lookup(functionName, _definingLibr ary); 5582 Element element = _resolver.nameScope.lookup(functionName, _definingLibr ary);
4615 if (element != null) { 5583 if (element != null) {
4616 return element; 5584 return element;
4617 } 5585 }
4618 } 5586 }
4619 } 5587 }
4620 return null; 5588 return null;
4621 } 5589 }
4622 5590
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4659 memberElement = lookUpSetter(target, targetType, propertyName.name); 5627 memberElement = lookUpSetter(target, targetType, propertyName.name);
4660 } 5628 }
4661 if (memberElement == null) { 5629 if (memberElement == null) {
4662 memberElement = lookUpGetter(target, targetType, propertyName.name); 5630 memberElement = lookUpGetter(target, targetType, propertyName.name);
4663 } 5631 }
4664 if (memberElement == null) { 5632 if (memberElement == null) {
4665 memberElement = lookUpMethod(target, targetType, propertyName.name); 5633 memberElement = lookUpMethod(target, targetType, propertyName.name);
4666 } 5634 }
4667 return memberElement; 5635 return memberElement;
4668 } 5636 }
5637
4669 void resolvePropertyAccess(Expression target, SimpleIdentifier propertyName) { 5638 void resolvePropertyAccess(Expression target, SimpleIdentifier propertyName) {
4670 Type2 staticType = getStaticType(target); 5639 Type2 staticType = getStaticType(target);
4671 ExecutableElement staticElement = resolveProperty(target, staticType, proper tyName); 5640 Type2 propagatedType = getPropagatedType(target);
5641 Element staticElement = null;
5642 Element propagatedElement = null;
5643 ClassElementImpl typeReference = getTypeReference(target);
5644 if (typeReference != null) {
5645 staticElement = propagatedElement = resolveElement(typeReference, property Name.name);
5646 } else {
5647 staticElement = resolveProperty(target, staticType, propertyName);
5648 propagatedElement = resolveProperty(target, propagatedType, propertyName);
5649 }
4672 if (target.parent.parent is Annotation) { 5650 if (target.parent.parent is Annotation) {
4673 if (staticElement != null) { 5651 if (staticElement != null) {
4674 propertyName.staticElement = staticElement; 5652 propertyName.staticElement = staticElement;
4675 } 5653 }
4676 return; 5654 return;
4677 } 5655 }
4678 propertyName.staticElement = staticElement; 5656 propertyName.staticElement = staticElement;
4679 Type2 propagatedType = getPropagatedType(target);
4680 ExecutableElement propagatedElement = resolveProperty(target, propagatedType , propertyName);
4681 propertyName.propagatedElement = propagatedElement; 5657 propertyName.propagatedElement = propagatedElement;
4682 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement)); 5658 bool shouldReportMissingMember_static = shouldReportMissingMember(staticType , staticElement) && (_strictMode || shouldReportMissingMember(propagatedType, pr opagatedElement));
4683 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false; 5659 bool shouldReportMissingMember_propagated = !shouldReportMissingMember_stati c && _enableHints ? shouldReportMissingMember(propagatedType, propagatedElement) : false;
4684 if (shouldReportMissingMember_propagated) { 5660 if (shouldReportMissingMember_propagated) {
4685 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) { 5661 if (memberFoundInSubclass(propagatedType.element, propertyName.name, false , true)) {
4686 shouldReportMissingMember_propagated = false; 5662 shouldReportMissingMember_propagated = false;
4687 } 5663 }
4688 } 5664 }
4689 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) { 5665 if (shouldReportMissingMember_static || shouldReportMissingMember_propagated ) {
4690 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element; 5666 Element staticOrPropagatedEnclosingElt = shouldReportMissingMember_static ? staticType.element : propagatedType.element;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4723 * Resolve the given simple identifier if possible. Return the element to whic h it could be 5699 * Resolve the given simple identifier if possible. Return the element to whic h it could be
4724 * resolved, or `null` if it could not be resolved. This does not record the r esults of the 5700 * resolved, or `null` if it could not be resolved. This does not record the r esults of the
4725 * resolution. 5701 * resolution.
4726 * 5702 *
4727 * @param node the identifier to be resolved 5703 * @param node the identifier to be resolved
4728 * @return the element to which the identifier could be resolved 5704 * @return the element to which the identifier could be resolved
4729 */ 5705 */
4730 Element resolveSimpleIdentifier(SimpleIdentifier node) { 5706 Element resolveSimpleIdentifier(SimpleIdentifier node) {
4731 Element element = _resolver.nameScope.lookup(node, _definingLibrary); 5707 Element element = _resolver.nameScope.lookup(node, _definingLibrary);
4732 if (element is PropertyAccessorElement && node.inSetterContext()) { 5708 if (element is PropertyAccessorElement && node.inSetterContext()) {
4733 PropertyInducingElement variable = ((element as PropertyAccessorElement)). variable; 5709 PropertyInducingElement variable = (element as PropertyAccessorElement).va riable;
4734 if (variable != null) { 5710 if (variable != null) {
4735 PropertyAccessorElement setter = variable.setter; 5711 PropertyAccessorElement setter = variable.setter;
4736 if (setter == null) { 5712 if (setter == null) {
4737 ClassElement enclosingClass = _resolver.enclosingClass; 5713 ClassElement enclosingClass = _resolver.enclosingClass;
4738 if (enclosingClass != null) { 5714 if (enclosingClass != null) {
4739 setter = lookUpSetter(null, enclosingClass.type, node.name); 5715 setter = lookUpSetter(null, enclosingClass.type, node.name);
4740 } 5716 }
4741 } 5717 }
4742 if (setter != null) { 5718 if (setter != null) {
4743 element = setter; 5719 element = setter;
(...skipping 21 matching lines...) Expand all
4765 /** 5741 /**
4766 * If the given type is a type parameter, resolve it to the type that should b e used when looking 5742 * If the given type is a type parameter, resolve it to the type that should b e used when looking
4767 * up members. Otherwise, return the original type. 5743 * up members. Otherwise, return the original type.
4768 * 5744 *
4769 * @param type the type that is to be resolved if it is a type parameter 5745 * @param type the type that is to be resolved if it is a type parameter
4770 * @return the type that should be used in place of the argument if it is a ty pe parameter, or the 5746 * @return the type that should be used in place of the argument if it is a ty pe parameter, or the
4771 * original argument if it isn't a type parameter 5747 * original argument if it isn't a type parameter
4772 */ 5748 */
4773 Type2 resolveTypeParameter(Type2 type) { 5749 Type2 resolveTypeParameter(Type2 type) {
4774 if (type is TypeParameterType) { 5750 if (type is TypeParameterType) {
4775 Type2 bound = ((type as TypeParameterType)).element.bound; 5751 Type2 bound = (type as TypeParameterType).element.bound;
4776 if (bound == null) { 5752 if (bound == null) {
4777 return _resolver.typeProvider.objectType; 5753 return _resolver.typeProvider.objectType;
4778 } 5754 }
4779 return bound; 5755 return bound;
4780 } 5756 }
4781 return type; 5757 return type;
4782 } 5758 }
4783 5759
4784 /** 5760 /**
4785 * Return the propagated element if it is not `null`, or the static element if it is. 5761 * Return the propagated element if it is not `null`, or the static element if it is.
(...skipping 23 matching lines...) Expand all
4809 addAnnotations(annotationList, list.metadata); 5785 addAnnotations(annotationList, list.metadata);
4810 if (list.parent is FieldDeclaration) { 5786 if (list.parent is FieldDeclaration) {
4811 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; 5787 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration;
4812 addAnnotations(annotationList, fieldDeclaration.metadata); 5788 addAnnotations(annotationList, fieldDeclaration.metadata);
4813 } else if (list.parent is TopLevelVariableDeclaration) { 5789 } else if (list.parent is TopLevelVariableDeclaration) {
4814 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve lVariableDeclaration; 5790 TopLevelVariableDeclaration variableDeclaration = list.parent as TopLeve lVariableDeclaration;
4815 addAnnotations(annotationList, variableDeclaration.metadata); 5791 addAnnotations(annotationList, variableDeclaration.metadata);
4816 } 5792 }
4817 } 5793 }
4818 if (!annotationList.isEmpty) { 5794 if (!annotationList.isEmpty) {
4819 ((element as ElementImpl)).metadata = new List.from(annotationList); 5795 (element as ElementImpl).metadata = new List.from(annotationList);
4820 } 5796 }
4821 } 5797 }
4822 5798
4823 /** 5799 /**
4824 * Return `true` if we should report an error as a result of looking up a memb er in the 5800 * Return `true` if we should report an error as a result of looking up a memb er in the
4825 * given type and not finding any member. 5801 * given type and not finding any member.
4826 * 5802 *
4827 * @param type the type in which we attempted to perform the look-up 5803 * @param type the type in which we attempted to perform the look-up
4828 * @param member the result of the look-up 5804 * @param member the result of the look-up
4829 * @return `true` if we should report an error 5805 * @return `true` if we should report an error
4830 */ 5806 */
4831 bool shouldReportMissingMember(Type2 type, ExecutableElement member) { 5807 bool shouldReportMissingMember(Type2 type, Element member) {
4832 if (member != null || type == null || type.isDynamic || type.isBottom) { 5808 if (member != null || type == null || type.isDynamic || type.isBottom) {
4833 return false; 5809 return false;
4834 } 5810 }
4835 return true; 5811 return true;
4836 } 5812 }
4837 } 5813 }
5814
4838 /** 5815 /**
4839 * Instances of the class `SyntheticIdentifier` implement an identifier that can be used to 5816 * Instances of the class `SyntheticIdentifier` implement an identifier that can be used to
4840 * look up names in the lexical scope when there is no identifier in the AST str ucture. There is 5817 * look up names in the lexical scope when there is no identifier in the AST str ucture. There is
4841 * no identifier in the AST when the parser could not distinguish between a meth od invocation and 5818 * no identifier in the AST when the parser could not distinguish between a meth od invocation and
4842 * an invocation of a top-level function imported with a prefix. 5819 * an invocation of a top-level function imported with a prefix.
4843 */ 5820 */
4844 class ElementResolver_SyntheticIdentifier extends Identifier { 5821 class ElementResolver_SyntheticIdentifier extends Identifier {
4845
4846 /** 5822 /**
4847 * The name of the synthetic identifier. 5823 * The name of the synthetic identifier.
4848 */ 5824 */
4849 String _name; 5825 String _name;
4850 5826
4851 /** 5827 /**
4852 * Initialize a newly created synthetic identifier to have the given name. 5828 * Initialize a newly created synthetic identifier to have the given name.
4853 * 5829 *
4854 * @param name the name of the synthetic identifier 5830 * @param name the name of the synthetic identifier
4855 */ 5831 */
4856 ElementResolver_SyntheticIdentifier(String name) { 5832 ElementResolver_SyntheticIdentifier(String name) {
4857 this._name = name; 5833 this._name = name;
4858 } 5834 }
5835
4859 accept(ASTVisitor visitor) => null; 5836 accept(ASTVisitor visitor) => null;
5837
4860 sc.Token get beginToken => null; 5838 sc.Token get beginToken => null;
5839
4861 Element get bestElement => null; 5840 Element get bestElement => null;
5841
4862 sc.Token get endToken => null; 5842 sc.Token get endToken => null;
5843
4863 String get name => _name; 5844 String get name => _name;
5845
4864 Element get propagatedElement => null; 5846 Element get propagatedElement => null;
5847
4865 Element get staticElement => null; 5848 Element get staticElement => null;
5849
4866 void visitChildren(ASTVisitor visitor) { 5850 void visitChildren(ASTVisitor visitor) {
4867 } 5851 }
4868 } 5852 }
5853
5854 /**
5855 * Instances of the class `IncrementalResolver` resolve the smallest portion of an AST
5856 * structure that we currently know how to resolve.
5857 */
5858 class IncrementalResolver {
5859 /**
5860 * The element for the library containing the compilation unit being visited.
5861 */
5862 LibraryElement _definingLibrary;
5863
5864 /**
5865 * The source representing the compilation unit being visited.
5866 */
5867 Source _source;
5868
5869 /**
5870 * The object used to access the types from the core library.
5871 */
5872 TypeProvider _typeProvider;
5873
5874 /**
5875 * The error listener that will be informed of any errors that are found durin g resolution.
5876 */
5877 AnalysisErrorListener _errorListener;
5878
5879 /**
5880 * Initialize a newly created incremental resolver to resolve a node in the gi ven source in the
5881 * given library, reporting errors to the given error listener.
5882 *
5883 * @param definingLibrary the element for the library containing the compilati on unit being
5884 * visited
5885 * @param source the source representing the compilation unit being visited
5886 * @param typeProvider the object used to access the types from the core libra ry
5887 * @param errorListener the error listener that will be informed of any errors that are found
5888 * during resolution
5889 */
5890 IncrementalResolver(LibraryElement definingLibrary, Source source, TypeProvide r typeProvider, AnalysisErrorListener errorListener) {
5891 this._definingLibrary = definingLibrary;
5892 this._source = source;
5893 this._typeProvider = typeProvider;
5894 this._errorListener = errorListener;
5895 }
5896
5897 /**
5898 * Resolve the given node, reporting any errors or warnings to the given liste ner.
5899 *
5900 * @param node the root of the AST structure to be resolved
5901 * @throws AnalysisException if the node could not be resolved
5902 */
5903 void resolve(ASTNode node) {
5904 ASTNode rootNode = findResolutionRoot(node);
5905 Scope scope = ScopeBuilder.scopeFor(rootNode, _errorListener);
5906 if (elementModelChanged(rootNode.parent)) {
5907 throw new AnalysisException.con1("Cannot resolve node: element model chang ed");
5908 }
5909 resolveTypes(node, scope);
5910 resolveVariables(node, scope);
5911 resolveReferences(node, scope);
5912 }
5913
5914 /**
5915 * Return `true` if the given node can be resolved independently of any other nodes.
5916 *
5917 * <b>Note:</b> This method needs to be kept in sync with [ScopeBuilder#scopeF orAstNode].
5918 *
5919 * @param node the node being tested
5920 * @return `true` if the given node can be resolved independently of any other nodes
5921 */
5922 bool canBeResolved(ASTNode node) => node is ClassDeclaration || node is ClassT ypeAlias || node is CompilationUnit || node is ConstructorDeclaration || node is FunctionDeclaration || node is FunctionTypeAlias || node is MethodDeclaration;
5923
5924 /**
5925 * Return `true` if the portion of the element model defined by the given node has changed.
5926 *
5927 * @param node the node defining the portion of the element model being tested
5928 * @return `true` if the element model defined by the given node has changed
5929 * @throws AnalysisException if the correctness of the element model cannot be determined
5930 */
5931 bool elementModelChanged(ASTNode node) {
5932 Element element = getElement(node);
5933 if (element == null) {
5934 throw new AnalysisException.con1("Cannot resolve node: a ${node.runtimeTyp e.toString()} does not define an element");
5935 }
5936 DeclarationMatcher matcher = new DeclarationMatcher();
5937 return !matcher.matches(node, element);
5938 }
5939
5940 /**
5941 * Starting at the given node, find the smallest AST node that can be resolved independently of
5942 * any other nodes. Return the node that was found.
5943 *
5944 * @param node the node at which the search is to begin
5945 * @return the smallest AST node that can be resolved independently of any oth er nodes
5946 * @throws AnalysisException if there is no such node
5947 */
5948 ASTNode findResolutionRoot(ASTNode node) {
5949 ASTNode result = node;
5950 ASTNode parent = result.parent;
5951 while (parent != null && !canBeResolved(parent)) {
5952 result = parent;
5953 parent = result.parent;
5954 }
5955 if (parent == null) {
5956 throw new AnalysisException.con1("Cannot resolve node: no resolvable node" );
5957 }
5958 return result;
5959 }
5960
5961 /**
5962 * Return the element defined by the given node, or `null` if the node does no t define an
5963 * element.
5964 *
5965 * @param node the node defining the element to be returned
5966 * @return the element defined by the given node
5967 */
5968 Element getElement(ASTNode node) {
5969 if (node is Declaration) {
5970 return (node as Declaration).element;
5971 } else if (node is CompilationUnit) {
5972 return (node as CompilationUnit).element;
5973 }
5974 return null;
5975 }
5976
5977 void resolveReferences(ASTNode node, Scope scope) {
5978 ResolverVisitor visitor = new ResolverVisitor.con3(_definingLibrary, _source , _typeProvider, scope, _errorListener);
5979 node.accept(visitor);
5980 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondition alAnalysisErrors) {
5981 if (conditionalCode.shouldIncludeErrorCode()) {
5982 visitor.reportError(conditionalCode.analysisError);
5983 }
5984 }
5985 }
5986
5987 void resolveTypes(ASTNode node, Scope scope) {
5988 TypeResolverVisitor visitor = new TypeResolverVisitor.con3(_definingLibrary, _source, _typeProvider, scope, _errorListener);
5989 node.accept(visitor);
5990 }
5991
5992 void resolveVariables(ASTNode node, Scope scope) {
5993 VariableResolverVisitor visitor = new VariableResolverVisitor.con2(_defining Library, _source, _typeProvider, scope, _errorListener);
5994 node.accept(visitor);
5995 }
5996 }
5997
4869 /** 5998 /**
4870 * Instances of the class `InheritanceManager` manage the knowledge of where cla ss members 5999 * Instances of the class `InheritanceManager` manage the knowledge of where cla ss members
4871 * (methods, getters & setters) are inherited from. 6000 * (methods, getters & setters) are inherited from.
4872 * 6001 *
4873 * @coverage dart.engine.resolver 6002 * @coverage dart.engine.resolver
4874 */ 6003 */
4875 class InheritanceManager { 6004 class InheritanceManager {
4876
4877 /** 6005 /**
4878 * The [LibraryElement] that is managed by this manager. 6006 * The [LibraryElement] that is managed by this manager.
4879 */ 6007 */
4880 LibraryElement _library; 6008 LibraryElement _library;
4881 6009
4882 /** 6010 /**
4883 * This is a mapping between each [ClassElement] and a map between the [String ] member 6011 * This is a mapping between each [ClassElement] and a map between the [String ] member
4884 * names and the associated [ExecutableElement] in the mixin and superclass ch ain. 6012 * names and the associated [ExecutableElement] in the mixin and superclass ch ain.
4885 */ 6013 */
4886 Map<ClassElement, MemberMap> _classLookup; 6014 Map<ClassElement, MemberMap> _classLookup;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
5227 int numOfEltsWithMatchingNames = set.length; 6355 int numOfEltsWithMatchingNames = set.length;
5228 if (numOfEltsWithMatchingNames == 1) { 6356 if (numOfEltsWithMatchingNames == 1) {
5229 resultMap.put(key, new JavaIterator(set).next()); 6357 resultMap.put(key, new JavaIterator(set).next());
5230 } else { 6358 } else {
5231 bool allMethods = true; 6359 bool allMethods = true;
5232 bool allSetters = true; 6360 bool allSetters = true;
5233 bool allGetters = true; 6361 bool allGetters = true;
5234 for (ExecutableElement executableElement in set) { 6362 for (ExecutableElement executableElement in set) {
5235 if (executableElement is PropertyAccessorElement) { 6363 if (executableElement is PropertyAccessorElement) {
5236 allMethods = false; 6364 allMethods = false;
5237 if (((executableElement as PropertyAccessorElement)).isSetter) { 6365 if ((executableElement as PropertyAccessorElement).isSetter) {
5238 allGetters = false; 6366 allGetters = false;
5239 } else { 6367 } else {
5240 allSetters = false; 6368 allSetters = false;
5241 } 6369 }
5242 } else { 6370 } else {
5243 allGetters = false; 6371 allGetters = false;
5244 allSetters = false; 6372 allSetters = false;
5245 } 6373 }
5246 } 6374 }
5247 if (allMethods || allGetters || allSetters) { 6375 if (allMethods || allGetters || allSetters) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
5367 if (executableElement is MethodMember) { 6495 if (executableElement is MethodMember) {
5368 executableElement = MethodMember.from(executableElement as MethodMember, superType); 6496 executableElement = MethodMember.from(executableElement as MethodMember, superType);
5369 map.setValue(i, executableElement); 6497 map.setValue(i, executableElement);
5370 } else if (executableElement is PropertyAccessorMember) { 6498 } else if (executableElement is PropertyAccessorMember) {
5371 executableElement = PropertyAccessorMember.from(executableElement as Pro pertyAccessorMember, superType); 6499 executableElement = PropertyAccessorMember.from(executableElement as Pro pertyAccessorMember, superType);
5372 map.setValue(i, executableElement); 6500 map.setValue(i, executableElement);
5373 } 6501 }
5374 } 6502 }
5375 } 6503 }
5376 } 6504 }
6505
5377 /** 6506 /**
5378 * Instances of the class `Library` represent the data about a single library du ring the 6507 * Instances of the class `Library` represent the data about a single library du ring the
5379 * resolution of some (possibly different) library. They are not intended to be used except during 6508 * resolution of some (possibly different) library. They are not intended to be used except during
5380 * the resolution process. 6509 * the resolution process.
5381 * 6510 *
5382 * @coverage dart.engine.resolver 6511 * @coverage dart.engine.resolver
5383 */ 6512 */
5384 class Library { 6513 class Library {
5385
5386 /** 6514 /**
5387 * The analysis context in which this library is being analyzed. 6515 * The analysis context in which this library is being analyzed.
5388 */ 6516 */
5389 InternalAnalysisContext _analysisContext; 6517 InternalAnalysisContext _analysisContext;
5390 6518
5391 /** 6519 /**
5392 * The inheritance manager which is used for this member lookups in this libra ry. 6520 * The inheritance manager which is used for this member lookups in this libra ry.
5393 */ 6521 */
5394 InheritanceManager _inheritanceManager; 6522 InheritanceManager _inheritanceManager;
5395 6523
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
5651 * Set the library element representing this library to the given library elem ent. 6779 * Set the library element representing this library to the given library elem ent.
5652 * 6780 *
5653 * @param libraryElement the library element representing this library 6781 * @param libraryElement the library element representing this library
5654 */ 6782 */
5655 void set libraryElement(LibraryElementImpl libraryElement) { 6783 void set libraryElement(LibraryElementImpl libraryElement) {
5656 this._libraryElement = libraryElement; 6784 this._libraryElement = libraryElement;
5657 if (_inheritanceManager != null) { 6785 if (_inheritanceManager != null) {
5658 _inheritanceManager.libraryElement = libraryElement; 6786 _inheritanceManager.libraryElement = libraryElement;
5659 } 6787 }
5660 } 6788 }
6789
5661 String toString() => librarySource.shortName; 6790 String toString() => librarySource.shortName;
5662 } 6791 }
6792
5663 /** 6793 /**
5664 * Instances of the class `LibraryElementBuilder` build an element model for a s ingle library. 6794 * Instances of the class `LibraryElementBuilder` build an element model for a s ingle library.
5665 * 6795 *
5666 * @coverage dart.engine.resolver 6796 * @coverage dart.engine.resolver
5667 */ 6797 */
5668 class LibraryElementBuilder { 6798 class LibraryElementBuilder {
5669
5670 /** 6799 /**
5671 * The analysis context in which the element model will be built. 6800 * The analysis context in which the element model will be built.
5672 */ 6801 */
5673 InternalAnalysisContext _analysisContext; 6802 InternalAnalysisContext _analysisContext;
5674 6803
5675 /** 6804 /**
5676 * The listener to which errors will be reported. 6805 * The listener to which errors will be reported.
5677 */ 6806 */
5678 AnalysisErrorListener _errorListener; 6807 AnalysisErrorListener _errorListener;
5679 6808
(...skipping 26 matching lines...) Expand all
5706 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit(librarySource, definingCompilationUnit); 6835 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit(librarySource, definingCompilationUnit);
5707 NodeList<Directive> directives = definingCompilationUnit.directives; 6836 NodeList<Directive> directives = definingCompilationUnit.directives;
5708 LibraryIdentifier libraryNameNode = null; 6837 LibraryIdentifier libraryNameNode = null;
5709 bool hasPartDirective = false; 6838 bool hasPartDirective = false;
5710 FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement); 6839 FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement);
5711 List<Directive> directivesToResolve = new List<Directive>(); 6840 List<Directive> directivesToResolve = new List<Directive>();
5712 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>(); 6841 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>();
5713 for (Directive directive in directives) { 6842 for (Directive directive in directives) {
5714 if (directive is LibraryDirective) { 6843 if (directive is LibraryDirective) {
5715 if (libraryNameNode == null) { 6844 if (libraryNameNode == null) {
5716 libraryNameNode = ((directive as LibraryDirective)).name; 6845 libraryNameNode = (directive as LibraryDirective).name;
5717 directivesToResolve.add(directive); 6846 directivesToResolve.add(directive);
5718 } 6847 }
5719 } else if (directive is PartDirective) { 6848 } else if (directive is PartDirective) {
5720 PartDirective partDirective = directive as PartDirective; 6849 PartDirective partDirective = directive as PartDirective;
5721 StringLiteral partUri = partDirective.uri; 6850 StringLiteral partUri = partDirective.uri;
5722 Source partSource = library.getSource(partDirective); 6851 Source partSource = library.getSource(partDirective);
5723 if (partSource != null && partSource.exists()) { 6852 if (partSource != null && partSource.exists()) {
5724 hasPartDirective = true; 6853 hasPartDirective = true;
5725 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, library.getAST(partSource)); 6854 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, library.getAST(partSource));
5726 part.uri = library.getUri(partDirective); 6855 part.uri = library.getUri(partDirective);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5806 * @param directivesToResolve a list of directives that should be resolved to the library being 6935 * @param directivesToResolve a list of directives that should be resolved to the library being
5807 * built 6936 * built
5808 * @return the name of the library that the given part is declared to be a par t of 6937 * @return the name of the library that the given part is declared to be a par t of
5809 */ 6938 */
5810 String getPartLibraryName(Library library, Source partSource, List<Directive> directivesToResolve) { 6939 String getPartLibraryName(Library library, Source partSource, List<Directive> directivesToResolve) {
5811 try { 6940 try {
5812 CompilationUnit partUnit = library.getAST(partSource); 6941 CompilationUnit partUnit = library.getAST(partSource);
5813 for (Directive directive in partUnit.directives) { 6942 for (Directive directive in partUnit.directives) {
5814 if (directive is PartOfDirective) { 6943 if (directive is PartOfDirective) {
5815 directivesToResolve.add(directive); 6944 directivesToResolve.add(directive);
5816 LibraryIdentifier libraryName = ((directive as PartOfDirective)).libra ryName; 6945 LibraryIdentifier libraryName = (directive as PartOfDirective).library Name;
5817 if (libraryName != null) { 6946 if (libraryName != null) {
5818 return libraryName.name; 6947 return libraryName.name;
5819 } 6948 }
5820 } 6949 }
5821 } 6950 }
5822 } on AnalysisException catch (exception) { 6951 } on AnalysisException catch (exception) {
5823 } 6952 }
5824 return null; 6953 return null;
5825 } 6954 }
5826 6955
5827 /** 6956 /**
5828 * Look through all of the compilation units defined for the given library, lo oking for getters 6957 * Look through all of the compilation units defined for the given library, lo oking for getters
5829 * and setters that are defined in different compilation units but that have t he same names. If 6958 * and setters that are defined in different compilation units but that have t he same names. If
5830 * any are found, make sure that they have the same variable element. 6959 * any are found, make sure that they have the same variable element.
5831 * 6960 *
5832 * @param libraryElement the library defining the compilation units to be proc essed 6961 * @param libraryElement the library defining the compilation units to be proc essed
5833 */ 6962 */
5834 void patchTopLevelAccessors(LibraryElementImpl libraryElement) { 6963 void patchTopLevelAccessors(LibraryElementImpl libraryElement) {
5835 Map<String, PropertyAccessorElement> getters = new Map<String, PropertyAcces sorElement>(); 6964 Map<String, PropertyAccessorElement> getters = new Map<String, PropertyAcces sorElement>();
5836 List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>(); 6965 List<PropertyAccessorElement> setters = new List<PropertyAccessorElement>();
5837 collectAccessors(getters, setters, libraryElement.definingCompilationUnit); 6966 collectAccessors(getters, setters, libraryElement.definingCompilationUnit);
5838 for (CompilationUnitElement unit in libraryElement.parts) { 6967 for (CompilationUnitElement unit in libraryElement.parts) {
5839 collectAccessors(getters, setters, unit); 6968 collectAccessors(getters, setters, unit);
5840 } 6969 }
5841 for (PropertyAccessorElement setter in setters) { 6970 for (PropertyAccessorElement setter in setters) {
5842 PropertyAccessorElement getter = getters[setter.displayName]; 6971 PropertyAccessorElement getter = getters[setter.displayName];
5843 if (getter != null) { 6972 if (getter != null) {
5844 PropertyInducingElementImpl variable = getter.variable as PropertyInduci ngElementImpl; 6973 PropertyInducingElementImpl variable = getter.variable as PropertyInduci ngElementImpl;
5845 variable.setter = setter; 6974 variable.setter = setter;
5846 ((setter as PropertyAccessorElementImpl)).variable = variable; 6975 (setter as PropertyAccessorElementImpl).variable = variable;
5847 } 6976 }
5848 } 6977 }
5849 } 6978 }
5850 } 6979 }
6980
5851 /** 6981 /**
5852 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent 6982 * Instances of the class `LibraryResolver` are used to resolve one or more mutu ally dependent
5853 * libraries within a single context. 6983 * libraries within a single context.
5854 * 6984 *
5855 * @coverage dart.engine.resolver 6985 * @coverage dart.engine.resolver
5856 */ 6986 */
5857 class LibraryResolver { 6987 class LibraryResolver {
5858
5859 /** 6988 /**
5860 * The analysis context in which the libraries are being analyzed. 6989 * The analysis context in which the libraries are being analyzed.
5861 */ 6990 */
5862 InternalAnalysisContext analysisContext; 6991 InternalAnalysisContext analysisContext;
5863 6992
5864 /** 6993 /**
5865 * The listener to which analysis errors will be reported, this error listener is either 6994 * The listener to which analysis errors will be reported, this error listener is either
5866 * references [recordingErrorListener], or it unions the passed 6995 * references [recordingErrorListener], or it unions the passed
5867 * [AnalysisErrorListener] with the [recordingErrorListener]. 6996 * [AnalysisErrorListener] with the [recordingErrorListener].
5868 */ 6997 */
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
6064 * Build the element model representing the combinators declared by the given directive. 7193 * Build the element model representing the combinators declared by the given directive.
6065 * 7194 *
6066 * @param directive the directive that declares the combinators 7195 * @param directive the directive that declares the combinators
6067 * @return an array containing the import combinators that were built 7196 * @return an array containing the import combinators that were built
6068 */ 7197 */
6069 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) { 7198 List<NamespaceCombinator> buildCombinators(NamespaceDirective directive) {
6070 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>(); 7199 List<NamespaceCombinator> combinators = new List<NamespaceCombinator>();
6071 for (Combinator combinator in directive.combinators) { 7200 for (Combinator combinator in directive.combinators) {
6072 if (combinator is HideCombinator) { 7201 if (combinator is HideCombinator) {
6073 HideElementCombinatorImpl hide = new HideElementCombinatorImpl(); 7202 HideElementCombinatorImpl hide = new HideElementCombinatorImpl();
6074 hide.hiddenNames = getIdentifiers(((combinator as HideCombinator)).hidde nNames); 7203 hide.hiddenNames = getIdentifiers((combinator as HideCombinator).hiddenN ames);
6075 combinators.add(hide); 7204 combinators.add(hide);
6076 } else { 7205 } else {
6077 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl(); 7206 ShowElementCombinatorImpl show = new ShowElementCombinatorImpl();
6078 show.offset = combinator.offset; 7207 show.offset = combinator.offset;
6079 show.end = combinator.end; 7208 show.end = combinator.end;
6080 show.shownNames = getIdentifiers(((combinator as ShowCombinator)).shownN ames); 7209 show.shownNames = getIdentifiers((combinator as ShowCombinator).shownNam es);
6081 combinators.add(show); 7210 combinators.add(show);
6082 } 7211 }
6083 } 7212 }
6084 return new List.from(combinators); 7213 return new List.from(combinators);
6085 } 7214 }
6086 7215
6087 /** 7216 /**
6088 * Every library now has a corresponding [LibraryElement], so it is now possib le to resolve 7217 * Every library now has a corresponding [LibraryElement], so it is now possib le to resolve
6089 * the import and export directives. 7218 * the import and export directives.
6090 * 7219 *
(...skipping 17 matching lines...) Expand all
6108 StringLiteral uriLiteral = importDirective.uri; 7237 StringLiteral uriLiteral = importDirective.uri;
6109 if (uriLiteral != null) { 7238 if (uriLiteral != null) {
6110 importElement.uriEnd = uriLiteral.end; 7239 importElement.uriEnd = uriLiteral.end;
6111 } 7240 }
6112 importElement.uri = library.getUri(importDirective); 7241 importElement.uri = library.getUri(importDirective);
6113 importElement.combinators = buildCombinators(importDirective); 7242 importElement.combinators = buildCombinators(importDirective);
6114 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment; 7243 LibraryElement importedLibraryElement = importedLibrary.libraryEle ment;
6115 if (importedLibraryElement != null) { 7244 if (importedLibraryElement != null) {
6116 importElement.importedLibrary = importedLibraryElement; 7245 importElement.importedLibrary = importedLibraryElement;
6117 } 7246 }
6118 SimpleIdentifier prefixNode = ((directive as ImportDirective)).pre fix; 7247 SimpleIdentifier prefixNode = (directive as ImportDirective).prefi x;
6119 if (prefixNode != null) { 7248 if (prefixNode != null) {
6120 importElement.prefixOffset = prefixNode.offset; 7249 importElement.prefixOffset = prefixNode.offset;
6121 String prefixName = prefixNode.name; 7250 String prefixName = prefixNode.name;
6122 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; 7251 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
6123 if (prefix == null) { 7252 if (prefix == null) {
6124 prefix = new PrefixElementImpl(prefixNode); 7253 prefix = new PrefixElementImpl(prefixNode);
6125 nameToPrefixMap[prefixName] = prefix; 7254 nameToPrefixMap[prefixName] = prefix;
6126 } 7255 }
6127 importElement.prefix = prefix; 7256 importElement.prefix = prefix;
6128 prefixNode.staticElement = prefix; 7257 prefixNode.staticElement = prefix;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
6451 * 7580 *
6452 * @param library the library to be resolved 7581 * @param library the library to be resolved
6453 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 7582 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
6454 * the library cannot be analyzed 7583 * the library cannot be analyzed
6455 */ 7584 */
6456 void resolveReferencesAndTypes2(Library library) { 7585 void resolveReferencesAndTypes2(Library library) {
6457 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art(); 7586 TimeCounter_TimeCounterHandle timeCounter = PerformanceStatistics.resolve.st art();
6458 try { 7587 try {
6459 for (Source source in library.compilationUnitSources) { 7588 for (Source source in library.compilationUnitSources) {
6460 CompilationUnit ast = library.getAST(source); 7589 CompilationUnit ast = library.getAST(source);
6461 ast.accept(new VariableResolverVisitor(library, source, _typeProvider)); 7590 ast.accept(new VariableResolverVisitor.con1(library, source, _typeProvid er));
6462 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typ eProvider); 7591 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typ eProvider);
6463 ast.accept(visitor); 7592 ast.accept(visitor);
6464 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) { 7593 for (ProxyConditionalAnalysisError conditionalCode in visitor.proxyCondi tionalAnalysisErrors) {
6465 if (conditionalCode.shouldIncludeErrorCode()) { 7594 if (conditionalCode.shouldIncludeErrorCode()) {
6466 visitor.reportError(conditionalCode.analysisError); 7595 visitor.reportError(conditionalCode.analysisError);
6467 } 7596 }
6468 } 7597 }
6469 } 7598 }
6470 } finally { 7599 } finally {
6471 timeCounter.stop(); 7600 timeCounter.stop();
(...skipping 14 matching lines...) Expand all
6486 return null; 7615 return null;
6487 } 7616 }
6488 String uriContent = uriLiteral.stringValue.trim(); 7617 String uriContent = uriLiteral.stringValue.trim();
6489 if (uriContent == null || uriContent.isEmpty) { 7618 if (uriContent == null || uriContent.isEmpty) {
6490 return null; 7619 return null;
6491 } 7620 }
6492 uriContent = Uri.encodeFull(uriContent); 7621 uriContent = Uri.encodeFull(uriContent);
6493 return analysisContext.sourceFactory.resolveUri(librarySource, uriContent); 7622 return analysisContext.sourceFactory.resolveUri(librarySource, uriContent);
6494 } 7623 }
6495 } 7624 }
7625
6496 /** 7626 /**
6497 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as 7627 * This class is used to replace uses of `HashMap<String, ExecutableElement>` wh ich are not as
6498 * performant as this class. 7628 * performant as this class.
6499 */ 7629 */
6500 class MemberMap { 7630 class MemberMap {
6501
6502 /** 7631 /**
6503 * The current size of this map. 7632 * The current size of this map.
6504 */ 7633 */
6505 int size = 0; 7634 int size = 0;
6506 7635
6507 /** 7636 /**
6508 * The array of keys. 7637 * The array of keys.
6509 */ 7638 */
6510 List<String> _keys; 7639 List<String> _keys;
6511 7640
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
6639 } 7768 }
6640 7769
6641 /** 7770 /**
6642 * Initializes [keys] and [values]. 7771 * Initializes [keys] and [values].
6643 */ 7772 */
6644 void initArrays(int initialCapacity) { 7773 void initArrays(int initialCapacity) {
6645 _keys = new List<String>(initialCapacity); 7774 _keys = new List<String>(initialCapacity);
6646 _values = new List<ExecutableElement>(initialCapacity); 7775 _values = new List<ExecutableElement>(initialCapacity);
6647 } 7776 }
6648 } 7777 }
7778
6649 /** 7779 /**
6650 * This class is a wrapper for an [AnalysisError] which can also be queried afte r resolution 7780 * This class is a wrapper for an [AnalysisError] which can also be queried afte r resolution
6651 * to find out if the error should actually be reported. In this case, these err ors are conditional 7781 * to find out if the error should actually be reported. In this case, these err ors are conditional
6652 * on the non-existence of an `@proxy` annotation. 7782 * on the non-existence of an `@proxy` annotation.
6653 * 7783 *
6654 * If we have other conditional error codes in the future, we should have this c lass implement some 7784 * If we have other conditional error codes in the future, we should have this c lass implement some
6655 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode can be visited 7785 * ConditionalErrorCode so that after resolution, a list of ConditionalErrorCode can be visited
6656 * instead of multiple lists of *ConditionalErrorCodes. 7786 * instead of multiple lists of *ConditionalErrorCodes.
6657 */ 7787 */
6658 class ProxyConditionalAnalysisError { 7788 class ProxyConditionalAnalysisError {
6659
6660 /** 7789 /**
6661 * The name of the proxy annotation, from the meta pub package. 7790 * The name of the proxy annotation, from dart:core.
6662 */ 7791 */
6663 static String _PROXY_ANNOTATION_NAME = "proxy"; 7792 static String _PROXY_ANNOTATION_NAME = "proxy";
6664 7793
6665 /** 7794 /**
6666 * The name of the meta library name, from the meta pub package.
6667 */
6668 static String _META_LIBRARY_NAME = "meta";
6669
6670 /**
6671 * Return `true` if the given element represents a class that has the proxy an notation. 7795 * Return `true` if the given element represents a class that has the proxy an notation.
6672 * 7796 *
6673 * @param element the class being tested 7797 * @param element the class being tested
6674 * @return `true` if the given element represents a class that has the proxy a nnotation 7798 * @return `true` if the given element represents a class that has the proxy a nnotation
6675 */ 7799 */
6676 static bool classHasProxyAnnotation(Element element) { 7800 static bool classHasProxyAnnotation(Element element) {
6677 if (element is ClassElement) { 7801 if (element is ClassElement) {
6678 ClassElement classElement = element as ClassElement; 7802 ClassElement classElement = element as ClassElement;
6679 List<ElementAnnotation> annotations = classElement.metadata; 7803 List<ElementAnnotation> annotations = classElement.metadata;
6680 for (ElementAnnotation annotation in annotations) { 7804 for (ElementAnnotation annotation in annotations) {
6681 Element elementAnnotation = annotation.element; 7805 Element elementAnnotation = annotation.element;
6682 if (elementAnnotation != null) { 7806 if (elementAnnotation != null) {
6683 LibraryElement lib = elementAnnotation.library; 7807 LibraryElement lib = elementAnnotation.library;
6684 if (elementAnnotation.name == _PROXY_ANNOTATION_NAME && lib != null && lib.name == _META_LIBRARY_NAME) { 7808 if (lib != null && lib.isDartCore && elementAnnotation.name == _PROXY_ ANNOTATION_NAME) {
6685 return true; 7809 return true;
6686 } 7810 }
6687 } 7811 }
6688 } 7812 }
6689 } 7813 }
6690 return false; 7814 return false;
6691 } 7815 }
6692 7816
6693 /** 7817 /**
6694 * The enclosing [ClassElement], this is what will determine if the error code should, or 7818 * The enclosing [ClassElement], this is what will determine if the error code should, or
(...skipping 18 matching lines...) Expand all
6713 this.analysisError = analysisError; 7837 this.analysisError = analysisError;
6714 } 7838 }
6715 7839
6716 /** 7840 /**
6717 * Return `true` iff the enclosing class has the proxy annotation. 7841 * Return `true` iff the enclosing class has the proxy annotation.
6718 * 7842 *
6719 * @return `true` iff the enclosing class has the proxy annotation 7843 * @return `true` iff the enclosing class has the proxy annotation
6720 */ 7844 */
6721 bool shouldIncludeErrorCode() => !classHasProxyAnnotation(_enclosingElement); 7845 bool shouldIncludeErrorCode() => !classHasProxyAnnotation(_enclosingElement);
6722 } 7846 }
7847
6723 /** 7848 /**
6724 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single 7849 * Instances of the class `ResolverVisitor` are used to resolve the nodes within a single
6725 * compilation unit. 7850 * compilation unit.
6726 * 7851 *
6727 * @coverage dart.engine.resolver 7852 * @coverage dart.engine.resolver
6728 */ 7853 */
6729 class ResolverVisitor extends ScopedVisitor { 7854 class ResolverVisitor extends ScopedVisitor {
6730
6731 /** 7855 /**
6732 * The manager for the inheritance mappings. 7856 * The manager for the inheritance mappings.
6733 */ 7857 */
6734 InheritanceManager _inheritanceManager; 7858 InheritanceManager _inheritanceManager;
6735 7859
6736 /** 7860 /**
6737 * The object used to resolve the element associated with the current node. 7861 * The object used to resolve the element associated with the current node.
6738 */ 7862 */
6739 ElementResolver _elementResolver; 7863 ElementResolver _elementResolver;
6740 7864
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
6791 * @param source the source representing the compilation unit being visited 7915 * @param source the source representing the compilation unit being visited
6792 * @param typeProvider the object used to access the types from the core libra ry 7916 * @param typeProvider the object used to access the types from the core libra ry
6793 * @param errorListener the error listener that will be informed of any errors that are found 7917 * @param errorListener the error listener that will be informed of any errors that are found
6794 * during resolution 7918 * during resolution
6795 */ 7919 */
6796 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, InheritanceManager inheritanceManager, AnalysisErrorListener er rorListener) : super.con2(definingLibrary, source, typeProvider, errorListener) { 7920 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, InheritanceManager inheritanceManager, AnalysisErrorListener er rorListener) : super.con2(definingLibrary, source, typeProvider, errorListener) {
6797 this._inheritanceManager = inheritanceManager; 7921 this._inheritanceManager = inheritanceManager;
6798 this._elementResolver = new ElementResolver(this); 7922 this._elementResolver = new ElementResolver(this);
6799 this._typeAnalyzer = new StaticTypeAnalyzer(this); 7923 this._typeAnalyzer = new StaticTypeAnalyzer(this);
6800 } 7924 }
7925
7926 /**
7927 * Initialize a newly created visitor to resolve the nodes in an AST node.
7928 *
7929 * @param definingLibrary the element for the library containing the node bein g visited
7930 * @param source the source representing the compilation unit containing the n ode being visited
7931 * @param typeProvider the object used to access the types from the core libra ry
7932 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
7933 * @param errorListener the error listener that will be informed of any errors that are found
7934 * during resolution
7935 */
7936 ResolverVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : super.c on3(definingLibrary, source, typeProvider, nameScope, errorListener) {
7937 this._inheritanceManager = new InheritanceManager(definingLibrary);
7938 this._elementResolver = new ElementResolver(this);
7939 this._typeAnalyzer = new StaticTypeAnalyzer(this);
7940 }
7941
6801 Object visitAsExpression(AsExpression node) { 7942 Object visitAsExpression(AsExpression node) {
6802 super.visitAsExpression(node); 7943 super.visitAsExpression(node);
6803 override(node.expression, node.type.type); 7944 override(node.expression, node.type.type);
6804 return null; 7945 return null;
6805 } 7946 }
7947
6806 Object visitAssertStatement(AssertStatement node) { 7948 Object visitAssertStatement(AssertStatement node) {
6807 super.visitAssertStatement(node); 7949 super.visitAssertStatement(node);
6808 propagateTrueState(node.condition); 7950 propagateTrueState(node.condition);
6809 return null; 7951 return null;
6810 } 7952 }
7953
6811 Object visitBinaryExpression(BinaryExpression node) { 7954 Object visitBinaryExpression(BinaryExpression node) {
6812 sc.TokenType operatorType = node.operator.type; 7955 sc.TokenType operatorType = node.operator.type;
6813 Expression leftOperand = node.leftOperand; 7956 Expression leftOperand = node.leftOperand;
6814 Expression rightOperand = node.rightOperand; 7957 Expression rightOperand = node.rightOperand;
6815 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) { 7958 if (identical(operatorType, sc.TokenType.AMPERSAND_AMPERSAND)) {
6816 safelyVisit(leftOperand); 7959 safelyVisit(leftOperand);
6817 if (rightOperand != null) { 7960 if (rightOperand != null) {
6818 try { 7961 try {
6819 overrideManager.enterScope(); 7962 overrideManager.enterScope();
6820 promoteManager.enterScope(); 7963 promoteManager.enterScope();
6821 propagateTrueState(leftOperand); 7964 propagateTrueState(leftOperand);
6822 promoteTypes(leftOperand); 7965 promoteTypes(leftOperand);
6823 clearTypePromotionsIfPotentiallyMutatedIn(leftOperand); 7966 clearTypePromotionsIfPotentiallyMutatedIn(leftOperand);
6824 clearTypePromotionsIfPotentiallyMutatedIn(rightOperand); 7967 clearTypePromotionsIfPotentiallyMutatedIn(rightOperand);
6825 clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(rightOperan d); 7968 clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(rightOper and);
6826 rightOperand.accept(this); 7969 rightOperand.accept(this);
6827 } finally { 7970 } finally {
6828 overrideManager.exitScope(); 7971 overrideManager.exitScope();
6829 promoteManager.exitScope(); 7972 promoteManager.exitScope();
6830 } 7973 }
6831 } 7974 }
6832 } else if (identical(operatorType, sc.TokenType.BAR_BAR)) { 7975 } else if (identical(operatorType, sc.TokenType.BAR_BAR)) {
6833 safelyVisit(leftOperand); 7976 safelyVisit(leftOperand);
6834 if (rightOperand != null) { 7977 if (rightOperand != null) {
6835 try { 7978 try {
6836 overrideManager.enterScope(); 7979 overrideManager.enterScope();
6837 propagateFalseState(leftOperand); 7980 propagateFalseState(leftOperand);
6838 rightOperand.accept(this); 7981 rightOperand.accept(this);
6839 } finally { 7982 } finally {
6840 overrideManager.exitScope(); 7983 overrideManager.exitScope();
6841 } 7984 }
6842 } 7985 }
6843 } else { 7986 } else {
6844 safelyVisit(leftOperand); 7987 safelyVisit(leftOperand);
6845 safelyVisit(rightOperand); 7988 safelyVisit(rightOperand);
6846 } 7989 }
6847 node.accept(_elementResolver); 7990 node.accept(_elementResolver);
6848 node.accept(_typeAnalyzer); 7991 node.accept(_typeAnalyzer);
6849 return null; 7992 return null;
6850 } 7993 }
7994
6851 Object visitBlockFunctionBody(BlockFunctionBody node) { 7995 Object visitBlockFunctionBody(BlockFunctionBody node) {
6852 try { 7996 try {
6853 overrideManager.enterScope(); 7997 overrideManager.enterScope();
6854 super.visitBlockFunctionBody(node); 7998 super.visitBlockFunctionBody(node);
6855 } finally { 7999 } finally {
6856 overrideManager.exitScope(); 8000 overrideManager.exitScope();
6857 } 8001 }
6858 return null; 8002 return null;
6859 } 8003 }
8004
6860 Object visitBreakStatement(BreakStatement node) { 8005 Object visitBreakStatement(BreakStatement node) {
6861 node.accept(_elementResolver); 8006 node.accept(_elementResolver);
6862 node.accept(_typeAnalyzer); 8007 node.accept(_typeAnalyzer);
6863 return null; 8008 return null;
6864 } 8009 }
8010
6865 Object visitClassDeclaration(ClassDeclaration node) { 8011 Object visitClassDeclaration(ClassDeclaration node) {
6866 ClassElement outerType = enclosingClass; 8012 ClassElement outerType = enclosingClass;
6867 try { 8013 try {
6868 enclosingClass = node.element; 8014 enclosingClass = node.element;
6869 _typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.ty pe; 8015 _typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.ty pe;
6870 super.visitClassDeclaration(node); 8016 super.visitClassDeclaration(node);
6871 } finally { 8017 } finally {
6872 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; 8018 _typeAnalyzer.thisType = outerType == null ? null : outerType.type;
6873 enclosingClass = outerType; 8019 enclosingClass = outerType;
6874 } 8020 }
6875 return null; 8021 return null;
6876 } 8022 }
8023
6877 Object visitCommentReference(CommentReference node) { 8024 Object visitCommentReference(CommentReference node) {
6878 node.accept(_elementResolver); 8025 node.accept(_elementResolver);
6879 node.accept(_typeAnalyzer); 8026 node.accept(_typeAnalyzer);
6880 return null; 8027 return null;
6881 } 8028 }
8029
6882 Object visitCompilationUnit(CompilationUnit node) { 8030 Object visitCompilationUnit(CompilationUnit node) {
6883 try { 8031 try {
6884 overrideManager.enterScope(); 8032 overrideManager.enterScope();
6885 for (Directive directive in node.directives) { 8033 for (Directive directive in node.directives) {
6886 directive.accept(this); 8034 directive.accept(this);
6887 } 8035 }
6888 List<CompilationUnitMember> classes = new List<CompilationUnitMember>(); 8036 List<CompilationUnitMember> classes = new List<CompilationUnitMember>();
6889 for (CompilationUnitMember declaration in node.declarations) { 8037 for (CompilationUnitMember declaration in node.declarations) {
6890 if (declaration is ClassDeclaration) { 8038 if (declaration is ClassDeclaration) {
6891 classes.add(declaration); 8039 classes.add(declaration);
6892 } else { 8040 } else {
6893 declaration.accept(this); 8041 declaration.accept(this);
6894 } 8042 }
6895 } 8043 }
6896 for (CompilationUnitMember declaration in classes) { 8044 for (CompilationUnitMember declaration in classes) {
6897 declaration.accept(this); 8045 declaration.accept(this);
6898 } 8046 }
6899 } finally { 8047 } finally {
6900 overrideManager.exitScope(); 8048 overrideManager.exitScope();
6901 } 8049 }
6902 node.accept(_elementResolver); 8050 node.accept(_elementResolver);
6903 node.accept(_typeAnalyzer); 8051 node.accept(_typeAnalyzer);
6904 return null; 8052 return null;
6905 } 8053 }
8054
6906 Object visitConditionalExpression(ConditionalExpression node) { 8055 Object visitConditionalExpression(ConditionalExpression node) {
6907 Expression condition = node.condition; 8056 Expression condition = node.condition;
6908 safelyVisit(condition); 8057 safelyVisit(condition);
6909 Expression thenExpression = node.thenExpression; 8058 Expression thenExpression = node.thenExpression;
6910 if (thenExpression != null) { 8059 if (thenExpression != null) {
6911 try { 8060 try {
6912 overrideManager.enterScope(); 8061 overrideManager.enterScope();
6913 promoteManager.enterScope(); 8062 promoteManager.enterScope();
6914 propagateTrueState(condition); 8063 propagateTrueState(condition);
6915 promoteTypes(condition); 8064 promoteTypes(condition);
6916 clearTypePromotionsIfPotentiallyMutatedIn(thenExpression); 8065 clearTypePromotionsIfPotentiallyMutatedIn(thenExpression);
6917 clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(thenExpressio n); 8066 clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(thenExpress ion);
6918 thenExpression.accept(this); 8067 thenExpression.accept(this);
6919 } finally { 8068 } finally {
6920 overrideManager.exitScope(); 8069 overrideManager.exitScope();
6921 promoteManager.exitScope(); 8070 promoteManager.exitScope();
6922 } 8071 }
6923 } 8072 }
6924 Expression elseExpression = node.elseExpression; 8073 Expression elseExpression = node.elseExpression;
6925 if (elseExpression != null) { 8074 if (elseExpression != null) {
6926 try { 8075 try {
6927 overrideManager.enterScope(); 8076 overrideManager.enterScope();
6928 propagateFalseState(condition); 8077 propagateFalseState(condition);
6929 elseExpression.accept(this); 8078 elseExpression.accept(this);
6930 } finally { 8079 } finally {
6931 overrideManager.exitScope(); 8080 overrideManager.exitScope();
6932 } 8081 }
6933 } 8082 }
6934 node.accept(_elementResolver); 8083 node.accept(_elementResolver);
6935 node.accept(_typeAnalyzer); 8084 node.accept(_typeAnalyzer);
6936 bool thenIsAbrupt = isAbruptTermination(thenExpression); 8085 bool thenIsAbrupt = isAbruptTermination(thenExpression);
6937 bool elseIsAbrupt = isAbruptTermination(elseExpression); 8086 bool elseIsAbrupt = isAbruptTermination(elseExpression);
6938 if (elseIsAbrupt && !thenIsAbrupt) { 8087 if (elseIsAbrupt && !thenIsAbrupt) {
6939 propagateTrueState(condition); 8088 propagateTrueState(condition);
6940 propagateState(thenExpression); 8089 propagateState(thenExpression);
6941 } else if (thenIsAbrupt && !elseIsAbrupt) { 8090 } else if (thenIsAbrupt && !elseIsAbrupt) {
6942 propagateFalseState(condition); 8091 propagateFalseState(condition);
6943 propagateState(elseExpression); 8092 propagateState(elseExpression);
6944 } 8093 }
6945 return null; 8094 return null;
6946 } 8095 }
8096
6947 Object visitConstructorDeclaration(ConstructorDeclaration node) { 8097 Object visitConstructorDeclaration(ConstructorDeclaration node) {
6948 ExecutableElement outerFunction = enclosingFunction; 8098 ExecutableElement outerFunction = enclosingFunction;
6949 try { 8099 try {
6950 enclosingFunction = node.element; 8100 enclosingFunction = node.element;
6951 super.visitConstructorDeclaration(node); 8101 super.visitConstructorDeclaration(node);
6952 } finally { 8102 } finally {
6953 enclosingFunction = outerFunction; 8103 enclosingFunction = outerFunction;
6954 } 8104 }
6955 return null; 8105 return null;
6956 } 8106 }
8107
6957 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 8108 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
6958 safelyVisit(node.expression); 8109 safelyVisit(node.expression);
6959 node.accept(_elementResolver); 8110 node.accept(_elementResolver);
6960 node.accept(_typeAnalyzer); 8111 node.accept(_typeAnalyzer);
6961 return null; 8112 return null;
6962 } 8113 }
8114
6963 Object visitConstructorName(ConstructorName node) { 8115 Object visitConstructorName(ConstructorName node) {
6964 node.accept(_elementResolver); 8116 node.accept(_elementResolver);
6965 node.accept(_typeAnalyzer); 8117 node.accept(_typeAnalyzer);
6966 return null; 8118 return null;
6967 } 8119 }
8120
6968 Object visitContinueStatement(ContinueStatement node) { 8121 Object visitContinueStatement(ContinueStatement node) {
6969 node.accept(_elementResolver); 8122 node.accept(_elementResolver);
6970 node.accept(_typeAnalyzer); 8123 node.accept(_typeAnalyzer);
6971 return null; 8124 return null;
6972 } 8125 }
8126
6973 Object visitDoStatement(DoStatement node) { 8127 Object visitDoStatement(DoStatement node) {
6974 try { 8128 try {
6975 overrideManager.enterScope(); 8129 overrideManager.enterScope();
6976 super.visitDoStatement(node); 8130 super.visitDoStatement(node);
6977 } finally { 8131 } finally {
6978 overrideManager.exitScope(); 8132 overrideManager.exitScope();
6979 } 8133 }
6980 return null; 8134 return null;
6981 } 8135 }
8136
6982 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 8137 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
6983 try { 8138 try {
6984 overrideManager.enterScope(); 8139 overrideManager.enterScope();
6985 super.visitExpressionFunctionBody(node); 8140 super.visitExpressionFunctionBody(node);
6986 } finally { 8141 } finally {
6987 overrideManager.exitScope(); 8142 overrideManager.exitScope();
6988 } 8143 }
6989 return null; 8144 return null;
6990 } 8145 }
8146
6991 Object visitFieldDeclaration(FieldDeclaration node) { 8147 Object visitFieldDeclaration(FieldDeclaration node) {
6992 try { 8148 try {
6993 overrideManager.enterScope(); 8149 overrideManager.enterScope();
6994 super.visitFieldDeclaration(node); 8150 super.visitFieldDeclaration(node);
6995 } finally { 8151 } finally {
6996 Map<Element, Type2> overrides = overrideManager.captureOverrides(node.fiel ds); 8152 Map<Element, Type2> overrides = overrideManager.captureOverrides(node.fiel ds);
6997 overrideManager.exitScope(); 8153 overrideManager.exitScope();
6998 overrideManager.applyOverrides(overrides); 8154 overrideManager.applyOverrides(overrides);
6999 } 8155 }
7000 return null; 8156 return null;
7001 } 8157 }
8158
7002 Object visitForEachStatement(ForEachStatement node) { 8159 Object visitForEachStatement(ForEachStatement node) {
7003 try { 8160 try {
7004 overrideManager.enterScope(); 8161 overrideManager.enterScope();
7005 super.visitForEachStatement(node); 8162 super.visitForEachStatement(node);
7006 } finally { 8163 } finally {
7007 overrideManager.exitScope(); 8164 overrideManager.exitScope();
7008 } 8165 }
7009 return null; 8166 return null;
7010 } 8167 }
8168
7011 Object visitForStatement(ForStatement node) { 8169 Object visitForStatement(ForStatement node) {
7012 try { 8170 try {
7013 overrideManager.enterScope(); 8171 overrideManager.enterScope();
7014 super.visitForStatement(node); 8172 super.visitForStatement(node);
7015 } finally { 8173 } finally {
7016 overrideManager.exitScope(); 8174 overrideManager.exitScope();
7017 } 8175 }
7018 return null; 8176 return null;
7019 } 8177 }
8178
7020 Object visitFunctionDeclaration(FunctionDeclaration node) { 8179 Object visitFunctionDeclaration(FunctionDeclaration node) {
7021 ExecutableElement outerFunction = enclosingFunction; 8180 ExecutableElement outerFunction = enclosingFunction;
7022 try { 8181 try {
7023 SimpleIdentifier functionName = node.name; 8182 SimpleIdentifier functionName = node.name;
7024 enclosingFunction = functionName.staticElement as ExecutableElement; 8183 enclosingFunction = functionName.staticElement as ExecutableElement;
7025 super.visitFunctionDeclaration(node); 8184 super.visitFunctionDeclaration(node);
7026 } finally { 8185 } finally {
7027 enclosingFunction = outerFunction; 8186 enclosingFunction = outerFunction;
7028 } 8187 }
7029 return null; 8188 return null;
7030 } 8189 }
8190
7031 Object visitFunctionExpression(FunctionExpression node) { 8191 Object visitFunctionExpression(FunctionExpression node) {
7032 ExecutableElement outerFunction = enclosingFunction; 8192 ExecutableElement outerFunction = enclosingFunction;
7033 try { 8193 try {
7034 enclosingFunction = node.element; 8194 enclosingFunction = node.element;
7035 overrideManager.enterScope(); 8195 overrideManager.enterScope();
7036 super.visitFunctionExpression(node); 8196 super.visitFunctionExpression(node);
7037 } finally { 8197 } finally {
7038 overrideManager.exitScope(); 8198 overrideManager.exitScope();
7039 enclosingFunction = outerFunction; 8199 enclosingFunction = outerFunction;
7040 } 8200 }
7041 return null; 8201 return null;
7042 } 8202 }
8203
7043 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 8204 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
7044 safelyVisit(node.function); 8205 safelyVisit(node.function);
7045 node.accept(_elementResolver); 8206 node.accept(_elementResolver);
7046 inferFunctionExpressionsParametersTypes(node.argumentList); 8207 inferFunctionExpressionsParametersTypes(node.argumentList);
7047 safelyVisit(node.argumentList); 8208 safelyVisit(node.argumentList);
7048 node.accept(_typeAnalyzer); 8209 node.accept(_typeAnalyzer);
7049 return null; 8210 return null;
7050 } 8211 }
8212
7051 Object visitHideCombinator(HideCombinator node) => null; 8213 Object visitHideCombinator(HideCombinator node) => null;
8214
7052 Object visitIfStatement(IfStatement node) { 8215 Object visitIfStatement(IfStatement node) {
7053 Expression condition = node.condition; 8216 Expression condition = node.condition;
7054 safelyVisit(condition); 8217 safelyVisit(condition);
7055 Map<Element, Type2> thenOverrides = null; 8218 Map<Element, Type2> thenOverrides = null;
7056 Statement thenStatement = node.thenStatement; 8219 Statement thenStatement = node.thenStatement;
7057 if (thenStatement != null) { 8220 if (thenStatement != null) {
7058 try { 8221 try {
7059 overrideManager.enterScope(); 8222 overrideManager.enterScope();
7060 promoteManager.enterScope(); 8223 promoteManager.enterScope();
7061 propagateTrueState(condition); 8224 propagateTrueState(condition);
7062 promoteTypes(condition); 8225 promoteTypes(condition);
7063 clearTypePromotionsIfPotentiallyMutatedIn(thenStatement); 8226 clearTypePromotionsIfPotentiallyMutatedIn(thenStatement);
7064 clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(thenStatement ); 8227 clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(thenStateme nt);
7065 visitStatementInScope(thenStatement); 8228 visitStatementInScope(thenStatement);
7066 } finally { 8229 } finally {
7067 thenOverrides = overrideManager.captureLocalOverrides(); 8230 thenOverrides = overrideManager.captureLocalOverrides();
7068 overrideManager.exitScope(); 8231 overrideManager.exitScope();
7069 promoteManager.exitScope(); 8232 promoteManager.exitScope();
7070 } 8233 }
7071 } 8234 }
7072 Map<Element, Type2> elseOverrides = null; 8235 Map<Element, Type2> elseOverrides = null;
7073 Statement elseStatement = node.elseStatement; 8236 Statement elseStatement = node.elseStatement;
7074 if (elseStatement != null) { 8237 if (elseStatement != null) {
(...skipping 16 matching lines...) Expand all
7091 overrideManager.applyOverrides(thenOverrides); 8254 overrideManager.applyOverrides(thenOverrides);
7092 } 8255 }
7093 } else if (thenIsAbrupt && !elseIsAbrupt) { 8256 } else if (thenIsAbrupt && !elseIsAbrupt) {
7094 propagateFalseState(condition); 8257 propagateFalseState(condition);
7095 if (elseOverrides != null) { 8258 if (elseOverrides != null) {
7096 overrideManager.applyOverrides(elseOverrides); 8259 overrideManager.applyOverrides(elseOverrides);
7097 } 8260 }
7098 } 8261 }
7099 return null; 8262 return null;
7100 } 8263 }
8264
7101 Object visitLabel(Label node) => null; 8265 Object visitLabel(Label node) => null;
8266
7102 Object visitLibraryIdentifier(LibraryIdentifier node) => null; 8267 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
8268
7103 Object visitMethodDeclaration(MethodDeclaration node) { 8269 Object visitMethodDeclaration(MethodDeclaration node) {
7104 ExecutableElement outerFunction = enclosingFunction; 8270 ExecutableElement outerFunction = enclosingFunction;
7105 try { 8271 try {
7106 enclosingFunction = node.element; 8272 enclosingFunction = node.element;
7107 super.visitMethodDeclaration(node); 8273 super.visitMethodDeclaration(node);
7108 } finally { 8274 } finally {
7109 enclosingFunction = outerFunction; 8275 enclosingFunction = outerFunction;
7110 } 8276 }
7111 return null; 8277 return null;
7112 } 8278 }
8279
7113 Object visitMethodInvocation(MethodInvocation node) { 8280 Object visitMethodInvocation(MethodInvocation node) {
7114 safelyVisit(node.target); 8281 safelyVisit(node.target);
7115 node.accept(_elementResolver); 8282 node.accept(_elementResolver);
7116 inferFunctionExpressionsParametersTypes(node.argumentList); 8283 inferFunctionExpressionsParametersTypes(node.argumentList);
7117 safelyVisit(node.argumentList); 8284 safelyVisit(node.argumentList);
7118 node.accept(_typeAnalyzer); 8285 node.accept(_typeAnalyzer);
7119 return null; 8286 return null;
7120 } 8287 }
8288
7121 Object visitNode(ASTNode node) { 8289 Object visitNode(ASTNode node) {
7122 node.visitChildren(this); 8290 node.visitChildren(this);
7123 node.accept(_elementResolver); 8291 node.accept(_elementResolver);
7124 node.accept(_typeAnalyzer); 8292 node.accept(_typeAnalyzer);
7125 return null; 8293 return null;
7126 } 8294 }
8295
7127 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 8296 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
7128 safelyVisit(node.prefix); 8297 safelyVisit(node.prefix);
7129 node.accept(_elementResolver); 8298 node.accept(_elementResolver);
7130 node.accept(_typeAnalyzer); 8299 node.accept(_typeAnalyzer);
7131 return null; 8300 return null;
7132 } 8301 }
8302
7133 Object visitPropertyAccess(PropertyAccess node) { 8303 Object visitPropertyAccess(PropertyAccess node) {
7134 safelyVisit(node.target); 8304 safelyVisit(node.target);
7135 node.accept(_elementResolver); 8305 node.accept(_elementResolver);
7136 node.accept(_typeAnalyzer); 8306 node.accept(_typeAnalyzer);
7137 return null; 8307 return null;
7138 } 8308 }
8309
7139 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 8310 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
7140 safelyVisit(node.argumentList); 8311 safelyVisit(node.argumentList);
7141 node.accept(_elementResolver); 8312 node.accept(_elementResolver);
7142 node.accept(_typeAnalyzer); 8313 node.accept(_typeAnalyzer);
7143 return null; 8314 return null;
7144 } 8315 }
8316
7145 Object visitShowCombinator(ShowCombinator node) => null; 8317 Object visitShowCombinator(ShowCombinator node) => null;
8318
7146 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 8319 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
7147 safelyVisit(node.argumentList); 8320 safelyVisit(node.argumentList);
7148 node.accept(_elementResolver); 8321 node.accept(_elementResolver);
7149 node.accept(_typeAnalyzer); 8322 node.accept(_typeAnalyzer);
7150 return null; 8323 return null;
7151 } 8324 }
8325
7152 Object visitSwitchCase(SwitchCase node) { 8326 Object visitSwitchCase(SwitchCase node) {
7153 try { 8327 try {
7154 overrideManager.enterScope(); 8328 overrideManager.enterScope();
7155 super.visitSwitchCase(node); 8329 super.visitSwitchCase(node);
7156 } finally { 8330 } finally {
7157 overrideManager.exitScope(); 8331 overrideManager.exitScope();
7158 } 8332 }
7159 return null; 8333 return null;
7160 } 8334 }
8335
7161 Object visitSwitchDefault(SwitchDefault node) { 8336 Object visitSwitchDefault(SwitchDefault node) {
7162 try { 8337 try {
7163 overrideManager.enterScope(); 8338 overrideManager.enterScope();
7164 super.visitSwitchDefault(node); 8339 super.visitSwitchDefault(node);
7165 } finally { 8340 } finally {
7166 overrideManager.exitScope(); 8341 overrideManager.exitScope();
7167 } 8342 }
7168 return null; 8343 return null;
7169 } 8344 }
8345
7170 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 8346 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
7171 try { 8347 try {
7172 overrideManager.enterScope(); 8348 overrideManager.enterScope();
7173 super.visitTopLevelVariableDeclaration(node); 8349 super.visitTopLevelVariableDeclaration(node);
7174 } finally { 8350 } finally {
7175 Map<Element, Type2> overrides = overrideManager.captureOverrides(node.vari ables); 8351 Map<Element, Type2> overrides = overrideManager.captureOverrides(node.vari ables);
7176 overrideManager.exitScope(); 8352 overrideManager.exitScope();
7177 overrideManager.applyOverrides(overrides); 8353 overrideManager.applyOverrides(overrides);
7178 } 8354 }
7179 return null; 8355 return null;
7180 } 8356 }
8357
7181 Object visitTypeName(TypeName node) => null; 8358 Object visitTypeName(TypeName node) => null;
8359
7182 Object visitWhileStatement(WhileStatement node) { 8360 Object visitWhileStatement(WhileStatement node) {
7183 Expression condition = node.condition; 8361 Expression condition = node.condition;
7184 safelyVisit(condition); 8362 safelyVisit(condition);
7185 Statement body = node.body; 8363 Statement body = node.body;
7186 if (body != null) { 8364 if (body != null) {
7187 try { 8365 try {
7188 overrideManager.enterScope(); 8366 overrideManager.enterScope();
7189 propagateTrueState(condition); 8367 propagateTrueState(condition);
7190 visitStatementInScope(body); 8368 visitStatementInScope(body);
7191 } finally { 8369 } finally {
7192 overrideManager.exitScope(); 8370 overrideManager.exitScope();
7193 } 8371 }
7194 } 8372 }
7195 node.accept(_elementResolver); 8373 node.accept(_elementResolver);
7196 node.accept(_typeAnalyzer); 8374 node.accept(_typeAnalyzer);
7197 return null; 8375 return null;
7198 } 8376 }
7199 8377
7200 /** 8378 /**
7201 * Return the propagated element associated with the given expression whose ty pe can be 8379 * Return the propagated element associated with the given expression whose ty pe can be
7202 * overridden, or `null` if there is no element whose type can be overridden. 8380 * overridden, or `null` if there is no element whose type can be overridden.
7203 * 8381 *
7204 * @param expression the expression with which the element is associated 8382 * @param expression the expression with which the element is associated
7205 * @return the element associated with the given expression 8383 * @return the element associated with the given expression
7206 */ 8384 */
7207 VariableElement getOverridablePropagatedElement(Expression expression) { 8385 VariableElement getOverridablePropagatedElement(Expression expression) {
7208 Element element = null; 8386 Element element = null;
7209 if (expression is SimpleIdentifier) { 8387 if (expression is SimpleIdentifier) {
7210 element = ((expression as SimpleIdentifier)).propagatedElement; 8388 element = (expression as SimpleIdentifier).propagatedElement;
7211 } else if (expression is PrefixedIdentifier) { 8389 } else if (expression is PrefixedIdentifier) {
7212 element = ((expression as PrefixedIdentifier)).propagatedElement; 8390 element = (expression as PrefixedIdentifier).propagatedElement;
7213 } else if (expression is PropertyAccess) { 8391 } else if (expression is PropertyAccess) {
7214 element = ((expression as PropertyAccess)).propertyName.propagatedElement; 8392 element = (expression as PropertyAccess).propertyName.propagatedElement;
7215 } 8393 }
7216 if (element is VariableElement) { 8394 if (element is VariableElement) {
7217 return element as VariableElement; 8395 return element as VariableElement;
7218 } 8396 }
7219 return null; 8397 return null;
7220 } 8398 }
7221 8399
7222 /** 8400 /**
7223 * Return the static element associated with the given expression whose type c an be overridden, or 8401 * Return the static element associated with the given expression whose type c an be overridden, or
7224 * `null` if there is no element whose type can be overridden. 8402 * `null` if there is no element whose type can be overridden.
7225 * 8403 *
7226 * @param expression the expression with which the element is associated 8404 * @param expression the expression with which the element is associated
7227 * @return the element associated with the given expression 8405 * @return the element associated with the given expression
7228 */ 8406 */
7229 VariableElement getOverridableStaticElement(Expression expression) { 8407 VariableElement getOverridableStaticElement(Expression expression) {
7230 Element element = null; 8408 Element element = null;
7231 if (expression is SimpleIdentifier) { 8409 if (expression is SimpleIdentifier) {
7232 element = ((expression as SimpleIdentifier)).staticElement; 8410 element = (expression as SimpleIdentifier).staticElement;
7233 } else if (expression is PrefixedIdentifier) { 8411 } else if (expression is PrefixedIdentifier) {
7234 element = ((expression as PrefixedIdentifier)).staticElement; 8412 element = (expression as PrefixedIdentifier).staticElement;
7235 } else if (expression is PropertyAccess) { 8413 } else if (expression is PropertyAccess) {
7236 element = ((expression as PropertyAccess)).propertyName.staticElement; 8414 element = (expression as PropertyAccess).propertyName.staticElement;
7237 } 8415 }
7238 if (element is VariableElement) { 8416 if (element is VariableElement) {
7239 return element as VariableElement; 8417 return element as VariableElement;
7240 } 8418 }
7241 return null; 8419 return null;
7242 } 8420 }
7243 8421
7244 /** 8422 /**
7245 * Return the static element associated with the given expression whose type c an be promoted, or 8423 * Return the static element associated with the given expression whose type c an be promoted, or
7246 * `null` if there is no element whose type can be promoted. 8424 * `null` if there is no element whose type can be promoted.
7247 * 8425 *
7248 * @param expression the expression with which the element is associated 8426 * @param expression the expression with which the element is associated
7249 * @return the element associated with the given expression 8427 * @return the element associated with the given expression
7250 */ 8428 */
7251 VariableElement getPromotionStaticElement(Expression expression) { 8429 VariableElement getPromotionStaticElement(Expression expression) {
8430 while (expression is ParenthesizedExpression) {
8431 expression = (expression as ParenthesizedExpression).expression;
8432 }
7252 if (expression is! SimpleIdentifier) { 8433 if (expression is! SimpleIdentifier) {
7253 return null; 8434 return null;
7254 } 8435 }
7255 SimpleIdentifier identifier = expression as SimpleIdentifier; 8436 SimpleIdentifier identifier = expression as SimpleIdentifier;
7256 Element element = identifier.staticElement; 8437 Element element = identifier.staticElement;
7257 if (element is! VariableElement) { 8438 if (element is! VariableElement) {
7258 return null; 8439 return null;
7259 } 8440 }
7260 ElementKind kind = element.kind; 8441 ElementKind kind = element.kind;
7261 if (identical(kind, ElementKind.LOCAL_VARIABLE)) { 8442 if (identical(kind, ElementKind.LOCAL_VARIABLE)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
7305 return; 8486 return;
7306 } 8487 }
7307 } 8488 }
7308 Type2 currentType = getBestType(element); 8489 Type2 currentType = getBestType(element);
7309 if (currentType == null || !currentType.isMoreSpecificThan(potentialType)) { 8490 if (currentType == null || !currentType.isMoreSpecificThan(potentialType)) {
7310 overrideManager.setType(element, potentialType); 8491 overrideManager.setType(element, potentialType);
7311 } 8492 }
7312 } 8493 }
7313 8494
7314 /** 8495 /**
7315 * If it is appropriate to do so, promotes the current type of the static elem ent associated with
7316 * the given expression with the given type. Generally speaking, it is appropr iate if the given
7317 * type is more specific than the current type.
7318 *
7319 * @param expression the expression used to access the static element whose ty pes might be
7320 * promoted
7321 * @param potentialType the potential type of the elements
7322 */
7323 void promote(Expression expression, Type2 potentialType) {
7324 VariableElement element = getPromotionStaticElement(expression);
7325 if (element != null) {
7326 if (((element as VariableElementImpl)).isPotentiallyMutatedInClosure) {
7327 return;
7328 }
7329 Type2 type = expression.staticType;
7330 if (type == null || type.isDynamic) {
7331 return;
7332 }
7333 if (potentialType == null || potentialType.isDynamic) {
7334 return;
7335 }
7336 if (!potentialType.isMoreSpecificThan(type)) {
7337 return;
7338 }
7339 promoteManager.setType(element, potentialType);
7340 }
7341 }
7342
7343 /**
7344 * Report a conditional analysis error with the given error code and arguments . 8496 * Report a conditional analysis error with the given error code and arguments .
7345 * 8497 *
7346 * @param enclosingElement the enclosing element 8498 * @param enclosingElement the enclosing element
7347 * @param errorCode the error code of the error to be reported 8499 * @param errorCode the error code of the error to be reported
7348 * @param node the node specifying the location of the error 8500 * @param node the node specifying the location of the error
7349 * @param arguments the arguments to the error, used to compose the error mess age 8501 * @param arguments the arguments to the error, used to compose the error mess age
7350 */ 8502 */
7351 void reportErrorProxyConditionalAnalysisError(Element enclosingElement, ErrorC ode errorCode, ASTNode node, List<Object> arguments) { 8503 void reportErrorProxyConditionalAnalysisError(Element enclosingElement, ErrorC ode errorCode, ASTNode node, List<Object> arguments) {
7352 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi ngElement, new AnalysisError.con2(source, node.offset, node.length, errorCode, a rguments))); 8504 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi ngElement, new AnalysisError.con2(source, node.offset, node.length, errorCode, a rguments)));
7353 } 8505 }
(...skipping 15 matching lines...) Expand all
7369 * Report a conditional analysis error with the given error code and arguments . 8521 * Report a conditional analysis error with the given error code and arguments .
7370 * 8522 *
7371 * @param enclosingElement the enclosing element 8523 * @param enclosingElement the enclosing element
7372 * @param errorCode the error code of the error to be reported 8524 * @param errorCode the error code of the error to be reported
7373 * @param token the token specifying the location of the error 8525 * @param token the token specifying the location of the error
7374 * @param arguments the arguments to the error, used to compose the error mess age 8526 * @param arguments the arguments to the error, used to compose the error mess age
7375 */ 8527 */
7376 void reportErrorProxyConditionalAnalysisError3(Element enclosingElement, Error Code errorCode, sc.Token token, List<Object> arguments) { 8528 void reportErrorProxyConditionalAnalysisError3(Element enclosingElement, Error Code errorCode, sc.Token token, List<Object> arguments) {
7377 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi ngElement, new AnalysisError.con2(source, token.offset, token.length, errorCode, arguments))); 8529 proxyConditionalAnalysisErrors.add(new ProxyConditionalAnalysisError(enclosi ngElement, new AnalysisError.con2(source, token.offset, token.length, errorCode, arguments)));
7378 } 8530 }
8531
7379 void visitForEachStatementInScope(ForEachStatement node) { 8532 void visitForEachStatementInScope(ForEachStatement node) {
7380 Expression iterator = node.iterator; 8533 Expression iterator = node.iterator;
7381 safelyVisit(iterator); 8534 safelyVisit(iterator);
7382 DeclaredIdentifier loopVariable = node.loopVariable; 8535 DeclaredIdentifier loopVariable = node.loopVariable;
7383 SimpleIdentifier identifier = node.identifier; 8536 SimpleIdentifier identifier = node.identifier;
7384 safelyVisit(loopVariable); 8537 safelyVisit(loopVariable);
7385 safelyVisit(identifier); 8538 safelyVisit(identifier);
7386 Statement body = node.body; 8539 Statement body = node.body;
7387 if (body != null) { 8540 if (body != null) {
7388 try { 8541 try {
(...skipping 14 matching lines...) Expand all
7403 } 8556 }
7404 } 8557 }
7405 visitStatementInScope(body); 8558 visitStatementInScope(body);
7406 } finally { 8559 } finally {
7407 overrideManager.exitScope(); 8560 overrideManager.exitScope();
7408 } 8561 }
7409 } 8562 }
7410 node.accept(_elementResolver); 8563 node.accept(_elementResolver);
7411 node.accept(_typeAnalyzer); 8564 node.accept(_typeAnalyzer);
7412 } 8565 }
8566
7413 void visitForStatementInScope(ForStatement node) { 8567 void visitForStatementInScope(ForStatement node) {
7414 safelyVisit(node.variables); 8568 safelyVisit(node.variables);
7415 safelyVisit(node.initialization); 8569 safelyVisit(node.initialization);
7416 safelyVisit(node.condition); 8570 safelyVisit(node.condition);
7417 overrideManager.enterScope(); 8571 overrideManager.enterScope();
7418 try { 8572 try {
7419 propagateTrueState(node.condition); 8573 propagateTrueState(node.condition);
7420 visitStatementInScope(node.body); 8574 visitStatementInScope(node.body);
7421 node.updaters.accept(this); 8575 node.updaters.accept(this);
7422 } finally { 8576 } finally {
7423 overrideManager.exitScope(); 8577 overrideManager.exitScope();
7424 } 8578 }
7425 } 8579 }
7426 8580
7427 /** 8581 /**
7428 * Checks each promoted variable in the current scope for compliance with the following 8582 * Checks each promoted variable in the current scope for compliance with the following
7429 * specification statement: 8583 * specification statement:
7430 * 8584 *
7431 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t hen the variable 8585 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t hen the variable
7432 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>. 8586 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>.
7433 */ 8587 */
7434 void clearTypePromotionsIfAccessedInScopeAndProtentiallyMutated(ASTNode target ) { 8588 void clearTypePromotionsIfAccessedInClosureAndProtentiallyMutated(ASTNode targ et) {
7435 for (Element element in promoteManager.promotedElements) { 8589 for (Element element in promoteManager.promotedElements) {
7436 if (((element as VariableElementImpl)).isPotentiallyMutatedInScope) { 8590 if ((element as VariableElementImpl).isPotentiallyMutatedInScope) {
7437 if (isVariableAccessedInClosure(element, target)) { 8591 if (isVariableAccessedInClosure(element, target)) {
7438 promoteManager.setType(element, null); 8592 promoteManager.setType(element, null);
7439 } 8593 }
7440 } 8594 }
7441 } 8595 }
7442 } 8596 }
7443 8597
7444 /** 8598 /**
7445 * Checks each promoted variable in the current scope for compliance with the following 8599 * Checks each promoted variable in the current scope for compliance with the following
7446 * specification statement: 8600 * specification statement:
(...skipping 12 matching lines...) Expand all
7459 * Return the best type information available for the given element. If the ty pe of the element 8613 * Return the best type information available for the given element. If the ty pe of the element
7460 * has been overridden, then return the overriding type. Otherwise, return the static type. 8614 * has been overridden, then return the overriding type. Otherwise, return the static type.
7461 * 8615 *
7462 * @param element the element for which type information is to be returned 8616 * @param element the element for which type information is to be returned
7463 * @return the best type information available for the given element 8617 * @return the best type information available for the given element
7464 */ 8618 */
7465 Type2 getBestType(Element element) { 8619 Type2 getBestType(Element element) {
7466 Type2 bestType = overrideManager.getType(element); 8620 Type2 bestType = overrideManager.getType(element);
7467 if (bestType == null) { 8621 if (bestType == null) {
7468 if (element is LocalVariableElement) { 8622 if (element is LocalVariableElement) {
7469 bestType = ((element as LocalVariableElement)).type; 8623 bestType = (element as LocalVariableElement).type;
7470 } else if (element is ParameterElement) { 8624 } else if (element is ParameterElement) {
7471 bestType = ((element as ParameterElement)).type; 8625 bestType = (element as ParameterElement).type;
7472 } 8626 }
7473 } 8627 }
7474 return bestType; 8628 return bestType;
7475 } 8629 }
7476 8630
7477 /** 8631 /**
7478 * The given expression is the expression used to compute the iterator for a f or-each statement. 8632 * The given expression is the expression used to compute the iterator for a f or-each statement.
7479 * Attempt to compute the type of objects that will be assigned to the loop va riable and return 8633 * Attempt to compute the type of objects that will be assigned to the loop va riable and return
7480 * that type. Return `null` if the type could not be determined. 8634 * that type. Return `null` if the type could not be determined.
7481 * 8635 *
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
7547 8701
7548 /** 8702 /**
7549 * Return `true` if the given expression terminates abruptly (that is, if any expression 8703 * Return `true` if the given expression terminates abruptly (that is, if any expression
7550 * following the given expression will not be reached). 8704 * following the given expression will not be reached).
7551 * 8705 *
7552 * @param expression the expression being tested 8706 * @param expression the expression being tested
7553 * @return `true` if the given expression terminates abruptly 8707 * @return `true` if the given expression terminates abruptly
7554 */ 8708 */
7555 bool isAbruptTermination(Expression expression) { 8709 bool isAbruptTermination(Expression expression) {
7556 while (expression is ParenthesizedExpression) { 8710 while (expression is ParenthesizedExpression) {
7557 expression = ((expression as ParenthesizedExpression)).expression; 8711 expression = (expression as ParenthesizedExpression).expression;
7558 } 8712 }
7559 return expression is ThrowExpression || expression is RethrowExpression; 8713 return expression is ThrowExpression || expression is RethrowExpression;
7560 } 8714 }
7561 8715
7562 /** 8716 /**
7563 * Return `true` if the given statement terminates abruptly (that is, if any s tatement 8717 * Return `true` if the given statement terminates abruptly (that is, if any s tatement
7564 * following the given statement will not be reached). 8718 * following the given statement will not be reached).
7565 * 8719 *
7566 * @param statement the statement being tested 8720 * @param statement the statement being tested
7567 * @return `true` if the given statement terminates abruptly 8721 * @return `true` if the given statement terminates abruptly
7568 */ 8722 */
7569 bool isAbruptTermination2(Statement statement) { 8723 bool isAbruptTermination2(Statement statement) {
7570 if (statement is ReturnStatement || statement is BreakStatement || statement is ContinueStatement) { 8724 if (statement is ReturnStatement || statement is BreakStatement || statement is ContinueStatement) {
7571 return true; 8725 return true;
7572 } else if (statement is ExpressionStatement) { 8726 } else if (statement is ExpressionStatement) {
7573 return isAbruptTermination(((statement as ExpressionStatement)).expression ); 8727 return isAbruptTermination((statement as ExpressionStatement).expression);
7574 } else if (statement is Block) { 8728 } else if (statement is Block) {
7575 NodeList<Statement> statements = ((statement as Block)).statements; 8729 NodeList<Statement> statements = (statement as Block).statements;
7576 int size = statements.length; 8730 int size = statements.length;
7577 if (size == 0) { 8731 if (size == 0) {
7578 return false; 8732 return false;
7579 } 8733 }
7580 return isAbruptTermination2(statements[size - 1]); 8734 return isAbruptTermination2(statements[size - 1]);
7581 } 8735 }
7582 return false; 8736 return false;
7583 } 8737 }
7584 8738
7585 /** 8739 /**
7586 * Return `true` if the given variable is accessed within a closure in the giv en 8740 * Return `true` if the given variable is accessed within a closure in the giv en
7587 * [ASTNode] and also mutated somewhere in variable scope. This information is only 8741 * [ASTNode] and also mutated somewhere in variable scope. This information is only
7588 * available for local variables (including parameters). 8742 * available for local variables (including parameters).
7589 * 8743 *
7590 * @param variable the variable to check 8744 * @param variable the variable to check
7591 * @param target the [ASTNode] to check within 8745 * @param target the [ASTNode] to check within
7592 * @return `true` if this variable is potentially mutated somewhere in the giv en ASTNode 8746 * @return `true` if this variable is potentially mutated somewhere in the giv en ASTNode
7593 */ 8747 */
7594 bool isVariableAccessedInClosure(Element variable, ASTNode target) { 8748 bool isVariableAccessedInClosure(Element variable, ASTNode target) {
7595 List<bool> result = [false]; 8749 List<bool> result = [false];
7596 target.accept(new RecursiveASTVisitor_7(result, variable)); 8750 target.accept(new RecursiveASTVisitor_8(result, variable));
7597 return result[0]; 8751 return result[0];
7598 } 8752 }
7599 8753
7600 /** 8754 /**
7601 * Return `true` if the given variable is potentially mutated somewhere in the given 8755 * Return `true` if the given variable is potentially mutated somewhere in the given
7602 * [ASTNode]. This information is only available for local variables (includin g parameters). 8756 * [ASTNode]. This information is only available for local variables (includin g parameters).
7603 * 8757 *
7604 * @param variable the variable to check 8758 * @param variable the variable to check
7605 * @param target the [ASTNode] to check within 8759 * @param target the [ASTNode] to check within
7606 * @return `true` if this variable is potentially mutated somewhere in the giv en ASTNode 8760 * @return `true` if this variable is potentially mutated somewhere in the giv en ASTNode
7607 */ 8761 */
7608 bool isVariablePotentiallyMutatedIn(Element variable, ASTNode target) { 8762 bool isVariablePotentiallyMutatedIn(Element variable, ASTNode target) {
7609 List<bool> result = [false]; 8763 List<bool> result = [false];
7610 target.accept(new RecursiveASTVisitor_8(result, variable)); 8764 target.accept(new RecursiveASTVisitor_9(result, variable));
7611 return result[0]; 8765 return result[0];
7612 } 8766 }
7613 8767
7614 /** 8768 /**
8769 * If it is appropriate to do so, promotes the current type of the static elem ent associated with
8770 * the given expression with the given type. Generally speaking, it is appropr iate if the given
8771 * type is more specific than the current type.
8772 *
8773 * @param expression the expression used to access the static element whose ty pes might be
8774 * promoted
8775 * @param potentialType the potential type of the elements
8776 */
8777 void promote(Expression expression, Type2 potentialType) {
8778 VariableElement element = getPromotionStaticElement(expression);
8779 if (element != null) {
8780 if ((element as VariableElementImpl).isPotentiallyMutatedInClosure) {
8781 return;
8782 }
8783 Type2 type = promoteManager.getType(element);
8784 if (type == null) {
8785 type = expression.staticType;
8786 }
8787 if (type == null || type.isDynamic) {
8788 return;
8789 }
8790 if (potentialType == null || potentialType.isDynamic) {
8791 return;
8792 }
8793 if (!potentialType.isMoreSpecificThan(type)) {
8794 return;
8795 }
8796 promoteManager.setType(element, potentialType);
8797 }
8798 }
8799
8800 /**
7615 * Promotes type information using given condition. 8801 * Promotes type information using given condition.
7616 */ 8802 */
7617 void promoteTypes(Expression condition) { 8803 void promoteTypes(Expression condition) {
7618 if (condition is BinaryExpression) { 8804 if (condition is BinaryExpression) {
7619 BinaryExpression binary = condition as BinaryExpression; 8805 BinaryExpression binary = condition as BinaryExpression;
7620 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) { 8806 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) {
7621 Expression left = binary.leftOperand; 8807 Expression left = binary.leftOperand;
7622 Expression right = binary.rightOperand; 8808 Expression right = binary.rightOperand;
7623 promoteTypes(left); 8809 promoteTypes(left);
7624 promoteTypes(right); 8810 promoteTypes(right);
7625 clearTypePromotionsIfPotentiallyMutatedIn(right); 8811 clearTypePromotionsIfPotentiallyMutatedIn(right);
7626 } 8812 }
7627 } else if (condition is IsExpression) { 8813 } else if (condition is IsExpression) {
7628 IsExpression is2 = condition as IsExpression; 8814 IsExpression is2 = condition as IsExpression;
7629 if (is2.notOperator == null) { 8815 if (is2.notOperator == null) {
7630 promote(is2.expression, is2.type.type); 8816 promote(is2.expression, is2.type.type);
7631 } 8817 }
7632 } else if (condition is ParenthesizedExpression) { 8818 } else if (condition is ParenthesizedExpression) {
7633 promoteTypes(((condition as ParenthesizedExpression)).expression); 8819 promoteTypes((condition as ParenthesizedExpression).expression);
7634 } 8820 }
7635 } 8821 }
7636 8822
7637 /** 8823 /**
7638 * Propagate any type information that results from knowing that the given con dition will have 8824 * Propagate any type information that results from knowing that the given con dition will have
7639 * been evaluated to 'false'. 8825 * been evaluated to 'false'.
7640 * 8826 *
7641 * @param condition the condition that will have evaluated to 'false' 8827 * @param condition the condition that will have evaluated to 'false'
7642 */ 8828 */
7643 void propagateFalseState(Expression condition) { 8829 void propagateFalseState(Expression condition) {
7644 if (condition is BinaryExpression) { 8830 if (condition is BinaryExpression) {
7645 BinaryExpression binary = condition as BinaryExpression; 8831 BinaryExpression binary = condition as BinaryExpression;
7646 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) { 8832 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) {
7647 propagateFalseState(binary.leftOperand); 8833 propagateFalseState(binary.leftOperand);
7648 propagateFalseState(binary.rightOperand); 8834 propagateFalseState(binary.rightOperand);
7649 } 8835 }
7650 } else if (condition is IsExpression) { 8836 } else if (condition is IsExpression) {
7651 IsExpression is2 = condition as IsExpression; 8837 IsExpression is2 = condition as IsExpression;
7652 if (is2.notOperator != null) { 8838 if (is2.notOperator != null) {
7653 override(is2.expression, is2.type.type); 8839 override(is2.expression, is2.type.type);
7654 } 8840 }
7655 } else if (condition is PrefixExpression) { 8841 } else if (condition is PrefixExpression) {
7656 PrefixExpression prefix = condition as PrefixExpression; 8842 PrefixExpression prefix = condition as PrefixExpression;
7657 if (identical(prefix.operator.type, sc.TokenType.BANG)) { 8843 if (identical(prefix.operator.type, sc.TokenType.BANG)) {
7658 propagateTrueState(prefix.operand); 8844 propagateTrueState(prefix.operand);
7659 } 8845 }
7660 } else if (condition is ParenthesizedExpression) { 8846 } else if (condition is ParenthesizedExpression) {
7661 propagateFalseState(((condition as ParenthesizedExpression)).expression); 8847 propagateFalseState((condition as ParenthesizedExpression).expression);
7662 } 8848 }
7663 } 8849 }
7664 8850
7665 /** 8851 /**
7666 * Propagate any type information that results from knowing that the given exp ression will have 8852 * Propagate any type information that results from knowing that the given exp ression will have
7667 * been evaluated without altering the flow of execution. 8853 * been evaluated without altering the flow of execution.
7668 * 8854 *
7669 * @param expression the expression that will have been evaluated 8855 * @param expression the expression that will have been evaluated
7670 */ 8856 */
7671 void propagateState(Expression expression) { 8857 void propagateState(Expression expression) {
(...skipping 16 matching lines...) Expand all
7688 IsExpression is2 = condition as IsExpression; 8874 IsExpression is2 = condition as IsExpression;
7689 if (is2.notOperator == null) { 8875 if (is2.notOperator == null) {
7690 override(is2.expression, is2.type.type); 8876 override(is2.expression, is2.type.type);
7691 } 8877 }
7692 } else if (condition is PrefixExpression) { 8878 } else if (condition is PrefixExpression) {
7693 PrefixExpression prefix = condition as PrefixExpression; 8879 PrefixExpression prefix = condition as PrefixExpression;
7694 if (identical(prefix.operator.type, sc.TokenType.BANG)) { 8880 if (identical(prefix.operator.type, sc.TokenType.BANG)) {
7695 propagateFalseState(prefix.operand); 8881 propagateFalseState(prefix.operand);
7696 } 8882 }
7697 } else if (condition is ParenthesizedExpression) { 8883 } else if (condition is ParenthesizedExpression) {
7698 propagateTrueState(((condition as ParenthesizedExpression)).expression); 8884 propagateTrueState((condition as ParenthesizedExpression).expression);
7699 } 8885 }
7700 } 8886 }
7701 8887
7702 /** 8888 /**
7703 * Record that the propagated type of the given node is the given type. 8889 * Record that the propagated type of the given node is the given type.
7704 * 8890 *
7705 * @param expression the node whose type is to be recorded 8891 * @param expression the node whose type is to be recorded
7706 * @param type the propagated type of the node 8892 * @param type the propagated type of the node
7707 */ 8893 */
7708 void recordPropagatedType(Expression expression, Type2 type) { 8894 void recordPropagatedType(Expression expression, Type2 type) {
7709 if (type != null && !type.isDynamic) { 8895 if (type != null && !type.isDynamic) {
7710 expression.propagatedType = type; 8896 expression.propagatedType = type;
7711 } 8897 }
7712 } 8898 }
8899
7713 get elementResolver_J2DAccessor => _elementResolver; 8900 get elementResolver_J2DAccessor => _elementResolver;
8901
7714 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; 8902 set elementResolver_J2DAccessor(__v) => _elementResolver = __v;
8903
7715 get labelScope_J2DAccessor => labelScope; 8904 get labelScope_J2DAccessor => labelScope;
8905
7716 set labelScope_J2DAccessor(__v) => labelScope = __v; 8906 set labelScope_J2DAccessor(__v) => labelScope = __v;
8907
7717 get nameScope_J2DAccessor => nameScope; 8908 get nameScope_J2DAccessor => nameScope;
8909
7718 set nameScope_J2DAccessor(__v) => nameScope = __v; 8910 set nameScope_J2DAccessor(__v) => nameScope = __v;
8911
7719 get typeAnalyzer_J2DAccessor => _typeAnalyzer; 8912 get typeAnalyzer_J2DAccessor => _typeAnalyzer;
8913
7720 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; 8914 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v;
8915
7721 get enclosingClass_J2DAccessor => enclosingClass; 8916 get enclosingClass_J2DAccessor => enclosingClass;
8917
7722 set enclosingClass_J2DAccessor(__v) => enclosingClass = __v; 8918 set enclosingClass_J2DAccessor(__v) => enclosingClass = __v;
7723 } 8919 }
7724 class RecursiveASTVisitor_7 extends RecursiveASTVisitor<Object> { 8920
8921 class RecursiveASTVisitor_8 extends RecursiveASTVisitor<Object> {
7725 List<bool> result; 8922 List<bool> result;
8923
7726 Element variable; 8924 Element variable;
7727 RecursiveASTVisitor_7(this.result, this.variable) : super(); 8925
8926 RecursiveASTVisitor_8(this.result, this.variable) : super();
8927
7728 bool _inClosure = false; 8928 bool _inClosure = false;
8929
7729 Object visitFunctionExpression(FunctionExpression node) { 8930 Object visitFunctionExpression(FunctionExpression node) {
7730 bool inClosure = this._inClosure; 8931 bool inClosure = this._inClosure;
7731 try { 8932 try {
7732 this._inClosure = true; 8933 this._inClosure = true;
7733 return super.visitFunctionExpression(node); 8934 return super.visitFunctionExpression(node);
7734 } finally { 8935 } finally {
7735 this._inClosure = inClosure; 8936 this._inClosure = inClosure;
7736 } 8937 }
7737 } 8938 }
8939
7738 Object visitSimpleIdentifier(SimpleIdentifier node) { 8940 Object visitSimpleIdentifier(SimpleIdentifier node) {
7739 if (result[0]) { 8941 if (result[0]) {
7740 return null; 8942 return null;
7741 } 8943 }
7742 if (_inClosure && identical(node.staticElement, variable)) { 8944 if (_inClosure && identical(node.staticElement, variable)) {
7743 result[0] = javaBooleanOr(result[0], true); 8945 result[0] = javaBooleanOr(result[0], true);
7744 } 8946 }
7745 return null; 8947 return null;
7746 } 8948 }
7747 } 8949 }
7748 class RecursiveASTVisitor_8 extends RecursiveASTVisitor<Object> { 8950
8951 class RecursiveASTVisitor_9 extends RecursiveASTVisitor<Object> {
7749 List<bool> result; 8952 List<bool> result;
8953
7750 Element variable; 8954 Element variable;
7751 RecursiveASTVisitor_8(this.result, this.variable) : super(); 8955
8956 RecursiveASTVisitor_9(this.result, this.variable) : super();
8957
7752 Object visitSimpleIdentifier(SimpleIdentifier node) { 8958 Object visitSimpleIdentifier(SimpleIdentifier node) {
7753 if (result[0]) { 8959 if (result[0]) {
7754 return null; 8960 return null;
7755 } 8961 }
7756 if (identical(node.staticElement, variable)) { 8962 if (identical(node.staticElement, variable)) {
7757 if (node.inSetterContext()) { 8963 if (node.inSetterContext()) {
7758 result[0] = javaBooleanOr(result[0], true); 8964 result[0] = javaBooleanOr(result[0], true);
7759 } 8965 }
7760 } 8966 }
7761 return null; 8967 return null;
7762 } 8968 }
7763 } 8969 }
8970
7764 /** 8971 /**
7765 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST structure is 8972 * The abstract class `ScopedVisitor` maintains name and label scopes as an AST structure is
7766 * being visited. 8973 * being visited.
7767 * 8974 *
7768 * @coverage dart.engine.resolver 8975 * @coverage dart.engine.resolver
7769 */ 8976 */
7770 abstract class ScopedVisitor extends UnifyingASTVisitor<Object> { 8977 abstract class ScopedVisitor extends UnifyingASTVisitor<Object> {
7771
7772 /** 8978 /**
7773 * The element for the library containing the compilation unit being visited. 8979 * The element for the library containing the compilation unit being visited.
7774 */ 8980 */
7775 LibraryElement definingLibrary; 8981 LibraryElement definingLibrary;
7776 8982
7777 /** 8983 /**
7778 * The source representing the compilation unit being visited. 8984 * The source representing the compilation unit being visited.
7779 */ 8985 */
7780 Source source; 8986 Source source;
7781 8987
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
7828 */ 9034 */
7829 ScopedVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, AnalysisErrorListener errorListener) { 9035 ScopedVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, AnalysisErrorListener errorListener) {
7830 this.definingLibrary = definingLibrary; 9036 this.definingLibrary = definingLibrary;
7831 this.source = source; 9037 this.source = source;
7832 this._errorListener = errorListener; 9038 this._errorListener = errorListener;
7833 this.nameScope = new LibraryScope(definingLibrary, errorListener); 9039 this.nameScope = new LibraryScope(definingLibrary, errorListener);
7834 this.typeProvider = typeProvider; 9040 this.typeProvider = typeProvider;
7835 } 9041 }
7836 9042
7837 /** 9043 /**
9044 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
9045 *
9046 * @param definingLibrary the element for the library containing the compilati on unit being
9047 * visited
9048 * @param source the source representing the compilation unit being visited
9049 * @param typeProvider the object used to access the types from the core libra ry
9050 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
9051 * @param errorListener the error listener that will be informed of any errors that are found
9052 * during resolution
9053 */
9054 ScopedVisitor.con3(LibraryElement definingLibrary, Source source, TypeProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) {
9055 this.definingLibrary = definingLibrary;
9056 this.source = source;
9057 this._errorListener = errorListener;
9058 this.nameScope = nameScope;
9059 this.typeProvider = typeProvider;
9060 }
9061
9062 /**
7838 * Report an error with the given analysis error. 9063 * Report an error with the given analysis error.
7839 * 9064 *
7840 * @param errorCode analysis error 9065 * @param errorCode analysis error
7841 */ 9066 */
7842 void reportError(AnalysisError analysisError) { 9067 void reportError(AnalysisError analysisError) {
7843 _errorListener.onError(analysisError); 9068 _errorListener.onError(analysisError);
7844 } 9069 }
9070
7845 Object visitBlock(Block node) { 9071 Object visitBlock(Block node) {
7846 Scope outerScope = nameScope; 9072 Scope outerScope = nameScope;
7847 try { 9073 try {
7848 EnclosedScope enclosedScope = new EnclosedScope(nameScope); 9074 EnclosedScope enclosedScope = new EnclosedScope(nameScope);
7849 hideNamesDefinedInBlock(enclosedScope, node); 9075 hideNamesDefinedInBlock(enclosedScope, node);
7850 nameScope = enclosedScope; 9076 nameScope = enclosedScope;
7851 super.visitBlock(node); 9077 super.visitBlock(node);
7852 } finally { 9078 } finally {
7853 nameScope = outerScope; 9079 nameScope = outerScope;
7854 } 9080 }
7855 return null; 9081 return null;
7856 } 9082 }
9083
7857 Object visitCatchClause(CatchClause node) { 9084 Object visitCatchClause(CatchClause node) {
7858 SimpleIdentifier exception = node.exceptionParameter; 9085 SimpleIdentifier exception = node.exceptionParameter;
7859 if (exception != null) { 9086 if (exception != null) {
7860 Scope outerScope = nameScope; 9087 Scope outerScope = nameScope;
7861 try { 9088 try {
7862 nameScope = new EnclosedScope(nameScope); 9089 nameScope = new EnclosedScope(nameScope);
7863 nameScope.define(exception.staticElement); 9090 nameScope.define(exception.staticElement);
7864 SimpleIdentifier stackTrace = node.stackTraceParameter; 9091 SimpleIdentifier stackTrace = node.stackTraceParameter;
7865 if (stackTrace != null) { 9092 if (stackTrace != null) {
7866 nameScope.define(stackTrace.staticElement); 9093 nameScope.define(stackTrace.staticElement);
7867 } 9094 }
7868 super.visitCatchClause(node); 9095 super.visitCatchClause(node);
7869 } finally { 9096 } finally {
7870 nameScope = outerScope; 9097 nameScope = outerScope;
7871 } 9098 }
7872 } else { 9099 } else {
7873 super.visitCatchClause(node); 9100 super.visitCatchClause(node);
7874 } 9101 }
7875 return null; 9102 return null;
7876 } 9103 }
9104
7877 Object visitClassDeclaration(ClassDeclaration node) { 9105 Object visitClassDeclaration(ClassDeclaration node) {
7878 Scope outerScope = nameScope; 9106 Scope outerScope = nameScope;
7879 try { 9107 try {
7880 nameScope = new ClassScope(nameScope, node.element); 9108 nameScope = new ClassScope(nameScope, node.element);
7881 super.visitClassDeclaration(node); 9109 super.visitClassDeclaration(node);
7882 } finally { 9110 } finally {
7883 nameScope = outerScope; 9111 nameScope = outerScope;
7884 } 9112 }
7885 return null; 9113 return null;
7886 } 9114 }
9115
7887 Object visitClassTypeAlias(ClassTypeAlias node) { 9116 Object visitClassTypeAlias(ClassTypeAlias node) {
7888 Scope outerScope = nameScope; 9117 Scope outerScope = nameScope;
7889 try { 9118 try {
7890 nameScope = new ClassScope(nameScope, node.element); 9119 nameScope = new ClassScope(nameScope, node.element);
7891 super.visitClassTypeAlias(node); 9120 super.visitClassTypeAlias(node);
7892 } finally { 9121 } finally {
7893 nameScope = outerScope; 9122 nameScope = outerScope;
7894 } 9123 }
7895 return null; 9124 return null;
7896 } 9125 }
9126
7897 Object visitConstructorDeclaration(ConstructorDeclaration node) { 9127 Object visitConstructorDeclaration(ConstructorDeclaration node) {
7898 Scope outerScope = nameScope; 9128 Scope outerScope = nameScope;
7899 try { 9129 try {
7900 nameScope = new FunctionScope(nameScope, node.element); 9130 nameScope = new FunctionScope(nameScope, node.element);
7901 super.visitConstructorDeclaration(node); 9131 super.visitConstructorDeclaration(node);
7902 } finally { 9132 } finally {
7903 nameScope = outerScope; 9133 nameScope = outerScope;
7904 } 9134 }
7905 return null; 9135 return null;
7906 } 9136 }
9137
7907 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 9138 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
7908 VariableElement element = node.element; 9139 VariableElement element = node.element;
7909 if (element != null) { 9140 if (element != null) {
7910 nameScope.define(element); 9141 nameScope.define(element);
7911 } 9142 }
7912 super.visitDeclaredIdentifier(node); 9143 super.visitDeclaredIdentifier(node);
7913 return null; 9144 return null;
7914 } 9145 }
9146
7915 Object visitDoStatement(DoStatement node) { 9147 Object visitDoStatement(DoStatement node) {
7916 LabelScope outerLabelScope = labelScope; 9148 LabelScope outerLabelScope = labelScope;
7917 try { 9149 try {
7918 labelScope = new LabelScope.con1(labelScope, false, false); 9150 labelScope = new LabelScope.con1(labelScope, false, false);
7919 visitStatementInScope(node.body); 9151 visitStatementInScope(node.body);
7920 safelyVisit(node.condition); 9152 safelyVisit(node.condition);
7921 } finally { 9153 } finally {
7922 labelScope = outerLabelScope; 9154 labelScope = outerLabelScope;
7923 } 9155 }
7924 return null; 9156 return null;
7925 } 9157 }
9158
7926 Object visitForEachStatement(ForEachStatement node) { 9159 Object visitForEachStatement(ForEachStatement node) {
7927 Scope outerNameScope = nameScope; 9160 Scope outerNameScope = nameScope;
7928 LabelScope outerLabelScope = labelScope; 9161 LabelScope outerLabelScope = labelScope;
7929 try { 9162 try {
7930 nameScope = new EnclosedScope(nameScope); 9163 nameScope = new EnclosedScope(nameScope);
7931 labelScope = new LabelScope.con1(outerLabelScope, false, false); 9164 labelScope = new LabelScope.con1(outerLabelScope, false, false);
7932 visitForEachStatementInScope(node); 9165 visitForEachStatementInScope(node);
7933 } finally { 9166 } finally {
7934 labelScope = outerLabelScope; 9167 labelScope = outerLabelScope;
7935 nameScope = outerNameScope; 9168 nameScope = outerNameScope;
7936 } 9169 }
7937 return null; 9170 return null;
7938 } 9171 }
9172
7939 Object visitFormalParameterList(FormalParameterList node) { 9173 Object visitFormalParameterList(FormalParameterList node) {
7940 super.visitFormalParameterList(node); 9174 super.visitFormalParameterList(node);
7941 if (nameScope is FunctionScope) { 9175 if (nameScope is FunctionScope) {
7942 ((nameScope as FunctionScope)).defineParameters(); 9176 (nameScope as FunctionScope).defineParameters();
7943 } 9177 }
7944 if (nameScope is FunctionTypeScope) { 9178 if (nameScope is FunctionTypeScope) {
7945 ((nameScope as FunctionTypeScope)).defineParameters(); 9179 (nameScope as FunctionTypeScope).defineParameters();
7946 } 9180 }
7947 return null; 9181 return null;
7948 } 9182 }
9183
7949 Object visitForStatement(ForStatement node) { 9184 Object visitForStatement(ForStatement node) {
7950 Scope outerNameScope = nameScope; 9185 Scope outerNameScope = nameScope;
7951 LabelScope outerLabelScope = labelScope; 9186 LabelScope outerLabelScope = labelScope;
7952 try { 9187 try {
7953 nameScope = new EnclosedScope(nameScope); 9188 nameScope = new EnclosedScope(nameScope);
7954 labelScope = new LabelScope.con1(outerLabelScope, false, false); 9189 labelScope = new LabelScope.con1(outerLabelScope, false, false);
7955 visitForStatementInScope(node); 9190 visitForStatementInScope(node);
7956 } finally { 9191 } finally {
7957 labelScope = outerLabelScope; 9192 labelScope = outerLabelScope;
7958 nameScope = outerNameScope; 9193 nameScope = outerNameScope;
7959 } 9194 }
7960 return null; 9195 return null;
7961 } 9196 }
9197
7962 Object visitFunctionDeclaration(FunctionDeclaration node) { 9198 Object visitFunctionDeclaration(FunctionDeclaration node) {
7963 ExecutableElement function = node.element; 9199 ExecutableElement function = node.element;
7964 Scope outerScope = nameScope; 9200 Scope outerScope = nameScope;
7965 try { 9201 try {
7966 nameScope = new FunctionScope(nameScope, function); 9202 nameScope = new FunctionScope(nameScope, function);
7967 super.visitFunctionDeclaration(node); 9203 super.visitFunctionDeclaration(node);
7968 } finally { 9204 } finally {
7969 nameScope = outerScope; 9205 nameScope = outerScope;
7970 } 9206 }
7971 if (function.enclosingElement is! CompilationUnitElement) { 9207 if (function.enclosingElement is! CompilationUnitElement) {
7972 nameScope.define(function); 9208 nameScope.define(function);
7973 } 9209 }
7974 return null; 9210 return null;
7975 } 9211 }
9212
7976 Object visitFunctionExpression(FunctionExpression node) { 9213 Object visitFunctionExpression(FunctionExpression node) {
7977 if (node.parent is FunctionDeclaration) { 9214 if (node.parent is FunctionDeclaration) {
7978 super.visitFunctionExpression(node); 9215 super.visitFunctionExpression(node);
7979 } else { 9216 } else {
7980 Scope outerScope = nameScope; 9217 Scope outerScope = nameScope;
7981 try { 9218 try {
7982 ExecutableElement functionElement = node.element; 9219 ExecutableElement functionElement = node.element;
7983 if (functionElement == null) { 9220 if (functionElement == null) {
7984 } else { 9221 } else {
7985 nameScope = new FunctionScope(nameScope, functionElement); 9222 nameScope = new FunctionScope(nameScope, functionElement);
7986 } 9223 }
7987 super.visitFunctionExpression(node); 9224 super.visitFunctionExpression(node);
7988 } finally { 9225 } finally {
7989 nameScope = outerScope; 9226 nameScope = outerScope;
7990 } 9227 }
7991 } 9228 }
7992 return null; 9229 return null;
7993 } 9230 }
9231
7994 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 9232 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
7995 Scope outerScope = nameScope; 9233 Scope outerScope = nameScope;
7996 try { 9234 try {
7997 nameScope = new FunctionTypeScope(nameScope, node.element); 9235 nameScope = new FunctionTypeScope(nameScope, node.element);
7998 super.visitFunctionTypeAlias(node); 9236 super.visitFunctionTypeAlias(node);
7999 } finally { 9237 } finally {
8000 nameScope = outerScope; 9238 nameScope = outerScope;
8001 } 9239 }
8002 return null; 9240 return null;
8003 } 9241 }
9242
8004 Object visitIfStatement(IfStatement node) { 9243 Object visitIfStatement(IfStatement node) {
8005 safelyVisit(node.condition); 9244 safelyVisit(node.condition);
8006 visitStatementInScope(node.thenStatement); 9245 visitStatementInScope(node.thenStatement);
8007 visitStatementInScope(node.elseStatement); 9246 visitStatementInScope(node.elseStatement);
8008 return null; 9247 return null;
8009 } 9248 }
9249
8010 Object visitLabeledStatement(LabeledStatement node) { 9250 Object visitLabeledStatement(LabeledStatement node) {
8011 LabelScope outerScope = addScopesFor(node.labels); 9251 LabelScope outerScope = addScopesFor(node.labels);
8012 try { 9252 try {
8013 super.visitLabeledStatement(node); 9253 super.visitLabeledStatement(node);
8014 } finally { 9254 } finally {
8015 labelScope = outerScope; 9255 labelScope = outerScope;
8016 } 9256 }
8017 return null; 9257 return null;
8018 } 9258 }
9259
8019 Object visitMethodDeclaration(MethodDeclaration node) { 9260 Object visitMethodDeclaration(MethodDeclaration node) {
8020 Scope outerScope = nameScope; 9261 Scope outerScope = nameScope;
8021 try { 9262 try {
8022 nameScope = new FunctionScope(nameScope, node.element); 9263 nameScope = new FunctionScope(nameScope, node.element);
8023 super.visitMethodDeclaration(node); 9264 super.visitMethodDeclaration(node);
8024 } finally { 9265 } finally {
8025 nameScope = outerScope; 9266 nameScope = outerScope;
8026 } 9267 }
8027 return null; 9268 return null;
8028 } 9269 }
9270
8029 Object visitSwitchCase(SwitchCase node) { 9271 Object visitSwitchCase(SwitchCase node) {
8030 node.expression.accept(this); 9272 node.expression.accept(this);
8031 Scope outerNameScope = nameScope; 9273 Scope outerNameScope = nameScope;
8032 try { 9274 try {
8033 nameScope = new EnclosedScope(nameScope); 9275 nameScope = new EnclosedScope(nameScope);
8034 node.statements.accept(this); 9276 node.statements.accept(this);
8035 } finally { 9277 } finally {
8036 nameScope = outerNameScope; 9278 nameScope = outerNameScope;
8037 } 9279 }
8038 return null; 9280 return null;
8039 } 9281 }
9282
8040 Object visitSwitchDefault(SwitchDefault node) { 9283 Object visitSwitchDefault(SwitchDefault node) {
8041 Scope outerNameScope = nameScope; 9284 Scope outerNameScope = nameScope;
8042 try { 9285 try {
8043 nameScope = new EnclosedScope(nameScope); 9286 nameScope = new EnclosedScope(nameScope);
8044 node.statements.accept(this); 9287 node.statements.accept(this);
8045 } finally { 9288 } finally {
8046 nameScope = outerNameScope; 9289 nameScope = outerNameScope;
8047 } 9290 }
8048 return null; 9291 return null;
8049 } 9292 }
9293
8050 Object visitSwitchStatement(SwitchStatement node) { 9294 Object visitSwitchStatement(SwitchStatement node) {
8051 LabelScope outerScope = labelScope; 9295 LabelScope outerScope = labelScope;
8052 try { 9296 try {
8053 labelScope = new LabelScope.con1(outerScope, true, false); 9297 labelScope = new LabelScope.con1(outerScope, true, false);
8054 for (SwitchMember member in node.members) { 9298 for (SwitchMember member in node.members) {
8055 for (Label label in member.labels) { 9299 for (Label label in member.labels) {
8056 SimpleIdentifier labelName = label.label; 9300 SimpleIdentifier labelName = label.label;
8057 LabelElement labelElement = labelName.staticElement as LabelElement; 9301 LabelElement labelElement = labelName.staticElement as LabelElement;
8058 labelScope = new LabelScope.con2(labelScope, labelName.name, labelElem ent); 9302 labelScope = new LabelScope.con2(labelScope, labelName.name, labelElem ent);
8059 } 9303 }
8060 } 9304 }
8061 super.visitSwitchStatement(node); 9305 super.visitSwitchStatement(node);
8062 } finally { 9306 } finally {
8063 labelScope = outerScope; 9307 labelScope = outerScope;
8064 } 9308 }
8065 return null; 9309 return null;
8066 } 9310 }
9311
8067 Object visitVariableDeclaration(VariableDeclaration node) { 9312 Object visitVariableDeclaration(VariableDeclaration node) {
9313 super.visitVariableDeclaration(node);
8068 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent is! FieldDeclaration) { 9314 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent is! FieldDeclaration) {
8069 VariableElement element = node.element; 9315 VariableElement element = node.element;
8070 if (element != null) { 9316 if (element != null) {
8071 nameScope.define(element); 9317 nameScope.define(element);
8072 } 9318 }
8073 } 9319 }
8074 super.visitVariableDeclaration(node);
8075 return null; 9320 return null;
8076 } 9321 }
9322
8077 Object visitWhileStatement(WhileStatement node) { 9323 Object visitWhileStatement(WhileStatement node) {
8078 LabelScope outerScope = labelScope; 9324 LabelScope outerScope = labelScope;
8079 try { 9325 try {
8080 labelScope = new LabelScope.con1(outerScope, false, false); 9326 labelScope = new LabelScope.con1(outerScope, false, false);
8081 safelyVisit(node.condition); 9327 safelyVisit(node.condition);
8082 visitStatementInScope(node.body); 9328 visitStatementInScope(node.body);
8083 } finally { 9329 } finally {
8084 labelScope = outerScope; 9330 labelScope = outerScope;
8085 } 9331 }
8086 return null; 9332 return null;
8087 } 9333 }
8088 9334
8089 /** 9335 /**
8090 * Report an error with the given error code and arguments. 9336 * Report an error with the given error code and arguments.
8091 * 9337 *
8092 * @param errorCode the error code of the error to be reported 9338 * @param errorCode the error code of the error to be reported
8093 * @param node the node specifying the location of the error 9339 * @param node the node specifying the location of the error
8094 * @param arguments the arguments to the error, used to compose the error mess age 9340 * @param arguments the arguments to the error, used to compose the error mess age
8095 */ 9341 */
8096 void reportError5(ErrorCode errorCode, ASTNode node, List<Object> arguments) { 9342 void reportError6(ErrorCode errorCode, ASTNode node, List<Object> arguments) {
8097 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng th, errorCode, arguments)); 9343 _errorListener.onError(new AnalysisError.con2(source, node.offset, node.leng th, errorCode, arguments));
8098 } 9344 }
8099 9345
8100 /** 9346 /**
8101 * Report an error with the given error code and arguments. 9347 * Report an error with the given error code and arguments.
8102 * 9348 *
8103 * @param errorCode the error code of the error to be reported 9349 * @param errorCode the error code of the error to be reported
8104 * @param offset the offset of the location of the error 9350 * @param offset the offset of the location of the error
8105 * @param length the length of the location of the error 9351 * @param length the length of the location of the error
8106 * @param arguments the arguments to the error, used to compose the error mess age 9352 * @param arguments the arguments to the error, used to compose the error mess age
8107 */ 9353 */
8108 void reportError6(ErrorCode errorCode, int offset, int length, List<Object> ar guments) { 9354 void reportError7(ErrorCode errorCode, int offset, int length, List<Object> ar guments) {
8109 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC ode, arguments)); 9355 _errorListener.onError(new AnalysisError.con2(source, offset, length, errorC ode, arguments));
8110 } 9356 }
8111 9357
8112 /** 9358 /**
8113 * Report an error with the given error code and arguments. 9359 * Report an error with the given error code and arguments.
8114 * 9360 *
8115 * @param errorCode the error code of the error to be reported 9361 * @param errorCode the error code of the error to be reported
8116 * @param token the token specifying the location of the error 9362 * @param token the token specifying the location of the error
8117 * @param arguments the arguments to the error, used to compose the error mess age 9363 * @param arguments the arguments to the error, used to compose the error mess age
8118 */ 9364 */
8119 void reportError7(ErrorCode errorCode, sc.Token token, List<Object> arguments) { 9365 void reportError8(ErrorCode errorCode, sc.Token token, List<Object> arguments) {
8120 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le ngth, errorCode, arguments)); 9366 _errorListener.onError(new AnalysisError.con2(source, token.offset, token.le ngth, errorCode, arguments));
8121 } 9367 }
8122 9368
8123 /** 9369 /**
8124 * Visit the given AST node if it is not null. 9370 * Visit the given AST node if it is not null.
8125 * 9371 *
8126 * @param node the node to be visited 9372 * @param node the node to be visited
8127 */ 9373 */
8128 void safelyVisit(ASTNode node) { 9374 void safelyVisit(ASTNode node) {
8129 if (node != null) { 9375 if (node != null) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
8212 } 9458 }
8213 } 9459 }
8214 if (statement is FunctionDeclarationStatement) { 9460 if (statement is FunctionDeclarationStatement) {
8215 FunctionDeclarationStatement fds = statement as FunctionDeclarationState ment; 9461 FunctionDeclarationStatement fds = statement as FunctionDeclarationState ment;
8216 Element element = fds.functionDeclaration.element; 9462 Element element = fds.functionDeclaration.element;
8217 scope.hide(element); 9463 scope.hide(element);
8218 } 9464 }
8219 } 9465 }
8220 } 9466 }
8221 } 9467 }
9468
8222 /** 9469 /**
8223 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F irst, they 9470 * Instances of the class `StaticTypeAnalyzer` perform two type-related tasks. F irst, they
8224 * compute the static type of every expression. Second, they look for any static type errors or 9471 * compute the static type of every expression. Second, they look for any static type errors or
8225 * warnings that might need to be generated. The requirements for the type analy zer are: 9472 * warnings that might need to be generated. The requirements for the type analy zer are:
8226 * <ol> 9473 * <ol>
8227 * * Every element that refers to types should be fully populated. 9474 * * Every element that refers to types should be fully populated.
8228 * * Every node representing an expression should be resolved to the Type of the expression. 9475 * * Every node representing an expression should be resolved to the Type of the expression.
8229 * </ol> 9476 * </ol>
8230 * 9477 *
8231 * @coverage dart.engine.resolver 9478 * @coverage dart.engine.resolver
8232 */ 9479 */
8233 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { 9480 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> {
8234
8235 /** 9481 /**
8236 * Create a table mapping HTML tag names to the names of the classes (in 'dart :html') that 9482 * Create a table mapping HTML tag names to the names of the classes (in 'dart :html') that
8237 * implement those tags. 9483 * implement those tags.
8238 * 9484 *
8239 * @return the table that was created 9485 * @return the table that was created
8240 */ 9486 */
8241 static Map<String, String> createHtmlTagToClassMap() { 9487 static Map<String, String> createHtmlTagToClassMap() {
8242 Map<String, String> map = new Map<String, String>(); 9488 Map<String, String> map = new Map<String, String>();
8243 map["a"] = "AnchorElement"; 9489 map["a"] = "AnchorElement";
8244 map["area"] = "AreaElement"; 9490 map["area"] = "AreaElement";
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
8578 } 9824 }
8579 9825
8580 /** 9826 /**
8581 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is 9827 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is
8582 * double.</blockquote> 9828 * double.</blockquote>
8583 */ 9829 */
8584 Object visitDoubleLiteral(DoubleLiteral node) { 9830 Object visitDoubleLiteral(DoubleLiteral node) {
8585 recordStaticType(node, _typeProvider.doubleType); 9831 recordStaticType(node, _typeProvider.doubleType);
8586 return null; 9832 return null;
8587 } 9833 }
9834
8588 Object visitFunctionDeclaration(FunctionDeclaration node) { 9835 Object visitFunctionDeclaration(FunctionDeclaration node) {
8589 FunctionExpression function = node.functionExpression; 9836 FunctionExpression function = node.functionExpression;
8590 ExecutableElementImpl functionElement = node.element as ExecutableElementImp l; 9837 ExecutableElementImpl functionElement = node.element as ExecutableElementImp l;
8591 functionElement.returnType = computeStaticReturnType2(node); 9838 functionElement.returnType = computeStaticReturnType2(node);
8592 recordPropagatedType(functionElement, function.body); 9839 recordPropagatedType(functionElement, function.body);
8593 recordStaticType(function, functionElement.type); 9840 recordStaticType(function, functionElement.type);
8594 return null; 9841 return null;
8595 } 9842 }
8596 9843
8597 /** 9844 /**
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
9007 recordPropagatedType2(node, propagatedStaticType); 10254 recordPropagatedType2(node, propagatedStaticType);
9008 } 10255 }
9009 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedE lement); 10256 Type2 propagatedPropagatedType = computePropagatedReturnType(propagatedE lement);
9010 if (propagatedPropagatedType != null && (staticStaticType == null || pro pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType )) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh an(propagatedStaticType))) { 10257 if (propagatedPropagatedType != null && (staticStaticType == null || pro pagatedPropagatedType.isMoreSpecificThan(staticStaticType)) && (staticPropagated Type == null || propagatedPropagatedType.isMoreSpecificThan(staticPropagatedType )) && (propagatedStaticType == null || propagatedPropagatedType.isMoreSpecificTh an(propagatedStaticType))) {
9011 recordPropagatedType2(node, propagatedPropagatedType); 10258 recordPropagatedType2(node, propagatedPropagatedType);
9012 } 10259 }
9013 } 10260 }
9014 } 10261 }
9015 return null; 10262 return null;
9016 } 10263 }
10264
9017 Object visitNamedExpression(NamedExpression node) { 10265 Object visitNamedExpression(NamedExpression node) {
9018 Expression expression = node.expression; 10266 Expression expression = node.expression;
9019 recordStaticType(node, getStaticType(expression)); 10267 recordStaticType(node, getStaticType(expression));
9020 recordPropagatedType2(node, expression.propagatedType); 10268 recordPropagatedType2(node, expression.propagatedType);
9021 return null; 10269 return null;
9022 } 10270 }
9023 10271
9024 /** 10272 /**
9025 * The Dart Language Specification, 12.2: <blockquote>The static type of `null ` is bottom. 10273 * The Dart Language Specification, 12.2: <blockquote>The static type of `null ` is bottom.
9026 * </blockquote> 10274 * </blockquote>
9027 */ 10275 */
9028 Object visitNullLiteral(NullLiteral node) { 10276 Object visitNullLiteral(NullLiteral node) {
9029 recordStaticType(node, _typeProvider.bottomType); 10277 recordStaticType(node, _typeProvider.bottomType);
9030 return null; 10278 return null;
9031 } 10279 }
10280
9032 Object visitParenthesizedExpression(ParenthesizedExpression node) { 10281 Object visitParenthesizedExpression(ParenthesizedExpression node) {
9033 Expression expression = node.expression; 10282 Expression expression = node.expression;
9034 recordStaticType(node, getStaticType(expression)); 10283 recordStaticType(node, getStaticType(expression));
9035 recordPropagatedType2(node, expression.propagatedType); 10284 recordPropagatedType2(node, expression.propagatedType);
9036 return null; 10285 return null;
9037 } 10286 }
9038 10287
9039 /** 10288 /**
9040 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form 10289 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form
9041 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1; 10290 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
9079 10328
9080 /** 10329 /**
9081 * See [visitSimpleIdentifier]. 10330 * See [visitSimpleIdentifier].
9082 */ 10331 */
9083 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 10332 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
9084 SimpleIdentifier prefixedIdentifier = node.identifier; 10333 SimpleIdentifier prefixedIdentifier = node.identifier;
9085 Element staticElement = prefixedIdentifier.staticElement; 10334 Element staticElement = prefixedIdentifier.staticElement;
9086 Type2 staticType = _dynamicType; 10335 Type2 staticType = _dynamicType;
9087 if (staticElement is ClassElement) { 10336 if (staticElement is ClassElement) {
9088 if (isNotTypeLiteral(node)) { 10337 if (isNotTypeLiteral(node)) {
9089 staticType = ((staticElement as ClassElement)).type; 10338 staticType = (staticElement as ClassElement).type;
9090 } else { 10339 } else {
9091 staticType = _typeProvider.typeType; 10340 staticType = _typeProvider.typeType;
9092 } 10341 }
9093 } else if (staticElement is FunctionTypeAliasElement) { 10342 } else if (staticElement is FunctionTypeAliasElement) {
9094 if (isNotTypeLiteral(node)) { 10343 if (isNotTypeLiteral(node)) {
9095 staticType = ((staticElement as FunctionTypeAliasElement)).type; 10344 staticType = (staticElement as FunctionTypeAliasElement).type;
9096 } else { 10345 } else {
9097 staticType = _typeProvider.typeType; 10346 staticType = _typeProvider.typeType;
9098 } 10347 }
9099 } else if (staticElement is MethodElement) { 10348 } else if (staticElement is MethodElement) {
9100 staticType = ((staticElement as MethodElement)).type; 10349 staticType = (staticElement as MethodElement).type;
9101 } else if (staticElement is PropertyAccessorElement) { 10350 } else if (staticElement is PropertyAccessorElement) {
9102 staticType = getType(staticElement as PropertyAccessorElement, node.prefix .staticType); 10351 staticType = getType(staticElement as PropertyAccessorElement, node.prefix .staticType);
9103 } else if (staticElement is ExecutableElement) { 10352 } else if (staticElement is ExecutableElement) {
9104 staticType = ((staticElement as ExecutableElement)).type; 10353 staticType = (staticElement as ExecutableElement).type;
9105 } else if (staticElement is TypeParameterElement) { 10354 } else if (staticElement is TypeParameterElement) {
9106 staticType = ((staticElement as TypeParameterElement)).type; 10355 staticType = (staticElement as TypeParameterElement).type;
9107 } else if (staticElement is VariableElement) { 10356 } else if (staticElement is VariableElement) {
9108 staticType = ((staticElement as VariableElement)).type; 10357 staticType = (staticElement as VariableElement).type;
9109 } 10358 }
9110 recordStaticType(prefixedIdentifier, staticType); 10359 recordStaticType(prefixedIdentifier, staticType);
9111 recordStaticType(node, staticType); 10360 recordStaticType(node, staticType);
9112 Element propagatedElement = prefixedIdentifier.propagatedElement; 10361 Element propagatedElement = prefixedIdentifier.propagatedElement;
9113 Type2 propagatedType = null; 10362 Type2 propagatedType = null;
9114 if (propagatedElement is ClassElement) { 10363 if (propagatedElement is ClassElement) {
9115 if (isNotTypeLiteral(node)) { 10364 if (isNotTypeLiteral(node)) {
9116 propagatedType = ((propagatedElement as ClassElement)).type; 10365 propagatedType = (propagatedElement as ClassElement).type;
9117 } else { 10366 } else {
9118 propagatedType = _typeProvider.typeType; 10367 propagatedType = _typeProvider.typeType;
9119 } 10368 }
9120 } else if (propagatedElement is FunctionTypeAliasElement) { 10369 } else if (propagatedElement is FunctionTypeAliasElement) {
9121 propagatedType = ((propagatedElement as FunctionTypeAliasElement)).type; 10370 propagatedType = (propagatedElement as FunctionTypeAliasElement).type;
9122 } else if (propagatedElement is MethodElement) { 10371 } else if (propagatedElement is MethodElement) {
9123 propagatedType = ((propagatedElement as MethodElement)).type; 10372 propagatedType = (propagatedElement as MethodElement).type;
9124 } else if (propagatedElement is PropertyAccessorElement) { 10373 } else if (propagatedElement is PropertyAccessorElement) {
9125 propagatedType = getType(propagatedElement as PropertyAccessorElement, nod e.prefix.staticType); 10374 propagatedType = getType(propagatedElement as PropertyAccessorElement, nod e.prefix.staticType);
9126 } else if (propagatedElement is ExecutableElement) { 10375 } else if (propagatedElement is ExecutableElement) {
9127 propagatedType = ((propagatedElement as ExecutableElement)).type; 10376 propagatedType = (propagatedElement as ExecutableElement).type;
9128 } else if (propagatedElement is TypeParameterElement) { 10377 } else if (propagatedElement is TypeParameterElement) {
9129 propagatedType = ((propagatedElement as TypeParameterElement)).type; 10378 propagatedType = (propagatedElement as TypeParameterElement).type;
9130 } else if (propagatedElement is VariableElement) { 10379 } else if (propagatedElement is VariableElement) {
9131 propagatedType = ((propagatedElement as VariableElement)).type; 10380 propagatedType = (propagatedElement as VariableElement).type;
9132 } 10381 }
9133 Type2 overriddenType = _overrideManager.getType(propagatedElement); 10382 Type2 overriddenType = _overrideManager.getType(propagatedElement);
9134 if (propagatedType == null || (overriddenType != null && overriddenType.isMo reSpecificThan(propagatedType))) { 10383 if (propagatedType == null || (overriddenType != null && overriddenType.isMo reSpecificThan(propagatedType))) {
9135 propagatedType = overriddenType; 10384 propagatedType = overriddenType;
9136 } 10385 }
9137 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 10386 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
9138 recordPropagatedType2(prefixedIdentifier, propagatedType); 10387 recordPropagatedType2(prefixedIdentifier, propagatedType);
9139 recordPropagatedType2(node, propagatedType); 10388 recordPropagatedType2(node, propagatedType);
9140 } 10389 }
9141 return null; 10390 return null;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
9212 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an 10461 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an
9213 * identifier ... 10462 * identifier ...
9214 * 10463 *
9215 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote> 10464 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote>
9216 */ 10465 */
9217 Object visitPropertyAccess(PropertyAccess node) { 10466 Object visitPropertyAccess(PropertyAccess node) {
9218 SimpleIdentifier propertyName = node.propertyName; 10467 SimpleIdentifier propertyName = node.propertyName;
9219 Element element = propertyName.staticElement; 10468 Element element = propertyName.staticElement;
9220 Type2 staticType = _dynamicType; 10469 Type2 staticType = _dynamicType;
9221 if (element is MethodElement) { 10470 if (element is MethodElement) {
9222 staticType = ((element as MethodElement)).type; 10471 staticType = (element as MethodElement).type;
9223 } else if (element is PropertyAccessorElement) { 10472 } else if (element is PropertyAccessorElement) {
9224 staticType = getType(element as PropertyAccessorElement, node.target != nu ll ? getStaticType(node.target) : null); 10473 staticType = getType(element as PropertyAccessorElement, node.target != nu ll ? getStaticType(node.target) : null);
9225 } else { 10474 } else {
9226 } 10475 }
9227 recordStaticType(propertyName, staticType); 10476 recordStaticType(propertyName, staticType);
9228 recordStaticType(node, staticType); 10477 recordStaticType(node, staticType);
9229 Type2 propagatedType = _overrideManager.getType(element); 10478 Type2 propagatedType = _overrideManager.getType(element);
9230 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) { 10479 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType)) {
9231 recordPropagatedType2(node, propagatedType); 10480 recordPropagatedType2(node, propagatedType);
9232 } 10481 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
9282 * to be thrown. 10531 * to be thrown.
9283 * * Otherwise <i>e</i> is equivalent to the property extraction <i>this.id</i >. 10532 * * Otherwise <i>e</i> is equivalent to the property extraction <i>this.id</i >.
9284 * 10533 *
9285 * </blockquote> 10534 * </blockquote>
9286 */ 10535 */
9287 Object visitSimpleIdentifier(SimpleIdentifier node) { 10536 Object visitSimpleIdentifier(SimpleIdentifier node) {
9288 Element element = node.staticElement; 10537 Element element = node.staticElement;
9289 Type2 staticType = _dynamicType; 10538 Type2 staticType = _dynamicType;
9290 if (element is ClassElement) { 10539 if (element is ClassElement) {
9291 if (isNotTypeLiteral(node)) { 10540 if (isNotTypeLiteral(node)) {
9292 staticType = ((element as ClassElement)).type; 10541 staticType = (element as ClassElement).type;
9293 } else { 10542 } else {
9294 staticType = _typeProvider.typeType; 10543 staticType = _typeProvider.typeType;
9295 } 10544 }
9296 } else if (element is FunctionTypeAliasElement) { 10545 } else if (element is FunctionTypeAliasElement) {
9297 if (isNotTypeLiteral(node)) { 10546 if (isNotTypeLiteral(node)) {
9298 staticType = ((element as FunctionTypeAliasElement)).type; 10547 staticType = (element as FunctionTypeAliasElement).type;
9299 } else { 10548 } else {
9300 staticType = _typeProvider.typeType; 10549 staticType = _typeProvider.typeType;
9301 } 10550 }
9302 } else if (element is MethodElement) { 10551 } else if (element is MethodElement) {
9303 staticType = ((element as MethodElement)).type; 10552 staticType = (element as MethodElement).type;
9304 } else if (element is PropertyAccessorElement) { 10553 } else if (element is PropertyAccessorElement) {
9305 staticType = getType(element as PropertyAccessorElement, null); 10554 staticType = getType(element as PropertyAccessorElement, null);
9306 } else if (element is ExecutableElement) { 10555 } else if (element is ExecutableElement) {
9307 staticType = ((element as ExecutableElement)).type; 10556 staticType = (element as ExecutableElement).type;
9308 } else if (element is TypeParameterElement) { 10557 } else if (element is TypeParameterElement) {
9309 staticType = ((element as TypeParameterElement)).type; 10558 staticType = (element as TypeParameterElement).type;
9310 } else if (element is VariableElement) { 10559 } else if (element is VariableElement) {
9311 VariableElement variable = element as VariableElement; 10560 VariableElement variable = element as VariableElement;
9312 staticType = _promoteManager.getStaticType(variable); 10561 staticType = _promoteManager.getStaticType(variable);
9313 } else if (element is PrefixElement) { 10562 } else if (element is PrefixElement) {
9314 return null; 10563 return null;
9315 } else { 10564 } else {
9316 staticType = _dynamicType; 10565 staticType = _dynamicType;
9317 } 10566 }
9318 recordStaticType(node, staticType); 10567 recordStaticType(node, staticType);
9319 Type2 propagatedType = _overrideManager.getType(element); 10568 Type2 propagatedType = _overrideManager.getType(element);
(...skipping 13 matching lines...) Expand all
9333 } 10582 }
9334 10583
9335 /** 10584 /**
9336 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is 10585 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is
9337 * `String`.</blockquote> 10586 * `String`.</blockquote>
9338 */ 10587 */
9339 Object visitStringInterpolation(StringInterpolation node) { 10588 Object visitStringInterpolation(StringInterpolation node) {
9340 recordStaticType(node, _typeProvider.stringType); 10589 recordStaticType(node, _typeProvider.stringType);
9341 return null; 10590 return null;
9342 } 10591 }
10592
9343 Object visitSuperExpression(SuperExpression node) { 10593 Object visitSuperExpression(SuperExpression node) {
9344 if (_thisType == null) { 10594 if (_thisType == null) {
9345 recordStaticType(node, _dynamicType); 10595 recordStaticType(node, _dynamicType);
9346 } else { 10596 } else {
9347 recordStaticType(node, _thisType); 10597 recordStaticType(node, _thisType);
9348 } 10598 }
9349 return null; 10599 return null;
9350 } 10600 }
10601
9351 Object visitSymbolLiteral(SymbolLiteral node) { 10602 Object visitSymbolLiteral(SymbolLiteral node) {
9352 recordStaticType(node, _typeProvider.symbolType); 10603 recordStaticType(node, _typeProvider.symbolType);
9353 return null; 10604 return null;
9354 } 10605 }
9355 10606
9356 /** 10607 /**
9357 * The Dart Language Specification, 12.10: <blockquote>The static type of `thi s` is the 10608 * The Dart Language Specification, 12.10: <blockquote>The static type of `thi s` is the
9358 * interface of the immediately enclosing class.</blockquote> 10609 * interface of the immediately enclosing class.</blockquote>
9359 */ 10610 */
9360 Object visitThisExpression(ThisExpression node) { 10611 Object visitThisExpression(ThisExpression node) {
9361 if (_thisType == null) { 10612 if (_thisType == null) {
9362 recordStaticType(node, _dynamicType); 10613 recordStaticType(node, _dynamicType);
9363 } else { 10614 } else {
9364 recordStaticType(node, _thisType); 10615 recordStaticType(node, _thisType);
9365 } 10616 }
9366 return null; 10617 return null;
9367 } 10618 }
9368 10619
9369 /** 10620 /**
9370 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr ow expression is 10621 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr ow expression is
9371 * bottom.</blockquote> 10622 * bottom.</blockquote>
9372 */ 10623 */
9373 Object visitThrowExpression(ThrowExpression node) { 10624 Object visitThrowExpression(ThrowExpression node) {
9374 recordStaticType(node, _typeProvider.bottomType); 10625 recordStaticType(node, _typeProvider.bottomType);
9375 return null; 10626 return null;
9376 } 10627 }
10628
9377 Object visitVariableDeclaration(VariableDeclaration node) { 10629 Object visitVariableDeclaration(VariableDeclaration node) {
9378 Expression initializer = node.initializer; 10630 Expression initializer = node.initializer;
9379 if (initializer != null) { 10631 if (initializer != null) {
9380 Type2 rightType = initializer.bestType; 10632 Type2 rightType = initializer.bestType;
9381 SimpleIdentifier name = node.name; 10633 SimpleIdentifier name = node.name;
9382 recordPropagatedType2(name, rightType); 10634 recordPropagatedType2(name, rightType);
9383 VariableElement element = name.staticElement as VariableElement; 10635 VariableElement element = name.staticElement as VariableElement;
9384 if (element != null) { 10636 if (element != null) {
9385 _resolver.override2(element, rightType); 10637 _resolver.override2(element, rightType);
9386 } 10638 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
9425 * @param body the boy of the function whose propagated return type is to be c omputed 10677 * @param body the boy of the function whose propagated return type is to be c omputed
9426 * @return the propagated return type that was computed 10678 * @return the propagated return type that was computed
9427 */ 10679 */
9428 Type2 computePropagatedReturnType2(FunctionBody body) { 10680 Type2 computePropagatedReturnType2(FunctionBody body) {
9429 if (body is ExpressionFunctionBody) { 10681 if (body is ExpressionFunctionBody) {
9430 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody; 10682 ExpressionFunctionBody expressionBody = body as ExpressionFunctionBody;
9431 return expressionBody.expression.bestType; 10683 return expressionBody.expression.bestType;
9432 } 10684 }
9433 if (body is BlockFunctionBody) { 10685 if (body is BlockFunctionBody) {
9434 List<Type2> result = [null]; 10686 List<Type2> result = [null];
9435 body.accept(new GeneralizingASTVisitor_9(result)); 10687 body.accept(new GeneralizingASTVisitor_10(result));
9436 return result[0]; 10688 return result[0];
9437 } 10689 }
9438 return null; 10690 return null;
9439 } 10691 }
9440 10692
9441 /** 10693 /**
9442 * Compute the static return type of the method or function represented by the given element. 10694 * Compute the static return type of the method or function represented by the given element.
9443 * 10695 *
9444 * @param element the element representing the method or function invoked by t he given node 10696 * @param element the element representing the method or function invoked by t he given node
9445 * @return the static return type that was computed 10697 * @return the static return type that was computed
9446 */ 10698 */
9447 Type2 computeStaticReturnType(Element element) { 10699 Type2 computeStaticReturnType(Element element) {
9448 if (element is PropertyAccessorElement) { 10700 if (element is PropertyAccessorElement) {
9449 FunctionType propertyType = ((element as PropertyAccessorElement)).type; 10701 FunctionType propertyType = (element as PropertyAccessorElement).type;
9450 if (propertyType != null) { 10702 if (propertyType != null) {
9451 Type2 returnType = propertyType.returnType; 10703 Type2 returnType = propertyType.returnType;
9452 if (returnType.isDartCoreFunction) { 10704 if (returnType.isDartCoreFunction) {
9453 return _dynamicType; 10705 return _dynamicType;
9454 } else if (returnType is InterfaceType) { 10706 } else if (returnType is InterfaceType) {
9455 MethodElement callMethod = ((returnType as InterfaceType)).lookUpMetho d(ElementResolver.CALL_METHOD_NAME, _resolver.definingLibrary); 10707 MethodElement callMethod = (returnType as InterfaceType).lookUpMethod( ElementResolver.CALL_METHOD_NAME, _resolver.definingLibrary);
9456 if (callMethod != null) { 10708 if (callMethod != null) {
9457 return callMethod.type.returnType; 10709 return callMethod.type.returnType;
9458 } 10710 }
9459 } else if (returnType is FunctionType) { 10711 } else if (returnType is FunctionType) {
9460 Type2 innerReturnType = ((returnType as FunctionType)).returnType; 10712 Type2 innerReturnType = (returnType as FunctionType).returnType;
9461 if (innerReturnType != null) { 10713 if (innerReturnType != null) {
9462 return innerReturnType; 10714 return innerReturnType;
9463 } 10715 }
9464 } 10716 }
9465 if (returnType != null) { 10717 if (returnType != null) {
9466 return returnType; 10718 return returnType;
9467 } 10719 }
9468 } 10720 }
9469 } else if (element is ExecutableElement) { 10721 } else if (element is ExecutableElement) {
9470 FunctionType type = ((element as ExecutableElement)).type; 10722 FunctionType type = (element as ExecutableElement).type;
9471 if (type != null) { 10723 if (type != null) {
9472 return type.returnType; 10724 return type.returnType;
9473 } 10725 }
9474 } else if (element is VariableElement) { 10726 } else if (element is VariableElement) {
9475 VariableElement variable = element as VariableElement; 10727 VariableElement variable = element as VariableElement;
9476 Type2 variableType = _promoteManager.getStaticType(variable); 10728 Type2 variableType = _promoteManager.getStaticType(variable);
9477 if (variableType is FunctionType) { 10729 if (variableType is FunctionType) {
9478 return ((variableType as FunctionType)).returnType; 10730 return (variableType as FunctionType).returnType;
9479 } 10731 }
9480 } 10732 }
9481 return _dynamicType; 10733 return _dynamicType;
9482 } 10734 }
9483 10735
9484 /** 10736 /**
9485 * Given a function declaration, compute the return static type of the functio n. The return type 10737 * Given a function declaration, compute the return static type of the functio n. The return type
9486 * of functions with a block body is `dynamicType`, with an expression body it is the type 10738 * of functions with a block body is `dynamicType`, with an expression body it is the type
9487 * of the expression. 10739 * of the expression.
9488 * 10740 *
(...skipping 12 matching lines...) Expand all
9501 * Given a function expression, compute the return type of the function. The r eturn type of 10753 * Given a function expression, compute the return type of the function. The r eturn type of
9502 * functions with a block body is `dynamicType`, with an expression body it is the type of 10754 * functions with a block body is `dynamicType`, with an expression body it is the type of
9503 * the expression. 10755 * the expression.
9504 * 10756 *
9505 * @param node the function expression whose return type is to be computed 10757 * @param node the function expression whose return type is to be computed
9506 * @return the return type that was computed 10758 * @return the return type that was computed
9507 */ 10759 */
9508 Type2 computeStaticReturnType3(FunctionExpression node) { 10760 Type2 computeStaticReturnType3(FunctionExpression node) {
9509 FunctionBody body = node.body; 10761 FunctionBody body = node.body;
9510 if (body is ExpressionFunctionBody) { 10762 if (body is ExpressionFunctionBody) {
9511 return getStaticType(((body as ExpressionFunctionBody)).expression); 10763 return getStaticType((body as ExpressionFunctionBody).expression);
9512 } 10764 }
9513 return _dynamicType; 10765 return _dynamicType;
9514 } 10766 }
9515 10767
9516 /** 10768 /**
9517 * If the given element name can be mapped to the name of a class defined with in the given 10769 * If the given element name can be mapped to the name of a class defined with in the given
9518 * library, return the type specified by the argument. 10770 * library, return the type specified by the argument.
9519 * 10771 *
9520 * @param library the library in which the specified type would be defined 10772 * @param library the library in which the specified type would be defined
9521 * @param elementName the name of the element for which a type is being sought 10773 * @param elementName the name of the element for which a type is being sought
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
9569 * string literal, return the String value of the argument. 10821 * string literal, return the String value of the argument.
9570 * 10822 *
9571 * @param argumentList the list of arguments from which a string value is to b e extracted 10823 * @param argumentList the list of arguments from which a string value is to b e extracted
9572 * @return the string specified by the first argument in the argument list 10824 * @return the string specified by the first argument in the argument list
9573 */ 10825 */
9574 String getFirstArgumentAsString(ArgumentList argumentList) { 10826 String getFirstArgumentAsString(ArgumentList argumentList) {
9575 NodeList<Expression> arguments = argumentList.arguments; 10827 NodeList<Expression> arguments = argumentList.arguments;
9576 if (arguments.length > 0) { 10828 if (arguments.length > 0) {
9577 Expression argument = arguments[0]; 10829 Expression argument = arguments[0];
9578 if (argument is SimpleStringLiteral) { 10830 if (argument is SimpleStringLiteral) {
9579 return ((argument as SimpleStringLiteral)).value; 10831 return (argument as SimpleStringLiteral).value;
9580 } 10832 }
9581 } 10833 }
9582 return null; 10834 return null;
9583 } 10835 }
9584 10836
9585 /** 10837 /**
9586 * If the given argument list contains at least one argument, and if the argum ent is a simple 10838 * If the given argument list contains at least one argument, and if the argum ent is a simple
9587 * string literal, and if the value of the argument is the name of a class def ined within the 10839 * string literal, and if the value of the argument is the name of a class def ined within the
9588 * given library, return the type specified by the argument. 10840 * given library, return the type specified by the argument.
9589 * 10841 *
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
9701 bool isHtmlLibrary(LibraryElement library) => library != null && "dart.dom.htm l" == library.name; 10953 bool isHtmlLibrary(LibraryElement library) => library != null && "dart.dom.htm l" == library.name;
9702 10954
9703 /** 10955 /**
9704 * Return `true` if the given node is not a type literal. 10956 * Return `true` if the given node is not a type literal.
9705 * 10957 *
9706 * @param node the node being tested 10958 * @param node the node being tested
9707 * @return `true` if the given node is not a type literal 10959 * @return `true` if the given node is not a type literal
9708 */ 10960 */
9709 bool isNotTypeLiteral(Identifier node) { 10961 bool isNotTypeLiteral(Identifier node) {
9710 ASTNode parent = node.parent; 10962 ASTNode parent = node.parent;
9711 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent is TypeName || identical(((parent as PrefixedIdentifier)).prefix, node))) || (p arent is PropertyAccess && identical(((parent as PropertyAccess)).target, node)) || (parent is MethodInvocation && identical(node, ((parent as MethodInvocation) ).target)); 10963 return parent is TypeName || (parent is PrefixedIdentifier && (parent.parent is TypeName || identical((parent as PrefixedIdentifier).prefix, node))) || (par ent is PropertyAccess && identical((parent as PropertyAccess).target, node)) || (parent is MethodInvocation && identical(node, (parent as MethodInvocation).targ et));
9712 } 10964 }
9713 10965
9714 /** 10966 /**
9715 * Given a function element and its body, compute and record the propagated re turn type of the 10967 * Given a function element and its body, compute and record the propagated re turn type of the
9716 * function. 10968 * function.
9717 * 10969 *
9718 * @param functionElement the function element to record propagated return typ e for 10970 * @param functionElement the function element to record propagated return typ e for
9719 * @param body the boy of the function whose propagated return type is to be c omputed 10971 * @param body the boy of the function whose propagated return type is to be c omputed
9720 * @return the propagated return type that was computed, may be `null` if it i s not more 10972 * @return the propagated return type that was computed, may be `null` if it i s not more
9721 * specific than the static return type. 10973 * specific than the static return type.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
9782 } 11034 }
9783 } 11035 }
9784 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.Toke nType.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) { 11036 if (identical(operator, sc.TokenType.MINUS) || identical(operator, sc.Toke nType.PERCENT) || identical(operator, sc.TokenType.PLUS) || identical(operator, sc.TokenType.STAR) || identical(operator, sc.TokenType.TILDE_SLASH)) {
9785 if (getStaticType(node.rightOperand) == intType) { 11037 if (getStaticType(node.rightOperand) == intType) {
9786 staticType = intType; 11038 staticType = intType;
9787 } 11039 }
9788 } 11040 }
9789 } 11041 }
9790 return staticType; 11042 return staticType;
9791 } 11043 }
11044
9792 get thisType_J2DAccessor => _thisType; 11045 get thisType_J2DAccessor => _thisType;
11046
9793 set thisType_J2DAccessor(__v) => _thisType = __v; 11047 set thisType_J2DAccessor(__v) => _thisType = __v;
9794 } 11048 }
9795 class GeneralizingASTVisitor_9 extends GeneralizingASTVisitor<Object> { 11049
11050 class GeneralizingASTVisitor_10 extends GeneralizingASTVisitor<Object> {
9796 List<Type2> result; 11051 List<Type2> result;
9797 GeneralizingASTVisitor_9(this.result) : super(); 11052
11053 GeneralizingASTVisitor_10(this.result) : super();
11054
9798 Object visitExpression(Expression node) => null; 11055 Object visitExpression(Expression node) => null;
11056
9799 Object visitReturnStatement(ReturnStatement node) { 11057 Object visitReturnStatement(ReturnStatement node) {
9800 Type2 type; 11058 Type2 type;
9801 Expression expression = node.expression; 11059 Expression expression = node.expression;
9802 if (expression != null) { 11060 if (expression != null) {
9803 type = expression.bestType; 11061 type = expression.bestType;
9804 } else { 11062 } else {
9805 type = BottomTypeImpl.instance; 11063 type = BottomTypeImpl.instance;
9806 } 11064 }
9807 if (result[0] == null) { 11065 if (result[0] == null) {
9808 result[0] = type; 11066 result[0] = type;
9809 } else { 11067 } else {
9810 result[0] = result[0].getLeastUpperBound(type); 11068 result[0] = result[0].getLeastUpperBound(type);
9811 } 11069 }
9812 return null; 11070 return null;
9813 } 11071 }
9814 } 11072 }
11073
9815 /** 11074 /**
9816 * Instances of this class manage the knowledge of what the set of subtypes are for a given type. 11075 * Instances of this class manage the knowledge of what the set of subtypes are for a given type.
9817 */ 11076 */
9818 class SubtypeManager { 11077 class SubtypeManager {
9819
9820 /** 11078 /**
9821 * A map between [ClassElement]s and a set of [ClassElement]s that are subtype s of the 11079 * A map between [ClassElement]s and a set of [ClassElement]s that are subtype s of the
9822 * key. 11080 * key.
9823 */ 11081 */
9824 Map<ClassElement, Set<ClassElement>> _subtypeMap = new Map<ClassElement, Set<C lassElement>>(); 11082 Map<ClassElement, Set<ClassElement>> _subtypeMap = new Map<ClassElement, Set<C lassElement>>();
9825 11083
9826 /** 11084 /**
9827 * The set of all [LibraryElement]s that have been visited by the manager. Thi s is used both 11085 * The set of all [LibraryElement]s that have been visited by the manager. Thi s is used both
9828 * to prevent infinite loops in the recursive methods, and also as a marker fo r the scope of the 11086 * to prevent infinite loops in the recursive methods, and also as a marker fo r the scope of the
9829 * libraries visited by this manager. 11087 * libraries visited by this manager.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
9954 */ 11212 */
9955 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) { 11213 void putInSubtypeMap(ClassElement supertypeElement, ClassElement subtypeElemen t) {
9956 Set<ClassElement> subtypes = _subtypeMap[supertypeElement]; 11214 Set<ClassElement> subtypes = _subtypeMap[supertypeElement];
9957 if (subtypes == null) { 11215 if (subtypes == null) {
9958 subtypes = new Set<ClassElement>(); 11216 subtypes = new Set<ClassElement>();
9959 _subtypeMap[supertypeElement] = subtypes; 11217 _subtypeMap[supertypeElement] = subtypes;
9960 } 11218 }
9961 javaSetAdd(subtypes, subtypeElement); 11219 javaSetAdd(subtypes, subtypeElement);
9962 } 11220 }
9963 } 11221 }
11222
9964 /** 11223 /**
9965 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an 11224 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an
9966 * element within a given context. 11225 * element within a given context.
9967 */ 11226 */
9968 class TypeOverrideManager { 11227 class TypeOverrideManager {
9969
9970 /** 11228 /**
9971 * The current override scope, or `null` if no scope has been entered. 11229 * The current override scope, or `null` if no scope has been entered.
9972 */ 11230 */
9973 TypeOverrideManager_TypeOverrideScope _currentScope; 11231 TypeOverrideManager_TypeOverrideScope _currentScope;
9974 11232
9975 /** 11233 /**
9976 * Apply a set of overrides that were previously captured. 11234 * Apply a set of overrides that were previously captured.
9977 * 11235 *
9978 * @param overrides the overrides to be applied 11236 * @param overrides the overrides to be applied
9979 */ 11237 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
10048 * @param element the element whose type might have been overridden 11306 * @param element the element whose type might have been overridden
10049 * @param type the overridden type of the given element 11307 * @param type the overridden type of the given element
10050 */ 11308 */
10051 void setType(Element element, Type2 type) { 11309 void setType(Element element, Type2 type) {
10052 if (_currentScope == null) { 11310 if (_currentScope == null) {
10053 throw new IllegalStateException("Cannot override without a scope"); 11311 throw new IllegalStateException("Cannot override without a scope");
10054 } 11312 }
10055 _currentScope.setType(element, type); 11313 _currentScope.setType(element, type);
10056 } 11314 }
10057 } 11315 }
11316
10058 /** 11317 /**
10059 * Instances of the class `TypeOverrideScope` represent a scope in which the typ es of 11318 * Instances of the class `TypeOverrideScope` represent a scope in which the typ es of
10060 * elements can be overridden. 11319 * elements can be overridden.
10061 */ 11320 */
10062 class TypeOverrideManager_TypeOverrideScope { 11321 class TypeOverrideManager_TypeOverrideScope {
10063
10064 /** 11322 /**
10065 * The outer scope in which types might be overridden. 11323 * The outer scope in which types might be overridden.
10066 */ 11324 */
10067 TypeOverrideManager_TypeOverrideScope _outerScope; 11325 TypeOverrideManager_TypeOverrideScope _outerScope;
10068 11326
10069 /** 11327 /**
10070 * A table mapping elements to the overridden type of that element. 11328 * A table mapping elements to the overridden type of that element.
10071 */ 11329 */
10072 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>(); 11330 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>();
10073 11331
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
10125 /** 11383 /**
10126 * Return the overridden type of the given element, or `null` if the type of t he element 11384 * Return the overridden type of the given element, or `null` if the type of t he element
10127 * has not been overridden. 11385 * has not been overridden.
10128 * 11386 *
10129 * @param element the element whose type might have been overridden 11387 * @param element the element whose type might have been overridden
10130 * @return the overridden type of the given element 11388 * @return the overridden type of the given element
10131 */ 11389 */
10132 Type2 getType(Element element) { 11390 Type2 getType(Element element) {
10133 Type2 type = _overridenTypes[element]; 11391 Type2 type = _overridenTypes[element];
10134 if (type == null && element is PropertyAccessorElement) { 11392 if (type == null && element is PropertyAccessorElement) {
10135 type = _overridenTypes[((element as PropertyAccessorElement)).variable]; 11393 type = _overridenTypes[(element as PropertyAccessorElement).variable];
10136 } 11394 }
10137 if (type != null) { 11395 if (type != null) {
10138 return type; 11396 return type;
10139 } else if (_outerScope != null) { 11397 } else if (_outerScope != null) {
10140 return _outerScope.getType(element); 11398 return _outerScope.getType(element);
10141 } 11399 }
10142 return null; 11400 return null;
10143 } 11401 }
10144 11402
10145 /** 11403 /**
10146 * Set the overridden type of the given element to the given type 11404 * Set the overridden type of the given element to the given type
10147 * 11405 *
10148 * @param element the element whose type might have been overridden 11406 * @param element the element whose type might have been overridden
10149 * @param type the overridden type of the given element 11407 * @param type the overridden type of the given element
10150 */ 11408 */
10151 void setType(Element element, Type2 type) { 11409 void setType(Element element, Type2 type) {
10152 _overridenTypes[element] = type; 11410 _overridenTypes[element] = type;
10153 } 11411 }
10154 } 11412 }
11413
10155 /** 11414 /**
10156 * Instances of the class `TypePromotionManager` manage the ability to promote t ypes of local 11415 * Instances of the class `TypePromotionManager` manage the ability to promote t ypes of local
10157 * variables and formal parameters from their declared types based on control fl ow. 11416 * variables and formal parameters from their declared types based on control fl ow.
10158 */ 11417 */
10159 class TypePromotionManager { 11418 class TypePromotionManager {
10160
10161 /** 11419 /**
10162 * The current promotion scope, or `null` if no scope has been entered. 11420 * The current promotion scope, or `null` if no scope has been entered.
10163 */ 11421 */
10164 TypePromotionManager_TypePromoteScope _currentScope; 11422 TypePromotionManager_TypePromoteScope _currentScope;
10165 11423
10166 /** 11424 /**
10167 * Enter a new promotions scope. 11425 * Enter a new promotions scope.
10168 */ 11426 */
10169 void enterScope() { 11427 void enterScope() {
10170 _currentScope = new TypePromotionManager_TypePromoteScope(_currentScope); 11428 _currentScope = new TypePromotionManager_TypePromoteScope(_currentScope);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
10218 * @param element the element whose type might have been promoted 11476 * @param element the element whose type might have been promoted
10219 * @param type the promoted type of the given element 11477 * @param type the promoted type of the given element
10220 */ 11478 */
10221 void setType(Element element, Type2 type) { 11479 void setType(Element element, Type2 type) {
10222 if (_currentScope == null) { 11480 if (_currentScope == null) {
10223 throw new IllegalStateException("Cannot promote without a scope"); 11481 throw new IllegalStateException("Cannot promote without a scope");
10224 } 11482 }
10225 _currentScope.setType(element, type); 11483 _currentScope.setType(element, type);
10226 } 11484 }
10227 } 11485 }
11486
10228 /** 11487 /**
10229 * Instances of the class `TypePromoteScope` represent a scope in which the type s of 11488 * Instances of the class `TypePromoteScope` represent a scope in which the type s of
10230 * elements can be promoted. 11489 * elements can be promoted.
10231 */ 11490 */
10232 class TypePromotionManager_TypePromoteScope { 11491 class TypePromotionManager_TypePromoteScope {
10233
10234 /** 11492 /**
10235 * The outer scope in which types might be promoter. 11493 * The outer scope in which types might be promoter.
10236 */ 11494 */
10237 TypePromotionManager_TypePromoteScope _outerScope; 11495 TypePromotionManager_TypePromoteScope _outerScope;
10238 11496
10239 /** 11497 /**
10240 * A table mapping elements to the promoted type of that element. 11498 * A table mapping elements to the promoted type of that element.
10241 */ 11499 */
10242 Map<Element, Type2> _promotedTypes = new Map<Element, Type2>(); 11500 Map<Element, Type2> _promotedTypes = new Map<Element, Type2>();
10243 11501
(...skipping 14 matching lines...) Expand all
10258 /** 11516 /**
10259 * Return the promoted type of the given element, or `null` if the type of the element has 11517 * Return the promoted type of the given element, or `null` if the type of the element has
10260 * not been promoted. 11518 * not been promoted.
10261 * 11519 *
10262 * @param element the element whose type might have been promoted 11520 * @param element the element whose type might have been promoted
10263 * @return the promoted type of the given element 11521 * @return the promoted type of the given element
10264 */ 11522 */
10265 Type2 getType(Element element) { 11523 Type2 getType(Element element) {
10266 Type2 type = _promotedTypes[element]; 11524 Type2 type = _promotedTypes[element];
10267 if (type == null && element is PropertyAccessorElement) { 11525 if (type == null && element is PropertyAccessorElement) {
10268 type = _promotedTypes[((element as PropertyAccessorElement)).variable]; 11526 type = _promotedTypes[(element as PropertyAccessorElement).variable];
10269 } 11527 }
10270 if (type != null) { 11528 if (type != null) {
10271 return type; 11529 return type;
10272 } else if (_outerScope != null) { 11530 } else if (_outerScope != null) {
10273 return _outerScope.getType(element); 11531 return _outerScope.getType(element);
10274 } 11532 }
10275 return null; 11533 return null;
10276 } 11534 }
10277 11535
10278 /** 11536 /**
10279 * Set the promoted type of the given element to the given type. 11537 * Set the promoted type of the given element to the given type.
10280 * 11538 *
10281 * @param element the element whose type might have been promoted 11539 * @param element the element whose type might have been promoted
10282 * @param type the promoted type of the given element 11540 * @param type the promoted type of the given element
10283 */ 11541 */
10284 void setType(Element element, Type2 type) { 11542 void setType(Element element, Type2 type) {
10285 _promotedTypes[element] = type; 11543 _promotedTypes[element] = type;
10286 } 11544 }
10287 } 11545 }
11546
10288 /** 11547 /**
10289 * The interface `TypeProvider` defines the behavior of objects that provide acc ess to types 11548 * The interface `TypeProvider` defines the behavior of objects that provide acc ess to types
10290 * defined by the language. 11549 * defined by the language.
10291 * 11550 *
10292 * @coverage dart.engine.resolver 11551 * @coverage dart.engine.resolver
10293 */ 11552 */
10294 abstract class TypeProvider { 11553 abstract class TypeProvider {
10295
10296 /**
10297 * Return the type representing the built-in type 'Null'.
10298 *
10299 * @return the type representing the built-in type 'null'
10300 */
10301 InterfaceType get nullType;
10302
10303 /** 11554 /**
10304 * Return the type representing the built-in type 'bool'. 11555 * Return the type representing the built-in type 'bool'.
10305 * 11556 *
10306 * @return the type representing the built-in type 'bool' 11557 * @return the type representing the built-in type 'bool'
10307 */ 11558 */
10308 InterfaceType get boolType; 11559 InterfaceType get boolType;
10309 11560
10310 /** 11561 /**
10311 * Return the type representing the type 'bottom'. 11562 * Return the type representing the type 'bottom'.
10312 * 11563 *
10313 * @return the type representing the type 'bottom' 11564 * @return the type representing the type 'bottom'
10314 */ 11565 */
10315 Type2 get bottomType; 11566 Type2 get bottomType;
10316 11567
10317 /** 11568 /**
11569 * Return the type representing the built-in type 'Deprecated'.
11570 *
11571 * @return the type representing the built-in type 'Deprecated'
11572 */
11573 InterfaceType get deprecatedType;
11574
11575 /**
10318 * Return the type representing the built-in type 'double'. 11576 * Return the type representing the built-in type 'double'.
10319 * 11577 *
10320 * @return the type representing the built-in type 'double' 11578 * @return the type representing the built-in type 'double'
10321 */ 11579 */
10322 InterfaceType get doubleType; 11580 InterfaceType get doubleType;
10323 11581
10324 /** 11582 /**
10325 * Return the type representing the built-in type 'dynamic'. 11583 * Return the type representing the built-in type 'dynamic'.
10326 * 11584 *
10327 * @return the type representing the built-in type 'dynamic' 11585 * @return the type representing the built-in type 'dynamic'
(...skipping 22 matching lines...) Expand all
10350 InterfaceType get listType; 11608 InterfaceType get listType;
10351 11609
10352 /** 11610 /**
10353 * Return the type representing the built-in type 'Map'. 11611 * Return the type representing the built-in type 'Map'.
10354 * 11612 *
10355 * @return the type representing the built-in type 'Map' 11613 * @return the type representing the built-in type 'Map'
10356 */ 11614 */
10357 InterfaceType get mapType; 11615 InterfaceType get mapType;
10358 11616
10359 /** 11617 /**
11618 * Return the type representing the built-in type 'Null'.
11619 *
11620 * @return the type representing the built-in type 'null'
11621 */
11622 InterfaceType get nullType;
11623
11624 /**
10360 * Return the type representing the built-in type 'num'. 11625 * Return the type representing the built-in type 'num'.
10361 * 11626 *
10362 * @return the type representing the built-in type 'num' 11627 * @return the type representing the built-in type 'num'
10363 */ 11628 */
10364 InterfaceType get numType; 11629 InterfaceType get numType;
10365 11630
10366 /** 11631 /**
10367 * Return the type representing the built-in type 'Object'. 11632 * Return the type representing the built-in type 'Object'.
10368 * 11633 *
10369 * @return the type representing the built-in type 'Object' 11634 * @return the type representing the built-in type 'Object'
(...skipping 21 matching lines...) Expand all
10391 */ 11656 */
10392 InterfaceType get symbolType; 11657 InterfaceType get symbolType;
10393 11658
10394 /** 11659 /**
10395 * Return the type representing the built-in type 'Type'. 11660 * Return the type representing the built-in type 'Type'.
10396 * 11661 *
10397 * @return the type representing the built-in type 'Type' 11662 * @return the type representing the built-in type 'Type'
10398 */ 11663 */
10399 InterfaceType get typeType; 11664 InterfaceType get typeType;
10400 } 11665 }
11666
10401 /** 11667 /**
10402 * Instances of the class `TypeProviderImpl` provide access to types defined by the language 11668 * Instances of the class `TypeProviderImpl` provide access to types defined by the language
10403 * by looking for those types in the element model for the core library. 11669 * by looking for those types in the element model for the core library.
10404 * 11670 *
10405 * @coverage dart.engine.resolver 11671 * @coverage dart.engine.resolver
10406 */ 11672 */
10407 class TypeProviderImpl implements TypeProvider { 11673 class TypeProviderImpl implements TypeProvider {
10408
10409 /** 11674 /**
10410 * The type representing the built-in type 'bool'. 11675 * The type representing the built-in type 'bool'.
10411 */ 11676 */
10412 InterfaceType _boolType; 11677 InterfaceType _boolType;
10413 11678
10414 /** 11679 /**
10415 * The type representing the type 'bottom'. 11680 * The type representing the type 'bottom'.
10416 */ 11681 */
10417 Type2 _bottomType; 11682 Type2 _bottomType;
10418 11683
10419 /** 11684 /**
10420 * The type representing the built-in type 'double'. 11685 * The type representing the built-in type 'double'.
10421 */ 11686 */
10422 InterfaceType _doubleType; 11687 InterfaceType _doubleType;
10423 11688
10424 /** 11689 /**
11690 * The type representing the built-in type 'Deprecated'.
11691 */
11692 InterfaceType _deprecatedType;
11693
11694 /**
10425 * The type representing the built-in type 'dynamic'. 11695 * The type representing the built-in type 'dynamic'.
10426 */ 11696 */
10427 Type2 _dynamicType; 11697 Type2 _dynamicType;
10428 11698
10429 /** 11699 /**
10430 * The type representing the built-in type 'Function'. 11700 * The type representing the built-in type 'Function'.
10431 */ 11701 */
10432 InterfaceType _functionType; 11702 InterfaceType _functionType;
10433 11703
10434 /** 11704 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
10482 InterfaceType _typeType; 11752 InterfaceType _typeType;
10483 11753
10484 /** 11754 /**
10485 * Initialize a newly created type provider to provide the types defined in th e given library. 11755 * Initialize a newly created type provider to provide the types defined in th e given library.
10486 * 11756 *
10487 * @param coreLibrary the element representing the core library (dart:core). 11757 * @param coreLibrary the element representing the core library (dart:core).
10488 */ 11758 */
10489 TypeProviderImpl(LibraryElement coreLibrary) { 11759 TypeProviderImpl(LibraryElement coreLibrary) {
10490 initializeFrom(coreLibrary); 11760 initializeFrom(coreLibrary);
10491 } 11761 }
11762
10492 InterfaceType get boolType => _boolType; 11763 InterfaceType get boolType => _boolType;
11764
10493 Type2 get bottomType => _bottomType; 11765 Type2 get bottomType => _bottomType;
11766
11767 InterfaceType get deprecatedType => _deprecatedType;
11768
10494 InterfaceType get doubleType => _doubleType; 11769 InterfaceType get doubleType => _doubleType;
11770
10495 Type2 get dynamicType => _dynamicType; 11771 Type2 get dynamicType => _dynamicType;
11772
10496 InterfaceType get functionType => _functionType; 11773 InterfaceType get functionType => _functionType;
11774
10497 InterfaceType get intType => _intType; 11775 InterfaceType get intType => _intType;
11776
10498 InterfaceType get listType => _listType; 11777 InterfaceType get listType => _listType;
11778
10499 InterfaceType get mapType => _mapType; 11779 InterfaceType get mapType => _mapType;
11780
10500 InterfaceType get nullType => _nullType; 11781 InterfaceType get nullType => _nullType;
11782
10501 InterfaceType get numType => _numType; 11783 InterfaceType get numType => _numType;
11784
10502 InterfaceType get objectType => _objectType; 11785 InterfaceType get objectType => _objectType;
11786
10503 InterfaceType get stackTraceType => _stackTraceType; 11787 InterfaceType get stackTraceType => _stackTraceType;
11788
10504 InterfaceType get stringType => _stringType; 11789 InterfaceType get stringType => _stringType;
11790
10505 InterfaceType get symbolType => _symbolType; 11791 InterfaceType get symbolType => _symbolType;
11792
10506 InterfaceType get typeType => _typeType; 11793 InterfaceType get typeType => _typeType;
10507 11794
10508 /** 11795 /**
10509 * Return the type with the given name from the given namespace, or `null` if there is no 11796 * Return the type with the given name from the given namespace, or `null` if there is no
10510 * class with the given name. 11797 * class with the given name.
10511 * 11798 *
10512 * @param namespace the namespace in which to search for the given name 11799 * @param namespace the namespace in which to search for the given name
10513 * @param typeName the name of the type being searched for 11800 * @param typeName the name of the type being searched for
10514 * @return the type that was found 11801 * @return the type that was found
10515 */ 11802 */
10516 InterfaceType getType(Namespace namespace, String typeName) { 11803 InterfaceType getType(Namespace namespace, String typeName) {
10517 Element element = namespace.get(typeName); 11804 Element element = namespace.get(typeName);
10518 if (element == null) { 11805 if (element == null) {
10519 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ eName}"); 11806 AnalysisEngine.instance.logger.logInformation("No definition of type ${typ eName}");
10520 return null; 11807 return null;
10521 } 11808 }
10522 return ((element as ClassElement)).type; 11809 return (element as ClassElement).type;
10523 } 11810 }
10524 11811
10525 /** 11812 /**
10526 * Initialize the types provided by this type provider from the given library. 11813 * Initialize the types provided by this type provider from the given library.
10527 * 11814 *
10528 * @param library the library containing the definitions of the core types 11815 * @param library the library containing the definitions of the core types
10529 */ 11816 */
10530 void initializeFrom(LibraryElement library) { 11817 void initializeFrom(LibraryElement library) {
10531 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); 11818 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library);
10532 _boolType = getType(namespace, "bool"); 11819 _boolType = getType(namespace, "bool");
10533 _bottomType = BottomTypeImpl.instance; 11820 _bottomType = BottomTypeImpl.instance;
11821 _deprecatedType = getType(namespace, "Deprecated");
10534 _doubleType = getType(namespace, "double"); 11822 _doubleType = getType(namespace, "double");
10535 _dynamicType = DynamicTypeImpl.instance; 11823 _dynamicType = DynamicTypeImpl.instance;
10536 _functionType = getType(namespace, "Function"); 11824 _functionType = getType(namespace, "Function");
10537 _intType = getType(namespace, "int"); 11825 _intType = getType(namespace, "int");
10538 _listType = getType(namespace, "List"); 11826 _listType = getType(namespace, "List");
10539 _mapType = getType(namespace, "Map"); 11827 _mapType = getType(namespace, "Map");
10540 _nullType = getType(namespace, "Null"); 11828 _nullType = getType(namespace, "Null");
10541 _numType = getType(namespace, "num"); 11829 _numType = getType(namespace, "num");
10542 _objectType = getType(namespace, "Object"); 11830 _objectType = getType(namespace, "Object");
10543 _stackTraceType = getType(namespace, "StackTrace"); 11831 _stackTraceType = getType(namespace, "StackTrace");
10544 _stringType = getType(namespace, "String"); 11832 _stringType = getType(namespace, "String");
10545 _symbolType = getType(namespace, "Symbol"); 11833 _symbolType = getType(namespace, "Symbol");
10546 _typeType = getType(namespace, "Type"); 11834 _typeType = getType(namespace, "Type");
10547 } 11835 }
10548 } 11836 }
11837
10549 /** 11838 /**
10550 * Instances of the class `TypeResolverVisitor` are used to resolve the types as sociated with 11839 * Instances of the class `TypeResolverVisitor` are used to resolve the types as sociated with
10551 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces, 11840 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces,
10552 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building 11841 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building
10553 * the type hierarchy. 11842 * the type hierarchy.
10554 * 11843 *
10555 * @coverage dart.engine.resolver 11844 * @coverage dart.engine.resolver
10556 */ 11845 */
10557 class TypeResolverVisitor extends ScopedVisitor { 11846 class TypeResolverVisitor extends ScopedVisitor {
10558
10559 /** 11847 /**
10560 * @return `true` if the name of the given [TypeName] is an built-in identifie r. 11848 * @return `true` if the name of the given [TypeName] is an built-in identifie r.
10561 */ 11849 */
10562 static bool isBuiltInIdentifier(TypeName node) { 11850 static bool isBuiltInIdentifier(TypeName node) {
10563 sc.Token token = node.name.beginToken; 11851 sc.Token token = node.name.beginToken;
10564 return identical(token.type, sc.TokenType.KEYWORD); 11852 return identical(token.type, sc.TokenType.KEYWORD);
10565 } 11853 }
10566 11854
10567 /** 11855 /**
10568 * @return `true` if given [TypeName] is used as a type annotation. 11856 * @return `true` if given [TypeName] is used as a type annotation.
10569 */ 11857 */
10570 static bool isTypeAnnotation(TypeName node) { 11858 static bool isTypeAnnotation(TypeName node) {
10571 ASTNode parent = node.parent; 11859 ASTNode parent = node.parent;
10572 if (parent is VariableDeclarationList) { 11860 if (parent is VariableDeclarationList) {
10573 return identical(((parent as VariableDeclarationList)).type, node); 11861 return identical((parent as VariableDeclarationList).type, node);
10574 } 11862 }
10575 if (parent is FieldFormalParameter) { 11863 if (parent is FieldFormalParameter) {
10576 return identical(((parent as FieldFormalParameter)).type, node); 11864 return identical((parent as FieldFormalParameter).type, node);
10577 } 11865 }
10578 if (parent is SimpleFormalParameter) { 11866 if (parent is SimpleFormalParameter) {
10579 return identical(((parent as SimpleFormalParameter)).type, node); 11867 return identical((parent as SimpleFormalParameter).type, node);
10580 } 11868 }
10581 return false; 11869 return false;
10582 } 11870 }
10583 11871
10584 /** 11872 /**
10585 * The type representing the type 'dynamic'. 11873 * The type representing the type 'dynamic'.
10586 */ 11874 */
10587 Type2 _dynamicType; 11875 Type2 _dynamicType;
10588 11876
10589 /** 11877 /**
(...skipping 18 matching lines...) Expand all
10608 * @param definingLibrary the element for the library containing the compilati on unit being 11896 * @param definingLibrary the element for the library containing the compilati on unit being
10609 * visited 11897 * visited
10610 * @param source the source representing the compilation unit being visited 11898 * @param source the source representing the compilation unit being visited
10611 * @param typeProvider the object used to access the types from the core libra ry 11899 * @param typeProvider the object used to access the types from the core libra ry
10612 * @param errorListener the error listener that will be informed of any errors that are found 11900 * @param errorListener the error listener that will be informed of any errors that are found
10613 * during resolution 11901 * during resolution
10614 */ 11902 */
10615 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) { 11903 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) {
10616 _dynamicType = typeProvider.dynamicType; 11904 _dynamicType = typeProvider.dynamicType;
10617 } 11905 }
11906
11907 /**
11908 * Initialize a newly created visitor to resolve the nodes in an AST node.
11909 *
11910 * @param definingLibrary the element for the library containing the node bein g visited
11911 * @param source the source representing the compilation unit containing the n ode being visited
11912 * @param typeProvider the object used to access the types from the core libra ry
11913 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
11914 * @param errorListener the error listener that will be informed of any errors that are found
11915 * during resolution
11916 */
11917 TypeResolverVisitor.con3(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : sup er.con3(definingLibrary, source, typeProvider, nameScope, errorListener) {
11918 _dynamicType = typeProvider.dynamicType;
11919 }
11920
10618 Object visitCatchClause(CatchClause node) { 11921 Object visitCatchClause(CatchClause node) {
10619 super.visitCatchClause(node); 11922 super.visitCatchClause(node);
10620 SimpleIdentifier exception = node.exceptionParameter; 11923 SimpleIdentifier exception = node.exceptionParameter;
10621 if (exception != null) { 11924 if (exception != null) {
10622 TypeName exceptionTypeName = node.exceptionType; 11925 TypeName exceptionTypeName = node.exceptionType;
10623 Type2 exceptionType; 11926 Type2 exceptionType;
10624 if (exceptionTypeName == null) { 11927 if (exceptionTypeName == null) {
10625 exceptionType = typeProvider.dynamicType; 11928 exceptionType = typeProvider.dynamicType;
10626 } else { 11929 } else {
10627 exceptionType = getType3(exceptionTypeName); 11930 exceptionType = getType3(exceptionTypeName);
10628 } 11931 }
10629 recordType(exception, exceptionType); 11932 recordType(exception, exceptionType);
10630 Element element = exception.staticElement; 11933 Element element = exception.staticElement;
10631 if (element is VariableElementImpl) { 11934 if (element is VariableElementImpl) {
10632 ((element as VariableElementImpl)).type = exceptionType; 11935 (element as VariableElementImpl).type = exceptionType;
10633 } else { 11936 } else {
10634 } 11937 }
10635 } 11938 }
10636 SimpleIdentifier stackTrace = node.stackTraceParameter; 11939 SimpleIdentifier stackTrace = node.stackTraceParameter;
10637 if (stackTrace != null) { 11940 if (stackTrace != null) {
10638 recordType(stackTrace, typeProvider.stackTraceType); 11941 recordType(stackTrace, typeProvider.stackTraceType);
10639 } 11942 }
10640 return null; 11943 return null;
10641 } 11944 }
11945
10642 Object visitClassDeclaration(ClassDeclaration node) { 11946 Object visitClassDeclaration(ClassDeclaration node) {
10643 _hasReferenceToSuper = false; 11947 _hasReferenceToSuper = false;
10644 super.visitClassDeclaration(node); 11948 super.visitClassDeclaration(node);
10645 ClassElementImpl classElement = getClassElement(node.name); 11949 ClassElementImpl classElement = getClassElement(node.name);
10646 InterfaceType superclassType = null; 11950 InterfaceType superclassType = null;
10647 ExtendsClause extendsClause = node.extendsClause; 11951 ExtendsClause extendsClause = node.extendsClause;
10648 if (extendsClause != null) { 11952 if (extendsClause != null) {
10649 ErrorCode errorCode = (node.withClause == null ? CompileTimeErrorCode.EXTE NDS_NON_CLASS : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS) as ErrorCo de; 11953 ErrorCode errorCode = (node.withClause == null ? CompileTimeErrorCode.EXTE NDS_NON_CLASS : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS) as ErrorCo de;
10650 superclassType = resolveType(extendsClause.superclass, errorCode, errorCod e); 11954 superclassType = resolveType(extendsClause.superclass, errorCode, errorCod e);
10651 if (superclassType != typeProvider.objectType) { 11955 if (superclassType != typeProvider.objectType) {
10652 classElement.validMixin = false; 11956 classElement.validMixin = false;
10653 } 11957 }
10654 } 11958 }
10655 if (classElement != null) { 11959 if (classElement != null) {
10656 if (superclassType == null) { 11960 if (superclassType == null) {
10657 InterfaceType objectType = typeProvider.objectType; 11961 InterfaceType objectType = typeProvider.objectType;
10658 if (classElement.type != objectType) { 11962 if (classElement.type != objectType) {
10659 superclassType = objectType; 11963 superclassType = objectType;
10660 } 11964 }
10661 } 11965 }
10662 classElement.supertype = superclassType; 11966 classElement.supertype = superclassType;
10663 classElement.hasReferenceToSuper2 = _hasReferenceToSuper; 11967 classElement.hasReferenceToSuper2 = _hasReferenceToSuper;
10664 } 11968 }
10665 resolve(classElement, node.withClause, node.implementsClause); 11969 resolve(classElement, node.withClause, node.implementsClause);
10666 return null; 11970 return null;
10667 } 11971 }
11972
10668 Object visitClassTypeAlias(ClassTypeAlias node) { 11973 Object visitClassTypeAlias(ClassTypeAlias node) {
10669 super.visitClassTypeAlias(node); 11974 super.visitClassTypeAlias(node);
10670 ClassElementImpl classElement = getClassElement(node.name); 11975 ClassElementImpl classElement = getClassElement(node.name);
10671 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS; 11976 ErrorCode errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
10672 InterfaceType superclassType = resolveType(node.superclass, errorCode, error Code); 11977 InterfaceType superclassType = resolveType(node.superclass, errorCode, error Code);
10673 if (superclassType == null) { 11978 if (superclassType == null) {
10674 superclassType = typeProvider.objectType; 11979 superclassType = typeProvider.objectType;
10675 } 11980 }
10676 if (classElement != null && superclassType != null) { 11981 if (classElement != null && superclassType != null) {
10677 classElement.supertype = superclassType; 11982 classElement.supertype = superclassType;
10678 } 11983 }
10679 resolve(classElement, node.withClause, node.implementsClause); 11984 resolve(classElement, node.withClause, node.implementsClause);
10680 return null; 11985 return null;
10681 } 11986 }
11987
10682 Object visitConstructorDeclaration(ConstructorDeclaration node) { 11988 Object visitConstructorDeclaration(ConstructorDeclaration node) {
10683 super.visitConstructorDeclaration(node); 11989 super.visitConstructorDeclaration(node);
10684 ExecutableElementImpl element = node.element as ExecutableElementImpl; 11990 ExecutableElementImpl element = node.element as ExecutableElementImpl;
10685 ClassElement definingClass = element.enclosingElement as ClassElement; 11991 ClassElement definingClass = element.enclosingElement as ClassElement;
10686 element.returnType = definingClass.type; 11992 element.returnType = definingClass.type;
10687 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 11993 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
10688 type.typeArguments = definingClass.type.typeArguments; 11994 type.typeArguments = definingClass.type.typeArguments;
10689 element.type = type; 11995 element.type = type;
10690 return null; 11996 return null;
10691 } 11997 }
11998
10692 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 11999 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
10693 super.visitDeclaredIdentifier(node); 12000 super.visitDeclaredIdentifier(node);
10694 Type2 declaredType; 12001 Type2 declaredType;
10695 TypeName typeName = node.type; 12002 TypeName typeName = node.type;
10696 if (typeName == null) { 12003 if (typeName == null) {
10697 declaredType = _dynamicType; 12004 declaredType = _dynamicType;
10698 } else { 12005 } else {
10699 declaredType = getType3(typeName); 12006 declaredType = getType3(typeName);
10700 } 12007 }
10701 LocalVariableElementImpl element = node.element as LocalVariableElementImpl; 12008 LocalVariableElementImpl element = node.element as LocalVariableElementImpl;
10702 element.type = declaredType; 12009 element.type = declaredType;
10703 return null; 12010 return null;
10704 } 12011 }
12012
10705 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 12013 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
10706 super.visitDefaultFormalParameter(node); 12014 super.visitDefaultFormalParameter(node);
10707 return null; 12015 return null;
10708 } 12016 }
12017
10709 Object visitFieldFormalParameter(FieldFormalParameter node) { 12018 Object visitFieldFormalParameter(FieldFormalParameter node) {
10710 super.visitFieldFormalParameter(node); 12019 super.visitFieldFormalParameter(node);
10711 Element element = node.identifier.staticElement; 12020 Element element = node.identifier.staticElement;
10712 if (element is ParameterElementImpl) { 12021 if (element is ParameterElementImpl) {
10713 ParameterElementImpl parameter = element as ParameterElementImpl; 12022 ParameterElementImpl parameter = element as ParameterElementImpl;
10714 FormalParameterList parameterList = node.parameters; 12023 FormalParameterList parameterList = node.parameters;
10715 if (parameterList == null) { 12024 if (parameterList == null) {
10716 Type2 type; 12025 Type2 type;
10717 TypeName typeName = node.type; 12026 TypeName typeName = node.type;
10718 if (typeName == null) { 12027 if (typeName == null) {
10719 type = _dynamicType; 12028 type = _dynamicType;
10720 } else { 12029 } else {
10721 type = getType3(typeName); 12030 type = getType3(typeName);
10722 } 12031 }
10723 parameter.type = type; 12032 parameter.type = type;
10724 } else { 12033 } else {
10725 setFunctionTypedParameterType(parameter, node.type, node.parameters); 12034 setFunctionTypedParameterType(parameter, node.type, node.parameters);
10726 } 12035 }
10727 } else { 12036 } else {
10728 } 12037 }
10729 return null; 12038 return null;
10730 } 12039 }
12040
10731 Object visitFunctionDeclaration(FunctionDeclaration node) { 12041 Object visitFunctionDeclaration(FunctionDeclaration node) {
10732 super.visitFunctionDeclaration(node); 12042 super.visitFunctionDeclaration(node);
10733 ExecutableElementImpl element = node.element as ExecutableElementImpl; 12043 ExecutableElementImpl element = node.element as ExecutableElementImpl;
10734 element.returnType = computeReturnType(node.returnType); 12044 element.returnType = computeReturnType(node.returnType);
10735 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 12045 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
10736 ClassElement definingClass = element.getAncestor(ClassElement); 12046 ClassElement definingClass = element.getAncestor(ClassElement);
10737 if (definingClass != null) { 12047 if (definingClass != null) {
10738 type.typeArguments = definingClass.type.typeArguments; 12048 type.typeArguments = definingClass.type.typeArguments;
10739 } 12049 }
10740 element.type = type; 12050 element.type = type;
10741 return null; 12051 return null;
10742 } 12052 }
12053
10743 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 12054 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
10744 super.visitFunctionTypeAlias(node); 12055 super.visitFunctionTypeAlias(node);
10745 FunctionTypeAliasElementImpl element = node.element as FunctionTypeAliasElem entImpl; 12056 FunctionTypeAliasElementImpl element = node.element as FunctionTypeAliasElem entImpl;
10746 element.returnType = computeReturnType(node.returnType); 12057 element.returnType = computeReturnType(node.returnType);
10747 return null; 12058 return null;
10748 } 12059 }
12060
10749 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 12061 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
10750 super.visitFunctionTypedFormalParameter(node); 12062 super.visitFunctionTypedFormalParameter(node);
10751 Element element = node.identifier.staticElement; 12063 Element element = node.identifier.staticElement;
10752 if (element is ParameterElementImpl) { 12064 if (element is ParameterElementImpl) {
10753 setFunctionTypedParameterType(element as ParameterElementImpl, node.return Type, node.parameters); 12065 setFunctionTypedParameterType(element as ParameterElementImpl, node.return Type, node.parameters);
10754 } else { 12066 } else {
10755 } 12067 }
10756 return null; 12068 return null;
10757 } 12069 }
12070
10758 Object visitMethodDeclaration(MethodDeclaration node) { 12071 Object visitMethodDeclaration(MethodDeclaration node) {
10759 super.visitMethodDeclaration(node); 12072 super.visitMethodDeclaration(node);
10760 ExecutableElementImpl element = node.element as ExecutableElementImpl; 12073 ExecutableElementImpl element = node.element as ExecutableElementImpl;
10761 element.returnType = computeReturnType(node.returnType); 12074 element.returnType = computeReturnType(node.returnType);
10762 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 12075 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
10763 ClassElement definingClass = element.getAncestor(ClassElement); 12076 ClassElement definingClass = element.getAncestor(ClassElement);
10764 if (definingClass != null) { 12077 if (definingClass != null) {
10765 type.typeArguments = definingClass.type.typeArguments; 12078 type.typeArguments = definingClass.type.typeArguments;
10766 } 12079 }
10767 element.type = type; 12080 element.type = type;
10768 if (element is PropertyAccessorElement) { 12081 if (element is PropertyAccessorElement) {
10769 PropertyAccessorElement accessor = element as PropertyAccessorElement; 12082 PropertyAccessorElement accessor = element as PropertyAccessorElement;
10770 PropertyInducingElementImpl variable = accessor.variable as PropertyInduci ngElementImpl; 12083 PropertyInducingElementImpl variable = accessor.variable as PropertyInduci ngElementImpl;
10771 if (accessor.isGetter) { 12084 if (accessor.isGetter) {
10772 variable.type = type.returnType; 12085 variable.type = type.returnType;
10773 } else if (variable.type == null) { 12086 } else if (variable.type == null) {
10774 List<Type2> parameterTypes = type.normalParameterTypes; 12087 List<Type2> parameterTypes = type.normalParameterTypes;
10775 if (parameterTypes != null && parameterTypes.length > 0) { 12088 if (parameterTypes != null && parameterTypes.length > 0) {
10776 variable.type = parameterTypes[0]; 12089 variable.type = parameterTypes[0];
10777 } 12090 }
10778 } 12091 }
10779 } 12092 }
10780 return null; 12093 return null;
10781 } 12094 }
12095
10782 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 12096 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
10783 super.visitSimpleFormalParameter(node); 12097 super.visitSimpleFormalParameter(node);
10784 Type2 declaredType; 12098 Type2 declaredType;
10785 TypeName typeName = node.type; 12099 TypeName typeName = node.type;
10786 if (typeName == null) { 12100 if (typeName == null) {
10787 declaredType = _dynamicType; 12101 declaredType = _dynamicType;
10788 } else { 12102 } else {
10789 declaredType = getType3(typeName); 12103 declaredType = getType3(typeName);
10790 } 12104 }
10791 Element element = node.identifier.staticElement; 12105 Element element = node.identifier.staticElement;
10792 if (element is ParameterElement) { 12106 if (element is ParameterElement) {
10793 ((element as ParameterElementImpl)).type = declaredType; 12107 (element as ParameterElementImpl).type = declaredType;
10794 } else { 12108 } else {
10795 } 12109 }
10796 return null; 12110 return null;
10797 } 12111 }
12112
10798 Object visitSuperExpression(SuperExpression node) { 12113 Object visitSuperExpression(SuperExpression node) {
10799 _hasReferenceToSuper = true; 12114 _hasReferenceToSuper = true;
10800 return super.visitSuperExpression(node); 12115 return super.visitSuperExpression(node);
10801 } 12116 }
12117
10802 Object visitTypeName(TypeName node) { 12118 Object visitTypeName(TypeName node) {
10803 super.visitTypeName(node); 12119 super.visitTypeName(node);
10804 Identifier typeName = node.name; 12120 Identifier typeName = node.name;
10805 TypeArgumentList argumentList = node.typeArguments; 12121 TypeArgumentList argumentList = node.typeArguments;
10806 Element element = nameScope.lookup(typeName, definingLibrary); 12122 Element element = nameScope.lookup(typeName, definingLibrary);
10807 if (element == null) { 12123 if (element == null) {
10808 if (typeName.name == this._dynamicType.name) { 12124 if (typeName.name == this._dynamicType.name) {
10809 setElement(typeName, this._dynamicType.element); 12125 setElement(typeName, this._dynamicType.element);
10810 if (argumentList != null) { 12126 if (argumentList != null) {
10811 } 12127 }
(...skipping 10 matching lines...) Expand all
10822 return null; 12138 return null;
10823 } 12139 }
10824 ASTNode parent = node.parent; 12140 ASTNode parent = node.parent;
10825 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen tList == null) { 12141 if (typeName is PrefixedIdentifier && parent is ConstructorName && argumen tList == null) {
10826 ConstructorName name = parent as ConstructorName; 12142 ConstructorName name = parent as ConstructorName;
10827 if (name.name == null) { 12143 if (name.name == null) {
10828 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier ; 12144 PrefixedIdentifier prefixedIdentifier = typeName as PrefixedIdentifier ;
10829 SimpleIdentifier prefix = prefixedIdentifier.prefix; 12145 SimpleIdentifier prefix = prefixedIdentifier.prefix;
10830 element = nameScope.lookup(prefix, definingLibrary); 12146 element = nameScope.lookup(prefix, definingLibrary);
10831 if (element is PrefixElement) { 12147 if (element is PrefixElement) {
10832 if (parent.parent is InstanceCreationExpression && ((parent.parent a s InstanceCreationExpression)).isConst) { 12148 if (parent.parent is InstanceCreationExpression && (parent.parent as InstanceCreationExpression).isConst) {
10833 reportError5(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde ntifier.identifier, [prefixedIdentifier.identifier.name]); 12149 reportError6(CompileTimeErrorCode.CONST_WITH_NON_TYPE, prefixedIde ntifier.identifier, [prefixedIdentifier.identifier.name]);
10834 } else { 12150 } else {
10835 reportError5(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi er.identifier, [prefixedIdentifier.identifier.name]); 12151 reportError6(StaticWarningCode.NEW_WITH_NON_TYPE, prefixedIdentifi er.identifier, [prefixedIdentifier.identifier.name]);
10836 } 12152 }
10837 setElement(prefix, element); 12153 setElement(prefix, element);
10838 return null; 12154 return null;
10839 } else if (element != null) { 12155 } else if (element != null) {
10840 name.name = prefixedIdentifier.identifier; 12156 name.name = prefixedIdentifier.identifier;
10841 name.period = prefixedIdentifier.period; 12157 name.period = prefixedIdentifier.period;
10842 node.name = prefix; 12158 node.name = prefix;
10843 typeName = prefix; 12159 typeName = prefix;
10844 } 12160 }
10845 } 12161 }
10846 } 12162 }
10847 } 12163 }
10848 bool elementValid = element is! MultiplyDefinedElement; 12164 bool elementValid = element is! MultiplyDefinedElement;
10849 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation Expression(node)) { 12165 if (elementValid && element is! ClassElement && isTypeNameInInstanceCreation Expression(node)) {
10850 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); 12166 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
10851 InstanceCreationExpression creation = node.parent.parent as InstanceCreati onExpression; 12167 InstanceCreationExpression creation = node.parent.parent as InstanceCreati onExpression;
10852 if (creation.isConst) { 12168 if (creation.isConst) {
10853 if (element == null) { 12169 if (element == null) {
10854 reportError5(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty peName]); 12170 reportError6(CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [ty peName]);
10855 } else { 12171 } else {
10856 reportError5(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, [typeName]); 12172 reportError6(CompileTimeErrorCode.CONST_WITH_NON_TYPE, typeNameSimple, [typeName]);
10857 } 12173 }
10858 elementValid = false; 12174 elementValid = false;
10859 } else { 12175 } else {
10860 if (element != null) { 12176 if (element != null) {
10861 reportError5(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ eName]); 12177 reportError6(StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typ eName]);
10862 elementValid = false; 12178 elementValid = false;
10863 } 12179 }
10864 } 12180 }
10865 } 12181 }
10866 if (elementValid && element == null) { 12182 if (elementValid && element == null) {
10867 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName); 12183 SimpleIdentifier typeNameSimple = getTypeSimpleIdentifier(typeName);
10868 RedirectingConstructorKind redirectingConstructorKind; 12184 RedirectingConstructorKind redirectingConstructorKind;
10869 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) { 12185 if (isBuiltInIdentifier(node) && isTypeAnnotation(node)) {
10870 reportError5(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName, [typeName.name]); 12186 reportError6(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, typeName, [typeName.name]);
10871 } else if (typeNameSimple.name == "boolean") { 12187 } else if (typeNameSimple.name == "boolean") {
10872 reportError5(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []); 12188 reportError6(StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []);
10873 } else if (isTypeNameInCatchClause(node)) { 12189 } else if (isTypeNameInCatchClause(node)) {
10874 reportError5(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]); 12190 reportError6(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]);
10875 } else if (isTypeNameInAsExpression(node)) { 12191 } else if (isTypeNameInAsExpression(node)) {
10876 reportError5(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]); 12192 reportError6(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]);
10877 } else if (isTypeNameInIsExpression(node)) { 12193 } else if (isTypeNameInIsExpression(node)) {
10878 reportError5(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]); 12194 reportError6(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]);
10879 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) { 12195 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) {
10880 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 12196 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode;
10881 reportError5(errorCode, typeName, [typeName.name]); 12197 reportError6(errorCode, typeName, [typeName.name]);
10882 } else if (isTypeNameInTypeArgumentList(node)) { 12198 } else if (isTypeNameInTypeArgumentList(node)) {
10883 reportError5(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]); 12199 reportError6(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]);
10884 } else { 12200 } else {
10885 reportError5(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name ]); 12201 reportError6(StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name ]);
10886 } 12202 }
10887 elementValid = false; 12203 elementValid = false;
10888 } 12204 }
10889 if (!elementValid) { 12205 if (!elementValid) {
10890 if (element is MultiplyDefinedElement) { 12206 if (element is MultiplyDefinedElement) {
10891 setElement(typeName, element); 12207 setElement(typeName, element);
10892 } else { 12208 } else {
10893 setElement(typeName, this._dynamicType.element); 12209 setElement(typeName, this._dynamicType.element);
10894 } 12210 }
10895 typeName.staticType = this._dynamicType; 12211 typeName.staticType = this._dynamicType;
10896 node.type = this._dynamicType; 12212 node.type = this._dynamicType;
10897 return null; 12213 return null;
10898 } 12214 }
10899 Type2 type = null; 12215 Type2 type = null;
10900 if (element is ClassElement) { 12216 if (element is ClassElement) {
10901 setElement(typeName, element); 12217 setElement(typeName, element);
10902 type = ((element as ClassElement)).type; 12218 type = (element as ClassElement).type;
10903 } else if (element is FunctionTypeAliasElement) { 12219 } else if (element is FunctionTypeAliasElement) {
10904 setElement(typeName, element); 12220 setElement(typeName, element);
10905 type = ((element as FunctionTypeAliasElement)).type; 12221 type = (element as FunctionTypeAliasElement).type;
10906 } else if (element is TypeParameterElement) { 12222 } else if (element is TypeParameterElement) {
10907 setElement(typeName, element); 12223 setElement(typeName, element);
10908 type = ((element as TypeParameterElement)).type; 12224 type = (element as TypeParameterElement).type;
10909 if (argumentList != null) { 12225 if (argumentList != null) {
10910 } 12226 }
10911 } else if (element is MultiplyDefinedElement) { 12227 } else if (element is MultiplyDefinedElement) {
10912 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting Elements; 12228 List<Element> elements = (element as MultiplyDefinedElement).conflictingEl ements;
10913 type = getType(elements); 12229 type = getType(elements);
10914 if (type != null) { 12230 if (type != null) {
10915 node.type = type; 12231 node.type = type;
10916 } 12232 }
10917 } else { 12233 } else {
10918 RedirectingConstructorKind redirectingConstructorKind; 12234 RedirectingConstructorKind redirectingConstructorKind;
10919 if (isTypeNameInCatchClause(node)) { 12235 if (isTypeNameInCatchClause(node)) {
10920 reportError5(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]); 12236 reportError6(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, [type Name.name]);
10921 } else if (isTypeNameInAsExpression(node)) { 12237 } else if (isTypeNameInAsExpression(node)) {
10922 reportError5(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]); 12238 reportError6(StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.nam e]);
10923 } else if (isTypeNameInIsExpression(node)) { 12239 } else if (isTypeNameInIsExpression(node)) {
10924 reportError5(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]); 12240 reportError6(StaticWarningCode.TYPE_TEST_NON_TYPE, typeName, [typeName.n ame]);
10925 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) { 12241 } else if ((redirectingConstructorKind = getRedirectingConstructorKind(nod e)) != null) {
10926 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode; 12242 ErrorCode errorCode = (identical(redirectingConstructorKind, Redirecting ConstructorKind.CONST) ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS : StaticWarn ingCode.REDIRECT_TO_NON_CLASS) as ErrorCode;
10927 reportError5(errorCode, typeName, [typeName.name]); 12243 reportError6(errorCode, typeName, [typeName.name]);
10928 } else if (isTypeNameInTypeArgumentList(node)) { 12244 } else if (isTypeNameInTypeArgumentList(node)) {
10929 reportError5(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]); 12245 reportError6(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, typeName, [typeName.name]);
10930 } else { 12246 } else {
10931 ASTNode parent = typeName.parent; 12247 ASTNode parent = typeName.parent;
10932 while (parent is TypeName) { 12248 while (parent is TypeName) {
10933 parent = parent.parent; 12249 parent = parent.parent;
10934 } 12250 }
10935 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) { 12251 if (parent is ExtendsClause || parent is ImplementsClause || parent is W ithClause || parent is ClassTypeAlias) {
10936 } else { 12252 } else {
10937 reportError5(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); 12253 reportError6(StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]);
10938 } 12254 }
10939 } 12255 }
10940 setElement(typeName, this._dynamicType.element); 12256 setElement(typeName, this._dynamicType.element);
10941 typeName.staticType = this._dynamicType; 12257 typeName.staticType = this._dynamicType;
10942 node.type = this._dynamicType; 12258 node.type = this._dynamicType;
10943 return null; 12259 return null;
10944 } 12260 }
10945 if (argumentList != null) { 12261 if (argumentList != null) {
10946 NodeList<TypeName> arguments = argumentList.arguments; 12262 NodeList<TypeName> arguments = argumentList.arguments;
10947 int argumentCount = arguments.length; 12263 int argumentCount = arguments.length;
10948 List<Type2> parameters = getTypeArguments(type); 12264 List<Type2> parameters = getTypeArguments(type);
10949 int parameterCount = parameters.length; 12265 int parameterCount = parameters.length;
10950 int count = Math.min(argumentCount, parameterCount); 12266 int count = Math.min(argumentCount, parameterCount);
10951 List<Type2> typeArguments = new List<Type2>(); 12267 List<Type2> typeArguments = new List<Type2>();
10952 for (int i = 0; i < count; i++) { 12268 for (int i = 0; i < count; i++) {
10953 Type2 argumentType = getType3(arguments[i]); 12269 Type2 argumentType = getType3(arguments[i]);
10954 if (argumentType != null) { 12270 if (argumentType != null) {
10955 typeArguments.add(argumentType); 12271 typeArguments.add(argumentType);
10956 } 12272 }
10957 } 12273 }
10958 if (argumentCount != parameterCount) { 12274 if (argumentCount != parameterCount) {
10959 reportError5(getInvalidTypeParametersErrorCode(node), node, [typeName.na me, parameterCount, argumentCount]); 12275 reportError6(getInvalidTypeParametersErrorCode(node), node, [typeName.na me, parameterCount, argumentCount]);
10960 } 12276 }
10961 argumentCount = typeArguments.length; 12277 argumentCount = typeArguments.length;
10962 if (argumentCount < parameterCount) { 12278 if (argumentCount < parameterCount) {
10963 for (int i = argumentCount; i < parameterCount; i++) { 12279 for (int i = argumentCount; i < parameterCount; i++) {
10964 typeArguments.add(this._dynamicType); 12280 typeArguments.add(this._dynamicType);
10965 } 12281 }
10966 } 12282 }
10967 if (type is InterfaceTypeImpl) { 12283 if (type is InterfaceTypeImpl) {
10968 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; 12284 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl;
10969 type = interfaceType.substitute4(new List.from(typeArguments)); 12285 type = interfaceType.substitute4(new List.from(typeArguments));
(...skipping 11 matching lines...) Expand all
10981 for (int i = 0; i < parameterCount; i++) { 12297 for (int i = 0; i < parameterCount; i++) {
10982 arguments[i] = dynamicType; 12298 arguments[i] = dynamicType;
10983 } 12299 }
10984 type = type.substitute2(arguments, parameters); 12300 type = type.substitute2(arguments, parameters);
10985 } 12301 }
10986 } 12302 }
10987 typeName.staticType = type; 12303 typeName.staticType = type;
10988 node.type = type; 12304 node.type = type;
10989 return null; 12305 return null;
10990 } 12306 }
12307
10991 Object visitVariableDeclaration(VariableDeclaration node) { 12308 Object visitVariableDeclaration(VariableDeclaration node) {
10992 super.visitVariableDeclaration(node); 12309 super.visitVariableDeclaration(node);
10993 Type2 declaredType; 12310 Type2 declaredType;
10994 TypeName typeName = ((node.parent as VariableDeclarationList)).type; 12311 TypeName typeName = (node.parent as VariableDeclarationList).type;
10995 if (typeName == null) { 12312 if (typeName == null) {
10996 declaredType = _dynamicType; 12313 declaredType = _dynamicType;
10997 } else { 12314 } else {
10998 declaredType = getType3(typeName); 12315 declaredType = getType3(typeName);
10999 } 12316 }
11000 Element element = node.name.staticElement; 12317 Element element = node.name.staticElement;
11001 if (element is VariableElement) { 12318 if (element is VariableElement) {
11002 ((element as VariableElementImpl)).type = declaredType; 12319 (element as VariableElementImpl).type = declaredType;
11003 if (element is PropertyInducingElement) { 12320 if (element is PropertyInducingElement) {
11004 PropertyInducingElement variableElement = element as PropertyInducingEle ment; 12321 PropertyInducingElement variableElement = element as PropertyInducingEle ment;
11005 PropertyAccessorElementImpl getter = variableElement.getter as PropertyA ccessorElementImpl; 12322 PropertyAccessorElementImpl getter = variableElement.getter as PropertyA ccessorElementImpl;
11006 getter.returnType = declaredType; 12323 getter.returnType = declaredType;
11007 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter); 12324 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
11008 ClassElement definingClass = element.getAncestor(ClassElement); 12325 ClassElement definingClass = element.getAncestor(ClassElement);
11009 if (definingClass != null) { 12326 if (definingClass != null) {
11010 getterType.typeArguments = definingClass.type.typeArguments; 12327 getterType.typeArguments = definingClass.type.typeArguments;
11011 } 12328 }
11012 getter.type = getterType; 12329 getter.type = getterType;
11013 PropertyAccessorElementImpl setter = variableElement.setter as PropertyA ccessorElementImpl; 12330 PropertyAccessorElementImpl setter = variableElement.setter as PropertyA ccessorElementImpl;
11014 if (setter != null) { 12331 if (setter != null) {
11015 List<ParameterElement> parameters = setter.parameters; 12332 List<ParameterElement> parameters = setter.parameters;
11016 if (parameters.length > 0) { 12333 if (parameters.length > 0) {
11017 ((parameters[0] as ParameterElementImpl)).type = declaredType; 12334 (parameters[0] as ParameterElementImpl).type = declaredType;
11018 } 12335 }
11019 setter.returnType = VoidTypeImpl.instance; 12336 setter.returnType = VoidTypeImpl.instance;
11020 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter); 12337 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter);
11021 if (definingClass != null) { 12338 if (definingClass != null) {
11022 setterType.typeArguments = definingClass.type.typeArguments; 12339 setterType.typeArguments = definingClass.type.typeArguments;
11023 } 12340 }
11024 setter.type = setterType; 12341 setter.type = setterType;
11025 } 12342 }
11026 } 12343 }
11027 } else { 12344 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
11086 * 12403 *
11087 * @param node the type name with the wrong number of type arguments 12404 * @param node the type name with the wrong number of type arguments
11088 * @return the error code that should be used to report that the wrong number of type arguments 12405 * @return the error code that should be used to report that the wrong number of type arguments
11089 * were provided 12406 * were provided
11090 */ 12407 */
11091 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) { 12408 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) {
11092 ASTNode parent = node.parent; 12409 ASTNode parent = node.parent;
11093 if (parent is ConstructorName) { 12410 if (parent is ConstructorName) {
11094 parent = parent.parent; 12411 parent = parent.parent;
11095 if (parent is InstanceCreationExpression) { 12412 if (parent is InstanceCreationExpression) {
11096 if (((parent as InstanceCreationExpression)).isConst) { 12413 if ((parent as InstanceCreationExpression).isConst) {
11097 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS; 12414 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS;
11098 } else { 12415 } else {
11099 return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS; 12416 return StaticWarningCode.NEW_WITH_INVALID_TYPE_PARAMETERS;
11100 } 12417 }
11101 } 12418 }
11102 } 12419 }
11103 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS; 12420 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
11104 } 12421 }
11105 12422
11106 /** 12423 /**
(...skipping 28 matching lines...) Expand all
11135 * @param elements the elements to which a single name could potentially be re solved 12452 * @param elements the elements to which a single name could potentially be re solved
11136 * @return the single interface type that should be used for the type name 12453 * @return the single interface type that should be used for the type name
11137 */ 12454 */
11138 InterfaceType getType(List<Element> elements) { 12455 InterfaceType getType(List<Element> elements) {
11139 InterfaceType type = null; 12456 InterfaceType type = null;
11140 for (Element element in elements) { 12457 for (Element element in elements) {
11141 if (element is ClassElement) { 12458 if (element is ClassElement) {
11142 if (type != null) { 12459 if (type != null) {
11143 return null; 12460 return null;
11144 } 12461 }
11145 type = ((element as ClassElement)).type; 12462 type = (element as ClassElement).type;
11146 } 12463 }
11147 } 12464 }
11148 return type; 12465 return type;
11149 } 12466 }
11150 12467
11151 /** 12468 /**
11152 * Return the type represented by the given type name. 12469 * Return the type represented by the given type name.
11153 * 12470 *
11154 * @param typeName the type name representing the type to be returned 12471 * @param typeName the type name representing the type to be returned
11155 * @return the type represented by the type name 12472 * @return the type represented by the type name
11156 */ 12473 */
11157 Type2 getType3(TypeName typeName) { 12474 Type2 getType3(TypeName typeName) {
11158 Type2 type = typeName.type; 12475 Type2 type = typeName.type;
11159 if (type == null) { 12476 if (type == null) {
11160 return _dynamicType; 12477 return _dynamicType;
11161 } 12478 }
11162 return type; 12479 return type;
11163 } 12480 }
11164 12481
11165 /** 12482 /**
11166 * Return the type arguments associated with the given type. 12483 * Return the type arguments associated with the given type.
11167 * 12484 *
11168 * @param type the type whole type arguments are to be returned 12485 * @param type the type whole type arguments are to be returned
11169 * @return the type arguments associated with the given type 12486 * @return the type arguments associated with the given type
11170 */ 12487 */
11171 List<Type2> getTypeArguments(Type2 type) { 12488 List<Type2> getTypeArguments(Type2 type) {
11172 if (type is InterfaceType) { 12489 if (type is InterfaceType) {
11173 return ((type as InterfaceType)).typeArguments; 12490 return (type as InterfaceType).typeArguments;
11174 } else if (type is FunctionType) { 12491 } else if (type is FunctionType) {
11175 return ((type as FunctionType)).typeArguments; 12492 return (type as FunctionType).typeArguments;
11176 } 12493 }
11177 return TypeImpl.EMPTY_ARRAY; 12494 return TypeImpl.EMPTY_ARRAY;
11178 } 12495 }
11179 12496
11180 /** 12497 /**
11181 * Returns the simple identifier of the given (may be qualified) type name. 12498 * Returns the simple identifier of the given (may be qualified) type name.
11182 * 12499 *
11183 * @param typeName the (may be qualified) qualified type name 12500 * @param typeName the (may be qualified) qualified type name
11184 * @return the simple identifier of the given (may be qualified) type name. 12501 * @return the simple identifier of the given (may be qualified) type name.
11185 */ 12502 */
11186 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) { 12503 SimpleIdentifier getTypeSimpleIdentifier(Identifier typeName) {
11187 if (typeName is SimpleIdentifier) { 12504 if (typeName is SimpleIdentifier) {
11188 return typeName as SimpleIdentifier; 12505 return typeName as SimpleIdentifier;
11189 } else { 12506 } else {
11190 return ((typeName as PrefixedIdentifier)).identifier; 12507 return (typeName as PrefixedIdentifier).identifier;
11191 } 12508 }
11192 } 12509 }
11193 12510
11194 /** 12511 /**
11195 * Checks if the given type name is used as the type in an as expression. 12512 * Checks if the given type name is used as the type in an as expression.
11196 * 12513 *
11197 * @param typeName the type name to analyzer 12514 * @param typeName the type name to analyzer
11198 * @return `true` if the given type name is used as the type in an as expressi on 12515 * @return `true` if the given type name is used as the type in an as expressi on
11199 */ 12516 */
11200 bool isTypeNameInAsExpression(TypeName typeName) { 12517 bool isTypeNameInAsExpression(TypeName typeName) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
11306 TypeName typeName = typeNames[i]; 12623 TypeName typeName = typeNames[i];
11307 if (!detectedRepeatOnIndex[i]) { 12624 if (!detectedRepeatOnIndex[i]) {
11308 Element element = typeName.name.staticElement; 12625 Element element = typeName.name.staticElement;
11309 for (int j = i + 1; j < typeNames.length; j++) { 12626 for (int j = i + 1; j < typeNames.length; j++) {
11310 TypeName typeName2 = typeNames[j]; 12627 TypeName typeName2 = typeNames[j];
11311 Identifier identifier2 = typeName2.name; 12628 Identifier identifier2 = typeName2.name;
11312 String name2 = identifier2.name; 12629 String name2 = identifier2.name;
11313 Element element2 = identifier2.staticElement; 12630 Element element2 = identifier2.staticElement;
11314 if (element != null && element == element2) { 12631 if (element != null && element == element2) {
11315 detectedRepeatOnIndex[j] = true; 12632 detectedRepeatOnIndex[j] = true;
11316 reportError5(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]); 12633 reportError6(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]);
11317 } 12634 }
11318 } 12635 }
11319 } 12636 }
11320 } 12637 }
11321 } 12638 }
11322 } 12639 }
11323 12640
11324 /** 12641 /**
11325 * Return the type specified by the given name. 12642 * Return the type specified by the given name.
11326 * 12643 *
11327 * @param typeName the type name specifying the type to be returned 12644 * @param typeName the type name specifying the type to be returned
11328 * @param nonTypeError the error to produce if the type name is defined to be something other than 12645 * @param nonTypeError the error to produce if the type name is defined to be something other than
11329 * a type 12646 * a type
11330 * @param dynamicTypeError the error to produce if the type name is "dynamic" 12647 * @param dynamicTypeError the error to produce if the type name is "dynamic"
11331 * @return the type specified by the type name 12648 * @return the type specified by the type name
11332 */ 12649 */
11333 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode dynamicTypeError) { 12650 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError, ErrorCode dynamicTypeError) {
11334 Type2 type = typeName.type; 12651 Type2 type = typeName.type;
11335 if (type is InterfaceType) { 12652 if (type is InterfaceType) {
11336 return type as InterfaceType; 12653 return type as InterfaceType;
11337 } 12654 }
11338 Identifier name = typeName.name; 12655 Identifier name = typeName.name;
11339 if (name.name == sc.Keyword.DYNAMIC.syntax) { 12656 if (name.name == sc.Keyword.DYNAMIC.syntax) {
11340 reportError5(dynamicTypeError, name, [name.name]); 12657 reportError6(dynamicTypeError, name, [name.name]);
11341 } else { 12658 } else {
11342 reportError5(nonTypeError, name, [name.name]); 12659 reportError6(nonTypeError, name, [name.name]);
11343 } 12660 }
11344 return null; 12661 return null;
11345 } 12662 }
11346 12663
11347 /** 12664 /**
11348 * Resolve the types in the given list of type names. 12665 * Resolve the types in the given list of type names.
11349 * 12666 *
11350 * @param typeNames the type names to be resolved 12667 * @param typeNames the type names to be resolved
11351 * @param nonTypeError the error to produce if the type name is defined to be something other than 12668 * @param nonTypeError the error to produce if the type name is defined to be something other than
11352 * a type 12669 * a type
11353 * @param dynamicTypeError the error to produce if the type name is "dynamic" 12670 * @param dynamicTypeError the error to produce if the type name is "dynamic"
11354 * @return an array containing all of the types that were resolved. 12671 * @return an array containing all of the types that were resolved.
11355 */ 12672 */
11356 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy peError, ErrorCode dynamicTypeError) { 12673 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy peError, ErrorCode dynamicTypeError) {
11357 List<InterfaceType> types = new List<InterfaceType>(); 12674 List<InterfaceType> types = new List<InterfaceType>();
11358 for (TypeName typeName in typeNames) { 12675 for (TypeName typeName in typeNames) {
11359 InterfaceType type = resolveType(typeName, nonTypeError, dynamicTypeError) ; 12676 InterfaceType type = resolveType(typeName, nonTypeError, dynamicTypeError) ;
11360 if (type != null) { 12677 if (type != null) {
11361 types.add(type); 12678 types.add(type);
11362 } 12679 }
11363 } 12680 }
11364 return new List.from(types); 12681 return new List.from(types);
11365 } 12682 }
12683
11366 void setElement(Identifier typeName, Element element) { 12684 void setElement(Identifier typeName, Element element) {
11367 if (element != null) { 12685 if (element != null) {
11368 if (typeName is SimpleIdentifier) { 12686 if (typeName is SimpleIdentifier) {
11369 ((typeName as SimpleIdentifier)).staticElement = element; 12687 (typeName as SimpleIdentifier).staticElement = element;
11370 } else if (typeName is PrefixedIdentifier) { 12688 } else if (typeName is PrefixedIdentifier) {
11371 PrefixedIdentifier identifier = typeName as PrefixedIdentifier; 12689 PrefixedIdentifier identifier = typeName as PrefixedIdentifier;
11372 identifier.identifier.staticElement = element; 12690 identifier.identifier.staticElement = element;
11373 SimpleIdentifier prefix = identifier.prefix; 12691 SimpleIdentifier prefix = identifier.prefix;
11374 Element prefixElement = nameScope.lookup(prefix, definingLibrary); 12692 Element prefixElement = nameScope.lookup(prefix, definingLibrary);
11375 if (prefixElement != null) { 12693 if (prefixElement != null) {
11376 prefix.staticElement = prefixElement; 12694 prefix.staticElement = prefixElement;
11377 } 12695 }
11378 } 12696 }
11379 } 12697 }
(...skipping 26 matching lines...) Expand all
11406 if (alias != null) { 12724 if (alias != null) {
11407 aliasElement.typeParameters = alias.typeParameters; 12725 aliasElement.typeParameters = alias.typeParameters;
11408 type.typeArguments = alias.type.typeArguments; 12726 type.typeArguments = alias.type.typeArguments;
11409 } else { 12727 } else {
11410 type.typeArguments = TypeImpl.EMPTY_ARRAY; 12728 type.typeArguments = TypeImpl.EMPTY_ARRAY;
11411 } 12729 }
11412 } 12730 }
11413 element.type = type; 12731 element.type = type;
11414 } 12732 }
11415 } 12733 }
12734
11416 /** 12735 /**
11417 * Kind of the redirecting constructor. 12736 * Kind of the redirecting constructor.
11418 */ 12737 */
11419 class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> { 12738 class RedirectingConstructorKind extends Enum<RedirectingConstructorKind> {
11420 static final RedirectingConstructorKind CONST = new RedirectingConstructorKind ('CONST', 0); 12739 static final RedirectingConstructorKind CONST = new RedirectingConstructorKind ('CONST', 0);
12740
11421 static final RedirectingConstructorKind NORMAL = new RedirectingConstructorKin d('NORMAL', 1); 12741 static final RedirectingConstructorKind NORMAL = new RedirectingConstructorKin d('NORMAL', 1);
12742
11422 static final List<RedirectingConstructorKind> values = [CONST, NORMAL]; 12743 static final List<RedirectingConstructorKind> values = [CONST, NORMAL];
12744
11423 RedirectingConstructorKind(String name, int ordinal) : super(name, ordinal); 12745 RedirectingConstructorKind(String name, int ordinal) : super(name, ordinal);
11424 } 12746 }
12747
11425 /** 12748 /**
11426 * Instances of the class `VariableResolverVisitor` are used to resolve 12749 * Instances of the class `VariableResolverVisitor` are used to resolve
11427 * [SimpleIdentifier]s to local variables and formal parameters. 12750 * [SimpleIdentifier]s to local variables and formal parameters.
11428 * 12751 *
11429 * @coverage dart.engine.resolver 12752 * @coverage dart.engine.resolver
11430 */ 12753 */
11431 class VariableResolverVisitor extends ScopedVisitor { 12754 class VariableResolverVisitor extends ScopedVisitor {
11432
11433 /** 12755 /**
11434 * The method or function that we are currently visiting, or `null` if we are not inside a 12756 * The method or function that we are currently visiting, or `null` if we are not inside a
11435 * method or function. 12757 * method or function.
11436 */ 12758 */
11437 ExecutableElement _enclosingFunction; 12759 ExecutableElement _enclosingFunction;
11438 12760
11439 /** 12761 /**
11440 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 12762 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
11441 * 12763 *
11442 * @param library the library containing the compilation unit being resolved 12764 * @param library the library containing the compilation unit being resolved
11443 * @param source the source representing the compilation unit being visited 12765 * @param source the source representing the compilation unit being visited
11444 * @param typeProvider the object used to access the types from the core libra ry 12766 * @param typeProvider the object used to access the types from the core libra ry
11445 */ 12767 */
11446 VariableResolverVisitor(Library library, Source source, TypeProvider typeProvi der) : super.con1(library, source, typeProvider); 12768 VariableResolverVisitor.con1(Library library, Source source, TypeProvider type Provider) : super.con1(library, source, typeProvider);
12769
12770 /**
12771 * Initialize a newly created visitor to resolve the nodes in an AST node.
12772 *
12773 * @param definingLibrary the element for the library containing the node bein g visited
12774 * @param source the source representing the compilation unit containing the n ode being visited
12775 * @param typeProvider the object used to access the types from the core libra ry
12776 * @param nameScope the scope used to resolve identifiers in the node that wil l first be visited
12777 * @param errorListener the error listener that will be informed of any errors that are found
12778 * during resolution
12779 */
12780 VariableResolverVisitor.con2(LibraryElement definingLibrary, Source source, Ty peProvider typeProvider, Scope nameScope, AnalysisErrorListener errorListener) : super.con3(definingLibrary, source, typeProvider, nameScope, errorListener);
12781
11447 Object visitFunctionDeclaration(FunctionDeclaration node) { 12782 Object visitFunctionDeclaration(FunctionDeclaration node) {
11448 ExecutableElement outerFunction = _enclosingFunction; 12783 ExecutableElement outerFunction = _enclosingFunction;
11449 try { 12784 try {
11450 _enclosingFunction = node.element; 12785 _enclosingFunction = node.element;
11451 return super.visitFunctionDeclaration(node); 12786 return super.visitFunctionDeclaration(node);
11452 } finally { 12787 } finally {
11453 _enclosingFunction = outerFunction; 12788 _enclosingFunction = outerFunction;
11454 } 12789 }
11455 } 12790 }
12791
11456 Object visitFunctionExpression(FunctionExpression node) { 12792 Object visitFunctionExpression(FunctionExpression node) {
11457 if (node.parent is! FunctionDeclaration) { 12793 if (node.parent is! FunctionDeclaration) {
11458 ExecutableElement outerFunction = _enclosingFunction; 12794 ExecutableElement outerFunction = _enclosingFunction;
11459 try { 12795 try {
11460 _enclosingFunction = node.element; 12796 _enclosingFunction = node.element;
11461 return super.visitFunctionExpression(node); 12797 return super.visitFunctionExpression(node);
11462 } finally { 12798 } finally {
11463 _enclosingFunction = outerFunction; 12799 _enclosingFunction = outerFunction;
11464 } 12800 }
11465 } else { 12801 } else {
11466 return super.visitFunctionExpression(node); 12802 return super.visitFunctionExpression(node);
11467 } 12803 }
11468 } 12804 }
12805
11469 Object visitSimpleIdentifier(SimpleIdentifier node) { 12806 Object visitSimpleIdentifier(SimpleIdentifier node) {
11470 if (node.staticElement != null) { 12807 if (node.staticElement != null) {
11471 return null; 12808 return null;
11472 } 12809 }
11473 ASTNode parent = node.parent; 12810 ASTNode parent = node.parent;
11474 if (parent is PrefixedIdentifier && identical(((parent as PrefixedIdentifier )).identifier, node)) { 12811 if (parent is PrefixedIdentifier && identical((parent as PrefixedIdentifier) .identifier, node)) {
11475 return null; 12812 return null;
11476 } 12813 }
11477 if (parent is PropertyAccess && identical(((parent as PropertyAccess)).prope rtyName, node)) { 12814 if (parent is PropertyAccess && identical((parent as PropertyAccess).propert yName, node)) {
11478 return null; 12815 return null;
11479 } 12816 }
11480 if (parent is MethodInvocation && identical(((parent as MethodInvocation)).m ethodName, node)) { 12817 if (parent is MethodInvocation && identical((parent as MethodInvocation).met hodName, node)) {
11481 return null; 12818 return null;
11482 } 12819 }
11483 if (parent is ConstructorName) { 12820 if (parent is ConstructorName) {
11484 return null; 12821 return null;
11485 } 12822 }
11486 if (parent is Label) { 12823 if (parent is Label) {
11487 return null; 12824 return null;
11488 } 12825 }
11489 Element element = nameScope.lookup(node, definingLibrary); 12826 Element element = nameScope.lookup(node, definingLibrary);
11490 if (element is! VariableElement) { 12827 if (element is! VariableElement) {
(...skipping 15 matching lines...) Expand all
11506 ParameterElementImpl parameterImpl = element as ParameterElementImpl; 12843 ParameterElementImpl parameterImpl = element as ParameterElementImpl;
11507 parameterImpl.markPotentiallyMutatedInScope(); 12844 parameterImpl.markPotentiallyMutatedInScope();
11508 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) { 12845 if (_enclosingFunction != null && (element.enclosingElement != _enclosin gFunction)) {
11509 parameterImpl.markPotentiallyMutatedInClosure(); 12846 parameterImpl.markPotentiallyMutatedInClosure();
11510 } 12847 }
11511 } 12848 }
11512 } 12849 }
11513 return null; 12850 return null;
11514 } 12851 }
11515 } 12852 }
12853
11516 /** 12854 /**
11517 * Instances of the class `ClassScope` implement the scope defined by a class. 12855 * Instances of the class `ClassScope` implement the scope defined by a class.
11518 * 12856 *
11519 * @coverage dart.engine.resolver 12857 * @coverage dart.engine.resolver
11520 */ 12858 */
11521 class ClassScope extends EnclosedScope { 12859 class ClassScope extends EnclosedScope {
11522
11523 /** 12860 /**
11524 * Initialize a newly created scope enclosed within another scope. 12861 * Initialize a newly created scope enclosed within another scope.
11525 * 12862 *
11526 * @param enclosingScope the scope in which this scope is lexically enclosed 12863 * @param enclosingScope the scope in which this scope is lexically enclosed
11527 * @param typeElement the element representing the type represented by this sc ope 12864 * @param typeElement the element representing the type represented by this sc ope
11528 */ 12865 */
11529 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose dScope(enclosingScope)) { 12866 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose dScope(enclosingScope)) {
11530 defineTypeParameters(typeElement); 12867 defineTypeParameters(typeElement);
11531 defineMembers(typeElement); 12868 defineMembers(typeElement);
11532 } 12869 }
12870
11533 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 12871 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
11534 if (existing is PropertyAccessorElement && duplicate is MethodElement) { 12872 if (existing is PropertyAccessorElement && duplicate is MethodElement) {
11535 if (existing.nameOffset < duplicate.nameOffset) { 12873 if (existing.nameOffset < duplicate.nameOffset) {
11536 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM E, [existing.displayName]); 12874 return new AnalysisError.con2(duplicate.source, duplicate.nameOffset, du plicate.displayName.length, CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAM E, [existing.displayName]);
11537 } else { 12875 } else {
11538 return new AnalysisError.con2(existing.source, existing.nameOffset, exis ting.displayName.length, CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, [existing.displayName]); 12876 return new AnalysisError.con2(existing.source, existing.nameOffset, exis ting.displayName.length, CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, [existing.displayName]);
11539 } 12877 }
11540 } 12878 }
11541 return super.getErrorForDuplicate(existing, duplicate); 12879 return super.getErrorForDuplicate(existing, duplicate);
11542 } 12880 }
(...skipping 17 matching lines...) Expand all
11560 * 12898 *
11561 * @param typeElement the element representing the type represented by this sc ope 12899 * @param typeElement the element representing the type represented by this sc ope
11562 */ 12900 */
11563 void defineTypeParameters(ClassElement typeElement) { 12901 void defineTypeParameters(ClassElement typeElement) {
11564 Scope parameterScope = enclosingScope; 12902 Scope parameterScope = enclosingScope;
11565 for (TypeParameterElement typeParameter in typeElement.typeParameters) { 12903 for (TypeParameterElement typeParameter in typeElement.typeParameters) {
11566 parameterScope.define(typeParameter); 12904 parameterScope.define(typeParameter);
11567 } 12905 }
11568 } 12906 }
11569 } 12907 }
12908
11570 /** 12909 /**
11571 * Instances of the class `EnclosedScope` implement a scope that is lexically en closed in 12910 * Instances of the class `EnclosedScope` implement a scope that is lexically en closed in
11572 * another scope. 12911 * another scope.
11573 * 12912 *
11574 * @coverage dart.engine.resolver 12913 * @coverage dart.engine.resolver
11575 */ 12914 */
11576 class EnclosedScope extends Scope { 12915 class EnclosedScope extends Scope {
11577
11578 /** 12916 /**
11579 * The scope in which this scope is lexically enclosed. 12917 * The scope in which this scope is lexically enclosed.
11580 */ 12918 */
11581 Scope enclosingScope; 12919 Scope _enclosingScope;
11582 12920
11583 /** 12921 /**
11584 * A set of names that will be defined in this scope, but right now are not de fined. However 12922 * A table mapping names that will be defined in this scope, but right now are not initialized.
11585 * according to the scoping rules these names are hidden, even if they were de fined in an outer 12923 * According to the scoping rules these names are hidden, even if they were de fined in an outer
11586 * scope. 12924 * scope.
11587 */ 12925 */
11588 Set<String> _hiddenNames = new Set<String>(); 12926 Map<String, Element> _hiddenElements = new Map<String, Element>();
11589 12927
11590 /** 12928 /**
11591 * Initialize a newly created scope enclosed within another scope. 12929 * Initialize a newly created scope enclosed within another scope.
11592 * 12930 *
11593 * @param enclosingScope the scope in which this scope is lexically enclosed 12931 * @param enclosingScope the scope in which this scope is lexically enclosed
11594 */ 12932 */
11595 EnclosedScope(Scope enclosingScope) { 12933 EnclosedScope(Scope enclosingScope) {
11596 this.enclosingScope = enclosingScope; 12934 this._enclosingScope = enclosingScope;
11597 } 12935 }
11598 AnalysisErrorListener get errorListener => enclosingScope.errorListener; 12936
12937 Scope get enclosingScope => _enclosingScope;
12938
12939 AnalysisErrorListener get errorListener => _enclosingScope.errorListener;
11599 12940
11600 /** 12941 /**
11601 * Hides the name of the given element in this scope. If there is already an e lement with the 12942 * Record that given element is declared in this scope, but hasn't been initia lized yet, so it is
11602 * given name defined in an outer scope, then it will become unavailable. 12943 * error to use. If there is already an element with the given name defined in an outer scope,
12944 * then it will become unavailable.
11603 * 12945 *
11604 * @param element the element to be hidden in this scope 12946 * @param element the element declared, but not initialized in this scope
11605 */ 12947 */
11606 void hide(Element element) { 12948 void hide(Element element) {
11607 if (element != null) { 12949 if (element != null) {
11608 String name = element.name; 12950 String name = element.name;
11609 if (name != null && !name.isEmpty) { 12951 if (name != null && !name.isEmpty) {
11610 javaSetAdd(_hiddenNames, name); 12952 _hiddenElements[name] = element;
11611 } 12953 }
11612 } 12954 }
11613 } 12955 }
12956
11614 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) { 12957 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) {
11615 Element element = localLookup(name, referencingLibrary); 12958 Element element = localLookup(name, referencingLibrary);
11616 if (element != null) { 12959 if (element != null) {
11617 return element; 12960 return element;
11618 } 12961 }
11619 if (_hiddenNames.contains(name)) { 12962 Element hiddenElement = _hiddenElements[name];
12963 if (hiddenElement != null) {
11620 errorListener.onError(new AnalysisError.con2(getSource(identifier), identi fier.offset, identifier.length, CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATI ON, [])); 12964 errorListener.onError(new AnalysisError.con2(getSource(identifier), identi fier.offset, identifier.length, CompileTimeErrorCode.REFERENCED_BEFORE_DECLARATI ON, []));
12965 return hiddenElement;
11621 } 12966 }
11622 return enclosingScope.lookup3(identifier, name, referencingLibrary); 12967 return _enclosingScope.lookup3(identifier, name, referencingLibrary);
11623 } 12968 }
11624 } 12969 }
12970
11625 /** 12971 /**
11626 * Instances of the class `FunctionScope` implement the scope defined by a funct ion. 12972 * Instances of the class `FunctionScope` implement the scope defined by a funct ion.
11627 * 12973 *
11628 * @coverage dart.engine.resolver 12974 * @coverage dart.engine.resolver
11629 */ 12975 */
11630 class FunctionScope extends EnclosedScope { 12976 class FunctionScope extends EnclosedScope {
11631 ExecutableElement _functionElement; 12977 ExecutableElement _functionElement;
12978
11632 bool _parametersDefined = false; 12979 bool _parametersDefined = false;
11633 12980
11634 /** 12981 /**
11635 * Initialize a newly created scope enclosed within another scope. 12982 * Initialize a newly created scope enclosed within another scope.
11636 * 12983 *
11637 * @param enclosingScope the scope in which this scope is lexically enclosed 12984 * @param enclosingScope the scope in which this scope is lexically enclosed
11638 * @param functionElement the element representing the type represented by thi s scope 12985 * @param functionElement the element representing the type represented by thi s scope
11639 */ 12986 */
11640 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) { 12987 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) {
11641 this._functionElement = functionElement; 12988 this._functionElement = functionElement;
(...skipping 14 matching lines...) Expand all
11656 parameterScope.define(_functionElement); 13003 parameterScope.define(_functionElement);
11657 } 13004 }
11658 } 13005 }
11659 for (ParameterElement parameter in _functionElement.parameters) { 13006 for (ParameterElement parameter in _functionElement.parameters) {
11660 if (!parameter.isInitializingFormal) { 13007 if (!parameter.isInitializingFormal) {
11661 parameterScope.define(parameter); 13008 parameterScope.define(parameter);
11662 } 13009 }
11663 } 13010 }
11664 } 13011 }
11665 } 13012 }
13013
11666 /** 13014 /**
11667 * Instances of the class `FunctionTypeScope` implement the scope defined by a f unction type 13015 * Instances of the class `FunctionTypeScope` implement the scope defined by a f unction type
11668 * alias. 13016 * alias.
11669 * 13017 *
11670 * @coverage dart.engine.resolver 13018 * @coverage dart.engine.resolver
11671 */ 13019 */
11672 class FunctionTypeScope extends EnclosedScope { 13020 class FunctionTypeScope extends EnclosedScope {
11673 FunctionTypeAliasElement _typeElement; 13021 FunctionTypeAliasElement _typeElement;
13022
11674 bool _parametersDefined = false; 13023 bool _parametersDefined = false;
11675 13024
11676 /** 13025 /**
11677 * Initialize a newly created scope enclosed within another scope. 13026 * Initialize a newly created scope enclosed within another scope.
11678 * 13027 *
11679 * @param enclosingScope the scope in which this scope is lexically enclosed 13028 * @param enclosingScope the scope in which this scope is lexically enclosed
11680 * @param typeElement the element representing the type alias represented by t his scope 13029 * @param typeElement the element representing the type alias represented by t his scope
11681 */ 13030 */
11682 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement) : super(new EnclosedScope(enclosingScope)) { 13031 FunctionTypeScope(Scope enclosingScope, FunctionTypeAliasElement typeElement) : super(new EnclosedScope(enclosingScope)) {
11683 this._typeElement = typeElement; 13032 this._typeElement = typeElement;
(...skipping 20 matching lines...) Expand all
11704 * 13053 *
11705 * @param typeElement the element representing the type represented by this sc ope 13054 * @param typeElement the element representing the type represented by this sc ope
11706 */ 13055 */
11707 void defineTypeParameters() { 13056 void defineTypeParameters() {
11708 Scope typeParameterScope = enclosingScope; 13057 Scope typeParameterScope = enclosingScope;
11709 for (TypeParameterElement typeParameter in _typeElement.typeParameters) { 13058 for (TypeParameterElement typeParameter in _typeElement.typeParameters) {
11710 typeParameterScope.define(typeParameter); 13059 typeParameterScope.define(typeParameter);
11711 } 13060 }
11712 } 13061 }
11713 } 13062 }
13063
11714 /** 13064 /**
11715 * Instances of the class `LabelScope` represent a scope in which a single label is defined. 13065 * Instances of the class `LabelScope` represent a scope in which a single label is defined.
11716 * 13066 *
11717 * @coverage dart.engine.resolver 13067 * @coverage dart.engine.resolver
11718 */ 13068 */
11719 class LabelScope { 13069 class LabelScope {
11720
11721 /** 13070 /**
11722 * The label scope enclosing this label scope. 13071 * The label scope enclosing this label scope.
11723 */ 13072 */
11724 LabelScope _outerScope; 13073 LabelScope _outerScope;
11725 13074
11726 /** 13075 /**
11727 * The label defined in this scope. 13076 * The label defined in this scope.
11728 */ 13077 */
11729 String _label; 13078 String _label;
11730 13079
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
11787 LabelElement lookup2(String targetLabel) { 13136 LabelElement lookup2(String targetLabel) {
11788 if (_label == targetLabel) { 13137 if (_label == targetLabel) {
11789 return _element; 13138 return _element;
11790 } else if (_outerScope != null) { 13139 } else if (_outerScope != null) {
11791 return _outerScope.lookup2(targetLabel); 13140 return _outerScope.lookup2(targetLabel);
11792 } else { 13141 } else {
11793 return null; 13142 return null;
11794 } 13143 }
11795 } 13144 }
11796 } 13145 }
13146
11797 /** 13147 /**
11798 * Instances of the class `LibraryImportScope` represent the scope containing al l of the names 13148 * Instances of the class `LibraryImportScope` represent the scope containing al l of the names
11799 * available from imported libraries. 13149 * available from imported libraries.
11800 * 13150 *
11801 * @coverage dart.engine.resolver 13151 * @coverage dart.engine.resolver
11802 */ 13152 */
11803 class LibraryImportScope extends Scope { 13153 class LibraryImportScope extends Scope {
11804
11805 /** 13154 /**
11806 * The element representing the library in which this scope is enclosed. 13155 * The element representing the library in which this scope is enclosed.
11807 */ 13156 */
11808 LibraryElement _definingLibrary; 13157 LibraryElement _definingLibrary;
11809 13158
11810 /** 13159 /**
11811 * The listener that is to be informed when an error is encountered. 13160 * The listener that is to be informed when an error is encountered.
11812 */ 13161 */
11813 AnalysisErrorListener _errorListener; 13162 AnalysisErrorListener _errorListener;
11814 13163
11815 /** 13164 /**
11816 * A list of the namespaces representing the names that are available in this scope from imported 13165 * A list of the namespaces representing the names that are available in this scope from imported
11817 * libraries. 13166 * libraries.
11818 */ 13167 */
11819 List<Namespace> _importedNamespaces = new List<Namespace>(); 13168 List<Namespace> _importedNamespaces = new List<Namespace>();
11820 13169
11821 /** 13170 /**
11822 * Initialize a newly created scope representing the names imported into the g iven library. 13171 * Initialize a newly created scope representing the names imported into the g iven library.
11823 * 13172 *
11824 * @param definingLibrary the element representing the library that imports th e names defined in 13173 * @param definingLibrary the element representing the library that imports th e names defined in
11825 * this scope 13174 * this scope
11826 * @param errorListener the listener that is to be informed when an error is e ncountered 13175 * @param errorListener the listener that is to be informed when an error is e ncountered
11827 */ 13176 */
11828 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error Listener) { 13177 LibraryImportScope(LibraryElement definingLibrary, AnalysisErrorListener error Listener) {
11829 this._definingLibrary = definingLibrary; 13178 this._definingLibrary = definingLibrary;
11830 this._errorListener = errorListener; 13179 this._errorListener = errorListener;
11831 createImportedNamespaces(definingLibrary); 13180 createImportedNamespaces(definingLibrary);
11832 } 13181 }
13182
11833 void define(Element element) { 13183 void define(Element element) {
11834 if (!Scope.isPrivateName(element.displayName)) { 13184 if (!Scope.isPrivateName(element.displayName)) {
11835 super.define(element); 13185 super.define(element);
11836 } 13186 }
11837 } 13187 }
13188
11838 AnalysisErrorListener get errorListener => _errorListener; 13189 AnalysisErrorListener get errorListener => _errorListener;
13190
11839 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) { 13191 Element lookup3(Identifier identifier, String name, LibraryElement referencing Library) {
11840 Element foundElement = localLookup(name, referencingLibrary); 13192 Element foundElement = localLookup(name, referencingLibrary);
11841 if (foundElement != null) { 13193 if (foundElement != null) {
11842 return foundElement; 13194 return foundElement;
11843 } 13195 }
11844 for (Namespace nameSpace in _importedNamespaces) { 13196 for (Namespace nameSpace in _importedNamespaces) {
11845 Element element = nameSpace.get(name); 13197 Element element = nameSpace.get(name);
11846 if (element != null) { 13198 if (element != null) {
11847 if (foundElement == null) { 13199 if (foundElement == null) {
11848 foundElement = element; 13200 foundElement = element;
11849 } else if (foundElement != element) { 13201 } else if (foundElement != element) {
11850 foundElement = MultiplyDefinedElementImpl.fromElements(_definingLibrar y.context, foundElement, element); 13202 foundElement = MultiplyDefinedElementImpl.fromElements(_definingLibrar y.context, foundElement, element);
11851 } 13203 }
11852 } 13204 }
11853 } 13205 }
11854 if (foundElement is MultiplyDefinedElementImpl) { 13206 if (foundElement is MultiplyDefinedElementImpl) {
11855 foundElement = removeSdkElements(identifier, name, foundElement as Multipl yDefinedElementImpl); 13207 foundElement = removeSdkElements(identifier, name, foundElement as Multipl yDefinedElementImpl);
11856 } 13208 }
11857 if (foundElement is MultiplyDefinedElementImpl) { 13209 if (foundElement is MultiplyDefinedElementImpl) {
11858 String foundEltName = foundElement.displayName; 13210 String foundEltName = foundElement.displayName;
11859 List<Element> conflictingMembers = ((foundElement as MultiplyDefinedElemen tImpl)).conflictingElements; 13211 List<Element> conflictingMembers = (foundElement as MultiplyDefinedElement Impl).conflictingElements;
11860 String libName1 = getLibraryName(conflictingMembers[0], ""); 13212 String libName1 = getLibraryName(conflictingMembers[0], "");
11861 String libName2 = getLibraryName(conflictingMembers[1], ""); 13213 String libName2 = getLibraryName(conflictingMembers[1], "");
11862 _errorListener.onError(new AnalysisError.con2(getSource(identifier), ident ifier.offset, identifier.length, StaticWarningCode.AMBIGUOUS_IMPORT, [foundEltNa me, libName1, libName2])); 13214 _errorListener.onError(new AnalysisError.con2(getSource(identifier), ident ifier.offset, identifier.length, StaticWarningCode.AMBIGUOUS_IMPORT, [foundEltNa me, libName1, libName2]));
11863 return foundElement; 13215 return foundElement;
11864 } 13216 }
11865 if (foundElement != null) { 13217 if (foundElement != null) {
11866 defineWithoutChecking2(name, foundElement); 13218 defineWithoutChecking2(name, foundElement);
11867 } 13219 }
11868 return foundElement; 13220 return foundElement;
11869 } 13221 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
11933 return conflictingMembers[0]; 13285 return conflictingMembers[0];
11934 } else if (to == 0) { 13286 } else if (to == 0) {
11935 AnalysisEngine.instance.logger.logInformation("Multiply defined SDK elemen t: ${foundElement}"); 13287 AnalysisEngine.instance.logger.logInformation("Multiply defined SDK elemen t: ${foundElement}");
11936 return foundElement; 13288 return foundElement;
11937 } 13289 }
11938 List<Element> remaining = new List<Element>(to); 13290 List<Element> remaining = new List<Element>(to);
11939 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to); 13291 JavaSystem.arraycopy(conflictingMembers, 0, remaining, 0, to);
11940 return new MultiplyDefinedElementImpl(_definingLibrary.context, remaining); 13292 return new MultiplyDefinedElementImpl(_definingLibrary.context, remaining);
11941 } 13293 }
11942 } 13294 }
13295
11943 /** 13296 /**
11944 * Instances of the class `LibraryScope` implement a scope containing all of the names defined 13297 * Instances of the class `LibraryScope` implement a scope containing all of the names defined
11945 * in a given library. 13298 * in a given library.
11946 * 13299 *
11947 * @coverage dart.engine.resolver 13300 * @coverage dart.engine.resolver
11948 */ 13301 */
11949 class LibraryScope extends EnclosedScope { 13302 class LibraryScope extends EnclosedScope {
11950
11951 /** 13303 /**
11952 * Initialize a newly created scope representing the names defined in the give n library. 13304 * Initialize a newly created scope representing the names defined in the give n library.
11953 * 13305 *
11954 * @param definingLibrary the element representing the library represented by this scope 13306 * @param definingLibrary the element representing the library represented by this scope
11955 * @param errorListener the listener that is to be informed when an error is e ncountered 13307 * @param errorListener the listener that is to be informed when an error is e ncountered
11956 */ 13308 */
11957 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen er) : super(new LibraryImportScope(definingLibrary, errorListener)) { 13309 LibraryScope(LibraryElement definingLibrary, AnalysisErrorListener errorListen er) : super(new LibraryImportScope(definingLibrary, errorListener)) {
11958 defineTopLevelNames(definingLibrary); 13310 defineTopLevelNames(definingLibrary);
11959 } 13311 }
13312
11960 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 13313 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
11961 if (existing is PrefixElement) { 13314 if (existing is PrefixElement) {
11962 int offset = duplicate.nameOffset; 13315 int offset = duplicate.nameOffset;
11963 if (duplicate is PropertyAccessorElement) { 13316 if (duplicate is PropertyAccessorElement) {
11964 PropertyAccessorElement accessor = duplicate as PropertyAccessorElement; 13317 PropertyAccessorElement accessor = duplicate as PropertyAccessorElement;
11965 if (accessor.isSynthetic) { 13318 if (accessor.isSynthetic) {
11966 offset = accessor.variable.nameOffset; 13319 offset = accessor.variable.nameOffset;
11967 } 13320 }
11968 } 13321 }
11969 return new AnalysisError.con2(duplicate.source, offset, duplicate.displayN ame.length, CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [existin g.displayName]); 13322 return new AnalysisError.con2(duplicate.source, offset, duplicate.displayN ame.length, CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, [existin g.displayName]);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
12002 void defineTopLevelNames(LibraryElement definingLibrary) { 13355 void defineTopLevelNames(LibraryElement definingLibrary) {
12003 for (PrefixElement prefix in definingLibrary.prefixes) { 13356 for (PrefixElement prefix in definingLibrary.prefixes) {
12004 define(prefix); 13357 define(prefix);
12005 } 13358 }
12006 defineLocalNames(definingLibrary.definingCompilationUnit); 13359 defineLocalNames(definingLibrary.definingCompilationUnit);
12007 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { 13360 for (CompilationUnitElement compilationUnit in definingLibrary.parts) {
12008 defineLocalNames(compilationUnit); 13361 defineLocalNames(compilationUnit);
12009 } 13362 }
12010 } 13363 }
12011 } 13364 }
13365
12012 /** 13366 /**
12013 * Instances of the class `Namespace` implement a mapping of identifiers to the elements 13367 * Instances of the class `Namespace` implement a mapping of identifiers to the elements
12014 * represented by those identifiers. Namespaces are the building blocks for scop es. 13368 * represented by those identifiers. Namespaces are the building blocks for scop es.
12015 * 13369 *
12016 * @coverage dart.engine.resolver 13370 * @coverage dart.engine.resolver
12017 */ 13371 */
12018 class Namespace { 13372 class Namespace {
12019
12020 /** 13373 /**
12021 * A table mapping names that are defined in this namespace to the element rep resenting the thing 13374 * A table mapping names that are defined in this namespace to the element rep resenting the thing
12022 * declared with that name. 13375 * declared with that name.
12023 */ 13376 */
12024 Map<String, Element> _definedNames; 13377 Map<String, Element> _definedNames;
12025 13378
12026 /** 13379 /**
12027 * An empty namespace. 13380 * An empty namespace.
12028 */ 13381 */
12029 static Namespace EMPTY = new Namespace(new Map<String, Element>()); 13382 static Namespace EMPTY = new Namespace(new Map<String, Element>());
(...skipping 17 matching lines...) Expand all
12047 */ 13400 */
12048 Element get(String name) => _definedNames[name]; 13401 Element get(String name) => _definedNames[name];
12049 13402
12050 /** 13403 /**
12051 * Return a table containing the same mappings as those defined by this namesp ace. 13404 * Return a table containing the same mappings as those defined by this namesp ace.
12052 * 13405 *
12053 * @return a table containing the same mappings as those defined by this names pace 13406 * @return a table containing the same mappings as those defined by this names pace
12054 */ 13407 */
12055 Map<String, Element> get definedNames => new Map<String, Element>.from(_define dNames); 13408 Map<String, Element> get definedNames => new Map<String, Element>.from(_define dNames);
12056 } 13409 }
13410
12057 /** 13411 /**
12058 * Instances of the class `NamespaceBuilder` are used to build a `Namespace`. Na mespace 13412 * Instances of the class `NamespaceBuilder` are used to build a `Namespace`. Na mespace
12059 * builders are thread-safe and re-usable. 13413 * builders are thread-safe and re-usable.
12060 * 13414 *
12061 * @coverage dart.engine.resolver 13415 * @coverage dart.engine.resolver
12062 */ 13416 */
12063 class NamespaceBuilder { 13417 class NamespaceBuilder {
12064
12065 /** 13418 /**
12066 * Create a namespace representing the export namespace of the given [ExportEl ement]. 13419 * Create a namespace representing the export namespace of the given [ExportEl ement].
12067 * 13420 *
12068 * @param element the export element whose export namespace is to be created 13421 * @param element the export element whose export namespace is to be created
12069 * @return the export namespace that was created 13422 * @return the export namespace that was created
12070 */ 13423 */
12071 Namespace createExportNamespace(ExportElement element) { 13424 Namespace createExportNamespace(ExportElement element) {
12072 LibraryElement exportedLibrary = element.exportedLibrary; 13425 LibraryElement exportedLibrary = element.exportedLibrary;
12073 if (exportedLibrary == null) { 13426 if (exportedLibrary == null) {
12074 return Namespace.EMPTY; 13427 return Namespace.EMPTY;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
12180 13533
12181 /** 13534 /**
12182 * Apply the given combinators to all of the names in the given mapping table. 13535 * Apply the given combinators to all of the names in the given mapping table.
12183 * 13536 *
12184 * @param definedNames the mapping table to which the namespace operations are to be applied 13537 * @param definedNames the mapping table to which the namespace operations are to be applied
12185 * @param combinators the combinators to be applied 13538 * @param combinators the combinators to be applied
12186 */ 13539 */
12187 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo mbinator> combinators) { 13540 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo mbinator> combinators) {
12188 for (NamespaceCombinator combinator in combinators) { 13541 for (NamespaceCombinator combinator in combinators) {
12189 if (combinator is HideElementCombinator) { 13542 if (combinator is HideElementCombinator) {
12190 hide(definedNames, ((combinator as HideElementCombinator)).hiddenNames); 13543 hide(definedNames, (combinator as HideElementCombinator).hiddenNames);
12191 } else if (combinator is ShowElementCombinator) { 13544 } else if (combinator is ShowElementCombinator) {
12192 definedNames = show(definedNames, ((combinator as ShowElementCombinator) ).shownNames); 13545 definedNames = show(definedNames, (combinator as ShowElementCombinator). shownNames);
12193 } else { 13546 } else {
12194 AnalysisEngine.instance.logger.logError("Unknown type of combinator: ${c ombinator.runtimeType.toString()}"); 13547 AnalysisEngine.instance.logger.logError("Unknown type of combinator: ${c ombinator.runtimeType.toString()}");
12195 } 13548 }
12196 } 13549 }
12197 return definedNames; 13550 return definedNames;
12198 } 13551 }
12199 13552
12200 /** 13553 /**
12201 * Apply the given prefix to all of the names in the table of defined names. 13554 * Apply the given prefix to all of the names in the table of defined names.
12202 * 13555 *
(...skipping 27 matching lines...) Expand all
12230 try { 13583 try {
12231 Map<String, Element> definedNames = new Map<String, Element>(); 13584 Map<String, Element> definedNames = new Map<String, Element>();
12232 for (ExportElement element in library.exports) { 13585 for (ExportElement element in library.exports) {
12233 LibraryElement exportedLibrary = element.exportedLibrary; 13586 LibraryElement exportedLibrary = element.exportedLibrary;
12234 if (exportedLibrary != null && !visitedElements.contains(exportedLibrary )) { 13587 if (exportedLibrary != null && !visitedElements.contains(exportedLibrary )) {
12235 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry, visitedElements); 13588 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry, visitedElements);
12236 exportedNames = apply(exportedNames, element.combinators); 13589 exportedNames = apply(exportedNames, element.combinators);
12237 addAll(definedNames, exportedNames); 13590 addAll(definedNames, exportedNames);
12238 } 13591 }
12239 } 13592 }
12240 addAll2(definedNames, ((library.context as InternalAnalysisContext)).getPu blicNamespace(library)); 13593 addAll2(definedNames, (library.context as InternalAnalysisContext).getPubl icNamespace(library));
12241 return definedNames; 13594 return definedNames;
12242 } finally { 13595 } finally {
12243 visitedElements.remove(library); 13596 visitedElements.remove(library);
12244 } 13597 }
12245 } 13598 }
12246 13599
12247 /** 13600 /**
12248 * Hide all of the given names by removing them from the given collection of d efined names. 13601 * Hide all of the given names by removing them from the given collection of d efined names.
12249 * 13602 *
12250 * @param definedNames the names that were defined before this operation 13603 * @param definedNames the names that were defined before this operation
(...skipping 22 matching lines...) Expand all
12273 } 13626 }
12274 String setterName = "${name}="; 13627 String setterName = "${name}=";
12275 element = definedNames[setterName]; 13628 element = definedNames[setterName];
12276 if (element != null) { 13629 if (element != null) {
12277 newNames[setterName] = element; 13630 newNames[setterName] = element;
12278 } 13631 }
12279 } 13632 }
12280 return newNames; 13633 return newNames;
12281 } 13634 }
12282 } 13635 }
13636
12283 /** 13637 /**
12284 * The abstract class `Scope` defines the behavior common to name scopes used by the resolver 13638 * The abstract class `Scope` defines the behavior common to name scopes used by the resolver
12285 * to determine which names are visible at any given point in the code. 13639 * to determine which names are visible at any given point in the code.
12286 * 13640 *
12287 * @coverage dart.engine.resolver 13641 * @coverage dart.engine.resolver
12288 */ 13642 */
12289 abstract class Scope { 13643 abstract class Scope {
12290
12291 /** 13644 /**
12292 * The prefix used to mark an identifier as being private to its library. 13645 * The prefix used to mark an identifier as being private to its library.
12293 */ 13646 */
12294 static String PRIVATE_NAME_PREFIX = "_"; 13647 static String PRIVATE_NAME_PREFIX = "_";
12295 13648
12296 /** 13649 /**
12297 * The suffix added to the declared name of a setter when looking up the sette r. Used to 13650 * The suffix added to the declared name of a setter when looking up the sette r. Used to
12298 * disambiguate between a getter and a setter that have the same name. 13651 * disambiguate between a getter and a setter that have the same name.
12299 */ 13652 */
12300 static String SETTER_SUFFIX = "="; 13653 static String SETTER_SUFFIX = "=";
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
12332 if (name != null && !name.isEmpty) { 13685 if (name != null && !name.isEmpty) {
12333 if (_definedNames.containsKey(name)) { 13686 if (_definedNames.containsKey(name)) {
12334 errorListener.onError(getErrorForDuplicate(_definedNames[name], element) ); 13687 errorListener.onError(getErrorForDuplicate(_definedNames[name], element) );
12335 } else { 13688 } else {
12336 _definedNames[name] = element; 13689 _definedNames[name] = element;
12337 } 13690 }
12338 } 13691 }
12339 } 13692 }
12340 13693
12341 /** 13694 /**
13695 * Return the scope in which this scope is lexically enclosed.
13696 *
13697 * @return the scope in which this scope is lexically enclosed
13698 */
13699 Scope get enclosingScope => null;
13700
13701 /**
12342 * Return the element with which the given identifier is associated, or `null` if the name 13702 * Return the element with which the given identifier is associated, or `null` if the name
12343 * is not defined within this scope. 13703 * is not defined within this scope.
12344 * 13704 *
12345 * @param identifier the identifier associated with the element to be returned 13705 * @param identifier the identifier associated with the element to be returned
12346 * @param referencingLibrary the library that contains the reference to the na me, used to 13706 * @param referencingLibrary the library that contains the reference to the na me, used to
12347 * implement library-level privacy 13707 * implement library-level privacy
12348 * @return the element with which the given identifier is associated 13708 * @return the element with which the given identifier is associated
12349 */ 13709 */
12350 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo okup3(identifier, identifier.name, referencingLibrary); 13710 Element lookup(Identifier identifier, LibraryElement referencingLibrary) => lo okup3(identifier, identifier.name, referencingLibrary);
12351 13711
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
12440 String getName(Element element) { 13800 String getName(Element element) {
12441 if (element is MethodElement) { 13801 if (element is MethodElement) {
12442 MethodElement method = element as MethodElement; 13802 MethodElement method = element as MethodElement;
12443 if (method.name == "-" && method.parameters.length == 0) { 13803 if (method.name == "-" && method.parameters.length == 0) {
12444 return UNARY_MINUS; 13804 return UNARY_MINUS;
12445 } 13805 }
12446 } 13806 }
12447 return element.name; 13807 return element.name;
12448 } 13808 }
12449 } 13809 }
13810
13811 /**
13812 * Instances of the class `ScopeBuilder` build the scope for a given node in an AST structure.
13813 * At the moment, this class only handles top-level and class-level declarations .
13814 */
13815 class ScopeBuilder {
13816 /**
13817 * Return the scope in which the given AST structure should be resolved.
13818 *
13819 * @param node the root of the AST structure to be resolved
13820 * @param errorListener the listener to which analysis errors will be reported
13821 * @return the scope in which the given AST structure should be resolved
13822 * @throws AnalysisException if the AST structure has not been resolved or is not part of a
13823 * [CompilationUnit]
13824 */
13825 static Scope scopeFor(ASTNode node, AnalysisErrorListener errorListener) {
13826 if (node == null) {
13827 throw new AnalysisException.con1("Cannot create scope: node is null");
13828 } else if (node is CompilationUnit) {
13829 ScopeBuilder builder = new ScopeBuilder(errorListener);
13830 return builder.scopeForAstNode(node);
13831 }
13832 ASTNode parent = node.parent;
13833 if (parent == null) {
13834 throw new AnalysisException.con1("Cannot create scope: node is not part of a CompilationUnit");
13835 }
13836 ScopeBuilder builder = new ScopeBuilder(errorListener);
13837 return builder.scopeForAstNode(parent);
13838 }
13839
13840 /**
13841 * The listener to which analysis errors will be reported.
13842 */
13843 AnalysisErrorListener _errorListener;
13844
13845 /**
13846 * Initialize a newly created scope builder to generate a scope that will repo rt errors to the
13847 * given listener.
13848 *
13849 * @param errorListener the listener to which analysis errors will be reported
13850 */
13851 ScopeBuilder(AnalysisErrorListener errorListener) {
13852 this._errorListener = errorListener;
13853 }
13854
13855 /**
13856 * Return the scope in which the given AST structure should be resolved.
13857 *
13858 * <b>Note:</b> This method needs to be kept in sync with
13859 * [IncrementalResolver#canBeResolved].
13860 *
13861 * @param node the root of the AST structure to be resolved
13862 * @return the scope in which the given AST structure should be resolved
13863 * @throws AnalysisException if the AST structure has not been resolved or is not part of a
13864 * [CompilationUnit]
13865 */
13866 Scope scopeForAstNode(ASTNode node) {
13867 if (node is CompilationUnit) {
13868 return scopeForCompilationUnit(node as CompilationUnit);
13869 }
13870 ASTNode parent = node.parent;
13871 if (parent == null) {
13872 throw new AnalysisException.con1("Cannot create scope: node is not part of a CompilationUnit");
13873 }
13874 Scope scope = scopeForAstNode(parent);
13875 if (node is ClassDeclaration) {
13876 scope = new ClassScope(scope, (node as ClassDeclaration).element);
13877 } else if (node is ClassTypeAlias) {
13878 scope = new ClassScope(scope, (node as ClassTypeAlias).element);
13879 } else if (node is ConstructorDeclaration) {
13880 FunctionScope functionScope = new FunctionScope(scope, (node as Constructo rDeclaration).element);
13881 functionScope.defineParameters();
13882 scope = functionScope;
13883 } else if (node is FunctionDeclaration) {
13884 FunctionScope functionScope = new FunctionScope(scope, (node as FunctionDe claration).element);
13885 functionScope.defineParameters();
13886 scope = functionScope;
13887 } else if (node is FunctionTypeAlias) {
13888 scope = new FunctionTypeScope(scope, (node as FunctionTypeAlias).element);
13889 } else if (node is MethodDeclaration) {
13890 FunctionScope functionScope = new FunctionScope(scope, (node as MethodDecl aration).element);
13891 functionScope.defineParameters();
13892 scope = functionScope;
13893 }
13894 return scope;
13895 }
13896
13897 Scope scopeForCompilationUnit(CompilationUnit node) {
13898 CompilationUnitElement unitElement = node.element;
13899 if (unitElement == null) {
13900 throw new AnalysisException.con1("Cannot create scope: compilation unit is not resolved");
13901 }
13902 LibraryElement libraryElement = unitElement.library;
13903 if (libraryElement == null) {
13904 throw new AnalysisException.con1("Cannot create scope: compilation unit is not part of a library");
13905 }
13906 return new LibraryScope(libraryElement, _errorListener);
13907 }
13908 }
13909
12450 /** 13910 /**
12451 * Instances of the class `ConstantVerifier` traverse an AST structure looking f or additional 13911 * Instances of the class `ConstantVerifier` traverse an AST structure looking f or additional
12452 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors 13912 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors
12453 * and warnings related to constant expressions. 13913 * and warnings related to constant expressions.
12454 * 13914 *
12455 * @coverage dart.engine.resolver 13915 * @coverage dart.engine.resolver
12456 */ 13916 */
12457 class ConstantVerifier extends RecursiveASTVisitor<Object> { 13917 class ConstantVerifier extends RecursiveASTVisitor<Object> {
12458
12459 /** 13918 /**
12460 * The error reporter by which errors will be reported. 13919 * The error reporter by which errors will be reported.
12461 */ 13920 */
12462 ErrorReporter _errorReporter; 13921 ErrorReporter _errorReporter;
12463 13922
12464 /** 13923 /**
12465 * The type representing the type 'bool'. 13924 * The type representing the type 'bool'.
12466 */ 13925 */
12467 InterfaceType _boolType; 13926 InterfaceType _boolType;
12468 13927
(...skipping 17 matching lines...) Expand all
12486 * 13945 *
12487 * @param errorReporter the error reporter by which errors will be reported 13946 * @param errorReporter the error reporter by which errors will be reported
12488 */ 13947 */
12489 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) { 13948 ConstantVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) {
12490 this._errorReporter = errorReporter; 13949 this._errorReporter = errorReporter;
12491 this._boolType = typeProvider.boolType; 13950 this._boolType = typeProvider.boolType;
12492 this._intType = typeProvider.intType; 13951 this._intType = typeProvider.intType;
12493 this._numType = typeProvider.numType; 13952 this._numType = typeProvider.numType;
12494 this._stringType = typeProvider.stringType; 13953 this._stringType = typeProvider.stringType;
12495 } 13954 }
13955
12496 Object visitAnnotation(Annotation node) { 13956 Object visitAnnotation(Annotation node) {
12497 super.visitAnnotation(node); 13957 super.visitAnnotation(node);
12498 Element element = node.element; 13958 Element element = node.element;
12499 if (element is ConstructorElement) { 13959 if (element is ConstructorElement) {
12500 ConstructorElement constructorElement = element as ConstructorElement; 13960 ConstructorElement constructorElement = element as ConstructorElement;
12501 if (!constructorElement.isConst) { 13961 if (!constructorElement.isConst) {
12502 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION _CONSTRUCTOR, node, []); 13962 _errorReporter.reportError2(CompileTimeErrorCode.NON_CONSTANT_ANNOTATION _CONSTRUCTOR, node, []);
12503 return null; 13963 return null;
12504 } 13964 }
12505 ArgumentList argumentList = node.arguments; 13965 ArgumentList argumentList = node.arguments;
12506 if (argumentList == null) { 13966 if (argumentList == null) {
12507 _errorReporter.reportError2(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCT OR_ARGUMENTS, node, []); 13967 _errorReporter.reportError2(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCT OR_ARGUMENTS, node, []);
12508 return null; 13968 return null;
12509 } 13969 }
12510 validateConstantArguments(argumentList); 13970 validateConstantArguments(argumentList);
12511 } 13971 }
12512 return null; 13972 return null;
12513 } 13973 }
13974
12514 Object visitConstructorDeclaration(ConstructorDeclaration node) { 13975 Object visitConstructorDeclaration(ConstructorDeclaration node) {
12515 if (node.constKeyword != null) { 13976 if (node.constKeyword != null) {
12516 validateInitializers(node); 13977 validateInitializers(node);
12517 } 13978 }
12518 validateDefaultValues(node.parameters); 13979 validateDefaultValues(node.parameters);
12519 return super.visitConstructorDeclaration(node); 13980 return super.visitConstructorDeclaration(node);
12520 } 13981 }
13982
12521 Object visitFunctionExpression(FunctionExpression node) { 13983 Object visitFunctionExpression(FunctionExpression node) {
12522 super.visitFunctionExpression(node); 13984 super.visitFunctionExpression(node);
12523 validateDefaultValues(node.parameters); 13985 validateDefaultValues(node.parameters);
12524 return null; 13986 return null;
12525 } 13987 }
13988
12526 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 13989 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
12527 validateConstantArguments2(node); 13990 validateConstantArguments2(node);
12528 return super.visitInstanceCreationExpression(node); 13991 return super.visitInstanceCreationExpression(node);
12529 } 13992 }
13993
12530 Object visitListLiteral(ListLiteral node) { 13994 Object visitListLiteral(ListLiteral node) {
12531 super.visitListLiteral(node); 13995 super.visitListLiteral(node);
12532 if (node.constKeyword != null) { 13996 if (node.constKeyword != null) {
12533 for (Expression element in node.elements) { 13997 for (Expression element in node.elements) {
12534 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT); 13998 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT);
12535 } 13999 }
12536 } 14000 }
12537 return null; 14001 return null;
12538 } 14002 }
14003
12539 Object visitMapLiteral(MapLiteral node) { 14004 Object visitMapLiteral(MapLiteral node) {
12540 super.visitMapLiteral(node); 14005 super.visitMapLiteral(node);
12541 bool isConst = node.constKeyword != null; 14006 bool isConst = node.constKeyword != null;
12542 bool reportEqualKeys = true; 14007 bool reportEqualKeys = true;
12543 Set<Object> keys = new Set<Object>(); 14008 Set<Object> keys = new Set<Object>();
12544 List<Expression> invalidKeys = new List<Expression>(); 14009 List<Expression> invalidKeys = new List<Expression>();
12545 for (MapLiteralEntry entry in node.entries) { 14010 for (MapLiteralEntry entry in node.entries) {
12546 Expression key = entry.key; 14011 Expression key = entry.key;
12547 if (isConst) { 14012 if (isConst) {
12548 EvaluationResultImpl result = validate(key, CompileTimeErrorCode.NON_CON STANT_MAP_KEY); 14013 EvaluationResultImpl result = validate(key, CompileTimeErrorCode.NON_CON STANT_MAP_KEY);
12549 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); 14014 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
12550 if (result is ValidResult) { 14015 if (result is ValidResult) {
12551 Object value = ((result as ValidResult)).value; 14016 Object value = (result as ValidResult).value;
12552 if (keys.contains(value)) { 14017 if (keys.contains(value)) {
12553 invalidKeys.add(key); 14018 invalidKeys.add(key);
12554 } else { 14019 } else {
12555 javaSetAdd(keys, value); 14020 javaSetAdd(keys, value);
12556 } 14021 }
12557 } 14022 }
12558 } else { 14023 } else {
12559 EvaluationResultImpl result = key.accept(new ConstantVisitor()); 14024 EvaluationResultImpl result = key.accept(new ConstantVisitor());
12560 if (result is ValidResult) { 14025 if (result is ValidResult) {
12561 Object value = ((result as ValidResult)).value; 14026 Object value = (result as ValidResult).value;
12562 if (keys.contains(value)) { 14027 if (keys.contains(value)) {
12563 invalidKeys.add(key); 14028 invalidKeys.add(key);
12564 } else { 14029 } else {
12565 javaSetAdd(keys, value); 14030 javaSetAdd(keys, value);
12566 } 14031 }
12567 } else { 14032 } else {
12568 reportEqualKeys = false; 14033 reportEqualKeys = false;
12569 } 14034 }
12570 } 14035 }
12571 } 14036 }
12572 if (reportEqualKeys) { 14037 if (reportEqualKeys) {
12573 for (Expression key in invalidKeys) { 14038 for (Expression key in invalidKeys) {
12574 _errorReporter.reportError2(StaticWarningCode.EQUAL_KEYS_IN_MAP, key, [] ); 14039 _errorReporter.reportError2(StaticWarningCode.EQUAL_KEYS_IN_MAP, key, [] );
12575 } 14040 }
12576 } 14041 }
12577 return null; 14042 return null;
12578 } 14043 }
14044
12579 Object visitMethodDeclaration(MethodDeclaration node) { 14045 Object visitMethodDeclaration(MethodDeclaration node) {
12580 super.visitMethodDeclaration(node); 14046 super.visitMethodDeclaration(node);
12581 validateDefaultValues(node.parameters); 14047 validateDefaultValues(node.parameters);
12582 return null; 14048 return null;
12583 } 14049 }
14050
12584 Object visitSwitchCase(SwitchCase node) { 14051 Object visitSwitchCase(SwitchCase node) {
12585 super.visitSwitchCase(node); 14052 super.visitSwitchCase(node);
12586 validate(node.expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION) ; 14053 validate(node.expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION) ;
12587 return null; 14054 return null;
12588 } 14055 }
14056
12589 Object visitVariableDeclaration(VariableDeclaration node) { 14057 Object visitVariableDeclaration(VariableDeclaration node) {
12590 super.visitVariableDeclaration(node); 14058 super.visitVariableDeclaration(node);
12591 Expression initializer = node.initializer; 14059 Expression initializer = node.initializer;
12592 if (initializer != null && node.isConst) { 14060 if (initializer != null && node.isConst) {
12593 VariableElementImpl element = node.element as VariableElementImpl; 14061 VariableElementImpl element = node.element as VariableElementImpl;
12594 EvaluationResultImpl result = element.evaluationResult; 14062 EvaluationResultImpl result = element.evaluationResult;
12595 if (result == null) { 14063 if (result == null) {
12596 result = validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_WI TH_NON_CONSTANT_VALUE); 14064 result = validate(initializer, CompileTimeErrorCode.CONST_INITIALIZED_WI TH_NON_CONSTANT_VALUE);
12597 element.evaluationResult = result; 14065 element.evaluationResult = result;
12598 } else if (result is ErrorResult) { 14066 } else if (result is ErrorResult) {
12599 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON STANT_VALUE); 14067 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON STANT_VALUE);
12600 } 14068 }
12601 } 14069 }
12602 return null; 14070 return null;
12603 } 14071 }
12604 14072
12605 /** 14073 /**
12606 * If the given result represents one or more errors, report those errors. Exc ept for special 14074 * If the given result represents one or more errors, report those errors. Exc ept for special
12607 * cases, use the given error code rather than the one reported in the error. 14075 * cases, use the given error code rather than the one reported in the error.
12608 * 14076 *
12609 * @param result the result containing any errors that need to be reported 14077 * @param result the result containing any errors that need to be reported
12610 * @param errorCode the error code to be used if the result represents an erro r 14078 * @param errorCode the error code to be used if the result represents an erro r
12611 */ 14079 */
12612 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode) { 14080 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode) {
12613 if (result is ErrorResult) { 14081 if (result is ErrorResult) {
12614 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { 14082 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) {
12615 ErrorCode dataErrorCode = data.errorCode; 14083 ErrorCode dataErrorCode = data.errorCode;
12616 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRIN G) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || ide ntical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identical(dat aErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) { 14084 if (identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCE PTION) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRIN G) || identical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) || ide ntical(dataErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) || identical(dat aErrorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM)) {
12617 _errorReporter.reportError2(dataErrorCode, data.node, []); 14085 _errorReporter.reportError2(dataErrorCode, data.node, []);
12618 } else { 14086 } else {
12619 _errorReporter.reportError2(errorCode, data.node, []); 14087 _errorReporter.reportError2(errorCode, data.node, []);
12620 } 14088 }
12621 } 14089 }
12622 } 14090 }
12623 } 14091 }
12624 14092
(...skipping 12 matching lines...) Expand all
12637 } 14105 }
12638 14106
12639 /** 14107 /**
12640 * Validate that if the passed arguments are constant expressions. 14108 * Validate that if the passed arguments are constant expressions.
12641 * 14109 *
12642 * @param argumentList the argument list to evaluate 14110 * @param argumentList the argument list to evaluate
12643 */ 14111 */
12644 void validateConstantArguments(ArgumentList argumentList) { 14112 void validateConstantArguments(ArgumentList argumentList) {
12645 for (Expression argument in argumentList.arguments) { 14113 for (Expression argument in argumentList.arguments) {
12646 if (argument is NamedExpression) { 14114 if (argument is NamedExpression) {
12647 argument = ((argument as NamedExpression)).expression; 14115 argument = (argument as NamedExpression).expression;
12648 } 14116 }
12649 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT); 14117 validate(argument, CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT);
12650 } 14118 }
12651 } 14119 }
12652 14120
12653 /** 14121 /**
12654 * Validate that if the passed instance creation is 'const' then all its argum ents are constant 14122 * Validate that if the passed instance creation is 'const' then all its argum ents are constant
12655 * expressions. 14123 * expressions.
12656 * 14124 *
12657 * @param node the instance creation evaluate 14125 * @param node the instance creation evaluate
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
12691 } 14159 }
12692 14160
12693 /** 14161 /**
12694 * Validates that the given expression is a compile time constant. 14162 * Validates that the given expression is a compile time constant.
12695 * 14163 *
12696 * @param parameterElements the elements of parameters of constant constructor , they are 14164 * @param parameterElements the elements of parameters of constant constructor , they are
12697 * considered as a valid potentially constant expressions 14165 * considered as a valid potentially constant expressions
12698 * @param expression the expression to validate 14166 * @param expression the expression to validate
12699 */ 14167 */
12700 void validateInitializerExpression(List<ParameterElement> parameterElements, E xpression expression) { 14168 void validateInitializerExpression(List<ParameterElement> parameterElements, E xpression expression) {
12701 EvaluationResultImpl result = expression.accept(new ConstantVisitor_13(this, parameterElements)); 14169 EvaluationResultImpl result = expression.accept(new ConstantVisitor_14(this, parameterElements));
12702 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER) ; 14170 reportErrors(result, CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER) ;
12703 } 14171 }
12704 14172
12705 /** 14173 /**
12706 * Validates that all of the arguments of a constructor initializer are compil e time constants. 14174 * Validates that all of the arguments of a constructor initializer are compil e time constants.
12707 * 14175 *
12708 * @param parameterElements the elements of parameters of constant constructor , they are 14176 * @param parameterElements the elements of parameters of constant constructor , they are
12709 * considered as a valid potentially constant expressions 14177 * considered as a valid potentially constant expressions
12710 * @param argumentList the argument list to validate 14178 * @param argumentList the argument list to validate
12711 */ 14179 */
(...skipping 24 matching lines...) Expand all
12736 RedirectingConstructorInvocation invocation = initializer as Redirecting ConstructorInvocation; 14204 RedirectingConstructorInvocation invocation = initializer as Redirecting ConstructorInvocation;
12737 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 14205 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
12738 } 14206 }
12739 if (initializer is SuperConstructorInvocation) { 14207 if (initializer is SuperConstructorInvocation) {
12740 SuperConstructorInvocation invocation = initializer as SuperConstructorI nvocation; 14208 SuperConstructorInvocation invocation = initializer as SuperConstructorI nvocation;
12741 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList); 14209 validateInitializerInvocationArguments(parameterElements, invocation.arg umentList);
12742 } 14210 }
12743 } 14211 }
12744 } 14212 }
12745 } 14213 }
12746 class ConstantVisitor_13 extends ConstantVisitor { 14214
14215 class ConstantVisitor_14 extends ConstantVisitor {
12747 final ConstantVerifier ConstantVerifier_this; 14216 final ConstantVerifier ConstantVerifier_this;
14217
12748 List<ParameterElement> parameterElements; 14218 List<ParameterElement> parameterElements;
12749 ConstantVisitor_13(this.ConstantVerifier_this, this.parameterElements) : super (); 14219
14220 ConstantVisitor_14(this.ConstantVerifier_this, this.parameterElements) : super ();
14221
12750 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { 14222 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) {
12751 Element element = node.staticElement; 14223 Element element = node.staticElement;
12752 for (ParameterElement parameterElement in parameterElements) { 14224 for (ParameterElement parameterElement in parameterElements) {
12753 if (identical(parameterElement, element) && parameterElement != null) { 14225 if (identical(parameterElement, element) && parameterElement != null) {
12754 Type2 type = parameterElement.type; 14226 Type2 type = parameterElement.type;
12755 if (type != null) { 14227 if (type != null) {
12756 if (type.isDynamic) { 14228 if (type.isDynamic) {
12757 return ValidResult.RESULT_DYNAMIC; 14229 return ValidResult.RESULT_DYNAMIC;
12758 } 14230 }
12759 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) { 14231 if (type.isSubtypeOf(ConstantVerifier_this._boolType)) {
12760 return ValidResult.RESULT_BOOL; 14232 return ValidResult.RESULT_BOOL;
12761 } 14233 }
12762 if (type.isSubtypeOf(ConstantVerifier_this._intType)) { 14234 if (type.isSubtypeOf(ConstantVerifier_this._intType)) {
12763 return ValidResult.RESULT_INT; 14235 return ValidResult.RESULT_INT;
12764 } 14236 }
12765 if (type.isSubtypeOf(ConstantVerifier_this._numType)) { 14237 if (type.isSubtypeOf(ConstantVerifier_this._numType)) {
12766 return ValidResult.RESULT_NUM; 14238 return ValidResult.RESULT_NUM;
12767 } 14239 }
12768 if (type.isSubtypeOf(ConstantVerifier_this._stringType)) { 14240 if (type.isSubtypeOf(ConstantVerifier_this._stringType)) {
12769 return ValidResult.RESULT_STRING; 14241 return ValidResult.RESULT_STRING;
12770 } 14242 }
12771 } 14243 }
12772 return ValidResult.RESULT_OBJECT; 14244 return ValidResult.RESULT_OBJECT;
12773 } 14245 }
12774 } 14246 }
12775 return super.visitSimpleIdentifier(node); 14247 return super.visitSimpleIdentifier(node);
12776 } 14248 }
12777 } 14249 }
14250
12778 /** 14251 /**
12779 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional 14252 * Instances of the class `ErrorVerifier` traverse an AST structure looking for additional
12780 * errors and warnings not covered by the parser and resolver. 14253 * errors and warnings not covered by the parser and resolver.
12781 * 14254 *
12782 * @coverage dart.engine.resolver 14255 * @coverage dart.engine.resolver
12783 */ 14256 */
12784 class ErrorVerifier extends RecursiveASTVisitor<Object> { 14257 class ErrorVerifier extends RecursiveASTVisitor<Object> {
12785
12786 /**
12787 * Checks if the given expression is the reference to the type.
12788 *
12789 * @param expr the expression to evaluate
12790 * @return `true` if the given expression is the reference to the type
12791 */
12792 static bool isTypeReference(Expression expr) {
12793 if (expr is Identifier) {
12794 Identifier identifier = expr as Identifier;
12795 return identifier.staticElement is ClassElement;
12796 }
12797 return false;
12798 }
12799
12800 /** 14258 /**
12801 * The error reporter by which errors will be reported. 14259 * The error reporter by which errors will be reported.
12802 */ 14260 */
12803 ErrorReporter _errorReporter; 14261 ErrorReporter _errorReporter;
12804 14262
12805 /** 14263 /**
12806 * The current library that is being analyzed. 14264 * The current library that is being analyzed.
12807 */ 14265 */
12808 LibraryElement _currentLibrary; 14266 LibraryElement _currentLibrary;
12809 14267
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
12953 * A table mapping name of the library to the export directive which export th is library. 14411 * A table mapping name of the library to the export directive which export th is library.
12954 */ 14412 */
12955 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem ent>(); 14413 Map<String, LibraryElement> _nameToExportElement = new Map<String, LibraryElem ent>();
12956 14414
12957 /** 14415 /**
12958 * A table mapping name of the library to the import directive which import th is library. 14416 * A table mapping name of the library to the import directive which import th is library.
12959 */ 14417 */
12960 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem ent>(); 14418 Map<String, LibraryElement> _nameToImportElement = new Map<String, LibraryElem ent>();
12961 14419
12962 /** 14420 /**
12963 * A table mapping names to the export elements exported them. 14421 * A table mapping names to the exported elements.
12964 */ 14422 */
12965 Map<String, ExportElement> _exportedNames = new Map<String, ExportElement>(); 14423 Map<String, Element> _exportedElements = new Map<String, Element>();
12966 14424
12967 /** 14425 /**
12968 * A set of the names of the variable initializers we are visiting now. 14426 * A set of the names of the variable initializers we are visiting now.
12969 */ 14427 */
12970 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String >(); 14428 Set<String> _namesForReferenceToDeclaredVariableInInitializer = new Set<String >();
12971 14429
12972 /** 14430 /**
12973 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS] and 14431 * A list of types used by the [CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS] and
12974 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes. 14432 * [CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS] error codes.
12975 */ 14433 */
12976 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 14434 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
14435
12977 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider, InheritanceManager inheritanceManager) { 14436 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider, InheritanceManager inheritanceManager) {
12978 this._errorReporter = errorReporter; 14437 this._errorReporter = errorReporter;
12979 this._currentLibrary = currentLibrary; 14438 this._currentLibrary = currentLibrary;
12980 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary; 14439 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary;
12981 this._typeProvider = typeProvider; 14440 this._typeProvider = typeProvider;
12982 this._inheritanceManager = inheritanceManager; 14441 this._inheritanceManager = inheritanceManager;
12983 _strictMode = currentLibrary.context.analysisOptions.strictMode; 14442 _strictMode = currentLibrary.context.analysisOptions.strictMode;
12984 _isEnclosingConstructorConst = false; 14443 _isEnclosingConstructorConst = false;
12985 _isInCatchClause = false; 14444 _isInCatchClause = false;
12986 _isInStaticVariableDeclaration = false; 14445 _isInStaticVariableDeclaration = false;
12987 _isInInstanceVariableDeclaration = false; 14446 _isInInstanceVariableDeclaration = false;
12988 _isInInstanceVariableInitializer = false; 14447 _isInInstanceVariableInitializer = false;
12989 _isInConstructorInitializer = false; 14448 _isInConstructorInitializer = false;
12990 _isInStaticMethod = false; 14449 _isInStaticMethod = false;
12991 _boolType = typeProvider.boolType; 14450 _boolType = typeProvider.boolType;
12992 _dynamicType = typeProvider.dynamicType; 14451 _dynamicType = typeProvider.dynamicType;
12993 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [ 14452 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [
12994 typeProvider.nullType, 14453 typeProvider.nullType,
12995 typeProvider.numType, 14454 typeProvider.numType,
12996 typeProvider.intType, 14455 typeProvider.intType,
12997 typeProvider.doubleType, 14456 typeProvider.doubleType,
12998 _boolType, 14457 _boolType,
12999 typeProvider.stringType]; 14458 typeProvider.stringType];
13000 } 14459 }
14460
13001 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { 14461 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
13002 checkForArgumentDefinitionTestNonParameter(node); 14462 checkForArgumentDefinitionTestNonParameter(node);
13003 return super.visitArgumentDefinitionTest(node); 14463 return super.visitArgumentDefinitionTest(node);
13004 } 14464 }
14465
13005 Object visitArgumentList(ArgumentList node) { 14466 Object visitArgumentList(ArgumentList node) {
13006 checkForArgumentTypeNotAssignable(node); 14467 checkForArgumentTypeNotAssignable(node);
13007 return super.visitArgumentList(node); 14468 return super.visitArgumentList(node);
13008 } 14469 }
14470
13009 Object visitAssertStatement(AssertStatement node) { 14471 Object visitAssertStatement(AssertStatement node) {
13010 checkForNonBoolExpression(node); 14472 checkForNonBoolExpression(node);
13011 return super.visitAssertStatement(node); 14473 return super.visitAssertStatement(node);
13012 } 14474 }
14475
13013 Object visitAssignmentExpression(AssignmentExpression node) { 14476 Object visitAssignmentExpression(AssignmentExpression node) {
13014 sc.Token operator = node.operator; 14477 sc.Token operator = node.operator;
13015 sc.TokenType operatorType = operator.type; 14478 sc.TokenType operatorType = operator.type;
13016 if (identical(operatorType, sc.TokenType.EQ)) { 14479 if (identical(operatorType, sc.TokenType.EQ)) {
13017 checkForInvalidAssignment2(node.leftHandSide, node.rightHandSide); 14480 checkForInvalidAssignment2(node.leftHandSide, node.rightHandSide);
13018 } else { 14481 } else {
13019 checkForInvalidAssignment(node); 14482 checkForInvalidAssignment(node);
13020 } 14483 }
13021 checkForAssignmentToFinal(node); 14484 checkForAssignmentToFinal(node);
13022 checkForArgumentTypeNotAssignable2(node.rightHandSide); 14485 checkForArgumentTypeNotAssignable2(node.rightHandSide);
13023 return super.visitAssignmentExpression(node); 14486 return super.visitAssignmentExpression(node);
13024 } 14487 }
14488
13025 Object visitBinaryExpression(BinaryExpression node) { 14489 Object visitBinaryExpression(BinaryExpression node) {
13026 checkForArgumentTypeNotAssignable2(node.rightOperand); 14490 checkForArgumentTypeNotAssignable2(node.rightOperand);
13027 return super.visitBinaryExpression(node); 14491 return super.visitBinaryExpression(node);
13028 } 14492 }
14493
13029 Object visitBlockFunctionBody(BlockFunctionBody node) { 14494 Object visitBlockFunctionBody(BlockFunctionBody node) {
13030 int previousReturnWithCount = _returnWithCount; 14495 int previousReturnWithCount = _returnWithCount;
13031 int previousReturnWithoutCount = _returnWithoutCount; 14496 int previousReturnWithoutCount = _returnWithoutCount;
13032 try { 14497 try {
13033 _returnWithCount = 0; 14498 _returnWithCount = 0;
13034 _returnWithoutCount = 0; 14499 _returnWithoutCount = 0;
13035 super.visitBlockFunctionBody(node); 14500 super.visitBlockFunctionBody(node);
13036 checkForMixedReturns(node); 14501 checkForMixedReturns(node);
13037 } finally { 14502 } finally {
13038 _returnWithCount = previousReturnWithCount; 14503 _returnWithCount = previousReturnWithCount;
13039 _returnWithoutCount = previousReturnWithoutCount; 14504 _returnWithoutCount = previousReturnWithoutCount;
13040 } 14505 }
13041 return null; 14506 return null;
13042 } 14507 }
14508
13043 Object visitCatchClause(CatchClause node) { 14509 Object visitCatchClause(CatchClause node) {
13044 bool previousIsInCatchClause = _isInCatchClause; 14510 bool previousIsInCatchClause = _isInCatchClause;
13045 try { 14511 try {
13046 _isInCatchClause = true; 14512 _isInCatchClause = true;
13047 return super.visitCatchClause(node); 14513 return super.visitCatchClause(node);
13048 } finally { 14514 } finally {
13049 _isInCatchClause = previousIsInCatchClause; 14515 _isInCatchClause = previousIsInCatchClause;
13050 } 14516 }
13051 } 14517 }
14518
13052 Object visitClassDeclaration(ClassDeclaration node) { 14519 Object visitClassDeclaration(ClassDeclaration node) {
13053 ClassElement outerClass = _enclosingClass; 14520 ClassElement outerClass = _enclosingClass;
13054 try { 14521 try {
13055 _isInNativeClass = node.nativeClause != null; 14522 _isInNativeClass = node.nativeClause != null;
13056 _enclosingClass = node.element; 14523 _enclosingClass = node.element;
13057 WithClause withClause = node.withClause; 14524 WithClause withClause = node.withClause;
13058 ImplementsClause implementsClause = node.implementsClause; 14525 ImplementsClause implementsClause = node.implementsClause;
13059 ExtendsClause extendsClause = node.extendsClause; 14526 ExtendsClause extendsClause = node.extendsClause;
13060 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME); 14527 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME);
13061 checkForMemberWithClassName(); 14528 checkForMemberWithClassName();
(...skipping 13 matching lines...) Expand all
13075 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>(); 14542 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>();
13076 for (FieldElement fieldElement in fieldElements) { 14543 for (FieldElement fieldElement in fieldElements) {
13077 if (!fieldElement.isSynthetic) { 14544 if (!fieldElement.isSynthetic) {
13078 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION; 14545 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION;
13079 } 14546 }
13080 } 14547 }
13081 } 14548 }
13082 checkForFinalNotInitialized(node); 14549 checkForFinalNotInitialized(node);
13083 checkForDuplicateDefinitionInheritance(); 14550 checkForDuplicateDefinitionInheritance();
13084 checkForConflictingGetterAndMethod(); 14551 checkForConflictingGetterAndMethod();
14552 checkForConflictingInstanceGetterAndSuperclassMember();
13085 checkImplementsSuperClass(node); 14553 checkImplementsSuperClass(node);
13086 checkImplementsFunctionWithoutCall(node); 14554 checkImplementsFunctionWithoutCall(node);
13087 return super.visitClassDeclaration(node); 14555 return super.visitClassDeclaration(node);
13088 } finally { 14556 } finally {
13089 _isInNativeClass = false; 14557 _isInNativeClass = false;
13090 _initialFieldElementsMap = null; 14558 _initialFieldElementsMap = null;
13091 _enclosingClass = outerClass; 14559 _enclosingClass = outerClass;
13092 } 14560 }
13093 } 14561 }
14562
13094 Object visitClassTypeAlias(ClassTypeAlias node) { 14563 Object visitClassTypeAlias(ClassTypeAlias node) {
13095 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 14564 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
13096 checkForAllMixinErrorCodes(node.withClause); 14565 checkForAllMixinErrorCodes(node.withClause);
13097 ClassElement outerClassElement = _enclosingClass; 14566 ClassElement outerClassElement = _enclosingClass;
13098 try { 14567 try {
13099 _enclosingClass = node.element; 14568 _enclosingClass = node.element;
13100 checkForRecursiveInterfaceInheritance(node.element); 14569 checkForRecursiveInterfaceInheritance(node.element);
13101 checkForTypeAliasCannotReferenceItself_mixin(node); 14570 checkForTypeAliasCannotReferenceItself_mixin(node);
13102 } finally { 14571 } finally {
13103 _enclosingClass = outerClassElement; 14572 _enclosingClass = outerClassElement;
13104 } 14573 }
13105 return super.visitClassTypeAlias(node); 14574 return super.visitClassTypeAlias(node);
13106 } 14575 }
14576
13107 Object visitComment(Comment node) { 14577 Object visitComment(Comment node) {
13108 _isInComment = true; 14578 _isInComment = true;
13109 try { 14579 try {
13110 return super.visitComment(node); 14580 return super.visitComment(node);
13111 } finally { 14581 } finally {
13112 _isInComment = false; 14582 _isInComment = false;
13113 } 14583 }
13114 } 14584 }
14585
13115 Object visitConditionalExpression(ConditionalExpression node) { 14586 Object visitConditionalExpression(ConditionalExpression node) {
13116 checkForNonBoolCondition(node.condition); 14587 checkForNonBoolCondition(node.condition);
13117 return super.visitConditionalExpression(node); 14588 return super.visitConditionalExpression(node);
13118 } 14589 }
14590
13119 Object visitConstructorDeclaration(ConstructorDeclaration node) { 14591 Object visitConstructorDeclaration(ConstructorDeclaration node) {
13120 ExecutableElement outerFunction = _enclosingFunction; 14592 ExecutableElement outerFunction = _enclosingFunction;
13121 try { 14593 try {
13122 _enclosingFunction = node.element; 14594 _enclosingFunction = node.element;
13123 _isEnclosingConstructorConst = node.constKeyword != null; 14595 _isEnclosingConstructorConst = node.constKeyword != null;
13124 checkForConstConstructorWithNonFinalField(node); 14596 checkForConstConstructorWithNonFinalField(node);
13125 checkForConstConstructorWithNonConstSuper(node); 14597 checkForConstConstructorWithNonConstSuper(node);
13126 checkForConflictingConstructorNameAndMember(node); 14598 checkForConflictingConstructorNameAndMember(node);
13127 checkForAllFinalInitializedErrorCodes(node); 14599 checkForAllFinalInitializedErrorCodes(node);
13128 checkForRedirectingConstructorErrorCodes(node); 14600 checkForRedirectingConstructorErrorCodes(node);
13129 checkForMultipleSuperInitializers(node); 14601 checkForMultipleSuperInitializers(node);
13130 checkForRecursiveConstructorRedirect(node); 14602 checkForRecursiveConstructorRedirect(node);
13131 if (!checkForRecursiveFactoryRedirect(node)) { 14603 if (!checkForRecursiveFactoryRedirect(node)) {
13132 checkForAllRedirectConstructorErrorCodes(node); 14604 checkForAllRedirectConstructorErrorCodes(node);
13133 } 14605 }
13134 checkForUndefinedConstructorInInitializerImplicit(node); 14606 checkForUndefinedConstructorInInitializerImplicit(node);
13135 checkForRedirectToNonConstConstructor(node); 14607 checkForRedirectToNonConstConstructor(node);
13136 checkForReturnInGenerativeConstructor(node); 14608 checkForReturnInGenerativeConstructor(node);
13137 return super.visitConstructorDeclaration(node); 14609 return super.visitConstructorDeclaration(node);
13138 } finally { 14610 } finally {
13139 _isEnclosingConstructorConst = false; 14611 _isEnclosingConstructorConst = false;
13140 _enclosingFunction = outerFunction; 14612 _enclosingFunction = outerFunction;
13141 } 14613 }
13142 } 14614 }
14615
13143 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { 14616 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
13144 _isInConstructorInitializer = true; 14617 _isInConstructorInitializer = true;
13145 try { 14618 try {
13146 checkForFieldInitializerNotAssignable(node); 14619 checkForFieldInitializerNotAssignable(node);
13147 return super.visitConstructorFieldInitializer(node); 14620 return super.visitConstructorFieldInitializer(node);
13148 } finally { 14621 } finally {
13149 _isInConstructorInitializer = false; 14622 _isInConstructorInitializer = false;
13150 } 14623 }
13151 } 14624 }
14625
13152 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 14626 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
13153 checkForInvalidAssignment2(node.identifier, node.defaultValue); 14627 checkForInvalidAssignment2(node.identifier, node.defaultValue);
13154 checkForDefaultValueInFunctionTypedParameter(node); 14628 checkForDefaultValueInFunctionTypedParameter(node);
13155 return super.visitDefaultFormalParameter(node); 14629 return super.visitDefaultFormalParameter(node);
13156 } 14630 }
14631
13157 Object visitDoStatement(DoStatement node) { 14632 Object visitDoStatement(DoStatement node) {
13158 checkForNonBoolCondition(node.condition); 14633 checkForNonBoolCondition(node.condition);
13159 return super.visitDoStatement(node); 14634 return super.visitDoStatement(node);
13160 } 14635 }
14636
13161 Object visitExportDirective(ExportDirective node) { 14637 Object visitExportDirective(ExportDirective node) {
13162 checkForAmbiguousExport(node); 14638 checkForAmbiguousExport(node);
13163 checkForExportDuplicateLibraryName(node); 14639 checkForExportDuplicateLibraryName(node);
13164 checkForExportInternalLibrary(node); 14640 checkForExportInternalLibrary(node);
13165 return super.visitExportDirective(node); 14641 return super.visitExportDirective(node);
13166 } 14642 }
14643
13167 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 14644 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
13168 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type; 14645 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
13169 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType; 14646 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType;
13170 checkForReturnOfInvalidType(node.expression, expectedReturnType); 14647 checkForReturnOfInvalidType(node.expression, expectedReturnType);
13171 return super.visitExpressionFunctionBody(node); 14648 return super.visitExpressionFunctionBody(node);
13172 } 14649 }
14650
13173 Object visitFieldDeclaration(FieldDeclaration node) { 14651 Object visitFieldDeclaration(FieldDeclaration node) {
13174 if (!node.isStatic) { 14652 if (!node.isStatic) {
13175 VariableDeclarationList variables = node.fields; 14653 VariableDeclarationList variables = node.fields;
13176 if (variables.isConst) { 14654 if (variables.isConst) {
13177 _errorReporter.reportError4(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v ariables.keyword, []); 14655 _errorReporter.reportError5(CompileTimeErrorCode.CONST_INSTANCE_FIELD, v ariables.keyword, []);
13178 } 14656 }
13179 } 14657 }
13180 _isInStaticVariableDeclaration = node.isStatic; 14658 _isInStaticVariableDeclaration = node.isStatic;
13181 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; 14659 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration;
13182 try { 14660 try {
13183 checkForAllInvalidOverrideErrorCodes2(node); 14661 checkForAllInvalidOverrideErrorCodes2(node);
13184 return super.visitFieldDeclaration(node); 14662 return super.visitFieldDeclaration(node);
13185 } finally { 14663 } finally {
13186 _isInStaticVariableDeclaration = false; 14664 _isInStaticVariableDeclaration = false;
13187 _isInInstanceVariableDeclaration = false; 14665 _isInInstanceVariableDeclaration = false;
13188 } 14666 }
13189 } 14667 }
14668
13190 Object visitFieldFormalParameter(FieldFormalParameter node) { 14669 Object visitFieldFormalParameter(FieldFormalParameter node) {
13191 checkForConstFormalParameter(node); 14670 checkForConstFormalParameter(node);
13192 checkForPrivateOptionalParameter(node); 14671 checkForPrivateOptionalParameter(node);
13193 checkForFieldInitializingFormalRedirectingConstructor(node); 14672 checkForFieldInitializingFormalRedirectingConstructor(node);
13194 return super.visitFieldFormalParameter(node); 14673 return super.visitFieldFormalParameter(node);
13195 } 14674 }
14675
13196 Object visitFunctionDeclaration(FunctionDeclaration node) { 14676 Object visitFunctionDeclaration(FunctionDeclaration node) {
13197 ExecutableElement outerFunction = _enclosingFunction; 14677 ExecutableElement outerFunction = _enclosingFunction;
13198 try { 14678 try {
13199 SimpleIdentifier identifier = node.name; 14679 SimpleIdentifier identifier = node.name;
13200 String methodName = ""; 14680 String methodName = "";
13201 if (identifier != null) { 14681 if (identifier != null) {
13202 methodName = identifier.name; 14682 methodName = identifier.name;
13203 } 14683 }
13204 _enclosingFunction = node.element; 14684 _enclosingFunction = node.element;
13205 if (node.isSetter || node.isGetter) { 14685 if (node.isSetter || node.isGetter) {
13206 checkForMismatchedAccessorTypes(node, methodName); 14686 checkForMismatchedAccessorTypes(node, methodName);
13207 if (node.isSetter) { 14687 if (node.isSetter) {
13208 FunctionExpression functionExpression = node.functionExpression; 14688 FunctionExpression functionExpression = node.functionExpression;
13209 if (functionExpression != null) { 14689 if (functionExpression != null) {
13210 checkForWrongNumberOfParametersForSetter(node.name, functionExpressi on.parameters); 14690 checkForWrongNumberOfParametersForSetter(node.name, functionExpressi on.parameters);
13211 } 14691 }
13212 TypeName returnType = node.returnType; 14692 TypeName returnType = node.returnType;
13213 checkForNonVoidReturnTypeForSetter(returnType); 14693 checkForNonVoidReturnTypeForSetter(returnType);
13214 } 14694 }
13215 } 14695 }
13216 return super.visitFunctionDeclaration(node); 14696 return super.visitFunctionDeclaration(node);
13217 } finally { 14697 } finally {
13218 _enclosingFunction = outerFunction; 14698 _enclosingFunction = outerFunction;
13219 } 14699 }
13220 } 14700 }
14701
13221 Object visitFunctionExpression(FunctionExpression node) { 14702 Object visitFunctionExpression(FunctionExpression node) {
13222 if (node.parent is! FunctionDeclaration) { 14703 if (node.parent is! FunctionDeclaration) {
13223 ExecutableElement outerFunction = _enclosingFunction; 14704 ExecutableElement outerFunction = _enclosingFunction;
13224 try { 14705 try {
13225 _enclosingFunction = node.element; 14706 _enclosingFunction = node.element;
13226 return super.visitFunctionExpression(node); 14707 return super.visitFunctionExpression(node);
13227 } finally { 14708 } finally {
13228 _enclosingFunction = outerFunction; 14709 _enclosingFunction = outerFunction;
13229 } 14710 }
13230 } else { 14711 } else {
13231 return super.visitFunctionExpression(node); 14712 return super.visitFunctionExpression(node);
13232 } 14713 }
13233 } 14714 }
14715
13234 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 14716 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
13235 Expression functionExpression = node.function; 14717 Expression functionExpression = node.function;
13236 Type2 expressionType = functionExpression.staticType; 14718 Type2 expressionType = functionExpression.staticType;
13237 if (!isFunctionType(expressionType)) { 14719 if (!isFunctionType(expressionType)) {
13238 _errorReporter.reportError2(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON_EXPRESSION, functionExpression, []); 14720 _errorReporter.reportError2(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON_EXPRESSION, functionExpression, []);
13239 } 14721 }
13240 return super.visitFunctionExpressionInvocation(node); 14722 return super.visitFunctionExpressionInvocation(node);
13241 } 14723 }
14724
13242 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 14725 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
13243 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 14726 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
13244 checkForDefaultValueInFunctionTypeAlias(node); 14727 checkForDefaultValueInFunctionTypeAlias(node);
13245 checkForTypeAliasCannotReferenceItself_function(node); 14728 checkForTypeAliasCannotReferenceItself_function(node);
13246 return super.visitFunctionTypeAlias(node); 14729 return super.visitFunctionTypeAlias(node);
13247 } 14730 }
14731
13248 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 14732 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
13249 bool old = _isInFunctionTypedFormalParameter; 14733 bool old = _isInFunctionTypedFormalParameter;
13250 _isInFunctionTypedFormalParameter = true; 14734 _isInFunctionTypedFormalParameter = true;
13251 try { 14735 try {
13252 return super.visitFunctionTypedFormalParameter(node); 14736 return super.visitFunctionTypedFormalParameter(node);
13253 } finally { 14737 } finally {
13254 _isInFunctionTypedFormalParameter = old; 14738 _isInFunctionTypedFormalParameter = old;
13255 } 14739 }
13256 } 14740 }
14741
13257 Object visitIfStatement(IfStatement node) { 14742 Object visitIfStatement(IfStatement node) {
13258 checkForNonBoolCondition(node.condition); 14743 checkForNonBoolCondition(node.condition);
13259 return super.visitIfStatement(node); 14744 return super.visitIfStatement(node);
13260 } 14745 }
14746
13261 Object visitImportDirective(ImportDirective node) { 14747 Object visitImportDirective(ImportDirective node) {
13262 checkForImportDuplicateLibraryName(node); 14748 checkForImportDuplicateLibraryName(node);
13263 checkForImportInternalLibrary(node); 14749 checkForImportInternalLibrary(node);
13264 return super.visitImportDirective(node); 14750 return super.visitImportDirective(node);
13265 } 14751 }
14752
13266 Object visitIndexExpression(IndexExpression node) { 14753 Object visitIndexExpression(IndexExpression node) {
13267 checkForArgumentTypeNotAssignable2(node.index); 14754 checkForArgumentTypeNotAssignable2(node.index);
13268 return super.visitIndexExpression(node); 14755 return super.visitIndexExpression(node);
13269 } 14756 }
14757
13270 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 14758 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
13271 _isInConstInstanceCreation = node.isConst; 14759 _isInConstInstanceCreation = node.isConst;
13272 try { 14760 try {
13273 ConstructorName constructorName = node.constructorName; 14761 ConstructorName constructorName = node.constructorName;
13274 TypeName typeName = constructorName.type; 14762 TypeName typeName = constructorName.type;
13275 Type2 type = typeName.type; 14763 Type2 type = typeName.type;
13276 if (type is InterfaceType) { 14764 if (type is InterfaceType) {
13277 InterfaceType interfaceType = type as InterfaceType; 14765 InterfaceType interfaceType = type as InterfaceType;
13278 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); 14766 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
13279 if (_isInConstInstanceCreation) { 14767 if (_isInConstInstanceCreation) {
13280 checkForConstWithNonConst(node); 14768 checkForConstWithNonConst(node);
13281 checkForConstWithUndefinedConstructor(node); 14769 checkForConstWithUndefinedConstructor(node);
13282 checkForConstWithTypeParameters(node); 14770 checkForConstWithTypeParameters(node);
13283 } else { 14771 } else {
13284 checkForNewWithUndefinedConstructor(node); 14772 checkForNewWithUndefinedConstructor(node);
13285 } 14773 }
13286 } 14774 }
13287 return super.visitInstanceCreationExpression(node); 14775 return super.visitInstanceCreationExpression(node);
13288 } finally { 14776 } finally {
13289 _isInConstInstanceCreation = false; 14777 _isInConstInstanceCreation = false;
13290 } 14778 }
13291 } 14779 }
14780
13292 Object visitListLiteral(ListLiteral node) { 14781 Object visitListLiteral(ListLiteral node) {
13293 if (node.constKeyword != null) { 14782 if (node.constKeyword != null) {
13294 TypeArgumentList typeArguments = node.typeArguments; 14783 TypeArgumentList typeArguments = node.typeArguments;
13295 if (typeArguments != null) { 14784 if (typeArguments != null) {
13296 NodeList<TypeName> arguments = typeArguments.arguments; 14785 NodeList<TypeName> arguments = typeArguments.arguments;
13297 if (arguments.length != 0) { 14786 if (arguments.length != 0) {
13298 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 14787 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
13299 } 14788 }
13300 } 14789 }
13301 } 14790 }
13302 checkForExpectedOneListTypeArgument(node); 14791 checkForExpectedOneListTypeArgument(node);
13303 checkForListElementTypeNotAssignable(node); 14792 checkForListElementTypeNotAssignable(node);
13304 return super.visitListLiteral(node); 14793 return super.visitListLiteral(node);
13305 } 14794 }
14795
13306 Object visitMapLiteral(MapLiteral node) { 14796 Object visitMapLiteral(MapLiteral node) {
13307 TypeArgumentList typeArguments = node.typeArguments; 14797 TypeArgumentList typeArguments = node.typeArguments;
13308 if (typeArguments != null) { 14798 if (typeArguments != null) {
13309 NodeList<TypeName> arguments = typeArguments.arguments; 14799 NodeList<TypeName> arguments = typeArguments.arguments;
13310 if (arguments.length != 0) { 14800 if (arguments.length != 0) {
13311 if (node.constKeyword != null) { 14801 if (node.constKeyword != null) {
13312 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 14802 checkForInvalidTypeArgumentInConstTypedLiteral(arguments, CompileTimeE rrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
13313 } 14803 }
13314 } 14804 }
13315 } 14805 }
13316 checkExpectedTwoMapTypeArguments(typeArguments); 14806 checkExpectedTwoMapTypeArguments(typeArguments);
13317 checkForNonConstMapAsExpressionStatement(node); 14807 checkForNonConstMapAsExpressionStatement(node);
13318 checkForMapTypeNotAssignable(node); 14808 checkForMapTypeNotAssignable(node);
13319 checkForConstMapKeyExpressionTypeImplementsEquals2(node); 14809 checkForConstMapKeyExpressionTypeImplementsEquals2(node);
13320 return super.visitMapLiteral(node); 14810 return super.visitMapLiteral(node);
13321 } 14811 }
14812
13322 Object visitMethodDeclaration(MethodDeclaration node) { 14813 Object visitMethodDeclaration(MethodDeclaration node) {
13323 ExecutableElement previousFunction = _enclosingFunction; 14814 ExecutableElement previousFunction = _enclosingFunction;
13324 try { 14815 try {
13325 _isInStaticMethod = node.isStatic; 14816 _isInStaticMethod = node.isStatic;
13326 _enclosingFunction = node.element; 14817 _enclosingFunction = node.element;
13327 SimpleIdentifier identifier = node.name; 14818 SimpleIdentifier identifier = node.name;
13328 String methodName = ""; 14819 String methodName = "";
13329 if (identifier != null) { 14820 if (identifier != null) {
13330 methodName = identifier.name; 14821 methodName = identifier.name;
13331 } 14822 }
13332 if (node.isSetter || node.isGetter) { 14823 if (node.isSetter || node.isGetter) {
13333 checkForMismatchedAccessorTypes(node, methodName); 14824 checkForMismatchedAccessorTypes(node, methodName);
13334 checkForConflictingInstanceGetterAndSuperclassMember(node);
13335 } 14825 }
13336 if (node.isGetter) { 14826 if (node.isGetter) {
13337 checkForConflictingStaticGetterAndInstanceSetter(node); 14827 checkForConflictingStaticGetterAndInstanceSetter(node);
13338 } else if (node.isSetter) { 14828 } else if (node.isSetter) {
13339 checkForWrongNumberOfParametersForSetter(node.name, node.parameters); 14829 checkForWrongNumberOfParametersForSetter(node.name, node.parameters);
13340 checkForNonVoidReturnTypeForSetter(node.returnType); 14830 checkForNonVoidReturnTypeForSetter(node.returnType);
13341 checkForConflictingStaticSetterAndInstanceMember(node); 14831 checkForConflictingStaticSetterAndInstanceMember(node);
13342 } else if (node.isOperator) { 14832 } else if (node.isOperator) {
13343 checkForOptionalParameterInOperator(node); 14833 checkForOptionalParameterInOperator(node);
13344 checkForWrongNumberOfParametersForOperator(node); 14834 checkForWrongNumberOfParametersForOperator(node);
13345 checkForNonVoidReturnTypeForOperator(node); 14835 checkForNonVoidReturnTypeForOperator(node);
14836 } else {
14837 checkForConflictingInstanceMethodSetter(node);
13346 } 14838 }
13347 checkForConcreteClassWithAbstractMember(node); 14839 checkForConcreteClassWithAbstractMember(node);
13348 checkForAllInvalidOverrideErrorCodes3(node); 14840 checkForAllInvalidOverrideErrorCodes3(node);
13349 return super.visitMethodDeclaration(node); 14841 return super.visitMethodDeclaration(node);
13350 } finally { 14842 } finally {
13351 _enclosingFunction = previousFunction; 14843 _enclosingFunction = previousFunction;
13352 _isInStaticMethod = false; 14844 _isInStaticMethod = false;
13353 } 14845 }
13354 } 14846 }
14847
13355 Object visitMethodInvocation(MethodInvocation node) { 14848 Object visitMethodInvocation(MethodInvocation node) {
13356 Expression target = node.realTarget; 14849 Expression target = node.realTarget;
13357 SimpleIdentifier methodName = node.methodName; 14850 SimpleIdentifier methodName = node.methodName;
13358 checkForStaticAccessToInstanceMember(target, methodName); 14851 if (target != null) {
13359 checkForInstanceAccessToStaticMember(target, methodName); 14852 ClassElement typeReference = ElementResolver.getTypeReference(target);
13360 if (target == null) { 14853 checkForStaticAccessToInstanceMember(typeReference, methodName);
14854 checkForInstanceAccessToStaticMember(typeReference, methodName);
14855 } else {
13361 checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); 14856 checkForUnqualifiedReferenceToNonLocalStaticMember(methodName);
13362 } 14857 }
13363 return super.visitMethodInvocation(node); 14858 return super.visitMethodInvocation(node);
13364 } 14859 }
14860
13365 Object visitNativeClause(NativeClause node) { 14861 Object visitNativeClause(NativeClause node) {
13366 if (!_isInSystemLibrary) { 14862 if (!_isInSystemLibrary) {
13367 _errorReporter.reportError2(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node, []); 14863 _errorReporter.reportError2(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node, []);
13368 } 14864 }
13369 return super.visitNativeClause(node); 14865 return super.visitNativeClause(node);
13370 } 14866 }
14867
13371 Object visitNativeFunctionBody(NativeFunctionBody node) { 14868 Object visitNativeFunctionBody(NativeFunctionBody node) {
13372 checkForNativeFunctionBodyInNonSDKCode(node); 14869 checkForNativeFunctionBodyInNonSDKCode(node);
13373 return super.visitNativeFunctionBody(node); 14870 return super.visitNativeFunctionBody(node);
13374 } 14871 }
14872
13375 Object visitPostfixExpression(PostfixExpression node) { 14873 Object visitPostfixExpression(PostfixExpression node) {
13376 checkForAssignmentToFinal2(node.operand); 14874 checkForAssignmentToFinal2(node.operand);
13377 checkForIntNotAssignable(node.operand); 14875 checkForIntNotAssignable(node.operand);
13378 return super.visitPostfixExpression(node); 14876 return super.visitPostfixExpression(node);
13379 } 14877 }
14878
13380 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 14879 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
13381 if (node.parent is! Annotation) { 14880 if (node.parent is! Annotation) {
13382 checkForStaticAccessToInstanceMember(node.prefix, node.identifier); 14881 ClassElement typeReference = ElementResolver.getTypeReference(node.prefix) ;
13383 checkForInstanceAccessToStaticMember(node.prefix, node.identifier); 14882 SimpleIdentifier name = node.identifier;
14883 checkForStaticAccessToInstanceMember(typeReference, name);
14884 checkForInstanceAccessToStaticMember(typeReference, name);
13384 } 14885 }
13385 return super.visitPrefixedIdentifier(node); 14886 return super.visitPrefixedIdentifier(node);
13386 } 14887 }
14888
13387 Object visitPrefixExpression(PrefixExpression node) { 14889 Object visitPrefixExpression(PrefixExpression node) {
13388 sc.TokenType operatorType = node.operator.type; 14890 sc.TokenType operatorType = node.operator.type;
13389 Expression operand = node.operand; 14891 Expression operand = node.operand;
13390 if (identical(operatorType, sc.TokenType.BANG)) { 14892 if (identical(operatorType, sc.TokenType.BANG)) {
13391 checkForNonBoolNegationExpression(operand); 14893 checkForNonBoolNegationExpression(operand);
13392 } else if (operatorType.isIncrementOperator) { 14894 } else if (operatorType.isIncrementOperator) {
13393 checkForAssignmentToFinal2(operand); 14895 checkForAssignmentToFinal2(operand);
13394 } 14896 }
13395 checkForIntNotAssignable(operand); 14897 checkForIntNotAssignable(operand);
13396 return super.visitPrefixExpression(node); 14898 return super.visitPrefixExpression(node);
13397 } 14899 }
14900
13398 Object visitPropertyAccess(PropertyAccess node) { 14901 Object visitPropertyAccess(PropertyAccess node) {
13399 Expression target = node.realTarget; 14902 ClassElement typeReference = ElementResolver.getTypeReference(node.realTarge t);
13400 SimpleIdentifier propertyName = node.propertyName; 14903 SimpleIdentifier propertyName = node.propertyName;
13401 checkForStaticAccessToInstanceMember(target, propertyName); 14904 checkForStaticAccessToInstanceMember(typeReference, propertyName);
13402 checkForInstanceAccessToStaticMember(target, propertyName); 14905 checkForInstanceAccessToStaticMember(typeReference, propertyName);
13403 return super.visitPropertyAccess(node); 14906 return super.visitPropertyAccess(node);
13404 } 14907 }
14908
13405 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 14909 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
13406 _isInConstructorInitializer = true; 14910 _isInConstructorInitializer = true;
13407 try { 14911 try {
13408 return super.visitRedirectingConstructorInvocation(node); 14912 return super.visitRedirectingConstructorInvocation(node);
13409 } finally { 14913 } finally {
13410 _isInConstructorInitializer = false; 14914 _isInConstructorInitializer = false;
13411 } 14915 }
13412 } 14916 }
14917
13413 Object visitRethrowExpression(RethrowExpression node) { 14918 Object visitRethrowExpression(RethrowExpression node) {
13414 checkForRethrowOutsideCatch(node); 14919 checkForRethrowOutsideCatch(node);
13415 return super.visitRethrowExpression(node); 14920 return super.visitRethrowExpression(node);
13416 } 14921 }
14922
13417 Object visitReturnStatement(ReturnStatement node) { 14923 Object visitReturnStatement(ReturnStatement node) {
13418 if (node.expression == null) { 14924 if (node.expression == null) {
13419 _returnWithoutCount++; 14925 _returnWithoutCount++;
13420 } else { 14926 } else {
13421 _returnWithCount++; 14927 _returnWithCount++;
13422 } 14928 }
13423 checkForAllReturnStatementErrorCodes(node); 14929 checkForAllReturnStatementErrorCodes(node);
13424 return super.visitReturnStatement(node); 14930 return super.visitReturnStatement(node);
13425 } 14931 }
14932
13426 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 14933 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
13427 checkForConstFormalParameter(node); 14934 checkForConstFormalParameter(node);
13428 checkForPrivateOptionalParameter(node); 14935 checkForPrivateOptionalParameter(node);
13429 return super.visitSimpleFormalParameter(node); 14936 return super.visitSimpleFormalParameter(node);
13430 } 14937 }
14938
13431 Object visitSimpleIdentifier(SimpleIdentifier node) { 14939 Object visitSimpleIdentifier(SimpleIdentifier node) {
13432 checkForImplicitThisReferenceInInitializer(node); 14940 checkForImplicitThisReferenceInInitializer(node);
13433 if (!isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) { 14941 if (!isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) {
13434 checkForUnqualifiedReferenceToNonLocalStaticMember(node); 14942 checkForUnqualifiedReferenceToNonLocalStaticMember(node);
13435 } 14943 }
13436 return super.visitSimpleIdentifier(node); 14944 return super.visitSimpleIdentifier(node);
13437 } 14945 }
14946
13438 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 14947 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
13439 _isInConstructorInitializer = true; 14948 _isInConstructorInitializer = true;
13440 try { 14949 try {
13441 return super.visitSuperConstructorInvocation(node); 14950 return super.visitSuperConstructorInvocation(node);
13442 } finally { 14951 } finally {
13443 _isInConstructorInitializer = false; 14952 _isInConstructorInitializer = false;
13444 } 14953 }
13445 } 14954 }
14955
13446 Object visitSwitchStatement(SwitchStatement node) { 14956 Object visitSwitchStatement(SwitchStatement node) {
13447 checkForInconsistentCaseExpressionTypes(node); 14957 checkForInconsistentCaseExpressionTypes(node);
13448 checkForSwitchExpressionNotAssignable(node); 14958 checkForSwitchExpressionNotAssignable(node);
13449 checkForCaseBlocksNotTerminated(node); 14959 checkForCaseBlocksNotTerminated(node);
13450 return super.visitSwitchStatement(node); 14960 return super.visitSwitchStatement(node);
13451 } 14961 }
14962
13452 Object visitThisExpression(ThisExpression node) { 14963 Object visitThisExpression(ThisExpression node) {
13453 checkForInvalidReferenceToThis(node); 14964 checkForInvalidReferenceToThis(node);
13454 return super.visitThisExpression(node); 14965 return super.visitThisExpression(node);
13455 } 14966 }
14967
13456 Object visitThrowExpression(ThrowExpression node) { 14968 Object visitThrowExpression(ThrowExpression node) {
13457 checkForConstEvalThrowsException(node); 14969 checkForConstEvalThrowsException(node);
13458 return super.visitThrowExpression(node); 14970 return super.visitThrowExpression(node);
13459 } 14971 }
14972
13460 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 14973 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
13461 checkForFinalNotInitialized2(node.variables); 14974 checkForFinalNotInitialized2(node.variables);
13462 return super.visitTopLevelVariableDeclaration(node); 14975 return super.visitTopLevelVariableDeclaration(node);
13463 } 14976 }
14977
13464 Object visitTypeName(TypeName node) { 14978 Object visitTypeName(TypeName node) {
13465 checkForTypeArgumentNotMatchingBounds(node); 14979 checkForTypeArgumentNotMatchingBounds(node);
13466 checkForTypeParameterReferencedByStatic(node); 14980 checkForTypeParameterReferencedByStatic(node);
13467 return super.visitTypeName(node); 14981 return super.visitTypeName(node);
13468 } 14982 }
14983
13469 Object visitTypeParameter(TypeParameter node) { 14984 Object visitTypeParameter(TypeParameter node) {
13470 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_PARAMETER_NAME); 14985 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_PARAMETER_NAME);
13471 checkForTypeParameterSupertypeOfItsBound(node); 14986 checkForTypeParameterSupertypeOfItsBound(node);
13472 return super.visitTypeParameter(node); 14987 return super.visitTypeParameter(node);
13473 } 14988 }
14989
13474 Object visitVariableDeclaration(VariableDeclaration node) { 14990 Object visitVariableDeclaration(VariableDeclaration node) {
13475 SimpleIdentifier nameNode = node.name; 14991 SimpleIdentifier nameNode = node.name;
13476 Expression initializerNode = node.initializer; 14992 Expression initializerNode = node.initializer;
13477 checkForInvalidAssignment2(nameNode, initializerNode); 14993 checkForInvalidAssignment2(nameNode, initializerNode);
13478 nameNode.accept(this); 14994 nameNode.accept(this);
13479 String name = nameNode.name; 14995 String name = nameNode.name;
13480 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name); 14996 javaSetAdd(_namesForReferenceToDeclaredVariableInInitializer, name);
13481 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; 14997 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration;
13482 try { 14998 try {
13483 if (initializerNode != null) { 14999 if (initializerNode != null) {
13484 initializerNode.accept(this); 15000 initializerNode.accept(this);
13485 } 15001 }
13486 } finally { 15002 } finally {
13487 _isInInstanceVariableInitializer = false; 15003 _isInInstanceVariableInitializer = false;
13488 _namesForReferenceToDeclaredVariableInInitializer.remove(name); 15004 _namesForReferenceToDeclaredVariableInInitializer.remove(name);
13489 } 15005 }
13490 return null; 15006 return null;
13491 } 15007 }
15008
13492 Object visitVariableDeclarationList(VariableDeclarationList node) => super.vis itVariableDeclarationList(node); 15009 Object visitVariableDeclarationList(VariableDeclarationList node) => super.vis itVariableDeclarationList(node);
15010
13493 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) { 15011 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
13494 checkForFinalNotInitialized2(node.variables); 15012 checkForFinalNotInitialized2(node.variables);
13495 return super.visitVariableDeclarationStatement(node); 15013 return super.visitVariableDeclarationStatement(node);
13496 } 15014 }
15015
13497 Object visitWhileStatement(WhileStatement node) { 15016 Object visitWhileStatement(WhileStatement node) {
13498 checkForNonBoolCondition(node.condition); 15017 checkForNonBoolCondition(node.condition);
13499 return super.visitWhileStatement(node); 15018 return super.visitWhileStatement(node);
13500 } 15019 }
13501 15020
13502 /** 15021 /**
13503 * This verifies if the passed map literal has type arguments then there is ex actly two. 15022 * This verifies if the passed map literal has type arguments then there is ex actly two.
13504 * 15023 *
13505 * @param node the map literal to evaluate 15024 * @param node the map literal to evaluate
13506 * @return `true` if and only if an error code is generated on the passed node 15025 * @return `true` if and only if an error code is generated on the passed node
(...skipping 27 matching lines...) Expand all
13534 } 15053 }
13535 if (_isInNativeClass) { 15054 if (_isInNativeClass) {
13536 return false; 15055 return false;
13537 } 15056 }
13538 bool foundError = false; 15057 bool foundError = false;
13539 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_ STATE>.from(_initialFieldElementsMap); 15058 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_ STATE>.from(_initialFieldElementsMap);
13540 NodeList<FormalParameter> formalParameters = node.parameters.parameters; 15059 NodeList<FormalParameter> formalParameters = node.parameters.parameters;
13541 for (FormalParameter formalParameter in formalParameters) { 15060 for (FormalParameter formalParameter in formalParameters) {
13542 FormalParameter parameter = formalParameter; 15061 FormalParameter parameter = formalParameter;
13543 if (parameter is DefaultFormalParameter) { 15062 if (parameter is DefaultFormalParameter) {
13544 parameter = ((parameter as DefaultFormalParameter)).parameter; 15063 parameter = (parameter as DefaultFormalParameter).parameter;
13545 } 15064 }
13546 if (parameter is FieldFormalParameter) { 15065 if (parameter is FieldFormalParameter) {
13547 FieldElement fieldElement = ((parameter.element as FieldFormalParameterE lementImpl)).field; 15066 FieldElement fieldElement = (parameter.element as FieldFormalParameterEl ementImpl).field;
13548 INIT_STATE state = fieldElementsMap[fieldElement]; 15067 INIT_STATE state = fieldElementsMap[fieldElement];
13549 if (identical(state, INIT_STATE.NOT_INIT)) { 15068 if (identical(state, INIT_STATE.NOT_INIT)) {
13550 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL; 15069 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL;
13551 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) { 15070 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) {
13552 if (fieldElement.isFinal || fieldElement.isConst) { 15071 if (fieldElement.isFinal || fieldElement.isConst) {
13553 _errorReporter.reportError2(StaticWarningCode.FINAL_INITIALIZED_IN_D ECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.displayNam e]); 15072 _errorReporter.reportError2(StaticWarningCode.FINAL_INITIALIZED_IN_D ECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.displayNam e]);
13554 foundError = true; 15073 foundError = true;
13555 } 15074 }
13556 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) { 15075 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) {
13557 if (fieldElement.isFinal || fieldElement.isConst) { 15076 if (fieldElement.isFinal || fieldElement.isConst) {
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
13916 } 15435 }
13917 bool problemReported = false; 15436 bool problemReported = false;
13918 for (TypeName mixinName in withClause.mixinTypes) { 15437 for (TypeName mixinName in withClause.mixinTypes) {
13919 Type2 mixinType = mixinName.type; 15438 Type2 mixinType = mixinName.type;
13920 if (mixinType is! InterfaceType) { 15439 if (mixinType is! InterfaceType) {
13921 continue; 15440 continue;
13922 } 15441 }
13923 if (checkForExtendsOrImplementsDisallowedClass(mixinName, CompileTimeError Code.MIXIN_OF_DISALLOWED_CLASS)) { 15442 if (checkForExtendsOrImplementsDisallowedClass(mixinName, CompileTimeError Code.MIXIN_OF_DISALLOWED_CLASS)) {
13924 problemReported = true; 15443 problemReported = true;
13925 } else { 15444 } else {
13926 ClassElement mixinElement = ((mixinType as InterfaceType)).element; 15445 ClassElement mixinElement = (mixinType as InterfaceType).element;
13927 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCo nstructor(mixinName, mixinElement)); 15446 problemReported = javaBooleanOr(problemReported, checkForMixinDeclaresCo nstructor(mixinName, mixinElement));
13928 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNo tFromObject(mixinName, mixinElement)); 15447 problemReported = javaBooleanOr(problemReported, checkForMixinInheritsNo tFromObject(mixinName, mixinElement));
13929 problemReported = javaBooleanOr(problemReported, checkForMixinReferences Super(mixinName, mixinElement)); 15448 problemReported = javaBooleanOr(problemReported, checkForMixinReferences Super(mixinName, mixinElement));
13930 } 15449 }
13931 } 15450 }
13932 return problemReported; 15451 return problemReported;
13933 } 15452 }
13934 15453
13935 /** 15454 /**
13936 * This checks error related to the redirected constructors. 15455 * This checks error related to the redirected constructors.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
13990 * @param node the return statement to evaluate 15509 * @param node the return statement to evaluate
13991 * @return `true` if and only if an error code is generated on the passed node 15510 * @return `true` if and only if an error code is generated on the passed node
13992 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR 15511 * @see CompileTimeErrorCode#RETURN_IN_GENERATIVE_CONSTRUCTOR
13993 * @see StaticWarningCode#RETURN_WITHOUT_VALUE 15512 * @see StaticWarningCode#RETURN_WITHOUT_VALUE
13994 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE 15513 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE
13995 */ 15514 */
13996 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) { 15515 bool checkForAllReturnStatementErrorCodes(ReturnStatement node) {
13997 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type; 15516 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
13998 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType; 15517 Type2 expectedReturnType = functionType == null ? DynamicTypeImpl.instance : functionType.returnType;
13999 Expression returnExpression = node.expression; 15518 Expression returnExpression = node.expression;
14000 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! ((_enclosingFunction as ConstructorElement)).isFactory; 15519 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && ! (_enclosingFunction as ConstructorElement).isFactory;
14001 if (isGenerativeConstructor) { 15520 if (isGenerativeConstructor) {
14002 if (returnExpression == null) { 15521 if (returnExpression == null) {
14003 return false; 15522 return false;
14004 } 15523 }
14005 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONS TRUCTOR, returnExpression, []); 15524 _errorReporter.reportError2(CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONS TRUCTOR, returnExpression, []);
14006 return true; 15525 return true;
14007 } 15526 }
14008 if (returnExpression == null) { 15527 if (returnExpression == null) {
14009 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { 15528 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) {
14010 return false; 15529 return false;
(...skipping 15 matching lines...) Expand all
14026 bool checkForAmbiguousExport(ExportDirective node) { 15545 bool checkForAmbiguousExport(ExportDirective node) {
14027 if (node.element is! ExportElement) { 15546 if (node.element is! ExportElement) {
14028 return false; 15547 return false;
14029 } 15548 }
14030 ExportElement exportElement = node.element as ExportElement; 15549 ExportElement exportElement = node.element as ExportElement;
14031 LibraryElement exportedLibrary = exportElement.exportedLibrary; 15550 LibraryElement exportedLibrary = exportElement.exportedLibrary;
14032 if (exportedLibrary == null) { 15551 if (exportedLibrary == null) {
14033 return false; 15552 return false;
14034 } 15553 }
14035 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle ment); 15554 Namespace namespace = new NamespaceBuilder().createExportNamespace(exportEle ment);
14036 Set<String> newNames = namespace.definedNames.keys.toSet(); 15555 Map<String, Element> definedNames = namespace.definedNames;
14037 for (String name in newNames) { 15556 for (MapEntry<String, Element> definedEntry in getMapEntrySet(definedNames)) {
14038 ExportElement prevElement = _exportedNames[name]; 15557 String name = definedEntry.getKey();
14039 if (prevElement != null && prevElement != exportElement) { 15558 Element element = definedEntry.getValue();
15559 Element prevElement = _exportedElements[name];
15560 if (element != null && prevElement != null && prevElement != element) {
14040 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node, [ 15561 _errorReporter.reportError2(CompileTimeErrorCode.AMBIGUOUS_EXPORT, node, [
14041 name, 15562 name,
14042 prevElement.exportedLibrary.definingCompilationUnit.displayName, 15563 prevElement.library.definingCompilationUnit.displayName,
14043 exportedLibrary.definingCompilationUnit.displayName]); 15564 element.library.definingCompilationUnit.displayName]);
14044 return true; 15565 return true;
14045 } else { 15566 } else {
14046 _exportedNames[name] = exportElement; 15567 _exportedElements[name] = element;
14047 } 15568 }
14048 } 15569 }
14049 return false; 15570 return false;
14050 } 15571 }
14051 15572
14052 /** 15573 /**
14053 * This verifies that the passed argument definition test identifier is a para meter. 15574 * This verifies that the passed argument definition test identifier is a para meter.
14054 * 15575 *
14055 * @param node the [ArgumentDefinitionTest] to evaluate 15576 * @param node the [ArgumentDefinitionTest] to evaluate
14056 * @return `true` if and only if an error code is generated on the passed node 15577 * @return `true` if and only if an error code is generated on the passed node
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
14173 * 15694 *
14174 * @param node the expression to evaluate 15695 * @param node the expression to evaluate
14175 * @return `true` if and only if an error code is generated on the passed node 15696 * @return `true` if and only if an error code is generated on the passed node
14176 * @see StaticWarningCode#ASSIGNMENT_TO_CONST 15697 * @see StaticWarningCode#ASSIGNMENT_TO_CONST
14177 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL 15698 * @see StaticWarningCode#ASSIGNMENT_TO_FINAL
14178 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD 15699 * @see StaticWarningCode#ASSIGNMENT_TO_METHOD
14179 */ 15700 */
14180 bool checkForAssignmentToFinal2(Expression expression) { 15701 bool checkForAssignmentToFinal2(Expression expression) {
14181 Element element = null; 15702 Element element = null;
14182 if (expression is Identifier) { 15703 if (expression is Identifier) {
14183 element = ((expression as Identifier)).staticElement; 15704 element = (expression as Identifier).staticElement;
14184 } 15705 }
14185 if (expression is PropertyAccess) { 15706 if (expression is PropertyAccess) {
14186 element = ((expression as PropertyAccess)).propertyName.staticElement; 15707 element = (expression as PropertyAccess).propertyName.staticElement;
14187 } 15708 }
14188 if (element is PropertyAccessorElement) { 15709 if (element is PropertyAccessorElement) {
14189 PropertyAccessorElement accessor = element as PropertyAccessorElement; 15710 PropertyAccessorElement accessor = element as PropertyAccessorElement;
14190 element = accessor.variable; 15711 element = accessor.variable;
14191 } 15712 }
14192 if (element is VariableElement) { 15713 if (element is VariableElement) {
14193 VariableElement variable = element as VariableElement; 15714 VariableElement variable = element as VariableElement;
14194 if (variable.isConst) { 15715 if (variable.isConst) {
14195 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_CONST, expre ssion, []); 15716 _errorReporter.reportError2(StaticWarningCode.ASSIGNMENT_TO_CONST, expre ssion, []);
14196 return true; 15717 return true;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
14251 if (index != -1 && index < members.length - 1) { 15772 if (index != -1 && index < members.length - 1) {
14252 return false; 15773 return false;
14253 } 15774 }
14254 } 15775 }
14255 } else { 15776 } else {
14256 Statement statement = statements[statements.length - 1]; 15777 Statement statement = statements[statements.length - 1];
14257 if (statement is BreakStatement || statement is ContinueStatement || state ment is ReturnStatement) { 15778 if (statement is BreakStatement || statement is ContinueStatement || state ment is ReturnStatement) {
14258 return false; 15779 return false;
14259 } 15780 }
14260 if (statement is ExpressionStatement) { 15781 if (statement is ExpressionStatement) {
14261 Expression expression = ((statement as ExpressionStatement)).expression; 15782 Expression expression = (statement as ExpressionStatement).expression;
14262 if (expression is ThrowExpression) { 15783 if (expression is ThrowExpression) {
14263 return false; 15784 return false;
14264 } 15785 }
14265 } 15786 }
14266 } 15787 }
14267 _errorReporter.reportError4(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod e.keyword, []); 15788 _errorReporter.reportError5(StaticWarningCode.CASE_BLOCK_NOT_TERMINATED, nod e.keyword, []);
14268 return true; 15789 return true;
14269 } 15790 }
14270 15791
14271 /** 15792 /**
14272 * This verifies that the switch cases in the given switch statement is termin ated with 'break', 15793 * This verifies that the switch cases in the given switch statement is termin ated with 'break',
14273 * 'continue', 'return' or 'throw'. 15794 * 'continue', 'return' or 'throw'.
14274 * 15795 *
14275 * @param node the switch statement containing the cases to be checked 15796 * @param node the switch statement containing the cases to be checked
14276 * @return `true` if and only if an error code is generated on the passed node 15797 * @return `true` if and only if an error code is generated on the passed node
14277 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED 15798 * @see StaticWarningCode#CASE_BLOCK_NOT_TERMINATED
(...skipping 17 matching lines...) Expand all
14295 * 15816 *
14296 * @param node the switch statement to evaluate 15817 * @param node the switch statement to evaluate
14297 * @param type the common type of all 'case' expressions 15818 * @param type the common type of all 'case' expressions
14298 * @return `true` if and only if an error code is generated on the passed node 15819 * @return `true` if and only if an error code is generated on the passed node
14299 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS 15820 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
14300 */ 15821 */
14301 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty pe) { 15822 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node, Type2 ty pe) {
14302 if (!implementsEqualsWhenNotAllowed(type)) { 15823 if (!implementsEqualsWhenNotAllowed(type)) {
14303 return false; 15824 return false;
14304 } 15825 }
14305 _errorReporter.reportError4(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM ENTS_EQUALS, node.keyword, [type.displayName]); 15826 _errorReporter.reportError5(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEM ENTS_EQUALS, node.keyword, [type.displayName]);
14306 return true; 15827 return true;
14307 } 15828 }
14308 15829
14309 /** 15830 /**
14310 * This verifies that the passed method declaration is abstract only if the en closing class is 15831 * This verifies that the passed method declaration is abstract only if the en closing class is
14311 * also abstract. 15832 * also abstract.
14312 * 15833 *
14313 * @param node the method declaration to evaluate 15834 * @param node the method declaration to evaluate
14314 * @return `true` if and only if an error code is generated on the passed node 15835 * @return `true` if and only if an error code is generated on the passed node
14315 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER 15836 * @see StaticWarningCode#CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
14385 return false; 15906 return false;
14386 } 15907 }
14387 bool hasProblem = false; 15908 bool hasProblem = false;
14388 for (MethodElement method in _enclosingClass.methods) { 15909 for (MethodElement method in _enclosingClass.methods) {
14389 String name = method.name; 15910 String name = method.name;
14390 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name); 15911 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name);
14391 if (inherited is! PropertyAccessorElement) { 15912 if (inherited is! PropertyAccessorElement) {
14392 continue; 15913 continue;
14393 } 15914 }
14394 hasProblem = true; 15915 hasProblem = true;
14395 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME THOD, method.nameOffset, name.length, [ 15916 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_GETTER_AND_ME THOD, method.nameOffset, name.length, [
14396 _enclosingClass.displayName, 15917 _enclosingClass.displayName,
14397 inherited.enclosingElement.displayName, 15918 inherited.enclosingElement.displayName,
14398 name]); 15919 name]);
14399 } 15920 }
14400 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 15921 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
14401 if (!accessor.isGetter) { 15922 if (!accessor.isGetter) {
14402 continue; 15923 continue;
14403 } 15924 }
14404 String name = accessor.name; 15925 String name = accessor.name;
14405 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name); 15926 ExecutableElement inherited = _inheritanceManager.lookupInheritance(_enclo singClass, name);
14406 if (inherited is! MethodElement) { 15927 if (inherited is! MethodElement) {
14407 continue; 15928 continue;
14408 } 15929 }
14409 hasProblem = true; 15930 hasProblem = true;
14410 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE TTER, accessor.nameOffset, name.length, [ 15931 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_METHOD_AND_GE TTER, accessor.nameOffset, name.length, [
14411 _enclosingClass.displayName, 15932 _enclosingClass.displayName,
14412 inherited.enclosingElement.displayName, 15933 inherited.enclosingElement.displayName,
14413 name]); 15934 name]);
14414 } 15935 }
14415 return hasProblem; 15936 return hasProblem;
14416 } 15937 }
14417 15938
14418 /** 15939 /**
14419 * This verifies that the superclass of the enclosing class does not declare a ccessible static 15940 * This verifies that the superclass of the [enclosingClass] does not declare accessible
14420 * member with the same name as the passed instance getter/setter method decla ration. 15941 * static members with the same name as the instance getters/setters declared in
15942 * [enclosingClass].
14421 * 15943 *
14422 * @param node the method declaration to evaluate 15944 * @param node the method declaration to evaluate
14423 * @return `true` if and only if an error code is generated on the passed node 15945 * @return `true` if and only if an error code is generated on the passed node
14424 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER 15946 * @see StaticWarningCode#CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER
14425 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER 15947 * @see StaticWarningCode#CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_MEMBER
14426 */ 15948 */
14427 bool checkForConflictingInstanceGetterAndSuperclassMember(MethodDeclaration no de) { 15949 bool checkForConflictingInstanceGetterAndSuperclassMember() {
15950 if (_enclosingClass == null) {
15951 return false;
15952 }
15953 InterfaceType enclosingType = _enclosingClass.type;
15954 bool hasProblem = false;
15955 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
15956 if (accessor.isStatic) {
15957 continue;
15958 }
15959 String name = accessor.displayName;
15960 bool getter = accessor.isGetter;
15961 if (accessor.isSetter && accessor.isSynthetic) {
15962 continue;
15963 }
15964 ExecutableElement superElement;
15965 superElement = enclosingType.lookUpGetterInSuperclass(name, _currentLibrar y);
15966 if (superElement == null) {
15967 superElement = enclosingType.lookUpSetterInSuperclass(name, _currentLibr ary);
15968 }
15969 if (superElement == null) {
15970 superElement = enclosingType.lookUpMethodInSuperclass(name, _currentLibr ary);
15971 }
15972 if (superElement == null) {
15973 continue;
15974 }
15975 if (!superElement.isStatic) {
15976 continue;
15977 }
15978 ClassElement superElementClass = superElement.enclosingElement as ClassEle ment;
15979 InterfaceType superElementType = superElementClass.type;
15980 hasProblem = true;
15981 if (getter) {
15982 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_INSTANCE_GETTE R_AND_SUPERCLASS_MEMBER, accessor, [superElementType.displayName]);
15983 } else {
15984 _errorReporter.reportError3(StaticWarningCode.CONFLICTING_INSTANCE_SETTE R_AND_SUPERCLASS_MEMBER, accessor, [superElementType.displayName]);
15985 }
15986 }
15987 return hasProblem;
15988 }
15989
15990 /**
15991 * This verifies that the enclosing class does not have a setter with the same name as the passed
15992 * instance method declaration.
15993 *
15994 * @param node the method declaration to evaluate
15995 * @return `true` if and only if an error code is generated on the passed node
15996 * @see StaticWarningCode#CONFLICTING_INSTANCE_METHOD_SETTER
15997 */
15998 bool checkForConflictingInstanceMethodSetter(MethodDeclaration node) {
14428 if (node.isStatic) { 15999 if (node.isStatic) {
14429 return false; 16000 return false;
14430 } 16001 }
14431 SimpleIdentifier nameNode = node.name; 16002 SimpleIdentifier nameNode = node.name;
14432 if (nameNode == null) { 16003 if (nameNode == null) {
14433 return false; 16004 return false;
14434 } 16005 }
14435 String name = nameNode.name; 16006 String name = nameNode.name;
14436 if (_enclosingClass == null) { 16007 if (_enclosingClass == null) {
14437 return false; 16008 return false;
14438 } 16009 }
14439 InterfaceType enclosingType = _enclosingClass.type; 16010 ExecutableElement setter = _inheritanceManager.lookupMember(_enclosingClass, "${name}=");
14440 ExecutableElement superElement; 16011 if (setter == null) {
14441 superElement = enclosingType.lookUpGetterInSuperclass(name, _currentLibrary) ;
14442 if (superElement == null) {
14443 superElement = enclosingType.lookUpSetterInSuperclass(name, _currentLibrar y);
14444 }
14445 if (superElement == null) {
14446 superElement = enclosingType.lookUpMethodInSuperclass(name, _currentLibrar y);
14447 }
14448 if (superElement == null) {
14449 return false; 16012 return false;
14450 } 16013 }
14451 if (!superElement.isStatic) { 16014 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_METHOD_SE TTER, nameNode, [
14452 return false; 16015 _enclosingClass.displayName,
14453 } 16016 name,
14454 ClassElement superElementClass = superElement.enclosingElement as ClassEleme nt; 16017 setter.enclosingElement.displayName]);
14455 InterfaceType superElementType = superElementClass.type;
14456 if (node.isGetter) {
14457 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_GETTER_ AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]);
14458 } else {
14459 _errorReporter.reportError2(StaticWarningCode.CONFLICTING_INSTANCE_SETTER_ AND_SUPERCLASS_MEMBER, nameNode, [superElementType.displayName]);
14460 }
14461 return true; 16018 return true;
14462 } 16019 }
14463 16020
14464 /** 16021 /**
14465 * This verifies that the enclosing class does not have an instance member wit h the same name as 16022 * This verifies that the enclosing class does not have an instance member wit h the same name as
14466 * the passed static getter method declaration. 16023 * the passed static getter method declaration.
14467 * 16024 *
14468 * @param node the method declaration to evaluate 16025 * @param node the method declaration to evaluate
14469 * @return `true` if and only if an error code is generated on the passed node 16026 * @return `true` if and only if an error code is generated on the passed node
14470 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER 16027 * @see StaticWarningCode#CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
14542 * @param node the class declaration to evaluate 16099 * @param node the class declaration to evaluate
14543 * @return `true` if and only if an error code is generated on the passed node 16100 * @return `true` if and only if an error code is generated on the passed node
14544 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_CLASS 16101 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_CLASS
14545 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_MEMBER 16102 * @see CompileTimeErrorCode#CONFLICTING_TYPE_VARIABLE_AND_MEMBER
14546 */ 16103 */
14547 bool checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) { 16104 bool checkForConflictingTypeVariableErrorCodes(ClassDeclaration node) {
14548 bool problemReported = false; 16105 bool problemReported = false;
14549 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) { 16106 for (TypeParameterElement typeParameter in _enclosingClass.typeParameters) {
14550 String name = typeParameter.name; 16107 String name = typeParameter.name;
14551 if (_enclosingClass.name == name) { 16108 if (_enclosingClass.name == name) {
14552 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_CLASS, typeParameter.nameOffset, name.length, [name]); 16109 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_CLASS, typeParameter.nameOffset, name.length, [name]);
14553 problemReported = true; 16110 problemReported = true;
14554 } 16111 }
14555 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) { 16112 if (_enclosingClass.getMethod(name) != null || _enclosingClass.getGetter(n ame) != null || _enclosingClass.getSetter(name) != null) {
14556 _errorReporter.reportError3(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]); 16113 _errorReporter.reportError4(CompileTimeErrorCode.CONFLICTING_TYPE_VARIAB LE_AND_MEMBER, typeParameter.nameOffset, name.length, [name]);
14557 problemReported = true; 16114 problemReported = true;
14558 } 16115 }
14559 } 16116 }
14560 return problemReported; 16117 return problemReported;
14561 } 16118 }
14562 16119
14563 /** 16120 /**
14564 * This verifies that if the passed constructor declaration is 'const' then th ere are no 16121 * This verifies that if the passed constructor declaration is 'const' then th ere are no
14565 * invocations of non-'const' super constructors. 16122 * invocations of non-'const' super constructors.
14566 * 16123 *
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
14702 * [InstanceCreationExpression], this is the AST node that the error is attached to 16259 * [InstanceCreationExpression], this is the AST node that the error is attached to
14703 * @param type the type being constructed with this [InstanceCreationExpressio n] 16260 * @param type the type being constructed with this [InstanceCreationExpressio n]
14704 * @return `true` if and only if an error code is generated on the passed node 16261 * @return `true` if and only if an error code is generated on the passed node
14705 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 16262 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS
14706 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 16263 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS
14707 */ 16264 */
14708 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type Name typeName, InterfaceType type) { 16265 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type Name typeName, InterfaceType type) {
14709 if (type.element.isAbstract) { 16266 if (type.element.isAbstract) {
14710 ConstructorElement element = node.staticElement; 16267 ConstructorElement element = node.staticElement;
14711 if (element != null && !element.isFactory) { 16268 if (element != null && !element.isFactory) {
14712 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO NST)) { 16269 if (identical((node.keyword as sc.KeywordToken).keyword, sc.Keyword.CONS T)) {
14713 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS S, typeName, []); 16270 _errorReporter.reportError2(StaticWarningCode.CONST_WITH_ABSTRACT_CLAS S, typeName, []);
14714 } else { 16271 } else {
14715 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS, typeName, []); 16272 _errorReporter.reportError2(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS, typeName, []);
14716 } 16273 }
14717 return true; 16274 return true;
14718 } 16275 }
14719 } 16276 }
14720 return false; 16277 return false;
14721 } 16278 }
14722 16279
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
14902 if (name == null) { 16459 if (name == null) {
14903 return false; 16460 return false;
14904 } 16461 }
14905 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name); 16462 ExecutableElement inheritedMember = _inheritanceManager.lookupInheritance(_e nclosingClass, name);
14906 if (inheritedMember == null) { 16463 if (inheritedMember == null) {
14907 return false; 16464 return false;
14908 } 16465 }
14909 if (inheritedMember.isStatic) { 16466 if (inheritedMember.isStatic) {
14910 return false; 16467 return false;
14911 } 16468 }
14912 _errorReporter.reportError3(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle ment.displayName]); 16469 _errorReporter.reportError4(CompileTimeErrorCode.DUPLICATE_DEFINITION_INHERI TANCE, staticMember.nameOffset, name.length, [name, inheritedMember.enclosingEle ment.displayName]);
14913 return true; 16470 return true;
14914 } 16471 }
14915 16472
14916 /** 16473 /**
14917 * This verifies if the passed list literal has type arguments then there is e xactly one. 16474 * This verifies if the passed list literal has type arguments then there is e xactly one.
14918 * 16475 *
14919 * @param node the list literal to evaluate 16476 * @param node the list literal to evaluate
14920 * @return `true` if and only if an error code is generated on the passed node 16477 * @return `true` if and only if an error code is generated on the passed node
14921 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS 16478 * @see StaticTypeWarningCode#EXPECTED_ONE_LIST_TYPE_ARGUMENTS
14922 */ 16479 */
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
15024 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e rrorCode) { 16581 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e rrorCode) {
15025 if (typeName.isSynthetic) { 16582 if (typeName.isSynthetic) {
15026 return false; 16583 return false;
15027 } 16584 }
15028 Type2 superType = typeName.type; 16585 Type2 superType = typeName.type;
15029 for (InterfaceType disallowedType in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMEN T) { 16586 for (InterfaceType disallowedType in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMEN T) {
15030 if (superType != null && superType == disallowedType) { 16587 if (superType != null && superType == disallowedType) {
15031 if (superType == _typeProvider.numType) { 16588 if (superType == _typeProvider.numType) {
15032 ASTNode grandParent = typeName.parent.parent; 16589 ASTNode grandParent = typeName.parent.parent;
15033 if (grandParent is ClassDeclaration) { 16590 if (grandParent is ClassDeclaration) {
15034 ClassElement classElement = ((grandParent as ClassDeclaration)).elem ent; 16591 ClassElement classElement = (grandParent as ClassDeclaration).elemen t;
15035 Type2 classType = classElement.type; 16592 Type2 classType = classElement.type;
15036 if (classType != null && (classType == _typeProvider.intType || clas sType == _typeProvider.doubleType)) { 16593 if (classType != null && (classType == _typeProvider.intType || clas sType == _typeProvider.doubleType)) {
15037 return false; 16594 return false;
15038 } 16595 }
15039 } 16596 }
15040 } 16597 }
15041 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display Name]); 16598 _errorReporter.reportError2(errorCode, typeName, [disallowedType.display Name]);
15042 return true; 16599 return true;
15043 } 16600 }
15044 } 16601 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
15361 if (errors == null || errors.isEmpty) { 16918 if (errors == null || errors.isEmpty) {
15362 return false; 16919 return false;
15363 } 16920 }
15364 for (AnalysisError error in errors) { 16921 for (AnalysisError error in errors) {
15365 _errorReporter.reportError(error); 16922 _errorReporter.reportError(error);
15366 } 16923 }
15367 return true; 16924 return true;
15368 } 16925 }
15369 16926
15370 /** 16927 /**
15371 * This checks that if the given "target" is not a type reference then the "na me" is reference to 16928 * This checks the given "typeReference" is not a type reference and that then the "name" is
15372 * an instance member. 16929 * reference to an instance member.
15373 * 16930 *
15374 * @param target the target of the name access to evaluate 16931 * @param typeReference the resolved [ClassElement] of the left hand side of t he expression,
16932 * or `null`, aka, the class element of 'C' in 'C.x', see
16933 * [getTypeReference]
15375 * @param name the accessed name to evaluate 16934 * @param name the accessed name to evaluate
15376 * @return `true` if and only if an error code is generated on the passed node 16935 * @return `true` if and only if an error code is generated on the passed node
15377 * @see StaticTypeWarningCode#INSTANCE_ACCESS_TO_STATIC_MEMBER 16936 * @see StaticTypeWarningCode#INSTANCE_ACCESS_TO_STATIC_MEMBER
15378 */ 16937 */
15379 bool checkForInstanceAccessToStaticMember(Expression target, SimpleIdentifier name) { 16938 bool checkForInstanceAccessToStaticMember(ClassElement typeReference, SimpleId entifier name) {
15380 if (target == null) {
15381 return false;
15382 }
15383 if (_isInComment) { 16939 if (_isInComment) {
15384 return false; 16940 return false;
15385 } 16941 }
16942 if (typeReference != null) {
16943 return false;
16944 }
15386 Element element = name.staticElement; 16945 Element element = name.staticElement;
15387 if (element is! ExecutableElement) { 16946 if (element is! ExecutableElement) {
15388 return false; 16947 return false;
15389 } 16948 }
15390 ExecutableElement executableElement = element as ExecutableElement; 16949 ExecutableElement executableElement = element as ExecutableElement;
15391 if (executableElement.enclosingElement is! ClassElement) { 16950 if (executableElement.enclosingElement is! ClassElement) {
15392 return false; 16951 return false;
15393 } 16952 }
15394 if (!executableElement.isStatic) { 16953 if (!executableElement.isStatic) {
15395 return false; 16954 return false;
15396 } 16955 }
15397 if (isTypeReference(target)) {
15398 return false;
15399 }
15400 _errorReporter.reportError2(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_ MEMBER, name, [name.name]); 16956 _errorReporter.reportError2(StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_ MEMBER, name, [name.name]);
15401 return true; 16957 return true;
15402 } 16958 }
15403 16959
15404 /** 16960 /**
15405 * This verifies that an 'int' can be assigned to the parameter corresponding to the given 16961 * This verifies that an 'int' can be assigned to the parameter corresponding to the given
15406 * expression. This is used for prefix and postfix expressions where the argum ent value is 16962 * expression. This is used for prefix and postfix expressions where the argum ent value is
15407 * implicit. 16963 * implicit.
15408 * 16964 *
15409 * @param argument the expression to which the operator is being applied 16965 * @param argument the expression to which the operator is being applied
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
15604 if (_enclosingClass == null) { 17160 if (_enclosingClass == null) {
15605 return false; 17161 return false;
15606 } 17162 }
15607 String className = _enclosingClass.name; 17163 String className = _enclosingClass.name;
15608 if (className == null) { 17164 if (className == null) {
15609 return false; 17165 return false;
15610 } 17166 }
15611 bool problemReported = false; 17167 bool problemReported = false;
15612 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { 17168 for (PropertyAccessorElement accessor in _enclosingClass.accessors) {
15613 if (className == accessor.name) { 17169 if (className == accessor.name) {
15614 _errorReporter.reportError3(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, className.length, []); 17170 _errorReporter.reportError4(CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME, accessor.nameOffset, className.length, []);
15615 problemReported = true; 17171 problemReported = true;
15616 } 17172 }
15617 } 17173 }
15618 return problemReported; 17174 return problemReported;
15619 } 17175 }
15620 17176
15621 /** 17177 /**
15622 * Check to make sure that all similarly typed accessors are of the same type (including inherited 17178 * Check to make sure that all similarly typed accessors are of the same type (including inherited
15623 * accessors). 17179 * accessors).
15624 * 17180 *
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
15888 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass); 17444 MemberMap membersInheritedFromInterfaces = _inheritanceManager.getMapOfMembe rsInheritedFromInterfaces(_enclosingClass);
15889 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass); 17445 MemberMap membersInheritedFromSuperclasses = _inheritanceManager.getMapOfMem bersInheritedFromClasses(_enclosingClass);
15890 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) { 17446 for (int i = 0; i < membersInheritedFromInterfaces.size; i++) {
15891 String memberName = membersInheritedFromInterfaces.getKey(i); 17447 String memberName = membersInheritedFromInterfaces.getKey(i);
15892 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i); 17448 ExecutableElement executableElt = membersInheritedFromInterfaces.getValue( i);
15893 if (memberName == null) { 17449 if (memberName == null) {
15894 break; 17450 break;
15895 } 17451 }
15896 ExecutableElement elt = membersInheritedFromSuperclasses.get(executableElt .name); 17452 ExecutableElement elt = membersInheritedFromSuperclasses.get(executableElt .name);
15897 if (elt != null) { 17453 if (elt != null) {
15898 if (elt is MethodElement && !((elt as MethodElement)).isAbstract) { 17454 if (elt is MethodElement && !(elt as MethodElement).isAbstract) {
15899 continue; 17455 continue;
15900 } else if (elt is PropertyAccessorElement && !((elt as PropertyAccessorE lement)).isAbstract) { 17456 } else if (elt is PropertyAccessorElement && !(elt as PropertyAccessorEl ement).isAbstract) {
15901 continue; 17457 continue;
15902 } 17458 }
15903 } 17459 }
15904 if (executableElt is MethodElement) { 17460 if (executableElt is MethodElement) {
15905 if (!methodsInEnclosingClass.contains(memberName) && !memberHasConcreteM ethodImplementationInSuperclassChain(_enclosingClass, memberName, new List<Class Element>())) { 17461 if (!methodsInEnclosingClass.contains(memberName) && !memberHasConcreteM ethodImplementationInSuperclassChain(_enclosingClass, memberName, new List<Class Element>())) {
15906 javaSetAdd(missingOverrides, executableElt); 17462 javaSetAdd(missingOverrides, executableElt);
15907 } 17463 }
15908 } else if (executableElt is PropertyAccessorElement) { 17464 } else if (executableElt is PropertyAccessorElement) {
15909 if (!accessorsInEnclosingClass.contains(memberName) && !memberHasConcret eAccessorImplementationInSuperclassChain(_enclosingClass, memberName, new List<C lassElement>())) { 17465 if (!accessorsInEnclosingClass.contains(memberName) && !memberHasConcret eAccessorImplementationInSuperclassChain(_enclosingClass, memberName, new List<C lassElement>())) {
15910 javaSetAdd(missingOverrides, executableElt); 17466 javaSetAdd(missingOverrides, executableElt);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
16203 if (size > 0 && _enclosingClass == classElt) { 17759 if (size > 0 && _enclosingClass == classElt) {
16204 String enclosingClassName = _enclosingClass.displayName; 17760 String enclosingClassName = _enclosingClass.displayName;
16205 if (size > 1) { 17761 if (size > 1) {
16206 String separator = ", "; 17762 String separator = ", ";
16207 JavaStringBuilder builder = new JavaStringBuilder(); 17763 JavaStringBuilder builder = new JavaStringBuilder();
16208 for (int i = 0; i < size; i++) { 17764 for (int i = 0; i < size; i++) {
16209 builder.append(path[i].displayName); 17765 builder.append(path[i].displayName);
16210 builder.append(separator); 17766 builder.append(separator);
16211 } 17767 }
16212 builder.append(classElt.displayName); 17768 builder.append(classElt.displayName);
16213 _errorReporter.reportError3(CompileTimeErrorCode.RECURSIVE_INTERFACE_INH ERITANCE, _enclosingClass.nameOffset, enclosingClassName.length, [enclosingClass Name, builder.toString()]); 17769 _errorReporter.reportError4(CompileTimeErrorCode.RECURSIVE_INTERFACE_INH ERITANCE, _enclosingClass.nameOffset, enclosingClassName.length, [enclosingClass Name, builder.toString()]);
16214 return true; 17770 return true;
16215 } else { 17771 } else {
16216 InterfaceType supertype = classElt.supertype; 17772 InterfaceType supertype = classElt.supertype;
16217 ErrorCode errorCode = (supertype != null && _enclosingClass == supertype .element ? CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTEND S : CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS) a s ErrorCode; 17773 ErrorCode errorCode = (supertype != null && _enclosingClass == supertype .element ? CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTEND S : CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_IMPLEMENTS) a s ErrorCode;
16218 _errorReporter.reportError3(errorCode, _enclosingClass.nameOffset, enclo singClassName.length, [enclosingClassName]); 17774 _errorReporter.reportError4(errorCode, _enclosingClass.nameOffset, enclo singClassName.length, [enclosingClassName]);
16219 return true; 17775 return true;
16220 } 17776 }
16221 } 17777 }
16222 if (path.indexOf(classElt) > 0) { 17778 if (path.indexOf(classElt) > 0) {
16223 return false; 17779 return false;
16224 } 17780 }
16225 path.add(classElt); 17781 path.add(classElt);
16226 InterfaceType supertype = classElt.supertype; 17782 InterfaceType supertype = classElt.supertype;
16227 if (supertype != null && checkForRecursiveInterfaceInheritance2(supertype.el ement, path)) { 17783 if (supertype != null && checkForRecursiveInterfaceInheritance2(supertype.el ement, path)) {
16228 return true; 17784 return true;
(...skipping 17 matching lines...) Expand all
16246 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR 17802 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR
16247 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR 17803 * @see CompileTimeErrorCode#FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR
16248 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS 17804 * @see CompileTimeErrorCode#MULTIPLE_REDIRECTING_CONSTRUCTOR_INVOCATIONS
16249 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR 17805 * @see CompileTimeErrorCode#SUPER_IN_REDIRECTING_CONSTRUCTOR
16250 */ 17806 */
16251 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { 17807 bool checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) {
16252 bool errorReported = false; 17808 bool errorReported = false;
16253 ConstructorName redirectedConstructor = node.redirectedConstructor; 17809 ConstructorName redirectedConstructor = node.redirectedConstructor;
16254 if (redirectedConstructor != null) { 17810 if (redirectedConstructor != null) {
16255 for (FormalParameter parameter in node.parameters.parameters) { 17811 for (FormalParameter parameter in node.parameters.parameters) {
16256 if (parameter is DefaultFormalParameter && ((parameter as DefaultFormalP arameter)).defaultValue != null) { 17812 if (parameter is DefaultFormalParameter && (parameter as DefaultFormalPa rameter).defaultValue != null) {
16257 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_REDI RECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []); 17813 _errorReporter.reportError2(CompileTimeErrorCode.DEFAULT_VALUE_IN_REDI RECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []);
16258 errorReported = true; 17814 errorReported = true;
16259 } 17815 }
16260 } 17816 }
16261 } 17817 }
16262 int numRedirections = 0; 17818 int numRedirections = 0;
16263 for (ConstructorInitializer initializer in node.initializers) { 17819 for (ConstructorInitializer initializer in node.initializers) {
16264 if (initializer is RedirectingConstructorInvocation) { 17820 if (initializer is RedirectingConstructorInvocation) {
16265 if (numRedirections > 0) { 17821 if (numRedirections > 0) {
16266 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_REDIRECTING_ CONSTRUCTOR_INVOCATIONS, initializer, []); 17822 _errorReporter.reportError2(CompileTimeErrorCode.MULTIPLE_REDIRECTING_ CONSTRUCTOR_INVOCATIONS, initializer, []);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
16392 } 17948 }
16393 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ 17949 _errorReporter.reportError2(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [
16394 staticReturnType.displayName, 17950 staticReturnType.displayName,
16395 expectedReturnType.displayName, 17951 expectedReturnType.displayName,
16396 _enclosingFunction.displayName]); 17952 _enclosingFunction.displayName]);
16397 return true; 17953 return true;
16398 } 17954 }
16399 } 17955 }
16400 17956
16401 /** 17957 /**
16402 * This checks that if the given "target" is the type reference then the "name " is not the 17958 * This checks the given "typeReference" and that the "name" is not the refere nce to an instance
16403 * reference to a instance member. 17959 * member.
16404 * 17960 *
16405 * @param target the target of the name access to evaluate 17961 * @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
17963 * [getTypeReference]
16406 * @param name the accessed name to evaluate 17964 * @param name the accessed name to evaluate
16407 * @return `true` if and only if an error code is generated on the passed node 17965 * @return `true` if and only if an error code is generated on the passed node
16408 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER 17966 * @see StaticWarningCode#STATIC_ACCESS_TO_INSTANCE_MEMBER
16409 */ 17967 */
16410 bool checkForStaticAccessToInstanceMember(Expression target, SimpleIdentifier name) { 17968 bool checkForStaticAccessToInstanceMember(ClassElement typeReference, SimpleId entifier name) {
17969 if (typeReference == null) {
17970 return false;
17971 }
16411 Element element = name.staticElement; 17972 Element element = name.staticElement;
16412 if (element is! ExecutableElement) { 17973 if (element is! ExecutableElement) {
16413 return false; 17974 return false;
16414 } 17975 }
16415 ExecutableElement memberElement = element as ExecutableElement; 17976 ExecutableElement memberElement = element as ExecutableElement;
16416 if (memberElement.isStatic) { 17977 if (memberElement.isStatic) {
16417 return false; 17978 return false;
16418 } 17979 }
16419 if (!isTypeReference(target)) {
16420 return false;
16421 }
16422 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB ER, name, [name.name]); 17980 _errorReporter.reportError2(StaticWarningCode.STATIC_ACCESS_TO_INSTANCE_MEMB ER, name, [name.name]);
16423 return true; 17981 return true;
16424 } 17982 }
16425 17983
16426 /** 17984 /**
16427 * This checks that the type of the passed 'switch' expression is assignable t o the type of the 17985 * This checks that the type of the passed 'switch' expression is assignable t o the type of the
16428 * 'case' members. 17986 * 'case' members.
16429 * 17987 *
16430 * @param node the 'switch' statement to evaluate 17988 * @param node the 'switch' statement to evaluate
16431 * @return `true` if and only if an error code is generated on the passed node 17989 * @return `true` if and only if an error code is generated on the passed node
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
16501 return false; 18059 return false;
16502 } 18060 }
16503 Element element = type.element; 18061 Element element = type.element;
16504 if (element is! ClassElement) { 18062 if (element is! ClassElement) {
16505 return false; 18063 return false;
16506 } 18064 }
16507 ClassElement classElement = element as ClassElement; 18065 ClassElement classElement = element as ClassElement;
16508 List<Type2> typeParameters = classElement.type.typeArguments; 18066 List<Type2> typeParameters = classElement.type.typeArguments;
16509 List<TypeParameterElement> boundingElts = classElement.typeParameters; 18067 List<TypeParameterElement> boundingElts = classElement.typeParameters;
16510 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments; 18068 NodeList<TypeName> typeNameArgList = node.typeArguments.arguments;
16511 List<Type2> typeArguments = ((type as InterfaceType)).typeArguments; 18069 List<Type2> typeArguments = (type as InterfaceType).typeArguments;
16512 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length) ; 18070 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.length) ;
16513 bool foundError = false; 18071 bool foundError = false;
16514 for (int i = 0; i < loopThroughIndex; i++) { 18072 for (int i = 0; i < loopThroughIndex; i++) {
16515 TypeName argTypeName = typeNameArgList[i]; 18073 TypeName argTypeName = typeNameArgList[i];
16516 Type2 argType = argTypeName.type; 18074 Type2 argType = argTypeName.type;
16517 Type2 boundType = boundingElts[i].bound; 18075 Type2 boundType = boundingElts[i].bound;
16518 if (argType != null && boundType != null) { 18076 if (argType != null && boundType != null) {
16519 boundType = boundType.substitute2(typeArguments, typeParameters); 18077 boundType = boundType.substitute2(typeArguments, typeParameters);
16520 if (!argType.isSubtypeOf(boundType)) { 18078 if (!argType.isSubtypeOf(boundType)) {
16521 ErrorCode errorCode; 18079 ErrorCode errorCode;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
16607 } 18165 }
16608 if (!superUnnamedConstructor.isDefaultConstructor) { 18166 if (!superUnnamedConstructor.isDefaultConstructor) {
16609 int offset; 18167 int offset;
16610 int length; 18168 int length;
16611 { 18169 {
16612 Identifier returnType = node.returnType; 18170 Identifier returnType = node.returnType;
16613 SimpleIdentifier name = node.name; 18171 SimpleIdentifier name = node.name;
16614 offset = returnType.offset; 18172 offset = returnType.offset;
16615 length = (name != null ? name.end : returnType.end) - offset; 18173 length = (name != null ? name.end : returnType.end) - offset;
16616 } 18174 }
16617 _errorReporter.reportError3(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTR UCTOR_EXPLICIT, offset, length, [superType.displayName]); 18175 _errorReporter.reportError4(CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTR UCTOR_EXPLICIT, offset, length, [superType.displayName]);
16618 } 18176 }
16619 return false; 18177 return false;
16620 } 18178 }
16621 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN ITIALIZER_DEFAULT, node.returnType, [superElement.name]); 18179 _errorReporter.reportError2(CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_IN ITIALIZER_DEFAULT, node.returnType, [superElement.name]);
16622 return true; 18180 return true;
16623 } 18181 }
16624 18182
16625 /** 18183 /**
16626 * This checks that if the given name is a reference to a static member it is defined in the 18184 * This checks that if the given name is a reference to a static member it is defined in the
16627 * enclosing class rather than in a superclass. 18185 * enclosing class rather than in a superclass.
16628 * 18186 *
16629 * @param name the name to be evaluated 18187 * @param name the name to be evaluated
16630 * @return `true` if and only if an error code is generated on the passed node 18188 * @return `true` if and only if an error code is generated on the passed node
16631 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER 18189 * @see StaticTypeWarningCode#UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER
16632 */ 18190 */
16633 bool checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name) { 18191 bool checkForUnqualifiedReferenceToNonLocalStaticMember(SimpleIdentifier name) {
16634 Element element = name.staticElement; 18192 Element element = name.staticElement;
16635 if (element == null || element is TypeParameterElement) { 18193 if (element == null || element is TypeParameterElement) {
16636 return false; 18194 return false;
16637 } 18195 }
16638 Element enclosingElement = element.enclosingElement; 18196 Element enclosingElement = element.enclosingElement;
16639 if (enclosingElement is! ClassElement) { 18197 if (enclosingElement is! ClassElement) {
16640 return false; 18198 return false;
16641 } 18199 }
16642 if ((element is MethodElement && !((element as MethodElement)).isStatic) || (element is PropertyAccessorElement && !((element as PropertyAccessorElement)).i sStatic)) { 18200 if ((element is MethodElement && !(element as MethodElement).isStatic) || (e lement is PropertyAccessorElement && !(element as PropertyAccessorElement).isSta tic)) {
16643 return false; 18201 return false;
16644 } 18202 }
16645 if (identical(enclosingElement, _enclosingClass)) { 18203 if (identical(enclosingElement, _enclosingClass)) {
16646 return false; 18204 return false;
16647 } 18205 }
16648 _errorReporter.reportError2(StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_N ON_LOCAL_STATIC_MEMBER, name, [name.name]); 18206 _errorReporter.reportError2(StaticTypeWarningCode.UNQUALIFIED_REFERENCE_TO_N ON_LOCAL_STATIC_MEMBER, name, [name.name]);
16649 return true; 18207 return true;
16650 } 18208 }
16651 18209
16652 /** 18210 /**
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
16726 return false; 18284 return false;
16727 } 18285 }
16728 ClassElement classElement = node.element; 18286 ClassElement classElement = node.element;
16729 if (classElement == null) { 18287 if (classElement == null) {
16730 return false; 18288 return false;
16731 } 18289 }
16732 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { 18290 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) {
16733 return false; 18291 return false;
16734 } 18292 }
16735 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call"); 18293 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement , "call");
16736 if (callMethod == null || callMethod is! MethodElement || ((callMethod as Me thodElement)).isAbstract) { 18294 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met hodElement).isAbstract) {
16737 _errorReporter.reportError2(StaticWarningCode.FUNCTION_WITHOUT_CALL, node. name, []); 18295 _errorReporter.reportError2(StaticWarningCode.FUNCTION_WITHOUT_CALL, node. name, []);
16738 return true; 18296 return true;
16739 } 18297 }
16740 return false; 18298 return false;
16741 } 18299 }
16742 18300
16743 /** 18301 /**
16744 * This verifies that the given class declaration does not have the same class in the 'extends' 18302 * This verifies that the given class declaration does not have the same class in the 'extends'
16745 * and 'implements' clauses. 18303 * and 'implements' clauses.
16746 * 18304 *
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
16811 18369
16812 /** 18370 /**
16813 * Return the variable element represented by the given expression, or `null` if there is no 18371 * Return the variable element represented by the given expression, or `null` if there is no
16814 * such element. 18372 * such element.
16815 * 18373 *
16816 * @param expression the expression whose element is to be returned 18374 * @param expression the expression whose element is to be returned
16817 * @return the variable element represented by the expression 18375 * @return the variable element represented by the expression
16818 */ 18376 */
16819 VariableElement getVariableElement(Expression expression) { 18377 VariableElement getVariableElement(Expression expression) {
16820 if (expression is Identifier) { 18378 if (expression is Identifier) {
16821 Element element = ((expression as Identifier)).staticElement; 18379 Element element = (expression as Identifier).staticElement;
16822 if (element is VariableElement) { 18380 if (element is VariableElement) {
16823 return element as VariableElement; 18381 return element as VariableElement;
16824 } 18382 }
16825 } 18383 }
16826 return null; 18384 return null;
16827 } 18385 }
16828 18386
16829 /** 18387 /**
16830 * @return `true` if the given constructor redirects to itself, directly or in directly 18388 * @return `true` if the given constructor redirects to itself, directly or in directly
16831 */ 18389 */
16832 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) { 18390 bool hasRedirectingFactoryConstructorCycle(ConstructorElement element) {
16833 Set<ConstructorElement> constructors = new Set<ConstructorElement>(); 18391 Set<ConstructorElement> constructors = new Set<ConstructorElement>();
16834 ConstructorElement current = element; 18392 ConstructorElement current = element;
16835 while (current != null) { 18393 while (current != null) {
16836 if (constructors.contains(current)) { 18394 if (constructors.contains(current)) {
16837 return identical(current, element); 18395 return identical(current, element);
16838 } 18396 }
16839 javaSetAdd(constructors, current); 18397 javaSetAdd(constructors, current);
16840 current = current.redirectedConstructor; 18398 current = current.redirectedConstructor;
16841 if (current is ConstructorMember) { 18399 if (current is ConstructorMember) {
16842 current = ((current as ConstructorMember)).baseElement; 18400 current = (current as ConstructorMember).baseElement;
16843 } 18401 }
16844 } 18402 }
16845 return false; 18403 return false;
16846 } 18404 }
16847 18405
16848 /** 18406 /**
16849 * @return <code>true</code> if given [Element] has direct or indirect referen ce to itself 18407 * @return <code>true</code> if given [Element] has direct or indirect referen ce to itself
16850 * from anywhere except [ClassElement] or type parameter bounds. 18408 * from anywhere except [ClassElement] or type parameter bounds.
16851 */ 18409 */
16852 bool hasTypedefSelfReference(Element target) { 18410 bool hasTypedefSelfReference(Element target) {
(...skipping 13 matching lines...) Expand all
16866 firstIteration = false; 18424 firstIteration = false;
16867 break; 18425 break;
16868 } else { 18426 } else {
16869 return true; 18427 return true;
16870 } 18428 }
16871 } 18429 }
16872 if (current != null && !checked.contains(current)) { 18430 if (current != null && !checked.contains(current)) {
16873 break; 18431 break;
16874 } 18432 }
16875 } 18433 }
16876 current.accept(new GeneralizingElementVisitor_14(target, toCheck)); 18434 current.accept(new GeneralizingElementVisitor_15(target, toCheck));
16877 javaSetAdd(checked, current); 18435 javaSetAdd(checked, current);
16878 } 18436 }
16879 } 18437 }
16880 18438
16881 /** 18439 /**
16882 * @return `true` if given [Type] implements operator <i>==</i>, and it is not 18440 * @return `true` if given [Type] implements operator <i>==</i>, and it is not
16883 * <i>int</i> or <i>String</i>. 18441 * <i>int</i> or <i>String</i>.
16884 */ 18442 */
16885 bool implementsEqualsWhenNotAllowed(Type2 type) { 18443 bool implementsEqualsWhenNotAllowed(Type2 type) {
16886 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) { 18444 if (type == null || type == _typeProvider.intType || type == _typeProvider.s tringType) {
16887 return false; 18445 return false;
16888 } 18446 }
16889 Element element = type.element; 18447 Element element = type.element;
16890 if (element is! ClassElement) { 18448 if (element is! ClassElement) {
16891 return false; 18449 return false;
16892 } 18450 }
16893 ClassElement classElement = element as ClassElement; 18451 ClassElement classElement = element as ClassElement;
16894 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); 18452 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
16895 if (method == null || method.enclosingElement.type.isObject) { 18453 if (method == null || method.enclosingElement.type.isObject) {
16896 return false; 18454 return false;
16897 } 18455 }
16898 return true; 18456 return true;
16899 } 18457 }
18458
16900 bool isFunctionType(Type2 type) { 18459 bool isFunctionType(Type2 type) {
16901 if (type.isDynamic || type.isBottom) { 18460 if (type.isDynamic || type.isBottom) {
16902 return true; 18461 return true;
16903 } else if (type is FunctionType || type.isDartCoreFunction) { 18462 } else if (type is FunctionType || type.isDartCoreFunction) {
16904 return true; 18463 return true;
16905 } else if (type is InterfaceType) { 18464 } else if (type is InterfaceType) {
16906 MethodElement callMethod = ((type as InterfaceType)).lookUpMethod(ElementR esolver.CALL_METHOD_NAME, _currentLibrary); 18465 MethodElement callMethod = (type as InterfaceType).lookUpMethod(ElementRes olver.CALL_METHOD_NAME, _currentLibrary);
16907 return callMethod != null; 18466 return callMethod != null;
16908 } 18467 }
16909 return false; 18468 return false;
16910 } 18469 }
16911 18470
16912 /** 18471 /**
16913 * @return `true` if the given [ASTNode] is the part of constant constructor 18472 * @return `true` if the given [ASTNode] is the part of constant constructor
16914 * invocation. 18473 * invocation.
16915 */ 18474 */
16916 bool isInConstConstructorInvocation(ASTNode node) { 18475 bool isInConstConstructorInvocation(ASTNode node) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
16954 * a static member of a supertype 18513 * a static member of a supertype
16955 */ 18514 */
16956 bool isUnqualifiedReferenceToNonLocalStaticMemberAllowed(SimpleIdentifier node ) { 18515 bool isUnqualifiedReferenceToNonLocalStaticMemberAllowed(SimpleIdentifier node ) {
16957 if (node.inDeclarationContext()) { 18516 if (node.inDeclarationContext()) {
16958 return true; 18517 return true;
16959 } 18518 }
16960 ASTNode parent = node.parent; 18519 ASTNode parent = node.parent;
16961 if (parent is ConstructorName || parent is MethodInvocation || parent is Pro pertyAccess || parent is SuperConstructorInvocation) { 18520 if (parent is ConstructorName || parent is MethodInvocation || parent is Pro pertyAccess || parent is SuperConstructorInvocation) {
16962 return true; 18521 return true;
16963 } 18522 }
16964 if (parent is PrefixedIdentifier && identical(((parent as PrefixedIdentifier )).identifier, node)) { 18523 if (parent is PrefixedIdentifier && identical((parent as PrefixedIdentifier) .identifier, node)) {
16965 return true; 18524 return true;
16966 } 18525 }
16967 if (parent is Annotation && identical(((parent as Annotation)).constructorNa me, node)) { 18526 if (parent is Annotation && identical((parent as Annotation).constructorName , node)) {
16968 return true; 18527 return true;
16969 } 18528 }
16970 if (parent is CommentReference) { 18529 if (parent is CommentReference) {
16971 CommentReference commentReference = parent as CommentReference; 18530 CommentReference commentReference = parent as CommentReference;
16972 if (commentReference.newKeyword != null) { 18531 if (commentReference.newKeyword != null) {
16973 return true; 18532 return true;
16974 } 18533 }
16975 } 18534 }
16976 return false; 18535 return false;
16977 } 18536 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
17051 InterfaceType superType = classElement.supertype; 18610 InterfaceType superType = classElement.supertype;
17052 if (superType != null) { 18611 if (superType != null) {
17053 ClassElement superClassElt = superType.element; 18612 ClassElement superClassElt = superType.element;
17054 if (superClassElt != null) { 18613 if (superClassElt != null) {
17055 return memberHasConcreteMethodImplementationInSuperclassChain(superClass Elt, methodName, superclassChain); 18614 return memberHasConcreteMethodImplementationInSuperclassChain(superClass Elt, methodName, superclassChain);
17056 } 18615 }
17057 } 18616 }
17058 return false; 18617 return false;
17059 } 18618 }
17060 } 18619 }
18620
17061 /** 18621 /**
17062 * This enum holds one of four states of a field initialization state through a constructor 18622 * This enum holds one of four states of a field initialization state through a constructor
17063 * signature, not initialized, initialized in the field declaration, initialized in the field 18623 * signature, not initialized, initialized in the field declaration, initialized in the field
17064 * formal, and finally, initialized in the initializers list. 18624 * formal, and finally, initialized in the initializers list.
17065 */ 18625 */
17066 class INIT_STATE extends Enum<INIT_STATE> { 18626 class INIT_STATE extends Enum<INIT_STATE> {
17067 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0); 18627 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0);
18628
17068 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT ION', 1); 18629 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT ION', 1);
18630
17069 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2); 18631 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2);
18632
17070 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 3); 18633 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 3);
18634
17071 static final List<INIT_STATE> values = [ 18635 static final List<INIT_STATE> values = [
17072 NOT_INIT, 18636 NOT_INIT,
17073 INIT_IN_DECLARATION, 18637 INIT_IN_DECLARATION,
17074 INIT_IN_FIELD_FORMAL, 18638 INIT_IN_FIELD_FORMAL,
17075 INIT_IN_INITIALIZERS]; 18639 INIT_IN_INITIALIZERS];
18640
17076 INIT_STATE(String name, int ordinal) : super(name, ordinal); 18641 INIT_STATE(String name, int ordinal) : super(name, ordinal);
17077 } 18642 }
17078 class GeneralizingElementVisitor_14 extends GeneralizingElementVisitor<Object> { 18643
18644 class GeneralizingElementVisitor_15 extends GeneralizingElementVisitor<Object> {
17079 Element target; 18645 Element target;
18646
17080 List<Element> toCheck; 18647 List<Element> toCheck;
17081 GeneralizingElementVisitor_14(this.target, this.toCheck) : super(); 18648
18649 GeneralizingElementVisitor_15(this.target, this.toCheck) : super();
18650
17082 bool _inClass = false; 18651 bool _inClass = false;
18652
17083 Object visitClassElement(ClassElement element) { 18653 Object visitClassElement(ClassElement element) {
17084 addTypeToCheck(element.supertype); 18654 addTypeToCheck(element.supertype);
17085 for (InterfaceType mixin in element.mixins) { 18655 for (InterfaceType mixin in element.mixins) {
17086 addTypeToCheck(mixin); 18656 addTypeToCheck(mixin);
17087 } 18657 }
17088 _inClass = !element.isTypedef; 18658 _inClass = !element.isTypedef;
17089 try { 18659 try {
17090 return super.visitClassElement(element); 18660 return super.visitClassElement(element);
17091 } finally { 18661 } finally {
17092 _inClass = false; 18662 _inClass = false;
17093 } 18663 }
17094 } 18664 }
18665
17095 Object visitExecutableElement(ExecutableElement element) { 18666 Object visitExecutableElement(ExecutableElement element) {
17096 if (element.isSynthetic) { 18667 if (element.isSynthetic) {
17097 return null; 18668 return null;
17098 } 18669 }
17099 addTypeToCheck(element.returnType); 18670 addTypeToCheck(element.returnType);
17100 return super.visitExecutableElement(element); 18671 return super.visitExecutableElement(element);
17101 } 18672 }
18673
17102 Object visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { 18674 Object visitFunctionTypeAliasElement(FunctionTypeAliasElement element) {
17103 addTypeToCheck(element.returnType); 18675 addTypeToCheck(element.returnType);
17104 return super.visitFunctionTypeAliasElement(element); 18676 return super.visitFunctionTypeAliasElement(element);
17105 } 18677 }
18678
17106 Object visitParameterElement(ParameterElement element) { 18679 Object visitParameterElement(ParameterElement element) {
17107 addTypeToCheck(element.type); 18680 addTypeToCheck(element.type);
17108 return super.visitParameterElement(element); 18681 return super.visitParameterElement(element);
17109 } 18682 }
18683
17110 Object visitTypeParameterElement(TypeParameterElement element) { 18684 Object visitTypeParameterElement(TypeParameterElement element) {
17111 addTypeToCheck(element.bound); 18685 addTypeToCheck(element.bound);
17112 return super.visitTypeParameterElement(element); 18686 return super.visitTypeParameterElement(element);
17113 } 18687 }
18688
17114 Object visitVariableElement(VariableElement element) { 18689 Object visitVariableElement(VariableElement element) {
17115 addTypeToCheck(element.type); 18690 addTypeToCheck(element.type);
17116 return super.visitVariableElement(element); 18691 return super.visitVariableElement(element);
17117 } 18692 }
18693
17118 void addTypeToCheck(Type2 type) { 18694 void addTypeToCheck(Type2 type) {
17119 if (type == null) { 18695 if (type == null) {
17120 return; 18696 return;
17121 } 18697 }
17122 Element element = type.element; 18698 Element element = type.element;
17123 if (_inClass && target == element) { 18699 if (_inClass && target == element) {
17124 return; 18700 return;
17125 } 18701 }
17126 toCheck.add(element); 18702 toCheck.add(element);
17127 if (type is InterfaceType) { 18703 if (type is InterfaceType) {
17128 InterfaceType interfaceType = type as InterfaceType; 18704 InterfaceType interfaceType = type as InterfaceType;
17129 for (Type2 typeArgument in interfaceType.typeArguments) { 18705 for (Type2 typeArgument in interfaceType.typeArguments) {
17130 addTypeToCheck(typeArgument); 18706 addTypeToCheck(typeArgument);
17131 } 18707 }
17132 } 18708 }
17133 } 18709 }
17134 } 18710 }
18711
17135 /** 18712 /**
17136 * The enumeration `ResolverErrorCode` defines the error codes used for errors d etected by the 18713 * The enumeration `ResolverErrorCode` defines the error codes used for errors d etected by the
17137 * resolver. The convention for this class is for the name of the error code to indicate the problem 18714 * resolver. The convention for this class is for the name of the error code to indicate the problem
17138 * that caused the error to be generated and for the error message to explain wh at is wrong and, 18715 * that caused the error to be generated and for the error message to explain wh at is wrong and,
17139 * when appropriate, how the problem can be corrected. 18716 * when appropriate, how the problem can be corrected.
17140 * 18717 *
17141 * @coverage dart.engine.resolver 18718 * @coverage dart.engine.resolver
17142 */ 18719 */
17143 class ResolverErrorCode extends Enum<ResolverErrorCode> implements ErrorCode { 18720 class ResolverErrorCode extends Enum<ResolverErrorCode> implements ErrorCode {
17144 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro rCode.con1('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Bre ak label resolves to case or default statement"); 18721 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro rCode.con1('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Bre ak label resolves to case or default statement");
18722
17145 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod e.con1('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label resolves to switch, must be loop or switch member"); 18723 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod e.con1('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label resolves to switch, must be loop or switch member");
18724
17146 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol verErrorCode.con1('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TI ME_ERROR, "Libraries that have parts must have a library directive"); 18725 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol verErrorCode.con1('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TI ME_ERROR, "Libraries that have parts must have a library directive");
18726
17147 static final List<ResolverErrorCode> values = [ 18727 static final List<ResolverErrorCode> values = [
17148 BREAK_LABEL_ON_SWITCH_MEMBER, 18728 BREAK_LABEL_ON_SWITCH_MEMBER,
17149 CONTINUE_LABEL_ON_SWITCH, 18729 CONTINUE_LABEL_ON_SWITCH,
17150 MISSING_LIBRARY_DIRECTIVE_WITH_PART]; 18730 MISSING_LIBRARY_DIRECTIVE_WITH_PART];
17151 18731
17152 /** 18732 /**
17153 * The type of this error. 18733 * The type of this error.
17154 */ 18734 */
17155 ErrorType _type; 18735 ErrorType _type;
17156 18736
(...skipping 24 matching lines...) Expand all
17181 * 18761 *
17182 * @param type the type of this error 18762 * @param type the type of this error
17183 * @param message the template used to create the message to be displayed for the error 18763 * @param message the template used to create the message to be displayed for the error
17184 * @param correction the template used to create the correction to be displaye d for the error 18764 * @param correction the template used to create the correction to be displaye d for the error
17185 */ 18765 */
17186 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) { 18766 ResolverErrorCode.con2(String name, int ordinal, ErrorType type, String messag e, String correction) : super(name, ordinal) {
17187 this._type = type; 18767 this._type = type;
17188 this._message = message; 18768 this._message = message;
17189 this.correction9 = correction; 18769 this.correction9 = correction;
17190 } 18770 }
18771
17191 String get correction => correction9; 18772 String get correction => correction9;
18773
17192 ErrorSeverity get errorSeverity => _type.severity; 18774 ErrorSeverity get errorSeverity => _type.severity;
18775
17193 String get message => _message; 18776 String get message => _message;
18777
17194 ErrorType get type => _type; 18778 ErrorType get type => _type;
17195 } 18779 }
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