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

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

Issue 2085553002: Implement _SameResolutionValidator as AstComparator. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
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 analyzer.src.generated.incremental_resolution_validator; 5 library analyzer.src.generated.incremental_resolution_validator;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
11 import 'package:analyzer/src/dart/ast/utilities.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 12 import 'package:analyzer/src/dart/element/element.dart';
11 import 'package:analyzer/src/dart/element/member.dart'; 13 import 'package:analyzer/src/dart/element/member.dart';
12 14
13 /** 15 /**
14 * Validates that the [actual] and the [expected] units have the same structure 16 * Validates that the [actual] and the [expected] units have the same structure
15 * and resolution. Throws [IncrementalResolutionMismatch] otherwise. 17 * and resolution. Throws [IncrementalResolutionMismatch] otherwise.
16 */ 18 */
17 void assertSameResolution(CompilationUnit actual, CompilationUnit expected, 19 void assertSameResolution(CompilationUnit actual, CompilationUnit expected,
18 {bool validateTypes: false}) { 20 {bool validateTypes: false}) {
19 _SameResolutionValidator validator = 21 _SameResolutionValidator validator = new _SameResolutionValidator(validateType s);
20 new _SameResolutionValidator(validateTypes, expected); 22 validator.isEqualNodes(expected, actual);
21 actual.accept(validator);
22 } 23 }
23 24
24 /** 25 /**
25 * This exception is thrown when a mismatch between actual and expected AST 26 * This exception is thrown when a mismatch between actual and expected AST
26 * or resolution is found. 27 * or resolution is found.
27 */ 28 */
28 class IncrementalResolutionMismatch { 29 class IncrementalResolutionMismatch {
29 final String message; 30 final String message;
30 IncrementalResolutionMismatch(this.message); 31 IncrementalResolutionMismatch(this.message);
31 32
32 @override 33 @override
33 String toString() => "IncrementalResolutionMismatch: $message"; 34 String toString() => "IncrementalResolutionMismatch: $message";
34 } 35 }
35 36
36 class _SameResolutionValidator implements AstVisitor { 37 /**
38 * An [AstVisitor] that compares the structure of two [AstNode]s and their
39 * resolution to see whether they are equal.
40 */
41 class _SameResolutionValidator extends AstComparator {
37 final bool validateTypes; 42 final bool validateTypes;
38 43
39 /// The expected node to compare with the visited node. 44 _SameResolutionValidator(this.validateTypes);
40 AstNode other;
41
42 _SameResolutionValidator(this.validateTypes, this.other);
43 45
44 @override 46 @override
45 visitAdjacentStrings(AdjacentStrings node) {} 47 bool failDifferentLength(List expectedList, List actualList) {
46 48 int expectedLength = expectedList.length;
47 @override 49 int actualLength = actualList.length;
48 visitAnnotation(Annotation node) { 50 String message = '';
49 Annotation other = this.other; 51 message += 'Expected length: $expectedLength\n';
50 _visitNode(node.name, other.name); 52 message += 'but $actualLength found\n';
51 _visitNode(node.constructorName, other.constructorName); 53 message += 'in $actualList';
52 _visitNode(node.arguments, other.arguments); 54 _fail(message);
53 _verifyElement(node.element, other.element); 55 return false;
54 } 56 }
55 57
56 @override 58 @override
57 visitArgumentList(ArgumentList node) { 59 bool failIfNotNull(Object expected, Object actual) {
58 ArgumentList other = this.other; 60 if (actual != null) {
59 _visitList(node.arguments, other.arguments); 61 _fail('Expected null, but found $actual');
62 return false;
63 }
64 return true;
60 } 65 }
61 66
62 @override 67 @override
63 visitAsExpression(AsExpression node) { 68 bool failIsNull(Object expected, Object actual) {
64 AsExpression other = this.other; 69 _fail('Expected not null, but found null');
65 _visitExpression(node, other); 70 return false;
66 _visitNode(node.expression, other.expression);
67 _visitNode(node.type, other.type);
68 } 71 }
69 72
70 @override 73 @override
71 visitAssertStatement(AssertStatement node) { 74 bool failRuntimeType(Object expected, Object actual) {
72 AssertStatement other = this.other; 75 _fail('Expected ${expected.runtimeType}, but found ${actual.runtimeType}');
73 _visitNode(node.condition, other.condition); 76 return false;
74 _visitNode(node.message, other.message);
75 } 77 }
76 78
77 @override 79 @override
78 visitAssignmentExpression(AssignmentExpression node) { 80 bool isEqualNodes(AstNode first, AstNode second) {
79 AssignmentExpression other = this.other; 81 super.isEqualNodes(first, second);
80 _visitExpression(node, other); 82 if (first is SimpleIdentifier && second is SimpleIdentifier) {
81 _verifyElement(node.staticElement, other.staticElement); 83 int offset = first.offset;
82 _verifyElement(node.propagatedElement, other.propagatedElement); 84 _verifyElement(
83 _visitNode(node.leftHandSide, other.leftHandSide); 85 first.staticElement, second.staticElement, 'staticElement[$offset]');
84 _visitNode(node.rightHandSide, other.rightHandSide); 86 _verifyElement(first.propagatedElement, second.propagatedElement,
87 'propagatedElement[$offset]');
88 } else if (first is Declaration && second is Declaration) {
89 int offset = first.offset;
90 _verifyElement(first.element, second.element, 'declaration[$offset]');
91 } else if (first is Directive && second is Directive) {
92 int offset = first.offset;
93 _verifyElement(first.element, second.element, 'directive[$offset]');
94 } else if (first is Expression && second is Expression) {
95 int offset = first.offset;
96 _verifyType(first.staticType, second.staticType, 'staticType[$offset]');
97 _verifyType(first.propagatedType, second.propagatedType,
98 'propagatedType[$offset]');
99 _verifyElement(first.staticParameterElement,
100 second.staticParameterElement, 'staticParameterElement[$offset]');
101 _verifyElement(
102 first.propagatedParameterElement,
103 second.propagatedParameterElement,
104 'propagatedParameterElement[$offset]');
105 }
106 return true;
85 } 107 }
86 108
87 @override 109 @override
88 visitAwaitExpression(AwaitExpression node) { 110 bool isEqualTokensNotNull(Token expected, Token actual) {
89 AwaitExpression other = this.other; 111 _verifyEqual('lexeme', expected.lexeme, actual.lexeme);
90 _visitExpression(node, other); 112 _verifyEqual('offset', expected.offset, actual.offset);
91 _visitNode(node.expression, other.expression); 113 _verifyEqual('offset', expected.length, actual.length);
92 } 114 return true;
93
94 @override
95 visitBinaryExpression(BinaryExpression node) {
96 BinaryExpression other = this.other;
97 _visitExpression(node, other);
98 _verifyElement(node.staticElement, other.staticElement);
99 _verifyElement(node.propagatedElement, other.propagatedElement);
100 _visitNode(node.leftOperand, other.leftOperand);
101 _visitNode(node.rightOperand, other.rightOperand);
102 }
103
104 @override
105 visitBlock(Block node) {
106 Block other = this.other;
107 _visitList(node.statements, other.statements);
108 }
109
110 @override
111 visitBlockFunctionBody(BlockFunctionBody node) {
112 BlockFunctionBody other = this.other;
113 _visitNode(node.block, other.block);
114 }
115
116 @override
117 visitBooleanLiteral(BooleanLiteral node) {
118 BooleanLiteral other = this.other;
119 _visitExpression(node, other);
120 }
121
122 @override
123 visitBreakStatement(BreakStatement node) {
124 BreakStatement other = this.other;
125 _visitNode(node.label, other.label);
126 }
127
128 @override
129 visitCascadeExpression(CascadeExpression node) {
130 CascadeExpression other = this.other;
131 _visitExpression(node, other);
132 _visitNode(node.target, other.target);
133 _visitList(node.cascadeSections, other.cascadeSections);
134 }
135
136 @override
137 visitCatchClause(CatchClause node) {
138 CatchClause other = this.other;
139 _visitNode(node.exceptionType, other.exceptionType);
140 _visitNode(node.exceptionParameter, other.exceptionParameter);
141 _visitNode(node.stackTraceParameter, other.stackTraceParameter);
142 _visitNode(node.body, other.body);
143 }
144
145 @override
146 visitClassDeclaration(ClassDeclaration node) {
147 ClassDeclaration other = this.other;
148 _visitDeclaration(node, other);
149 _visitNode(node.name, other.name);
150 _visitNode(node.typeParameters, other.typeParameters);
151 _visitNode(node.extendsClause, other.extendsClause);
152 _visitNode(node.implementsClause, other.implementsClause);
153 _visitNode(node.withClause, other.withClause);
154 _visitList(node.members, other.members);
155 }
156
157 @override
158 visitClassTypeAlias(ClassTypeAlias node) {
159 ClassTypeAlias other = this.other;
160 _visitDeclaration(node, other);
161 _visitNode(node.name, other.name);
162 _visitNode(node.typeParameters, other.typeParameters);
163 _visitNode(node.superclass, other.superclass);
164 _visitNode(node.withClause, other.withClause);
165 }
166
167 @override
168 visitComment(Comment node) {
169 Comment other = this.other;
170 _visitList(node.references, other.references);
171 }
172
173 @override
174 visitCommentReference(CommentReference node) {
175 CommentReference other = this.other;
176 _visitNode(node.identifier, other.identifier);
177 }
178
179 @override
180 visitCompilationUnit(CompilationUnit node) {
181 CompilationUnit other = this.other;
182 _verifyElement(node.element, other.element);
183 _visitList(node.directives, other.directives);
184 _visitList(node.declarations, other.declarations);
185 }
186
187 @override
188 visitConditionalExpression(ConditionalExpression node) {
189 ConditionalExpression other = this.other;
190 _visitExpression(node, other);
191 _visitNode(node.condition, other.condition);
192 _visitNode(node.thenExpression, other.thenExpression);
193 _visitNode(node.elseExpression, other.elseExpression);
194 }
195
196 @override
197 visitConfiguration(Configuration node) {
198 Configuration other = this.other;
199 _visitNode(node.name, other.name);
200 _visitNode(node.value, other.value);
201 _visitNode(node.libraryUri, other.libraryUri);
202 }
203
204 @override
205 visitConstructorDeclaration(ConstructorDeclaration node) {
206 ConstructorDeclaration other = this.other;
207 _visitDeclaration(node, other);
208 _visitNode(node.returnType, other.returnType);
209 _visitNode(node.name, other.name);
210 _visitNode(node.parameters, other.parameters);
211 _visitNode(node.redirectedConstructor, other.redirectedConstructor);
212 _visitList(node.initializers, other.initializers);
213 }
214
215 @override
216 visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
217 ConstructorFieldInitializer other = this.other;
218 _visitNode(node.fieldName, other.fieldName);
219 _visitNode(node.expression, other.expression);
220 }
221
222 @override
223 visitConstructorName(ConstructorName node) {
224 ConstructorName other = this.other;
225 _verifyElement(node.staticElement, other.staticElement);
226 _visitNode(node.type, other.type);
227 _visitNode(node.name, other.name);
228 }
229
230 @override
231 visitContinueStatement(ContinueStatement node) {
232 ContinueStatement other = this.other;
233 _visitNode(node.label, other.label);
234 }
235
236 @override
237 visitDeclaredIdentifier(DeclaredIdentifier node) {
238 DeclaredIdentifier other = this.other;
239 _visitNode(node.type, other.type);
240 _visitNode(node.identifier, other.identifier);
241 }
242
243 @override
244 visitDefaultFormalParameter(DefaultFormalParameter node) {
245 DefaultFormalParameter other = this.other;
246 _visitNode(node.parameter, other.parameter);
247 _visitNode(node.defaultValue, other.defaultValue);
248 }
249
250 @override
251 visitDoStatement(DoStatement node) {
252 DoStatement other = this.other;
253 _visitNode(node.condition, other.condition);
254 _visitNode(node.body, other.body);
255 }
256
257 @override
258 visitDottedName(DottedName node) {
259 DottedName other = this.other;
260 _visitList(node.components, other.components);
261 }
262
263 @override
264 visitDoubleLiteral(DoubleLiteral node) {
265 DoubleLiteral other = this.other;
266 _visitExpression(node, other);
267 }
268
269 @override
270 visitEmptyFunctionBody(EmptyFunctionBody node) {}
271
272 @override
273 visitEmptyStatement(EmptyStatement node) {}
274
275 @override
276 visitEnumConstantDeclaration(EnumConstantDeclaration node) {
277 EnumConstantDeclaration other = this.other;
278 _visitDeclaration(node, other);
279 _visitNode(node.name, other.name);
280 }
281
282 @override
283 visitEnumDeclaration(EnumDeclaration node) {
284 EnumDeclaration other = this.other;
285 _visitDeclaration(node, other);
286 _visitNode(node.name, other.name);
287 _visitList(node.constants, other.constants);
288 }
289
290 @override
291 visitExportDirective(ExportDirective node) {
292 ExportDirective other = this.other;
293 _visitDirective(node, other);
294 }
295
296 @override
297 visitExpressionFunctionBody(ExpressionFunctionBody node) {
298 ExpressionFunctionBody other = this.other;
299 _visitNode(node.expression, other.expression);
300 }
301
302 @override
303 visitExpressionStatement(ExpressionStatement node) {
304 ExpressionStatement other = this.other;
305 _visitNode(node.expression, other.expression);
306 }
307
308 @override
309 visitExtendsClause(ExtendsClause node) {
310 ExtendsClause other = this.other;
311 _visitNode(node.superclass, other.superclass);
312 }
313
314 @override
315 visitFieldDeclaration(FieldDeclaration node) {
316 FieldDeclaration other = this.other;
317 _visitDeclaration(node, other);
318 _visitNode(node.fields, other.fields);
319 }
320
321 @override
322 visitFieldFormalParameter(FieldFormalParameter node) {
323 FieldFormalParameter other = this.other;
324 _visitNormalFormalParameter(node, other);
325 _visitNode(node.type, other.type);
326 _visitNode(node.parameters, other.parameters);
327 }
328
329 @override
330 visitForEachStatement(ForEachStatement node) {
331 ForEachStatement other = this.other;
332 _visitNode(node.identifier, other.identifier);
333 _visitNode(node.loopVariable, other.loopVariable);
334 _visitNode(node.iterable, other.iterable);
335 }
336
337 @override
338 visitFormalParameterList(FormalParameterList node) {
339 FormalParameterList other = this.other;
340 _visitList(node.parameters, other.parameters);
341 }
342
343 @override
344 visitForStatement(ForStatement node) {
345 ForStatement other = this.other;
346 _visitNode(node.variables, other.variables);
347 _visitNode(node.initialization, other.initialization);
348 _visitNode(node.condition, other.condition);
349 _visitList(node.updaters, other.updaters);
350 _visitNode(node.body, other.body);
351 }
352
353 @override
354 visitFunctionDeclaration(FunctionDeclaration node) {
355 FunctionDeclaration other = this.other;
356 _visitDeclaration(node, other);
357 _visitNode(node.returnType, other.returnType);
358 _visitNode(node.name, other.name);
359 _visitNode(node.functionExpression, other.functionExpression);
360 }
361
362 @override
363 visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
364 FunctionDeclarationStatement other = this.other;
365 _visitNode(node.functionDeclaration, other.functionDeclaration);
366 }
367
368 @override
369 visitFunctionExpression(FunctionExpression node) {
370 FunctionExpression other = this.other;
371 _visitExpression(node, other);
372 _verifyElement(node.element, other.element);
373 _visitNode(node.parameters, other.parameters);
374 _visitNode(node.body, other.body);
375 }
376
377 @override
378 visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
379 FunctionExpressionInvocation other = this.other;
380 _visitExpression(node, other);
381 _verifyElement(node.staticElement, other.staticElement);
382 _verifyElement(node.propagatedElement, other.propagatedElement);
383 _visitNode(node.function, other.function);
384 _visitNode(node.argumentList, other.argumentList);
385 }
386
387 @override
388 visitFunctionTypeAlias(FunctionTypeAlias node) {
389 FunctionTypeAlias other = this.other;
390 _visitDeclaration(node, other);
391 _visitNode(node.returnType, other.returnType);
392 _visitNode(node.name, other.name);
393 _visitNode(node.typeParameters, other.typeParameters);
394 _visitNode(node.parameters, other.parameters);
395 }
396
397 @override
398 visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
399 FunctionTypedFormalParameter other = this.other;
400 _visitNormalFormalParameter(node, other);
401 _visitNode(node.returnType, other.returnType);
402 _visitNode(node.parameters, other.parameters);
403 }
404
405 @override
406 visitHideCombinator(HideCombinator node) {
407 HideCombinator other = this.other;
408 _visitList(node.hiddenNames, other.hiddenNames);
409 }
410
411 @override
412 visitIfStatement(IfStatement node) {
413 IfStatement other = this.other;
414 _visitNode(node.condition, other.condition);
415 _visitNode(node.thenStatement, other.thenStatement);
416 _visitNode(node.elseStatement, other.elseStatement);
417 }
418
419 @override
420 visitImplementsClause(ImplementsClause node) {
421 ImplementsClause other = this.other;
422 _visitList(node.interfaces, other.interfaces);
423 }
424
425 @override
426 visitImportDirective(ImportDirective node) {
427 ImportDirective other = this.other;
428 _visitDirective(node, other);
429 _visitNode(node.prefix, other.prefix);
430 _verifyElement(node.uriElement, other.uriElement);
431 }
432
433 @override
434 visitIndexExpression(IndexExpression node) {
435 IndexExpression other = this.other;
436 _visitExpression(node, other);
437 _verifyElement(node.staticElement, other.staticElement);
438 _verifyElement(node.propagatedElement, other.propagatedElement);
439 _visitNode(node.target, other.target);
440 _visitNode(node.index, other.index);
441 }
442
443 @override
444 visitInstanceCreationExpression(InstanceCreationExpression node) {
445 InstanceCreationExpression other = this.other;
446 _visitExpression(node, other);
447 _verifyElement(node.staticElement, other.staticElement);
448 _visitNode(node.constructorName, other.constructorName);
449 _visitNode(node.argumentList, other.argumentList);
450 }
451
452 @override
453 visitIntegerLiteral(IntegerLiteral node) {
454 IntegerLiteral other = this.other;
455 _visitExpression(node, other);
456 }
457
458 @override
459 visitInterpolationExpression(InterpolationExpression node) {
460 InterpolationExpression other = this.other;
461 _visitNode(node.expression, other.expression);
462 }
463
464 @override
465 visitInterpolationString(InterpolationString node) {}
466
467 @override
468 visitIsExpression(IsExpression node) {
469 IsExpression other = this.other;
470 _visitExpression(node, other);
471 _visitNode(node.expression, other.expression);
472 _visitNode(node.type, other.type);
473 }
474
475 @override
476 visitLabel(Label node) {
477 Label other = this.other;
478 _visitNode(node.label, other.label);
479 }
480
481 @override
482 visitLabeledStatement(LabeledStatement node) {
483 LabeledStatement other = this.other;
484 _visitList(node.labels, other.labels);
485 _visitNode(node.statement, other.statement);
486 }
487
488 @override
489 visitLibraryDirective(LibraryDirective node) {
490 LibraryDirective other = this.other;
491 _visitDirective(node, other);
492 _visitNode(node.name, other.name);
493 }
494
495 @override
496 visitLibraryIdentifier(LibraryIdentifier node) {
497 LibraryIdentifier other = this.other;
498 _visitList(node.components, other.components);
499 }
500
501 @override
502 visitListLiteral(ListLiteral node) {
503 ListLiteral other = this.other;
504 _visitExpression(node, other);
505 _visitList(node.elements, other.elements);
506 }
507
508 @override
509 visitMapLiteral(MapLiteral node) {
510 MapLiteral other = this.other;
511 _visitExpression(node, other);
512 _visitList(node.entries, other.entries);
513 }
514
515 @override
516 visitMapLiteralEntry(MapLiteralEntry node) {
517 MapLiteralEntry other = this.other;
518 _visitNode(node.key, other.key);
519 _visitNode(node.value, other.value);
520 }
521
522 @override
523 visitMethodDeclaration(MethodDeclaration node) {
524 MethodDeclaration other = this.other;
525 _visitDeclaration(node, other);
526 _visitNode(node.name, other.name);
527 _visitNode(node.parameters, other.parameters);
528 _visitNode(node.body, other.body);
529 }
530
531 @override
532 visitMethodInvocation(MethodInvocation node) {
533 MethodInvocation other = this.other;
534 _visitNode(node.target, other.target);
535 _visitNode(node.methodName, other.methodName);
536 _visitNode(node.argumentList, other.argumentList);
537 }
538
539 @override
540 visitNamedExpression(NamedExpression node) {
541 NamedExpression other = this.other;
542 _visitNode(node.name, other.name);
543 _visitNode(node.expression, other.expression);
544 }
545
546 @override
547 visitNativeClause(NativeClause node) {}
548
549 @override
550 visitNativeFunctionBody(NativeFunctionBody node) {}
551
552 @override
553 visitNullLiteral(NullLiteral node) {
554 NullLiteral other = this.other;
555 _visitExpression(node, other);
556 }
557
558 @override
559 visitParenthesizedExpression(ParenthesizedExpression node) {
560 ParenthesizedExpression other = this.other;
561 _visitNode(node.expression, other.expression);
562 }
563
564 @override
565 visitPartDirective(PartDirective node) {
566 PartDirective other = this.other;
567 _visitDirective(node, other);
568 }
569
570 @override
571 visitPartOfDirective(PartOfDirective node) {
572 PartOfDirective other = this.other;
573 _visitDirective(node, other);
574 _visitNode(node.libraryName, other.libraryName);
575 }
576
577 @override
578 visitPostfixExpression(PostfixExpression node) {
579 PostfixExpression other = this.other;
580 _visitExpression(node, other);
581 _verifyElement(node.staticElement, other.staticElement);
582 _verifyElement(node.propagatedElement, other.propagatedElement);
583 _visitNode(node.operand, other.operand);
584 }
585
586 @override
587 visitPrefixedIdentifier(PrefixedIdentifier node) {
588 PrefixedIdentifier other = this.other;
589 _visitExpression(node, other);
590 _visitNode(node.prefix, other.prefix);
591 _visitNode(node.identifier, other.identifier);
592 }
593
594 @override
595 visitPrefixExpression(PrefixExpression node) {
596 PrefixExpression other = this.other;
597 _visitExpression(node, other);
598 _verifyElement(node.staticElement, other.staticElement);
599 _verifyElement(node.propagatedElement, other.propagatedElement);
600 _visitNode(node.operand, other.operand);
601 }
602
603 @override
604 visitPropertyAccess(PropertyAccess node) {
605 PropertyAccess other = this.other;
606 _visitExpression(node, other);
607 _visitNode(node.target, other.target);
608 _visitNode(node.propertyName, other.propertyName);
609 }
610
611 @override
612 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
613 RedirectingConstructorInvocation other = this.other;
614 _verifyElement(node.staticElement, other.staticElement);
615 _visitNode(node.constructorName, other.constructorName);
616 _visitNode(node.argumentList, other.argumentList);
617 }
618
619 @override
620 visitRethrowExpression(RethrowExpression node) {
621 RethrowExpression other = this.other;
622 _visitExpression(node, other);
623 }
624
625 @override
626 visitReturnStatement(ReturnStatement node) {
627 ReturnStatement other = this.other;
628 _visitNode(node.expression, other.expression);
629 }
630
631 @override
632 visitScriptTag(ScriptTag node) {}
633
634 @override
635 visitShowCombinator(ShowCombinator node) {
636 ShowCombinator other = this.other;
637 _visitList(node.shownNames, other.shownNames);
638 }
639
640 @override
641 visitSimpleFormalParameter(SimpleFormalParameter node) {
642 SimpleFormalParameter other = this.other;
643 _visitNormalFormalParameter(node, other);
644 _visitNode(node.type, other.type);
645 }
646
647 @override
648 visitSimpleIdentifier(SimpleIdentifier node) {
649 SimpleIdentifier other = this.other;
650 _verifyElement(node.staticElement, other.staticElement);
651 _verifyElement(node.propagatedElement, other.propagatedElement);
652 _visitExpression(node, other);
653 }
654
655 @override
656 visitSimpleStringLiteral(SimpleStringLiteral node) {}
657
658 @override
659 visitStringInterpolation(StringInterpolation node) {
660 StringInterpolation other = this.other;
661 _visitList(node.elements, other.elements);
662 }
663
664 @override
665 visitSuperConstructorInvocation(SuperConstructorInvocation node) {
666 SuperConstructorInvocation other = this.other;
667 _verifyElement(node.staticElement, other.staticElement);
668 _visitNode(node.constructorName, other.constructorName);
669 _visitNode(node.argumentList, other.argumentList);
670 }
671
672 @override
673 visitSuperExpression(SuperExpression node) {
674 SuperExpression other = this.other;
675 _visitExpression(node, other);
676 }
677
678 @override
679 visitSwitchCase(SwitchCase node) {
680 SwitchCase other = this.other;
681 _visitList(node.labels, other.labels);
682 _visitNode(node.expression, other.expression);
683 _visitList(node.statements, other.statements);
684 }
685
686 @override
687 visitSwitchDefault(SwitchDefault node) {
688 SwitchDefault other = this.other;
689 _visitList(node.statements, other.statements);
690 }
691
692 @override
693 visitSwitchStatement(SwitchStatement node) {
694 SwitchStatement other = this.other;
695 _visitNode(node.expression, other.expression);
696 _visitList(node.members, other.members);
697 }
698
699 @override
700 visitSymbolLiteral(SymbolLiteral node) {}
701
702 @override
703 visitThisExpression(ThisExpression node) {
704 ThisExpression other = this.other;
705 _visitExpression(node, other);
706 }
707
708 @override
709 visitThrowExpression(ThrowExpression node) {
710 ThrowExpression other = this.other;
711 _visitNode(node.expression, other.expression);
712 }
713
714 @override
715 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
716 TopLevelVariableDeclaration other = this.other;
717 _visitNode(node.variables, other.variables);
718 }
719
720 @override
721 visitTryStatement(TryStatement node) {
722 TryStatement other = this.other;
723 _visitNode(node.body, other.body);
724 _visitList(node.catchClauses, other.catchClauses);
725 _visitNode(node.finallyBlock, other.finallyBlock);
726 }
727
728 @override
729 visitTypeArgumentList(TypeArgumentList node) {
730 TypeArgumentList other = this.other;
731 _visitList(node.arguments, other.arguments);
732 }
733
734 @override
735 visitTypeName(TypeName node) {
736 TypeName other = this.other;
737 _verifyType(node.type, other.type);
738 _visitNode(node.name, node.name);
739 _visitNode(node.typeArguments, other.typeArguments);
740 }
741
742 @override
743 visitTypeParameter(TypeParameter node) {
744 TypeParameter other = this.other;
745 _visitNode(node.name, other.name);
746 _visitNode(node.bound, other.bound);
747 }
748
749 @override
750 visitTypeParameterList(TypeParameterList node) {
751 TypeParameterList other = this.other;
752 _visitList(node.typeParameters, other.typeParameters);
753 }
754
755 @override
756 visitVariableDeclaration(VariableDeclaration node) {
757 VariableDeclaration other = this.other;
758 _visitDeclaration(node, other);
759 _visitNode(node.name, other.name);
760 _visitNode(node.initializer, other.initializer);
761 }
762
763 @override
764 visitVariableDeclarationList(VariableDeclarationList node) {
765 VariableDeclarationList other = this.other;
766 _visitNode(node.type, other.type);
767 _visitList(node.variables, other.variables);
768 }
769
770 @override
771 visitVariableDeclarationStatement(VariableDeclarationStatement node) {
772 VariableDeclarationStatement other = this.other;
773 _visitNode(node.variables, other.variables);
774 }
775
776 @override
777 visitWhileStatement(WhileStatement node) {
778 WhileStatement other = this.other;
779 _visitNode(node.condition, other.condition);
780 _visitNode(node.body, other.body);
781 }
782
783 @override
784 visitWithClause(WithClause node) {
785 WithClause other = this.other;
786 _visitList(node.mixinTypes, other.mixinTypes);
787 }
788
789 @override
790 visitYieldStatement(YieldStatement node) {
791 YieldStatement other = this.other;
792 _visitNode(node.expression, other.expression);
793 }
794
795 void _assertNode(AstNode a, AstNode b) {
796 _expectEquals(a.offset, b.offset);
797 _expectEquals(a.length, b.length);
798 }
799
800 void _expectEquals(actual, expected) {
801 if (actual != expected) {
802 String message = '';
803 message += 'Expected: $expected\n';
804 message += ' Actual: $actual\n';
805 _fail(message);
806 }
807 }
808
809 void _expectIsNull(obj) {
810 if (obj != null) {
811 String message = '';
812 message += 'Expected: null\n';
813 message += ' Actual: $obj\n';
814 _fail(message);
815 }
816 }
817
818 void _expectLength(List actualList, int expected) {
819 String message = '';
820 message += 'Expected length: $expected\n';
821 if (actualList == null) {
822 message += 'but null found.';
823 _fail(message);
824 }
825 int actual = actualList.length;
826 if (actual != expected) {
827 message += 'but $actual found\n';
828 message += 'in $actualList';
829 _fail(message);
830 }
831 } 115 }
832 116
833 void _fail(String message) { 117 void _fail(String message) {
834 throw new IncrementalResolutionMismatch(message); 118 throw new IncrementalResolutionMismatch(message);
835 } 119 }
836 120
837 void _verifyElement(Element a, Element b) { 121 void _verifyElement(Element a, Element b, String desc) {
838 if (a is Member && b is Member) { 122 if (a is Member && b is Member) {
839 a = (a as Member).baseElement; 123 a = (a as Member).baseElement;
840 b = (b as Member).baseElement; 124 b = (b as Member).baseElement;
841 } 125 }
842 String locationA = _getElementLocationWithoutUri(a); 126 String locationA = _getElementLocationWithoutUri(a);
843 String locationB = _getElementLocationWithoutUri(b); 127 String locationB = _getElementLocationWithoutUri(b);
844 if (locationA != locationB) { 128 if (locationA != locationB) {
845 int offset = other.offset; 129 _fail('$desc\nExpected: $b ($locationB)\n Actual: $a ($locationA)');
846 _fail('[$offset]\nExpected: $b ($locationB)\n Actual: $a ($locationA)');
847 } 130 }
848 if (a == null && b == null) { 131 if (a == null && b == null) {
849 return; 132 return;
850 } 133 }
851 _verifyEqual('nameOffset', a.nameOffset, b.nameOffset); 134 _verifyEqual('nameOffset', a.nameOffset, b.nameOffset);
852 if (a is ElementImpl && b is ElementImpl) { 135 if (a is ElementImpl && b is ElementImpl) {
853 _verifyEqual('codeOffset', a.codeOffset, b.codeOffset); 136 _verifyEqual('codeOffset', a.codeOffset, b.codeOffset);
854 _verifyEqual('codeLength', a.codeLength, b.codeLength); 137 _verifyEqual('codeLength', a.codeLength, b.codeLength);
855 } 138 }
856 if (a is LocalElement && b is LocalElement) { 139 if (a is LocalElement && b is LocalElement) {
857 _verifyEqual('visibleRange', a.visibleRange, b.visibleRange); 140 _verifyEqual('visibleRange', a.visibleRange, b.visibleRange);
858 } 141 }
859 _verifyEqual( 142 _verifyEqual(
860 'documentationComment', a.documentationComment, b.documentationComment); 143 'documentationComment', a.documentationComment, b.documentationComment);
861 } 144 }
862 145
863 void _verifyEqual(String name, actual, expected) { 146 void _verifyEqual(String name, actual, expected) {
864 if (actual != expected) { 147 if (actual != expected) {
865 _fail('$name\nExpected: $expected\n Actual: $actual'); 148 _fail('$name\nExpected: $expected\n Actual: $actual');
866 } 149 }
867 } 150 }
868 151
869 void _verifyType(DartType a, DartType b) { 152 void _verifyType(DartType a, DartType b, String desc) {
870 if (!validateTypes) { 153 if (!validateTypes) {
871 return; 154 return;
872 } 155 }
873 if (a != b) { 156 if (a != b) {
874 int offset = other.offset; 157 _fail('$desc\nExpected: $b\n Actual: $a');
875 _fail('[$offset]\nExpected: $b\n Actual: $a');
876 } 158 }
877 } 159 }
878 160
879 void _visitAnnotatedNode(AnnotatedNode node, AnnotatedNode other) {
880 _visitNode(node.documentationComment, other.documentationComment);
881 _visitList(node.metadata, other.metadata);
882 }
883
884 _visitDeclaration(Declaration node, Declaration other) {
885 _verifyElement(node.element, other.element);
886 _visitAnnotatedNode(node, other);
887 }
888
889 _visitDirective(Directive node, Directive other) {
890 _verifyElement(node.element, other.element);
891 _visitAnnotatedNode(node, other);
892 }
893
894 void _visitExpression(Expression a, Expression b) {
895 // print('[${a.offset}] |$a| vs. [${b.offset}] |$b|');
896 _verifyType(a.staticType, b.staticType);
897 _verifyType(a.propagatedType, b.propagatedType);
898 _verifyElement(a.staticParameterElement, b.staticParameterElement);
899 _verifyElement(a.propagatedParameterElement, b.propagatedParameterElement);
900 _assertNode(a, b);
901 }
902
903 void _visitList(NodeList nodeList, NodeList expected) {
904 int length = nodeList.length;
905 _expectLength(nodeList, expected.length);
906 for (int i = 0; i < length; i++) {
907 _visitNode(nodeList[i], expected[i]);
908 }
909 }
910
911 void _visitNode(AstNode node, AstNode other) {
912 if (node == null) {
913 _expectIsNull(other);
914 } else {
915 this.other = other;
916 _assertNode(node, other);
917 node.accept(this);
918 }
919 }
920
921 void _visitNormalFormalParameter(
922 NormalFormalParameter node, NormalFormalParameter other) {
923 _verifyElement(node.element, other.element);
924 _visitNode(node.documentationComment, other.documentationComment);
925 _visitList(node.metadata, other.metadata);
926 _visitNode(node.identifier, other.identifier);
927 }
928
929 /** 161 /**
930 * Returns an URI scheme independent version of the [element] location. 162 * Returns an URI scheme independent version of the [element] location.
931 */ 163 */
932 static String _getElementLocationWithoutUri(Element element) { 164 static String _getElementLocationWithoutUri(Element element) {
933 if (element == null) { 165 if (element == null) {
934 return '<null>'; 166 return '<null>';
935 } 167 }
936 if (element is UriReferencedElementImpl) { 168 if (element is UriReferencedElementImpl) {
937 return '<ignored>'; 169 return '<ignored>';
938 } 170 }
(...skipping 26 matching lines...) Expand all
965 * package:project/my_lib.dart -> my_lib.dart 197 * package:project/my_lib.dart -> my_lib.dart
966 */ 198 */
967 static String _getShortElementLocationUri(String uri) { 199 static String _getShortElementLocationUri(String uri) {
968 int index = uri.lastIndexOf('/'); 200 int index = uri.lastIndexOf('/');
969 if (index == -1) { 201 if (index == -1) {
970 return uri; 202 return uri;
971 } 203 }
972 return uri.substring(index + 1); 204 return uri.substring(index + 1);
973 } 205 }
974 } 206 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698