From c2f34182512c7a2fb90af6cb14d18df7f441216f Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 9 Apr 2024 18:51:48 +0000 Subject: [PATCH] DAS: Rename 'add___Insertion' to 'insert___' APIs Change-Id: I57693591999e0845e6a3560a19de770eef4968b2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362001 Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins Reviewed-by: Brian Wilkerson --- .../add_diagnostic_property_reference.dart | 2 +- .../dart/add_key_to_constructors.dart | 2 +- .../dart/add_missing_enum_case_clauses.dart | 2 +- .../add_missing_enum_like_case_clauses.dart | 2 +- .../dart/add_missing_switch_cases.dart | 4 +- .../correction/dart/create_constructor.dart | 4 +- .../create_constructor_for_final_fields.dart | 8 +- .../dart/create_constructor_super.dart | 4 +- .../correction/dart/create_field.dart | 4 +- .../correction/dart/create_getter.dart | 2 +- .../correction/dart/create_method.dart | 2 +- .../correction/dart/create_setter.dart | 2 +- .../legacy/rename_constructor.dart | 2 +- .../change_builder/change_builder_dart.dart | 188 +++++++++--------- .../change_builder/change_builder_dart.dart | 100 +++++----- 15 files changed, 165 insertions(+), 163 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart index f2a86fef9a9f..5aaf7753e2f3 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart @@ -123,7 +123,7 @@ class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer { .singleOrNull; if (debugFillProperties == null) { await builder.addDartFileEdit(file, (builder) { - builder.addMethodInsertion(classDeclaration, (builder) { + builder.insertMethod(classDeclaration, (builder) { final declPrefix = utils.oneIndent; final bodyPrefix = utils.twoIndents; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_key_to_constructors.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_key_to_constructors.dart index 57c337a60420..521c99074103 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_key_to_constructors.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_key_to_constructors.dart @@ -84,7 +84,7 @@ class AddKeyToConstructors extends ResolvedCorrectionProducer { var canBeConst = _canBeConst(node, constructors); await builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(node, (builder) { + builder.insertConstructor(node, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. if (canBeConst) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_case_clauses.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_case_clauses.dart index 4a25efc16435..46953fe2eaf8 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_case_clauses.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_case_clauses.dart @@ -88,7 +88,7 @@ class AddMissingEnumCaseClauses extends ResolvedCorrectionProducer { await builder.addDartFileEdit(file, (builder) { // TODO(brianwilkerson): Consider inserting the names in order into the // switch statement. - builder.addCaseClauseAtEndInsertion( + builder.insertCaseClauseAtEnd( switchKeyword: statement.switchKeyword, rightParenthesis: statement.rightParenthesis, leftBracket: statement.leftBracket, diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_like_case_clauses.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_like_case_clauses.dart index f5f55e2485e4..5f3c2396e4dd 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_like_case_clauses.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_enum_like_case_clauses.dart @@ -39,7 +39,7 @@ class AddMissingEnumLikeCaseClauses extends ResolvedCorrectionProducer { await builder.addDartFileEdit(file, (builder) { // TODO(brianwilkerson): Consider inserting the names in order into the // switch statement. - builder.addCaseClauseAtEndInsertion( + builder.insertCaseClauseAtEnd( switchKeyword: node.switchKeyword, rightParenthesis: node.rightParenthesis, leftBracket: node.leftBracket, diff --git a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_switch_cases.dart b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_switch_cases.dart index 688096c0985c..00e1788da5d8 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/add_missing_switch_cases.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/add_missing_switch_cases.dart @@ -61,7 +61,7 @@ class AddMissingSwitchCases extends ResolvedCorrectionProducer { final singleIndent = utils.oneIndent; await builder.addDartFileEdit(file, (builder) { - builder.addCaseClauseAtEndInsertion( + builder.insertCaseClauseAtEnd( switchKeyword: node.switchKeyword, rightParenthesis: node.rightParenthesis, leftBracket: node.leftBracket, @@ -86,7 +86,7 @@ class AddMissingSwitchCases extends ResolvedCorrectionProducer { final singleIndent = utils.oneIndent; await builder.addDartFileEdit(file, (builder) { - builder.addCaseClauseAtEndInsertion( + builder.insertCaseClauseAtEnd( switchKeyword: node.switchKeyword, rightParenthesis: node.rightParenthesis, leftBracket: node.leftBracket, diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart index d47c13ac6140..4edf3e8a9146 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor.dart @@ -167,7 +167,7 @@ class CreateConstructor extends ResolvedCorrectionProducer { var targetSource = targetElement.source; var targetFile = targetSource.fullName; await builder.addDartFileEdit(targetFile, (builder) { - builder.addConstructorInsertion(targetNode, (builder) { + builder.insertConstructor(targetNode, (builder) { builder.writeConstructorDeclaration(targetElement.name, argumentList: instanceCreation.argumentList); }); @@ -185,7 +185,7 @@ class CreateConstructor extends ResolvedCorrectionProducer { }) async { var targetFile = resolvedUnit.file.path; await builder.addDartFileEdit(targetFile, (builder) { - builder.addConstructorInsertion(unitMember, (builder) { + builder.insertConstructor(unitMember, (builder) { builder.writeConstructorDeclaration(unitMember.name.lexeme, isConst: isConst, argumentList: argumentList, diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_for_final_fields.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_for_final_fields.dart index 605a4b4f40d3..19fa0da4bb54 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_for_final_fields.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_for_final_fields.dart @@ -148,7 +148,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer { } await fixContext.builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(classDeclaration, (builder) { + builder.insertConstructor(classDeclaration, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. builder.write('const '); @@ -177,7 +177,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer { required NamedCompilationUnitMember classDeclaration, }) async { await fixContext.builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(classDeclaration, (builder) { + builder.insertConstructor(classDeclaration, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. builder.write('const '); @@ -204,7 +204,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer { final fieldsForInitializers = <_Field>[]; await fixContext.builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(containerDeclaration, (builder) { + builder.insertConstructor(containerDeclaration, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. if (isConst) { @@ -266,7 +266,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer { required List<_Field> fields, }) async { await fixContext.builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(containerDeclaration, (builder) { + builder.insertConstructor(containerDeclaration, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. if (isConst) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_super.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_super.dart index 1b5385528579..c648e2166464 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_super.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_constructor_super.dart @@ -92,7 +92,7 @@ class _CreateConstructor extends ResolvedCorrectionProducer { var requiredNamedParameters = _constructor.parameters.where((parameter) => parameter.isRequiredNamed); await builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(_targetClass, (builder) { + builder.insertConstructor(_targetClass, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. void writeParameters(bool isDefinition) { @@ -173,7 +173,7 @@ class _CreateConstructor extends ResolvedCorrectionProducer { var requiredNamedParameters = _constructor.parameters.where((parameter) => parameter.isRequiredNamed); await builder.addDartFileEdit(file, (builder) { - builder.addConstructorInsertion(_targetClass, (builder) { + builder.insertConstructor(_targetClass, (builder) { // TODO(srawlins): Replace this block with `writeConstructorDeclaration` // and `parameterWriter`. void writeParameter(ParameterElement parameter) { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_field.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_field.dart index b452b6b6d9c8..e151f165c37a 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_field.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_field.dart @@ -82,7 +82,7 @@ class CreateField extends CreateFieldOrGetter { var targetSource = targetElement.source; var targetFile = targetSource.fullName; await builder.addDartFileEdit(targetFile, (builder) { - builder.addFieldInsertion(targetNode, (builder) { + builder.insertField(targetNode, (builder) { builder.writeFieldDeclaration(_fieldName, isStatic: staticModifier, nameGroupName: 'NAME', @@ -104,7 +104,7 @@ class CreateField extends CreateFieldOrGetter { // Add proposal. await builder.addDartFileEdit(file, (builder) { var fieldType = parameter.type?.type; - builder.addFieldInsertion(targetClassNode, (builder) { + builder.insertField(targetClassNode, (builder) { builder.writeFieldDeclaration(_fieldName, nameGroupName: 'NAME', type: fieldType, typeGroupName: 'TYPE'); }); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_getter.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_getter.dart index 0631fd1534ac..f061d8166a80 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_getter.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_getter.dart @@ -212,7 +212,7 @@ class CreateGetter extends CreateFieldOrGetter { // Build method source. var targetFile = targetSource.fullName; await builder.addDartFileEdit(targetFile, (builder) { - builder.addGetterInsertion( + builder.insertGetter( targetNode, (builder) { builder.writeGetterDeclaration(_getterName, diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart index 43112951fc71..1925534e0496 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_method.dart @@ -188,7 +188,7 @@ class CreateMethod extends ResolvedCorrectionProducer { if (targetNode == null) { return; } - builder.addMethodInsertion(targetNode, (builder) { + builder.insertMethod(targetNode, (builder) { // Maybe 'static'. if (staticModifier) { builder.write('static '); diff --git a/pkg/analysis_server/lib/src/services/correction/dart/create_setter.dart b/pkg/analysis_server/lib/src/services/correction/dart/create_setter.dart index 13016bed8cb2..d8a19aa07059 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/create_setter.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/create_setter.dart @@ -98,7 +98,7 @@ class CreateSetter extends ResolvedCorrectionProducer { var targetFile = targetSource.fullName; _setterName = nameNode.name; await builder.addDartFileEdit(targetFile, (builder) { - builder.addGetterInsertion( + builder.insertGetter( targetNode, (builder) { var parameterTypeNode = climbPropertyAccess(nameNode); diff --git a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart index f3c5a728a2be..4d641c3796ca 100644 --- a/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart +++ b/pkg/analysis_server/lib/src/services/refactoring/legacy/rename_constructor.dart @@ -108,7 +108,7 @@ class RenameConstructorRefactoringImpl extends RenameRefactoringImpl { ) async { var builder = ChangeBuilder(session: sessionHelper.session); await builder.addDartFileEdit(resolvedUnit.path, (builder) { - builder.addConstructorInsertion(container, buildEdit); + builder.insertConstructor(container, buildEdit); }); var fileEdit = builder.sourceChange.getFileEdit(resolvedUnit.path); if (fileEdit == null) { diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart index 48f6b5517489..f076ad29958b 100644 --- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart +++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart @@ -1411,86 +1411,6 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl @override List get requiredImports => librariesToImport.keys.toList(); - @override - void addCaseClauseAtEndInsertion( - void Function(DartEditBuilder builder) buildEdit, { - required Token switchKeyword, - required Token rightParenthesis, - required Token leftBracket, - required Token rightBracket, - }) { - var blockStart = resolvedUnit.lineInfo.getLocation(leftBracket.offset); - var blockEnd = resolvedUnit.lineInfo.getLocation(rightBracket.offset); - var isBlockSingleLine = blockStart.lineNumber == blockEnd.lineNumber; - int offset; - if (isBlockSingleLine) { - offset = leftBracket.isSynthetic ? rightParenthesis.end : leftBracket.end; - } else { - offset = resolvedUnit.lineInfo.getOffsetOfLine(blockEnd.lineNumber - 1); - } - - addInsertion(offset, (builder) { - if (leftBracket.isSynthetic) { - builder.write(' {'); - } - if (isBlockSingleLine) { - builder.writeln(); - } - buildEdit(builder); - if (isBlockSingleLine) { - builder.write(resolvedUnit.linePrefix(switchKeyword.offset)); - } - if (rightBracket.isSynthetic) { - builder.write('}'); - } - }); - } - - @override - void addConstructorInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ) { - final sortConstructorsFirst = resolvedUnit.session.analysisContext - .getAnalysisOptionsForFile(resolvedUnit.file) - .codeStyleOptions - .sortConstructorsFirst; - var lastMemberFilter = sortConstructorsFirst - ? (member) => member is ConstructorDeclaration - : (member) => - member is ConstructorDeclaration || member is FieldDeclaration; - _addCompilationUnitMemberInsertion( - compilationUnitMember, - buildEdit, - lastMemberFilter: lastMemberFilter, - ); - } - - @override - void addFieldInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ) => - _addCompilationUnitMemberInsertion( - compilationUnitMember, - buildEdit, - lastMemberFilter: (member) => member is FieldDeclaration, - ); - - @override - void addGetterInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ) => - _addCompilationUnitMemberInsertion( - compilationUnitMember, - buildEdit, - lastMemberFilter: (member) => - member is FieldDeclaration || - member is ConstructorDeclaration || - member is MethodDeclaration && member.isGetter, - ); - @override void addInsertion( int offset, void Function(DartEditBuilder builder) buildEdit, @@ -1499,20 +1419,6 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl offset, (builder) => buildEdit(builder as DartEditBuilder), insertBeforeExisting: insertBeforeExisting); - @override - void addMethodInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ) => - _addCompilationUnitMemberInsertion( - compilationUnitMember, - buildEdit, - lastMemberFilter: (member) => - member is FieldDeclaration || - member is ConstructorDeclaration || - member is MethodDeclaration, - ); - @override void addReplacement(SourceRange range, void Function(DartEditBuilder builder) buildEdit) => @@ -1711,6 +1617,100 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl return false; } + @override + void insertCaseClauseAtEnd( + void Function(DartEditBuilder builder) buildEdit, { + required Token switchKeyword, + required Token rightParenthesis, + required Token leftBracket, + required Token rightBracket, + }) { + var blockStart = resolvedUnit.lineInfo.getLocation(leftBracket.offset); + var blockEnd = resolvedUnit.lineInfo.getLocation(rightBracket.offset); + var isBlockSingleLine = blockStart.lineNumber == blockEnd.lineNumber; + int offset; + if (isBlockSingleLine) { + offset = leftBracket.isSynthetic ? rightParenthesis.end : leftBracket.end; + } else { + offset = resolvedUnit.lineInfo.getOffsetOfLine(blockEnd.lineNumber - 1); + } + + addInsertion(offset, (builder) { + if (leftBracket.isSynthetic) { + builder.write(' {'); + } + if (isBlockSingleLine) { + builder.writeln(); + } + buildEdit(builder); + if (isBlockSingleLine) { + builder.write(resolvedUnit.linePrefix(switchKeyword.offset)); + } + if (rightBracket.isSynthetic) { + builder.write('}'); + } + }); + } + + @override + void insertConstructor( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ) { + final sortConstructorsFirst = resolvedUnit.session.analysisContext + .getAnalysisOptionsForFile(resolvedUnit.file) + .codeStyleOptions + .sortConstructorsFirst; + var lastMemberFilter = sortConstructorsFirst + ? (member) => member is ConstructorDeclaration + : (member) => + member is ConstructorDeclaration || member is FieldDeclaration; + _addCompilationUnitMemberInsertion( + compilationUnitMember, + buildEdit, + lastMemberFilter: lastMemberFilter, + ); + } + + @override + void insertField( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ) => + _addCompilationUnitMemberInsertion( + compilationUnitMember, + buildEdit, + lastMemberFilter: (member) => member is FieldDeclaration, + ); + + @override + void insertGetter( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ) => + _addCompilationUnitMemberInsertion( + compilationUnitMember, + buildEdit, + lastMemberFilter: (member) => + member is FieldDeclaration || + member is ConstructorDeclaration || + member is MethodDeclaration && member.isGetter, + ); + + @override + void insertMethod( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ) => + _addCompilationUnitMemberInsertion( + compilationUnitMember, + buildEdit, + lastMemberFilter: (member) => + member is FieldDeclaration || + member is ConstructorDeclaration || + member is MethodDeclaration, + ); + @override void replaceTypeWithFuture( TypeAnnotation? typeAnnotation, TypeProvider typeProvider) { diff --git a/pkg/analyzer_plugin/lib/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/utilities/change_builder/change_builder_dart.dart index 3f8fb91eac17..400c823cb76f 100644 --- a/pkg/analyzer_plugin/lib/utilities/change_builder/change_builder_dart.dart +++ b/pkg/analyzer_plugin/lib/utilities/change_builder/change_builder_dart.dart @@ -325,60 +325,13 @@ abstract class DartFileEditBuilder implements FileEditBuilder { /// edits. List get requiredImports; - /// Adds an insertion for a case clause at the end of a switch statement or - /// switch expression. - void addCaseClauseAtEndInsertion( - void Function(DartEditBuilder builder) buildEdit, { - required Token switchKeyword, - required Token rightParenthesis, - required Token leftBracket, - required Token rightBracket, - }); - - /// Adds an insertion for a constructor. - /// - /// The constructor is inserted after the last existing field or constructor, - /// or if the `sort_constructors_first` lint rule is enabled, after the last - /// existing constructor. - void addConstructorInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ); - - /// Adds an insertion for a field. - /// - /// The field is inserted after the last existing field, or at the beginning - /// of [compilationUnitMember], if it has no existing fields. - void addFieldInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ); - - /// Adds an insertion for a getter. - /// - /// The getter is inserted after the last existing field, constructor, or - /// getter, or at the beginning of [compilationUnitMember], if it has none of - /// these. - void addGetterInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ); - @override + // TODO(srawlins): Rename to `insert`. void addInsertion( int offset, void Function(DartEditBuilder builder) buildEdit); - /// Adds an insertion for a method. - /// - /// The method is inserted after the last existing field, constructor, or - /// method, or at the beginning of [compilationUnitMember], if it has none of - /// these. - void addMethodInsertion( - CompilationUnitMember compilationUnitMember, - void Function(DartEditBuilder builder) buildEdit, - ); - @override + // TODO(srawlins): Rename to `replace`. void addReplacement( SourceRange range, void Function(DartEditBuilder builder) buildEdit); @@ -443,6 +396,55 @@ abstract class DartFileEditBuilder implements FileEditBuilder { /// imported by a scheduled edit. bool importsLibrary(Uri uri); + /// Adds an insertion for a case clause at the end of a switch statement or + /// switch expression. + void insertCaseClauseAtEnd( + void Function(DartEditBuilder builder) buildEdit, { + required Token switchKeyword, + required Token rightParenthesis, + required Token leftBracket, + required Token rightBracket, + }); + + /// Adds an insertion for a constructor. + /// + /// The constructor is inserted after the last existing field or constructor, + /// or if the `sort_constructors_first` lint rule is enabled, after the last + /// existing constructor. + void insertConstructor( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ); + + /// Adds an insertion for a field. + /// + /// The field is inserted after the last existing field, or at the beginning + /// of [compilationUnitMember], if it has no existing fields. + void insertField( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ); + + /// Adds an insertion for a getter. + /// + /// The getter is inserted after the last existing field, constructor, or + /// getter, or at the beginning of [compilationUnitMember], if it has none of + /// these. + void insertGetter( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ); + + /// Adds an insertion for a method. + /// + /// The method is inserted after the last existing field, constructor, or + /// method, or at the beginning of [compilationUnitMember], if it has none of + /// these. + void insertMethod( + CompilationUnitMember compilationUnitMember, + void Function(DartEditBuilder builder) buildEdit, + ); + /// Optionally create an edit to replace the given [typeAnnotation] with the /// type `Future` (with the given type annotation as the type argument). The /// [typeProvider] is used to check the current type, because if it is already