-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import 'package:collection/collection.dart'; | ||
/// Experimental support for data classes in Dart using package:macros. | ||
library data_class_macro; | ||
|
||
export 'src/constructable_macro.dart' show Constructable; | ||
export 'src/copyable_macro.dart' show Copyable; | ||
export 'src/data_macro.dart' show Data; | ||
export 'src/equatable_macro.dart' show Equatable; | ||
export 'src/stringable_macro.dart' show Stringable; | ||
|
||
final deepEquals = const DeepCollectionEquality().equals; | ||
const undefined = Object(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:collection/collection.dart'; | ||
|
||
// Libraries used in augmented code. | ||
final dartCore = Uri.parse('dart:core'); | ||
final dataClassMacro = Uri.parse( | ||
'package:data_class_macro/src/_data_class_macro.dart', | ||
); | ||
|
||
// Methods used in augmented code. | ||
const undefined = Object(); | ||
final deepEquals = const DeepCollectionEquality().equals; | ||
|
||
// TODO(felangel): use jenkins hash from `package:equatable` | ||
// once https://github.com/felangel/equatable/pull/174 is published. | ||
/// Generate a hash for the provided [fields]. | ||
int hashAll(Iterable<Object?>? fields) { | ||
return _finish(fields == null ? 0 : fields.fold(0, _combine)); | ||
} | ||
|
||
int _combine(int hash, Object? object) { | ||
if (object is Map) { | ||
object.keys | ||
.sorted((Object? a, Object? b) => a.hashCode - b.hashCode) | ||
.forEach((Object? key) { | ||
hash = hash ^ _combine(hash, [key, (object! as Map)[key]]); | ||
}); | ||
return hash; | ||
} | ||
if (object is Set) { | ||
object = object.sorted((Object? a, Object? b) => a.hashCode - b.hashCode); | ||
} | ||
if (object is Iterable) { | ||
for (final value in object) { | ||
hash = hash ^ _combine(hash, value); | ||
} | ||
return hash ^ object.length; | ||
} | ||
|
||
hash = 0x1fffffff & (hash + object.hashCode); | ||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); | ||
return hash ^ (hash >> 6); | ||
} | ||
|
||
int _finish(int hash) { | ||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | ||
hash = hash ^ (hash >> 11); | ||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters