Analyzer: prep file_system tests for null safety.

Fields initialized in `setUp` are late.

Variables initialized with implicit casts like:

    ClassDeclaration clazz = unit.declarations[0];

would need a cast:

    ClassDeclaration clazz = unit.declarations[0] as ClassDeclaration;

so they are updated to use var, which is more idiomatic:

    var clazz = unit.declarations[0] as ClassDeclaration;

Change-Id: I4e4ae814a814d3a4200c5078a6904dbac0a8140c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170520
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Sam Rawlins 2020-11-05 17:39:37 +00:00 committed by commit-bot@chromium.org
parent d13eaddf97
commit e56e5104cf
7 changed files with 39 additions and 38 deletions

View file

@ -961,29 +961,29 @@ E f() => g;
}
void test_findPrevious_basic_class() {
ClassDeclaration clazz = unit.declarations[0];
var clazz = unit.declarations[0] as ClassDeclaration;
expect(clazz.findPrevious(findToken('A')).lexeme, 'class');
}
void test_findPrevious_basic_method() {
ClassDeclaration clazz = unit.declarations[0];
MethodDeclaration method = clazz.members[0];
var clazz = unit.declarations[0] as ClassDeclaration;
var method = clazz.members[0] as MethodDeclaration;
expect(method.findPrevious(findToken('foo')).lexeme, 'B');
}
void test_findPrevious_basic_statement() {
ClassDeclaration clazz = unit.declarations[0];
MethodDeclaration method = clazz.members[0];
BlockFunctionBody body = method.body;
var clazz = unit.declarations[0] as ClassDeclaration;
var method = clazz.members[0] as MethodDeclaration;
var body = method.body as BlockFunctionBody;
Statement statement = body.block.statements[0];
expect(statement.findPrevious(findToken('bar')).lexeme, 'return');
expect(statement.findPrevious(findToken(';')).lexeme, 'bar');
}
void test_findPrevious_missing() {
ClassDeclaration clazz = unit.declarations[0];
MethodDeclaration method = clazz.members[0];
BlockFunctionBody body = method.body;
var clazz = unit.declarations[0] as ClassDeclaration;
var method = clazz.members[0] as MethodDeclaration;
var body = method.body as BlockFunctionBody;
Statement statement = body.block.statements[0];
GatheringErrorListener listener = GatheringErrorListener(checkRanges: true);
@ -1000,15 +1000,15 @@ E f() => g;
}
void test_findPrevious_parent_method() {
ClassDeclaration clazz = unit.declarations[0];
MethodDeclaration method = clazz.members[0];
var clazz = unit.declarations[0] as ClassDeclaration;
var method = clazz.members[0] as MethodDeclaration;
expect(method.findPrevious(findToken('B')).lexeme, '{');
}
void test_findPrevious_parent_statement() {
ClassDeclaration clazz = unit.declarations[0];
MethodDeclaration method = clazz.members[0];
BlockFunctionBody body = method.body;
var clazz = unit.declarations[0] as ClassDeclaration;
var method = clazz.members[0] as MethodDeclaration;
var body = method.body as BlockFunctionBody;
Statement statement = body.block.statements[0];
expect(statement.findPrevious(findToken('return')).lexeme, '{');
}
@ -1019,8 +1019,8 @@ E f() => g;
}
void test_findPrevious_sibling_method() {
ClassDeclaration clazz = unit.declarations[0];
MethodDeclaration method = clazz.members[1];
var clazz = unit.declarations[0] as ClassDeclaration;
var method = clazz.members[1] as MethodDeclaration;
expect(method.findPrevious(findToken('D')).lexeme, '}');
}
}

View file

@ -39,12 +39,13 @@ class ErrorCodeValuesTest extends ParserTestCase {
extendsClause.superclass.name.name == 'ErrorCode') {
String className = declaration.name.name;
for (ClassMember member in declaration.members) {
if (member is FieldDeclaration &&
member.isStatic &&
(member.fields.type == null ? bad() : true) &&
member.fields.type.toSource() == className) {
String fieldName = member.fields.variables[0].name.name;
declaredCodes.add(className + '.' + fieldName);
if (member is FieldDeclaration && member.isStatic) {
var fields = member.fields;
if ((fields.type == null ? bad() : true) &&
fields.type.toSource() == className) {
String fieldName = fields.variables[0].name.name;
declaredCodes.add(className + '.' + fieldName);
}
}
}
}
@ -63,7 +64,7 @@ class ErrorCodeValuesTest extends ParserTestCase {
member.variables.variables[0].name.name == 'errorCodeValues',
orElse: () => null);
ListLiteral listLiteral = declaration.variables.variables[0].initializer;
for (PrefixedIdentifier element in listLiteral.elements) {
for (var element in listLiteral.elements.cast<PrefixedIdentifier>()) {
listedCodes.add(element.name);
}
return listedCodes;

View file

@ -19,17 +19,17 @@ abstract class FileSystemTestSupport {
String get defaultFileContent;
/// A path to a file within the [defaultFolderPath] that can be used by tests.
String get defaultFilePath;
String /*!*/ get defaultFilePath;
/// A path to a folder within the [tempPath] that can be used by tests.
String get defaultFolderPath;
String /*!*/ get defaultFolderPath;
/// Return the resource provider to be used by the tests.
ResourceProvider get provider;
/// The absolute path to the temporary directory in which all of the tests are
/// to work.
String get tempPath;
String /*!*/ get tempPath;
/// Return a file accessed through the resource provider. If [exists] is
/// `true` then the returned file will exist, otherwise it won't. If [content]

View file

@ -34,15 +34,15 @@ abstract class BaseTest extends FileSystemTestSupport {
/// The absolute path to the temporary directory in which all of the tests are
/// to work.
@override
String tempPath;
/*late*/ String tempPath;
/// A path to a folder within the [tempPath] that can be used by tests.
@override
String defaultFolderPath;
/*late*/ String defaultFolderPath;
/// A path to a file within the [defaultFolderPath] that can be used by tests.
@override
String defaultFilePath;
/*late*/ String defaultFilePath;
/// The content used for the file at the [defaultFilePath] if it is created
/// and no other content is provided.

View file

@ -819,11 +819,11 @@ class OverlayResourceProviderTest extends OverlayTestSupport {
}
class OverlayTestSupport {
MemoryResourceProvider baseProvider;
OverlayResourceProvider provider;
/*late*/ MemoryResourceProvider baseProvider;
/*late*/ OverlayResourceProvider provider;
String defaultFolderPath;
String defaultFilePath;
/*late*/ String defaultFolderPath;
/*late*/ String defaultFilePath;
void setUp() {
baseProvider = MemoryResourceProvider();

View file

@ -29,20 +29,20 @@ abstract class BaseTest extends FileSystemTestSupport {
/// A temporary directory on disk. All files and folders created by the tests
/// should be inside this directory.
io.Directory tempDirectory;
/*late*/ io.Directory tempDirectory;
/// The absolute path to the [tempDirectory]. This path will contain a
/// symbolic link on some operating systems.
@override
String tempPath;
/*late*/ String tempPath;
/// A path to a folder within the [tempDirectory] that can be used by tests.
@override
String defaultFolderPath;
/*late*/ String defaultFolderPath;
/// A path to a file within the [defaultFolderPath] that can be used by tests.
@override
String defaultFilePath;
/*late*/ String defaultFilePath;
/// The content used for the file at the [defaultFilePath] if it is created
/// and no other content is provided.

View file

@ -16,7 +16,7 @@ main() {
@reflectiveTest
class ResourceUriResolverTest with ResourceProviderMixin {
ResourceUriResolver resolver;
/*late*/ ResourceUriResolver resolver;
void setUp() {
resolver = ResourceUriResolver(resourceProvider);