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

Unified Diff: packages/analyzer/test/src/dart/ast/utilities_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: packages/analyzer/test/src/dart/ast/utilities_test.dart
diff --git a/packages/analyzer/test/generated/ast_test.dart b/packages/analyzer/test/src/dart/ast/utilities_test.dart
similarity index 63%
rename from packages/analyzer/test/generated/ast_test.dart
rename to packages/analyzer/test/src/dart/ast/utilities_test.dart
index e25c2533727cf2793abef1e2b014ad112002db9c..a48fb6e31d99379757daadd4c9ca034d0802eabd 100644
--- a/packages/analyzer/test/generated/ast_test.dart
+++ b/packages/analyzer/test/src/dart/ast/utilities_test.dart
@@ -2,221 +2,34 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library engine.ast_test;
-
-import 'package:analyzer/src/generated/ast.dart';
+library analyzer.test.src.dart.ast.utilities_test;
+
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/token.dart';
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
+import 'package:analyzer/src/dart/ast/utilities.dart';
+import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/java_engine.dart' show Predicate;
import 'package:analyzer/src/generated/java_engine.dart';
-import 'package:analyzer/src/generated/scanner.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
+import 'package:analyzer/src/generated/testing/element_factory.dart';
import 'package:analyzer/src/generated/testing/token_factory.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:unittest/unittest.dart';
-import '../reflective_tests.dart';
-import '../utils.dart';
-import 'parser_test.dart' show ParserTestCase;
-import 'test_support.dart';
+import '../../../generated/parser_test.dart' show ParserTestCase;
+import '../../../generated/test_support.dart';
+import '../../../utils.dart';
main() {
initializeTestEnvironment();
- runReflectiveTests(BreadthFirstVisitorTest);
- runReflectiveTests(ClassDeclarationTest);
- runReflectiveTests(ClassTypeAliasTest);
- runReflectiveTests(ConstantEvaluatorTest);
- runReflectiveTests(ConstructorDeclarationTest);
- runReflectiveTests(FieldFormalParameterTest);
- runReflectiveTests(IndexExpressionTest);
- runReflectiveTests(NodeListTest);
- runReflectiveTests(NodeLocatorTest);
- runReflectiveTests(SimpleIdentifierTest);
- runReflectiveTests(SimpleStringLiteralTest);
- runReflectiveTests(StringInterpolationTest);
- runReflectiveTests(ToSourceVisitorTest);
- runReflectiveTests(VariableDeclarationTest);
-}
-
-class AssignmentKind extends Enum<AssignmentKind> {
- static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
-
- static const AssignmentKind COMPOUND_LEFT =
- const AssignmentKind('COMPOUND_LEFT', 1);
-
- static const AssignmentKind COMPOUND_RIGHT =
- const AssignmentKind('COMPOUND_RIGHT', 2);
-
- static const AssignmentKind POSTFIX_INC =
- const AssignmentKind('POSTFIX_INC', 3);
-
- static const AssignmentKind PREFIX_DEC =
- const AssignmentKind('PREFIX_DEC', 4);
-
- static const AssignmentKind PREFIX_INC =
- const AssignmentKind('PREFIX_INC', 5);
-
- static const AssignmentKind PREFIX_NOT =
- const AssignmentKind('PREFIX_NOT', 6);
-
- static const AssignmentKind SIMPLE_LEFT =
- const AssignmentKind('SIMPLE_LEFT', 7);
-
- static const AssignmentKind SIMPLE_RIGHT =
- const AssignmentKind('SIMPLE_RIGHT', 8);
-
- static const AssignmentKind NONE = const AssignmentKind('NONE', 9);
-
- static const List<AssignmentKind> values = const [
- BINARY,
- COMPOUND_LEFT,
- COMPOUND_RIGHT,
- POSTFIX_INC,
- PREFIX_DEC,
- PREFIX_INC,
- PREFIX_NOT,
- SIMPLE_LEFT,
- SIMPLE_RIGHT,
- NONE
- ];
-
- const AssignmentKind(String name, int ordinal) : super(name, ordinal);
-}
-
-class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt
- extends BreadthFirstVisitor<Object> {
- List<AstNode> nodes;
-
- BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
-
- @override
- Object visitNode(AstNode node) {
- nodes.add(node);
- return super.visitNode(node);
- }
-}
-
-@reflectiveTest
-class BreadthFirstVisitorTest extends ParserTestCase {
- void test_it() {
- String source = r'''
-class A {
- bool get g => true;
-}
-class B {
- int f() {
- num q() {
- return 3;
- }
- return q() + 4;
- }
-}
-A f(var p) {
- if ((p as A).g) {
- return p;
- } else {
- return null;
- }
-}''';
- CompilationUnit unit = ParserTestCase.parseCompilationUnit(source);
- List<AstNode> nodes = new List<AstNode>();
- BreadthFirstVisitor<Object> visitor =
- new BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(nodes);
- visitor.visitAllNodes(unit);
- expect(nodes, hasLength(59));
- EngineTestCase.assertInstanceOf(
- (obj) => obj is CompilationUnit, CompilationUnit, nodes[0]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is ClassDeclaration, ClassDeclaration, nodes[2]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is FunctionDeclaration, FunctionDeclaration, nodes[3]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is FunctionDeclarationStatement,
- FunctionDeclarationStatement,
- nodes[27]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is IntegerLiteral, IntegerLiteral, nodes[58]);
- //3
- }
-}
-
-@reflectiveTest
-class ClassDeclarationTest extends ParserTestCase {
- void test_getConstructor() {
- List<ConstructorInitializer> initializers =
- new List<ConstructorInitializer>();
- ConstructorDeclaration defaultConstructor = AstFactory
- .constructorDeclaration(AstFactory.identifier3("Test"), null,
- AstFactory.formalParameterList(), initializers);
- ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(
- AstFactory.identifier3("Test"),
- "a",
- AstFactory.formalParameterList(),
- initializers);
- ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(
- AstFactory.identifier3("Test"),
- "b",
- AstFactory.formalParameterList(),
- initializers);
- ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null,
- null, null, null, [defaultConstructor, aConstructor, bConstructor]);
- expect(clazz.getConstructor(null), same(defaultConstructor));
- expect(clazz.getConstructor("a"), same(aConstructor));
- expect(clazz.getConstructor("b"), same(bConstructor));
- expect(clazz.getConstructor("noSuchConstructor"), same(null));
- }
-
- void test_getField() {
- VariableDeclaration aVar = AstFactory.variableDeclaration("a");
- VariableDeclaration bVar = AstFactory.variableDeclaration("b");
- VariableDeclaration cVar = AstFactory.variableDeclaration("c");
- ClassDeclaration clazz =
- AstFactory.classDeclaration(null, "Test", null, null, null, null, [
- AstFactory.fieldDeclaration2(false, null, [aVar]),
- AstFactory.fieldDeclaration2(false, null, [bVar, cVar])
- ]);
- expect(clazz.getField("a"), same(aVar));
- expect(clazz.getField("b"), same(bVar));
- expect(clazz.getField("c"), same(cVar));
- expect(clazz.getField("noSuchField"), same(null));
- }
-
- void test_getMethod() {
- MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null,
- null, AstFactory.identifier3("a"), AstFactory.formalParameterList());
- MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null,
- null, AstFactory.identifier3("b"), AstFactory.formalParameterList());
- ClassDeclaration clazz = AstFactory.classDeclaration(
- null, "Test", null, null, null, null, [aMethod, bMethod]);
- expect(clazz.getMethod("a"), same(aMethod));
- expect(clazz.getMethod("b"), same(bMethod));
- expect(clazz.getMethod("noSuchMethod"), same(null));
- }
-
- void test_isAbstract() {
- expect(
- AstFactory
- .classDeclaration(null, "A", null, null, null, null)
- .isAbstract,
- isFalse);
- expect(
- AstFactory
- .classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null)
- .isAbstract,
- isTrue);
- }
-}
-
-@reflectiveTest
-class ClassTypeAliasTest extends ParserTestCase {
- void test_isAbstract() {
- expect(
- AstFactory.classTypeAlias("A", null, null, null, null, null).isAbstract,
- isFalse);
- expect(
- AstFactory
- .classTypeAlias("B", null, Keyword.ABSTRACT, null, null, null)
- .isAbstract,
- isTrue);
- }
+ defineReflectiveTests(ConstantEvaluatorTest);
+ defineReflectiveTests(NodeLocatorTest);
+ defineReflectiveTests(NodeLocator2Test);
+ defineReflectiveTests(ResolutionCopierTest);
+ defineReflectiveTests(ToSourceVisitorTest);
}
@reflectiveTest
@@ -524,423 +337,46 @@ class ConstantEvaluatorTest extends ParserTestCase {
}
@reflectiveTest
-class ConstructorDeclarationTest extends EngineTestCase {
- void test_firstTokenAfterCommentAndMetadata_all_inverted() {
- Token externalKeyword = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
- externalKeyword.offset = 14;
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- Keyword.CONST,
- Keyword.FACTORY,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- declaration.externalKeyword = externalKeyword;
- declaration.constKeyword.offset = 8;
- Token factoryKeyword = declaration.factoryKeyword;
- factoryKeyword.offset = 0;
- expect(declaration.firstTokenAfterCommentAndMetadata, factoryKeyword);
- }
-
- void test_firstTokenAfterCommentAndMetadata_all_normal() {
- Token token = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
- token.offset = 0;
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- Keyword.CONST,
- Keyword.FACTORY,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- declaration.externalKeyword = token;
- declaration.constKeyword.offset = 9;
- declaration.factoryKeyword.offset = 15;
- expect(declaration.firstTokenAfterCommentAndMetadata, token);
- }
-
- void test_firstTokenAfterCommentAndMetadata_constOnly() {
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- Keyword.CONST,
- null,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- expect(declaration.firstTokenAfterCommentAndMetadata,
- declaration.constKeyword);
- }
-
- void test_firstTokenAfterCommentAndMetadata_externalOnly() {
- Token externalKeyword = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- null, null, AstFactory.identifier3('int'), null, null, null, null);
- declaration.externalKeyword = externalKeyword;
- expect(declaration.firstTokenAfterCommentAndMetadata, externalKeyword);
- }
-
- void test_firstTokenAfterCommentAndMetadata_factoryOnly() {
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- null,
- Keyword.FACTORY,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- expect(declaration.firstTokenAfterCommentAndMetadata,
- declaration.factoryKeyword);
- }
-}
-
-@reflectiveTest
-class FieldFormalParameterTest extends EngineTestCase {
- void test_endToken_noParameters() {
- FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('field');
- expect(parameter.endToken, parameter.identifier.endToken);
- }
-
- void test_endToken_parameters() {
- FieldFormalParameter parameter = AstFactory.fieldFormalParameter(
- null, null, 'field', AstFactory.formalParameterList([]));
- expect(parameter.endToken, parameter.parameters.endToken);
- }
-}
-
-@reflectiveTest
-class IndexExpressionTest extends EngineTestCase {
- void test_inGetterContext_assignment_compound_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] += c
- AstFactory.assignmentExpression(
- expression, TokenType.PLUS_EQ, AstFactory.identifier3("c"));
- expect(expression.inGetterContext(), isTrue);
- }
-
- void test_inGetterContext_assignment_simple_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] = c
- AstFactory.assignmentExpression(
- expression, TokenType.EQ, AstFactory.identifier3("c"));
- expect(expression.inGetterContext(), isFalse);
- }
-
- void test_inGetterContext_nonAssignment() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] + c
- AstFactory.binaryExpression(
- expression, TokenType.PLUS, AstFactory.identifier3("c"));
- expect(expression.inGetterContext(), isTrue);
- }
-
- void test_inSetterContext_assignment_compound_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] += c
- AstFactory.assignmentExpression(
- expression, TokenType.PLUS_EQ, AstFactory.identifier3("c"));
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_assignment_compound_right() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // c += a[b]
- AstFactory.assignmentExpression(
- AstFactory.identifier3("c"), TokenType.PLUS_EQ, expression);
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_assignment_simple_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] = c
- AstFactory.assignmentExpression(
- expression, TokenType.EQ, AstFactory.identifier3("c"));
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_assignment_simple_right() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // c = a[b]
- AstFactory.assignmentExpression(
- AstFactory.identifier3("c"), TokenType.EQ, expression);
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_nonAssignment() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- AstFactory.binaryExpression(
- expression, TokenType.PLUS, AstFactory.identifier3("c"));
- // a[b] + cc
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_postfix() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
- // a[b]++
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_prefix_bang() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // !a[b]
- AstFactory.prefixExpression(TokenType.BANG, expression);
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_prefix_minusMinus() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // --a[b]
- AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_prefix_plusPlus() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // ++a[b]
- AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
- expect(expression.inSetterContext(), isTrue);
- }
-}
-
-@reflectiveTest
-class NodeListTest extends EngineTestCase {
- void test_add() {
- AstNode parent = AstFactory.argumentList();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- NodeList<AstNode> list = new NodeList<AstNode>(parent);
- list.insert(0, secondNode);
- list.insert(0, firstNode);
- expect(list, hasLength(2));
- expect(list[0], same(firstNode));
- expect(list[1], same(secondNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- AstNode thirdNode = AstFactory.booleanLiteral(false);
- list.insert(1, thirdNode);
- expect(list, hasLength(3));
- expect(list[0], same(firstNode));
- expect(list[1], same(thirdNode));
- expect(list[2], same(secondNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- expect(thirdNode.parent, same(parent));
- }
-
- void test_add_negative() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.insert(-1, AstFactory.booleanLiteral(true));
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_add_tooBig() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.insert(1, AstFactory.booleanLiteral(true));
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_addAll() {
- AstNode parent = AstFactory.argumentList();
- List<AstNode> firstNodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- firstNodes.add(firstNode);
- firstNodes.add(secondNode);
- NodeList<AstNode> list = new NodeList<AstNode>(parent);
- list.addAll(firstNodes);
- expect(list, hasLength(2));
- expect(list[0], same(firstNode));
- expect(list[1], same(secondNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- List<AstNode> secondNodes = new List<AstNode>();
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- AstNode fourthNode = AstFactory.booleanLiteral(false);
- secondNodes.add(thirdNode);
- secondNodes.add(fourthNode);
- list.addAll(secondNodes);
- expect(list, hasLength(4));
- expect(list[0], same(firstNode));
- expect(list[1], same(secondNode));
- expect(list[2], same(thirdNode));
- expect(list[3], same(fourthNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- expect(thirdNode.parent, same(parent));
- expect(fourthNode.parent, same(parent));
- }
-
- void test_creation() {
- AstNode owner = AstFactory.argumentList();
- NodeList<AstNode> list = new NodeList<AstNode>(owner);
- expect(list, isNotNull);
- expect(list, hasLength(0));
- expect(list.owner, same(owner));
- }
-
- void test_get_negative() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list[-1];
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_get_tooBig() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list[1];
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_getBeginToken_empty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- expect(list.beginToken, isNull);
- }
-
- void test_getBeginToken_nonEmpty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- AstNode node =
- AstFactory.parenthesizedExpression(AstFactory.booleanLiteral(true));
- list.add(node);
- expect(list.beginToken, same(node.beginToken));
- }
-
- void test_getEndToken_empty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- expect(list.endToken, isNull);
- }
-
- void test_getEndToken_nonEmpty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- AstNode node =
- AstFactory.parenthesizedExpression(AstFactory.booleanLiteral(true));
- list.add(node);
- expect(list.endToken, same(node.endToken));
- }
-
- void test_indexOf() {
- List<AstNode> nodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- AstNode fourthNode = AstFactory.booleanLiteral(false);
- nodes.add(firstNode);
- nodes.add(secondNode);
- nodes.add(thirdNode);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- list.addAll(nodes);
- expect(list, hasLength(3));
- expect(list.indexOf(firstNode), 0);
- expect(list.indexOf(secondNode), 1);
- expect(list.indexOf(thirdNode), 2);
- expect(list.indexOf(fourthNode), -1);
- expect(list.indexOf(null), -1);
- }
-
- void test_remove() {
- List<AstNode> nodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- nodes.add(firstNode);
- nodes.add(secondNode);
- nodes.add(thirdNode);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- list.addAll(nodes);
- expect(list, hasLength(3));
- expect(list.removeAt(1), same(secondNode));
- expect(list, hasLength(2));
- expect(list[0], same(firstNode));
- expect(list[1], same(thirdNode));
- }
-
- void test_remove_negative() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.removeAt(-1);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_remove_tooBig() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.removeAt(1);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_set() {
- List<AstNode> nodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- nodes.add(firstNode);
- nodes.add(secondNode);
- nodes.add(thirdNode);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- list.addAll(nodes);
- expect(list, hasLength(3));
- AstNode fourthNode = AstFactory.integer(0);
- expect(javaListSet(list, 1, fourthNode), same(secondNode));
- expect(list, hasLength(3));
- expect(list[0], same(firstNode));
- expect(list[1], same(fourthNode));
- expect(list[2], same(thirdNode));
- }
-
- void test_set_negative() {
- AstNode node = AstFactory.booleanLiteral(true);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- javaListSet(list, -1, node);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_set_tooBig() {
- AstNode node = AstFactory.booleanLiteral(true);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- javaListSet(list, 1, node);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
+class NodeLocator2Test extends ParserTestCase {
+ void test_onlyStartOffset() {
+ String code = ' int vv; ';
+ // 012345678
+ CompilationUnit unit = ParserTestCase.parseCompilationUnit(code);
+ TopLevelVariableDeclaration declaration = unit.declarations[0];
+ VariableDeclarationList variableList = declaration.variables;
+ Identifier typeName = variableList.type.name;
+ SimpleIdentifier varName = variableList.variables[0].name;
+ expect(new NodeLocator2(0).searchWithin(unit), same(unit));
+ expect(new NodeLocator2(1).searchWithin(unit), same(typeName));
+ expect(new NodeLocator2(2).searchWithin(unit), same(typeName));
+ expect(new NodeLocator2(3).searchWithin(unit), same(typeName));
+ expect(new NodeLocator2(4).searchWithin(unit), same(variableList));
+ expect(new NodeLocator2(5).searchWithin(unit), same(varName));
+ expect(new NodeLocator2(6).searchWithin(unit), same(varName));
+ expect(new NodeLocator2(7).searchWithin(unit), same(declaration));
+ expect(new NodeLocator2(8).searchWithin(unit), same(unit));
+ expect(new NodeLocator2(9).searchWithin(unit), isNull);
+ expect(new NodeLocator2(100).searchWithin(unit), isNull);
+ }
+
+ void test_startEndOffset() {
+ String code = ' int vv; ';
+ // 012345678
+ CompilationUnit unit = ParserTestCase.parseCompilationUnit(code);
+ TopLevelVariableDeclaration declaration = unit.declarations[0];
+ VariableDeclarationList variableList = declaration.variables;
+ Identifier typeName = variableList.type.name;
+ SimpleIdentifier varName = variableList.variables[0].name;
+ expect(new NodeLocator2(-1, 2).searchWithin(unit), isNull);
+ expect(new NodeLocator2(0, 2).searchWithin(unit), same(unit));
+ expect(new NodeLocator2(1, 2).searchWithin(unit), same(typeName));
+ expect(new NodeLocator2(1, 3).searchWithin(unit), same(typeName));
+ expect(new NodeLocator2(1, 4).searchWithin(unit), same(variableList));
+ expect(new NodeLocator2(5, 6).searchWithin(unit), same(varName));
+ expect(new NodeLocator2(5, 7).searchWithin(unit), same(declaration));
+ expect(new NodeLocator2(5, 8).searchWithin(unit), same(unit));
+ expect(new NodeLocator2(5, 100).searchWithin(unit), isNull);
+ expect(new NodeLocator2(100, 200).searchWithin(unit), isNull);
}
}
@@ -984,7 +420,7 @@ class B {}''');
}
void _assertLocate(CompilationUnit unit, int start, int end,
- Predicate<AstNode> predicate, Type expectedClass) {
+ Predicate<Object> predicate, Type expectedClass) {
NodeLocator locator = new NodeLocator(start, end);
AstNode node = locator.searchWithin(unit);
expect(node, isNotNull);
@@ -997,654 +433,677 @@ class B {}''');
}
@reflectiveTest
-class SimpleIdentifierTest extends ParserTestCase {
- void test_inDeclarationContext_catch_exception() {
- SimpleIdentifier identifier =
- AstFactory.catchClause("e").exceptionParameter;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_catch_stack() {
- SimpleIdentifier identifier =
- AstFactory.catchClause2("e", "s").stackTraceParameter;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_classDeclaration() {
- SimpleIdentifier identifier =
- AstFactory.classDeclaration(null, "C", null, null, null, null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_classTypeAlias() {
- SimpleIdentifier identifier =
- AstFactory.classTypeAlias("C", null, null, null, null, null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_constructorDeclaration() {
- SimpleIdentifier identifier = AstFactory
- .constructorDeclaration(AstFactory.identifier3("C"), "c", null, null)
- .name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_declaredIdentifier() {
- DeclaredIdentifier declaredIdentifier = AstFactory.declaredIdentifier3("v");
- SimpleIdentifier identifier = declaredIdentifier.identifier;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_enumConstantDeclaration() {
- EnumDeclaration enumDeclaration =
- AstFactory.enumDeclaration2('MyEnum', ['CONST']);
- SimpleIdentifier identifier = enumDeclaration.constants[0].name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_enumDeclaration() {
- EnumDeclaration enumDeclaration =
- AstFactory.enumDeclaration2('MyEnum', ['A', 'B', 'C']);
- SimpleIdentifier identifier = enumDeclaration.name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_fieldFormalParameter() {
- SimpleIdentifier identifier =
- AstFactory.fieldFormalParameter2("p").identifier;
- expect(identifier.inDeclarationContext(), isFalse);
- }
-
- void test_inDeclarationContext_functionDeclaration() {
- SimpleIdentifier identifier =
- AstFactory.functionDeclaration(null, null, "f", null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_functionTypeAlias() {
- SimpleIdentifier identifier =
- AstFactory.typeAlias(null, "F", null, null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_label_false() {
- SimpleIdentifier identifier =
- AstFactory.namedExpression2("l", AstFactory.integer(0)).name.label;
- expect(identifier.inDeclarationContext(), isFalse);
- }
-
- void test_inDeclarationContext_label_true() {
- Label label = AstFactory.label2("l");
- SimpleIdentifier identifier = label.label;
- AstFactory.labeledStatement([label], AstFactory.emptyStatement());
- expect(identifier.inDeclarationContext(), isTrue);
+class ResolutionCopierTest extends EngineTestCase {
+ void test_visitAdjacentStrings() {
+ AdjacentStrings createNode() => new AdjacentStrings([
+ new SimpleStringLiteral(null, 'hello'),
+ new SimpleStringLiteral(null, 'world')
+ ]);
+
+ AdjacentStrings fromNode = createNode();
+ DartType propagatedType = ElementFactory.classElement2("A").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("B").type;
+ fromNode.staticType = staticType;
+
+ AdjacentStrings toNode = createNode();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitAnnotation() {
+ String annotationName = "proxy";
+ Annotation fromNode =
+ AstFactory.annotation(AstFactory.identifier3(annotationName));
+ Element element = ElementFactory.topLevelVariableElement2(annotationName);
+ fromNode.element = element;
+ Annotation toNode =
+ AstFactory.annotation(AstFactory.identifier3(annotationName));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_inDeclarationContext_methodDeclaration() {
- SimpleIdentifier identifier = AstFactory.identifier3("m");
- AstFactory.methodDeclaration2(
- null, null, null, null, identifier, null, null);
- expect(identifier.inDeclarationContext(), isTrue);
+ void test_visitAsExpression() {
+ AsExpression fromNode = AstFactory.asExpression(
+ AstFactory.identifier3("x"), AstFactory.typeName4("A"));
+ DartType propagatedType = ElementFactory.classElement2("A").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("B").type;
+ fromNode.staticType = staticType;
+ AsExpression toNode = AstFactory.asExpression(
+ AstFactory.identifier3("x"), AstFactory.typeName4("A"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_inDeclarationContext_prefix() {
- SimpleIdentifier identifier =
- AstFactory.importDirective3("uri", "pref").prefix;
- expect(identifier.inDeclarationContext(), isTrue);
+ void test_visitAssignmentExpression() {
+ AssignmentExpression fromNode = AstFactory.assignmentExpression(
+ AstFactory.identifier3("a"),
+ TokenType.PLUS_EQ,
+ AstFactory.identifier3("b"));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ MethodElement propagatedElement =
+ ElementFactory.methodElement("+", propagatedType);
+ fromNode.propagatedElement = propagatedElement;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ MethodElement staticElement = ElementFactory.methodElement("+", staticType);
+ fromNode.staticElement = staticElement;
+ fromNode.staticType = staticType;
+ AssignmentExpression toNode = AstFactory.assignmentExpression(
+ AstFactory.identifier3("a"),
+ TokenType.PLUS_EQ,
+ AstFactory.identifier3("b"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
}
- void test_inDeclarationContext_simpleFormalParameter() {
- SimpleIdentifier identifier =
- AstFactory.simpleFormalParameter3("p").identifier;
- expect(identifier.inDeclarationContext(), isTrue);
+ void test_visitBinaryExpression() {
+ BinaryExpression fromNode = AstFactory.binaryExpression(
+ AstFactory.identifier3("a"),
+ TokenType.PLUS,
+ AstFactory.identifier3("b"));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ MethodElement propagatedElement =
+ ElementFactory.methodElement("+", propagatedType);
+ fromNode.propagatedElement = propagatedElement;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ MethodElement staticElement = ElementFactory.methodElement("+", staticType);
+ fromNode.staticElement = staticElement;
+ fromNode.staticType = staticType;
+ BinaryExpression toNode = AstFactory.binaryExpression(
+ AstFactory.identifier3("a"),
+ TokenType.PLUS,
+ AstFactory.identifier3("b"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitBooleanLiteral() {
+ BooleanLiteral fromNode = AstFactory.booleanLiteral(true);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ BooleanLiteral toNode = AstFactory.booleanLiteral(true);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitCascadeExpression() {
+ CascadeExpression fromNode = AstFactory.cascadeExpression(
+ AstFactory.identifier3("a"), [AstFactory.identifier3("b")]);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ CascadeExpression toNode = AstFactory.cascadeExpression(
+ AstFactory.identifier3("a"), [AstFactory.identifier3("b")]);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitCompilationUnit() {
+ CompilationUnit fromNode = AstFactory.compilationUnit();
+ CompilationUnitElement element =
+ new CompilationUnitElementImpl("test.dart");
+ fromNode.element = element;
+ CompilationUnit toNode = AstFactory.compilationUnit();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_inDeclarationContext_typeParameter_bound() {
- TypeName bound = AstFactory.typeName4("A");
- SimpleIdentifier identifier = bound.name as SimpleIdentifier;
- AstFactory.typeParameter2("E", bound);
- expect(identifier.inDeclarationContext(), isFalse);
+ void test_visitConditionalExpression() {
+ ConditionalExpression fromNode = AstFactory.conditionalExpression(
+ AstFactory.identifier3("c"),
+ AstFactory.identifier3("a"),
+ AstFactory.identifier3("b"));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ ConditionalExpression toNode = AstFactory.conditionalExpression(
+ AstFactory.identifier3("c"),
+ AstFactory.identifier3("a"),
+ AstFactory.identifier3("b"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitConstructorDeclaration() {
+ String className = "A";
+ String constructorName = "c";
+ ConstructorDeclaration fromNode = AstFactory.constructorDeclaration(
+ AstFactory.identifier3(className),
+ constructorName,
+ AstFactory.formalParameterList(),
+ null);
+ ConstructorElement element = ElementFactory.constructorElement2(
+ ElementFactory.classElement2(className), constructorName);
+ fromNode.element = element;
+ ConstructorDeclaration toNode = AstFactory.constructorDeclaration(
+ AstFactory.identifier3(className),
+ constructorName,
+ AstFactory.formalParameterList(),
+ null);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_inDeclarationContext_typeParameter_name() {
- SimpleIdentifier identifier = AstFactory.typeParameter("E").name;
- expect(identifier.inDeclarationContext(), isTrue);
+ void test_visitConstructorName() {
+ ConstructorName fromNode =
+ AstFactory.constructorName(AstFactory.typeName4("A"), "c");
+ ConstructorElement staticElement = ElementFactory.constructorElement2(
+ ElementFactory.classElement2("A"), "c");
+ fromNode.staticElement = staticElement;
+ ConstructorName toNode =
+ AstFactory.constructorName(AstFactory.typeName4("A"), "c");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.staticElement, same(staticElement));
}
- void test_inDeclarationContext_variableDeclaration() {
- SimpleIdentifier identifier = AstFactory.variableDeclaration("v").name;
- expect(identifier.inDeclarationContext(), isTrue);
+ void test_visitDoubleLiteral() {
+ DoubleLiteral fromNode = AstFactory.doubleLiteral(1.0);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ DoubleLiteral toNode = AstFactory.doubleLiteral(1.0);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitExportDirective() {
+ ExportDirective fromNode = AstFactory.exportDirective2("dart:uri");
+ ExportElement element = new ExportElementImpl(-1);
+ fromNode.element = element;
+ ExportDirective toNode = AstFactory.exportDirective2("dart:uri");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_inGetterContext() {
- for (WrapperKind wrapper in WrapperKind.values) {
- for (AssignmentKind assignment in AssignmentKind.values) {
- SimpleIdentifier identifier = _createIdentifier(wrapper, assignment);
- if (assignment == AssignmentKind.SIMPLE_LEFT &&
- wrapper != WrapperKind.PREFIXED_LEFT &&
- wrapper != WrapperKind.PROPERTY_LEFT) {
- if (identifier.inGetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be false");
- }
- } else {
- if (!identifier.inGetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be true");
- }
- }
- }
- }
+ void test_visitFunctionExpression() {
+ FunctionExpression fromNode = AstFactory.functionExpression2(
+ AstFactory.formalParameterList(), AstFactory.emptyFunctionBody());
+ MethodElement element = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ fromNode.element = element;
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ FunctionExpression toNode = AstFactory.functionExpression2(
+ AstFactory.formalParameterList(), AstFactory.emptyFunctionBody());
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitFunctionExpressionInvocation() {
+ FunctionExpressionInvocation fromNode =
+ AstFactory.functionExpressionInvocation(AstFactory.identifier3("f"));
+ MethodElement propagatedElement = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ fromNode.propagatedElement = propagatedElement;
+ MethodElement staticElement = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ fromNode.staticElement = staticElement;
+ FunctionExpressionInvocation toNode =
+ AstFactory.functionExpressionInvocation(AstFactory.identifier3("f"));
+ ClassElement elementT = ElementFactory.classElement2('T');
+ fromNode.typeArguments =
+ AstFactory.typeArgumentList(<TypeName>[AstFactory.typeName(elementT)]);
+ toNode.typeArguments =
+ AstFactory.typeArgumentList(<TypeName>[AstFactory.typeName4('T')]);
+
+ _copyAndVerifyInvocation(fromNode, toNode);
+
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.staticElement, same(staticElement));
+ }
+
+ void test_visitImportDirective() {
+ ImportDirective fromNode = AstFactory.importDirective3("dart:uri", null);
+ ImportElement element = new ImportElementImpl(0);
+ fromNode.element = element;
+ ImportDirective toNode = AstFactory.importDirective3("dart:uri", null);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_inGetterContext_forEachLoop() {
- SimpleIdentifier identifier = AstFactory.identifier3("a");
- Expression iterator = AstFactory.listLiteral();
- Statement body = AstFactory.block();
- AstFactory.forEachStatement2(identifier, iterator, body);
- expect(identifier.inGetterContext(), isFalse);
- }
-
- void test_inReferenceContext() {
- SimpleIdentifier identifier = AstFactory.identifier3("id");
- AstFactory.namedExpression(
- AstFactory.label(identifier), AstFactory.identifier3("_"));
- expect(identifier.inGetterContext(), isFalse);
- expect(identifier.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext() {
- for (WrapperKind wrapper in WrapperKind.values) {
- for (AssignmentKind assignment in AssignmentKind.values) {
- SimpleIdentifier identifier = _createIdentifier(wrapper, assignment);
- if (wrapper == WrapperKind.PREFIXED_LEFT ||
- wrapper == WrapperKind.PROPERTY_LEFT ||
- assignment == AssignmentKind.BINARY ||
- assignment == AssignmentKind.COMPOUND_RIGHT ||
- assignment == AssignmentKind.PREFIX_NOT ||
- assignment == AssignmentKind.SIMPLE_RIGHT ||
- assignment == AssignmentKind.NONE) {
- if (identifier.inSetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be false");
- }
- } else {
- if (!identifier.inSetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be true");
- }
- }
- }
- }
+ void test_visitIndexExpression() {
+ IndexExpression fromNode = AstFactory.indexExpression(
+ AstFactory.identifier3("a"), AstFactory.integer(0));
+ MethodElement propagatedElement = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ MethodElement staticElement = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ AuxiliaryElements auxiliaryElements =
+ new AuxiliaryElements(staticElement, propagatedElement);
+ fromNode.auxiliaryElements = auxiliaryElements;
+ fromNode.propagatedElement = propagatedElement;
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ fromNode.staticElement = staticElement;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ IndexExpression toNode = AstFactory.indexExpression(
+ AstFactory.identifier3("a"), AstFactory.integer(0));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.auxiliaryElements, same(auxiliaryElements));
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitInstanceCreationExpression() {
+ InstanceCreationExpression fromNode = AstFactory
+ .instanceCreationExpression2(Keyword.NEW, AstFactory.typeName4("C"));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ ConstructorElement staticElement = ElementFactory.constructorElement2(
+ ElementFactory.classElement2("C"), null);
+ fromNode.staticElement = staticElement;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ InstanceCreationExpression toNode = AstFactory.instanceCreationExpression2(
+ Keyword.NEW, AstFactory.typeName4("C"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
}
- void test_inSetterContext_forEachLoop() {
- SimpleIdentifier identifier = AstFactory.identifier3("a");
- Expression iterator = AstFactory.listLiteral();
- Statement body = AstFactory.block();
- AstFactory.forEachStatement2(identifier, iterator, body);
- expect(identifier.inSetterContext(), isTrue);
+ void test_visitIntegerLiteral() {
+ IntegerLiteral fromNode = AstFactory.integer(2);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ IntegerLiteral toNode = AstFactory.integer(2);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitIsExpression() {
+ IsExpression fromNode = AstFactory.isExpression(
+ AstFactory.identifier3("x"), false, AstFactory.typeName4("A"));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ IsExpression toNode = AstFactory.isExpression(
+ AstFactory.identifier3("x"), false, AstFactory.typeName4("A"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitLibraryIdentifier() {
+ LibraryIdentifier fromNode =
+ AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ LibraryIdentifier toNode =
+ AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitListLiteral() {
+ ListLiteral fromNode = AstFactory.listLiteral();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ ListLiteral toNode = AstFactory.listLiteral();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitMapLiteral() {
+ MapLiteral fromNode = AstFactory.mapLiteral2();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ MapLiteral toNode = AstFactory.mapLiteral2();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitMethodInvocation() {
+ MethodInvocation fromNode = AstFactory.methodInvocation2("m");
+ MethodInvocation toNode = AstFactory.methodInvocation2("m");
+ ClassElement elementT = ElementFactory.classElement2('T');
+ fromNode.typeArguments =
+ AstFactory.typeArgumentList(<TypeName>[AstFactory.typeName(elementT)]);
+ toNode.typeArguments =
+ AstFactory.typeArgumentList(<TypeName>[AstFactory.typeName4('T')]);
+ _copyAndVerifyInvocation(fromNode, toNode);
}
- void test_isQualified_inMethodInvocation_noTarget() {
- MethodInvocation invocation =
- AstFactory.methodInvocation2("test", [AstFactory.identifier3("arg0")]);
- SimpleIdentifier identifier = invocation.methodName;
- expect(identifier.isQualified, isFalse);
+ void test_visitNamedExpression() {
+ NamedExpression fromNode =
+ AstFactory.namedExpression2("n", AstFactory.integer(0));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ NamedExpression toNode =
+ AstFactory.namedExpression2("n", AstFactory.integer(0));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_isQualified_inMethodInvocation_withTarget() {
- MethodInvocation invocation = AstFactory.methodInvocation(
- AstFactory.identifier3("target"),
- "test",
- [AstFactory.identifier3("arg0")]);
- SimpleIdentifier identifier = invocation.methodName;
- expect(identifier.isQualified, isTrue);
+ void test_visitNullLiteral() {
+ NullLiteral fromNode = AstFactory.nullLiteral();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ NullLiteral toNode = AstFactory.nullLiteral();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_isQualified_inPrefixedIdentifier_name() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.identifier4("prefix", identifier);
- expect(identifier.isQualified, isTrue);
+ void test_visitParenthesizedExpression() {
+ ParenthesizedExpression fromNode =
+ AstFactory.parenthesizedExpression(AstFactory.integer(0));
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ ParenthesizedExpression toNode =
+ AstFactory.parenthesizedExpression(AstFactory.integer(0));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_isQualified_inPrefixedIdentifier_prefix() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.identifier(identifier, AstFactory.identifier3("name"));
- expect(identifier.isQualified, isFalse);
+ void test_visitPartDirective() {
+ PartDirective fromNode = AstFactory.partDirective2("part.dart");
+ LibraryElement element = new LibraryElementImpl.forNode(
+ null, AstFactory.libraryIdentifier2(["lib"]));
+ fromNode.element = element;
+ PartDirective toNode = AstFactory.partDirective2("part.dart");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_isQualified_inPropertyAccess_name() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.propertyAccess(AstFactory.identifier3("target"), identifier);
- expect(identifier.isQualified, isTrue);
+ void test_visitPartOfDirective() {
+ PartOfDirective fromNode =
+ AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"]));
+ LibraryElement element = new LibraryElementImpl.forNode(
+ null, AstFactory.libraryIdentifier2(["lib"]));
+ fromNode.element = element;
+ PartOfDirective toNode =
+ AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"]));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.element, same(element));
}
- void test_isQualified_inPropertyAccess_target() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.propertyAccess(identifier, AstFactory.identifier3("name"));
- expect(identifier.isQualified, isFalse);
+ void test_visitPostfixExpression() {
+ String variableName = "x";
+ PostfixExpression fromNode = AstFactory.postfixExpression(
+ AstFactory.identifier3(variableName), TokenType.PLUS_PLUS);
+ MethodElement propagatedElement = ElementFactory.methodElement(
+ "+", ElementFactory.classElement2("C").type);
+ fromNode.propagatedElement = propagatedElement;
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ MethodElement staticElement = ElementFactory.methodElement(
+ "+", ElementFactory.classElement2("C").type);
+ fromNode.staticElement = staticElement;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ PostfixExpression toNode = AstFactory.postfixExpression(
+ AstFactory.identifier3(variableName), TokenType.PLUS_PLUS);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
}
- void test_isQualified_inReturnStatement() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.returnStatement2(identifier);
- expect(identifier.isQualified, isFalse);
+ void test_visitPrefixedIdentifier() {
+ PrefixedIdentifier fromNode = AstFactory.identifier5("p", "f");
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ PrefixedIdentifier toNode = AstFactory.identifier5("p", "f");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- SimpleIdentifier _createIdentifier(
- WrapperKind wrapper, AssignmentKind assignment) {
- SimpleIdentifier identifier = AstFactory.identifier3("a");
- Expression expression = identifier;
- while (true) {
- if (wrapper == WrapperKind.PREFIXED_LEFT) {
- expression =
- AstFactory.identifier(identifier, AstFactory.identifier3("_"));
- } else if (wrapper == WrapperKind.PREFIXED_RIGHT) {
- expression =
- AstFactory.identifier(AstFactory.identifier3("_"), identifier);
- } else if (wrapper == WrapperKind.PROPERTY_LEFT) {
- expression = AstFactory.propertyAccess2(expression, "_");
- } else if (wrapper == WrapperKind.PROPERTY_RIGHT) {
- expression =
- AstFactory.propertyAccess(AstFactory.identifier3("_"), identifier);
- } else if (wrapper == WrapperKind.NONE) {}
- break;
- }
- while (true) {
- if (assignment == AssignmentKind.BINARY) {
- AstFactory.binaryExpression(
- expression, TokenType.PLUS, AstFactory.identifier3("_"));
- } else if (assignment == AssignmentKind.COMPOUND_LEFT) {
- AstFactory.assignmentExpression(
- expression, TokenType.PLUS_EQ, AstFactory.identifier3("_"));
- } else if (assignment == AssignmentKind.COMPOUND_RIGHT) {
- AstFactory.assignmentExpression(
- AstFactory.identifier3("_"), TokenType.PLUS_EQ, expression);
- } else if (assignment == AssignmentKind.POSTFIX_INC) {
- AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
- } else if (assignment == AssignmentKind.PREFIX_DEC) {
- AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
- } else if (assignment == AssignmentKind.PREFIX_INC) {
- AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
- } else if (assignment == AssignmentKind.PREFIX_NOT) {
- AstFactory.prefixExpression(TokenType.BANG, expression);
- } else if (assignment == AssignmentKind.SIMPLE_LEFT) {
- AstFactory.assignmentExpression(
- expression, TokenType.EQ, AstFactory.identifier3("_"));
- } else if (assignment == AssignmentKind.SIMPLE_RIGHT) {
- AstFactory.assignmentExpression(
- AstFactory.identifier3("_"), TokenType.EQ, expression);
- } else if (assignment == AssignmentKind.NONE) {}
- break;
- }
- return identifier;
+ void test_visitPrefixExpression() {
+ PrefixExpression fromNode = AstFactory.prefixExpression(
+ TokenType.PLUS_PLUS, AstFactory.identifier3("x"));
+ MethodElement propagatedElement = ElementFactory.methodElement(
+ "+", ElementFactory.classElement2("C").type);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedElement = propagatedElement;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ MethodElement staticElement = ElementFactory.methodElement(
+ "+", ElementFactory.classElement2("C").type);
+ fromNode.staticElement = staticElement;
+ fromNode.staticType = staticType;
+ PrefixExpression toNode = AstFactory.prefixExpression(
+ TokenType.PLUS_PLUS, AstFactory.identifier3("x"));
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
}
- /**
- * Return the top-most node in the AST structure containing the given identifier.
- *
- * @param identifier the identifier in the AST structure being traversed
- * @return the root of the AST structure containing the identifier
- */
- AstNode _topMostNode(SimpleIdentifier identifier) {
- AstNode child = identifier;
- AstNode parent = identifier.parent;
- while (parent != null) {
- child = parent;
- parent = parent.parent;
- }
- return child;
+ void test_visitPropertyAccess() {
+ PropertyAccess fromNode =
+ AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y");
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ PropertyAccess toNode =
+ AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitRedirectingConstructorInvocation() {
+ RedirectingConstructorInvocation fromNode =
+ AstFactory.redirectingConstructorInvocation();
+ ConstructorElement staticElement = ElementFactory.constructorElement2(
+ ElementFactory.classElement2("C"), null);
+ fromNode.staticElement = staticElement;
+ RedirectingConstructorInvocation toNode =
+ AstFactory.redirectingConstructorInvocation();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.staticElement, same(staticElement));
}
-}
-@reflectiveTest
-class SimpleStringLiteralTest extends ParserTestCase {
- void test_contentsEnd() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
- .contentsEnd,
- 2);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('"X"'), "X")
- .contentsEnd,
- 2);
-
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('"""X"""'), "X")
- .contentsEnd,
- 4);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .contentsEnd,
- 4);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("''' \nX'''"), "X").contentsEnd,
- 7);
-
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .contentsEnd,
- 3);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('r"X"'), "X")
- .contentsEnd,
- 3);
-
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('r"""X"""'), "X")
- .contentsEnd,
- 5);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .contentsEnd,
- 5);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r''' \nX'''"), "X").contentsEnd,
- 8);
- }
-
- void test_contentsOffset() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
- .contentsOffset,
- 1);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
- .contentsOffset,
- 1);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X").contentsOffset,
- 3);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .contentsOffset,
- 3);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .contentsOffset,
- 2);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
- .contentsOffset,
- 2);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X").contentsOffset,
- 4);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .contentsOffset,
- 4);
- // leading whitespace
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("''' \ \nX''"), "X").contentsOffset,
- 6);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString('r""" \ \nX"""'), "X").contentsOffset,
- 7);
- }
-
- void test_isMultiline() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .isMultiline,
- isTrue);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .isMultiline,
- isTrue);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X").isMultiline,
- isTrue);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X").isMultiline,
- isTrue);
- }
-
- void test_isRaw() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X").isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
- .isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X").isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .isRaw,
- isTrue);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
- .isRaw,
- isTrue);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X").isRaw,
- isTrue);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .isRaw,
- isTrue);
- }
-
- void test_isSingleQuoted() {
- // '
- {
- var token = TokenFactory.tokenFromString("'X'");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // '''
- {
- var token = TokenFactory.tokenFromString("'''X'''");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // "
- {
- var token = TokenFactory.tokenFromString('"X"');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
- // """
- {
- var token = TokenFactory.tokenFromString('"""X"""');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
+ void test_visitRethrowExpression() {
+ RethrowExpression fromNode = AstFactory.rethrowExpression();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ RethrowExpression toNode = AstFactory.rethrowExpression();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_isSingleQuoted_raw() {
- // r'
- {
- var token = TokenFactory.tokenFromString("r'X'");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // r'''
- {
- var token = TokenFactory.tokenFromString("r'''X'''");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // r"
- {
- var token = TokenFactory.tokenFromString('r"X"');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
- // r"""
- {
- var token = TokenFactory.tokenFromString('r"""X"""');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
+ void test_visitSimpleIdentifier() {
+ SimpleIdentifier fromNode = AstFactory.identifier3("x");
+ MethodElement propagatedElement = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ MethodElement staticElement = ElementFactory.methodElement(
+ "m", ElementFactory.classElement2("C").type);
+ AuxiliaryElements auxiliaryElements =
+ new AuxiliaryElements(staticElement, propagatedElement);
+ fromNode.auxiliaryElements = auxiliaryElements;
+ fromNode.propagatedElement = propagatedElement;
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ fromNode.staticElement = staticElement;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ SimpleIdentifier toNode = AstFactory.identifier3("x");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.auxiliaryElements, same(auxiliaryElements));
+ expect(toNode.propagatedElement, same(propagatedElement));
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticElement, same(staticElement));
+ expect(toNode.staticType, same(staticType));
}
- void test_simple() {
- Token token = TokenFactory.tokenFromString("'value'");
- SimpleStringLiteral stringLiteral = new SimpleStringLiteral(token, "value");
- expect(stringLiteral.literal, same(token));
- expect(stringLiteral.beginToken, same(token));
- expect(stringLiteral.endToken, same(token));
- expect(stringLiteral.value, "value");
+ void test_visitSimpleStringLiteral() {
+ SimpleStringLiteral fromNode = AstFactory.string2("abc");
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ SimpleStringLiteral toNode = AstFactory.string2("abc");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
-}
-@reflectiveTest
-class StringInterpolationTest extends ParserTestCase {
- void test_contentsOffsetEnd() {
- AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
- // 'a${bb}ccc'
- {
- var ae = AstFactory.interpolationString("'a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 1);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // '''a${bb}ccc'''
- {
- var ae = AstFactory.interpolationString("'''a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 3);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // """a${bb}ccc"""
- {
- var ae = AstFactory.interpolationString('"""a', "a");
- var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 3);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // r'a${bb}ccc'
- {
- var ae = AstFactory.interpolationString("r'a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 2);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // r'''a${bb}ccc'''
- {
- var ae = AstFactory.interpolationString("r'''a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 4);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // r"""a${bb}ccc"""
- {
- var ae = AstFactory.interpolationString('r"""a', "a");
- var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 4);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
+ void test_visitStringInterpolation() {
+ StringInterpolation fromNode =
+ AstFactory.string([AstFactory.interpolationString("a", "'a'")]);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ StringInterpolation toNode =
+ AstFactory.string([AstFactory.interpolationString("a", "'a'")]);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_isMultiline() {
- var b = AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
- // '
- {
- var a = AstFactory.interpolationString("'a", "a");
- var c = AstFactory.interpolationString("ccc'", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isFalse);
- }
- // '''
- {
- var a = AstFactory.interpolationString("'''a", "a");
- var c = AstFactory.interpolationString("ccc'''", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isTrue);
- }
- // "
- {
- var a = AstFactory.interpolationString('"a', "a");
- var c = AstFactory.interpolationString('ccc"', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isFalse);
- }
- // """
- {
- var a = AstFactory.interpolationString('"""a', "a");
- var c = AstFactory.interpolationString('ccc"""', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isTrue);
- }
+ void test_visitSuperConstructorInvocation() {
+ SuperConstructorInvocation fromNode =
+ AstFactory.superConstructorInvocation();
+ ConstructorElement staticElement = ElementFactory.constructorElement2(
+ ElementFactory.classElement2("C"), null);
+ fromNode.staticElement = staticElement;
+ SuperConstructorInvocation toNode = AstFactory.superConstructorInvocation();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.staticElement, same(staticElement));
}
- void test_isRaw() {
- StringInterpolation node = AstFactory.string();
- expect(node.isRaw, isFalse);
+ void test_visitSuperExpression() {
+ SuperExpression fromNode = AstFactory.superExpression();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ SuperExpression toNode = AstFactory.superExpression();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitSymbolLiteral() {
+ SymbolLiteral fromNode = AstFactory.symbolLiteral(["s"]);
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ SymbolLiteral toNode = AstFactory.symbolLiteral(["s"]);
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
}
- void test_isSingleQuoted() {
- var b = AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
- // "
- {
- var a = AstFactory.interpolationString('"a', "a");
- var c = AstFactory.interpolationString('ccc"', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isFalse);
- }
- // """
- {
- var a = AstFactory.interpolationString('"""a', "a");
- var c = AstFactory.interpolationString('ccc"""', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isFalse);
- }
- // '
- {
- var a = AstFactory.interpolationString("'a", "a");
- var c = AstFactory.interpolationString("ccc'", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isTrue);
- }
- // '''
- {
- var a = AstFactory.interpolationString("'''a", "a");
- var c = AstFactory.interpolationString("ccc'''", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isTrue);
+ void test_visitThisExpression() {
+ ThisExpression fromNode = AstFactory.thisExpression();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ ThisExpression toNode = AstFactory.thisExpression();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitThrowExpression() {
+ ThrowExpression fromNode = AstFactory.throwExpression();
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+ ThrowExpression toNode = AstFactory.throwExpression();
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ }
+
+ void test_visitTypeName() {
+ TypeName fromNode = AstFactory.typeName4("C");
+ DartType type = ElementFactory.classElement2("C").type;
+ fromNode.type = type;
+ TypeName toNode = AstFactory.typeName4("C");
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.type, same(type));
+ }
+
+ void _copyAndVerifyInvocation(
+ InvocationExpression fromNode, InvocationExpression toNode) {
+ DartType propagatedType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedType = propagatedType;
+ DartType staticType = ElementFactory.classElement2("C").type;
+ fromNode.staticType = staticType;
+
+ DartType propagatedInvokeType = ElementFactory.classElement2("C").type;
+ fromNode.propagatedInvokeType = propagatedInvokeType;
+ DartType staticInvokeType = ElementFactory.classElement2("C").type;
+ fromNode.staticInvokeType = staticInvokeType;
+
+ ResolutionCopier.copyResolutionData(fromNode, toNode);
+ expect(toNode.propagatedType, same(propagatedType));
+ expect(toNode.staticType, same(staticType));
+ expect(toNode.propagatedInvokeType, same(propagatedInvokeType));
+ expect(toNode.staticInvokeType, same(staticInvokeType));
+ List<TypeName> fromTypeArguments = toNode.typeArguments.arguments;
+ List<TypeName> toTypeArguments = fromNode.typeArguments.arguments;
+ if (fromTypeArguments != null) {
+ for (int i = 0; i < fromTypeArguments.length; i++) {
+ TypeName toArgument = fromTypeArguments[i];
+ TypeName fromArgument = toTypeArguments[i];
+ expect(toArgument.type, same(fromArgument.type));
+ }
}
}
}
@@ -1688,6 +1147,13 @@ class ToSourceVisitorTest extends EngineTestCase {
"assert (a);", AstFactory.assertStatement(AstFactory.identifier3("a")));
}
+ void test_visitAssertStatement_withMessage() {
+ _assertSource(
+ "assert (a, b);",
+ AstFactory.assertStatement(
+ AstFactory.identifier3("a"), AstFactory.identifier3('b')));
+ }
+
void test_visitAssignmentExpression() {
_assertSource(
"a = b",
@@ -2290,6 +1756,13 @@ class ToSourceVisitorTest extends EngineTestCase {
_assertSource("continue;", AstFactory.continueStatement());
}
+ void test_visitDefaultFormalParameter_annotation() {
+ DefaultFormalParameter parameter = AstFactory.positionalFormalParameter(
+ AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0));
+ parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
+ _assertSource('@A p = 0', parameter);
+ }
+
void test_visitDefaultFormalParameter_named_noValue() {
_assertSource(
"p",
@@ -2318,13 +1791,6 @@ class ToSourceVisitorTest extends EngineTestCase {
AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0)));
}
- void test_visitDefaultFormalParameter_annotation() {
- DefaultFormalParameter parameter = AstFactory.positionalFormalParameter(
- AstFactory.simpleFormalParameter3("p"), AstFactory.integer(0));
- parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
- _assertSource('@A p = 0', parameter);
- }
-
void test_visitDoStatement() {
_assertSource(
"do {} while (c);",
@@ -2423,6 +1889,12 @@ class ToSourceVisitorTest extends EngineTestCase {
_assertSource("@deprecated var a;", declaration);
}
+ void test_visitFieldFormalParameter_annotation() {
+ FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('f');
+ parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
+ _assertSource('@A this.f', parameter);
+ }
+
void test_visitFieldFormalParameter_functionTyped() {
_assertSource(
"A this.a(b)",
@@ -2467,12 +1939,6 @@ class ToSourceVisitorTest extends EngineTestCase {
AstFactory.fieldFormalParameter(null, AstFactory.typeName4("A"), "a"));
}
- void test_visitFieldFormalParameter_annotation() {
- FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('f');
- parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
- _assertSource('@A this.f', parameter);
- }
-
void test_visitForEachStatement_declared() {
_assertSource(
"for (var a in b) {}",
@@ -2907,16 +2373,17 @@ class ToSourceVisitorTest extends EngineTestCase {
_assertSource("@deprecated typedef A F();", declaration);
}
- void test_visitFunctionTypedFormalParameter_noType() {
- _assertSource("f()", AstFactory.functionTypedFormalParameter(null, "f"));
- }
-
void test_visitFunctionTypedFormalParameter_annotation() {
- FunctionTypedFormalParameter parameter = AstFactory.functionTypedFormalParameter(null, "f");
+ FunctionTypedFormalParameter parameter =
+ AstFactory.functionTypedFormalParameter(null, "f");
parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
_assertSource('@A f()', parameter);
}
+ void test_visitFunctionTypedFormalParameter_noType() {
+ _assertSource("f()", AstFactory.functionTypedFormalParameter(null, "f"));
+ }
+
void test_visitFunctionTypedFormalParameter_type() {
_assertSource(
"T f()",
@@ -3524,6 +2991,12 @@ class ToSourceVisitorTest extends EngineTestCase {
_assertSource(scriptTag, AstFactory.scriptTag(scriptTag));
}
+ void test_visitSimpleFormalParameter_annotation() {
+ SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3('x');
+ parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
+ _assertSource('@A x', parameter);
+ }
+
void test_visitSimpleFormalParameter_keyword() {
_assertSource("var a", AstFactory.simpleFormalParameter(Keyword.VAR, "a"));
}
@@ -3540,12 +3013,6 @@ class ToSourceVisitorTest extends EngineTestCase {
AstFactory.simpleFormalParameter4(AstFactory.typeName4("A"), "a"));
}
- void test_visitSimpleFormalParameter_annotation() {
- SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3('x');
- parameter.metadata.add(AstFactory.annotation(AstFactory.identifier3("A")));
- _assertSource('@A x', parameter);
- }
-
void test_visitSimpleIdentifier() {
_assertSource("a", AstFactory.identifier3("a"));
}
@@ -3595,8 +3062,8 @@ class ToSourceVisitorTest extends EngineTestCase {
void test_visitSwitchCase_noLabels() {
_assertSource(
"case a: {}",
- AstFactory.switchCase(
- AstFactory.identifier3("a"), [AstFactory.block()]));
+ AstFactory
+ .switchCase(AstFactory.identifier3("a"), [AstFactory.block()]));
}
void test_visitSwitchCase_singleLabel() {
@@ -3627,8 +3094,8 @@ class ToSourceVisitorTest extends EngineTestCase {
void test_visitSwitchDefault_singleLabel() {
_assertSource(
"l1: default: {}",
- AstFactory.switchDefault(
- [AstFactory.label2("l1")], [AstFactory.block()]));
+ AstFactory
+ .switchDefault([AstFactory.label2("l1")], [AstFactory.block()]));
}
void test_visitSwitchStatement() {
@@ -3879,50 +3346,3 @@ class ToSourceVisitorTest extends EngineTestCase {
expect(writer.toString(), expectedSource);
}
}
-
-@reflectiveTest
-class VariableDeclarationTest extends ParserTestCase {
- void test_getDocumentationComment_onGrandParent() {
- VariableDeclaration varDecl = AstFactory.variableDeclaration("a");
- TopLevelVariableDeclaration decl =
- AstFactory.topLevelVariableDeclaration2(Keyword.VAR, [varDecl]);
- Comment comment = Comment.createDocumentationComment(new List<Token>(0));
- expect(varDecl.documentationComment, isNull);
- decl.documentationComment = comment;
- expect(varDecl.documentationComment, isNotNull);
- expect(decl.documentationComment, isNotNull);
- }
-
- void test_getDocumentationComment_onNode() {
- VariableDeclaration decl = AstFactory.variableDeclaration("a");
- Comment comment = Comment.createDocumentationComment(new List<Token>(0));
- decl.documentationComment = comment;
- expect(decl.documentationComment, isNotNull);
- }
-}
-
-class WrapperKind extends Enum<WrapperKind> {
- static const WrapperKind PREFIXED_LEFT =
- const WrapperKind('PREFIXED_LEFT', 0);
-
- static const WrapperKind PREFIXED_RIGHT =
- const WrapperKind('PREFIXED_RIGHT', 1);
-
- static const WrapperKind PROPERTY_LEFT =
- const WrapperKind('PROPERTY_LEFT', 2);
-
- static const WrapperKind PROPERTY_RIGHT =
- const WrapperKind('PROPERTY_RIGHT', 3);
-
- static const WrapperKind NONE = const WrapperKind('NONE', 4);
-
- static const List<WrapperKind> values = const [
- PREFIXED_LEFT,
- PREFIXED_RIGHT,
- PROPERTY_LEFT,
- PROPERTY_RIGHT,
- NONE
- ];
-
- const WrapperKind(String name, int ordinal) : super(name, ordinal);
-}
« no previous file with comments | « packages/analyzer/test/src/dart/ast/test_all.dart ('k') | packages/analyzer/test/src/dart/constant/evaluation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698