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

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

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

Powered by Google App Engine
This is Rietveld 408576698