Improve macro code formatting.
Change-Id: I3c9f1ddaf6b5562a10b767c2f5d7297a5ed655e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210421
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/test/analysis/notification_navigation_test.dart b/pkg/analysis_server/test/analysis/notification_navigation_test.dart
index 8a8f918..cccab31 100644
--- a/pkg/analysis_server/test/analysis/notification_navigation_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_navigation_test.dart
@@ -805,7 +805,6 @@
);
var generatedContent = generatedFile.readAsStringSync();
- // TODO(scheglov) Improve macro to be more formatted.
expect(generatedContent, r'''
import 'macro_annotations.dart';
@@ -813,12 +812,12 @@
@observable
int _foo = 0;
-int get foo => _foo;
+ int get foo => _foo;
-set foo(int val) {
- print('Setting foo to ${val}');
- _foo = val;
-}
+ set foo(int val) {
+ print('Setting foo to ${val}');
+ _foo = val;
+ }
}
void f(A a) {
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index d8b80ca..80e7594 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -80,7 +80,7 @@
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
- static const int DATA_VERSION = 169;
+ static const int DATA_VERSION = 170;
/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
diff --git a/pkg/analyzer/lib/src/macro/builders/data_class.dart b/pkg/analyzer/lib/src/macro/builders/data_class.dart
index 664f5d8..86d99e0 100644
--- a/pkg/analyzer/lib/src/macro/builders/data_class.dart
+++ b/pkg/analyzer/lib/src/macro/builders/data_class.dart
@@ -52,8 +52,9 @@
.join(' ^ ');
builder.addToClass(
Declaration('''
-@override
-int get hashCode => $expression;'''),
+ @override
+ int get hashCode => $expression;
+'''),
);
}
}
@@ -73,8 +74,9 @@
}).join(', ');
builder.addToClass(
Declaration('''
-@override
-String toString() => '${classElement.name}($fieldsCode)';'''),
+ @override
+ String toString() => '${classElement.name}($fieldsCode)';
+'''),
);
}
}
diff --git a/pkg/analyzer/lib/src/macro/builders/observable.dart b/pkg/analyzer/lib/src/macro/builders/observable.dart
index 6857d34..dac5565 100644
--- a/pkg/analyzer/lib/src/macro/builders/observable.dart
+++ b/pkg/analyzer/lib/src/macro/builders/observable.dart
@@ -33,15 +33,16 @@
var publicName = name.substring(1);
var getter = Declaration(
- '$typeCode get $publicName => $name;',
+ ' $typeCode get $publicName => $name;',
);
builder.addToClass(getter);
var setter = Declaration('''
-set $publicName($typeCode val) {
- print('Setting $publicName to \${val}');
- $name = val;
-}''');
+ set $publicName($typeCode val) {
+ print('Setting $publicName to \${val}');
+ $name = val;
+ }
+''');
builder.addToClass(setter);
}
}
diff --git a/pkg/analyzer/lib/src/macro/impl/macro.dart b/pkg/analyzer/lib/src/macro/impl/macro.dart
index 989bdb4..5974840 100644
--- a/pkg/analyzer/lib/src/macro/impl/macro.dart
+++ b/pkg/analyzer/lib/src/macro/impl/macro.dart
@@ -114,7 +114,7 @@
return a.data.id - b.data.id;
});
- const classMemberCodePrefix = '\n';
+ const classMemberCodePrefix = '\n ';
const classMemberCodeSuffix = '\n';
// TODO(scheglov) make it required?
var generatedContent = linkingUnit.input.sourceContent!;
diff --git a/pkg/analyzer/lib/src/summary2/informative_data.dart b/pkg/analyzer/lib/src/summary2/informative_data.dart
index f513e75..0136b19 100644
--- a/pkg/analyzer/lib/src/summary2/informative_data.dart
+++ b/pkg/analyzer/lib/src/summary2/informative_data.dart
@@ -669,7 +669,7 @@
) {
var macroGenerationDataList = unitElement.macroGenerationDataList;
if (macroGenerationDataList != null) {
- const classMemberCodePrefix = '\n';
+ const classMemberCodePrefix = '\n ';
const classMemberCodeSuffix = '\n';
var generatedContent = unitInfoData.content;
var shift = 0;
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 74fe439..a0c24da 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -21282,11 +21282,11 @@
final b @88
type: int?
constructors
- @92
+ @94
parameters
- requiredName final this.a @109
+ requiredName final this.a @111
type: int
- optionalNamed final this.b @117
+ optionalNamed final this.b @119
type: int?
accessors
synthetic get a @-1
@@ -21300,7 +21300,7 @@
final int a;
final int? b;
-A({required this.a, this.b});
+ A({required this.a, this.b});
}
''');
}
@@ -21335,7 +21335,7 @@
returnType: int
synthetic get b @-1
returnType: int
- get hashCode @102
+ get hashCode @106
metadata
Annotation
atSign: @ @0
@@ -21352,8 +21352,8 @@
final int a;
final int b;
-@override
-int get hashCode => a.hashCode ^ b.hashCode;
+ @override
+ int get hashCode => a.hashCode ^ b.hashCode;
}
''');
}
@@ -21410,15 +21410,15 @@
accessors
synthetic get b @-1
returnType: int
- get hashCode @126
+ get hashCode @130
metadata
Annotation
- atSign: @ @108
+ atSign: @ @110
element: dart:core::@getter::override
name: SimpleIdentifier
staticElement: dart:core::@getter::override
staticType: null
- token: override @109
+ token: override @111
returnType: int
macroGeneratedContent
import 'macro_annotations.dart';
@@ -21431,8 +21431,8 @@
class B extends A {
final int b;
-@override
-int get hashCode => b.hashCode ^ a.hashCode;
+ @override
+ int get hashCode => b.hashCode ^ a.hashCode;
}
''');
}
@@ -21479,11 +21479,11 @@
requiredPositional __f @-1
type: int
returnType: void
- get f @80
+ get f @82
returnType: int
- set f @94
+ set f @98
parameters
- requiredPositional val @100
+ requiredPositional val @104
type: int
returnType: void
macroGeneratedContent
@@ -21492,12 +21492,12 @@
@observable
int _f = 0;
-int get f => _f;
+ int get f => _f;
-set f(int val) {
- print('Setting f to ${val}');
- _f = val;
-}
+ set f(int val) {
+ print('Setting f to ${val}');
+ _f = val;
+ }
}
''');
}
@@ -21547,11 +21547,11 @@
requiredPositional __f @-1
type: T
returnType: void
- get f @75
+ get f @77
returnType: T
- set f @89
+ set f @93
parameters
- requiredPositional val @93
+ requiredPositional val @97
type: T
returnType: void
macroGeneratedContent
@@ -21560,12 +21560,12 @@
@observable
T _f;
-T get f => _f;
+ T get f => _f;
-set f(T val) {
- print('Setting f to ${val}');
- _f = val;
-}
+ set f(T val) {
+ print('Setting f to ${val}');
+ _f = val;
+ }
}
''');
}
@@ -21611,15 +21611,15 @@
synthetic get b @-1
returnType: int
methods
- toString @101
+ toString @105
metadata
Annotation
- atSign: @ @84
+ atSign: @ @86
element: dart:core::@getter::override
name: SimpleIdentifier
staticElement: dart:core::@getter::override
staticType: null
- token: override @85
+ token: override @87
returnType: String
macroGeneratedContent
import 'macro_annotations.dart';
@@ -21628,8 +21628,8 @@
final int a;
final int b;
-@override
-String toString() => 'A(a: $a, b: $b)';
+ @override
+ String toString() => 'A(a: $a, b: $b)';
}
''');
}