Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f2b0d38

Browse files
author
Dart CI
committed
Version 2.15.0-25.0.dev
Merge commit '099c5a5c939280c30a3de79c1432846a75bf7011' into 'dev'
2 parents ba50855 + 099c5a5 commit f2b0d38

21 files changed

+262
-153
lines changed

.dart_tool/package_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
"name": "dart2js_tools",
221221
"rootUri": "../pkg/dart2js_tools",
222222
"packageUri": "lib/",
223-
"languageVersion": "2.3"
223+
"languageVersion": "2.12"
224224
},
225225
{
226226
"name": "dart2native",
@@ -812,4 +812,4 @@
812812
"languageVersion": "2.12"
813813
}
814814
]
815-
}
815+
}

pkg/analysis_server/test/analysis/notification_navigation_test.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,20 +805,19 @@ void f(A a) {
805805
);
806806

807807
var generatedContent = generatedFile.readAsStringSync();
808-
// TODO(scheglov) Improve macro to be more formatted.
809808
expect(generatedContent, r'''
810809
import 'macro_annotations.dart';
811810
812811
class A {
813812
@observable
814813
int _foo = 0;
815814
816-
int get foo => _foo;
815+
int get foo => _foo;
817816
818-
set foo(int val) {
819-
print('Setting foo to ${val}');
820-
_foo = val;
821-
}
817+
set foo(int val) {
818+
print('Setting foo to ${val}');
819+
_foo = val;
820+
}
822821
}
823822
824823
void f(A a) {

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import 'package:meta/meta.dart';
8080
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
8181
class AnalysisDriver implements AnalysisDriverGeneric {
8282
/// The version of data format, should be incremented on every format change.
83-
static const int DATA_VERSION = 169;
83+
static const int DATA_VERSION = 170;
8484

8585
/// The number of exception contexts allowed to write. Once this field is
8686
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/macro/builders/data_class.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ class AutoConstructorMacro implements ClassDeclarationMacro {
3939
}
4040
}
4141

42+
class DataClassMacro implements ClassDeclarationMacro {
43+
const DataClassMacro();
44+
45+
@override
46+
void visitClassDeclaration(
47+
ast.ClassDeclaration declaration,
48+
ClassDeclarationBuilder builder,
49+
) {
50+
const AutoConstructorMacro().visitClassDeclaration(declaration, builder);
51+
const HashCodeMacro().visitClassDeclaration(declaration, builder);
52+
const ToStringMacro().visitClassDeclaration(declaration, builder);
53+
}
54+
}
55+
4256
class HashCodeMacro implements ClassDeclarationMacro {
4357
const HashCodeMacro();
4458

@@ -52,8 +66,9 @@ class HashCodeMacro implements ClassDeclarationMacro {
5266
.join(' ^ ');
5367
builder.addToClass(
5468
Declaration('''
55-
@override
56-
int get hashCode => $expression;'''),
69+
@override
70+
int get hashCode => $expression;
71+
'''),
5772
);
5873
}
5974
}
@@ -73,8 +88,9 @@ class ToStringMacro implements ClassDeclarationMacro {
7388
}).join(', ');
7489
builder.addToClass(
7590
Declaration('''
76-
@override
77-
String toString() => '${classElement.name}($fieldsCode)';'''),
91+
@override
92+
String toString() => '${classElement.name}($fieldsCode)';
93+
'''),
7894
);
7995
}
8096
}

pkg/analyzer/lib/src/macro/builders/observable.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ class ObservableMacro implements FieldDeclarationMacro {
3333
var publicName = name.substring(1);
3434

3535
var getter = Declaration(
36-
'$typeCode get $publicName => $name;',
36+
' $typeCode get $publicName => $name;',
3737
);
3838
builder.addToClass(getter);
3939

4040
var setter = Declaration('''
41-
set $publicName($typeCode val) {
42-
print('Setting $publicName to \${val}');
43-
$name = val;
44-
}''');
41+
set $publicName($typeCode val) {
42+
print('Setting $publicName to \${val}');
43+
$name = val;
44+
}
45+
''');
4546
builder.addToClass(setter);
4647
}
4748
}

pkg/analyzer/lib/src/macro/impl/macro.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class MacroGeneratedContent {
114114
return a.data.id - b.data.id;
115115
});
116116

117-
const classMemberCodePrefix = '\n';
117+
const classMemberCodePrefix = '\n ';
118118
const classMemberCodeSuffix = '\n';
119119
// TODO(scheglov) make it required?
120120
var generatedContent = linkingUnit.input.sourceContent!;

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ class InformativeDataApplier {
669669
) {
670670
var macroGenerationDataList = unitElement.macroGenerationDataList;
671671
if (macroGenerationDataList != null) {
672-
const classMemberCodePrefix = '\n';
672+
const classMemberCodePrefix = '\n ';
673673
const classMemberCodeSuffix = '\n';
674674
var generatedContent = unitInfoData.content;
675675
var shift = 0;

pkg/analyzer/lib/src/summary2/library_builder.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ class LibraryBuilder {
248248
classBuilder,
249249
);
250250
}
251+
if (hasMacroAnnotation(declaration, 'dataClass')) {
252+
macro.DataClassMacro().visitClassDeclaration(
253+
declaration,
254+
classBuilder,
255+
);
256+
}
251257
if (hasMacroAnnotation(declaration, 'hashCode')) {
252258
macro.HashCodeMacro().visitClassDeclaration(
253259
declaration,

0 commit comments

Comments
 (0)