Declare locals as final where not reassigned (dev) (#8574)

This commit is contained in:
Chris Bracken
2017-03-03 18:06:08 -08:00
committed by GitHub
parent 7a52fb6772
commit 6c97dd2c6c
35 changed files with 215 additions and 215 deletions

View File

@@ -25,7 +25,7 @@ Future<Null> main(List<String> args) async {
Directory.current = Directory.current.parent.parent;
// Create the pubspec.yaml file.
StringBuffer buf = new StringBuffer('''
final StringBuffer buf = new StringBuffer('''
name: Flutter
dependencies:
''');
@@ -40,10 +40,10 @@ dependencies:
new File('dev/docs/pubspec.yaml').writeAsStringSync(buf.toString());
// Create the library file.
Directory libDir = new Directory('dev/docs/lib');
final Directory libDir = new Directory('dev/docs/lib');
libDir.createSync();
StringBuffer contents = new StringBuffer('library temp_doc;\n\n');
final StringBuffer contents = new StringBuffer('library temp_doc;\n\n');
for (String libraryRef in libraryRefs()) {
contents.writeln('import \'package:$libraryRef\';');
}
@@ -58,14 +58,14 @@ dependencies:
);
printStream(process.stdout);
printStream(process.stderr);
int code = await process.exitCode;
final int code = await process.exitCode;
if (code != 0)
exit(code);
createFooter('dev/docs/lib/footer.html');
// Generate the documentation.
List<String> args = <String>[
final List<String> args = <String>[
'global', 'run', 'dartdoc',
'--header', 'styles.html',
'--header', 'analytics.html',
@@ -84,7 +84,7 @@ dependencies:
process = await Process.start('pub', args, workingDirectory: 'dev/docs');
printStream(process.stdout);
printStream(process.stderr);
int exitCode = await process.exitCode;
final int exitCode = await process.exitCode;
if (exitCode != 0)
exit(exitCode);
@@ -95,10 +95,10 @@ dependencies:
}
void createFooter(String footerPath) {
ProcessResult gitResult = Process.runSync('git', <String>['rev-parse', 'HEAD']);
String gitHead = (gitResult.exitCode == 0) ? gitResult.stdout.trim() : 'unknown';
final ProcessResult gitResult = Process.runSync('git', <String>['rev-parse', 'HEAD']);
final String gitHead = (gitResult.exitCode == 0) ? gitResult.stdout.trim() : 'unknown';
String timestamp = new DateFormat('yyyy-MM-dd HH:mm').format(new DateTime.now());
final String timestamp = new DateFormat('yyyy-MM-dd HH:mm').format(new DateTime.now());
new File(footerPath).writeAsStringSync(
'<p class="text-center" style="font-size: 10px">'
@@ -107,7 +107,7 @@ void createFooter(String footerPath) {
}
void sanityCheckDocs() {
List<String> canaries = <String>[
final List<String> canaries = <String>[
'$kDocRoot/api/dart-io/File-class.html',
'$kDocRoot/api/dart-ui/Canvas-class.html',
'$kDocRoot/api/dart-ui/Canvas/drawRect.html',
@@ -151,7 +151,7 @@ void copyIndexToRootOfDocs() {
}
void addHtmlBaseToIndex() {
File indexFile = new File('$kDocRoot/index.html');
final File indexFile = new File('$kDocRoot/index.html');
String indexContents = indexFile.readAsStringSync();
indexContents = indexContents.replaceFirst('</title>\n',
'</title>\n <base href="./flutter/">\n');
@@ -163,7 +163,7 @@ void addHtmlBaseToIndex() {
}
void putRedirectInOldIndexLocation() {
String metaTag = '<meta http-equiv="refresh" content="0;URL=../index.html">';
final String metaTag = '<meta http-equiv="refresh" content="0;URL=../index.html">';
new File('$kDocRoot/flutter/index.html').writeAsStringSync(metaTag);
}
@@ -178,7 +178,7 @@ List<Directory> findPackages() {
.where((FileSystemEntity entity) {
if (entity is! Directory)
return false;
File pubspec = new File('${entity.path}/pubspec.yaml');
final File pubspec = new File('${entity.path}/pubspec.yaml');
// TODO(ianh): Use a real YAML parser here
return !pubspec.readAsStringSync().contains('nodoc: true');
})
@@ -190,7 +190,7 @@ List<Directory> findPackages() {
/// diskPath toggles between import paths vs. disk paths.
Iterable<String> libraryRefs({ bool diskPath: false }) sync* {
for (Directory dir in findPackages()) {
String dirName = path.basename(dir.path);
final String dirName = path.basename(dir.path);
for (FileSystemEntity file in new Directory('${dir.path}/lib').listSync()) {
if (file is File && file.path.endsWith('.dart')) {
if (diskPath)

View File

@@ -13,26 +13,26 @@ const String kDocRoot = 'dev/docs/doc';
/// This script downloads an archive of Javadoc for the engine from the
/// artifact store and extracts it to the location used for Dartdoc.
Future<Null> main(List<String> args) async {
String engineVersion = new File('bin/internal/engine.version').readAsStringSync().trim();
final String engineVersion = new File('bin/internal/engine.version').readAsStringSync().trim();
String url = 'https://storage.googleapis.com/flutter_infra/flutter/$engineVersion/android-javadoc.zip';
http.Response response = await http.get(url);
final String url = 'https://storage.googleapis.com/flutter_infra/flutter/$engineVersion/android-javadoc.zip';
final http.Response response = await http.get(url);
Archive archive = new ZipDecoder().decodeBytes(response.bodyBytes);
final Archive archive = new ZipDecoder().decodeBytes(response.bodyBytes);
Directory output = new Directory('$kDocRoot/javadoc');
final Directory output = new Directory('$kDocRoot/javadoc');
print('Extracing javadoc to ${output.path}');
output.createSync(recursive: true);
for (ArchiveFile af in archive) {
if (af.isFile) {
File file = new File('${output.path}/${af.name}');
final File file = new File('${output.path}/${af.name}');
file.createSync(recursive: true);
file.writeAsBytesSync(af.content);
}
}
File testFile = new File('${output.path}/io/flutter/view/FlutterView.html');
final File testFile = new File('${output.path}/io/flutter/view/FlutterView.html');
if (!testFile.existsSync()) {
print('Expected file ${testFile.path} not found');
exit(1);

View File

@@ -17,14 +17,14 @@ void main(List<String> args) {
if (path.basename(Directory.current.path) == 'tools')
Directory.current = Directory.current.parent.parent;
ArgParser argParser = new ArgParser();
final ArgParser argParser = new ArgParser();
// ../mega_gallery? dev/benchmarks/mega_gallery?
argParser.addOption('out', defaultsTo: _normalize('dev/benchmarks/mega_gallery'));
argParser.addOption('copies');
argParser.addFlag('delete', negatable: false);
argParser.addFlag('help', abbr: 'h', negatable: false);
ArgResults results = argParser.parse(args);
final ArgResults results = argParser.parse(args);
if (results['help']) {
print('Generate n copies of flutter_gallery.\n');
@@ -33,8 +33,8 @@ void main(List<String> args) {
exit(0);
}
Directory source = new Directory(_normalize('examples/flutter_gallery'));
Directory out = new Directory(_normalize(results['out']));
final Directory source = new Directory(_normalize('examples/flutter_gallery'));
final Directory out = new Directory(_normalize(results['out']));
if (results['delete']) {
if (out.existsSync()) {
@@ -47,7 +47,7 @@ void main(List<String> args) {
int copies;
if (!results.wasParsed('copies')) {
SourceStats stats = getStatsFor(_dir(source, 'lib'));
final SourceStats stats = getStatsFor(_dir(source, 'lib'));
copies = (kTargetLineCount / stats.lines).round();
} else {
copies = int.parse(results['copies']);
@@ -59,7 +59,7 @@ void main(List<String> args) {
print(' packages/flutter : ${getStatsFor(new Directory("packages/flutter"))}');
print(' examples/flutter_gallery : ${getStatsFor(new Directory("examples/flutter_gallery"))}');
Directory lib = _dir(out, 'lib');
final Directory lib = _dir(out, 'lib');
if (lib.existsSync())
lib.deleteSync(recursive: true);
@@ -86,15 +86,15 @@ void main(List<String> args) {
// TODO(devoncarew): Create an entry-point that builds a UI with all `n` copies.
void _createEntry(File mainFile, int copies) {
StringBuffer imports = new StringBuffer();
StringBuffer importRefs = new StringBuffer();
final StringBuffer imports = new StringBuffer();
final StringBuffer importRefs = new StringBuffer();
for (int i = 1; i < copies; i++) {
imports.writeln("import 'gallery_$i/main.dart' as main_$i;");
importRefs.writeln(" main_$i.main;");
}
String contents = '''
final String contents = '''
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -116,8 +116,8 @@ void main() {
}
void _copyGallery(Directory galleryDir, int index) {
Directory lib = _dir(galleryDir, 'lib');
Directory dest = _dir(lib, 'gallery_$index');
final Directory lib = _dir(galleryDir, 'lib');
final Directory dest = _dir(lib, 'gallery_$index');
dest.createSync();
// Copy demo/, gallery/, and main.dart.
@@ -131,7 +131,7 @@ void _copy(Directory source, Directory target) {
target.createSync();
for (FileSystemEntity entity in source.listSync(followLinks: false)) {
String name = path.basename(entity.path);
final String name = path.basename(entity.path);
if (entity is Directory) {
if (name == 'build' || name.startsWith('.'))
@@ -140,7 +140,7 @@ void _copy(Directory source, Directory target) {
} else if (entity is File) {
if (name == '.packages' || name == 'pubspec.lock')
continue;
File dest = new File(path.join(target.path, name));
final File dest = new File(path.join(target.path, name));
dest.writeAsBytesSync(entity.readAsBytesSync());
}
}
@@ -162,7 +162,7 @@ SourceStats getStatsFor(Directory dir, [SourceStats stats]) {
stats ??= new SourceStats();
for (FileSystemEntity entity in dir.listSync(recursive: false, followLinks: false)) {
String name = path.basename(entity.path);
final String name = path.basename(entity.path);
if (entity is File && name.endsWith('.dart')) {
stats.files += 1;
stats.lines += _lineCount(entity);
@@ -184,7 +184,7 @@ int _lineCount(File file) {
}
String _comma(int count) {
String str = count.toString();
final String str = count.toString();
if (str.length > 3)
return str.substring(0, str.length - 3) + ',' + str.substring(str.length - 3);
return str;

View File

@@ -33,26 +33,26 @@ void main(List<String> args) {
if (path.basename(Directory.current.path) == 'tools')
Directory.current = Directory.current.parent.parent;
ArgParser argParser = new ArgParser();
final ArgParser argParser = new ArgParser();
argParser.addOption(kOptionCodepointsPath, defaultsTo: kDefaultCodepointsPath);
argParser.addOption(kOptionIconsPath, defaultsTo: kDefaultIconsPath);
argParser.addFlag(kOptionDryRun, defaultsTo: false);
ArgResults argResults = argParser.parse(args);
final ArgResults argResults = argParser.parse(args);
File iconFile = new File(path.absolute(argResults[kOptionIconsPath]));
final File iconFile = new File(path.absolute(argResults[kOptionIconsPath]));
if (!iconFile.existsSync()) {
stderr.writeln('Icons file not found: ${iconFile.path}');
exit(1);
}
File codepointsFile = new File(path.absolute(argResults[kOptionCodepointsPath]));
final File codepointsFile = new File(path.absolute(argResults[kOptionCodepointsPath]));
if (!codepointsFile.existsSync()) {
stderr.writeln('Codepoints file not found: ${codepointsFile.path}');
exit(1);
}
String iconData = iconFile.readAsStringSync();
String codepointData = codepointsFile.readAsStringSync();
String newIconData = regenerateIconsFile(iconData, codepointData);
final String iconData = iconFile.readAsStringSync();
final String codepointData = codepointsFile.readAsStringSync();
final String newIconData = regenerateIconsFile(iconData, codepointData);
if (argResults[kOptionDryRun])
stdout.writeln(newIconData);
@@ -61,14 +61,14 @@ void main(List<String> args) {
}
String regenerateIconsFile(String iconData, String codepointData) {
StringBuffer buf = new StringBuffer();
final StringBuffer buf = new StringBuffer();
bool generating = false;
for (String line in LineSplitter.split(iconData)) {
if (!generating)
buf.writeln(line);
if (line.contains(kBeginGeneratedMark)) {
generating = true;
String iconDeclarations = generateIconDeclarations(codepointData);
final String iconDeclarations = generateIconDeclarations(codepointData);
buf.write(iconDeclarations);
} else if (line.contains(kEndGeneratedMark)) {
generating = false;
@@ -87,13 +87,13 @@ String generateIconDeclarations(String codepointData) {
}
String getIconDeclaration(String line) {
List<String> tokens = line.split(' ');
final List<String> tokens = line.split(' ');
if (tokens.length != 2)
throw new FormatException('Unexpected codepoint data: $line');
String name = tokens[0];
String codepoint = tokens[1];
String identifier = kIdentifierRewrites[name] ?? name;
String description = name.replaceAll('_', ' ');
final String name = tokens[0];
final String codepoint = tokens[1];
final String identifier = kIdentifierRewrites[name] ?? name;
final String description = name.replaceAll('_', ' ');
return '''
/// <p><i class="material-icons md-36">$name</i> &#x2014; material icon named "$description".</p>