This repository was archived by the owner on May 25, 2022. It is now read-only.
File tree 6 files changed +37
-13
lines changed
6 files changed +37
-13
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## 0.0.6
4
+
5
+ - Check for missing import statement.
6
+ - Fix constraints for source_gen.
7
+
3
8
## 0.0.5
4
9
5
10
- Fix generation across multiple files, allow reuse of generated identifiers.
Original file line number Diff line number Diff line change 1
1
name : enum_class
2
- version : 0.0.5
2
+ version : 0.0.6
3
3
description : >
4
4
Dart classes as enums. This library is the runtime dependency.
5
5
authors :
Original file line number Diff line number Diff line change @@ -29,10 +29,20 @@ class EnumClassGenerator extends Generator {
29
29
final classElement = element as ClassElement ;
30
30
final enumName = classElement.displayName;
31
31
32
- // TODO(davidmorgan): do this in a way that works if the import is missing.
33
- if (classElement.allSupertypes
34
- .where ((i) => i.displayName == 'EnumClass' )
35
- .isEmpty) return null ;
32
+ if (classElement.supertype.displayName != 'EnumClass' ) {
33
+ // Maybe they're trying to use EnumClass but forgot to import the library.
34
+ if (classElement
35
+ .computeNode ()
36
+ .toSource ()
37
+ .contains ('class ${classElement .displayName } extends EnumClass' )) {
38
+ throw new InvalidGenerationSourceError (
39
+ 'Please make changes to use EnumClass.' ,
40
+ todo:
41
+ "Import EnumClass: import 'package:enum_class/enum_class.dart';" );
42
+ } else {
43
+ return null ;
44
+ }
45
+ }
36
46
37
47
final fields = _getApplicableFields (classElement);
38
48
final errors = concat ([
Original file line number Diff line number Diff line change 1
1
name : enum_class_generator
2
- version : 0.0.5
2
+ version : 0.0.6
3
3
description : >
4
4
Dart classes as enums. This library is the dev dependency.
5
5
authors :
@@ -12,8 +12,8 @@ environment:
12
12
dependencies :
13
13
analyzer : ' >=0.26.1 <1.0.0'
14
14
built_collection : ' ^1.0.0'
15
- enum_class : ' ^0.0.5 '
16
- source_gen : ' >=0.4.3 <1.0 .0'
15
+ enum_class : ' ^0.0.6 '
16
+ source_gen : ' >=0.4.3 <0.5 .0'
17
17
quiver : ' >=0.21.0 <0.22.0'
18
18
19
19
dev_dependencies :
Original file line number Diff line number Diff line change @@ -105,8 +105,7 @@ part of test_enum;
105
105
''' ));
106
106
});
107
107
108
- // TODO(davidmorgan): it would be better to fail with an error message.
109
- test ('fails silently on missing enum_class import' , () async {
108
+ test ('fails with error on missing enum_class import' , () async {
110
109
expect (await generate (r'''
111
110
library test_enum;
112
111
@@ -122,7 +121,17 @@ class TestEnum extends EnumClass {
122
121
static BuiltSet<TestEnum> get values => _$values;
123
122
static TestEnum valueOf(String name) => _$valueOf(name);
124
123
}
125
- ''' ), isEmpty);
124
+ ''' ), endsWith (r'''
125
+ part of test_enum;
126
+
127
+ // **************************************************************************
128
+ // Generator: EnumClassGenerator
129
+ // Target: class TestEnum
130
+ // **************************************************************************
131
+
132
+ // Error: Please make changes to use EnumClass.
133
+ // TODO: Import EnumClass: import 'package:enum_class/enum_class.dart';
134
+ ''' ));
126
135
});
127
136
128
137
test ('fails with error on missing part statement' , () async {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ environment:
10
10
sdk : ' >=1.8.0 <2.0.0'
11
11
12
12
dependencies :
13
- enum_class : ' ^0.0.4 '
13
+ enum_class : ' ^0.0.6 '
14
14
15
15
dev_dependencies :
16
- enum_class_generator : ' ^0.0.4 '
16
+ enum_class_generator : ' ^0.0.6 '
You can’t perform that action at this time.
0 commit comments