Skip to content

Commit

Permalink
Update analyzer and dart_style dependencies to allow upper versio…
Browse files Browse the repository at this point in the history
…ns (#727)

* Update `analyzer` and `dart_style` dependencies to allow upper versions

* Update source_gen

* Format generator.dart

* Update generator_tests
  • Loading branch information
Carapacik authored Dec 30, 2024
1 parent e8bdb48 commit dccfb6c
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 453 deletions.
4 changes: 3 additions & 1 deletion generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog
## 9.1.6

- Update `analyzer`, `dart_style` and `source_gen` dependencies to allow upper versions

## 9.1.5

Expand Down
24 changes: 16 additions & 8 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
});

final emitter = DartEmitter(useNullSafetySyntax: true);
return DartFormatter()
return DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
.format([_analyzerIgnores, classBuilder.accept(emitter)].join('\n\n'));
}

Expand Down Expand Up @@ -1727,7 +1727,7 @@ if (T != dynamic &&
.assign(refer(bodyName.displayName))
.statement,
);
} else if (_missingSerialize(ele.enclosingElement, bodyName.type)) {
} else if (_missingSerialize(ele.enclosingElement3, bodyName.type)) {
log.warning(
'${_displayString(bodyName.type)} must provide a `serialize${_displayString(bodyName.type)}()` method which returns a Map.\n'
"It is programmer's responsibility to make sure the ${_displayString(bodyName.type)} is properly serialized");
Expand Down Expand Up @@ -1911,7 +1911,7 @@ ${bodyName.displayName} == null
blocks.add(returnCode);
}
if (p.type.isNullable) {
blocks.add(Code('}'));
blocks.add(const Code('}'));
}
} else if (_displayString(p.type) == 'List<int>') {
final optionalFile = m.parameters
Expand Down Expand Up @@ -2278,10 +2278,18 @@ ${bodyName.displayName} == null
}

Object? _getFieldValue(ConstantReader? value) {
if (value?.isBool ?? false) return value?.boolValue;
if (value?.isDouble ?? false) return value?.doubleValue;
if (value?.isInt ?? false) return value?.intValue;
if (value?.isString ?? false) return value?.stringValue;
if (value?.isBool ?? false) {
return value?.boolValue;
}
if (value?.isDouble ?? false) {
return value?.doubleValue;
}
if (value?.isInt ?? false) {
return value?.intValue;
}
if (value?.isString ?? false) {
return value?.stringValue;
}
if (value?.objectValue.isEnum ?? false) {
return value?.objectValue.variable?.displayName;
}
Expand All @@ -2308,7 +2316,7 @@ ${bodyName.displayName} == null
final fields = <String, Object?>{};
final type = value!.objectValue.type;
if (type is InterfaceType) {
for (var field in type.element.fields) {
for (final field in type.element.fields) {
if (!field.isStatic) {
final fieldValue = value.peek(field.name);
fields[field.name] = _getFieldValue(fieldValue);
Expand Down
12 changes: 6 additions & 6 deletions generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ topics:
- rest
- retrofit
- codegen
version: 9.1.5
version: 9.1.6
environment:
sdk: '>=3.3.0 <4.0.0'

dependencies:
analyzer: ^6.5.0
analyzer: '>=6.9.0 <8.0.0'
build: ^2.4.1
built_collection: ^5.1.1
code_builder: ^4.10.0
dart_style: ^2.3.0
dart_style: '>=2.3.7 <4.0.0'
dio: ^5.0.0
protobuf: ^3.1.0
retrofit: ^4.4.0
source_gen: ^1.5.0
retrofit: ^4.4.1
source_gen: '>=1.5.0 <3.0.0'

dev_dependencies:
lints: ^4.0.0
lints: any
source_gen_test: ^1.0.6
test: ^1.25.0
2 changes: 1 addition & 1 deletion generator/test/generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Future<void> main() async {
RetrofitGenerator(RetrofitOptions()),
defaultConfiguration: ['default'],
additionalGenerators: {
'use_result': RetrofitGenerator(RetrofitOptions(useResult: true))
'use_result': RetrofitGenerator(RetrofitOptions(useResult: true)),
},
);
}
Loading

0 comments on commit dccfb6c

Please sign in to comment.