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

Unified Diff: pkg/analyzer/test/dart/ast/ast_test.dart

Issue 2539243002: Transition analyzer and analysis_server to new astFactory; remove old AST factory methods. (Closed)
Patch Set: Update CHANGELOG Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/dart/ast/ast_test.dart
diff --git a/pkg/analyzer/test/dart/ast/ast_test.dart b/pkg/analyzer/test/dart/ast/ast_test.dart
index 3a887f8d97fc94414928252af2dd7965018cd6d7..494cb07b663f23d8ae98d92841589e1d87309098 100644
--- a/pkg/analyzer/test/dart/ast/ast_test.dart
+++ b/pkg/analyzer/test/dart/ast/ast_test.dart
@@ -5,6 +5,7 @@
library analyzer.test.dart.ast.ast_test;
import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/ast/standard_ast_factory.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
@@ -365,7 +366,7 @@ class NodeListTest extends EngineTestCase {
AstNode parent = AstTestFactory.argumentList();
AstNode firstNode = AstTestFactory.booleanLiteral(true);
AstNode secondNode = AstTestFactory.booleanLiteral(false);
- NodeList<AstNode> list = new NodeList<AstNode>(parent);
+ NodeList<AstNode> list = astFactory.nodeList/*<AstNode>*/(parent);
list.insert(0, secondNode);
list.insert(0, firstNode);
expect(list, hasLength(2));
@@ -386,7 +387,7 @@ class NodeListTest extends EngineTestCase {
void test_add_negative() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list.insert(-1, AstTestFactory.booleanLiteral(true));
fail("Expected IndexOutOfBoundsException");
@@ -397,7 +398,7 @@ class NodeListTest extends EngineTestCase {
void test_add_tooBig() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list.insert(1, AstTestFactory.booleanLiteral(true));
fail("Expected IndexOutOfBoundsException");
@@ -413,7 +414,7 @@ class NodeListTest extends EngineTestCase {
AstNode secondNode = AstTestFactory.booleanLiteral(false);
firstNodes.add(firstNode);
firstNodes.add(secondNode);
- NodeList<AstNode> list = new NodeList<AstNode>(parent);
+ NodeList<AstNode> list = astFactory.nodeList/*<AstNode>*/(parent);
list.addAll(firstNodes);
expect(list, hasLength(2));
expect(list[0], same(firstNode));
@@ -439,7 +440,7 @@ class NodeListTest extends EngineTestCase {
void test_creation() {
AstNode owner = AstTestFactory.argumentList();
- NodeList<AstNode> list = new NodeList<AstNode>(owner);
+ NodeList<AstNode> list = astFactory.nodeList/*<AstNode>*/(owner);
expect(list, isNotNull);
expect(list, hasLength(0));
expect(list.owner, same(owner));
@@ -447,7 +448,7 @@ class NodeListTest extends EngineTestCase {
void test_get_negative() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list[-1];
fail("Expected IndexOutOfBoundsException");
@@ -458,7 +459,7 @@ class NodeListTest extends EngineTestCase {
void test_get_tooBig() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list[1];
fail("Expected IndexOutOfBoundsException");
@@ -469,13 +470,13 @@ class NodeListTest extends EngineTestCase {
void test_getBeginToken_empty() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
expect(list.beginToken, isNull);
}
void test_getBeginToken_nonEmpty() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
AstNode node = AstTestFactory
.parenthesizedExpression(AstTestFactory.booleanLiteral(true));
list.add(node);
@@ -484,13 +485,13 @@ class NodeListTest extends EngineTestCase {
void test_getEndToken_empty() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
expect(list.endToken, isNull);
}
void test_getEndToken_nonEmpty() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
AstNode node = AstTestFactory
.parenthesizedExpression(AstTestFactory.booleanLiteral(true));
list.add(node);
@@ -507,7 +508,7 @@ class NodeListTest extends EngineTestCase {
nodes.add(secondNode);
nodes.add(thirdNode);
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
list.addAll(nodes);
expect(list, hasLength(3));
expect(list.indexOf(firstNode), 0);
@@ -526,7 +527,7 @@ class NodeListTest extends EngineTestCase {
nodes.add(secondNode);
nodes.add(thirdNode);
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
list.addAll(nodes);
expect(list, hasLength(3));
expect(list.removeAt(1), same(secondNode));
@@ -537,7 +538,7 @@ class NodeListTest extends EngineTestCase {
void test_remove_negative() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list.removeAt(-1);
fail("Expected IndexOutOfBoundsException");
@@ -548,7 +549,7 @@ class NodeListTest extends EngineTestCase {
void test_remove_tooBig() {
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list.removeAt(1);
fail("Expected IndexOutOfBoundsException");
@@ -566,7 +567,7 @@ class NodeListTest extends EngineTestCase {
nodes.add(secondNode);
nodes.add(thirdNode);
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
list.addAll(nodes);
expect(list, hasLength(3));
AstNode fourthNode = AstTestFactory.integer(0);
@@ -580,7 +581,7 @@ class NodeListTest extends EngineTestCase {
void test_set_negative() {
AstNode node = AstTestFactory.booleanLiteral(true);
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list[-1] = node;
fail("Expected IndexOutOfBoundsException");
@@ -592,7 +593,7 @@ class NodeListTest extends EngineTestCase {
void test_set_tooBig() {
AstNode node = AstTestFactory.booleanLiteral(true);
NodeList<AstNode> list =
- new NodeList<AstNode>(AstTestFactory.argumentList());
+ astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList());
try {
list[1] = node;
fail("Expected IndexOutOfBoundsException");
@@ -795,47 +796,57 @@ class SimpleIdentifierTest extends ParserTestCase {
class SimpleStringLiteralTest extends ParserTestCase {
void test_contentsEnd() {
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
.contentsEnd,
2);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('"X"'), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString('"X"'), "X")
.contentsEnd,
2);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('"""X"""'), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString('"""X"""'), "X")
.contentsEnd,
4);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
.contentsEnd,
4);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("''' \nX'''"), "X")
.contentsEnd,
7);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
.contentsEnd,
3);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('r"X"'), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString('r"X"'), "X")
.contentsEnd,
3);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('r"""X"""'), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString('r"""X"""'), "X")
.contentsEnd,
5);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
.contentsEnd,
5);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("r''' \nX'''"), "X")
.contentsEnd,
8);
@@ -843,47 +854,57 @@ class SimpleStringLiteralTest extends ParserTestCase {
void test_contentsOffset() {
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
.contentsOffset,
1);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
.contentsOffset,
1);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X")
.contentsOffset,
3);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
.contentsOffset,
3);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
.contentsOffset,
2);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
.contentsOffset,
2);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X")
.contentsOffset,
4);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
.contentsOffset,
4);
// leading whitespace
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("''' \ \nX''"), "X")
.contentsOffset,
6);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString('r""" \ \nX"""'), "X")
.contentsOffset,
7);
@@ -891,36 +912,44 @@ class SimpleStringLiteralTest extends ParserTestCase {
void test_isMultiline() {
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
.isMultiline,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
.isMultiline,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
.isMultiline,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
.isMultiline,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
.isMultiline,
isTrue);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
.isMultiline,
isTrue);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X")
.isMultiline,
isTrue);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X")
.isMultiline,
isTrue);
@@ -928,36 +957,45 @@ class SimpleStringLiteralTest extends ParserTestCase {
void test_isRaw() {
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X").isRaw,
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
+ .isRaw,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
.isRaw,
isFalse);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X")
.isRaw,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
.isRaw,
isFalse);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
.isRaw,
isTrue);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
.isRaw,
isTrue);
expect(
- new SimpleStringLiteral(
+ astFactory
+ .simpleStringLiteral(
TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X")
.isRaw,
isTrue);
expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
+ astFactory
+ .simpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
.isRaw,
isTrue);
}
@@ -966,25 +1004,25 @@ class SimpleStringLiteralTest extends ParserTestCase {
// '
{
var token = TokenFactory.tokenFromString("'X'");
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isTrue);
}
// '''
{
var token = TokenFactory.tokenFromString("'''X'''");
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isTrue);
}
// "
{
var token = TokenFactory.tokenFromString('"X"');
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isFalse);
}
// """
{
var token = TokenFactory.tokenFromString('"""X"""');
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isFalse);
}
}
@@ -993,32 +1031,33 @@ class SimpleStringLiteralTest extends ParserTestCase {
// r'
{
var token = TokenFactory.tokenFromString("r'X'");
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isTrue);
}
// r'''
{
var token = TokenFactory.tokenFromString("r'''X'''");
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isTrue);
}
// r"
{
var token = TokenFactory.tokenFromString('r"X"');
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isFalse);
}
// r"""
{
var token = TokenFactory.tokenFromString('r"""X"""');
- var node = new SimpleStringLiteral(token, null);
+ var node = astFactory.simpleStringLiteral(token, null);
expect(node.isSingleQuoted, isFalse);
}
}
void test_simple() {
Token token = TokenFactory.tokenFromString("'value'");
- SimpleStringLiteral stringLiteral = new SimpleStringLiteral(token, "value");
+ SimpleStringLiteral stringLiteral =
+ astFactory.simpleStringLiteral(token, "value");
expect(stringLiteral.literal, same(token));
expect(stringLiteral.beginToken, same(token));
expect(stringLiteral.endToken, same(token));
@@ -1034,7 +1073,7 @@ class StringInterpolationTest extends ParserTestCase {
{
var ae = AstTestFactory.interpolationString("'a", "a");
var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
+ var cElement = astFactory.interpolationString(cToken, 'ccc');
StringInterpolation node = AstTestFactory.string([ae, ae, cElement]);
expect(node.contentsOffset, 1);
expect(node.contentsEnd, 10 + 4 - 1);
@@ -1043,7 +1082,7 @@ class StringInterpolationTest extends ParserTestCase {
{
var ae = AstTestFactory.interpolationString("'''a", "a");
var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
+ var cElement = astFactory.interpolationString(cToken, 'ccc');
StringInterpolation node = AstTestFactory.string([ae, ae, cElement]);
expect(node.contentsOffset, 3);
expect(node.contentsEnd, 10 + 4 - 1);
@@ -1052,7 +1091,7 @@ class StringInterpolationTest extends ParserTestCase {
{
var ae = AstTestFactory.interpolationString('"""a', "a");
var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
- var cElement = new InterpolationString(cToken, 'ccc');
+ var cElement = astFactory.interpolationString(cToken, 'ccc');
StringInterpolation node = AstTestFactory.string([ae, ae, cElement]);
expect(node.contentsOffset, 3);
expect(node.contentsEnd, 10 + 4 - 1);
@@ -1061,7 +1100,7 @@ class StringInterpolationTest extends ParserTestCase {
{
var ae = AstTestFactory.interpolationString("r'a", "a");
var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
+ var cElement = astFactory.interpolationString(cToken, 'ccc');
StringInterpolation node = AstTestFactory.string([ae, ae, cElement]);
expect(node.contentsOffset, 2);
expect(node.contentsEnd, 10 + 4 - 1);
@@ -1070,7 +1109,7 @@ class StringInterpolationTest extends ParserTestCase {
{
var ae = AstTestFactory.interpolationString("r'''a", "a");
var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
+ var cElement = astFactory.interpolationString(cToken, 'ccc');
StringInterpolation node = AstTestFactory.string([ae, ae, cElement]);
expect(node.contentsOffset, 4);
expect(node.contentsEnd, 10 + 4 - 1);
@@ -1079,7 +1118,7 @@ class StringInterpolationTest extends ParserTestCase {
{
var ae = AstTestFactory.interpolationString('r"""a', "a");
var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
- var cElement = new InterpolationString(cToken, 'ccc');
+ var cElement = astFactory.interpolationString(cToken, 'ccc');
StringInterpolation node = AstTestFactory.string([ae, ae, cElement]);
expect(node.contentsOffset, 4);
expect(node.contentsEnd, 10 + 4 - 1);
@@ -1164,7 +1203,7 @@ class VariableDeclarationTest extends ParserTestCase {
VariableDeclaration varDecl = AstTestFactory.variableDeclaration("a");
TopLevelVariableDeclaration decl =
AstTestFactory.topLevelVariableDeclaration2(Keyword.VAR, [varDecl]);
- Comment comment = Comment.createDocumentationComment(new List<Token>(0));
+ Comment comment = astFactory.documentationComment(new List<Token>(0));
expect(varDecl.documentationComment, isNull);
decl.documentationComment = comment;
expect(varDecl.documentationComment, isNotNull);
@@ -1173,7 +1212,7 @@ class VariableDeclarationTest extends ParserTestCase {
void test_getDocumentationComment_onNode() {
VariableDeclaration decl = AstTestFactory.variableDeclaration("a");
- Comment comment = Comment.createDocumentationComment(new List<Token>(0));
+ Comment comment = astFactory.documentationComment(new List<Token>(0));
decl.documentationComment = comment;
expect(decl.documentationComment, isNotNull);
}

Powered by Google App Engine
This is Rietveld 408576698