Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/reactive_forms_annotations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [8.5.0-beta10]

* analyzer 10 compatibility

## [8.5.0-beta9]

* analyzer 9 compatibility
Expand Down
2 changes: 1 addition & 1 deletion packages/reactive_forms_annotations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: reactive_forms_annotations
description: Annotations for reactive_forms_generator
repository: https://github.com/artflutter/reactive_forms_generator

version: 8.5.0-beta9
version: 8.5.0-beta10

environment:
sdk: ">=3.8.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/reactive_forms_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [8.5.0-beta10]

* analyzer 10 compatibility

## [8.5.0-beta9]

* analyzer 9 compatibility
Expand Down
28 changes: 23 additions & 5 deletions packages/reactive_forms_generator/lib/src/output/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,50 @@ import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:reactive_forms_generator/src/output/extensions.dart';

void replaceNode(AstNode oldNode, AstNode newNode) {
final parent = oldNode.parent;
if (parent is BlockClassBodyImpl &&
oldNode is ClassMemberImpl &&
newNode is ClassMemberImpl) {
final members = parent.members;
final index = members.indexWhere((member) => identical(member, oldNode));
if (index == -1) {
throw ArgumentError('The old node is not a child of its parent');
}

members[index] = newNode;
return;
}

NodeReplacer.replace(oldNode, newNode);
}

void replaceR(
Map<String, FieldDeclaration> fieldDeclaration,
Map<String, FormalParameter> fieldFormalParameter,
) {
fieldFormalParameter.forEach((key, node) {
if (node is SimpleFormalParameterImpl) {
NodeReplacer.replace(node, node.newParameter);
replaceNode(node, node.newParameter);
} else if (node is DefaultFormalParameterImpl) {
final parameter = node.parameter;

if (parameter is SimpleFormalParameterImpl) {
final field = fieldDeclaration[key];
if (field != null && field is FieldDeclarationImpl) {
NodeReplacer.replace(field, field.newField);
replaceNode(field, field.newField);
}

NodeReplacer.replace(node, node.newParameter2);
replaceNode(node, node.newParameter2);
}

if (parameter is FieldFormalParameterImpl) {
final field = fieldDeclaration[key];
if (field != null && field is FieldDeclarationImpl) {
NodeReplacer.replace(field, field.newField);
replaceNode(field, field.newField);
}

NodeReplacer.replace(node, node.newParameter2);
replaceNode(node, node.newParameter2);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,51 @@ extension on ClassDeclarationImpl {
finalKeyword: finalKeyword,
mixinKeyword: mixinKeyword,
classKeyword: classKeyword,
name: _outputToken(name.lexeme),
namePart: ClassNamePartImplStub(),
typeParameters: typeParameters,
namePart: namePart.outputClassNamePart,
extendsClause: extendsClause,
withClause: withClause?.outputWithClause,
implementsClause: implementsClause,
nativeClause: nativeClause,
body: ClassBodyImplStub(),
leftBracket: leftBracket,
members: members.map((member) => member.outputMember).toList(),
rightBracket: rightBracket,
body: body.outputClassBody,
);
}
}

extension on ClassNamePartImpl {
ClassNamePartImpl get outputClassNamePart {
return switch (this) {
final NameWithTypeParametersImpl part => NameWithTypeParametersImpl(
typeName: _outputToken(part.typeName.lexeme),
typeParameters: part.typeParameters,
),
final PrimaryConstructorDeclarationImpl part =>
PrimaryConstructorDeclarationImpl(
constKeyword: part.constKeyword,
typeName: _outputToken(part.typeName.lexeme),
typeParameters: part.typeParameters,
constructorName: part.constructorName,
formalParameters: part.formalParameters,
),
};
}
}

extension on ClassBodyImpl {
ClassBodyImpl get outputClassBody {
return switch (this) {
final BlockClassBodyImpl body => BlockClassBodyImpl(
leftBracket: body.leftBracket,
members: body.members.map((member) => member.outputMember).toList(),
rightBracket: body.rightBracket,
),
final EmptyClassBodyImpl body => EmptyClassBodyImpl(
semicolon: body.semicolon,
),
_ => this,
};
}
}

extension on WithClauseImpl {
WithClauseImpl get outputWithClause {
return WithClauseImpl(
Expand All @@ -125,27 +155,32 @@ extension on ClassMemberImpl {
final ConstructorDeclarationImpl member => member.outputConstructor,
final FieldDeclarationImpl member => member.outputField,
final MethodDeclarationImpl member => member,
final PrimaryConstructorBodyImpl member => member,
};
}
}

extension on ConstructorDeclarationImpl {
ConstructorDeclarationImpl get outputConstructor {
final typeName = this.typeName;
return ConstructorDeclarationImpl(
comment: null,
metadata: metadata,
augmentKeyword: augmentKeyword,
externalKeyword: externalKeyword,
constKeyword: constKeyword,
factoryKeyword: factoryKeyword,
returnType: SimpleIdentifierImpl(token: _outputToken(returnType.name)),
newKeyword: newKeyword,
typeName: typeName == null
? null
: SimpleIdentifierImpl(token: _outputToken(typeName.name)),
period: period,
name: name,
parameters: parameters,
separator: separator,
initializers: initializers,
redirectedConstructor: redirectedConstructor?.outputConstructorName,
body: body.outputBody(returnType.name),
body: body.outputBody(typeName?.name),
);
}
}
Expand All @@ -161,7 +196,7 @@ extension on ConstructorNameImpl {
}

extension on FunctionBodyImpl {
FunctionBodyImpl outputBody(String returnTypeName) {
FunctionBodyImpl outputBody(String? returnTypeName) {
return switch (this) {
final ExpressionFunctionBodyImpl body => body.outputExpressionBody(
returnTypeName,
Expand All @@ -172,7 +207,7 @@ extension on FunctionBodyImpl {
}

extension on ExpressionFunctionBodyImpl {
ExpressionFunctionBodyImpl outputExpressionBody(String returnTypeName) {
ExpressionFunctionBodyImpl outputExpressionBody(String? returnTypeName) {
return ExpressionFunctionBodyImpl(
keyword: keyword,
star: star,
Expand All @@ -184,7 +219,7 @@ extension on ExpressionFunctionBodyImpl {
}

extension on ExpressionImpl {
ExpressionImpl outputExpression(String returnTypeName) {
ExpressionImpl outputExpression(String? returnTypeName) {
return switch (this) {
final MethodInvocationImpl expression =>
expression.outputMethodInvocation(returnTypeName),
Expand All @@ -194,7 +229,11 @@ extension on ExpressionImpl {
}

extension on MethodInvocationImpl {
MethodInvocationImpl outputMethodInvocation(String returnTypeName) {
MethodInvocationImpl outputMethodInvocation(String? returnTypeName) {
if (returnTypeName == null) {
return this;
}

return MethodInvocationImpl(
target: target,
operator: operator,
Expand Down
4 changes: 2 additions & 2 deletions packages/reactive_forms_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: reactive_forms_generator
description: Generator for reactive_forms. Generates form classes based on model.
repository: https://github.com/artflutter/reactive_forms_generator

version: 8.5.0-beta9
version: 8.5.0-beta10

environment:
sdk: ">=3.8.0 <4.0.0"
Expand All @@ -11,7 +11,7 @@ resolution: workspace
dependencies:
build: ^4.0.1
source_gen: ^4.1.2
analyzer: ^9.0.0
analyzer: ^10.0.0
path: ^1.8.1
build_runner: ^2.7.0
code_builder: ^4.10.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ class User {
''',
).unit;

return unit.declarations
.whereType<ClassDeclaration>()
.single
.members
final classBody = unit.declarations.whereType<ClassDeclaration>().single.body;

return (classBody as BlockClassBody).members
.whereType<ConstructorDeclaration>()
.single
.parameters
Expand Down
14 changes: 7 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "5b7468c326d2f8a4f630056404ca0d291ade42918f4a3c6233618e724f39da8e"
sha256: "8d7ff3948166b8ec5da0fbb5962000926b8e02f2ed9b3e51d1738905fbd4c98d"
url: "https://pub.dev"
source: hosted
version: "92.0.0"
version: "93.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "70e4b1ef8003c64793a9e268a551a82869a8a96f39deb73dea28084b0e8bf75e"
sha256: de7148ed2fcec579b19f122c1800933dfa028f6d9fd38a152b04b1516cec120b
url: "https://pub.dev"
source: hosted
version: "9.0.0"
version: "10.0.1"
ansi_styles:
dependency: transitive
description:
Expand Down Expand Up @@ -221,10 +221,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: a9c30492da18ff84efe2422ba2d319a89942d93e58eb0b73d32abe822ef54b7b
sha256: "29f7ecc274a86d32920b1d9cfc7502fa87220da41ec60b55f329559d5732e2b2"
url: "https://pub.dev"
source: hosted
version: "3.1.3"
version: "3.1.7"
dartz:
dependency: transitive
description:
Expand Down Expand Up @@ -830,5 +830,5 @@ packages:
source: hosted
version: "2.2.4"
sdks:
dart: ">=3.9.0 <4.0.0"
dart: ">=3.10.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
Loading