Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit c3886a0

Browse files
committed
1. refine assert. defer message generation.
2. refine Path.
1 parent 4872d24 commit c3886a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+490
-541
lines changed

Runtime/animation/animation_controller.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public TickerFuture forward(float? from = null) {
157157
});
158158
D.assert(
159159
this._ticker != null,
160-
"AnimationController.forward() called after AnimationController.dispose()\n" +
160+
() => "AnimationController.forward() called after AnimationController.dispose()\n" +
161161
"AnimationController methods should not be used after calling dispose."
162162
);
163163
this._direction = _AnimationDirection.forward;
@@ -182,7 +182,7 @@ public TickerFuture reverse(float? from = null) {
182182
});
183183
D.assert(
184184
this._ticker != null,
185-
"AnimationController.reverse() called after AnimationController.dispose()\n" +
185+
() => "AnimationController.reverse() called after AnimationController.dispose()\n" +
186186
"AnimationController methods should not be used after calling dispose."
187187
);
188188
this._direction = _AnimationDirection.reverse;
@@ -196,7 +196,7 @@ public TickerFuture reverse(float? from = null) {
196196
public TickerFuture animateTo(float target, TimeSpan? duration = null, Curve curve = null) {
197197
D.assert(
198198
this._ticker != null,
199-
"AnimationController.animateTo() called after AnimationController.dispose()\n" +
199+
() => "AnimationController.animateTo() called after AnimationController.dispose()\n" +
200200
"AnimationController methods should not be used after calling dispose."
201201
);
202202
curve = curve ?? Curves.linear;
@@ -208,7 +208,7 @@ public TickerFuture animateTo(float target, TimeSpan? duration = null, Curve cur
208208
public TickerFuture animateBack(float target, TimeSpan? duration, Curve curve = null) {
209209
D.assert(
210210
this._ticker != null,
211-
"AnimationController.animateBack() called after AnimationController.dispose()\n" +
211+
() => "AnimationController.animateBack() called after AnimationController.dispose()\n" +
212212
"AnimationController methods should not be used after calling dispose."
213213
);
214214
curve = curve ?? Curves.linear;
@@ -300,7 +300,7 @@ public TickerFuture fling(float velocity = 1.0f) {
300300
public TickerFuture animateWith(Simulation simulation) {
301301
D.assert(
302302
this._ticker != null,
303-
"AnimationController.animateWith() called after AnimationController.dispose()\n" +
303+
() => "AnimationController.animateWith() called after AnimationController.dispose()\n" +
304304
"AnimationController methods should not be used after calling dispose."
305305
);
306306
this.stop();
@@ -324,7 +324,7 @@ TickerFuture _startSimulation(Simulation simulation) {
324324
public void stop(bool canceled = true) {
325325
D.assert(
326326
this._ticker != null,
327-
"AnimationController.stop() called after AnimationController.dispose()\n" +
327+
() => "AnimationController.stop() called after AnimationController.dispose()\n" +
328328
"AnimationController methods should not be used after calling dispose."
329329
);
330330
this._simulation = null;

Runtime/engine/UIWidgetsMessageManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ internal static void ensureUIWidgetsMessageManagerIfNeeded() {
3333
#endif
3434

3535
void OnEnable() {
36-
D.assert(_instance == null, "Only one instance of UIWidgetsMessageManager should exists");
36+
D.assert(_instance == null, () => "Only one instance of UIWidgetsMessageManager should exists");
3737
_instance = this;
3838
this.UpdateNameIfNeed();
3939
}
4040

4141
void OnDisable() {
42-
D.assert(_instance != null, "_instance should not be null");
42+
D.assert(_instance != null, () => "_instance should not be null");
4343
_instance = null;
4444
}
4545

Runtime/foundation/debug.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public static bool debugEnabled {
2626
}
2727

2828
[Conditional("UIWidgets_DEBUG")]
29-
public static void assert(Func<bool> result, string message = null) {
29+
public static void assert(Func<bool> result, Func<string> message = null) {
3030
if (!result()) {
31-
throw new AssertionError(message);
31+
throw new AssertionError(message != null ? message() : "");
3232
}
3333
}
3434

3535
[Conditional("UIWidgets_DEBUG")]
36-
public static void assert(bool result, string message = null) {
36+
public static void assert(bool result, Func<string> message = null) {
3737
if (!result) {
38-
throw new AssertionError(message);
38+
throw new AssertionError(message != null ? message() : "");
3939
}
4040
}
4141

Runtime/foundation/diagnostics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected DiagnosticsNode(
242242
bool showSeparator = true
243243
) {
244244
D.assert(name == null || !name.EndsWith(":"),
245-
"Names of diagnostic nodes must not end with colons.");
245+
() => "Names of diagnostic nodes must not end with colons.");
246246
this.name = name;
247247
this._style = style;
248248
this._showName = showName;

Runtime/foundation/observer_list.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace Unity.UIWidgets.foundation {
55
public class ObserverList<T> : ICollection<T> {
6-
public readonly List<T> _list = new List<T>();
7-
public bool _isDirty = false;
8-
public HashSet<T> _set = null;
6+
readonly List<T> _list = new List<T>();
7+
bool _isDirty = false;
8+
HashSet<T> _set = null;
99

1010
IEnumerator IEnumerable.GetEnumerator() {
1111
return this.GetEnumerator();

Runtime/gestures/arena.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text;
@@ -36,7 +37,7 @@ public virtual void resolve(GestureDisposition disposition) {
3637
}
3738

3839
class _GestureArena {
39-
public List<GestureArenaMember> members = new List<GestureArenaMember>();
40+
public readonly List<GestureArenaMember> members = new List<GestureArenaMember>();
4041
public bool isOpen = true;
4142
public bool isHeld = false;
4243
public bool hasPendingSweep = false;
@@ -81,13 +82,13 @@ public class GestureArenaManager {
8182

8283
public GestureArenaEntry add(int pointer, GestureArenaMember member) {
8384
_GestureArena state = this._arenas.putIfAbsent(pointer, () => {
84-
D.assert(this._debugLogDiagnostic(pointer, "★ Opening new gesture arena."));
85+
D.assert(this._debugLogDiagnostic(pointer, () => "★ Opening new gesture arena."));
8586
return state = new _GestureArena();
8687
});
8788

8889
state.add(member);
8990

90-
D.assert(this._debugLogDiagnostic(pointer, $"Adding: {member}"));
91+
D.assert(this._debugLogDiagnostic(pointer, () => $"Adding: {member}"));
9192
return new GestureArenaEntry(this, pointer, member);
9293
}
9394

@@ -98,7 +99,7 @@ public void close(int pointer) {
9899
}
99100

100101
state.isOpen = false;
101-
D.assert(this._debugLogDiagnostic(pointer, "Closing", state));
102+
D.assert(this._debugLogDiagnostic(pointer, () => "Closing", state));
102103
this._tryToResolveArena(pointer, state);
103104
}
104105

@@ -111,15 +112,15 @@ public void sweep(int pointer) {
111112
D.assert(!state.isOpen);
112113
if (state.isHeld) {
113114
state.hasPendingSweep = true;
114-
D.assert(this._debugLogDiagnostic(pointer, "Delaying sweep", state));
115+
D.assert(this._debugLogDiagnostic(pointer, () => "Delaying sweep", state));
115116
return;
116117
}
117118

118-
D.assert(this._debugLogDiagnostic(pointer, "Sweeping", state));
119+
D.assert(this._debugLogDiagnostic(pointer, () => "Sweeping", state));
119120
this._arenas.Remove(pointer);
120121
if (state.members.isNotEmpty()) {
121122
D.assert(this._debugLogDiagnostic(
122-
pointer, $"Winner: {state.members.First()}"));
123+
pointer, () => $"Winner: {state.members.First()}"));
123124

124125
state.members.First().acceptGesture(pointer);
125126
for (int i = 1; i < state.members.Count; i++) {
@@ -135,7 +136,7 @@ public void hold(int pointer) {
135136
}
136137

137138
state.isHeld = true;
138-
D.assert(this._debugLogDiagnostic(pointer, "Holding", state));
139+
D.assert(this._debugLogDiagnostic(pointer, () => "Holding", state));
139140
}
140141

141142
public void release(int pointer) {
@@ -145,7 +146,7 @@ public void release(int pointer) {
145146
}
146147

147148
state.isHeld = false;
148-
D.assert(this._debugLogDiagnostic(pointer, "Releasing", state));
149+
D.assert(this._debugLogDiagnostic(pointer, () => "Releasing", state));
149150
if (state.hasPendingSweep) {
150151
this.sweep(pointer);
151152
}
@@ -158,7 +159,7 @@ internal void _resolve(int pointer, GestureArenaMember member, GestureDispositio
158159
}
159160

160161
D.assert(this._debugLogDiagnostic(pointer,
161-
$"{(disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting")}: {member}"));
162+
() => $"{(disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting")}: {member}"));
162163

163164
D.assert(state.members.Contains(member));
164165
if (disposition == GestureDisposition.rejected) {
@@ -174,7 +175,7 @@ internal void _resolve(int pointer, GestureArenaMember member, GestureDispositio
174175
}
175176
else {
176177
D.assert(this._debugLogDiagnostic(pointer,
177-
$"Self-declared winner: {member}"));
178+
() => $"Self-declared winner: {member}"));
178179
this._resolveInFavorOf(pointer, state, member);
179180
}
180181
}
@@ -189,11 +190,11 @@ void _tryToResolveArena(int pointer, _GestureArena state) {
189190
}
190191
else if (state.members.isEmpty()) {
191192
this._arenas.Remove(pointer);
192-
D.assert(this._debugLogDiagnostic(pointer, "Arena empty."));
193+
D.assert(this._debugLogDiagnostic(pointer, () => "Arena empty."));
193194
}
194195
else if (state.eagerWinner != null) {
195196
D.assert(this._debugLogDiagnostic(pointer,
196-
$"Eager winner: {state.eagerWinner}"));
197+
() => $"Eager winner: {state.eagerWinner}"));
197198
this._resolveInFavorOf(pointer, state, state.eagerWinner);
198199
}
199200
}
@@ -209,7 +210,7 @@ void _resolveByDefault(int pointer, _GestureArena state) {
209210
D.assert(members.Count == 1);
210211
this._arenas.Remove(pointer);
211212
D.assert(this._debugLogDiagnostic(pointer,
212-
$"Default winner: {state.members.First()}"));
213+
() => $"Default winner: {state.members.First()}"));
213214
state.members.First().acceptGesture(pointer);
214215
}
215216

@@ -229,14 +230,14 @@ void _resolveInFavorOf(int pointer, _GestureArena state, GestureArenaMember memb
229230
member.acceptGesture(pointer);
230231
}
231232

232-
bool _debugLogDiagnostic(int pointer, string message, _GestureArena state = null) {
233+
bool _debugLogDiagnostic(int pointer, Func<string> message, _GestureArena state = null) {
233234
D.assert(() => {
234235
if (D.debugPrintGestureArenaDiagnostics) {
235-
int? count = state != null ? state.members.Count : (int?) null;
236+
int? count = state?.members.Count;
236237
string s = count != 1 ? "s" : "";
237238
Debug.LogFormat("Gesture arena {0} ❙ {1}{2}",
238239
pointer.ToString().PadRight(4),
239-
message,
240+
message(),
240241
count != null ? $" with {count} member{s}." : "");
241242
}
242243

Runtime/gestures/recognizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ protected PrimaryPointerGestureRecognizer(
207207
float? postAcceptSlopTolerance = Constants.kTouchSlop
208208
) : base(debugOwner: debugOwner, kind: kind) {
209209
D.assert(preAcceptSlopTolerance == null || preAcceptSlopTolerance >= 0,
210-
"The preAcceptSlopTolerance must be positive or null");
210+
() => "The preAcceptSlopTolerance must be positive or null");
211211

212212
D.assert(postAcceptSlopTolerance == null || postAcceptSlopTolerance >= 0,
213-
"The postAcceptSlopTolerance must be positive or null");
213+
() => "The postAcceptSlopTolerance must be positive or null");
214214

215215
this.deadline = deadline;
216216
this.preAcceptSlopTolerance = preAcceptSlopTolerance;

Runtime/material/app_bar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public SliverAppBar(
546546
bool pinned = false,
547547
bool snap = false
548548
) : base(key: key) {
549-
D.assert(floating || !snap, "The 'snap' argument only makes sense for floating app bars.");
549+
D.assert(floating || !snap, () => "The 'snap' argument only makes sense for floating app bars.");
550550
this.leading = leading;
551551
this.automaticallyImplyLeading = true;
552552
this.title = title;

Runtime/material/bottom_navigation_bar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public BottomNavigationBar(
4343
D.assert(items != null);
4444
D.assert(items.Count >= 2);
4545
D.assert(items.All((BottomNavigationBarItem item) => item.title != null) == true,
46-
"Every item must have a non-null title"
46+
() => "Every item must have a non-null title"
4747
);
4848
D.assert(0 <= currentIndex && currentIndex < items.Count);
4949
this.items = items;

Runtime/material/chip.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ public ActionChip(
844844
D.assert(label != null);
845845
D.assert(
846846
onPressed != null,
847-
"Rather than disabling an ActionChip by setting onPressed to null, " +
847+
() => "Rather than disabling an ActionChip by setting onPressed to null, " +
848848
"remove it from the interface entirely."
849849
);
850850
D.assert(pressElevation == null || pressElevation >= 0.0f);
@@ -1718,7 +1718,7 @@ protected override void removeChildRenderObject(RenderObject child) {
17181718
}
17191719

17201720
protected override void moveChildRenderObject(RenderObject child, object slotValue) {
1721-
D.assert(false, "not reachable");
1721+
D.assert(false, () => "not reachable");
17221722
}
17231723
}
17241724

@@ -2187,10 +2187,10 @@ Offset centerLayout(Size boxSize, float x) {
21872187
);
21882188
this.size = this.constraints.constrain(paddedSize);
21892189
D.assert(this.size.height == this.constraints.constrainHeight(paddedSize.height),
2190-
$"Constrained height {this.size.height} doesn't match expected height " +
2190+
() => $"Constrained height {this.size.height} doesn't match expected height " +
21912191
$"{this.constraints.constrainWidth(paddedSize.height)}");
21922192
D.assert(this.size.width == this.constraints.constrainWidth(paddedSize.width),
2193-
$"Constrained width {this.size.width} doesn't match expected width " +
2193+
() => $"Constrained width {this.size.width} doesn't match expected width " +
21942194
$"{this.constraints.constrainWidth(paddedSize.width)}");
21952195
}
21962196

0 commit comments

Comments
 (0)