Skip to content

Commit

Permalink
Merge pull request #169 from devmil/feature/add_readability_and_writa…
Browse files Browse the repository at this point in the history
…bility_metadata_for_fields

adds readability / writability data for fields
  • Loading branch information
devmil authored Feb 9, 2024
2 parents 324e4e9 + 25f4c50 commit 90bec51
Show file tree
Hide file tree
Showing 30 changed files with 454 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ jobs:
- name: Install Dependencies
run: |
dart pub get
dart pub global activate pana
dart pub global activate pana 0.21.45 #temporary as the latest version 0.22.0 has issues with the dartdoc interface
- name: Verify Pub Score
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 0.18.0
- add missing export to json output for `extract` command
- adds analysis of readability and writability of fields.
- fixes interface equality logic in the differ functionality to be less strict on library renaming (if the entry points are still the same)
- fix change compatibility check for `dynamic` and `Object?` parameters
- fix compatibility checks for return types of executables
Expand Down
6 changes: 6 additions & 0 deletions lib/src/diff/api_change_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ enum ApiChangeCode {
/// field experimental status changed
cf06._('CF06', 'field experimental status changed'),

/// field readability changed
cf07._('CF07', 'field readability changed'),

/// field writability changed
cf08._('CF08', 'field writability changed'),

/// iOS platform added
cpi01._('CPI01', 'iOS platform added'),

Expand Down
24 changes: 24 additions & 0 deletions lib/src/diff/package_api_differ.dart
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,30 @@ class PackageApiDiffer {
context,
isExperimental: isExperimental,
));
_comparePropertiesAndAddChange(
oldField.isReadable,
newField.isReadable,
context,
newField,
'Readablility changed. ${oldField.isReadable} -> ${newField.isReadable}',
changes,
changeCode: ApiChangeCode.cf07,
isExperimental: isExperimental,
// the change is compatible if the field gained readablility
isCompatibleChange: newField.isReadable,
);
_comparePropertiesAndAddChange(
oldField.isWriteable,
newField.isWriteable,
context,
newField,
'Writability changed. ${oldField.isWriteable} -> ${newField.isWriteable}',
changes,
changeCode: ApiChangeCode.cf08,
isExperimental: isExperimental,
// the change is compatible if the field gained writability
isCompatibleChange: newField.isWriteable,
);

return changes;
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/executable_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ExecutableDeclaration
/// name of the return type
required String returnTypeName,

// fill library name of the return type
// full library name of the return type
required String? returnTypeFullLibraryName,

/// name of the executable
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/executable_declaration.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ abstract class _ExecutableParameterDeclaration
mixin _$ExecutableDeclaration {
/// name of the return type
String get returnTypeName =>
throw _privateConstructorUsedError; // fill library name of the return type
throw _privateConstructorUsedError; // full library name of the return type
String? get returnTypeFullLibraryName => throw _privateConstructorUsedError;

/// name of the executable
Expand Down Expand Up @@ -604,7 +604,7 @@ class _$ExecutableDeclarationImpl extends _ExecutableDeclaration {
/// name of the return type
@override
final String returnTypeName;
// fill library name of the return type
// full library name of the return type
@override
final String? returnTypeFullLibraryName;

Expand Down Expand Up @@ -743,7 +743,7 @@ abstract class _ExecutableDeclaration extends ExecutableDeclaration {

/// name of the return type
String get returnTypeName;
@override // fill library name of the return type
@override // full library name of the return type
String? get returnTypeFullLibraryName;
@override

Expand Down
6 changes: 6 additions & 0 deletions lib/src/model/field_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class FieldDeclaration with _$FieldDeclaration implements Declaration {

/// the relative path of the library
required String relativePath,

/// whether this field is readable
required bool isReadable,

/// whether this field is writeable
required bool isWriteable,
}) = _FieldDeclaration;

/// helper to compute the signature of a field
Expand Down
70 changes: 63 additions & 7 deletions lib/src/model/field_declaration.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ mixin _$FieldDeclaration {
/// the relative path of the library
String get relativePath => throw _privateConstructorUsedError;

/// whether this field is readable
bool get isReadable => throw _privateConstructorUsedError;

/// whether this field is writeable
bool get isWriteable => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$FieldDeclarationCopyWith<FieldDeclaration> get copyWith =>
throw _privateConstructorUsedError;
Expand All @@ -59,7 +65,9 @@ abstract class $FieldDeclarationCopyWith<$Res> {
bool isStatic,
bool isExperimental,
Set<String>? entryPoints,
String relativePath});
String relativePath,
bool isReadable,
bool isWriteable});
}

/// @nodoc
Expand All @@ -83,6 +91,8 @@ class _$FieldDeclarationCopyWithImpl<$Res, $Val extends FieldDeclaration>
Object? isExperimental = null,
Object? entryPoints = freezed,
Object? relativePath = null,
Object? isReadable = null,
Object? isWriteable = null,
}) {
return _then(_value.copyWith(
typeName: null == typeName
Expand Down Expand Up @@ -117,6 +127,14 @@ class _$FieldDeclarationCopyWithImpl<$Res, $Val extends FieldDeclaration>
? _value.relativePath
: relativePath // ignore: cast_nullable_to_non_nullable
as String,
isReadable: null == isReadable
? _value.isReadable
: isReadable // ignore: cast_nullable_to_non_nullable
as bool,
isWriteable: null == isWriteable
? _value.isWriteable
: isWriteable // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
Expand All @@ -137,7 +155,9 @@ abstract class _$$FieldDeclarationImplCopyWith<$Res>
bool isStatic,
bool isExperimental,
Set<String>? entryPoints,
String relativePath});
String relativePath,
bool isReadable,
bool isWriteable});
}

/// @nodoc
Expand All @@ -159,6 +179,8 @@ class __$$FieldDeclarationImplCopyWithImpl<$Res>
Object? isExperimental = null,
Object? entryPoints = freezed,
Object? relativePath = null,
Object? isReadable = null,
Object? isWriteable = null,
}) {
return _then(_$FieldDeclarationImpl(
typeName: null == typeName
Expand Down Expand Up @@ -193,6 +215,14 @@ class __$$FieldDeclarationImplCopyWithImpl<$Res>
? _value.relativePath
: relativePath // ignore: cast_nullable_to_non_nullable
as String,
isReadable: null == isReadable
? _value.isReadable
: isReadable // ignore: cast_nullable_to_non_nullable
as bool,
isWriteable: null == isWriteable
? _value.isWriteable
: isWriteable // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
Expand All @@ -208,7 +238,9 @@ class _$FieldDeclarationImpl extends _FieldDeclaration {
required this.isStatic,
required this.isExperimental,
final Set<String>? entryPoints,
required this.relativePath})
required this.relativePath,
required this.isReadable,
required this.isWriteable})
: _entryPoints = entryPoints,
super._();

Expand Down Expand Up @@ -253,9 +285,17 @@ class _$FieldDeclarationImpl extends _FieldDeclaration {
@override
final String relativePath;

/// whether this field is readable
@override
final bool isReadable;

/// whether this field is writeable
@override
final bool isWriteable;

@override
String toString() {
return 'FieldDeclaration(typeName: $typeName, typeFullLibraryName: $typeFullLibraryName, name: $name, isDeprecated: $isDeprecated, isStatic: $isStatic, isExperimental: $isExperimental, entryPoints: $entryPoints, relativePath: $relativePath)';
return 'FieldDeclaration(typeName: $typeName, typeFullLibraryName: $typeFullLibraryName, name: $name, isDeprecated: $isDeprecated, isStatic: $isStatic, isExperimental: $isExperimental, entryPoints: $entryPoints, relativePath: $relativePath, isReadable: $isReadable, isWriteable: $isWriteable)';
}

@override
Expand All @@ -277,7 +317,11 @@ class _$FieldDeclarationImpl extends _FieldDeclaration {
const DeepCollectionEquality()
.equals(other._entryPoints, _entryPoints) &&
(identical(other.relativePath, relativePath) ||
other.relativePath == relativePath));
other.relativePath == relativePath) &&
(identical(other.isReadable, isReadable) ||
other.isReadable == isReadable) &&
(identical(other.isWriteable, isWriteable) ||
other.isWriteable == isWriteable));
}

@override
Expand All @@ -290,7 +334,9 @@ class _$FieldDeclarationImpl extends _FieldDeclaration {
isStatic,
isExperimental,
const DeepCollectionEquality().hash(_entryPoints),
relativePath);
relativePath,
isReadable,
isWriteable);

@JsonKey(ignore: true)
@override
Expand All @@ -310,7 +356,9 @@ abstract class _FieldDeclaration extends FieldDeclaration
required final bool isStatic,
required final bool isExperimental,
final Set<String>? entryPoints,
required final String relativePath}) = _$FieldDeclarationImpl;
required final String relativePath,
required final bool isReadable,
required final bool isWriteable}) = _$FieldDeclarationImpl;
const _FieldDeclaration._() : super._();

@override
Expand Down Expand Up @@ -346,6 +394,14 @@ abstract class _FieldDeclaration extends FieldDeclaration
/// the relative path of the library
String get relativePath;
@override

/// whether this field is readable
bool get isReadable;
@override

/// whether this field is writeable
bool get isWriteable;
@override
@JsonKey(ignore: true)
_$$FieldDeclarationImplCopyWith<_$FieldDeclarationImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
8 changes: 8 additions & 0 deletions lib/src/model/internal/internal_field_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class InternalFieldDeclaration implements InternalDeclaration {
final Set<String>? entryPoints;
@override
final String relativePath;
final bool isWriteable;
final bool isReadable;

InternalFieldDeclaration._({
required this.id,
Expand All @@ -35,6 +37,8 @@ class InternalFieldDeclaration implements InternalDeclaration {
required this.isStatic,
required this.entryPoints,
required this.relativePath,
required this.isReadable,
required this.isWriteable,
});

InternalFieldDeclaration.fromPropertyInducingElement(
Expand All @@ -57,6 +61,8 @@ class InternalFieldDeclaration implements InternalDeclaration {
entryPoints: {},
relativePath:
InternalDeclarationUtils.getRelativePath(rootPath, fieldElement),
isReadable: fieldElement.getter != null,
isWriteable: fieldElement.setter != null,
);

FieldDeclaration toFieldDeclaration() {
Expand All @@ -70,6 +76,8 @@ class InternalFieldDeclaration implements InternalDeclaration {
isStatic: isStatic,
entryPoints: entryPoints,
relativePath: relativePath,
isReadable: isReadable,
isWriteable: isWriteable,
);
}
}
4 changes: 4 additions & 0 deletions lib/src/storage/v3/field_declaration_storage_v3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class FieldDeclarationStorageV3 with _$FieldDeclarationStorageV3 {
required bool isStatic,
required Set<String> entryPoints,
required String relativePath,
required bool isReadable,
required bool isWriteable,
}) = _FieldDeclarationStorageV3;

factory FieldDeclarationStorageV3.fromJson(Map<String, Object?> json) =>
Expand All @@ -33,6 +35,8 @@ class FieldDeclarationStorageV3 with _$FieldDeclarationStorageV3 {
isStatic: fieldDeclaration.isStatic,
entryPoints: fieldDeclaration.entryPoints!,
relativePath: fieldDeclaration.relativePath,
isReadable: fieldDeclaration.isReadable,
isWriteable: fieldDeclaration.isWriteable,
);
}
}
Loading

0 comments on commit 90bec51

Please sign in to comment.