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

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

Issue 733203004: Matching fields, some parameters, ignore locals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.incremental_resolver; 5 library engine.incremental_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'element.dart'; 10 import 'element.dart';
(...skipping 20 matching lines...) Expand all
31 */ 31 */
32 FunctionTypeAliasElement _enclosingAlias; 32 FunctionTypeAliasElement _enclosingAlias;
33 33
34 /** 34 /**
35 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of 35 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
36 * a class. 36 * a class.
37 */ 37 */
38 ClassElement _enclosingClass; 38 ClassElement _enclosingClass;
39 39
40 /** 40 /**
41 * The method or function containing the AST nodes being visited, or `null` if we are not in
42 * the scope of a method or function.
43 */
44 ExecutableElement _enclosingExecutable;
45
46 /**
47 * The parameter containing the AST nodes being visited, or `null` if we are n ot in the 41 * The parameter containing the AST nodes being visited, or `null` if we are n ot in the
48 * scope of a parameter. 42 * scope of a parameter.
49 */ 43 */
50 ParameterElement _enclosingParameter; 44 ParameterElement _enclosingParameter;
51 45
46 FieldDeclaration _enclosingFieldNode = null;
52 bool _inTopLevelVariableDeclaration = false; 47 bool _inTopLevelVariableDeclaration = false;
53 48
54 /** 49 /**
55 * Is `true` if the current class declaration has a constructor. 50 * Is `true` if the current class declaration has a constructor.
56 */ 51 */
57 bool _hasConstructor = false; 52 bool _hasConstructor = false;
58 53
59 /** 54 /**
60 * A set containing all of the elements in the element model that were defined by the old AST node 55 * A set containing all of the elements in the element model that were defined by the old AST node
61 * corresponding to the AST node being visited. 56 * corresponding to the AST node being visited.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 133
139 @override 134 @override
140 visitCompilationUnit(CompilationUnit node) { 135 visitCompilationUnit(CompilationUnit node) {
141 _processElement(_enclosingUnit); 136 _processElement(_enclosingUnit);
142 super.visitCompilationUnit(node); 137 super.visitCompilationUnit(node);
143 } 138 }
144 139
145 @override 140 @override
146 visitConstructorDeclaration(ConstructorDeclaration node) { 141 visitConstructorDeclaration(ConstructorDeclaration node) {
147 _hasConstructor = true; 142 _hasConstructor = true;
148 ExecutableElement outerExecutable = _enclosingExecutable; 143 SimpleIdentifier constructorName = node.name;
149 try { 144 ConstructorElement element = constructorName == null ?
150 SimpleIdentifier constructorName = node.name; 145 _enclosingClass.unnamedConstructor :
151 if (constructorName == null) { 146 _enclosingClass.getNamedConstructor(constructorName.name);
152 _enclosingExecutable = _enclosingClass.unnamedConstructor; 147 _processElement(element);
153 } else { 148 _assertCompatibleParameters(node.parameters, element.parameters);
154 _enclosingExecutable =
155 _enclosingClass.getNamedConstructor(constructorName.name);
156 }
157 _processElement(_enclosingExecutable);
158 super.visitConstructorDeclaration(node);
159 } finally {
160 _enclosingExecutable = outerExecutable;
161 }
162 } 149 }
163 150
164 @override 151 @override
165 visitDefaultFormalParameter(DefaultFormalParameter node) {
166 SimpleIdentifier parameterName = node.parameter.identifier;
167 ParameterElement element = _getElementForParameter(node, parameterName);
168 Expression defaultValue = node.defaultValue;
169 if (defaultValue != null) {
170 ExecutableElement outerExecutable = _enclosingExecutable;
171 try {
172 if (element == null) {
173 // TODO(brianwilkerson) Report this internal error.
174 } else {
175 _enclosingExecutable = element.initializer;
176 }
177 defaultValue.accept(this);
178 } finally {
179 _enclosingExecutable = outerExecutable;
180 }
181 _processElement(_enclosingExecutable);
182 }
183 ParameterElement outerParameter = _enclosingParameter;
184 try {
185 _enclosingParameter = element;
186 _processElement(_enclosingParameter);
187 super.visitDefaultFormalParameter(node);
188 } finally {
189 _enclosingParameter = outerParameter;
190 }
191 }
192
193 @override
194 visitEnumDeclaration(EnumDeclaration node) { 152 visitEnumDeclaration(EnumDeclaration node) {
195 ClassElement enclosingEnum = 153 ClassElement enclosingEnum =
196 _findIdentifier(_enclosingUnit.enums, node.name); 154 _findIdentifier(_enclosingUnit.enums, node.name);
197 _processElement(enclosingEnum); 155 _processElement(enclosingEnum);
198 List<FieldElement> constants = enclosingEnum.fields; 156 List<FieldElement> constants = enclosingEnum.fields;
199 for (EnumConstantDeclaration constant in node.constants) { 157 for (EnumConstantDeclaration constant in node.constants) {
200 FieldElement constantElement = _findIdentifier(constants, constant.name); 158 FieldElement constantElement = _findIdentifier(constants, constant.name);
201 _processElement(constantElement); 159 _processElement(constantElement);
202 } 160 }
203 super.visitEnumDeclaration(node); 161 super.visitEnumDeclaration(node);
(...skipping 16 matching lines...) Expand all
220 visitExpressionFunctionBody(ExpressionFunctionBody node) { 178 visitExpressionFunctionBody(ExpressionFunctionBody node) {
221 // ignore bodies 179 // ignore bodies
222 } 180 }
223 181
224 @override 182 @override
225 visitExtendsClause(ExtendsClause node) { 183 visitExtendsClause(ExtendsClause node) {
226 _assertSameType(node.superclass, _enclosingClass.supertype); 184 _assertSameType(node.superclass, _enclosingClass.supertype);
227 } 185 }
228 186
229 @override 187 @override
230 visitFieldFormalParameter(FieldFormalParameter node) { 188 visitFieldDeclaration(FieldDeclaration node) {
231 if (node.parent is! DefaultFormalParameter) { 189 _enclosingFieldNode = node;
232 SimpleIdentifier parameterName = node.identifier; 190 try {
233 ParameterElement element = _getElementForParameter(node, parameterName); 191 super.visitFieldDeclaration(node);
234 ParameterElement outerParameter = _enclosingParameter; 192 } finally {
235 try { 193 _enclosingFieldNode = null;
236 _enclosingParameter = element;
237 _processElement(_enclosingParameter);
238 super.visitFieldFormalParameter(node);
239 } finally {
240 _enclosingParameter = outerParameter;
241 }
242 } else {
243 super.visitFieldFormalParameter(node);
244 } 194 }
245 } 195 }
246 196
247 @override 197 @override
248 visitFunctionDeclaration(FunctionDeclaration node) { 198 visitFunctionDeclaration(FunctionDeclaration node) {
249 ExecutableElement outerExecutable = _enclosingExecutable; 199 String name = node.name.name;
250 try { 200 Token property = node.propertyKeyword;
251 SimpleIdentifier functionName = node.name; 201 ExecutableElement element;
252 Token property = node.propertyKeyword; 202 if (property == null) {
253 if (property == null) { 203 element = _findElement(_enclosingUnit.functions, name);
254 if (_enclosingExecutable != null) { 204 _processElement(element);
255 _enclosingExecutable = 205 } else {
256 _findIdentifier(_enclosingExecutable.functions, functionName); 206 PropertyAccessorElement accessor =
257 } else { 207 _findElement(_enclosingUnit.accessors, name);
258 _enclosingExecutable = 208 _assertNotNull(accessor);
259 _findIdentifier(_enclosingUnit.functions, functionName); 209 _assertFalse(element.isSynthetic);
260 } 210 _assertEquals(node.isGetter, accessor.isGetter);
261 } else { 211 _assertEquals(node.isSetter, accessor.isSetter);
262 PropertyAccessorElement accessor = 212 element = accessor;
263 _findIdentifier(_enclosingUnit.accessors, functionName);
264 if ((property as KeywordToken).keyword == Keyword.SET) {
265 accessor = accessor.variable.setter;
266 }
267 _enclosingExecutable = accessor;
268 }
269 _processElement(_enclosingExecutable);
270 super.visitFunctionDeclaration(node);
271 } finally {
272 _enclosingExecutable = outerExecutable;
273 } 213 }
214 _processElement(element);
215 // TODO(scheglov) test returnType
216 _assertSameType(node.returnType, element.returnType);
217 _assertCompatibleParameters(
218 node.functionExpression.parameters,
219 element.parameters);
274 } 220 }
275 221
276 @override 222 @override
277 visitFunctionTypeAlias(FunctionTypeAlias node) { 223 visitFunctionTypeAlias(FunctionTypeAlias node) {
278 FunctionTypeAliasElement outerAlias = _enclosingAlias; 224 FunctionTypeAliasElement outerAlias = _enclosingAlias;
279 try { 225 try {
280 SimpleIdentifier aliasName = node.name; 226 SimpleIdentifier aliasName = node.name;
281 _enclosingAlias = 227 _enclosingAlias =
282 _findIdentifier(_enclosingUnit.functionTypeAliases, aliasName); 228 _findIdentifier(_enclosingUnit.functionTypeAliases, aliasName);
283 _processElement(_enclosingAlias); 229 _processElement(_enclosingAlias);
284 super.visitFunctionTypeAlias(node); 230 super.visitFunctionTypeAlias(node);
285 } finally { 231 } finally {
286 _enclosingAlias = outerAlias; 232 _enclosingAlias = outerAlias;
287 } 233 }
288 } 234 }
289 235
290 @override 236 @override
291 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
292 if (node.parent is! DefaultFormalParameter) {
293 SimpleIdentifier parameterName = node.identifier;
294 ParameterElement element = _getElementForParameter(node, parameterName);
295 ParameterElement outerParameter = _enclosingParameter;
296 try {
297 _enclosingParameter = element;
298 _processElement(_enclosingParameter);
299 super.visitFunctionTypedFormalParameter(node);
300 } finally {
301 _enclosingParameter = outerParameter;
302 }
303 } else {
304 super.visitFunctionTypedFormalParameter(node);
305 }
306 }
307
308 @override
309 visitImplementsClause(ImplementsClause node) { 237 visitImplementsClause(ImplementsClause node) {
310 List<TypeName> nodes = node.interfaces; 238 List<TypeName> nodes = node.interfaces;
311 List<InterfaceType> types = _enclosingClass.interfaces; 239 List<InterfaceType> types = _enclosingClass.interfaces;
312 _assertSameTypes(nodes, types); 240 _assertSameTypes(nodes, types);
313 } 241 }
314 242
315 @override 243 @override
316 visitImportDirective(ImportDirective node) { 244 visitImportDirective(ImportDirective node) {
317 String uri = _getStringValue(node.uri); 245 String uri = _getStringValue(node.uri);
318 if (uri != null) { 246 if (uri != null) {
319 LibraryElement library = _enclosingUnit.library; 247 LibraryElement library = _enclosingUnit.library;
320 ImportElement importElement = _findImport( 248 ImportElement importElement = _findImport(
321 library.imports, 249 library.imports,
322 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri), 250 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri),
323 node.prefix); 251 node.prefix);
324 _processElement(importElement); 252 _processElement(importElement);
325 } 253 }
326 super.visitImportDirective(node); 254 super.visitImportDirective(node);
327 } 255 }
328 256
329 @override 257 @override
330 visitMethodDeclaration(MethodDeclaration node) { 258 visitMethodDeclaration(MethodDeclaration node) {
331 ExecutableElement outerExecutable = _enclosingExecutable; 259 // prepare element name
332 try { 260 String name = node.name.name;
333 Token property = node.propertyKeyword; 261 if (name == TokenType.MINUS.lexeme &&
334 SimpleIdentifier methodName = node.name; 262 node.parameters.parameters.length == 0) {
335 String nameOfMethod = methodName.name; 263 name = "unary-";
336 if (nameOfMethod == TokenType.MINUS.lexeme &&
337 node.parameters.parameters.length == 0) {
338 nameOfMethod = "unary-";
339 }
340 if (property == null) {
341 _enclosingExecutable = _findWithNameAndOffset(
342 _enclosingClass.methods,
343 nameOfMethod,
344 methodName.offset);
345 methodName.staticElement = _enclosingExecutable;
346 } else {
347 PropertyAccessorElement accessor =
348 _findIdentifier(_enclosingClass.accessors, methodName);
349 if ((property as KeywordToken).keyword == Keyword.SET) {
350 accessor = accessor.variable.setter;
351 methodName.staticElement = accessor;
352 }
353 _enclosingExecutable = accessor;
354 }
355 _processElement(_enclosingExecutable);
356 super.visitMethodDeclaration(node);
357 } finally {
358 _enclosingExecutable = outerExecutable;
359 } 264 }
265 // prepare element
266 Token property = node.propertyKeyword;
267 ExecutableElement element;
268 if (property == null) {
269 element = _findElement(_enclosingClass.methods, name);
270 } else {
271 PropertyAccessorElement accessor =
272 _findElement(_enclosingClass.accessors, name);
273 _assertNotNull(accessor);
274 _assertFalse(element.isSynthetic);
275 _assertEquals(node.isGetter, accessor.isGetter);
276 _assertEquals(node.isSetter, accessor.isSetter);
277 element = accessor;
278 }
279 // process element
280 _processElement(element);
281 // TODO(scheglov) test returnType
282 _assertSameType(node.returnType, element.returnType);
283 _assertCompatibleParameters(node.parameters, element.parameters);
360 } 284 }
361 285
362 @override 286 @override
363 visitPartDirective(PartDirective node) { 287 visitPartDirective(PartDirective node) {
364 String uri = _getStringValue(node.uri); 288 String uri = _getStringValue(node.uri);
365 if (uri != null) { 289 if (uri != null) {
366 Source partSource = 290 Source partSource =
367 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri); 291 _enclosingUnit.context.sourceFactory.resolveUri(_enclosingUnit.source, uri);
368 CompilationUnitElement element = 292 CompilationUnitElement element =
369 _findPart(_enclosingUnit.library.parts, partSource); 293 _findPart(_enclosingUnit.library.parts, partSource);
370 _processElement(element); 294 _processElement(element);
371 } 295 }
372 super.visitPartDirective(node); 296 super.visitPartDirective(node);
373 } 297 }
374 298
375 @override 299 @override
376 visitSimpleFormalParameter(SimpleFormalParameter node) {
377 if (node.parent is! DefaultFormalParameter) {
378 SimpleIdentifier parameterName = node.identifier;
379 ParameterElement element = _getElementForParameter(node, parameterName);
380 ParameterElement outerParameter = _enclosingParameter;
381 try {
382 _enclosingParameter = element;
383 _processElement(_enclosingParameter);
384 super.visitSimpleFormalParameter(node);
385 } finally {
386 _enclosingParameter = outerParameter;
387 }
388 } else {
389 }
390 super.visitSimpleFormalParameter(node);
391 }
392
393 @override
394 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 300 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
395 _inTopLevelVariableDeclaration = true; 301 _inTopLevelVariableDeclaration = true;
396 try { 302 try {
397 super.visitTopLevelVariableDeclaration(node); 303 super.visitTopLevelVariableDeclaration(node);
398 } finally { 304 } finally {
399 _inTopLevelVariableDeclaration = false; 305 _inTopLevelVariableDeclaration = false;
400 } 306 }
401 } 307 }
402 308
403 @override 309 @override
404 visitTypeParameter(TypeParameter node) { 310 visitTypeParameter(TypeParameter node) {
405 SimpleIdentifier parameterName = node.name; 311 SimpleIdentifier parameterName = node.name;
406 TypeParameterElement element = null; 312 TypeParameterElement element = null;
407 if (_enclosingClass != null) { 313 if (_enclosingClass != null) {
408 element = _findIdentifier(_enclosingClass.typeParameters, parameterName); 314 element = _findIdentifier(_enclosingClass.typeParameters, parameterName);
409 } else if (_enclosingAlias != null) { 315 } else if (_enclosingAlias != null) {
410 element = _findIdentifier(_enclosingAlias.typeParameters, parameterName); 316 element = _findIdentifier(_enclosingAlias.typeParameters, parameterName);
411 } 317 }
412 _processElement(element); 318 _processElement(element);
413 super.visitTypeParameter(node); 319 super.visitTypeParameter(node);
414 } 320 }
415 321
416 @override 322 @override
417 visitVariableDeclaration(VariableDeclaration node) { 323 visitVariableDeclaration(VariableDeclaration node) {
324 // prepare variable
418 String name = node.name.name; 325 String name = node.name.name;
326 PropertyInducingElement variable;
419 if (_inTopLevelVariableDeclaration) { 327 if (_inTopLevelVariableDeclaration) {
420 TopLevelVariableElement variable = 328 variable = _findElement(_enclosingUnit.topLevelVariables, name);
421 _findElement(_enclosingUnit.topLevelVariables, name); 329 } else {
422 _assertNotNull(variable); 330 variable = _findElement(_enclosingClass.fields, name);
423 _assertFalse(variable.isSynthetic);
424 _assertEquals(node.isConst, variable.isConst);
425 _assertEquals(node.isFinal, variable.isFinal);
426 _assertSameType(
427 (node.parent as VariableDeclarationList).type,
428 variable.type);
429 _processElement(variable);
430 return;
431 } 331 }
432 VariableElement element; 332 // verify
433 if (_enclosingExecutable != null) { 333 _assertNotNull(variable);
434 element = _findElement(_enclosingExecutable.localVariables, name); 334 _processElement(variable);
335 _assertEquals(node.isConst, variable.isConst);
336 _assertEquals(node.isFinal, variable.isFinal);
337 if (_enclosingFieldNode != null) {
338 _assertEquals(_enclosingFieldNode.isStatic, variable.isStatic);
435 } 339 }
436 if (element == null && _enclosingClass != null) { 340 _assertSameType(
437 element = _findElement(_enclosingClass.fields, name); 341 (node.parent as VariableDeclarationList).type,
438 } 342 variable.type);
439 super.visitVariableDeclaration(node);
440 } 343 }
441 344
442 @override 345 @override
443 visitWithClause(WithClause node) { 346 visitWithClause(WithClause node) {
444 List<TypeName> nodes = node.mixinTypes; 347 List<TypeName> nodes = node.mixinTypes;
445 List<InterfaceType> types = _enclosingClass.mixins; 348 List<InterfaceType> types = _enclosingClass.mixins;
446 _assertSameTypes(nodes, types); 349 _assertSameTypes(nodes, types);
447 } 350 }
448 351
352 void _assertCompatibleParameter(FormalParameter node,
353 ParameterElement element) {
354 if (node is SimpleFormalParameter) {
355 _assertSameType(node.type, element.type);
356 } else {
357 // TODO(scheglov) support other parameter types
358 _assertTrue(false);
359 }
360 // TODO(scheglov) check names of named parameters
361 }
362
363 void _assertCompatibleParameters(FormalParameterList nodes,
364 List<ParameterElement> elements) {
365 List<FormalParameter> parameters = nodes.parameters;
366 int length = parameters.length;
367 _assertEquals(length, elements.length);
368 for (int i = 0; i < length; i++) {
369 _assertCompatibleParameter(parameters[i], elements[i]);
370 }
371 }
372
449 void _assertEquals(Object a, Object b) { 373 void _assertEquals(Object a, Object b) {
450 if (a != b) { 374 if (a != b) {
451 throw new _DeclarationMismatchException(); 375 throw new _DeclarationMismatchException();
452 } 376 }
453 } 377 }
454 378
455 void _assertFalse(bool condition) { 379 void _assertFalse(bool condition) {
456 if (condition) { 380 if (condition) {
457 throw new _DeclarationMismatchException(); 381 throw new _DeclarationMismatchException();
458 } 382 }
459 } 383 }
460 384
461 void _assertNotNull(Element element) { 385 void _assertNotNull(Element element) {
462 if (element == null) { 386 if (element == null) {
463 throw new _DeclarationMismatchException(); 387 throw new _DeclarationMismatchException();
464 } 388 }
465 } 389 }
466 390
467 void _assertSameType(TypeName node, DartType type) { 391 void _assertSameType(TypeName node, DartType type) {
392 // no return type == dynamic
393 if (node == null) {
394 return _assertTrue(type.isDynamic);
395 }
396 // check specific type kinds
468 String nodeName = node.name.name; 397 String nodeName = node.name.name;
469 if (type is InterfaceType) { 398 if (type is InterfaceType) {
470 _assertEquals(nodeName, type.name); 399 _assertEquals(nodeName, type.name);
471 // check arguments 400 // check arguments
472 TypeArgumentList nodeArgumentList = node.typeArguments; 401 TypeArgumentList nodeArgumentList = node.typeArguments;
473 List<DartType> typeArguments = type.typeArguments; 402 List<DartType> typeArguments = type.typeArguments;
474 if (nodeArgumentList == null) { 403 if (nodeArgumentList == null) {
475 _assertTrue(typeArguments.isEmpty); 404 _assertTrue(typeArguments.isEmpty);
476 } else { 405 } else {
477 List<TypeName> nodeArguments = nodeArgumentList.arguments; 406 List<TypeName> nodeArguments = nodeArgumentList.arguments;
478 _assertSameTypes(nodeArguments, typeArguments); 407 _assertSameTypes(nodeArguments, typeArguments);
479 } 408 }
480 } else { 409 } else {
481 // TODO(scheglov) support other types 410 // TODO(scheglov) support other types
482 _assertTrue(false); 411 _assertTrue(false);
483 } 412 }
484 } 413 }
485 414
486 void _assertSameTypes(List<TypeName> nodes, List<DartType> type) { 415 void _assertSameTypes(List<TypeName> nodes, List<DartType> types) {
487 int length = nodes.length; 416 int length = nodes.length;
488 _assertEquals(length, type.length); 417 _assertEquals(length, types.length);
489 for (int i = 0; i < length; i++) { 418 for (int i = 0; i < length; i++) {
490 _assertSameType(nodes[i], type[i]); 419 _assertSameType(nodes[i], types[i]);
491 } 420 }
492 } 421 }
493 422
494 void _assertTrue(bool condition) { 423 void _assertTrue(bool condition) {
495 if (!condition) { 424 if (!condition) {
496 throw new _DeclarationMismatchException(); 425 throw new _DeclarationMismatchException();
497 } 426 }
498 } 427 }
499 428
500 /** 429 /**
501 * Given that the comparison is to begin with the given element, capture the e nclosing elements 430 * Given that the comparison is to begin with the given element, capture the e nclosing elements
502 * that might be used while performing the comparison. 431 * that might be used while performing the comparison.
503 * 432 *
504 * @param element the element corresponding to the AST structure to be compare d 433 * @param element the element corresponding to the AST structure to be compare d
505 */ 434 */
506 void _captureEnclosingElements(Element element) { 435 void _captureEnclosingElements(Element element) {
507 Element parent = 436 Element parent =
508 element is CompilationUnitElement ? element : element.enclosingElement; 437 element is CompilationUnitElement ? element : element.enclosingElement;
509 while (parent != null) { 438 while (parent != null) {
510 if (parent is CompilationUnitElement) { 439 if (parent is CompilationUnitElement) {
511 _enclosingUnit = parent as CompilationUnitElement; 440 _enclosingUnit = parent as CompilationUnitElement;
512 } else if (parent is ClassElement) { 441 } else if (parent is ClassElement) {
513 if (_enclosingClass == null) { 442 if (_enclosingClass == null) {
514 _enclosingClass = parent as ClassElement; 443 _enclosingClass = parent as ClassElement;
515 } 444 }
516 } else if (parent is FunctionTypeAliasElement) { 445 } else if (parent is FunctionTypeAliasElement) {
517 if (_enclosingAlias == null) { 446 if (_enclosingAlias == null) {
518 _enclosingAlias = parent as FunctionTypeAliasElement; 447 _enclosingAlias = parent as FunctionTypeAliasElement;
519 } 448 }
520 } else if (parent is ExecutableElement) {
521 if (_enclosingExecutable == null) {
522 _enclosingExecutable = parent as ExecutableElement;
523 }
524 } else if (parent is ParameterElement) { 449 } else if (parent is ParameterElement) {
525 if (_enclosingParameter == null) { 450 if (_enclosingParameter == null) {
526 _enclosingParameter = parent as ParameterElement; 451 _enclosingParameter = parent as ParameterElement;
527 } 452 }
528 } 453 }
529 parent = parent.enclosingElement; 454 parent = parent.enclosingElement;
530 } 455 }
531 } 456 }
532 457
533 /** 458 /**
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } 562 }
638 } 563 }
639 return null; 564 return null;
640 } 565 }
641 566
642 void _gatherElements(Element element) { 567 void _gatherElements(Element element) {
643 element.accept(new _ElementsGatherer(this)); 568 element.accept(new _ElementsGatherer(this));
644 } 569 }
645 570
646 /** 571 /**
647 * Search the most closely enclosing list of parameters for a parameter with t he given name.
648 *
649 * @param node the node defining the parameter with the given name
650 * @param parameterName the name of the parameter being searched for
651 * @return the element representing the parameter with that name
652 */
653 ParameterElement _getElementForParameter(FormalParameter node,
654 SimpleIdentifier parameterName) {
655 List<ParameterElement> parameters = null;
656 if (_enclosingParameter != null) {
657 parameters = _enclosingParameter.parameters;
658 }
659 if (parameters == null && _enclosingExecutable != null) {
660 parameters = _enclosingExecutable.parameters;
661 }
662 if (parameters == null && _enclosingAlias != null) {
663 parameters = _enclosingAlias.parameters;
664 }
665 return parameters == null ?
666 null :
667 _findIdentifier(parameters, parameterName);
668 }
669
670 /**
671 * Return the value of the given string literal, or `null` if the string is no t a constant 572 * Return the value of the given string literal, or `null` if the string is no t a constant
672 * string without any string interpolation. 573 * string without any string interpolation.
673 * 574 *
674 * @param literal the string literal whose value is to be returned 575 * @param literal the string literal whose value is to be returned
675 * @return the value of the given string literal 576 * @return the value of the given string literal
676 */ 577 */
677 String _getStringValue(StringLiteral literal) { 578 String _getStringValue(StringLiteral literal) {
678 if (literal is StringInterpolation) { 579 if (literal is StringInterpolation) {
679 return null; 580 return null;
680 } 581 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 929
1029 _ElementsGatherer(this.matcher); 930 _ElementsGatherer(this.matcher);
1030 931
1031 @override 932 @override
1032 visitElement(Element element) { 933 visitElement(Element element) {
1033 _addElement(element); 934 _addElement(element);
1034 super.visitElement(element); 935 super.visitElement(element);
1035 } 936 }
1036 937
1037 @override 938 @override
939 visitExecutableElement(ExecutableElement element) {
940 _addElement(element);
941 }
942
943 @override
1038 visitPropertyAccessorElement(PropertyAccessorElement element) { 944 visitPropertyAccessorElement(PropertyAccessorElement element) {
1039 if (!element.isSynthetic) { 945 if (!element.isSynthetic) {
1040 _addElement(element); 946 _addElement(element);
1041 } 947 }
1042 // Don't visit children (such as synthetic setter parameters). 948 // Don't visit children (such as synthetic setter parameters).
1043 } 949 }
1044 950
1045 @override 951 @override
1046 visitPropertyInducingElement(PropertyInducingElement element) { 952 visitPropertyInducingElement(PropertyInducingElement element) {
1047 if (!element.isSynthetic) { 953 if (!element.isSynthetic) {
1048 _addElement(element); 954 _addElement(element);
1049 } 955 }
1050 // Don't visit children (such as property accessors). 956 // Don't visit children (such as property accessors).
1051 } 957 }
1052 958
1053 void _addElement(Element element) { 959 void _addElement(Element element) {
1054 if (element != null) { 960 if (element != null) {
1055 matcher._allElements.add(element); 961 matcher._allElements.add(element);
1056 matcher._unmatchedElements.add(element); 962 matcher._unmatchedElements.add(element);
1057 } 963 }
1058 } 964 }
1059 } 965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698