Skip to content

Commit 81f561c

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer_testing: Migrate flutter painting mock libraries
Change-Id: Ia29fd5f1413e0b3d0b32e24c7232c755d7f2bafb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465960 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent f247560 commit 81f561c

File tree

11 files changed

+576
-0
lines changed

11 files changed

+576
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final paintingLibrary = MockLibraryUnit('lib/painting.dart', r'''
8+
export 'src/painting/alignment.dart';
9+
export 'src/painting/basic_types.dart';
10+
export 'src/painting/border_radius.dart';
11+
export 'src/painting/borders.dart';
12+
export 'src/painting/box_border.dart';
13+
export 'src/painting/box_decoration.dart';
14+
export 'src/painting/colors.dart';
15+
export 'src/painting/decoration.dart';
16+
export 'src/painting/edge_insets.dart';
17+
export 'src/painting/text_painter.dart';
18+
export 'src/painting/text_style.dart';
19+
''');
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final paintingAlignmentLibrary = MockLibraryUnit(
8+
'lib/src/painting/alignment.dart',
9+
r'''
10+
import 'package:flutter/foundation.dart';
11+
import 'basic_types.dart';
12+
13+
class Alignment extends AlignmentGeometry {
14+
static const Alignment topLeft = Alignment(-1.0, -1.0);
15+
16+
static const Alignment topCenter = Alignment(0.0, -1.0);
17+
18+
static const Alignment topRight = Alignment(1.0, -1.0);
19+
20+
static const Alignment centerLeft = Alignment(-1.0, 0.0);
21+
22+
static const Alignment center = Alignment(0.0, 0.0);
23+
24+
static const Alignment centerRight = Alignment(1.0, 0.0);
25+
26+
static const Alignment bottomLeft = Alignment(-1.0, 1.0);
27+
28+
static const Alignment bottomCenter = Alignment(0.0, 1.0);
29+
30+
static const Alignment bottomRight = Alignment(1.0, 1.0);
31+
32+
final double x;
33+
34+
final double y;
35+
36+
const Alignment(this.x, this.y);
37+
}
38+
39+
class AlignmentDirectional extends AlignmentGeometry {
40+
static const AlignmentDirectional topStart = AlignmentDirectional(-1.0, -1.0);
41+
42+
static const AlignmentDirectional topCenter = AlignmentDirectional(0.0, -1.0);
43+
44+
static const AlignmentDirectional topEnd = AlignmentDirectional(1.0, -1.0);
45+
46+
static const AlignmentDirectional centerStart = AlignmentDirectional(
47+
-1.0,
48+
0.0,
49+
);
50+
51+
static const AlignmentDirectional center = AlignmentDirectional(0.0, 0.0);
52+
53+
static const AlignmentDirectional centerEnd = AlignmentDirectional(1.0, 0.0);
54+
55+
static const AlignmentDirectional bottomStart = AlignmentDirectional(
56+
-1.0,
57+
1.0,
58+
);
59+
60+
static const AlignmentDirectional bottomCenter = AlignmentDirectional(
61+
0.0,
62+
1.0,
63+
);
64+
65+
static const AlignmentDirectional bottomEnd = AlignmentDirectional(1.0, 1.0);
66+
67+
final double start;
68+
69+
final double y;
70+
71+
const AlignmentDirectional(this.start, this.y);
72+
}
73+
74+
@immutable
75+
abstract class AlignmentGeometry {
76+
const AlignmentGeometry();
77+
}
78+
79+
class TextAlignVertical {
80+
static const TextAlignVertical top = TextAlignVertical(y: -1.0);
81+
82+
static const TextAlignVertical center = TextAlignVertical(y: 0.0);
83+
84+
static const TextAlignVertical bottom = TextAlignVertical(y: 1.0);
85+
86+
final double y;
87+
88+
const TextAlignVertical({required this.y}) : assert(y >= -1.0 && y <= 1.0);
89+
}
90+
''',
91+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final paintingBasicTypesLibrary = MockLibraryUnit(
8+
'lib/src/painting/basic_types.dart',
9+
r'''
10+
import 'package:ui/ui.dart' show TextDirection;
11+
12+
export 'package:ui/ui.dart'
13+
show
14+
BlendMode,
15+
Color,
16+
FontStyle,
17+
FontWeight,
18+
Radius,
19+
TextAlign,
20+
TextBaseline,
21+
TextDirection;
22+
23+
enum Axis { horizontal, vertical }
24+
25+
enum AxisDirection { up, right, down, left }
26+
27+
enum VerticalDirection { up, down }
28+
''',
29+
);
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final paintingBorderRadiusLibrary = MockLibraryUnit(
8+
'lib/src/painting/border_radius.dart',
9+
r'''
10+
import 'package:flutter/foundation.dart';
11+
import 'basic_types.dart';
12+
13+
class BorderRadius extends BorderRadiusGeometry {
14+
static const BorderRadius zero = BorderRadius.all(Radius.zero);
15+
16+
final Radius topLeft;
17+
18+
final Radius topRight;
19+
20+
final Radius bottomLeft;
21+
22+
final Radius bottomRight;
23+
24+
const BorderRadius.all(Radius radius)
25+
: this.only(
26+
topLeft: radius,
27+
topRight: radius,
28+
bottomLeft: radius,
29+
bottomRight: radius,
30+
);
31+
32+
BorderRadius.circular(double radius);
33+
34+
const BorderRadius.horizontal({
35+
Radius left = Radius.zero,
36+
Radius right = Radius.zero,
37+
}) : this.only(
38+
topLeft: left,
39+
topRight: right,
40+
bottomLeft: left,
41+
bottomRight: right,
42+
);
43+
44+
const BorderRadius.only({
45+
this.topLeft = Radius.zero,
46+
this.topRight = Radius.zero,
47+
this.bottomLeft = Radius.zero,
48+
this.bottomRight = Radius.zero,
49+
});
50+
51+
const BorderRadius.vertical({
52+
Radius top = Radius.zero,
53+
Radius bottom = Radius.zero,
54+
}) : this.only(
55+
topLeft: top,
56+
topRight: top,
57+
bottomLeft: bottom,
58+
bottomRight: bottom,
59+
);
60+
}
61+
62+
class BorderRadiusDirectional extends BorderRadiusGeometry {
63+
static const BorderRadiusDirectional zero = BorderRadiusDirectional.all(
64+
Radius.zero,
65+
);
66+
67+
final Radius topStart;
68+
69+
final Radius topEnd;
70+
71+
final Radius bottomStart;
72+
73+
final Radius bottomEnd;
74+
75+
const BorderRadiusDirectional.all(Radius radius)
76+
: this.only(
77+
topStart: radius,
78+
topEnd: radius,
79+
bottomStart: radius,
80+
bottomEnd: radius,
81+
);
82+
83+
BorderRadiusDirectional.circular(double radius);
84+
85+
const BorderRadiusDirectional.horizontal({
86+
Radius start = Radius.zero,
87+
Radius end = Radius.zero,
88+
}) : this.only(
89+
topStart: start,
90+
topEnd: end,
91+
bottomStart: start,
92+
bottomEnd: end,
93+
);
94+
95+
const BorderRadiusDirectional.only({
96+
this.topStart = Radius.zero,
97+
this.topEnd = Radius.zero,
98+
this.bottomStart = Radius.zero,
99+
this.bottomEnd = Radius.zero,
100+
});
101+
102+
const BorderRadiusDirectional.vertical({
103+
Radius top = Radius.zero,
104+
Radius bottom = Radius.zero,
105+
}) : this.only(
106+
topStart: top,
107+
topEnd: top,
108+
bottomStart: bottom,
109+
bottomEnd: bottom,
110+
);
111+
}
112+
113+
@immutable
114+
abstract class BorderRadiusGeometry {
115+
const BorderRadiusGeometry();
116+
}
117+
''',
118+
);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final paintingBordersLibrary = MockLibraryUnit(
8+
'lib/src/painting/borders.dart',
9+
r'''
10+
import 'package:flutter/foundation.dart';
11+
import 'basic_types.dart';
12+
13+
@immutable
14+
class BorderSide {
15+
static const BorderSide none = BorderSide(
16+
width: 0.0,
17+
style: BorderStyle.none,
18+
);
19+
20+
final Color color;
21+
22+
final double width;
23+
24+
final BorderStyle style;
25+
26+
const BorderSide({
27+
this.color = const Color(0xFF000000),
28+
this.width = 1.0,
29+
this.style = BorderStyle.solid,
30+
double strokeAlign = strokeAlignInside,
31+
}) : assert(width >= 0.0);
32+
33+
BorderSide copyWith({
34+
Color? color,
35+
double? width,
36+
BorderStyle? style,
37+
double? strokeAlign,
38+
}) => throw 0;
39+
}
40+
41+
enum BorderStyle { none, solid }
42+
43+
@immutable
44+
abstract class ShapeBorder {
45+
const ShapeBorder();
46+
}
47+
''',
48+
);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final paintingBoxBorderLibrary = MockLibraryUnit(
8+
'lib/src/painting/box_border.dart',
9+
r'''
10+
import 'basic_types.dart';
11+
import 'border_radius.dart';
12+
import 'borders.dart';
13+
14+
class Border extends BoxBorder {
15+
@override
16+
final BorderSide top;
17+
18+
final BorderSide right;
19+
20+
@override
21+
final BorderSide bottom;
22+
23+
final BorderSide left;
24+
25+
const Border({
26+
this.top = BorderSide.none,
27+
this.right = BorderSide.none,
28+
this.bottom = BorderSide.none,
29+
this.left = BorderSide.none,
30+
});
31+
32+
factory Border.all({
33+
Color color = const Color(0xFF000000),
34+
double width = 1.0,
35+
BorderStyle style = BorderStyle.solid,
36+
double strokeAlign = BorderSide.strokeAlignInside,
37+
}) => throw 0;
38+
39+
const Border.fromBorderSide(BorderSide side)
40+
: top = side,
41+
right = side,
42+
bottom = side,
43+
left = side;
44+
}
45+
46+
class BorderDirectional extends BoxBorder {
47+
@override
48+
final BorderSide top;
49+
50+
final BorderSide start;
51+
52+
final BorderSide end;
53+
54+
@override
55+
final BorderSide bottom;
56+
57+
const BorderDirectional({
58+
this.top = BorderSide.none,
59+
this.start = BorderSide.none,
60+
this.end = BorderSide.none,
61+
this.bottom = BorderSide.none,
62+
});
63+
}
64+
65+
abstract class BoxBorder extends ShapeBorder {
66+
const BoxBorder();
67+
68+
BorderSide get bottom;
69+
70+
BorderSide get top;
71+
}
72+
73+
enum BoxShape { rectangle, circle }
74+
''',
75+
);

0 commit comments

Comments
 (0)