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

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

Issue 754673002: Matching of top-level functions, methods and accessors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 _enclosingFieldNode = node; 193 _enclosingFieldNode = node;
194 try { 194 try {
195 super.visitFieldDeclaration(node); 195 super.visitFieldDeclaration(node);
196 } finally { 196 } finally {
197 _enclosingFieldNode = null; 197 _enclosingFieldNode = null;
198 } 198 }
199 } 199 }
200 200
201 @override 201 @override
202 visitFunctionDeclaration(FunctionDeclaration node) { 202 visitFunctionDeclaration(FunctionDeclaration node) {
203 // prepare element name
203 String name = node.name.name; 204 String name = node.name.name;
205 if (node.isSetter) {
206 name += '=';
207 }
208 // prepare element
204 Token property = node.propertyKeyword; 209 Token property = node.propertyKeyword;
205 ExecutableElement element; 210 ExecutableElement element;
206 if (property == null) { 211 if (property == null) {
207 element = _findElement(_enclosingUnit.functions, name); 212 element = _findElement(_enclosingUnit.functions, name);
208 _processElement(element);
209 } else { 213 } else {
210 PropertyAccessorElement accessor = 214 element = _findElement(_enclosingUnit.accessors, name);
211 _findElement(_enclosingUnit.accessors, name);
212 _assertNotNull(accessor);
213 _assertFalse(element.isSynthetic);
214 _assertEquals(node.isGetter, accessor.isGetter);
215 _assertEquals(node.isSetter, accessor.isSetter);
216 element = accessor;
217 } 215 }
216 // process element
218 _processElement(element); 217 _processElement(element);
219 // TODO(scheglov) test returnType 218 _assertFalse(element.isSynthetic);
220 _assertSameType(node.returnType, element.returnType); 219 _assertSameType(node.returnType, element.returnType);
221 _assertCompatibleParameters( 220 _assertCompatibleParameters(
222 node.functionExpression.parameters, 221 node.functionExpression.parameters,
223 element.parameters); 222 element.parameters);
224 } 223 }
225 224
226 @override 225 @override
227 visitFunctionTypeAlias(FunctionTypeAlias node) { 226 visitFunctionTypeAlias(FunctionTypeAlias node) {
228 FunctionTypeAliasElement outerAlias = _enclosingAlias; 227 FunctionTypeAliasElement outerAlias = _enclosingAlias;
229 try { 228 try {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (name == TokenType.MINUS.lexeme && 271 if (name == TokenType.MINUS.lexeme &&
273 node.parameters.parameters.length == 0) { 272 node.parameters.parameters.length == 0) {
274 name = "unary-"; 273 name = "unary-";
275 } 274 }
276 // prepare element 275 // prepare element
277 Token property = node.propertyKeyword; 276 Token property = node.propertyKeyword;
278 ExecutableElement element; 277 ExecutableElement element;
279 if (property == null) { 278 if (property == null) {
280 element = _findElement(_enclosingClass.methods, name); 279 element = _findElement(_enclosingClass.methods, name);
281 } else { 280 } else {
282 PropertyAccessorElement accessor = 281 element = _findElement(_enclosingClass.accessors, name);
283 _findElement(_enclosingClass.accessors, name);
284 _assertNotNull(accessor);
285 _assertFalse(element.isSynthetic);
286 _assertEquals(node.isGetter, accessor.isGetter);
287 _assertEquals(node.isSetter, accessor.isSetter);
288 element = accessor;
289 } 282 }
290 // process element 283 // process element
291 _processElement(element); 284 _processElement(element);
292 // TODO(scheglov) test returnType 285 _assertFalse(element.isSynthetic);
286 _assertEquals(node.isStatic, element.isStatic);
293 _assertSameType(node.returnType, element.returnType); 287 _assertSameType(node.returnType, element.returnType);
294 _assertCompatibleParameters(node.parameters, element.parameters); 288 _assertCompatibleParameters(node.parameters, element.parameters);
295 } 289 }
296 290
297 @override 291 @override
298 visitPartDirective(PartDirective node) { 292 visitPartDirective(PartDirective node) {
299 String uri = _getStringValue(node.uri); 293 String uri = _getStringValue(node.uri);
300 if (uri != null) { 294 if (uri != null) {
301 CompilationUnitElement element = 295 CompilationUnitElement element =
302 _findUriReferencedElement(_enclosingLibrary.parts, uri); 296 _findUriReferencedElement(_enclosingLibrary.parts, uri);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 _assertSameType(node.type, element.type); 388 _assertSameType(node.type, element.type);
395 } else { 389 } else {
396 // TODO(scheglov) support other parameter types 390 // TODO(scheglov) support other parameter types
397 _assertTrue(false); 391 _assertTrue(false);
398 } 392 }
399 // TODO(scheglov) check names of named parameters 393 // TODO(scheglov) check names of named parameters
400 } 394 }
401 395
402 void _assertCompatibleParameters(FormalParameterList nodes, 396 void _assertCompatibleParameters(FormalParameterList nodes,
403 List<ParameterElement> elements) { 397 List<ParameterElement> elements) {
398 if (nodes == null) {
399 return _assertEquals(elements.length, 0);
400 }
404 List<FormalParameter> parameters = nodes.parameters; 401 List<FormalParameter> parameters = nodes.parameters;
405 int length = parameters.length; 402 int length = parameters.length;
406 _assertEquals(length, elements.length); 403 _assertEquals(length, elements.length);
407 for (int i = 0; i < length; i++) { 404 for (int i = 0; i < length; i++) {
408 _assertCompatibleParameter(parameters[i], elements[i]); 405 _assertCompatibleParameter(parameters[i], elements[i]);
409 } 406 }
410 } 407 }
411 408
412 void _assertEquals(Object a, Object b) { 409 void _assertEquals(Object a, Object b) {
413 if (a != b) { 410 if (a != b) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 497 }
501 parent = parent.enclosingElement; 498 parent = parent.enclosingElement;
502 } 499 }
503 } 500 }
504 501
505 /** 502 /**
506 * Return the [Element] in [elements] with the given [name]. 503 * Return the [Element] in [elements] with the given [name].
507 */ 504 */
508 Element _findElement(List<Element> elements, String name) { 505 Element _findElement(List<Element> elements, String name) {
509 for (Element element in elements) { 506 for (Element element in elements) {
510 if (element.displayName == name) { 507 if (element.name == name) {
511 return element; 508 return element;
512 } 509 }
513 } 510 }
514 return null; 511 return null;
515 } 512 }
516 513
517 /** 514 /**
518 * Return the element in the given array of elements that was created for the declaration with the 515 * Return the element in the given array of elements that was created for the declaration with the
519 * given name. 516 * given name.
520 * 517 *
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 visitFunctionExpression(FunctionExpression node) { 1070 visitFunctionExpression(FunctionExpression node) {
1074 _elements[node] = node.element; 1071 _elements[node] = node.element;
1075 super.visitFunctionExpression(node); 1072 super.visitFunctionExpression(node);
1076 } 1073 }
1077 1074
1078 @override 1075 @override
1079 visitSimpleIdentifier(SimpleIdentifier node) { 1076 visitSimpleIdentifier(SimpleIdentifier node) {
1080 _elements[node] = node.staticElement; 1077 _elements[node] = node.staticElement;
1081 } 1078 }
1082 } 1079 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698