From 4a94de12fea64bf45d9e19f1f839b1f34d9e800f Mon Sep 17 00:00:00 2001 From: kevmoo Date: Mon, 28 Nov 2016 11:47:45 -0800 Subject: [PATCH] Annotate some overrides ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140383298 --- lib/src/common/directives/ng_class.dart | 2 ++ lib/src/common/directives/ng_for.dart | 1 + lib/src/common/directives/ng_plural.dart | 1 + lib/src/common/directives/ng_style.dart | 1 + lib/src/common/directives/observable_list_diff.dart | 4 ++++ .../forms/directives/checkbox_value_accessor.dart | 3 +++ .../forms/directives/default_value_accessor.dart | 3 +++ .../common/forms/directives/ng_control_group.dart | 5 +++++ lib/src/common/forms/directives/ng_control_name.dart | 7 +++++++ lib/src/common/forms/directives/ng_form.dart | 10 ++++++++++ lib/src/common/forms/directives/ng_form_control.dart | 6 ++++++ lib/src/common/forms/directives/ng_form_model.dart | 12 ++++++++++++ lib/src/common/forms/directives/ng_model.dart | 6 ++++++ .../forms/directives/number_value_accessor.dart | 3 +++ .../directives/radio_control_value_accessor.dart | 6 ++++++ .../directives/select_control_value_accessor.dart | 5 +++++ test/core/linker/integration_dart_test.dart | 1 + test/core/linker/query_integration_test.dart | 6 ++++++ 18 files changed, 82 insertions(+) diff --git a/lib/src/common/directives/ng_class.dart b/lib/src/common/directives/ng_class.dart index 588a296089..4827e9c071 100644 --- a/lib/src/common/directives/ng_class.dart +++ b/lib/src/common/directives/ng_class.dart @@ -81,6 +81,7 @@ class NgClass implements DoCheck, OnDestroy { } } + @override void ngDoCheck() { if (_iterableDiffer != null) { var changes = _iterableDiffer.diff(_rawClass); @@ -96,6 +97,7 @@ class NgClass implements DoCheck, OnDestroy { } } + @override void ngOnDestroy() { _cleanupClasses(_rawClass); } diff --git a/lib/src/common/directives/ng_for.dart b/lib/src/common/directives/ng_for.dart index 51b3dc9418..95c7a88e02 100644 --- a/lib/src/common/directives/ng_for.dart +++ b/lib/src/common/directives/ng_for.dart @@ -121,6 +121,7 @@ class NgFor implements DoCheck { this._ngForTrackBy = value; } + @override void ngDoCheck() { if (_differ != null) { var changes = this._differ.diff(this._ngForOf); diff --git a/lib/src/common/directives/ng_plural.dart b/lib/src/common/directives/ng_plural.dart index f71ae1cde6..857cf3b55a 100644 --- a/lib/src/common/directives/ng_plural.dart +++ b/lib/src/common/directives/ng_plural.dart @@ -98,6 +98,7 @@ class NgPlural implements AfterContentInit { this._updateView(); } + @override void ngAfterContentInit() { this.cases.forEach(/* void */ (NgPluralCase pluralCase) { this._caseViews[this._formatValue(pluralCase)] = pluralCase._view; diff --git a/lib/src/common/directives/ng_style.dart b/lib/src/common/directives/ng_style.dart index 951710fad9..d076462e4c 100644 --- a/lib/src/common/directives/ng_style.dart +++ b/lib/src/common/directives/ng_style.dart @@ -56,6 +56,7 @@ class NgStyle implements DoCheck { } } + @override void ngDoCheck() { if (_differ == null) return; var changes = _differ.diff(_rawStyle); diff --git a/lib/src/common/directives/observable_list_diff.dart b/lib/src/common/directives/observable_list_diff.dart index a612d1d3d1..64cc0ea148 100644 --- a/lib/src/common/directives/observable_list_diff.dart +++ b/lib/src/common/directives/observable_list_diff.dart @@ -13,6 +13,7 @@ class ObservableListDiff extends DefaultIterableDiffer { ObservableList _collection; StreamSubscription _subscription; + @override void onDestroy() { if (this._subscription != null) { this._subscription.cancel(); @@ -21,6 +22,7 @@ class ObservableListDiff extends DefaultIterableDiffer { } } + @override DefaultIterableDiffer diff(Iterable iterable) { assert(iterable is ObservableList); ObservableList collection = iterable; @@ -56,7 +58,9 @@ class ObservableListDiff extends DefaultIterableDiffer { @Deprecated('No longer part of Angular. Copy into your project if needed') class ObservableListDiffFactory implements IterableDifferFactory { const ObservableListDiffFactory(); + @override bool supports(obj) => obj is ObservableList; + @override IterableDiffer create(ChangeDetectorRef cdRef, [Function trackByFn]) { return new ObservableListDiff(cdRef); } diff --git a/lib/src/common/forms/directives/checkbox_value_accessor.dart b/lib/src/common/forms/directives/checkbox_value_accessor.dart index bb03d79e1b..30e2510fcf 100644 --- a/lib/src/common/forms/directives/checkbox_value_accessor.dart +++ b/lib/src/common/forms/directives/checkbox_value_accessor.dart @@ -27,15 +27,18 @@ class CheckboxControlValueAccessor implements ControlValueAccessor { var onChange = (dynamic _) {}; var onTouched = () {}; CheckboxControlValueAccessor(this._elementRef); + @override void writeValue(dynamic value) { InputElement elm = this._elementRef.nativeElement; elm.checked = value; } + @override void registerOnChange(dynamic fn) { this.onChange = fn; } + @override void registerOnTouched(dynamic fn) { this.onTouched = fn; } diff --git a/lib/src/common/forms/directives/default_value_accessor.dart b/lib/src/common/forms/directives/default_value_accessor.dart index e2d043c545..32e609770c 100644 --- a/lib/src/common/forms/directives/default_value_accessor.dart +++ b/lib/src/common/forms/directives/default_value_accessor.dart @@ -27,15 +27,18 @@ class DefaultValueAccessor implements ControlValueAccessor { var onChange = (dynamic _) {}; var onTouched = () {}; DefaultValueAccessor(this._elementRef); + @override void writeValue(dynamic value) { var normalizedValue = value ?? ''; DOM.setProperty(_elementRef.nativeElement, 'value', normalizedValue); } + @override void registerOnChange(void fn(dynamic _)) { this.onChange = fn; } + @override void registerOnTouched(void fn()) { this.onTouched = fn; } diff --git a/lib/src/common/forms/directives/ng_control_group.dart b/lib/src/common/forms/directives/ng_control_group.dart index f24ad1b241..9e8c19dbc8 100644 --- a/lib/src/common/forms/directives/ng_control_group.dart +++ b/lib/src/common/forms/directives/ng_control_group.dart @@ -78,25 +78,30 @@ class NgControlGroup extends ControlContainer implements OnInit, OnDestroy { @Optional() @Self() @Inject(NG_VALIDATORS) this._validators, @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) this._asyncValidators); + @override void ngOnInit() { this.formDirective.addControlGroup(this); } + @override void ngOnDestroy() { this.formDirective.removeControlGroup(this); } /// Get the [ControlGroup] backing this binding. + @override ControlGroup get control { return this.formDirective.getControlGroup(this); } /// Get the path to this control group. + @override List get path { return controlPath(this.name, this._parent); } /// Get the [Form] to which this group belongs. + @override Form get formDirective { return this._parent.formDirective; } diff --git a/lib/src/common/forms/directives/ng_control_name.dart b/lib/src/common/forms/directives/ng_control_name.dart index 99dc0e96de..b63bb28a60 100644 --- a/lib/src/common/forms/directives/ng_control_name.dart +++ b/lib/src/common/forms/directives/ng_control_name.dart @@ -113,6 +113,7 @@ class NgControlName extends NgControl implements OnChanges, OnDestroy { List valueAccessors) { this.valueAccessor = selectValueAccessor(this, valueAccessors); } + @override ngOnChanges(Map changes) { if (!this._added) { this.formDirective.addControl(this); @@ -124,15 +125,18 @@ class NgControlName extends NgControl implements OnChanges, OnDestroy { } } + @override void ngOnDestroy() { this.formDirective.removeControl(this); } + @override void viewToModelUpdate(dynamic newValue) { this.viewModel = newValue; this.update.add(newValue); } + @override List get path { return controlPath(this.name, this._parent); } @@ -141,14 +145,17 @@ class NgControlName extends NgControl implements OnChanges, OnDestroy { return this._parent.formDirective; } + @override ValidatorFn get validator { return composeValidators(this._validators); } + @override AsyncValidatorFn get asyncValidator { return composeAsyncValidators(this._asyncValidators); } + @override Control get control { return this.formDirective.getControl(this); } diff --git a/lib/src/common/forms/directives/ng_form.dart b/lib/src/common/forms/directives/ng_form.dart index 7da801ca02..c5fcfc9686 100644 --- a/lib/src/common/forms/directives/ng_form.dart +++ b/lib/src/common/forms/directives/ng_form.dart @@ -97,14 +97,17 @@ class NgForm extends ControlContainer implements Form { this.form = new ControlGroup({}, null, composeValidators(validators), composeAsyncValidators(asyncValidators)); } + @override Form get formDirective { return this; } + @override ControlGroup get control { return this.form; } + @override List get path { return []; } @@ -113,6 +116,7 @@ class NgForm extends ControlContainer implements Form { return this.form.controls; } + @override void addControl(NgControl dir) { var container = _findContainer(dir.path); var ctrl = new Control(); @@ -123,10 +127,12 @@ class NgForm extends ControlContainer implements Form { }); } + @override Control getControl(NgControl dir) { return (this.form.find(dir.path) as Control); } + @override void removeControl(NgControl dir) { scheduleMicrotask(() { var container = this._findContainer(dir.path); @@ -137,6 +143,7 @@ class NgForm extends ControlContainer implements Form { }); } + @override void addControlGroup(NgControlGroup dir) { var container = _findContainer(dir.path); var group = new ControlGroup({}); @@ -147,6 +154,7 @@ class NgForm extends ControlContainer implements Form { }); } + @override void removeControlGroup(NgControlGroup dir) { scheduleMicrotask(() { var container = this._findContainer(dir.path); @@ -157,10 +165,12 @@ class NgForm extends ControlContainer implements Form { }); } + @override ControlGroup getControlGroup(NgControlGroup dir) { return (this.form.find(dir.path) as ControlGroup); } + @override void updateModel(NgControl dir, dynamic value) { scheduleMicrotask(() { var ctrl = (this.form.find(dir.path) as Control); diff --git a/lib/src/common/forms/directives/ng_form_control.dart b/lib/src/common/forms/directives/ng_form_control.dart index 220d5bba06..8c64492bd1 100644 --- a/lib/src/common/forms/directives/ng_form_control.dart +++ b/lib/src/common/forms/directives/ng_form_control.dart @@ -93,6 +93,7 @@ class NgFormControl extends NgControl implements OnChanges { List valueAccessors) { this.valueAccessor = selectValueAccessor(this, valueAccessors); } + @override void ngOnChanges(Map changes) { if (this._isControlChanged(changes)) { setUpControl(this.form, this); @@ -104,22 +105,27 @@ class NgFormControl extends NgControl implements OnChanges { } } + @override List get path { return []; } + @override ValidatorFn get validator { return composeValidators(this._validators); } + @override AsyncValidatorFn get asyncValidator { return composeAsyncValidators(this._asyncValidators); } + @override Control get control { return this.form; } + @override void viewToModelUpdate(dynamic newValue) { this.viewModel = newValue; this.update.add(newValue); diff --git a/lib/src/common/forms/directives/ng_form_model.dart b/lib/src/common/forms/directives/ng_form_model.dart index d785516ad8..ccb2ccc820 100644 --- a/lib/src/common/forms/directives/ng_form_model.dart +++ b/lib/src/common/forms/directives/ng_form_model.dart @@ -107,6 +107,7 @@ class NgFormModel extends ControlContainer implements Form, OnChanges { NgFormModel(@Optional() @Self() @Inject(NG_VALIDATORS) this._validators, @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) this._asyncValidators); + @override void ngOnChanges(Map changes) { _checkFormPresent(); if (changes.containsKey('form')) { @@ -120,12 +121,16 @@ class NgFormModel extends ControlContainer implements Form, OnChanges { _updateDomValue(); } + @override Form get formDirective => this; + @override ControlGroup get control => form; + @override List get path => []; + @override void addControl(NgControl dir) { dynamic ctrl = form.find(dir.path); setUpControl(ctrl, dir); @@ -133,25 +138,32 @@ class NgFormModel extends ControlContainer implements Form, OnChanges { directives.add(dir); } + @override Control getControl(NgControl dir) { return (form.find(dir.path) as Control); } + @override void removeControl(NgControl dir) { directives.remove(dir); } + @override void addControlGroup(NgControlGroup dir) { dynamic ctrl = form.find(dir.path); setUpControlGroup(ctrl, dir); ctrl.updateValueAndValidity(emitEvent: false); } + @override void removeControlGroup(NgControlGroup dir) {} + + @override ControlGroup getControlGroup(NgControlGroup dir) { return (form.find(dir.path) as ControlGroup); } + @override void updateModel(NgControl dir, dynamic value) { var ctrl = (form.find(dir.path) as Control); ctrl.updateValue(value); diff --git a/lib/src/common/forms/directives/ng_model.dart b/lib/src/common/forms/directives/ng_model.dart index 8dd11615c8..e98b27d93f 100644 --- a/lib/src/common/forms/directives/ng_model.dart +++ b/lib/src/common/forms/directives/ng_model.dart @@ -71,6 +71,7 @@ class NgModel extends NgControl implements OnChanges { : super() { this.valueAccessor = selectValueAccessor(this, valueAccessors); } + @override void ngOnChanges(Map changes) { if (!this._added) { setUpControl(this._control, this); @@ -83,22 +84,27 @@ class NgModel extends NgControl implements OnChanges { } } + @override Control get control { return this._control; } + @override List get path { return []; } + @override ValidatorFn get validator { return composeValidators(this._validators); } + @override AsyncValidatorFn get asyncValidator { return composeAsyncValidators(this._asyncValidators); } + @override void viewToModelUpdate(dynamic newValue) { this.viewModel = newValue; this.update.add(newValue); diff --git a/lib/src/common/forms/directives/number_value_accessor.dart b/lib/src/common/forms/directives/number_value_accessor.dart index 87fbbab34b..13578dc265 100644 --- a/lib/src/common/forms/directives/number_value_accessor.dart +++ b/lib/src/common/forms/directives/number_value_accessor.dart @@ -29,17 +29,20 @@ class NumberValueAccessor implements ControlValueAccessor { var onChange = (_) {}; var onTouched = () {}; NumberValueAccessor(this._elementRef); + @override void writeValue(value) { InputElement elm = _elementRef.nativeElement; elm.value = '$value'; } + @override void registerOnChange(dynamic fn) { this.onChange = (value) { fn(value == "" ? null : double.parse(value)); }; } + @override void registerOnTouched(dynamic fn) { this.onTouched = fn; } diff --git a/lib/src/common/forms/directives/radio_control_value_accessor.dart b/lib/src/common/forms/directives/radio_control_value_accessor.dart index aa34618aba..76b3d7f246 100644 --- a/lib/src/common/forms/directives/radio_control_value_accessor.dart +++ b/lib/src/common/forms/directives/radio_control_value_accessor.dart @@ -88,15 +88,19 @@ class RadioControlValueAccessor var onChange = () {}; var onTouched = () {}; RadioControlValueAccessor(this._elementRef, this._registry, this._injector); + + @override void ngOnInit() { this._control = this._injector.get(NgControl); this._registry.add(this._control, this); } + @override void ngOnDestroy() { this._registry.remove(this); } + @override void writeValue(dynamic value) { this._state = value; if (value?.checked ?? false) { @@ -104,6 +108,7 @@ class RadioControlValueAccessor } } + @override void registerOnChange(dynamic fn(dynamic _)) { this._fn = fn; this.onChange = () { @@ -116,6 +121,7 @@ class RadioControlValueAccessor this._fn(new RadioButtonState(false, this._state.value)); } + @override void registerOnTouched(dynamic fn()) { this.onTouched = fn; } diff --git a/lib/src/common/forms/directives/select_control_value_accessor.dart b/lib/src/common/forms/directives/select_control_value_accessor.dart index 2a59862f4f..493d9cb51b 100644 --- a/lib/src/common/forms/directives/select_control_value_accessor.dart +++ b/lib/src/common/forms/directives/select_control_value_accessor.dart @@ -47,6 +47,8 @@ class SelectControlValueAccessor implements ControlValueAccessor { var onChange = (dynamic _) {}; var onTouched = () {}; SelectControlValueAccessor(this._elementRef); + + @override void writeValue(dynamic value) { this.value = value; var valueString = _buildValueString(this._getOptionId(value), value); @@ -54,12 +56,14 @@ class SelectControlValueAccessor implements ControlValueAccessor { elm.value = valueString; } + @override void registerOnChange(dynamic fn(dynamic value)) { this.onChange = (String valueString) { fn(this._getOptionValue(valueString)); }; } + @override void registerOnTouched(dynamic fn()) { this.onTouched = fn; } @@ -115,6 +119,7 @@ class NgSelectOption implements OnDestroy { elm.value = value; } + @override void ngOnDestroy() { if (_select != null) { (this._select._optionMap.containsKey(this.id) && diff --git a/test/core/linker/integration_dart_test.dart b/test/core/linker/integration_dart_test.dart index a5ecb68ed1..3935ca6cd8 100644 --- a/test/core/linker/integration_dart_test.dart +++ b/test/core/linker/integration_dart_test.dart @@ -279,5 +279,6 @@ class DirectiveLoggingChecks implements DoCheck { DirectiveLoggingChecks(this.log); + @override ngDoCheck() => log.add("check"); } diff --git a/test/core/linker/query_integration_test.dart b/test/core/linker/query_integration_test.dart index db9249c016..18966ac552 100644 --- a/test/core/linker/query_integration_test.dart +++ b/test/core/linker/query_integration_test.dart @@ -823,6 +823,7 @@ class NeedsContentChildren implements AfterContentInit { @ContentChildren(TextDirective) QueryList textDirChildren; num numberOfChildrenAfterContentInit; + @override ngAfterContentInit() { this.numberOfChildrenAfterContentInit = this.textDirChildren.length; } @@ -836,6 +837,7 @@ class NeedsViewChildren implements AfterViewInit { @ViewChildren(TextDirective) QueryList textDirChildren; num numberOfChildrenAfterViewInit; + @override ngAfterViewInit() { this.numberOfChildrenAfterViewInit = this.textDirChildren.length; } @@ -855,10 +857,12 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked { } var log = []; + @override ngAfterContentInit() { this.log.add(["init", child != null ? child.text : null]); } + @override ngAfterContentChecked() { this.log.add(["check", child != null ? child.text : null]); } @@ -885,10 +889,12 @@ class NeedsViewChild implements AfterViewInit, AfterViewChecked { } var log = []; + @override ngAfterViewInit() { this.log.add(["init", child != null ? child.text : null]); } + @override ngAfterViewChecked() { this.log.add(["check", child != null ? child.text : null]); }