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

Unified Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 744553002: Infrastructure for testing IncrementalResolver. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/incremental_resolver_test.dart
diff --git a/pkg/analyzer/test/generated/incremental_resolver_test.dart b/pkg/analyzer/test/generated/incremental_resolver_test.dart
index 7c7cf2b0931ac67b078f950ae8b598ce48f77cf9..a7b742fc745c7496a7d32dafcc2d9599c3f5dbcd 100644
--- a/pkg/analyzer/test/generated/incremental_resolver_test.dart
+++ b/pkg/analyzer/test/generated/incremental_resolver_test.dart
@@ -7,9 +7,12 @@ library engine.incremental_resolver_test;
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/incremental_resolver.dart';
import 'package:analyzer/src/generated/java_engine.dart';
+import 'package:analyzer/src/generated/parser.dart';
import 'package:analyzer/src/generated/resolver.dart';
+import 'package:analyzer/src/generated/scanner.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/testing/element_factory.dart';
@@ -243,40 +246,127 @@ Map<int, String> A;
}
}
+
class IncrementalResolverTest extends ResolverTestCase {
- void test_resolve() {
- MethodDeclaration method = _resolveMethod(r'''
-class C {
- int m(int a) {
- return a + a;
+ Source source;
+ String code;
+ LibraryElement library;
+ CompilationUnit unit;
+
+ void fail_test_functionBody_addLocalVariable() {
+ // TODO(scheglov) this test fails, because we don't create element models
+ // for new local variables
+ _resolveUnit(r'''
+main(int a, int b) {
+ return a + b;
+}
+''');
+ _resolve(_editString(' return a + b;', r'''
+ int res = a + b;
+ return res;
+'''), _isBlock);
}
+
+ void test_functionBody_body() {
+ _resolveUnit(r'''
+main(int a, int b) {
+ return a + b;
}''');
- BlockFunctionBody body = method.body as BlockFunctionBody;
- ReturnStatement statement = body.block.statements[0] as ReturnStatement;
- BinaryExpression expression = statement.expression as BinaryExpression;
- SimpleIdentifier left = expression.leftOperand as SimpleIdentifier;
- Element leftElement = left.staticElement;
- SimpleIdentifier right = expression.rightOperand as SimpleIdentifier;
- Element rightElement = right.staticElement;
- expect(leftElement, isNotNull);
- expect(rightElement, same(leftElement));
- }
-
- MethodDeclaration _resolveMethod(String content) {
- Source source = addSource(content);
- LibraryElement library = resolve(source);
- CompilationUnit unit = resolveCompilationUnit(source, library);
- ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration;
- MethodDeclaration method = classNode.members[0] as MethodDeclaration;
- method.body.accept(new ResolutionEraser());
+ _resolve(_editString('+', '*'), _isFunctionBody);
+ }
+
+ void test_functionBody_statement() {
+ _resolveUnit(r'''
+main(int a, int b) {
+ return a + b;
+}''');
+ _resolve(_editString('+', '*'), _isStatement);
+ }
+
+ _Edit _editString(String search, String replacement, [int length]) {
+ int offset = code.indexOf(search);
+ expect(offset, isNot(-1));
+ if (length == null) {
+ length = search.length;
+ }
+ return new _Edit(offset, length, replacement);
+ }
+
+// _Edit _editMethodBody(String className, String methodName,
+// String replacement) {
+// ClassDeclaration clazz = _findClass(unit, className);
+// MethodDeclaration method = clazz.getMethod(methodName);
+// FunctionBody body = method.body;
+// return new _Edit(body.offset, body.length, replacement);
+// }
+
+ /**
+ * Applies [edit] to [code], find the [AstNode] specified by [predicate]
+ * and incrementally resolves it.
+ *
+ * Then resolves the new code from scratch and validates that results of
+ * the incremental resolution and non-incremental resolutions are the same.
+ */
+ void _resolve(_Edit edit, Predicate<AstNode> predicate) {
+ int offset = edit.offset;
+ // parse "newCode"
+ String newCode =
+ code.substring(0, offset) +
+ edit.replacement +
+ code.substring(offset + edit.length);
+ CompilationUnit newUnit = _parseUnit(newCode);
+ // replace the node
+ AstNode oldNode = _findNodeAt(unit, offset, predicate);
Brian Wilkerson 2014/11/20 15:38:39 This concerns me because it doesn't necessarily ma
scheglov 2014/11/20 16:13:17 We need to discuss this offline.
+ AstNode newNode = _findNodeAt(newUnit, offset, predicate);
+ bool success = NodeReplacer.replace(oldNode, newNode);
+ expect(success, isTrue);
+ // do incremental resolution
GatheringErrorListener errorListener = new GatheringErrorListener();
+ // TODO(scheglov) use 'replacement' to update elements offsets
IncrementalResolver resolver =
new IncrementalResolver(library, source, typeProvider, errorListener);
- resolver.resolve(method.body);
- return method;
+ resolver.resolve(newNode);
+ // resolve "newCode" from scratch
+ CompilationUnit fullNewUnit;
+ {
+ source = addSource(newCode);
+ LibraryElement library = resolve(source);
+ fullNewUnit = resolveCompilationUnit(source, library);
+ }
+ _SameResolutionValidator.assertSameResolution(unit, fullNewUnit);
+ }
+
+ void _resolveUnit(String code) {
+ this.code = code;
+ source = addSource(code);
+ library = resolve(source);
+ unit = resolveCompilationUnit(source, library);
+ }
+
+ static AstNode _findNodeAt(CompilationUnit oldUnit, int offset,
+ Predicate<AstNode> predicate) {
+ NodeLocator locator = new NodeLocator.con1(offset);
+ AstNode node = locator.searchWithin(oldUnit);
+ return node.getAncestor(predicate);
+ }
+
+ static bool _isBlock(AstNode node) => node is Block;
+
+ static bool _isFunctionBody(AstNode node) => node is FunctionBody;
+
+ static bool _isStatement(AstNode node) => node is Statement;
+
+ static CompilationUnit _parseUnit(String code) {
+ var errorListener = new BooleanErrorListener();
+ var reader = new CharSequenceReader(code);
+ var scanner = new Scanner(null, reader, errorListener);
+ var token = scanner.tokenize();
+ var parser = new Parser(null, errorListener);
+ return parser.parseCompilationUnit(token);
}
}
+
class ScopeBuilderTest extends EngineTestCase {
void test_scopeFor_ClassDeclaration() {
GatheringErrorListener listener = new GatheringErrorListener();
@@ -534,3 +624,825 @@ class ScopeBuilderTest extends EngineTestCase {
return methodNode;
}
}
+
+
+class _Edit {
+ final int offset;
+ final int length;
+ final String replacement;
+ _Edit(this.offset, this.length, this.replacement);
+}
+
+class _SameResolutionValidator implements AstVisitor {
+ AstNode other;
+
+ _SameResolutionValidator(this.other);
+
+ @override
+ visitAdjacentStrings(AdjacentStrings node) {
+ }
+
+ @override
+ visitAnnotation(Annotation node) {
+ Annotation other = this.other;
+ _vN(node.name, other.name);
+ _vN(node.constructorName, other.constructorName);
+ _vN(node.arguments, other.arguments);
+ _vE(node.element, other.element);
+ }
+
+ @override
+ visitArgumentList(ArgumentList node) {
+ ArgumentList other = this.other;
+ _vL(node.arguments, other.arguments);
+ }
+
+ @override
+ visitAsExpression(AsExpression node) {
+ AsExpression other = this.other;
+ _vEP(node, other);
+ _vN(node.expression, other.expression);
+ _vN(node.type, other.type);
+ }
+
+ @override
+ visitAssertStatement(AssertStatement node) {
+ AssertStatement other = this.other;
+ _vN(node.condition, other.condition);
+ }
+
+ @override
+ visitAssignmentExpression(AssignmentExpression node) {
+ AssignmentExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vN(node.leftHandSide, other.leftHandSide);
+ _vN(node.rightHandSide, other.rightHandSide);
+ }
+
+ @override
+ visitAwaitExpression(AwaitExpression node) {
+ AwaitExpression other = this.other;
+ _vEP(node, other);
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitBinaryExpression(BinaryExpression node) {
+ BinaryExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vN(node.leftOperand, other.leftOperand);
+ _vN(node.rightOperand, other.rightOperand);
+ }
+
+ @override
+ visitBlock(Block node) {
+ Block other = this.other;
+ _vL(node.statements, other.statements);
+ }
+
+ @override
+ visitBlockFunctionBody(BlockFunctionBody node) {
+ BlockFunctionBody other = this.other;
+ _vN(node.block, other.block);
+ }
+
+ @override
+ visitBooleanLiteral(BooleanLiteral node) {
+ BooleanLiteral other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitBreakStatement(BreakStatement node) {
+ BreakStatement other = this.other;
+ _vN(node.label, other.label);
+ }
+
+ @override
+ visitCascadeExpression(CascadeExpression node) {
+ CascadeExpression other = this.other;
+ _vEP(node, other);
+ _vN(node.target, other.target);
+ _vL(node.cascadeSections, other.cascadeSections);
+ }
+
+ @override
+ visitCatchClause(CatchClause node) {
+ CatchClause other = this.other;
+ _vN(node.exceptionType, other.exceptionType);
+ _vN(node.exceptionParameter, other.exceptionParameter);
+ _vN(node.stackTraceParameter, other.stackTraceParameter);
+ _vN(node.body, other.body);
+ }
+
+ @override
+ visitClassDeclaration(ClassDeclaration node) {
+ ClassDeclaration other = this.other;
+ _vN(node.name, other.name);
+ _vN(node.typeParameters, other.typeParameters);
+ _vN(node.extendsClause, other.extendsClause);
+ _vN(node.implementsClause, other.implementsClause);
+ _vN(node.withClause, other.withClause);
+ _vL(node.members, other.members);
+ }
+
+ @override
+ visitClassTypeAlias(ClassTypeAlias node) {
+ ClassTypeAlias other = this.other;
+ _vE(node.element, other.element);
+ _vN(node.name, other.name);
+ _vN(node.typeParameters, other.typeParameters);
+ _vN(node.superclass, other.superclass);
+ _vN(node.withClause, other.withClause);
+ }
+
+ @override
+ visitComment(Comment node) {
+ Comment other = this.other;
+ _vL(node.references, other.references);
+ }
+
+ @override
+ visitCommentReference(CommentReference node) {
+ CommentReference other = this.other;
+ _vN(node.identifier, other.identifier);
+ }
+
+ @override
+ visitCompilationUnit(CompilationUnit node) {
+ CompilationUnit other = this.other;
+ _vE(node.element, other.element);
+ _vL(node.directives, other.directives);
+ _vL(node.declarations, other.declarations);
+ }
+
+ @override
+ visitConditionalExpression(ConditionalExpression node) {
+ ConditionalExpression other = this.other;
+ _vEP(node, other);
+ _vN(node.condition, other.condition);
+ _vN(node.thenExpression, other.thenExpression);
+ _vN(node.elseExpression, other.elseExpression);
+ }
+
+ @override
+ visitConstructorDeclaration(ConstructorDeclaration node) {
+ ConstructorDeclaration other = this.other;
+ _vE(node.element, other.element);
+ _vN(node.returnType, other.returnType);
+ _vN(node.name, other.name);
+ _vN(node.parameters, other.parameters);
+ _vN(node.redirectedConstructor, other.redirectedConstructor);
+ _vL(node.initializers, other.initializers);
+ }
+
+ @override
+ visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
+ ConstructorFieldInitializer other = this.other;
+ _vN(node.fieldName, other.fieldName);
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitConstructorName(ConstructorName node) {
+ ConstructorName other = this.other;
+ _vE(node.staticElement, other.staticElement);
+ _vN(node.type, other.type);
+ _vN(node.name, other.name);
+ }
+
+ @override
+ visitContinueStatement(ContinueStatement node) {
+ ContinueStatement other = this.other;
+ _vN(node.label, other.label);
+ }
+
+ @override
+ visitDeclaredIdentifier(DeclaredIdentifier node) {
+ DeclaredIdentifier other = this.other;
+ _vN(node.type, other.type);
+ _vN(node.identifier, other.identifier);
+ }
+
+ @override
+ visitDefaultFormalParameter(DefaultFormalParameter node) {
+ DefaultFormalParameter other = this.other;
+ _vN(node.parameter, other.parameter);
+ _vN(node.defaultValue, other.defaultValue);
+ }
+
+ @override
+ visitDoStatement(DoStatement node) {
+ DoStatement other = this.other;
+ _vN(node.condition, other.condition);
+ _vN(node.body, other.body);
+ }
+
+ @override
+ visitDoubleLiteral(DoubleLiteral node) {
+ DoubleLiteral other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitEmptyFunctionBody(EmptyFunctionBody node) {
+ }
+
+ @override
+ visitEmptyStatement(EmptyStatement node) {
+ }
+
+ @override
+ visitEnumConstantDeclaration(EnumConstantDeclaration node) {
+ EnumConstantDeclaration other = this.other;
+ _vDeclaration(node, other);
+ _vN(node.name, other.name);
+ }
+
+ @override
+ visitEnumDeclaration(EnumDeclaration node) {
+ EnumDeclaration other = this.other;
+ _vDeclaration(node, other);
+ _vN(node.name, other.name);
+ _vL(node.constants, other.constants);
+ }
+
+ @override
+ visitExportDirective(ExportDirective node) {
+ ExportDirective other = this.other;
+ _vDirective(node, other);
+ }
+
+ @override
+ visitExpressionFunctionBody(ExpressionFunctionBody node) {
+ ExpressionFunctionBody other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitExpressionStatement(ExpressionStatement node) {
+ ExpressionStatement other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitExtendsClause(ExtendsClause node) {
+ ExtendsClause other = this.other;
+ _vN(node.superclass, other.superclass);
+ }
+
+ @override
+ visitFieldDeclaration(FieldDeclaration node) {
+ FieldDeclaration other = this.other;
+ _vN(node.fields, other.fields);
+ }
+
+ @override
+ visitFieldFormalParameter(FieldFormalParameter node) {
+ FieldFormalParameter other = this.other;
+ _visitNormalFormalParameter(node, other);
+ _vN(node.type, other.type);
+ _vN(node.parameters, other.parameters);
+ }
+
+ @override
+ visitForEachStatement(ForEachStatement node) {
+ ForEachStatement other = this.other;
+ _vN(node.identifier, other.identifier);
+ _vN(node.loopVariable, other.loopVariable);
+ _vN(node.iterable, other.iterable);
+ }
+
+ @override
+ visitFormalParameterList(FormalParameterList node) {
+ FormalParameterList other = this.other;
+ _vL(node.parameters, other.parameters);
+ }
+
+ @override
+ visitForStatement(ForStatement node) {
+ ForStatement other = this.other;
+ _vN(node.variables, other.variables);
+ _vN(node.initialization, other.initialization);
+ _vN(node.condition, other.condition);
+ _vL(node.updaters, other.updaters);
+ _vN(node.body, other.body);
+ }
+
+ @override
+ visitFunctionDeclaration(FunctionDeclaration node) {
+ FunctionDeclaration other = this.other;
+ _vDeclaration(node, other);
+ _vN(node.returnType, other.returnType);
+ _vN(node.name, other.name);
+ _vN(node.functionExpression, other.functionExpression);
+ }
+
+ @override
+ visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
+ FunctionDeclarationStatement other = this.other;
+ _vN(node.functionDeclaration, other.functionDeclaration);
+ }
+
+ @override
+ visitFunctionExpression(FunctionExpression node) {
+ FunctionExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.element, other.element);
+ _vN(node.parameters, other.parameters);
+ _vN(node.body, other.body);
+ }
+
+ @override
+ visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
+ FunctionExpressionInvocation other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vN(node.function, other.function);
+ _vN(node.argumentList, other.argumentList);
+ }
+
+ @override
+ visitFunctionTypeAlias(FunctionTypeAlias node) {
+ FunctionTypeAlias other = this.other;
+ _vDeclaration(node, other);
+ _vN(node.returnType, other.returnType);
+ _vN(node.name, other.name);
+ _vN(node.typeParameters, other.typeParameters);
+ _vN(node.parameters, other.parameters);
+ }
+
+ @override
+ visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
+ FunctionTypedFormalParameter other = this.other;
+ _visitNormalFormalParameter(node, other);
+ _vN(node.returnType, other.returnType);
+ _vN(node.parameters, other.parameters);
+ }
+
+ @override
+ visitHideCombinator(HideCombinator node) {
+ HideCombinator other = this.other;
+ _vL(node.hiddenNames, other.hiddenNames);
+ }
+
+ @override
+ visitIfStatement(IfStatement node) {
+ IfStatement other = this.other;
+ _vN(node.condition, other.condition);
+ _vN(node.thenStatement, other.thenStatement);
+ _vN(node.elseStatement, other.elseStatement);
+ }
+
+ @override
+ visitImplementsClause(ImplementsClause node) {
+ ImplementsClause other = this.other;
+ _vL(node.interfaces, other.interfaces);
+ }
+
+ @override
+ visitImportDirective(ImportDirective node) {
+ ImportDirective other = this.other;
+ _vDirective(node, other);
+ _vN(node.prefix, other.prefix);
+ _vE(node.uriElement, other.uriElement);
+ }
+
+ @override
+ visitIndexExpression(IndexExpression node) {
+ IndexExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vN(node.target, other.target);
+ _vN(node.index, other.index);
+ }
+
+ @override
+ visitInstanceCreationExpression(InstanceCreationExpression node) {
+ InstanceCreationExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vN(node.constructorName, other.constructorName);
+ _vN(node.argumentList, other.argumentList);
+ }
+
+ @override
+ visitIntegerLiteral(IntegerLiteral node) {
+ IntegerLiteral other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitInterpolationExpression(InterpolationExpression node) {
+ InterpolationExpression other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitInterpolationString(InterpolationString node) {
+ }
+
+ @override
+ visitIsExpression(IsExpression node) {
+ IsExpression other = this.other;
+ _vEP(node, other);
+ _vN(node.expression, other.expression);
+ _vN(node.type, other.type);
+ }
+
+ @override
+ visitLabel(Label node) {
+ Label other = this.other;
+ _vN(node.label, other.label);
+ }
+
+ @override
+ visitLabeledStatement(LabeledStatement node) {
+ LabeledStatement other = this.other;
+ _vL(node.labels, other.labels);
+ _vN(node.statement, other.statement);
+ }
+
+ @override
+ visitLibraryDirective(LibraryDirective node) {
+ LibraryDirective other = this.other;
+ _vDirective(node, other);
+ _vN(node.name, other.name);
+ }
+
+ @override
+ visitLibraryIdentifier(LibraryIdentifier node) {
+ LibraryIdentifier other = this.other;
+ _vL(node.components, other.components);
+ }
+
+ @override
+ visitListLiteral(ListLiteral node) {
+ ListLiteral other = this.other;
+ _vEP(node, other);
+ _vL(node.elements, other.elements);
+ }
+
+ @override
+ visitMapLiteral(MapLiteral node) {
+ MapLiteral other = this.other;
+ _vEP(node, other);
+ _vL(node.entries, other.entries);
+ }
+
+ @override
+ visitMapLiteralEntry(MapLiteralEntry node) {
+ MapLiteralEntry other = this.other;
+ _vN(node.key, other.key);
+ _vN(node.value, other.value);
+ }
+
+ @override
+ visitMethodDeclaration(MethodDeclaration node) {
+ MethodDeclaration other = this.other;
+ _vN(node.name, other.name);
+ _vN(node.parameters, other.parameters);
+ _vN(node.body, other.body);
+ }
+
+ @override
+ visitMethodInvocation(MethodInvocation node) {
+ MethodInvocation other = this.other;
+ _vN(node.target, other.target);
+ _vN(node.methodName, other.methodName);
+ _vN(node.argumentList, other.argumentList);
+ }
+
+ @override
+ visitNamedExpression(NamedExpression node) {
+ NamedExpression other = this.other;
+ _vN(node.name, other.name);
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitNativeClause(NativeClause node) {
+ }
+
+ @override
+ visitNativeFunctionBody(NativeFunctionBody node) {
+ }
+
+ @override
+ visitNullLiteral(NullLiteral node) {
+ NullLiteral other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitParenthesizedExpression(ParenthesizedExpression node) {
+ ParenthesizedExpression other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitPartDirective(PartDirective node) {
+ PartDirective other = this.other;
+ _vDirective(node, other);
+ }
+
+ @override
+ visitPartOfDirective(PartOfDirective node) {
+ PartOfDirective other = this.other;
+ _vDirective(node, other);
+ _vN(node.libraryName, other.libraryName);
+ }
+
+ @override
+ visitPostfixExpression(PostfixExpression node) {
+ PostfixExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vN(node.operand, other.operand);
+ }
+
+ @override
+ visitPrefixedIdentifier(PrefixedIdentifier node) {
+ PrefixedIdentifier other = this.other;
+ _vEP(node, other);
+ _vN(node.prefix, other.prefix);
+ _vN(node.identifier, other.identifier);
+ }
+
+ @override
+ visitPrefixExpression(PrefixExpression node) {
+ PrefixExpression other = this.other;
+ _vEP(node, other);
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vN(node.operand, other.operand);
+ }
+
+ @override
+ visitPropertyAccess(PropertyAccess node) {
+ PropertyAccess other = this.other;
+ _vEP(node, other);
+ _vN(node.target, other.target);
+ _vN(node.propertyName, other.propertyName);
+ }
+
+ @override
+ visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
+ RedirectingConstructorInvocation other = this.other;
+ _vE(node.staticElement, other.staticElement);
+ _vN(node.constructorName, other.constructorName);
+ _vN(node.argumentList, other.argumentList);
+ }
+
+ @override
+ visitRethrowExpression(RethrowExpression node) {
+ RethrowExpression other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitReturnStatement(ReturnStatement node) {
+ ReturnStatement other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitScriptTag(ScriptTag node) {
+ }
+
+ @override
+ visitShowCombinator(ShowCombinator node) {
+ ShowCombinator other = this.other;
+ _vL(node.shownNames, other.shownNames);
+ }
+
+ @override
+ visitSimpleFormalParameter(SimpleFormalParameter node) {
+ SimpleFormalParameter other = this.other;
+ _visitNormalFormalParameter(node, other);
+ _vN(node.type, other.type);
+ }
+
+ @override
+ visitSimpleIdentifier(SimpleIdentifier node) {
+ SimpleIdentifier other = this.other;
+ _vE(node.staticElement, other.staticElement);
+ _vE(node.propagatedElement, other.propagatedElement);
+ _vEP(node, other);
+ }
+
+ @override
+ visitSimpleStringLiteral(SimpleStringLiteral node) {
+ }
+
+ @override
+ visitStringInterpolation(StringInterpolation node) {
+ StringInterpolation other = this.other;
+ _vL(node.elements, other.elements);
+ }
+
+ @override
+ visitSuperConstructorInvocation(SuperConstructorInvocation node) {
+ SuperConstructorInvocation other = this.other;
+ _vE(node.staticElement, other.staticElement);
+ _vN(node.constructorName, other.constructorName);
+ _vN(node.argumentList, other.argumentList);
+ }
+
+ @override
+ visitSuperExpression(SuperExpression node) {
+ SuperExpression other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitSwitchCase(SwitchCase node) {
+ SwitchCase other = this.other;
+ _vL(node.labels, other.labels);
+ _vN(node.expression, other.expression);
+ _vL(node.statements, other.statements);
+ }
+
+ @override
+ visitSwitchDefault(SwitchDefault node) {
+ SwitchDefault other = this.other;
+ _vL(node.statements, other.statements);
+ }
+
+ @override
+ visitSwitchStatement(SwitchStatement node) {
+ SwitchStatement other = this.other;
+ _vN(node.expression, other.expression);
+ _vL(node.members, other.members);
+ }
+
+ @override
+ visitSymbolLiteral(SymbolLiteral node) {
+ }
+
+ @override
+ visitThisExpression(ThisExpression node) {
+ ThisExpression other = this.other;
+ _vEP(node, other);
+ }
+
+ @override
+ visitThrowExpression(ThrowExpression node) {
+ ThrowExpression other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ @override
+ visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
+ TopLevelVariableDeclaration other = this.other;
+ _vN(node.variables, other.variables);
+ }
+
+ @override
+ visitTryStatement(TryStatement node) {
+ TryStatement other = this.other;
+ _vN(node.body, other.body);
+ _vL(node.catchClauses, other.catchClauses);
+ _vN(node.finallyBlock, other.finallyBlock);
+ }
+
+ @override
+ visitTypeArgumentList(TypeArgumentList node) {
+ TypeArgumentList other = this.other;
+ _vL(node.arguments, other.arguments);
+ }
+
+ @override
+ visitTypeName(TypeName node) {
+ TypeName other = this.other;
+ _safeT(node.type, other.type);
+ _vN(node.name, node.name);
+ _vN(node.typeArguments, other.typeArguments);
+ }
+
+ @override
+ visitTypeParameter(TypeParameter node) {
+ TypeParameter other = this.other;
+ _vN(node.name, other.name);
+ _vN(node.bound, other.bound);
+ }
+
+ @override
+ visitTypeParameterList(TypeParameterList node) {
+ TypeParameterList other = this.other;
+ _vL(node.typeParameters, other.typeParameters);
+ }
+
+ @override
+ visitVariableDeclaration(VariableDeclaration node) {
+ VariableDeclaration other = this.other;
+ _vN(node.name, other.name);
+ _vN(node.initializer, other.initializer);
+ }
+
+ @override
+ visitVariableDeclarationList(VariableDeclarationList node) {
+ VariableDeclarationList other = this.other;
+ _vN(node.type, other.type);
+ _vL(node.variables, other.variables);
+ }
+
+ @override
+ visitVariableDeclarationStatement(VariableDeclarationStatement node) {
+ VariableDeclarationStatement other = this.other;
+ _vN(node.variables, other.variables);
+ }
+
+ @override
+ visitWhileStatement(WhileStatement node) {
+ WhileStatement other = this.other;
+ _vN(node.condition, other.condition);
+ _vN(node.body, other.body);
+ }
+
+ @override
+ visitWithClause(WithClause node) {
+ WithClause other = this.other;
+ _vL(node.mixinTypes, other.mixinTypes);
+ }
+
+ @override
+ visitYieldStatement(YieldStatement node) {
+ YieldStatement other = this.other;
+ _vN(node.expression, other.expression);
+ }
+
+ void _safeT(DartType a, DartType b) {
Brian Wilkerson 2014/11/20 15:38:39 These single letter abbreviations ("T" for type, "
scheglov 2014/11/20 16:13:17 Thank you. I forgot to rename these. Fixed.
+ expect(a, equals(b));
+ }
+
+ void _vAnnotatedNode(AnnotatedNode node, AnnotatedNode other) {
+ _vN(node.documentationComment, other.documentationComment);
+ _vL(node.metadata, other.metadata);
+ }
+
+ _vDeclaration(Declaration node, Declaration other) {
+ _vE(node.element, other.element);
+ _vAnnotatedNode(node, other);
+ }
+
+ _vDirective(Directive node, Directive other) {
+ _vE(node.element, other.element);
+ _vAnnotatedNode(node, other);
+ }
+
+ void _vE(Element a, Element b) {
+ if (a != b) {
+ fail('Expected: $b\n Actual: $a');
+ }
+ if (a == null && b == null) {
+ return;
+ }
+ // TODO(scheglov) uncomment when implement elements shifting
+// expect(a.nameOffset, b.nameOffset);
+ }
+
+ void _vEP(Expression a, Expression b) {
+ _safeT(a.staticType, b.staticType);
+ _safeT(a.propagatedType, b.propagatedType);
+ _vE(a.staticParameterElement, b.staticParameterElement);
+ _vE(a.propagatedParameterElement, b.propagatedParameterElement);
+ }
+
+ void _visitNormalFormalParameter(NormalFormalParameter node,
+ NormalFormalParameter other) {
+ _vN(node.documentationComment, other.documentationComment);
+ _vL(node.metadata, other.metadata);
+ _vN(node.identifier, other.identifier);
+ }
+
+ void _vL(NodeList nodeList, NodeList otherList) {
+ int length = nodeList.length;
+ expect(otherList, hasLength(length));
+ for (int i = 0; i < length; i++) {
+ _vN(nodeList[i], otherList[i]);
+ }
+ }
+
+ void _vN(AstNode node, AstNode other) {
+ if (node == null) {
+ expect(other, isNull);
+ } else {
+ this.other = other;
+ node.accept(this);
+ }
+ }
+
+ static void assertSameResolution(CompilationUnit actual,
+ CompilationUnit expected) {
+ _SameResolutionValidator validator = new _SameResolutionValidator(expected);
+ actual.accept(validator);
+ }
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698