Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Fix bug with Uint8Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
simc committed Sep 29, 2019
1 parent 504ce90 commit 104a8e2
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 4 deletions.
102 changes: 102 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
*.hive
.test_coverage.dart
coverage_badge.svg


# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.vscode/

# Flutter repo-specific
/bin/cache/
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/docs/doc/
/dev/docs/flutter.docs.zip
/dev/docs/lib/
/dev/docs/pubspec.yaml
/packages/flutter/coverage/
version

# packages file containing multi-root paths
.packages.generated

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.packages
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key.properties
*.jks

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Coverage
coverage/

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.5.2
- Fix bug with Uint8Lists

## 0.5.1
- Bump Hive version

Expand Down
81 changes: 80 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
include: ../analysis_options.yaml
include: package:pedantic/analysis_options.yaml
analyzer:
exclude:
- "**/*.g.dart"
strong-mode:
implicit-casts: false
errors:
include_file_not_found: ignore
linter:
rules:
#- public_member_api_docs
- always_declare_return_types
- annotate_overrides
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null
- avoid_types_as_parameter_names
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- cancel_subscriptions
- comment_references
- constant_identifier_names
- control_flow_in_finally
- directives_ordering
- empty_catches
- empty_constructor_bodies
- empty_statements
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- list_remove_unrelated_type
- lines_longer_than_80_chars
- no_adjacent_strings_in_list
- no_duplicate_case_values
- non_constant_identifier_names
- null_closures
- omit_local_variable_types
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- prefer_is_empty
- prefer_is_not_empty
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- recursive_getters
- slash_for_doc_comments
- test_types_in_equals
- throw_in_finally
- type_init_formals
- unawaited_futures
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_statements
- unnecessary_this
- unrelated_type_equality_checks
- use_rethrow_when_possible
- valid_regexps
11 changes: 9 additions & 2 deletions lib/src/class_builder.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:typed_data';

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:hive_generator/src/builder.dart';
Expand All @@ -8,6 +10,7 @@ class ClassBuilder extends Builder {
var mapChecker = const TypeChecker.fromRuntime(Map);
var setChecker = const TypeChecker.fromRuntime(Set);
var iterableChecker = const TypeChecker.fromRuntime(Iterable);
var uint8ListChecker = const TypeChecker.fromRuntime(Uint8List);

ClassBuilder(ClassElement cls, Map<int, FieldElement> fields)
: super(cls, fields);
Expand Down Expand Up @@ -65,7 +68,7 @@ class ClassBuilder extends Builder {
}

String _cast(DartType type, String variable) {
if (iterableChecker.isAssignableFromType(type)) {
if (iterableChecker.isAssignableFromType(type) && !isUint8List(type)) {
return '($variable as List)${_castIterable(type)}';
} else if (mapChecker.isExactlyType(type)) {
return '($variable as Map)${_castMap(type)}';
Expand All @@ -81,10 +84,14 @@ class ClassBuilder extends Builder {
mapChecker.isExactlyType(type);
}

bool isUint8List(DartType type) {
return uint8ListChecker.isExactlyType(type);
}

String _castIterable(DartType type) {
var paramType = type as ParameterizedType;
var arg = paramType.typeArguments[0];
if (isMapOrIterable(arg)) {
if (isMapOrIterable(arg) && !isUint8List(arg)) {
var cast = '';
if (listChecker.isExactlyType(type)) {
cast = '?.toList()';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: hive_generator
description: Extension for Hive. Automatically generates TypeAdapters to store any class.
version: 0.5.1
version: 0.5.2
author: Simon Leier <[email protected]>
homepage: https://github.com/leisim/hive

Expand Down

0 comments on commit 104a8e2

Please sign in to comment.