Skip to content

Commit

Permalink
Use '=' for default values of named parameters.
Browse files Browse the repository at this point in the history
R=brianwilkerson@google.com

Change-Id: I694c9e411fc125ae7b716d0f8b9e78c5cac57e34
Reviewed-on: https://dart-review.googlesource.com/68180
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Aug 2, 2018
1 parent f625490 commit 758e5ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/analysis_server/test/services/correction/fix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3852,7 +3852,7 @@ abstract class A {
String m3(int p1, double p2, Map<int, List<String>> p3);
String m4(p1, p2);
String m5(p1, [int p2 = 2, int p3, p4 = 4]);
String m6(p1, {int p2: 2, int p3, p4: 4});
String m6(p1, {int p2 = 2, int p3, p4: 4});
}
class B extends A {
Expand All @@ -3865,7 +3865,7 @@ abstract class A {
String m3(int p1, double p2, Map<int, List<String>> p3);
String m4(p1, p2);
String m5(p1, [int p2 = 2, int p3, p4 = 4]);
String m6(p1, {int p2: 2, int p3, p4: 4});
String m6(p1, {int p2 = 2, int p3, p4: 4});
}
class B extends A {
Expand Down Expand Up @@ -3895,7 +3895,7 @@ class B extends A {
}
@override
String m6(p1, {int p2: 2, int p3, p4: 4}) {
String m6(p1, {int p2 = 2, int p3, p4 = 4}) {
// TODO: implement m6
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,7 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
// default value
String defaultCode = parameter.defaultValueCode;
if (defaultCode != null) {
if (sawPositional) {
write(' = ');
} else {
write(': ');
}
write(' = ');
write(defaultCode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ class A {}

test_writeParameters_named() async {
String path = provider.convertPath('/test.dart');
String content = 'f(int i, {String s}) {}';
String content = 'f(int a, {bool b = false, String c}) {}';
addSource(path, content);

CompilationUnit unit = (await driver.getResult(path))?.unit;
Expand All @@ -1530,12 +1530,13 @@ class A {}
});
});
SourceEdit edit = getEdit(builder);
expect(edit.replacement, equalsIgnoringWhitespace('(int i, {String s})'));
expect(edit.replacement,
equalsIgnoringWhitespace('(int a, {bool b = false, String c})'));
}

test_writeParameters_positional() async {
String path = provider.convertPath('/test.dart');
String content = 'f(int i, [String s]) {}';
String content = 'f(int a, [bool b = false, String c]) {}';
addSource(path, content);
CompilationUnit unit = (await driver.getResult(path))?.unit;
FunctionDeclaration f = unit.declarations[0];
Expand All @@ -1550,7 +1551,8 @@ class A {}
});
});
SourceEdit edit = getEdit(builder);
expect(edit.replacement, equalsIgnoringWhitespace('(int i, [String s])'));
expect(edit.replacement,
equalsIgnoringWhitespace('(int a, [bool b = false, String c])'));
}

test_writeParameters_required() async {
Expand Down

0 comments on commit 758e5ea

Please sign in to comment.