Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.dart

Issue 1009833002: Quick Assist for creating a constructor for selected final fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698