Skip to content

Commit

Permalink
feat(cbl_generator): upgrade to analyzer 6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Dec 23, 2023
1 parent 7c2b778 commit 6a7832a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
15 changes: 5 additions & 10 deletions packages/cbl_generator/lib/src/analysis.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart';
import 'package:source_helper/source_helper.dart';

Expand Down Expand Up @@ -32,7 +32,7 @@ class _ClassHasRedirectingUnnamedConstructorVisitor
}
hasRedirectingConstructor = node.factoryKeyword != null &&
// ignore: deprecated_member_use
node.redirectedConstructor?.type.name.name == targetConstructor;
node.redirectedConstructor?.type.name2.lexeme == targetConstructor;
}
}

Expand All @@ -52,21 +52,16 @@ class _ClassHasMixinVisitor extends RecursiveAstVisitor<void> {
@override
void visitWithClause(WithClause node) {
// ignore: deprecated_member_use
hasMixin = node.mixinTypes.any((mixin) => mixin.name.name == mixinName);
hasMixin = node.mixinTypes.any((mixin) => mixin.name2.lexeme == mixinName);
}
}

bool isExactlyOneOfTypes(DartType type, Iterable<TypeChecker> typeCheckers) =>
typeCheckers.any((typeChecker) => typeChecker.isExactlyType(type));

extension ParameterElementExt on ParameterElement {
String? get documentationCommentValue =>
(session!.getParsedLibraryByElement(library!) as ParsedLibraryResult)
.getElementDeclaration(this)!
.node
.beginToken
.precedingComments
?.value();
Future<String?> documentationCommentValue(Resolver resolver) async =>
(await resolver.astNodeFor(this))!.beginToken.precedingComments?.value();
}

extension ConstantReaderExt on ConstantReader {
Expand Down
16 changes: 9 additions & 7 deletions packages/cbl_generator/lib/src/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class TypedDataAnalyzer {
kind,
);

final fields = _resolveTypedDataFields(annotatedClass, kind, cblLibrary);
final fields =
await _resolveTypedDataFields(annotatedClass, kind, cblLibrary);
final documentIdField = fields
.whereType<TypedDataMetadataField>()
.firstWhereOrNull((field) => field.kind == DocumentMetadataKind.id);
Expand Down Expand Up @@ -321,13 +322,13 @@ class TypedDataAnalyzer {
return null;
}

List<TypedDataObjectField> _resolveTypedDataFields(
Future<List<TypedDataObjectField>> _resolveTypedDataFields(
ClassElement clazz,
TypedDataObjectKind kind,
LibraryElement cblLibrary,
) =>
clazz.unnamedConstructor!.parameters.map(
(parameter) {
) async =>
Future.wait(clazz.unnamedConstructor!.parameters.map(
(parameter) async {
final annotations = parameter.metadata
.map((annotation) => annotation.computeConstantValue())
.map(ConstantReader.new);
Expand Down Expand Up @@ -375,7 +376,8 @@ class TypedDataAnalyzer {
isPositional: parameter.isPositional,
isRequired:
parameter.isRequiredNamed || parameter.isRequiredPositional,
documentationComment: parameter.documentationCommentValue,
documentationComment:
await parameter.documentationCommentValue(resolver),
);

final isDocumentId = _isDocumentIdField(parameter, annotations, kind);
Expand All @@ -396,7 +398,7 @@ class TypedDataAnalyzer {
defaultValueCode: defaultValueCode,
);
},
).toList();
));

bool _isDocumentIdField(
ParameterElement parameter,
Expand Down
2 changes: 1 addition & 1 deletion packages/cbl_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
sdk: ^3.0.0

dependencies:
analyzer: ^5.1.0
analyzer: ^6.0.0
build: ^2.3.0
build_config: ^1.0.0
cbl: ^3.0.0-dev.2
Expand Down
2 changes: 1 addition & 1 deletion tools/ci-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function checkBuildRunnerOutput() {

cd "$testPackageDir"

dart run build_runner build --delete-conflicting-outputs
dart run build_runner build --delete-conflicting-outputs --verbose

# Verify that the the build output did not change by checking if the repo is dirty.
# This check is flaky in CI. We check multiple times on the hunch that there is some kind of
Expand Down

0 comments on commit 6a7832a

Please sign in to comment.