Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Workiva/over_react into batch/fed…
Browse files Browse the repository at this point in the history
…x/mocktail/over_react
  • Loading branch information
bender-wk committed May 15, 2024
2 parents 82cc51b + 2fc0675 commit 8355683
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ List<FieldElement> getAllProps(InterfaceElement propsElement) {
final isMixinBasedPropsMixin =
interface is MixinElement && interface.superclassConstraints.any((s) => s.element.name == 'UiProps');
late final isLegacyPropsOrPropsMixinConsumerClass =
!isFromGeneratedFile && interface.metadata.any(_isPropsOrPropsMixinAnnotation);
!isFromGeneratedFile && interface.metadata.any(_isOneOfThePropsAnnotations);

if (!isMixinBasedPropsMixin && !isLegacyPropsOrPropsMixinConsumerClass) {
continue;
Expand All @@ -74,10 +74,11 @@ List<FieldElement> getAllProps(InterfaceElement propsElement) {
return allProps;
}

bool _isPropsOrPropsMixinAnnotation(ElementAnnotation e) {
bool _isOneOfThePropsAnnotations(ElementAnnotation e) {
// [2]
final element = e.element;
return element is ConstructorElement && const {'Props', 'PropsMixin'}.contains(element.enclosingElement.name);
return element is ConstructorElement &&
const {'Props', 'PropsMixin', 'AbstractProps'}.contains(element.enclosingElement.name);
}

bool _isPropsMixinAnnotation(ElementAnnotation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ void main() {
]);
});

test('concrete props class', () {
final propsElement = getInterfaceElement(result, 'V2AbstractProps');
verifyAllProps(getAllProps(propsElement), expectedNames: [
'v2_lateRequiredProp',
'v2_optionalProp',
'v2_annotationRequiredProp',
]);
});

test('props mixin', () {
final propsElement = getInterfaceElement(result, 'V2PropsMixin');
verifyAllProps(getAllProps(propsElement), expectedNames: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ void main() {
});
});

test('abstract props class', () {
final propsElement = getInterfaceElement(result, 'V2Props');
verifyRequiredProps(getAllRequiredProps(propsElement), expected: {
'v2_lateRequiredProp': PropRequiredness.late,
'v2_optionalProp': PropRequiredness.none,
'v2_annotationRequiredProp': PropRequiredness.annotation,
});
});

test('props mixin', () {
final propsElement = getInterfaceElement(result, 'V2PropsMixin');
verifyRequiredProps(getAllRequiredProps(propsElement), expected: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,52 @@ class V2Component extends UiComponent2<V2Props> {
render() {}
}
// ignore: undefined_class, mixin_of_non_class
abstract class V2AbstractProps extends _$V2AbstractProps with _$V2AbstractPropsAccessorsMixin {
// ignore: undefined_identifier, const_initialized_with_non_constant_value, invalid_assignment
static const PropsMeta meta = _$metaForV2AbstractProps;
}
@AbstractProps()
// ignore: mixin_of_non_class,undefined_class
abstract class _$V2AbstractProps extends UiProps {
late String v2_lateRequiredProp;
String? v2_optionalProp;
@requiredProp
String? v2_annotationRequiredProp;
//
// Non-props: edge-cases
//
@Accessor(doNotGenerate: true)
String? v2_doNotGenerate;
//
// Non-props: instance members
//
String get v2_getter => '';
// ignore: avoid_setters_without_getters
set v2_setter(_) => '';
String get v2_getterAndSetter => '';
set v2_getterAndSetter(String _) {}
//
// Non-props: static members
//
static String v2_static_field = '';
static String get v2_static_getter => '';
// ignore: avoid_setters_without_getters
static set v2_static_setter(_) => '';
static String get v2_static_getterAndSetter => '';
static set v2_static_getterAndSetter(String _) {}
}
@AbstractComponent()
abstract class V2AbstractComponent<TProps extends V2AbstractProps> extends UiComponent2<TProps> {
@override
render() {}
}
@Factory()
UiFactory<V3Props> V3 = castUiFactory(_$V3);
Expand Down

0 comments on commit 8355683

Please sign in to comment.