Skip to content

Commit

Permalink
Version 2.15.0-25.0.dev
Browse files Browse the repository at this point in the history
Merge commit '099c5a5c939280c30a3de79c1432846a75bf7011' into 'dev'
  • Loading branch information
Dart CI committed Aug 18, 2021
2 parents ba50855 + 099c5a5 commit f2b0d38
Show file tree
Hide file tree
Showing 21 changed files with 262 additions and 153 deletions.
4 changes: 2 additions & 2 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"name": "dart2js_tools",
"rootUri": "../pkg/dart2js_tools",
"packageUri": "lib/",
"languageVersion": "2.3"
"languageVersion": "2.12"
},
{
"name": "dart2native",
Expand Down Expand Up @@ -812,4 +812,4 @@
"languageVersion": "2.12"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -805,20 +805,19 @@ void f(A a) {
);

var generatedContent = generatedFile.readAsStringSync();
// TODO(scheglov) Improve macro to be more formatted.
expect(generatedContent, r'''
import 'macro_annotations.dart';
class A {
@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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import 'package:meta/meta.dart';
/// 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.
Expand Down
24 changes: 20 additions & 4 deletions pkg/analyzer/lib/src/macro/builders/data_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ class AutoConstructorMacro implements ClassDeclarationMacro {
}
}

class DataClassMacro implements ClassDeclarationMacro {
const DataClassMacro();

@override
void visitClassDeclaration(
ast.ClassDeclaration declaration,
ClassDeclarationBuilder builder,
) {
const AutoConstructorMacro().visitClassDeclaration(declaration, builder);
const HashCodeMacro().visitClassDeclaration(declaration, builder);
const ToStringMacro().visitClassDeclaration(declaration, builder);
}
}

class HashCodeMacro implements ClassDeclarationMacro {
const HashCodeMacro();

Expand All @@ -52,8 +66,9 @@ class HashCodeMacro implements ClassDeclarationMacro {
.join(' ^ ');
builder.addToClass(
Declaration('''
@override
int get hashCode => $expression;'''),
@override
int get hashCode => $expression;
'''),
);
}
}
Expand All @@ -73,8 +88,9 @@ class ToStringMacro implements ClassDeclarationMacro {
}).join(', ');
builder.addToClass(
Declaration('''
@override
String toString() => '${classElement.name}($fieldsCode)';'''),
@override
String toString() => '${classElement.name}($fieldsCode)';
'''),
);
}
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/analyzer/lib/src/macro/builders/observable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ class ObservableMacro implements FieldDeclarationMacro {
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/macro/impl/macro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MacroGeneratedContent {
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!;
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/summary2/informative_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ class InformativeDataApplier {
) {
var macroGenerationDataList = unitElement.macroGenerationDataList;
if (macroGenerationDataList != null) {
const classMemberCodePrefix = '\n';
const classMemberCodePrefix = '\n ';
const classMemberCodeSuffix = '\n';
var generatedContent = unitInfoData.content;
var shift = 0;
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ class LibraryBuilder {
classBuilder,
);
}
if (hasMacroAnnotation(declaration, 'dataClass')) {
macro.DataClassMacro().visitClassDeclaration(
declaration,
classBuilder,
);
}
if (hasMacroAnnotation(declaration, 'hashCode')) {
macro.HashCodeMacro().visitClassDeclaration(
declaration,
Expand Down
Loading

0 comments on commit f2b0d38

Please sign in to comment.