Skip to content

Commit

Permalink
fix registered abstract dependencies are reported missing.
Browse files Browse the repository at this point in the history
fix registering third party types as singleton throws an error.
  • Loading branch information
Milad Alakarie committed Mar 7, 2020
1 parent 7eef7e2 commit 0ccd5e7
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 93 deletions.
120 changes: 60 additions & 60 deletions example/.packages
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
# Generated by pub on 2020-03-06 16:12:30.100760.
_fe_analyzer_shared:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-1.0.3/lib/
analyzer:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/analyzer-0.39.4/lib/
args:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/args-1.5.3/lib/
async:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/async-2.4.0/lib/
build:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/build-1.2.2/lib/
build_config:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/build_config-0.4.2/lib/
build_daemon:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/build_daemon-2.1.3/lib/
build_resolvers:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/build_resolvers-1.3.3/lib/
build_runner:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/build_runner-1.8.0/lib/
build_runner_core:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/build_runner_core-4.5.1/lib/
built_collection:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/built_collection-4.3.2/lib/
built_value:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/built_value-7.0.9/lib/
charcode:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.3/lib/
checked_yaml:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/checked_yaml-1.0.2/lib/
code_builder:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/code_builder-3.2.1/lib/
collection:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/collection-1.14.12/lib/
convert:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1/lib/
crypto:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.4/lib/
csslib:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/csslib-0.16.1/lib/
dart_style:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/dart_style-1.3.3/lib/
fixnum:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/fixnum-0.10.11/lib/
get_it:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/get_it-4.0.0/lib/
glob:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/glob-1.2.0/lib/
graphs:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/graphs-0.2.0/lib/
html:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/html-0.14.0+3/lib/
http:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+4/lib/
http_multi_server:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.2.0/lib/
http_parser:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.3/lib/
# Generated by pub on 2020-03-07 19:01:09.150212.
_fe_analyzer_shared:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-1.0.3/lib/
analyzer:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.39.4/lib/
args:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.5.3/lib/
async:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.4.0/lib/
build:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/build-1.2.2/lib/
build_config:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/build_config-0.4.2/lib/
build_daemon:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/build_daemon-2.1.3/lib/
build_resolvers:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/build_resolvers-1.3.3/lib/
build_runner:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner-1.8.0/lib/
build_runner_core:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/build_runner_core-4.5.1/lib/
built_collection:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/built_collection-4.3.2/lib/
built_value:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/built_value-7.0.9/lib/
charcode:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.3/lib/
checked_yaml:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/checked_yaml-1.0.2/lib/
code_builder:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/code_builder-3.2.1/lib/
collection:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.14.11/lib/
convert:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1/lib/
crypto:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.4/lib/
csslib:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/csslib-0.16.1/lib/
dart_style:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/dart_style-1.3.3/lib/
fixnum:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/fixnum-0.10.11/lib/
get_it:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/get_it-4.0.0/lib/
glob:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/glob-1.2.0/lib/
graphs:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/graphs-0.2.0/lib/
html:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/html-0.14.0+3/lib/
http:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.0+4/lib/
http_multi_server:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.2.0/lib/
http_parser:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.3/lib/
injectable:../injectable/lib/
injectable_generator:../injectable_generator/lib/
io:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/io-0.3.3/lib/
js:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib/
json_annotation:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/json_annotation-3.0.1/lib/
logging:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/logging-0.11.4/lib/
matcher:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.6/lib/
meta:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/meta-1.1.8/lib/
mime:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/mime-0.9.6+3/lib/
node_interop:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/node_interop-1.0.3/lib/
node_io:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/node_io-1.0.1+2/lib/
package_config:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/package_config-1.9.1/lib/
package_resolver:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.10/lib/
path:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/path-1.6.4/lib/
pedantic:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/pedantic-1.9.0/lib/
pool:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/pool-1.4.0/lib/
pub_semver:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/pub_semver-1.4.3/lib/
pubspec_parse:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/pubspec_parse-0.1.5/lib/
quiver:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.3/lib/
shelf:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.5/lib/
shelf_web_socket:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.3/lib/
source_gen:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/source_gen-0.9.5/lib/
source_span:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/source_span-1.6.0/lib/
stack_trace:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib/
stream_channel:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0/lib/
stream_transform:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/stream_transform-1.2.0/lib/
string_scanner:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.5/lib/
term_glyph:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib/
timing:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/timing-0.1.1+2/lib/
typed_data:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/
watcher:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+13/lib/
web_socket_channel:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.1.0/lib/
yaml:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/yaml-2.2.0/lib/
io:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/io-0.3.3/lib/
js:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib/
json_annotation:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/json_annotation-3.0.1/lib/
logging:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/logging-0.11.4/lib/
matcher:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.6/lib/
meta:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.8/lib/
mime:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/mime-0.9.6+3/lib/
node_interop:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/node_interop-1.0.3/lib/
node_io:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/node_io-1.0.1+2/lib/
package_config:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/package_config-1.9.1/lib/
package_resolver:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.10/lib/
path:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.6.4/lib/
pedantic:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.9.0/lib/
pool:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/pool-1.4.0/lib/
pub_semver:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/pub_semver-1.4.3/lib/
pubspec_parse:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/pubspec_parse-0.1.5/lib/
quiver:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.3/lib/
shelf:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shelf-0.7.5/lib/
shelf_web_socket:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.3/lib/
source_gen:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/source_gen-0.9.5/lib/
source_span:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.6.0/lib/
stack_trace:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib/
stream_channel:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.0.0/lib/
stream_transform:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/stream_transform-1.2.0/lib/
string_scanner:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.5/lib/
term_glyph:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib/
timing:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/timing-0.1.1+2/lib/
typed_data:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.6/lib/
watcher:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+13/lib/
web_socket_channel:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.1.0/lib/
yaml:file:///Users/milad/dev/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/yaml-2.2.0/lib/
example:lib/
15 changes: 9 additions & 6 deletions example/lib/injector.iconfig.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions example/lib/register_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ abstract class RegisterModule {
// @preResolve
// @Singleton(dependsOn: [TestClass])
// Future<TestSingleton> get futureSing => TestSingleton.create();
@injectable
TestSingleton2 sinleton(String xs) => TestSingleton2(xs);

TestSingleton2 get test;
}

// @Named("class")
// @injectable
class TestSingleton2 {
TestSingleton2(@factoryParam String x);
TestSingleton2(AbsService service);
}

abstract class AbsService<T> {}

@named
@RegisterAs(AbsService)
@injectable
class BackendService extends AbsService<int> {
Expand All @@ -38,8 +37,7 @@ class BackendService extends AbsService<int> {
// @injectable
class ApiClient {
@factoryMethod
static Future<ApiClient> create(
@Named.from(BackendService) AbsService service) async {
static Future<ApiClient> create(AbsService service) async {
return ApiClient();
}
}
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
version: "1.14.11"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -210,7 +210,7 @@ packages:
path: "../injectable_generator"
relative: true
source: path
version: "0.3.0"
version: "0.3.1"
io:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ environment:
sdk: ">=2.5.0 <3.0.0"

dependencies:
# flutter:
# sdk: flutter
get_it: 4.0.0

injectable:
path: ../injectable
# path: ^1.6.0
Expand Down
2 changes: 1 addition & 1 deletion injectable_generator/.packages
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by pub on 2020-03-06 16:59:38.192235.
# Generated by pub on 2020-03-07 19:06:25.964912.
_fe_analyzer_shared:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-1.0.3/lib/
analyzer:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/analyzer-0.39.4/lib/
args:file:///Users/milad/.pub-cache/hosted/pub.dartlang.org/args-1.5.2/lib/
Expand Down
7 changes: 6 additions & 1 deletion injectable_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# ChangeLog

## [0.3.1] Breaking Changes!
## [0.3.2]

- fix registered abstract dependencies are reported missing.
- fix registering third party types as singleton throws an error.

## [0.3.1]

- fix resolve by instanceName is using positional var instead of named
- fix part files are imported as stand alone
Expand Down
18 changes: 8 additions & 10 deletions injectable_generator/lib/dependency_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import 'package:source_gen/source_gen.dart';
import 'dependency_config.dart';
import 'injectable_types.dart';

const TypeChecker namedChecker = const TypeChecker.fromRuntime(Named);
const TypeChecker singletonChecker = const TypeChecker.fromRuntime(Singleton);
const TypeChecker envChecker = const TypeChecker.fromRuntime(Environment);
const TypeChecker bindChecker = const TypeChecker.fromRuntime(RegisterAs);
const TypeChecker preResolveChecker = const TypeChecker.fromRuntime(PreResolve);
const TypeChecker factoryParamChecker =
const TypeChecker.fromRuntime(FactoryParam);
const TypeChecker constructorChecker =
const TypeChecker.fromRuntime(FactoryMethod);
const TypeChecker namedChecker = TypeChecker.fromRuntime(Named);
const TypeChecker singletonChecker = TypeChecker.fromRuntime(Singleton);
const TypeChecker envChecker = TypeChecker.fromRuntime(Environment);
const TypeChecker bindChecker = TypeChecker.fromRuntime(RegisterAs);
const TypeChecker preResolveChecker = TypeChecker.fromRuntime(PreResolve);
const TypeChecker factoryParamChecker = TypeChecker.fromRuntime(FactoryParam);
const TypeChecker constructorChecker = TypeChecker.fromRuntime(FactoryMethod);

class DependencyResolver {
Element _annotatedElement;
Expand Down Expand Up @@ -191,7 +189,7 @@ class DependencyResolver {
throwBoxedIf(
_dep.injectableType != InjectableType.factory &&
(_dep.dependencies.where((d) => d.isFactoryParam).isNotEmpty ||
_dep.moduleConfig?.params != null),
_dep.moduleConfig?.params?.isNotEmpty == true),
'Error generating [${clazz.name}]! only factories can have parameters');
return _dep;
}
Expand Down
2 changes: 0 additions & 2 deletions injectable_generator/lib/generator/singleton_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class SingletonGenerator extends RegisterFuncGenerator {
constructor = generateAwaitSetup(dep, constructBody);
}

print(constructor);

final typeArg = '<${dep.type}>';

if (dep.isAsync && !dep.preResolve) {
Expand Down
4 changes: 2 additions & 2 deletions injectable_generator/lib/injectable_config_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'dependency_config.dart';
import 'generator/config_code_generator.dart';
import 'utils.dart';

const TypeChecker bindChecker = const TypeChecker.fromRuntime(RegisterAs);
const TypeChecker bindChecker = TypeChecker.fromRuntime(RegisterAs);

class InjectableConfigGenerator extends GeneratorForAnnotation<InjectableInit> {
final injectableConfigFiles = Glob("**.injectable.json");
Expand All @@ -34,7 +34,7 @@ class InjectableConfigGenerator extends GeneratorForAnnotation<InjectableInit> {
void _reportMissingDependencies(List<DependencyConfig> deps) {
final messages = [];
final registeredDeps =
deps.map((dep) => stripGenericTypes(dep.bindTo)).toSet();
deps.map((dep) => stripGenericTypes(dep.type)).toSet();
deps.forEach((dep) {
dep.dependencies.where((d) => !d.isFactoryParam).forEach((iDep) {
final strippedClassName = stripGenericTypes(iDep.type);
Expand Down
5 changes: 3 additions & 2 deletions injectable_generator/lib/injectable_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:source_gen/source_gen.dart';
import 'dependency_config.dart';
import 'dependency_resolver.dart';

const TypeChecker typeChecker = const TypeChecker.fromRuntime(Injectable);
const TypeChecker moduleChecker = const TypeChecker.fromRuntime(RegisterModule);
const TypeChecker typeChecker = TypeChecker.fromRuntime(Injectable);
const TypeChecker moduleChecker = TypeChecker.fromRuntime(RegisterModule);

class InjectableGenerator implements Generator {
RegExp _classNameMatcher, _fileNameMatcher;
Expand Down Expand Up @@ -53,6 +53,7 @@ class InjectableGenerator implements Generator {

if (allDepsInStep.isNotEmpty) {
final inputID = buildStep.inputId.changeExtension(".injectable.json");

buildStep.writeAsString(inputID, json.encode(allDepsInStep));
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion injectable_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: injectable_generator
description: Injectable is a convenient code generator for [get_it](https://pub.dev/packages/get_it). Inspired by Angular DI, Guice DI and inject.dart.
version: 0.3.1
version: 0.3.2
homepage: https://github.com/Milad-Akarie/injectable

environment:
Expand Down

0 comments on commit 0ccd5e7

Please sign in to comment.