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

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

Issue 14308011: New Analysis Engine snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.resolver; 4 library engine.resolver;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'java_core.dart'; 7 import 'java_core.dart';
8 import 'java_engine.dart'; 8 import 'java_engine.dart';
9 import 'instrumentation.dart';
9 import 'source.dart'; 10 import 'source.dart';
10 import 'error.dart'; 11 import 'error.dart';
11 import 'scanner.dart' as sc; 12 import 'scanner.dart' as sc;
12 import 'utilities_dart.dart'; 13 import 'utilities_dart.dart';
13 import 'ast.dart'; 14 import 'ast.dart';
14 import 'parser.dart' show Parser; 15 import 'parser.dart' show Parser, ParserErrorCode;
16 import 'sdk.dart' show DartSdk;
15 import 'element.dart' hide HideCombinator, ShowCombinator; 17 import 'element.dart' hide HideCombinator, ShowCombinator;
16 import 'html.dart' as ht; 18 import 'html.dart' as ht;
17 import 'engine.dart'; 19 import 'engine.dart';
18 import 'constant.dart'; 20 import 'constant.dart';
19 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator; 21 import 'element.dart' as __imp_combi show HideCombinator, ShowCombinator;
20 22
21 /** 23 /**
22 * Instances of the class {@code CompilationUnitBuilder} build an element model for a single 24 * Instances of the class {@code CompilationUnitBuilder} build an element model for a single
23 * compilation unit. 25 * compilation unit.
24 * @coverage dart.engine.resolver 26 * @coverage dart.engine.resolver
25 */ 27 */
26 class CompilationUnitBuilder { 28 class CompilationUnitBuilder {
27 /** 29 /**
28 * The analysis context in which the element model will be built.
29 */
30 AnalysisContextImpl _analysisContext;
31 /**
32 * Initialize a newly created compilation unit element builder. 30 * Initialize a newly created compilation unit element builder.
33 * @param analysisContext the analysis context in which the element model will be built 31 * @param analysisContext the analysis context in which the element model will be built
34 */ 32 */
35 CompilationUnitBuilder(AnalysisContextImpl analysisContext) { 33 CompilationUnitBuilder() : super() {
36 this._analysisContext = analysisContext;
37 } 34 }
38 /** 35 /**
39 * Build the compilation unit element for the given source. 36 * Build the compilation unit element for the given source.
40 * @param source the source describing the compilation unit 37 * @param source the source describing the compilation unit
41 * @return the compilation unit element that was built
42 * @throws AnalysisException if the analysis could not be performed
43 */
44 CompilationUnitElementImpl buildCompilationUnit(Source source) => buildCompila tionUnit2(source, _analysisContext.parseCompilationUnit(source));
45 /**
46 * Build the compilation unit element for the given source.
47 * @param source the source describing the compilation unit
48 * @param unit the AST structure representing the compilation unit 38 * @param unit the AST structure representing the compilation unit
49 * @return the compilation unit element that was built 39 * @return the compilation unit element that was built
50 * @throws AnalysisException if the analysis could not be performed 40 * @throws AnalysisException if the analysis could not be performed
51 */ 41 */
52 CompilationUnitElementImpl buildCompilationUnit2(Source source13, CompilationU nit unit) { 42 CompilationUnitElementImpl buildCompilationUnit(Source source18, CompilationUn it unit) {
53 if (unit == null) { 43 if (unit == null) {
54 return null; 44 return null;
55 } 45 }
56 ElementHolder holder = new ElementHolder(); 46 ElementHolder holder = new ElementHolder();
57 ElementBuilder builder = new ElementBuilder(holder); 47 ElementBuilder builder = new ElementBuilder(holder);
58 unit.accept(builder); 48 unit.accept(builder);
59 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source13 .shortName); 49 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source18 .shortName);
60 element.accessors = holder.accessors; 50 element.accessors = holder.accessors;
61 element.functions = holder.functions; 51 element.functions = holder.functions;
62 element.source = source13; 52 element.source = source18;
63 element.typeAliases = holder.typeAliases; 53 element.typeAliases = holder.typeAliases;
64 element.types = holder.types; 54 element.types = holder.types;
65 element.topLevelVariables = holder.topLevelVariables; 55 element.topLevelVariables = holder.topLevelVariables;
66 unit.element = element; 56 unit.element = element;
67 return element; 57 return element;
68 } 58 }
69 } 59 }
70 /** 60 /**
71 * Instances of the class {@code ElementBuilder} traverse an AST structure and b uild the element 61 * Instances of the class {@code ElementBuilder} traverse an AST structure and b uild the element
72 * model representing the AST structure. 62 * model representing the AST structure.
(...skipping 16 matching lines...) Expand all
89 * A flag indicating whether the class currently being visited can be used as a mixin. 79 * A flag indicating whether the class currently being visited can be used as a mixin.
90 */ 80 */
91 bool _isValidMixin = false; 81 bool _isValidMixin = false;
92 /** 82 /**
93 * Initialize a newly created element builder to build the elements for a comp ilation unit. 83 * Initialize a newly created element builder to build the elements for a comp ilation unit.
94 * @param initialHolder the element holder associated with the compilation uni t being built 84 * @param initialHolder the element holder associated with the compilation uni t being built
95 */ 85 */
96 ElementBuilder(ElementHolder initialHolder) { 86 ElementBuilder(ElementHolder initialHolder) {
97 _currentHolder = initialHolder; 87 _currentHolder = initialHolder;
98 } 88 }
89 Object visitBlock(Block node) {
90 bool wasInField = _inFieldContext;
91 _inFieldContext = false;
92 try {
93 node.visitChildren(this);
94 } finally {
95 _inFieldContext = wasInField;
96 }
97 return null;
98 }
99 Object visitCatchClause(CatchClause node) { 99 Object visitCatchClause(CatchClause node) {
100 SimpleIdentifier exceptionParameter2 = node.exceptionParameter; 100 SimpleIdentifier exceptionParameter2 = node.exceptionParameter;
101 if (exceptionParameter2 != null) { 101 if (exceptionParameter2 != null) {
102 LocalVariableElementImpl exception = new LocalVariableElementImpl(exceptio nParameter2); 102 LocalVariableElementImpl exception = new LocalVariableElementImpl(exceptio nParameter2);
103 _currentHolder.addLocalVariable(exception); 103 _currentHolder.addLocalVariable(exception);
104 exceptionParameter2.element = exception; 104 exceptionParameter2.element = exception;
105 SimpleIdentifier stackTraceParameter2 = node.stackTraceParameter; 105 SimpleIdentifier stackTraceParameter2 = node.stackTraceParameter;
106 if (stackTraceParameter2 != null) { 106 if (stackTraceParameter2 != null) {
107 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack TraceParameter2); 107 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack TraceParameter2);
108 _currentHolder.addLocalVariable(stackTrace); 108 _currentHolder.addLocalVariable(stackTrace);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 153 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
154 interfaceType.typeArguments = createTypeVariableTypes(typeVariables5); 154 interfaceType.typeArguments = createTypeVariableTypes(typeVariables5);
155 element.type = interfaceType; 155 element.type = interfaceType;
156 _currentHolder.addType(element); 156 _currentHolder.addType(element);
157 className.element = element; 157 className.element = element;
158 return null; 158 return null;
159 } 159 }
160 Object visitConstructorDeclaration(ConstructorDeclaration node) { 160 Object visitConstructorDeclaration(ConstructorDeclaration node) {
161 _isValidMixin = false; 161 _isValidMixin = false;
162 ElementHolder holder = new ElementHolder(); 162 ElementHolder holder = new ElementHolder();
163 visitChildren(holder, node); 163 bool wasInFunction = _inFunction;
164 _inFunction = true;
165 try {
166 visitChildren(holder, node);
167 } finally {
168 _inFunction = wasInFunction;
169 }
164 SimpleIdentifier constructorName = node.name; 170 SimpleIdentifier constructorName = node.name;
165 ConstructorElementImpl element = new ConstructorElementImpl(constructorName) ; 171 ConstructorElementImpl element = new ConstructorElementImpl(constructorName) ;
166 if (node.factoryKeyword != null) { 172 if (node.factoryKeyword != null) {
167 element.factory = true; 173 element.factory = true;
168 } 174 }
169 element.functions = holder.functions; 175 element.functions = holder.functions;
170 element.labels = holder.labels; 176 element.labels = holder.labels;
171 element.localVariables = holder.localVariables; 177 element.localVariables = holder.localVariables;
172 element.parameters = holder.parameters; 178 element.parameters = holder.parameters;
173 element.const2 = node.constKeyword != null; 179 element.const2 = node.constKeyword != null;
(...skipping 29 matching lines...) Expand all
203 FunctionElementImpl initializer = new FunctionElementImpl(); 209 FunctionElementImpl initializer = new FunctionElementImpl();
204 initializer.functions = holder.functions; 210 initializer.functions = holder.functions;
205 initializer.labels = holder.labels; 211 initializer.labels = holder.labels;
206 initializer.localVariables = holder.localVariables; 212 initializer.localVariables = holder.localVariables;
207 initializer.parameters = holder.parameters; 213 initializer.parameters = holder.parameters;
208 SimpleIdentifier parameterName = node.parameter.identifier; 214 SimpleIdentifier parameterName = node.parameter.identifier;
209 ParameterElementImpl parameter; 215 ParameterElementImpl parameter;
210 if (node.isConst()) { 216 if (node.isConst()) {
211 parameter = new ConstParameterElementImpl(parameterName); 217 parameter = new ConstParameterElementImpl(parameterName);
212 parameter.const3 = true; 218 parameter.const3 = true;
219 } else if (node.parameter is FieldFormalParameter) {
220 parameter = new FieldFormalParameterElementImpl(parameterName);
213 } else { 221 } else {
214 parameter = new ParameterElementImpl(parameterName); 222 parameter = new ParameterElementImpl(parameterName);
215 } 223 }
216 parameter.final2 = node.isFinal(); 224 parameter.final2 = node.isFinal();
217 parameter.initializer = initializer; 225 parameter.initializer = initializer;
218 parameter.parameterKind = node.kind; 226 parameter.parameterKind = node.kind;
219 FunctionBody body = getFunctionBody(node); 227 FunctionBody body = getFunctionBody(node);
220 if (body != null) { 228 if (body != null) {
221 parameter.setVisibleRange(body.offset, body.length); 229 parameter.setVisibleRange(body.offset, body.length);
222 } 230 }
223 _currentHolder.addParameter(parameter); 231 _currentHolder.addParameter(parameter);
224 parameterName.element = parameter; 232 parameterName.element = parameter;
225 node.parameter.accept(this); 233 node.parameter.accept(this);
226 return null; 234 return null;
227 } 235 }
228 Object visitFieldDeclaration(FieldDeclaration node) { 236 Object visitFieldDeclaration(FieldDeclaration node) {
229 bool wasInField = _inFieldContext; 237 bool wasInField = _inFieldContext;
230 _inFieldContext = true; 238 _inFieldContext = true;
231 try { 239 try {
232 node.visitChildren(this); 240 node.visitChildren(this);
233 } finally { 241 } finally {
234 _inFieldContext = wasInField; 242 _inFieldContext = wasInField;
235 } 243 }
236 return null; 244 return null;
237 } 245 }
238 Object visitFieldFormalParameter(FieldFormalParameter node) { 246 Object visitFieldFormalParameter(FieldFormalParameter node) {
239 if (node.parent is! DefaultFormalParameter) { 247 if (node.parent is! DefaultFormalParameter) {
240 SimpleIdentifier parameterName = node.identifier; 248 SimpleIdentifier parameterName = node.identifier;
241 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); 249 FieldFormalParameterElementImpl parameter = new FieldFormalParameterElemen tImpl(parameterName);
242 parameter.const3 = node.isConst(); 250 parameter.const3 = node.isConst();
243 parameter.initializingFormal = true; 251 parameter.initializingFormal = true;
244 parameter.final2 = node.isFinal(); 252 parameter.final2 = node.isFinal();
245 parameter.parameterKind = node.kind; 253 parameter.parameterKind = node.kind;
246 _currentHolder.addParameter(parameter); 254 _currentHolder.addParameter(parameter);
247 parameterName.element = parameter; 255 parameterName.element = parameter;
248 } 256 }
249 return super.visitFieldFormalParameter(node); 257 return super.visitFieldFormalParameter(node);
250 } 258 }
251 Object visitFunctionDeclaration(FunctionDeclaration node) { 259 Object visitFunctionDeclaration(FunctionDeclaration node) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 321 }
314 Object visitFunctionExpression(FunctionExpression node) { 322 Object visitFunctionExpression(FunctionExpression node) {
315 ElementHolder holder = new ElementHolder(); 323 ElementHolder holder = new ElementHolder();
316 bool wasInFunction = _inFunction; 324 bool wasInFunction = _inFunction;
317 _inFunction = true; 325 _inFunction = true;
318 try { 326 try {
319 visitChildren(holder, node); 327 visitChildren(holder, node);
320 } finally { 328 } finally {
321 _inFunction = wasInFunction; 329 _inFunction = wasInFunction;
322 } 330 }
323 SimpleIdentifier functionName = null; 331 FunctionElementImpl element = new FunctionElementImpl.con2(node.beginToken.o ffset);
324 FunctionElementImpl element = new FunctionElementImpl.con1(functionName);
325 element.functions = holder.functions; 332 element.functions = holder.functions;
326 element.labels = holder.labels; 333 element.labels = holder.labels;
327 element.localVariables = holder.localVariables; 334 element.localVariables = holder.localVariables;
328 element.parameters = holder.parameters; 335 element.parameters = holder.parameters;
329 if (_inFunction) { 336 if (_inFunction) {
330 Block enclosingBlock = node.getAncestor(Block); 337 Block enclosingBlock = node.getAncestor(Block);
331 if (enclosingBlock != null) { 338 if (enclosingBlock != null) {
332 int functionEnd = node.offset + node.length; 339 int functionEnd = node.offset + node.length;
333 int blockEnd = enclosingBlock.offset + enclosingBlock.length; 340 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
334 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1); 341 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
335 } 342 }
336 } 343 }
337 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 344 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
338 element.type = type; 345 element.type = type;
339 _currentHolder.addFunction(element); 346 _currentHolder.addFunction(element);
340 node.element = element; 347 node.element = element;
341 return null; 348 return null;
342 } 349 }
343 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 350 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
344 ElementHolder holder = new ElementHolder(); 351 ElementHolder holder = new ElementHolder();
345 visitChildren(holder, node); 352 visitChildren(holder, node);
346 SimpleIdentifier aliasName = node.name; 353 SimpleIdentifier aliasName = node.name;
347 List<ParameterElement> parameters10 = holder.parameters; 354 List<ParameterElement> parameters11 = holder.parameters;
348 List<TypeVariableElement> typeVariables6 = holder.typeVariables; 355 List<TypeVariableElement> typeVariables6 = holder.typeVariables;
349 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia sName); 356 FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(alia sName);
350 element.parameters = parameters10; 357 element.parameters = parameters11;
351 element.typeVariables = typeVariables6; 358 element.typeVariables = typeVariables6;
352 FunctionTypeImpl type = new FunctionTypeImpl.con2(element); 359 FunctionTypeImpl type = new FunctionTypeImpl.con2(element);
353 type.typeArguments = createTypeVariableTypes(typeVariables6); 360 type.typeArguments = createTypeVariableTypes(typeVariables6);
354 element.type = type; 361 element.type = type;
355 _currentHolder.addTypeAlias(element); 362 _currentHolder.addTypeAlias(element);
356 aliasName.element = element; 363 aliasName.element = element;
357 return null; 364 return null;
358 } 365 }
359 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 366 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
360 if (node.parent is! DefaultFormalParameter) { 367 if (node.parent is! DefaultFormalParameter) {
361 SimpleIdentifier parameterName = node.identifier; 368 SimpleIdentifier parameterName = node.identifier;
362 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); 369 ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
363 parameter.parameterKind = node.kind; 370 parameter.parameterKind = node.kind;
364 _currentHolder.addParameter(parameter); 371 _currentHolder.addParameter(parameter);
365 parameterName.element = parameter; 372 parameterName.element = parameter;
366 } 373 }
367 visitChildren(new ElementHolder(), node); 374 ElementHolder holder = new ElementHolder();
375 visitChildren(holder, node);
376 ((node.element as ParameterElementImpl)).parameters = holder.parameters;
368 return null; 377 return null;
369 } 378 }
370 Object visitLabeledStatement(LabeledStatement node) { 379 Object visitLabeledStatement(LabeledStatement node) {
371 bool onSwitchStatement = node.statement is SwitchStatement; 380 bool onSwitchStatement = node.statement is SwitchStatement;
372 for (Label label in node.labels) { 381 for (Label label in node.labels) {
373 SimpleIdentifier labelName = label.label; 382 SimpleIdentifier labelName = label.label;
374 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme nt, false); 383 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme nt, false);
375 _currentHolder.addLabel(element); 384 _currentHolder.addLabel(element);
376 labelName.element = element; 385 labelName.element = element;
377 } 386 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 691 }
683 void addType(ClassElement element) { 692 void addType(ClassElement element) {
684 _types.add(element); 693 _types.add(element);
685 } 694 }
686 void addTypeAlias(FunctionTypeAliasElement element) { 695 void addTypeAlias(FunctionTypeAliasElement element) {
687 _typeAliases.add(element); 696 _typeAliases.add(element);
688 } 697 }
689 void addTypeVariable(TypeVariableElement element) { 698 void addTypeVariable(TypeVariableElement element) {
690 _typeVariables.add(element); 699 _typeVariables.add(element);
691 } 700 }
692 List<PropertyAccessorElement> get accessors => new List.from(_accessors); 701 List<PropertyAccessorElement> get accessors {
693 List<ConstructorElement> get constructors => new List.from(_constructors); 702 if (_accessors.isEmpty) {
703 return PropertyAccessorElementImpl.EMPTY_ARRAY;
704 }
705 return new List.from(_accessors);
706 }
707 List<ConstructorElement> get constructors {
708 if (_constructors.isEmpty) {
709 return ConstructorElementImpl.EMPTY_ARRAY;
710 }
711 return new List.from(_constructors);
712 }
694 FieldElement getField(String fieldName) { 713 FieldElement getField(String fieldName) {
695 for (FieldElement field in _fields) { 714 for (FieldElement field in _fields) {
696 if (field.name == fieldName) { 715 if (field.name == fieldName) {
697 return field; 716 return field;
698 } 717 }
699 } 718 }
700 return null; 719 return null;
701 } 720 }
702 List<FieldElement> get fields => new List.from(_fields); 721 List<FieldElement> get fields {
703 List<FunctionElement> get functions => new List.from(_functions); 722 if (_fields.isEmpty) {
704 List<LabelElement> get labels => new List.from(_labels); 723 return FieldElementImpl.EMPTY_ARRAY;
705 List<LocalVariableElement> get localVariables => new List.from(_localVariables ); 724 }
706 List<MethodElement> get methods => new List.from(_methods); 725 return new List.from(_fields);
707 List<ParameterElement> get parameters => new List.from(_parameters); 726 }
708 List<TopLevelVariableElement> get topLevelVariables => new List.from(_topLevel Variables); 727 List<FunctionElement> get functions {
709 List<FunctionTypeAliasElement> get typeAliases => new List.from(_typeAliases); 728 if (_functions.isEmpty) {
710 List<ClassElement> get types => new List.from(_types); 729 return FunctionElementImpl.EMPTY_ARRAY;
711 List<TypeVariableElement> get typeVariables => new List.from(_typeVariables); 730 }
731 return new List.from(_functions);
732 }
733 List<LabelElement> get labels {
734 if (_labels.isEmpty) {
735 return LabelElementImpl.EMPTY_ARRAY;
736 }
737 return new List.from(_labels);
738 }
739 List<LocalVariableElement> get localVariables {
740 if (_localVariables.isEmpty) {
741 return LocalVariableElementImpl.EMPTY_ARRAY;
742 }
743 return new List.from(_localVariables);
744 }
745 List<MethodElement> get methods {
746 if (_methods.isEmpty) {
747 return MethodElementImpl.EMPTY_ARRAY;
748 }
749 return new List.from(_methods);
750 }
751 List<ParameterElement> get parameters {
752 if (_parameters.isEmpty) {
753 return ParameterElementImpl.EMPTY_ARRAY;
754 }
755 return new List.from(_parameters);
756 }
757 List<TopLevelVariableElement> get topLevelVariables {
758 if (_topLevelVariables.isEmpty) {
759 return TopLevelVariableElementImpl.EMPTY_ARRAY;
760 }
761 return new List.from(_topLevelVariables);
762 }
763 List<FunctionTypeAliasElement> get typeAliases {
764 if (_typeAliases.isEmpty) {
765 return FunctionTypeAliasElementImpl.EMPTY_ARRAY;
766 }
767 return new List.from(_typeAliases);
768 }
769 List<ClassElement> get types {
770 if (_types.isEmpty) {
771 return ClassElementImpl.EMPTY_ARRAY;
772 }
773 return new List.from(_types);
774 }
775 List<TypeVariableElement> get typeVariables {
776 if (_typeVariables.isEmpty) {
777 return TypeVariableElementImpl.EMPTY_ARRAY;
778 }
779 return new List.from(_typeVariables);
780 }
712 } 781 }
713 /** 782 /**
714 * Instances of the class {@code HtmlUnitBuilder} build an element model for a s ingle HTML unit. 783 * Instances of the class {@code HtmlUnitBuilder} build an element model for a s ingle HTML unit.
715 */ 784 */
716 class HtmlUnitBuilder implements ht.XmlVisitor<Object> { 785 class HtmlUnitBuilder implements ht.XmlVisitor<Object> {
717 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\""; 786 static String _APPLICATION_DART_IN_DOUBLE_QUOTES = "\"application/dart\"";
718 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'"; 787 static String _APPLICATION_DART_IN_SINGLE_QUOTES = "'application/dart'";
719 static String _SCRIPT = "script"; 788 static String _SCRIPT = "script";
720 static String _SRC = "src"; 789 static String _SRC = "src";
721 static String _TYPE = "type"; 790 static String _TYPE = "type";
722 /** 791 /**
723 * The analysis context in which the element model will be built. 792 * The analysis context in which the element model will be built.
724 */ 793 */
725 AnalysisContextImpl _context; 794 InternalAnalysisContext _context;
726 /** 795 /**
727 * The HTML element being built. 796 * The HTML element being built.
728 */ 797 */
729 HtmlElementImpl _htmlElement; 798 HtmlElementImpl _htmlElement;
730 /** 799 /**
731 * The script elements being built. 800 * The script elements being built.
732 */ 801 */
733 List<HtmlScriptElement> _scripts; 802 List<HtmlScriptElement> _scripts;
734 /** 803 /**
735 * Initialize a newly created HTML unit builder. 804 * Initialize a newly created HTML unit builder.
736 * @param context the analysis context in which the element model will be buil t 805 * @param context the analysis context in which the element model will be buil t
737 */ 806 */
738 HtmlUnitBuilder(AnalysisContextImpl context) { 807 HtmlUnitBuilder(InternalAnalysisContext context) {
739 this._context = context; 808 this._context = context;
740 } 809 }
741 /** 810 /**
742 * Build the HTML element for the given source. 811 * Build the HTML element for the given source.
743 * @param source the source describing the compilation unit 812 * @param source the source describing the compilation unit
744 * @return the HTML element that was built 813 * @return the HTML element that was built
745 * @throws AnalysisException if the analysis could not be performed 814 * @throws AnalysisException if the analysis could not be performed
746 */ 815 */
747 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _ context.parseHtmlUnit(source)); 816 HtmlElementImpl buildHtmlElement(Source source) => buildHtmlElement2(source, _ context.parseHtmlUnit(source));
748 /** 817 /**
749 * Build the HTML element for the given source. 818 * Build the HTML element for the given source.
750 * @param source the source describing the compilation unit 819 * @param source the source describing the compilation unit
751 * @param unit the AST structure representing the HTML 820 * @param unit the AST structure representing the HTML
752 * @throws AnalysisException if the analysis could not be performed 821 * @throws AnalysisException if the analysis could not be performed
753 */ 822 */
754 HtmlElementImpl buildHtmlElement2(Source source14, ht.HtmlUnit unit) { 823 HtmlElementImpl buildHtmlElement2(Source source19, ht.HtmlUnit unit) {
755 HtmlElementImpl result = new HtmlElementImpl(_context, source14.shortName); 824 HtmlElementImpl result = new HtmlElementImpl(_context, source19.shortName);
756 result.source = source14; 825 result.source = source19;
757 _htmlElement = result; 826 _htmlElement = result;
758 unit.accept(this); 827 unit.accept(this);
759 _htmlElement = null; 828 _htmlElement = null;
760 unit.element = result; 829 unit.element = result;
761 return result; 830 return result;
762 } 831 }
763 Object visitHtmlUnit(ht.HtmlUnit node) { 832 Object visitHtmlUnit(ht.HtmlUnit node) {
764 _scripts = new List<HtmlScriptElement>(); 833 _scripts = new List<HtmlScriptElement>();
765 node.visitChildren(this); 834 node.visitChildren(this);
766 _htmlElement.scripts = new List.from(_scripts); 835 _htmlElement.scripts = new List.from(_scripts);
767 _scripts = null; 836 _scripts = null;
768 return null; 837 return null;
769 } 838 }
770 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null; 839 Object visitXmlAttributeNode(ht.XmlAttributeNode node) => null;
771 Object visitXmlTagNode(ht.XmlTagNode node) { 840 Object visitXmlTagNode(ht.XmlTagNode node) {
772 if (isScriptNode(node)) { 841 if (isScriptNode(node)) {
773 Source htmlSource = _htmlElement.source; 842 Source htmlSource = _htmlElement.source;
774 String scriptSourcePath = getScriptSourcePath(node); 843 String scriptSourcePath = getScriptSourcePath(node);
775 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) { 844 if (identical(node.attributeEnd.type, ht.TokenType.GT) && scriptSourcePath == null) {
776 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node); 845 EmbeddedHtmlScriptElementImpl script = new EmbeddedHtmlScriptElementImpl (node);
777 String contents = node.content; 846 String contents = node.content;
778 AnalysisErrorListener errorListener = new AnalysisErrorListener_2(); 847 AnalysisErrorListener errorListener = new AnalysisErrorListener_5();
779 sc.StringScanner scanner = new sc.StringScanner(null, contents, errorLis tener); 848 sc.StringScanner scanner = new sc.StringScanner(null, contents, errorLis tener);
780 sc.Token firstToken = scanner.tokenize(); 849 sc.Token firstToken = scanner.tokenize();
781 List<int> lineStarts2 = scanner.lineStarts; 850 List<int> lineStarts2 = scanner.lineStarts;
782 Parser parser = new Parser(null, errorListener); 851 Parser parser = new Parser(null, errorListener);
783 CompilationUnit unit = parser.parseCompilationUnit(firstToken); 852 CompilationUnit unit = parser.parseCompilationUnit(firstToken);
784 try { 853 try {
785 CompilationUnitBuilder builder = new CompilationUnitBuilder(_context); 854 CompilationUnitBuilder builder = new CompilationUnitBuilder();
786 CompilationUnitElementImpl elem = builder.buildCompilationUnit2(htmlSo urce, unit); 855 CompilationUnitElementImpl elem = builder.buildCompilationUnit(htmlSou rce, unit);
787 LibraryElementImpl library = new LibraryElementImpl(_context, null); 856 LibraryElementImpl library = new LibraryElementImpl(_context, null);
788 library.definingCompilationUnit = elem; 857 library.definingCompilationUnit = elem;
789 script.scriptLibrary = library; 858 script.scriptLibrary = library;
790 } on AnalysisException catch (e) { 859 } on AnalysisException catch (e) {
791 print(e); 860 print(e);
792 } 861 }
793 _scripts.add(script); 862 _scripts.add(script);
794 } else { 863 } else {
795 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node); 864 ExternalHtmlScriptElementImpl script = new ExternalHtmlScriptElementImpl (node);
796 if (scriptSourcePath != null) { 865 if (scriptSourcePath != null) {
797 script.scriptSource = htmlSource.resolve(scriptSourcePath); 866 script.scriptSource = _context.sourceFactory.resolveUri(htmlSource, sc riptSourcePath);
798 } 867 }
799 _scripts.add(script); 868 _scripts.add(script);
800 } 869 }
801 } else { 870 } else {
802 node.visitChildren(this); 871 node.visitChildren(this);
803 } 872 }
804 return null; 873 return null;
805 } 874 }
806 /** 875 /**
807 * Return the value of the source attribute if it exists. 876 * Return the value of the source attribute if it exists.
(...skipping 25 matching lines...) Expand all
833 String value = valueToken.lexeme; 902 String value = valueToken.lexeme;
834 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI ON_DART_IN_SINGLE_QUOTES) { 903 if (value == _APPLICATION_DART_IN_DOUBLE_QUOTES || value == _APPLICATI ON_DART_IN_SINGLE_QUOTES) {
835 return true; 904 return true;
836 } 905 }
837 } 906 }
838 } 907 }
839 } 908 }
840 return false; 909 return false;
841 } 910 }
842 } 911 }
843 class AnalysisErrorListener_2 implements AnalysisErrorListener { 912 class AnalysisErrorListener_5 implements AnalysisErrorListener {
844 void onError(AnalysisError error) { 913 void onError(AnalysisError error) {
845 } 914 }
846 } 915 }
847 /** 916 /**
917 * Instances of the class {@code DeclarationResolver} are used to resolve declar ations in an AST
918 * structure to already built elements.
919 */
920 class DeclarationResolver extends RecursiveASTVisitor<Object> {
921 /**
922 * The compilation unit containing the AST nodes being visited.
923 */
924 CompilationUnitElement _enclosingUnit;
925 /**
926 * The function type alias containing the AST nodes being visited, or {@code n ull} if we are not
927 * in the scope of a function type alias.
928 */
929 FunctionTypeAliasElement _enclosingAlias;
930 /**
931 * The class containing the AST nodes being visited, or {@code null} if we are not in the scope of
932 * a class.
933 */
934 ClassElement _enclosingClass;
935 /**
936 * The method or function containing the AST nodes being visited, or {@code nu ll} if we are not in
937 * the scope of a method or function.
938 */
939 ExecutableElement _enclosingExecutable;
940 /**
941 * The parameter containing the AST nodes being visited, or {@code null} if we are not in the
942 * scope of a parameter.
943 */
944 ParameterElement _enclosingParameter;
945 /**
946 * Initialize a newly created resolver.
947 */
948 DeclarationResolver() : super() {
949 }
950 /**
951 * Resolve the declarations within the given compilation unit to the elements rooted at the given
952 * element.
953 * @param unit the compilation unit to be resolved
954 * @param element the root of the element model used to resolve the AST nodes
955 */
956 void resolve(CompilationUnit unit, CompilationUnitElement element67) {
957 _enclosingUnit = element67;
958 unit.element = element67;
959 unit.accept(this);
960 }
961 Object visitCatchClause(CatchClause node) {
962 SimpleIdentifier exceptionParameter3 = node.exceptionParameter;
963 if (exceptionParameter3 != null) {
964 List<LocalVariableElement> localVariables3 = _enclosingExecutable.localVar iables;
965 find3(localVariables3, exceptionParameter3);
966 SimpleIdentifier stackTraceParameter3 = node.stackTraceParameter;
967 if (stackTraceParameter3 != null) {
968 find3(localVariables3, stackTraceParameter3);
969 }
970 }
971 return super.visitCatchClause(node);
972 }
973 Object visitClassDeclaration(ClassDeclaration node) {
974 ClassElement outerClass = _enclosingClass;
975 try {
976 SimpleIdentifier className = node.name;
977 _enclosingClass = find3(_enclosingUnit.types, className);
978 return super.visitClassDeclaration(node);
979 } finally {
980 _enclosingClass = outerClass;
981 }
982 }
983 Object visitClassTypeAlias(ClassTypeAlias node) {
984 ClassElement outerClass = _enclosingClass;
985 try {
986 SimpleIdentifier className = node.name;
987 _enclosingClass = find3(_enclosingUnit.types, className);
988 return super.visitClassTypeAlias(node);
989 } finally {
990 _enclosingClass = outerClass;
991 }
992 }
993 Object visitConstructorDeclaration(ConstructorDeclaration node) {
994 ExecutableElement outerExecutable = _enclosingExecutable;
995 try {
996 SimpleIdentifier constructorName = node.name;
997 if (constructorName == null) {
998 _enclosingExecutable = _enclosingClass.unnamedConstructor;
999 } else {
1000 _enclosingExecutable = _enclosingClass.getNamedConstructor(constructorNa me.name);
1001 constructorName.element = _enclosingExecutable;
1002 }
1003 node.element = _enclosingExecutable as ConstructorElement;
1004 return super.visitConstructorDeclaration(node);
1005 } finally {
1006 _enclosingExecutable = outerExecutable;
1007 }
1008 }
1009 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
1010 SimpleIdentifier variableName = node.identifier;
1011 find3(_enclosingExecutable.localVariables, variableName);
1012 return super.visitDeclaredIdentifier(node);
1013 }
1014 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
1015 SimpleIdentifier parameterName = node.parameter.identifier;
1016 ParameterElement element = find3(_enclosingExecutable.parameters, parameterN ame);
1017 Expression defaultValue2 = node.defaultValue;
1018 if (defaultValue2 != null) {
1019 ExecutableElement outerExecutable = _enclosingExecutable;
1020 try {
1021 if (element == null) {
1022 } else {
1023 _enclosingExecutable = element.initializer;
1024 }
1025 defaultValue2.accept(this);
1026 } finally {
1027 _enclosingExecutable = outerExecutable;
1028 }
1029 }
1030 ParameterElement outerParameter = _enclosingParameter;
1031 try {
1032 _enclosingParameter = element;
1033 return super.visitDefaultFormalParameter(node);
1034 } finally {
1035 _enclosingParameter = outerParameter;
1036 }
1037 }
1038 Object visitExportDirective(ExportDirective node) {
1039 String uri3 = getStringValue(node.uri);
1040 if (uri3 != null) {
1041 LibraryElement library31 = _enclosingUnit.library;
1042 ExportElement exportElement = find5(library31.exports, _enclosingUnit.cont ext.sourceFactory.resolveUri(_enclosingUnit.source, uri3));
1043 node.element = exportElement;
1044 }
1045 return super.visitExportDirective(node);
1046 }
1047 Object visitFieldFormalParameter(FieldFormalParameter node) {
1048 if (node.parent is! DefaultFormalParameter) {
1049 SimpleIdentifier parameterName = node.identifier;
1050 ParameterElement element = find3(_enclosingExecutable.parameters, paramete rName);
1051 ParameterElement outerParameter = _enclosingParameter;
1052 try {
1053 _enclosingParameter = element;
1054 return super.visitFieldFormalParameter(node);
1055 } finally {
1056 _enclosingParameter = outerParameter;
1057 }
1058 } else {
1059 return super.visitFieldFormalParameter(node);
1060 }
1061 }
1062 Object visitFunctionDeclaration(FunctionDeclaration node) {
1063 ExecutableElement outerExecutable = _enclosingExecutable;
1064 try {
1065 SimpleIdentifier functionName = node.name;
1066 sc.Token property = node.propertyKeyword;
1067 if (property == null) {
1068 if (_enclosingExecutable != null) {
1069 _enclosingExecutable = find3(_enclosingExecutable.functions, functionN ame);
1070 } else {
1071 _enclosingExecutable = find3(_enclosingUnit.functions, functionName);
1072 }
1073 } else {
1074 PropertyAccessorElement accessor = find3(_enclosingUnit.accessors, funct ionName);
1075 if (identical(((property as sc.KeywordToken)).keyword, sc.Keyword.SET)) {
1076 accessor = accessor.variable.setter;
1077 functionName.element = accessor;
1078 }
1079 _enclosingExecutable = accessor;
1080 }
1081 node.functionExpression.element = _enclosingExecutable;
1082 return super.visitFunctionDeclaration(node);
1083 } finally {
1084 _enclosingExecutable = outerExecutable;
1085 }
1086 }
1087 Object visitFunctionExpression(FunctionExpression node) {
1088 if (node.parent is! FunctionDeclaration) {
1089 FunctionElement element = find2(_enclosingExecutable.functions, node.begin Token.offset);
1090 node.element = element;
1091 }
1092 ExecutableElement outerExecutable = _enclosingExecutable;
1093 try {
1094 _enclosingExecutable = node.element;
1095 return super.visitFunctionExpression(node);
1096 } finally {
1097 _enclosingExecutable = outerExecutable;
1098 }
1099 }
1100 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
1101 FunctionTypeAliasElement outerAlias = _enclosingAlias;
1102 try {
1103 SimpleIdentifier aliasName = node.name;
1104 _enclosingAlias = find3(_enclosingUnit.functionTypeAliases, aliasName);
1105 return super.visitFunctionTypeAlias(node);
1106 } finally {
1107 _enclosingAlias = outerAlias;
1108 }
1109 }
1110 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
1111 if (node.parent is! DefaultFormalParameter) {
1112 SimpleIdentifier parameterName = node.identifier;
1113 ParameterElement element = find3(_enclosingExecutable.parameters, paramete rName);
1114 ParameterElement outerParameter = _enclosingParameter;
1115 try {
1116 _enclosingParameter = element;
1117 return super.visitFunctionTypedFormalParameter(node);
1118 } finally {
1119 _enclosingParameter = outerParameter;
1120 }
1121 } else {
1122 return super.visitFunctionTypedFormalParameter(node);
1123 }
1124 }
1125 Object visitImportDirective(ImportDirective node) {
1126 String uri4 = getStringValue(node.uri);
1127 if (uri4 != null) {
1128 LibraryElement library32 = _enclosingUnit.library;
1129 ImportElement importElement = find6(library32.imports, _enclosingUnit.cont ext.sourceFactory.resolveUri(_enclosingUnit.source, uri4), node.prefix);
1130 node.element = importElement;
1131 }
1132 return super.visitImportDirective(node);
1133 }
1134 Object visitLabeledStatement(LabeledStatement node) {
1135 for (Label label in node.labels) {
1136 SimpleIdentifier labelName = label.label;
1137 find3(_enclosingExecutable.labels, labelName);
1138 }
1139 return super.visitLabeledStatement(node);
1140 }
1141 Object visitLibraryDirective(LibraryDirective node) {
1142 node.element = _enclosingUnit.library;
1143 return super.visitLibraryDirective(node);
1144 }
1145 Object visitMethodDeclaration(MethodDeclaration node) {
1146 ExecutableElement outerExecutable = _enclosingExecutable;
1147 try {
1148 sc.Token property = node.propertyKeyword;
1149 SimpleIdentifier methodName = node.name;
1150 String nameOfMethod = methodName.name;
1151 if (nameOfMethod == sc.TokenType.MINUS.lexeme && node.parameters.parameter s.length == 0) {
1152 nameOfMethod = "unary-";
1153 }
1154 if (property == null) {
1155 _enclosingExecutable = find4(_enclosingClass.methods, nameOfMethod, meth odName.offset);
1156 methodName.element = _enclosingExecutable;
1157 } else {
1158 PropertyAccessorElement accessor = find3(_enclosingClass.accessors, meth odName);
1159 if (identical(((property as sc.KeywordToken)).keyword, sc.Keyword.SET)) {
1160 accessor = accessor.variable.setter;
1161 methodName.element = accessor;
1162 }
1163 _enclosingExecutable = accessor;
1164 }
1165 return super.visitMethodDeclaration(node);
1166 } finally {
1167 _enclosingExecutable = outerExecutable;
1168 }
1169 }
1170 Object visitPartDirective(PartDirective node) {
1171 String uri5 = getStringValue(node.uri);
1172 if (uri5 != null) {
1173 Source partSource = _enclosingUnit.context.sourceFactory.resolveUri(_enclo singUnit.source, uri5);
1174 node.element = find(_enclosingUnit.library.parts, partSource);
1175 }
1176 return super.visitPartDirective(node);
1177 }
1178 Object visitPartOfDirective(PartOfDirective node) {
1179 node.element = _enclosingUnit.library;
1180 return super.visitPartOfDirective(node);
1181 }
1182 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
1183 if (node.parent is! DefaultFormalParameter) {
1184 SimpleIdentifier parameterName = node.identifier;
1185 ParameterElement element = null;
1186 if (_enclosingParameter != null) {
1187 element = find3(_enclosingParameter.parameters, parameterName);
1188 } else if (_enclosingExecutable != null) {
1189 element = find3(_enclosingExecutable.parameters, parameterName);
1190 } else if (_enclosingAlias != null) {
1191 element = find3(_enclosingAlias.parameters, parameterName);
1192 } else {
1193 }
1194 ParameterElement outerParameter = _enclosingParameter;
1195 try {
1196 _enclosingParameter = element;
1197 return super.visitSimpleFormalParameter(node);
1198 } finally {
1199 _enclosingParameter = outerParameter;
1200 }
1201 } else {
1202 }
1203 return super.visitSimpleFormalParameter(node);
1204 }
1205 Object visitSwitchCase(SwitchCase node) {
1206 for (Label label in node.labels) {
1207 SimpleIdentifier labelName = label.label;
1208 find3(_enclosingExecutable.labels, labelName);
1209 }
1210 return super.visitSwitchCase(node);
1211 }
1212 Object visitSwitchDefault(SwitchDefault node) {
1213 for (Label label in node.labels) {
1214 SimpleIdentifier labelName = label.label;
1215 find3(_enclosingExecutable.labels, labelName);
1216 }
1217 return super.visitSwitchDefault(node);
1218 }
1219 Object visitTypeParameter(TypeParameter node) {
1220 SimpleIdentifier parameterName = node.name;
1221 if (_enclosingClass != null) {
1222 find3(_enclosingClass.typeVariables, parameterName);
1223 } else if (_enclosingAlias != null) {
1224 find3(_enclosingAlias.typeVariables, parameterName);
1225 }
1226 return super.visitTypeParameter(node);
1227 }
1228 Object visitVariableDeclaration(VariableDeclaration node) {
1229 VariableElement element = null;
1230 SimpleIdentifier variableName = node.name;
1231 if (_enclosingExecutable != null) {
1232 element = find3(_enclosingExecutable.localVariables, variableName);
1233 }
1234 if (element == null && _enclosingClass != null) {
1235 element = find3(_enclosingClass.fields, variableName);
1236 }
1237 if (element == null && _enclosingUnit != null) {
1238 element = find3(_enclosingUnit.topLevelVariables, variableName);
1239 }
1240 Expression initializer5 = node.initializer;
1241 if (initializer5 != null) {
1242 ExecutableElement outerExecutable = _enclosingExecutable;
1243 try {
1244 if (element == null) {
1245 } else {
1246 _enclosingExecutable = element.initializer;
1247 }
1248 return super.visitVariableDeclaration(node);
1249 } finally {
1250 _enclosingExecutable = outerExecutable;
1251 }
1252 }
1253 return super.visitVariableDeclaration(node);
1254 }
1255 /**
1256 * Append the value of the given string literal to the given string builder.
1257 * @param builder the builder to which the string's value is to be appended
1258 * @param literal the string literal whose value is to be appended to the buil der
1259 * @throws IllegalArgumentException if the string is not a constant string wit hout any string
1260 * interpolation
1261 */
1262 void appendStringValue(JavaStringBuilder builder, StringLiteral literal) {
1263 if (literal is SimpleStringLiteral) {
1264 builder.append(((literal as SimpleStringLiteral)).value);
1265 } else if (literal is AdjacentStrings) {
1266 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings ) {
1267 appendStringValue(builder, stringLiteral);
1268 }
1269 } else {
1270 throw new IllegalArgumentException();
1271 }
1272 }
1273 /**
1274 * Return the element for the part with the given source, or {@code null} if t here is no element
1275 * for the given source.
1276 * @param parts the elements for the parts
1277 * @param partSource the source for the part whose element is to be returned
1278 * @return the element for the part with the given source
1279 */
1280 CompilationUnitElement find(List<CompilationUnitElement> parts, Source partSou rce) {
1281 for (CompilationUnitElement part in parts) {
1282 if (part.source == partSource) {
1283 return part;
1284 }
1285 }
1286 return null;
1287 }
1288 /**
1289 * Return the element in the given array of elements that was created for the declaration at the
1290 * given offset. This method should only be used when there is no name
1291 * @param elements the elements of the appropriate kind that exist in the curr ent context
1292 * @param offset the offset of the name of the element to be returned
1293 * @return the element at the given offset
1294 */
1295 Element find2(List<Element> elements, int offset) => find4(elements, "", offse t);
1296 /**
1297 * Return the element in the given array of elements that was created for the declaration with the
1298 * given name.
1299 * @param elements the elements of the appropriate kind that exist in the curr ent context
1300 * @param identifier the name node in the declaration of the element to be ret urned
1301 * @return the element created for the declaration with the given name
1302 */
1303 Element find3(List<Element> elements, SimpleIdentifier identifier) {
1304 Element element = find4(elements, identifier.name, identifier.offset);
1305 identifier.element = element;
1306 return element;
1307 }
1308 /**
1309 * Return the element in the given array of elements that was created for the declaration with the
1310 * given name at the given offset.
1311 * @param elements the elements of the appropriate kind that exist in the curr ent context
1312 * @param name the name of the element to be returned
1313 * @param offset the offset of the name of the element to be returned
1314 * @return the element with the given name and offset
1315 */
1316 Element find4(List<Element> elements, String name30, int offset) {
1317 for (Element element in elements) {
1318 if (element.name == name30 && element.nameOffset == offset) {
1319 return element;
1320 }
1321 }
1322 return null;
1323 }
1324 /**
1325 * Return the export element from the given array whose library has the given source, or{@code null} if there is no such export.
1326 * @param exports the export elements being searched
1327 * @param source the source of the library associated with the export element to being searched
1328 * for
1329 * @return the export element whose library has the given source
1330 */
1331 ExportElement find5(List<ExportElement> exports, Source source21) {
1332 for (ExportElement export in exports) {
1333 if (export.exportedLibrary.source == source21) {
1334 return export;
1335 }
1336 }
1337 return null;
1338 }
1339 /**
1340 * Return the import element from the given array whose library has the given source and that has
1341 * the given prefix, or {@code null} if there is no such import.
1342 * @param imports the import elements being searched
1343 * @param source the source of the library associated with the import element to being searched
1344 * for
1345 * @param prefix the prefix with which the library was imported
1346 * @return the import element whose library has the given source and prefix
1347 */
1348 ImportElement find6(List<ImportElement> imports, Source source22, SimpleIdenti fier prefix12) {
1349 for (ImportElement element in imports) {
1350 if (element.importedLibrary.source == source22) {
1351 PrefixElement prefixElement = element.prefix;
1352 if (prefix12 == null) {
1353 if (prefixElement == null) {
1354 return element;
1355 }
1356 } else {
1357 if (prefixElement != null && prefix12.name == prefixElement.name) {
1358 return element;
1359 }
1360 }
1361 }
1362 }
1363 return null;
1364 }
1365 /**
1366 * Return the value of the given string literal, or {@code null} if the string is not a constant
1367 * string without any string interpolation.
1368 * @param literal the string literal whose value is to be returned
1369 * @return the value of the given string literal
1370 */
1371 String getStringValue(StringLiteral literal) {
1372 if (literal is StringInterpolation) {
1373 return null;
1374 }
1375 JavaStringBuilder builder = new JavaStringBuilder();
1376 try {
1377 appendStringValue(builder, literal);
1378 } on IllegalArgumentException catch (exception) {
1379 return null;
1380 }
1381 return builder.toString().trim();
1382 }
1383 }
1384 /**
848 * Instances of the class {@code ElementResolver} are used by instances of {@lin k ResolverVisitor}to resolve references within the AST structure to the elements being referenced. The requirements 1385 * Instances of the class {@code ElementResolver} are used by instances of {@lin k ResolverVisitor}to resolve references within the AST structure to the elements being referenced. The requirements
849 * for the element resolver are: 1386 * for the element resolver are:
850 * <ol> 1387 * <ol>
851 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which it refers. 1388 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which it refers.
852 * Specifically: 1389 * Specifically:
853 * <ul> 1390 * <ul>
854 * <li>An identifier within the declaration of that name should resolve to the e lement being 1391 * <li>An identifier within the declaration of that name should resolve to the e lement being
855 * declared.</li> 1392 * declared.</li>
856 * <li>An identifier denoting a prefix should resolve to the element representin g the import that 1393 * <li>An identifier denoting a prefix should resolve to the element representin g the import that
857 * defines the prefix (an {@link ImportElement}).</li> 1394 * defines the prefix (an {@link ImportElement}).</li>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 this._resolver = resolver; 1441 this._resolver = resolver;
905 } 1442 }
906 Object visitAssignmentExpression(AssignmentExpression node) { 1443 Object visitAssignmentExpression(AssignmentExpression node) {
907 sc.TokenType operator7 = node.operator.type; 1444 sc.TokenType operator7 = node.operator.type;
908 if (operator7 != sc.TokenType.EQ) { 1445 if (operator7 != sc.TokenType.EQ) {
909 operator7 = operatorFromCompoundAssignment(operator7); 1446 operator7 = operatorFromCompoundAssignment(operator7);
910 Expression leftNode = node.leftHandSide; 1447 Expression leftNode = node.leftHandSide;
911 if (leftNode != null) { 1448 if (leftNode != null) {
912 Type2 leftType = getType(leftNode); 1449 Type2 leftType = getType(leftNode);
913 if (leftType != null) { 1450 if (leftType != null) {
914 Element leftElement = leftType.element; 1451 MethodElement method = lookUpMethod(leftType, operator7.lexeme);
915 if (leftElement != null) { 1452 if (method != null) {
916 MethodElement method = lookUpMethod(leftElement, operator7.lexeme); 1453 node.element = method;
917 if (method != null) { 1454 } else {
918 node.element = method;
919 } else {
920 }
921 } 1455 }
922 } 1456 }
923 } 1457 }
924 } 1458 }
925 return null; 1459 return null;
926 } 1460 }
927 Object visitBinaryExpression(BinaryExpression node) { 1461 Object visitBinaryExpression(BinaryExpression node) {
928 sc.Token operator8 = node.operator; 1462 sc.Token operator8 = node.operator;
929 if (operator8.isUserDefinableOperator()) { 1463 if (operator8.isUserDefinableOperator()) {
930 Type2 leftType = getType(node.leftOperand); 1464 Type2 leftType = getType(node.leftOperand);
931 Element leftTypeElement;
932 if (leftType == null || leftType.isDynamic()) { 1465 if (leftType == null || leftType.isDynamic()) {
933 return null; 1466 return null;
934 } else if (leftType is FunctionType) { 1467 } else if (leftType is FunctionType) {
935 leftTypeElement = _resolver.typeProvider.functionType.element; 1468 leftType = _resolver.typeProvider.functionType;
936 } else {
937 leftTypeElement = leftType.element;
938 } 1469 }
939 String methodName = operator8.lexeme; 1470 String methodName = operator8.lexeme;
940 MethodElement member = lookUpMethod(leftTypeElement, methodName); 1471 MethodElement member = lookUpMethod(leftType, methodName);
941 if (member == null) { 1472 if (member == null) {
942 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator8, [methodName]); 1473 _resolver.reportError3(StaticWarningCode.UNDEFINED_OPERATOR, operator8, [methodName, leftType.name]);
943 } else { 1474 } else {
944 node.element = member; 1475 node.element = member;
945 } 1476 }
946 } 1477 }
947 return null; 1478 return null;
948 } 1479 }
949 Object visitBreakStatement(BreakStatement node) { 1480 Object visitBreakStatement(BreakStatement node) {
950 SimpleIdentifier labelNode = node.label; 1481 SimpleIdentifier labelNode = node.label;
951 LabelElementImpl labelElement = lookupLabel(node, labelNode); 1482 LabelElementImpl labelElement = lookupLabel(node, labelNode);
952 if (labelElement != null && labelElement.isOnSwitchMember()) { 1483 if (labelElement != null && labelElement.isOnSwitchMember()) {
953 _resolver.reportError(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labe lNode, []); 1484 _resolver.reportError(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labe lNode, []);
954 } 1485 }
955 return null; 1486 return null;
956 } 1487 }
1488 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
1489 FieldElement fieldElement = null;
1490 SimpleIdentifier fieldName2 = node.fieldName;
1491 ClassElement enclosingClass2 = _resolver.enclosingClass;
1492 fieldElement = ((enclosingClass2 as ClassElementImpl)).getField(fieldName2.n ame);
1493 if (fieldElement != null && !fieldElement.isSynthetic()) {
1494 recordResolution(fieldName2, fieldElement);
1495 }
1496 return null;
1497 }
957 Object visitConstructorName(ConstructorName node) { 1498 Object visitConstructorName(ConstructorName node) {
958 Type2 type13 = node.type.type; 1499 Type2 type14 = node.type.type;
959 if (type13 is DynamicTypeImpl) { 1500 if (type14 is DynamicTypeImpl) {
960 return null; 1501 return null;
961 } else if (type13 is! InterfaceType) { 1502 } else if (type14 is! InterfaceType) {
962 ASTNode parent14 = node.parent; 1503 ASTNode parent14 = node.parent;
963 if (parent14 is InstanceCreationExpression) { 1504 if (parent14 is InstanceCreationExpression) {
964 if (((parent14 as InstanceCreationExpression)).isConst()) { 1505 if (((parent14 as InstanceCreationExpression)).isConst()) {
965 } else { 1506 } else {
966 } 1507 }
967 } else { 1508 } else {
968 } 1509 }
969 return null; 1510 return null;
970 } 1511 }
971 ClassElement classElement = ((type13 as InterfaceType)).element; 1512 ClassElement classElement = ((type14 as InterfaceType)).element;
972 ConstructorElement constructor; 1513 ConstructorElement constructor;
973 SimpleIdentifier name15 = node.name; 1514 SimpleIdentifier name17 = node.name;
974 if (name15 == null) { 1515 if (name17 == null) {
975 constructor = classElement.unnamedConstructor; 1516 constructor = classElement.unnamedConstructor;
976 } else { 1517 } else {
977 constructor = classElement.getNamedConstructor(name15.name); 1518 constructor = classElement.getNamedConstructor(name17.name);
978 name15.element = constructor; 1519 name17.element = constructor;
979 } 1520 }
980 node.element = constructor; 1521 node.element = constructor;
981 return null; 1522 return null;
982 } 1523 }
983 Object visitContinueStatement(ContinueStatement node) { 1524 Object visitContinueStatement(ContinueStatement node) {
984 SimpleIdentifier labelNode = node.label; 1525 SimpleIdentifier labelNode = node.label;
985 LabelElementImpl labelElement = lookupLabel(node, labelNode); 1526 LabelElementImpl labelElement = lookupLabel(node, labelNode);
986 if (labelElement != null && labelElement.isOnSwitchStatement()) { 1527 if (labelElement != null && labelElement.isOnSwitchStatement()) {
987 _resolver.reportError(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNod e, []); 1528 _resolver.reportError(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNod e, []);
988 } 1529 }
989 return null; 1530 return null;
990 } 1531 }
991 Object visitExportDirective(ExportDirective node) { 1532 Object visitExportDirective(ExportDirective node) {
992 Element element26 = node.element; 1533 Element element28 = node.element;
993 if (element26 is ExportElement) { 1534 if (element28 is ExportElement) {
994 resolveCombinators(((element26 as ExportElement)).exportedLibrary, node.co mbinators); 1535 resolveCombinators(((element28 as ExportElement)).exportedLibrary, node.co mbinators);
995 } 1536 }
996 return null; 1537 return null;
997 } 1538 }
1539 Object visitFieldFormalParameter(FieldFormalParameter node) {
1540 String fieldName = node.identifier.name;
1541 ClassElement classElement = _resolver.enclosingClass;
1542 if (classElement != null) {
1543 FieldElement fieldElement = ((classElement as ClassElementImpl)).getField( fieldName);
1544 if (fieldElement != null) {
1545 if (!fieldElement.isSynthetic()) {
1546 ParameterElement parameterElement = node.element;
1547 if (parameterElement is FieldFormalParameterElementImpl) {
1548 ((parameterElement as FieldFormalParameterElementImpl)).field = fiel dElement;
1549 if (fieldElement.isStatic()) {
1550 _resolver.reportError(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR _STATIC_FIELD, node, [fieldName]);
1551 }
1552 }
1553 }
1554 } else {
1555 _resolver.reportError(CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_E XISTANT_FIELD, node, [fieldName]);
1556 }
1557 }
1558 return super.visitFieldFormalParameter(node);
1559 }
998 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null; 1560 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null;
999 Object visitImportDirective(ImportDirective node) { 1561 Object visitImportDirective(ImportDirective node) {
1000 SimpleIdentifier prefixNode = node.prefix; 1562 SimpleIdentifier prefixNode = node.prefix;
1001 if (prefixNode != null) { 1563 if (prefixNode != null) {
1002 String prefixName = prefixNode.name; 1564 String prefixName = prefixNode.name;
1003 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) { 1565 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) {
1004 if (prefixElement.name == prefixName) { 1566 if (prefixElement.name == prefixName) {
1005 recordResolution(prefixNode, prefixElement); 1567 recordResolution(prefixNode, prefixElement);
1006 break; 1568 break;
1007 } 1569 }
1008 } 1570 }
1009 } 1571 }
1010 Element element27 = node.element; 1572 Element element29 = node.element;
1011 if (element27 is ImportElement) { 1573 if (element29 is ImportElement) {
1012 resolveCombinators(((element27 as ImportElement)).importedLibrary, node.co mbinators); 1574 resolveCombinators(((element29 as ImportElement)).importedLibrary, node.co mbinators);
1013 } 1575 }
1014 return null; 1576 return null;
1015 } 1577 }
1016 Object visitIndexExpression(IndexExpression node) { 1578 Object visitIndexExpression(IndexExpression node) {
1017 Type2 arrayType = getType(node.realTarget); 1579 Type2 arrayType = getType(node.realTarget);
1018 if (arrayType == null || arrayType.isDynamic()) { 1580 if (arrayType == null || arrayType.isDynamic()) {
1019 return null; 1581 return null;
1020 } 1582 }
1021 Element arrayTypeElement = arrayType.element;
1022 String operator; 1583 String operator;
1023 if (node.inSetterContext()) { 1584 if (node.inSetterContext()) {
1024 operator = sc.TokenType.INDEX_EQ.lexeme; 1585 operator = sc.TokenType.INDEX_EQ.lexeme;
1025 } else { 1586 } else {
1026 operator = sc.TokenType.INDEX.lexeme; 1587 operator = sc.TokenType.INDEX.lexeme;
1027 } 1588 }
1028 MethodElement member = lookUpMethod(arrayTypeElement, operator); 1589 MethodElement member = lookUpMethod(arrayType, operator);
1029 if (member == null) { 1590 if (member == null) {
1030 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, node, [operato r]); 1591 _resolver.reportError(StaticWarningCode.UNDEFINED_OPERATOR, node, [operato r, arrayType.name]);
1031 } else { 1592 } else {
1032 node.element = member; 1593 node.element = member;
1033 } 1594 }
1034 return null; 1595 return null;
1035 } 1596 }
1036 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 1597 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
1037 ConstructorElement invokedConstructor = node.constructorName.element; 1598 ConstructorElement invokedConstructor = node.constructorName.element;
1038 node.element = invokedConstructor; 1599 node.element = invokedConstructor;
1039 resolveNamedArguments(node.argumentList, invokedConstructor); 1600 resolveNamedArguments(node.argumentList, invokedConstructor);
1040 return null; 1601 return null;
1041 } 1602 }
1042 Object visitMethodInvocation(MethodInvocation node) { 1603 Object visitMethodInvocation(MethodInvocation node) {
1043 SimpleIdentifier methodName2 = node.methodName; 1604 SimpleIdentifier methodName2 = node.methodName;
1044 Expression target = node.realTarget; 1605 Expression target = node.realTarget;
1045 Element element; 1606 Element element;
1046 if (target == null) { 1607 if (target == null) {
1047 element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrar y); 1608 element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrar y);
1048 if (element == null) { 1609 if (element == null) {
1049 element = lookUpMethod(_resolver.enclosingClass, methodName2.name); 1610 ClassElement enclosingClass3 = _resolver.enclosingClass;
1050 if (element == null) { 1611 if (enclosingClass3 != null) {
1051 PropertyAccessorElement getter = lookUpGetter(_resolver.enclosingClass , methodName2.name); 1612 InterfaceType enclosingType = enclosingClass3.type;
1052 if (getter != null) { 1613 element = lookUpMethod(enclosingType, methodName2.name);
1053 FunctionType getterType = getter.type; 1614 if (element == null) {
1054 if (getterType != null) { 1615 PropertyAccessorElement getter = lookUpGetter(enclosingType, methodN ame2.name);
1055 Type2 returnType5 = getterType.returnType; 1616 if (getter != null) {
1056 if (!isExecutableType(returnType5)) { 1617 FunctionType getterType = getter.type;
1057 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FU NCTION, methodName2, [methodName2.name]); 1618 if (getterType != null) {
1619 Type2 returnType5 = getterType.returnType;
1620 if (!isExecutableType(returnType5)) {
1621 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_ FUNCTION, methodName2, [methodName2.name]);
1622 }
1058 } 1623 }
1624 recordResolution(methodName2, getter);
1625 return null;
1059 } 1626 }
1060 recordResolution(methodName2, getter);
1061 return null;
1062 } 1627 }
1063 } 1628 }
1064 } 1629 }
1065 } else { 1630 } else {
1066 Type2 targetType = getType(target); 1631 Type2 targetType = getType(target);
1067 if (targetType is InterfaceType) { 1632 if (targetType is InterfaceType) {
1068 element = lookUpMethod(targetType.element, methodName2.name); 1633 InterfaceType classType = targetType as InterfaceType;
1634 element = lookUpMethod(classType, methodName2.name);
1069 if (element == null) { 1635 if (element == null) {
1070 ClassElement targetClass = targetType.element as ClassElement; 1636 PropertyAccessorElement accessor = classType.getGetter(methodName2.nam e);
1071 PropertyAccessorElement accessor = lookUpGetterInType(targetClass, met hodName2.name);
1072 if (accessor != null) { 1637 if (accessor != null) {
1073 Type2 returnType6 = accessor.type.returnType.substitute2(((targetTyp e as InterfaceType)).typeArguments, TypeVariableTypeImpl.getTypes(targetClass.ty peVariables)); 1638 Type2 returnType6 = accessor.type.returnType;
1074 if (!isExecutableType(returnType6)) { 1639 if (!isExecutableType(returnType6)) {
1075 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNC TION, methodName2, [methodName2.name]); 1640 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNC TION, methodName2, [methodName2.name]);
1076 return null; 1641 return null;
1077 } 1642 }
1078 element = accessor; 1643 element = accessor;
1079 } 1644 }
1080 } 1645 }
1081 if (element == null && target is SuperExpression) { 1646 if (element == null && target is SuperExpression) {
1082 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me thodName2, [methodName2.name, targetType.element.name]); 1647 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me thodName2, [methodName2.name, targetType.element.name]);
1083 return null; 1648 return null;
1084 } 1649 }
1085 } else if (target is SimpleIdentifier) { 1650 } else if (target is SimpleIdentifier) {
1086 Element targetElement = ((target as SimpleIdentifier)).element; 1651 Element targetElement = ((target as SimpleIdentifier)).element;
1087 if (targetElement is PrefixElement) { 1652 if (targetElement is PrefixElement) {
1088 String name9 = "${((target as SimpleIdentifier)).name}.${methodName2}" ; 1653 String name10 = "${((target as SimpleIdentifier)).name}.${methodName2} ";
1089 Identifier functionName = new Identifier_5(name9); 1654 Identifier functionName = new Identifier_8(name10);
1090 element = _resolver.nameScope.lookup(functionName, _resolver.definingL ibrary); 1655 element = _resolver.nameScope.lookup(functionName, _resolver.definingL ibrary);
1091 } else { 1656 } else {
1092 return null; 1657 return null;
1093 } 1658 }
1094 } else { 1659 } else {
1095 return null; 1660 return null;
1096 } 1661 }
1097 } 1662 }
1098 ExecutableElement invokedMethod = null; 1663 ExecutableElement invokedMethod = null;
1099 if (element is ExecutableElement) { 1664 if (element is PropertyAccessorElement) {
1665 PropertyAccessorElement getter = element as PropertyAccessorElement;
1666 FunctionType getterType = getter.type;
1667 if (getterType != null) {
1668 Type2 returnType7 = getterType.returnType;
1669 if (!isExecutableType(returnType7)) {
1670 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION , methodName2, [methodName2.name]);
1671 }
1672 }
1673 recordResolution(methodName2, element);
1674 return null;
1675 } else if (element is ExecutableElement) {
1100 invokedMethod = element as ExecutableElement; 1676 invokedMethod = element as ExecutableElement;
1101 } else { 1677 } else {
1102 if (element is PropertyInducingElement) { 1678 if (element is PropertyInducingElement) {
1103 PropertyAccessorElement getter3 = ((element as PropertyInducingElement)) .getter; 1679 PropertyAccessorElement getter3 = ((element as PropertyInducingElement)) .getter;
1104 FunctionType getterType = getter3.type; 1680 FunctionType getterType = getter3.type;
1105 if (getterType != null) { 1681 if (getterType != null) {
1106 Type2 returnType7 = getterType.returnType; 1682 Type2 returnType8 = getterType.returnType;
1107 if (!isExecutableType(returnType7)) { 1683 if (!isExecutableType(returnType8)) {
1108 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]); 1684 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]);
1109 } 1685 }
1110 } 1686 }
1111 recordResolution(methodName2, element); 1687 recordResolution(methodName2, element);
1112 return null; 1688 return null;
1113 } else if (element is VariableElement) { 1689 } else if (element is VariableElement) {
1114 Type2 variableType = ((element as VariableElement)).type; 1690 Type2 variableType = _resolver.overrideManager.getType(element);
1691 if (variableType == null) {
1692 variableType = ((element as VariableElement)).type;
1693 }
1115 if (!isExecutableType(variableType)) { 1694 if (!isExecutableType(variableType)) {
1116 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION , methodName2, [methodName2.name]); 1695 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION , methodName2, [methodName2.name]);
1117 } 1696 }
1118 recordResolution(methodName2, element); 1697 recordResolution(methodName2, element);
1119 return null; 1698 return null;
1120 } else { 1699 } else {
1121 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]); 1700 if (target == null) {
1701 ClassElement enclosingClass4 = _resolver.enclosingClass;
1702 if (enclosingClass4 == null) {
1703 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, meth odName2, [methodName2.name]);
1704 } else if (element == null) {
1705 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, method Name2, [methodName2.name, enclosingClass4.name]);
1706 } else {
1707 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]);
1708 }
1709 } else {
1710 Type2 targetType = getType(target);
1711 String targetTypeName = targetType == null ? null : targetType.name;
1712 if (targetTypeName == null) {
1713 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_FUNCTION, meth odName2, [methodName2.name]);
1714 } else {
1715 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_METHOD, method Name2, [methodName2.name, targetTypeName]);
1716 }
1717 }
1122 return null; 1718 return null;
1123 } 1719 }
1124 } 1720 }
1125 recordResolution(methodName2, invokedMethod); 1721 recordResolution(methodName2, invokedMethod);
1126 resolveNamedArguments(node.argumentList, invokedMethod); 1722 resolveNamedArguments(node.argumentList, invokedMethod);
1127 return null; 1723 return null;
1128 } 1724 }
1129 Object visitPostfixExpression(PostfixExpression node) { 1725 Object visitPostfixExpression(PostfixExpression node) {
1130 sc.Token operator9 = node.operator; 1726 sc.Token operator9 = node.operator;
1131 Type2 operandType = getType(node.operand); 1727 Type2 operandType = getType(node.operand);
1132 if (operandType == null || operandType.isDynamic()) { 1728 if (operandType == null || operandType.isDynamic()) {
1133 return null; 1729 return null;
1134 } 1730 }
1135 Element operandTypeElement = operandType.element;
1136 String methodName; 1731 String methodName;
1137 if (identical(operator9.type, sc.TokenType.PLUS_PLUS)) { 1732 if (identical(operator9.type, sc.TokenType.PLUS_PLUS)) {
1138 methodName = sc.TokenType.PLUS.lexeme; 1733 methodName = sc.TokenType.PLUS.lexeme;
1139 } else { 1734 } else {
1140 methodName = sc.TokenType.MINUS.lexeme; 1735 methodName = sc.TokenType.MINUS.lexeme;
1141 } 1736 }
1142 MethodElement member = lookUpMethod(operandTypeElement, methodName); 1737 MethodElement member = lookUpMethod(operandType, methodName);
1143 if (member == null) { 1738 if (member == null) {
1144 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator9, [m ethodName]); 1739 _resolver.reportError3(StaticWarningCode.UNDEFINED_OPERATOR, operator9, [m ethodName, operandType.name]);
1145 } else { 1740 } else {
1146 node.element = member; 1741 node.element = member;
1147 } 1742 }
1148 return null; 1743 return null;
1149 } 1744 }
1150 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 1745 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
1151 SimpleIdentifier prefix6 = node.prefix; 1746 SimpleIdentifier prefix6 = node.prefix;
1152 SimpleIdentifier identifier13 = node.identifier; 1747 SimpleIdentifier identifier14 = node.identifier;
1153 Element prefixElement = prefix6.element; 1748 Element prefixElement = prefix6.element;
1154 if (prefixElement is PrefixElement) { 1749 if (prefixElement is PrefixElement) {
1155 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra ry); 1750 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra ry);
1156 if (element == null) { 1751 if (element == null) {
1157 return null; 1752 return null;
1158 } 1753 }
1159 recordResolution(identifier13, element); 1754 recordResolution(identifier14, element);
1160 return null; 1755 return null;
1161 } 1756 }
1162 if (prefixElement is ClassElement) { 1757 if (prefixElement is ClassElement) {
1163 Element memberElement; 1758 Element memberElement;
1164 if (node.identifier.inSetterContext()) { 1759 if (node.identifier.inSetterContext()) {
1165 memberElement = lookUpSetterInType((prefixElement as ClassElement), iden tifier13.name); 1760 memberElement = ((prefixElement as ClassElementImpl)).getSetter(identifi er14.name);
1166 } else { 1761 } else {
1167 memberElement = lookUpGetterInType((prefixElement as ClassElement), iden tifier13.name); 1762 memberElement = ((prefixElement as ClassElementImpl)).getGetter(identifi er14.name);
1168 } 1763 }
1169 if (memberElement == null) { 1764 if (memberElement == null) {
1170 MethodElement methodElement = lookUpMethod(prefixElement, identifier13.n ame); 1765 MethodElement methodElement = lookUpMethod(((prefixElement as ClassEleme nt)).type, identifier14.name);
1171 if (methodElement != null) { 1766 if (methodElement != null) {
1172 recordResolution(identifier13, methodElement); 1767 recordResolution(identifier14, methodElement);
1173 return null; 1768 return null;
1174 } 1769 }
1175 } 1770 }
1176 if (memberElement == null) { 1771 if (memberElement == null) {
1177 reportGetterOrSetterNotFound(node, identifier13, prefixElement.name); 1772 reportGetterOrSetterNotFound(node, identifier14, prefixElement.name);
1178 } else { 1773 } else {
1179 recordResolution(identifier13, memberElement); 1774 recordResolution(identifier14, memberElement);
1180 } 1775 }
1181 return null; 1776 return null;
1182 } 1777 }
1183 Element variableTypeElement; 1778 Type2 variableType;
1184 if (prefixElement is PropertyAccessorElement) { 1779 if (prefixElement is PropertyAccessorElement) {
1185 PropertyAccessorElement accessor = prefixElement as PropertyAccessorElemen t; 1780 PropertyAccessorElement accessor = prefixElement as PropertyAccessorElemen t;
1186 FunctionType type14 = accessor.type; 1781 FunctionType type15 = accessor.type;
1187 if (type14 == null) { 1782 if (type15 == null) {
1188 return null; 1783 return null;
1189 } 1784 }
1190 Type2 variableType;
1191 if (accessor.isGetter()) { 1785 if (accessor.isGetter()) {
1192 variableType = type14.returnType; 1786 variableType = type15.returnType;
1193 } else { 1787 } else {
1194 variableType = type14.normalParameterTypes[0]; 1788 variableType = type15.normalParameterTypes[0];
1195 } 1789 }
1196 if (variableType == null || variableType.isDynamic()) { 1790 if (variableType == null || variableType.isDynamic()) {
1197 return null; 1791 return null;
1198 } 1792 }
1199 variableTypeElement = variableType.element;
1200 } else if (prefixElement is VariableElement) { 1793 } else if (prefixElement is VariableElement) {
1201 Type2 prefixType = ((prefixElement as VariableElement)).type; 1794 variableType = _resolver.overrideManager.getType(prefixElement);
1202 if (prefixType == null || prefixType.isDynamic()) { 1795 if (variableType == null) {
1796 variableType = ((prefixElement as VariableElement)).type;
1797 }
1798 if (variableType == null || variableType.isDynamic()) {
1203 return null; 1799 return null;
1204 } 1800 }
1205 variableTypeElement = prefixType.element;
1206 } else { 1801 } else {
1207 return null; 1802 return null;
1208 } 1803 }
1209 PropertyAccessorElement memberElement = null; 1804 PropertyAccessorElement memberElement = null;
1210 if (node.identifier.inSetterContext()) { 1805 if (node.identifier.inSetterContext()) {
1211 memberElement = lookUpSetter(variableTypeElement, identifier13.name); 1806 memberElement = lookUpSetter(variableType, identifier14.name);
1212 } 1807 }
1213 if (memberElement == null && node.identifier.inGetterContext()) { 1808 if (memberElement == null && node.identifier.inGetterContext()) {
1214 memberElement = lookUpGetter(variableTypeElement, identifier13.name); 1809 memberElement = lookUpGetter(variableType, identifier14.name);
1215 } 1810 }
1216 if (memberElement == null) { 1811 if (memberElement == null) {
1217 MethodElement methodElement = lookUpMethod(variableTypeElement, identifier 13.name); 1812 MethodElement methodElement = lookUpMethod(variableType, identifier14.name );
1218 if (methodElement != null) { 1813 if (methodElement != null) {
1219 recordResolution(identifier13, methodElement); 1814 recordResolution(identifier14, methodElement);
1220 return null; 1815 return null;
1221 } 1816 }
1222 } 1817 }
1223 if (memberElement == null) { 1818 if (memberElement == null) {
1224 reportGetterOrSetterNotFound(node, identifier13, variableTypeElement.name) ; 1819 reportGetterOrSetterNotFound(node, identifier14, variableType.element.name );
1225 } else { 1820 } else {
1226 recordResolution(identifier13, memberElement); 1821 recordResolution(identifier14, memberElement);
1227 } 1822 }
1228 return null; 1823 return null;
1229 } 1824 }
1230 Object visitPrefixExpression(PrefixExpression node) { 1825 Object visitPrefixExpression(PrefixExpression node) {
1231 sc.Token operator10 = node.operator; 1826 sc.Token operator10 = node.operator;
1232 sc.TokenType operatorType = operator10.type; 1827 sc.TokenType operatorType = operator10.type;
1233 if (operatorType.isUserDefinableOperator() || identical(operatorType, sc.Tok enType.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) { 1828 if (operatorType.isUserDefinableOperator() || identical(operatorType, sc.Tok enType.PLUS_PLUS) || identical(operatorType, sc.TokenType.MINUS_MINUS)) {
1234 Type2 operandType = getType(node.operand); 1829 Type2 operandType = getType(node.operand);
1235 if (operandType == null || operandType.isDynamic()) { 1830 if (operandType == null || operandType.isDynamic()) {
1236 return null; 1831 return null;
1237 } 1832 }
1238 Element operandTypeElement = operandType.element;
1239 String methodName; 1833 String methodName;
1240 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) { 1834 if (identical(operatorType, sc.TokenType.PLUS_PLUS)) {
1241 methodName = sc.TokenType.PLUS.lexeme; 1835 methodName = sc.TokenType.PLUS.lexeme;
1242 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) { 1836 } else if (identical(operatorType, sc.TokenType.MINUS_MINUS)) {
1243 methodName = sc.TokenType.MINUS.lexeme; 1837 methodName = sc.TokenType.MINUS.lexeme;
1244 } else if (identical(operatorType, sc.TokenType.MINUS)) { 1838 } else if (identical(operatorType, sc.TokenType.MINUS)) {
1245 methodName = "unary-"; 1839 methodName = "unary-";
1246 } else { 1840 } else {
1247 methodName = operator10.lexeme; 1841 methodName = operator10.lexeme;
1248 } 1842 }
1249 MethodElement member = lookUpMethod(operandTypeElement, methodName); 1843 MethodElement member = lookUpMethod(operandType, methodName);
1250 if (member == null) { 1844 if (member == null) {
1251 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator10, [methodName]); 1845 _resolver.reportError3(StaticWarningCode.UNDEFINED_OPERATOR, operator10, [methodName, operandType.name]);
1252 } else { 1846 } else {
1253 node.element = member; 1847 node.element = member;
1254 } 1848 }
1255 } 1849 }
1256 return null; 1850 return null;
1257 } 1851 }
1258 Object visitPropertyAccess(PropertyAccess node) { 1852 Object visitPropertyAccess(PropertyAccess node) {
1259 Type2 targetType = getType(node.realTarget); 1853 Type2 targetType = getType(node.realTarget);
1260 if (targetType is! InterfaceType) { 1854 if (targetType is! InterfaceType) {
1261 return null; 1855 return null;
1262 } 1856 }
1263 ClassElement targetElement = ((targetType as InterfaceType)).element;
1264 SimpleIdentifier identifier = node.propertyName; 1857 SimpleIdentifier identifier = node.propertyName;
1265 PropertyAccessorElement memberElement = null; 1858 PropertyAccessorElement memberElement = null;
1266 if (identifier.inSetterContext()) { 1859 if (identifier.inSetterContext()) {
1267 memberElement = lookUpSetter(targetElement, identifier.name); 1860 memberElement = lookUpSetter(targetType, identifier.name);
1268 } 1861 }
1269 if (memberElement == null && identifier.inGetterContext()) { 1862 if (memberElement == null && identifier.inGetterContext()) {
1270 memberElement = lookUpGetter(targetElement, identifier.name); 1863 memberElement = lookUpGetter(targetType, identifier.name);
1271 } 1864 }
1272 if (memberElement == null) { 1865 if (memberElement == null) {
1273 MethodElement methodElement = lookUpMethod(targetElement, identifier.name) ; 1866 MethodElement methodElement = lookUpMethod(targetType, identifier.name);
1274 if (methodElement != null) { 1867 if (methodElement != null) {
1275 recordResolution(identifier, methodElement); 1868 recordResolution(identifier, methodElement);
1276 return null; 1869 return null;
1277 } 1870 }
1278 } 1871 }
1279 if (memberElement == null) { 1872 if (memberElement == null) {
1280 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, identifier, [i dentifier.name]); 1873 if (identifier.inSetterContext()) {
1874 _resolver.reportError(StaticWarningCode.UNDEFINED_SETTER, identifier, [i dentifier.name, targetType.name]);
1875 } else if (identifier.inGetterContext()) {
1876 _resolver.reportError(StaticWarningCode.UNDEFINED_GETTER, identifier, [i dentifier.name, targetType.name]);
1877 } else {
1878 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, identifier , [identifier.name]);
1879 }
1281 } else { 1880 } else {
1282 recordResolution(identifier, memberElement); 1881 recordResolution(identifier, memberElement);
1283 } 1882 }
1284 return null; 1883 return null;
1285 } 1884 }
1286 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 1885 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
1287 ClassElement enclosingClass2 = _resolver.enclosingClass; 1886 ClassElement enclosingClass5 = _resolver.enclosingClass;
1288 if (enclosingClass2 == null) { 1887 if (enclosingClass5 == null) {
1289 return null; 1888 return null;
1290 } 1889 }
1291 SimpleIdentifier name = node.constructorName; 1890 SimpleIdentifier name = node.constructorName;
1292 ConstructorElement element; 1891 ConstructorElement element;
1293 if (name == null) { 1892 if (name == null) {
1294 element = enclosingClass2.unnamedConstructor; 1893 element = enclosingClass5.unnamedConstructor;
1295 } else { 1894 } else {
1296 element = enclosingClass2.getNamedConstructor(name.name); 1895 element = enclosingClass5.getNamedConstructor(name.name);
1297 } 1896 }
1298 if (element == null) { 1897 if (element == null) {
1299 return null; 1898 return null;
1300 } 1899 }
1301 if (name != null) { 1900 if (name != null) {
1302 recordResolution(name, element); 1901 recordResolution(name, element);
1303 } 1902 }
1304 node.element = element; 1903 node.element = element;
1305 resolveNamedArguments(node.argumentList, element); 1904 resolveNamedArguments(node.argumentList, element);
1306 return null; 1905 return null;
1307 } 1906 }
1308 Object visitSimpleIdentifier(SimpleIdentifier node) { 1907 Object visitSimpleIdentifier(SimpleIdentifier node) {
1309 if (node.element != null) { 1908 if (node.element != null) {
1310 return null; 1909 return null;
1311 } 1910 }
1312 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary ); 1911 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary );
1313 if (element is PropertyAccessorElement && node.inSetterContext()) { 1912 if (element is PropertyAccessorElement && node.inSetterContext()) {
1314 PropertyInducingElement variable4 = ((element as PropertyAccessorElement)) .variable; 1913 PropertyInducingElement variable5 = ((element as PropertyAccessorElement)) .variable;
1315 if (variable4 != null) { 1914 if (variable5 != null) {
1316 PropertyAccessorElement setter3 = variable4.setter; 1915 PropertyAccessorElement setter3 = variable5.setter;
1317 if (setter3 != null) { 1916 if (setter3 != null) {
1318 element = setter3; 1917 element = setter3;
1319 } 1918 }
1320 } 1919 }
1321 } 1920 }
1322 if (element == null && node.inSetterContext()) { 1921 ClassElement enclosingClass6 = _resolver.enclosingClass;
1323 element = lookUpSetter(_resolver.enclosingClass, node.name); 1922 if (element == null && enclosingClass6 != null) {
1324 } 1923 InterfaceType enclosingType = enclosingClass6.type;
1325 if (element == null && node.inGetterContext()) { 1924 if (element == null && node.inSetterContext()) {
1326 element = lookUpGetter(_resolver.enclosingClass, node.name); 1925 element = lookUpSetter(enclosingType, node.name);
1926 }
1927 if (element == null && node.inGetterContext()) {
1928 element = lookUpGetter(enclosingType, node.name);
1929 }
1930 if (element == null) {
1931 element = lookUpMethod(enclosingType, node.name);
1932 }
1327 } 1933 }
1328 if (element == null) { 1934 if (element == null) {
1329 element = lookUpMethod(_resolver.enclosingClass, node.name); 1935 _resolver.reportError(StaticWarningCode.UNDEFINED_IDENTIFIER, node, [node. name]);
1330 }
1331 if (element == null) {
1332 } 1936 }
1333 recordResolution(node, element); 1937 recordResolution(node, element);
1334 return null; 1938 return null;
1335 } 1939 }
1336 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 1940 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
1337 ClassElement enclosingClass3 = _resolver.enclosingClass; 1941 ClassElement enclosingClass7 = _resolver.enclosingClass;
1338 if (enclosingClass3 == null) { 1942 if (enclosingClass7 == null) {
1339 return null; 1943 return null;
1340 } 1944 }
1341 ClassElement superclass = getSuperclass(enclosingClass3); 1945 ClassElement superclass = getSuperclass(enclosingClass7);
1342 if (superclass == null) { 1946 if (superclass == null) {
1343 return null; 1947 return null;
1344 } 1948 }
1345 SimpleIdentifier name = node.constructorName; 1949 SimpleIdentifier name = node.constructorName;
1346 ConstructorElement element; 1950 ConstructorElement element;
1347 if (name == null) { 1951 if (name == null) {
1348 element = superclass.unnamedConstructor; 1952 element = superclass.unnamedConstructor;
1349 } else { 1953 } else {
1350 element = superclass.getNamedConstructor(name.name); 1954 element = superclass.getNamedConstructor(name.name);
1351 } 1955 }
(...skipping 17 matching lines...) Expand all
1369 } 1973 }
1370 return null; 1974 return null;
1371 } 1975 }
1372 /** 1976 /**
1373 * Search through the array of parameters for a parameter whose name matches t he given name. 1977 * Search through the array of parameters for a parameter whose name matches t he given name.
1374 * Return the parameter with the given name, or {@code null} if there is no su ch parameter. 1978 * Return the parameter with the given name, or {@code null} if there is no su ch parameter.
1375 * @param parameters the parameters being searched 1979 * @param parameters the parameters being searched
1376 * @param name the name being searched for 1980 * @param name the name being searched for
1377 * @return the parameter with the given name 1981 * @return the parameter with the given name
1378 */ 1982 */
1379 ParameterElement findNamedParameter(List<ParameterElement> parameters, String name26) { 1983 ParameterElement findNamedParameter(List<ParameterElement> parameters, String name31) {
1380 for (ParameterElement parameter in parameters) { 1984 for (ParameterElement parameter in parameters) {
1381 if (identical(parameter.parameterKind, ParameterKind.NAMED)) { 1985 if (identical(parameter.parameterKind, ParameterKind.NAMED)) {
1382 String parameteName = parameter.name; 1986 String parameteName = parameter.name;
1383 if (parameteName != null && parameteName == name26) { 1987 if (parameteName != null && parameteName == name31) {
1384 return parameter; 1988 return parameter;
1385 } 1989 }
1386 } 1990 }
1387 } 1991 }
1388 return null; 1992 return null;
1389 } 1993 }
1390 /** 1994 /**
1391 * Return the element representing the superclass of the given class. 1995 * Return the element representing the superclass of the given class.
1392 * @param targetClass the class whose superclass is to be returned 1996 * @param targetClass the class whose superclass is to be returned
1393 * @return the element representing the superclass of the given class 1997 * @return the element representing the superclass of the given class
(...skipping 15 matching lines...) Expand all
1409 return _resolver.typeProvider.objectType; 2013 return _resolver.typeProvider.objectType;
1410 } 2014 }
1411 return expression.staticType; 2015 return expression.staticType;
1412 } 2016 }
1413 /** 2017 /**
1414 * Return {@code true} if the given type represents an object that could be in voked using the call 2018 * Return {@code true} if the given type represents an object that could be in voked using the call
1415 * operator '()'. 2019 * operator '()'.
1416 * @param type the type being tested 2020 * @param type the type being tested
1417 * @return {@code true} if the given type represents an object that could be i nvoked 2021 * @return {@code true} if the given type represents an object that could be i nvoked
1418 */ 2022 */
1419 bool isExecutableType(Type2 type) => type.isDynamic() || (type is FunctionType ) || type.isDartCoreFunction(); 2023 bool isExecutableType(Type2 type) {
2024 if (type.isDynamic() || (type is FunctionType) || type.isDartCoreFunction()) {
2025 return true;
2026 } else if (type is InterfaceType) {
2027 ClassElement classElement = ((type as InterfaceType)).element;
2028 MethodElement methodElement = classElement.lookUpMethod("call", _resolver. definingLibrary);
2029 return methodElement != null;
2030 }
2031 return false;
2032 }
1420 /** 2033 /**
1421 * Look up the getter with the given name in the given type. Return the elemen t representing the 2034 * Look up the getter with the given name in the given type. Return the elemen t representing the
1422 * getter that was found, or {@code null} if there is no getter with the given name. 2035 * getter that was found, or {@code null} if there is no getter with the given name.
1423 * @param element the element representing the type in which the getter is def ined 2036 * @param type the type in which the getter is defined
1424 * @param getterName the name of the getter being looked up 2037 * @param getterName the name of the getter being looked up
1425 * @return the element representing the getter that was found 2038 * @return the element representing the getter that was found
1426 */ 2039 */
1427 PropertyAccessorElement lookUpGetter(Element element, String getterName) { 2040 PropertyAccessorElement lookUpGetter(Type2 type, String getterName) {
1428 if (identical(element, DynamicTypeImpl.instance)) { 2041 type = resolveTypeVariable(type);
1429 return null; 2042 if (type is InterfaceType) {
1430 } 2043 InterfaceType interfaceType = type as InterfaceType;
1431 element = resolveTypeVariable(element); 2044 PropertyAccessorElement accessor = interfaceType.lookUpGetter(getterName, _resolver.definingLibrary);
1432 if (element is ClassElement) { 2045 if (accessor != null) {
1433 ClassElement classElement = element as ClassElement; 2046 return accessor;
1434 PropertyAccessorElement member = classElement.lookUpGetter(getterName, _re solver.definingLibrary);
1435 if (member != null) {
1436 return member;
1437 } 2047 }
1438 return lookUpGetterInInterfaces((element as ClassElement), getterName, new Set<ClassElement>()); 2048 return lookUpGetterInInterfaces(interfaceType, getterName, new Set<ClassEl ement>());
1439 } 2049 }
1440 return null; 2050 return null;
1441 } 2051 }
1442 /** 2052 /**
1443 * Look up the name of a getter in the interfaces implemented by the given typ e, either directly 2053 * Look up the getter with the given name in the interfaces implemented by the given type, either
1444 * or indirectly. Return the element representing the getter that was found, o r {@code null} if 2054 * directly or indirectly. Return the element representing the getter that was found, or{@code null} if there is no getter with the given name.
1445 * there is no getter with the given name. 2055 * @param targetType the type in which the getter might be defined
1446 * @param element the element representing the type in which the getter is def ined 2056 * @param getterName the name of the getter being looked up
1447 * @param memberName the name of the getter being looked up
1448 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 2057 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
1449 * to prevent infinite recursion and to optimize the search 2058 * to prevent infinite recursion and to optimize the search
1450 * @return the element representing the getter that was found 2059 * @return the element representing the getter that was found
1451 */ 2060 */
1452 PropertyAccessorElement lookUpGetterInInterfaces(ClassElement targetClass, Str ing memberName, Set<ClassElement> visitedInterfaces) { 2061 PropertyAccessorElement lookUpGetterInInterfaces(InterfaceType targetType, Str ing getterName, Set<ClassElement> visitedInterfaces) {
2062 ClassElement targetClass = targetType.element;
1453 if (visitedInterfaces.contains(targetClass)) { 2063 if (visitedInterfaces.contains(targetClass)) {
1454 return null; 2064 return null;
1455 } 2065 }
1456 javaSetAdd(visitedInterfaces, targetClass); 2066 javaSetAdd(visitedInterfaces, targetClass);
1457 PropertyAccessorElement member = lookUpGetterInType(targetClass, memberName) ; 2067 PropertyAccessorElement getter = targetType.getGetter(getterName);
1458 if (member != null) { 2068 if (getter != null) {
1459 return member; 2069 return getter;
1460 } 2070 }
1461 for (InterfaceType interfaceType in targetClass.interfaces) { 2071 for (InterfaceType interfaceType in targetType.interfaces) {
1462 member = lookUpGetterInInterfaces(interfaceType.element, memberName, visit edInterfaces); 2072 getter = lookUpGetterInInterfaces(interfaceType, getterName, visitedInterf aces);
1463 if (member != null) { 2073 if (getter != null) {
1464 return member; 2074 return getter;
1465 } 2075 }
1466 } 2076 }
1467 ClassElement superclass = getSuperclass(targetClass); 2077 InterfaceType superclass3 = targetType.superclass;
1468 if (superclass == null) { 2078 if (superclass3 == null) {
1469 return null; 2079 return null;
1470 } 2080 }
1471 return lookUpGetterInInterfaces(superclass, memberName, visitedInterfaces); 2081 return lookUpGetterInInterfaces(superclass3, getterName, visitedInterfaces);
1472 }
1473 /**
1474 * Look up the name of a getter in the given type. Return the element represen ting the getter that
1475 * was found, or {@code null} if there is no getter with the given name.
1476 * @param element the element representing the type in which the getter is def ined
1477 * @param memberName the name of the getter being looked up
1478 * @return the element representing the getter that was found
1479 */
1480 PropertyAccessorElement lookUpGetterInType(ClassElement element, String member Name) {
1481 for (PropertyAccessorElement accessor in element.accessors) {
1482 if (accessor.isGetter() && accessor.name == memberName) {
1483 return accessor;
1484 }
1485 }
1486 return null;
1487 } 2082 }
1488 /** 2083 /**
1489 * Find the element corresponding to the given label node in the current label scope. 2084 * Find the element corresponding to the given label node in the current label scope.
1490 * @param parentNode the node containing the given label 2085 * @param parentNode the node containing the given label
1491 * @param labelNode the node representing the label being looked up 2086 * @param labelNode the node representing the label being looked up
1492 * @return the element corresponding to the given label node in the current sc ope 2087 * @return the element corresponding to the given label node in the current sc ope
1493 */ 2088 */
1494 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { 2089 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) {
1495 LabelScope labelScope2 = _resolver.labelScope; 2090 LabelScope labelScope2 = _resolver.labelScope;
1496 LabelElementImpl labelElement = null; 2091 LabelElementImpl labelElement = null;
(...skipping 22 matching lines...) Expand all
1519 if (labelContainer != _resolver.enclosingFunction) { 2114 if (labelContainer != _resolver.enclosingFunction) {
1520 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo de, [labelNode.name]); 2115 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo de, [labelNode.name]);
1521 labelElement = null; 2116 labelElement = null;
1522 } 2117 }
1523 } 2118 }
1524 return labelElement; 2119 return labelElement;
1525 } 2120 }
1526 /** 2121 /**
1527 * Look up the method with the given name in the given type. Return the elemen t representing the 2122 * Look up the method with the given name in the given type. Return the elemen t representing the
1528 * method that was found, or {@code null} if there is no method with the given name. 2123 * method that was found, or {@code null} if there is no method with the given name.
1529 * @param element the element representing the type in which the method is def ined 2124 * @param type the type in which the method is defined
1530 * @param methodName the name of the method being looked up 2125 * @param methodName the name of the method being looked up
1531 * @return the element representing the method that was found 2126 * @return the element representing the method that was found
1532 */ 2127 */
1533 MethodElement lookUpMethod(Element element, String methodName) { 2128 MethodElement lookUpMethod(Type2 type, String methodName) {
1534 if (identical(element, DynamicTypeImpl.instance)) { 2129 type = resolveTypeVariable(type);
1535 return null; 2130 if (type is InterfaceType) {
1536 } 2131 InterfaceType interfaceType = type as InterfaceType;
1537 element = resolveTypeVariable(element); 2132 MethodElement method = interfaceType.lookUpMethod(methodName, _resolver.de finingLibrary);
1538 if (element is ClassElement) { 2133 if (method != null) {
1539 ClassElement classElement = element as ClassElement; 2134 return method;
1540 MethodElement member = classElement.lookUpMethod(methodName, _resolver.def iningLibrary);
1541 if (member != null) {
1542 return member;
1543 } 2135 }
1544 return lookUpMethodInInterfaces((element as ClassElement), methodName, new Set<ClassElement>()); 2136 return lookUpMethodInInterfaces(interfaceType, methodName, new Set<ClassEl ement>());
1545 } 2137 }
1546 return null; 2138 return null;
1547 } 2139 }
1548 /** 2140 /**
1549 * Look up the name of a member in the interfaces implemented by the given typ e, either directly 2141 * Look up the method with the given name in the interfaces implemented by the given type, either
1550 * or indirectly. Return the element representing the member that was found, o r {@code null} if 2142 * directly or indirectly. Return the element representing the method that was found, or{@code null} if there is no method with the given name.
1551 * there is no member with the given name. 2143 * @param targetType the type in which the member might be defined
1552 * @param element the element representing the type in which the member is def ined 2144 * @param methodName the name of the method being looked up
1553 * @param memberName the name of the member being looked up
1554 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 2145 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
1555 * to prevent infinite recursion and to optimize the search 2146 * to prevent infinite recursion and to optimize the search
1556 * @return the element representing the member that was found 2147 * @return the element representing the method that was found
1557 */ 2148 */
1558 MethodElement lookUpMethodInInterfaces(ClassElement targetClass, String member Name, Set<ClassElement> visitedInterfaces) { 2149 MethodElement lookUpMethodInInterfaces(InterfaceType targetType, String method Name, Set<ClassElement> visitedInterfaces) {
2150 ClassElement targetClass = targetType.element;
1559 if (visitedInterfaces.contains(targetClass)) { 2151 if (visitedInterfaces.contains(targetClass)) {
1560 return null; 2152 return null;
1561 } 2153 }
1562 javaSetAdd(visitedInterfaces, targetClass); 2154 javaSetAdd(visitedInterfaces, targetClass);
1563 MethodElement member = lookUpMethodInType(targetClass, memberName); 2155 MethodElement method = targetType.getMethod(methodName);
1564 if (member != null) { 2156 if (method != null) {
1565 return member; 2157 return method;
1566 } 2158 }
1567 for (InterfaceType interfaceType in targetClass.interfaces) { 2159 for (InterfaceType interfaceType in targetType.interfaces) {
1568 member = lookUpMethodInInterfaces(interfaceType.element, memberName, visit edInterfaces); 2160 method = lookUpMethodInInterfaces(interfaceType, methodName, visitedInterf aces);
1569 if (member != null) { 2161 if (method != null) {
1570 return member; 2162 return method;
1571 } 2163 }
1572 } 2164 }
1573 ClassElement superclass = getSuperclass(targetClass); 2165 InterfaceType superclass4 = targetType.superclass;
1574 if (superclass == null) { 2166 if (superclass4 == null) {
1575 return null; 2167 return null;
1576 } 2168 }
1577 return lookUpMethodInInterfaces(superclass, memberName, visitedInterfaces); 2169 return lookUpMethodInInterfaces(superclass4, methodName, visitedInterfaces);
1578 } 2170 }
1579 /** 2171 /**
1580 * Look up the name of a method in the given type. Return the element represen ting the method that 2172 * Look up the setter with the given name in the given type. Return the elemen t representing the
1581 * was found, or {@code null} if there is no method with the given name. 2173 * setter that was found, or {@code null} if there is no setter with the given name.
1582 * @param element the element representing the type in which the method is def ined 2174 * @param type the type in which the setter is defined
1583 * @param memberName the name of the method being looked up 2175 * @param setterName the name of the setter being looked up
1584 * @return the element representing the method that was found 2176 * @return the element representing the setter that was found
1585 */ 2177 */
1586 MethodElement lookUpMethodInType(ClassElement element, String memberName) { 2178 PropertyAccessorElement lookUpSetter(Type2 type, String setterName) {
1587 for (MethodElement method in element.methods) { 2179 type = resolveTypeVariable(type);
1588 if (method.name == memberName) { 2180 if (type is InterfaceType) {
1589 return method; 2181 InterfaceType interfaceType = type as InterfaceType;
2182 PropertyAccessorElement accessor = interfaceType.lookUpSetter(setterName, _resolver.definingLibrary);
2183 if (accessor != null) {
2184 return accessor;
1590 } 2185 }
2186 return lookUpSetterInInterfaces(interfaceType, setterName, new Set<ClassEl ement>());
1591 } 2187 }
1592 return null; 2188 return null;
1593 } 2189 }
1594 /** 2190 /**
1595 * Look up the setter with the given name in the given type. Return the elemen t representing the 2191 * Look up the setter with the given name in the interfaces implemented by the given type, either
1596 * setter that was found, or {@code null} if there is no setter with the given name. 2192 * directly or indirectly. Return the element representing the setter that was found, or{@code null} if there is no setter with the given name.
1597 * @param element the element representing the type in which the setter is def ined 2193 * @param targetType the type in which the setter might be defined
1598 * @param setterName the name of the setter being looked up 2194 * @param setterName the name of the setter being looked up
1599 * @return the element representing the setter that was found
1600 */
1601 PropertyAccessorElement lookUpSetter(Element element, String setterName) {
1602 if (identical(element, DynamicTypeImpl.instance)) {
1603 return null;
1604 }
1605 element = resolveTypeVariable(element);
1606 if (element is ClassElement) {
1607 ClassElement classElement = element as ClassElement;
1608 PropertyAccessorElement member = classElement.lookUpSetter(setterName, _re solver.definingLibrary);
1609 if (member != null) {
1610 return member;
1611 }
1612 return lookUpSetterInInterfaces((element as ClassElement), setterName, new Set<ClassElement>());
1613 }
1614 return null;
1615 }
1616 /**
1617 * Look up the name of a setter in the interfaces implemented by the given typ e, either directly
1618 * or indirectly. Return the element representing the setter that was found, o r {@code null} if
1619 * there is no setter with the given name.
1620 * @param element the element representing the type in which the setter is def ined
1621 * @param memberName the name of the setter being looked up
1622 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used 2195 * @param visitedInterfaces a set containing all of the interfaces that have b een examined, used
1623 * to prevent infinite recursion and to optimize the search 2196 * to prevent infinite recursion and to optimize the search
1624 * @return the element representing the setter that was found 2197 * @return the element representing the setter that was found
1625 */ 2198 */
1626 PropertyAccessorElement lookUpSetterInInterfaces(ClassElement targetClass, Str ing memberName, Set<ClassElement> visitedInterfaces) { 2199 PropertyAccessorElement lookUpSetterInInterfaces(InterfaceType targetType, Str ing setterName, Set<ClassElement> visitedInterfaces) {
2200 ClassElement targetClass = targetType.element;
1627 if (visitedInterfaces.contains(targetClass)) { 2201 if (visitedInterfaces.contains(targetClass)) {
1628 return null; 2202 return null;
1629 } 2203 }
1630 javaSetAdd(visitedInterfaces, targetClass); 2204 javaSetAdd(visitedInterfaces, targetClass);
1631 PropertyAccessorElement member = lookUpSetterInType(targetClass, memberName) ; 2205 PropertyAccessorElement setter = targetType.getGetter(setterName);
1632 if (member != null) { 2206 if (setter != null) {
1633 return member; 2207 return setter;
1634 } 2208 }
1635 for (InterfaceType interfaceType in targetClass.interfaces) { 2209 for (InterfaceType interfaceType in targetType.interfaces) {
1636 member = lookUpSetterInInterfaces(interfaceType.element, memberName, visit edInterfaces); 2210 setter = lookUpSetterInInterfaces(interfaceType, setterName, visitedInterf aces);
1637 if (member != null) { 2211 if (setter != null) {
1638 return member; 2212 return setter;
1639 } 2213 }
1640 } 2214 }
1641 ClassElement superclass = getSuperclass(targetClass); 2215 InterfaceType superclass5 = targetType.superclass;
1642 if (superclass == null) { 2216 if (superclass5 == null) {
1643 return null; 2217 return null;
1644 } 2218 }
1645 return lookUpSetterInInterfaces(superclass, memberName, visitedInterfaces); 2219 return lookUpSetterInInterfaces(superclass5, setterName, visitedInterfaces);
1646 }
1647 /**
1648 * Look up the name of a setter in the given type. Return the element represen ting the setter that
1649 * was found, or {@code null} if there is no setter with the given name.
1650 * @param element the element representing the type in which the setter is def ined
1651 * @param memberName the name of the setter being looked up
1652 * @return the element representing the setter that was found
1653 */
1654 PropertyAccessorElement lookUpSetterInType(ClassElement element, String member Name) {
1655 for (PropertyAccessorElement accessor in element.accessors) {
1656 if (accessor.isSetter() && accessor.name == memberName) {
1657 return accessor;
1658 }
1659 }
1660 return null;
1661 } 2220 }
1662 /** 2221 /**
1663 * Return the binary operator that is invoked by the given compound assignment operator. 2222 * Return the binary operator that is invoked by the given compound assignment operator.
1664 * @param operator the assignment operator being mapped 2223 * @param operator the assignment operator being mapped
1665 * @return the binary operator that invoked by the given assignment operator 2224 * @return the binary operator that invoked by the given assignment operator
1666 */ 2225 */
1667 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) { 2226 sc.TokenType operatorFromCompoundAssignment(sc.TokenType operator) {
1668 while (true) { 2227 while (true) {
1669 if (operator == sc.TokenType.AMPERSAND_EQ) { 2228 if (operator == sc.TokenType.AMPERSAND_EQ) {
1670 return sc.TokenType.AMPERSAND; 2229 return sc.TokenType.AMPERSAND;
(...skipping 21 matching lines...) Expand all
1692 break; 2251 break;
1693 } 2252 }
1694 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to it's corresponding operator"); 2253 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to it's corresponding operator");
1695 return operator; 2254 return operator;
1696 } 2255 }
1697 /** 2256 /**
1698 * Record the fact that the given AST node was resolved to the given element. 2257 * Record the fact that the given AST node was resolved to the given element.
1699 * @param node the AST node that was resolved 2258 * @param node the AST node that was resolved
1700 * @param element the element to which the AST node was resolved 2259 * @param element the element to which the AST node was resolved
1701 */ 2260 */
1702 void recordResolution(SimpleIdentifier node, Element element58) { 2261 void recordResolution(SimpleIdentifier node, Element element68) {
1703 if (element58 != null) { 2262 if (element68 != null) {
1704 node.element = element58; 2263 node.element = element68;
1705 } 2264 }
1706 } 2265 }
1707 /** 2266 /**
1708 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and 2267 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and
1709 * <code>UNDEFINED_GETTER</code>. 2268 * <code>UNDEFINED_GETTER</code>.
1710 * @param node the prefixed identifier that gives the context to determine if the error on the 2269 * @param node the prefixed identifier that gives the context to determine if the error on the
1711 * undefined identifier is a getter or a setter 2270 * undefined identifier is a getter or a setter
1712 * @param identifier the identifier in the passed prefix identifier 2271 * @param identifier the identifier in the passed prefix identifier
1713 * @param typeName the name of the type of the left hand side of the passed pr efixed identifier 2272 * @param typeName the name of the type of the left hand side of the passed pr efixed identifier
1714 */ 2273 */
1715 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id entifier30, String typeName) { 2274 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id entifier32, String typeName) {
1716 bool isSetterContext = node.identifier.inSetterContext(); 2275 bool isSetterContext = node.identifier.inSetterContext();
1717 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT ER : StaticTypeWarningCode.UNDEFINED_GETTER; 2276 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT ER : StaticTypeWarningCode.UNDEFINED_GETTER;
1718 _resolver.reportError(errorCode, identifier30, [identifier30.name, typeName] ); 2277 _resolver.reportError(errorCode, identifier32, [identifier32.name, typeName] );
1719 } 2278 }
1720 /** 2279 /**
1721 * Resolve the names in the given combinators in the scope of the given librar y. 2280 * Resolve the names in the given combinators in the scope of the given librar y.
1722 * @param library the library that defines the names 2281 * @param library the library that defines the names
1723 * @param combinators the combinators containing the names to be resolved 2282 * @param combinators the combinators containing the names to be resolved
1724 */ 2283 */
1725 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) { 2284 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) {
1726 if (library == null) { 2285 if (library == null) {
1727 return; 2286 return;
1728 } 2287 }
(...skipping 17 matching lines...) Expand all
1746 * Resolve the names associated with any named arguments to the parameter elem ents named by the 2305 * Resolve the names associated with any named arguments to the parameter elem ents named by the
1747 * argument. 2306 * argument.
1748 * @param argumentList the arguments to be resolved 2307 * @param argumentList the arguments to be resolved
1749 * @param invokedMethod the method or function defining the parameters to whic h the named 2308 * @param invokedMethod the method or function defining the parameters to whic h the named
1750 * arguments are to be resolved 2309 * arguments are to be resolved
1751 */ 2310 */
1752 void resolveNamedArguments(ArgumentList argumentList, ExecutableElement invoke dMethod) { 2311 void resolveNamedArguments(ArgumentList argumentList, ExecutableElement invoke dMethod) {
1753 if (invokedMethod == null) { 2312 if (invokedMethod == null) {
1754 return; 2313 return;
1755 } 2314 }
1756 List<ParameterElement> parameters11 = invokedMethod.parameters; 2315 List<ParameterElement> parameters13 = invokedMethod.parameters;
1757 for (Expression argument in argumentList.arguments) { 2316 for (Expression argument in argumentList.arguments) {
1758 if (argument is NamedExpression) { 2317 if (argument is NamedExpression) {
1759 SimpleIdentifier name16 = ((argument as NamedExpression)).name.label; 2318 SimpleIdentifier name18 = ((argument as NamedExpression)).name.label;
1760 ParameterElement parameter = findNamedParameter(parameters11, name16.nam e); 2319 ParameterElement parameter = findNamedParameter(parameters13, name18.nam e);
1761 if (parameter != null) { 2320 if (parameter != null) {
1762 recordResolution(name16, parameter); 2321 recordResolution(name18, parameter);
1763 } 2322 }
1764 } 2323 }
1765 } 2324 }
1766 } 2325 }
1767 /** 2326 /**
1768 * If the given element is a type variable, resolve it to the class that shoul d be used when 2327 * If the given type is a type variable, resolve it to the type that should be used when looking
1769 * looking up members. Otherwise, return the original element. 2328 * up members. Otherwise, return the original type.
1770 * @param element the element that is to be resolved if it is a type variable 2329 * @param type the type that is to be resolved if it is a type variable
1771 * @return the class that should be used in place of the argument if it is a t ype variable, or the 2330 * @return the type that should be used in place of the argument if it is a ty pe variable, or the
1772 * original argument if it isn't a type variable 2331 * original argument if it isn't a type variable
1773 */ 2332 */
1774 Element resolveTypeVariable(Element element59) { 2333 Type2 resolveTypeVariable(Type2 type) {
1775 if (element59 is TypeVariableElement) { 2334 if (type is TypeVariableType) {
1776 Type2 bound4 = ((element59 as TypeVariableElement)).bound; 2335 Type2 bound4 = ((type as TypeVariableType)).element.bound;
1777 if (bound4 == null) { 2336 if (bound4 == null) {
1778 return _resolver.typeProvider.objectType.element; 2337 return _resolver.typeProvider.objectType;
1779 } 2338 }
1780 return bound4.element; 2339 return bound4;
1781 } 2340 }
1782 return element59; 2341 return type;
1783 } 2342 }
1784 } 2343 }
1785 class Identifier_5 extends Identifier { 2344 class Identifier_8 extends Identifier {
1786 String name9; 2345 String name10;
1787 Identifier_5(this.name9) : super(); 2346 Identifier_8(this.name10) : super();
1788 accept(ASTVisitor visitor) => null; 2347 accept(ASTVisitor visitor) => null;
1789 sc.Token get beginToken => null; 2348 sc.Token get beginToken => null;
1790 Element get element => null; 2349 Element get element => null;
1791 sc.Token get endToken => null; 2350 sc.Token get endToken => null;
1792 String get name => name9; 2351 String get name => name10;
1793 void visitChildren(ASTVisitor<Object> visitor) { 2352 void visitChildren(ASTVisitor<Object> visitor) {
1794 } 2353 }
1795 } 2354 }
1796 /** 2355 /**
1797 * Instances of the class {@code Library} represent the data about a single libr ary during the 2356 * Instances of the class {@code Library} represent the data about a single libr ary during the
1798 * resolution of some (possibly different) library. They are not intended to be used except during 2357 * resolution of some (possibly different) library. They are not intended to be used except during
1799 * the resolution process. 2358 * the resolution process.
1800 * @coverage dart.engine.resolver 2359 * @coverage dart.engine.resolver
1801 */ 2360 */
1802 class Library { 2361 class Library {
1803 /** 2362 /**
1804 * The analysis context in which this library is being analyzed. 2363 * The analysis context in which this library is being analyzed.
1805 */ 2364 */
1806 AnalysisContextImpl _analysisContext; 2365 InternalAnalysisContext _analysisContext;
1807 /** 2366 /**
1808 * The listener to which analysis errors will be reported. 2367 * The listener to which analysis errors will be reported.
1809 */ 2368 */
1810 AnalysisErrorListener _errorListener; 2369 AnalysisErrorListener _errorListener;
1811 /** 2370 /**
1812 * The source specifying the defining compilation unit of this library. 2371 * The source specifying the defining compilation unit of this library.
1813 */ 2372 */
1814 Source _librarySource; 2373 Source _librarySource;
1815 /** 2374 /**
1816 * The library element representing this library. 2375 * The library element representing this library.
(...skipping 19 matching lines...) Expand all
1836 /** 2395 /**
1837 * The library scope used when resolving elements within this library's compil ation units. 2396 * The library scope used when resolving elements within this library's compil ation units.
1838 */ 2397 */
1839 LibraryScope _libraryScope; 2398 LibraryScope _libraryScope;
1840 /** 2399 /**
1841 * Initialize a newly created data holder that can maintain the data associate d with a library. 2400 * Initialize a newly created data holder that can maintain the data associate d with a library.
1842 * @param analysisContext the analysis context in which this library is being analyzed 2401 * @param analysisContext the analysis context in which this library is being analyzed
1843 * @param errorListener the listener to which analysis errors will be reported 2402 * @param errorListener the listener to which analysis errors will be reported
1844 * @param librarySource the source specifying the defining compilation unit of this library 2403 * @param librarySource the source specifying the defining compilation unit of this library
1845 */ 2404 */
1846 Library(AnalysisContextImpl analysisContext, AnalysisErrorListener errorListen er, Source librarySource) { 2405 Library(InternalAnalysisContext analysisContext, AnalysisErrorListener errorLi stener, Source librarySource) {
1847 this._analysisContext = analysisContext; 2406 this._analysisContext = analysisContext;
1848 this._errorListener = errorListener; 2407 this._errorListener = errorListener;
1849 this._librarySource = librarySource; 2408 this._librarySource = librarySource;
1850 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L ibraryElementImpl; 2409 this._libraryElement = analysisContext.getLibraryElement(librarySource) as L ibraryElementImpl;
1851 } 2410 }
1852 /** 2411 /**
1853 * Record that the given library is exported from this library. 2412 * Record that the given library is exported from this library.
1854 * @param importLibrary the library that is exported from this library 2413 * @param importLibrary the library that is exported from this library
1855 */ 2414 */
1856 void addExport(ExportDirective directive, Library exportLibrary) { 2415 void addExport(ExportDirective directive, Library exportLibrary) {
1857 _exportedLibraries[directive] = exportLibrary; 2416 _exportedLibraries[directive] = exportLibrary;
1858 } 2417 }
1859 /** 2418 /**
1860 * Record that the given library is imported into this library. 2419 * Record that the given library is imported into this library.
1861 * @param importLibrary the library that is imported into this library 2420 * @param importLibrary the library that is imported into this library
1862 */ 2421 */
1863 void addImport(ImportDirective directive, Library importLibrary) { 2422 void addImport(ImportDirective directive, Library importLibrary) {
1864 _importedLibraries[directive] = importLibrary; 2423 _importedLibraries[directive] = importLibrary;
1865 } 2424 }
1866 /** 2425 /**
1867 * Return the AST structure associated with the given source. 2426 * Return the AST structure associated with the given source.
1868 * @param source the source representing the compilation unit whose AST is to be returned 2427 * @param source the source representing the compilation unit whose AST is to be returned
1869 * @return the AST structure associated with the given source 2428 * @return the AST structure associated with the given source
1870 * @throws AnalysisException if an AST structure could not be created for the compilation unit 2429 * @throws AnalysisException if an AST structure could not be created for the compilation unit
1871 */ 2430 */
1872 CompilationUnit getAST(Source source) { 2431 CompilationUnit getAST(Source source) {
1873 CompilationUnit unit = _astMap[source]; 2432 CompilationUnit unit = _astMap[source];
1874 if (unit == null) { 2433 if (unit == null) {
1875 unit = _analysisContext.parseCompilationUnit(source); 2434 unit = _analysisContext.computeResolvableCompilationUnit(source);
1876 _astMap[source] = unit; 2435 _astMap[source] = unit;
1877 } 2436 }
1878 return unit; 2437 return unit;
1879 } 2438 }
1880 /** 2439 /**
1881 * Return a collection containing the sources for the compilation units in thi s library. 2440 * Return a collection containing the sources for the compilation units in thi s library, including
2441 * the defining compilation unit.
1882 * @return the sources for the compilation units in this library 2442 * @return the sources for the compilation units in this library
1883 */ 2443 */
1884 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); 2444 Set<Source> get compilationUnitSources => _astMap.keys.toSet();
1885 /** 2445 /**
1886 * Return the AST structure associated with the defining compilation unit for this library. 2446 * Return the AST structure associated with the defining compilation unit for this library.
1887 * @return the AST structure associated with the defining compilation unit for this library 2447 * @return the AST structure associated with the defining compilation unit for this library
1888 * @throws AnalysisException if an AST structure could not be created for the defining compilation 2448 * @throws AnalysisException if an AST structure could not be created for the defining compilation
1889 * unit 2449 * unit
1890 */ 2450 */
1891 CompilationUnit get definingCompilationUnit => getAST(librarySource); 2451 CompilationUnit get definingCompilationUnit => getAST(librarySource);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 * Return the result of resolving the given URI against the URI of the library , or {@code null} if 2528 * Return the result of resolving the given URI against the URI of the library , or {@code null} if
1969 * the URI is not valid. If the URI is not valid, report the error. 2529 * the URI is not valid. If the URI is not valid, report the error.
1970 * @param uriLiteral the string literal specifying the URI to be resolved 2530 * @param uriLiteral the string literal specifying the URI to be resolved
1971 * @return the result of resolving the given URI against the URI of the librar y 2531 * @return the result of resolving the given URI against the URI of the librar y
1972 */ 2532 */
1973 Source getSource(StringLiteral uriLiteral) { 2533 Source getSource(StringLiteral uriLiteral) {
1974 if (uriLiteral is StringInterpolation) { 2534 if (uriLiteral is StringInterpolation) {
1975 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, [])); 2535 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, []));
1976 return null; 2536 return null;
1977 } 2537 }
1978 return getSource2(getStringValue(uriLiteral)); 2538 Source source = getSource2(getStringValue(uriLiteral));
2539 if (source == null || !source.exists()) {
2540 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.INVALID_URI, [uriLiteral.toSource ()]));
2541 }
2542 return source;
1979 } 2543 }
1980 /** 2544 /**
1981 * Set whether this library explicitly imports core to match the given value. 2545 * Set whether this library explicitly imports core to match the given value.
1982 * @param explicitlyImportsCore {@code true} if this library explicitly import s core 2546 * @param explicitlyImportsCore {@code true} if this library explicitly import s core
1983 */ 2547 */
1984 void set explicitlyImportsCore(bool explicitlyImportsCore2) { 2548 void set explicitlyImportsCore(bool explicitlyImportsCore2) {
1985 this._explicitlyImportsCore = explicitlyImportsCore2; 2549 this._explicitlyImportsCore = explicitlyImportsCore2;
1986 } 2550 }
1987 /** 2551 /**
1988 * Set the library element representing this library to the given library elem ent. 2552 * Set the library element representing this library to the given library elem ent.
(...skipping 24 matching lines...) Expand all
2013 /** 2577 /**
2014 * Return the result of resolving the given URI against the URI of the library , or {@code null} if 2578 * Return the result of resolving the given URI against the URI of the library , or {@code null} if
2015 * the URI is not valid. 2579 * the URI is not valid.
2016 * @param uri the URI to be resolved 2580 * @param uri the URI to be resolved
2017 * @return the result of resolving the given URI against the URI of the librar y 2581 * @return the result of resolving the given URI against the URI of the librar y
2018 */ 2582 */
2019 Source getSource2(String uri) { 2583 Source getSource2(String uri) {
2020 if (uri == null) { 2584 if (uri == null) {
2021 return null; 2585 return null;
2022 } 2586 }
2023 return _librarySource.resolve(uri); 2587 return _analysisContext.sourceFactory.resolveUri(_librarySource, uri);
2024 } 2588 }
2025 /** 2589 /**
2026 * Return the value of the given string literal, or {@code null} if the string is not a constant 2590 * Return the value of the given string literal, or {@code null} if the string is not a constant
2027 * string without any string interpolation. 2591 * string without any string interpolation.
2028 * @param literal the string literal whose value is to be returned 2592 * @param literal the string literal whose value is to be returned
2029 * @return the value of the given string literal 2593 * @return the value of the given string literal
2030 */ 2594 */
2031 String getStringValue(StringLiteral literal) { 2595 String getStringValue(StringLiteral literal) {
2032 JavaStringBuilder builder = new JavaStringBuilder(); 2596 JavaStringBuilder builder = new JavaStringBuilder();
2033 try { 2597 try {
2034 appendStringValue(builder, literal); 2598 appendStringValue(builder, literal);
2035 } on IllegalArgumentException catch (exception) { 2599 } on IllegalArgumentException catch (exception) {
2036 return null; 2600 return null;
2037 } 2601 }
2038 return builder.toString().trim(); 2602 return builder.toString().trim();
2039 } 2603 }
2040 } 2604 }
2041 /** 2605 /**
2042 * Instances of the class {@code LibraryElementBuilder} build an element model f or a single library. 2606 * Instances of the class {@code LibraryElementBuilder} build an element model f or a single library.
2043 * @coverage dart.engine.resolver 2607 * @coverage dart.engine.resolver
2044 */ 2608 */
2045 class LibraryElementBuilder { 2609 class LibraryElementBuilder {
2046 /** 2610 /**
2047 * The analysis context in which the element model will be built. 2611 * The analysis context in which the element model will be built.
2048 */ 2612 */
2049 AnalysisContextImpl _analysisContext; 2613 InternalAnalysisContext _analysisContext;
2050 /** 2614 /**
2051 * The listener to which errors will be reported. 2615 * The listener to which errors will be reported.
2052 */ 2616 */
2053 AnalysisErrorListener _errorListener; 2617 AnalysisErrorListener _errorListener;
2054 /** 2618 /**
2055 * The name of the core library.
2056 */
2057 static String CORE_LIBRARY_URI = "dart:core";
2058 /**
2059 * The name of the function used as an entry point. 2619 * The name of the function used as an entry point.
2060 */ 2620 */
2061 static String _ENTRY_POINT_NAME = "main"; 2621 static String _ENTRY_POINT_NAME = "main";
2062 /** 2622 /**
2063 * Initialize a newly created library element builder. 2623 * Initialize a newly created library element builder.
2064 * @param resolver the resolver for which the element model is being built 2624 * @param resolver the resolver for which the element model is being built
2065 */ 2625 */
2066 LibraryElementBuilder(LibraryResolver resolver) { 2626 LibraryElementBuilder(LibraryResolver resolver) {
2067 this._analysisContext = resolver.analysisContext; 2627 this._analysisContext = resolver.analysisContext;
2068 this._errorListener = resolver.errorListener; 2628 this._errorListener = resolver.errorListener;
2069 } 2629 }
2070 /** 2630 /**
2071 * Build the library element for the given library. 2631 * Build the library element for the given library.
2072 * @param library the library for which an element model is to be built 2632 * @param library the library for which an element model is to be built
2073 * @return the library element that was built 2633 * @return the library element that was built
2074 * @throws AnalysisException if the analysis could not be performed 2634 * @throws AnalysisException if the analysis could not be performed
2075 */ 2635 */
2076 LibraryElementImpl buildLibrary(Library library) { 2636 LibraryElementImpl buildLibrary(Library library) {
2077 CompilationUnitBuilder builder = new CompilationUnitBuilder(_analysisContext ); 2637 CompilationUnitBuilder builder = new CompilationUnitBuilder();
2078 Source librarySource2 = library.librarySource; 2638 Source librarySource2 = library.librarySource;
2079 CompilationUnit definingCompilationUnit3 = library.definingCompilationUnit; 2639 CompilationUnit definingCompilationUnit3 = library.definingCompilationUnit;
2080 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit2(librarySource2, definingCompilationUnit3); 2640 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit(librarySource2, definingCompilationUnit3);
2081 NodeList<Directive> directives3 = definingCompilationUnit3.directives; 2641 NodeList<Directive> directives3 = definingCompilationUnit3.directives;
2082 LibraryIdentifier libraryNameNode = null; 2642 LibraryIdentifier libraryNameNode = null;
2083 bool hasPartDirective = false; 2643 bool hasPartDirective = false;
2084 FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement); 2644 FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement);
2085 List<Directive> directivesToResolve = new List<Directive>(); 2645 List<Directive> directivesToResolve = new List<Directive>();
2086 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>(); 2646 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>();
2087 for (Directive directive in directives3) { 2647 for (Directive directive in directives3) {
2088 if (directive is LibraryDirective) { 2648 if (directive is LibraryDirective) {
2089 if (libraryNameNode == null) { 2649 if (libraryNameNode == null) {
2090 libraryNameNode = ((directive as LibraryDirective)).name; 2650 libraryNameNode = ((directive as LibraryDirective)).name;
2091 directivesToResolve.add(directive); 2651 directivesToResolve.add(directive);
2092 } 2652 }
2093 } else if (directive is PartDirective) { 2653 } else if (directive is PartDirective) {
2094 hasPartDirective = true; 2654 hasPartDirective = true;
2095 StringLiteral partUri = ((directive as PartDirective)).uri; 2655 StringLiteral partUri = ((directive as PartDirective)).uri;
2096 Source partSource = library.getSource(partUri); 2656 Source partSource = library.getSource(partUri);
2097 if (partSource != null && partSource.exists()) { 2657 if (partSource != null && partSource.exists()) {
2098 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce); 2658 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce, library.getAST(partSource));
2099 String partLibraryName = getPartLibraryName(library, partSource, direc tivesToResolve); 2659 String partLibraryName = getPartLibraryName(library, partSource, direc tivesToResolve);
2100 if (partLibraryName == null) { 2660 if (partLibraryName == null) {
2101 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, ResolverErrorCode.MISSING_PART_OF_DIRECTIVE, [])); 2661 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, [partUri.toSour ce()]));
2102 } else if (libraryNameNode == null) { 2662 } else if (libraryNameNode == null) {
2103 } else if (libraryNameNode.name != partLibraryName) { 2663 } else if (libraryNameNode.name != partLibraryName) {
2104 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryN ameNode.name, partLibraryName])); 2664 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryN ameNode.name, partLibraryName]));
2105 } 2665 }
2106 if (entryPoint == null) { 2666 if (entryPoint == null) {
2107 entryPoint = findEntryPoint(part); 2667 entryPoint = findEntryPoint(part);
2108 } 2668 }
2109 directive.element = part; 2669 directive.element = part;
2110 sourcedCompilationUnits.add(part); 2670 sourcedCompilationUnits.add(part);
2111 } 2671 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 } 2727 }
2168 /** 2728 /**
2169 * Instances of the class {@code LibraryResolver} are used to resolve one or mor e mutually dependent 2729 * Instances of the class {@code LibraryResolver} are used to resolve one or mor e mutually dependent
2170 * libraries within a single context. 2730 * libraries within a single context.
2171 * @coverage dart.engine.resolver 2731 * @coverage dart.engine.resolver
2172 */ 2732 */
2173 class LibraryResolver { 2733 class LibraryResolver {
2174 /** 2734 /**
2175 * The analysis context in which the libraries are being analyzed. 2735 * The analysis context in which the libraries are being analyzed.
2176 */ 2736 */
2177 AnalysisContextImpl _analysisContext; 2737 InternalAnalysisContext _analysisContext;
2178 /** 2738 /**
2179 * The listener to which analysis errors will be reported, this error listener is either 2739 * The listener to which analysis errors will be reported, this error listener is either
2180 * references {@link #recordingErrorListener}, or it unions the passed{@link A nalysisErrorListener} with the {@link #recordingErrorListener}. 2740 * references {@link #recordingErrorListener}, or it unions the passed{@link A nalysisErrorListener} with the {@link #recordingErrorListener}.
2181 */ 2741 */
2182 AnalysisErrorListener _errorListener; 2742 AnalysisErrorListener _errorListener;
2183 /** 2743 /**
2184 * This error listener is used by the resolver to be able to call the listener and get back the 2744 * This error listener is used by the resolver to be able to call the listener and get back the
2185 * set of errors for each {@link Source}. 2745 * set of errors for each {@link Source}.
2186 * @see #recordResults() 2746 * @see #recordResults()
2187 */ 2747 */
(...skipping 15 matching lines...) Expand all
2203 */ 2763 */
2204 Map<Source, Library> _libraryMap = new Map<Source, Library>(); 2764 Map<Source, Library> _libraryMap = new Map<Source, Library>();
2205 /** 2765 /**
2206 * A collection containing the libraries that are being resolved together. 2766 * A collection containing the libraries that are being resolved together.
2207 */ 2767 */
2208 Set<Library> _librariesInCycles; 2768 Set<Library> _librariesInCycles;
2209 /** 2769 /**
2210 * Initialize a newly created library resolver to resolve libraries within the given context. 2770 * Initialize a newly created library resolver to resolve libraries within the given context.
2211 * @param analysisContext the analysis context in which the library is being a nalyzed 2771 * @param analysisContext the analysis context in which the library is being a nalyzed
2212 */ 2772 */
2213 LibraryResolver.con1(AnalysisContextImpl analysisContext) { 2773 LibraryResolver.con1(InternalAnalysisContext analysisContext) {
2214 _jtd_constructor_243_impl(analysisContext); 2774 _jtd_constructor_263_impl(analysisContext);
2215 } 2775 }
2216 _jtd_constructor_243_impl(AnalysisContextImpl analysisContext) { 2776 _jtd_constructor_263_impl(InternalAnalysisContext analysisContext) {
2217 _jtd_constructor_244_impl(analysisContext, null); 2777 _jtd_constructor_264_impl(analysisContext, null);
2218 } 2778 }
2219 /** 2779 /**
2220 * Initialize a newly created library resolver to resolve libraries within the given context. 2780 * Initialize a newly created library resolver to resolve libraries within the given context.
2221 * @param analysisContext the analysis context in which the library is being a nalyzed 2781 * @param analysisContext the analysis context in which the library is being a nalyzed
2222 * @param errorListener the listener to which analysis errors will be reported 2782 * @param errorListener the listener to which analysis errors will be reported
2223 */ 2783 */
2224 LibraryResolver.con2(AnalysisContextImpl analysisContext2, AnalysisErrorListen er additionalAnalysisErrorListener) { 2784 LibraryResolver.con2(InternalAnalysisContext analysisContext2, AnalysisErrorLi stener additionalAnalysisErrorListener) {
2225 _jtd_constructor_244_impl(analysisContext2, additionalAnalysisErrorListener) ; 2785 _jtd_constructor_264_impl(analysisContext2, additionalAnalysisErrorListener) ;
2226 } 2786 }
2227 _jtd_constructor_244_impl(AnalysisContextImpl analysisContext2, AnalysisErrorL istener additionalAnalysisErrorListener) { 2787 _jtd_constructor_264_impl(InternalAnalysisContext analysisContext2, AnalysisEr rorListener additionalAnalysisErrorListener) {
2228 this._analysisContext = analysisContext2; 2788 this._analysisContext = analysisContext2;
2229 this._recordingErrorListener = new RecordingErrorListener(); 2789 this._recordingErrorListener = new RecordingErrorListener();
2230 if (additionalAnalysisErrorListener == null) { 2790 if (additionalAnalysisErrorListener == null) {
2231 this._errorListener = _recordingErrorListener; 2791 this._errorListener = _recordingErrorListener;
2232 } else { 2792 } else {
2233 this._errorListener = new AnalysisErrorListener_6(this, additionalAnalysis ErrorListener); 2793 this._errorListener = new AnalysisErrorListener_9(this, additionalAnalysis ErrorListener);
2234 } 2794 }
2235 _coreLibrarySource = analysisContext2.sourceFactory.forUri(LibraryElementBui lder.CORE_LIBRARY_URI); 2795 _coreLibrarySource = analysisContext2.sourceFactory.forUri(DartSdk.DART_CORE );
2236 } 2796 }
2237 /** 2797 /**
2238 * Return the analysis context in which the libraries are being analyzed. 2798 * Return the analysis context in which the libraries are being analyzed.
2239 * @return the analysis context in which the libraries are being analyzed 2799 * @return the analysis context in which the libraries are being analyzed
2240 */ 2800 */
2241 AnalysisContextImpl get analysisContext => _analysisContext; 2801 InternalAnalysisContext get analysisContext => _analysisContext;
2242 /** 2802 /**
2243 * Return the listener to which analysis errors will be reported. 2803 * Return the listener to which analysis errors will be reported.
2244 * @return the listener to which analysis errors will be reported 2804 * @return the listener to which analysis errors will be reported
2245 */ 2805 */
2246 AnalysisErrorListener get errorListener => _errorListener; 2806 AnalysisErrorListener get errorListener => _errorListener;
2247 /** 2807 /**
2248 * Resolve the library specified by the given source in the given context. 2808 * Resolve the library specified by the given source in the given context.
2249 * <p> 2809 * <p>
2250 * Note that because Dart allows circular imports between libraries, it is pos sible that more than 2810 * Note that because Dart allows circular imports between libraries, it is pos sible that more than
2251 * one library will need to be resolved. In such cases the error listener can receive errors from 2811 * one library will need to be resolved. In such cases the error listener can receive errors from
2252 * multiple libraries. 2812 * multiple libraries.
2253 * @param librarySource the source specifying the defining compilation unit of the library to be 2813 * @param librarySource the source specifying the defining compilation unit of the library to be
2254 * resolved 2814 * resolved
2255 * @param fullAnalysis {@code true} if a full analysis should be performed 2815 * @param fullAnalysis {@code true} if a full analysis should be performed
2256 * @return the element representing the resolved library 2816 * @return the element representing the resolved library
2257 * @throws AnalysisException if the library could not be resolved for some rea son 2817 * @throws AnalysisException if the library could not be resolved for some rea son
2258 */ 2818 */
2259 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) { 2819 LibraryElement resolveLibrary(Source librarySource, bool fullAnalysis) {
2260 Library targetLibrary = createLibrary(librarySource); 2820 InstrumentationBuilder instrumentation = Instrumentation.builder2("dart.engi ne.LibraryResolver.resolveLibrary");
2261 _coreLibrary = _libraryMap[_coreLibrarySource]; 2821 try {
2262 if (_coreLibrary == null) { 2822 instrumentation.metric("fullAnalysis", fullAnalysis);
2263 _coreLibrary = createLibrary(_coreLibrarySource); 2823 instrumentation.data3("fullName", librarySource.fullName);
2824 Library targetLibrary = createLibrary(librarySource);
2825 _coreLibrary = _libraryMap[_coreLibrarySource];
2826 if (_coreLibrary == null) {
2827 _coreLibrary = createLibrary(_coreLibrarySource);
2828 }
2829 instrumentation.metric3("createLibrary", "complete");
2830 computeLibraryDependencies(targetLibrary);
2831 _librariesInCycles = computeLibrariesInCycles(targetLibrary);
2832 buildElementModels();
2833 instrumentation.metric3("buildElementModels", "complete");
2834 LibraryElement coreElement = _coreLibrary.libraryElement;
2835 if (coreElement == null) {
2836 throw new AnalysisException.con1("Could not resolve dart:core");
2837 }
2838 buildDirectiveModels();
2839 instrumentation.metric3("buildDirectiveModels", "complete");
2840 _typeProvider = new TypeProviderImpl(coreElement);
2841 buildTypeHierarchies();
2842 instrumentation.metric3("buildTypeHierarchies", "complete");
2843 resolveReferencesAndTypes();
2844 instrumentation.metric3("resolveReferencesAndTypes", "complete");
2845 performConstantEvaluation();
2846 instrumentation.metric3("performConstantEvaluation", "complete");
2847 if (fullAnalysis) {
2848 runAdditionalAnalyses();
2849 instrumentation.metric3("runAdditionalAnalyses", "complete");
2850 }
2851 recordResults();
2852 instrumentation.metric3("recordResults", "complete");
2853 instrumentation.metric2("librariesInCycles", _librariesInCycles.length);
2854 for (Library lib in _librariesInCycles) {
2855 instrumentation.metric2("librariesInCycles-CompilationUnitSources-Size", lib.compilationUnitSources.length);
2856 }
2857 return targetLibrary.libraryElement;
2858 } finally {
2859 instrumentation.log();
2264 } 2860 }
2265 computeLibraryDependencies(targetLibrary);
2266 _librariesInCycles = computeLibrariesInCycles(targetLibrary);
2267 buildElementModels();
2268 buildDirectiveModels();
2269 _typeProvider = new TypeProviderImpl(_coreLibrary.libraryElement);
2270 buildTypeHierarchies();
2271 resolveReferencesAndTypes();
2272 if (fullAnalysis) {
2273 runAdditionalAnalyses();
2274 }
2275 recordResults();
2276 return targetLibrary.libraryElement;
2277 } 2861 }
2278 /** 2862 /**
2279 * Add a dependency to the given map from the referencing library to the refer enced library. 2863 * Add a dependency to the given map from the referencing library to the refer enced library.
2280 * @param dependencyMap the map to which the dependency is to be added 2864 * @param dependencyMap the map to which the dependency is to be added
2281 * @param referencingLibrary the library that references the referenced librar y 2865 * @param referencingLibrary the library that references the referenced librar y
2282 * @param referencedLibrary the library referenced by the referencing library 2866 * @param referencedLibrary the library referenced by the referencing library
2283 */ 2867 */
2284 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref erencingLibrary, Library referencedLibrary) { 2868 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref erencingLibrary, Library referencedLibrary) {
2285 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; 2869 List<Library> dependentLibraries = dependencyMap[referencedLibrary];
2286 if (dependentLibraries == null) { 2870 if (dependentLibraries == null) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 } 3005 }
2422 } 3006 }
2423 /** 3007 /**
2424 * Resolve the type hierarchy across all of the types declared in the librarie s in the current 3008 * Resolve the type hierarchy across all of the types declared in the librarie s in the current
2425 * cycle. 3009 * cycle.
2426 * @throws AnalysisException if any of the type hierarchies could not be resol ved 3010 * @throws AnalysisException if any of the type hierarchies could not be resol ved
2427 */ 3011 */
2428 void buildTypeHierarchies() { 3012 void buildTypeHierarchies() {
2429 for (Library library in _librariesInCycles) { 3013 for (Library library in _librariesInCycles) {
2430 for (Source source in library.compilationUnitSources) { 3014 for (Source source in library.compilationUnitSources) {
2431 TypeResolverVisitor visitor = new TypeResolverVisitor(library, source, _ typeProvider); 3015 TypeResolverVisitor visitor = new TypeResolverVisitor.con1(library, sour ce, _typeProvider);
2432 library.getAST(source).accept(visitor); 3016 library.getAST(source).accept(visitor);
2433 } 3017 }
2434 } 3018 }
2435 } 3019 }
2436 /** 3020 /**
2437 * Compute a dependency map of libraries reachable from the given library. A d ependency map is a 3021 * Compute a dependency map of libraries reachable from the given library. A d ependency map is a
2438 * table that maps individual libraries to a list of the libraries that either import or export 3022 * table that maps individual libraries to a list of the libraries that either import or export
2439 * those libraries. 3023 * those libraries.
2440 * <p> 3024 * <p>
2441 * This map is used to compute all of the libraries involved in a cycle that i nclude the root 3025 * This map is used to compute all of the libraries involved in a cycle that i nclude the root
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 } 3064 }
2481 Library importedLibrary = _libraryMap[importedSource]; 3065 Library importedLibrary = _libraryMap[importedSource];
2482 if (importedLibrary == null) { 3066 if (importedLibrary == null) {
2483 importedLibrary = createLibraryOrNull(importedSource); 3067 importedLibrary = createLibraryOrNull(importedSource);
2484 if (importedLibrary != null) { 3068 if (importedLibrary != null) {
2485 computeLibraryDependencies(importedLibrary); 3069 computeLibraryDependencies(importedLibrary);
2486 } 3070 }
2487 } 3071 }
2488 if (importedLibrary != null) { 3072 if (importedLibrary != null) {
2489 library.addImport(importDirective, importedLibrary); 3073 library.addImport(importDirective, importedLibrary);
3074 if (doesCompilationUnitHavePartOfDirective(importedLibrary.getAST(im portedSource))) {
3075 StringLiteral uriLiteral = importDirective.uri;
3076 _errorListener.onError(new AnalysisError.con2(library.librarySourc e, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.IMPORT_OF_NON_LIBR ARY, [uriLiteral.toSource()]));
3077 }
2490 } 3078 }
2491 } 3079 }
2492 } else if (directive is ExportDirective) { 3080 } else if (directive is ExportDirective) {
2493 ExportDirective exportDirective = directive as ExportDirective; 3081 ExportDirective exportDirective = directive as ExportDirective;
2494 Source exportedSource = library.getSource(exportDirective.uri); 3082 Source exportedSource = library.getSource(exportDirective.uri);
2495 if (exportedSource != null) { 3083 if (exportedSource != null) {
2496 Library exportedLibrary = _libraryMap[exportedSource]; 3084 Library exportedLibrary = _libraryMap[exportedSource];
2497 if (exportedLibrary == null) { 3085 if (exportedLibrary == null) {
2498 exportedLibrary = createLibraryOrNull(exportedSource); 3086 exportedLibrary = createLibraryOrNull(exportedSource);
2499 if (exportedLibrary != null) { 3087 if (exportedLibrary != null) {
2500 computeLibraryDependencies(exportedLibrary); 3088 computeLibraryDependencies(exportedLibrary);
2501 } 3089 }
2502 } 3090 }
2503 if (exportedLibrary != null) { 3091 if (exportedLibrary != null) {
2504 library.addExport(exportDirective, exportedLibrary); 3092 library.addExport(exportDirective, exportedLibrary);
3093 if (doesCompilationUnitHavePartOfDirective(exportedLibrary.getAST(ex portedSource))) {
3094 StringLiteral uriLiteral = exportDirective.uri;
3095 _errorListener.onError(new AnalysisError.con2(library.librarySourc e, uriLiteral.offset, uriLiteral.length, CompileTimeErrorCode.EXPORT_OF_NON_LIBR ARY, [uriLiteral.toSource()]));
3096 }
2505 } 3097 }
2506 } 3098 }
2507 } 3099 }
2508 } 3100 }
2509 library.explicitlyImportsCore = explicitlyImportsCore; 3101 library.explicitlyImportsCore = explicitlyImportsCore;
2510 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) { 3102 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) {
2511 Library importedLibrary = _libraryMap[_coreLibrarySource]; 3103 Library importedLibrary = _libraryMap[_coreLibrarySource];
2512 if (importedLibrary == null) { 3104 if (importedLibrary == null) {
2513 importedLibrary = createLibraryOrNull(_coreLibrarySource); 3105 importedLibrary = createLibraryOrNull(_coreLibrarySource);
2514 if (importedLibrary != null) { 3106 if (importedLibrary != null) {
(...skipping 29 matching lines...) Expand all
2544 Library library = new Library(_analysisContext, _errorListener, librarySourc e); 3136 Library library = new Library(_analysisContext, _errorListener, librarySourc e);
2545 try { 3137 try {
2546 library.definingCompilationUnit; 3138 library.definingCompilationUnit;
2547 } on AnalysisException catch (exception) { 3139 } on AnalysisException catch (exception) {
2548 return null; 3140 return null;
2549 } 3141 }
2550 _libraryMap[librarySource] = library; 3142 _libraryMap[librarySource] = library;
2551 return library; 3143 return library;
2552 } 3144 }
2553 /** 3145 /**
3146 * Return {@code true} if and only if the passed {@link CompilationUnit} has a part-of directive.
3147 * @param node the {@link CompilationUnit} to test
3148 * @return {@code true} if and only if the passed {@link CompilationUnit} has a part-of directive
3149 */
3150 bool doesCompilationUnitHavePartOfDirective(CompilationUnit node) {
3151 NodeList<Directive> directives4 = node.directives;
3152 for (Directive directive in directives4) {
3153 if (directive is PartOfDirective) {
3154 return true;
3155 }
3156 }
3157 return false;
3158 }
3159 /**
2554 * Return an array containing the lexical identifiers associated with the node s in the given list. 3160 * Return an array containing the lexical identifiers associated with the node s in the given list.
2555 * @param names the AST nodes representing the identifiers 3161 * @param names the AST nodes representing the identifiers
2556 * @return the lexical identifiers associated with the nodes in the list 3162 * @return the lexical identifiers associated with the nodes in the list
2557 */ 3163 */
2558 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { 3164 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) {
2559 int count = names.length; 3165 int count = names.length;
2560 List<String> identifiers = new List<String>(count); 3166 List<String> identifiers = new List<String>(count);
2561 for (int i = 0; i < count; i++) { 3167 for (int i = 0; i < count; i++) {
2562 identifiers[i] = names[i].name; 3168 identifiers[i] = names[i].name;
2563 } 3169 }
2564 return identifiers; 3170 return identifiers;
2565 } 3171 }
2566 /** 3172 /**
3173 * Compute a value for all of the constants in the libraries being analyzed.
3174 */
3175 void performConstantEvaluation() {
3176 ConstantValueComputer computer = new ConstantValueComputer();
3177 for (Library library in _librariesInCycles) {
3178 for (Source source in library.compilationUnitSources) {
3179 try {
3180 CompilationUnit unit = library.getAST(source);
3181 if (unit != null) {
3182 computer.add(unit);
3183 }
3184 } on AnalysisException catch (exception) {
3185 AnalysisEngine.instance.logger.logError2("Internal Error: Could not ac cess AST for ${source.fullName} during constant evaluation", exception);
3186 }
3187 }
3188 }
3189 computer.computeValues();
3190 }
3191 /**
2567 * Record the results of resolution with the analysis context. This includes r ecording 3192 * Record the results of resolution with the analysis context. This includes r ecording
2568 * <ul> 3193 * <ul>
2569 * <li>the resolved AST associated with each compilation unit,</li> 3194 * <li>the resolved AST associated with each compilation unit,</li>
2570 * <li>the set of resolution errors produced for each compilation unit, and</l i> 3195 * <li>the set of resolution errors produced for each compilation unit, and</l i>
2571 * <li>the element models produced for each library.</li> 3196 * <li>the element models produced for each library.</li>
2572 * </ul> 3197 * </ul>
2573 */ 3198 */
2574 void recordResults() { 3199 void recordResults() {
2575 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>(); 3200 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>();
2576 for (Library library in _librariesInCycles) { 3201 for (Library library in _librariesInCycles) {
(...skipping 22 matching lines...) Expand all
2599 } 3224 }
2600 } 3225 }
2601 /** 3226 /**
2602 * Resolve the identifiers and perform type analysis in the given library. 3227 * Resolve the identifiers and perform type analysis in the given library.
2603 * @param library the library to be resolved 3228 * @param library the library to be resolved
2604 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 3229 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
2605 * the library cannot be analyzed 3230 * the library cannot be analyzed
2606 */ 3231 */
2607 void resolveReferencesAndTypes2(Library library) { 3232 void resolveReferencesAndTypes2(Library library) {
2608 for (Source source in library.compilationUnitSources) { 3233 for (Source source in library.compilationUnitSources) {
2609 ResolverVisitor visitor = new ResolverVisitor(library, source, _typeProvid er); 3234 ResolverVisitor visitor = new ResolverVisitor.con1(library, source, _typeP rovider);
2610 library.getAST(source).accept(visitor); 3235 library.getAST(source).accept(visitor);
2611 } 3236 }
2612 } 3237 }
2613 /** 3238 /**
2614 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er rorVerifier}analysis in the current cycle. 3239 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er rorVerifier}analysis in the current cycle.
2615 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 3240 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
2616 * the library cannot be analyzed 3241 * the library cannot be analyzed
2617 */ 3242 */
2618 void runAdditionalAnalyses() { 3243 void runAdditionalAnalyses() {
2619 for (Library library in _librariesInCycles) { 3244 for (Library library in _librariesInCycles) {
(...skipping 10 matching lines...) Expand all
2630 for (Source source in library.compilationUnitSources) { 3255 for (Source source in library.compilationUnitSources) {
2631 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 3256 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
2632 CompilationUnit unit = library.getAST(source); 3257 CompilationUnit unit = library.getAST(source);
2633 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib raryElement, _typeProvider); 3258 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, library.lib raryElement, _typeProvider);
2634 unit.accept(errorVerifier); 3259 unit.accept(errorVerifier);
2635 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter); 3260 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter);
2636 unit.accept(constantVerifier); 3261 unit.accept(constantVerifier);
2637 } 3262 }
2638 } 3263 }
2639 } 3264 }
2640 class AnalysisErrorListener_6 implements AnalysisErrorListener { 3265 class AnalysisErrorListener_9 implements AnalysisErrorListener {
2641 final LibraryResolver LibraryResolver_this; 3266 final LibraryResolver LibraryResolver_this;
2642 AnalysisErrorListener additionalAnalysisErrorListener; 3267 AnalysisErrorListener additionalAnalysisErrorListener;
2643 AnalysisErrorListener_6(this.LibraryResolver_this, this.additionalAnalysisErro rListener); 3268 AnalysisErrorListener_9(this.LibraryResolver_this, this.additionalAnalysisErro rListener);
2644 void onError(AnalysisError error) { 3269 void onError(AnalysisError error) {
2645 additionalAnalysisErrorListener.onError(error); 3270 additionalAnalysisErrorListener.onError(error);
2646 LibraryResolver_this._recordingErrorListener.onError(error); 3271 LibraryResolver_this._recordingErrorListener.onError(error);
2647 } 3272 }
2648 } 3273 }
2649 /** 3274 /**
2650 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes within a single 3275 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes within a single
2651 * compilation unit. 3276 * compilation unit.
2652 * @coverage dart.engine.resolver 3277 * @coverage dart.engine.resolver
2653 */ 3278 */
(...skipping 10 matching lines...) Expand all
2664 * The class element representing the class containing the current node, or {@ code null} if the 3289 * The class element representing the class containing the current node, or {@ code null} if the
2665 * current node is not contained in a class. 3290 * current node is not contained in a class.
2666 */ 3291 */
2667 ClassElement _enclosingClass = null; 3292 ClassElement _enclosingClass = null;
2668 /** 3293 /**
2669 * The element representing the function containing the current node, or {@cod e null} if the 3294 * The element representing the function containing the current node, or {@cod e null} if the
2670 * current node is not contained in a function. 3295 * current node is not contained in a function.
2671 */ 3296 */
2672 ExecutableElement _enclosingFunction = null; 3297 ExecutableElement _enclosingFunction = null;
2673 /** 3298 /**
3299 * The object keeping track of which elements have had their types overridden.
3300 */
3301 TypeOverrideManager _overrideManager = new TypeOverrideManager();
3302 /**
2674 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 3303 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
2675 * @param library the library containing the compilation unit being resolved 3304 * @param library the library containing the compilation unit being resolved
2676 * @param source the source representing the compilation unit being visited 3305 * @param source the source representing the compilation unit being visited
2677 * @param typeProvider the object used to access the types from the core libra ry 3306 * @param typeProvider the object used to access the types from the core libra ry
2678 */ 3307 */
2679 ResolverVisitor(Library library, Source source, TypeProvider typeProvider) : s uper(library, source, typeProvider) { 3308 ResolverVisitor.con1(Library library, Source source, TypeProvider typeProvider ) : super.con1(library, source, typeProvider) {
3309 _jtd_constructor_265_impl(library, source, typeProvider);
3310 }
3311 _jtd_constructor_265_impl(Library library, Source source, TypeProvider typePro vider) {
2680 this._elementResolver = new ElementResolver(this); 3312 this._elementResolver = new ElementResolver(this);
2681 this._typeAnalyzer = new StaticTypeAnalyzer(this); 3313 this._typeAnalyzer = new StaticTypeAnalyzer(this);
2682 } 3314 }
3315 /**
3316 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3317 * @param definingLibrary the element for the library containing the compilati on unit being
3318 * visited
3319 * @param source the source representing the compilation unit being visited
3320 * @param typeProvider the object used to access the types from the core libra ry
3321 * @param errorListener the error listener that will be informed of any errors that are found
3322 * during resolution
3323 */
3324 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypeProvid er typeProvider, AnalysisErrorListener errorListener) : super.con2(definingLibra ry, source, typeProvider, errorListener) {
3325 _jtd_constructor_266_impl(definingLibrary, source, typeProvider, errorListen er);
3326 }
3327 _jtd_constructor_266_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) {
3328 this._elementResolver = new ElementResolver(this);
3329 this._typeAnalyzer = new StaticTypeAnalyzer(this);
3330 }
3331 /**
3332 * Return the object keeping track of which elements have had their types over ridden.
3333 * @return the object keeping track of which elements have had their types ove rridden
3334 */
3335 TypeOverrideManager get overrideManager => _overrideManager;
3336 Object visitAsExpression(AsExpression node) {
3337 super.visitAsExpression(node);
3338 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3339 VariableElement element = getOverridableElement(node.expression);
3340 if (element != null) {
3341 Type2 type16 = node.type.type;
3342 if (type16 != null) {
3343 _overrideManager.setType(element, type16);
3344 }
3345 }
3346 }
3347 return null;
3348 }
3349 Object visitAssertStatement(AssertStatement node) {
3350 Expression condition3 = node.condition;
3351 condition3.accept(this);
3352 propagateTrueState(condition3);
3353 return null;
3354 }
3355 Object visitBreakStatement(BreakStatement node) {
3356 node.accept(_elementResolver);
3357 node.accept(_typeAnalyzer);
3358 return null;
3359 }
2683 Object visitClassDeclaration(ClassDeclaration node) { 3360 Object visitClassDeclaration(ClassDeclaration node) {
2684 ClassElement outerType = _enclosingClass; 3361 ClassElement outerType = _enclosingClass;
2685 try { 3362 try {
2686 _enclosingClass = node.element; 3363 _enclosingClass = node.element;
2687 _typeAnalyzer.thisType = _enclosingClass == null ? null : _enclosingClass. type; 3364 _typeAnalyzer.thisType = _enclosingClass == null ? null : _enclosingClass. type;
2688 super.visitClassDeclaration(node); 3365 super.visitClassDeclaration(node);
2689 } finally { 3366 } finally {
2690 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; 3367 _typeAnalyzer.thisType = outerType == null ? null : outerType.type;
2691 _enclosingClass = outerType; 3368 _enclosingClass = outerType;
2692 } 3369 }
2693 return null; 3370 return null;
2694 } 3371 }
3372 Object visitComment(Comment node) => null;
3373 Object visitCompilationUnit(CompilationUnit node) {
3374 try {
3375 _overrideManager.enterScope();
3376 for (Directive directive in node.directives) {
3377 directive.accept(this);
3378 }
3379 List<CompilationUnitMember> classes = new List<CompilationUnitMember>();
3380 for (CompilationUnitMember declaration in node.declarations) {
3381 if (declaration is ClassDeclaration) {
3382 classes.add(declaration);
3383 } else {
3384 declaration.accept(this);
3385 }
3386 }
3387 for (CompilationUnitMember declaration in classes) {
3388 declaration.accept(this);
3389 }
3390 } finally {
3391 _overrideManager.exitScope();
3392 }
3393 return null;
3394 }
3395 Object visitConditionalExpression(ConditionalExpression node) {
3396 Expression condition4 = node.condition;
3397 condition4.accept(this);
3398 Expression thenExpression2 = node.thenExpression;
3399 if (thenExpression2 != null) {
3400 try {
3401 _overrideManager.enterScope();
3402 propagateTrueState(condition4);
3403 thenExpression2.accept(this);
3404 } finally {
3405 _overrideManager.exitScope();
3406 }
3407 }
3408 Expression elseExpression2 = node.elseExpression;
3409 if (elseExpression2 != null) {
3410 try {
3411 _overrideManager.enterScope();
3412 propagateFalseState(condition4);
3413 elseExpression2.accept(this);
3414 } finally {
3415 _overrideManager.exitScope();
3416 }
3417 }
3418 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3419 bool thenIsAbrupt = thenExpression2 != null && isAbruptTermination(thenExp ression2);
3420 bool elseIsAbrupt = elseExpression2 != null && isAbruptTermination(elseExp ression2);
3421 if (elseIsAbrupt && !thenIsAbrupt) {
3422 propagateTrueState(condition4);
3423 } else if (thenIsAbrupt && !elseIsAbrupt) {
3424 propagateFalseState(condition4);
3425 }
3426 }
3427 return null;
3428 }
3429 Object visitConstructorDeclaration(ConstructorDeclaration node) {
3430 ExecutableElement outerFunction = _enclosingFunction;
3431 try {
3432 _enclosingFunction = node.element;
3433 super.visitConstructorDeclaration(node);
3434 } finally {
3435 _enclosingFunction = outerFunction;
3436 }
3437 return null;
3438 }
3439 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
3440 safelyVisit(node.expression);
3441 node.accept(_elementResolver);
3442 node.accept(_typeAnalyzer);
3443 return null;
3444 }
3445 Object visitConstructorName(ConstructorName node) {
3446 node.accept(_elementResolver);
3447 node.accept(_typeAnalyzer);
3448 return null;
3449 }
3450 Object visitContinueStatement(ContinueStatement node) {
3451 node.accept(_elementResolver);
3452 node.accept(_typeAnalyzer);
3453 return null;
3454 }
3455 Object visitFieldDeclaration(FieldDeclaration node) {
3456 try {
3457 _overrideManager.enterScope();
3458 super.visitFieldDeclaration(node);
3459 } finally {
3460 Map<Element, Type2> overrides = captureOverrides(node.fields);
3461 _overrideManager.exitScope();
3462 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) {
3463 _overrideManager.setType(entry.getKey(), entry.getValue());
3464 }
3465 }
3466 return null;
3467 }
3468 Object visitForStatement(ForStatement node) {
3469 try {
3470 _overrideManager.enterScope();
3471 super.visitForStatement(node);
3472 } finally {
3473 _overrideManager.exitScope();
3474 }
3475 return null;
3476 }
3477 Object visitFunctionBody(FunctionBody node) {
3478 try {
3479 _overrideManager.enterScope();
3480 super.visitFunctionBody(node);
3481 } finally {
3482 _overrideManager.exitScope();
3483 }
3484 return null;
3485 }
2695 Object visitFunctionDeclaration(FunctionDeclaration node) { 3486 Object visitFunctionDeclaration(FunctionDeclaration node) {
2696 ExecutableElement outerFunction = _enclosingFunction; 3487 ExecutableElement outerFunction = _enclosingFunction;
2697 try { 3488 try {
2698 SimpleIdentifier functionName = node.name; 3489 SimpleIdentifier functionName = node.name;
2699 _enclosingFunction = functionName.element as ExecutableElement; 3490 _enclosingFunction = functionName.element as ExecutableElement;
2700 super.visitFunctionDeclaration(node); 3491 super.visitFunctionDeclaration(node);
2701 } finally { 3492 } finally {
2702 _enclosingFunction = outerFunction; 3493 _enclosingFunction = outerFunction;
2703 } 3494 }
2704 return null; 3495 return null;
2705 } 3496 }
2706 Object visitFunctionExpression(FunctionExpression node) { 3497 Object visitFunctionExpression(FunctionExpression node) {
2707 ExecutableElement outerFunction = _enclosingFunction; 3498 ExecutableElement outerFunction = _enclosingFunction;
2708 try { 3499 try {
2709 _enclosingFunction = node.element; 3500 _enclosingFunction = node.element;
3501 _overrideManager.enterScope();
2710 super.visitFunctionExpression(node); 3502 super.visitFunctionExpression(node);
2711 } finally { 3503 } finally {
3504 _overrideManager.exitScope();
2712 _enclosingFunction = outerFunction; 3505 _enclosingFunction = outerFunction;
2713 } 3506 }
2714 return null; 3507 return null;
2715 } 3508 }
3509 Object visitHideCombinator(HideCombinator node) => null;
3510 Object visitIfStatement(IfStatement node) {
3511 Expression condition5 = node.condition;
3512 condition5.accept(this);
3513 Statement thenStatement2 = node.thenStatement;
3514 if (thenStatement2 != null) {
3515 try {
3516 _overrideManager.enterScope();
3517 propagateTrueState(condition5);
3518 thenStatement2.accept(this);
3519 } finally {
3520 _overrideManager.exitScope();
3521 }
3522 }
3523 Statement elseStatement2 = node.elseStatement;
3524 if (elseStatement2 != null) {
3525 try {
3526 _overrideManager.enterScope();
3527 propagateFalseState(condition5);
3528 elseStatement2.accept(this);
3529 } finally {
3530 _overrideManager.exitScope();
3531 }
3532 }
3533 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3534 bool thenIsAbrupt = thenStatement2 != null && isAbruptTermination2(thenSta tement2);
3535 bool elseIsAbrupt = elseStatement2 != null && isAbruptTermination2(elseSta tement2);
3536 if (elseIsAbrupt && !thenIsAbrupt) {
3537 propagateTrueState(condition5);
3538 } else if (thenIsAbrupt && !elseIsAbrupt) {
3539 propagateFalseState(condition5);
3540 }
3541 }
3542 return null;
3543 }
2716 Object visitLabel(Label node) => null; 3544 Object visitLabel(Label node) => null;
2717 Object visitLibraryIdentifier(LibraryIdentifier node) => null; 3545 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
2718 Object visitMethodDeclaration(MethodDeclaration node) { 3546 Object visitMethodDeclaration(MethodDeclaration node) {
2719 ExecutableElement outerFunction = _enclosingFunction; 3547 ExecutableElement outerFunction = _enclosingFunction;
2720 try { 3548 try {
2721 _enclosingFunction = node.element; 3549 _enclosingFunction = node.element;
2722 super.visitMethodDeclaration(node); 3550 super.visitMethodDeclaration(node);
2723 } finally { 3551 } finally {
2724 _enclosingFunction = outerFunction; 3552 _enclosingFunction = outerFunction;
2725 } 3553 }
2726 return null; 3554 return null;
2727 } 3555 }
3556 Object visitMethodInvocation(MethodInvocation node) {
3557 safelyVisit(node.target);
3558 safelyVisit(node.argumentList);
3559 node.accept(_elementResolver);
3560 node.accept(_typeAnalyzer);
3561 return null;
3562 }
2728 Object visitNode(ASTNode node) { 3563 Object visitNode(ASTNode node) {
2729 node.visitChildren(this); 3564 node.visitChildren(this);
2730 node.accept(_elementResolver); 3565 node.accept(_elementResolver);
2731 node.accept(_typeAnalyzer); 3566 node.accept(_typeAnalyzer);
2732 return null; 3567 return null;
2733 } 3568 }
2734 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 3569 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
2735 SimpleIdentifier prefix7 = node.prefix; 3570 safelyVisit(node.prefix);
2736 if (prefix7 != null) {
2737 prefix7.accept(this);
2738 }
2739 node.accept(_elementResolver); 3571 node.accept(_elementResolver);
2740 node.accept(_typeAnalyzer); 3572 node.accept(_typeAnalyzer);
2741 return null; 3573 return null;
2742 } 3574 }
2743 Object visitPropertyAccess(PropertyAccess node) { 3575 Object visitPropertyAccess(PropertyAccess node) {
2744 Expression target4 = node.target; 3576 safelyVisit(node.target);
2745 if (target4 != null) {
2746 target4.accept(this);
2747 }
2748 node.accept(_elementResolver); 3577 node.accept(_elementResolver);
2749 node.accept(_typeAnalyzer); 3578 node.accept(_typeAnalyzer);
2750 return null; 3579 return null;
2751 } 3580 }
2752 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 3581 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
2753 ArgumentList argumentList10 = node.argumentList; 3582 safelyVisit(node.argumentList);
2754 if (argumentList10 != null) {
2755 argumentList10.accept(this);
2756 }
2757 node.accept(_elementResolver); 3583 node.accept(_elementResolver);
2758 node.accept(_typeAnalyzer); 3584 node.accept(_typeAnalyzer);
2759 return null; 3585 return null;
2760 } 3586 }
3587 Object visitShowCombinator(ShowCombinator node) => null;
2761 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 3588 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2762 ArgumentList argumentList11 = node.argumentList; 3589 safelyVisit(node.argumentList);
2763 if (argumentList11 != null) {
2764 argumentList11.accept(this);
2765 }
2766 node.accept(_elementResolver); 3590 node.accept(_elementResolver);
2767 node.accept(_typeAnalyzer); 3591 node.accept(_typeAnalyzer);
2768 return null; 3592 return null;
2769 } 3593 }
3594 Object visitSwitchCase(SwitchCase node) {
3595 try {
3596 _overrideManager.enterScope();
3597 super.visitSwitchCase(node);
3598 } finally {
3599 _overrideManager.exitScope();
3600 }
3601 return null;
3602 }
3603 Object visitSwitchDefault(SwitchDefault node) {
3604 try {
3605 _overrideManager.enterScope();
3606 super.visitSwitchDefault(node);
3607 } finally {
3608 _overrideManager.exitScope();
3609 }
3610 return null;
3611 }
3612 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
3613 try {
3614 _overrideManager.enterScope();
3615 super.visitTopLevelVariableDeclaration(node);
3616 } finally {
3617 Map<Element, Type2> overrides = captureOverrides(node.variables);
3618 _overrideManager.exitScope();
3619 for (MapEntry<Element, Type2> entry in getMapEntrySet(overrides)) {
3620 _overrideManager.setType(entry.getKey(), entry.getValue());
3621 }
3622 }
3623 return null;
3624 }
2770 Object visitTypeName(TypeName node) => null; 3625 Object visitTypeName(TypeName node) => null;
2771 /** 3626 /**
2772 * Return the class element representing the class containing the current node , or {@code null} if 3627 * Return the class element representing the class containing the current node , or {@code null} if
2773 * the current node is not contained in a class. 3628 * the current node is not contained in a class.
2774 * @return the class element representing the class containing the current nod e 3629 * @return the class element representing the class containing the current nod e
2775 */ 3630 */
2776 ClassElement get enclosingClass => _enclosingClass; 3631 ClassElement get enclosingClass => _enclosingClass;
2777 /** 3632 /**
2778 * Return the element representing the function containing the current node, o r {@code null} if 3633 * Return the element representing the function containing the current node, o r {@code null} if
2779 * the current node is not contained in a function. 3634 * the current node is not contained in a function.
2780 * @return the element representing the function containing the current node 3635 * @return the element representing the function containing the current node
2781 */ 3636 */
2782 ExecutableElement get enclosingFunction => _enclosingFunction; 3637 ExecutableElement get enclosingFunction => _enclosingFunction;
3638 /**
3639 * Return the element associated with the given expression whose type can be o verridden, or{@code null} if there is no element whose type can be overridden.
3640 * @param expression the expression with which the element is associated
3641 * @return the element associated with the given expression
3642 */
3643 VariableElement getOverridableElement(Expression expression) {
3644 if (expression is SimpleIdentifier) {
3645 Element element30 = ((expression as SimpleIdentifier)).element;
3646 if (element30 is VariableElement) {
3647 return element30 as VariableElement;
3648 }
3649 }
3650 return null;
3651 }
3652 /**
3653 * Return a map from the elements for the variables in the given list that hav e their types
3654 * overridden to the overriding type.
3655 * @param variableList the list of variables whose overriding types are to be captured
3656 * @return a table mapping elements to their overriding types
3657 */
3658 Map<Element, Type2> captureOverrides(VariableDeclarationList variableList) {
3659 Map<Element, Type2> overrides = new Map<Element, Type2>();
3660 if (StaticTypeAnalyzer.USE_TYPE_PROPAGATION) {
3661 if (variableList.isConst() || variableList.isFinal()) {
3662 for (VariableDeclaration variable in variableList.variables) {
3663 Element element31 = variable.element;
3664 if (element31 != null) {
3665 Type2 type = _overrideManager.getType(element31);
3666 if (type != null) {
3667 overrides[element31] = type;
3668 }
3669 }
3670 }
3671 }
3672 }
3673 return overrides;
3674 }
3675 /**
3676 * Return {@code true} if the given expression terminates abruptly (that is, i f any expression
3677 * following the given expression will not be reached).
3678 * @param expression the expression being tested
3679 * @return {@code true} if the given expression terminates abruptly
3680 */
3681 bool isAbruptTermination(Expression expression18) {
3682 while (expression18 is ParenthesizedExpression) {
3683 expression18 = ((expression18 as ParenthesizedExpression)).expression;
3684 }
3685 return expression18 is ThrowExpression || expression18 is RethrowExpression;
3686 }
3687 /**
3688 * Return {@code true} if the given statement terminates abruptly (that is, if any statement
3689 * following the given statement will not be reached).
3690 * @param statement the statement being tested
3691 * @return {@code true} if the given statement terminates abruptly
3692 */
3693 bool isAbruptTermination2(Statement statement) {
3694 if (statement is ReturnStatement) {
3695 return true;
3696 } else if (statement is ExpressionStatement) {
3697 return isAbruptTermination(((statement as ExpressionStatement)).expression );
3698 } else if (statement is Block) {
3699 NodeList<Statement> statements2 = ((statement as Block)).statements;
3700 int size6 = statements2.length;
3701 if (size6 == 0) {
3702 return false;
3703 }
3704 return isAbruptTermination2(statements2[size6 - 1]);
3705 }
3706 return false;
3707 }
3708 /**
3709 * Propagate any type information that results from knowing that the given con dition will have
3710 * evaluated to 'false'.
3711 * @param condition the condition that will have evaluated to 'false'
3712 */
3713 void propagateFalseState(Expression condition) {
3714 while (condition is ParenthesizedExpression) {
3715 condition = ((condition as ParenthesizedExpression)).expression;
3716 }
3717 if (condition is IsExpression) {
3718 IsExpression is2 = condition as IsExpression;
3719 if (is2.notOperator != null) {
3720 Element element = getOverridableElement(is2.expression);
3721 if (element != null) {
3722 Type2 type17 = is2.type.type;
3723 if (type17 != null) {
3724 _overrideManager.setType(element, type17);
3725 }
3726 }
3727 }
3728 } else if (condition is BinaryExpression) {
3729 BinaryExpression binary = condition as BinaryExpression;
3730 if (identical(binary.operator.type, sc.TokenType.BAR_BAR)) {
3731 propagateFalseState(binary.leftOperand);
3732 propagateFalseState(binary.rightOperand);
3733 }
3734 }
3735 }
3736 /**
3737 * Propagate any type information that results from knowing that the given con dition will have
3738 * evaluated to 'true'.
3739 * @param condition the condition that will have evaluated to 'true'
3740 */
3741 void propagateTrueState(Expression condition) {
3742 while (condition is ParenthesizedExpression) {
3743 condition = ((condition as ParenthesizedExpression)).expression;
3744 }
3745 if (condition is IsExpression) {
3746 IsExpression is3 = condition as IsExpression;
3747 if (is3.notOperator == null) {
3748 Element element = getOverridableElement(is3.expression);
3749 if (element != null) {
3750 Type2 type18 = is3.type.type;
3751 if (type18 != null) {
3752 _overrideManager.setType(element, type18);
3753 }
3754 }
3755 }
3756 } else if (condition is BinaryExpression) {
3757 BinaryExpression binary = condition as BinaryExpression;
3758 if (identical(binary.operator.type, sc.TokenType.AMPERSAND_AMPERSAND)) {
3759 propagateTrueState(binary.leftOperand);
3760 propagateTrueState(binary.rightOperand);
3761 }
3762 }
3763 }
3764 /**
3765 * Visit the given AST node if it is not null.
3766 * @param node the node to be visited
3767 */
3768 void safelyVisit(ASTNode node) {
3769 if (node != null) {
3770 node.accept(this);
3771 }
3772 }
2783 get elementResolver_J2DAccessor => _elementResolver; 3773 get elementResolver_J2DAccessor => _elementResolver;
2784 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; 3774 set elementResolver_J2DAccessor(__v) => _elementResolver = __v;
2785 get labelScope_J2DAccessor => _labelScope; 3775 get labelScope_J2DAccessor => _labelScope;
2786 set labelScope_J2DAccessor(__v) => _labelScope = __v; 3776 set labelScope_J2DAccessor(__v) => _labelScope = __v;
2787 get nameScope_J2DAccessor => _nameScope; 3777 get nameScope_J2DAccessor => _nameScope;
2788 set nameScope_J2DAccessor(__v) => _nameScope = __v; 3778 set nameScope_J2DAccessor(__v) => _nameScope = __v;
2789 get typeAnalyzer_J2DAccessor => _typeAnalyzer; 3779 get typeAnalyzer_J2DAccessor => _typeAnalyzer;
2790 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; 3780 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v;
2791 get enclosingClass_J2DAccessor => _enclosingClass; 3781 get enclosingClass_J2DAccessor => _enclosingClass;
2792 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v; 3782 set enclosingClass_J2DAccessor(__v) => _enclosingClass = __v;
(...skipping 27 matching lines...) Expand all
2820 /** 3810 /**
2821 * The scope used to resolve labels for {@code break} and {@code continue} sta tements, or{@code null} if no labels have been defined in the current context. 3811 * The scope used to resolve labels for {@code break} and {@code continue} sta tements, or{@code null} if no labels have been defined in the current context.
2822 */ 3812 */
2823 LabelScope _labelScope; 3813 LabelScope _labelScope;
2824 /** 3814 /**
2825 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 3815 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
2826 * @param library the library containing the compilation unit being resolved 3816 * @param library the library containing the compilation unit being resolved
2827 * @param source the source representing the compilation unit being visited 3817 * @param source the source representing the compilation unit being visited
2828 * @param typeProvider the object used to access the types from the core libra ry 3818 * @param typeProvider the object used to access the types from the core libra ry
2829 */ 3819 */
2830 ScopedVisitor(Library library, Source source, TypeProvider typeProvider) { 3820 ScopedVisitor.con1(Library library, Source source8, TypeProvider typeProvider2 ) {
3821 _jtd_constructor_267_impl(library, source8, typeProvider2);
3822 }
3823 _jtd_constructor_267_impl(Library library, Source source8, TypeProvider typePr ovider2) {
2831 this._definingLibrary = library.libraryElement; 3824 this._definingLibrary = library.libraryElement;
2832 this._source = source; 3825 this._source = source8;
2833 LibraryScope libraryScope2 = library.libraryScope; 3826 LibraryScope libraryScope2 = library.libraryScope;
2834 this._errorListener = libraryScope2.errorListener; 3827 this._errorListener = libraryScope2.errorListener;
2835 this._nameScope = libraryScope2; 3828 this._nameScope = libraryScope2;
2836 this._typeProvider = typeProvider; 3829 this._typeProvider = typeProvider2;
3830 }
3831 /**
3832 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3833 * @param definingLibrary the element for the library containing the compilati on unit being
3834 * visited
3835 * @param source the source representing the compilation unit being visited
3836 * @param typeProvider the object used to access the types from the core libra ry
3837 * @param errorListener the error listener that will be informed of any errors that are found
3838 * during resolution
3839 */
3840 ScopedVisitor.con2(LibraryElement definingLibrary2, Source source9, TypeProvid er typeProvider3, AnalysisErrorListener errorListener2) {
3841 _jtd_constructor_268_impl(definingLibrary2, source9, typeProvider3, errorLis tener2);
3842 }
3843 _jtd_constructor_268_impl(LibraryElement definingLibrary2, Source source9, Typ eProvider typeProvider3, AnalysisErrorListener errorListener2) {
3844 this._definingLibrary = definingLibrary2;
3845 this._source = source9;
3846 this._errorListener = errorListener2;
3847 this._nameScope = new LibraryScope(definingLibrary2, errorListener2);
3848 this._typeProvider = typeProvider3;
2837 } 3849 }
2838 /** 3850 /**
2839 * Return the library element for the library containing the compilation unit being resolved. 3851 * Return the library element for the library containing the compilation unit being resolved.
2840 * @return the library element for the library containing the compilation unit being resolved 3852 * @return the library element for the library containing the compilation unit being resolved
2841 */ 3853 */
2842 LibraryElement get definingLibrary => _definingLibrary; 3854 LibraryElement get definingLibrary => _definingLibrary;
2843 /** 3855 /**
2844 * Return the object used to access the types from the core library. 3856 * Return the object used to access the types from the core library.
2845 * @return the object used to access the types from the core library 3857 * @return the object used to access the types from the core library
2846 */ 3858 */
2847 TypeProvider get typeProvider => _typeProvider; 3859 TypeProvider get typeProvider => _typeProvider;
2848 Object visitBlock(Block node) { 3860 Object visitBlock(Block node) {
2849 Scope outerScope = _nameScope; 3861 Scope outerScope = _nameScope;
2850 _nameScope = new EnclosedScope(_nameScope); 3862 _nameScope = new EnclosedScope(_nameScope);
2851 try { 3863 try {
2852 super.visitBlock(node); 3864 super.visitBlock(node);
2853 } finally { 3865 } finally {
2854 _nameScope = outerScope; 3866 _nameScope = outerScope;
2855 } 3867 }
2856 return null; 3868 return null;
2857 } 3869 }
3870 Object visitCatchClause(CatchClause node) {
3871 SimpleIdentifier exception = node.exceptionParameter;
3872 if (exception != null) {
3873 Scope outerScope = _nameScope;
3874 _nameScope = new EnclosedScope(_nameScope);
3875 try {
3876 _nameScope.define(exception.element);
3877 SimpleIdentifier stackTrace = node.stackTraceParameter;
3878 if (stackTrace != null) {
3879 _nameScope.define(stackTrace.element);
3880 }
3881 super.visitCatchClause(node);
3882 } finally {
3883 _nameScope = outerScope;
3884 }
3885 }
3886 return null;
3887 }
2858 Object visitClassDeclaration(ClassDeclaration node) { 3888 Object visitClassDeclaration(ClassDeclaration node) {
2859 Scope outerScope = _nameScope; 3889 Scope outerScope = _nameScope;
2860 try { 3890 try {
2861 _nameScope = new ClassScope(_nameScope, node.element); 3891 _nameScope = new ClassScope(_nameScope, node.element);
2862 super.visitClassDeclaration(node); 3892 super.visitClassDeclaration(node);
2863 } finally { 3893 } finally {
2864 _nameScope = outerScope; 3894 _nameScope = outerScope;
2865 } 3895 }
2866 return null; 3896 return null;
2867 } 3897 }
(...skipping 10 matching lines...) Expand all
2878 Object visitConstructorDeclaration(ConstructorDeclaration node) { 3908 Object visitConstructorDeclaration(ConstructorDeclaration node) {
2879 Scope outerScope = _nameScope; 3909 Scope outerScope = _nameScope;
2880 try { 3910 try {
2881 _nameScope = new FunctionScope(_nameScope, node.element); 3911 _nameScope = new FunctionScope(_nameScope, node.element);
2882 super.visitConstructorDeclaration(node); 3912 super.visitConstructorDeclaration(node);
2883 } finally { 3913 } finally {
2884 _nameScope = outerScope; 3914 _nameScope = outerScope;
2885 } 3915 }
2886 return null; 3916 return null;
2887 } 3917 }
3918 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
3919 VariableElement element32 = node.element;
3920 if (element32 != null) {
3921 _nameScope.define(element32);
3922 }
3923 super.visitDeclaredIdentifier(node);
3924 return null;
3925 }
2888 Object visitDoStatement(DoStatement node) { 3926 Object visitDoStatement(DoStatement node) {
2889 LabelScope outerScope = _labelScope; 3927 LabelScope outerScope = _labelScope;
2890 _labelScope = new LabelScope.con1(outerScope, false, false); 3928 _labelScope = new LabelScope.con1(outerScope, false, false);
2891 try { 3929 try {
2892 super.visitDoStatement(node); 3930 super.visitDoStatement(node);
2893 } finally { 3931 } finally {
2894 _labelScope = outerScope; 3932 _labelScope = outerScope;
2895 } 3933 }
2896 return null; 3934 return null;
2897 } 3935 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3015 } 4053 }
3016 try { 4054 try {
3017 super.visitSwitchStatement(node); 4055 super.visitSwitchStatement(node);
3018 } finally { 4056 } finally {
3019 _labelScope = outerScope; 4057 _labelScope = outerScope;
3020 } 4058 }
3021 return null; 4059 return null;
3022 } 4060 }
3023 Object visitVariableDeclaration(VariableDeclaration node) { 4061 Object visitVariableDeclaration(VariableDeclaration node) {
3024 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent is! FieldDeclaration) { 4062 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent is! FieldDeclaration) {
3025 VariableElement element28 = node.element; 4063 VariableElement element33 = node.element;
3026 if (element28 != null) { 4064 if (element33 != null) {
3027 _nameScope.define(element28); 4065 _nameScope.define(element33);
3028 } 4066 }
3029 } 4067 }
3030 super.visitVariableDeclaration(node); 4068 super.visitVariableDeclaration(node);
3031 return null; 4069 return null;
3032 } 4070 }
3033 Object visitWhileStatement(WhileStatement node) { 4071 Object visitWhileStatement(WhileStatement node) {
3034 LabelScope outerScope = _labelScope; 4072 LabelScope outerScope = _labelScope;
3035 _labelScope = new LabelScope.con1(outerScope, false, false); 4073 _labelScope = new LabelScope.con1(outerScope, false, false);
3036 try { 4074 try {
3037 super.visitWhileStatement(node); 4075 super.visitWhileStatement(node);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3089 * compute the static type of every expression. Second, they look for any static type errors or 4127 * compute the static type of every expression. Second, they look for any static type errors or
3090 * warnings that might need to be generated. The requirements for the type analy zer are: 4128 * warnings that might need to be generated. The requirements for the type analy zer are:
3091 * <ol> 4129 * <ol>
3092 * <li>Every element that refers to types should be fully populated. 4130 * <li>Every element that refers to types should be fully populated.
3093 * <li>Every node representing an expression should be resolved to the Type of t he expression.</li> 4131 * <li>Every node representing an expression should be resolved to the Type of t he expression.</li>
3094 * </ol> 4132 * </ol>
3095 * @coverage dart.engine.resolver 4133 * @coverage dart.engine.resolver
3096 */ 4134 */
3097 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { 4135 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> {
3098 /** 4136 /**
4137 * Create a table mapping HTML tag names to the names of the classes (in 'dart :html') that
4138 * implement those tags.
4139 * @return the table that was created
4140 */
4141 static Map<String, String> createHtmlTagToClassMap() {
4142 Map<String, String> map = new Map<String, String>();
4143 map["a"] = "AnchorElement";
4144 map["area"] = "AreaElement";
4145 map["br"] = "BRElement";
4146 map["base"] = "BaseElement";
4147 map["body"] = "BodyElement";
4148 map["button"] = "ButtonElement";
4149 map["canvas"] = "CanvasElement";
4150 map["content"] = "ContentElement";
4151 map["dl"] = "DListElement";
4152 map["datalist"] = "DataListElement";
4153 map["details"] = "DetailsElement";
4154 map["div"] = "DivElement";
4155 map["embed"] = "EmbedElement";
4156 map["fieldset"] = "FieldSetElement";
4157 map["form"] = "FormElement";
4158 map["hr"] = "HRElement";
4159 map["head"] = "HeadElement";
4160 map["h1"] = "HeadingElement";
4161 map["h2"] = "HeadingElement";
4162 map["h3"] = "HeadingElement";
4163 map["h4"] = "HeadingElement";
4164 map["h5"] = "HeadingElement";
4165 map["h6"] = "HeadingElement";
4166 map["html"] = "HtmlElement";
4167 map["iframe"] = "IFrameElement";
4168 map["img"] = "ImageElement";
4169 map["input"] = "InputElement";
4170 map["keygen"] = "KeygenElement";
4171 map["li"] = "LIElement";
4172 map["label"] = "LabelElement";
4173 map["legend"] = "LegendElement";
4174 map["link"] = "LinkElement";
4175 map["map"] = "MapElement";
4176 map["menu"] = "MenuElement";
4177 map["meter"] = "MeterElement";
4178 map["ol"] = "OListElement";
4179 map["object"] = "ObjectElement";
4180 map["optgroup"] = "OptGroupElement";
4181 map["output"] = "OutputElement";
4182 map["p"] = "ParagraphElement";
4183 map["param"] = "ParamElement";
4184 map["pre"] = "PreElement";
4185 map["progress"] = "ProgressElement";
4186 map["script"] = "ScriptElement";
4187 map["select"] = "SelectElement";
4188 map["source"] = "SourceElement";
4189 map["span"] = "SpanElement";
4190 map["style"] = "StyleElement";
4191 map["caption"] = "TableCaptionElement";
4192 map["td"] = "TableCellElement";
4193 map["col"] = "TableColElement";
4194 map["table"] = "TableElement";
4195 map["tr"] = "TableRowElement";
4196 map["textarea"] = "TextAreaElement";
4197 map["title"] = "TitleElement";
4198 map["track"] = "TrackElement";
4199 map["ul"] = "UListElement";
4200 map["video"] = "VideoElement";
4201 return map;
4202 }
4203 /**
4204 * The resolver driving the resolution and type analysis.
4205 */
4206 ResolverVisitor _resolver;
4207 /**
3099 * The object providing access to the types defined by the language. 4208 * The object providing access to the types defined by the language.
3100 */ 4209 */
3101 TypeProvider _typeProvider; 4210 TypeProvider _typeProvider;
3102 /** 4211 /**
3103 * The type representing the type 'dynamic'. 4212 * The type representing the type 'dynamic'.
3104 */ 4213 */
3105 Type2 _dynamicType; 4214 Type2 _dynamicType;
3106 /** 4215 /**
3107 * The type representing the class containing the nodes being analyzed, or {@c ode null} if the 4216 * The type representing the class containing the nodes being analyzed, or {@c ode null} if the
3108 * nodes are not within a class. 4217 * nodes are not within a class.
3109 */ 4218 */
3110 InterfaceType _thisType; 4219 InterfaceType _thisType;
3111 /** 4220 /**
4221 * The object keeping track of which elements have had their types overridden.
4222 */
4223 TypeOverrideManager _overrideManager;
4224 /**
4225 * A flag indicating whether type propagation should be enabled.
4226 */
4227 static bool USE_TYPE_PROPAGATION = true;
4228 /**
4229 * A table mapping HTML tag names to the names of the classes (in 'dart:html') that implement
4230 * those tags.
4231 */
4232 static Map<String, String> _HTML_ELEMENT_TO_CLASS_MAP = createHtmlTagToClassMa p();
4233 /**
3112 * Initialize a newly created type analyzer. 4234 * Initialize a newly created type analyzer.
3113 * @param resolver the resolver driving this participant 4235 * @param resolver the resolver driving this participant
3114 */ 4236 */
3115 StaticTypeAnalyzer(ResolverVisitor resolver) { 4237 StaticTypeAnalyzer(ResolverVisitor resolver) {
4238 this._resolver = resolver;
3116 _typeProvider = resolver.typeProvider; 4239 _typeProvider = resolver.typeProvider;
3117 _dynamicType = _typeProvider.dynamicType; 4240 _dynamicType = _typeProvider.dynamicType;
4241 _overrideManager = resolver.overrideManager;
3118 } 4242 }
3119 /** 4243 /**
3120 * Set the type of the class being analyzed to the given type. 4244 * Set the type of the class being analyzed to the given type.
3121 * @param thisType the type representing the class containing the nodes being analyzed 4245 * @param thisType the type representing the class containing the nodes being analyzed
3122 */ 4246 */
3123 void set thisType(InterfaceType thisType2) { 4247 void set thisType(InterfaceType thisType2) {
3124 this._thisType = thisType2; 4248 this._thisType = thisType2;
3125 } 4249 }
3126 /** 4250 /**
3127 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote> 4251 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote>
3128 */ 4252 */
3129 Object visitAdjacentStrings(AdjacentStrings node) => recordType(node, _typePro vider.stringType); 4253 Object visitAdjacentStrings(AdjacentStrings node) => recordType(node, _typePro vider.stringType);
3130 /** 4254 /**
3131 * The Dart Language Specification, 12.33: <blockquote>The static type of an a rgument definition 4255 * The Dart Language Specification, 12.33: <blockquote>The static type of an a rgument definition
3132 * test is {@code bool}.</blockquote> 4256 * test is {@code bool}.</blockquote>
3133 */ 4257 */
3134 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) => recordType( node, _typeProvider.boolType); 4258 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) => recordType( node, _typeProvider.boolType);
3135 /** 4259 /**
3136 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ... 4260 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ...
3137 * <p> 4261 * <p>
3138 * It is a static warning if <i>T</i> does not denote a type available in the current lexical 4262 * It is a static warning if <i>T</i> does not denote a type available in the current lexical
3139 * scope. 4263 * scope.
3140 * <p> 4264 * <p>
3141 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote > 4265 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote >
3142 */ 4266 */
3143 Object visitAsExpression(AsExpression node) => recordType(node, getType3(node. type)); 4267 Object visitAsExpression(AsExpression node) => recordType(node, getType4(node. type));
3144 /** 4268 /**
3145 * The Dart Language Specification, 12.18: <blockquote> ... an assignment <i>a </i> of the form 4269 * The Dart Language Specification, 12.18: <blockquote> ... an assignment <i>a </i> of the form
3146 * <i>v = e</i> ... 4270 * <i>v = e</i> ...
3147 * <p> 4271 * <p>
3148 * It is a static type warning if the static type of <i>e</i> may not be assig ned to the static 4272 * It is a static type warning if the static type of <i>e</i> may not be assig ned to the static
3149 * type of <i>v</i>. 4273 * type of <i>v</i>.
3150 * <p> 4274 * <p>
3151 * The static type of the expression <i>v = e</i> is the static type of <i>e</ i>. 4275 * The static type of the expression <i>v = e</i> is the static type of <i>e</ i>.
3152 * <p> 4276 * <p>
3153 * ... an assignment of the form <i>C.v = e</i> ... 4277 * ... an assignment of the form <i>C.v = e</i> ...
(...skipping 22 matching lines...) Expand all
3176 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale nt to <i>((x) => x.v 4300 * assignment of the form <i>e<sub>1</sub>.v op= e<sub>2</sub></i> is equivale nt to <i>((x) => x.v
3177 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha t is not used in 4301 * = x.v op e<sub>2</sub>)(e<sub>1</sub>)</i> where <i>x</i> is a variable tha t is not used in
3178 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op= 4302 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op=
3179 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su b>)(e<sub>1</sub>, 4303 * e<sub>3</sub></i> is equivalent to <i>((a, i) => a[i] = a[i] op e<sub>3</su b>)(e<sub>1</sub>,
3180 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in 4304 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in
3181 * <i>e<sub>3</sub></i>. </blockquote> 4305 * <i>e<sub>3</sub></i>. </blockquote>
3182 */ 4306 */
3183 Object visitAssignmentExpression(AssignmentExpression node) { 4307 Object visitAssignmentExpression(AssignmentExpression node) {
3184 sc.TokenType operator11 = node.operator.type; 4308 sc.TokenType operator11 = node.operator.type;
3185 if (operator11 != sc.TokenType.EQ) { 4309 if (operator11 != sc.TokenType.EQ) {
3186 return recordReturnType(node, node.element, null); 4310 return recordReturnType(node, node.element);
3187 } 4311 }
3188 return recordType(node, getType(node.rightHandSide)); 4312 Type2 rightType = getType2(node.rightHandSide);
4313 if (USE_TYPE_PROPAGATION) {
4314 VariableElement element = _resolver.getOverridableElement(node.leftHandSid e);
4315 if (element != null) {
4316 override(element, getType(element), rightType);
4317 }
4318 }
4319 return recordType(node, rightType);
3189 } 4320 }
3190 /** 4321 /**
3191 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean 4322 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean
3192 * expression is {@code bool}.</blockquote> 4323 * expression is {@code bool}.</blockquote>
3193 * <p> 4324 * <p>
3194 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form 4325 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form
3195 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n 4326 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n
3196 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i >super op 4327 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i >super op
3197 * e<sub>2</sub></i> is equivalent to the method invocation 4328 * e<sub>2</sub></i> is equivalent to the method invocation
3198 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 4329 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
(...skipping 23 matching lines...) Expand all
3222 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n 4353 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n
3223 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the form <i>super op 4354 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the form <i>super op
3224 * e<sub>2</sub></i> is equivalent to the method invocation 4355 * e<sub>2</sub></i> is equivalent to the method invocation
3225 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 4356 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
3226 */ 4357 */
3227 Object visitBinaryExpression(BinaryExpression node) { 4358 Object visitBinaryExpression(BinaryExpression node) {
3228 sc.TokenType operator12 = node.operator.type; 4359 sc.TokenType operator12 = node.operator.type;
3229 while (true) { 4360 while (true) {
3230 if (operator12 == sc.TokenType.AMPERSAND_AMPERSAND || operator12 == sc.Tok enType.BAR_BAR || operator12 == sc.TokenType.EQ_EQ || operator12 == sc.TokenType .BANG_EQ) { 4361 if (operator12 == sc.TokenType.AMPERSAND_AMPERSAND || operator12 == sc.Tok enType.BAR_BAR || operator12 == sc.TokenType.EQ_EQ || operator12 == sc.TokenType .BANG_EQ) {
3231 return recordType(node, _typeProvider.boolType); 4362 return recordType(node, _typeProvider.boolType);
4363 } else if (operator12 == sc.TokenType.MINUS || operator12 == sc.TokenType. PERCENT || operator12 == sc.TokenType.PLUS || operator12 == sc.TokenType.STAR || operator12 == sc.TokenType.TILDE_SLASH) {
4364 Type2 intType2 = _typeProvider.intType;
4365 if (identical(getType2(node.leftOperand), intType2) && identical(getType 2(node.rightOperand), intType2)) {
4366 return recordType(node, intType2);
4367 }
4368 } else if (operator12 == sc.TokenType.SLASH) {
4369 Type2 doubleType2 = _typeProvider.doubleType;
4370 if (identical(getType2(node.leftOperand), doubleType2) || identical(getT ype2(node.rightOperand), doubleType2)) {
4371 return recordType(node, doubleType2);
4372 }
3232 } 4373 }
3233 break; 4374 break;
3234 } 4375 }
3235 return recordReturnType(node, node.element, null); 4376 return recordReturnType(node, node.element);
3236 } 4377 }
3237 /** 4378 /**
3238 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is{@code bool}.</blockquote> 4379 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is{@code bool}.</blockquote>
3239 */ 4380 */
3240 Object visitBooleanLiteral(BooleanLiteral node) => recordType(node, _typeProvi der.boolType); 4381 Object visitBooleanLiteral(BooleanLiteral node) => recordType(node, _typeProvi der.boolType);
3241 /** 4382 /**
3242 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv ocation expression 4383 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv ocation expression
3243 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff ix; return 4384 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff ix; return
3244 * t;}(e)</i>.</blockquote> 4385 * t;}(e)</i>.</blockquote>
3245 */ 4386 */
3246 Object visitCascadeExpression(CascadeExpression node) => recordType(node, getT ype(node.target)); 4387 Object visitCascadeExpression(CascadeExpression node) => recordType(node, getT ype2(node.target));
3247 /** 4388 /**
3248 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr ession <i>c</i> of 4389 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr ession <i>c</i> of
3249 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... 4390 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ...
3250 * <p> 4391 * <p>
3251 * It is a static type warning if the type of e<sub>1</sub> may not be assigne d to {@code bool}. 4392 * It is a static type warning if the type of e<sub>1</sub> may not be assigne d to {@code bool}.
3252 * <p> 4393 * <p>
3253 * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i> 4394 * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i>
3254 * and the static type of <i>e<sub>3</sub></i>.</blockquote> 4395 * and the static type of <i>e<sub>3</sub></i>.</blockquote>
3255 */ 4396 */
3256 Object visitConditionalExpression(ConditionalExpression node) { 4397 Object visitConditionalExpression(ConditionalExpression node) {
3257 Type2 thenType = getType(node.thenExpression); 4398 Type2 thenType = getType2(node.thenExpression);
3258 Type2 elseType = getType(node.elseExpression); 4399 Type2 elseType = getType2(node.elseExpression);
3259 if (thenType == null) { 4400 if (thenType == null) {
3260 return recordType(node, _dynamicType); 4401 return recordType(node, _dynamicType);
3261 } 4402 }
3262 Type2 resultType = thenType.getLeastUpperBound(elseType); 4403 Type2 resultType = thenType.getLeastUpperBound(elseType);
3263 return recordType(node, resultType); 4404 return recordType(node, resultType);
3264 } 4405 }
3265 /** 4406 /**
3266 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is{@code double}.</blockquote> 4407 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is{@code double}.</blockquote>
3267 */ 4408 */
3268 Object visitDoubleLiteral(DoubleLiteral node) => recordType(node, _typeProvide r.doubleType); 4409 Object visitDoubleLiteral(DoubleLiteral node) => recordType(node, _typeProvide r.doubleType);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub >n+1</sub>: 4456 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub >n+1</sub>:
3316 * a<sub>n+1</sub>, &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i> e<sub>f</sub></i> is 4457 * a<sub>n+1</sub>, &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>, where <i> e<sub>f</sub></i> is
3317 * an expression. 4458 * an expression.
3318 * <p> 4459 * <p>
3319 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be 4460 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be
3320 * assigned to a function type. 4461 * assigned to a function type.
3321 * <p> 4462 * <p>
3322 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the 4463 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the
3323 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e> 4464 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e>
3324 */ 4465 */
3325 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => recordReturnType(node, node.element, null); 4466 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => recordReturnType(node, node.element);
3326 /** 4467 /**
3327 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form 4468 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form
3328 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method 4469 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method
3329 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote> 4470 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote>
3330 */ 4471 */
3331 Object visitIndexExpression(IndexExpression node) { 4472 Object visitIndexExpression(IndexExpression node) {
3332 Type2 type = getType(node.realTarget); 4473 if (node.inSetterContext()) {
3333 List<Type2> typeArgs = null; 4474 return recordArgumentType(node, node.element);
3334 if (type is InterfaceType) {
3335 typeArgs = ((type as InterfaceType)).typeArguments;
3336 } 4475 }
3337 if (node.inSetterContext()) { 4476 return recordReturnType(node, node.element);
3338 return recordArgumentType(node, node.element, typeArgs);
3339 }
3340 return recordReturnType(node, node.element, typeArgs);
3341 } 4477 }
3342 /** 4478 /**
3343 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of 4479 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of
3344 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new 4480 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new
3345 * T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> 4481 * T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>.</blockquote>
3346 * <p> 4482 * <p>
3347 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a constant object 4483 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a constant object
3348 * expression of either the form <i>const T.id(a<sub>1</sub>, &hellip;, a<sub> n</sub>)</i> or the 4484 * expression of either the form <i>const T.id(a<sub>1</sub>, &hellip;, a<sub> n</sub>)</i> or the
3349 * form <i>const T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>. </ blockquote> 4485 * form <i>const T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>. </ blockquote>
3350 */ 4486 */
3351 Object visitInstanceCreationExpression(InstanceCreationExpression node) => rec ordType(node, node.constructorName.type.type); 4487 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
4488 if (USE_TYPE_PROPAGATION) {
4489 ConstructorElement element34 = node.element;
4490 if (element34 != null && "Element" == element34.enclosingElement.name && " tag" == element34.name) {
4491 LibraryElement library33 = element34.library;
4492 if (isHtmlLibrary(library33)) {
4493 Type2 returnType = getFirstArgumentAsType2(library33, node.argumentLis t, _HTML_ELEMENT_TO_CLASS_MAP);
4494 if (returnType != null) {
4495 return recordType(node, returnType);
4496 }
4497 }
4498 }
4499 }
4500 return recordType(node, node.constructorName.type.type);
4501 }
3352 /** 4502 /**
3353 * The Dart Language Specification, 12.3: <blockquote>The static type of an in teger literal is{@code int}.</blockquote> 4503 * The Dart Language Specification, 12.3: <blockquote>The static type of an in teger literal is{@code int}.</blockquote>
3354 */ 4504 */
3355 Object visitIntegerLiteral(IntegerLiteral node) => recordType(node, _typeProvi der.intType); 4505 Object visitIntegerLiteral(IntegerLiteral node) => recordType(node, _typeProvi der.intType);
3356 /** 4506 /**
3357 * The Dart Language Specification, 12.31: <blockquote>It is a static warning if <i>T</i> does not 4507 * The Dart Language Specification, 12.31: <blockquote>It is a static warning if <i>T</i> does not
3358 * denote a type available in the current lexical scope. 4508 * denote a type available in the current lexical scope.
3359 * <p> 4509 * <p>
3360 * The static type of an is-expression is {@code bool}.</blockquote> 4510 * The static type of an is-expression is {@code bool}.</blockquote>
3361 */ 4511 */
3362 Object visitIsExpression(IsExpression node) => recordType(node, _typeProvider. boolType); 4512 Object visitIsExpression(IsExpression node) => recordType(node, _typeProvider. boolType);
3363 /** 4513 /**
3364 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis t literal of the 4514 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis t literal of the
3365 * form <i><b>const</b> &lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> or the form 4515 * form <i><b>const</b> &lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> or the form
3366 * <i>&lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; E&gt;}. The static 4516 * <i>&lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; E&gt;}. The static
3367 * type a list literal of the form <i><b>const</b> [e<sub>1</sub>, &hellip;, e <sub>n</sub>]</i> or 4517 * type a list literal of the form <i><b>const</b> [e<sub>1</sub>, &hellip;, e <sub>n</sub>]</i> or
3368 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; dynamic&gt;}.</blockquote> 4518 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; dynamic&gt;}.</blockquote>
3369 */ 4519 */
3370 Object visitListLiteral(ListLiteral node) { 4520 Object visitListLiteral(ListLiteral node) {
3371 TypeArgumentList typeArguments8 = node.typeArguments; 4521 TypeArgumentList typeArguments8 = node.typeArguments;
3372 if (typeArguments8 != null) { 4522 if (typeArguments8 != null) {
3373 NodeList<TypeName> arguments4 = typeArguments8.arguments; 4523 NodeList<TypeName> arguments4 = typeArguments8.arguments;
3374 if (arguments4 != null && arguments4.length == 1) { 4524 if (arguments4 != null && arguments4.length == 1) {
3375 TypeName argumentType = arguments4[0]; 4525 TypeName argumentType = arguments4[0];
3376 return recordType(node, _typeProvider.listType.substitute5(<Type2> [getT ype3(argumentType)])); 4526 return recordType(node, _typeProvider.listType.substitute5(<Type2> [getT ype4(argumentType)]));
3377 } 4527 }
3378 } 4528 }
3379 return recordType(node, _typeProvider.listType.substitute5(<Type2> [_dynamic Type])); 4529 return recordType(node, _typeProvider.listType.substitute5(<Type2> [_dynamic Type]));
3380 } 4530 }
3381 /** 4531 /**
3382 * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form 4532 * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form
3383 * <i><b>const</b> &lt;String, V&gt; {k<sub>1</sub>:e<sub>1</sub>, &hellip;, 4533 * <i><b>const</b> &lt;String, V&gt; {k<sub>1</sub>:e<sub>1</sub>, &hellip;,
3384 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>&lt;String, V&gt; {k<sub>1< /sub>:e<sub>1</sub>, 4534 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>&lt;String, V&gt; {k<sub>1< /sub>:e<sub>1</sub>,
3385 * &hellip;, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, V&gt;}. The static type a 4535 * &hellip;, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, V&gt;}. The static type a
3386 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell ip;, 4536 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell ip;,
3387 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub >, &hellip;, 4537 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub >, &hellip;,
3388 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, dynamic&gt;}. 4538 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, dynamic&gt;}.
3389 * <p> 4539 * <p>
3390 * It is a compile-time error if the first type argument to a map literal is n ot 4540 * It is a compile-time error if the first type argument to a map literal is n ot
3391 * <i>String</i>.</blockquote> 4541 * <i>String</i>.</blockquote>
3392 */ 4542 */
3393 Object visitMapLiteral(MapLiteral node) { 4543 Object visitMapLiteral(MapLiteral node) {
3394 TypeArgumentList typeArguments9 = node.typeArguments; 4544 TypeArgumentList typeArguments9 = node.typeArguments;
3395 if (typeArguments9 != null) { 4545 if (typeArguments9 != null) {
3396 NodeList<TypeName> arguments5 = typeArguments9.arguments; 4546 NodeList<TypeName> arguments5 = typeArguments9.arguments;
3397 if (arguments5 != null && arguments5.length == 2) { 4547 if (arguments5 != null && arguments5.length == 2) {
3398 TypeName keyType = arguments5[0]; 4548 TypeName keyType = arguments5[0];
3399 if (keyType != _typeProvider.stringType) { 4549 if (keyType != _typeProvider.stringType) {
3400 } 4550 }
3401 TypeName valueType = arguments5[1]; 4551 TypeName valueType = arguments5[1];
3402 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_type Provider.stringType, getType3(valueType)])); 4552 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_type Provider.stringType, getType4(valueType)]));
3403 } 4553 }
3404 } 4554 }
3405 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_typeProv ider.stringType, _dynamicType])); 4555 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_typeProv ider.stringType, _dynamicType]));
3406 } 4556 }
3407 /** 4557 /**
3408 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in vocation <i>i</i> 4558 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in vocation <i>i</i>
3409 * has the form <i>o.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub> : a<sub>n+1</sub>, 4559 * has the form <i>o.m(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub>n+1</sub> : a<sub>n+1</sub>,
3410 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. 4560 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
3411 * <p> 4561 * <p>
3412 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if <i>T</i> does not 4562 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if <i>T</i> does not
(...skipping 20 matching lines...) Expand all
3433 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. 4583 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
3434 * <p> 4584 * <p>
3435 * It is a static type warning if <i>S</i> does not have an accessible instanc e member named m. If 4585 * It is a static type warning if <i>S</i> does not have an accessible instanc e member named m. If
3436 * <i>S.m</i> exists, it is a static warning if the type <i>F</i> of <i>S.m</i > may not be 4586 * <i>S.m</i> exists, it is a static warning if the type <i>F</i> of <i>S.m</i > may not be
3437 * assigned to a function type. 4587 * assigned to a function type.
3438 * <p> 4588 * <p>
3439 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st atic type of 4589 * If <i>S.m</i> does not exist, or if <i>F</i> is not a function type, the st atic type of
3440 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared return type of 4590 * <i>i</i> is dynamic. Otherwise the static type of <i>i</i> is the declared return type of
3441 * <i>F</i>.</blockquote> 4591 * <i>F</i>.</blockquote>
3442 */ 4592 */
3443 Object visitMethodInvocation(MethodInvocation node) => recordReturnType(node, node.methodName.element, null); 4593 Object visitMethodInvocation(MethodInvocation node) {
3444 Object visitNamedExpression(NamedExpression node) => recordType(node, getType( node.expression)); 4594 if (USE_TYPE_PROPAGATION) {
4595 String methodName3 = node.methodName.name;
4596 if (methodName3 == "\$dom_createEvent") {
4597 Expression target = node.realTarget;
4598 if (target != null) {
4599 Type2 targetType = getType2(target);
4600 if (targetType is InterfaceType && (targetType.name == "HtmlDocument" || targetType.name == "Document")) {
4601 LibraryElement library34 = targetType.element.library;
4602 if (isHtmlLibrary(library34)) {
4603 Type2 returnType = getFirstArgumentAsType(library34, node.argument List);
4604 if (returnType != null) {
4605 return recordType(node, returnType);
4606 }
4607 }
4608 }
4609 }
4610 } else if (methodName3 == "JS") {
4611 Type2 returnType = getFirstArgumentAsType(_typeProvider.objectType.eleme nt.library, node.argumentList);
4612 if (returnType != null) {
4613 return recordType(node, returnType);
4614 }
4615 }
4616 }
4617 return recordReturnType(node, node.methodName.element);
4618 }
4619 Object visitNamedExpression(NamedExpression node) => recordType(node, getType2 (node.expression));
3445 /** 4620 /**
3446 * The Dart Language Specification, 12.2: <blockquote>The static type of {@cod e null} is bottom. 4621 * The Dart Language Specification, 12.2: <blockquote>The static type of {@cod e null} is bottom.
3447 * </blockquote> 4622 * </blockquote>
3448 */ 4623 */
3449 Object visitNullLiteral(NullLiteral node) => recordType(node, _typeProvider.bo ttomType); 4624 Object visitNullLiteral(NullLiteral node) => recordType(node, _typeProvider.bo ttomType);
3450 Object visitParenthesizedExpression(ParenthesizedExpression node) => recordTyp e(node, getType(node.expression)); 4625 Object visitParenthesizedExpression(ParenthesizedExpression node) => recordTyp e(node, getType2(node.expression));
3451 /** 4626 /**
3452 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form 4627 * The Dart Language Specification, 12.28: <blockquote>A postfix expression of the form
3453 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1; 4628 * <i>v++</i>, where <i>v</i> is an identifier, is equivalent to <i>(){var r = v; v = r + 1;
3454 * return r}()</i>. 4629 * return r}()</i>.
3455 * <p> 4630 * <p>
3456 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r = C.v; C.v = r + 1; 4631 * A postfix expression of the form <i>C.v++</i> is equivalent to <i>(){var r = C.v; C.v = r + 1;
3457 * return r}()</i>. 4632 * return r}()</i>.
3458 * <p> 4633 * <p>
3459 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var r = x.v; x.v = r + 4634 * A postfix expression of the form <i>e1.v++</i> is equivalent to <i>(x){var r = x.v; x.v = r +
3460 * 1; return r}(e1)</i>. 4635 * 1; return r}(e1)</i>.
3461 * <p> 4636 * <p>
3462 * A postfix expression of the form <i>e1[e2]++</i> is equivalent to <i>(a, i) {var r = a[i]; a[i] 4637 * A postfix expression of the form <i>e1[e2]++</i> is equivalent to <i>(a, i) {var r = a[i]; a[i]
3463 * = r + 1; return r}(e1, e2)</i> 4638 * = r + 1; return r}(e1, e2)</i>
3464 * <p> 4639 * <p>
3465 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie r, is equivalent to 4640 * A postfix expression of the form <i>v--</i>, where <i>v</i> is an identifie r, is equivalent to
3466 * <i>(){var r = v; v = r - 1; return r}()</i>. 4641 * <i>(){var r = v; v = r - 1; return r}()</i>.
3467 * <p> 4642 * <p>
3468 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r = C.v; C.v = r - 1; 4643 * A postfix expression of the form <i>C.v--</i> is equivalent to <i>(){var r = C.v; C.v = r - 1;
3469 * return r}()</i>. 4644 * return r}()</i>.
3470 * <p> 4645 * <p>
3471 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var r = x.v; x.v = r - 4646 * A postfix expression of the form <i>e1.v--</i> is equivalent to <i>(x){var r = x.v; x.v = r -
3472 * 1; return r}(e1)</i>. 4647 * 1; return r}(e1)</i>.
3473 * <p> 4648 * <p>
3474 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i] 4649 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i]
3475 * = r - 1; return r}(e1, e2)</i></blockquote> 4650 * = r - 1; return r}(e1, e2)</i></blockquote>
3476 */ 4651 */
3477 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT ype(node.operand)); 4652 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT ype2(node.operand));
3478 /** 4653 /**
3479 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. 4654 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}.
3480 */ 4655 */
3481 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 4656 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
3482 SimpleIdentifier prefixedIdentifier = node.identifier; 4657 SimpleIdentifier prefixedIdentifier = node.identifier;
3483 Element element29 = prefixedIdentifier.element; 4658 Element element35 = prefixedIdentifier.element;
3484 if (element29 is VariableElement) { 4659 if (element35 == null) {
3485 Type2 variableType = ((element29 as VariableElement)).type; 4660 return recordType(node, _dynamicType);
3486 recordType(prefixedIdentifier, variableType); 4661 }
3487 return recordType(node, variableType); 4662 if (USE_TYPE_PROPAGATION) {
3488 } else if (element29 is PropertyAccessorElement) { 4663 Type2 type = _overrideManager.getType(element35);
3489 Type2 propertyType = getType2((element29 as PropertyAccessorElement)); 4664 if (type != null) {
3490 recordType(prefixedIdentifier, propertyType); 4665 return recordType(node, type);
3491 return recordType(node, propertyType); 4666 }
3492 } else if (element29 is MethodElement) { 4667 }
3493 Type2 returnType = ((element29 as MethodElement)).type; 4668 Type2 type;
3494 recordType(prefixedIdentifier, returnType); 4669 if (element35 is ClassElement) {
3495 return recordType(node, returnType); 4670 if (isNotTypeLiteral(node)) {
4671 type = ((element35 as ClassElement)).type;
4672 } else {
4673 type = _typeProvider.typeType;
4674 }
4675 } else if (element35 is FunctionTypeAliasElement) {
4676 type = ((element35 as FunctionTypeAliasElement)).type;
4677 } else if (element35 is MethodElement) {
4678 type = ((element35 as MethodElement)).type;
4679 } else if (element35 is PropertyAccessorElement) {
4680 type = getType3((element35 as PropertyAccessorElement), node.prefix.static Type);
4681 } else if (element35 is ExecutableElement) {
4682 type = ((element35 as ExecutableElement)).type;
4683 } else if (element35 is TypeVariableElement) {
4684 type = ((element35 as TypeVariableElement)).type;
4685 } else if (element35 is VariableElement) {
4686 type = ((element35 as VariableElement)).type;
3496 } else { 4687 } else {
4688 type = _dynamicType;
3497 } 4689 }
3498 recordType(prefixedIdentifier, _dynamicType); 4690 recordType(prefixedIdentifier, type);
3499 return recordType(node, _dynamicType); 4691 return recordType(node, type);
3500 } 4692 }
3501 /** 4693 /**
3502 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form 4694 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form
3503 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the 4695 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the
3504 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote> 4696 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote>
3505 */ 4697 */
3506 Object visitPrefixExpression(PrefixExpression node) { 4698 Object visitPrefixExpression(PrefixExpression node) {
3507 sc.TokenType operator13 = node.operator.type; 4699 sc.TokenType operator13 = node.operator.type;
3508 if (identical(operator13, sc.TokenType.BANG)) { 4700 if (identical(operator13, sc.TokenType.BANG)) {
3509 return recordType(node, _typeProvider.boolType); 4701 return recordType(node, _typeProvider.boolType);
3510 } 4702 }
3511 return recordReturnType(node, node.element, null); 4703 return recordReturnType(node, node.element);
3512 } 4704 }
3513 /** 4705 /**
3514 * The Dart Language Specification, 12.13: <blockquote> Property extraction al lows for a member of 4706 * The Dart Language Specification, 12.13: <blockquote> Property extraction al lows for a member of
3515 * an object to be concisely extracted from the object. If <i>o</i> is an obje ct, and if <i>m</i> 4707 * an object to be concisely extracted from the object. If <i>o</i> is an obje ct, and if <i>m</i>
3516 * is the name of a method member of <i>o</i>, then 4708 * is the name of a method member of <i>o</i>, then
3517 * <ul> 4709 * <ul>
3518 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, &hellip;, r<sub>n</sub>, 4710 * <li><i>o.m</i> is defined to be equivalent to: <i>(r<sub>1</sub>, &hellip;, r<sub>n</sub>,
3519 * {p<sub>1</sub> : d<sub>1</sub>, &hellip;, p<sub>k</sub> : d<sub>k</sub>}){r eturn 4711 * {p<sub>1</sub> : d<sub>1</sub>, &hellip;, p<sub>k</sub> : d<sub>k</sub>}){r eturn
3520 * o.m(r<sub>1</sub>, &hellip;, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, & hellip;, 4712 * o.m(r<sub>1</sub>, &hellip;, r<sub>n</sub>, p<sub>1</sub>: p<sub>1</sub>, & hellip;,
3521 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i> r<sub>1</sub>, 4713 * p<sub>k</sub>: p<sub>k</sub>);}</i> if <i>m</i> has required parameters <i> r<sub>1</sub>,
(...skipping 26 matching lines...) Expand all
3548 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it exists or dynamic 4740 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it exists or dynamic
3549 * otherwise. 4741 * otherwise.
3550 * <p> 4742 * <p>
3551 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an 4743 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an
3552 * identifier ... 4744 * identifier ...
3553 * <p> 4745 * <p>
3554 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote> 4746 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote>
3555 */ 4747 */
3556 Object visitPropertyAccess(PropertyAccess node) { 4748 Object visitPropertyAccess(PropertyAccess node) {
3557 SimpleIdentifier propertyName2 = node.propertyName; 4749 SimpleIdentifier propertyName2 = node.propertyName;
3558 Element element30 = propertyName2.element; 4750 Element element36 = propertyName2.element;
3559 if (element30 is MethodElement) { 4751 if (USE_TYPE_PROPAGATION) {
3560 FunctionType type15 = ((element30 as MethodElement)).type; 4752 Type2 type = _overrideManager.getType(element36);
3561 recordType(propertyName2, type15); 4753 if (type != null) {
3562 return recordType(node, type15); 4754 return recordType(node, type);
3563 } else if (element30 is PropertyAccessorElement) { 4755 }
3564 Type2 propertyType = getType2((element30 as PropertyAccessorElement)); 4756 }
4757 if (element36 is MethodElement) {
4758 FunctionType type19 = ((element36 as MethodElement)).type;
4759 recordType(propertyName2, type19);
4760 return recordType(node, type19);
4761 } else if (element36 is PropertyAccessorElement) {
4762 Type2 propertyType = getType3((element36 as PropertyAccessorElement), node .target != null ? node.target.staticType : null);
3565 recordType(propertyName2, propertyType); 4763 recordType(propertyName2, propertyType);
3566 return recordType(node, propertyType); 4764 return recordType(node, propertyType);
3567 } else { 4765 } else {
3568 } 4766 }
3569 recordType(propertyName2, _dynamicType); 4767 recordType(propertyName2, _dynamicType);
3570 return recordType(node, _dynamicType); 4768 return recordType(node, _dynamicType);
3571 } 4769 }
3572 /** 4770 /**
3573 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret hrow expression is 4771 * The Dart Language Specification, 12.9: <blockquote>The static type of a ret hrow expression is
3574 * bottom.</blockquote> 4772 * bottom.</blockquote>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3610 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is equivalent to the 4808 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is equivalent to the
3611 * getter invocation <i>id</i>. 4809 * getter invocation <i>id</i>.
3612 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be it function, 4810 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be it function,
3613 * method, getter, or setter) or variable initializer, evaluation of e causes a NoSuchMethodError 4811 * method, getter, or setter) or variable initializer, evaluation of e causes a NoSuchMethodError
3614 * to be thrown. 4812 * to be thrown.
3615 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id< /i>. 4813 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id< /i>.
3616 * </ul> 4814 * </ul>
3617 * </blockquote> 4815 * </blockquote>
3618 */ 4816 */
3619 Object visitSimpleIdentifier(SimpleIdentifier node) { 4817 Object visitSimpleIdentifier(SimpleIdentifier node) {
3620 Element element31 = node.element; 4818 Element element37 = node.element;
3621 if (element31 == null) { 4819 if (element37 == null) {
3622 return recordType(node, _dynamicType); 4820 return recordType(node, _dynamicType);
3623 } else if (element31 is ClassElement) { 4821 }
4822 if (USE_TYPE_PROPAGATION) {
4823 Type2 type = _overrideManager.getType(element37);
4824 if (type != null) {
4825 return recordType(node, type);
4826 }
4827 }
4828 Type2 type;
4829 if (element37 is ClassElement) {
3624 if (isNotTypeLiteral(node)) { 4830 if (isNotTypeLiteral(node)) {
3625 return recordType(node, ((element31 as ClassElement)).type); 4831 type = ((element37 as ClassElement)).type;
4832 } else {
4833 type = _typeProvider.typeType;
3626 } 4834 }
3627 return recordType(node, _typeProvider.typeType); 4835 } else if (element37 is FunctionTypeAliasElement) {
3628 } else if (element31 is TypeVariableElement) { 4836 type = ((element37 as FunctionTypeAliasElement)).type;
3629 return recordType(node, ((element31 as TypeVariableElement)).type); 4837 } else if (element37 is MethodElement) {
3630 } else if (element31 is FunctionTypeAliasElement) { 4838 type = ((element37 as MethodElement)).type;
3631 return recordType(node, ((element31 as FunctionTypeAliasElement)).type); 4839 } else if (element37 is PropertyAccessorElement) {
3632 } else if (element31 is VariableElement) { 4840 type = getType3((element37 as PropertyAccessorElement), null);
3633 return recordType(node, ((element31 as VariableElement)).type); 4841 } else if (element37 is ExecutableElement) {
3634 } else if (element31 is MethodElement) { 4842 type = ((element37 as ExecutableElement)).type;
3635 return recordType(node, ((element31 as MethodElement)).type); 4843 } else if (element37 is TypeVariableElement) {
3636 } else if (element31 is PropertyAccessorElement) { 4844 type = ((element37 as TypeVariableElement)).type;
3637 return recordType(node, getType2((element31 as PropertyAccessorElement))); 4845 } else if (element37 is VariableElement) {
3638 } else if (element31 is ExecutableElement) { 4846 type = ((element37 as VariableElement)).type;
3639 return recordType(node, ((element31 as ExecutableElement)).type); 4847 } else if (element37 is PrefixElement) {
3640 } else if (element31 is PrefixElement) {
3641 return null; 4848 return null;
3642 } else { 4849 } else {
3643 return recordType(node, _dynamicType); 4850 type = _dynamicType;
3644 } 4851 }
4852 return recordType(node, type);
3645 } 4853 }
3646 /** 4854 /**
3647 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote> 4855 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote>
3648 */ 4856 */
3649 Object visitSimpleStringLiteral(SimpleStringLiteral node) => recordType(node, _typeProvider.stringType); 4857 Object visitSimpleStringLiteral(SimpleStringLiteral node) => recordType(node, _typeProvider.stringType);
3650 /** 4858 /**
3651 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote> 4859 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote>
3652 */ 4860 */
3653 Object visitStringInterpolation(StringInterpolation node) => recordType(node, _typeProvider.stringType); 4861 Object visitStringInterpolation(StringInterpolation node) => recordType(node, _typeProvider.stringType);
3654 Object visitSuperExpression(SuperExpression node) { 4862 Object visitSuperExpression(SuperExpression node) {
(...skipping 12 matching lines...) Expand all
3667 return recordType(node, _dynamicType); 4875 return recordType(node, _dynamicType);
3668 } else { 4876 } else {
3669 return recordType(node, _thisType); 4877 return recordType(node, _thisType);
3670 } 4878 }
3671 } 4879 }
3672 /** 4880 /**
3673 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr ow expression is 4881 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr ow expression is
3674 * bottom.</blockquote> 4882 * bottom.</blockquote>
3675 */ 4883 */
3676 Object visitThrowExpression(ThrowExpression node) => recordType(node, _typePro vider.bottomType); 4884 Object visitThrowExpression(ThrowExpression node) => recordType(node, _typePro vider.bottomType);
4885 Object visitVariableDeclaration(VariableDeclaration node) {
4886 if (USE_TYPE_PROPAGATION) {
4887 Expression initializer6 = node.initializer;
4888 if (initializer6 != null) {
4889 Type2 rightType = getType2(initializer6);
4890 VariableElement element38 = node.name.element as VariableElement;
4891 if (element38 != null) {
4892 override(element38, getType(element38), rightType);
4893 }
4894 }
4895 }
4896 return null;
4897 }
3677 /** 4898 /**
3678 * Given a function declaration, compute the return type of the function. The return type of 4899 * Given a function declaration, compute the return type of the function. The return type of
3679 * functions with a block body is {@code dynamicType}, with an expression body it is the type of 4900 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
3680 * the expression. 4901 * the expression.
3681 * @param node the function expression whose return type is to be computed 4902 * @param node the function expression whose return type is to be computed
3682 * @return the return type that was computed 4903 * @return the return type that was computed
3683 */ 4904 */
3684 Type2 computeReturnType(FunctionDeclaration node) { 4905 Type2 computeReturnType(FunctionDeclaration node) {
3685 TypeName returnType8 = node.returnType; 4906 TypeName returnType9 = node.returnType;
3686 if (returnType8 == null) { 4907 if (returnType9 == null) {
3687 return computeReturnType2(node.functionExpression); 4908 return computeReturnType2(node.functionExpression);
3688 } 4909 }
3689 return returnType8.type; 4910 return returnType9.type;
3690 } 4911 }
3691 /** 4912 /**
3692 * Given a function expression, compute the return type of the function. The r eturn type of 4913 * Given a function expression, compute the return type of the function. The r eturn type of
3693 * functions with a block body is {@code dynamicType}, with an expression body it is the type of 4914 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
3694 * the expression. 4915 * the expression.
3695 * @param node the function expression whose return type is to be computed 4916 * @param node the function expression whose return type is to be computed
3696 * @return the return type that was computed 4917 * @return the return type that was computed
3697 */ 4918 */
3698 Type2 computeReturnType2(FunctionExpression node) { 4919 Type2 computeReturnType2(FunctionExpression node) {
3699 FunctionBody body4 = node.body; 4920 FunctionBody body4 = node.body;
3700 if (body4 is ExpressionFunctionBody) { 4921 if (body4 is ExpressionFunctionBody) {
3701 return getType(((body4 as ExpressionFunctionBody)).expression); 4922 return getType2(((body4 as ExpressionFunctionBody)).expression);
3702 } 4923 }
3703 return _dynamicType; 4924 return _dynamicType;
3704 } 4925 }
3705 /** 4926 /**
4927 * If the given argument list contains at least one argument, and if the argum ent is a simple
4928 * string literal, and if the value of the argument is the name of a class def ined within the
4929 * given library, return the type specified by the argument.
4930 * @param library the library in which the specified type would be defined
4931 * @param argumentList the list of arguments from which a type is to be extrac ted
4932 * @return the type specified by the first argument in the argument list
4933 */
4934 Type2 getFirstArgumentAsType(LibraryElement library, ArgumentList argumentList ) => getFirstArgumentAsType2(library, argumentList, null);
4935 /**
4936 * If the given argument list contains at least one argument, and if the argum ent is a simple
4937 * string literal, and if the value of the argument is the name of a class def ined within the
4938 * given library, return the type specified by the argument.
4939 * @param library the library in which the specified type would be defined
4940 * @param argumentList the list of arguments from which a type is to be extrac ted
4941 * @return the type specified by the first argument in the argument list
4942 */
4943 Type2 getFirstArgumentAsType2(LibraryElement library, ArgumentList argumentLis t, Map<String, String> nameMap) {
4944 NodeList<Expression> arguments6 = argumentList.arguments;
4945 if (arguments6.length > 0) {
4946 Expression argument = arguments6[0];
4947 if (argument is SimpleStringLiteral) {
4948 String argumentValue = ((argument as SimpleStringLiteral)).value;
4949 if (argumentValue != null) {
4950 if (nameMap != null) {
4951 argumentValue = nameMap[argumentValue.toLowerCase()];
4952 }
4953 ClassElement returnType = library.getType(argumentValue);
4954 if (returnType != null) {
4955 return returnType.type;
4956 }
4957 }
4958 }
4959 }
4960 return null;
4961 }
4962 Type2 getType(Element element) {
4963 if (element is LocalVariableElement) {
4964 return ((element as LocalVariableElement)).type;
4965 } else if (element is ParameterElement) {
4966 return ((element as ParameterElement)).type;
4967 }
4968 return null;
4969 }
4970 /**
3706 * Return the type of the given expression that is to be used for type analysi s. 4971 * Return the type of the given expression that is to be used for type analysi s.
3707 * @param expression the expression whose type is to be returned 4972 * @param expression the expression whose type is to be returned
3708 * @return the type of the given expression 4973 * @return the type of the given expression
3709 */ 4974 */
3710 Type2 getType(Expression expression) { 4975 Type2 getType2(Expression expression) {
3711 Type2 type = expression.staticType; 4976 Type2 type = expression.staticType;
3712 if (type == null) { 4977 if (type == null) {
3713 return _dynamicType; 4978 return _dynamicType;
3714 } 4979 }
3715 return type; 4980 return type;
3716 } 4981 }
3717 /** 4982 /**
3718 * Return the type that should be recorded for a node that resolved to the giv en accessor. 4983 * Return the type that should be recorded for a node that resolved to the giv en accessor.
3719 * @param accessor the accessor that the node resolved to 4984 * @param accessor the accessor that the node resolved to
4985 * @param context if the accessor element has context [by being the RHS of a{@ link PrefixedIdentifier} or {@link PropertyAccess}], and the return type of the
4986 * accessor is a parameter type, then the type of the LHS can be used to get m ore
4987 * specific type information
3720 * @return the type that should be recorded for a node that resolved to the gi ven accessor 4988 * @return the type that should be recorded for a node that resolved to the gi ven accessor
3721 */ 4989 */
3722 Type2 getType2(PropertyAccessorElement accessor) { 4990 Type2 getType3(PropertyAccessorElement accessor, Type2 context) {
3723 FunctionType functionType = accessor.type; 4991 FunctionType functionType = accessor.type;
3724 if (functionType == null) { 4992 if (functionType == null) {
3725 return _dynamicType; 4993 return _dynamicType;
3726 } 4994 }
3727 if (accessor.isSetter()) { 4995 if (accessor.isSetter()) {
3728 List<Type2> parameterTypes = functionType.normalParameterTypes; 4996 List<Type2> parameterTypes = functionType.normalParameterTypes;
3729 if (parameterTypes != null && parameterTypes.length > 0) { 4997 if (parameterTypes != null && parameterTypes.length > 0) {
3730 return parameterTypes[0]; 4998 return parameterTypes[0];
3731 } 4999 }
3732 PropertyAccessorElement getter4 = accessor.variable.getter; 5000 PropertyAccessorElement getter4 = accessor.variable.getter;
3733 if (getter4 != null) { 5001 if (getter4 != null) {
3734 functionType = getter4.type; 5002 functionType = getter4.type;
3735 if (functionType != null) { 5003 if (functionType != null) {
3736 return functionType.returnType; 5004 return functionType.returnType;
3737 } 5005 }
3738 } 5006 }
3739 return _dynamicType; 5007 return _dynamicType;
3740 } 5008 }
3741 return functionType.returnType; 5009 Type2 returnType10 = functionType.returnType;
5010 if (returnType10 is TypeVariableType && context is InterfaceType) {
5011 InterfaceType interfaceTypeContext = (context as InterfaceType);
5012 List<TypeVariableElement> parameterElements = interfaceTypeContext.element != null ? interfaceTypeContext.element.typeVariables : null;
5013 if (parameterElements != null) {
5014 for (int i = 0; i < parameterElements.length; i++) {
5015 TypeVariableElement varElt = parameterElements[i];
5016 if (returnType10.name == varElt.name) {
5017 return interfaceTypeContext.typeArguments[i];
5018 }
5019 }
5020 }
5021 }
5022 return returnType10;
3742 } 5023 }
3743 /** 5024 /**
3744 * Return the type represented by the given type name. 5025 * Return the type represented by the given type name.
3745 * @param typeName the type name representing the type to be returned 5026 * @param typeName the type name representing the type to be returned
3746 * @return the type represented by the type name 5027 * @return the type represented by the type name
3747 */ 5028 */
3748 Type2 getType3(TypeName typeName) { 5029 Type2 getType4(TypeName typeName) {
3749 Type2 type16 = typeName.type; 5030 Type2 type20 = typeName.type;
3750 if (type16 == null) { 5031 if (type20 == null) {
3751 return _dynamicType; 5032 return _dynamicType;
3752 } 5033 }
3753 return type16; 5034 return type20;
3754 } 5035 }
3755 /** 5036 /**
5037 * Return {@code true} if the given library is the 'dart:html' library.
5038 * @param library the library being tested
5039 * @return {@code true} if the library is 'dart:html'
5040 */
5041 bool isHtmlLibrary(LibraryElement library) => library.name == "dart.dom.html";
5042 /**
3756 * Return {@code true} if the given node is not a type literal. 5043 * Return {@code true} if the given node is not a type literal.
3757 * @param node the node being tested 5044 * @param node the node being tested
3758 * @return {@code true} if the given node is not a type literal 5045 * @return {@code true} if the given node is not a type literal
3759 */ 5046 */
3760 bool isNotTypeLiteral(SimpleIdentifier node) { 5047 bool isNotTypeLiteral(Identifier node) {
3761 ASTNode parent15 = node.parent; 5048 ASTNode parent15 = node.parent;
3762 return parent15 is TypeName || (parent15 is PrefixedIdentifier && (parent15. parent is TypeName || identical(((parent15 as PrefixedIdentifier)).prefix, node) )) || (parent15 is PropertyAccess && identical(((parent15 as PropertyAccess)).ta rget, node)) || (parent15 is MethodInvocation && identical(node, ((parent15 as M ethodInvocation)).target)); 5049 return parent15 is TypeName || (parent15 is PrefixedIdentifier && (parent15. parent is TypeName || identical(((parent15 as PrefixedIdentifier)).prefix, node) )) || (parent15 is PropertyAccess && identical(((parent15 as PropertyAccess)).ta rget, node)) || (parent15 is MethodInvocation && identical(node, ((parent15 as M ethodInvocation)).target));
3763 } 5050 }
3764 /** 5051 /**
5052 * If it is appropriate to do so, override the type of the given element. Use the static type and
5053 * inferred type of the element to determine whether or not it is appropriate.
5054 * @param element the element whose type might be overridden
5055 * @param staticType the static type of the element
5056 * @param inferredType the inferred type of the element
5057 */
5058 void override(VariableElement element, Type2 staticType, Type2 inferredType) {
5059 if (identical(inferredType, BottomTypeImpl.instance) || element is! Variable Element) {
5060 return;
5061 }
5062 if (element is PropertyInducingElement) {
5063 PropertyInducingElement variable = element as PropertyInducingElement;
5064 if (!variable.isConst() && !variable.isFinal()) {
5065 return;
5066 }
5067 }
5068 if (staticType == null || (inferredType != null && inferredType.isMoreSpecif icThan(staticType))) {
5069 _overrideManager.setType(element, inferredType);
5070 }
5071 }
5072 /**
3765 * Record that the static type of the given node is the type of the second arg ument to the method 5073 * Record that the static type of the given node is the type of the second arg ument to the method
3766 * represented by the given element. 5074 * represented by the given element.
3767 * @param expression the node whose type is to be recorded 5075 * @param expression the node whose type is to be recorded
3768 * @param element the element representing the method invoked by the given nod e 5076 * @param element the element representing the method invoked by the given nod e
3769 * @param typeArguments the array of {@link Type}s to perform a substitution o n the parameter
3770 * types from the type in the passed {@link Element}, or <code>null</code>
3771 */ 5077 */
3772 Object recordArgumentType(IndexExpression expression, MethodElement element, L ist<Type2> typeArguments10) { 5078 Object recordArgumentType(IndexExpression expression, MethodElement element) {
3773 if (element != null) { 5079 if (element != null) {
3774 List<ParameterElement> parameters12 = element.parameters; 5080 List<ParameterElement> parameters14 = element.parameters;
3775 if (parameters12 != null && parameters12.length == 2) { 5081 if (parameters14 != null && parameters14.length == 2) {
3776 ClassElement classElement = parameters12[1].getAncestor(ClassElement); 5082 return recordType(expression, parameters14[1].type);
3777 List<Type2> typeParameters = classElement == null ? null : classElement. type.typeArguments;
3778 if (typeArguments10 == null || typeParameters == null || typeArguments10 .length != typeParameters.length) {
3779 return recordType(expression, parameters12[1].type);
3780 } else {
3781 return recordType(expression, parameters12[1].type.substitute2(typeArg uments10, typeParameters));
3782 }
3783 } 5083 }
3784 } 5084 }
3785 return recordType(expression, _dynamicType); 5085 return recordType(expression, _dynamicType);
3786 } 5086 }
3787 /** 5087 /**
3788 * Record that the static type of the given node is the return type of the met hod or function 5088 * Record that the static type of the given node is the return type of the met hod or function
3789 * represented by the given element. 5089 * represented by the given element.
3790 * @param expression the node whose type is to be recorded 5090 * @param expression the node whose type is to be recorded
3791 * @param element the element representing the method or function invoked by t he given node 5091 * @param element the element representing the method or function invoked by t he given node
3792 * @param typeArguments the array of {@link Type}s to perform a substitution o n the parameter
3793 * types from the type in the passed {@link Element}, or <code>null</code>
3794 */ 5092 */
3795 Object recordReturnType(Expression expression, Element element, List<Type2> ty peArguments11) { 5093 Object recordReturnType(Expression expression, Element element) {
3796 if (element is PropertyAccessorElement) { 5094 if (element is PropertyAccessorElement) {
3797 FunctionType propertyType = ((element as PropertyAccessorElement)).type; 5095 FunctionType propertyType = ((element as PropertyAccessorElement)).type;
3798 if (propertyType != null) { 5096 if (propertyType != null) {
3799 Type2 returnType9 = propertyType.returnType; 5097 Type2 returnType11 = propertyType.returnType;
3800 if (returnType9 is FunctionType) { 5098 if (returnType11 is FunctionType) {
3801 Type2 innerReturnType = ((returnType9 as FunctionType)).returnType; 5099 Type2 innerReturnType = ((returnType11 as FunctionType)).returnType;
3802 if (innerReturnType != null) { 5100 if (innerReturnType != null) {
3803 return recordType(expression, innerReturnType); 5101 return recordType(expression, innerReturnType);
3804 } 5102 }
5103 } else if (returnType11.isDartCoreFunction()) {
5104 return recordType(expression, _dynamicType);
3805 } 5105 }
3806 if (returnType9 != null) { 5106 if (returnType11 != null) {
3807 return recordType(expression, returnType9); 5107 return recordType(expression, returnType11);
3808 } 5108 }
3809 } 5109 }
3810 } else if (element is ExecutableElement) { 5110 } else if (element is ExecutableElement) {
3811 FunctionType type17 = ((element as ExecutableElement)).type; 5111 FunctionType type21 = ((element as ExecutableElement)).type;
3812 if (type17 != null) { 5112 if (type21 != null) {
3813 ClassElement classElement = element.getAncestor(ClassElement); 5113 return recordType(expression, type21.returnType);
3814 List<Type2> typeParameters = classElement == null ? null : classElement. type.typeArguments;
3815 if (typeArguments11 == null || typeParameters == null || typeArguments11 .length != typeParameters.length) {
3816 return recordType(expression, type17.returnType);
3817 } else {
3818 return recordType(expression, type17.returnType.substitute2(typeArgume nts11, typeParameters));
3819 }
3820 } 5114 }
3821 } else if (element is VariableElement) { 5115 } else if (element is VariableElement) {
3822 Type2 variableType = ((element as VariableElement)).type; 5116 Type2 variableType = ((element as VariableElement)).type;
3823 if (variableType is FunctionType) { 5117 if (variableType is FunctionType) {
3824 return recordType(expression, ((variableType as FunctionType)).returnTyp e); 5118 return recordType(expression, ((variableType as FunctionType)).returnTyp e);
3825 } 5119 }
3826 } 5120 }
3827 return recordType(expression, _dynamicType); 5121 return recordType(expression, _dynamicType);
3828 } 5122 }
3829 /** 5123 /**
3830 * Record that the static type of the given node is the given type. 5124 * Record that the static type of the given node is the given type.
3831 * @param expression the node whose type is to be recorded 5125 * @param expression the node whose type is to be recorded
3832 * @param type the static type of the node 5126 * @param type the static type of the node
3833 */ 5127 */
3834 Object recordType(Expression expression, Type2 type) { 5128 Object recordType(Expression expression, Type2 type) {
3835 if (type == null) { 5129 if (type == null) {
3836 expression.staticType = _dynamicType; 5130 expression.staticType = _dynamicType;
3837 } else { 5131 } else {
3838 expression.staticType = type; 5132 expression.staticType = type;
3839 } 5133 }
3840 return null; 5134 return null;
3841 } 5135 }
3842 /** 5136 /**
3843 * Set the return type and parameter type information for the given function t ype based on the 5137 * Set the return type and parameter type information for the given function t ype based on the
3844 * given return type and parameter elements. 5138 * given return type and parameter elements.
3845 * @param functionType the function type to be filled in 5139 * @param functionType the function type to be filled in
3846 * @param returnType the return type of the function, or {@code null} if no ty pe was declared 5140 * @param returnType the return type of the function, or {@code null} if no ty pe was declared
3847 * @param parameters the elements representing the parameters to the function 5141 * @param parameters the elements representing the parameters to the function
3848 */ 5142 */
3849 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType12, For malParameterList parameterList) { 5143 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType14, For malParameterList parameterList) {
3850 List<Type2> normalParameterTypes = new List<Type2>(); 5144 List<Type2> normalParameterTypes = new List<Type2>();
3851 List<Type2> optionalParameterTypes = new List<Type2>(); 5145 List<Type2> optionalParameterTypes = new List<Type2>();
3852 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>(); 5146 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
3853 if (parameterList != null) { 5147 if (parameterList != null) {
3854 for (ParameterElement parameter in parameterList.elements) { 5148 for (ParameterElement parameter in parameterList.elements) {
3855 while (true) { 5149 while (true) {
3856 if (parameter.parameterKind == ParameterKind.REQUIRED) { 5150 if (parameter.parameterKind == ParameterKind.REQUIRED) {
3857 normalParameterTypes.add(parameter.type); 5151 normalParameterTypes.add(parameter.type);
3858 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { 5152 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) {
3859 optionalParameterTypes.add(parameter.type); 5153 optionalParameterTypes.add(parameter.type);
3860 } else if (parameter.parameterKind == ParameterKind.NAMED) { 5154 } else if (parameter.parameterKind == ParameterKind.NAMED) {
3861 namedParameterTypes[parameter.name] = parameter.type; 5155 namedParameterTypes[parameter.name] = parameter.type;
3862 } 5156 }
3863 break; 5157 break;
3864 } 5158 }
3865 } 5159 }
3866 } 5160 }
3867 functionType.normalParameterTypes = new List.from(normalParameterTypes); 5161 functionType.normalParameterTypes = new List.from(normalParameterTypes);
3868 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); 5162 functionType.optionalParameterTypes = new List.from(optionalParameterTypes);
3869 functionType.namedParameterTypes = namedParameterTypes; 5163 functionType.namedParameterTypes = namedParameterTypes;
3870 functionType.returnType = returnType12; 5164 functionType.returnType = returnType14;
3871 } 5165 }
3872 get thisType_J2DAccessor => _thisType; 5166 get thisType_J2DAccessor => _thisType;
3873 set thisType_J2DAccessor(__v) => _thisType = __v; 5167 set thisType_J2DAccessor(__v) => _thisType = __v;
3874 } 5168 }
3875 /** 5169 /**
5170 * Instances of the class {@code TypeOverrideManager} manage the ability to over ride the type of an
5171 * element within a given context.
5172 */
5173 class TypeOverrideManager {
5174 /**
5175 * The current override scope, or {@code null} if no scope has been entered.
5176 */
5177 TypeOverrideManager_TypeOverrideScope _currentScope;
5178 /**
5179 * Initialize a newly created override manager to not be in any scope.
5180 */
5181 TypeOverrideManager() : super() {
5182 }
5183 /**
5184 * Enter a new override scope.
5185 */
5186 void enterScope() {
5187 _currentScope = new TypeOverrideManager_TypeOverrideScope(_currentScope);
5188 }
5189 /**
5190 * Exit the current override scope.
5191 */
5192 void exitScope() {
5193 if (_currentScope == null) {
5194 throw new IllegalStateException("No scope to exit");
5195 }
5196 _currentScope = _currentScope._outerScope;
5197 }
5198 /**
5199 * Return the overridden type of the given element, or {@code null} if the typ e of the element has
5200 * not been overridden.
5201 * @param element the element whose type might have been overridden
5202 * @return the overridden type of the given element
5203 */
5204 Type2 getType(Element element) {
5205 if (_currentScope == null) {
5206 return null;
5207 }
5208 return _currentScope.getType(element);
5209 }
5210 /**
5211 * Set the overridden type of the given element to the given type
5212 * @param element the element whose type might have been overridden
5213 * @param type the overridden type of the given element
5214 */
5215 void setType(Element element, Type2 type) {
5216 if (_currentScope == null) {
5217 throw new IllegalStateException("Cannot override without a scope");
5218 }
5219 _currentScope.setType(element, type);
5220 }
5221 }
5222 /**
5223 * Instances of the class {@code TypeOverrideScope} represent a scope in which t he types of
5224 * elements can be overridden.
5225 */
5226 class TypeOverrideManager_TypeOverrideScope {
5227 /**
5228 * The outer scope in which types might be overridden.
5229 */
5230 TypeOverrideManager_TypeOverrideScope _outerScope;
5231 /**
5232 * A table mapping elements to the overridden type of that element.
5233 */
5234 Map<Element, Type2> _overridenTypes = new Map<Element, Type2>();
5235 /**
5236 * Initialize a newly created scope to be an empty child of the given scope.
5237 * @param outerScope the outer scope in which types might be overridden
5238 */
5239 TypeOverrideManager_TypeOverrideScope(TypeOverrideManager_TypeOverrideScope ou terScope) {
5240 this._outerScope = outerScope;
5241 }
5242 /**
5243 * Return the overridden type of the given element, or {@code null} if the typ e of the element
5244 * has not been overridden.
5245 * @param element the element whose type might have been overridden
5246 * @return the overridden type of the given element
5247 */
5248 Type2 getType(Element element) {
5249 Type2 type = _overridenTypes[element];
5250 if (type == null && element is PropertyAccessorElement) {
5251 type = _overridenTypes[((element as PropertyAccessorElement)).variable];
5252 }
5253 if (type != null) {
5254 return type;
5255 } else if (_outerScope != null) {
5256 return _outerScope.getType(element);
5257 }
5258 return null;
5259 }
5260 /**
5261 * Set the overridden type of the given element to the given type
5262 * @param element the element whose type might have been overridden
5263 * @param type the overridden type of the given element
5264 */
5265 void setType(Element element, Type2 type) {
5266 _overridenTypes[element] = type;
5267 }
5268 }
5269 /**
3876 * The interface {@code TypeProvider} defines the behavior of objects that provi de access to types 5270 * The interface {@code TypeProvider} defines the behavior of objects that provi de access to types
3877 * defined by the language. 5271 * defined by the language.
3878 * @coverage dart.engine.resolver 5272 * @coverage dart.engine.resolver
3879 */ 5273 */
3880 abstract class TypeProvider { 5274 abstract class TypeProvider {
3881 /** 5275 /**
3882 * Return the type representing the built-in type 'bool'. 5276 * Return the type representing the built-in type 'bool'.
3883 * @return the type representing the built-in type 'bool' 5277 * @return the type representing the built-in type 'bool'
3884 */ 5278 */
3885 InterfaceType get boolType; 5279 InterfaceType get boolType;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
4069 /** 5463 /**
4070 * The type representing the type 'dynamic'. 5464 * The type representing the type 'dynamic'.
4071 */ 5465 */
4072 Type2 _dynamicType; 5466 Type2 _dynamicType;
4073 /** 5467 /**
4074 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 5468 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
4075 * @param library the library containing the compilation unit being resolved 5469 * @param library the library containing the compilation unit being resolved
4076 * @param source the source representing the compilation unit being visited 5470 * @param source the source representing the compilation unit being visited
4077 * @param typeProvider the object used to access the types from the core libra ry 5471 * @param typeProvider the object used to access the types from the core libra ry
4078 */ 5472 */
4079 TypeResolverVisitor(Library library, Source source, TypeProvider typeProvider) : super(library, source, typeProvider) { 5473 TypeResolverVisitor.con1(Library library, Source source, TypeProvider typeProv ider) : super.con1(library, source, typeProvider) {
5474 _jtd_constructor_273_impl(library, source, typeProvider);
5475 }
5476 _jtd_constructor_273_impl(Library library, Source source, TypeProvider typePro vider) {
5477 _dynamicType = typeProvider.dynamicType;
5478 }
5479 /**
5480 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
5481 * @param definingLibrary the element for the library containing the compilati on unit being
5482 * visited
5483 * @param source the source representing the compilation unit being visited
5484 * @param typeProvider the object used to access the types from the core libra ry
5485 * @param errorListener the error listener that will be informed of any errors that are found
5486 * during resolution
5487 */
5488 TypeResolverVisitor.con2(LibraryElement definingLibrary, Source source, TypePr ovider typeProvider, AnalysisErrorListener errorListener) : super.con2(definingL ibrary, source, typeProvider, errorListener) {
5489 _jtd_constructor_274_impl(definingLibrary, source, typeProvider, errorListen er);
5490 }
5491 _jtd_constructor_274_impl(LibraryElement definingLibrary, Source source, TypeP rovider typeProvider, AnalysisErrorListener errorListener) {
4080 _dynamicType = typeProvider.dynamicType; 5492 _dynamicType = typeProvider.dynamicType;
4081 } 5493 }
4082 Object visitCatchClause(CatchClause node) { 5494 Object visitCatchClause(CatchClause node) {
4083 super.visitCatchClause(node); 5495 super.visitCatchClause(node);
4084 SimpleIdentifier exception = node.exceptionParameter; 5496 SimpleIdentifier exception = node.exceptionParameter;
4085 if (exception != null) { 5497 if (exception != null) {
4086 TypeName exceptionTypeName = node.exceptionType; 5498 TypeName exceptionTypeName = node.exceptionType;
4087 Type2 exceptionType; 5499 Type2 exceptionType;
4088 if (exceptionTypeName == null) { 5500 if (exceptionTypeName == null) {
4089 exceptionType = typeProvider.objectType; 5501 exceptionType = typeProvider.objectType;
4090 } else { 5502 } else {
4091 exceptionType = getType4(exceptionTypeName); 5503 exceptionType = getType5(exceptionTypeName);
4092 } 5504 }
4093 recordType(exception, exceptionType); 5505 recordType(exception, exceptionType);
4094 Element element32 = exception.element; 5506 Element element39 = exception.element;
4095 if (element32 is VariableElementImpl) { 5507 if (element39 is VariableElementImpl) {
4096 ((element32 as VariableElementImpl)).type = exceptionType; 5508 ((element39 as VariableElementImpl)).type = exceptionType;
4097 } else { 5509 } else {
4098 } 5510 }
4099 } 5511 }
4100 SimpleIdentifier stackTrace = node.stackTraceParameter; 5512 SimpleIdentifier stackTrace = node.stackTraceParameter;
4101 if (stackTrace != null) { 5513 if (stackTrace != null) {
4102 recordType(stackTrace, typeProvider.stackTraceType); 5514 recordType(stackTrace, typeProvider.stackTraceType);
4103 } 5515 }
4104 return null; 5516 return null;
4105 } 5517 }
4106 Object visitClassDeclaration(ClassDeclaration node) { 5518 Object visitClassDeclaration(ClassDeclaration node) {
4107 super.visitClassDeclaration(node); 5519 super.visitClassDeclaration(node);
4108 ClassElementImpl classElement = getClassElement(node.name); 5520 ClassElementImpl classElement = getClassElement(node.name);
4109 InterfaceType superclassType = null; 5521 InterfaceType superclassType = null;
4110 ExtendsClause extendsClause4 = node.extendsClause; 5522 ExtendsClause extendsClause4 = node.extendsClause;
4111 if (extendsClause4 != null) { 5523 if (extendsClause4 != null) {
4112 superclassType = resolveType(extendsClause4.superclass, CompileTimeErrorCo de.EXTENDS_NON_CLASS, CompileTimeErrorCode.EXTENDS_NON_CLASS, null); 5524 superclassType = resolveType(extendsClause4.superclass, CompileTimeErrorCo de.EXTENDS_NON_CLASS);
4113 if (superclassType != typeProvider.objectType) { 5525 if (superclassType != typeProvider.objectType) {
4114 classElement.validMixin = false; 5526 classElement.validMixin = false;
4115 } 5527 }
4116 } 5528 }
4117 if (classElement != null) { 5529 if (classElement != null) {
4118 if (superclassType == null) { 5530 if (superclassType == null) {
4119 InterfaceType objectType2 = typeProvider.objectType; 5531 InterfaceType objectType2 = typeProvider.objectType;
4120 if (classElement.type != objectType2) { 5532 if (classElement.type != objectType2) {
4121 superclassType = objectType2; 5533 superclassType = objectType2;
4122 } 5534 }
4123 } 5535 }
4124 classElement.supertype = superclassType; 5536 classElement.supertype = superclassType;
4125 } 5537 }
4126 resolve(classElement, node.withClause, node.implementsClause); 5538 resolve(classElement, node.withClause, node.implementsClause);
4127 return null; 5539 return null;
4128 } 5540 }
4129 Object visitClassTypeAlias(ClassTypeAlias node) { 5541 Object visitClassTypeAlias(ClassTypeAlias node) {
4130 super.visitClassTypeAlias(node); 5542 super.visitClassTypeAlias(node);
4131 ClassElementImpl classElement = getClassElement(node.name); 5543 ClassElementImpl classElement = getClassElement(node.name);
4132 InterfaceType superclassType = resolveType(node.superclass, CompileTimeError Code.EXTENDS_NON_CLASS, CompileTimeErrorCode.EXTENDS_NON_CLASS, null); 5544 InterfaceType superclassType = resolveType(node.superclass, CompileTimeError Code.EXTENDS_NON_CLASS);
4133 if (superclassType == null) { 5545 if (superclassType == null) {
4134 superclassType = typeProvider.objectType; 5546 superclassType = typeProvider.objectType;
4135 } 5547 }
4136 if (classElement != null && superclassType != null) { 5548 if (classElement != null && superclassType != null) {
4137 classElement.supertype = superclassType; 5549 classElement.supertype = superclassType;
4138 } 5550 }
4139 resolve(classElement, node.withClause, node.implementsClause); 5551 resolve(classElement, node.withClause, node.implementsClause);
4140 return null; 5552 return null;
4141 } 5553 }
4142 Object visitConstructorDeclaration(ConstructorDeclaration node) { 5554 Object visitConstructorDeclaration(ConstructorDeclaration node) {
4143 super.visitConstructorDeclaration(node); 5555 super.visitConstructorDeclaration(node);
4144 ExecutableElementImpl element33 = node.element as ExecutableElementImpl; 5556 ExecutableElementImpl element40 = node.element as ExecutableElementImpl;
4145 FunctionTypeImpl type = new FunctionTypeImpl.con1(element33); 5557 FunctionTypeImpl type = new FunctionTypeImpl.con1(element40);
4146 setTypeInformation(type, null, element33.parameters); 5558 setTypeInformation(type, null, element40.parameters);
4147 type.returnType = ((element33.enclosingElement as ClassElement)).type; 5559 type.returnType = ((element40.enclosingElement as ClassElement)).type;
4148 element33.type = type; 5560 element40.type = type;
4149 return null; 5561 return null;
4150 } 5562 }
4151 Object visitDeclaredIdentifier(DeclaredIdentifier node) { 5563 Object visitDeclaredIdentifier(DeclaredIdentifier node) {
4152 super.visitDeclaredIdentifier(node); 5564 super.visitDeclaredIdentifier(node);
4153 Type2 declaredType; 5565 Type2 declaredType;
4154 TypeName typeName = node.type; 5566 TypeName typeName = node.type;
4155 if (typeName == null) { 5567 if (typeName == null) {
4156 declaredType = _dynamicType; 5568 declaredType = _dynamicType;
4157 } else { 5569 } else {
4158 declaredType = getType4(typeName); 5570 declaredType = getType5(typeName);
4159 } 5571 }
4160 LocalVariableElementImpl element34 = node.element as LocalVariableElementImp l; 5572 LocalVariableElementImpl element41 = node.element as LocalVariableElementImp l;
4161 element34.type = declaredType; 5573 element41.type = declaredType;
4162 return null; 5574 return null;
4163 } 5575 }
4164 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 5576 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
4165 super.visitDefaultFormalParameter(node); 5577 super.visitDefaultFormalParameter(node);
4166 return null; 5578 return null;
4167 } 5579 }
4168 Object visitFieldFormalParameter(FieldFormalParameter node) { 5580 Object visitFieldFormalParameter(FieldFormalParameter node) {
4169 super.visitFieldFormalParameter(node); 5581 super.visitFieldFormalParameter(node);
4170 Element element35 = node.identifier.element; 5582 Element element42 = node.identifier.element;
4171 if (element35 is ParameterElementImpl) { 5583 if (element42 is ParameterElementImpl) {
4172 ParameterElementImpl parameter = element35 as ParameterElementImpl; 5584 ParameterElementImpl parameter = element42 as ParameterElementImpl;
4173 Type2 type; 5585 Type2 type;
4174 TypeName typeName = node.type; 5586 TypeName typeName = node.type;
4175 if (typeName == null) { 5587 if (typeName == null) {
4176 type = _dynamicType; 5588 type = _dynamicType;
4177 } else { 5589 } else {
4178 type = getType4(typeName); 5590 type = getType5(typeName);
4179 } 5591 }
4180 parameter.type = type; 5592 parameter.type = type;
4181 } else { 5593 } else {
4182 } 5594 }
4183 return null; 5595 return null;
4184 } 5596 }
4185 Object visitFunctionDeclaration(FunctionDeclaration node) { 5597 Object visitFunctionDeclaration(FunctionDeclaration node) {
4186 super.visitFunctionDeclaration(node); 5598 super.visitFunctionDeclaration(node);
4187 ExecutableElementImpl element36 = node.element as ExecutableElementImpl; 5599 ExecutableElementImpl element43 = node.element as ExecutableElementImpl;
4188 FunctionTypeImpl type = new FunctionTypeImpl.con1(element36); 5600 FunctionTypeImpl type = new FunctionTypeImpl.con1(element43);
4189 setTypeInformation(type, node.returnType, element36.parameters); 5601 setTypeInformation(type, node.returnType, element43.parameters);
4190 element36.type = type; 5602 element43.type = type;
4191 return null; 5603 return null;
4192 } 5604 }
4193 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 5605 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
4194 super.visitFunctionTypeAlias(node); 5606 super.visitFunctionTypeAlias(node);
4195 FunctionTypeAliasElementImpl element37 = node.element as FunctionTypeAliasEl ementImpl; 5607 FunctionTypeAliasElementImpl element44 = node.element as FunctionTypeAliasEl ementImpl;
4196 FunctionTypeImpl type18 = element37.type as FunctionTypeImpl; 5608 FunctionTypeImpl type22 = element44.type as FunctionTypeImpl;
4197 setTypeInformation(type18, node.returnType, element37.parameters); 5609 setTypeInformation(type22, node.returnType, element44.parameters);
4198 return null; 5610 return null;
4199 } 5611 }
4200 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 5612 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
4201 super.visitFunctionTypedFormalParameter(node); 5613 super.visitFunctionTypedFormalParameter(node);
4202 ParameterElementImpl element38 = node.identifier.element as ParameterElement Impl; 5614 ParameterElementImpl element45 = node.identifier.element as ParameterElement Impl;
4203 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement )); 5615 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement ));
4204 setTypeInformation(type, node.returnType, getElements(node.parameters)); 5616 setTypeInformation(type, node.returnType, getElements(node.parameters));
4205 element38.type = type; 5617 element45.type = type;
4206 return null; 5618 return null;
4207 } 5619 }
4208 Object visitMethodDeclaration(MethodDeclaration node) { 5620 Object visitMethodDeclaration(MethodDeclaration node) {
4209 super.visitMethodDeclaration(node); 5621 super.visitMethodDeclaration(node);
4210 ExecutableElementImpl element39 = node.element as ExecutableElementImpl; 5622 ExecutableElementImpl element46 = node.element as ExecutableElementImpl;
4211 FunctionTypeImpl type = new FunctionTypeImpl.con1(element39); 5623 FunctionTypeImpl type = new FunctionTypeImpl.con1(element46);
4212 setTypeInformation(type, node.returnType, element39.parameters); 5624 setTypeInformation(type, node.returnType, element46.parameters);
4213 element39.type = type; 5625 element46.type = type;
4214 if (element39 is PropertyAccessorElementImpl) { 5626 if (element46 is PropertyAccessorElement) {
4215 PropertyAccessorElementImpl accessor = element39 as PropertyAccessorElemen tImpl; 5627 PropertyAccessorElement accessor = element46 as PropertyAccessorElement;
4216 PropertyInducingElementImpl variable5 = accessor.variable as PropertyInduc ingElementImpl; 5628 PropertyInducingElementImpl variable6 = accessor.variable as PropertyInduc ingElementImpl;
4217 if (accessor.isGetter()) { 5629 if (accessor.isGetter()) {
4218 variable5.type = type.returnType; 5630 variable6.type = type.returnType;
4219 } else if (variable5.type == null) { 5631 } else if (variable6.type == null) {
4220 List<Type2> parameterTypes = type.normalParameterTypes; 5632 List<Type2> parameterTypes = type.normalParameterTypes;
4221 if (parameterTypes != null && parameterTypes.length > 0) { 5633 if (parameterTypes != null && parameterTypes.length > 0) {
4222 variable5.type = parameterTypes[0]; 5634 variable6.type = parameterTypes[0];
4223 } 5635 }
4224 } 5636 }
4225 } 5637 }
4226 return null; 5638 return null;
4227 } 5639 }
4228 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 5640 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
4229 super.visitSimpleFormalParameter(node); 5641 super.visitSimpleFormalParameter(node);
4230 Type2 declaredType; 5642 Type2 declaredType;
4231 TypeName typeName = node.type; 5643 TypeName typeName = node.type;
4232 if (typeName == null) { 5644 if (typeName == null) {
4233 declaredType = _dynamicType; 5645 declaredType = _dynamicType;
4234 } else { 5646 } else {
4235 declaredType = getType4(typeName); 5647 declaredType = getType5(typeName);
4236 } 5648 }
4237 Element element40 = node.identifier.element; 5649 Element element47 = node.identifier.element;
4238 if (element40 is ParameterElement) { 5650 if (element47 is ParameterElement) {
4239 ((element40 as ParameterElementImpl)).type = declaredType; 5651 ((element47 as ParameterElementImpl)).type = declaredType;
4240 } else { 5652 } else {
4241 } 5653 }
4242 return null; 5654 return null;
4243 } 5655 }
4244 Object visitTypeName(TypeName node) { 5656 Object visitTypeName(TypeName node) {
4245 super.visitTypeName(node); 5657 super.visitTypeName(node);
4246 Identifier typeName = node.name; 5658 Identifier typeName = node.name;
4247 TypeArgumentList argumentList = node.typeArguments; 5659 TypeArgumentList argumentList = node.typeArguments;
4248 Element element = nameScope.lookup(typeName, definingLibrary); 5660 Element element = nameScope.lookup(typeName, definingLibrary);
4249 if (element == null) { 5661 if (element == null) {
(...skipping 10 matching lines...) Expand all
4260 if (argumentList != null) { 5672 if (argumentList != null) {
4261 } 5673 }
4262 typeName.staticType = voidType; 5674 typeName.staticType = voidType;
4263 node.type = voidType; 5675 node.type = voidType;
4264 return null; 5676 return null;
4265 } 5677 }
4266 ASTNode parent16 = node.parent; 5678 ASTNode parent16 = node.parent;
4267 if (typeName is PrefixedIdentifier && parent16 is ConstructorName && argum entList == null) { 5679 if (typeName is PrefixedIdentifier && parent16 is ConstructorName && argum entList == null) {
4268 ConstructorName name = parent16 as ConstructorName; 5680 ConstructorName name = parent16 as ConstructorName;
4269 if (name.name == null) { 5681 if (name.name == null) {
4270 SimpleIdentifier prefix8 = ((typeName as PrefixedIdentifier)).prefix; 5682 SimpleIdentifier prefix7 = ((typeName as PrefixedIdentifier)).prefix;
4271 element = nameScope.lookup(prefix8, definingLibrary); 5683 element = nameScope.lookup(prefix7, definingLibrary);
4272 if (element is PrefixElement) { 5684 if (element is PrefixElement) {
4273 return null; 5685 return null;
4274 } else if (element != null) { 5686 } else if (element != null) {
4275 name.name = ((typeName as PrefixedIdentifier)).identifier; 5687 name.name = ((typeName as PrefixedIdentifier)).identifier;
4276 name.period = ((typeName as PrefixedIdentifier)).period; 5688 name.period = ((typeName as PrefixedIdentifier)).period;
4277 node.name = prefix8; 5689 node.name = prefix7;
4278 typeName = prefix8; 5690 typeName = prefix7;
4279 } 5691 }
4280 } 5692 }
4281 } 5693 }
4282 } 5694 }
4283 if (element == null) { 5695 if (element == null) {
5696 Identifier simpleIdentifier;
5697 if (typeName is SimpleIdentifier) {
5698 simpleIdentifier = typeName;
5699 } else {
5700 simpleIdentifier = ((typeName as PrefixedIdentifier)).prefix;
5701 }
5702 reportError(StaticWarningCode.UNDEFINED_CLASS, simpleIdentifier, [simpleId entifier.name]);
4284 setElement(typeName, _dynamicType.element); 5703 setElement(typeName, _dynamicType.element);
4285 typeName.staticType = _dynamicType; 5704 typeName.staticType = _dynamicType;
4286 node.type = _dynamicType; 5705 node.type = _dynamicType;
4287 return null; 5706 return null;
4288 } 5707 }
4289 Type2 type = null; 5708 Type2 type = null;
4290 if (element is ClassElement) { 5709 if (element is ClassElement) {
4291 setElement(typeName, element); 5710 setElement(typeName, element);
4292 type = ((element as ClassElement)).type; 5711 type = ((element as ClassElement)).type;
4293 } else if (element is FunctionTypeAliasElement) { 5712 } else if (element is FunctionTypeAliasElement) {
4294 setElement(typeName, element); 5713 setElement(typeName, element);
4295 type = ((element as FunctionTypeAliasElement)).type; 5714 type = ((element as FunctionTypeAliasElement)).type;
4296 } else if (element is TypeVariableElement) { 5715 } else if (element is TypeVariableElement) {
4297 setElement(typeName, element); 5716 setElement(typeName, element);
4298 type = ((element as TypeVariableElement)).type; 5717 type = ((element as TypeVariableElement)).type;
4299 if (argumentList != null) { 5718 if (argumentList != null) {
4300 } 5719 }
5720 } else if (element is MultiplyDefinedElement) {
5721 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting Elements;
5722 type = getType(elements);
5723 if (type != null) {
5724 node.type = type;
5725 }
4301 } else { 5726 } else {
4302 setElement(typeName, _dynamicType.element); 5727 setElement(typeName, _dynamicType.element);
4303 typeName.staticType = _dynamicType; 5728 typeName.staticType = _dynamicType;
4304 node.type = _dynamicType; 5729 node.type = _dynamicType;
4305 return null; 5730 return null;
4306 } 5731 }
4307 if (argumentList != null) { 5732 if (argumentList != null) {
4308 NodeList<TypeName> arguments6 = argumentList.arguments; 5733 NodeList<TypeName> arguments7 = argumentList.arguments;
4309 int argumentCount = arguments6.length; 5734 int argumentCount = arguments7.length;
4310 List<Type2> parameters = getTypeArguments(type); 5735 List<Type2> parameters = getTypeArguments(type);
4311 int parameterCount = parameters.length; 5736 int parameterCount = parameters.length;
4312 int count = Math.min(argumentCount, parameterCount); 5737 int count = Math.min(argumentCount, parameterCount);
4313 List<Type2> typeArguments = new List<Type2>(); 5738 List<Type2> typeArguments = new List<Type2>();
4314 for (int i = 0; i < count; i++) { 5739 for (int i = 0; i < count; i++) {
4315 Type2 argumentType = getType4(arguments6[i]); 5740 Type2 argumentType = getType5(arguments7[i]);
4316 if (argumentType != null) { 5741 if (argumentType != null) {
4317 typeArguments.add(argumentType); 5742 typeArguments.add(argumentType);
4318 } 5743 }
4319 } 5744 }
4320 if (argumentCount != parameterCount) { 5745 if (argumentCount != parameterCount) {
4321 reportError(getInvalidTypeParametersErrorCode(node), node, [typeName.nam e, argumentCount, parameterCount]); 5746 reportError(getInvalidTypeParametersErrorCode(node), node, [typeName.nam e, parameterCount, argumentCount]);
4322 } 5747 }
4323 argumentCount = typeArguments.length; 5748 argumentCount = typeArguments.length;
4324 if (argumentCount < parameterCount) { 5749 if (argumentCount < parameterCount) {
4325 for (int i = argumentCount; i < parameterCount; i++) { 5750 for (int i = argumentCount; i < parameterCount; i++) {
4326 typeArguments.add(_dynamicType); 5751 typeArguments.add(_dynamicType);
4327 } 5752 }
4328 } 5753 }
4329 if (type is InterfaceTypeImpl) { 5754 if (type is InterfaceTypeImpl) {
4330 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; 5755 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl;
4331 type = interfaceType.substitute5(new List.from(typeArguments)); 5756 type = interfaceType.substitute5(new List.from(typeArguments));
(...skipping 18 matching lines...) Expand all
4350 node.type = type; 5775 node.type = type;
4351 return null; 5776 return null;
4352 } 5777 }
4353 Object visitVariableDeclaration(VariableDeclaration node) { 5778 Object visitVariableDeclaration(VariableDeclaration node) {
4354 super.visitVariableDeclaration(node); 5779 super.visitVariableDeclaration(node);
4355 Type2 declaredType; 5780 Type2 declaredType;
4356 TypeName typeName = ((node.parent as VariableDeclarationList)).type; 5781 TypeName typeName = ((node.parent as VariableDeclarationList)).type;
4357 if (typeName == null) { 5782 if (typeName == null) {
4358 declaredType = _dynamicType; 5783 declaredType = _dynamicType;
4359 } else { 5784 } else {
4360 declaredType = getType4(typeName); 5785 declaredType = getType5(typeName);
4361 } 5786 }
4362 Element element41 = node.name.element; 5787 Element element48 = node.name.element;
4363 if (element41 is VariableElement) { 5788 if (element48 is VariableElement) {
4364 ((element41 as VariableElementImpl)).type = declaredType; 5789 ((element48 as VariableElementImpl)).type = declaredType;
4365 if (element41 is FieldElement) { 5790 if (element48 is PropertyInducingElement) {
4366 FieldElement field = element41 as FieldElement; 5791 PropertyInducingElement variableElement = element48 as PropertyInducingE lement;
4367 PropertyAccessorElementImpl getter5 = field.getter as PropertyAccessorEl ementImpl; 5792 PropertyAccessorElementImpl getter5 = variableElement.getter as Property AccessorElementImpl;
4368 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter5); 5793 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter5);
4369 getterType.returnType = declaredType; 5794 getterType.returnType = declaredType;
4370 getter5.type = getterType; 5795 getter5.type = getterType;
4371 PropertyAccessorElementImpl setter4 = field.setter as PropertyAccessorEl ementImpl; 5796 PropertyAccessorElementImpl setter4 = variableElement.setter as Property AccessorElementImpl;
4372 if (setter4 != null) { 5797 if (setter4 != null) {
4373 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter4); 5798 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter4);
4374 setterType.returnType = VoidTypeImpl.instance; 5799 setterType.returnType = VoidTypeImpl.instance;
4375 setterType.normalParameterTypes = <Type2> [declaredType]; 5800 setterType.normalParameterTypes = <Type2> [declaredType];
4376 setter4.type = setterType; 5801 setter4.type = setterType;
4377 } 5802 }
4378 } 5803 }
4379 } else { 5804 } else {
4380 } 5805 }
4381 return null; 5806 return null;
4382 } 5807 }
4383 /** 5808 /**
4384 * Return the class element that represents the class whose name was provided. 5809 * Return the class element that represents the class whose name was provided.
4385 * @param identifier the name from the declaration of a class 5810 * @param identifier the name from the declaration of a class
4386 * @return the class element that represents the class 5811 * @return the class element that represents the class
4387 */ 5812 */
4388 ClassElementImpl getClassElement(SimpleIdentifier identifier) { 5813 ClassElementImpl getClassElement(SimpleIdentifier identifier) {
4389 if (identifier == null) { 5814 if (identifier == null) {
4390 return null; 5815 return null;
4391 } 5816 }
4392 Element element42 = identifier.element; 5817 Element element49 = identifier.element;
4393 if (element42 is! ClassElementImpl) { 5818 if (element49 is! ClassElementImpl) {
4394 return null; 5819 return null;
4395 } 5820 }
4396 return element42 as ClassElementImpl; 5821 return element49 as ClassElementImpl;
4397 } 5822 }
4398 /** 5823 /**
4399 * Return an array containing all of the elements associated with the paramete rs in the given 5824 * Return an array containing all of the elements associated with the paramete rs in the given
4400 * list. 5825 * list.
4401 * @param parameterList the list of parameters whose elements are to be return ed 5826 * @param parameterList the list of parameters whose elements are to be return ed
4402 * @return the elements associated with the parameters 5827 * @return the elements associated with the parameters
4403 */ 5828 */
4404 List<ParameterElement> getElements(FormalParameterList parameterList) { 5829 List<ParameterElement> getElements(FormalParameterList parameterList) {
4405 List<ParameterElement> elements = new List<ParameterElement>(); 5830 List<ParameterElement> elements = new List<ParameterElement>();
4406 for (FormalParameter parameter in parameterList.parameters) { 5831 for (FormalParameter parameter in parameterList.parameters) {
4407 ParameterElement element43 = parameter.identifier.element as ParameterElem ent; 5832 ParameterElement element50 = parameter.identifier.element as ParameterElem ent;
4408 if (element43 != null) { 5833 if (element50 != null) {
4409 elements.add(element43); 5834 elements.add(element50);
4410 } 5835 }
4411 } 5836 }
4412 return new List.from(elements); 5837 return new List.from(elements);
4413 } 5838 }
4414 /** 5839 /**
4415 * The number of type arguments in the given type name does not match the numb er of parameters in 5840 * The number of type arguments in the given type name does not match the numb er of parameters in
4416 * the corresponding class element. Return the error code that should be used to report this 5841 * the corresponding class element. Return the error code that should be used to report this
4417 * error. 5842 * error.
4418 * @param node the type name with the wrong number of type arguments 5843 * @param node the type name with the wrong number of type arguments
4419 * @return the error code that should be used to report that the wrong number of type arguments 5844 * @return the error code that should be used to report that the wrong number of type arguments
(...skipping 29 matching lines...) Expand all
4449 type = ((element as ClassElement)).type; 5874 type = ((element as ClassElement)).type;
4450 } 5875 }
4451 } 5876 }
4452 return type; 5877 return type;
4453 } 5878 }
4454 /** 5879 /**
4455 * Return the type represented by the given type name. 5880 * Return the type represented by the given type name.
4456 * @param typeName the type name representing the type to be returned 5881 * @param typeName the type name representing the type to be returned
4457 * @return the type represented by the type name 5882 * @return the type represented by the type name
4458 */ 5883 */
4459 Type2 getType4(TypeName typeName) { 5884 Type2 getType5(TypeName typeName) {
4460 Type2 type19 = typeName.type; 5885 Type2 type23 = typeName.type;
4461 if (type19 == null) { 5886 if (type23 == null) {
4462 return _dynamicType; 5887 return _dynamicType;
4463 } 5888 }
4464 return type19; 5889 return type23;
4465 } 5890 }
4466 /** 5891 /**
4467 * Return the type arguments associated with the given type. 5892 * Return the type arguments associated with the given type.
4468 * @param type the type whole type arguments are to be returned 5893 * @param type the type whole type arguments are to be returned
4469 * @return the type arguments associated with the given type 5894 * @return the type arguments associated with the given type
4470 */ 5895 */
4471 List<Type2> getTypeArguments(Type2 type) { 5896 List<Type2> getTypeArguments(Type2 type) {
4472 if (type is InterfaceType) { 5897 if (type is InterfaceType) {
4473 return ((type as InterfaceType)).typeArguments; 5898 return ((type as InterfaceType)).typeArguments;
4474 } else if (type is FunctionType) { 5899 } else if (type is FunctionType) {
(...skipping 17 matching lines...) Expand all
4492 /** 5917 /**
4493 * Resolve the types in the given with and implements clauses and associate th ose types with the 5918 * Resolve the types in the given with and implements clauses and associate th ose types with the
4494 * given class element. 5919 * given class element.
4495 * @param classElement the class element with which the mixin and interface ty pes are to be 5920 * @param classElement the class element with which the mixin and interface ty pes are to be
4496 * associated 5921 * associated
4497 * @param withClause the with clause to be resolved 5922 * @param withClause the with clause to be resolved
4498 * @param implementsClause the implements clause to be resolved 5923 * @param implementsClause the implements clause to be resolved
4499 */ 5924 */
4500 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC lause implementsClause) { 5925 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC lause implementsClause) {
4501 if (withClause != null) { 5926 if (withClause != null) {
4502 List<InterfaceType> mixinTypes2 = resolveTypes(withClause.mixinTypes, Comp ileTimeErrorCode.MIXIN_OF_NON_CLASS, CompileTimeErrorCode.MIXIN_OF_NON_CLASS, nu ll); 5927 List<InterfaceType> mixinTypes2 = resolveTypes(withClause.mixinTypes, Comp ileTimeErrorCode.MIXIN_OF_NON_CLASS);
4503 if (classElement != null) { 5928 if (classElement != null) {
4504 classElement.mixins = mixinTypes2; 5929 classElement.mixins = mixinTypes2;
4505 } 5930 }
4506 } 5931 }
4507 if (implementsClause != null) { 5932 if (implementsClause != null) {
4508 List<InterfaceType> interfaceTypes = resolveTypes(implementsClause.interfa ces, CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, CompileTimeErrorCode.IMPLEMENTS_ NON_CLASS, null); 5933 NodeList<TypeName> interfaces3 = implementsClause.interfaces;
5934 List<InterfaceType> interfaceTypes = resolveTypes(interfaces3, CompileTime ErrorCode.IMPLEMENTS_NON_CLASS);
5935 List<TypeName> typeNames = new List.from(interfaces3);
5936 String dynamicKeyword = sc.Keyword.DYNAMIC.syntax;
5937 List<bool> detectedRepeatOnIndex = new List<bool>.filled(typeNames.length, false);
5938 for (int i = 0; i < detectedRepeatOnIndex.length; i++) {
5939 detectedRepeatOnIndex[i] = false;
5940 }
5941 for (int i = 0; i < typeNames.length; i++) {
5942 TypeName typeName = typeNames[i];
5943 String name19 = typeName.name.name;
5944 if (name19 == dynamicKeyword) {
5945 reportError(CompileTimeErrorCode.IMPLEMENTS_DYNAMIC, typeName, []);
5946 } else {
5947 Element element51 = typeName.name.element;
5948 if (element51 != null && element51 == classElement) {
5949 reportError(CompileTimeErrorCode.IMPLEMENTS_SELF, typeName, [name19] );
5950 }
5951 }
5952 if (!detectedRepeatOnIndex[i]) {
5953 for (int j = i + 1; j < typeNames.length; j++) {
5954 Element element52 = typeName.name.element;
5955 TypeName typeName2 = typeNames[j];
5956 Identifier identifier2 = typeName2.name;
5957 String name2 = identifier2.name;
5958 Element element2 = identifier2.element;
5959 if (element52 != null && element52 == element2) {
5960 detectedRepeatOnIndex[j] = true;
5961 reportError(CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [ name2]);
5962 }
5963 }
5964 }
5965 }
4509 if (classElement != null) { 5966 if (classElement != null) {
4510 classElement.interfaces = interfaceTypes; 5967 classElement.interfaces = interfaceTypes;
4511 } 5968 }
4512 } 5969 }
4513 } 5970 }
4514 /** 5971 /**
4515 * Return the type specified by the given name. 5972 * Return the type specified by the given name.
4516 * @param typeName the type name specifying the type to be returned 5973 * @param typeName the type name specifying the type to be returned
4517 * @param undefinedError the error to produce if the type name is not defined
4518 * @param nonTypeError the error to produce if the type name is defined to be something other than 5974 * @param nonTypeError the error to produce if the type name is defined to be something other than
4519 * a type 5975 * a type
4520 * @param nonInterfaceType the error to produce if the type is not an interfac e type
4521 * @return the type specified by the type name 5976 * @return the type specified by the type name
4522 */ 5977 */
4523 InterfaceType resolveType(TypeName typeName, ErrorCode undefinedError, ErrorCo de nonTypeError, ErrorCode nonInterfaceType) { 5978 InterfaceType resolveType(TypeName typeName, ErrorCode nonTypeError) {
4524 Identifier name17 = typeName.name; 5979 Type2 type24 = typeName.type;
4525 Element element = nameScope.lookup(name17, definingLibrary); 5980 if (type24 is InterfaceType) {
4526 if (element == null) { 5981 return type24 as InterfaceType;
4527 reportError(undefinedError, name17, [name17.name]); 5982 }
4528 } else if (element is ClassElement) { 5983 Identifier name20 = typeName.name;
4529 Type2 classType = ((element as ClassElement)).type; 5984 if (name20.name != sc.Keyword.DYNAMIC.syntax) {
4530 typeName.type = classType; 5985 reportError(nonTypeError, name20, [name20.name]);
4531 if (classType is InterfaceType) {
4532 return classType as InterfaceType;
4533 }
4534 reportError(nonInterfaceType, name17, [name17.name]);
4535 } else if (element is MultiplyDefinedElement) {
4536 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting Elements;
4537 InterfaceType type = getType(elements);
4538 if (type != null) {
4539 typeName.type = type;
4540 }
4541 } else {
4542 reportError(nonTypeError, name17, [name17.name]);
4543 } 5986 }
4544 return null; 5987 return null;
4545 } 5988 }
4546 /** 5989 /**
4547 * Resolve the types in the given list of type names. 5990 * Resolve the types in the given list of type names.
4548 * @param typeNames the type names to be resolved 5991 * @param typeNames the type names to be resolved
4549 * @param undefinedError the error to produce if the type name is not defined
4550 * @param nonTypeError the error to produce if the type name is defined to be something other than 5992 * @param nonTypeError the error to produce if the type name is defined to be something other than
4551 * a type 5993 * a type
4552 * @param nonInterfaceType the error to produce if the type is not an interfac e type
4553 * @return an array containing all of the types that were resolved. 5994 * @return an array containing all of the types that were resolved.
4554 */ 5995 */
4555 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode undef inedError, ErrorCode nonTypeError, ErrorCode nonInterfaceType) { 5996 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode nonTy peError) {
4556 List<InterfaceType> types = new List<InterfaceType>(); 5997 List<InterfaceType> types = new List<InterfaceType>();
4557 for (TypeName typeName in typeNames) { 5998 for (TypeName typeName in typeNames) {
4558 InterfaceType type = resolveType(typeName, undefinedError, nonTypeError, n onInterfaceType); 5999 InterfaceType type = resolveType(typeName, nonTypeError);
4559 if (type != null) { 6000 if (type != null) {
4560 types.add(type); 6001 types.add(type);
4561 } 6002 }
4562 } 6003 }
4563 return new List.from(types); 6004 return new List.from(types);
4564 } 6005 }
4565 void setElement(Identifier typeName, Element element60) { 6006 void setElement(Identifier typeName, Element element69) {
4566 if (element60 != null) { 6007 if (element69 != null) {
4567 if (typeName is SimpleIdentifier) { 6008 if (typeName is SimpleIdentifier) {
4568 ((typeName as SimpleIdentifier)).element = element60; 6009 ((typeName as SimpleIdentifier)).element = element69;
4569 } else if (typeName is PrefixedIdentifier) { 6010 } else if (typeName is PrefixedIdentifier) {
4570 PrefixedIdentifier identifier = typeName as PrefixedIdentifier; 6011 PrefixedIdentifier identifier = typeName as PrefixedIdentifier;
4571 identifier.identifier.element = element60; 6012 identifier.identifier.element = element69;
4572 SimpleIdentifier prefix9 = identifier.prefix; 6013 SimpleIdentifier prefix8 = identifier.prefix;
4573 Element prefixElement = nameScope.lookup(prefix9, definingLibrary); 6014 Element prefixElement = nameScope.lookup(prefix8, definingLibrary);
4574 if (prefixElement != null) { 6015 if (prefixElement != null) {
4575 prefix9.element = prefixElement; 6016 prefix8.element = prefixElement;
4576 } 6017 }
4577 } 6018 }
4578 } 6019 }
4579 } 6020 }
4580 /** 6021 /**
4581 * Set the return type and parameter type information for the given function t ype based on the 6022 * Set the return type and parameter type information for the given function t ype based on the
4582 * given return type and parameter elements. 6023 * given return type and parameter elements.
4583 * @param functionType the function type to be filled in 6024 * @param functionType the function type to be filled in
4584 * @param returnType the return type of the function, or {@code null} if no ty pe was declared 6025 * @param returnType the return type of the function, or {@code null} if no ty pe was declared
4585 * @param parameters the elements representing the parameters to the function 6026 * @param parameters the elements representing the parameters to the function
4586 */ 6027 */
4587 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType13, List<ParameterElement> parameters) { 6028 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType15, List<ParameterElement> parameters) {
4588 List<Type2> normalParameterTypes = new List<Type2>(); 6029 List<Type2> normalParameterTypes = new List<Type2>();
4589 List<Type2> optionalParameterTypes = new List<Type2>(); 6030 List<Type2> optionalParameterTypes = new List<Type2>();
4590 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>(); 6031 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
4591 for (ParameterElement parameter in parameters) { 6032 for (ParameterElement parameter in parameters) {
4592 while (true) { 6033 while (true) {
4593 if (parameter.parameterKind == ParameterKind.REQUIRED) { 6034 if (parameter.parameterKind == ParameterKind.REQUIRED) {
4594 normalParameterTypes.add(parameter.type); 6035 normalParameterTypes.add(parameter.type);
4595 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { 6036 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) {
4596 optionalParameterTypes.add(parameter.type); 6037 optionalParameterTypes.add(parameter.type);
4597 } else if (parameter.parameterKind == ParameterKind.NAMED) { 6038 } else if (parameter.parameterKind == ParameterKind.NAMED) {
4598 namedParameterTypes[parameter.name] = parameter.type; 6039 namedParameterTypes[parameter.name] = parameter.type;
4599 } 6040 }
4600 break; 6041 break;
4601 } 6042 }
4602 } 6043 }
4603 if (!normalParameterTypes.isEmpty) { 6044 if (!normalParameterTypes.isEmpty) {
4604 functionType.normalParameterTypes = new List.from(normalParameterTypes); 6045 functionType.normalParameterTypes = new List.from(normalParameterTypes);
4605 } 6046 }
4606 if (!optionalParameterTypes.isEmpty) { 6047 if (!optionalParameterTypes.isEmpty) {
4607 functionType.optionalParameterTypes = new List.from(optionalParameterTypes ); 6048 functionType.optionalParameterTypes = new List.from(optionalParameterTypes );
4608 } 6049 }
4609 if (!namedParameterTypes.isEmpty) { 6050 if (!namedParameterTypes.isEmpty) {
4610 functionType.namedParameterTypes = namedParameterTypes; 6051 functionType.namedParameterTypes = namedParameterTypes;
4611 } 6052 }
4612 if (returnType13 == null) { 6053 if (returnType15 == null) {
4613 functionType.returnType = _dynamicType; 6054 functionType.returnType = _dynamicType;
4614 } else { 6055 } else {
4615 functionType.returnType = returnType13.type; 6056 functionType.returnType = returnType15.type;
4616 } 6057 }
4617 } 6058 }
4618 } 6059 }
4619 /** 6060 /**
4620 * Instances of the class {@code ClassScope} implement the scope defined by a cl ass. 6061 * Instances of the class {@code ClassScope} implement the scope defined by a cl ass.
4621 * @coverage dart.engine.resolver 6062 * @coverage dart.engine.resolver
4622 */ 6063 */
4623 class ClassScope extends EnclosedScope { 6064 class ClassScope extends EnclosedScope {
4624 /** 6065 /**
4625 * Initialize a newly created scope enclosed within another scope. 6066 * Initialize a newly created scope enclosed within another scope.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
4698 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) { 6139 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) {
4699 defineParameters(functionElement); 6140 defineParameters(functionElement);
4700 } 6141 }
4701 /** 6142 /**
4702 * Define the parameters for the given function in the scope that encloses thi s function. 6143 * Define the parameters for the given function in the scope that encloses thi s function.
4703 * @param functionElement the element representing the function represented by this scope 6144 * @param functionElement the element representing the function represented by this scope
4704 */ 6145 */
4705 void defineParameters(ExecutableElement functionElement) { 6146 void defineParameters(ExecutableElement functionElement) {
4706 Scope parameterScope = enclosingScope; 6147 Scope parameterScope = enclosingScope;
4707 if (functionElement.enclosingElement is ExecutableElement) { 6148 if (functionElement.enclosingElement is ExecutableElement) {
4708 String name18 = functionElement.name; 6149 String name21 = functionElement.name;
4709 if (name18 != null && !name18.isEmpty) { 6150 if (name21 != null && !name21.isEmpty) {
4710 parameterScope.define(functionElement); 6151 parameterScope.define(functionElement);
4711 } 6152 }
4712 } 6153 }
4713 for (ParameterElement parameter in functionElement.parameters) { 6154 for (ParameterElement parameter in functionElement.parameters) {
4714 if (!parameter.isInitializingFormal()) { 6155 if (!parameter.isInitializingFormal()) {
4715 parameterScope.define(parameter); 6156 parameterScope.define(parameter);
4716 } 6157 }
4717 } 6158 }
4718 } 6159 }
4719 } 6160 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4767 * The label element returned for scopes that can be the target of an unlabele d {@code break} or{@code continue}. 6208 * The label element returned for scopes that can be the target of an unlabele d {@code break} or{@code continue}.
4768 */ 6209 */
4769 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); 6210 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne w sc.StringToken(sc.TokenType.IDENTIFIER, "", 0));
4770 /** 6211 /**
4771 * Initialize a newly created scope to represent the potential target of an un labeled{@code break} or {@code continue}. 6212 * Initialize a newly created scope to represent the potential target of an un labeled{@code break} or {@code continue}.
4772 * @param outerScope the label scope enclosing the new label scope 6213 * @param outerScope the label scope enclosing the new label scope
4773 * @param onSwitchStatement {@code true} if this label is associated with a {@ code switch}statement 6214 * @param onSwitchStatement {@code true} if this label is associated with a {@ code switch}statement
4774 * @param onSwitchMember {@code true} if this label is associated with a {@cod e switch} member 6215 * @param onSwitchMember {@code true} if this label is associated with a {@cod e switch} member
4775 */ 6216 */
4776 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) { 6217 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) {
4777 _jtd_constructor_254_impl(outerScope, onSwitchStatement, onSwitchMember); 6218 _jtd_constructor_279_impl(outerScope, onSwitchStatement, onSwitchMember);
4778 } 6219 }
4779 _jtd_constructor_254_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) { 6220 _jtd_constructor_279_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) {
4780 _jtd_constructor_255_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); 6221 _jtd_constructor_280_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember));
4781 } 6222 }
4782 /** 6223 /**
4783 * Initialize a newly created scope to represent the given label. 6224 * Initialize a newly created scope to represent the given label.
4784 * @param outerScope the label scope enclosing the new label scope 6225 * @param outerScope the label scope enclosing the new label scope
4785 * @param label the label defined in this scope 6226 * @param label the label defined in this scope
4786 * @param element the element to which the label resolves 6227 * @param element the element to which the label resolves
4787 */ 6228 */
4788 LabelScope.con2(LabelScope outerScope2, String label4, LabelElement element21) { 6229 LabelScope.con2(LabelScope outerScope2, String label4, LabelElement element21) {
4789 _jtd_constructor_255_impl(outerScope2, label4, element21); 6230 _jtd_constructor_280_impl(outerScope2, label4, element21);
4790 } 6231 }
4791 _jtd_constructor_255_impl(LabelScope outerScope2, String label4, LabelElement element21) { 6232 _jtd_constructor_280_impl(LabelScope outerScope2, String label4, LabelElement element21) {
4792 this._outerScope = outerScope2; 6233 this._outerScope = outerScope2;
4793 this._label = label4; 6234 this._label = label4;
4794 this._element = element21; 6235 this._element = element21;
4795 } 6236 }
4796 /** 6237 /**
4797 * Return the label element corresponding to the given label, or {@code null} if the given label 6238 * Return the label element corresponding to the given label, or {@code null} if the given label
4798 * is not defined in this scope. 6239 * is not defined in this scope.
4799 * @param targetLabel the label being looked up 6240 * @param targetLabel the label being looked up
4800 * @return the label element corresponding to the given label 6241 * @return the label element corresponding to the given label
4801 */ 6242 */
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4847 createImportedNamespaces(definingLibrary); 6288 createImportedNamespaces(definingLibrary);
4848 } 6289 }
4849 void define(Element element) { 6290 void define(Element element) {
4850 if (!Scope.isPrivateName(element.name)) { 6291 if (!Scope.isPrivateName(element.name)) {
4851 super.define(element); 6292 super.define(element);
4852 } 6293 }
4853 } 6294 }
4854 LibraryElement get definingLibrary => _definingLibrary; 6295 LibraryElement get definingLibrary => _definingLibrary;
4855 AnalysisErrorListener get errorListener => _errorListener; 6296 AnalysisErrorListener get errorListener => _errorListener;
4856 Element lookup3(String name, LibraryElement referencingLibrary) { 6297 Element lookup3(String name, LibraryElement referencingLibrary) {
4857 if (Scope.isPrivateName(name)) {
4858 return null;
4859 }
4860 Element foundElement = localLookup(name, referencingLibrary); 6298 Element foundElement = localLookup(name, referencingLibrary);
4861 if (foundElement != null) { 6299 if (foundElement != null) {
4862 return foundElement; 6300 return foundElement;
4863 } 6301 }
4864 for (Namespace nameSpace in _importedNamespaces) { 6302 for (Namespace nameSpace in _importedNamespaces) {
4865 Element element = nameSpace.get(name); 6303 Element element = nameSpace.get(name);
4866 if (element != null) { 6304 if (element != null) {
4867 if (foundElement == null) { 6305 if (foundElement == null) {
4868 foundElement = element; 6306 foundElement = element;
4869 } else { 6307 } else {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
5040 if (namespace != null) { 6478 if (namespace != null) {
5041 addAll(definedNames2, namespace.definedNames); 6479 addAll(definedNames2, namespace.definedNames);
5042 } 6480 }
5043 } 6481 }
5044 /** 6482 /**
5045 * Add the given element to the given mapping table if it has a publicly visib le name. 6483 * Add the given element to the given mapping table if it has a publicly visib le name.
5046 * @param definedNames the mapping table to which the public name is to be add ed 6484 * @param definedNames the mapping table to which the public name is to be add ed
5047 * @param element the element to be added 6485 * @param element the element to be added
5048 */ 6486 */
5049 void addIfPublic(Map<String, Element> definedNames, Element element) { 6487 void addIfPublic(Map<String, Element> definedNames, Element element) {
5050 String name19 = element.name; 6488 String name22 = element.name;
5051 if (name19 != null && !Scope.isPrivateName(name19)) { 6489 if (name22 != null && !Scope.isPrivateName(name22)) {
5052 definedNames[name19] = element; 6490 definedNames[name22] = element;
5053 } 6491 }
5054 } 6492 }
5055 /** 6493 /**
5056 * Add to the given mapping table all of the public top-level names that are d efined in the given 6494 * Add to the given mapping table all of the public top-level names that are d efined in the given
5057 * compilation unit. 6495 * compilation unit.
5058 * @param definedNames the mapping table to which the public names are to be a dded 6496 * @param definedNames the mapping table to which the public names are to be a dded
5059 * @param compilationUnit the compilation unit defining the top-level names to be added to this 6497 * @param compilationUnit the compilation unit defining the top-level names to be added to this
5060 * namespace 6498 * namespace
5061 */ 6499 */
5062 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement compilationUnit) { 6500 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement compilationUnit) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
5123 try { 6561 try {
5124 Map<String, Element> definedNames = new Map<String, Element>(); 6562 Map<String, Element> definedNames = new Map<String, Element>();
5125 for (ExportElement element in library.exports) { 6563 for (ExportElement element in library.exports) {
5126 LibraryElement exportedLibrary3 = element.exportedLibrary; 6564 LibraryElement exportedLibrary3 = element.exportedLibrary;
5127 if (exportedLibrary3 != null && !visitedElements.contains(exportedLibrar y3)) { 6565 if (exportedLibrary3 != null && !visitedElements.contains(exportedLibrar y3)) {
5128 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry3, visitedElements); 6566 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry3, visitedElements);
5129 exportedNames = apply(exportedNames, element.combinators); 6567 exportedNames = apply(exportedNames, element.combinators);
5130 addAll(definedNames, exportedNames); 6568 addAll(definedNames, exportedNames);
5131 } 6569 }
5132 } 6570 }
5133 addAll2(definedNames, ((library.context as AnalysisContextImpl)).getPublic Namespace(library)); 6571 addAll2(definedNames, ((library.context as InternalAnalysisContext)).getPu blicNamespace(library));
5134 return definedNames; 6572 return definedNames;
5135 } finally { 6573 } finally {
5136 visitedElements.remove(library); 6574 visitedElements.remove(library);
5137 } 6575 }
5138 } 6576 }
5139 /** 6577 /**
5140 * Hide all of the given names by removing them from the given collection of d efined names. 6578 * Hide all of the given names by removing them from the given collection of d efined names.
5141 * @param definedNames the names that were defined before this operation 6579 * @param definedNames the names that were defined before this operation
5142 * @param hiddenNames the names to be hidden 6580 * @param hiddenNames the names to be hidden
5143 */ 6581 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
5201 } 6639 }
5202 /** 6640 /**
5203 * Add the given element to this scope. If there is already an element with th e given name defined 6641 * Add the given element to this scope. If there is already an element with th e given name defined
5204 * in this scope, then an error will be generated and the original element wil l continue to be 6642 * in this scope, then an error will be generated and the original element wil l continue to be
5205 * mapped to the name. If there is an element with the given name in an enclos ing scope, then a 6643 * mapped to the name. If there is an element with the given name in an enclos ing scope, then a
5206 * warning will be generated but the given element will hide the inherited ele ment. 6644 * warning will be generated but the given element will hide the inherited ele ment.
5207 * @param element the element to be added to this scope 6645 * @param element the element to be added to this scope
5208 */ 6646 */
5209 void define(Element element) { 6647 void define(Element element) {
5210 String name = getName(element); 6648 String name = getName(element);
5211 if (_definedNames.containsKey(name)) { 6649 if (name != null && !name.isEmpty) {
5212 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)); 6650 if (_definedNames.containsKey(name)) {
5213 } else { 6651 errorListener.onError(getErrorForDuplicate(_definedNames[name], element) );
5214 _definedNames[name] = element; 6652 } else {
6653 _definedNames[name] = element;
6654 }
5215 } 6655 }
5216 } 6656 }
5217 /** 6657 /**
5218 * Return the element with which the given identifier is associated, or {@code null} if the name 6658 * Return the element with which the given identifier is associated, or {@code null} if the name
5219 * is not defined within this scope. 6659 * is not defined within this scope.
5220 * @param identifier the identifier associated with the element to be returned 6660 * @param identifier the identifier associated with the element to be returned
5221 * @param referencingLibrary the library that contains the reference to the na me, used to 6661 * @param referencingLibrary the library that contains the reference to the na me, used to
5222 * implement library-level privacy 6662 * implement library-level privacy
5223 * @return the element with which the given identifier is associated 6663 * @return the element with which the given identifier is associated
5224 */ 6664 */
(...skipping 10 matching lines...) Expand all
5235 * @return the element representing the library in which this scope is enclose d 6675 * @return the element representing the library in which this scope is enclose d
5236 */ 6676 */
5237 LibraryElement get definingLibrary; 6677 LibraryElement get definingLibrary;
5238 /** 6678 /**
5239 * Return the error code to be used when reporting that a name being defined l ocally conflicts 6679 * Return the error code to be used when reporting that a name being defined l ocally conflicts
5240 * with another element of the same name in the local scope. 6680 * with another element of the same name in the local scope.
5241 * @param existing the first element to be declared with the conflicting name 6681 * @param existing the first element to be declared with the conflicting name
5242 * @param duplicate another element declared with the conflicting name 6682 * @param duplicate another element declared with the conflicting name
5243 * @return the error code used to report duplicate names within a scope 6683 * @return the error code used to report duplicate names within a scope
5244 */ 6684 */
5245 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) => new AnalysisError.con2(source, duplicate.nameOffset, duplicate.name.length, Compile TimeErrorCode.DUPLICATE_DEFINITION, [existing.name]); 6685 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
6686 Source source15 = duplicate.source;
6687 if (source15 == null) {
6688 source15 = source;
6689 }
6690 return new AnalysisError.con2(source15, duplicate.nameOffset, duplicate.name .length, CompileTimeErrorCode.DUPLICATE_DEFINITION, [existing.name]);
6691 }
5246 /** 6692 /**
5247 * Return the listener that is to be informed when an error is encountered. 6693 * Return the listener that is to be informed when an error is encountered.
5248 * @return the listener that is to be informed when an error is encountered 6694 * @return the listener that is to be informed when an error is encountered
5249 */ 6695 */
5250 AnalysisErrorListener get errorListener; 6696 AnalysisErrorListener get errorListener;
5251 /** 6697 /**
5252 * Return the source object representing the compilation unit with which error s related to this 6698 * Return the source object representing the compilation unit with which error s related to this
5253 * scope should be associated. 6699 * scope should be associated.
5254 * @return the source object with which errors should be associated 6700 * @return the source object with which errors should be associated
5255 */ 6701 */
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5326 return null; 6772 return null;
5327 } 6773 }
5328 Object visitMapLiteral(MapLiteral node) { 6774 Object visitMapLiteral(MapLiteral node) {
5329 super.visitMapLiteral(node); 6775 super.visitMapLiteral(node);
5330 bool isConst = node.modifier != null; 6776 bool isConst = node.modifier != null;
5331 Set<String> keys = new Set<String>(); 6777 Set<String> keys = new Set<String>();
5332 for (MapLiteralEntry entry in node.entries) { 6778 for (MapLiteralEntry entry in node.entries) {
5333 StringLiteral key4 = entry.key; 6779 StringLiteral key4 = entry.key;
5334 EvaluationResultImpl result = validate(key4, CompileTimeErrorCode.NON_CONS TANT_MAP_KEY); 6780 EvaluationResultImpl result = validate(key4, CompileTimeErrorCode.NON_CONS TANT_MAP_KEY);
5335 if (result is ValidResult && ((result as ValidResult)).value is String) { 6781 if (result is ValidResult && ((result as ValidResult)).value is String) {
5336 String value10 = ((result as ValidResult)).value as String; 6782 String value11 = ((result as ValidResult)).value as String;
5337 if (keys.contains(value10)) { 6783 if (keys.contains(value11)) {
5338 _errorReporter.reportError(StaticWarningCode.EQUAL_KEYS_IN_MAP, key4, []); 6784 _errorReporter.reportError(StaticWarningCode.EQUAL_KEYS_IN_MAP, key4, []);
5339 } else { 6785 } else {
5340 javaSetAdd(keys, value10); 6786 javaSetAdd(keys, value11);
5341 } 6787 }
5342 } 6788 }
5343 if (isConst) { 6789 if (isConst) {
5344 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE); 6790 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
5345 } 6791 }
5346 } 6792 }
5347 return null; 6793 return null;
5348 } 6794 }
5349 Object visitMethodDeclaration(MethodDeclaration node) { 6795 Object visitMethodDeclaration(MethodDeclaration node) {
5350 super.visitMethodDeclaration(node); 6796 super.visitMethodDeclaration(node);
5351 validateDefaultValues(node.parameters); 6797 validateDefaultValues(node.parameters);
5352 return null; 6798 return null;
5353 } 6799 }
5354 Object visitSwitchCase(SwitchCase node) { 6800 Object visitSwitchCase(SwitchCase node) {
5355 super.visitSwitchCase(node); 6801 super.visitSwitchCase(node);
5356 validate(node.expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION) ; 6802 validate(node.expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION) ;
5357 return null; 6803 return null;
5358 } 6804 }
5359 Object visitVariableDeclaration(VariableDeclaration node) { 6805 Object visitVariableDeclaration(VariableDeclaration node) {
5360 super.visitVariableDeclaration(node); 6806 super.visitVariableDeclaration(node);
5361 Expression initializer4 = node.initializer; 6807 Expression initializer7 = node.initializer;
5362 if (initializer4 != null && node.isConst()) { 6808 if (initializer7 != null && node.isConst()) {
5363 EvaluationResultImpl result = validate(initializer4, CompileTimeErrorCode. CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE); 6809 VariableElementImpl element58 = node.element as VariableElementImpl;
5364 VariableElementImpl element49 = node.element as VariableElementImpl; 6810 EvaluationResultImpl result = element58.evaluationResult;
5365 element49.evaluationResult = result; 6811 if (result == null) {
6812 result = validate(initializer7, CompileTimeErrorCode.CONST_INITIALIZED_W ITH_NON_CONSTANT_VALUE);
6813 element58.evaluationResult = result;
6814 } else if (result is ErrorResult) {
6815 reportErrors(result, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON STANT_VALUE);
6816 }
5366 } 6817 }
5367 return null; 6818 return null;
5368 } 6819 }
5369 /** 6820 /**
6821 * If the given result represents one or more errors, report those errors. Exc ept for special
6822 * cases, use the given error code rather than the one reported in the error.
6823 * @param result the result containing any errors that need to be reported
6824 * @param errorCode the error code to be used if the result represents an erro r
6825 */
6826 void reportErrors(EvaluationResultImpl result, ErrorCode errorCode) {
6827 if (result is ErrorResult) {
6828 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) {
6829 _errorReporter.reportError(errorCode, data.node, []);
6830 }
6831 }
6832 }
6833 /**
5370 * Validate that the given expression is a compile time constant. Return the v alue of the compile 6834 * Validate that the given expression is a compile time constant. Return the v alue of the compile
5371 * time constant, or {@code null} if the expression is not a compile time cons tant. 6835 * time constant, or {@code null} if the expression is not a compile time cons tant.
5372 * @param expression the expression to be validated 6836 * @param expression the expression to be validated
5373 * @param errorCode the error code to be used if the expression is not a compi le time constant 6837 * @param errorCode the error code to be used if the expression is not a compi le time constant
5374 * @return the value of the compile time constant 6838 * @return the value of the compile time constant
5375 */ 6839 */
5376 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode4) { 6840 EvaluationResultImpl validate(Expression expression, ErrorCode errorCode) {
5377 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); 6841 EvaluationResultImpl result = expression.accept(new ConstantVisitor());
5378 if (result is ErrorResult) { 6842 reportErrors(result, errorCode);
5379 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) {
5380 if (identical(data.errorCode, CompileTimeErrorCode.COMPILE_TIME_CONSTANT _RAISES_EXCEPTION_DIVIDE_BY_ZERO)) {
5381 _errorReporter.reportError(data.errorCode, data.node, []);
5382 } else {
5383 _errorReporter.reportError(errorCode4, data.node, []);
5384 }
5385 }
5386 }
5387 return result; 6843 return result;
5388 } 6844 }
5389 /** 6845 /**
5390 * Validate that the default value associated with each of the parameters in t he given list is a 6846 * Validate that the default value associated with each of the parameters in t he given list is a
5391 * compile time constant. 6847 * compile time constant.
5392 * @param parameters the list of parameters to be validated 6848 * @param parameters the list of parameters to be validated
5393 */ 6849 */
5394 void validateDefaultValues(FormalParameterList parameters15) { 6850 void validateDefaultValues(FormalParameterList parameters17) {
5395 if (parameters15 == null) { 6851 if (parameters17 == null) {
5396 return; 6852 return;
5397 } 6853 }
5398 for (FormalParameter parameter in parameters15.parameters) { 6854 for (FormalParameter parameter in parameters17.parameters) {
5399 if (parameter is DefaultFormalParameter) { 6855 if (parameter is DefaultFormalParameter) {
5400 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara meter; 6856 DefaultFormalParameter defaultParameter = parameter as DefaultFormalPara meter;
5401 Expression defaultValue2 = defaultParameter.defaultValue; 6857 Expression defaultValue3 = defaultParameter.defaultValue;
5402 if (defaultValue2 != null) { 6858 if (defaultValue3 != null) {
5403 EvaluationResultImpl result = validate(defaultValue2, CompileTimeError Code.NON_CONSTANT_DEFAULT_VALUE); 6859 EvaluationResultImpl result = validate(defaultValue3, CompileTimeError Code.NON_CONSTANT_DEFAULT_VALUE);
5404 if (defaultParameter.isConst()) { 6860 if (defaultParameter.isConst()) {
5405 VariableElementImpl element50 = parameter.element as VariableElement Impl; 6861 VariableElementImpl element59 = parameter.element as VariableElement Impl;
5406 element50.evaluationResult = result; 6862 element59.evaluationResult = result;
5407 } 6863 }
5408 } 6864 }
5409 } 6865 }
5410 } 6866 }
5411 } 6867 }
5412 } 6868 }
5413 /** 6869 /**
5414 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin g for additional 6870 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin g for additional
5415 * errors and warnings not covered by the parser and resolver. 6871 * errors and warnings not covered by the parser and resolver.
5416 * @coverage dart.engine.resolver 6872 * @coverage dart.engine.resolver
5417 */ 6873 */
5418 class ErrorVerifier extends RecursiveASTVisitor<Object> { 6874 class ErrorVerifier extends RecursiveASTVisitor<Object> {
5419 /** 6875 /**
5420 * The error reporter by which errors will be reported. 6876 * The error reporter by which errors will be reported.
5421 */ 6877 */
5422 ErrorReporter _errorReporter; 6878 ErrorReporter _errorReporter;
5423 /** 6879 /**
5424 * The current library that is being analyzed. 6880 * The current library that is being analyzed.
5425 */ 6881 */
5426 LibraryElement _currentLibrary; 6882 LibraryElement _currentLibrary;
5427 /** 6883 /**
5428 * The type representing the type 'dynamic'. 6884 * The type representing the type 'dynamic'.
5429 */ 6885 */
5430 Type2 _dynamicType; 6886 Type2 _dynamicType;
5431 /** 6887 /**
5432 * The object providing access to the types defined by the language. 6888 * The object providing access to the types defined by the language.
5433 */ 6889 */
5434 TypeProvider _typeProvider; 6890 TypeProvider _typeProvider;
5435 /** 6891 /**
5436 * This is set to <code>true</code> iff the visitor is currently visiting chil dren nodes of a{@link ConstructorDeclaration} and the constructor is 'const'. 6892 * This is set to {@code true} iff the visitor is currently visiting children nodes of a{@link ConstructorDeclaration} and the constructor is 'const'.
5437 * @see #visitConstructorDeclaration(ConstructorDeclaration) 6893 * @see #visitConstructorDeclaration(ConstructorDeclaration)
5438 */ 6894 */
5439 bool _isEnclosingConstructorConst = false; 6895 bool _isEnclosingConstructorConst = false;
5440 /** 6896 /**
5441 * This is set to <code>true</code> iff the visitor is currently visiting chil dren nodes of a{@link CatchClause}. 6897 * This is set to {@code true} iff the visitor is currently visiting children nodes of a{@link CatchClause}.
5442 * @see #visitCatchClause(CatchClause) 6898 * @see #visitCatchClause(CatchClause)
5443 */ 6899 */
5444 bool _isInCatchClause = false; 6900 bool _isInCatchClause = false;
5445 /** 6901 /**
5446 * The method or function that we are currently visiting, or <code>null</code> if we are not 6902 * This is set to {@code true} iff the visitor is currently visiting code in t he SDK.
5447 * inside a method or function.
5448 */ 6903 */
5449 ExecutableElement _currentFunction; 6904 bool _isInSystemLibrary = false;
6905 /**
6906 * The method or function that we are currently visiting, or {@code null} if w e are not inside a
6907 * method or function.
6908 */
6909 ExecutableElement _enclosingFunction;
6910 /**
6911 * This map is initialized when visiting the contents of a class declaration. If the visitor is
6912 * not in an enclosing class declaration, then the map is set to {@code null}.
6913 * <p>
6914 * When set the map maps the set of {@link FieldElement}s in the class to an{@ link INIT_STATE#NOT_INIT} or {@link INIT_STATE#INIT_IN_DECLARATION}. <code>check For*</code>
6915 * methods, specifically {@link #checkForAllFinalInitializedErrorCodes(Constru ctorDeclaration)},
6916 * can make a copy of the map to compute error code states. <code>checkFor*</c ode> methods should
6917 * only ever make a copy, or read from this map after it has been set in{@link #visitClassDeclaration(ClassDeclaration)}.
6918 * @see #visitClassDeclaration(ClassDeclaration)
6919 * @see #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration)
6920 */
6921 Map<FieldElement, INIT_STATE> _initialFieldElementsMap;
5450 /** 6922 /**
5451 * A list of types used by the {@link CompileTimeErrorCode#EXTENDS_DISALLOWED_ CLASS} and{@link CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS} error codes. 6923 * A list of types used by the {@link CompileTimeErrorCode#EXTENDS_DISALLOWED_ CLASS} and{@link CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS} error codes.
5452 */ 6924 */
5453 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 6925 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
5454 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider) { 6926 ErrorVerifier(ErrorReporter errorReporter, LibraryElement currentLibrary, Type Provider typeProvider) {
5455 this._errorReporter = errorReporter; 6927 this._errorReporter = errorReporter;
5456 this._currentLibrary = currentLibrary; 6928 this._currentLibrary = currentLibrary;
6929 this._isInSystemLibrary = currentLibrary.source.isInSystemLibrary();
5457 this._typeProvider = typeProvider; 6930 this._typeProvider = typeProvider;
5458 _isEnclosingConstructorConst = false; 6931 _isEnclosingConstructorConst = false;
5459 _isInCatchClause = false; 6932 _isInCatchClause = false;
5460 _dynamicType = typeProvider.dynamicType; 6933 _dynamicType = typeProvider.dynamicType;
5461 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [typeProvider.num Type, typeProvider.intType, typeProvider.doubleType, typeProvider.boolType, type Provider.stringType]; 6934 _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT = <InterfaceType> [typeProvider.num Type, typeProvider.intType, typeProvider.doubleType, typeProvider.boolType, type Provider.stringType];
5462 } 6935 }
5463 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) { 6936 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
5464 checkForArgumentDefinitionTestNonParameter(node); 6937 checkForArgumentDefinitionTestNonParameter(node);
5465 return super.visitArgumentDefinitionTest(node); 6938 return super.visitArgumentDefinitionTest(node);
5466 } 6939 }
5467 Object visitAssertStatement(AssertStatement node) { 6940 Object visitAssertStatement(AssertStatement node) {
5468 checkForNonBoolExpression(node); 6941 checkForNonBoolExpression(node);
5469 return super.visitAssertStatement(node); 6942 return super.visitAssertStatement(node);
5470 } 6943 }
5471 Object visitAssignmentExpression(AssignmentExpression node) { 6944 Object visitAssignmentExpression(AssignmentExpression node) {
5472 checkForInvalidAssignment(node); 6945 checkForInvalidAssignment(node);
5473 return super.visitAssignmentExpression(node); 6946 return super.visitAssignmentExpression(node);
5474 } 6947 }
5475 Object visitCatchClause(CatchClause node) { 6948 Object visitCatchClause(CatchClause node) {
5476 bool previousIsInCatchClause = _isInCatchClause; 6949 bool previousIsInCatchClause = _isInCatchClause;
5477 try { 6950 try {
5478 _isInCatchClause = true; 6951 _isInCatchClause = true;
5479 return super.visitCatchClause(node); 6952 return super.visitCatchClause(node);
5480 } finally { 6953 } finally {
5481 _isInCatchClause = previousIsInCatchClause; 6954 _isInCatchClause = previousIsInCatchClause;
5482 } 6955 }
5483 } 6956 }
5484 Object visitClassDeclaration(ClassDeclaration node) { 6957 Object visitClassDeclaration(ClassDeclaration node) {
5485 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_NAME); 6958 try {
5486 return super.visitClassDeclaration(node); 6959 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_I DENTIFIER_AS_TYPE_NAME);
6960 ClassElement classElement = node.element;
6961 if (classElement != null) {
6962 List<FieldElement> fieldElements = classElement.fields;
6963 _initialFieldElementsMap = new Map<FieldElement, INIT_STATE>();
6964 for (FieldElement fieldElement in fieldElements) {
6965 if (!fieldElement.isSynthetic()) {
6966 _initialFieldElementsMap[fieldElement] = fieldElement.initializer == null ? INIT_STATE.NOT_INIT : INIT_STATE.INIT_IN_DECLARATION;
6967 }
6968 }
6969 }
6970 checkForFinalNotInitialized(node);
6971 return super.visitClassDeclaration(node);
6972 } finally {
6973 _initialFieldElementsMap = null;
6974 }
5487 } 6975 }
5488 Object visitClassTypeAlias(ClassTypeAlias node) { 6976 Object visitClassTypeAlias(ClassTypeAlias node) {
5489 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 6977 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
5490 return super.visitClassTypeAlias(node); 6978 return super.visitClassTypeAlias(node);
5491 } 6979 }
5492 Object visitConditionalExpression(ConditionalExpression node) { 6980 Object visitConditionalExpression(ConditionalExpression node) {
5493 checkForNonBoolCondition(node.condition); 6981 checkForNonBoolCondition(node.condition);
5494 return super.visitConditionalExpression(node); 6982 return super.visitConditionalExpression(node);
5495 } 6983 }
5496 Object visitConstructorDeclaration(ConstructorDeclaration node) { 6984 Object visitConstructorDeclaration(ConstructorDeclaration node) {
5497 ExecutableElement previousFunction = _currentFunction; 6985 ExecutableElement outerFunction = _enclosingFunction;
5498 try { 6986 try {
5499 _currentFunction = node.element; 6987 _enclosingFunction = node.element;
5500 _isEnclosingConstructorConst = node.constKeyword != null; 6988 _isEnclosingConstructorConst = node.constKeyword != null;
5501 checkForConstConstructorWithNonFinalField(node); 6989 checkForConstConstructorWithNonFinalField(node);
5502 checkForConflictingConstructorNameAndMember(node); 6990 checkForConflictingConstructorNameAndMember(node);
6991 checkForAllFinalInitializedErrorCodes(node);
5503 return super.visitConstructorDeclaration(node); 6992 return super.visitConstructorDeclaration(node);
5504 } finally { 6993 } finally {
5505 _isEnclosingConstructorConst = false; 6994 _isEnclosingConstructorConst = false;
5506 _currentFunction = previousFunction; 6995 _enclosingFunction = outerFunction;
5507 } 6996 }
5508 } 6997 }
5509 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
5510 checkForFieldInitializedInInitializerAndDeclaration(node);
5511 checkForFieldInitializedInParameterAndInitializer(node);
5512 return super.visitConstructorFieldInitializer(node);
5513 }
5514 Object visitDoStatement(DoStatement node) { 6998 Object visitDoStatement(DoStatement node) {
5515 checkForNonBoolCondition(node.condition); 6999 checkForNonBoolCondition(node.condition);
5516 return super.visitDoStatement(node); 7000 return super.visitDoStatement(node);
5517 } 7001 }
5518 Object visitExtendsClause(ExtendsClause node) { 7002 Object visitExtendsClause(ExtendsClause node) {
5519 checkForExtendsDisallowedClass(node); 7003 checkForExtendsDisallowedClass(node);
5520 return super.visitExtendsClause(node); 7004 return super.visitExtendsClause(node);
5521 } 7005 }
5522 Object visitFieldFormalParameter(FieldFormalParameter node) { 7006 Object visitFieldFormalParameter(FieldFormalParameter node) {
5523 checkForConstFormalParameter(node); 7007 checkForConstFormalParameter(node);
5524 checkForFieldInitializerOutsideConstructor(node); 7008 checkForFieldInitializerOutsideConstructor(node);
5525 return super.visitFieldFormalParameter(node); 7009 return super.visitFieldFormalParameter(node);
5526 } 7010 }
5527 Object visitFunctionDeclaration(FunctionDeclaration node) { 7011 Object visitFunctionDeclaration(FunctionDeclaration node) {
5528 ExecutableElement previousFunction = _currentFunction; 7012 ExecutableElement outerFunction = _enclosingFunction;
5529 try { 7013 try {
5530 _currentFunction = node.element; 7014 _enclosingFunction = node.element;
5531 return super.visitFunctionDeclaration(node); 7015 return super.visitFunctionDeclaration(node);
5532 } finally { 7016 } finally {
5533 _currentFunction = previousFunction; 7017 _enclosingFunction = outerFunction;
5534 } 7018 }
5535 } 7019 }
5536 Object visitFunctionExpression(FunctionExpression node) { 7020 Object visitFunctionExpression(FunctionExpression node) {
5537 ExecutableElement previousFunction = _currentFunction; 7021 ExecutableElement outerFunction = _enclosingFunction;
5538 try { 7022 try {
5539 _currentFunction = node.element; 7023 _enclosingFunction = node.element;
5540 return super.visitFunctionExpression(node); 7024 return super.visitFunctionExpression(node);
5541 } finally { 7025 } finally {
5542 _currentFunction = previousFunction; 7026 _enclosingFunction = outerFunction;
5543 } 7027 }
5544 } 7028 }
5545 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 7029 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
5546 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME); 7030 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPEDEF_NAME);
5547 checkForDefaultValueInFunctionTypeAlias(node); 7031 checkForDefaultValueInFunctionTypeAlias(node);
5548 return super.visitFunctionTypeAlias(node); 7032 return super.visitFunctionTypeAlias(node);
5549 } 7033 }
5550 Object visitIfStatement(IfStatement node) { 7034 Object visitIfStatement(IfStatement node) {
5551 checkForNonBoolCondition(node.condition); 7035 checkForNonBoolCondition(node.condition);
5552 return super.visitIfStatement(node); 7036 return super.visitIfStatement(node);
5553 } 7037 }
5554 Object visitImplementsClause(ImplementsClause node) { 7038 Object visitImplementsClause(ImplementsClause node) {
5555 checkForImplementsDisallowedClass(node); 7039 checkForImplementsDisallowedClass(node);
5556 return super.visitImplementsClause(node); 7040 return super.visitImplementsClause(node);
5557 } 7041 }
5558 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 7042 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
5559 ConstructorName constructorName4 = node.constructorName; 7043 ConstructorName constructorName4 = node.constructorName;
5560 TypeName typeName = constructorName4.type; 7044 TypeName typeName = constructorName4.type;
5561 Type2 type20 = typeName.type; 7045 Type2 type25 = typeName.type;
5562 if (type20 is InterfaceType) { 7046 if (type25 is InterfaceType) {
5563 InterfaceType interfaceType = type20 as InterfaceType; 7047 InterfaceType interfaceType = type25 as InterfaceType;
5564 checkForConstWithNonConst(node); 7048 checkForConstWithNonConst(node);
5565 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType); 7049 checkForConstOrNewWithAbstractClass(node, typeName, interfaceType);
5566 checkForTypeArgumentNotMatchingBounds(node, constructorName4.element, type Name); 7050 checkForTypeArgumentNotMatchingBounds(node, constructorName4.element, type Name);
5567 } 7051 }
5568 return super.visitInstanceCreationExpression(node); 7052 return super.visitInstanceCreationExpression(node);
5569 } 7053 }
5570 Object visitMethodDeclaration(MethodDeclaration node) { 7054 Object visitMethodDeclaration(MethodDeclaration node) {
5571 ExecutableElement previousFunction = _currentFunction; 7055 ExecutableElement previousFunction = _enclosingFunction;
5572 try { 7056 try {
5573 _currentFunction = node.element; 7057 _enclosingFunction = node.element;
5574 return super.visitMethodDeclaration(node); 7058 return super.visitMethodDeclaration(node);
5575 } finally { 7059 } finally {
5576 _currentFunction = previousFunction; 7060 _enclosingFunction = previousFunction;
5577 } 7061 }
5578 } 7062 }
7063 Object visitNativeFunctionBody(NativeFunctionBody node) {
7064 checkForNativeFunctionBodyInNonSDKCode(node);
7065 return super.visitNativeFunctionBody(node);
7066 }
5579 Object visitRethrowExpression(RethrowExpression node) { 7067 Object visitRethrowExpression(RethrowExpression node) {
5580 checkForRethrowOutsideCatch(node); 7068 checkForRethrowOutsideCatch(node);
5581 return super.visitRethrowExpression(node); 7069 return super.visitRethrowExpression(node);
5582 } 7070 }
5583 Object visitReturnStatement(ReturnStatement node) { 7071 Object visitReturnStatement(ReturnStatement node) {
5584 checkForReturnOfInvalidType(node); 7072 checkForReturnOfInvalidType(node);
5585 return super.visitReturnStatement(node); 7073 return super.visitReturnStatement(node);
5586 } 7074 }
5587 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 7075 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
5588 checkForConstFormalParameter(node); 7076 checkForConstFormalParameter(node);
5589 return super.visitSimpleFormalParameter(node); 7077 return super.visitSimpleFormalParameter(node);
5590 } 7078 }
5591 Object visitSwitchStatement(SwitchStatement node) { 7079 Object visitSwitchStatement(SwitchStatement node) {
5592 checkForCaseExpressionTypeImplementsEquals(node); 7080 checkForCaseExpressionTypeImplementsEquals(node);
5593 return super.visitSwitchStatement(node); 7081 return super.visitSwitchStatement(node);
5594 } 7082 }
5595 Object visitThrowExpression(ThrowExpression node) { 7083 Object visitThrowExpression(ThrowExpression node) {
5596 checkForConstEvalThrowsException(node); 7084 checkForConstEvalThrowsException(node);
5597 return super.visitThrowExpression(node); 7085 return super.visitThrowExpression(node);
5598 } 7086 }
7087 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
7088 checkForFinalNotInitialized2(node.variables);
7089 return super.visitTopLevelVariableDeclaration(node);
7090 }
5599 Object visitTypeParameter(TypeParameter node) { 7091 Object visitTypeParameter(TypeParameter node) {
5600 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_VARIABLE_NAME); 7092 checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_IDE NTIFIER_AS_TYPE_VARIABLE_NAME);
5601 return super.visitTypeParameter(node); 7093 return super.visitTypeParameter(node);
5602 } 7094 }
5603 Object visitVariableDeclarationList(VariableDeclarationList node) { 7095 Object visitVariableDeclarationList(VariableDeclarationList node) {
5604 checkForBuiltInIdentifierAsName2(node); 7096 checkForBuiltInIdentifierAsName2(node);
5605 return super.visitVariableDeclarationList(node); 7097 return super.visitVariableDeclarationList(node);
5606 } 7098 }
7099 Object visitVariableDeclarationStatement(VariableDeclarationStatement node) {
7100 checkForFinalNotInitialized2(node.variables);
7101 return super.visitVariableDeclarationStatement(node);
7102 }
5607 Object visitWhileStatement(WhileStatement node) { 7103 Object visitWhileStatement(WhileStatement node) {
5608 checkForNonBoolCondition(node.condition); 7104 checkForNonBoolCondition(node.condition);
5609 return super.visitWhileStatement(node); 7105 return super.visitWhileStatement(node);
5610 } 7106 }
5611 /** 7107 /**
7108 * This verifies that the passed constructor declaration does not violate any of the error codes
7109 * relating to the initialization of fields in the enclosing class.
7110 * @param node the {@link ConstructorDeclaration} to evaluate
7111 * @return return {@code true} if and only if an error code is generated on th e passed node
7112 * @see #initialFieldElementsMap
7113 * @see CompileTimeErrorCode#FINAL_INITIALIZED_IN_DECLARATION_AND_CONSTRUCTOR
7114 * @see CompileTimeErrorCode#FINAL_INITIALIZED_MULTIPLE_TIMES
7115 */
7116 bool checkForAllFinalInitializedErrorCodes(ConstructorDeclaration node) {
7117 if (node.factoryKeyword != null || node.redirectedConstructor != null || nod e.externalKeyword != null) {
7118 return false;
7119 }
7120 bool foundError = false;
7121 Map<FieldElement, INIT_STATE> fieldElementsMap = new Map<FieldElement, INIT_ STATE>.from(_initialFieldElementsMap);
7122 NodeList<FormalParameter> formalParameters = node.parameters.parameters;
7123 for (FormalParameter formalParameter in formalParameters) {
7124 FormalParameter parameter = formalParameter;
7125 if (parameter is DefaultFormalParameter) {
7126 parameter = ((parameter as DefaultFormalParameter)).parameter;
7127 }
7128 if (parameter is FieldFormalParameter) {
7129 FieldElement fieldElement = ((parameter.element as FieldFormalParameterE lementImpl)).field;
7130 INIT_STATE state = fieldElementsMap[fieldElement];
7131 if (identical(state, INIT_STATE.NOT_INIT)) {
7132 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_FIELD_FORMAL;
7133 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) {
7134 if (fieldElement.isFinal() || fieldElement.isConst()) {
7135 _errorReporter.reportError(CompileTimeErrorCode.FINAL_INITIALIZED_IN _DECLARATION_AND_CONSTRUCTOR, formalParameter.identifier, [fieldElement.name]);
7136 foundError = true;
7137 }
7138 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) {
7139 if (fieldElement.isFinal() || fieldElement.isConst()) {
7140 _errorReporter.reportError(CompileTimeErrorCode.FINAL_INITIALIZED_MU LTIPLE_TIMES, formalParameter.identifier, [fieldElement.name]);
7141 foundError = true;
7142 }
7143 }
7144 }
7145 }
7146 NodeList<ConstructorInitializer> initializers2 = node.initializers;
7147 for (ConstructorInitializer constructorInitializer in initializers2) {
7148 if (constructorInitializer is ConstructorFieldInitializer) {
7149 ConstructorFieldInitializer constructorFieldInitializer = constructorIni tializer as ConstructorFieldInitializer;
7150 SimpleIdentifier fieldName3 = constructorFieldInitializer.fieldName;
7151 Element element60 = fieldName3.element;
7152 if (element60 is FieldElement) {
7153 FieldElement fieldElement = element60 as FieldElement;
7154 INIT_STATE state = fieldElementsMap[fieldElement];
7155 if (identical(state, INIT_STATE.NOT_INIT)) {
7156 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS;
7157 } else if (identical(state, INIT_STATE.INIT_IN_DECLARATION)) {
7158 if (fieldElement.isFinal() || fieldElement.isConst()) {
7159 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_ IN_INITIALIZER_AND_DECLARATION, fieldName3, []);
7160 foundError = true;
7161 }
7162 } else if (identical(state, INIT_STATE.INIT_IN_FIELD_FORMAL)) {
7163 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_IN _PARAMETER_AND_INITIALIZER, fieldName3, []);
7164 foundError = true;
7165 } else if (identical(state, INIT_STATE.INIT_IN_INITIALIZERS)) {
7166 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_BY _MULTIPLE_INITIALIZERS, fieldName3, [fieldElement.name]);
7167 foundError = true;
7168 }
7169 }
7170 }
7171 }
7172 return foundError;
7173 }
7174 /**
5612 * This verifies that the passed argument definition test identifier is a para meter. 7175 * This verifies that the passed argument definition test identifier is a para meter.
5613 * @param node the {@link ArgumentDefinitionTest} to evaluate 7176 * @param node the {@link ArgumentDefinitionTest} to evaluate
5614 * @return return <code>true</code> if and only if an error code is generated on the passed node 7177 * @return return {@code true} if and only if an error code is generated on th e passed node
5615 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER 7178 * @see CompileTimeErrorCode#ARGUMENT_DEFINITION_TEST_NON_PARAMETER
5616 */ 7179 */
5617 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) { 7180 bool checkForArgumentDefinitionTestNonParameter(ArgumentDefinitionTest node) {
5618 SimpleIdentifier identifier14 = node.identifier; 7181 SimpleIdentifier identifier15 = node.identifier;
5619 Element element51 = identifier14.element; 7182 Element element61 = identifier15.element;
5620 if (element51 != null && element51 is! ParameterElement) { 7183 if (element61 != null && element61 is! ParameterElement) {
5621 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N ON_PARAMETER, identifier14, [identifier14.name]); 7184 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N ON_PARAMETER, identifier15, [identifier15.name]);
5622 return true; 7185 return true;
5623 } 7186 }
5624 return false; 7187 return false;
5625 } 7188 }
5626 /** 7189 /**
5627 * This verifies that the passed identifier is not a keyword, and generates th e passed error code 7190 * This verifies that the passed identifier is not a keyword, and generates th e passed error code
5628 * on the identifier if it is a keyword. 7191 * on the identifier if it is a keyword.
5629 * @param identifier the identifier to check to ensure that it is not a keywor d 7192 * @param identifier the identifier to check to ensure that it is not a keywor d
5630 * @param errorCode if the passed identifier is a keyword then this error code is created on the 7193 * @param errorCode if the passed identifier is a keyword then this error code is created on the
5631 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_ IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_ NAME} 7194 * identifier, the error code will be one of{@link CompileTimeErrorCode#BUILT_ IN_IDENTIFIER_AS_TYPE_NAME},{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_T YPE_VARIABLE_NAME} or{@link CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_ NAME}
5632 * @return return <code>true</code> if and only if an error code is generated on the passed node 7195 * @return return {@code true} if and only if an error code is generated on th e passed node
5633 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME 7196 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_NAME
5634 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME 7197 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME
5635 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME 7198 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME
5636 */ 7199 */
5637 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er rorCode) { 7200 bool checkForBuiltInIdentifierAsName(SimpleIdentifier identifier, ErrorCode er rorCode) {
5638 sc.Token token13 = identifier.token; 7201 sc.Token token18 = identifier.token;
5639 if (identical(token13.type, sc.TokenType.KEYWORD)) { 7202 if (identical(token18.type, sc.TokenType.KEYWORD)) {
5640 _errorReporter.reportError(errorCode, identifier, [identifier.name]); 7203 _errorReporter.reportError(errorCode, identifier, [identifier.name]);
5641 return true; 7204 return true;
5642 } 7205 }
5643 return false; 7206 return false;
5644 } 7207 }
5645 /** 7208 /**
5646 * This verifies that the passed variable declaration list does not have a bui lt-in identifier. 7209 * This verifies that the passed variable declaration list does not have a bui lt-in identifier.
5647 * @param node the variable declaration list to check 7210 * @param node the variable declaration list to check
5648 * @return return <code>true</code> if and only if an error code is generated on the passed node 7211 * @return return {@code true} if and only if an error code is generated on th e passed node
5649 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE 7212 * @see CompileTimeErrorCode#BUILT_IN_IDENTIFIER_AS_TYPE
5650 */ 7213 */
5651 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) { 7214 bool checkForBuiltInIdentifierAsName2(VariableDeclarationList node) {
5652 TypeName typeName = node.type; 7215 TypeName typeName = node.type;
5653 if (typeName != null) { 7216 if (typeName != null) {
5654 Identifier identifier = typeName.name; 7217 Identifier identifier = typeName.name;
5655 if (identifier is SimpleIdentifier) { 7218 if (identifier is SimpleIdentifier) {
5656 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier; 7219 SimpleIdentifier simpleIdentifier = identifier as SimpleIdentifier;
5657 sc.Token token14 = simpleIdentifier.token; 7220 sc.Token token19 = simpleIdentifier.token;
5658 if (identical(token14.type, sc.TokenType.KEYWORD)) { 7221 if (identical(token19.type, sc.TokenType.KEYWORD)) {
5659 if (((token14 as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) { 7222 if (((token19 as sc.KeywordToken)).keyword != sc.Keyword.DYNAMIC) {
5660 _errorReporter.reportError(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_ AS_TYPE, identifier, [identifier.name]); 7223 _errorReporter.reportError(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_ AS_TYPE, identifier, [identifier.name]);
5661 return true; 7224 return true;
5662 } 7225 }
5663 } 7226 }
5664 } 7227 }
5665 } 7228 }
5666 return false; 7229 return false;
5667 } 7230 }
5668 /** 7231 /**
5669 * This verifies that the passed switch statement does not have a case express ion with the 7232 * This verifies that the passed switch statement does not have a case express ion with the
5670 * operator '==' overridden. 7233 * operator '==' overridden.
5671 * @param node the switch statement to evaluate 7234 * @param node the switch statement to evaluate
5672 * @return return <code>true</code> if and only if an error code is generated on the passed node 7235 * @return return {@code true} if and only if an error code is generated on th e passed node
5673 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS 7236 * @see CompileTimeErrorCode#CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS
5674 */ 7237 */
5675 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) { 7238 bool checkForCaseExpressionTypeImplementsEquals(SwitchStatement node) {
5676 Expression expression16 = node.expression; 7239 Expression expression16 = node.expression;
5677 Type2 type = expression16.staticType; 7240 Type2 type = expression16.staticType;
5678 if (type != null && type != _typeProvider.intType && type != _typeProvider.s tringType) { 7241 if (type != null && type != _typeProvider.intType && type != _typeProvider.s tringType) {
5679 Element element52 = type.element; 7242 Element element62 = type.element;
5680 if (element52 is ClassElement) { 7243 if (element62 is ClassElement) {
5681 ClassElement classElement = element52 as ClassElement; 7244 ClassElement classElement = element62 as ClassElement;
5682 MethodElement method = classElement.lookUpMethod("==", _currentLibrary); 7245 MethodElement method = classElement.lookUpMethod("==", _currentLibrary);
5683 if (method != null && method.enclosingElement.type != _typeProvider.obje ctType) { 7246 if (method != null && method.enclosingElement.type != _typeProvider.obje ctType) {
5684 _errorReporter.reportError(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_I MPLEMENTS_EQUALS, expression16, [element52.name]); 7247 _errorReporter.reportError(CompileTimeErrorCode.CASE_EXPRESSION_TYPE_I MPLEMENTS_EQUALS, expression16, [element62.name]);
5685 return true; 7248 return true;
5686 } 7249 }
5687 } 7250 }
5688 } 7251 }
5689 return false; 7252 return false;
5690 } 7253 }
5691 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) { 7254 bool checkForConflictingConstructorNameAndMember(ConstructorDeclaration node) {
5692 ConstructorElement constructorElement = node.element; 7255 ConstructorElement constructorElement = node.element;
5693 SimpleIdentifier constructorName = node.name; 7256 SimpleIdentifier constructorName = node.name;
5694 if (constructorName != null && constructorElement != null && !constructorNam e.isSynthetic()) { 7257 if (constructorName != null && constructorElement != null && !constructorNam e.isSynthetic()) {
5695 String name21 = constructorName.name; 7258 String name24 = constructorName.name;
5696 ClassElement classElement = constructorElement.enclosingElement; 7259 ClassElement classElement = constructorElement.enclosingElement;
5697 List<FieldElement> fields3 = classElement.fields; 7260 List<FieldElement> fields3 = classElement.fields;
5698 for (FieldElement field in fields3) { 7261 for (FieldElement field in fields3) {
5699 if (field.name == name21) { 7262 if (field.name == name24) {
5700 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO R_NAME_AND_FIELD, node, [name21]); 7263 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO R_NAME_AND_FIELD, node, [name24]);
5701 return true; 7264 return true;
5702 } 7265 }
5703 } 7266 }
5704 List<MethodElement> methods3 = classElement.methods; 7267 List<MethodElement> methods3 = classElement.methods;
5705 for (MethodElement method in methods3) { 7268 for (MethodElement method in methods3) {
5706 if (method.name == name21) { 7269 if (method.name == name24) {
5707 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO R_NAME_AND_METHOD, node, [name21]); 7270 _errorReporter.reportError(CompileTimeErrorCode.CONFLICTING_CONSTRUCTO R_NAME_AND_METHOD, node, [name24]);
5708 return true; 7271 return true;
5709 } 7272 }
5710 } 7273 }
5711 } 7274 }
5712 return false; 7275 return false;
5713 } 7276 }
5714 /** 7277 /**
5715 * This verifies that the passed constructor declaration is not 'const' if it has a non-final 7278 * This verifies that the passed constructor declaration is not 'const' if it has a non-final
5716 * instance variable. 7279 * instance variable.
5717 * @param node the instance creation expression to evaluate 7280 * @param node the instance creation expression to evaluate
5718 * @return return <code>true</code> if and only if an error code is generated on the passed node 7281 * @return return {@code true} if and only if an error code is generated on th e passed node
5719 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD 7282 * @see CompileTimeErrorCode#CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD
5720 */ 7283 */
5721 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) { 7284 bool checkForConstConstructorWithNonFinalField(ConstructorDeclaration node) {
5722 if (!_isEnclosingConstructorConst) { 7285 if (!_isEnclosingConstructorConst) {
5723 return false; 7286 return false;
5724 } 7287 }
5725 ConstructorElement constructorElement = node.element; 7288 ConstructorElement constructorElement = node.element;
5726 if (constructorElement != null) { 7289 if (constructorElement != null) {
5727 ClassElement classElement = constructorElement.enclosingElement; 7290 ClassElement classElement = constructorElement.enclosingElement;
5728 List<FieldElement> elements = classElement.fields; 7291 List<FieldElement> elements = classElement.fields;
5729 for (FieldElement field in elements) { 7292 for (FieldElement field in elements) {
5730 if (!field.isFinal() && !field.isConst() && !field.isSynthetic()) { 7293 if (!field.isFinal() && !field.isConst() && !field.isStatic() && !field. isSynthetic()) {
5731 _errorReporter.reportError(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH _NON_FINAL_FIELD, node, []); 7294 _errorReporter.reportError(CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH _NON_FINAL_FIELD, node, []);
5732 return true; 7295 return true;
5733 } 7296 }
5734 } 7297 }
5735 } 7298 }
5736 return false; 7299 return false;
5737 } 7300 }
5738 /** 7301 /**
5739 * This verifies that the passed throw expression is not enclosed in a 'const' constructor 7302 * This verifies that the passed throw expression is not enclosed in a 'const' constructor
5740 * declaration. 7303 * declaration.
5741 * @param node the throw expression expression to evaluate 7304 * @param node the throw expression expression to evaluate
5742 * @return return <code>true</code> if and only if an error code is generated on the passed node 7305 * @return return {@code true} if and only if an error code is generated on th e passed node
5743 * @see CompileTimeErrorCode#CONST_EVAL_THROWS_EXCEPTION 7306 * @see CompileTimeErrorCode#CONST_EVAL_THROWS_EXCEPTION
5744 */ 7307 */
5745 bool checkForConstEvalThrowsException(ThrowExpression node) { 7308 bool checkForConstEvalThrowsException(ThrowExpression node) {
5746 if (_isEnclosingConstructorConst) { 7309 if (_isEnclosingConstructorConst) {
5747 _errorReporter.reportError(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTIO N, node, []); 7310 _errorReporter.reportError(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTIO N, node, []);
5748 return true; 7311 return true;
5749 } 7312 }
5750 return false; 7313 return false;
5751 } 7314 }
5752 /** 7315 /**
5753 * This verifies that the passed normal formal parameter is not 'const'. 7316 * This verifies that the passed normal formal parameter is not 'const'.
5754 * @param node the normal formal parameter to evaluate 7317 * @param node the normal formal parameter to evaluate
5755 * @return return <code>true</code> if and only if an error code is generated on the passed node 7318 * @return return {@code true} if and only if an error code is generated on th e passed node
5756 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER 7319 * @see CompileTimeErrorCode#CONST_FORMAL_PARAMETER
5757 */ 7320 */
5758 bool checkForConstFormalParameter(NormalFormalParameter node) { 7321 bool checkForConstFormalParameter(NormalFormalParameter node) {
5759 if (node.isConst()) { 7322 if (node.isConst()) {
5760 _errorReporter.reportError(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, no de, []); 7323 _errorReporter.reportError(CompileTimeErrorCode.CONST_FORMAL_PARAMETER, no de, []);
5761 return true; 7324 return true;
5762 } 7325 }
5763 return false; 7326 return false;
5764 } 7327 }
5765 /** 7328 /**
5766 * This verifies that the passed instance creation expression is not being inv oked on an abstract 7329 * This verifies that the passed instance creation expression is not being inv oked on an abstract
5767 * class. 7330 * class.
5768 * @param node the instance creation expression to evaluate 7331 * @param node the instance creation expression to evaluate
5769 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th e{@link InstanceCreationExpression}, this is the AST node that the error is atta ched to 7332 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th e{@link InstanceCreationExpression}, this is the AST node that the error is atta ched to
5770 * @param type the type being constructed with this {@link InstanceCreationExp ression} 7333 * @param type the type being constructed with this {@link InstanceCreationExp ression}
5771 * @return return <code>true</code> if and only if an error code is generated on the passed node 7334 * @return return {@code true} if and only if an error code is generated on th e passed node
5772 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS 7335 * @see StaticWarningCode#CONST_WITH_ABSTRACT_CLASS
5773 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS 7336 * @see StaticWarningCode#NEW_WITH_ABSTRACT_CLASS
5774 */ 7337 */
5775 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type Name typeName, InterfaceType type) { 7338 bool checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Type Name typeName, InterfaceType type) {
5776 if (type.element.isAbstract()) { 7339 if (type.element.isAbstract()) {
5777 ConstructorElement element53 = node.element; 7340 ConstructorElement element63 = node.element;
5778 if (element53 != null && !element53.isFactory()) { 7341 if (element63 != null && !element63.isFactory()) {
5779 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO NST)) { 7342 if (identical(((node.keyword as sc.KeywordToken)).keyword, sc.Keyword.CO NST)) {
5780 _errorReporter.reportError(StaticWarningCode.CONST_WITH_ABSTRACT_CLASS , typeName, []); 7343 _errorReporter.reportError(StaticWarningCode.CONST_WITH_ABSTRACT_CLASS , typeName, []);
5781 } else { 7344 } else {
5782 _errorReporter.reportError(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS, typeName, []); 7345 _errorReporter.reportError(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS, typeName, []);
5783 } 7346 }
5784 return true; 7347 return true;
5785 } 7348 }
5786 } 7349 }
5787 return false; 7350 return false;
5788 } 7351 }
5789 /** 7352 /**
5790 * This verifies that if the passed instance creation expression is 'const', t hen it is not being 7353 * This verifies that if the passed instance creation expression is 'const', t hen it is not being
5791 * invoked on a constructor that is not 'const'. 7354 * invoked on a constructor that is not 'const'.
5792 * @param node the instance creation expression to evaluate 7355 * @param node the instance creation expression to evaluate
5793 * @return return <code>true</code> if and only if an error code is generated on the passed node 7356 * @return return {@code true} if and only if an error code is generated on th e passed node
5794 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST 7357 * @see CompileTimeErrorCode#CONST_WITH_NON_CONST
5795 */ 7358 */
5796 bool checkForConstWithNonConst(InstanceCreationExpression node) { 7359 bool checkForConstWithNonConst(InstanceCreationExpression node) {
5797 ConstructorElement constructorElement = node.element; 7360 ConstructorElement constructorElement = node.element;
5798 if (node.isConst() && constructorElement != null && !constructorElement.isCo nst()) { 7361 if (node.isConst() && constructorElement != null && !constructorElement.isCo nst()) {
5799 _errorReporter.reportError(CompileTimeErrorCode.CONST_WITH_NON_CONST, node , []); 7362 _errorReporter.reportError(CompileTimeErrorCode.CONST_WITH_NON_CONST, node , []);
5800 return true; 7363 return true;
5801 } 7364 }
5802 return false; 7365 return false;
5803 } 7366 }
5804 /** 7367 /**
5805 * This verifies that there are no default parameters in the passed function t ype alias. 7368 * This verifies that there are no default parameters in the passed function t ype alias.
5806 * @param node the function type alias to evaluate 7369 * @param node the function type alias to evaluate
5807 * @return return <code>true</code> if and only if an error code is generated on the passed node 7370 * @return return {@code true} if and only if an error code is generated on th e passed node
5808 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS 7371 * @see CompileTimeErrorCode#DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS
5809 */ 7372 */
5810 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { 7373 bool checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) {
5811 bool result = false; 7374 bool result = false;
5812 FormalParameterList formalParameterList = node.parameters; 7375 FormalParameterList formalParameterList = node.parameters;
5813 NodeList<FormalParameter> parameters13 = formalParameterList.parameters; 7376 NodeList<FormalParameter> parameters15 = formalParameterList.parameters;
5814 for (FormalParameter formalParameter in parameters13) { 7377 for (FormalParameter formalParameter in parameters15) {
5815 if (formalParameter is DefaultFormalParameter) { 7378 if (formalParameter is DefaultFormalParameter) {
5816 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau ltFormalParameter; 7379 DefaultFormalParameter defaultFormalParameter = formalParameter as Defau ltFormalParameter;
5817 if (defaultFormalParameter.defaultValue != null) { 7380 if (defaultFormalParameter.defaultValue != null) {
5818 _errorReporter.reportError(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCT ION_TYPE_ALIAS, node, []); 7381 _errorReporter.reportError(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCT ION_TYPE_ALIAS, node, []);
5819 result = true; 7382 result = true;
5820 } 7383 }
5821 } 7384 }
5822 } 7385 }
5823 return result; 7386 return result;
5824 } 7387 }
5825 /** 7388 /**
5826 * This verifies that the passed extends clause does not extend classes such a s num or String. 7389 * This verifies that the passed extends clause does not extend classes such a s num or String.
5827 * @param node the extends clause to test 7390 * @param node the extends clause to test
5828 * @return return <code>true</code> if and only if an error code is generated on the passed node 7391 * @return return {@code true} if and only if an error code is generated on th e passed node
5829 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 7392 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS
5830 */ 7393 */
5831 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) => checkForEx tendsOrImplementsDisallowedClass(extendsClause.superclass, CompileTimeErrorCode. EXTENDS_DISALLOWED_CLASS); 7394 bool checkForExtendsDisallowedClass(ExtendsClause extendsClause) => checkForEx tendsOrImplementsDisallowedClass(extendsClause.superclass, CompileTimeErrorCode. EXTENDS_DISALLOWED_CLASS);
5832 /** 7395 /**
5833 * This verifies that the passed type name does not extend or implement classe s such as 'num' or 7396 * This verifies that the passed type name does not extend or implement classe s such as 'num' or
5834 * 'String'. 7397 * 'String'.
5835 * @param node the type name to test 7398 * @param node the type name to test
5836 * @return return <code>true</code> if and only if an error code is generated on the passed node 7399 * @return return {@code true} if and only if an error code is generated on th e passed node
5837 * @see #checkForExtendsDisallowedClass(ExtendsClause) 7400 * @see #checkForExtendsDisallowedClass(ExtendsClause)
5838 * @see #checkForImplementsDisallowedClass(ImplementsClause) 7401 * @see #checkForImplementsDisallowedClass(ImplementsClause)
5839 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS 7402 * @see CompileTimeErrorCode#EXTENDS_DISALLOWED_CLASS
5840 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 7403 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS
5841 */ 7404 */
5842 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e rrorCode) { 7405 bool checkForExtendsOrImplementsDisallowedClass(TypeName typeName, ErrorCode e rrorCode) {
5843 if (typeName.isSynthetic()) { 7406 if (typeName.isSynthetic()) {
5844 return false; 7407 return false;
5845 } 7408 }
5846 Type2 superType = typeName.type; 7409 Type2 superType = typeName.type;
5847 for (InterfaceType disallowedType in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMEN T) { 7410 for (InterfaceType disallowedType in _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMEN T) {
5848 if (superType == disallowedType) { 7411 if (superType != null && superType == disallowedType) {
5849 if (superType == _typeProvider.numType) { 7412 if (superType == _typeProvider.numType) {
5850 ASTNode grandParent = typeName.parent.parent; 7413 ASTNode grandParent = typeName.parent.parent;
5851 if (grandParent is ClassDeclaration) { 7414 if (grandParent is ClassDeclaration) {
5852 ClassElement classElement = ((grandParent as ClassDeclaration)).elem ent; 7415 ClassElement classElement = ((grandParent as ClassDeclaration)).elem ent;
5853 Type2 classType = classElement.type; 7416 Type2 classType = classElement.type;
5854 if (classType != null && (classType == _typeProvider.intType || clas sType == _typeProvider.doubleType)) { 7417 if (classType != null && (classType == _typeProvider.intType || clas sType == _typeProvider.doubleType)) {
5855 return false; 7418 return false;
5856 } 7419 }
5857 } 7420 }
5858 } 7421 }
5859 _errorReporter.reportError(errorCode, typeName, [disallowedType.name]); 7422 _errorReporter.reportError(errorCode, typeName, [disallowedType.name]);
5860 return true; 7423 return true;
5861 } 7424 }
5862 } 7425 }
5863 return false; 7426 return false;
5864 } 7427 }
5865 /** 7428 /**
5866 * This verifies that the passed constructor field initializer is not also a f inal variable that
5867 * already included an initialization.
5868 * @param node the constructor field initializer to test
5869 * @return return <code>true</code> if and only if an error code is generated on the passed node
5870 * @see CompileTimeErrorCode#FIELD_INITIALIZED_IN_INITIALIZER_AND_DECLARATION
5871 */
5872 bool checkForFieldInitializedInInitializerAndDeclaration(ConstructorFieldIniti alizer node) {
5873 SimpleIdentifier identifier = node.fieldName;
5874 Element element54 = identifier.element;
5875 if (element54 is PropertyAccessorElement) {
5876 PropertyAccessorElement propertyAccessorElement = element54 as PropertyAcc essorElement;
5877 PropertyInducingElement propertyInducingElement = propertyAccessorElement. variable;
5878 if (propertyInducingElement.initializer != null && (propertyInducingElemen t.isFinal() || propertyInducingElement.isConst())) {
5879 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_IN_INI TIALIZER_AND_DECLARATION, node, []);
5880 return true;
5881 }
5882 }
5883 return false;
5884 }
5885 /**
5886 * This verifies that the passed constructor field initializer is not also a f ield formal
5887 * parameter in the constructor declaration.
5888 * @param node the constructor field initializer to test
5889 * @return return <code>true</code> if and only if an error code is generated on the passed node
5890 * @see CompileTimeErrorCode#FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER
5891 */
5892 bool checkForFieldInitializedInParameterAndInitializer(ConstructorFieldInitial izer node) {
5893 SimpleIdentifier identifier = node.fieldName;
5894 Element element55 = identifier.element;
5895 ASTNode parent18 = node.parent;
5896 if (element55 != null && parent18 is ConstructorDeclaration) {
5897 ConstructorDeclaration constructorDeclaration = parent18 as ConstructorDec laration;
5898 NodeList<FormalParameter> formalParameters = constructorDeclaration.parame ters.parameters;
5899 for (FormalParameter formalParameter in formalParameters) {
5900 if (formalParameter is FieldFormalParameter) {
5901 FieldFormalParameter fieldFormalParameter = formalParameter as FieldFo rmalParameter;
5902 if (fieldFormalParameter.identifier.name == element55.name) {
5903 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZED_IN _PARAMETER_AND_INITIALIZER, node, []);
5904 return true;
5905 }
5906 }
5907 }
5908 }
5909 return false;
5910 }
5911 /**
5912 * This verifies that the passed field formal parameter is in a constructor de claration. 7429 * This verifies that the passed field formal parameter is in a constructor de claration.
5913 * @param node the field formal parameter to test 7430 * @param node the field formal parameter to test
5914 * @return return <code>true</code> if and only if an error code is generated on the passed node 7431 * @return return {@code true} if and only if an error code is generated on th e passed node
5915 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR 7432 * @see CompileTimeErrorCode#FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
5916 */ 7433 */
5917 bool checkForFieldInitializerOutsideConstructor(FieldFormalParameter node) { 7434 bool checkForFieldInitializerOutsideConstructor(FieldFormalParameter node) {
5918 ASTNode parent19 = node.parent; 7435 ASTNode parent18 = node.parent;
5919 if (parent19 != null) { 7436 if (parent18 != null) {
5920 ASTNode grandparent = parent19.parent; 7437 ASTNode grandparent = parent18.parent;
5921 if (grandparent != null && grandparent is! ConstructorDeclaration && grand parent.parent is! ConstructorDeclaration) { 7438 if (grandparent != null && grandparent is! ConstructorDeclaration && grand parent.parent is! ConstructorDeclaration) {
5922 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSID E_CONSTRUCTOR, node, []); 7439 _errorReporter.reportError(CompileTimeErrorCode.FIELD_INITIALIZER_OUTSID E_CONSTRUCTOR, node, []);
5923 return true; 7440 return true;
5924 } 7441 }
5925 } 7442 }
5926 return false; 7443 return false;
5927 } 7444 }
5928 /** 7445 /**
7446 * This verifies that final fields that are declared, without any constructors in the enclosing
7447 * class, are initialized. Cases in which there is at least one constructor ar e handled at the end
7448 * of {@link #checkForAllFinalInitializedErrorCodes(ConstructorDeclaration)}.
7449 * @param node the class declaration to test
7450 * @return {@code true} if and only if an error code is generated on the passe d node
7451 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED
7452 */
7453 bool checkForFinalNotInitialized(ClassDeclaration node) {
7454 NodeList<ClassMember> classMembers = node.members;
7455 for (ClassMember classMember in classMembers) {
7456 if (classMember is ConstructorDeclaration) {
7457 return false;
7458 }
7459 }
7460 bool foundError = false;
7461 for (ClassMember classMember in classMembers) {
7462 if (classMember is FieldDeclaration) {
7463 FieldDeclaration field = classMember as FieldDeclaration;
7464 foundError = javaBooleanOr(foundError, checkForFinalNotInitialized2(fiel d.fields));
7465 }
7466 }
7467 return foundError;
7468 }
7469 /**
7470 * This verifies that the passed variable declaration list has only initialize d variables if the
7471 * list is final or const. This method is called by{@link #checkForFinalNotIni tialized(ClassDeclaration)},{@link #visitTopLevelVariableDeclaration(TopLevelVar iableDeclaration)} and{@link #visitVariableDeclarationStatement(VariableDeclarat ionStatement)}.
7472 * @param node the class declaration to test
7473 * @return {@code true} if and only if an error code is generated on the passe d node
7474 * @see CompileTimeErrorCode#FINAL_NOT_INITIALIZED
7475 */
7476 bool checkForFinalNotInitialized2(VariableDeclarationList node) {
7477 bool foundError = false;
7478 if (!node.isSynthetic() && (node.isConst() || node.isFinal())) {
7479 NodeList<VariableDeclaration> variables3 = node.variables;
7480 for (VariableDeclaration variable in variables3) {
7481 if (variable.initializer == null) {
7482 _errorReporter.reportError(CompileTimeErrorCode.FINAL_NOT_INITIALIZED, variable, [variable.name.name]);
7483 foundError = true;
7484 }
7485 }
7486 }
7487 return foundError;
7488 }
7489 /**
5929 * This verifies that the passed implements clause does not implement classes such as 'num' or 7490 * This verifies that the passed implements clause does not implement classes such as 'num' or
5930 * 'String'. 7491 * 'String'.
5931 * @param node the implements clause to test 7492 * @param node the implements clause to test
5932 * @return return <code>true</code> if and only if an error code is generated on the passed node 7493 * @return return {@code true} if and only if an error code is generated on th e passed node
5933 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS 7494 * @see CompileTimeErrorCode#IMPLEMENTS_DISALLOWED_CLASS
5934 */ 7495 */
5935 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) { 7496 bool checkForImplementsDisallowedClass(ImplementsClause implementsClause) {
5936 bool result = false; 7497 bool foundError = false;
5937 for (TypeName type in implementsClause.interfaces) { 7498 for (TypeName type in implementsClause.interfaces) {
5938 result = javaBooleanOr(result, checkForExtendsOrImplementsDisallowedClass( type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)); 7499 foundError = javaBooleanOr(foundError, checkForExtendsOrImplementsDisallow edClass(type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS));
5939 ;
5940 } 7500 }
5941 return result; 7501 return foundError;
5942 } 7502 }
5943 /** 7503 /**
5944 * This verifies that the passed assignment expression represents a valid assi gnment. 7504 * This verifies that the passed assignment expression represents a valid assi gnment.
5945 * @param node the assignment expression to evaluate 7505 * @param node the assignment expression to evaluate
5946 * @return return <code>true</code> if and only if an error code is generated on the passed node 7506 * @return return {@code true} if and only if an error code is generated on th e passed node
5947 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT 7507 * @see StaticTypeWarningCode#INVALID_ASSIGNMENT
5948 */ 7508 */
5949 bool checkForInvalidAssignment(AssignmentExpression node) { 7509 bool checkForInvalidAssignment(AssignmentExpression node) {
5950 Expression lhs = node.leftHandSide; 7510 Expression lhs = node.leftHandSide;
5951 Expression rhs = node.rightHandSide; 7511 Expression rhs = node.rightHandSide;
5952 Type2 leftType = getType(lhs); 7512 VariableElement leftElement = getVariableElement(lhs);
7513 Type2 leftType = (leftElement == null) ? getType(lhs) : leftElement.type;
5953 Type2 rightType = getType(rhs); 7514 Type2 rightType = getType(rhs);
5954 if (!rightType.isAssignableTo(leftType)) { 7515 if (!rightType.isAssignableTo(leftType)) {
5955 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [leftType.name, rightType.name]); 7516 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType.name, leftType.name]);
5956 return true; 7517 return true;
5957 } 7518 }
5958 return false; 7519 return false;
7520 }
7521 /**
7522 * Checks to ensure that native function bodies can only in SDK code.
7523 * @param node the native function body to test
7524 * @return return {@code true} if and only if an error code is generated on th e passed node
7525 * @see ParserErrorCode#NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE
7526 */
7527 bool checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) {
7528 if (!_isInSystemLibrary) {
7529 _errorReporter.reportError(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK _CODE, node, []);
7530 return true;
7531 }
7532 return false;
5959 } 7533 }
5960 /** 7534 /**
5961 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is 7535 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is
5962 * reported on the expression. 7536 * reported on the expression.
5963 * @param condition the conditional expression to test 7537 * @param condition the conditional expression to test
5964 * @return return <code>true</code> if and only if an error code is generated on the passed node 7538 * @return return {@code true} if and only if an error code is generated on th e passed node
5965 * @see StaticTypeWarningCode#NON_BOOL_CONDITION 7539 * @see StaticTypeWarningCode#NON_BOOL_CONDITION
5966 */ 7540 */
5967 bool checkForNonBoolCondition(Expression condition) { 7541 bool checkForNonBoolCondition(Expression condition) {
5968 Type2 conditionType = getType(condition); 7542 Type2 conditionType = getType(condition);
5969 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo lType)) { 7543 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo lType)) {
5970 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi tion, []); 7544 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi tion, []);
5971 return true; 7545 return true;
5972 } 7546 }
5973 return false; 7547 return false;
5974 } 7548 }
5975 /** 7549 /**
5976 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input. 7550 * This verifies that the passed assert statement has either a 'bool' or '() - > bool' input.
5977 * @param node the assert statement to evaluate 7551 * @param node the assert statement to evaluate
5978 * @return return <code>true</code> if and only if an error code is generated on the passed node 7552 * @return return {@code true} if and only if an error code is generated on th e passed node
5979 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION 7553 * @see StaticTypeWarningCode#NON_BOOL_EXPRESSION
5980 */ 7554 */
5981 bool checkForNonBoolExpression(AssertStatement node) { 7555 bool checkForNonBoolExpression(AssertStatement node) {
5982 Expression expression = node.condition; 7556 Expression expression = node.condition;
5983 Type2 type = getType(expression); 7557 Type2 type = getType(expression);
5984 if (type is InterfaceType) { 7558 if (type is InterfaceType) {
5985 if (!type.isAssignableTo(_typeProvider.boolType)) { 7559 if (!type.isAssignableTo(_typeProvider.boolType)) {
5986 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []); 7560 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []);
5987 return true; 7561 return true;
5988 } 7562 }
5989 } else if (type is FunctionType) { 7563 } else if (type is FunctionType) {
5990 FunctionType functionType = type as FunctionType; 7564 FunctionType functionType = type as FunctionType;
5991 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_typeProvider.boolType)) { 7565 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_typeProvider.boolType)) {
5992 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []); 7566 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []);
5993 return true; 7567 return true;
5994 } 7568 }
5995 } 7569 }
5996 return false; 7570 return false;
5997 } 7571 }
5998 /** 7572 /**
5999 * This checks that the rethrow is inside of a catch clause. 7573 * This checks that the rethrow is inside of a catch clause.
6000 * @param node the rethrow expression to evaluate 7574 * @param node the rethrow expression to evaluate
6001 * @return <code>true</code> if and only if an error code is generated on the passed node 7575 * @return {@code true} if and only if an error code is generated on the passe d node
6002 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH 7576 * @see CompileTimeErrorCode#RETHROW_OUTSIDE_CATCH
6003 */ 7577 */
6004 bool checkForRethrowOutsideCatch(RethrowExpression node) { 7578 bool checkForRethrowOutsideCatch(RethrowExpression node) {
6005 if (!_isInCatchClause) { 7579 if (!_isInCatchClause) {
6006 _errorReporter.reportError(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, nod e, []); 7580 _errorReporter.reportError(CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH, nod e, []);
6007 return true; 7581 return true;
6008 } 7582 }
6009 return false; 7583 return false;
6010 } 7584 }
6011 /** 7585 /**
6012 * This checks that the return type matches the type of the declared return ty pe in the enclosing 7586 * This checks that the return type matches the type of the declared return ty pe in the enclosing
6013 * method or function. 7587 * method or function.
6014 * @param node the return statement to evaluate 7588 * @param node the return statement to evaluate
6015 * @return return <code>true</code> if and only if an error code is generated on the passed node 7589 * @return return {@code true} if and only if an error code is generated on th e passed node
6016 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE 7590 * @see StaticTypeWarningCode#RETURN_OF_INVALID_TYPE
6017 */ 7591 */
6018 bool checkForReturnOfInvalidType(ReturnStatement node) { 7592 bool checkForReturnOfInvalidType(ReturnStatement node) {
6019 FunctionType functionType = _currentFunction == null ? null : _currentFuncti on.type; 7593 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu nction.type;
6020 Type2 expectedReturnType = functionType == null ? null : functionType.return Type; 7594 Type2 expectedReturnType = functionType == null ? null : functionType.return Type;
6021 Expression returnExpression = node.expression; 7595 Expression returnExpression = node.expression;
6022 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr ession != null) { 7596 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr ession != null) {
6023 Type2 actualReturnType = getType(returnExpression); 7597 Type2 actualReturnType = getType(returnExpression);
6024 if (!actualReturnType.isAssignableTo(expectedReturnType)) { 7598 if (!actualReturnType.isAssignableTo(expectedReturnType)) {
6025 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [actualReturnType.name, expectedReturnType.name]); 7599 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [actualReturnType.name, expectedReturnType.name, _enclosingFu nction.name]);
6026 return true; 7600 return true;
6027 } 7601 }
6028 } 7602 }
6029 return false; 7603 return false;
6030 } 7604 }
6031 /** 7605 /**
6032 * This verifies that the type arguments in the passed instance creation expre ssion are all within 7606 * This verifies that the type arguments in the passed instance creation expre ssion are all within
6033 * their bounds as specified by the class element where the constructor [that is being invoked] is 7607 * their bounds as specified by the class element where the constructor [that is being invoked] is
6034 * declared. 7608 * declared.
6035 * @param node the instance creation expression to evaluate 7609 * @param node the instance creation expression to evaluate
6036 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th e{@link InstanceCreationExpression}, this is the AST node that the error is atta ched to 7610 * @param typeName the {@link TypeName} of the {@link ConstructorName} from th e{@link InstanceCreationExpression}, this is the AST node that the error is atta ched to
6037 * @param constructorElement the {@link ConstructorElement} from the instance creation expression 7611 * @param constructorElement the {@link ConstructorElement} from the instance creation expression
6038 * @return return <code>true</code> if and only if an error code is generated on the passed node 7612 * @return return {@code true} if and only if an error code is generated on th e passed node
6039 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS 7613 * @see StaticTypeWarningCode#TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
6040 */ 7614 */
6041 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co nstructorElement constructorElement, TypeName typeName) { 7615 bool checkForTypeArgumentNotMatchingBounds(InstanceCreationExpression node, Co nstructorElement constructorElement, TypeName typeName) {
6042 if (typeName.typeArguments != null && constructorElement != null) { 7616 if (typeName.typeArguments != null && constructorElement != null) {
6043 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments; 7617 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
6044 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme nt.typeVariables; 7618 List<TypeVariableElement> boundingElts = constructorElement.enclosingEleme nt.typeVariables;
6045 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt h); 7619 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.lengt h);
6046 for (int i = 0; i < loopThroughIndex; i++) { 7620 for (int i = 0; i < loopThroughIndex; i++) {
6047 TypeName argTypeName = typeNameArgList[i]; 7621 TypeName argTypeName = typeNameArgList[i];
6048 Type2 argType = argTypeName.type; 7622 Type2 argType = argTypeName.type;
(...skipping 10 matching lines...) Expand all
6059 } 7633 }
6060 /** 7634 /**
6061 * Return the type of the given expression that is to be used for type analysi s. 7635 * Return the type of the given expression that is to be used for type analysi s.
6062 * @param expression the expression whose type is to be returned 7636 * @param expression the expression whose type is to be returned
6063 * @return the type of the given expression 7637 * @return the type of the given expression
6064 */ 7638 */
6065 Type2 getType(Expression expression) { 7639 Type2 getType(Expression expression) {
6066 Type2 type = expression.staticType; 7640 Type2 type = expression.staticType;
6067 return type == null ? _dynamicType : type; 7641 return type == null ? _dynamicType : type;
6068 } 7642 }
7643 /**
7644 * Return the variable element represented by the given expression, or {@code null} if there is no
7645 * such element.
7646 * @param expression the expression whose element is to be returned
7647 * @return the variable element represented by the expression
7648 */
7649 VariableElement getVariableElement(Expression expression) {
7650 if (expression is Identifier) {
7651 Element element64 = ((expression as Identifier)).element;
7652 if (element64 is VariableElement) {
7653 return element64 as VariableElement;
7654 }
7655 }
7656 return null;
7657 }
7658 }
7659 /**
7660 * This enum holds one of four states of a field initialization state through a constructor
7661 * signature, not initialized, initialized in the field declaration, initialized in the field
7662 * formal, and finally, initialized in the initializers list.
7663 */
7664 class INIT_STATE implements Comparable<INIT_STATE> {
7665 static final INIT_STATE NOT_INIT = new INIT_STATE('NOT_INIT', 0);
7666 static final INIT_STATE INIT_IN_DECLARATION = new INIT_STATE('INIT_IN_DECLARAT ION', 1);
7667 static final INIT_STATE INIT_IN_FIELD_FORMAL = new INIT_STATE('INIT_IN_FIELD_F ORMAL', 2);
7668 static final INIT_STATE INIT_IN_DEFAULT_VALUE = new INIT_STATE('INIT_IN_DEFAUL T_VALUE', 3);
7669 static final INIT_STATE INIT_IN_INITIALIZERS = new INIT_STATE('INIT_IN_INITIAL IZERS', 4);
7670 static final List<INIT_STATE> values = [NOT_INIT, INIT_IN_DECLARATION, INIT_IN _FIELD_FORMAL, INIT_IN_DEFAULT_VALUE, INIT_IN_INITIALIZERS];
7671 final String __name;
7672 final int __ordinal;
7673 int get ordinal => __ordinal;
7674 INIT_STATE(this.__name, this.__ordinal) {
7675 }
7676 int compareTo(INIT_STATE other) => __ordinal - other.__ordinal;
7677 String toString() => __name;
6069 } 7678 }
6070 /** 7679 /**
6071 * The enumeration {@code ResolverErrorCode} defines the error codes used for er rors detected by the 7680 * The enumeration {@code ResolverErrorCode} defines the error codes used for er rors detected by the
6072 * resolver. The convention for this class is for the name of the error code to indicate the problem 7681 * resolver. The convention for this class is for the name of the error code to indicate the problem
6073 * that caused the error to be generated and for the error message to explain wh at is wrong and, 7682 * that caused the error to be generated and for the error message to explain wh at is wrong and,
6074 * when appropriate, how the problem can be corrected. 7683 * when appropriate, how the problem can be corrected.
6075 * @coverage dart.engine.resolver 7684 * @coverage dart.engine.resolver
6076 */ 7685 */
6077 class ResolverErrorCode implements ErrorCode { 7686 class ResolverErrorCode implements Comparable<ResolverErrorCode>, ErrorCode {
6078 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la bel resolves to case or default statement"); 7687 static final ResolverErrorCode BREAK_LABEL_ON_SWITCH_MEMBER = new ResolverErro rCode('BREAK_LABEL_ON_SWITCH_MEMBER', 0, ErrorType.COMPILE_TIME_ERROR, "Break la bel resolves to case or default statement");
6079 static final ResolverErrorCode CANNOT_BE_RESOLVED = new ResolverErrorCode('CAN NOT_BE_RESOLVED', 1, ErrorType.STATIC_WARNING, "Cannot resolve the name '%s'"); 7688 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod e('CONTINUE_LABEL_ON_SWITCH', 1, ErrorType.COMPILE_TIME_ERROR, "A continue label resolves to switch, must be loop or switch member");
6080 static final ResolverErrorCode CONTINUE_LABEL_ON_SWITCH = new ResolverErrorCod e('CONTINUE_LABEL_ON_SWITCH', 2, ErrorType.COMPILE_TIME_ERROR, "A continue label resolves to switch, must be loop or switch member"); 7689 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 2, ErrorType.COMPILE_TIME_ER ROR, "Libraries that have parts must have a library directive");
6081 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 3, ErrorType.COMPILE_TIME_ER ROR, "Libraries that have parts must have a library directive"); 7690 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C ONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART];
6082 static final ResolverErrorCode MISSING_PART_OF_DIRECTIVE = new ResolverErrorCo de('MISSING_PART_OF_DIRECTIVE', 4, ErrorType.COMPILE_TIME_ERROR, "The included p art must have a part-of directive");
6083 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C ANNOT_BE_RESOLVED, CONTINUE_LABEL_ON_SWITCH, MISSING_LIBRARY_DIRECTIVE_WITH_PART , MISSING_PART_OF_DIRECTIVE];
6084 final String __name; 7691 final String __name;
6085 final int __ordinal; 7692 final int __ordinal;
6086 int get ordinal => __ordinal; 7693 int get ordinal => __ordinal;
6087 /** 7694 /**
6088 * The type of this error. 7695 * The type of this error.
6089 */ 7696 */
6090 ErrorType _type; 7697 ErrorType _type;
6091 /** 7698 /**
6092 * The message template used to create the message to be displayed for this er ror. 7699 * The message template used to create the message to be displayed for this er ror.
6093 */ 7700 */
6094 String _message; 7701 String _message;
6095 /** 7702 /**
6096 * Initialize a newly created error code to have the given type and message. 7703 * Initialize a newly created error code to have the given type and message.
6097 * @param type the type of this error 7704 * @param type the type of this error
6098 * @param message the message template used to create the message to be displa yed for the error 7705 * @param message the message template used to create the message to be displa yed for the error
6099 */ 7706 */
6100 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message) { 7707 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message) {
6101 this._type = type; 7708 this._type = type;
6102 this._message = message; 7709 this._message = message;
6103 } 7710 }
6104 ErrorSeverity get errorSeverity => _type.severity; 7711 ErrorSeverity get errorSeverity => _type.severity;
6105 String get message => _message; 7712 String get message => _message;
6106 ErrorType get type => _type; 7713 ErrorType get type => _type;
6107 bool needsRecompilation() => true; 7714 bool needsRecompilation() => true;
7715 int compareTo(ResolverErrorCode other) => __ordinal - other.__ordinal;
6108 String toString() => __name; 7716 String toString() => __name;
6109 } 7717 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/parser.dart ('k') | pkg/analyzer_experimental/lib/src/generated/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698