Skip to content

Commit bede1de

Browse files
authored
[material_ui] Standardize M3 and M3E token template base class names (flutter#12675)
Work towards flutter#191088 **Ports over flutter/packages#12209 which landed on the `m3e_migration` feature branch.** ### Original PR description As title. Related to flutter#187899 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent c776615 commit bede1de

4 files changed

Lines changed: 23 additions & 24 deletions

File tree

‎packages/material_ui/tool/gen_defaults/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This updates generated component theming files under
1414
## Templates
1515

1616
There is a template file for every component that needs defaults from the token
17-
database. These templates are implemented as subclasses of either `M3TokenTemplate` or `M3ETokenTemplate`.
17+
database. These templates are implemented as subclasses of either `TokenTemplateM3` or `TokenTemplateM3E`.
1818

1919
Templates need to override the `generateContents` method to provide the
2020
generated code block as a string.

‎packages/material_ui/tool/gen_defaults/templates/template.dart‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import '../data/shape_struct.dart';
1212
enum _MaterialVersion { material3, material3Expressive }
1313

1414
/// A template for generating Material 3 component defaults.
15-
abstract class M3TokenTemplate extends TokenTemplate {
16-
const M3TokenTemplate();
15+
abstract class TokenTemplateM3 extends TokenTemplate {
16+
const TokenTemplateM3();
1717

1818
@override
1919
_MaterialVersion get _version => _MaterialVersion.material3;
2020
}
2121

2222
/// A template for generating Material 3 Expressive component defaults.
23-
abstract class M3ETokenTemplate extends TokenTemplate {
24-
const M3ETokenTemplate();
23+
abstract class TokenTemplateM3E extends TokenTemplate {
24+
const TokenTemplateM3E();
2525

2626
@override
2727
_MaterialVersion get _version => _MaterialVersion.material3Expressive;
@@ -52,7 +52,7 @@ abstract class TokenTemplate {
5252
static final RegExp _nameRegExp = RegExp(r'^[A-Z][a-zA-Z0-9]*( [A-Z][a-zA-Z0-9]*)*$');
5353

5454
/// The name of the template, which corresponds to the target file name.
55-
/// E.g., 'Icon Button' for generating 'icon_button_m3_defaults.g.dart'.
55+
/// E.g., 'Icon Button' for generating 'icon_button_defaults_m3.g.dart'.
5656
String get name;
5757

5858
/// The path of the parent file relative to `lib/src`.
@@ -154,8 +154,8 @@ abstract class TokenTemplate {
154154
void generateFile({bool verbose = false}) {
155155
final String snakeName = name.toLowerCase().replaceAll(' ', '_');
156156
final String outputFileName = switch (_version) {
157-
_MaterialVersion.material3 => '${snakeName}_m3_defaults.g.dart',
158-
_MaterialVersion.material3Expressive => '${snakeName}_m3e_defaults.g.dart',
157+
_MaterialVersion.material3 => '${snakeName}_defaults_m3.g.dart',
158+
_MaterialVersion.material3Expressive => '${snakeName}_defaults_m3e.g.dart',
159159
};
160160
final fileName = '$materialLib/$outputFileName';
161161
if (verbose) {

‎packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ void main() {
2525

2626
for (final isM3E in <bool>[true, false]) {
2727
TokenTemplate buttonTemplate() =>
28-
isM3E ? M3EIconButtonTemplate(testPath()) : M3IconButtonTemplate(testPath());
28+
isM3E ? IconButtonTemplateM3E(testPath()) : IconButtonTemplateM3(testPath());
2929

3030
String filePath() {
31-
final fileName = 'icon_button_m3${isM3E ? 'e' : ''}_defaults.g.dart';
31+
final fileName = 'icon_button_defaults_m3${isM3E ? 'e' : ''}.g.dart';
3232
return '${testPath()}/$fileName';
3333
}
3434

3535
group(isM3E ? 'M3E Template' : 'M3 Template', () {
3636
test(
37-
'will generate a part file ending in icon_button_m3${isM3E ? 'e' : ''}_defaults.g.dart',
37+
'will generate a part file ending in icon_button_defaults_m3${isM3E ? 'e' : ''}.g.dart',
3838
() {
3939
buttonTemplate().generateFile(verbose: true);
4040
expect(File(filePath()).existsSync(), isTrue);
@@ -69,12 +69,12 @@ void main() {
6969
}
7070

7171
test('color generates color expression', () {
72-
final template = M3IconButtonTemplate(testPath());
72+
final template = IconButtonTemplateM3(testPath());
7373
expect(template.color(TokenColorRole.onSurface, '_colors'), '_colors.onSurface');
7474
});
7575

7676
test('colorWithOpacity generates color expression with opacity', () {
77-
final template = M3IconButtonTemplate(testPath());
77+
final template = IconButtonTemplateM3(testPath());
7878
expect(
7979
template.colorWithOpacity(TokenColorRole.onSurface, 0.12, '_colors'),
8080
'_colors.onSurface.withOpacity(0.12)',
@@ -86,7 +86,7 @@ void main() {
8686
});
8787

8888
test('shape generates shape expressions', () {
89-
final template = M3IconButtonTemplate(testPath());
89+
final template = IconButtonTemplateM3(testPath());
9090
expect(
9191
template.shape(
9292
const ShapeStruct(
@@ -126,7 +126,7 @@ void main() {
126126
});
127127

128128
test('shape throws UnsupportedError for unsupported shape family', () {
129-
final template = M3IconButtonTemplate(testPath());
129+
final template = IconButtonTemplateM3(testPath());
130130
expect(
131131
() => template.shape(
132132
const ShapeStruct(
@@ -146,12 +146,11 @@ void main() {
146146
),
147147
);
148148
});
149-
150149
test('will run dart format over the generated file', () {
151150
final template = UnformattedTemplate(testPath());
152151
template.generateFile();
153152

154-
final file = File('${testPath()}/unformatted_m3_defaults.g.dart');
153+
final file = File('${testPath()}/unformatted_defaults_m3.g.dart');
155154
expect(file.readAsStringSync(), contains(formattedClass));
156155
});
157156

‎packages/material_ui/tool/gen_defaults/test/test_fixtures/test_templates.dart‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import '../../templates/template.dart';
66
import 'icon_button_token_data.dart';
77

8-
class M3EIconButtonTemplate extends M3ETokenTemplate {
9-
M3EIconButtonTemplate(this.customMaterialLib);
8+
class IconButtonTemplateM3E extends TokenTemplateM3E {
9+
IconButtonTemplateM3E(this.customMaterialLib);
1010

1111
final String customMaterialLib;
1212

@@ -30,8 +30,8 @@ class $className {
3030
}
3131
}
3232

33-
class M3IconButtonTemplate extends M3TokenTemplate {
34-
M3IconButtonTemplate(this.customMaterialLib);
33+
class IconButtonTemplateM3 extends TokenTemplateM3 {
34+
IconButtonTemplateM3(this.customMaterialLib);
3535

3636
final String customMaterialLib;
3737

@@ -66,7 +66,7 @@ class $className {
6666
}
6767
}
6868

69-
class UnformattedTemplate extends M3TokenTemplate {
69+
class UnformattedTemplate extends TokenTemplateM3 {
7070
UnformattedTemplate(this.customMaterialLib);
7171

7272
final String customMaterialLib;
@@ -91,7 +91,7 @@ final int x = 1 ;
9191
}
9292
}
9393

94-
class InvalidTemplate extends M3TokenTemplate {
94+
class InvalidTemplate extends TokenTemplateM3 {
9595
InvalidTemplate(this.customMaterialLib);
9696

9797
final String customMaterialLib;
@@ -115,7 +115,7 @@ class _SomeOtherClassNameDefaults {
115115
}
116116
}
117117

118-
class SnakeCaseNameTemplate extends M3TokenTemplate {
118+
class SnakeCaseNameTemplate extends TokenTemplateM3 {
119119
SnakeCaseNameTemplate(this.customMaterialLib);
120120

121121
final String customMaterialLib;

0 commit comments

Comments
 (0)