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

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

Issue 12502002: Update analyzer-experimental. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 'source.dart'; 9 import 'source.dart';
10 import 'error.dart'; 10 import 'error.dart';
(...skipping 25 matching lines...) Expand all
36 CompilationUnitBuilder(AnalysisContextImpl analysisContext, AnalysisErrorListe ner errorListener) { 36 CompilationUnitBuilder(AnalysisContextImpl analysisContext, AnalysisErrorListe ner errorListener) {
37 this._analysisContext = analysisContext; 37 this._analysisContext = analysisContext;
38 this._errorListener = errorListener; 38 this._errorListener = errorListener;
39 } 39 }
40 /** 40 /**
41 * Build the compilation unit element for the given source. 41 * Build the compilation unit element for the given source.
42 * @param source the source describing the compilation unit 42 * @param source the source describing the compilation unit
43 * @return the compilation unit element that was built 43 * @return the compilation unit element that was built
44 * @throws AnalysisException if the analysis could not be performed 44 * @throws AnalysisException if the analysis could not be performed
45 */ 45 */
46 CompilationUnitElementImpl buildCompilationUnit(Source source) => buildCompila tionUnit2(source, _analysisContext.parse2(source, _errorListener)); 46 CompilationUnitElementImpl buildCompilationUnit(Source source) => buildCompila tionUnit2(source, _analysisContext.parse3(source, _errorListener));
47 /** 47 /**
48 * Build the compilation unit element for the given source. 48 * Build the compilation unit element for the given source.
49 * @param source the source describing the compilation unit 49 * @param source the source describing the compilation unit
50 * @param unit the AST structure representing the compilation unit 50 * @param unit the AST structure representing the compilation unit
51 * @return the compilation unit element that was built 51 * @return the compilation unit element that was built
52 * @throws AnalysisException if the analysis could not be performed 52 * @throws AnalysisException if the analysis could not be performed
53 */ 53 */
54 CompilationUnitElementImpl buildCompilationUnit2(Source source11, CompilationU nit unit) { 54 CompilationUnitElementImpl buildCompilationUnit2(Source source13, CompilationU nit unit) {
55 ElementHolder holder = new ElementHolder(); 55 ElementHolder holder = new ElementHolder();
56 ElementBuilder builder = new ElementBuilder(holder); 56 ElementBuilder builder = new ElementBuilder(holder);
57 unit.accept(builder); 57 unit.accept(builder);
58 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source11 .shortName); 58 CompilationUnitElementImpl element = new CompilationUnitElementImpl(source13 .shortName);
59 element.accessors = holder.accessors; 59 element.accessors = holder.accessors;
60 element.functions = holder.functions; 60 element.functions = holder.functions;
61 element.source = source11; 61 element.source = source13;
62 element.typeAliases = holder.typeAliases; 62 element.typeAliases = holder.typeAliases;
63 element.types = holder.types; 63 element.types = holder.types;
64 element.variables = holder.variables; 64 element.topLevelVariables = holder.topLevelVariables;
65 unit.element = element; 65 unit.element = element;
66 return element; 66 return element;
67 } 67 }
68 } 68 }
69 /** 69 /**
70 * Instances of the class {@code ElementBuilder} traverse an AST structure and b uild the element 70 * Instances of the class {@code ElementBuilder} traverse an AST structure and b uild the element
71 * model representing the AST structure. 71 * model representing the AST structure.
72 */ 72 */
73 class ElementBuilder extends RecursiveASTVisitor<Object> { 73 class ElementBuilder extends RecursiveASTVisitor<Object> {
74 /** 74 /**
75 * The element holder associated with the element that is currently being buil t. 75 * The element holder associated with the element that is currently being buil t.
76 */ 76 */
77 ElementHolder _currentHolder; 77 ElementHolder _currentHolder;
78 /** 78 /**
79 * A flag indicating whether a variable declaration is in the context of a fie ld declaration. 79 * A flag indicating whether a variable declaration is in the context of a fie ld declaration.
80 */ 80 */
81 bool _inFieldContext = false; 81 bool _inFieldContext = false;
82 /** 82 /**
83 * A flag indicating whether a variable declaration is within the body of a me thod or function.
84 */
85 bool _inFunction = false;
86 /**
87 * A flag indicating whether the class currently being visited can be used as a mixin.
88 */
89 bool _isValidMixin = false;
90 /**
83 * Initialize a newly created element builder to build the elements for a comp ilation unit. 91 * Initialize a newly created element builder to build the elements for a comp ilation unit.
84 * @param initialHolder the element holder associated with the compilation uni t being built 92 * @param initialHolder the element holder associated with the compilation uni t being built
85 */ 93 */
86 ElementBuilder(ElementHolder initialHolder) { 94 ElementBuilder(ElementHolder initialHolder) {
87 _currentHolder = initialHolder; 95 _currentHolder = initialHolder;
88 } 96 }
89 Object visitCatchClause(CatchClause node) { 97 Object visitCatchClause(CatchClause node) {
90 SimpleIdentifier exceptionParameter2 = node.exceptionParameter; 98 SimpleIdentifier exceptionParameter2 = node.exceptionParameter;
91 if (exceptionParameter2 != null) { 99 if (exceptionParameter2 != null) {
92 VariableElementImpl exception = new VariableElementImpl.con1(exceptionPara meter2); 100 LocalVariableElementImpl exception = new LocalVariableElementImpl(exceptio nParameter2);
93 _currentHolder.addVariable(exception); 101 _currentHolder.addLocalVariable(exception);
94 exceptionParameter2.element = exception; 102 exceptionParameter2.element = exception;
95 SimpleIdentifier stackTraceParameter2 = node.stackTraceParameter; 103 SimpleIdentifier stackTraceParameter2 = node.stackTraceParameter;
96 if (stackTraceParameter2 != null) { 104 if (stackTraceParameter2 != null) {
97 VariableElementImpl stackTrace = new VariableElementImpl.con1(stackTrace Parameter2); 105 LocalVariableElementImpl stackTrace = new LocalVariableElementImpl(stack TraceParameter2);
98 _currentHolder.addVariable(stackTrace); 106 _currentHolder.addLocalVariable(stackTrace);
99 stackTraceParameter2.element = stackTrace; 107 stackTraceParameter2.element = stackTrace;
100 } 108 }
101 } 109 }
102 node.visitChildren(this); 110 return super.visitCatchClause(node);
103 return null;
104 } 111 }
105 Object visitClassDeclaration(ClassDeclaration node) { 112 Object visitClassDeclaration(ClassDeclaration node) {
106 ElementHolder holder = new ElementHolder(); 113 ElementHolder holder = new ElementHolder();
114 _isValidMixin = true;
107 visitChildren(holder, node); 115 visitChildren(holder, node);
108 SimpleIdentifier className = node.name; 116 SimpleIdentifier className = node.name;
109 ClassElementImpl element = new ClassElementImpl(className); 117 ClassElementImpl element = new ClassElementImpl(className);
118 List<TypeVariableElement> typeVariables4 = holder.typeVariables;
119 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
120 int typeVariableCount = typeVariables4.length;
121 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
122 for (int i = 0; i < typeVariableCount; i++) {
123 TypeVariableElementImpl typeVariable = typeVariables4[i] as TypeVariableEl ementImpl;
124 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
125 typeVariable.type = typeArgument;
126 typeArguments[i] = typeArgument;
127 }
128 interfaceType.typeArguments = typeArguments;
129 element.type = interfaceType;
110 List<ConstructorElement> constructors3 = holder.constructors; 130 List<ConstructorElement> constructors3 = holder.constructors;
111 if (constructors3.length == 0) { 131 if (constructors3.length == 0) {
112 ConstructorElementImpl constructor = new ConstructorElementImpl(null); 132 ConstructorElementImpl constructor = new ConstructorElementImpl(null);
113 constructor.synthetic = true; 133 constructor.synthetic = true;
114 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor); 134 FunctionTypeImpl type = new FunctionTypeImpl.con1(constructor);
115 type.returnType = element.type; 135 type.returnType = interfaceType;
116 constructor.type = type; 136 constructor.type = type;
117 constructors3 = <ConstructorElement> [constructor]; 137 constructors3 = <ConstructorElement> [constructor];
118 } 138 }
119 element.abstract = node.abstractKeyword != null; 139 element.abstract = node.abstractKeyword != null;
120 element.accessors = holder.accessors; 140 element.accessors = holder.accessors;
121 element.constructors = constructors3; 141 element.constructors = constructors3;
122 element.fields = holder.fields; 142 element.fields = holder.fields;
123 element.methods = holder.methods; 143 element.methods = holder.methods;
124 List<TypeVariableElement> typeVariables4 = holder.typeVariables;
125 element.typeVariables = typeVariables4; 144 element.typeVariables = typeVariables4;
126 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 145 element.validMixin = _isValidMixin;
127 int typeVariableCount = typeVariables4.length;
128 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
129 for (int i = 0; i < typeVariableCount; i++) {
130 TypeVariableElementImpl typeVariable = (typeVariables4[i] as TypeVariableE lementImpl);
131 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
132 typeVariable.type = typeArgument;
133 typeArguments[i] = typeArgument;
134 }
135 interfaceType.typeArguments = typeArguments;
136 element.type = interfaceType;
137 _currentHolder.addType(element); 146 _currentHolder.addType(element);
138 className.element = element; 147 className.element = element;
139 return null; 148 return null;
140 } 149 }
141 Object visitClassTypeAlias(ClassTypeAlias node) { 150 Object visitClassTypeAlias(ClassTypeAlias node) {
142 ElementHolder holder = new ElementHolder(); 151 ElementHolder holder = new ElementHolder();
143 visitChildren(holder, node); 152 visitChildren(holder, node);
144 SimpleIdentifier className = node.name; 153 SimpleIdentifier className = node.name;
145 ClassElementImpl element = new ClassElementImpl(className); 154 ClassElementImpl element = new ClassElementImpl(className);
146 element.abstract = node.abstractKeyword != null; 155 element.abstract = node.abstractKeyword != null;
156 element.typedef = true;
147 List<TypeVariableElement> typeVariables5 = holder.typeVariables; 157 List<TypeVariableElement> typeVariables5 = holder.typeVariables;
148 element.typeVariables = typeVariables5; 158 element.typeVariables = typeVariables5;
149 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element); 159 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl.con1(element);
150 int typeVariableCount = typeVariables5.length; 160 int typeVariableCount = typeVariables5.length;
151 List<Type2> typeArguments = new List<Type2>(typeVariableCount); 161 List<Type2> typeArguments = new List<Type2>(typeVariableCount);
152 for (int i = 0; i < typeVariableCount; i++) { 162 for (int i = 0; i < typeVariableCount; i++) {
153 TypeVariableElementImpl typeVariable = (typeVariables5[i] as TypeVariableE lementImpl); 163 TypeVariableElementImpl typeVariable = typeVariables5[i] as TypeVariableEl ementImpl;
154 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ; 164 TypeVariableTypeImpl typeArgument = new TypeVariableTypeImpl(typeVariable) ;
155 typeVariable.type = typeArgument; 165 typeVariable.type = typeArgument;
156 typeArguments[i] = typeArgument; 166 typeArguments[i] = typeArgument;
157 } 167 }
158 interfaceType.typeArguments = typeArguments; 168 interfaceType.typeArguments = typeArguments;
159 element.type = interfaceType; 169 element.type = interfaceType;
160 _currentHolder.addType(element); 170 _currentHolder.addType(element);
161 className.element = element; 171 className.element = element;
162 return null; 172 return null;
163 } 173 }
164 Object visitConstructorDeclaration(ConstructorDeclaration node) { 174 Object visitConstructorDeclaration(ConstructorDeclaration node) {
175 _isValidMixin = false;
165 ElementHolder holder = new ElementHolder(); 176 ElementHolder holder = new ElementHolder();
166 visitChildren(holder, node); 177 visitChildren(holder, node);
167 SimpleIdentifier constructorName = node.name; 178 SimpleIdentifier constructorName = node.name;
168 ConstructorElementImpl element = new ConstructorElementImpl(constructorName) ; 179 ConstructorElementImpl element = new ConstructorElementImpl(constructorName) ;
169 if (node.factoryKeyword != null) { 180 if (node.factoryKeyword != null) {
170 element.factory = true; 181 element.factory = true;
171 } 182 }
172 element.functions = holder.functions; 183 element.functions = holder.functions;
173 element.labels = holder.labels; 184 element.labels = holder.labels;
174 element.localVariables = holder.variables; 185 element.localVariables = holder.localVariables;
175 element.parameters = holder.parameters; 186 element.parameters = holder.parameters;
176 _currentHolder.addConstructor(element); 187 _currentHolder.addConstructor(element);
177 node.element = element; 188 node.element = element;
178 if (constructorName != null) { 189 if (constructorName != null) {
179 constructorName.element = element; 190 constructorName.element = element;
180 } 191 }
181 return null; 192 return null;
182 } 193 }
183 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 194 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
184 ElementHolder holder = new ElementHolder(); 195 ElementHolder holder = new ElementHolder();
185 visitChildren(holder, node.defaultValue); 196 visit(holder, node.defaultValue);
186 FunctionElementImpl initializer = new FunctionElementImpl(); 197 FunctionElementImpl initializer = new FunctionElementImpl();
187 initializer.functions = holder.functions; 198 initializer.functions = holder.functions;
188 initializer.labels = holder.labels; 199 initializer.labels = holder.labels;
189 initializer.localVariables = holder.variables; 200 initializer.localVariables = holder.localVariables;
190 initializer.parameters = holder.parameters; 201 initializer.parameters = holder.parameters;
191 SimpleIdentifier parameterName = node.parameter.identifier; 202 SimpleIdentifier parameterName = node.parameter.identifier;
192 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); 203 ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
193 parameter.const2 = node.isConst(); 204 parameter.const2 = node.isConst();
194 parameter.final2 = node.isFinal(); 205 parameter.final2 = node.isFinal();
195 parameter.initializer = initializer; 206 parameter.initializer = initializer;
196 parameter.parameterKind = node.kind; 207 parameter.parameterKind = node.kind;
208 FunctionBody body = getFunctionBody(node);
209 if (body != null) {
210 parameter.setVisibleRange(body.offset, body.length);
211 }
197 _currentHolder.addParameter(parameter); 212 _currentHolder.addParameter(parameter);
198 parameterName.element = parameter; 213 parameterName.element = parameter;
199 node.parameter.accept(this); 214 node.parameter.accept(this);
200 return null; 215 return null;
201 } 216 }
202 Object visitFieldDeclaration(FieldDeclaration node) { 217 Object visitFieldDeclaration(FieldDeclaration node) {
203 bool wasInField = _inFieldContext; 218 bool wasInField = _inFieldContext;
204 _inFieldContext = true; 219 _inFieldContext = true;
205 try { 220 try {
206 node.visitChildren(this); 221 node.visitChildren(this);
207 } finally { 222 } finally {
208 _inFieldContext = wasInField; 223 _inFieldContext = wasInField;
209 } 224 }
210 return null; 225 return null;
211 } 226 }
212 Object visitFieldFormalParameter(FieldFormalParameter node) { 227 Object visitFieldFormalParameter(FieldFormalParameter node) {
213 if (node.parent is! DefaultFormalParameter) { 228 if (node.parent is! DefaultFormalParameter) {
214 SimpleIdentifier parameterName = node.identifier; 229 SimpleIdentifier parameterName = node.identifier;
215 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); 230 ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
216 parameter.const2 = node.isConst(); 231 parameter.const2 = node.isConst();
217 parameter.initializingFormal = true; 232 parameter.initializingFormal = true;
218 parameter.final2 = node.isFinal(); 233 parameter.final2 = node.isFinal();
219 parameter.parameterKind = node.kind; 234 parameter.parameterKind = node.kind;
220 _currentHolder.addParameter(parameter); 235 _currentHolder.addParameter(parameter);
221 parameterName.element = parameter; 236 parameterName.element = parameter;
222 } 237 }
223 node.visitChildren(this); 238 return super.visitFieldFormalParameter(node);
224 return null;
225 } 239 }
226 Object visitFunctionDeclaration(FunctionDeclaration node) { 240 Object visitFunctionDeclaration(FunctionDeclaration node) {
227 ElementHolder holder = new ElementHolder(); 241 FunctionExpression expression = node.functionExpression;
228 visitChildren(holder, node); 242 if (expression != null) {
229 SimpleIdentifier functionName = node.name; 243 ElementHolder holder = new ElementHolder();
230 FunctionElementImpl element = new FunctionElementImpl.con1(functionName); 244 bool wasInFunction = _inFunction;
231 element.functions = holder.functions; 245 _inFunction = true;
232 element.labels = holder.labels; 246 try {
233 element.localVariables = holder.variables; 247 visitChildren(holder, expression);
234 element.parameters = holder.parameters; 248 } finally {
235 _currentHolder.addFunction(element); 249 _inFunction = wasInFunction;
236 functionName.element = element; 250 }
251 Token property = node.propertyKeyword;
252 if (property == null) {
253 SimpleIdentifier functionName = node.name;
254 FunctionElementImpl element = new FunctionElementImpl.con1(functionName) ;
255 element.functions = holder.functions;
256 element.labels = holder.labels;
257 element.localVariables = holder.localVariables;
258 element.parameters = holder.parameters;
259 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
260 element.type = type;
261 _currentHolder.addFunction(element);
262 expression.element = element;
263 functionName.element = element;
264 } else {
265 SimpleIdentifier propertyNameNode = node.name;
266 if (propertyNameNode == null) {
267 return null;
268 }
269 String propertyName = propertyNameNode.name;
270 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldE lementImpl;
271 if (field == null) {
272 field = new FieldElementImpl.con2(node.name.name);
273 field.final2 = true;
274 _currentHolder.addField(field);
275 }
276 if (matches(property, Keyword.GET)) {
277 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.c on1(propertyNameNode);
278 getter.functions = holder.functions;
279 getter.labels = holder.labels;
280 getter.localVariables = holder.localVariables;
281 getter.variable = field;
282 getter.getter = true;
283 field.getter = getter;
284 _currentHolder.addAccessor(getter);
285 propertyNameNode.element = getter;
286 } else {
287 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.c on1(propertyNameNode);
288 setter.functions = holder.functions;
289 setter.labels = holder.labels;
290 setter.localVariables = holder.localVariables;
291 setter.parameters = holder.parameters;
292 setter.variable = field;
293 setter.setter = true;
294 field.setter = setter;
295 field.final2 = false;
296 _currentHolder.addAccessor(setter);
297 propertyNameNode.element = setter;
298 }
299 }
300 }
237 return null; 301 return null;
238 } 302 }
239 Object visitFunctionExpression(FunctionExpression node) { 303 Object visitFunctionExpression(FunctionExpression node) {
240 ElementHolder holder = new ElementHolder(); 304 ElementHolder holder = new ElementHolder();
241 visitChildren(holder, node); 305 bool wasInFunction = _inFunction;
306 _inFunction = true;
307 try {
308 visitChildren(holder, node);
309 } finally {
310 _inFunction = wasInFunction;
311 }
242 SimpleIdentifier functionName = null; 312 SimpleIdentifier functionName = null;
243 FunctionElementImpl element = new FunctionElementImpl.con1(functionName); 313 FunctionElementImpl element = new FunctionElementImpl.con1(functionName);
244 element.functions = holder.functions; 314 element.functions = holder.functions;
245 element.labels = holder.labels; 315 element.labels = holder.labels;
246 element.localVariables = holder.variables; 316 element.localVariables = holder.localVariables;
247 element.parameters = holder.parameters; 317 element.parameters = holder.parameters;
318 if (_inFunction) {
319 Block enclosingBlock = node.getAncestor(Block);
320 if (enclosingBlock != null) {
321 int functionEnd = node.offset + node.length;
322 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
323 element.setVisibleRange(functionEnd, blockEnd - functionEnd - 1);
324 }
325 }
248 FunctionTypeImpl type = new FunctionTypeImpl.con1(element); 326 FunctionTypeImpl type = new FunctionTypeImpl.con1(element);
249 element.type = type; 327 element.type = type;
250 _currentHolder.addFunction(element); 328 _currentHolder.addFunction(element);
251 node.element = element; 329 node.element = element;
252 return null; 330 return null;
253 } 331 }
254 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 332 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
255 ElementHolder holder = new ElementHolder(); 333 ElementHolder holder = new ElementHolder();
256 visitChildren(holder, node); 334 visitChildren(holder, node);
257 SimpleIdentifier aliasName = node.name; 335 SimpleIdentifier aliasName = node.name;
(...skipping 19 matching lines...) Expand all
277 return null; 355 return null;
278 } 356 }
279 Object visitLabeledStatement(LabeledStatement node) { 357 Object visitLabeledStatement(LabeledStatement node) {
280 bool onSwitchStatement = node.statement is SwitchStatement; 358 bool onSwitchStatement = node.statement is SwitchStatement;
281 for (Label label in node.labels) { 359 for (Label label in node.labels) {
282 SimpleIdentifier labelName = label.label; 360 SimpleIdentifier labelName = label.label;
283 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme nt, false); 361 LabelElementImpl element = new LabelElementImpl(labelName, onSwitchStateme nt, false);
284 _currentHolder.addLabel(element); 362 _currentHolder.addLabel(element);
285 labelName.element = element; 363 labelName.element = element;
286 } 364 }
287 node.visitChildren(this); 365 return super.visitLabeledStatement(node);
288 return null;
289 } 366 }
290 Object visitMethodDeclaration(MethodDeclaration node) { 367 Object visitMethodDeclaration(MethodDeclaration node) {
291 ElementHolder holder = new ElementHolder(); 368 ElementHolder holder = new ElementHolder();
292 visitChildren(holder, node); 369 bool wasInFunction = _inFunction;
370 _inFunction = true;
371 try {
372 visitChildren(holder, node);
373 } finally {
374 _inFunction = wasInFunction;
375 }
293 Token property = node.propertyKeyword; 376 Token property = node.propertyKeyword;
294 if (property == null) { 377 if (property == null) {
295 Identifier methodName = node.name; 378 SimpleIdentifier methodName = node.name;
296 String nameOfMethod = methodName.name; 379 String nameOfMethod = methodName.name;
297 if (nameOfMethod == TokenType.MINUS.lexeme && node.parameters.parameters.l ength == 0) { 380 if (nameOfMethod == TokenType.MINUS.lexeme && node.parameters.parameters.l ength == 0) {
298 nameOfMethod = "unary-"; 381 nameOfMethod = "unary-";
299 } 382 }
300 MethodElementImpl element = new MethodElementImpl.con2(nameOfMethod, metho dName.offset); 383 MethodElementImpl element = new MethodElementImpl.con2(nameOfMethod, metho dName.offset);
301 Token keyword = node.modifierKeyword; 384 Token keyword = node.modifierKeyword;
302 element.abstract = matches(keyword, Keyword.ABSTRACT); 385 element.abstract = matches(keyword, Keyword.ABSTRACT);
303 element.functions = holder.functions; 386 element.functions = holder.functions;
304 element.labels = holder.labels; 387 element.labels = holder.labels;
305 element.localVariables = holder.variables; 388 element.localVariables = holder.localVariables;
306 element.parameters = holder.parameters; 389 element.parameters = holder.parameters;
307 element.static = matches(keyword, Keyword.STATIC); 390 element.static = matches(keyword, Keyword.STATIC);
308 _currentHolder.addMethod(element); 391 _currentHolder.addMethod(element);
309 methodName.element = element; 392 methodName.element = element;
310 } else { 393 } else {
311 Identifier propertyNameNode = node.name; 394 SimpleIdentifier propertyNameNode = node.name;
312 String propertyName = propertyNameNode.name; 395 String propertyName = propertyNameNode.name;
313 FieldElementImpl field = (_currentHolder.getField(propertyName) as FieldEl ementImpl); 396 FieldElementImpl field = _currentHolder.getField(propertyName) as FieldEle mentImpl;
314 if (field == null) { 397 if (field == null) {
315 field = new FieldElementImpl.con2(node.name.name); 398 field = new FieldElementImpl.con2(node.name.name);
316 field.final2 = true; 399 field.final2 = true;
317 field.static = matches(node.modifierKeyword, Keyword.STATIC); 400 field.static = matches(node.modifierKeyword, Keyword.STATIC);
318 _currentHolder.addField(field); 401 _currentHolder.addField(field);
319 } 402 }
320 if (matches(property, Keyword.GET)) { 403 if (matches(property, Keyword.GET)) {
321 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con 2(propertyNameNode); 404 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con 1(propertyNameNode);
322 getter.functions = holder.functions; 405 getter.functions = holder.functions;
323 getter.labels = holder.labels; 406 getter.labels = holder.labels;
324 getter.localVariables = holder.variables; 407 getter.localVariables = holder.localVariables;
325 getter.field = field; 408 getter.variable = field;
326 getter.getter = true; 409 getter.getter = true;
327 field.getter = getter; 410 field.getter = getter;
328 _currentHolder.addAccessor(getter); 411 _currentHolder.addAccessor(getter);
329 propertyNameNode.element = getter; 412 propertyNameNode.element = getter;
330 } else { 413 } else {
331 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(propertyNameNode); 414 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 1(propertyNameNode);
332 setter.functions = holder.functions; 415 setter.functions = holder.functions;
333 setter.labels = holder.labels; 416 setter.labels = holder.labels;
334 setter.localVariables = holder.variables; 417 setter.localVariables = holder.localVariables;
335 setter.parameters = holder.parameters; 418 setter.parameters = holder.parameters;
336 setter.field = field; 419 setter.variable = field;
337 setter.setter = true; 420 setter.setter = true;
338 field.setter = setter; 421 field.setter = setter;
339 field.final2 = false; 422 field.final2 = false;
340 _currentHolder.addAccessor(setter); 423 _currentHolder.addAccessor(setter);
341 propertyNameNode.element = setter; 424 propertyNameNode.element = setter;
342 } 425 }
343 } 426 }
344 return null; 427 return null;
345 } 428 }
346 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 429 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
347 if (node.parent is! DefaultFormalParameter) { 430 if (node.parent is! DefaultFormalParameter) {
348 SimpleIdentifier parameterName = node.identifier; 431 SimpleIdentifier parameterName = node.identifier;
349 ParameterElementImpl parameter = new ParameterElementImpl(parameterName); 432 ParameterElementImpl parameter = new ParameterElementImpl(parameterName);
350 parameter.const2 = node.isConst(); 433 parameter.const2 = node.isConst();
351 parameter.final2 = node.isFinal(); 434 parameter.final2 = node.isFinal();
352 parameter.parameterKind = node.kind; 435 parameter.parameterKind = node.kind;
353 _currentHolder.addParameter(parameter); 436 _currentHolder.addParameter(parameter);
354 parameterName.element = parameter; 437 parameterName.element = parameter;
355 } 438 }
356 node.visitChildren(this); 439 return super.visitSimpleFormalParameter(node);
357 return null; 440 }
441 Object visitSuperExpression(SuperExpression node) {
442 _isValidMixin = false;
443 return super.visitSuperExpression(node);
358 } 444 }
359 Object visitSwitchCase(SwitchCase node) { 445 Object visitSwitchCase(SwitchCase node) {
360 for (Label label in node.labels) { 446 for (Label label in node.labels) {
361 SimpleIdentifier labelName = label.label; 447 SimpleIdentifier labelName = label.label;
362 LabelElementImpl element = new LabelElementImpl(labelName, false, true); 448 LabelElementImpl element = new LabelElementImpl(labelName, false, true);
363 _currentHolder.addLabel(element); 449 _currentHolder.addLabel(element);
364 labelName.element = element; 450 labelName.element = element;
365 } 451 }
366 node.visitChildren(this); 452 return super.visitSwitchCase(node);
367 return null;
368 } 453 }
369 Object visitSwitchDefault(SwitchDefault node) { 454 Object visitSwitchDefault(SwitchDefault node) {
370 for (Label label in node.labels) { 455 for (Label label in node.labels) {
371 SimpleIdentifier labelName = label.label; 456 SimpleIdentifier labelName = label.label;
372 LabelElementImpl element = new LabelElementImpl(labelName, false, true); 457 LabelElementImpl element = new LabelElementImpl(labelName, false, true);
373 _currentHolder.addLabel(element); 458 _currentHolder.addLabel(element);
374 labelName.element = element; 459 labelName.element = element;
375 } 460 }
376 node.visitChildren(this); 461 return super.visitSwitchDefault(node);
377 return null;
378 } 462 }
379 Object visitTypeParameter(TypeParameter node) { 463 Object visitTypeParameter(TypeParameter node) {
380 SimpleIdentifier parameterName = node.name; 464 SimpleIdentifier parameterName = node.name;
381 TypeVariableElementImpl element = new TypeVariableElementImpl(parameterName) ; 465 TypeVariableElementImpl element = new TypeVariableElementImpl(parameterName) ;
382 TypeVariableTypeImpl type = new TypeVariableTypeImpl(element); 466 TypeVariableTypeImpl type = new TypeVariableTypeImpl(element);
383 element.type = type; 467 element.type = type;
384 _currentHolder.addTypeVariable(element); 468 _currentHolder.addTypeVariable(element);
385 parameterName.element = element; 469 parameterName.element = element;
386 node.visitChildren(this); 470 return super.visitTypeParameter(node);
387 return null;
388 } 471 }
389 Object visitVariableDeclaration(VariableDeclaration node) { 472 Object visitVariableDeclaration(VariableDeclaration node) {
390 VariableElementImpl element; 473 VariableElementImpl element;
391 if (_inFieldContext) { 474 if (_inFieldContext) {
392 SimpleIdentifier fieldName = node.name; 475 SimpleIdentifier fieldName = node.name;
393 FieldElementImpl field = new FieldElementImpl.con1(fieldName); 476 FieldElementImpl field = new FieldElementImpl.con1(fieldName);
394 element = field; 477 element = field;
395 _currentHolder.addField(field); 478 _currentHolder.addField(field);
396 fieldName.element = field; 479 fieldName.element = field;
480 } else if (_inFunction) {
481 SimpleIdentifier variableName = node.name;
482 element = new LocalVariableElementImpl(variableName);
483 Block enclosingBlock = node.getAncestor(Block);
484 int functionEnd = node.offset + node.length;
485 int blockEnd = enclosingBlock.offset + enclosingBlock.length;
486 ((element as LocalVariableElementImpl)).setVisibleRange(functionEnd, block End - functionEnd - 1);
487 _currentHolder.addLocalVariable((element as LocalVariableElementImpl));
488 variableName.element = element;
397 } else { 489 } else {
398 SimpleIdentifier variableName = node.name; 490 SimpleIdentifier variableName = node.name;
399 element = new VariableElementImpl.con1(variableName); 491 element = new TopLevelVariableElementImpl.con1(variableName);
400 _currentHolder.addVariable(element); 492 _currentHolder.addTopLevelVariable((element as TopLevelVariableElementImpl ));
401 variableName.element = element; 493 variableName.element = element;
402 } 494 }
403 Token keyword26 = ((node.parent as VariableDeclarationList)).keyword; 495 Token keyword26 = ((node.parent as VariableDeclarationList)).keyword;
404 bool isFinal = matches(keyword26, Keyword.FINAL); 496 bool isFinal = matches(keyword26, Keyword.FINAL);
405 element.const2 = matches(keyword26, Keyword.CONST); 497 element.const2 = matches(keyword26, Keyword.CONST);
406 element.final2 = isFinal; 498 element.final2 = isFinal;
407 if (node.initializer != null) { 499 if (node.initializer != null) {
408 ElementHolder holder = new ElementHolder(); 500 ElementHolder holder = new ElementHolder();
409 bool wasInFieldContext = _inFieldContext; 501 bool wasInFieldContext = _inFieldContext;
410 _inFieldContext = false; 502 _inFieldContext = false;
411 try { 503 try {
412 visitChildren(holder, node.initializer); 504 visit(holder, node.initializer);
413 } finally { 505 } finally {
414 _inFieldContext = wasInFieldContext; 506 _inFieldContext = wasInFieldContext;
415 } 507 }
416 FunctionElementImpl initializer = new FunctionElementImpl(); 508 FunctionElementImpl initializer = new FunctionElementImpl();
417 initializer.functions = holder.functions; 509 initializer.functions = holder.functions;
418 initializer.labels = holder.labels; 510 initializer.labels = holder.labels;
419 initializer.localVariables = holder.variables; 511 initializer.localVariables = holder.localVariables;
420 initializer.synthetic = true; 512 initializer.synthetic = true;
421 element.initializer = initializer; 513 element.initializer = initializer;
422 } 514 }
423 if (_inFieldContext) { 515 if (element is PropertyInducingElementImpl) {
424 FieldElementImpl field = (element as FieldElementImpl); 516 PropertyInducingElementImpl variable = element as PropertyInducingElementI mpl;
425 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con1( field); 517 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con2( variable);
426 getter.getter = true; 518 getter.getter = true;
427 _currentHolder.addAccessor(getter); 519 _currentHolder.addAccessor(getter);
428 field.getter = getter; 520 variable.getter = getter;
429 if (!isFinal) { 521 if (!isFinal) {
430 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 1(field); 522 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con 2(variable);
431 setter.setter = true; 523 setter.setter = true;
432 _currentHolder.addAccessor(setter); 524 _currentHolder.addAccessor(setter);
433 field.setter = setter; 525 variable.setter = setter;
434 } 526 }
435 field.static = matches(((node.parent.parent as FieldDeclaration)).keyword, Keyword.STATIC); 527 if (_inFieldContext) {
528 ((variable as FieldElementImpl)).static = matches(((node.parent.parent a s FieldDeclaration)).keyword, Keyword.STATIC);
529 }
436 } 530 }
437 node.visitChildren(this); 531 return super.visitVariableDeclaration(node);
532 }
533 /**
534 * Return the body of the function that contains the given parameter, or {@cod e null} if no
535 * function body could be found.
536 * @param node the parameter contained in the function whose body is to be ret urned
537 * @return the body of the function that contains the given parameter
538 */
539 FunctionBody getFunctionBody(FormalParameter node) {
540 ASTNode parent13 = node.parent;
541 while (parent13 != null) {
542 if (parent13 is FunctionExpression) {
543 return ((parent13 as FunctionExpression)).body;
544 } else if (parent13 is MethodDeclaration) {
545 return ((parent13 as MethodDeclaration)).body;
546 }
547 parent13 = parent13.parent;
548 }
438 return null; 549 return null;
439 } 550 }
440 /** 551 /**
441 * Return {@code true} if the given token is a token for the given keyword. 552 * Return {@code true} if the given token is a token for the given keyword.
442 * @param token the token being tested 553 * @param token the token being tested
443 * @param keyword the keyword being tested for 554 * @param keyword the keyword being tested for
444 * @return {@code true} if the given token is a token for the given keyword 555 * @return {@code true} if the given token is a token for the given keyword
445 */ 556 */
446 bool matches(Token token, Keyword keyword34) => token != null && identical(tok en.type, TokenType.KEYWORD) && identical(((token as KeywordToken)).keyword, keyw ord34); 557 bool matches(Token token, Keyword keyword34) => token != null && identical(tok en.type, TokenType.KEYWORD) && identical(((token as KeywordToken)).keyword, keyw ord34);
447 /** 558 /**
559 * Make the given holder be the current holder while visiting the given node.
560 * @param holder the holder that will gather elements that are built while vis iting the children
561 * @param node the node to be visited
562 */
563 void visit(ElementHolder holder, ASTNode node) {
564 if (node != null) {
565 ElementHolder previousHolder = _currentHolder;
566 _currentHolder = holder;
567 try {
568 node.accept(this);
569 } finally {
570 _currentHolder = previousHolder;
571 }
572 }
573 }
574 /**
448 * Make the given holder be the current holder while visiting the children of the given node. 575 * Make the given holder be the current holder while visiting the children of the given node.
449 * @param holder the holder that will gather elements that are built while vis iting the children 576 * @param holder the holder that will gather elements that are built while vis iting the children
450 * @param node the node whose children are to be visited 577 * @param node the node whose children are to be visited
451 */ 578 */
452 void visitChildren(ElementHolder holder, ASTNode node) { 579 void visitChildren(ElementHolder holder, ASTNode node) {
453 if (node != null) { 580 if (node != null) {
454 ElementHolder previousHolder = _currentHolder; 581 ElementHolder previousHolder = _currentHolder;
455 _currentHolder = holder; 582 _currentHolder = holder;
456 try { 583 try {
457 node.visitChildren(this); 584 node.visitChildren(this);
458 } finally { 585 } finally {
459 _currentHolder = previousHolder; 586 _currentHolder = previousHolder;
460 } 587 }
461 } 588 }
462 } 589 }
463 } 590 }
464 /** 591 /**
465 * Instances of the class {@code ElementHolder} hold on to elements created whil e traversing an AST 592 * Instances of the class {@code ElementHolder} hold on to elements created whil e traversing an AST
466 * structure so that they can be accessed when creating their enclosing element. 593 * structure so that they can be accessed when creating their enclosing element.
467 */ 594 */
468 class ElementHolder { 595 class ElementHolder {
469 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>() ; 596 List<PropertyAccessorElement> _accessors = new List<PropertyAccessorElement>() ;
470 List<ConstructorElement> _constructors = new List<ConstructorElement>(); 597 List<ConstructorElement> _constructors = new List<ConstructorElement>();
471 List<FieldElement> _fields = new List<FieldElement>(); 598 List<FieldElement> _fields = new List<FieldElement>();
472 List<FunctionElement> _functions = new List<FunctionElement>(); 599 List<FunctionElement> _functions = new List<FunctionElement>();
473 List<LabelElement> _labels = new List<LabelElement>(); 600 List<LabelElement> _labels = new List<LabelElement>();
601 List<VariableElement> _localVariables = new List<VariableElement>();
474 List<MethodElement> _methods = new List<MethodElement>(); 602 List<MethodElement> _methods = new List<MethodElement>();
475 List<TypeAliasElement> _typeAliases = new List<TypeAliasElement>(); 603 List<TypeAliasElement> _typeAliases = new List<TypeAliasElement>();
476 List<ParameterElement> _parameters = new List<ParameterElement>(); 604 List<ParameterElement> _parameters = new List<ParameterElement>();
605 List<VariableElement> _topLevelVariables = new List<VariableElement>();
477 List<ClassElement> _types = new List<ClassElement>(); 606 List<ClassElement> _types = new List<ClassElement>();
478 List<TypeVariableElement> _typeVariables = new List<TypeVariableElement>(); 607 List<TypeVariableElement> _typeVariables = new List<TypeVariableElement>();
479 List<VariableElement> _variables = new List<VariableElement>();
480 /** 608 /**
481 * Initialize a newly created element holder. 609 * Initialize a newly created element holder.
482 */ 610 */
483 ElementHolder() : super() { 611 ElementHolder() : super() {
484 } 612 }
485 void addAccessor(PropertyAccessorElement element) { 613 void addAccessor(PropertyAccessorElement element) {
486 _accessors.add(element); 614 _accessors.add(element);
487 } 615 }
488 void addConstructor(ConstructorElement element) { 616 void addConstructor(ConstructorElement element) {
489 _constructors.add(element); 617 _constructors.add(element);
490 } 618 }
491 void addField(FieldElement element) { 619 void addField(FieldElement element) {
492 _fields.add(element); 620 _fields.add(element);
493 } 621 }
494 void addFunction(FunctionElement element) { 622 void addFunction(FunctionElement element) {
495 _functions.add(element); 623 _functions.add(element);
496 } 624 }
497 void addLabel(LabelElement element) { 625 void addLabel(LabelElement element) {
498 _labels.add(element); 626 _labels.add(element);
499 } 627 }
628 void addLocalVariable(LocalVariableElement element) {
629 _localVariables.add(element);
630 }
500 void addMethod(MethodElement element) { 631 void addMethod(MethodElement element) {
501 _methods.add(element); 632 _methods.add(element);
502 } 633 }
503 void addParameter(ParameterElement element) { 634 void addParameter(ParameterElement element) {
504 _parameters.add(element); 635 _parameters.add(element);
505 } 636 }
637 void addTopLevelVariable(TopLevelVariableElement element) {
638 _topLevelVariables.add(element);
639 }
506 void addType(ClassElement element) { 640 void addType(ClassElement element) {
507 _types.add(element); 641 _types.add(element);
508 } 642 }
509 void addTypeAlias(TypeAliasElement element) { 643 void addTypeAlias(TypeAliasElement element) {
510 _typeAliases.add(element); 644 _typeAliases.add(element);
511 } 645 }
512 void addTypeVariable(TypeVariableElement element) { 646 void addTypeVariable(TypeVariableElement element) {
513 _typeVariables.add(element); 647 _typeVariables.add(element);
514 } 648 }
515 void addVariable(VariableElement element) {
516 _variables.add(element);
517 }
518 List<PropertyAccessorElement> get accessors => new List.from(_accessors); 649 List<PropertyAccessorElement> get accessors => new List.from(_accessors);
519 List<ConstructorElement> get constructors => new List.from(_constructors); 650 List<ConstructorElement> get constructors => new List.from(_constructors);
520 FieldElement getField(String fieldName) { 651 FieldElement getField(String fieldName) {
521 for (FieldElement field in _fields) { 652 for (FieldElement field in _fields) {
522 if (field.name == fieldName) { 653 if (field.name == fieldName) {
523 return field; 654 return field;
524 } 655 }
525 } 656 }
526 return null; 657 return null;
527 } 658 }
528 List<FieldElement> get fields => new List.from(_fields); 659 List<FieldElement> get fields => new List.from(_fields);
529 List<FunctionElement> get functions => new List.from(_functions); 660 List<FunctionElement> get functions => new List.from(_functions);
530 List<LabelElement> get labels => new List.from(_labels); 661 List<LabelElement> get labels => new List.from(_labels);
662 List<LocalVariableElement> get localVariables => new List.from(_localVariables );
531 List<MethodElement> get methods => new List.from(_methods); 663 List<MethodElement> get methods => new List.from(_methods);
532 List<ParameterElement> get parameters => new List.from(_parameters); 664 List<ParameterElement> get parameters => new List.from(_parameters);
665 List<TopLevelVariableElement> get topLevelVariables => new List.from(_topLevel Variables);
533 List<TypeAliasElement> get typeAliases => new List.from(_typeAliases); 666 List<TypeAliasElement> get typeAliases => new List.from(_typeAliases);
534 List<ClassElement> get types => new List.from(_types); 667 List<ClassElement> get types => new List.from(_types);
535 List<TypeVariableElement> get typeVariables => new List.from(_typeVariables); 668 List<TypeVariableElement> get typeVariables => new List.from(_typeVariables);
536 List<VariableElement> get variables => new List.from(_variables);
537 } 669 }
538 /** 670 /**
539 * 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 671 * 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
540 * for the element resolver are: 672 * for the element resolver are:
541 * <ol> 673 * <ol>
542 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which it refers. 674 * <li>Every {@link SimpleIdentifier} should be resolved to the element to which it refers.
543 * Specifically: 675 * Specifically:
544 * <ul> 676 * <ul>
545 * <li>An identifier within the declaration of that name should resolve to the e lement being 677 * <li>An identifier within the declaration of that name should resolve to the e lement being
546 * declared.</li> 678 * declared.</li>
(...skipping 13 matching lines...) Expand all
560 * the element representing the method invoked by that operator (a {@link Method Element}).</li> 692 * the element representing the method invoked by that operator (a {@link Method Element}).</li>
561 * <li>Every {@link FunctionExpressionInvocation} should resolve to the element representing the 693 * <li>Every {@link FunctionExpressionInvocation} should resolve to the element representing the
562 * function being invoked (a {@link FunctionElement}). This will be the same ele ment as that to 694 * function being invoked (a {@link FunctionElement}). This will be the same ele ment as that to
563 * which the name is resolved if the function has a name, but is provided for th ose cases where an 695 * which the name is resolved if the function has a name, but is provided for th ose cases where an
564 * unnamed function is being invoked.</li> 696 * unnamed function is being invoked.</li>
565 * <li>Every {@link LibraryDirective} and {@link PartOfDirective} should resolve to the element 697 * <li>Every {@link LibraryDirective} and {@link PartOfDirective} should resolve to the element
566 * representing the library being specified by the directive (a {@link LibraryEl ement}) unless, in 698 * representing the library being specified by the directive (a {@link LibraryEl ement}) unless, in
567 * the case of a part-of directive, the specified library does not exist.</li> 699 * the case of a part-of directive, the specified library does not exist.</li>
568 * <li>Every {@link ImportDirective} and {@link ExportDirective} should resolve to the element 700 * <li>Every {@link ImportDirective} and {@link ExportDirective} should resolve to the element
569 * representing the library being specified by the directive unless the specifie d library does not 701 * representing the library being specified by the directive unless the specifie d library does not
570 * exist (a {@link LibraryElement}).</li> 702 * exist (an {@link ImportElement} or {@link ExportElement}).</li>
571 * <li>The identifier representing the prefix in an {@link ImportDirective} shou ld resolve to the 703 * <li>The identifier representing the prefix in an {@link ImportDirective} shou ld resolve to the
572 * element representing the prefix (a {@link PrefixElement}).</li> 704 * element representing the prefix (a {@link PrefixElement}).</li>
573 * <li>The identifiers in the hide and show combinators in {@link ImportDirectiv e}s and{@link ExportDirective}s should resolve to the elements that are being hi dden or shown, 705 * <li>The identifiers in the hide and show combinators in {@link ImportDirectiv e}s and{@link ExportDirective}s should resolve to the elements that are being hi dden or shown,
574 * respectively, unless those names are not defined in the specified library (or the specified 706 * respectively, unless those names are not defined in the specified library (or the specified
575 * library does not exist).</li> 707 * library does not exist).</li>
576 * <li>Every {@link PartDirective} should resolve to the element representing th e compilation unit 708 * <li>Every {@link PartDirective} should resolve to the element representing th e compilation unit
577 * being specified by the string unless the specified compilation unit does not exist (a{@link CompilationUnitElement}).</li> 709 * being specified by the string unless the specified compilation unit does not exist (a{@link CompilationUnitElement}).</li>
578 * </ol> 710 * </ol>
579 * Note that AST nodes that would represent elements that are not defined are no t resolved to 711 * Note that AST nodes that would represent elements that are not defined are no t resolved to
580 * anything. This includes such things as references to undeclared variables (wh ich is an error) and 712 * anything. This includes such things as references to undeclared variables (wh ich is an error) and
(...skipping 15 matching lines...) Expand all
596 Object visitAssignmentExpression(AssignmentExpression node) { 728 Object visitAssignmentExpression(AssignmentExpression node) {
597 TokenType operator7 = node.operator.type; 729 TokenType operator7 = node.operator.type;
598 if (operator7 != TokenType.EQ) { 730 if (operator7 != TokenType.EQ) {
599 operator7 = operatorFromCompoundAssignment(operator7); 731 operator7 = operatorFromCompoundAssignment(operator7);
600 Expression leftNode = node.leftHandSide; 732 Expression leftNode = node.leftHandSide;
601 if (leftNode != null) { 733 if (leftNode != null) {
602 Type2 leftType = leftNode.staticType; 734 Type2 leftType = leftNode.staticType;
603 if (leftType != null) { 735 if (leftType != null) {
604 Element leftElement = leftType.element; 736 Element leftElement = leftType.element;
605 if (leftElement != null) { 737 if (leftElement != null) {
606 MethodElement method = lookUpMethod(leftElement, operator7.lexeme, 1 , []); 738 MethodElement method = lookUpMethod(leftElement, operator7.lexeme);
607 if (method != null) { 739 if (method != null) {
608 node.element = method; 740 node.element = method;
609 } else { 741 } else {
610 } 742 }
611 } 743 }
612 } 744 }
613 } 745 }
614 } 746 }
615 return null; 747 return null;
616 } 748 }
617 Object visitBinaryExpression(BinaryExpression node) { 749 Object visitBinaryExpression(BinaryExpression node) {
618 Token operator8 = node.operator; 750 Token operator8 = node.operator;
619 if (operator8.isUserDefinableOperator()) { 751 if (operator8.isUserDefinableOperator()) {
620 Type2 leftType = getType(node.leftOperand); 752 Type2 leftType = getType(node.leftOperand);
621 Element leftTypeElement; 753 Element leftTypeElement;
622 if (leftType == null) { 754 if (leftType == null || leftType.isDynamic()) {
623 return null; 755 return null;
624 } else if (leftType is FunctionType) { 756 } else if (leftType is FunctionType) {
625 leftTypeElement = _resolver.typeProvider.functionType.element; 757 leftTypeElement = _resolver.typeProvider.functionType.element;
626 } else { 758 } else {
627 leftTypeElement = leftType.element; 759 leftTypeElement = leftType.element;
628 } 760 }
629 String methodName = operator8.lexeme; 761 String methodName = operator8.lexeme;
630 MethodElement member = lookUpMethod(leftTypeElement, methodName, 1, []); 762 MethodElement member = lookUpMethod(leftTypeElement, methodName);
631 if (member == null) { 763 if (member == null) {
632 _resolver.reportError2(ResolverErrorCode.CANNOT_BE_RESOLVED, operator8, [methodName]); 764 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator8, [methodName]);
633 } else { 765 } else {
634 node.element = member; 766 node.element = member;
635 } 767 }
636 } 768 }
637 return null; 769 return null;
638 } 770 }
639 Object visitBreakStatement(BreakStatement node) { 771 Object visitBreakStatement(BreakStatement node) {
640 SimpleIdentifier labelNode = node.label; 772 SimpleIdentifier labelNode = node.label;
641 LabelElementImpl labelElement = lookupLabel(node, labelNode); 773 LabelElementImpl labelElement = lookupLabel(node, labelNode);
642 if (labelElement != null && labelElement.isOnSwitchMember()) { 774 if (labelElement != null && labelElement.isOnSwitchMember()) {
643 _resolver.reportError(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labe lNode, []); 775 _resolver.reportError(ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER, labe lNode, []);
644 } 776 }
645 return null; 777 return null;
646 } 778 }
647 Object visitConstructorName(ConstructorName node) { 779 Object visitConstructorName(ConstructorName node) {
648 Type2 type10 = node.type.type; 780 Type2 type13 = node.type.type;
649 if (type10 is! InterfaceType) { 781 if (type13 is DynamicTypeImpl) {
782 return null;
783 } else if (type13 is! InterfaceType) {
784 ASTNode parent14 = node.parent;
785 if (parent14 is InstanceCreationExpression) {
786 if (((parent14 as InstanceCreationExpression)).isConst()) {
787 } else {
788 }
789 } else {
790 }
650 return null; 791 return null;
651 } 792 }
652 ClassElement classElement = ((type10 as InterfaceType)).element; 793 ClassElement classElement = ((type13 as InterfaceType)).element;
653 ConstructorElement constructor; 794 ConstructorElement constructor;
654 SimpleIdentifier name14 = node.name; 795 SimpleIdentifier name14 = node.name;
655 if (name14 == null) { 796 if (name14 == null) {
656 constructor = classElement.unnamedConstructor; 797 constructor = classElement.unnamedConstructor;
657 } else { 798 } else {
658 constructor = classElement.getNamedConstructor(name14.name); 799 constructor = classElement.getNamedConstructor(name14.name);
659 name14.element = constructor; 800 name14.element = constructor;
660 } 801 }
661 node.element = constructor; 802 node.element = constructor;
662 return null; 803 return null;
663 } 804 }
664 Object visitContinueStatement(ContinueStatement node) { 805 Object visitContinueStatement(ContinueStatement node) {
665 SimpleIdentifier labelNode = node.label; 806 SimpleIdentifier labelNode = node.label;
666 LabelElementImpl labelElement = lookupLabel(node, labelNode); 807 LabelElementImpl labelElement = lookupLabel(node, labelNode);
667 if (labelElement != null && labelElement.isOnSwitchStatement()) { 808 if (labelElement != null && labelElement.isOnSwitchStatement()) {
668 _resolver.reportError(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNod e, []); 809 _resolver.reportError(ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH, labelNod e, []);
669 } 810 }
670 return null; 811 return null;
671 } 812 }
813 Object visitExportDirective(ExportDirective node) {
814 Element element20 = node.element;
815 if (element20 is ExportElement) {
816 resolveCombinators(((element20 as ExportElement)).exportedLibrary, node.co mbinators);
817 }
818 return null;
819 }
672 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null; 820 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => null;
673 Object visitImportDirective(ImportDirective node) { 821 Object visitImportDirective(ImportDirective node) {
674 SimpleIdentifier prefixNode = node.prefix; 822 SimpleIdentifier prefixNode = node.prefix;
675 if (prefixNode != null) { 823 if (prefixNode != null) {
676 String prefixName = prefixNode.name; 824 String prefixName = prefixNode.name;
677 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) { 825 for (PrefixElement prefixElement in _resolver.definingLibrary.prefixes) {
678 if (prefixElement.name == prefixName) { 826 if (prefixElement.name == prefixName) {
679 recordResolution(prefixNode, prefixElement); 827 recordResolution(prefixNode, prefixElement);
828 break;
680 } 829 }
681 return null;
682 } 830 }
683 } 831 }
832 Element element21 = node.element;
833 if (element21 is ImportElement) {
834 resolveCombinators(((element21 as ImportElement)).importedLibrary, node.co mbinators);
835 }
684 return null; 836 return null;
685 } 837 }
686 Object visitIndexExpression(IndexExpression node) { 838 Object visitIndexExpression(IndexExpression node) {
687 Type2 arrayType = getType(node.array); 839 Type2 arrayType = getType(node.realTarget);
688 if (arrayType == null) { 840 if (arrayType == null || arrayType.isDynamic()) {
689 return null; 841 return null;
690 } 842 }
691 Element arrayTypeElement = arrayType.element; 843 Element arrayTypeElement = arrayType.element;
692 String operator; 844 String operator;
693 if (node.inSetterContext()) { 845 if (node.inSetterContext()) {
694 operator = TokenType.INDEX_EQ.lexeme; 846 operator = TokenType.INDEX_EQ.lexeme;
695 } else { 847 } else {
696 operator = TokenType.INDEX.lexeme; 848 operator = TokenType.INDEX.lexeme;
697 } 849 }
698 MethodElement member = lookUpMethod(arrayTypeElement, operator, 1, []); 850 MethodElement member = lookUpMethod(arrayTypeElement, operator);
699 if (member == null) { 851 if (member == null) {
700 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, node, [operato r]); 852 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, node, [operato r]);
701 } else { 853 } else {
702 node.element = member; 854 node.element = member;
703 } 855 }
704 return null; 856 return null;
705 } 857 }
706 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 858 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
707 node.element = node.constructorName.element; 859 ConstructorElement invokedConstructor = node.constructorName.element;
860 node.element = invokedConstructor;
861 resolveNamedArguments(node.argumentList, invokedConstructor);
708 return null; 862 return null;
709 } 863 }
710 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
711 Object visitMethodInvocation(MethodInvocation node) { 864 Object visitMethodInvocation(MethodInvocation node) {
712 SimpleIdentifier methodName2 = node.methodName; 865 SimpleIdentifier methodName2 = node.methodName;
713 Expression target4 = node.target; 866 Expression target = node.realTarget;
714 Element element; 867 Element element;
715 if (target4 == null) { 868 if (target == null) {
716 element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrar y); 869 element = _resolver.nameScope.lookup(methodName2, _resolver.definingLibrar y);
717 if (element == null) { 870 if (element == null) {
718 element = lookUpMethod(_resolver.enclosingClass, methodName2.name, -1, [ ]); 871 element = lookUpMethod(_resolver.enclosingClass, methodName2.name);
719 } 872 }
720 } else { 873 } else {
721 Type2 targetType = getType(target4); 874 Type2 targetType = getType(target);
722 if (targetType is InterfaceType) { 875 if (targetType is InterfaceType) {
723 int parameterCount = 0; 876 element = lookUpMethod(targetType.element, methodName2.name);
724 List<String> parameterNames = new List<String>(); 877 if (element == null) {
725 ArgumentList argumentList10 = node.argumentList; 878 PropertyAccessorElement accessor = lookUpGetterInType((targetType.elem ent as ClassElement), methodName2.name);
726 for (Expression argument in argumentList10.arguments) { 879 if (accessor != null) {
727 if (argument is NamedExpression) { 880 Type2 returnType4 = accessor.type.returnType;
728 parameterNames.add(((argument as NamedExpression)).name.label.name); 881 if (!returnType4.isDynamic() && returnType4 is! FunctionType) {
729 } else { 882 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNC TION, methodName2, [methodName2.name]);
730 parameterCount++; 883 return null;
884 }
885 element = accessor;
731 } 886 }
732 } 887 }
733 element = lookUpMethod(targetType.element, methodName2.name, parameterCo unt, new List.from(parameterNames)); 888 if (element == null && target is SuperExpression) {
734 } else if (target4 is SimpleIdentifier) { 889 _resolver.reportError(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, me thodName2, [methodName2.name, targetType.element.name]);
735 Element targetElement = ((target4 as SimpleIdentifier)).element; 890 return null;
891 }
892 } else if (target is SimpleIdentifier) {
893 Element targetElement = ((target as SimpleIdentifier)).element;
736 if (targetElement is PrefixElement) { 894 if (targetElement is PrefixElement) {
737 String name9 = "${((target4 as SimpleIdentifier)).name}.${methodName2} "; 895 String name9 = "${((target as SimpleIdentifier)).name}.${methodName2}" ;
738 Identifier functionName = new Identifier_2(name9); 896 Identifier functionName = new Identifier_3(name9);
739 element = _resolver.nameScope.lookup(functionName, _resolver.definingL ibrary); 897 element = _resolver.nameScope.lookup(functionName, _resolver.definingL ibrary);
740 } else { 898 } else {
741 return null; 899 return null;
742 } 900 }
743 } else { 901 } else {
744 return null; 902 return null;
745 } 903 }
746 } 904 }
747 ExecutableElement invokedMethod = null; 905 ExecutableElement invokedMethod = null;
748 if (element is ExecutableElement) { 906 if (element is ExecutableElement) {
749 invokedMethod = (element as ExecutableElement); 907 invokedMethod = element as ExecutableElement;
750 } else if (element is FieldElement) {
751 } else { 908 } else {
752 return null; 909 if (element is PropertyInducingElement) {
753 } 910 PropertyAccessorElement getter3 = ((element as PropertyInducingElement)) .getter;
754 if (invokedMethod == null) { 911 FunctionType getterType = getter3.type;
755 return null; 912 if (getterType != null) {
913 Type2 returnType5 = getterType.returnType;
914 if (!returnType5.isDynamic() && returnType5 is! FunctionType) {
915 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTI ON, methodName2, [methodName2.name]);
916 }
917 }
918 recordResolution(methodName2, element);
919 return null;
920 } else if (element is VariableElement) {
921 Type2 variableType = ((element as VariableElement)).type;
922 if (!variableType.isDynamic() && variableType is! FunctionType) {
923 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION , methodName2, [methodName2.name]);
924 }
925 recordResolution(methodName2, element);
926 return null;
927 } else {
928 _resolver.reportError(StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, methodName2, [methodName2.name]);
929 return null;
930 }
756 } 931 }
757 recordResolution(methodName2, invokedMethod); 932 recordResolution(methodName2, invokedMethod);
933 resolveNamedArguments(node.argumentList, invokedMethod);
758 return null; 934 return null;
759 } 935 }
760 Object visitPostfixExpression(PostfixExpression node) { 936 Object visitPostfixExpression(PostfixExpression node) {
761 Token operator9 = node.operator; 937 Token operator9 = node.operator;
762 if (operator9.isUserDefinableOperator()) { 938 Type2 operandType = getType(node.operand);
763 Type2 operandType = getType(node.operand); 939 if (operandType == null || operandType.isDynamic()) {
764 if (operandType == null) { 940 return null;
765 return null; 941 }
766 } 942 Element operandTypeElement = operandType.element;
767 Element operandTypeElement = operandType.element; 943 String methodName;
768 String methodName; 944 if (identical(operator9.type, TokenType.PLUS_PLUS)) {
769 if (identical(operator9.type, TokenType.PLUS_PLUS)) { 945 methodName = TokenType.PLUS.lexeme;
770 methodName = TokenType.PLUS.lexeme; 946 } else {
771 } else { 947 methodName = TokenType.MINUS.lexeme;
772 methodName = TokenType.MINUS.lexeme; 948 }
773 } 949 MethodElement member = lookUpMethod(operandTypeElement, methodName);
774 MethodElement member = lookUpMethod(operandTypeElement, methodName, 1, []) ; 950 if (member == null) {
775 if (member == null) { 951 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator9, [m ethodName]);
776 _resolver.reportError2(ResolverErrorCode.CANNOT_BE_RESOLVED, operator9, [methodName]); 952 } else {
777 } else { 953 node.element = member;
778 node.element = member;
779 }
780 } 954 }
781 return null; 955 return null;
782 } 956 }
783 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 957 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
784 SimpleIdentifier prefix5 = node.prefix; 958 SimpleIdentifier prefix6 = node.prefix;
785 SimpleIdentifier identifier10 = node.identifier; 959 SimpleIdentifier identifier12 = node.identifier;
786 Element prefixElement = prefix5.element; 960 Element prefixElement = prefix6.element;
787 if (prefixElement is PrefixElement) { 961 if (prefixElement is PrefixElement) {
788 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra ry); 962 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibra ry);
789 if (element == null) { 963 if (element == null) {
790 return null; 964 return null;
791 } 965 }
792 recordResolution(identifier10, element); 966 recordResolution(identifier12, element);
793 recordResolution(node, element);
794 return null; 967 return null;
795 } 968 }
796 if (prefixElement is ClassElement) { 969 if (prefixElement is ClassElement) {
797 Element memberElement; 970 Element memberElement;
798 if (node.identifier.inSetterContext()) { 971 if (node.identifier.inSetterContext()) {
799 memberElement = lookUpSetterInType((prefixElement as ClassElement), iden tifier10.name); 972 memberElement = lookUpSetterInType((prefixElement as ClassElement), iden tifier12.name);
800 } else { 973 } else {
801 memberElement = lookUpGetterInType((prefixElement as ClassElement), iden tifier10.name); 974 memberElement = lookUpGetterInType((prefixElement as ClassElement), iden tifier12.name);
802 } 975 }
803 if (memberElement == null) { 976 if (memberElement == null) {
804 MethodElement methodElement = lookUpMethod(prefixElement, identifier10.n ame, -1, []); 977 MethodElement methodElement = lookUpMethod(prefixElement, identifier12.n ame);
805 if (methodElement != null) { 978 if (methodElement != null) {
806 recordResolution(identifier10, methodElement); 979 recordResolution(identifier12, methodElement);
807 recordResolution(node, methodElement);
808 return null; 980 return null;
809 } 981 }
810 } 982 }
811 if (memberElement == null) { 983 if (memberElement == null) {
812 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, identifier10 , [identifier10.name]); 984 reportGetterOrSetterNotFound(node, identifier12, prefixElement.name);
813 } else { 985 } else {
814 recordResolution(identifier10, memberElement); 986 recordResolution(identifier12, memberElement);
815 recordResolution(node, memberElement);
816 } 987 }
817 return null; 988 return null;
818 } 989 }
819 Element variableType; 990 Element variableTypeElement;
820 if (prefixElement is PropertyAccessorElement) { 991 if (prefixElement is PropertyAccessorElement) {
821 PropertyAccessorElement accessor = (prefixElement as PropertyAccessorEleme nt); 992 PropertyAccessorElement accessor = prefixElement as PropertyAccessorElemen t;
993 FunctionType type14 = accessor.type;
994 if (type14 == null) {
995 return null;
996 }
997 Type2 variableType;
822 if (accessor.isGetter()) { 998 if (accessor.isGetter()) {
823 variableType = accessor.type.returnType.element; 999 variableType = type14.returnType;
824 } else { 1000 } else {
825 variableType = accessor.type.normalParameterTypes[0].element; 1001 variableType = type14.normalParameterTypes[0];
826 } 1002 }
1003 if (variableType == null || variableType.isDynamic()) {
1004 return null;
1005 }
1006 variableTypeElement = variableType.element;
827 } else if (prefixElement is VariableElement) { 1007 } else if (prefixElement is VariableElement) {
828 variableType = ((prefixElement as VariableElement)).type.element; 1008 Type2 prefixType = ((prefixElement as VariableElement)).type;
1009 if (prefixType == null || prefixType.isDynamic()) {
1010 return null;
1011 }
1012 variableTypeElement = prefixType.element;
829 } else { 1013 } else {
830 return null; 1014 return null;
831 } 1015 }
832 PropertyAccessorElement memberElement; 1016 PropertyAccessorElement memberElement = null;
833 if (node.identifier.inGetterContext()) { 1017 if (node.identifier.inSetterContext()) {
834 memberElement = lookUpGetter(variableType, identifier10.name); 1018 memberElement = lookUpSetter(variableTypeElement, identifier12.name);
835 } else { 1019 }
836 memberElement = lookUpSetter(variableType, identifier10.name); 1020 if (memberElement == null && node.identifier.inGetterContext()) {
1021 memberElement = lookUpGetter(variableTypeElement, identifier12.name);
837 } 1022 }
838 if (memberElement == null) { 1023 if (memberElement == null) {
839 MethodElement methodElement = lookUpMethod(variableType, identifier10.name , -1, []); 1024 MethodElement methodElement = lookUpMethod(variableTypeElement, identifier 12.name);
840 if (methodElement != null) { 1025 if (methodElement != null) {
841 recordResolution(identifier10, methodElement); 1026 recordResolution(identifier12, methodElement);
842 recordResolution(node, methodElement);
843 return null; 1027 return null;
844 } 1028 }
845 } 1029 }
846 if (memberElement == null) { 1030 if (memberElement == null) {
847 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, identifier10, [identifier10.name]); 1031 reportGetterOrSetterNotFound(node, identifier12, variableTypeElement.name) ;
848 } else { 1032 } else {
849 recordResolution(identifier10, memberElement); 1033 recordResolution(identifier12, memberElement);
850 recordResolution(node, memberElement);
851 } 1034 }
852 return null; 1035 return null;
853 } 1036 }
854 Object visitPrefixExpression(PrefixExpression node) { 1037 Object visitPrefixExpression(PrefixExpression node) {
855 Token operator10 = node.operator; 1038 Token operator10 = node.operator;
856 TokenType operatorType = operator10.type; 1039 TokenType operatorType = operator10.type;
857 if (operatorType.isUserDefinableOperator() || identical(operatorType, TokenT ype.PLUS_PLUS) || identical(operatorType, TokenType.MINUS_MINUS)) { 1040 if (operatorType.isUserDefinableOperator() || identical(operatorType, TokenT ype.PLUS_PLUS) || identical(operatorType, TokenType.MINUS_MINUS)) {
858 Type2 operandType = getType(node.operand); 1041 Type2 operandType = getType(node.operand);
859 if (operandType == null) { 1042 if (operandType == null || operandType.isDynamic()) {
860 return null; 1043 return null;
861 } 1044 }
862 Element operandTypeElement = operandType.element; 1045 Element operandTypeElement = operandType.element;
863 String methodName; 1046 String methodName;
864 if (identical(operatorType, TokenType.PLUS_PLUS)) { 1047 if (identical(operatorType, TokenType.PLUS_PLUS)) {
865 methodName = TokenType.PLUS.lexeme; 1048 methodName = TokenType.PLUS.lexeme;
866 } else if (identical(operatorType, TokenType.MINUS_MINUS)) { 1049 } else if (identical(operatorType, TokenType.MINUS_MINUS)) {
867 methodName = TokenType.MINUS.lexeme; 1050 methodName = TokenType.MINUS.lexeme;
868 } else if (identical(operatorType, TokenType.MINUS)) { 1051 } else if (identical(operatorType, TokenType.MINUS)) {
869 methodName = "unary-"; 1052 methodName = "unary-";
870 } else { 1053 } else {
871 methodName = operator10.lexeme; 1054 methodName = operator10.lexeme;
872 } 1055 }
873 MethodElement member = lookUpMethod(operandTypeElement, methodName, 1, []) ; 1056 MethodElement member = lookUpMethod(operandTypeElement, methodName);
874 if (member == null) { 1057 if (member == null) {
875 _resolver.reportError2(ResolverErrorCode.CANNOT_BE_RESOLVED, operator10, [methodName]); 1058 _resolver.reportError3(ResolverErrorCode.CANNOT_BE_RESOLVED, operator10, [methodName]);
876 } else { 1059 } else {
877 node.element = member; 1060 node.element = member;
878 } 1061 }
879 } 1062 }
880 return null; 1063 return null;
881 } 1064 }
882 Object visitPropertyAccess(PropertyAccess node) { 1065 Object visitPropertyAccess(PropertyAccess node) {
883 Type2 targetType = getType(node.realTarget); 1066 Type2 targetType = getType(node.realTarget);
884 if (targetType is! InterfaceType) { 1067 if (targetType is! InterfaceType) {
885 return null; 1068 return null;
886 } 1069 }
887 ClassElement targetElement = ((targetType as InterfaceType)).element; 1070 ClassElement targetElement = ((targetType as InterfaceType)).element;
888 SimpleIdentifier identifier = node.propertyName; 1071 SimpleIdentifier identifier = node.propertyName;
889 PropertyAccessorElement memberElement; 1072 PropertyAccessorElement memberElement = null;
890 if (identifier.inSetterContext()) { 1073 if (identifier.inSetterContext()) {
891 memberElement = lookUpSetter(targetElement, identifier.name); 1074 memberElement = lookUpSetter(targetElement, identifier.name);
892 } else { 1075 }
1076 if (memberElement == null && identifier.inGetterContext()) {
893 memberElement = lookUpGetter(targetElement, identifier.name); 1077 memberElement = lookUpGetter(targetElement, identifier.name);
894 } 1078 }
895 if (memberElement == null) { 1079 if (memberElement == null) {
896 MethodElement methodElement = lookUpMethod(targetElement, identifier.name, -1, []); 1080 MethodElement methodElement = lookUpMethod(targetElement, identifier.name) ;
897 if (methodElement != null) { 1081 if (methodElement != null) {
898 recordResolution(identifier, methodElement); 1082 recordResolution(identifier, methodElement);
899 return null; 1083 return null;
900 } 1084 }
901 } 1085 }
902 if (memberElement == null) { 1086 if (memberElement == null) {
903 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, identifier, [i dentifier.name]); 1087 _resolver.reportError(ResolverErrorCode.CANNOT_BE_RESOLVED, identifier, [i dentifier.name]);
904 } else { 1088 } else {
905 recordResolution(identifier, memberElement); 1089 recordResolution(identifier, memberElement);
906 } 1090 }
(...skipping 11 matching lines...) Expand all
918 } else { 1102 } else {
919 element = enclosingClass2.getNamedConstructor(name.name); 1103 element = enclosingClass2.getNamedConstructor(name.name);
920 } 1104 }
921 if (element == null) { 1105 if (element == null) {
922 return null; 1106 return null;
923 } 1107 }
924 if (name != null) { 1108 if (name != null) {
925 recordResolution(name, element); 1109 recordResolution(name, element);
926 } 1110 }
927 node.element = element; 1111 node.element = element;
1112 resolveNamedArguments(node.argumentList, element);
928 return null; 1113 return null;
929 } 1114 }
930 Object visitSimpleIdentifier(SimpleIdentifier node) { 1115 Object visitSimpleIdentifier(SimpleIdentifier node) {
931 if (node.element != null) { 1116 if (node.element != null) {
932 return null; 1117 return null;
933 } 1118 }
934 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary ); 1119 Element element = _resolver.nameScope.lookup(node, _resolver.definingLibrary );
935 if (element == null) { 1120 if (element is PropertyAccessorElement && node.inSetterContext()) {
936 if (node.inGetterContext()) { 1121 PropertyInducingElement variable4 = ((element as PropertyAccessorElement)) .variable;
937 element = lookUpGetter(_resolver.enclosingClass, node.name); 1122 if (variable4 != null) {
938 } else { 1123 PropertyAccessorElement setter3 = variable4.setter;
939 element = lookUpSetter(_resolver.enclosingClass, node.name); 1124 if (setter3 != null) {
1125 element = setter3;
1126 }
940 } 1127 }
941 } 1128 }
1129 if (element == null && node.inSetterContext()) {
1130 element = lookUpSetter(_resolver.enclosingClass, node.name);
1131 }
1132 if (element == null && node.inGetterContext()) {
1133 element = lookUpGetter(_resolver.enclosingClass, node.name);
1134 }
942 if (element == null) { 1135 if (element == null) {
943 element = lookUpMethod(_resolver.enclosingClass, node.name, -1, []); 1136 element = lookUpMethod(_resolver.enclosingClass, node.name);
944 } 1137 }
945 if (element == null) { 1138 if (element == null) {
946 } 1139 }
947 recordResolution(node, element); 1140 recordResolution(node, element);
948 return null; 1141 return null;
949 } 1142 }
950 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 1143 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
951 ClassElement enclosingClass3 = _resolver.enclosingClass; 1144 ClassElement enclosingClass3 = _resolver.enclosingClass;
952 if (enclosingClass3 == null) { 1145 if (enclosingClass3 == null) {
953 return null; 1146 return null;
954 } 1147 }
955 ClassElement superclass = getSuperclass(enclosingClass3); 1148 ClassElement superclass = getSuperclass(enclosingClass3);
956 if (superclass == null) { 1149 if (superclass == null) {
957 return null; 1150 return null;
958 } 1151 }
959 SimpleIdentifier name = node.constructorName; 1152 SimpleIdentifier name = node.constructorName;
960 ConstructorElement element; 1153 ConstructorElement element;
961 if (name == null) { 1154 if (name == null) {
962 element = superclass.unnamedConstructor; 1155 element = superclass.unnamedConstructor;
963 } else { 1156 } else {
964 element = superclass.getNamedConstructor(name.name); 1157 element = superclass.getNamedConstructor(name.name);
965 } 1158 }
966 if (element == null) { 1159 if (element == null) {
967 return null; 1160 return null;
968 } 1161 }
969 if (name != null) { 1162 if (name != null) {
970 recordResolution(name, element); 1163 recordResolution(name, element);
971 } 1164 }
972 node.element = element; 1165 node.element = element;
1166 resolveNamedArguments(node.argumentList, element);
1167 return null;
1168 }
1169 Object visitTypeParameter(TypeParameter node) {
1170 TypeName bound3 = node.bound;
1171 if (bound3 != null) {
1172 TypeVariableElementImpl variable = node.name.element as TypeVariableElemen tImpl;
1173 if (variable != null) {
1174 variable.bound = bound3.type;
1175 }
1176 }
973 return null; 1177 return null;
974 } 1178 }
975 /** 1179 /**
1180 * Search through the array of parameters for a parameter whose name matches t he given name.
1181 * Return the parameter with the given name, or {@code null} if there is no su ch parameter.
1182 * @param parameters the parameters being searched
1183 * @param name the name being searched for
1184 * @return the parameter with the given name
1185 */
1186 ParameterElement findNamedParameter(List<ParameterElement> parameters, String name24) {
1187 for (ParameterElement parameter in parameters) {
1188 if (identical(parameter.parameterKind, ParameterKind.NAMED)) {
1189 String parameteName = parameter.name;
1190 if (parameteName != null && parameteName == name24) {
1191 return parameter;
1192 }
1193 }
1194 }
1195 return null;
1196 }
1197 /**
976 * Return the element representing the superclass of the given class. 1198 * Return the element representing the superclass of the given class.
977 * @param targetClass the class whose superclass is to be returned 1199 * @param targetClass the class whose superclass is to be returned
978 * @return the element representing the superclass of the given class 1200 * @return the element representing the superclass of the given class
979 */ 1201 */
980 ClassElement getSuperclass(ClassElement targetClass) { 1202 ClassElement getSuperclass(ClassElement targetClass) {
981 InterfaceType superType = targetClass.supertype; 1203 InterfaceType superType = targetClass.supertype;
982 if (superType == null) { 1204 if (superType == null) {
983 return null; 1205 return null;
984 } 1206 }
985 return superType.element; 1207 return superType.element;
(...skipping 10 matching lines...) Expand all
996 * @param element the element representing the type in which the getter is def ined 1218 * @param element the element representing the type in which the getter is def ined
997 * @param getterName the name of the getter being looked up 1219 * @param getterName the name of the getter being looked up
998 * @return the element representing the getter that was found 1220 * @return the element representing the getter that was found
999 */ 1221 */
1000 PropertyAccessorElement lookUpGetter(Element element, String getterName) { 1222 PropertyAccessorElement lookUpGetter(Element element, String getterName) {
1001 if (identical(element, DynamicTypeImpl.instance)) { 1223 if (identical(element, DynamicTypeImpl.instance)) {
1002 return null; 1224 return null;
1003 } 1225 }
1004 element = resolveTypeVariable(element); 1226 element = resolveTypeVariable(element);
1005 if (element is ClassElement) { 1227 if (element is ClassElement) {
1006 ClassElement classElement = (element as ClassElement); 1228 ClassElement classElement = element as ClassElement;
1007 PropertyAccessorElement member = classElement.lookUpGetter(getterName, _re solver.definingLibrary); 1229 PropertyAccessorElement member = classElement.lookUpGetter(getterName, _re solver.definingLibrary);
1008 if (member != null) { 1230 if (member != null) {
1009 return member; 1231 return member;
1010 } 1232 }
1011 return lookUpGetterInInterfaces((element as ClassElement), getterName, new Set<ClassElement>()); 1233 return lookUpGetterInInterfaces((element as ClassElement), getterName, new Set<ClassElement>());
1012 } 1234 }
1013 return null; 1235 return null;
1014 } 1236 }
1015 /** 1237 /**
1016 * Look up the name of a getter in the interfaces implemented by the given typ e, either directly 1238 * Look up the name of a getter in the interfaces implemented by the given typ e, either directly
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 * @param parentNode the node containing the given label 1285 * @param parentNode the node containing the given label
1064 * @param labelNode the node representing the label being looked up 1286 * @param labelNode the node representing the label being looked up
1065 * @return the element corresponding to the given label node in the current sc ope 1287 * @return the element corresponding to the given label node in the current sc ope
1066 */ 1288 */
1067 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) { 1289 LabelElementImpl lookupLabel(ASTNode parentNode, SimpleIdentifier labelNode) {
1068 LabelScope labelScope2 = _resolver.labelScope; 1290 LabelScope labelScope2 = _resolver.labelScope;
1069 LabelElementImpl labelElement = null; 1291 LabelElementImpl labelElement = null;
1070 if (labelNode == null) { 1292 if (labelNode == null) {
1071 if (labelScope2 == null) { 1293 if (labelScope2 == null) {
1072 } else { 1294 } else {
1073 labelElement = (labelScope2.lookup2(LabelScope.EMPTY_LABEL) as LabelElem entImpl); 1295 labelElement = labelScope2.lookup2(LabelScope.EMPTY_LABEL) as LabelEleme ntImpl;
1074 if (labelElement == null) { 1296 if (labelElement == null) {
1075 } 1297 }
1298 labelElement = null;
1076 } 1299 }
1077 } else { 1300 } else {
1078 if (labelScope2 == null) { 1301 if (labelScope2 == null) {
1079 _resolver.reportError(ResolverErrorCode.UNDEFINED_LABEL, labelNode, [lab elNode.name]); 1302 _resolver.reportError(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [ labelNode.name]);
1080 } else { 1303 } else {
1081 labelElement = (labelScope2.lookup(labelNode) as LabelElementImpl); 1304 labelElement = labelScope2.lookup(labelNode) as LabelElementImpl;
1082 if (labelElement == null) { 1305 if (labelElement == null) {
1083 _resolver.reportError(ResolverErrorCode.UNDEFINED_LABEL, labelNode, [l abelNode.name]); 1306 _resolver.reportError(CompileTimeErrorCode.LABEL_UNDEFINED, labelNode, [labelNode.name]);
1084 } else { 1307 } else {
1085 recordResolution(labelNode, labelElement); 1308 recordResolution(labelNode, labelElement);
1086 } 1309 }
1087 } 1310 }
1088 } 1311 }
1089 if (labelElement != null) { 1312 if (labelElement != null) {
1090 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent); 1313 ExecutableElement labelContainer = labelElement.getAncestor(ExecutableElem ent);
1091 if (labelContainer != _resolver.enclosingFunction) { 1314 if (labelContainer != _resolver.enclosingFunction) {
1092 if (labelNode == null) { 1315 _resolver.reportError(CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, labelNo de, [labelNode.name]);
1093 _resolver.reportError(ResolverErrorCode.LABEL_IN_OUTER_SCOPE, parentNo de, [""]);
1094 } else {
1095 _resolver.reportError(ResolverErrorCode.LABEL_IN_OUTER_SCOPE, labelNod e, [labelNode.name]);
1096 }
1097 labelElement = null; 1316 labelElement = null;
1098 } 1317 }
1099 } 1318 }
1100 return labelElement; 1319 return labelElement;
1101 } 1320 }
1102 /** 1321 /**
1103 * Look up the method with the given name in the given type. Return the elemen t representing the 1322 * Look up the method with the given name in the given type. Return the elemen t representing the
1104 * method that was found, or {@code null} if there is no method with the given name. 1323 * method that was found, or {@code null} if there is no method with the given name.
1105 * @param element the element representing the type in which the method is def ined 1324 * @param element the element representing the type in which the method is def ined
1106 * @param methodName the name of the method being looked up 1325 * @param methodName the name of the method being looked up
1107 * @return the element representing the method that was found 1326 * @return the element representing the method that was found
1108 */ 1327 */
1109 MethodElement lookUpMethod(Element element, String methodName, int parameterCo unt, List<String> parameterNames) { 1328 MethodElement lookUpMethod(Element element, String methodName) {
1110 if (identical(element, DynamicTypeImpl.instance)) { 1329 if (identical(element, DynamicTypeImpl.instance)) {
1111 return null; 1330 return null;
1112 } 1331 }
1113 element = resolveTypeVariable(element); 1332 element = resolveTypeVariable(element);
1114 if (element is ClassElement) { 1333 if (element is ClassElement) {
1115 ClassElement classElement = (element as ClassElement); 1334 ClassElement classElement = element as ClassElement;
1116 MethodElement member = classElement.lookUpMethod(methodName, _resolver.def iningLibrary); 1335 MethodElement member = classElement.lookUpMethod(methodName, _resolver.def iningLibrary);
1117 if (member != null) { 1336 if (member != null) {
1118 return member; 1337 return member;
1119 } 1338 }
1120 return lookUpMethodInInterfaces((element as ClassElement), methodName, new Set<ClassElement>()); 1339 return lookUpMethodInInterfaces((element as ClassElement), methodName, new Set<ClassElement>());
1121 } 1340 }
1122 return null; 1341 return null;
1123 } 1342 }
1124 /** 1343 /**
1125 * Look up the name of a member in the interfaces implemented by the given typ e, either directly 1344 * Look up the name of a member in the interfaces implemented by the given typ e, either directly
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 * @param element the element representing the type in which the setter is def ined 1392 * @param element the element representing the type in which the setter is def ined
1174 * @param setterName the name of the setter being looked up 1393 * @param setterName the name of the setter being looked up
1175 * @return the element representing the setter that was found 1394 * @return the element representing the setter that was found
1176 */ 1395 */
1177 PropertyAccessorElement lookUpSetter(Element element, String setterName) { 1396 PropertyAccessorElement lookUpSetter(Element element, String setterName) {
1178 if (identical(element, DynamicTypeImpl.instance)) { 1397 if (identical(element, DynamicTypeImpl.instance)) {
1179 return null; 1398 return null;
1180 } 1399 }
1181 element = resolveTypeVariable(element); 1400 element = resolveTypeVariable(element);
1182 if (element is ClassElement) { 1401 if (element is ClassElement) {
1183 ClassElement classElement = (element as ClassElement); 1402 ClassElement classElement = element as ClassElement;
1184 PropertyAccessorElement member = classElement.lookUpSetter(setterName, _re solver.definingLibrary); 1403 PropertyAccessorElement member = classElement.lookUpSetter(setterName, _re solver.definingLibrary);
1185 if (member != null) { 1404 if (member != null) {
1186 return member; 1405 return member;
1187 } 1406 }
1188 return lookUpSetterInInterfaces((element as ClassElement), setterName, new Set<ClassElement>()); 1407 return lookUpSetterInInterfaces((element as ClassElement), setterName, new Set<ClassElement>());
1189 } 1408 }
1190 return null; 1409 return null;
1191 } 1410 }
1192 /** 1411 /**
1193 * Look up the name of a setter in the interfaces implemented by the given typ e, either directly 1412 * Look up the name of a setter in the interfaces implemented by the given typ e, either directly
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 } 1453 }
1235 } 1454 }
1236 return null; 1455 return null;
1237 } 1456 }
1238 /** 1457 /**
1239 * Return the binary operator that is invoked by the given compound assignment operator. 1458 * Return the binary operator that is invoked by the given compound assignment operator.
1240 * @param operator the assignment operator being mapped 1459 * @param operator the assignment operator being mapped
1241 * @return the binary operator that invoked by the given assignment operator 1460 * @return the binary operator that invoked by the given assignment operator
1242 */ 1461 */
1243 TokenType operatorFromCompoundAssignment(TokenType operator) { 1462 TokenType operatorFromCompoundAssignment(TokenType operator) {
1244 if (operator == TokenType.AMPERSAND_EQ) { 1463 while (true) {
1245 return TokenType.AMPERSAND; 1464 if (operator == TokenType.AMPERSAND_EQ) {
1246 } else if (operator == TokenType.BAR_EQ) { 1465 return TokenType.AMPERSAND;
1247 return TokenType.BAR; 1466 } else if (operator == TokenType.BAR_EQ) {
1248 } else if (operator == TokenType.CARET_EQ) { 1467 return TokenType.BAR;
1249 return TokenType.CARET; 1468 } else if (operator == TokenType.CARET_EQ) {
1250 } else if (operator == TokenType.GT_GT_EQ) { 1469 return TokenType.CARET;
1251 return TokenType.GT_GT; 1470 } else if (operator == TokenType.GT_GT_EQ) {
1252 } else if (operator == TokenType.LT_LT_EQ) { 1471 return TokenType.GT_GT;
1253 return TokenType.LT_LT; 1472 } else if (operator == TokenType.LT_LT_EQ) {
1254 } else if (operator == TokenType.MINUS_EQ) { 1473 return TokenType.LT_LT;
1255 return TokenType.MINUS; 1474 } else if (operator == TokenType.MINUS_EQ) {
1256 } else if (operator == TokenType.PERCENT_EQ) { 1475 return TokenType.MINUS;
1257 return TokenType.PERCENT; 1476 } else if (operator == TokenType.PERCENT_EQ) {
1258 } else if (operator == TokenType.PLUS_EQ) { 1477 return TokenType.PERCENT;
1259 return TokenType.PLUS; 1478 } else if (operator == TokenType.PLUS_EQ) {
1260 } else if (operator == TokenType.SLASH_EQ) { 1479 return TokenType.PLUS;
1261 return TokenType.SLASH; 1480 } else if (operator == TokenType.SLASH_EQ) {
1262 } else if (operator == TokenType.STAR_EQ) { 1481 return TokenType.SLASH;
1263 return TokenType.STAR; 1482 } else if (operator == TokenType.STAR_EQ) {
1264 } else if (operator == TokenType.TILDE_SLASH_EQ) { 1483 return TokenType.STAR;
1265 return TokenType.TILDE_SLASH; 1484 } else if (operator == TokenType.TILDE_SLASH_EQ) {
1485 return TokenType.TILDE_SLASH;
1486 }
1487 break;
1266 } 1488 }
1267 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to it's corresponding operator"); 1489 AnalysisEngine.instance.logger.logError("Failed to map ${operator.lexeme} to it's corresponding operator");
1268 return operator; 1490 return operator;
1269 } 1491 }
1270 /** 1492 /**
1271 * Record the fact that the given AST node was resolved to the given element. 1493 * Record the fact that the given AST node was resolved to the given element.
1272 * @param node the AST node that was resolved 1494 * @param node the AST node that was resolved
1273 * @param element the element to which the AST node was resolved 1495 * @param element the element to which the AST node was resolved
1274 */ 1496 */
1275 void recordResolution(Identifier node, Element element39) { 1497 void recordResolution(SimpleIdentifier node, Element element46) {
1276 if (element39 != null) { 1498 if (element46 != null) {
1277 node.element = element39; 1499 node.element = element46;
1278 } 1500 }
1279 } 1501 }
1280 /** 1502 /**
1503 * Report the {@link StaticTypeWarningCode}s <code>UNDEFINED_SETTER</code> and
1504 * <code>UNDEFINED_GETTER</code>.
1505 * @param node the prefixed identifier that gives the context to determine if the error on the
1506 * undefined identifier is a getter or a setter
1507 * @param identifier the identifier in the passed prefix identifier
1508 * @param typeName the name of the type of the left hand side of the passed pr efixed identifier
1509 */
1510 void reportGetterOrSetterNotFound(PrefixedIdentifier node, SimpleIdentifier id entifier29, String typeName) {
1511 bool isSetterContext = node.identifier.inSetterContext();
1512 ErrorCode errorCode = isSetterContext ? StaticTypeWarningCode.UNDEFINED_SETT ER : StaticTypeWarningCode.UNDEFINED_GETTER;
1513 _resolver.reportError(errorCode, identifier29, [identifier29.name, typeName] );
1514 }
1515 /**
1516 * Resolve the names in the given combinators in the scope of the given librar y.
1517 * @param library the library that defines the names
1518 * @param combinators the combinators containing the names to be resolved
1519 */
1520 void resolveCombinators(LibraryElement library, NodeList<Combinator> combinato rs) {
1521 if (library == null) {
1522 return;
1523 }
1524 Namespace namespace = new NamespaceBuilder().createExportNamespace(library);
1525 for (Combinator combinator in combinators) {
1526 NodeList<SimpleIdentifier> names;
1527 if (combinator is HideCombinator) {
1528 names = ((combinator as HideCombinator)).hiddenNames;
1529 } else {
1530 names = ((combinator as ShowCombinator)).shownNames;
1531 }
1532 for (SimpleIdentifier name in names) {
1533 Element element = namespace.get(name.name);
1534 if (element != null) {
1535 name.element = element;
1536 }
1537 }
1538 }
1539 }
1540 /**
1541 * Resolve the names associated with any named arguments to the parameter elem ents named by the
1542 * argument.
1543 * @param argumentList the arguments to be resolved
1544 * @param invokedMethod the method or function defining the parameters to whic h the named
1545 * arguments are to be resolved
1546 */
1547 void resolveNamedArguments(ArgumentList argumentList, ExecutableElement invoke dMethod) {
1548 if (invokedMethod == null) {
1549 return;
1550 }
1551 List<ParameterElement> parameters11 = invokedMethod.parameters;
1552 for (Expression argument in argumentList.arguments) {
1553 if (argument is NamedExpression) {
1554 SimpleIdentifier name15 = ((argument as NamedExpression)).name.label;
1555 ParameterElement parameter = findNamedParameter(parameters11, name15.nam e);
1556 if (parameter != null) {
1557 recordResolution(name15, parameter);
1558 }
1559 }
1560 }
1561 }
1562 /**
1281 * If the given element is a type variable, resolve it to the class that shoul d be used when 1563 * If the given element is a type variable, resolve it to the class that shoul d be used when
1282 * looking up members. Otherwise, return the original element. 1564 * looking up members. Otherwise, return the original element.
1283 * @param element the element that is to be resolved if it is a type variable 1565 * @param element the element that is to be resolved if it is a type variable
1284 * @return the class that should be used in place of the argument if it is a t ype variable, or the 1566 * @return the class that should be used in place of the argument if it is a t ype variable, or the
1285 * original argument if it isn't a type variable 1567 * original argument if it isn't a type variable
1286 */ 1568 */
1287 Element resolveTypeVariable(Element element40) { 1569 Element resolveTypeVariable(Element element47) {
1288 if (element40 is TypeVariableElement) { 1570 if (element47 is TypeVariableElement) {
1289 Type2 bound3 = ((element40 as TypeVariableElement)).bound; 1571 Type2 bound4 = ((element47 as TypeVariableElement)).bound;
1290 if (bound3 == null) { 1572 if (bound4 == null) {
1291 return _resolver.typeProvider.objectType.element; 1573 return _resolver.typeProvider.objectType.element;
1292 } 1574 }
1293 return bound3.element; 1575 return bound4.element;
1294 } 1576 }
1295 return element40; 1577 return element47;
1296 } 1578 }
1297 } 1579 }
1298 class Identifier_2 extends Identifier { 1580 class Identifier_3 extends Identifier {
1299 String name9; 1581 String name9;
1300 Identifier_2(this.name9) : super(); 1582 Identifier_3(this.name9) : super();
1301 accept(ASTVisitor visitor) => null; 1583 accept(ASTVisitor visitor) => null;
1302 Token get beginToken => null; 1584 Token get beginToken => null;
1585 Element get element => null;
1303 Token get endToken => null; 1586 Token get endToken => null;
1304 String get name => name9; 1587 String get name => name9;
1305 void visitChildren(ASTVisitor<Object> visitor) { 1588 void visitChildren(ASTVisitor<Object> visitor) {
1306 } 1589 }
1307 } 1590 }
1308 /** 1591 /**
1309 * Instances of the class {@code Library} represent the data about a single libr ary during the 1592 * Instances of the class {@code Library} represent the data about a single libr ary during the
1310 * resolution of some (possibly different) library. They are not intended to be used except during 1593 * resolution of some (possibly different) library. They are not intended to be used except during
1311 * the resolution process. 1594 * the resolution process.
1312 */ 1595 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 /** 1634 /**
1352 * Initialize a newly created data holder that can maintain the data associate d with a library. 1635 * Initialize a newly created data holder that can maintain the data associate d with a library.
1353 * @param analysisContext the analysis context in which this library is being analyzed 1636 * @param analysisContext the analysis context in which this library is being analyzed
1354 * @param errorListener the listener to which analysis errors will be reported 1637 * @param errorListener the listener to which analysis errors will be reported
1355 * @param librarySource the source specifying the defining compilation unit of this library 1638 * @param librarySource the source specifying the defining compilation unit of this library
1356 */ 1639 */
1357 Library(AnalysisContextImpl analysisContext, AnalysisErrorListener errorListen er, Source librarySource) { 1640 Library(AnalysisContextImpl analysisContext, AnalysisErrorListener errorListen er, Source librarySource) {
1358 this._analysisContext = analysisContext; 1641 this._analysisContext = analysisContext;
1359 this._errorListener = errorListener; 1642 this._errorListener = errorListener;
1360 this._librarySource = librarySource; 1643 this._librarySource = librarySource;
1361 this._libraryElement = (analysisContext.getLibraryElementOrNull(librarySourc e) as LibraryElementImpl); 1644 this._libraryElement = analysisContext.getLibraryElementOrNull(librarySource ) as LibraryElementImpl;
1362 } 1645 }
1363 /** 1646 /**
1364 * Record that the given library is exported from this library. 1647 * Record that the given library is exported from this library.
1365 * @param importLibrary the library that is exported from this library 1648 * @param importLibrary the library that is exported from this library
1366 */ 1649 */
1367 void addExport(ExportDirective directive, Library exportLibrary) { 1650 void addExport(ExportDirective directive, Library exportLibrary) {
1368 _exportedLibraries[directive] = exportLibrary; 1651 _exportedLibraries[directive] = exportLibrary;
1369 } 1652 }
1370 /** 1653 /**
1371 * Record that the given library is imported into this library. 1654 * Record that the given library is imported into this library.
1372 * @param importLibrary the library that is imported into this library 1655 * @param importLibrary the library that is imported into this library
1373 */ 1656 */
1374 void addImport(ImportDirective directive, Library importLibrary) { 1657 void addImport(ImportDirective directive, Library importLibrary) {
1375 _importedLibraries[directive] = importLibrary; 1658 _importedLibraries[directive] = importLibrary;
1376 } 1659 }
1377 /** 1660 /**
1378 * Return the AST structure associated with the given source. 1661 * Return the AST structure associated with the given source.
1379 * @param source the source representing the compilation unit whose AST is to be returned 1662 * @param source the source representing the compilation unit whose AST is to be returned
1380 * @return the AST structure associated with the given source 1663 * @return the AST structure associated with the given source
1381 * @throws AnalysisException if an AST structure could not be created for the compilation unit 1664 * @throws AnalysisException if an AST structure could not be created for the compilation unit
1382 */ 1665 */
1383 CompilationUnit getAST(Source source) { 1666 CompilationUnit getAST(Source source) {
1384 CompilationUnit unit = _astMap[source]; 1667 CompilationUnit unit = _astMap[source];
1385 if (unit == null) { 1668 if (unit == null) {
1386 unit = _analysisContext.parse2(source, _errorListener); 1669 unit = _analysisContext.parse3(source, _errorListener);
1387 _astMap[source] = unit; 1670 _astMap[source] = unit;
1388 } 1671 }
1389 return unit; 1672 return unit;
1390 } 1673 }
1391 /** 1674 /**
1392 * Return a collection containing the sources for the compilation units in thi s library. 1675 * Return a collection containing the sources for the compilation units in thi s library.
1393 * @return the sources for the compilation units in this library 1676 * @return the sources for the compilation units in this library
1394 */ 1677 */
1395 Set<Source> get compilationUnitSources => _astMap.keys.toSet(); 1678 Set<Source> get compilationUnitSources => _astMap.keys.toSet();
1396 /** 1679 /**
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 libraries.addAll(_importedLibraries.values); 1728 libraries.addAll(_importedLibraries.values);
1446 libraries.addAll(_exportedLibraries.values); 1729 libraries.addAll(_exportedLibraries.values);
1447 return new List.from(libraries); 1730 return new List.from(libraries);
1448 } 1731 }
1449 /** 1732 /**
1450 * Return the library element representing this library, creating it if necess ary. 1733 * Return the library element representing this library, creating it if necess ary.
1451 * @return the library element representing this library 1734 * @return the library element representing this library
1452 */ 1735 */
1453 LibraryElementImpl get libraryElement { 1736 LibraryElementImpl get libraryElement {
1454 if (_libraryElement == null) { 1737 if (_libraryElement == null) {
1455 _libraryElement = (_analysisContext.getLibraryElement(_librarySource) as L ibraryElementImpl); 1738 _libraryElement = _analysisContext.getLibraryElement(_librarySource) as Li braryElementImpl;
1456 } 1739 }
1457 return _libraryElement; 1740 return _libraryElement;
1458 } 1741 }
1459 /** 1742 /**
1460 * Return the library scope used when resolving elements within this library's compilation units. 1743 * Return the library scope used when resolving elements within this library's compilation units.
1461 * @return the library scope used when resolving elements within this library' s compilation units 1744 * @return the library scope used when resolving elements within this library' s compilation units
1462 */ 1745 */
1463 LibraryScope get libraryScope { 1746 LibraryScope get libraryScope {
1464 if (_libraryScope == null) { 1747 if (_libraryScope == null) {
1465 _libraryScope = new LibraryScope(_libraryElement, _errorListener); 1748 _libraryScope = new LibraryScope(_libraryElement, _errorListener);
1466 } 1749 }
1467 return _libraryScope; 1750 return _libraryScope;
1468 } 1751 }
1469 /** 1752 /**
1470 * Return the source specifying the defining compilation unit of this library. 1753 * Return the source specifying the defining compilation unit of this library.
1471 * @return the source specifying the defining compilation unit of this library 1754 * @return the source specifying the defining compilation unit of this library
1472 */ 1755 */
1473 Source get librarySource => _librarySource; 1756 Source get librarySource => _librarySource;
1474 /** 1757 /**
1475 * Return the result of resolving the given URI against the URI of the library , or {@code null} if 1758 * Return the result of resolving the given URI against the URI of the library , or {@code null} if
1476 * the URI is not valid. If the URI is not valid, report the error. 1759 * the URI is not valid. If the URI is not valid, report the error.
1477 * @param uriLiteral the string literal specifying the URI to be resolved 1760 * @param uriLiteral the string literal specifying the URI to be resolved
1478 * @return the result of resolving the given URI against the URI of the librar y 1761 * @return the result of resolving the given URI against the URI of the librar y
1479 */ 1762 */
1480 Source getSource(StringLiteral uriLiteral) => getSource2(getStringValue(uriLit eral), uriLiteral.offset, uriLiteral.length); 1763 Source getSource(StringLiteral uriLiteral) {
1764 if (uriLiteral is StringInterpolation) {
1765 _errorListener.onError(new AnalysisError.con2(_librarySource, uriLiteral.o ffset, uriLiteral.length, CompileTimeErrorCode.URI_WITH_INTERPOLATION, []));
1766 return null;
1767 }
1768 return getSource2(getStringValue(uriLiteral));
1769 }
1481 /** 1770 /**
1482 * Set whether this library explicitly imports core to match the given value. 1771 * Set whether this library explicitly imports core to match the given value.
1483 * @param explicitlyImportsCore {@code true} if this library explicitly import s core 1772 * @param explicitlyImportsCore {@code true} if this library explicitly import s core
1484 */ 1773 */
1485 void set explicitlyImportsCore(bool explicitlyImportsCore2) { 1774 void set explicitlyImportsCore(bool explicitlyImportsCore2) {
1486 this._explicitlyImportsCore = explicitlyImportsCore2; 1775 this._explicitlyImportsCore = explicitlyImportsCore2;
1487 } 1776 }
1488 /** 1777 /**
1489 * Set the library element representing this library to the given library elem ent. 1778 * Set the library element representing this library to the given library elem ent.
1490 * @param libraryElement the library element representing this library 1779 * @param libraryElement the library element representing this library
1491 */ 1780 */
1492 void set libraryElement(LibraryElementImpl libraryElement2) { 1781 void set libraryElement(LibraryElementImpl libraryElement2) {
1493 this._libraryElement = libraryElement2; 1782 this._libraryElement = libraryElement2;
1494 } 1783 }
1495 String toString() => _librarySource.shortName; 1784 String toString() => _librarySource.shortName;
1496 /** 1785 /**
1497 * Append the value of the given string literal to the given string builder. 1786 * Append the value of the given string literal to the given string builder.
1498 * @param builder the builder to which the string's value is to be appended 1787 * @param builder the builder to which the string's value is to be appended
1499 * @param literal the string literal whose value is to be appended to the buil der 1788 * @param literal the string literal whose value is to be appended to the buil der
1500 * @throws IllegalArgumentException if the string is not a constant string wit hout any string 1789 * @throws IllegalArgumentException if the string is not a constant string wit hout any string
1501 * interpolation 1790 * interpolation
1502 */ 1791 */
1503 void appendStringValue(StringBuffer builder, StringLiteral literal) { 1792 void appendStringValue(StringBuffer builder, StringLiteral literal) {
1504 if (literal is SimpleStringLiteral) { 1793 if (literal is SimpleStringLiteral) {
1505 builder.add(((literal as SimpleStringLiteral)).value); 1794 builder.write(((literal as SimpleStringLiteral)).value);
1506 } else if (literal is AdjacentStrings) { 1795 } else if (literal is AdjacentStrings) {
1507 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings ) { 1796 for (StringLiteral stringLiteral in ((literal as AdjacentStrings)).strings ) {
1508 appendStringValue(builder, stringLiteral); 1797 appendStringValue(builder, stringLiteral);
1509 } 1798 }
1510 } else { 1799 } else {
1511 throw new IllegalArgumentException(); 1800 throw new IllegalArgumentException();
1512 } 1801 }
1513 } 1802 }
1514 /** 1803 /**
1515 * Return the result of resolving the given URI against the URI of the library , or {@code null} if 1804 * Return the result of resolving the given URI against the URI of the library , or {@code null} if
1516 * the URI is not valid. If the URI is not valid, report the error. 1805 * the URI is not valid.
1517 * @param uri the URI to be resolved 1806 * @param uri the URI to be resolved
1518 * @param uriOffset the offset of the string literal representing the URI
1519 * @param uriLength the length of the string literal representing the URI
1520 * @return the result of resolving the given URI against the URI of the librar y 1807 * @return the result of resolving the given URI against the URI of the librar y
1521 */ 1808 */
1522 Source getSource2(String uri, int uriOffset, int uriLength) { 1809 Source getSource2(String uri) {
1523 if (uri == null) { 1810 if (uri == null) {
1524 _errorListener.onError(new AnalysisError.con2(_librarySource, uriOffset, u riLength, ResolverErrorCode.INVALID_URI, []));
1525 return null; 1811 return null;
1526 } 1812 }
1527 return _librarySource.resolve(uri); 1813 return _librarySource.resolve(uri);
1528 } 1814 }
1529 /** 1815 /**
1530 * Return the value of the given string literal, or {@code null} if the string is not a constant 1816 * Return the value of the given string literal, or {@code null} if the string is not a constant
1531 * string without any string interpolation. 1817 * string without any string interpolation.
1532 * @param literal the string literal whose value is to be returned 1818 * @param literal the string literal whose value is to be returned
1533 * @return the value of the given string literal 1819 * @return the value of the given string literal
1534 */ 1820 */
1535 String getStringValue(StringLiteral literal) { 1821 String getStringValue(StringLiteral literal) {
1536 StringBuffer builder = new StringBuffer(); 1822 StringBuffer builder = new StringBuffer();
1537 try { 1823 try {
1538 appendStringValue(builder, literal); 1824 appendStringValue(builder, literal);
1539 } on IllegalArgumentException catch (exception) { 1825 } on IllegalArgumentException catch (exception) {
1540 return null; 1826 return null;
1541 } 1827 }
1542 return builder.toString(); 1828 return builder.toString().trim();
1543 } 1829 }
1544 } 1830 }
1545 /** 1831 /**
1546 * Instances of the class {@code LibraryElementBuilder} build an element model f or a single library. 1832 * Instances of the class {@code LibraryElementBuilder} build an element model f or a single library.
1547 */ 1833 */
1548 class LibraryElementBuilder { 1834 class LibraryElementBuilder {
1549 /** 1835 /**
1550 * The analysis context in which the element model will be built. 1836 * The analysis context in which the element model will be built.
1551 */ 1837 */
1552 AnalysisContextImpl _analysisContext; 1838 AnalysisContextImpl _analysisContext;
(...skipping 25 matching lines...) Expand all
1578 */ 1864 */
1579 LibraryElementImpl buildLibrary(Library library) { 1865 LibraryElementImpl buildLibrary(Library library) {
1580 CompilationUnitBuilder builder = new CompilationUnitBuilder(_analysisContext , _errorListener); 1866 CompilationUnitBuilder builder = new CompilationUnitBuilder(_analysisContext , _errorListener);
1581 Source librarySource2 = library.librarySource; 1867 Source librarySource2 = library.librarySource;
1582 CompilationUnit definingCompilationUnit3 = library.definingCompilationUnit; 1868 CompilationUnit definingCompilationUnit3 = library.definingCompilationUnit;
1583 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit2(librarySource2, definingCompilationUnit3); 1869 CompilationUnitElementImpl definingCompilationUnitElement = builder.buildCom pilationUnit2(librarySource2, definingCompilationUnit3);
1584 NodeList<Directive> directives3 = definingCompilationUnit3.directives; 1870 NodeList<Directive> directives3 = definingCompilationUnit3.directives;
1585 LibraryIdentifier libraryNameNode = null; 1871 LibraryIdentifier libraryNameNode = null;
1586 bool hasPartDirective = false; 1872 bool hasPartDirective = false;
1587 FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement); 1873 FunctionElement entryPoint = findEntryPoint(definingCompilationUnitElement);
1588 List<ImportElement> imports = new List<ImportElement>();
1589 List<ExportElement> exports = new List<ExportElement>();
1590 List<Directive> directivesToResolve = new List<Directive>(); 1874 List<Directive> directivesToResolve = new List<Directive>();
1591 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>(); 1875 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>();
1592 for (Directive directive in directives3) { 1876 for (Directive directive in directives3) {
1593 if (directive is LibraryDirective) { 1877 if (directive is LibraryDirective) {
1594 if (libraryNameNode == null) { 1878 if (libraryNameNode == null) {
1595 libraryNameNode = ((directive as LibraryDirective)).name; 1879 libraryNameNode = ((directive as LibraryDirective)).name;
1596 directivesToResolve.add(directive); 1880 directivesToResolve.add(directive);
1597 } 1881 }
1598 } else if (directive is PartDirective) { 1882 } else if (directive is PartDirective) {
1599 hasPartDirective = true; 1883 hasPartDirective = true;
1600 StringLiteral partUri = ((directive as PartDirective)).uri; 1884 StringLiteral partUri = ((directive as PartDirective)).uri;
1601 Source partSource = library.getSource(partUri); 1885 Source partSource = library.getSource(partUri);
1602 if (partSource != null) { 1886 if (partSource != null) {
1603 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce); 1887 CompilationUnitElementImpl part = builder.buildCompilationUnit(partSou rce);
1604 String partLibraryName = getPartLibraryName(library, partSource, direc tivesToResolve); 1888 String partLibraryName = getPartLibraryName(library, partSource, direc tivesToResolve);
1605 if (partLibraryName == null) { 1889 if (partLibraryName == null) {
1606 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, ResolverErrorCode.MISSING_PART_OF_DIRECTIVE, [])); 1890 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, ResolverErrorCode.MISSING_PART_OF_DIRECTIVE, []));
1607 } else if (libraryNameNode == null) { 1891 } else if (libraryNameNode == null) {
1608 } else if (libraryNameNode.name != partLibraryName) { 1892 } else if (libraryNameNode.name != partLibraryName) {
1609 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, ResolverErrorCode.PART_WITH_WRONG_LIBRARY_NAME, [partL ibraryName])); 1893 _errorListener.onError(new AnalysisError.con2(librarySource2, partUr i.offset, partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [libraryN ameNode.name, partLibraryName]));
1610 } 1894 }
1611 if (entryPoint == null) { 1895 if (entryPoint == null) {
1612 entryPoint = findEntryPoint(part); 1896 entryPoint = findEntryPoint(part);
1613 } 1897 }
1614 directive.element = part; 1898 directive.element = part;
1615 sourcedCompilationUnits.add(part); 1899 sourcedCompilationUnits.add(part);
1616 } 1900 }
1617 } 1901 }
1618 } 1902 }
1619 if (hasPartDirective && libraryNameNode == null) { 1903 if (hasPartDirective && libraryNameNode == null) {
1620 _errorListener.onError(new AnalysisError.con1(librarySource2, ResolverErro rCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART, [])); 1904 _errorListener.onError(new AnalysisError.con1(librarySource2, ResolverErro rCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART, []));
1621 } 1905 }
1622 LibraryElementImpl libraryElement = new LibraryElementImpl(_analysisContext, libraryNameNode); 1906 LibraryElementImpl libraryElement = new LibraryElementImpl(_analysisContext, libraryNameNode);
1623 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 1907 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
1624 if (entryPoint != null) { 1908 if (entryPoint != null) {
1625 libraryElement.entryPoint = entryPoint; 1909 libraryElement.entryPoint = entryPoint;
1626 } 1910 }
1627 libraryElement.imports = new List.from(imports);
1628 libraryElement.exports = new List.from(exports);
1629 libraryElement.parts = new List.from(sourcedCompilationUnits); 1911 libraryElement.parts = new List.from(sourcedCompilationUnits);
1630 for (Directive directive in directivesToResolve) { 1912 for (Directive directive in directivesToResolve) {
1631 directive.element = libraryElement; 1913 directive.element = libraryElement;
1632 } 1914 }
1633 library.libraryElement = libraryElement; 1915 library.libraryElement = libraryElement;
1634 return libraryElement; 1916 return libraryElement;
1635 } 1917 }
1636 /** 1918 /**
1637 * Search the top-level functions defined in the given compilation unit for th e entry point. 1919 * Search the top-level functions defined in the given compilation unit for th e entry point.
1638 * @param element the compilation unit to be searched 1920 * @param element the compilation unit to be searched
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 /** 1957 /**
1676 * Instances of the class {@code LibraryResolver} are used to resolve one or mor e mutually dependent 1958 * Instances of the class {@code LibraryResolver} are used to resolve one or mor e mutually dependent
1677 * libraries within a single context. 1959 * libraries within a single context.
1678 */ 1960 */
1679 class LibraryResolver { 1961 class LibraryResolver {
1680 /** 1962 /**
1681 * The analysis context in which the libraries are being analyzed. 1963 * The analysis context in which the libraries are being analyzed.
1682 */ 1964 */
1683 AnalysisContextImpl _analysisContext; 1965 AnalysisContextImpl _analysisContext;
1684 /** 1966 /**
1685 * The listener to which analysis errors will be reported. 1967 * The listener to which analysis errors will be reported, this error listener is either
1968 * references {@link #recordingErrorListener}, or it unions the passed{@link A nalysisErrorListener} with the {@link #recordingErrorListener}.
1686 */ 1969 */
1687 AnalysisErrorListener _errorListener; 1970 AnalysisErrorListener _errorListener;
1688 /** 1971 /**
1972 * This error listener is used by the resolver to be able to call the listener and get back the
1973 * set of errors for each {@link Source}.
1974 * @see #recordErrors()
1975 */
1976 RecordingErrorListener _recordingErrorListener;
1977 /**
1689 * A source object representing the core library (dart:core). 1978 * A source object representing the core library (dart:core).
1690 */ 1979 */
1691 Source _coreLibrarySource; 1980 Source _coreLibrarySource;
1692 /** 1981 /**
1693 * The object representing the core library. 1982 * The object representing the core library.
1694 */ 1983 */
1695 Library _coreLibrary; 1984 Library _coreLibrary;
1696 /** 1985 /**
1697 * The object used to access the types from the core library. 1986 * The object used to access the types from the core library.
1698 */ 1987 */
1699 TypeProvider _typeProvider; 1988 TypeProvider _typeProvider;
1700 /** 1989 /**
1701 * A table mapping library sources to the information being maintained for tho se libraries. 1990 * A table mapping library sources to the information being maintained for tho se libraries.
1702 */ 1991 */
1703 Map<Source, Library> _libraryMap = new Map<Source, Library>(); 1992 Map<Source, Library> _libraryMap = new Map<Source, Library>();
1704 /** 1993 /**
1705 * A collection containing the libraries that are being resolved together. 1994 * A collection containing the libraries that are being resolved together.
1706 */ 1995 */
1707 Set<Library> _librariesInCycles; 1996 Set<Library> _librariesInCycles;
1708 /** 1997 /**
1709 * Initialize a newly created library resolver to resolve libraries within the given context. 1998 * Initialize a newly created library resolver to resolve libraries within the given context.
1710 * @param analysisContext the analysis context in which the library is being a nalyzed 1999 * @param analysisContext the analysis context in which the library is being a nalyzed
2000 */
2001 LibraryResolver.con1(AnalysisContextImpl analysisContext) {
2002 _jtd_constructor_220_impl(analysisContext);
2003 }
2004 _jtd_constructor_220_impl(AnalysisContextImpl analysisContext) {
2005 _jtd_constructor_221_impl(analysisContext, null);
2006 }
2007 /**
2008 * Initialize a newly created library resolver to resolve libraries within the given context.
2009 * @param analysisContext the analysis context in which the library is being a nalyzed
1711 * @param errorListener the listener to which analysis errors will be reported 2010 * @param errorListener the listener to which analysis errors will be reported
1712 */ 2011 */
1713 LibraryResolver(AnalysisContextImpl analysisContext, AnalysisErrorListener err orListener) { 2012 LibraryResolver.con2(AnalysisContextImpl analysisContext2, AnalysisErrorListen er additionalAnalysisErrorListener) {
1714 this._analysisContext = analysisContext; 2013 _jtd_constructor_221_impl(analysisContext2, additionalAnalysisErrorListener) ;
1715 this._errorListener = errorListener; 2014 }
1716 _coreLibrarySource = analysisContext.sourceFactory.forUri(LibraryElementBuil der.CORE_LIBRARY_URI); 2015 _jtd_constructor_221_impl(AnalysisContextImpl analysisContext2, AnalysisErrorL istener additionalAnalysisErrorListener) {
2016 this._analysisContext = analysisContext2;
2017 this._recordingErrorListener = new RecordingErrorListener();
2018 if (additionalAnalysisErrorListener == null) {
2019 this._errorListener = _recordingErrorListener;
2020 } else {
2021 this._errorListener = new AnalysisErrorListener_4(this, additionalAnalysis ErrorListener);
2022 }
2023 _coreLibrarySource = analysisContext2.sourceFactory.forUri(LibraryElementBui lder.CORE_LIBRARY_URI);
1717 } 2024 }
1718 /** 2025 /**
1719 * Return the analysis context in which the libraries are being analyzed. 2026 * Return the analysis context in which the libraries are being analyzed.
1720 * @return the analysis context in which the libraries are being analyzed 2027 * @return the analysis context in which the libraries are being analyzed
1721 */ 2028 */
1722 AnalysisContextImpl get analysisContext => _analysisContext; 2029 AnalysisContextImpl get analysisContext => _analysisContext;
1723 /** 2030 /**
1724 * Return the listener to which analysis errors will be reported. 2031 * Return the listener to which analysis errors will be reported.
1725 * @return the listener to which analysis errors will be reported 2032 * @return the listener to which analysis errors will be reported
1726 */ 2033 */
(...skipping 17 matching lines...) Expand all
1744 _coreLibrary = createLibrary(_coreLibrarySource); 2051 _coreLibrary = createLibrary(_coreLibrarySource);
1745 } 2052 }
1746 computeLibraryDependencies(targetLibrary); 2053 computeLibraryDependencies(targetLibrary);
1747 _librariesInCycles = computeLibrariesInCycles(targetLibrary); 2054 _librariesInCycles = computeLibrariesInCycles(targetLibrary);
1748 buildElementModels(); 2055 buildElementModels();
1749 buildDirectiveModels(); 2056 buildDirectiveModels();
1750 _typeProvider = new TypeProviderImpl(_coreLibrary.libraryElement); 2057 _typeProvider = new TypeProviderImpl(_coreLibrary.libraryElement);
1751 buildTypeHierarchies(); 2058 buildTypeHierarchies();
1752 resolveReferencesAndTypes(); 2059 resolveReferencesAndTypes();
1753 if (fullAnalysis) { 2060 if (fullAnalysis) {
2061 runAdditionalAnalyses();
1754 } 2062 }
1755 recordLibraryElements(); 2063 recordLibraryElements();
2064 recordErrors();
1756 return targetLibrary.libraryElement; 2065 return targetLibrary.libraryElement;
1757 } 2066 }
1758 /** 2067 /**
1759 * Add a dependency to the given map from the referencing library to the refer enced library. 2068 * Add a dependency to the given map from the referencing library to the refer enced library.
1760 * @param dependencyMap the map to which the dependency is to be added 2069 * @param dependencyMap the map to which the dependency is to be added
1761 * @param referencingLibrary the library that references the referenced librar y 2070 * @param referencingLibrary the library that references the referenced librar y
1762 * @param referencedLibrary the library referenced by the referencing library 2071 * @param referencedLibrary the library referenced by the referencing library
1763 */ 2072 */
1764 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref erencingLibrary, Library referencedLibrary) { 2073 void addDependencyToMap(Map<Library, List<Library>> dependencyMap, Library ref erencingLibrary, Library referencedLibrary) {
1765 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; 2074 List<Library> dependentLibraries = dependencyMap[referencedLibrary];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 * @throws AnalysisException if the defining compilation unit for any of the l ibraries could not 2142 * @throws AnalysisException if the defining compilation unit for any of the l ibraries could not
1834 * be accessed 2143 * be accessed
1835 */ 2144 */
1836 void buildDirectiveModels() { 2145 void buildDirectiveModels() {
1837 for (Library library in _librariesInCycles) { 2146 for (Library library in _librariesInCycles) {
1838 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>(); 2147 Map<String, PrefixElementImpl> nameToPrefixMap = new Map<String, PrefixEle mentImpl>();
1839 List<ImportElement> imports = new List<ImportElement>(); 2148 List<ImportElement> imports = new List<ImportElement>();
1840 List<ExportElement> exports = new List<ExportElement>(); 2149 List<ExportElement> exports = new List<ExportElement>();
1841 for (Directive directive in library.definingCompilationUnit.directives) { 2150 for (Directive directive in library.definingCompilationUnit.directives) {
1842 if (directive is ImportDirective) { 2151 if (directive is ImportDirective) {
1843 ImportDirective importDirective = (directive as ImportDirective); 2152 ImportDirective importDirective = directive as ImportDirective;
1844 Library importedLibrary = library.getImport(importDirective); 2153 Library importedLibrary = library.getImport(importDirective);
1845 ImportElementImpl importElement = new ImportElementImpl(); 2154 if (importedLibrary != null) {
1846 importElement.combinators = buildCombinators(importDirective); 2155 ImportElementImpl importElement = new ImportElementImpl();
1847 LibraryElement importedLibraryElement = importedLibrary.libraryElement ; 2156 importElement.combinators = buildCombinators(importDirective);
1848 if (importedLibraryElement != null) { 2157 LibraryElement importedLibraryElement = importedLibrary.libraryEleme nt;
1849 importElement.importedLibrary = importedLibraryElement; 2158 if (importedLibraryElement != null) {
1850 directive.element = importedLibraryElement; 2159 importElement.importedLibrary = importedLibraryElement;
2160 }
2161 SimpleIdentifier prefixNode = ((directive as ImportDirective)).prefi x;
2162 if (prefixNode != null) {
2163 String prefixName = prefixNode.name;
2164 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
2165 if (prefix == null) {
2166 prefix = new PrefixElementImpl(prefixNode);
2167 nameToPrefixMap[prefixName] = prefix;
2168 }
2169 importElement.prefix = prefix;
2170 }
2171 directive.element = importElement;
2172 imports.add(importElement);
1851 } 2173 }
1852 SimpleIdentifier prefixNode = ((directive as ImportDirective)).prefix;
1853 if (prefixNode != null) {
1854 String prefixName = prefixNode.name;
1855 PrefixElementImpl prefix = nameToPrefixMap[prefixName];
1856 if (prefix == null) {
1857 prefix = new PrefixElementImpl(prefixNode);
1858 nameToPrefixMap[prefixName] = prefix;
1859 }
1860 importElement.prefix = prefix;
1861 }
1862 imports.add(importElement);
1863 } else if (directive is ExportDirective) { 2174 } else if (directive is ExportDirective) {
1864 ExportDirective exportDirective = (directive as ExportDirective); 2175 ExportDirective exportDirective = directive as ExportDirective;
1865 ExportElementImpl exportElement = new ExportElementImpl(); 2176 ExportElementImpl exportElement = new ExportElementImpl();
1866 exportElement.combinators = buildCombinators(exportDirective); 2177 exportElement.combinators = buildCombinators(exportDirective);
1867 LibraryElement exportedLibrary = library.getExport(exportDirective).li braryElement; 2178 Library exportedLibrary = library.getExport(exportDirective);
1868 if (exportedLibrary != null) { 2179 if (exportedLibrary != null) {
1869 exportElement.exportedLibrary = exportedLibrary; 2180 LibraryElement exportedLibraryElement = exportedLibrary.libraryEleme nt;
1870 directive.element = exportedLibrary; 2181 if (exportedLibraryElement != null) {
2182 exportElement.exportedLibrary = exportedLibraryElement;
2183 }
2184 directive.element = exportElement;
2185 exports.add(exportElement);
1871 } 2186 }
1872 exports.add(exportElement);
1873 } 2187 }
1874 } 2188 }
1875 Source librarySource3 = library.librarySource; 2189 Source librarySource3 = library.librarySource;
1876 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource3 ) { 2190 if (!library.explicitlyImportsCore && _coreLibrarySource != librarySource3 ) {
1877 ImportElementImpl importElement = new ImportElementImpl(); 2191 ImportElementImpl importElement = new ImportElementImpl();
1878 importElement.importedLibrary = _coreLibrary.libraryElement; 2192 importElement.importedLibrary = _coreLibrary.libraryElement;
1879 importElement.synthetic = true; 2193 importElement.synthetic = true;
1880 imports.add(importElement); 2194 imports.add(importElement);
1881 } 2195 }
1882 LibraryElementImpl libraryElement3 = library.libraryElement; 2196 LibraryElementImpl libraryElement3 = library.libraryElement;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 */ 2246 */
1933 Set<Library> computeLibrariesInCycles(Library library) { 2247 Set<Library> computeLibrariesInCycles(Library library) {
1934 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library); 2248 Map<Library, List<Library>> dependencyMap = computeDependencyMap(library);
1935 Set<Library> librariesInCycle = new Set<Library>(); 2249 Set<Library> librariesInCycle = new Set<Library>();
1936 addLibrariesInCycle(library, librariesInCycle, dependencyMap); 2250 addLibrariesInCycle(library, librariesInCycle, dependencyMap);
1937 return librariesInCycle; 2251 return librariesInCycle;
1938 } 2252 }
1939 /** 2253 /**
1940 * Recursively traverse the libraries reachable from the given library, creati ng instances of the 2254 * Recursively traverse the libraries reachable from the given library, creati ng instances of the
1941 * class {@link Library} to represent them, and record the references in the l ibrary objects. 2255 * class {@link Library} to represent them, and record the references in the l ibrary objects.
1942 * @param library the library to be processed to find libaries that have not y et been traversed 2256 * @param library the library to be processed to find libraries that have not yet been traversed
1943 * @throws AnalysisException if some portion of the library graph could not be traversed 2257 * @throws AnalysisException if some portion of the library graph could not be traversed
1944 */ 2258 */
1945 void computeLibraryDependencies(Library library) { 2259 void computeLibraryDependencies(Library library) {
1946 bool explicitlyImportsCore = false; 2260 bool explicitlyImportsCore = false;
1947 CompilationUnit unit = library.definingCompilationUnit; 2261 CompilationUnit unit = library.definingCompilationUnit;
1948 for (Directive directive in unit.directives) { 2262 for (Directive directive in unit.directives) {
1949 if (directive is ImportDirective) { 2263 if (directive is ImportDirective) {
1950 ImportDirective importDirective = (directive as ImportDirective); 2264 ImportDirective importDirective = directive as ImportDirective;
1951 Source importedSource = library.getSource(importDirective.uri); 2265 Source importedSource = library.getSource(importDirective.uri);
1952 if (importedSource == _coreLibrarySource) { 2266 if (importedSource != null) {
1953 explicitlyImportsCore = true; 2267 if (importedSource == _coreLibrarySource) {
2268 explicitlyImportsCore = true;
2269 }
2270 Library importedLibrary = _libraryMap[importedSource];
2271 if (importedLibrary == null) {
2272 importedLibrary = createLibraryOrNull(importedSource);
2273 if (importedLibrary != null) {
2274 computeLibraryDependencies(importedLibrary);
2275 }
2276 }
2277 if (importedLibrary != null) {
2278 library.addImport(importDirective, importedLibrary);
2279 }
1954 } 2280 }
1955 Library importedLibrary = _libraryMap[importedSource]; 2281 } else if (directive is ExportDirective) {
1956 if (importedLibrary == null) { 2282 ExportDirective exportDirective = directive as ExportDirective;
1957 importedLibrary = createLibrary(importedSource); 2283 Source exportedSource = library.getSource(exportDirective.uri);
1958 computeLibraryDependencies(importedLibrary); 2284 if (exportedSource != null) {
2285 Library exportedLibrary = _libraryMap[exportedSource];
2286 if (exportedLibrary == null) {
2287 exportedLibrary = createLibraryOrNull(exportedSource);
2288 if (exportedLibrary != null) {
2289 computeLibraryDependencies(exportedLibrary);
2290 }
2291 }
2292 if (exportedLibrary != null) {
2293 library.addExport(exportDirective, exportedLibrary);
2294 }
1959 } 2295 }
1960 library.addImport(importDirective, importedLibrary);
1961 } else if (directive is ExportDirective) {
1962 ExportDirective exportDirective = (directive as ExportDirective);
1963 Source exportedSource = library.getSource(exportDirective.uri);
1964 Library exportedLibrary = _libraryMap[exportedSource];
1965 if (exportedLibrary == null) {
1966 exportedLibrary = createLibrary(exportedSource);
1967 computeLibraryDependencies(exportedLibrary);
1968 }
1969 library.addExport(exportDirective, exportedLibrary);
1970 } 2296 }
1971 } 2297 }
1972 library.explicitlyImportsCore = explicitlyImportsCore; 2298 library.explicitlyImportsCore = explicitlyImportsCore;
1973 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) { 2299 if (!explicitlyImportsCore && _coreLibrarySource != library.librarySource) {
1974 Library importedLibrary = _libraryMap[_coreLibrarySource]; 2300 Library importedLibrary = _libraryMap[_coreLibrarySource];
1975 if (importedLibrary == null) { 2301 if (importedLibrary == null) {
1976 importedLibrary = createLibrary(_coreLibrarySource); 2302 importedLibrary = createLibraryOrNull(_coreLibrarySource);
1977 computeLibraryDependencies(importedLibrary); 2303 if (importedLibrary != null) {
2304 computeLibraryDependencies(importedLibrary);
2305 }
1978 } 2306 }
1979 } 2307 }
1980 } 2308 }
1981 /** 2309 /**
1982 * Create an object to represent the information about the library defined by the compilation unit 2310 * Create an object to represent the information about the library defined by the compilation unit
1983 * with the given source. 2311 * with the given source.
1984 * @param librarySource the source of the library's defining compilation unit 2312 * @param librarySource the source of the library's defining compilation unit
1985 * @return the library object that was created 2313 * @return the library object that was created
2314 * @throws AnalysisException if the library source is not valid
1986 */ 2315 */
1987 Library createLibrary(Source librarySource) { 2316 Library createLibrary(Source librarySource) {
1988 Library library = new Library(_analysisContext, _errorListener, librarySourc e); 2317 Library library = new Library(_analysisContext, _errorListener, librarySourc e);
2318 library.definingCompilationUnit;
1989 _libraryMap[librarySource] = library; 2319 _libraryMap[librarySource] = library;
1990 return library; 2320 return library;
1991 } 2321 }
2322 /**
2323 * Create an object to represent the information about the library defined by the compilation unit
2324 * with the given source. Return the library object that was created, or {@cod e null} if the
2325 * source is not valid.
2326 * @param librarySource the source of the library's defining compilation unit
2327 * @return the library object that was created
2328 */
2329 Library createLibraryOrNull(Source librarySource) {
2330 Library library = new Library(_analysisContext, _errorListener, librarySourc e);
2331 try {
2332 library.definingCompilationUnit;
2333 } on AnalysisException catch (exception) {
2334 return null;
2335 }
2336 _libraryMap[librarySource] = library;
2337 return library;
2338 }
1992 /** 2339 /**
1993 * Return an array containing the lexical identifiers associated with the node s in the given list. 2340 * Return an array containing the lexical identifiers associated with the node s in the given list.
1994 * @param names the AST nodes representing the identifiers 2341 * @param names the AST nodes representing the identifiers
1995 * @return the lexical identifiers associated with the nodes in the list 2342 * @return the lexical identifiers associated with the nodes in the list
1996 */ 2343 */
1997 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) { 2344 List<String> getIdentifiers(NodeList<SimpleIdentifier> names) {
1998 int count = names.length; 2345 int count = names.length;
1999 List<String> identifiers = new List<String>(count); 2346 List<String> identifiers = new List<String>(count);
2000 for (int i = 0; i < count; i++) { 2347 for (int i = 0; i < count; i++) {
2001 identifiers[i] = names[i].name; 2348 identifiers[i] = names[i].name;
2002 } 2349 }
2003 return identifiers; 2350 return identifiers;
2004 } 2351 }
2005 /** 2352 /**
2353 * For each library, loop through the set of all {@link CompilationUnit}s reco rding the set of
2354 * resolution errors on each unit.
2355 */
2356 void recordErrors() {
2357 for (Library library in _librariesInCycles) {
2358 try {
2359 CompilationUnit definingUnit = library.definingCompilationUnit;
2360 definingUnit.resolutionErrors = _recordingErrorListener.getErrors2(libra ry.librarySource);
2361 } on AnalysisException catch (e) {
2362 throw new AnalysisException();
2363 }
2364 Set<Source> sources = library.compilationUnitSources;
2365 for (Source source in sources) {
2366 try {
2367 CompilationUnit unit = library.getAST(source);
2368 unit.resolutionErrors = _recordingErrorListener.getErrors2(source);
2369 } on JavaException catch (e) {
2370 throw new AnalysisException();
2371 }
2372 }
2373 }
2374 }
2375 /**
2006 * As the final step in the process, record the resolved element models with t he analysis context. 2376 * As the final step in the process, record the resolved element models with t he analysis context.
2007 */ 2377 */
2008 void recordLibraryElements() { 2378 void recordLibraryElements() {
2009 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>(); 2379 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>();
2010 for (Library library in _librariesInCycles) { 2380 for (Library library in _librariesInCycles) {
2011 elementMap[library.librarySource] = library.libraryElement; 2381 elementMap[library.librarySource] = library.libraryElement;
2012 } 2382 }
2013 _analysisContext.recordLibraryElements(elementMap); 2383 _analysisContext.recordLibraryElements(elementMap);
2014 } 2384 }
2015 /** 2385 /**
(...skipping 11 matching lines...) Expand all
2027 * @param library the library to be resolved 2397 * @param library the library to be resolved
2028 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 2398 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
2029 * the library cannot be analyzed 2399 * the library cannot be analyzed
2030 */ 2400 */
2031 void resolveReferencesAndTypes2(Library library) { 2401 void resolveReferencesAndTypes2(Library library) {
2032 for (Source source in library.compilationUnitSources) { 2402 for (Source source in library.compilationUnitSources) {
2033 ResolverVisitor visitor = new ResolverVisitor(library, source, _typeProvid er); 2403 ResolverVisitor visitor = new ResolverVisitor(library, source, _typeProvid er);
2034 library.getAST(source).accept(visitor); 2404 library.getAST(source).accept(visitor);
2035 } 2405 }
2036 } 2406 }
2407 /**
2408 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er rorVerifier}analysis in the current cycle.
2409 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
2410 * the library cannot be analyzed
2411 */
2412 void runAdditionalAnalyses() {
2413 for (Library library in _librariesInCycles) {
2414 runAdditionalAnalyses2(library);
2415 }
2416 }
2417 /**
2418 * Run additional analyses, such as the {@link ConstantVerifier} and {@link Er rorVerifier}analysis in the given library.
2419 * @param library the library to have the extra analyses processes run
2420 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
2421 * the library cannot be analyzed
2422 */
2423 void runAdditionalAnalyses2(Library library) {
2424 for (Source source in library.compilationUnitSources) {
2425 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
2426 CompilationUnit unit = library.getAST(source);
2427 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _typeProvid er);
2428 unit.accept(errorVerifier);
2429 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter);
2430 unit.accept(constantVerifier);
2431 }
2432 }
2433 }
2434 class AnalysisErrorListener_4 implements AnalysisErrorListener {
2435 final LibraryResolver LibraryResolver_this;
2436 AnalysisErrorListener additionalAnalysisErrorListener;
2437 AnalysisErrorListener_4(this.LibraryResolver_this, this.additionalAnalysisErro rListener);
2438 void onError(AnalysisError error) {
2439 additionalAnalysisErrorListener.onError(error);
2440 LibraryResolver_this._recordingErrorListener.onError(error);
2441 }
2037 } 2442 }
2038 /** 2443 /**
2039 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes within a single 2444 * Instances of the class {@code ResolverVisitor} are used to resolve the nodes within a single
2040 * compilation unit. 2445 * compilation unit.
2041 */ 2446 */
2042 class ResolverVisitor extends ScopedVisitor { 2447 class ResolverVisitor extends ScopedVisitor {
2043 /** 2448 /**
2044 * The object used to resolve the element associated with the current node. 2449 * The object used to resolve the element associated with the current node.
2045 */ 2450 */
2046 ElementResolver _elementResolver; 2451 ElementResolver _elementResolver;
(...skipping 30 matching lines...) Expand all
2077 } finally { 2482 } finally {
2078 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; 2483 _typeAnalyzer.thisType = outerType == null ? null : outerType.type;
2079 _enclosingClass = outerType; 2484 _enclosingClass = outerType;
2080 } 2485 }
2081 return null; 2486 return null;
2082 } 2487 }
2083 Object visitFunctionDeclaration(FunctionDeclaration node) { 2488 Object visitFunctionDeclaration(FunctionDeclaration node) {
2084 ExecutableElement outerFunction = _enclosingFunction; 2489 ExecutableElement outerFunction = _enclosingFunction;
2085 try { 2490 try {
2086 SimpleIdentifier functionName = node.name; 2491 SimpleIdentifier functionName = node.name;
2087 _enclosingFunction = (functionName.element as ExecutableElement); 2492 _enclosingFunction = functionName.element as ExecutableElement;
2088 super.visitFunctionDeclaration(node); 2493 super.visitFunctionDeclaration(node);
2089 } finally { 2494 } finally {
2090 _enclosingFunction = outerFunction; 2495 _enclosingFunction = outerFunction;
2091 } 2496 }
2092 return null; 2497 return null;
2093 } 2498 }
2094 Object visitFunctionExpression(FunctionExpression node) { 2499 Object visitFunctionExpression(FunctionExpression node) {
2095 ExecutableElement outerFunction = _enclosingFunction; 2500 ExecutableElement outerFunction = _enclosingFunction;
2096 try { 2501 try {
2097 _enclosingFunction = node.element; 2502 _enclosingFunction = node.element;
2098 super.visitFunctionExpression(node); 2503 super.visitFunctionExpression(node);
2099 } finally { 2504 } finally {
2100 _enclosingFunction = outerFunction; 2505 _enclosingFunction = outerFunction;
2101 } 2506 }
2102 return null; 2507 return null;
2103 } 2508 }
2509 Object visitLabel(Label node) => null;
2104 Object visitLibraryIdentifier(LibraryIdentifier node) => null; 2510 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
2105 Object visitMethodDeclaration(MethodDeclaration node) { 2511 Object visitMethodDeclaration(MethodDeclaration node) {
2106 ExecutableElement outerFunction = _enclosingFunction; 2512 ExecutableElement outerFunction = _enclosingFunction;
2107 try { 2513 try {
2108 _enclosingFunction = node.element; 2514 _enclosingFunction = node.element;
2109 super.visitMethodDeclaration(node); 2515 super.visitMethodDeclaration(node);
2110 } finally { 2516 } finally {
2111 _enclosingFunction = outerFunction; 2517 _enclosingFunction = outerFunction;
2112 } 2518 }
2113 return null; 2519 return null;
2114 } 2520 }
2115 Object visitNode(ASTNode node) { 2521 Object visitNode(ASTNode node) {
2116 node.visitChildren(this); 2522 node.visitChildren(this);
2117 node.accept(_elementResolver); 2523 node.accept(_elementResolver);
2118 node.accept(_typeAnalyzer); 2524 node.accept(_typeAnalyzer);
2119 return null; 2525 return null;
2120 } 2526 }
2121 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 2527 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
2122 SimpleIdentifier prefix6 = node.prefix; 2528 SimpleIdentifier prefix7 = node.prefix;
2123 if (prefix6 != null) { 2529 if (prefix7 != null) {
2124 prefix6.accept(this); 2530 prefix7.accept(this);
2125 } 2531 }
2126 node.accept(_elementResolver); 2532 node.accept(_elementResolver);
2127 node.accept(_typeAnalyzer); 2533 node.accept(_typeAnalyzer);
2128 return null; 2534 return null;
2129 } 2535 }
2130 Object visitPropertyAccess(PropertyAccess node) { 2536 Object visitPropertyAccess(PropertyAccess node) {
2131 Expression target5 = node.target; 2537 Expression target4 = node.target;
2132 if (target5 != null) { 2538 if (target4 != null) {
2133 target5.accept(this); 2539 target4.accept(this);
2134 } 2540 }
2135 node.accept(_elementResolver); 2541 node.accept(_elementResolver);
2136 node.accept(_typeAnalyzer); 2542 node.accept(_typeAnalyzer);
2137 return null; 2543 return null;
2138 } 2544 }
2139 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 2545 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
2546 ArgumentList argumentList10 = node.argumentList;
2547 if (argumentList10 != null) {
2548 argumentList10.accept(this);
2549 }
2550 node.accept(_elementResolver);
2551 node.accept(_typeAnalyzer);
2552 return null;
2553 }
2554 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2140 ArgumentList argumentList11 = node.argumentList; 2555 ArgumentList argumentList11 = node.argumentList;
2141 if (argumentList11 != null) { 2556 if (argumentList11 != null) {
2142 argumentList11.accept(this); 2557 argumentList11.accept(this);
2143 } 2558 }
2144 node.accept(_elementResolver); 2559 node.accept(_elementResolver);
2145 node.accept(_typeAnalyzer); 2560 node.accept(_typeAnalyzer);
2146 return null;
2147 }
2148 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
2149 ArgumentList argumentList12 = node.argumentList;
2150 if (argumentList12 != null) {
2151 argumentList12.accept(this);
2152 }
2153 node.accept(_elementResolver);
2154 node.accept(_typeAnalyzer);
2155 return null; 2561 return null;
2156 } 2562 }
2157 Object visitTypeName(TypeName node) => null; 2563 Object visitTypeName(TypeName node) => null;
2158 /** 2564 /**
2159 * Return the class element representing the class containing the current node , or {@code null} if 2565 * Return the class element representing the class containing the current node , or {@code null} if
2160 * the current node is not contained in a class. 2566 * the current node is not contained in a class.
2161 * @return the class element representing the class containing the current nod e 2567 * @return the class element representing the class containing the current nod e
2162 */ 2568 */
2163 ClassElement get enclosingClass => _enclosingClass; 2569 ClassElement get enclosingClass => _enclosingClass;
2164 /** 2570 /**
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 LabelScope outerScope = _labelScope; 2671 LabelScope outerScope = _labelScope;
2266 _labelScope = new LabelScope.con1(outerScope, false, false); 2672 _labelScope = new LabelScope.con1(outerScope, false, false);
2267 try { 2673 try {
2268 super.visitDoStatement(node); 2674 super.visitDoStatement(node);
2269 } finally { 2675 } finally {
2270 _labelScope = outerScope; 2676 _labelScope = outerScope;
2271 } 2677 }
2272 return null; 2678 return null;
2273 } 2679 }
2274 Object visitForEachStatement(ForEachStatement node) { 2680 Object visitForEachStatement(ForEachStatement node) {
2275 LabelScope outerScope = _labelScope; 2681 LabelScope outerLabelScope = _labelScope;
2276 _labelScope = new LabelScope.con1(outerScope, false, false); 2682 _labelScope = new LabelScope.con1(outerLabelScope, false, false);
2683 Scope outerNameScope = _nameScope;
2684 _nameScope = new EnclosedScope(_nameScope);
2277 try { 2685 try {
2278 super.visitForEachStatement(node); 2686 super.visitForEachStatement(node);
2279 } finally { 2687 } finally {
2280 _labelScope = outerScope; 2688 _nameScope = outerNameScope;
2689 _labelScope = outerLabelScope;
2281 } 2690 }
2282 return null; 2691 return null;
2283 } 2692 }
2284 Object visitForStatement(ForStatement node) { 2693 Object visitForStatement(ForStatement node) {
2285 LabelScope outerScope = _labelScope; 2694 LabelScope outerLabelScope = _labelScope;
2286 _labelScope = new LabelScope.con1(outerScope, false, false); 2695 _labelScope = new LabelScope.con1(outerLabelScope, false, false);
2696 Scope outerNameScope = _nameScope;
2697 _nameScope = new EnclosedScope(_nameScope);
2287 try { 2698 try {
2288 super.visitForStatement(node); 2699 super.visitForStatement(node);
2289 } finally { 2700 } finally {
2290 _labelScope = outerScope; 2701 _nameScope = outerNameScope;
2702 _labelScope = outerLabelScope;
2291 } 2703 }
2292 return null; 2704 return null;
2293 } 2705 }
2294 Object visitFunctionDeclaration(FunctionDeclaration node) { 2706 Object visitFunctionDeclaration(FunctionDeclaration node) {
2295 FunctionElement function = node.element; 2707 ExecutableElement function = node.element;
2296 Scope outerScope = _nameScope; 2708 Scope outerScope = _nameScope;
2297 try { 2709 try {
2298 _nameScope = new FunctionScope(_nameScope, function); 2710 _nameScope = new FunctionScope(_nameScope, function);
2299 super.visitFunctionDeclaration(node); 2711 super.visitFunctionDeclaration(node);
2300 } finally { 2712 } finally {
2301 _nameScope = outerScope; 2713 _nameScope = outerScope;
2302 } 2714 }
2303 _nameScope.define(function); 2715 if (function.enclosingElement is! CompilationUnitElement) {
2716 _nameScope.define(function);
2717 }
2304 return null; 2718 return null;
2305 } 2719 }
2306 Object visitFunctionExpression(FunctionExpression node) { 2720 Object visitFunctionExpression(FunctionExpression node) {
2307 Scope outerScope = _nameScope; 2721 Scope outerScope = _nameScope;
2308 try { 2722 try {
2309 _nameScope = new FunctionScope(_nameScope, node.element); 2723 ExecutableElement functionElement = node.element;
2724 if (functionElement == null) {
2725 } else {
2726 _nameScope = new FunctionScope(_nameScope, functionElement);
2727 }
2310 super.visitFunctionExpression(node); 2728 super.visitFunctionExpression(node);
2311 } finally { 2729 } finally {
2312 _nameScope = outerScope; 2730 _nameScope = outerScope;
2313 } 2731 }
2314 return null; 2732 return null;
2315 } 2733 }
2316 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 2734 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
2317 Scope outerScope = _nameScope; 2735 Scope outerScope = _nameScope;
2318 try { 2736 try {
2319 _nameScope = new FunctionTypeScope(_nameScope, node.element); 2737 _nameScope = new FunctionTypeScope(_nameScope, node.element);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2366 _labelScope = outerLabelScope; 2784 _labelScope = outerLabelScope;
2367 } 2785 }
2368 return null; 2786 return null;
2369 } 2787 }
2370 Object visitSwitchStatement(SwitchStatement node) { 2788 Object visitSwitchStatement(SwitchStatement node) {
2371 LabelScope outerScope = _labelScope; 2789 LabelScope outerScope = _labelScope;
2372 _labelScope = new LabelScope.con1(outerScope, true, false); 2790 _labelScope = new LabelScope.con1(outerScope, true, false);
2373 for (SwitchMember member in node.members) { 2791 for (SwitchMember member in node.members) {
2374 for (Label label in member.labels) { 2792 for (Label label in member.labels) {
2375 SimpleIdentifier labelName = label.label; 2793 SimpleIdentifier labelName = label.label;
2376 LabelElement labelElement = (labelName.element as LabelElement); 2794 LabelElement labelElement = labelName.element as LabelElement;
2377 _labelScope = new LabelScope.con2(outerScope, labelName.name, labelEleme nt); 2795 _labelScope = new LabelScope.con2(outerScope, labelName.name, labelEleme nt);
2378 } 2796 }
2379 } 2797 }
2380 try { 2798 try {
2381 super.visitSwitchStatement(node); 2799 super.visitSwitchStatement(node);
2382 } finally { 2800 } finally {
2383 _labelScope = outerScope; 2801 _labelScope = outerScope;
2384 } 2802 }
2385 return null; 2803 return null;
2386 } 2804 }
2387 Object visitVariableDeclaration(VariableDeclaration node) { 2805 Object visitVariableDeclaration(VariableDeclaration node) {
2388 if (node.parent.parent is! TopLevelVariableDeclaration) { 2806 if (node.parent.parent is! TopLevelVariableDeclaration && node.parent.parent is! FieldDeclaration) {
2389 VariableElement element19 = node.element; 2807 VariableElement element22 = node.element;
2390 if (element19 != null) { 2808 if (element22 != null) {
2391 _nameScope.define(element19); 2809 _nameScope.define(element22);
2392 } 2810 }
2393 } 2811 }
2394 super.visitVariableDeclaration(node); 2812 super.visitVariableDeclaration(node);
2395 return null; 2813 return null;
2396 } 2814 }
2397 Object visitWhileStatement(WhileStatement node) { 2815 Object visitWhileStatement(WhileStatement node) {
2398 LabelScope outerScope = _labelScope; 2816 LabelScope outerScope = _labelScope;
2399 _labelScope = new LabelScope.con1(outerScope, false, false); 2817 _labelScope = new LabelScope.con1(outerScope, false, false);
2400 try { 2818 try {
2401 super.visitWhileStatement(node); 2819 super.visitWhileStatement(node);
(...skipping 11 matching lines...) Expand all
2413 * Return the name scope in which the current node is being resolved. 2831 * Return the name scope in which the current node is being resolved.
2414 * @return the name scope in which the current node is being resolved 2832 * @return the name scope in which the current node is being resolved
2415 */ 2833 */
2416 Scope get nameScope => _nameScope; 2834 Scope get nameScope => _nameScope;
2417 /** 2835 /**
2418 * Report an error with the given error code and arguments. 2836 * Report an error with the given error code and arguments.
2419 * @param errorCode the error code of the error to be reported 2837 * @param errorCode the error code of the error to be reported
2420 * @param node the node specifying the location of the error 2838 * @param node the node specifying the location of the error
2421 * @param arguments the arguments to the error, used to compose the error mess age 2839 * @param arguments the arguments to the error, used to compose the error mess age
2422 */ 2840 */
2423 void reportError(ResolverErrorCode errorCode, ASTNode node, List<Object> argum ents) { 2841 void reportError(ErrorCode errorCode, ASTNode node, List<Object> arguments) {
2424 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len gth, errorCode, [arguments])); 2842 _errorListener.onError(new AnalysisError.con2(_source, node.offset, node.len gth, errorCode, [arguments]));
2425 } 2843 }
2426 /** 2844 /**
2427 * Report an error with the given error code and arguments. 2845 * Report an error with the given error code and arguments.
2428 * @param errorCode the error code of the error to be reported 2846 * @param errorCode the error code of the error to be reported
2429 * @param token the token specifying the location of the error 2847 * @param token the token specifying the location of the error
2430 * @param arguments the arguments to the error, used to compose the error mess age 2848 * @param arguments the arguments to the error, used to compose the error mess age
2431 */ 2849 */
2432 void reportError2(ResolverErrorCode errorCode, Token token, List<Object> argum ents) { 2850 void reportError3(ErrorCode errorCode, Token token, List<Object> arguments) {
2433 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l ength, errorCode, [arguments])); 2851 _errorListener.onError(new AnalysisError.con2(_source, token.offset, token.l ength, errorCode, [arguments]));
2434 } 2852 }
2435 /** 2853 /**
2436 * Add scopes for each of the given labels. 2854 * Add scopes for each of the given labels.
2437 * @param labels the labels for which new scopes are to be added 2855 * @param labels the labels for which new scopes are to be added
2438 * @return the scope that was in effect before the new scopes were added 2856 * @return the scope that was in effect before the new scopes were added
2439 */ 2857 */
2440 LabelScope addScopesFor(NodeList<Label> labels) { 2858 LabelScope addScopesFor(NodeList<Label> labels) {
2441 LabelScope outerScope = _labelScope; 2859 LabelScope outerScope = _labelScope;
2442 for (Label label in labels) { 2860 for (Label label in labels) {
2443 SimpleIdentifier labelNameNode = label.label; 2861 SimpleIdentifier labelNameNode = label.label;
2444 String labelName = labelNameNode.name; 2862 String labelName = labelNameNode.name;
2445 LabelElement labelElement = (labelNameNode.element as LabelElement); 2863 LabelElement labelElement = labelNameNode.element as LabelElement;
2446 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); 2864 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement);
2447 } 2865 }
2448 return outerScope; 2866 return outerScope;
2449 } 2867 }
2450 } 2868 }
2451 /** 2869 /**
2452 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta sks. First, they 2870 * Instances of the class {@code StaticTypeAnalyzer} perform two type-related ta sks. First, they
2453 * compute the static type of every expression. Second, they look for any static type errors or 2871 * compute the static type of every expression. Second, they look for any static type errors or
2454 * warnings that might need to be generated. The requirements for the type analy zer are: 2872 * warnings that might need to be generated. The requirements for the type analy zer are:
2455 * <ol> 2873 * <ol>
2456 * <li>Every element that refers to types should be fully populated. 2874 * <li>Every element that refers to types should be fully populated.
2457 * <li>Every node representing an expression should be resolved to the Type of t he expression.</li> 2875 * <li>Every node representing an expression should be resolved to the Type of t he expression.</li>
2458 * </ol> 2876 * </ol>
2459 */ 2877 */
2460 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> { 2878 class StaticTypeAnalyzer extends SimpleASTVisitor<Object> {
2461 /** 2879 /**
2462 * The resolver driving this participant.
2463 */
2464 ResolverVisitor _resolver;
2465 /**
2466 * The object providing access to the types defined by the language. 2880 * The object providing access to the types defined by the language.
2467 */ 2881 */
2468 TypeProvider _typeProvider; 2882 TypeProvider _typeProvider;
2469 /** 2883 /**
2884 * The type representing the type 'dynamic'.
2885 */
2886 Type2 _dynamicType;
2887 /**
2470 * The type representing the class containing the nodes being analyzed, or {@c ode null} if the 2888 * The type representing the class containing the nodes being analyzed, or {@c ode null} if the
2471 * nodes are not within a class. 2889 * nodes are not within a class.
2472 */ 2890 */
2473 InterfaceType _thisType; 2891 InterfaceType _thisType;
2474 /** 2892 /**
2475 * Initialize a newly created type analyzer. 2893 * Initialize a newly created type analyzer.
2476 * @param resolver the resolver driving this participant 2894 * @param resolver the resolver driving this participant
2477 */ 2895 */
2478 StaticTypeAnalyzer(ResolverVisitor resolver) { 2896 StaticTypeAnalyzer(ResolverVisitor resolver) {
2479 this._resolver = resolver;
2480 _typeProvider = resolver.typeProvider; 2897 _typeProvider = resolver.typeProvider;
2898 _dynamicType = _typeProvider.dynamicType;
2481 } 2899 }
2482 /** 2900 /**
2483 * Set the type of the class being analyzed to the given type. 2901 * Set the type of the class being analyzed to the given type.
2484 * @param thisType the type representing the class containing the nodes being analyzed 2902 * @param thisType the type representing the class containing the nodes being analyzed
2485 */ 2903 */
2486 void set thisType(InterfaceType thisType2) { 2904 void set thisType(InterfaceType thisType2) {
2487 this._thisType = thisType2; 2905 this._thisType = thisType2;
2488 } 2906 }
2489 /** 2907 /**
2490 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote> 2908 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote>
2491 */ 2909 */
2492 Object visitAdjacentStrings(AdjacentStrings node) => recordType(node, _typePro vider.stringType); 2910 Object visitAdjacentStrings(AdjacentStrings node) => recordType(node, _typePro vider.stringType);
2493 /** 2911 /**
2494 * The Dart Language Specification, 12.33: <blockquote>The static type of an a rgument definition 2912 * The Dart Language Specification, 12.33: <blockquote>The static type of an a rgument definition
2495 * test is {@code bool}.</blockquote> 2913 * test is {@code bool}.</blockquote>
2496 */ 2914 */
2497 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) => recordType( node, _typeProvider.boolType); 2915 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) => recordType( node, _typeProvider.boolType);
2498 /** 2916 /**
2499 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ... 2917 * The Dart Language Specification, 12.32: <blockquote>... the cast expression <i>e as T</i> ...
2500 * <p> 2918 * <p>
2501 * It is a static warning if <i>T</i> does not denote a type available in the current lexical 2919 * It is a static warning if <i>T</i> does not denote a type available in the current lexical
2502 * scope. 2920 * scope.
2503 * <p> 2921 * <p>
2504 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote > 2922 * The static type of a cast expression <i>e as T</i> is <i>T</i>.</blockquote >
2505 */ 2923 */
2506 Object visitAsExpression(AsExpression node) => recordType(node, getType2(node. type)); 2924 Object visitAsExpression(AsExpression node) => recordType(node, getType3(node. type));
2507 /** 2925 /**
2508 * The Dart Language Specification, 12.18: <blockquote> ... an assignment <i>a </i> of the form 2926 * The Dart Language Specification, 12.18: <blockquote> ... an assignment <i>a </i> of the form
2509 * <i>v = e</i> ... 2927 * <i>v = e</i> ...
2510 * <p> 2928 * <p>
2511 * It is a static type warning if the static type of <i>e</i> may not be assig ned to the static 2929 * It is a static type warning if the static type of <i>e</i> may not be assig ned to the static
2512 * type of <i>v</i>. 2930 * type of <i>v</i>.
2513 * <p> 2931 * <p>
2514 * The static type of the expression <i>v = e</i> is the static type of <i>e</ i>. 2932 * The static type of the expression <i>v = e</i> is the static type of <i>e</ i>.
2515 * <p> 2933 * <p>
2516 * ... an assignment of the form <i>C.v = e</i> ... 2934 * ... an assignment of the form <i>C.v = e</i> ...
(...skipping 24 matching lines...) Expand all
2541 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op= 2959 * <i>e<sub>2</sub></i>. A compound assignment of the form <i>e<sub>1</sub>[e< sub>2</sub>] op=
2542 * 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>, 2960 * 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>,
2543 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in 2961 * e<sub>2</sub>)</i> where <i>a</i> and <i>i</i> are a variables that are not used in
2544 * <i>e<sub>3</sub></i>. </blockquote> 2962 * <i>e<sub>3</sub></i>. </blockquote>
2545 */ 2963 */
2546 Object visitAssignmentExpression(AssignmentExpression node) { 2964 Object visitAssignmentExpression(AssignmentExpression node) {
2547 TokenType operator11 = node.operator.type; 2965 TokenType operator11 = node.operator.type;
2548 if (operator11 != TokenType.EQ) { 2966 if (operator11 != TokenType.EQ) {
2549 return recordReturnType(node, node.element); 2967 return recordReturnType(node, node.element);
2550 } 2968 }
2551 Type2 leftType = getType(node.leftHandSide); 2969 return recordType(node, getType(node.rightHandSide));
2552 Type2 rightType = getType(node.rightHandSide);
2553 if (!rightType.isAssignableTo(leftType)) {
2554 }
2555 return recordType(node, rightType);
2556 } 2970 }
2557 /** 2971 /**
2558 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean 2972 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean
2559 * expression is {@code bool}.</blockquote> 2973 * expression is {@code bool}.</blockquote>
2560 * <p> 2974 * <p>
2561 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form 2975 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form
2562 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n 2976 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n
2563 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i >super op 2977 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i >super op
2564 * e<sub>2</sub></i> is equivalent to the method invocation 2978 * e<sub>2</sub></i> is equivalent to the method invocation
2565 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 2979 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
(...skipping 20 matching lines...) Expand all
2586 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 3000 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
2587 * <p> 3001 * <p>
2588 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres sion of the form 3002 * The Dart Language Specification, 12.26: <blockquote>A multiplicative expres sion of the form
2589 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n 3003 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n
2590 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the form <i>super op 3004 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A multiplicative expression of the form <i>super op
2591 * e<sub>2</sub></i> is equivalent to the method invocation 3005 * e<sub>2</sub></i> is equivalent to the method invocation
2592 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 3006 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
2593 */ 3007 */
2594 Object visitBinaryExpression(BinaryExpression node) { 3008 Object visitBinaryExpression(BinaryExpression node) {
2595 TokenType operator12 = node.operator.type; 3009 TokenType operator12 = node.operator.type;
2596 if (operator12 == TokenType.AMPERSAND_AMPERSAND || operator12 == TokenType.B AR_BAR || operator12 == TokenType.EQ_EQ || operator12 == TokenType.BANG_EQ) { 3010 while (true) {
2597 return recordType(node, _typeProvider.boolType); 3011 if (operator12 == TokenType.AMPERSAND_AMPERSAND || operator12 == TokenType .BAR_BAR || operator12 == TokenType.EQ_EQ || operator12 == TokenType.BANG_EQ) {
3012 return recordType(node, _typeProvider.boolType);
3013 }
3014 break;
2598 } 3015 }
2599 return recordReturnType(node, node.element); 3016 return recordReturnType(node, node.element);
2600 } 3017 }
2601 /** 3018 /**
2602 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is{@code bool}.</blockquote> 3019 * The Dart Language Specification, 12.4: <blockquote>The static type of a boo lean literal is{@code bool}.</blockquote>
2603 */ 3020 */
2604 Object visitBooleanLiteral(BooleanLiteral node) => recordType(node, _typeProvi der.boolType); 3021 Object visitBooleanLiteral(BooleanLiteral node) => recordType(node, _typeProvi der.boolType);
2605 /** 3022 /**
2606 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv ocation expression 3023 * The Dart Language Specification, 12.15.2: <blockquote>A cascaded method inv ocation expression
2607 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff ix; return 3024 * of the form <i>e..suffix</i> is equivalent to the expression <i>(t) {t.suff ix; return
2608 * t;}(e)</i>.</blockquote> 3025 * t;}(e)</i>.</blockquote>
2609 */ 3026 */
2610 Object visitCascadeExpression(CascadeExpression node) => recordType(node, getT ype(node.target)); 3027 Object visitCascadeExpression(CascadeExpression node) => recordType(node, getT ype(node.target));
2611 /** 3028 /**
2612 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr ession <i>c</i> of 3029 * The Dart Language Specification, 12.19: <blockquote> ... a conditional expr ession <i>c</i> of
2613 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ... 3030 * the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub></i> ...
2614 * <p> 3031 * <p>
2615 * It is a static type warning if the type of e<sub>1</sub> may not be assigne d to {@code bool}. 3032 * It is a static type warning if the type of e<sub>1</sub> may not be assigne d to {@code bool}.
2616 * <p> 3033 * <p>
2617 * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i> 3034 * The static type of <i>c</i> is the least upper bound of the static type of <i>e<sub>2</sub></i>
2618 * and the static type of <i>e<sub>3</sub></i>.</blockquote> 3035 * and the static type of <i>e<sub>3</sub></i>.</blockquote>
2619 */ 3036 */
2620 Object visitConditionalExpression(ConditionalExpression node) { 3037 Object visitConditionalExpression(ConditionalExpression node) {
2621 Type2 conditionType = getType(node.condition);
2622 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo lType)) {
2623 _resolver.reportError(ResolverErrorCode.NON_BOOLEAN_CONDITION, node.condit ion, []);
2624 }
2625 Type2 thenType = getType(node.thenExpression); 3038 Type2 thenType = getType(node.thenExpression);
2626 Type2 elseType = getType(node.elseExpression); 3039 Type2 elseType = getType(node.elseExpression);
2627 if (thenType == null) { 3040 if (thenType == null) {
2628 return recordType(node, _typeProvider.dynamicType); 3041 return recordType(node, _dynamicType);
2629 } 3042 }
2630 Type2 resultType = thenType.getLeastUpperBound(elseType); 3043 Type2 resultType = thenType.getLeastUpperBound(elseType);
2631 return recordType(node, resultType); 3044 return recordType(node, resultType);
2632 } 3045 }
2633 /** 3046 /**
2634 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is{@code double}.</blockquote> 3047 * The Dart Language Specification, 12.3: <blockquote>The static type of a lit eral double is{@code double}.</blockquote>
2635 */ 3048 */
2636 Object visitDoubleLiteral(DoubleLiteral node) => recordType(node, _typeProvide r.doubleType); 3049 Object visitDoubleLiteral(DoubleLiteral node) => recordType(node, _typeProvide r.doubleType);
3050 Object visitFunctionDeclaration(FunctionDeclaration node) {
3051 FunctionExpression function = node.functionExpression;
3052 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl;
3053 setTypeInformation(functionType, computeReturnType(node), function.parameter s);
3054 return recordType(function, functionType);
3055 }
2637 /** 3056 /**
2638 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun ction literal of the 3057 * The Dart Language Specification, 12.9: <blockquote>The static type of a fun ction literal of the
2639 * form <i>(T<sub>1</sub> a<sub>1</sub>, &hellip;, T<sub>n</sub> a<sub>n</sub> , [T<sub>n+1</sub> 3058 * form <i>(T<sub>1</sub> a<sub>1</sub>, &hellip;, T<sub>n</sub> a<sub>n</sub> , [T<sub>n+1</sub>
2640 * x<sub>n+1</sub> = d1, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub> = dk]) => e </i> is 3059 * x<sub>n+1</sub> = d1, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub> = dk]) => e </i> is
2641 * <i>(T<sub>1</sub>, &hellip;, Tn, [T<sub>n+1</sub> x<sub>n+1</sub>, &hellip; , T<sub>n+k</sub> 3060 * <i>(T<sub>1</sub>, &hellip;, Tn, [T<sub>n+1</sub> x<sub>n+1</sub>, &hellip; , T<sub>n+k</sub>
2642 * x<sub>n+k</sub>]) &rarr; T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is t he static type of 3061 * x<sub>n+k</sub>]) &rarr; T<sub>0</sub></i>, where <i>T<sub>0</sub></i> is t he static type of
2643 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is 3062 * <i>e</i>. In any case where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is
2644 * considered to have been specified as dynamic. 3063 * considered to have been specified as dynamic.
2645 * <p> 3064 * <p>
2646 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;, 3065 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;,
(...skipping 11 matching lines...) Expand all
2658 * specified as dynamic. 3077 * specified as dynamic.
2659 * <p> 3078 * <p>
2660 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;, 3079 * The static type of a function literal of the form <i>(T<sub>1</sub> a<sub>1 </sub>, &hellip;,
2661 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip ;, T<sub>n+k</sub> 3080 * T<sub>n</sub> a<sub>n</sub>, {T<sub>n+1</sub> x<sub>n+1</sub> : d1, &hellip ;, T<sub>n+k</sub>
2662 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub >, {T<sub>n+1</sub> 3081 * x<sub>n+k</sub> : dk}) {s}</i> is <i>(T<sub>1</sub>, &hellip;, T<sub>n</sub >, {T<sub>n+1</sub>
2663 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; dynamic </i>. In any case 3082 * x<sub>n+1</sub>, &hellip;, T<sub>n+k</sub> x<sub>n+k</sub>}) &rarr; dynamic </i>. In any case
2664 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been 3083 * where <i>T<sub>i</sub>, 1 &lt;= i &lt;= n</i>, is not specified, it is cons idered to have been
2665 * specified as dynamic.</blockquote> 3084 * specified as dynamic.</blockquote>
2666 */ 3085 */
2667 Object visitFunctionExpression(FunctionExpression node) { 3086 Object visitFunctionExpression(FunctionExpression node) {
2668 FunctionTypeImpl functionType = (node.element.type as FunctionTypeImpl); 3087 if (node.parent is FunctionDeclaration) {
2669 setTypeInformation(functionType, computeReturnType(node), node.parameters); 3088 return null;
3089 }
3090 FunctionTypeImpl functionType = node.element.type as FunctionTypeImpl;
3091 setTypeInformation(functionType, computeReturnType2(node), node.parameters);
2670 return recordType(node, functionType); 3092 return recordType(node, functionType);
2671 } 3093 }
2672 /** 3094 /**
2673 * The Dart Language Specification, 12.14.4: <blockquote>A function expression invocation <i>i</i> 3095 * The Dart Language Specification, 12.14.4: <blockquote>A function expression invocation <i>i</i>
2674 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub >n+1</sub>: 3096 * has the form <i>e<sub>f</sub>(a<sub>1</sub>, &hellip;, a<sub>n</sub>, x<sub >n+1</sub>:
2675 * 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 3097 * 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
2676 * an expression. 3098 * an expression.
2677 * <p> 3099 * <p>
2678 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be 3100 * It is a static type warning if the static type <i>F</i> of <i>e<sub>f</sub> </i> may not be
2679 * assigned to a function type. 3101 * assigned to a function type.
2680 * <p> 3102 * <p>
2681 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the 3103 * If <i>F</i> is not a function type, the static type of <i>i</i> is dynamic. Otherwise the
2682 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e> 3104 * static type of <i>i</i> is the declared return type of <i>F</i>.</blockquot e>
2683 */ 3105 */
2684 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => recordReturnType(node, node.element); 3106 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) => recordReturnType(node, node.element);
2685 /** 3107 /**
2686 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form 3108 * The Dart Language Specification, 12.29: <blockquote>An assignable expressio n of the form
2687 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method 3109 * <i>e<sub>1</sub>[e<sub>2</sub>]</i> is evaluated as a method invocation of the operator method
2688 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote> 3110 * <i>[]</i> on <i>e<sub>1</sub></i> with argument <i>e<sub>2</sub></i>.</bloc kquote>
2689 */ 3111 */
2690 Object visitIndexExpression(IndexExpression node) => recordReturnType(node, no de.element); 3112 Object visitIndexExpression(IndexExpression node) {
3113 if (node.inSetterContext()) {
3114 return recordArgumentType(node, node.element);
3115 }
3116 return recordReturnType(node, node.element);
3117 }
2691 /** 3118 /**
2692 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of 3119 * The Dart Language Specification, 12.11.1: <blockquote>The static type of a new expression of
2693 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new 3120 * either the form <i>new T.id(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> or the form <i>new
2694 * T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>.</blockquote> 3121 * T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>.</blockquote>
2695 * <p> 3122 * <p>
2696 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a constant object 3123 * The Dart Language Specification, 12.11.2: <blockquote>The static type of a constant object
2697 * expression of either the form <i>const T.id(a<sub>1</sub>, &hellip;, a<sub> n</sub>)</i> or the 3124 * expression of either the form <i>const T.id(a<sub>1</sub>, &hellip;, a<sub> n</sub>)</i> or the
2698 * form <i>const T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>. </ blockquote> 3125 * form <i>const T(a<sub>1</sub>, &hellip;, a<sub>n</sub>)</i> is <i>T</i>. </ blockquote>
2699 */ 3126 */
2700 Object visitInstanceCreationExpression(InstanceCreationExpression node) => rec ordReturnType(node, node.element); 3127 Object visitInstanceCreationExpression(InstanceCreationExpression node) => rec ordType(node, node.constructorName.type.type);
2701 /** 3128 /**
2702 * The Dart Language Specification, 12.3: <blockquote>The static type of an in teger literal is{@code int}.</blockquote> 3129 * The Dart Language Specification, 12.3: <blockquote>The static type of an in teger literal is{@code int}.</blockquote>
2703 */ 3130 */
2704 Object visitIntegerLiteral(IntegerLiteral node) => recordType(node, _typeProvi der.intType); 3131 Object visitIntegerLiteral(IntegerLiteral node) => recordType(node, _typeProvi der.intType);
2705 /** 3132 /**
2706 * The Dart Language Specification, 12.31: <blockquote>It is a static warning if <i>T</i> does not 3133 * The Dart Language Specification, 12.31: <blockquote>It is a static warning if <i>T</i> does not
2707 * denote a type available in the current lexical scope. 3134 * denote a type available in the current lexical scope.
2708 * <p> 3135 * <p>
2709 * The static type of an is-expression is {@code bool}.</blockquote> 3136 * The static type of an is-expression is {@code bool}.</blockquote>
2710 */ 3137 */
2711 Object visitIsExpression(IsExpression node) => recordType(node, _typeProvider. boolType); 3138 Object visitIsExpression(IsExpression node) => recordType(node, _typeProvider. boolType);
2712 /** 3139 /**
2713 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis t literal of the 3140 * The Dart Language Specification, 12.6: <blockquote>The static type of a lis t literal of the
2714 * form <i><b>const</b> &lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> or the form 3141 * form <i><b>const</b> &lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> or the form
2715 * <i>&lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; E&gt;}. The static 3142 * <i>&lt;E&gt;[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; E&gt;}. The static
2716 * type a list literal of the form <i><b>const</b> [e<sub>1</sub>, &hellip;, e <sub>n</sub>]</i> or 3143 * type a list literal of the form <i><b>const</b> [e<sub>1</sub>, &hellip;, e <sub>n</sub>]</i> or
2717 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; dynamic&gt;}.</blockquote> 3144 * the form <i>[e<sub>1</sub>, &hellip;, e<sub>n</sub>]</i> is {@code List&lt; dynamic&gt;}.</blockquote>
2718 */ 3145 */
2719 Object visitListLiteral(ListLiteral node) { 3146 Object visitListLiteral(ListLiteral node) {
2720 TypeArgumentList typeArguments8 = node.typeArguments; 3147 TypeArgumentList typeArguments8 = node.typeArguments;
2721 if (typeArguments8 != null) { 3148 if (typeArguments8 != null) {
2722 NodeList<TypeName> arguments3 = typeArguments8.arguments; 3149 NodeList<TypeName> arguments3 = typeArguments8.arguments;
2723 if (arguments3 != null && arguments3.length == 1) { 3150 if (arguments3 != null && arguments3.length == 1) {
2724 TypeName argumentType = arguments3[0]; 3151 TypeName argumentType = arguments3[0];
2725 return recordType(node, _typeProvider.listType.substitute5(<Type2> [getT ype2(argumentType)])); 3152 return recordType(node, _typeProvider.listType.substitute5(<Type2> [getT ype3(argumentType)]));
2726 } 3153 }
2727 } 3154 }
2728 return recordType(node, _typeProvider.listType.substitute5(<Type2> [_typePro vider.dynamicType])); 3155 return recordType(node, _typeProvider.listType.substitute5(<Type2> [_dynamic Type]));
2729 } 3156 }
2730 /** 3157 /**
2731 * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form 3158 * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form
2732 * <i><b>const</b> &lt;String, V&gt; {k<sub>1</sub>:e<sub>1</sub>, &hellip;, 3159 * <i><b>const</b> &lt;String, V&gt; {k<sub>1</sub>:e<sub>1</sub>, &hellip;,
2733 * 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>, 3160 * 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>,
2734 * &hellip;, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, V&gt;}. The static type a 3161 * &hellip;, k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, V&gt;}. The static type a
2735 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell ip;, 3162 * map literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, &hell ip;,
2736 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub >, &hellip;, 3163 * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub >, &hellip;,
2737 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, dynamic&gt;}. 3164 * k<sub>n</sub>:e<sub>n</sub>}</i> is {@code Map&lt;String, dynamic&gt;}.
2738 * <p> 3165 * <p>
2739 * It is a compile-time error if the first type argument to a map literal is n ot 3166 * It is a compile-time error if the first type argument to a map literal is n ot
2740 * <i>String</i>.</blockquote> 3167 * <i>String</i>.</blockquote>
2741 */ 3168 */
2742 Object visitMapLiteral(MapLiteral node) { 3169 Object visitMapLiteral(MapLiteral node) {
2743 TypeArgumentList typeArguments9 = node.typeArguments; 3170 TypeArgumentList typeArguments9 = node.typeArguments;
2744 if (typeArguments9 != null) { 3171 if (typeArguments9 != null) {
2745 NodeList<TypeName> arguments4 = typeArguments9.arguments; 3172 NodeList<TypeName> arguments4 = typeArguments9.arguments;
2746 if (arguments4 != null && arguments4.length == 2) { 3173 if (arguments4 != null && arguments4.length == 2) {
2747 TypeName keyType = arguments4[0]; 3174 TypeName keyType = arguments4[0];
2748 if (keyType != _typeProvider.stringType) { 3175 if (keyType != _typeProvider.stringType) {
2749 } 3176 }
2750 TypeName valueType = arguments4[1]; 3177 TypeName valueType = arguments4[1];
2751 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_type Provider.stringType, getType2(valueType)])); 3178 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_type Provider.stringType, getType3(valueType)]));
2752 } 3179 }
2753 } 3180 }
2754 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_typeProv ider.stringType, _typeProvider.dynamicType])); 3181 return recordType(node, _typeProvider.mapType.substitute5(<Type2> [_typeProv ider.stringType, _dynamicType]));
2755 } 3182 }
2756 /** 3183 /**
2757 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in vocation <i>i</i> 3184 * The Dart Language Specification, 12.15.1: <blockquote>An ordinary method in vocation <i>i</i>
2758 * 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>, 3185 * 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>,
2759 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>. 3186 * &hellip;, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
2760 * <p> 3187 * <p>
2761 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if <i>T</i> does not 3188 * Let <i>T</i> be the static type of <i>o</i>. It is a static type warning if <i>T</i> does not
2762 * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it is a static warning 3189 * have an accessible instance member named <i>m</i>. If <i>T.m</i> exists, it is a static warning
2763 * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type. 3190 * if the type <i>F</i> of <i>T.m</i> may not be assigned to a function type.
2764 * <p> 3191 * <p>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 * <p> 3249 * <p>
2823 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i] 3250 * A postfix expression of the form <i>e1[e2]--</i> is equivalent to <i>(a, i) {var r = a[i]; a[i]
2824 * = r - 1; return r}(e1, e2)</i></blockquote> 3251 * = r - 1; return r}(e1, e2)</i></blockquote>
2825 */ 3252 */
2826 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT ype(node.operand)); 3253 Object visitPostfixExpression(PostfixExpression node) => recordType(node, getT ype(node.operand));
2827 /** 3254 /**
2828 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}. 3255 * See {@link #visitSimpleIdentifier(SimpleIdentifier)}.
2829 */ 3256 */
2830 Object visitPrefixedIdentifier(PrefixedIdentifier node) { 3257 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
2831 SimpleIdentifier prefixedIdentifier = node.identifier; 3258 SimpleIdentifier prefixedIdentifier = node.identifier;
2832 Element element20 = prefixedIdentifier.element; 3259 Element element23 = prefixedIdentifier.element;
2833 if (element20 is VariableElement) { 3260 if (element23 is VariableElement) {
2834 Type2 variableType = ((element20 as VariableElement)).type; 3261 Type2 variableType = ((element23 as VariableElement)).type;
2835 recordType(prefixedIdentifier, variableType); 3262 recordType(prefixedIdentifier, variableType);
2836 return recordType(node, variableType); 3263 return recordType(node, variableType);
2837 } else if (element20 is PropertyAccessorElement) { 3264 } else if (element23 is PropertyAccessorElement) {
2838 Type2 propertyType = ((element20 as PropertyAccessorElement)).type.returnT ype; 3265 Type2 propertyType = getType2((element23 as PropertyAccessorElement));
2839 recordType(prefixedIdentifier, propertyType); 3266 recordType(prefixedIdentifier, propertyType);
2840 return recordType(node, propertyType); 3267 return recordType(node, propertyType);
2841 } else if (element20 is MethodElement) { 3268 } else if (element23 is MethodElement) {
2842 Type2 returnType = ((element20 as MethodElement)).type; 3269 Type2 returnType = ((element23 as MethodElement)).type;
2843 recordType(prefixedIdentifier, returnType); 3270 recordType(prefixedIdentifier, returnType);
2844 return recordType(node, returnType); 3271 return recordType(node, returnType);
2845 } else { 3272 } else {
2846 } 3273 }
2847 recordType(prefixedIdentifier, _typeProvider.dynamicType); 3274 recordType(prefixedIdentifier, _dynamicType);
2848 return recordType(node, _typeProvider.dynamicType); 3275 return recordType(node, _dynamicType);
2849 } 3276 }
2850 /** 3277 /**
2851 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form 3278 * The Dart Language Specification, 12.27: <blockquote>A unary expression <i>u </i> of the form
2852 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the 3279 * <i>op e</i> is equivalent to a method invocation <i>expression e.op()</i>. An expression of the
2853 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote> 3280 * form <i>op super</i> is equivalent to the method invocation <i>super.op()<i >.</blockquote>
2854 */ 3281 */
2855 Object visitPrefixExpression(PrefixExpression node) { 3282 Object visitPrefixExpression(PrefixExpression node) {
2856 TokenType operator13 = node.operator.type; 3283 TokenType operator13 = node.operator.type;
2857 if (identical(operator13, TokenType.BANG)) { 3284 if (identical(operator13, TokenType.BANG)) {
2858 return recordType(node, _typeProvider.boolType); 3285 return recordType(node, _typeProvider.boolType);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it exists or dynamic 3324 * The static type of <i>i</i> is the declared return type of <i>C.m</i> if it exists or dynamic
2898 * otherwise. 3325 * otherwise.
2899 * <p> 3326 * <p>
2900 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an 3327 * ... a top-level getter invocation <i>i</i> of the form <i>m</i>, where <i>m </i> is an
2901 * identifier ... 3328 * identifier ...
2902 * <p> 3329 * <p>
2903 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote> 3330 * The static type of <i>i</i> is the declared return type of <i>m</i>.</block quote>
2904 */ 3331 */
2905 Object visitPropertyAccess(PropertyAccess node) { 3332 Object visitPropertyAccess(PropertyAccess node) {
2906 SimpleIdentifier propertyName2 = node.propertyName; 3333 SimpleIdentifier propertyName2 = node.propertyName;
2907 Element element21 = propertyName2.element; 3334 Element element24 = propertyName2.element;
2908 if (element21 is MethodElement) { 3335 if (element24 is MethodElement) {
2909 FunctionType type11 = ((element21 as MethodElement)).type; 3336 FunctionType type15 = ((element24 as MethodElement)).type;
2910 recordType(propertyName2, type11); 3337 recordType(propertyName2, type15);
2911 return recordType(node, type11); 3338 return recordType(node, type15);
2912 } else if (element21 is PropertyAccessorElement) { 3339 } else if (element24 is PropertyAccessorElement) {
2913 PropertyAccessorElement accessor = (element21 as PropertyAccessorElement); 3340 Type2 propertyType = getType2((element24 as PropertyAccessorElement));
2914 if (accessor.isGetter()) { 3341 recordType(propertyName2, propertyType);
2915 if (accessor.type == null) { 3342 return recordType(node, propertyType);
2916 recordType(propertyName2, _typeProvider.dynamicType);
2917 return recordType(node, _typeProvider.dynamicType);
2918 }
2919 Type2 returnType4 = accessor.type.returnType;
2920 recordType(propertyName2, returnType4);
2921 return recordType(node, returnType4);
2922 } else {
2923 recordType(propertyName2, VoidTypeImpl.instance);
2924 return recordType(node, VoidTypeImpl.instance);
2925 }
2926 } else { 3343 } else {
2927 } 3344 }
2928 recordType(propertyName2, _typeProvider.dynamicType); 3345 recordType(propertyName2, _dynamicType);
2929 return recordType(node, _typeProvider.dynamicType); 3346 return recordType(node, _dynamicType);
2930 } 3347 }
2931 /** 3348 /**
2932 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi fier expression 3349 * The Dart Language Specification, 12.30: <blockquote>Evaluation of an identi fier expression
2933 * <i>e</i> of the form <i>id</i> proceeds as follows: 3350 * <i>e</i> of the form <i>id</i> proceeds as follows:
2934 * <p> 3351 * <p>
2935 * Let <i>d</i> be the innermost declaration in the enclosing lexical scope wh ose name is 3352 * Let <i>d</i> be the innermost declaration in the enclosing lexical scope wh ose name is
2936 * <i>id</i>. If no such declaration exists in the lexical scope, let <i>d</i> be the declaration 3353 * <i>id</i>. If no such declaration exists in the lexical scope, let <i>d</i> be the declaration
2937 * of the inherited member named <i>id</i> if it exists. 3354 * of the inherited member named <i>id</i> if it exists.
2938 * <ul> 3355 * <ul>
2939 * <li>If <i>d</i> is a class or type alias <i>T</i>, the value of <i>e</i> is the unique instance 3356 * <li>If <i>d</i> is a class or type alias <i>T</i>, the value of <i>e</i> is the unique instance
(...skipping 24 matching lines...) Expand all
2964 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is equivalent to the 3381 * <li>If <i>d</i> is the declaration of a top level getter, then <i>e</i> is equivalent to the
2965 * getter invocation <i>id</i>. 3382 * getter invocation <i>id</i>.
2966 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be it function, 3383 * <li>Otherwise, if <i>e</i> occurs inside a top level or static function (be it function,
2967 * method, getter, or setter) or variable initializer, evaluation of e causes a NoSuchMethodError 3384 * method, getter, or setter) or variable initializer, evaluation of e causes a NoSuchMethodError
2968 * to be thrown. 3385 * to be thrown.
2969 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id< /i>. 3386 * <li>Otherwise <i>e</i> is equivalent to the property extraction <i>this.id< /i>.
2970 * </ul> 3387 * </ul>
2971 * </blockquote> 3388 * </blockquote>
2972 */ 3389 */
2973 Object visitSimpleIdentifier(SimpleIdentifier node) { 3390 Object visitSimpleIdentifier(SimpleIdentifier node) {
2974 Element element22 = node.element; 3391 Element element25 = node.element;
2975 if (element22 == null) { 3392 if (element25 == null) {
2976 return recordType(node, _typeProvider.dynamicType); 3393 return recordType(node, _dynamicType);
2977 } else if (element22 is ClassElement) { 3394 } else if (element25 is ClassElement) {
2978 if (isTypeName(node)) { 3395 if (isTypeName(node)) {
2979 return recordType(node, ((element22 as ClassElement)).type); 3396 return recordType(node, ((element25 as ClassElement)).type);
2980 } 3397 }
2981 return recordType(node, _typeProvider.typeType); 3398 return recordType(node, _typeProvider.typeType);
2982 } else if (element22 is TypeVariableElement) { 3399 } else if (element25 is TypeVariableElement) {
2983 return recordType(node, ((element22 as TypeVariableElement)).type); 3400 return recordType(node, ((element25 as TypeVariableElement)).type);
2984 } else if (element22 is TypeAliasElement) { 3401 } else if (element25 is TypeAliasElement) {
2985 return recordType(node, ((element22 as TypeAliasElement)).type); 3402 return recordType(node, ((element25 as TypeAliasElement)).type);
2986 } else if (element22 is VariableElement) { 3403 } else if (element25 is VariableElement) {
2987 return recordType(node, ((element22 as VariableElement)).type); 3404 return recordType(node, ((element25 as VariableElement)).type);
2988 } else if (element22 is MethodElement) { 3405 } else if (element25 is MethodElement) {
2989 return recordType(node, ((element22 as MethodElement)).type); 3406 return recordType(node, ((element25 as MethodElement)).type);
2990 } else if (element22 is PropertyAccessorElement) { 3407 } else if (element25 is PropertyAccessorElement) {
2991 PropertyAccessorElement accessor = (element22 as PropertyAccessorElement); 3408 return recordType(node, getType2((element25 as PropertyAccessorElement)));
2992 if (accessor.isGetter()) { 3409 } else if (element25 is ExecutableElement) {
2993 return recordType(node, accessor.type.returnType); 3410 return recordType(node, ((element25 as ExecutableElement)).type);
2994 } else { 3411 } else if (element25 is PrefixElement) {
2995 return recordType(node, accessor.type.normalParameterTypes[0]);
2996 }
2997 } else if (element22 is ExecutableElement) {
2998 return recordType(node, ((element22 as ExecutableElement)).type);
2999 } else if (element22 is PrefixElement) {
3000 return null; 3412 return null;
3001 } else { 3413 } else {
3002 return recordType(node, _typeProvider.dynamicType); 3414 return recordType(node, _dynamicType);
3003 } 3415 }
3004 } 3416 }
3005 /** 3417 /**
3006 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote> 3418 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote>
3007 */ 3419 */
3008 Object visitSimpleStringLiteral(SimpleStringLiteral node) => recordType(node, _typeProvider.stringType); 3420 Object visitSimpleStringLiteral(SimpleStringLiteral node) => recordType(node, _typeProvider.stringType);
3009 /** 3421 /**
3010 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote> 3422 * The Dart Language Specification, 12.5: <blockquote>The static type of a str ing literal is{@code String}.</blockquote>
3011 */ 3423 */
3012 Object visitStringInterpolation(StringInterpolation node) => recordType(node, _typeProvider.stringType); 3424 Object visitStringInterpolation(StringInterpolation node) => recordType(node, _typeProvider.stringType);
3013 Object visitSuperExpression(SuperExpression node) => recordType(node, _thisTyp e == null ? _typeProvider.dynamicType : _thisType.superclass); 3425 Object visitSuperExpression(SuperExpression node) {
3426 if (_thisType == null) {
3427 return recordType(node, _dynamicType);
3428 } else {
3429 return recordType(node, _thisType.superclass);
3430 }
3431 }
3014 /** 3432 /**
3015 * The Dart Language Specification, 12.10: <blockquote>The static type of {@co de this} is the 3433 * The Dart Language Specification, 12.10: <blockquote>The static type of {@co de this} is the
3016 * interface of the immediately enclosing class.</blockquote> 3434 * interface of the immediately enclosing class.</blockquote>
3017 */ 3435 */
3018 Object visitThisExpression(ThisExpression node) => recordType(node, _thisType) ; 3436 Object visitThisExpression(ThisExpression node) {
3437 if (_thisType == null) {
3438 return recordType(node, _dynamicType);
3439 } else {
3440 return recordType(node, _thisType);
3441 }
3442 }
3019 /** 3443 /**
3020 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr ow expression is 3444 * The Dart Language Specification, 12.8: <blockquote>The static type of a thr ow expression is
3021 * bottom.</blockquote> 3445 * bottom.</blockquote>
3022 */ 3446 */
3023 Object visitThrowExpression(ThrowExpression node) => recordType(node, _typePro vider.bottomType); 3447 Object visitThrowExpression(ThrowExpression node) => recordType(node, _typePro vider.bottomType);
3024 /** 3448 /**
3449 * Given a function declaration, compute the return type of the function. The return type of
3450 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
3451 * the expression.
3452 * @param node the function expression whose return type is to be computed
3453 * @return the return type that was computed
3454 */
3455 Type2 computeReturnType(FunctionDeclaration node) {
3456 TypeName returnType6 = node.returnType;
3457 if (returnType6 == null) {
3458 return computeReturnType2(node.functionExpression);
3459 }
3460 return returnType6.type;
3461 }
3462 /**
3025 * Given a function expression, compute the return type of the function. The r eturn type of 3463 * Given a function expression, compute the return type of the function. The r eturn type of
3026 * functions with a block body is {@code dynamicType}, with an expression body it is the type of 3464 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
3027 * the expression. 3465 * the expression.
3028 * @param node the function expression whose return type is to be computed 3466 * @param node the function expression whose return type is to be computed
3029 * @return the return type that was computed 3467 * @return the return type that was computed
3030 */ 3468 */
3031 Type2 computeReturnType(FunctionExpression node) { 3469 Type2 computeReturnType2(FunctionExpression node) {
3032 FunctionBody body4 = node.body; 3470 FunctionBody body4 = node.body;
3033 if (body4 is ExpressionFunctionBody) { 3471 if (body4 is ExpressionFunctionBody) {
3034 return getType(((body4 as ExpressionFunctionBody)).expression); 3472 return getType(((body4 as ExpressionFunctionBody)).expression);
3035 } 3473 }
3036 return _typeProvider.dynamicType; 3474 return _dynamicType;
3037 } 3475 }
3038 /** 3476 /**
3039 * Return the type of the given expression that is to be used for type analysi s. 3477 * Return the type of the given expression that is to be used for type analysi s.
3040 * @param expression the expression whose type is to be returned 3478 * @param expression the expression whose type is to be returned
3041 * @return the type of the given expression 3479 * @return the type of the given expression
3042 */ 3480 */
3043 Type2 getType(Expression expression) { 3481 Type2 getType(Expression expression) {
3044 Type2 type = expression.staticType; 3482 Type2 type = expression.staticType;
3045 if (type == null) { 3483 if (type == null) {
3046 return _typeProvider.dynamicType; 3484 return _dynamicType;
3047 } 3485 }
3048 return type; 3486 return type;
3049 } 3487 }
3050 /** 3488 /**
3489 * Return the type that should be recorded for a node that resolved to the giv en accessor.
3490 * @param accessor the accessor that the node resolved to
3491 * @return the type that should be recorded for a node that resolved to the gi ven accessor
3492 */
3493 Type2 getType2(PropertyAccessorElement accessor) {
3494 if (accessor.isSetter()) {
3495 PropertyAccessorElement getter4 = accessor.variable.getter;
3496 if (getter4 == null) {
3497 List<Type2> parameterTypes = accessor.type.normalParameterTypes;
3498 if (parameterTypes.length > 0) {
3499 return parameterTypes[0];
3500 } else {
3501 return _dynamicType;
3502 }
3503 }
3504 accessor = getter4;
3505 }
3506 if (accessor.type == null) {
3507 return _dynamicType;
3508 }
3509 return accessor.type.returnType;
3510 }
3511 /**
3051 * Return the type represented by the given type name. 3512 * Return the type represented by the given type name.
3052 * @param typeName the type name representing the type to be returned 3513 * @param typeName the type name representing the type to be returned
3053 * @return the type represented by the type name 3514 * @return the type represented by the type name
3054 */ 3515 */
3055 Type2 getType2(TypeName typeName) { 3516 Type2 getType3(TypeName typeName) {
3056 Type2 type12 = typeName.type; 3517 Type2 type16 = typeName.type;
3057 if (type12 == null) { 3518 if (type16 == null) {
3058 return _typeProvider.dynamicType; 3519 return _dynamicType;
3059 } 3520 }
3060 return type12; 3521 return type16;
3061 } 3522 }
3062 /** 3523 /**
3063 * Return {@code true} if the given node is being used as the name of a type. 3524 * Return {@code true} if the given node is being used as the name of a type.
3064 * @param node the node being tested 3525 * @param node the node being tested
3065 * @return {@code true} if the given node is being used as the name of a type 3526 * @return {@code true} if the given node is being used as the name of a type
3066 */ 3527 */
3067 bool isTypeName(SimpleIdentifier node) { 3528 bool isTypeName(SimpleIdentifier node) {
3068 ASTNode parent8 = node.parent; 3529 ASTNode parent15 = node.parent;
3069 return parent8 is TypeName || (parent8 is PrefixedIdentifier && parent8.pare nt is TypeName) || (parent8 is MethodInvocation && identical(node, ((parent8 as MethodInvocation)).target)); 3530 return parent15 is TypeName || (parent15 is PrefixedIdentifier && parent15.p arent is TypeName) || (parent15 is MethodInvocation && identical(node, ((parent1 5 as MethodInvocation)).target));
3531 }
3532 /**
3533 * Record that the static type of the given node is the type of the second arg ument to the method
3534 * represented by the given element.
3535 * @param expression the node whose type is to be recorded
3536 * @param element the element representing the method invoked by the given nod e
3537 */
3538 Object recordArgumentType(IndexExpression expression, MethodElement element) {
3539 if (element != null) {
3540 List<ParameterElement> parameters12 = element.parameters;
3541 if (parameters12 != null && parameters12.length == 2) {
3542 return recordType(expression, parameters12[1].type);
3543 }
3544 }
3545 return recordType(expression, _dynamicType);
3070 } 3546 }
3071 /** 3547 /**
3072 * Record that the static type of the given node is the return type of the met hod or function 3548 * Record that the static type of the given node is the return type of the met hod or function
3073 * represented by the given element. 3549 * represented by the given element.
3074 * @param expression the node whose type is to be recorded 3550 * @param expression the node whose type is to be recorded
3075 * @param element the element representing the method or function invoked by t he given node 3551 * @param element the element representing the method or function invoked by t he given node
3076 */ 3552 */
3077 Object recordReturnType(Expression expression, Element element) { 3553 Object recordReturnType(Expression expression, Element element) {
3078 if (element is ExecutableElement) { 3554 if (element is ExecutableElement) {
3079 FunctionType type13 = ((element as ExecutableElement)).type; 3555 FunctionType type17 = ((element as ExecutableElement)).type;
3080 if (type13 != null) { 3556 if (type17 != null) {
3081 return recordType(expression, type13.returnType); 3557 return recordType(expression, type17.returnType);
3082 } 3558 }
3083 } else if (element is VariableElement) { 3559 } else if (element is VariableElement) {
3084 Type2 variableType = ((element as VariableElement)).type; 3560 Type2 variableType = ((element as VariableElement)).type;
3085 if (variableType is FunctionType) { 3561 if (variableType is FunctionType) {
3086 return recordType(expression, ((variableType as FunctionType)).returnTyp e); 3562 return recordType(expression, ((variableType as FunctionType)).returnTyp e);
3087 } 3563 }
3088 } 3564 }
3089 return recordType(expression, _typeProvider.dynamicType); 3565 return recordType(expression, _dynamicType);
3090 } 3566 }
3091 /** 3567 /**
3092 * Record that the static type of the given node is the given type. 3568 * Record that the static type of the given node is the given type.
3093 * @param expression the node whose type is to be recorded 3569 * @param expression the node whose type is to be recorded
3094 * @param type the static type of the node 3570 * @param type the static type of the node
3095 */ 3571 */
3096 Object recordType(Expression expression, Type2 type) { 3572 Object recordType(Expression expression, Type2 type) {
3097 if (type == null) { 3573 if (type == null) {
3098 expression.staticType = _typeProvider.dynamicType; 3574 expression.staticType = _dynamicType;
3099 } else { 3575 } else {
3100 expression.staticType = type; 3576 expression.staticType = type;
3101 } 3577 }
3102 return null; 3578 return null;
3103 } 3579 }
3104 /** 3580 /**
3105 * Set the return type and parameter type information for the given function t ype based on the 3581 * Set the return type and parameter type information for the given function t ype based on the
3106 * given return type and parameter elements. 3582 * given return type and parameter elements.
3107 * @param functionType the function type to be filled in 3583 * @param functionType the function type to be filled in
3108 * @param returnType the return type of the function, or {@code null} if no ty pe was declared 3584 * @param returnType the return type of the function, or {@code null} if no ty pe was declared
3109 * @param parameters the elements representing the parameters to the function 3585 * @param parameters the elements representing the parameters to the function
3110 */ 3586 */
3111 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType7, Form alParameterList parameterList) { 3587 void setTypeInformation(FunctionTypeImpl functionType, Type2 returnType9, Form alParameterList parameterList) {
3112 List<Type2> normalParameterTypes = new List<Type2>(); 3588 List<Type2> normalParameterTypes = new List<Type2>();
3113 List<Type2> optionalParameterTypes = new List<Type2>(); 3589 List<Type2> optionalParameterTypes = new List<Type2>();
3114 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>(); 3590 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
3115 if (parameterList != null) { 3591 if (parameterList != null) {
3116 for (ParameterElement parameter in parameterList.elements) { 3592 for (ParameterElement parameter in parameterList.elements) {
3117 if (parameter.parameterKind == ParameterKind.REQUIRED) { 3593 while (true) {
3118 normalParameterTypes.add(parameter.type); 3594 if (parameter.parameterKind == ParameterKind.REQUIRED) {
3119 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { 3595 normalParameterTypes.add(parameter.type);
3120 optionalParameterTypes.add(parameter.type); 3596 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) {
3121 } else if (parameter.parameterKind == ParameterKind.NAMED) { 3597 optionalParameterTypes.add(parameter.type);
3122 namedParameterTypes[parameter.name] = parameter.type; 3598 } else if (parameter.parameterKind == ParameterKind.NAMED) {
3599 namedParameterTypes[parameter.name] = parameter.type;
3600 }
3601 break;
3123 } 3602 }
3124 } 3603 }
3125 } 3604 }
3126 functionType.normalParameterTypes = new List.from(normalParameterTypes); 3605 functionType.normalParameterTypes = new List.from(normalParameterTypes);
3127 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); 3606 functionType.optionalParameterTypes = new List.from(optionalParameterTypes);
3128 functionType.namedParameterTypes = namedParameterTypes; 3607 functionType.namedParameterTypes = namedParameterTypes;
3129 functionType.returnType = returnType7; 3608 functionType.returnType = returnType9;
3130 } 3609 }
3131 } 3610 }
3132 /** 3611 /**
3133 * The interface {@code TypeProvider} defines the behavior of objects that provi de access to types 3612 * The interface {@code TypeProvider} defines the behavior of objects that provi de access to types
3134 * defined by the language. 3613 * defined by the language.
3135 */ 3614 */
3136 abstract class TypeProvider { 3615 abstract class TypeProvider {
3137 /** 3616 /**
3138 * Return the type representing the built-in type 'bool'. 3617 * Return the type representing the built-in type 'bool'.
3139 * @return the type representing the built-in type 'bool' 3618 * @return the type representing the built-in type 'bool'
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3303 } 3782 }
3304 } 3783 }
3305 /** 3784 /**
3306 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty pes associated with 3785 * Instances of the class {@code TypeResolverVisitor} are used to resolve the ty pes associated with
3307 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces, 3786 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces,
3308 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building 3787 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building
3309 * the type hierarchy. 3788 * the type hierarchy.
3310 */ 3789 */
3311 class TypeResolverVisitor extends ScopedVisitor { 3790 class TypeResolverVisitor extends ScopedVisitor {
3312 /** 3791 /**
3792 * The type representing the type 'dynamic'.
3793 */
3794 Type2 _dynamicType;
3795 /**
3313 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 3796 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
3314 * @param library the library containing the compilation unit being resolved 3797 * @param library the library containing the compilation unit being resolved
3315 * @param source the source representing the compilation unit being visited 3798 * @param source the source representing the compilation unit being visited
3316 * @param typeProvider the object used to access the types from the core libra ry 3799 * @param typeProvider the object used to access the types from the core libra ry
3317 */ 3800 */
3318 TypeResolverVisitor(Library library, Source source, TypeProvider typeProvider) : super(library, source, typeProvider) { 3801 TypeResolverVisitor(Library library, Source source, TypeProvider typeProvider) : super(library, source, typeProvider) {
3802 _dynamicType = typeProvider.dynamicType;
3319 } 3803 }
3320 Object visitCatchClause(CatchClause node) { 3804 Object visitCatchClause(CatchClause node) {
3321 super.visitCatchClause(node); 3805 super.visitCatchClause(node);
3322 SimpleIdentifier exception = node.exceptionParameter; 3806 SimpleIdentifier exception = node.exceptionParameter;
3323 if (exception != null) { 3807 if (exception != null) {
3324 TypeName exceptionTypeName = node.exceptionType; 3808 TypeName exceptionTypeName = node.exceptionType;
3325 Type2 exceptionType; 3809 Type2 exceptionType;
3326 if (exceptionTypeName == null) { 3810 if (exceptionTypeName == null) {
3327 exceptionType = typeProvider.objectType; 3811 exceptionType = typeProvider.objectType;
3328 } else { 3812 } else {
3329 exceptionType = getType(exceptionTypeName); 3813 exceptionType = getType4(exceptionTypeName);
3330 } 3814 }
3331 recordType(exception, exceptionType); 3815 recordType(exception, exceptionType);
3332 Element element23 = exception.element; 3816 Element element26 = exception.element;
3333 if (element23 is VariableElementImpl) { 3817 if (element26 is VariableElementImpl) {
3334 ((element23 as VariableElementImpl)).type = exceptionType; 3818 ((element26 as VariableElementImpl)).type = exceptionType;
3335 } else { 3819 } else {
3336 } 3820 }
3337 } 3821 }
3338 SimpleIdentifier stackTrace = node.stackTraceParameter; 3822 SimpleIdentifier stackTrace = node.stackTraceParameter;
3339 if (stackTrace != null) { 3823 if (stackTrace != null) {
3340 recordType(stackTrace, typeProvider.stackTraceType); 3824 recordType(stackTrace, typeProvider.stackTraceType);
3341 } 3825 }
3342 return null; 3826 return null;
3343 } 3827 }
3344 Object visitClassDeclaration(ClassDeclaration node) { 3828 Object visitClassDeclaration(ClassDeclaration node) {
3345 super.visitClassDeclaration(node); 3829 super.visitClassDeclaration(node);
3346 ClassElementImpl classElement = getClassElement(node.name); 3830 ClassElementImpl classElement = getClassElement(node.name);
3347 InterfaceType superclassType = null; 3831 InterfaceType superclassType = null;
3348 ExtendsClause extendsClause4 = node.extendsClause; 3832 ExtendsClause extendsClause4 = node.extendsClause;
3349 if (extendsClause4 != null) { 3833 if (extendsClause4 != null) {
3350 superclassType = resolveType(extendsClause4.superclass, null, null, null); 3834 superclassType = resolveType(extendsClause4.superclass, CompileTimeErrorCo de.EXTENDS_NON_CLASS, CompileTimeErrorCode.EXTENDS_NON_CLASS, null);
3835 if (superclassType != typeProvider.objectType) {
3836 classElement.validMixin = false;
3837 }
3351 } 3838 }
3352 if (classElement != null) { 3839 if (classElement != null) {
3353 if (superclassType == null) { 3840 if (superclassType == null) {
3354 InterfaceType objectType2 = typeProvider.objectType; 3841 InterfaceType objectType2 = typeProvider.objectType;
3355 if (classElement.type != objectType2) { 3842 if (classElement.type != objectType2) {
3356 superclassType = objectType2; 3843 superclassType = objectType2;
3357 } 3844 }
3358 } 3845 }
3359 classElement.supertype = superclassType; 3846 classElement.supertype = superclassType;
3360 } 3847 }
3361 resolve(classElement, node.withClause, node.implementsClause); 3848 resolve(classElement, node.withClause, node.implementsClause);
3362 return null; 3849 return null;
3363 } 3850 }
3364 Object visitClassTypeAlias(ClassTypeAlias node) { 3851 Object visitClassTypeAlias(ClassTypeAlias node) {
3365 super.visitClassTypeAlias(node); 3852 super.visitClassTypeAlias(node);
3366 ClassElementImpl classElement = getClassElement(node.name); 3853 ClassElementImpl classElement = getClassElement(node.name);
3367 InterfaceType superclassType = resolveType(node.superclass, null, null, null ); 3854 InterfaceType superclassType = resolveType(node.superclass, CompileTimeError Code.EXTENDS_NON_CLASS, CompileTimeErrorCode.EXTENDS_NON_CLASS, null);
3368 if (superclassType == null) { 3855 if (superclassType == null) {
3369 superclassType = typeProvider.objectType; 3856 superclassType = typeProvider.objectType;
3370 } 3857 }
3371 if (classElement != null && superclassType != null) { 3858 if (classElement != null && superclassType != null) {
3372 classElement.supertype = superclassType; 3859 classElement.supertype = superclassType;
3373 } 3860 }
3374 resolve(classElement, node.withClause, node.implementsClause); 3861 resolve(classElement, node.withClause, node.implementsClause);
3375 return null; 3862 return null;
3376 } 3863 }
3377 Object visitConstructorDeclaration(ConstructorDeclaration node) { 3864 Object visitConstructorDeclaration(ConstructorDeclaration node) {
3378 super.visitConstructorDeclaration(node); 3865 super.visitConstructorDeclaration(node);
3379 ExecutableElementImpl element24 = (node.element as ExecutableElementImpl); 3866 ExecutableElementImpl element27 = node.element as ExecutableElementImpl;
3380 FunctionTypeImpl type = new FunctionTypeImpl.con1(element24); 3867 FunctionTypeImpl type = new FunctionTypeImpl.con1(element27);
3381 setTypeInformation(type, null, element24.parameters); 3868 setTypeInformation(type, null, element27.parameters);
3382 type.returnType = ((element24.enclosingElement as ClassElement)).type; 3869 type.returnType = ((element27.enclosingElement as ClassElement)).type;
3383 element24.type = type; 3870 element27.type = type;
3384 return null; 3871 return null;
3385 } 3872 }
3386 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 3873 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
3387 super.visitDefaultFormalParameter(node); 3874 super.visitDefaultFormalParameter(node);
3388 return null; 3875 return null;
3389 } 3876 }
3390 Object visitFieldFormalParameter(FieldFormalParameter node) { 3877 Object visitFieldFormalParameter(FieldFormalParameter node) {
3391 super.visitFieldFormalParameter(node); 3878 super.visitFieldFormalParameter(node);
3392 Element element25 = node.identifier.element; 3879 Element element28 = node.identifier.element;
3393 if (element25 is ParameterElementImpl) { 3880 if (element28 is ParameterElementImpl) {
3394 ParameterElementImpl parameter = (element25 as ParameterElementImpl); 3881 ParameterElementImpl parameter = element28 as ParameterElementImpl;
3395 Type2 type; 3882 Type2 type;
3396 TypeName typeName = node.type; 3883 TypeName typeName = node.type;
3397 if (typeName == null) { 3884 if (typeName == null) {
3398 type = typeProvider.dynamicType; 3885 type = _dynamicType;
3399 } else { 3886 } else {
3400 type = getType(typeName); 3887 type = getType4(typeName);
3401 } 3888 }
3402 parameter.type = type; 3889 parameter.type = type;
3403 } else { 3890 } else {
3404 } 3891 }
3405 return null; 3892 return null;
3406 } 3893 }
3407 Object visitFunctionDeclaration(FunctionDeclaration node) { 3894 Object visitFunctionDeclaration(FunctionDeclaration node) {
3408 super.visitFunctionDeclaration(node); 3895 super.visitFunctionDeclaration(node);
3409 ExecutableElementImpl element26 = (node.element as ExecutableElementImpl); 3896 ExecutableElementImpl element29 = node.element as ExecutableElementImpl;
3410 FunctionTypeImpl type = new FunctionTypeImpl.con1(element26);
3411 setTypeInformation(type, node.returnType, element26.parameters);
3412 element26.type = type;
3413 return null;
3414 }
3415 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
3416 super.visitFunctionTypeAlias(node);
3417 TypeAliasElementImpl element27 = (node.element as TypeAliasElementImpl);
3418 FunctionTypeImpl type14 = (element27.type as FunctionTypeImpl);
3419 setTypeInformation(type14, node.returnType, element27.parameters);
3420 return null;
3421 }
3422 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
3423 super.visitFunctionTypedFormalParameter(node);
3424 ParameterElementImpl element28 = (node.identifier.element as ParameterElemen tImpl);
3425 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement ));
3426 setTypeInformation(type, node.returnType, getElements(node.parameters));
3427 element28.type = type;
3428 return null;
3429 }
3430 Object visitMethodDeclaration(MethodDeclaration node) {
3431 super.visitMethodDeclaration(node);
3432 ExecutableElementImpl element29 = (node.element as ExecutableElementImpl);
3433 FunctionTypeImpl type = new FunctionTypeImpl.con1(element29); 3897 FunctionTypeImpl type = new FunctionTypeImpl.con1(element29);
3434 setTypeInformation(type, node.returnType, element29.parameters); 3898 setTypeInformation(type, node.returnType, element29.parameters);
3435 element29.type = type; 3899 element29.type = type;
3436 return null; 3900 return null;
3437 } 3901 }
3902 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
3903 super.visitFunctionTypeAlias(node);
3904 TypeAliasElementImpl element30 = node.element as TypeAliasElementImpl;
3905 FunctionTypeImpl type18 = element30.type as FunctionTypeImpl;
3906 setTypeInformation(type18, node.returnType, element30.parameters);
3907 return null;
3908 }
3909 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
3910 super.visitFunctionTypedFormalParameter(node);
3911 ParameterElementImpl element31 = node.identifier.element as ParameterElement Impl;
3912 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement ));
3913 setTypeInformation(type, node.returnType, getElements(node.parameters));
3914 element31.type = type;
3915 return null;
3916 }
3917 Object visitMethodDeclaration(MethodDeclaration node) {
3918 super.visitMethodDeclaration(node);
3919 ExecutableElementImpl element32 = node.element as ExecutableElementImpl;
3920 FunctionTypeImpl type = new FunctionTypeImpl.con1(element32);
3921 setTypeInformation(type, node.returnType, element32.parameters);
3922 element32.type = type;
3923 if (element32 is PropertyAccessorElementImpl) {
3924 PropertyAccessorElementImpl accessor = element32 as PropertyAccessorElemen tImpl;
3925 PropertyInducingElementImpl variable5 = accessor.variable as PropertyInduc ingElementImpl;
3926 if (accessor.isGetter()) {
3927 variable5.type = type.returnType;
3928 } else if (variable5.type == null) {
3929 List<Type2> parameterTypes = type.normalParameterTypes;
3930 if (parameterTypes != null && parameterTypes.length > 0) {
3931 variable5.type = parameterTypes[0];
3932 }
3933 }
3934 }
3935 return null;
3936 }
3438 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 3937 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
3439 super.visitSimpleFormalParameter(node); 3938 super.visitSimpleFormalParameter(node);
3440 Type2 declaredType; 3939 Type2 declaredType;
3441 TypeName typeName = node.type; 3940 TypeName typeName = node.type;
3442 if (typeName == null) { 3941 if (typeName == null) {
3443 declaredType = typeProvider.dynamicType; 3942 declaredType = _dynamicType;
3444 } else { 3943 } else {
3445 declaredType = getType(typeName); 3944 declaredType = getType4(typeName);
3446 } 3945 }
3447 Element element30 = node.identifier.element; 3946 Element element33 = node.identifier.element;
3448 if (element30 is ParameterElement) { 3947 if (element33 is ParameterElement) {
3449 ((element30 as ParameterElementImpl)).type = declaredType; 3948 ((element33 as ParameterElementImpl)).type = declaredType;
3450 } else { 3949 } else {
3451 } 3950 }
3452 return null; 3951 return null;
3453 } 3952 }
3454 Object visitTypeName(TypeName node) { 3953 Object visitTypeName(TypeName node) {
3455 super.visitTypeName(node); 3954 super.visitTypeName(node);
3456 Identifier typeName = node.name; 3955 Identifier typeName = node.name;
3956 TypeArgumentList argumentList = node.typeArguments;
3457 Element element = nameScope.lookup(typeName, definingLibrary); 3957 Element element = nameScope.lookup(typeName, definingLibrary);
3458 Type2 type = null;
3459 if (element == null) { 3958 if (element == null) {
3460 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; 3959 if (typeName.name == _dynamicType.name) {
3960 setElement(typeName, _dynamicType.element);
3961 if (argumentList != null) {
3962 }
3963 typeName.staticType = _dynamicType;
3964 node.type = _dynamicType;
3965 return null;
3966 }
3461 VoidTypeImpl voidType = VoidTypeImpl.instance; 3967 VoidTypeImpl voidType = VoidTypeImpl.instance;
3462 if (typeName.name == dynamicType.name) { 3968 if (typeName.name == voidType.name) {
3463 element = dynamicType.element; 3969 if (argumentList != null) {
3464 type = dynamicType; 3970 }
3465 setElement(typeName, element); 3971 typeName.staticType = voidType;
3466 } else if (typeName.name == voidType.name) { 3972 node.type = voidType;
3467 type = voidType; 3973 return null;
3468 } else { 3974 }
3469 ASTNode parent9 = node.parent; 3975 ASTNode parent16 = node.parent;
3470 if (typeName is PrefixedIdentifier && parent9 is ConstructorName) { 3976 if (typeName is PrefixedIdentifier && parent16 is ConstructorName && argum entList == null) {
3471 ConstructorName name = (parent9 as ConstructorName); 3977 ConstructorName name = parent16 as ConstructorName;
3472 if (name.name == null) { 3978 if (name.name == null) {
3473 SimpleIdentifier prefix7 = ((typeName as PrefixedIdentifier)).prefix ; 3979 SimpleIdentifier prefix8 = ((typeName as PrefixedIdentifier)).prefix;
3474 element = nameScope.lookup(prefix7, definingLibrary); 3980 element = nameScope.lookup(prefix8, definingLibrary);
3475 if (element is PrefixElement) { 3981 if (element is PrefixElement) {
3476 return null; 3982 return null;
3477 } else if (element != null) { 3983 } else if (element != null) {
3478 name.name = ((typeName as PrefixedIdentifier)).identifier; 3984 name.name = ((typeName as PrefixedIdentifier)).identifier;
3479 node.name = prefix7; 3985 name.period = ((typeName as PrefixedIdentifier)).period;
3480 typeName = prefix7; 3986 node.name = prefix8;
3481 } 3987 typeName = prefix8;
3482 } 3988 }
3483 } 3989 }
3484 } 3990 }
3485 } 3991 }
3486 if (element == null && type == null) { 3992 if (element == null) {
3993 setElement(typeName, _dynamicType.element);
3994 typeName.staticType = _dynamicType;
3995 node.type = _dynamicType;
3487 return null; 3996 return null;
3488 } else if (element is ClassElement) { 3997 }
3998 Type2 type = null;
3999 if (element is ClassElement) {
3489 setElement(typeName, element); 4000 setElement(typeName, element);
3490 type = ((element as ClassElement)).type; 4001 type = ((element as ClassElement)).type;
3491 } else if (element is TypeAliasElement) { 4002 } else if (element is TypeAliasElement) {
3492 setElement(typeName, element); 4003 setElement(typeName, element);
3493 type = ((element as TypeAliasElement)).type; 4004 type = ((element as TypeAliasElement)).type;
3494 } else if (element is TypeVariableElement) { 4005 } else if (element is TypeVariableElement) {
3495 setElement(typeName, element); 4006 setElement(typeName, element);
3496 type = ((element as TypeVariableElement)).type; 4007 type = ((element as TypeVariableElement)).type;
3497 } else if (type == null) { 4008 if (argumentList != null) {
4009 }
4010 } else {
4011 setElement(typeName, _dynamicType.element);
4012 typeName.staticType = _dynamicType;
4013 node.type = _dynamicType;
3498 return null; 4014 return null;
3499 } 4015 }
3500 if (type == null) {
3501 return null;
3502 }
3503 TypeArgumentList argumentList = node.typeArguments;
3504 if (argumentList != null) { 4016 if (argumentList != null) {
3505 NodeList<TypeName> arguments5 = argumentList.arguments; 4017 NodeList<TypeName> arguments5 = argumentList.arguments;
3506 int argumentCount = arguments5.length; 4018 int argumentCount = arguments5.length;
3507 List<Type2> parameters = getTypeArguments(type); 4019 List<Type2> parameters = getTypeArguments(type);
3508 int parameterCount = parameters.length; 4020 int parameterCount = parameters.length;
3509 if (argumentCount != parameterCount) { 4021 int count = Math.min(argumentCount, parameterCount);
3510 } 4022 List<Type2> typeArguments = new List<Type2>(count);
3511 List<Type2> typeArguments = new List<Type2>(argumentCount); 4023 for (int i = 0; i < count; i++) {
3512 for (int i = 0; i < argumentCount; i++) { 4024 Type2 argumentType = getType4(arguments5[i]);
3513 Type2 argumentType = getType(arguments5[i]);
3514 if (argumentType != null) { 4025 if (argumentType != null) {
3515 typeArguments.add(argumentType); 4026 typeArguments.add(argumentType);
3516 } 4027 }
3517 } 4028 }
4029 if (argumentCount != parameterCount) {
4030 reportError(getInvalidTypeParametersErrorCode(node), node, [typeName.nam e, argumentCount, parameterCount]);
4031 }
4032 argumentCount = typeArguments.length;
4033 if (argumentCount < parameterCount) {
4034 for (int i = argumentCount; i < parameterCount; i++) {
4035 typeArguments.add(_dynamicType);
4036 }
4037 }
3518 if (type is InterfaceTypeImpl) { 4038 if (type is InterfaceTypeImpl) {
3519 InterfaceTypeImpl interfaceType = (type as InterfaceTypeImpl); 4039 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl;
3520 argumentCount = typeArguments.length; 4040 type = interfaceType.substitute5(new List.from(typeArguments));
3521 if (interfaceType.typeArguments.length == argumentCount) {
3522 type = interfaceType.substitute5(new List.from(typeArguments));
3523 } else {
3524 }
3525 } else if (type is FunctionTypeImpl) { 4041 } else if (type is FunctionTypeImpl) {
3526 FunctionTypeImpl functionType = (type as FunctionTypeImpl); 4042 FunctionTypeImpl functionType = type as FunctionTypeImpl;
3527 argumentCount = typeArguments.length; 4043 type = functionType.substitute4(new List.from(typeArguments));
3528 if (functionType.typeArguments.length == argumentCount) {
3529 type = functionType.substitute4(new List.from(typeArguments));
3530 } else {
3531 }
3532 } else { 4044 } else {
3533 } 4045 }
3534 } else { 4046 } else {
3535 List<Type2> parameters = getTypeArguments(type); 4047 List<Type2> parameters = getTypeArguments(type);
3536 int parameterCount = parameters.length; 4048 int parameterCount = parameters.length;
3537 if (parameterCount > 0) { 4049 if (parameterCount > 0) {
3538 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; 4050 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance;
3539 List<Type2> arguments = new List<Type2>(parameterCount); 4051 List<Type2> arguments = new List<Type2>(parameterCount);
3540 for (int i = 0; i < parameterCount; i++) { 4052 for (int i = 0; i < parameterCount; i++) {
3541 arguments[i] = dynamicType; 4053 arguments[i] = dynamicType;
3542 } 4054 }
3543 type = type.substitute2(arguments, parameters); 4055 type = type.substitute2(arguments, parameters);
3544 } 4056 }
3545 } 4057 }
3546 typeName.staticType = type; 4058 typeName.staticType = type;
3547 node.type = type; 4059 node.type = type;
3548 return null; 4060 return null;
3549 } 4061 }
3550 Object visitVariableDeclaration(VariableDeclaration node) { 4062 Object visitVariableDeclaration(VariableDeclaration node) {
3551 super.visitVariableDeclaration(node); 4063 super.visitVariableDeclaration(node);
3552 Type2 declaredType; 4064 Type2 declaredType;
3553 TypeName typeName = ((node.parent as VariableDeclarationList)).type; 4065 TypeName typeName = ((node.parent as VariableDeclarationList)).type;
3554 if (typeName == null) { 4066 if (typeName == null) {
3555 declaredType = typeProvider.dynamicType; 4067 declaredType = _dynamicType;
3556 } else { 4068 } else {
3557 declaredType = getType(typeName); 4069 declaredType = getType4(typeName);
3558 } 4070 }
3559 Element element31 = node.name.element; 4071 Element element34 = node.name.element;
3560 if (element31 is VariableElement) { 4072 if (element34 is VariableElement) {
3561 ((element31 as VariableElementImpl)).type = declaredType; 4073 ((element34 as VariableElementImpl)).type = declaredType;
3562 if (element31 is FieldElement) { 4074 if (element34 is FieldElement) {
3563 FieldElement field = (element31 as FieldElement); 4075 FieldElement field = element34 as FieldElement;
3564 PropertyAccessorElementImpl getter3 = (field.getter as PropertyAccessorE lementImpl); 4076 PropertyAccessorElementImpl getter5 = field.getter as PropertyAccessorEl ementImpl;
3565 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter3); 4077 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter5);
3566 getterType.returnType = declaredType; 4078 getterType.returnType = declaredType;
3567 getter3.type = getterType; 4079 getter5.type = getterType;
3568 PropertyAccessorElementImpl setter3 = (field.setter as PropertyAccessorE lementImpl); 4080 PropertyAccessorElementImpl setter4 = field.setter as PropertyAccessorEl ementImpl;
3569 if (setter3 != null) { 4081 if (setter4 != null) {
3570 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter3); 4082 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(setter4);
3571 setterType.returnType = VoidTypeImpl.instance; 4083 setterType.returnType = VoidTypeImpl.instance;
3572 setterType.normalParameterTypes = <Type2> [declaredType]; 4084 setterType.normalParameterTypes = <Type2> [declaredType];
3573 setter3.type = setterType; 4085 setter4.type = setterType;
3574 } 4086 }
3575 } 4087 }
3576 } else { 4088 } else {
3577 } 4089 }
3578 return null; 4090 return null;
3579 } 4091 }
3580 /** 4092 /**
3581 * Return the class element that represents the class whose name was provided. 4093 * Return the class element that represents the class whose name was provided.
3582 * @param identifier the name from the declaration of a class 4094 * @param identifier the name from the declaration of a class
3583 * @return the class element that represents the class 4095 * @return the class element that represents the class
3584 */ 4096 */
3585 ClassElementImpl getClassElement(SimpleIdentifier identifier) { 4097 ClassElementImpl getClassElement(SimpleIdentifier identifier) {
3586 if (identifier == null) { 4098 if (identifier == null) {
3587 return null; 4099 return null;
3588 } 4100 }
3589 Element element32 = identifier.element; 4101 Element element35 = identifier.element;
3590 if (element32 is! ClassElementImpl) { 4102 if (element35 is! ClassElementImpl) {
3591 return null; 4103 return null;
3592 } 4104 }
3593 return (element32 as ClassElementImpl); 4105 return element35 as ClassElementImpl;
3594 } 4106 }
3595 /** 4107 /**
3596 * Return an array containing all of the elements associated with the paramete rs in the given 4108 * Return an array containing all of the elements associated with the paramete rs in the given
3597 * list. 4109 * list.
3598 * @param parameterList the list of parameters whose elements are to be return ed 4110 * @param parameterList the list of parameters whose elements are to be return ed
3599 * @return the elements associated with the parameters 4111 * @return the elements associated with the parameters
3600 */ 4112 */
3601 List<ParameterElement> getElements(FormalParameterList parameterList) { 4113 List<ParameterElement> getElements(FormalParameterList parameterList) {
3602 List<ParameterElement> elements = new List<ParameterElement>(); 4114 List<ParameterElement> elements = new List<ParameterElement>();
3603 for (FormalParameter parameter in parameterList.parameters) { 4115 for (FormalParameter parameter in parameterList.parameters) {
3604 ParameterElement element33 = (parameter.identifier.element as ParameterEle ment); 4116 ParameterElement element36 = parameter.identifier.element as ParameterElem ent;
3605 if (element33 != null) { 4117 if (element36 != null) {
3606 elements.add(element33); 4118 elements.add(element36);
3607 } 4119 }
3608 } 4120 }
3609 return new List.from(elements); 4121 return new List.from(elements);
3610 } 4122 }
3611 /** 4123 /**
4124 * The number of type arguments in the given type name does not match the numb er of parameters in
4125 * the corresponding class element. Return the error code that should be used to report this
4126 * error.
4127 * @param node the type name with the wrong number of type arguments
4128 * @return the error code that should be used to report that the wrong number of type arguments
4129 * were provided
4130 */
4131 ErrorCode getInvalidTypeParametersErrorCode(TypeName node) {
4132 ASTNode parent17 = node.parent;
4133 if (parent17 is ConstructorName) {
4134 parent17 = parent17.parent;
4135 if (parent17 is InstanceCreationExpression) {
4136 if (((parent17 as InstanceCreationExpression)).isConst()) {
4137 return CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS;
4138 } else {
4139 return CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS;
4140 }
4141 }
4142 }
4143 return StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
4144 }
4145 /**
4146 * Given the multiple elements to which a single name could potentially be res olved, return the
4147 * single interface type that should be used, or {@code null} if there is no c lear choice.
4148 * @param elements the elements to which a single name could potentially be re solved
4149 * @return the single interface type that should be used for the type name
4150 */
4151 InterfaceType getType(List<Element> elements) {
4152 InterfaceType type = null;
4153 for (Element element in elements) {
4154 if (element is ClassElement) {
4155 if (type != null) {
4156 return null;
4157 }
4158 type = ((element as ClassElement)).type;
4159 }
4160 }
4161 return type;
4162 }
4163 /**
3612 * Return the type represented by the given type name. 4164 * Return the type represented by the given type name.
3613 * @param typeName the type name representing the type to be returned 4165 * @param typeName the type name representing the type to be returned
3614 * @return the type represented by the type name 4166 * @return the type represented by the type name
3615 */ 4167 */
3616 Type2 getType(TypeName typeName) => typeName.type; 4168 Type2 getType4(TypeName typeName) {
4169 Type2 type19 = typeName.type;
4170 if (type19 == null) {
4171 return _dynamicType;
4172 }
4173 return type19;
4174 }
3617 /** 4175 /**
3618 * Return the type arguments associated with the given type. 4176 * Return the type arguments associated with the given type.
3619 * @param type the type whole type arguments are to be returned 4177 * @param type the type whole type arguments are to be returned
3620 * @return the type arguments associated with the given type 4178 * @return the type arguments associated with the given type
3621 */ 4179 */
3622 List<Type2> getTypeArguments(Type2 type) { 4180 List<Type2> getTypeArguments(Type2 type) {
3623 if (type is InterfaceType) { 4181 if (type is InterfaceType) {
3624 return ((type as InterfaceType)).typeArguments; 4182 return ((type as InterfaceType)).typeArguments;
3625 } else if (type is FunctionType) { 4183 } else if (type is FunctionType) {
3626 return ((type as FunctionType)).typeArguments; 4184 return ((type as FunctionType)).typeArguments;
3627 } 4185 }
3628 return TypeImpl.EMPTY_ARRAY; 4186 return TypeImpl.EMPTY_ARRAY;
3629 } 4187 }
3630 /** 4188 /**
3631 * Record that the static type of the given node is the given type. 4189 * Record that the static type of the given node is the given type.
3632 * @param expression the node whose type is to be recorded 4190 * @param expression the node whose type is to be recorded
3633 * @param type the static type of the node 4191 * @param type the static type of the node
3634 */ 4192 */
3635 Object recordType(Expression expression, Type2 type) { 4193 Object recordType(Expression expression, Type2 type) {
3636 if (type == null) { 4194 if (type == null) {
3637 expression.staticType = typeProvider.dynamicType; 4195 expression.staticType = _dynamicType;
3638 } else { 4196 } else {
3639 expression.staticType = type; 4197 expression.staticType = type;
3640 } 4198 }
3641 return null; 4199 return null;
3642 } 4200 }
3643 /** 4201 /**
3644 * Resolve the types in the given with and implements clauses and associate th ose types with the 4202 * Resolve the types in the given with and implements clauses and associate th ose types with the
3645 * given class element. 4203 * given class element.
3646 * @param classElement the class element with which the mixin and interface ty pes are to be 4204 * @param classElement the class element with which the mixin and interface ty pes are to be
3647 * associated 4205 * associated
3648 * @param withClause the with clause to be resolved 4206 * @param withClause the with clause to be resolved
3649 * @param implementsClause the implements clause to be resolved 4207 * @param implementsClause the implements clause to be resolved
3650 */ 4208 */
3651 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC lause implementsClause) { 4209 void resolve(ClassElementImpl classElement, WithClause withClause, ImplementsC lause implementsClause) {
3652 if (withClause != null) { 4210 if (withClause != null) {
3653 List<InterfaceType> mixinTypes2 = resolveTypes(withClause.mixinTypes, null , null, null); 4211 List<InterfaceType> mixinTypes2 = resolveTypes(withClause.mixinTypes, Comp ileTimeErrorCode.MIXIN_OF_NON_CLASS, CompileTimeErrorCode.MIXIN_OF_NON_CLASS, nu ll);
3654 if (classElement != null) { 4212 if (classElement != null) {
3655 classElement.mixins = mixinTypes2; 4213 classElement.mixins = mixinTypes2;
3656 } 4214 }
3657 } 4215 }
3658 if (implementsClause != null) { 4216 if (implementsClause != null) {
3659 List<InterfaceType> interfaceTypes = resolveTypes(implementsClause.interfa ces, null, null, null); 4217 List<InterfaceType> interfaceTypes = resolveTypes(implementsClause.interfa ces, CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, CompileTimeErrorCode.IMPLEMENTS_ NON_CLASS, null);
3660 if (classElement != null) { 4218 if (classElement != null) {
3661 classElement.interfaces = interfaceTypes; 4219 classElement.interfaces = interfaceTypes;
3662 } 4220 }
3663 } 4221 }
3664 } 4222 }
3665 /** 4223 /**
3666 * Return the type specified by the given name. 4224 * Return the type specified by the given name.
3667 * @param typeName the type name specifying the type to be returned 4225 * @param typeName the type name specifying the type to be returned
3668 * @param undefinedError the error to produce if the type name is not defined 4226 * @param undefinedError the error to produce if the type name is not defined
3669 * @param nonTypeError the error to produce if the type name is defined to be something other than 4227 * @param nonTypeError the error to produce if the type name is defined to be something other than
3670 * a type 4228 * a type
3671 * @param nonInterfaceType the error to produce if the type is not an interfac e type 4229 * @param nonInterfaceType the error to produce if the type is not an interfac e type
3672 * @return the type specified by the type name 4230 * @return the type specified by the type name
3673 */ 4231 */
3674 InterfaceType resolveType(TypeName typeName, ResolverErrorCode undefinedError, ResolverErrorCode nonTypeError, ResolverErrorCode nonInterfaceType) { 4232 InterfaceType resolveType(TypeName typeName, ErrorCode undefinedError, ErrorCo de nonTypeError, ErrorCode nonInterfaceType) {
3675 Identifier name15 = typeName.name; 4233 Identifier name16 = typeName.name;
3676 Element element = nameScope.lookup(name15, definingLibrary); 4234 Element element = nameScope.lookup(name16, definingLibrary);
3677 if (element == null) { 4235 if (element == null) {
3678 reportError(undefinedError, name15, []); 4236 reportError(undefinedError, name16, []);
3679 } else if (element is ClassElement) { 4237 } else if (element is ClassElement) {
3680 Type2 classType = ((element as ClassElement)).type; 4238 Type2 classType = ((element as ClassElement)).type;
3681 typeName.type = classType; 4239 typeName.type = classType;
3682 if (classType is InterfaceType) { 4240 if (classType is InterfaceType) {
3683 return (classType as InterfaceType); 4241 return classType as InterfaceType;
3684 } 4242 }
3685 reportError(nonInterfaceType, name15, []); 4243 reportError(nonInterfaceType, name16, []);
4244 } else if (element is MultiplyDefinedElement) {
4245 List<Element> elements = ((element as MultiplyDefinedElement)).conflicting Elements;
4246 InterfaceType type = getType(elements);
4247 if (type != null) {
4248 typeName.type = type;
4249 }
3686 } else { 4250 } else {
3687 reportError(nonTypeError, name15, []); 4251 reportError(nonTypeError, name16, []);
3688 } 4252 }
3689 return null; 4253 return null;
3690 } 4254 }
3691 /** 4255 /**
3692 * Resolve the types in the given list of type names. 4256 * Resolve the types in the given list of type names.
3693 * @param typeNames the type names to be resolved 4257 * @param typeNames the type names to be resolved
3694 * @param undefinedError the error to produce if the type name is not defined 4258 * @param undefinedError the error to produce if the type name is not defined
3695 * @param nonTypeError the error to produce if the type name is defined to be something other than 4259 * @param nonTypeError the error to produce if the type name is defined to be something other than
3696 * a type 4260 * a type
3697 * @param nonInterfaceType the error to produce if the type is not an interfac e type 4261 * @param nonInterfaceType the error to produce if the type is not an interfac e type
3698 * @return an array containing all of the types that were resolved. 4262 * @return an array containing all of the types that were resolved.
3699 */ 4263 */
3700 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ResolverErrorCo de undefinedError, ResolverErrorCode nonTypeError, ResolverErrorCode nonInterfac eType) { 4264 List<InterfaceType> resolveTypes(NodeList<TypeName> typeNames, ErrorCode undef inedError, ErrorCode nonTypeError, ErrorCode nonInterfaceType) {
3701 List<InterfaceType> types = new List<InterfaceType>(); 4265 List<InterfaceType> types = new List<InterfaceType>();
3702 for (TypeName typeName in typeNames) { 4266 for (TypeName typeName in typeNames) {
3703 InterfaceType type = resolveType(typeName, undefinedError, nonTypeError, n onInterfaceType); 4267 InterfaceType type = resolveType(typeName, undefinedError, nonTypeError, n onInterfaceType);
3704 if (type != null) { 4268 if (type != null) {
3705 types.add(type); 4269 types.add(type);
3706 } 4270 }
3707 } 4271 }
3708 return new List.from(types); 4272 return new List.from(types);
3709 } 4273 }
3710 void setElement(Identifier typeName, Element element41) { 4274 void setElement(Identifier typeName, Element element48) {
3711 if (element41 != null) { 4275 if (element48 != null) {
3712 typeName.element = element41; 4276 if (typeName is SimpleIdentifier) {
3713 if (typeName is PrefixedIdentifier) { 4277 ((typeName as SimpleIdentifier)).element = element48;
3714 PrefixedIdentifier identifier = (typeName as PrefixedIdentifier); 4278 } else if (typeName is PrefixedIdentifier) {
3715 identifier.identifier.element = element41; 4279 PrefixedIdentifier identifier = typeName as PrefixedIdentifier;
3716 SimpleIdentifier prefix8 = identifier.prefix; 4280 identifier.identifier.element = element48;
3717 Element prefixElement = nameScope.lookup(prefix8, definingLibrary); 4281 SimpleIdentifier prefix9 = identifier.prefix;
4282 Element prefixElement = nameScope.lookup(prefix9, definingLibrary);
3718 if (prefixElement != null) { 4283 if (prefixElement != null) {
3719 prefix8.element = prefixElement; 4284 prefix9.element = prefixElement;
3720 } 4285 }
3721 } 4286 }
3722 } 4287 }
3723 } 4288 }
3724 /** 4289 /**
3725 * Set the return type and parameter type information for the given function t ype based on the 4290 * Set the return type and parameter type information for the given function t ype based on the
3726 * given return type and parameter elements. 4291 * given return type and parameter elements.
3727 * @param functionType the function type to be filled in 4292 * @param functionType the function type to be filled in
3728 * @param returnType the return type of the function, or {@code null} if no ty pe was declared 4293 * @param returnType the return type of the function, or {@code null} if no ty pe was declared
3729 * @param parameters the elements representing the parameters to the function 4294 * @param parameters the elements representing the parameters to the function
3730 */ 4295 */
3731 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType8, L ist<ParameterElement> parameters) { 4296 void setTypeInformation(FunctionTypeImpl functionType, TypeName returnType10, List<ParameterElement> parameters) {
3732 List<Type2> normalParameterTypes = new List<Type2>(); 4297 List<Type2> normalParameterTypes = new List<Type2>();
3733 List<Type2> optionalParameterTypes = new List<Type2>(); 4298 List<Type2> optionalParameterTypes = new List<Type2>();
3734 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>(); 4299 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
3735 for (ParameterElement parameter in parameters) { 4300 for (ParameterElement parameter in parameters) {
3736 if (parameter.parameterKind == ParameterKind.REQUIRED) { 4301 while (true) {
3737 normalParameterTypes.add(parameter.type); 4302 if (parameter.parameterKind == ParameterKind.REQUIRED) {
3738 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) { 4303 normalParameterTypes.add(parameter.type);
3739 optionalParameterTypes.add(parameter.type); 4304 } else if (parameter.parameterKind == ParameterKind.POSITIONAL) {
3740 } else if (parameter.parameterKind == ParameterKind.NAMED) { 4305 optionalParameterTypes.add(parameter.type);
3741 namedParameterTypes[parameter.name] = parameter.type; 4306 } else if (parameter.parameterKind == ParameterKind.NAMED) {
4307 namedParameterTypes[parameter.name] = parameter.type;
4308 }
4309 break;
3742 } 4310 }
3743 } 4311 }
3744 functionType.normalParameterTypes = new List.from(normalParameterTypes); 4312 if (!normalParameterTypes.isEmpty) {
3745 functionType.optionalParameterTypes = new List.from(optionalParameterTypes); 4313 functionType.normalParameterTypes = new List.from(normalParameterTypes);
3746 functionType.namedParameterTypes = namedParameterTypes; 4314 }
3747 if (returnType8 == null) { 4315 if (!optionalParameterTypes.isEmpty) {
3748 functionType.returnType = typeProvider.dynamicType; 4316 functionType.optionalParameterTypes = new List.from(optionalParameterTypes );
4317 }
4318 if (!namedParameterTypes.isEmpty) {
4319 functionType.namedParameterTypes = namedParameterTypes;
4320 }
4321 if (returnType10 == null) {
4322 functionType.returnType = _dynamicType;
3749 } else { 4323 } else {
3750 functionType.returnType = returnType8.type; 4324 functionType.returnType = returnType10.type;
3751 } 4325 }
3752 } 4326 }
3753 } 4327 }
3754 /** 4328 /**
3755 * Instances of the class {@code ClassScope} implement the scope defined by a cl ass. 4329 * Instances of the class {@code ClassScope} implement the scope defined by a cl ass.
3756 */ 4330 */
3757 class ClassScope extends EnclosedScope { 4331 class ClassScope extends EnclosedScope {
3758 /** 4332 /**
3759 * Initialize a newly created scope enclosed within another scope. 4333 * Initialize a newly created scope enclosed within another scope.
3760 * @param enclosingScope the scope in which this scope is lexically enclosed 4334 * @param enclosingScope the scope in which this scope is lexically enclosed
3761 * @param typeElement the element representing the type represented by this sc ope 4335 * @param typeElement the element representing the type represented by this sc ope
3762 */ 4336 */
3763 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose dScope(enclosingScope)) { 4337 ClassScope(Scope enclosingScope, ClassElement typeElement) : super(new Enclose dScope(enclosingScope)) {
3764 defineTypeParameters(typeElement); 4338 defineTypeParameters(typeElement);
3765 defineMembers(typeElement); 4339 defineMembers(typeElement);
3766 } 4340 }
3767 /** 4341 /**
3768 * Define the instance members defined by the class. 4342 * Define the instance members defined by the class.
3769 * @param typeElement the element representing the type represented by this sc ope 4343 * @param typeElement the element representing the type represented by this sc ope
3770 */ 4344 */
3771 void defineMembers(ClassElement typeElement) { 4345 void defineMembers(ClassElement typeElement) {
3772 for (PropertyAccessorElement accessor in typeElement.accessors) { 4346 for (PropertyAccessorElement accessor in typeElement.accessors) {
3773 define(accessor); 4347 define(accessor);
3774 } 4348 }
3775 for (FieldElement field in typeElement.fields) {
3776 define(field);
3777 }
3778 for (MethodElement method in typeElement.methods) { 4349 for (MethodElement method in typeElement.methods) {
3779 define(method); 4350 define(method);
3780 } 4351 }
3781 } 4352 }
3782 /** 4353 /**
3783 * Define the type parameters for the class. 4354 * Define the type parameters for the class.
3784 * @param typeElement the element representing the type represented by this sc ope 4355 * @param typeElement the element representing the type represented by this sc ope
3785 */ 4356 */
3786 void defineTypeParameters(ClassElement typeElement) { 4357 void defineTypeParameters(ClassElement typeElement) {
3787 Scope parameterScope = enclosingScope; 4358 Scope parameterScope = enclosingScope;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3833 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) { 4404 FunctionScope(Scope enclosingScope, ExecutableElement functionElement) : super (new EnclosedScope(enclosingScope)) {
3834 defineParameters(functionElement); 4405 defineParameters(functionElement);
3835 } 4406 }
3836 /** 4407 /**
3837 * Define the parameters for the given function in the scope that encloses thi s function. 4408 * Define the parameters for the given function in the scope that encloses thi s function.
3838 * @param functionElement the element representing the function represented by this scope 4409 * @param functionElement the element representing the function represented by this scope
3839 */ 4410 */
3840 void defineParameters(ExecutableElement functionElement) { 4411 void defineParameters(ExecutableElement functionElement) {
3841 Scope parameterScope = enclosingScope; 4412 Scope parameterScope = enclosingScope;
3842 if (functionElement.enclosingElement is ExecutableElement) { 4413 if (functionElement.enclosingElement is ExecutableElement) {
3843 String name16 = functionElement.name; 4414 String name17 = functionElement.name;
3844 if (name16 != null && !name16.isEmpty) { 4415 if (name17 != null && !name17.isEmpty) {
3845 parameterScope.define(functionElement); 4416 parameterScope.define(functionElement);
3846 } 4417 }
3847 } 4418 }
3848 for (ParameterElement parameter in functionElement.parameters) { 4419 for (ParameterElement parameter in functionElement.parameters) {
3849 if (!parameter.isInitializingFormal()) { 4420 if (!parameter.isInitializingFormal()) {
3850 parameterScope.define(parameter); 4421 parameterScope.define(parameter);
3851 } 4422 }
3852 } 4423 }
3853 } 4424 }
3854 } 4425 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3900 * The label element returned for scopes that can be the target of an unlabele d {@code break} or{@code continue}. 4471 * The label element returned for scopes that can be the target of an unlabele d {@code break} or{@code continue}.
3901 */ 4472 */
3902 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne w StringToken(TokenType.IDENTIFIER, "", 0)); 4473 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = new SimpleIdentifier.full(ne w StringToken(TokenType.IDENTIFIER, "", 0));
3903 /** 4474 /**
3904 * Initialize a newly created scope to represent the potential target of an un labeled{@code break} or {@code continue}. 4475 * Initialize a newly created scope to represent the potential target of an un labeled{@code break} or {@code continue}.
3905 * @param outerScope the label scope enclosing the new label scope 4476 * @param outerScope the label scope enclosing the new label scope
3906 * @param onSwitchStatement {@code true} if this label is associated with a {@ code switch}statement 4477 * @param onSwitchStatement {@code true} if this label is associated with a {@ code switch}statement
3907 * @param onSwitchMember {@code true} if this label is associated with a {@cod e switch} member 4478 * @param onSwitchMember {@code true} if this label is associated with a {@cod e switch} member
3908 */ 4479 */
3909 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) { 4480 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMe mber) {
3910 _jtd_constructor_198_impl(outerScope, onSwitchStatement, onSwitchMember); 4481 _jtd_constructor_231_impl(outerScope, onSwitchStatement, onSwitchMember);
3911 } 4482 }
3912 _jtd_constructor_198_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) { 4483 _jtd_constructor_231_impl(LabelScope outerScope, bool onSwitchStatement, bool onSwitchMember) {
3913 _jtd_constructor_199_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember)); 4484 _jtd_constructor_232_impl(outerScope, EMPTY_LABEL, new LabelElementImpl(_EMP TY_LABEL_IDENTIFIER, onSwitchStatement, onSwitchMember));
3914 } 4485 }
3915 /** 4486 /**
3916 * Initialize a newly created scope to represent the given label. 4487 * Initialize a newly created scope to represent the given label.
3917 * @param outerScope the label scope enclosing the new label scope 4488 * @param outerScope the label scope enclosing the new label scope
3918 * @param label the label defined in this scope 4489 * @param label the label defined in this scope
3919 * @param element the element to which the label resolves 4490 * @param element the element to which the label resolves
3920 */ 4491 */
3921 LabelScope.con2(LabelScope outerScope2, String label3, LabelElement element18) { 4492 LabelScope.con2(LabelScope outerScope2, String label4, LabelElement element18) {
3922 _jtd_constructor_199_impl(outerScope2, label3, element18); 4493 _jtd_constructor_232_impl(outerScope2, label4, element18);
3923 } 4494 }
3924 _jtd_constructor_199_impl(LabelScope outerScope2, String label3, LabelElement element18) { 4495 _jtd_constructor_232_impl(LabelScope outerScope2, String label4, LabelElement element18) {
3925 this._outerScope = outerScope2; 4496 this._outerScope = outerScope2;
3926 this._label = label3; 4497 this._label = label4;
3927 this._element = element18; 4498 this._element = element18;
3928 } 4499 }
3929 /** 4500 /**
3930 * Return the label element corresponding to the given label, or {@code null} if the given label 4501 * Return the label element corresponding to the given label, or {@code null} if the given label
3931 * is not defined in this scope. 4502 * is not defined in this scope.
3932 * @param targetLabel the label being looked up 4503 * @param targetLabel the label being looked up
3933 * @return the label element corresponding to the given label 4504 * @return the label element corresponding to the given label
3934 */ 4505 */
3935 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name) ; 4506 LabelElement lookup(SimpleIdentifier targetLabel) => lookup2(targetLabel.name) ;
3936 /** 4507 /**
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3996 for (Namespace nameSpace in _importedNamespaces) { 4567 for (Namespace nameSpace in _importedNamespaces) {
3997 Element element = nameSpace.get(name); 4568 Element element = nameSpace.get(name);
3998 if (element != null) { 4569 if (element != null) {
3999 if (foundElement == null) { 4570 if (foundElement == null) {
4000 foundElement = element; 4571 foundElement = element;
4001 } else { 4572 } else {
4002 foundElement = new MultiplyDefinedElementImpl(_definingLibrary.context , foundElement, element); 4573 foundElement = new MultiplyDefinedElementImpl(_definingLibrary.context , foundElement, element);
4003 } 4574 }
4004 } 4575 }
4005 } 4576 }
4577 if (foundElement is MultiplyDefinedElementImpl) {
4578 }
4006 if (foundElement != null) { 4579 if (foundElement != null) {
4007 defineWithoutChecking(foundElement); 4580 defineWithoutChecking(foundElement);
4008 } 4581 }
4009 return foundElement; 4582 return foundElement;
4010 } 4583 }
4011 /** 4584 /**
4012 * Create all of the namespaces associated with the libraries imported into th is library. The 4585 * Create all of the namespaces associated with the libraries imported into th is library. The
4013 * names are not added to this scope, but are stored for later reference. 4586 * names are not added to this scope, but are stored for later reference.
4014 * @param definingLibrary the element representing the library that imports th e libraries for 4587 * @param definingLibrary the element representing the library that imports th e libraries for
4015 * which namespaces will be created 4588 * which namespaces will be created
(...skipping 30 matching lines...) Expand all
4046 } 4619 }
4047 for (FunctionElement element in compilationUnit.functions) { 4620 for (FunctionElement element in compilationUnit.functions) {
4048 define(element); 4621 define(element);
4049 } 4622 }
4050 for (TypeAliasElement element in compilationUnit.typeAliases) { 4623 for (TypeAliasElement element in compilationUnit.typeAliases) {
4051 define(element); 4624 define(element);
4052 } 4625 }
4053 for (ClassElement element in compilationUnit.types) { 4626 for (ClassElement element in compilationUnit.types) {
4054 define(element); 4627 define(element);
4055 } 4628 }
4056 for (VariableElement element in compilationUnit.variables) {
4057 define(element);
4058 }
4059 } 4629 }
4060 /** 4630 /**
4061 * Add to this scope all of the names that are explicitly defined in the given library. 4631 * Add to this scope all of the names that are explicitly defined in the given library.
4062 * @param definingLibrary the element representing the library that defines th e names in this 4632 * @param definingLibrary the element representing the library that defines th e names in this
4063 * scope 4633 * scope
4064 */ 4634 */
4065 void defineTopLevelNames(LibraryElement definingLibrary) { 4635 void defineTopLevelNames(LibraryElement definingLibrary) {
4066 for (PrefixElement prefix in definingLibrary.prefixes) { 4636 for (PrefixElement prefix in definingLibrary.prefixes) {
4067 define(prefix); 4637 define(prefix);
4068 } 4638 }
4069 defineLocalNames(definingLibrary.definingCompilationUnit); 4639 defineLocalNames(definingLibrary.definingCompilationUnit);
4070 for (CompilationUnitElement compilationUnit in definingLibrary.parts) { 4640 for (CompilationUnitElement compilationUnit in definingLibrary.parts) {
4071 defineLocalNames(compilationUnit); 4641 defineLocalNames(compilationUnit);
4072 } 4642 }
4073 } 4643 }
4074 } 4644 }
4075 /** 4645 /**
4076 * Instances of the class {@code Namespace} implement a mapping of identifiers t o the elements 4646 * Instances of the class {@code Namespace} implement a mapping of identifiers t o the elements
4077 * represented by those identifiers. Namespaces are the building blocks for scop es. 4647 * represented by those identifiers. Namespaces are the building blocks for scop es.
4078 */ 4648 */
4079 class Namespace { 4649 class Namespace {
4080 /** 4650 /**
4081 * A table mapping names that are defined in this namespace to the element rep resenting the thing 4651 * A table mapping names that are defined in this namespace to the element rep resenting the thing
4082 * declared with that name. 4652 * declared with that name.
4083 */ 4653 */
4084 Map<String, Element> _definedNames = new Map<String, Element>(); 4654 Map<String, Element> _definedNames;
4655 /**
4656 * An empty namespace.
4657 */
4658 static Namespace EMPTY = new Namespace(new Map<String, Element>());
4085 /** 4659 /**
4086 * Initialize a newly created namespace to have the given defined names. 4660 * Initialize a newly created namespace to have the given defined names.
4087 * @param definedNames the mapping from names that are defined in this namespa ce to the 4661 * @param definedNames the mapping from names that are defined in this namespa ce to the
4088 * corresponding elements 4662 * corresponding elements
4089 */ 4663 */
4090 Namespace(Map<String, Element> definedNames) { 4664 Namespace(Map<String, Element> definedNames) {
4091 this._definedNames = definedNames; 4665 this._definedNames = definedNames;
4092 } 4666 }
4093 /** 4667 /**
4094 * Return the element in this namespace that is available to the containing sc ope using the given 4668 * Return the element in this namespace that is available to the containing sc ope using the given
(...skipping 23 matching lines...) Expand all
4118 * @param library the library whose export namespace is to be created 4692 * @param library the library whose export namespace is to be created
4119 * @return the export namespace that was created 4693 * @return the export namespace that was created
4120 */ 4694 */
4121 Namespace createExportNamespace(LibraryElement library) => new Namespace(creat eExportMapping(library, new Set<LibraryElement>())); 4695 Namespace createExportNamespace(LibraryElement library) => new Namespace(creat eExportMapping(library, new Set<LibraryElement>()));
4122 /** 4696 /**
4123 * Create a namespace representing the import namespace of the given library. 4697 * Create a namespace representing the import namespace of the given library.
4124 * @param library the library whose import namespace is to be created 4698 * @param library the library whose import namespace is to be created
4125 * @return the import namespace that was created 4699 * @return the import namespace that was created
4126 */ 4700 */
4127 Namespace createImportNamespace(ImportElement element) { 4701 Namespace createImportNamespace(ImportElement element) {
4128 Map<String, Element> definedNames = createExportMapping(element.importedLibr ary, new Set<LibraryElement>()); 4702 LibraryElement importedLibrary4 = element.importedLibrary;
4703 if (importedLibrary4 == null) {
4704 return Namespace.EMPTY;
4705 }
4706 Map<String, Element> definedNames = createExportMapping(importedLibrary4, ne w Set<LibraryElement>());
4129 definedNames = apply(definedNames, element.combinators); 4707 definedNames = apply(definedNames, element.combinators);
4130 definedNames = apply2(definedNames, element.prefix); 4708 definedNames = apply2(definedNames, element.prefix);
4131 return new Namespace(definedNames); 4709 return new Namespace(definedNames);
4132 } 4710 }
4133 /** 4711 /**
4134 * Create a namespace representing the public namespace of the given library. 4712 * Create a namespace representing the public namespace of the given library.
4135 * @param library the library whose public namespace is to be created 4713 * @param library the library whose public namespace is to be created
4136 * @return the public namespace that was created 4714 * @return the public namespace that was created
4137 */ 4715 */
4138 Namespace createPublicNamespace(LibraryElement library) { 4716 Namespace createPublicNamespace(LibraryElement library) {
(...skipping 21 matching lines...) Expand all
4160 */ 4738 */
4161 void addAll2(Map<String, Element> definedNames2, Namespace namespace) { 4739 void addAll2(Map<String, Element> definedNames2, Namespace namespace) {
4162 addAll(definedNames2, namespace.definedNames); 4740 addAll(definedNames2, namespace.definedNames);
4163 } 4741 }
4164 /** 4742 /**
4165 * Add the given element to the given mapping table if it has a publicly visib le name. 4743 * Add the given element to the given mapping table if it has a publicly visib le name.
4166 * @param definedNames the mapping table to which the public name is to be add ed 4744 * @param definedNames the mapping table to which the public name is to be add ed
4167 * @param element the element to be added 4745 * @param element the element to be added
4168 */ 4746 */
4169 void addIfPublic(Map<String, Element> definedNames, Element element) { 4747 void addIfPublic(Map<String, Element> definedNames, Element element) {
4170 String name17 = element.name; 4748 String name18 = element.name;
4171 if (name17 != null && !Scope.isPrivateName(name17)) { 4749 if (name18 != null && !Scope.isPrivateName(name18)) {
4172 definedNames[name17] = element; 4750 definedNames[name18] = element;
4173 } 4751 }
4174 } 4752 }
4175 /** 4753 /**
4176 * Add to the given mapping table all of the public top-level names that are d efined in the given 4754 * Add to the given mapping table all of the public top-level names that are d efined in the given
4177 * compilation unit. 4755 * compilation unit.
4178 * @param definedNames the mapping table to which the public names are to be a dded 4756 * @param definedNames the mapping table to which the public names are to be a dded
4179 * @param compilationUnit the compilation unit defining the top-level names to be added to this 4757 * @param compilationUnit the compilation unit defining the top-level names to be added to this
4180 * namespace 4758 * namespace
4181 */ 4759 */
4182 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement compilationUnit) { 4760 void addPublicNames(Map<String, Element> definedNames, CompilationUnitElement compilationUnit) {
4183 for (PropertyAccessorElement element in compilationUnit.accessors) { 4761 for (PropertyAccessorElement element in compilationUnit.accessors) {
4184 addIfPublic(definedNames, element); 4762 addIfPublic(definedNames, element);
4185 } 4763 }
4186 for (FunctionElement element in compilationUnit.functions) { 4764 for (FunctionElement element in compilationUnit.functions) {
4187 addIfPublic(definedNames, element); 4765 addIfPublic(definedNames, element);
4188 } 4766 }
4189 for (TypeAliasElement element in compilationUnit.typeAliases) { 4767 for (TypeAliasElement element in compilationUnit.typeAliases) {
4190 addIfPublic(definedNames, element); 4768 addIfPublic(definedNames, element);
4191 } 4769 }
4192 for (ClassElement element in compilationUnit.types) { 4770 for (ClassElement element in compilationUnit.types) {
4193 addIfPublic(definedNames, element); 4771 addIfPublic(definedNames, element);
4194 } 4772 }
4195 for (VariableElement element in compilationUnit.variables) { 4773 for (VariableElement element in compilationUnit.topLevelVariables) {
4196 addIfPublic(definedNames, element); 4774 addIfPublic(definedNames, element);
4197 } 4775 }
4198 } 4776 }
4199 /** 4777 /**
4200 * Apply the given combinators to all of the names in the given mapping table. 4778 * Apply the given combinators to all of the names in the given mapping table.
4201 * @param definedNames the mapping table to which the namespace operations are to be applied 4779 * @param definedNames the mapping table to which the namespace operations are to be applied
4202 * @param combinators the combinators to be applied 4780 * @param combinators the combinators to be applied
4203 */ 4781 */
4204 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo mbinator> combinators) { 4782 Map<String, Element> apply(Map<String, Element> definedNames, List<NamespaceCo mbinator> combinators) {
4205 for (NamespaceCombinator combinator in combinators) { 4783 for (NamespaceCombinator combinator in combinators) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4237 * export directives of the given library because all of the names defined by them will 4815 * export directives of the given library because all of the names defined by them will
4238 * be added by another library 4816 * be added by another library
4239 * @return the mapping table that was created 4817 * @return the mapping table that was created
4240 */ 4818 */
4241 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl ement> visitedElements) { 4819 Map<String, Element> createExportMapping(LibraryElement library, Set<LibraryEl ement> visitedElements) {
4242 javaSetAdd(visitedElements, library); 4820 javaSetAdd(visitedElements, library);
4243 try { 4821 try {
4244 Map<String, Element> definedNames = new Map<String, Element>(); 4822 Map<String, Element> definedNames = new Map<String, Element>();
4245 for (ExportElement element in library.exports) { 4823 for (ExportElement element in library.exports) {
4246 LibraryElement exportedLibrary3 = element.exportedLibrary; 4824 LibraryElement exportedLibrary3 = element.exportedLibrary;
4247 if (!visitedElements.contains(exportedLibrary3)) { 4825 if (exportedLibrary3 != null && !visitedElements.contains(exportedLibrar y3)) {
4248 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry3, visitedElements); 4826 Map<String, Element> exportedNames = createExportMapping(exportedLibra ry3, visitedElements);
4249 exportedNames = apply(exportedNames, element.combinators); 4827 exportedNames = apply(exportedNames, element.combinators);
4250 addAll(definedNames, exportedNames); 4828 addAll(definedNames, exportedNames);
4251 } 4829 }
4252 } 4830 }
4253 addAll2(definedNames, ((library.context as AnalysisContextImpl)).getPublic Namespace(library)); 4831 addAll2(definedNames, ((library.context as AnalysisContextImpl)).getPublic Namespace(library));
4254 return definedNames; 4832 return definedNames;
4255 } finally { 4833 } finally {
4256 visitedElements.remove(library); 4834 visitedElements.remove(library);
4257 } 4835 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4323 * in this scope, then an error will be generated and the original element wil l continue to be 4901 * in this scope, then an error will be generated and the original element wil l continue to be
4324 * mapped to the name. If there is an element with the given name in an enclos ing scope, then a 4902 * mapped to the name. If there is an element with the given name in an enclos ing scope, then a
4325 * warning will be generated but the given element will hide the inherited ele ment. 4903 * warning will be generated but the given element will hide the inherited ele ment.
4326 * @param element the element to be added to this scope 4904 * @param element the element to be added to this scope
4327 */ 4905 */
4328 void define(Element element) { 4906 void define(Element element) {
4329 String name = getName(element); 4907 String name = getName(element);
4330 if (_definedNames.containsKey(name)) { 4908 if (_definedNames.containsKey(name)) {
4331 errorListener.onError(getErrorForDuplicate(_definedNames[name], element)); 4909 errorListener.onError(getErrorForDuplicate(_definedNames[name], element));
4332 } else { 4910 } else {
4333 Element overriddenElement = lookup3(name, definingLibrary);
4334 if (overriddenElement != null) {
4335 AnalysisError error = getErrorForHiding(overriddenElement, element);
4336 if (error != null) {
4337 errorListener.onError(error);
4338 }
4339 }
4340 _definedNames[name] = element; 4911 _definedNames[name] = element;
4341 } 4912 }
4342 } 4913 }
4343 /** 4914 /**
4344 * Return the element with which the given identifier is associated, or {@code null} if the name 4915 * Return the element with which the given identifier is associated, or {@code null} if the name
4345 * is not defined within this scope. 4916 * is not defined within this scope.
4346 * @param identifier the identifier associated with the element to be returned 4917 * @param identifier the identifier associated with the element to be returned
4347 * @param referencingLibrary the library that contains the reference to the na me, used to 4918 * @param referencingLibrary the library that contains the reference to the na me, used to
4348 * implement library-level privacy 4919 * implement library-level privacy
4349 * @return the element with which the given identifier is associated 4920 * @return the element with which the given identifier is associated
(...skipping 11 matching lines...) Expand all
4361 * @return the element representing the library in which this scope is enclose d 4932 * @return the element representing the library in which this scope is enclose d
4362 */ 4933 */
4363 LibraryElement get definingLibrary; 4934 LibraryElement get definingLibrary;
4364 /** 4935 /**
4365 * Return the error code to be used when reporting that a name being defined l ocally conflicts 4936 * Return the error code to be used when reporting that a name being defined l ocally conflicts
4366 * with another element of the same name in the local scope. 4937 * with another element of the same name in the local scope.
4367 * @param existing the first element to be declared with the conflicting name 4938 * @param existing the first element to be declared with the conflicting name
4368 * @param duplicate another element declared with the conflicting name 4939 * @param duplicate another element declared with the conflicting name
4369 * @return the error code used to report duplicate names within a scope 4940 * @return the error code used to report duplicate names within a scope
4370 */ 4941 */
4371 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) => new AnalysisError.con1(source, ResolverErrorCode.DUPLICATE_MEMBER_ERROR, [existing. name]); 4942 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) => new AnalysisError.con2(source, duplicate.nameOffset, duplicate.name.length, Compile TimeErrorCode.DUPLICATE_DEFINITION, [existing.name]);
4372 /**
4373 * Return the error code to be used when reporting that a name being defined l ocally hides a name
4374 * defined in an outer scope.
4375 * @param hidden the element whose visibility is being hidden
4376 * @param hiding the element that is hiding the visibility of another declarat ion
4377 * @return the error code used to report name hiding
4378 */
4379 AnalysisError getErrorForHiding(Element hidden, Element hiding) => new Analysi sError.con1(source, ResolverErrorCode.DUPLICATE_MEMBER_WARNING, [hidden.name]);
4380 /** 4943 /**
4381 * Return the listener that is to be informed when an error is encountered. 4944 * Return the listener that is to be informed when an error is encountered.
4382 * @return the listener that is to be informed when an error is encountered 4945 * @return the listener that is to be informed when an error is encountered
4383 */ 4946 */
4384 AnalysisErrorListener get errorListener; 4947 AnalysisErrorListener get errorListener;
4385 /** 4948 /**
4386 * Return the source object representing the compilation unit with which error s related to this 4949 * Return the source object representing the compilation unit with which error s related to this
4387 * scope should be associated. 4950 * scope should be associated.
4388 * @return the source object with which errors should be associated 4951 * @return the source object with which errors should be associated
4389 */ 4952 */
(...skipping 17 matching lines...) Expand all
4407 * @return the element with which the given name is associated 4970 * @return the element with which the given name is associated
4408 */ 4971 */
4409 Element lookup3(String name, LibraryElement referencingLibrary); 4972 Element lookup3(String name, LibraryElement referencingLibrary);
4410 /** 4973 /**
4411 * Return the name that will be used to look up the given element. 4974 * Return the name that will be used to look up the given element.
4412 * @param element the element whose look-up name is to be returned 4975 * @param element the element whose look-up name is to be returned
4413 * @return the name that will be used to look up the given element 4976 * @return the name that will be used to look up the given element
4414 */ 4977 */
4415 String getName(Element element) { 4978 String getName(Element element) {
4416 if (element is MethodElement) { 4979 if (element is MethodElement) {
4417 MethodElement method = (element as MethodElement); 4980 MethodElement method = element as MethodElement;
4418 if (method.name == "-" && method.parameters.length == 0) { 4981 if (method.name == "-" && method.parameters.length == 0) {
4419 return UNARY_MINUS; 4982 return UNARY_MINUS;
4420 } 4983 }
4421 } else if (element is PropertyAccessorElement) { 4984 } else if (element is PropertyAccessorElement) {
4422 PropertyAccessorElement accessor = (element as PropertyAccessorElement); 4985 PropertyAccessorElement accessor = element as PropertyAccessorElement;
4423 if (accessor.isSetter()) { 4986 if (accessor.isSetter()) {
4424 return "${accessor.name}${SETTER_SUFFIX}"; 4987 return "${accessor.name}${SETTER_SUFFIX}";
4425 } 4988 }
4426 } 4989 }
4427 return element.name; 4990 return element.name;
4428 } 4991 }
4429 } 4992 }
4430 /** 4993 /**
4994 * Instances of the class {@code ConstantVerifier} traverse an AST structure loo king for additional
4995 * errors and warnings not covered by the parser and resolver. In particular, it looks for errors
4996 * and warnings related to constant expressions.
4997 */
4998 class ConstantVerifier extends RecursiveASTVisitor<Object> {
4999 /**
5000 * The error reporter by which errors will be reported.
5001 */
5002 ErrorReporter _errorReporter;
5003 /**
5004 * The constant evaluator used to evaluate constants.
5005 */
5006 ConstantEvaluator _evaluator;
5007 /**
5008 * Initialize a newly created constant verifier.
5009 * @param errorReporter the error reporter by which errors will be reported
5010 */
5011 ConstantVerifier(ErrorReporter errorReporter) {
5012 this._errorReporter = errorReporter;
5013 _evaluator = new ConstantEvaluator();
5014 }
5015 Object visitFunctionExpression(FunctionExpression node) {
5016 super.visitFunctionExpression(node);
5017 validateDefaultValues(node.parameters);
5018 return null;
5019 }
5020 Object visitListLiteral(ListLiteral node) {
5021 super.visitListLiteral(node);
5022 if (node.modifier != null) {
5023 for (Expression element in node.elements) {
5024 validate(element, CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT);
5025 }
5026 }
5027 return null;
5028 }
5029 Object visitMapLiteral(MapLiteral node) {
5030 super.visitMapLiteral(node);
5031 bool isConst = node.modifier != null;
5032 Set<String> keys = new Set<String>();
5033 for (MapLiteralEntry entry in node.entries) {
5034 StringLiteral key4 = entry.key;
5035 Object value = validate(key4, CompileTimeErrorCode.NON_CONSTANT_MAP_KEY);
5036 if (value is String) {
5037 if (keys.contains(value)) {
5038 _errorReporter.reportError(StaticWarningCode.EQUAL_KEYS_IN_MAP, key4, []);
5039 } else {
5040 javaSetAdd(keys, (value as String));
5041 }
5042 } else if (value != null) {
5043 }
5044 if (isConst) {
5045 validate(entry.value, CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE);
5046 }
5047 }
5048 return null;
5049 }
5050 Object visitMethodDeclaration(MethodDeclaration node) {
5051 super.visitMethodDeclaration(node);
5052 validateDefaultValues(node.parameters);
5053 return null;
5054 }
5055 Object visitSwitchCase(SwitchCase node) {
5056 super.visitSwitchCase(node);
5057 validate(node.expression, CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION) ;
5058 return null;
5059 }
5060 Object visitVariableDeclaration(VariableDeclaration node) {
5061 super.visitVariableDeclaration(node);
5062 Expression initializer4 = node.initializer;
5063 if (initializer4 != null && node.isConst()) {
5064 validate(initializer4, CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CON STANT_VALUE);
5065 }
5066 return null;
5067 }
5068 /**
5069 * Validate that the given expression is a compile time constant. Return the v alue of the compile
5070 * time constant, or {@code null} if the expression is not a compile time cons tant.
5071 * @param expression the expression to be validated
5072 * @param errorCode the error code to be used if the expression is not a compi le time constant
5073 * @return the value of the compile time constant
5074 */
5075 Object validate(Expression expression, ErrorCode errorCode) {
5076 Object value = expression.accept(_evaluator);
5077 if (identical(value, ConstantEvaluator.NOT_A_CONSTANT)) {
5078 _errorReporter.reportError(errorCode, expression, []);
5079 return null;
5080 }
5081 if (identical(value, errorCode)) {
5082 _errorReporter.reportError(CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAIS ES_EXCEPTION, expression, []);
5083 return null;
5084 }
5085 if (identical(value, errorCode)) {
5086 _errorReporter.reportError(CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CON STANT, expression, []);
5087 return null;
5088 }
5089 return value;
5090 }
5091 /**
5092 * Validate that the default value associated with each of the parameters in t he given list is a
5093 * compile time constant.
5094 * @param parameters the list of parameters to be validated
5095 */
5096 void validateDefaultValues(FormalParameterList parameters14) {
5097 if (parameters14 == null) {
5098 return;
5099 }
5100 for (FormalParameter parameter in parameters14.parameters) {
5101 if (parameter is DefaultFormalParameter) {
5102 Expression defaultValue2 = ((parameter as DefaultFormalParameter)).defau ltValue;
5103 if (defaultValue2 != null) {
5104 validate(defaultValue2, CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALU E);
5105 }
5106 }
5107 }
5108 }
5109 }
5110 /**
5111 * Instances of the class {@code ErrorVerifier} traverse an AST structure lookin g for additional
5112 * errors and warnings not covered by the parser and resolver.
5113 */
5114 class ErrorVerifier extends RecursiveASTVisitor<Object> {
5115 /**
5116 * The error reporter by which errors will be reported.
5117 */
5118 ErrorReporter _errorReporter;
5119 /**
5120 * The type representing the type 'dynamic'.
5121 */
5122 Type2 _dynamicType;
5123 /**
5124 * The object providing access to the types defined by the language.
5125 */
5126 TypeProvider _typeProvider;
5127 /**
5128 * The method or function that we are currently visiting, or {@code null} if w e are not inside a
5129 * method or function.
5130 */
5131 ExecutableElement _currentFunction;
5132 ErrorVerifier(ErrorReporter errorReporter, TypeProvider typeProvider) {
5133 this._errorReporter = errorReporter;
5134 this._typeProvider = typeProvider;
5135 _dynamicType = typeProvider.dynamicType;
5136 }
5137 Object visitArgumentDefinitionTest(ArgumentDefinitionTest node) {
5138 SimpleIdentifier identifier13 = node.identifier;
5139 Element element42 = identifier13.element;
5140 if (element42 != null && element42 is! ParameterElement) {
5141 _errorReporter.reportError(CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_N ON_PARAMETER, identifier13, [identifier13.name]);
5142 }
5143 return super.visitArgumentDefinitionTest(node);
5144 }
5145 Object visitAssertStatement(AssertStatement node) {
5146 Expression expression = node.condition;
5147 Type2 type = getType(expression);
5148 if (type is InterfaceType) {
5149 if (!type.isAssignableTo(_typeProvider.boolType)) {
5150 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []);
5151 }
5152 } else if (type is FunctionType) {
5153 FunctionType functionType = type as FunctionType;
5154 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA ssignableTo(_typeProvider.boolType)) {
5155 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_EXPRESSION, ex pression, []);
5156 }
5157 }
5158 return super.visitAssertStatement(node);
5159 }
5160 Object visitAssignmentExpression(AssignmentExpression node) {
5161 Expression lhs = node.leftHandSide;
5162 Expression rhs = node.rightHandSide;
5163 Type2 leftType = getType(lhs);
5164 Type2 rightType = getType(rhs);
5165 if (!rightType.isAssignableTo(leftType)) {
5166 _errorReporter.reportError(StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [leftType.name, rightType.name]);
5167 }
5168 return super.visitAssignmentExpression(node);
5169 }
5170 Object visitConditionalExpression(ConditionalExpression node) {
5171 checkForNonBoolCondition(node.condition);
5172 return super.visitConditionalExpression(node);
5173 }
5174 Object visitConstructorDeclaration(ConstructorDeclaration node) {
5175 ExecutableElement previousFunction = _currentFunction;
5176 try {
5177 _currentFunction = node.element;
5178 return super.visitConstructorDeclaration(node);
5179 } finally {
5180 _currentFunction = previousFunction;
5181 }
5182 }
5183 Object visitDoStatement(DoStatement node) {
5184 checkForNonBoolCondition(node.condition);
5185 return super.visitDoStatement(node);
5186 }
5187 Object visitFunctionDeclaration(FunctionDeclaration node) {
5188 ExecutableElement previousFunction = _currentFunction;
5189 try {
5190 _currentFunction = node.element;
5191 return super.visitFunctionDeclaration(node);
5192 } finally {
5193 _currentFunction = previousFunction;
5194 }
5195 }
5196 Object visitFunctionExpression(FunctionExpression node) {
5197 ExecutableElement previousFunction = _currentFunction;
5198 try {
5199 _currentFunction = node.element;
5200 return super.visitFunctionExpression(node);
5201 } finally {
5202 _currentFunction = previousFunction;
5203 }
5204 }
5205 Object visitIfStatement(IfStatement node) {
5206 checkForNonBoolCondition(node.condition);
5207 return super.visitIfStatement(node);
5208 }
5209 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
5210 ConstructorName constructorName4 = node.constructorName;
5211 TypeName typeName = constructorName4.type;
5212 Type2 createdType = typeName.type;
5213 if (createdType is InterfaceType) {
5214 if (((createdType as InterfaceType)).element.isAbstract()) {
5215 ConstructorElement element43 = node.element;
5216 if (element43 != null && !element43.isFactory()) {
5217 if (identical(((node.keyword as KeywordToken)).keyword, Keyword.CONST) ) {
5218 _errorReporter.reportError(StaticWarningCode.CONST_WITH_ABSTRACT_CLA SS, typeName, []);
5219 } else {
5220 _errorReporter.reportError(StaticWarningCode.NEW_WITH_ABSTRACT_CLASS , typeName, []);
5221 }
5222 }
5223 }
5224 if (typeName.typeArguments != null) {
5225 ConstructorElement constructorElement = constructorName4.element;
5226 if (constructorElement != null) {
5227 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
5228 List<TypeVariableElement> boundingElts = constructorElement.enclosingE lement.typeVariables;
5229 int loopThroughIndex = Math.min(typeNameArgList.length, boundingElts.l ength);
5230 for (int i = 0; i < loopThroughIndex; i++) {
5231 TypeName argTypeName = typeNameArgList[i];
5232 Type2 argType = argTypeName.type;
5233 Type2 boundType = boundingElts[i].bound;
5234 if (argType != null && boundType != null) {
5235 if (!argType.isSubtypeOf(boundType)) {
5236 _errorReporter.reportError(StaticTypeWarningCode.TYPE_ARGUMENT_N OT_MATCHING_BOUNDS, argTypeName, [argTypeName.name, boundingElts[i].name]);
5237 }
5238 }
5239 }
5240 }
5241 }
5242 } else {
5243 _errorReporter.reportError(CompileTimeErrorCode.NON_CONSTANT_MAP_KEY, type Name, []);
5244 }
5245 return super.visitInstanceCreationExpression(node);
5246 }
5247 Object visitMethodDeclaration(MethodDeclaration node) {
5248 ExecutableElement previousFunction = _currentFunction;
5249 try {
5250 _currentFunction = node.element;
5251 return super.visitMethodDeclaration(node);
5252 } finally {
5253 _currentFunction = previousFunction;
5254 }
5255 }
5256 Object visitReturnStatement(ReturnStatement node) {
5257 FunctionType functionType = _currentFunction == null ? null : _currentFuncti on.type;
5258 Type2 expectedReturnType = functionType == null ? null : functionType.return Type;
5259 Expression returnExpression = node.expression;
5260 if (expectedReturnType != null && !expectedReturnType.isVoid() && returnExpr ession != null) {
5261 Type2 actualReturnType = getType(returnExpression);
5262 if (!actualReturnType.isAssignableTo(expectedReturnType)) {
5263 _errorReporter.reportError(StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [actualReturnType.name, expectedReturnType.name]);
5264 }
5265 }
5266 return super.visitReturnStatement(node);
5267 }
5268 Object visitWhileStatement(WhileStatement node) {
5269 checkForNonBoolCondition(node.condition);
5270 return super.visitWhileStatement(node);
5271 }
5272 /**
5273 * Checks to ensure that the expressions that need to be of type bool, are. Ot herwise an error is
5274 * reported on the expression.
5275 * @see StaticTypeWarningCode#NON_BOOL_CONDITION
5276 * @param condition the conditional expression to test
5277 */
5278 void checkForNonBoolCondition(Expression condition) {
5279 Type2 conditionType = getType(condition);
5280 if (conditionType != null && !conditionType.isAssignableTo(_typeProvider.boo lType)) {
5281 _errorReporter.reportError(StaticTypeWarningCode.NON_BOOL_CONDITION, condi tion, []);
5282 }
5283 }
5284 /**
5285 * Return the type of the given expression that is to be used for type analysi s.
5286 * @param expression the expression whose type is to be returned
5287 * @return the type of the given expression
5288 */
5289 Type2 getType(Expression expression) {
5290 Type2 type = expression.staticType;
5291 return type == null ? _dynamicType : type;
5292 }
5293 }
5294 /**
4431 * The enumeration {@code ResolverErrorCode} defines the error codes used for er rors detected by the 5295 * The enumeration {@code ResolverErrorCode} defines the error codes used for er rors detected by the
4432 * resolver. The convention for this class is for the name of the error code to indicate the problem 5296 * resolver. The convention for this class is for the name of the error code to indicate the problem
4433 * that caused the error to be generated and for the error message to explain wh at is wrong and, 5297 * that caused the error to be generated and for the error message to explain wh at is wrong and,
4434 * when appropriate, how the problem can be corrected. 5298 * when appropriate, how the problem can be corrected.
4435 */ 5299 */
4436 class ResolverErrorCode implements ErrorCode { 5300 class ResolverErrorCode implements ErrorCode {
4437 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"); 5301 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");
4438 static final ResolverErrorCode CANNOT_BE_RESOLVED = new ResolverErrorCode('CAN NOT_BE_RESOLVED', 1, ErrorType.STATIC_WARNING, "Cannot resolve the name '%s'"); 5302 static final ResolverErrorCode CANNOT_BE_RESOLVED = new ResolverErrorCode('CAN NOT_BE_RESOLVED', 1, ErrorType.STATIC_WARNING, "Cannot resolve the name '%s'");
4439 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"); 5303 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");
4440 /** 5304 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");
4441 * It is a compile-time error if [the URI] is not a compile-time constant, or if [the URI] 5305 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");
4442 * involves string interpolation. 5306 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];
4443 */
4444 static final ResolverErrorCode INVALID_URI = new ResolverErrorCode('INVALID_UR I', 3, ErrorType.COMPILE_TIME_ERROR, "URI's used in directives must be compile t ime constants without interpolation expressions");
4445 static final ResolverErrorCode LABEL_IN_OUTER_SCOPE = new ResolverErrorCode('L ABEL_IN_OUTER_SCOPE', 4, ErrorType.COMPILE_TIME_ERROR, "Cannot reference label ' %s' declared in an outer method or function");
4446 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_IMPORTED = new Resolv erErrorCode('MISSING_LIBRARY_DIRECTIVE_IMPORTED', 5, ErrorType.COMPILE_TIME_ERRO R, "Libraries that are imported by other libraries must have a library directive ");
4447 static final ResolverErrorCode MISSING_LIBRARY_DIRECTIVE_WITH_PART = new Resol verErrorCode('MISSING_LIBRARY_DIRECTIVE_WITH_PART', 6, ErrorType.COMPILE_TIME_ER ROR, "Libraries that have parts must have a library directive");
4448 static final ResolverErrorCode MISSING_PART_OF_DIRECTIVE = new ResolverErrorCo de('MISSING_PART_OF_DIRECTIVE', 7, ErrorType.COMPILE_TIME_ERROR, "The included p art must have a part-of directive");
4449 static final ResolverErrorCode NON_BOOLEAN_CONDITION = new ResolverErrorCode(' NON_BOOLEAN_CONDITION', 8, ErrorType.STATIC_TYPE_WARNING, "Conditions must have a static type of 'bool'");
4450 static final ResolverErrorCode PART_WITH_WRONG_LIBRARY_NAME = new ResolverErro rCode('PART_WITH_WRONG_LIBRARY_NAME', 9, ErrorType.STATIC_WARNING, "The included part appears to be part of the library '%s'");
4451 static final ResolverErrorCode UNDEFINED_LABEL = new ResolverErrorCode('UNDEFI NED_LABEL', 10, ErrorType.COMPILE_TIME_ERROR, "The label '%s' is not defined");
4452 static final ResolverErrorCode DUPLICATE_MEMBER_ERROR = new ResolverErrorCode( 'DUPLICATE_MEMBER_ERROR', 11, ErrorType.COMPILE_TIME_ERROR, "Duplicate member '% s'");
4453 static final ResolverErrorCode DUPLICATE_MEMBER_WARNING = new ResolverErrorCod e('DUPLICATE_MEMBER_WARNING', 12, ErrorType.STATIC_WARNING, "Duplicate member '% s'");
4454 static final List<ResolverErrorCode> values = [BREAK_LABEL_ON_SWITCH_MEMBER, C ANNOT_BE_RESOLVED, CONTINUE_LABEL_ON_SWITCH, INVALID_URI, LABEL_IN_OUTER_SCOPE, MISSING_LIBRARY_DIRECTIVE_IMPORTED, MISSING_LIBRARY_DIRECTIVE_WITH_PART, MISSING _PART_OF_DIRECTIVE, NON_BOOLEAN_CONDITION, PART_WITH_WRONG_LIBRARY_NAME, UNDEFIN ED_LABEL, DUPLICATE_MEMBER_ERROR, DUPLICATE_MEMBER_WARNING];
4455 final String __name; 5307 final String __name;
4456 final int __ordinal; 5308 final int __ordinal;
4457 /** 5309 /**
4458 * The type of this error. 5310 * The type of this error.
4459 */ 5311 */
4460 ErrorType _type; 5312 ErrorType _type;
4461 /** 5313 /**
4462 * The message template used to create the message to be displayed for this er ror. 5314 * The message template used to create the message to be displayed for this er ror.
4463 */ 5315 */
4464 String _message; 5316 String _message;
4465 /** 5317 /**
4466 * Initialize a newly created error code to have the given type and message. 5318 * Initialize a newly created error code to have the given type and message.
4467 * @param type the type of this error 5319 * @param type the type of this error
4468 * @param message the message template used to create the message to be displa yed for the error 5320 * @param message the message template used to create the message to be displa yed for the error
4469 */ 5321 */
4470 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message) { 5322 ResolverErrorCode(this.__name, this.__ordinal, ErrorType type, String message) {
4471 this._type = type; 5323 this._type = type;
4472 this._message = message; 5324 this._message = message;
4473 } 5325 }
4474 ErrorSeverity get errorSeverity => _type.severity; 5326 ErrorSeverity get errorSeverity => _type.severity;
4475 String get message => _message; 5327 String get message => _message;
4476 ErrorType get type => _type; 5328 ErrorType get type => _type;
4477 bool needsRecompilation() => true; 5329 bool needsRecompilation() => true;
4478 String toString() => __name; 5330 String toString() => __name;
4479 } 5331 }
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