Unnecessary new (#20138)
* enable lint unnecessary_new * fix tests * fix tests * fix tests
This commit is contained in:
committed by
GitHub
parent
d7a0dcaa4a
commit
d927c93310
@@ -38,13 +38,13 @@ Future<Null> main(List<String> arguments) async {
|
||||
Directory.current = Directory.current.parent.parent;
|
||||
|
||||
final ProcessResult flutter = Process.runSync('flutter', <String>[]);
|
||||
final File versionFile = new File('version');
|
||||
final File versionFile = File('version');
|
||||
if (flutter.exitCode != 0 || !versionFile.existsSync())
|
||||
throw new Exception('Failed to determine Flutter version.');
|
||||
throw Exception('Failed to determine Flutter version.');
|
||||
final String version = versionFile.readAsStringSync();
|
||||
|
||||
// Create the pubspec.yaml file.
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final StringBuffer buf = StringBuffer();
|
||||
buf.writeln('name: Flutter');
|
||||
buf.writeln('homepage: https://flutter.io');
|
||||
buf.writeln('version: $version');
|
||||
@@ -57,17 +57,17 @@ Future<Null> main(List<String> arguments) async {
|
||||
buf.writeln('dependency_overrides:');
|
||||
buf.writeln(' platform_integration:');
|
||||
buf.writeln(' path: platform_integration');
|
||||
new File('dev/docs/pubspec.yaml').writeAsStringSync(buf.toString());
|
||||
File('dev/docs/pubspec.yaml').writeAsStringSync(buf.toString());
|
||||
|
||||
// Create the library file.
|
||||
final Directory libDir = new Directory('dev/docs/lib');
|
||||
final Directory libDir = Directory('dev/docs/lib');
|
||||
libDir.createSync();
|
||||
|
||||
final StringBuffer contents = new StringBuffer('library temp_doc;\n\n');
|
||||
final StringBuffer contents = StringBuffer('library temp_doc;\n\n');
|
||||
for (String libraryRef in libraryRefs()) {
|
||||
contents.writeln('import \'package:$libraryRef\';');
|
||||
}
|
||||
new File('dev/docs/lib/temp_doc.dart').writeAsStringSync(contents.toString());
|
||||
File('dev/docs/lib/temp_doc.dart').writeAsStringSync(contents.toString());
|
||||
|
||||
final String flutterRoot = Directory.current.path;
|
||||
final Map<String, String> pubEnvironment = <String, String>{
|
||||
@@ -76,7 +76,7 @@ Future<Null> main(List<String> arguments) async {
|
||||
|
||||
// If there's a .pub-cache dir in the flutter root, use that.
|
||||
final String pubCachePath = '$flutterRoot/.pub-cache';
|
||||
if (new Directory(pubCachePath).existsSync()) {
|
||||
if (Directory(pubCachePath).existsSync()) {
|
||||
pubEnvironment['PUB_CACHE'] = pubCachePath;
|
||||
}
|
||||
|
||||
@@ -156,14 +156,14 @@ Future<Null> main(List<String> arguments) async {
|
||||
);
|
||||
printStream(process.stdout, prefix: args['json'] ? '' : 'dartdoc:stdout: ',
|
||||
filter: args['verbose'] ? const <Pattern>[] : <Pattern>[
|
||||
new RegExp(r'^generating docs for library '), // unnecessary verbosity
|
||||
new RegExp(r'^pars'), // unnecessary verbosity
|
||||
RegExp(r'^generating docs for library '), // unnecessary verbosity
|
||||
RegExp(r'^pars'), // unnecessary verbosity
|
||||
],
|
||||
);
|
||||
printStream(process.stderr, prefix: args['json'] ? '' : 'dartdoc:stderr: ',
|
||||
filter: args['verbose'] ? const <Pattern>[] : <Pattern>[
|
||||
new RegExp(r'^[ ]+warning: generic type handled as HTML:'), // https://github.com/dart-lang/dartdoc/issues/1475
|
||||
new RegExp(r'^ warning: .+: \(.+/\.pub-cache/hosted/pub.dartlang.org/.+\)'), // packages outside our control
|
||||
RegExp(r'^[ ]+warning: generic type handled as HTML:'), // https://github.com/dart-lang/dartdoc/issues/1475
|
||||
RegExp(r'^ warning: .+: \(.+/\.pub-cache/hosted/pub.dartlang.org/.+\)'), // packages outside our control
|
||||
],
|
||||
);
|
||||
final int exitCode = await process.exitCode;
|
||||
@@ -177,7 +177,7 @@ Future<Null> main(List<String> arguments) async {
|
||||
}
|
||||
|
||||
ArgParser _createArgsParser() {
|
||||
final ArgParser parser = new ArgParser();
|
||||
final ArgParser parser = ArgParser();
|
||||
parser.addFlag('help', abbr: 'h', negatable: false,
|
||||
help: 'Show command help.');
|
||||
parser.addFlag('verbose', negatable: true, defaultsTo: true,
|
||||
@@ -193,7 +193,7 @@ ArgParser _createArgsParser() {
|
||||
return parser;
|
||||
}
|
||||
|
||||
final RegExp gitBranchRegexp = new RegExp(r'^## (.*)');
|
||||
final RegExp gitBranchRegexp = RegExp(r'^## (.*)');
|
||||
|
||||
void createFooter(String footerPath) {
|
||||
const int kGitRevisionLength = 10;
|
||||
@@ -212,9 +212,9 @@ void createFooter(String footerPath) {
|
||||
|
||||
gitRevision = gitRevision.length > kGitRevisionLength ? gitRevision.substring(0, kGitRevisionLength) : gitRevision;
|
||||
|
||||
final String timestamp = new DateFormat('yyyy-MM-dd HH:mm').format(new DateTime.now());
|
||||
final String timestamp = DateFormat('yyyy-MM-dd HH:mm').format(DateTime.now());
|
||||
|
||||
new File(footerPath).writeAsStringSync(<String>[
|
||||
File(footerPath).writeAsStringSync(<String>[
|
||||
'• </span class="no-break">$timestamp<span>',
|
||||
'• </span class="no-break">$gitRevision</span>',
|
||||
gitBranchOut].join(' '));
|
||||
@@ -232,8 +232,8 @@ void sanityCheckDocs() {
|
||||
'$kDocRoot/api/widgets/Widget-class.html',
|
||||
];
|
||||
for (String canary in canaries) {
|
||||
if (!new File(canary).existsSync())
|
||||
throw new Exception('Missing "$canary", which probably means the documentation failed to build correctly.');
|
||||
if (!File(canary).existsSync())
|
||||
throw Exception('Missing "$canary", which probably means the documentation failed to build correctly.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,22 +252,22 @@ void createIndexAndCleanup() {
|
||||
|
||||
void removeOldFlutterDocsDir() {
|
||||
try {
|
||||
new Directory('$kDocRoot/flutter').deleteSync(recursive: true);
|
||||
Directory('$kDocRoot/flutter').deleteSync(recursive: true);
|
||||
} on FileSystemException {
|
||||
// If the directory does not exist, that's OK.
|
||||
}
|
||||
}
|
||||
|
||||
void renameApiDir() {
|
||||
new Directory('$kDocRoot/api').renameSync('$kDocRoot/flutter');
|
||||
Directory('$kDocRoot/api').renameSync('$kDocRoot/flutter');
|
||||
}
|
||||
|
||||
void copyIndexToRootOfDocs() {
|
||||
new File('$kDocRoot/flutter/index.html').copySync('$kDocRoot/index.html');
|
||||
File('$kDocRoot/flutter/index.html').copySync('$kDocRoot/index.html');
|
||||
}
|
||||
|
||||
void changePackageToSdkInTitlebar() {
|
||||
final File indexFile = new File('$kDocRoot/index.html');
|
||||
final File indexFile = File('$kDocRoot/index.html');
|
||||
String indexContents = indexFile.readAsStringSync();
|
||||
indexContents = indexContents.replaceFirst(
|
||||
'<li><a href="https://flutter.io">Flutter package</a></li>',
|
||||
@@ -278,7 +278,7 @@ void changePackageToSdkInTitlebar() {
|
||||
}
|
||||
|
||||
void addHtmlBaseToIndex() {
|
||||
final File indexFile = new File('$kDocRoot/index.html');
|
||||
final File indexFile = File('$kDocRoot/index.html');
|
||||
String indexContents = indexFile.readAsStringSync();
|
||||
indexContents = indexContents.replaceFirst(
|
||||
'</title>\n',
|
||||
@@ -298,7 +298,7 @@ void addHtmlBaseToIndex() {
|
||||
|
||||
void putRedirectInOldIndexLocation() {
|
||||
const String metaTag = '<meta http-equiv="refresh" content="0;URL=../index.html">';
|
||||
new File('$kDocRoot/flutter/index.html').writeAsStringSync(metaTag);
|
||||
File('$kDocRoot/flutter/index.html').writeAsStringSync(metaTag);
|
||||
}
|
||||
|
||||
List<String> findPackageNames() {
|
||||
@@ -307,12 +307,12 @@ List<String> findPackageNames() {
|
||||
|
||||
/// Finds all packages in the Flutter SDK
|
||||
List<FileSystemEntity> findPackages() {
|
||||
return new Directory('packages')
|
||||
return Directory('packages')
|
||||
.listSync()
|
||||
.where((FileSystemEntity entity) {
|
||||
if (entity is! Directory)
|
||||
return false;
|
||||
final File pubspec = new File('${entity.path}/pubspec.yaml');
|
||||
final File pubspec = File('${entity.path}/pubspec.yaml');
|
||||
// TODO(ianh): Use a real YAML parser here
|
||||
return !pubspec.readAsStringSync().contains('nodoc: true');
|
||||
})
|
||||
@@ -326,7 +326,7 @@ List<FileSystemEntity> findPackages() {
|
||||
Iterable<String> libraryRefs({ bool diskPath = false }) sync* {
|
||||
for (Directory dir in findPackages()) {
|
||||
final String dirName = path.basename(dir.path);
|
||||
for (FileSystemEntity file in new Directory('${dir.path}/lib').listSync()) {
|
||||
for (FileSystemEntity file in Directory('${dir.path}/lib').listSync()) {
|
||||
if (file is File && file.path.endsWith('.dart')) {
|
||||
if (diskPath)
|
||||
yield '$dirName/lib/${path.basename(file.path)}';
|
||||
|
||||
@@ -41,7 +41,7 @@ Future<Null> main(List<String> rawArgs) async {
|
||||
|
||||
final bool writeToFile = parseArgs(rawArgs).writeToFile;
|
||||
|
||||
final File dotPackagesFile = new File(path.join('packages', 'flutter_localizations', '.packages'));
|
||||
final File dotPackagesFile = File(path.join('packages', 'flutter_localizations', '.packages'));
|
||||
final bool dotPackagesExists = dotPackagesFile.existsSync();
|
||||
|
||||
if (!dotPackagesExists) {
|
||||
@@ -64,12 +64,12 @@ Future<Null> main(List<String> rawArgs) async {
|
||||
.split(':')
|
||||
.last;
|
||||
|
||||
final Directory dateSymbolsDirectory = new Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'symbols'));
|
||||
final Directory dateSymbolsDirectory = Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'symbols'));
|
||||
final Map<String, File> symbolFiles = _listIntlData(dateSymbolsDirectory);
|
||||
final Directory datePatternsDirectory = new Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'patterns'));
|
||||
final Directory datePatternsDirectory = Directory(path.join(pathToIntl, 'src', 'data', 'dates', 'patterns'));
|
||||
final Map<String, File> patternFiles = _listIntlData(datePatternsDirectory);
|
||||
final List<String> materialLocales = _materialLocales().toList();
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
|
||||
buffer.writeln(
|
||||
'''
|
||||
@@ -108,7 +108,7 @@ Future<Null> main(List<String> rawArgs) async {
|
||||
buffer.writeln('};');
|
||||
|
||||
if (writeToFile) {
|
||||
final File dateLocalizationsFile = new File(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'date_localizations.dart'));
|
||||
final File dateLocalizationsFile = File(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'date_localizations.dart'));
|
||||
dateLocalizationsFile.writeAsStringSync(buffer.toString());
|
||||
Process.runSync(path.join('bin', 'cache', 'dart-sdk', 'bin', 'dartfmt'), <String>[
|
||||
'-w',
|
||||
@@ -138,7 +138,7 @@ String _jsonToMap(dynamic json) {
|
||||
return '<dynamic>[${json.map(_jsonToMap).join(',')}]';
|
||||
|
||||
if (json is Map<String, dynamic>) {
|
||||
final StringBuffer buffer = new StringBuffer('<String, dynamic>{');
|
||||
final StringBuffer buffer = StringBuffer('<String, dynamic>{');
|
||||
json.forEach((String key, dynamic value) {
|
||||
buffer.writeln(_jsonToMapEntry(key, value));
|
||||
});
|
||||
@@ -150,8 +150,8 @@ String _jsonToMap(dynamic json) {
|
||||
}
|
||||
|
||||
Iterable<String> _materialLocales() sync* {
|
||||
final RegExp filenameRE = new RegExp(r'material_(\w+)\.arb$');
|
||||
final Directory materialLocalizationsDirectory = new Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
|
||||
final RegExp filenameRE = RegExp(r'material_(\w+)\.arb$');
|
||||
final Directory materialLocalizationsDirectory = Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
|
||||
for (FileSystemEntity entity in materialLocalizationsDirectory.listSync()) {
|
||||
final String filePath = entity.path;
|
||||
if (FileSystemEntity.isFileSync(filePath) && filenameRE.hasMatch(filePath))
|
||||
@@ -171,5 +171,5 @@ Map<String, File> _listIntlData(Directory directory) {
|
||||
|
||||
final List<String> locales = localeFiles.keys.toList(growable: false);
|
||||
locales.sort();
|
||||
return new Map<String, File>.fromIterable(locales, value: (dynamic locale) => localeFiles[locale]);
|
||||
return Map<String, File>.fromIterable(locales, value: (dynamic locale) => localeFiles[locale]);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ String generateString(String s) {
|
||||
if (!s.contains("'"))
|
||||
return "r'$s'";
|
||||
|
||||
final StringBuffer output = new StringBuffer();
|
||||
final StringBuffer output = StringBuffer();
|
||||
bool started = false; // Have we started writing a raw string.
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
if (s[i] == "'") {
|
||||
@@ -108,11 +108,11 @@ String generateString(String s) {
|
||||
|
||||
/// This is the core of this script; it generates the code used for translations.
|
||||
String generateTranslationBundles() {
|
||||
final StringBuffer output = new StringBuffer();
|
||||
final StringBuffer supportedLocales = new StringBuffer();
|
||||
final StringBuffer output = StringBuffer();
|
||||
final StringBuffer supportedLocales = StringBuffer();
|
||||
|
||||
final Map<String, List<String>> languageToLocales = <String, List<String>>{};
|
||||
final Set<String> allResourceIdentifiers = new Set<String>();
|
||||
final Set<String> allResourceIdentifiers = Set<String>();
|
||||
for (String locale in localeToResources.keys.toList()..sort()) {
|
||||
final List<String> codes = locale.split('_'); // [language, country]
|
||||
assert(codes.length == 1 || codes.length == 2);
|
||||
@@ -201,7 +201,7 @@ String generateTranslationBundles() {
|
||||
/// See also:
|
||||
///
|
||||
/// * [getTranslation], whose documentation describes these values.
|
||||
final Set<String> kSupportedLanguages = new HashSet<String>.from(const <String>[
|
||||
final Set<String> kSupportedLanguages = HashSet<String>.from(const <String>[
|
||||
${languageCodes.map((String value) => " '$value', // ${describeLocale(value)}").toList().join('\n')}
|
||||
]);
|
||||
|
||||
@@ -234,7 +234,7 @@ GlobalMaterialLocalizations getTranslation(
|
||||
if (languageToLocales[language].length == 1) {
|
||||
output.writeln('''
|
||||
case '$language':
|
||||
return new MaterialLocalization${camelCase(languageToLocales[language][0])}($arguments);''');
|
||||
return MaterialLocalization${camelCase(languageToLocales[language][0])}($arguments);''');
|
||||
} else {
|
||||
output.writeln('''
|
||||
case '$language': {
|
||||
@@ -246,11 +246,11 @@ GlobalMaterialLocalizations getTranslation(
|
||||
final String countryCode = localeName.substring(localeName.indexOf('_') + 1);
|
||||
output.writeln('''
|
||||
case '$countryCode':
|
||||
return new MaterialLocalization${camelCase(localeName)}($arguments);''');
|
||||
return MaterialLocalization${camelCase(localeName)}($arguments);''');
|
||||
}
|
||||
output.writeln('''
|
||||
}
|
||||
return new MaterialLocalization${camelCase(language)}($arguments);
|
||||
return MaterialLocalization${camelCase(language)}($arguments);
|
||||
}''');
|
||||
}
|
||||
}
|
||||
@@ -323,7 +323,7 @@ String generateValue(String value, Map<String, dynamic> attributes) {
|
||||
switch (attributes['x-flutter-type']) {
|
||||
case 'icuShortTimePattern':
|
||||
if (!_icuTimeOfDayToEnum.containsKey(value)) {
|
||||
throw new Exception(
|
||||
throw Exception(
|
||||
'"$value" is not one of the ICU short time patterns supported '
|
||||
'by the material library. Here is the list of supported '
|
||||
'patterns:\n ' + _icuTimeOfDayToEnum.keys.join('\n ')
|
||||
@@ -399,11 +399,11 @@ Future<void> main(List<String> rawArgs) async {
|
||||
// is the 2nd command line argument, lc is a language code and cc is the country
|
||||
// code. In most cases both codes are just two characters.
|
||||
|
||||
final Directory directory = new Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
|
||||
final RegExp filenameRE = new RegExp(r'material_(\w+)\.arb$');
|
||||
final Directory directory = Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
|
||||
final RegExp filenameRE = RegExp(r'material_(\w+)\.arb$');
|
||||
|
||||
try {
|
||||
validateEnglishLocalizations(new File(path.join(directory.path, 'material_en.arb')));
|
||||
validateEnglishLocalizations(File(path.join(directory.path, 'material_en.arb')));
|
||||
} on ValidationError catch (exception) {
|
||||
exitWithError('$exception');
|
||||
}
|
||||
@@ -413,7 +413,7 @@ Future<void> main(List<String> rawArgs) async {
|
||||
for (FileSystemEntity entity in directory.listSync()) {
|
||||
final String entityPath = entity.path;
|
||||
if (FileSystemEntity.isFileSync(entityPath) && filenameRE.hasMatch(entityPath)) {
|
||||
processBundle(new File(entityPath), locale: filenameRE.firstMatch(entityPath)[1]);
|
||||
processBundle(File(entityPath), locale: filenameRE.firstMatch(entityPath)[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,12 +423,12 @@ Future<void> main(List<String> rawArgs) async {
|
||||
exitWithError('$exception');
|
||||
}
|
||||
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.writeln(outputHeader.replaceFirst('@(regenerate)', 'dart dev/tools/gen_localizations.dart --overwrite'));
|
||||
buffer.write(generateTranslationBundles());
|
||||
|
||||
if (options.writeToFile) {
|
||||
final File localizationsFile = new File(path.join(directory.path, 'localizations.dart'));
|
||||
final File localizationsFile = File(path.join(directory.path, 'localizations.dart'));
|
||||
localizationsFile.writeAsStringSync(buffer.toString());
|
||||
} else {
|
||||
stdout.write(buffer.toString());
|
||||
|
||||
@@ -13,7 +13,7 @@ const String kDocRoot = 'dev/docs/doc';
|
||||
/// This script downloads an archive of Javadoc and objc doc for the engine from
|
||||
/// the artifact store and extracts them to the location used for Dartdoc.
|
||||
Future<Null> main(List<String> args) async {
|
||||
final String engineVersion = new File('bin/internal/engine.version').readAsStringSync().trim();
|
||||
final String engineVersion = File('bin/internal/engine.version').readAsStringSync().trim();
|
||||
|
||||
final String javadocUrl = 'https://storage.googleapis.com/flutter_infra/flutter/$engineVersion/android-javadoc.zip';
|
||||
generateDocs(javadocUrl, 'javadoc', 'io/flutter/view/FlutterView.html');
|
||||
@@ -25,21 +25,21 @@ Future<Null> main(List<String> args) async {
|
||||
Future<Null> generateDocs(String url, String docName, String checkFile) async {
|
||||
final http.Response response = await http.get(url);
|
||||
|
||||
final Archive archive = new ZipDecoder().decodeBytes(response.bodyBytes);
|
||||
final Archive archive = ZipDecoder().decodeBytes(response.bodyBytes);
|
||||
|
||||
final Directory output = new Directory('$kDocRoot/$docName');
|
||||
final Directory output = Directory('$kDocRoot/$docName');
|
||||
print('Extracting $docName to ${output.path}');
|
||||
output.createSync(recursive: true);
|
||||
|
||||
for (ArchiveFile af in archive) {
|
||||
if (af.isFile) {
|
||||
final File file = new File('${output.path}/${af.name}');
|
||||
final File file = File('${output.path}/${af.name}');
|
||||
file.createSync(recursive: true);
|
||||
file.writeAsBytesSync(af.content);
|
||||
}
|
||||
}
|
||||
|
||||
final File testFile = new File('${output.path}/$checkFile');
|
||||
final File testFile = File('${output.path}/$checkFile');
|
||||
if (!testFile.existsSync()) {
|
||||
print('Expected file ${testFile.path} not found');
|
||||
exit(1);
|
||||
|
||||
@@ -24,7 +24,7 @@ const String kHelp = 'help';
|
||||
const String kUpstreamRemote = 'git@github.com:flutter/flutter.git';
|
||||
|
||||
void main(List<String> args) {
|
||||
final ArgParser argParser = new ArgParser(allowTrailingOptions: false);
|
||||
final ArgParser argParser = ArgParser(allowTrailingOptions: false);
|
||||
argParser.addOption(
|
||||
kIncrement,
|
||||
help: 'Specifies which part of the x.y.z version number to increment. Required.',
|
||||
@@ -168,7 +168,7 @@ String getFullTag() {
|
||||
}
|
||||
|
||||
Match parseFullTag(String version) {
|
||||
final RegExp versionPattern = new RegExp('^v([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)-g([a-f0-9]+)\$');
|
||||
final RegExp versionPattern = RegExp('^v([0-9]+)\.([0-9]+)\.([0-9]+)-([0-9]+)-g([a-f0-9]+)\$');
|
||||
return versionPattern.matchAsPrefix(version);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ void exitWithError(String errorMessage) {
|
||||
}
|
||||
|
||||
void checkCwdIsRepoRoot(String commandName) {
|
||||
final bool isRepoRoot = new Directory('.git').existsSync();
|
||||
final bool isRepoRoot = Directory('.git').existsSync();
|
||||
|
||||
if (!isRepoRoot) {
|
||||
exitWithError(
|
||||
@@ -34,7 +34,7 @@ String camelCase(String locale) {
|
||||
}
|
||||
|
||||
GeneratorOptions parseArgs(List<String> rawArgs) {
|
||||
final argslib.ArgParser argParser = new argslib.ArgParser()
|
||||
final argslib.ArgParser argParser = argslib.ArgParser()
|
||||
..addFlag(
|
||||
'overwrite',
|
||||
abbr: 'w',
|
||||
@@ -43,7 +43,7 @@ GeneratorOptions parseArgs(List<String> rawArgs) {
|
||||
final argslib.ArgResults args = argParser.parse(rawArgs);
|
||||
final bool writeToFile = args['overwrite'];
|
||||
|
||||
return new GeneratorOptions(writeToFile: writeToFile);
|
||||
return GeneratorOptions(writeToFile: writeToFile);
|
||||
}
|
||||
|
||||
class GeneratorOptions {
|
||||
@@ -88,7 +88,7 @@ const String kParentheticalPrefix = ' (';
|
||||
///
|
||||
/// The data is obtained from the official IANA registry.
|
||||
Future<void> precacheLanguageAndRegionTags() async {
|
||||
final HttpClient client = new HttpClient();
|
||||
final HttpClient client = HttpClient();
|
||||
final HttpClientRequest request = await client.getUrl(Uri.parse(registry));
|
||||
final HttpClientResponse response = await request.close();
|
||||
final String body = (await response.transform(utf8.decoder).toList()).join('');
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'dart:io';
|
||||
// The first suffix in kPluralSuffixes must be "Other". "Other" is special
|
||||
// because it's the only one that is required.
|
||||
const List<String> kPluralSuffixes = <String>['Other', 'Zero', 'One', 'Two', 'Few', 'Many'];
|
||||
final RegExp kPluralRegexp = new RegExp(r'(\w*)(' + kPluralSuffixes.skip(1).join(r'|') + r')$');
|
||||
final RegExp kPluralRegexp = RegExp(r'(\w*)(' + kPluralSuffixes.skip(1).join(r'|') + r')$');
|
||||
|
||||
class ValidationError implements Exception {
|
||||
ValidationError(this. message);
|
||||
@@ -28,11 +28,11 @@ class ValidationError implements Exception {
|
||||
///
|
||||
/// Throws an exception upon failure.
|
||||
void validateEnglishLocalizations(File file) {
|
||||
final StringBuffer errorMessages = new StringBuffer();
|
||||
final StringBuffer errorMessages = StringBuffer();
|
||||
|
||||
if (!file.existsSync()) {
|
||||
errorMessages.writeln('English localizations do not exist: $file');
|
||||
throw new ValidationError(errorMessages.toString());
|
||||
throw ValidationError(errorMessages.toString());
|
||||
}
|
||||
|
||||
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync());
|
||||
@@ -83,7 +83,7 @@ void validateEnglishLocalizations(File file) {
|
||||
}
|
||||
|
||||
if (errorMessages.isNotEmpty)
|
||||
throw new ValidationError(errorMessages.toString());
|
||||
throw ValidationError(errorMessages.toString());
|
||||
}
|
||||
|
||||
/// Enforces the following invariants in our localizations:
|
||||
@@ -100,8 +100,8 @@ void validateLocalizations(
|
||||
Map<String, Map<String, dynamic>> localeToAttributes,
|
||||
) {
|
||||
final Map<String, String> canonicalLocalizations = localeToResources['en'];
|
||||
final Set<String> canonicalKeys = new Set<String>.from(canonicalLocalizations.keys);
|
||||
final StringBuffer errorMessages = new StringBuffer();
|
||||
final Set<String> canonicalKeys = Set<String>.from(canonicalLocalizations.keys);
|
||||
final StringBuffer errorMessages = StringBuffer();
|
||||
bool explainMissingKeys = false;
|
||||
for (final String locale in localeToResources.keys) {
|
||||
final Map<String, String> resources = localeToResources[locale];
|
||||
@@ -119,7 +119,7 @@ void validateLocalizations(
|
||||
return resources.containsKey('${prefix}Other');
|
||||
}
|
||||
|
||||
final Set<String> keys = new Set<String>.from(
|
||||
final Set<String> keys = Set<String>.from(
|
||||
resources.keys.where((String key) => !isPluralVariation(key))
|
||||
);
|
||||
|
||||
@@ -161,6 +161,6 @@ void validateLocalizations(
|
||||
..writeln(' "notUsed": "Sindhi time format does not use a.m. indicator"')
|
||||
..writeln('}');
|
||||
}
|
||||
throw new ValidationError(errorMessages.toString());
|
||||
throw ValidationError(errorMessages.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ void main(List<String> args) {
|
||||
if (path.basename(Directory.current.path) == 'tools')
|
||||
Directory.current = Directory.current.parent.parent;
|
||||
|
||||
final ArgParser argParser = new ArgParser();
|
||||
final ArgParser argParser = ArgParser();
|
||||
argParser.addOption('out');
|
||||
argParser.addOption('copies');
|
||||
argParser.addFlag('delete', negatable: false);
|
||||
@@ -32,8 +32,8 @@ void main(List<String> args) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
final Directory source = new Directory(_normalize('examples/flutter_gallery'));
|
||||
final Directory out = new Directory(_normalize(results['out']));
|
||||
final Directory source = Directory(_normalize('examples/flutter_gallery'));
|
||||
final Directory out = Directory(_normalize(results['out']));
|
||||
|
||||
if (results['delete']) {
|
||||
if (out.existsSync()) {
|
||||
@@ -61,8 +61,8 @@ void main(List<String> args) {
|
||||
print('Making $copies copies of flutter_gallery.');
|
||||
print('');
|
||||
print('Stats:');
|
||||
print(' packages/flutter : ${getStatsFor(new Directory("packages/flutter"))}');
|
||||
print(' examples/flutter_gallery : ${getStatsFor(new Directory("examples/flutter_gallery"))}');
|
||||
print(' packages/flutter : ${getStatsFor(Directory("packages/flutter"))}');
|
||||
print(' examples/flutter_gallery : ${getStatsFor(Directory("examples/flutter_gallery"))}');
|
||||
|
||||
final Directory lib = _dir(out, 'lib');
|
||||
if (lib.existsSync())
|
||||
@@ -91,7 +91,7 @@ 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) {
|
||||
final StringBuffer imports = new StringBuffer();
|
||||
final StringBuffer imports = StringBuffer();
|
||||
|
||||
for (int i = 1; i < copies; i++) {
|
||||
imports.writeln('// ignore: unused_import');
|
||||
@@ -137,18 +137,18 @@ void _copy(Directory source, Directory target) {
|
||||
if (entity is Directory) {
|
||||
if (name == 'build' || name.startsWith('.'))
|
||||
continue;
|
||||
_copy(entity, new Directory(path.join(target.path, name)));
|
||||
_copy(entity, Directory(path.join(target.path, name)));
|
||||
} else if (entity is File) {
|
||||
if (name == '.packages' || name == 'pubspec.lock')
|
||||
continue;
|
||||
final File dest = new File(path.join(target.path, name));
|
||||
final File dest = File(path.join(target.path, name));
|
||||
dest.writeAsBytesSync(entity.readAsBytesSync());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Directory _dir(Directory parent, String name) => new Directory(path.join(parent.path, name));
|
||||
File _file(Directory parent, String name) => new File(path.join(parent.path, name));
|
||||
Directory _dir(Directory parent, String name) => Directory(path.join(parent.path, name));
|
||||
File _file(Directory parent, String name) => File(path.join(parent.path, name));
|
||||
String _normalize(String filePath) => path.normalize(path.absolute(filePath));
|
||||
|
||||
class SourceStats {
|
||||
@@ -160,7 +160,7 @@ class SourceStats {
|
||||
}
|
||||
|
||||
SourceStats getStatsFor(Directory dir, [SourceStats stats]) {
|
||||
stats ??= new SourceStats();
|
||||
stats ??= SourceStats();
|
||||
|
||||
for (FileSystemEntity entity in dir.listSync(recursive: false, followLinks: false)) {
|
||||
final String name = path.basename(entity.path);
|
||||
|
||||
@@ -71,7 +71,7 @@ const Map<String, String> kIdentifierRewrites = <String, String>{
|
||||
|
||||
};
|
||||
|
||||
final Set<String> kMirroredIcons = new Set<String>.from(<String>[
|
||||
final Set<String> kMirroredIcons = Set<String>.from(<String>[
|
||||
// This list is obtained from:
|
||||
// http://google.github.io/material-design-icons/#icons-in-rtl
|
||||
'arrow_back',
|
||||
@@ -152,18 +152,18 @@ void main(List<String> args) {
|
||||
if (path.basename(Directory.current.path) == 'tools')
|
||||
Directory.current = Directory.current.parent.parent;
|
||||
|
||||
final ArgParser argParser = new ArgParser();
|
||||
final ArgParser argParser = ArgParser();
|
||||
argParser.addOption(kOptionCodepointsPath, defaultsTo: kDefaultCodepointsPath);
|
||||
argParser.addOption(kOptionIconsPath, defaultsTo: kDefaultIconsPath);
|
||||
argParser.addFlag(kOptionDryRun, defaultsTo: false);
|
||||
final ArgResults argResults = argParser.parse(args);
|
||||
|
||||
final File iconFile = new File(path.absolute(argResults[kOptionIconsPath]));
|
||||
final File iconFile = File(path.absolute(argResults[kOptionIconsPath]));
|
||||
if (!iconFile.existsSync()) {
|
||||
stderr.writeln('Icons file not found: ${iconFile.path}');
|
||||
exit(1);
|
||||
}
|
||||
final File codepointsFile = new File(path.absolute(argResults[kOptionCodepointsPath]));
|
||||
final File codepointsFile = File(path.absolute(argResults[kOptionCodepointsPath]));
|
||||
if (!codepointsFile.existsSync()) {
|
||||
stderr.writeln('Codepoints file not found: ${codepointsFile.path}');
|
||||
exit(1);
|
||||
@@ -180,7 +180,7 @@ void main(List<String> args) {
|
||||
}
|
||||
|
||||
String regenerateIconsFile(String iconData, String codepointData) {
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final StringBuffer buf = StringBuffer();
|
||||
bool generating = false;
|
||||
for (String line in LineSplitter.split(iconData)) {
|
||||
if (!generating)
|
||||
@@ -208,7 +208,7 @@ String generateIconDeclarations(String codepointData) {
|
||||
String getIconDeclaration(String line) {
|
||||
final List<String> tokens = line.split(' ');
|
||||
if (tokens.length != 2)
|
||||
throw new FormatException('Unexpected codepoint data: $line');
|
||||
throw FormatException('Unexpected codepoint data: $line');
|
||||
final String name = tokens[0];
|
||||
final String codepoint = tokens[1];
|
||||
final String identifier = kIdentifierRewrites[name] ?? name;
|
||||
|
||||
@@ -12,7 +12,7 @@ const String kCodegenComment =
|
||||
'// This file was generated by vitool.\n';
|
||||
|
||||
void main(List<String> args) {
|
||||
final ArgParser parser = new ArgParser();
|
||||
final ArgParser parser = ArgParser();
|
||||
|
||||
parser.addFlag(
|
||||
'help',
|
||||
@@ -70,10 +70,10 @@ void main(List<String> args) {
|
||||
frames.add(data);
|
||||
}
|
||||
|
||||
final StringBuffer generatedSb = new StringBuffer();
|
||||
final StringBuffer generatedSb = StringBuffer();
|
||||
|
||||
if (argResults.wasParsed('header')) {
|
||||
generatedSb.write(new File(argResults['header']).readAsStringSync());
|
||||
generatedSb.write(File(argResults['header']).readAsStringSync());
|
||||
generatedSb.write('\n');
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@ void main(List<String> args) {
|
||||
if (argResults.wasParsed('part-of'))
|
||||
generatedSb.write('part of ${argResults['part-of']};\n');
|
||||
|
||||
final Animation animation = new Animation.fromFrameData(frames);
|
||||
final Animation animation = Animation.fromFrameData(frames);
|
||||
generatedSb.write(animation.toDart('_AnimatedIconData', argResults['asset-name']));
|
||||
|
||||
final File outFile = new File(argResults['output']);
|
||||
final File outFile = File(argResults['output']);
|
||||
outFile.writeAsStringSync(generatedSb.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class Animation {
|
||||
final Point<double> size = frames[0].size;
|
||||
final List<PathAnimation> paths = <PathAnimation>[];
|
||||
for (int i = 0; i < frames[0].paths.length; i += 1) {
|
||||
paths.add(new PathAnimation.fromFrameData(frames, i));
|
||||
paths.add(PathAnimation.fromFrameData(frames, i));
|
||||
}
|
||||
return new Animation(size, paths);
|
||||
return Animation(size, paths);
|
||||
}
|
||||
|
||||
/// The size of the animation (width, height) in pixels.
|
||||
@@ -40,13 +40,13 @@ class Animation {
|
||||
for (int i = 0; i < frames.length; i += 1) {
|
||||
final FrameData frame = frames[i];
|
||||
if (size != frame.size)
|
||||
throw new Exception(
|
||||
throw Exception(
|
||||
'All animation frames must have the same size,\n'
|
||||
'first frame size was: (${size.x}, ${size.y})\n'
|
||||
'frame $i size was: (${frame.size.x}, ${frame.size.y})'
|
||||
);
|
||||
if (numPaths != frame.paths.length)
|
||||
throw new Exception(
|
||||
throw Exception(
|
||||
'All animation frames must have the same number of paths,\n'
|
||||
'first frame has $numPaths paths\n'
|
||||
'frame $i has ${frame.paths.length} paths'
|
||||
@@ -55,7 +55,7 @@ class Animation {
|
||||
}
|
||||
|
||||
String toDart(String className, String varName) {
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final StringBuffer sb = StringBuffer();
|
||||
sb.write('const $className $varName = const $className(\n');
|
||||
sb.write('${kIndent}const Size(${size.x}, ${size.y}),\n');
|
||||
sb.write('${kIndent}const <_PathFrames>[\n');
|
||||
@@ -78,7 +78,7 @@ class PathAnimation {
|
||||
final List<PathCommandAnimation> commands = <PathCommandAnimation>[];
|
||||
for (int commandIdx = 0; commandIdx < frames[0].paths[pathIdx].commands.length; commandIdx += 1) {
|
||||
final int numPointsInCommand = frames[0].paths[pathIdx].commands[commandIdx].points.length;
|
||||
final List<List<Point<double>>> points = new List<List<Point<double>>>(numPointsInCommand);
|
||||
final List<List<Point<double>>> points = List<List<Point<double>>>(numPointsInCommand);
|
||||
for (int j = 0; j < numPointsInCommand; j += 1)
|
||||
points[j] = <Point<double>>[];
|
||||
final String commandType = frames[0].paths[pathIdx].commands[commandIdx].type;
|
||||
@@ -86,7 +86,7 @@ class PathAnimation {
|
||||
final FrameData frame = frames[i];
|
||||
final String currentCommandType = frame.paths[pathIdx].commands[commandIdx].type;
|
||||
if (commandType != currentCommandType)
|
||||
throw new Exception(
|
||||
throw Exception(
|
||||
'Paths must be built from the same commands in all frames'
|
||||
'command $commandIdx at frame 0 was of type \'$commandType\''
|
||||
'command $commandIdx at frame $i was of type \'$currentCommandType\''
|
||||
@@ -94,13 +94,13 @@ class PathAnimation {
|
||||
for (int j = 0; j < numPointsInCommand; j += 1)
|
||||
points[j].add(frame.paths[pathIdx].commands[commandIdx].points[j]);
|
||||
}
|
||||
commands.add(new PathCommandAnimation(commandType, points));
|
||||
commands.add(PathCommandAnimation(commandType, points));
|
||||
}
|
||||
|
||||
final List<double> opacities =
|
||||
frames.map<double>((FrameData d) => d.paths[pathIdx].opacity).toList();
|
||||
|
||||
return new PathAnimation(commands, opacities: opacities);
|
||||
return PathAnimation(commands, opacities: opacities);
|
||||
}
|
||||
|
||||
/// List of commands for drawing the path.
|
||||
@@ -114,7 +114,7 @@ class PathAnimation {
|
||||
}
|
||||
|
||||
String toDart() {
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final StringBuffer sb = StringBuffer();
|
||||
sb.write('${kIndent * 2}const _PathFrames(\n');
|
||||
sb.write('${kIndent * 3}opacities: const <double>[\n');
|
||||
for (double opacity in opacities)
|
||||
@@ -162,9 +162,9 @@ class PathCommandAnimation {
|
||||
dartCommandClass = '_PathClose';
|
||||
break;
|
||||
default:
|
||||
throw new Exception('unsupported path command: $type');
|
||||
throw Exception('unsupported path command: $type');
|
||||
}
|
||||
final StringBuffer sb = new StringBuffer();
|
||||
final StringBuffer sb = StringBuffer();
|
||||
sb.write('${kIndent * 4}const $dartCommandClass(\n');
|
||||
for (List<Point<double>> pointFrames in points) {
|
||||
sb.write('${kIndent * 5}const <Offset>[\n');
|
||||
@@ -188,15 +188,15 @@ class PathCommandAnimation {
|
||||
/// support SVG files exported by a specific tool the motion design team is
|
||||
/// using.
|
||||
FrameData interpretSvg(String svgFilePath) {
|
||||
final File file = new File(svgFilePath);
|
||||
final File file = File(svgFilePath);
|
||||
final String fileData = file.readAsStringSync();
|
||||
final XmlElement svgElement = _extractSvgElement(xml.parse(fileData));
|
||||
final double width = parsePixels(_extractAttr(svgElement, 'width')).toDouble();
|
||||
final double height = parsePixels(_extractAttr(svgElement, 'height')).toDouble();
|
||||
|
||||
final List<SvgPath> paths =
|
||||
_interpretSvgGroup(svgElement.children, new _Transform());
|
||||
return new FrameData(new Point<double>(width, height), paths);
|
||||
_interpretSvgGroup(svgElement.children, _Transform());
|
||||
return FrameData(Point<double>(width, height), paths);
|
||||
}
|
||||
|
||||
List<SvgPath> _interpretSvgGroup(List<XmlNode> children, _Transform transform) {
|
||||
@@ -220,7 +220,7 @@ List<SvgPath> _interpretSvgGroup(List<XmlNode> children, _Transform transform) {
|
||||
transformMatrix = transformMatrix.multiplied(
|
||||
_parseSvgTransform(_extractAttr(element, 'transform')));
|
||||
|
||||
final _Transform subtreeTransform = new _Transform(
|
||||
final _Transform subtreeTransform = _Transform(
|
||||
transformMatrix: transformMatrix,
|
||||
opacity: opacity
|
||||
);
|
||||
@@ -238,7 +238,7 @@ List<SvgPath> _interpretSvgGroup(List<XmlNode> children, _Transform transform) {
|
||||
// group 3 will match "12.0, 12.0 23.0, 9.0"
|
||||
//
|
||||
// Commas are optional.
|
||||
final RegExp _pointMatcher = new RegExp(r'^ *([\-\.0-9]+) *,? *([\-\.0-9]+)(.*)');
|
||||
final RegExp _pointMatcher = RegExp(r'^ *([\-\.0-9]+) *,? *([\-\.0-9]+)(.*)');
|
||||
|
||||
/// Parse a string with a list of points, e.g:
|
||||
/// '25.0, 1.0 12.0, 12.0 23.0, 9.0' will be parsed to:
|
||||
@@ -250,7 +250,7 @@ List<Point<double>> parsePoints(String points) {
|
||||
final List<Point<double>> result = <Point<double>>[];
|
||||
while (unParsed.isNotEmpty && _pointMatcher.hasMatch(unParsed)) {
|
||||
final Match m = _pointMatcher.firstMatch(unParsed);
|
||||
result.add(new Point<double>(
|
||||
result.add(Point<double>(
|
||||
double.parse(m.group(1)),
|
||||
double.parse(m.group(2))
|
||||
));
|
||||
@@ -293,29 +293,29 @@ class SvgPath {
|
||||
final double opacity;
|
||||
|
||||
static const String _pathCommandAtom = ' *([a-zA-Z]) *([\-\.0-9 ,]*)';
|
||||
static final RegExp _pathCommandValidator = new RegExp('^($_pathCommandAtom)*\$');
|
||||
static final RegExp _pathCommandMatcher = new RegExp(_pathCommandAtom);
|
||||
static final RegExp _pathCommandValidator = RegExp('^($_pathCommandAtom)*\$');
|
||||
static final RegExp _pathCommandMatcher = RegExp(_pathCommandAtom);
|
||||
|
||||
static SvgPath fromElement(XmlElement pathElement) {
|
||||
assert(pathElement.name.local == 'path');
|
||||
final String id = _extractAttr(pathElement, 'id');
|
||||
final String dAttr = _extractAttr(pathElement, 'd');
|
||||
final List<SvgPathCommand> commands = <SvgPathCommand>[];
|
||||
final SvgPathCommandBuilder commandsBuilder = new SvgPathCommandBuilder();
|
||||
final SvgPathCommandBuilder commandsBuilder = SvgPathCommandBuilder();
|
||||
if (!_pathCommandValidator.hasMatch(dAttr))
|
||||
throw new Exception('illegal or unsupported path d expression: $dAttr');
|
||||
throw Exception('illegal or unsupported path d expression: $dAttr');
|
||||
for (Match match in _pathCommandMatcher.allMatches(dAttr)) {
|
||||
final String commandType = match.group(1);
|
||||
final String pointStr = match.group(2);
|
||||
commands.add(commandsBuilder.build(commandType, parsePoints(pointStr)));
|
||||
}
|
||||
return new SvgPath(id, commands);
|
||||
return SvgPath(id, commands);
|
||||
}
|
||||
|
||||
SvgPath applyTransform(_Transform transform) {
|
||||
final List<SvgPathCommand> transformedCommands =
|
||||
commands.map((SvgPathCommand c) => c.applyTransform(transform)).toList();
|
||||
return new SvgPath(id, transformedCommands, opacity: opacity * transform.opacity);
|
||||
return SvgPath(id, transformedCommands, opacity: opacity * transform.opacity);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -364,7 +364,7 @@ class SvgPathCommand {
|
||||
_pointsToVector3Array(points)
|
||||
)
|
||||
);
|
||||
return new SvgPathCommand(type, transformedPoints);
|
||||
return SvgPathCommand(type, transformedPoints);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -411,7 +411,7 @@ class SvgPathCommandBuilder {
|
||||
else
|
||||
lastPoint = absPoints.last;
|
||||
|
||||
return new SvgPathCommand(type.toUpperCase(), absPoints);
|
||||
return SvgPathCommand(type.toUpperCase(), absPoints);
|
||||
}
|
||||
|
||||
static bool _isRelativeCommand(String type) {
|
||||
@@ -420,7 +420,7 @@ class SvgPathCommandBuilder {
|
||||
}
|
||||
|
||||
List<double> _pointsToVector3Array(List<Point<double>> points) {
|
||||
final List<double> result = new List<double>(points.length * 3);
|
||||
final List<double> result = List<double>(points.length * 3);
|
||||
for (int i = 0; i < points.length; i += 1) {
|
||||
result[i * 3] = points[i].x;
|
||||
result[i * 3 + 1] = points[i].y;
|
||||
@@ -431,9 +431,9 @@ List<double> _pointsToVector3Array(List<Point<double>> points) {
|
||||
|
||||
List<Point<double>> _vector3ArrayToPoints(List<double> vector) {
|
||||
final int numPoints = (vector.length / 3).floor();
|
||||
final List<Point<double>> points = new List<Point<double>>(numPoints);
|
||||
final List<Point<double>> points = List<Point<double>>(numPoints);
|
||||
for (int i = 0; i < numPoints; i += 1) {
|
||||
points[i] = new Point<double>(vector[i*3], vector[i*3 + 1]);
|
||||
points[i] = Point<double>(vector[i*3], vector[i*3 + 1]);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
@@ -446,13 +446,13 @@ class _Transform {
|
||||
|
||||
/// Constructs a new _Transform, default arguments create a no-op transform.
|
||||
_Transform({Matrix3 transformMatrix, this.opacity = 1.0}) :
|
||||
this.transformMatrix = transformMatrix ?? new Matrix3.identity();
|
||||
this.transformMatrix = transformMatrix ?? Matrix3.identity();
|
||||
|
||||
final Matrix3 transformMatrix;
|
||||
final double opacity;
|
||||
|
||||
_Transform applyTransform(_Transform transform) {
|
||||
return new _Transform(
|
||||
return _Transform(
|
||||
transformMatrix: transform.transformMatrix.multiplied(transformMatrix),
|
||||
opacity: transform.opacity * opacity,
|
||||
);
|
||||
@@ -461,14 +461,14 @@ class _Transform {
|
||||
|
||||
|
||||
const String _transformCommandAtom = ' *([^(]+)\\(([^)]*)\\)';
|
||||
final RegExp _transformValidator = new RegExp('^($_transformCommandAtom)*\$');
|
||||
final RegExp _transformCommand = new RegExp(_transformCommandAtom);
|
||||
final RegExp _transformValidator = RegExp('^($_transformCommandAtom)*\$');
|
||||
final RegExp _transformCommand = RegExp(_transformCommandAtom);
|
||||
|
||||
Matrix3 _parseSvgTransform(String transform) {
|
||||
if (!_transformValidator.hasMatch(transform))
|
||||
throw new Exception('illegal or unsupported transform: $transform');
|
||||
throw Exception('illegal or unsupported transform: $transform');
|
||||
final Iterable<Match> matches =_transformCommand.allMatches(transform).toList().reversed;
|
||||
Matrix3 result = new Matrix3.identity();
|
||||
Matrix3 result = Matrix3.identity();
|
||||
for (Match m in matches) {
|
||||
final String command = m.group(1);
|
||||
final String params = m.group(2);
|
||||
@@ -484,12 +484,12 @@ Matrix3 _parseSvgTransform(String transform) {
|
||||
result = _parseSvgRotate(params).multiplied(result);
|
||||
continue;
|
||||
}
|
||||
throw new Exception('unimplemented transform: $command');
|
||||
throw Exception('unimplemented transform: $command');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
final RegExp _valueSeparator = new RegExp('( *, *| +)');
|
||||
final RegExp _valueSeparator = RegExp('( *, *| +)');
|
||||
|
||||
Matrix3 _parseSvgTranslate(String paramsStr) {
|
||||
final List<String> params = paramsStr.split(_valueSeparator);
|
||||
@@ -517,18 +517,18 @@ Matrix3 _parseSvgRotate(String paramsStr) {
|
||||
}
|
||||
|
||||
Matrix3 _matrix(double a, double b, double c, double d, double e, double f) {
|
||||
return new Matrix3(a, b, 0.0, c, d, 0.0, e, f, 1.0);
|
||||
return Matrix3(a, b, 0.0, c, d, 0.0, e, f, 1.0);
|
||||
}
|
||||
|
||||
// Matches a pixels expression e.g "14px".
|
||||
// First group is just the number.
|
||||
final RegExp _pixelsExp = new RegExp('^([0-9]+)px\$');
|
||||
final RegExp _pixelsExp = RegExp('^([0-9]+)px\$');
|
||||
|
||||
/// Parses a pixel expression, e.g "14px", and returns the number.
|
||||
/// Throws an [ArgumentError] if the given string doesn't match the pattern.
|
||||
int parsePixels(String pixels) {
|
||||
if (!_pixelsExp.hasMatch(pixels))
|
||||
throw new ArgumentError(
|
||||
throw ArgumentError(
|
||||
'illegal pixels expression: \'$pixels\''
|
||||
' (the tool currently only support pixel units).');
|
||||
return int.parse(_pixelsExp.firstMatch(pixels).group(1));
|
||||
@@ -539,7 +539,7 @@ String _extractAttr(XmlElement element, String name) {
|
||||
return element.attributes.singleWhere((XmlAttribute x) => x.name.local == name)
|
||||
.value;
|
||||
} catch (e) {
|
||||
throw new ArgumentError(
|
||||
throw ArgumentError(
|
||||
'Can\'t find a single \'$name\' attributes in ${element.name}, '
|
||||
'attributes were: ${element.attributes}'
|
||||
);
|
||||
|
||||
@@ -224,7 +224,7 @@ void main() {
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(new PathAnimation.fromFrameData(frameData, 0),
|
||||
expect(PathAnimation.fromFrameData(frameData, 0),
|
||||
const PathAnimationMatcher(PathAnimation(
|
||||
<PathCommandAnimation>[
|
||||
PathCommandAnimation('M', <List<Point<double>>>[
|
||||
@@ -259,7 +259,7 @@ void main() {
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(new PathAnimation.fromFrameData(frameData, 0),
|
||||
expect(PathAnimation.fromFrameData(frameData, 0),
|
||||
const PathAnimationMatcher(PathAnimation(
|
||||
<PathCommandAnimation>[
|
||||
PathCommandAnimation('M', <List<Point<double>>>[
|
||||
@@ -270,7 +270,7 @@ void main() {
|
||||
))
|
||||
);
|
||||
|
||||
expect(new PathAnimation.fromFrameData(frameData, 1),
|
||||
expect(PathAnimation.fromFrameData(frameData, 1),
|
||||
const PathAnimationMatcher(PathAnimation(
|
||||
<PathCommandAnimation>[
|
||||
PathCommandAnimation('M', <List<Point<double>>>[
|
||||
@@ -308,7 +308,7 @@ void main() {
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(new PathAnimation.fromFrameData(frameData, 0),
|
||||
expect(PathAnimation.fromFrameData(frameData, 0),
|
||||
const PathAnimationMatcher(PathAnimation(
|
||||
<PathCommandAnimation>[
|
||||
PathCommandAnimation('M', <List<Point<double>>>[
|
||||
@@ -345,7 +345,7 @@ void main() {
|
||||
],
|
||||
),
|
||||
];
|
||||
final Animation animation = new Animation.fromFrameData(frameData);
|
||||
final Animation animation = Animation.fromFrameData(frameData);
|
||||
expect(animation.paths[0],
|
||||
const PathAnimationMatcher(PathAnimation(
|
||||
<PathCommandAnimation>[
|
||||
|
||||
Reference in New Issue
Block a user