| Index: pkg/analysis_server/lib/src/services/correction/util.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
|
| index f214c9fd26b792398af53a290f8088f0d58e704f..fc157f46c9a84e47fa2dd4fec06a64b900501bcd 100644
|
| --- a/pkg/analysis_server/lib/src/services/correction/util.dart
|
| +++ b/pkg/analysis_server/lib/src/services/correction/util.dart
|
| @@ -1061,6 +1061,33 @@ class CorrectionUtils {
|
| }
|
|
|
| /**
|
| + * Return the best locations for a new constructor in the given
|
| + * [classDeclaration].
|
| + */
|
| + ConstructorLocation findNewConstructorLocation(
|
| + ClassDeclaration classDeclaration) {
|
| + String eol = endOfLine;
|
| + List<ClassMember> members = classDeclaration.members;
|
| + // find the last field/constructor
|
| + ClassMember lastFieldOrConstructor = null;
|
| + for (ClassMember member in members) {
|
| + if (member is FieldDeclaration || member is ConstructorDeclaration) {
|
| + lastFieldOrConstructor = member;
|
| + } else {
|
| + break;
|
| + }
|
| + }
|
| + // after the last field/constructor
|
| + if (lastFieldOrConstructor != null) {
|
| + return new ConstructorLocation(eol + eol, lastFieldOrConstructor.end, '');
|
| + }
|
| + // at the beginning of the class
|
| + String suffix = members.isEmpty ? '' : eol;
|
| + return new ConstructorLocation(
|
| + eol, classDeclaration.leftBracket.end, suffix);
|
| + }
|
| +
|
| + /**
|
| * Returns the source with indentation changed from [oldIndent] to
|
| * [newIndent], keeping indentation of lines relative to each other.
|
| */
|
| @@ -1480,3 +1507,14 @@ class _OrderedOperandsVisitor extends GeneralizingAstVisitor {
|
| return null;
|
| }
|
| }
|
| +
|
| +/**
|
| + * Describes the location for a newly created [ConstructorDeclaration].
|
| + */
|
| +class ConstructorLocation {
|
| + final String prefix;
|
| + final int offset;
|
| + final String suffix;
|
| +
|
| + ConstructorLocation(this.prefix, this.offset, this.suffix);
|
| +}
|
|
|