From de25ea22f77af753e4429987c34532096b703507 Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 14 Apr 2016 10:03:46 -0700 Subject: [PATCH] Adding `@optionalTypeArgs`. With the new dev build we've got the updated linter and so can use the `@optionalTypeArgs` annotation (in `meta 0.12.0`). Bonus: this lets us clean up one more Regexp in the `analyze` command! :) --- packages/flutter/lib/src/widgets/framework.dart | 4 ++++ packages/flutter/lib/src/widgets/scrollable.dart | 2 ++ packages/flutter/pubspec.yaml | 2 ++ packages/flutter_tools/lib/src/commands/analyze.dart | 6 ------ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index fe4da7c4aa..870a19733b 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -10,6 +10,7 @@ import 'debug.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; +import 'package:meta/meta.dart'; export 'dart:ui' show hashValues, hashList; export 'package:flutter/rendering.dart' show RenderObject, RenderBox, debugPrint; @@ -112,6 +113,7 @@ typedef void GlobalKeyRemoveListener(GlobalKey key); /// GlobalKeys are relatively expensive. If you don't need any of the features /// listed above, consider using a [Key], [ValueKey], [ObjectKey], or /// [UniqueKey] instead. +@optionalTypeArgs abstract class GlobalKey> extends Key { /// Constructs a LabeledGlobalKey, which is a GlobalKey with a label used for debugging. /// The label is not used for comparing the identity of the key. @@ -253,6 +255,7 @@ class GlobalObjectKey extends GlobalKey { } /// This class is a work-around for the "is" operator not accepting a variable value as its right operand +@optionalTypeArgs class TypeMatcher { const TypeMatcher(); bool check(dynamic object) => object is T; @@ -346,6 +349,7 @@ enum _StateLifecycle { typedef void StateSetter(VoidCallback fn); /// The logic and internal state for a [StatefulWidget]. +@optionalTypeArgs abstract class State { /// The current configuration (an instance of the corresponding /// [StatefulWidget] class). diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 0a1665678f..4f521955af 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -8,6 +8,7 @@ import 'dart:ui' as ui show window; import 'package:newton/newton.dart'; import 'package:flutter/gestures.dart'; +import 'package:meta/meta.dart'; import 'basic.dart'; import 'framework.dart'; @@ -217,6 +218,7 @@ abstract class Scrollable extends StatefulWidget { /// along the [config.scrollDirection] axis and are implemented in /// terms of the [pixelOffsetToScrollOffset] and /// [scrollOffsetToPixelOffset] methods. +@optionalTypeArgs abstract class ScrollableState extends State { @override void initState() { diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index ac749df531..ec56addfab 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -12,6 +12,8 @@ dependencies: # We need to pin crypto because archive can't handle larger numbers. crypto: 0.9.2 + meta: ^0.12.0 + sky_engine: path: ../../bin/cache/pkg/sky_engine sky_services: diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart index a61c39568e..bce3b086e4 100644 --- a/packages/flutter_tools/lib/src/commands/analyze.dart +++ b/packages/flutter_tools/lib/src/commands/analyze.dart @@ -357,7 +357,6 @@ class AnalyzeCommand extends FlutterCommand { ]; RegExp generalPattern = new RegExp(r'^\[(error|warning|hint|lint)\] (.+) \(([^(),]+), line ([0-9]+), col ([0-9]+)\)$'); - RegExp classesWithOptionalTypeArgumentsPattern = new RegExp(r'\b(GlobalKey|State|ScrollableState|Element|StatelessElement|TypeMatcher)\b'); RegExp conflictingNamesPattern = new RegExp('^The imported libraries \'([^\']+)\' and \'([^\']+)\' cannot have the same name \'([^\']+)\'\$'); RegExp missingFilePattern = new RegExp('^Target of URI does not exist: \'([^\')]+)\'\$'); RegExp documentAllMembersPattern = new RegExp('^Document all public members\$'); @@ -419,11 +418,6 @@ class AnalyzeCommand extends FlutterCommand { } else if (sourceLines.first.startsWith('// DO NOT EDIT. This is code generated')) { // autogenerated code - TODO(ianh): Fix the intl package resource generator shouldIgnore = true; - } else if (level == 'lint' && errorMessage == 'Specify type annotations.') { - // we want the type annotations on certain classes to be optional. - // see https://github.com/dart-lang/linter/issues/196 - if (classesWithOptionalTypeArgumentsPattern.matchAsPrefix(sourceLine, colNumber-1) != null) - shouldIgnore = true; } if (shouldIgnore) continue;