浏览代码

stash changes

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
bc758b2b
共有 5 个文件被更改,包括 430 次插入136 次删除
  1. 376
      com.unity.uiwidgets/Runtime/foundation/assertions.cs
  2. 9
      com.unity.uiwidgets/Runtime/foundation/binding.cs
  3. 15
      com.unity.uiwidgets/Runtime/foundation/change_notifier.cs
  4. 160
      com.unity.uiwidgets/Runtime/foundation/diagnostics.cs
  5. 6
      com.unity.uiwidgets/Runtime/foundation/print.cs

376
com.unity.uiwidgets/Runtime/foundation/assertions.cs


namespace Unity.UIWidgets.foundation {
public delegate void UIWidgetsExceptionHandler(UIWidgetsErrorDetails details);
public delegate void InformationCollector(StringBuilder information);
public delegate IEnumerable<DiagnosticsNode> DiagnosticPropertiesTransformer(IEnumerable<DiagnosticsNode> properties);
public delegate IEnumerable<DiagnosticsNode> InformationCollector();
internal abstract class _ErrorDiagnostic : DiagnosticsProperty<List<object>> {
internal _ErrorDiagnostic(
String message,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name: null,
value: new List<object>() {message},
showName: false,
showSeparator: false,
defaultValue: null,
style: style,
level: level) {
D.assert(message != null);
}
internal _ErrorDiagnostic(
List<object> messageParts,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name: null,
value: messageParts,
showName: false,
showSeparator: false,
defaultValue: null,
style: style,
level: level) {
D.assert(messageParts != null);
}
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
return string.Join("", value);
}
}
internal class ErrorDescription : _ErrorDiagnostic {
public ErrorDescription(string message) : base(message, level: DiagnosticLevel.info) {
}
public ErrorDescription(List<object> messageParts) : base(messageParts, level: DiagnosticLevel.info) {
}
}
internal class ErrorSummary : _ErrorDiagnostic {
public ErrorSummary(string message) : base(message, level: DiagnosticLevel.summary) {
}
public ErrorSummary(List<object> messageParts) : base(messageParts, level: DiagnosticLevel.summary) {
}
}
internal class ErrorHint : _ErrorDiagnostic {
public ErrorHint(string message) : base(message, level: DiagnosticLevel.hint) {
}
public ErrorHint(List<object> messageParts) : base(messageParts, level: DiagnosticLevel.hint) {
}
}
public class ErrorSpacer : DiagnosticsProperty<object> {
public ErrorSpacer() : base(

}
}
public class UIWidgetsErrorDetails {
public class UIWidgetsErrorDetails : Diagnosticable {
string context = null,
DiagnosticsNode context = null,
IterableFilter<string> stackFilter = null,
InformationCollector informationCollector = null,
bool silent = false

this.informationCollector = informationCollector;
this.silent = silent;
}
public static readonly List<DiagnosticPropertiesTransformer> propertiesTransformers =
new List<DiagnosticPropertiesTransformer>();
public readonly string context;
public readonly DiagnosticsNode context;
public readonly bool silent;
public string exceptionAsString() {

return longMessage;
}
public override string ToString() {
var buffer = new StringBuilder();
if (library.isNotEmpty() || context.isNotEmpty()) {
if (library.isNotEmpty()) {
buffer.AppendFormat("Error caught by {0}", library);
if (context.isNotEmpty()) {
buffer.Append(", ");
}
Diagnosticable _exceptionToDiagnosticable() {
return null;
}
public DiagnosticsNode summary {
get {
string formatException() {
return exceptionAsString().Split('\n')[0].TrimStart();
else {
buffer.Append("Exception ");
if (foundation_.kReleaseMode) {
return DiagnosticsNode.message(formatException());
if (context.isNotEmpty()) {
buffer.AppendFormat("thrown {0}", context);
Diagnosticable diagnosticable = this._exceptionToDiagnosticable();
DiagnosticsNode summary = null;
if (diagnosticable != null) {
DiagnosticPropertiesBuilder builder = new DiagnosticPropertiesBuilder();
debugFillProperties(builder);
summary = builder.properties.First((DiagnosticsNode node) => node.level == DiagnosticLevel.summary);
buffer.Append(". ");
return summary ?? new ErrorSummary(formatException());
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
DiagnosticsNode verb = context != null
? new ErrorDescription($"thrown {new ErrorDescription($" {context}")}")
: new ErrorDescription("");
Diagnosticable diagnosticable = this._exceptionToDiagnosticable();
if (exception is NullReferenceException) {
properties.add(new ErrorDescription($"The null value was {verb}."));
buffer.Append("An error was caught. ");
DiagnosticsNode errorName;
errorName = new ErrorDescription($"{exception.GetType()}");
properties.add(new ErrorDescription($"The following {errorName} was {verb}:"));
if (diagnosticable != null) {
diagnosticable.debugFillProperties(properties);
}
else {
string prefix = $"{exception.GetType()}";
string message = exceptionAsString();
if (message.StartsWith(prefix)) {
message = message.Substring(prefix.Length);
}
properties.add(new ErrorSummary(message));
}
buffer.AppendLine(exceptionAsString());
informationCollector(buffer);
properties.add(new ErrorSpacer());
foreach (var diagnosticsNode in informationCollector()) {
properties.add(diagnosticsNode);
}
}
if (exception.StackTrace != null) {
IEnumerable<string> stackLines = exception.StackTrace.TrimEnd().Split('\n');
if (stackFilter != null) {
stackLines = stackFilter(stackLines);
public override string toStringShort() {
return library != null ? $"Exception caught by {library}" : "Exception caught";
}
public override string toString(DiagnosticLevel minLevel = DiagnosticLevel.info) {
return toDiagnosticsNode(style: DiagnosticsTreeStyle.error).toStringDeep(minLevel: minLevel);
}
public override DiagnosticsNode toDiagnosticsNode(string name = null,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.sparse) {
return new _UIWIdgetsErrorDetailsNode(
name: name,
value: this,
style: style
);
}
}
internal class _UIWIdgetsErrorDetailsNode : DiagnosticableNode<UIWidgetsErrorDetails> {
public _UIWIdgetsErrorDetailsNode(
string name,
UIWidgetsErrorDetails value,
DiagnosticsTreeStyle style
) : base(
name: name,
value: value,
style: style
) {
D.assert(value != null);
}
new DiagnosticPropertiesBuilder _builder {
get {
DiagnosticPropertiesBuilder builder = base._builder;
if (builder == null) {
return null;
else {
stackLines = UIWidgetsError.defaultStackFilter(stackLines);
IEnumerable<DiagnosticsNode> properties = builder.properties;
foreach (DiagnosticPropertiesTransformer transformer in UIWidgetsErrorDetails.propertiesTransformers) {
properties = transformer(properties);
buffer.Append(string.Join("\n", stackLines.ToArray()));
return new DiagnosticPropertiesBuilder(properties.ToList());
return buffer.ToString().TrimEnd();
public UIWidgetsError(string message) : base(message) {
public UIWidgetsError(string message) {
string[] lines = message.Split('\n');
this.diagnostics = new List<DiagnosticsNode>() {
new ErrorSummary(lines[0])
};
for (var i = 1; i < lines.Length; i++) {
this.diagnostics.Add(new ErrorDescription(lines[i]));
}
public UIWidgetsError(List<DiagnosticsNode> diagnostics) {
this.diagnostics = diagnostics;
D.assert(diagnostics != null && diagnostics.isNotEmpty(), () => new UIWidgetsError(new List<DiagnosticsNode>() {new ErrorSummary("Empty FlutterError")}).ToString());
D.assert(diagnostics.first().level == DiagnosticLevel.summary,
() => new UIWidgetsError(new List<DiagnosticsNode>() {
new ErrorSummary("UIWidgetsError is missing a summary."),
new ErrorDescription("All UIWidgetsError objects should start with a short (one line) " +
"summary description of the problem that was detected."),
new DiagnosticsProperty<UIWidgetsError>("Malformed", this, expandableValue: true, showSeparator: false, style : DiagnosticsTreeStyle.whitespace),
new ErrorDescription(
"\nThis error should still help you solve your problem, " +
"however please also report this malformed error in the " +
"framework by filing a bug on GitHub:\n" +
" https://https://github.com/Unity-Technologies/com.unity.uiwidgets"
)
}).ToString());
D.assert(() => {
IEnumerable<DiagnosticsNode> summaries =
diagnostics.Where((DiagnosticsNode node) => node.level == DiagnosticLevel.summary);
if (summaries.Count() > 1) {
return false;
}
return true;
}, () => {
IEnumerable<DiagnosticsNode> summaries =
diagnostics.Where((DiagnosticsNode node) => node.level == DiagnosticLevel.summary);
List<DiagnosticsNode> message = new List<DiagnosticsNode>() {
new ErrorSummary("UIWidgetsError contained multiple error summaries."),
new ErrorDescription(
"All UIWidgetsError objects should have only a single short " +
"(one line) summary description of the problem that was " +
"detected."
),
new DiagnosticsProperty<UIWidgetsError>("Malformed", this, expandableValue: true, showSeparator: false, style : DiagnosticsTreeStyle.whitespace)
};
int i = 0;
foreach (DiagnosticsNode summary in summaries) {
message.Add(new DiagnosticsProperty<DiagnosticsNode>($"Summary {i}", summary, expandableValue : true));
i += 1;
}
message.Add(new ErrorDescription(
"\nThis error should still help you solve your problem, " +
"however please also report this malformed error in the " +
"framework by filing a bug on GitHub:\n" +
" https://https://github.com/Unity-Technologies/com.unity.uiwidgets"
));
return new UIWidgetsError(message).ToString();
});
}
public readonly List<DiagnosticsNode> diagnostics;
public override string Message => ToString();
static int _errorCount = 0;
public static void resetErrorCount() {
_errorCount = 0;
}
const int wrapWidth = 100;
public static void dumpErrorToConsole(UIWidgetsErrorDetails details) {
dumpErrorToConsole(details, forceReport: false);

return;
}
D.logError(details.ToString(), details.exception);
if (_errorCount == 0 || forceReport) {
D.logError(details.ToString(), details.exception);
}
D.logError($"Another exception was thrown: ${details.summary}");
_errorCount += 1;
}
public static IEnumerable<string> defaultStackFilter(IEnumerable<string> frames) {

public static void reportError(UIWidgetsErrorDetails details) {
D.assert(details != null);
D.assert(details.exception != null);
if (onError != null) {
onError(details);
public void debugFillProperties(DiagnosticPropertiesBuilder properties) {
foreach (var diagnosticsNode in diagnostics)
{
properties.add(diagnosticsNode);
}
internal abstract class _ErrorDiagnostic : DiagnosticsProperty<List<object>> {
/// This constructor provides a reliable hook for a kernel transformer to find
/// error messages that need to be rewritten to include object references for
/// interactive display of errors.
internal _ErrorDiagnostic(
String message,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.sparse, // DiagnosticsTreeStyle.flat
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name: null,
value: new List<object>() {message},
showName: false,
showSeparator: false,
defaultValue: null,
style: style,
level: level) {
D.assert(message != null);
}
/// In debug builds, a kernel transformer rewrites calls to the default
/// constructors for [ErrorSummary], [ErrorDetails], and [ErrorHint] to use
/// this constructor.
//
// ```dart
// _ErrorDiagnostic('Element $element must be $color')
// ```
// Desugars to:
// ```dart
// _ErrorDiagnostic.fromParts(<Object>['Element ', element, ' must be ', color])
// ```
//
// Slightly more complex case:
// ```dart
// _ErrorDiagnostic('Element ${element.runtimeType} must be $color')
// ```
// Desugars to:
//```dart
// _ErrorDiagnostic.fromParts(<Object>[
// 'Element ',
// DiagnosticsProperty(null, element, description: element.runtimeType?.toString()),
// ' must be ',
// color,
// ])
// ```
internal _ErrorDiagnostic(
List<object> messageParts,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.sparse,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name: null,
value: messageParts,
showName: false,
showSeparator: false,
defaultValue: null,
style: style,
level: level) {
D.assert(messageParts != null);
}
public string toStringShort() => "UIWidgetsError";
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
return String.Join("", value);
public override string ToString() {
return string.Join("\n", diagnostics);
}
internal class ErrorDescription : _ErrorDiagnostic {
/// A lint enforces that this constructor can only be called with a string
/// literal to match the limitations of the Dart Kernel transformer that
/// optionally extracts out objects referenced using string interpolation in
/// the message passed in.
///
/// The message will display with the same text regardless of whether the
/// kernel transformer is used. The kernel transformer is required so that
/// debugging tools can provide interactive displays of objects described by
/// the error.
public ErrorDescription(string message) : base(message, level: DiagnosticLevel.info) {
}
/// Calls to the default constructor may be rewritten to use this constructor
/// in debug mode using a kernel transformer.
// ignore: unused_element
public ErrorDescription(List<object> messageParts) : base(messageParts, level: DiagnosticLevel.info) {
public static void reportError(UIWidgetsErrorDetails details) {
D.assert(details != null);
D.assert(details.exception != null);
if (onError != null) {
onError(details);
}
}
}
}

9
com.unity.uiwidgets/Runtime/foundation/binding.cs


protected BindingBase() {
Timeline.startSync("Framework initialization");
D.assert(!_debugInitialized);
D.assert(_debugInitialized);
initServiceExtensions();

}
static bool _debugInitialized = false;
D.assert(!_debugInitialized);
D.assert(() => {
_debugInitialized = true;
return true;
});
}
protected virtual void initServiceExtensions() {

15
com.unity.uiwidgets/Runtime/foundation/change_notifier.cs


}
}
catch (Exception ex) {
IEnumerable<DiagnosticsNode> infoCollector() {
yield return new DiagnosticsProperty<ChangeNotifier>(
$"The {GetType()} sending notification was",
this,
style: DiagnosticsTreeStyle.errorProperty
);
}
context: "while dispatching notifications for " + GetType(),
informationCollector: information => {
information.AppendLine("The " + GetType() + " sending notification was:");
information.Append(" " + this);
}
context: new ErrorDescription($"while dispatching notifications for {GetType()}"),
informationCollector: infoCollector
));
}
}

160
com.unity.uiwidgets/Runtime/foundation/diagnostics.cs


debug,
info,
warning,
hint,
summary,
none,
error,
flat,
shallow,
truncateChildren
}
public class DiagnosticUtils {

bool lineBreakProperties = true,
string afterName = ":",
string afterDescriptionIfBody = "",
string afterDescription = "",
string mandatoryAfterProperties = "",
string propertySeparator = "",
string bodyIndent = "",
string footer = "",

bool isBlankLineBetweenPropertiesAndChildren = true
bool isBlankLineBetweenPropertiesAndChildren = true,
string beforeName = "",
string suffixLineOne = "",
string mandatoryFooter = ""
) {
D.assert(prefixLineOne != null);
D.assert(prefixOtherLines != null);

D.assert(lineBreak != null);
D.assert(afterName != null);
D.assert(afterDescriptionIfBody != null);
D.assert(afterDescription != null);
D.assert(beforeProperties != null);
D.assert(afterProperties != null);
D.assert(propertySeparator != null);

public readonly string prefixLineOne;
public readonly string suffixLineOne;
public readonly string prefixOtherLines;
public readonly string prefixLastChildLineOne;

public readonly bool lineBreakProperties;
public readonly string beforeName;
public readonly string afterDescription;
public readonly string mandatoryAfterProperties;
public readonly string propertySeparator;

public readonly string footer;
public readonly string mandatoryFooter;
public readonly bool isBlankLineBetweenPropertiesAndChildren;
}

prefixLineOne: "╞═╦══ ",
prefixLastChildLineOne: "╘═╦══ ",
prefixOtherLines: " ║ ",
footer: " ╚═══════════\n",
footer: " ╚═══════════",
linkCharacter: "│",
propertyPrefixIfChildren: "",
propertyPrefixNoChildren: "",

addBlankLineIfNoChildren: false,
isBlankLineBetweenPropertiesAndChildren: false
);
public static readonly TextTreeConfiguration errorTextConfiguration = new TextTreeConfiguration(
prefixLineOne: "╞═╦",
prefixLastChildLineOne: "╘═╦",
prefixOtherLines: " ║ ",
footer: " ╚═══════════",
linkCharacter: "│",
propertyPrefixIfChildren: "",
propertyPrefixNoChildren: "",
prefixOtherLinesRootNode: "",
beforeName: "══╡ ",
suffixLineOne: " ╞══",
mandatoryFooter: "═════",
addBlankLineIfNoChildren: false,
isBlankLineBetweenPropertiesAndChildren: false
);
public static readonly TextTreeConfiguration whitespaceTextConfiguration = new TextTreeConfiguration(
prefixLineOne: "",

afterDescriptionIfBody: ":",
isBlankLineBetweenPropertiesAndChildren: false
);
public static readonly TextTreeConfiguration flatTextConfiguration = new TextTreeConfiguration(
prefixLineOne: "",
prefixLastChildLineOne: "",
prefixOtherLines: "",
prefixOtherLinesRootNode: "",
bodyIndent: "",
propertyPrefixIfChildren: "",
propertyPrefixNoChildren: "",
linkCharacter: "",
addBlankLineIfNoChildren: false,
afterDescriptionIfBody: ":",
isBlankLineBetweenPropertiesAndChildren: false
);
public static readonly TextTreeConfiguration singleLineTextConfiguration = new TextTreeConfiguration(
propertySeparator: ", ",

lineBreakProperties: false,
addBlankLineIfNoChildren: false,
showChildren: false,
propertyPrefixIfChildren: " ",
propertyPrefixNoChildren: " ",
linkCharacter: "",
prefixOtherLinesRootNode: ""
);
public static readonly TextTreeConfiguration errorPropertyTextConfiguration = new TextTreeConfiguration(
propertySeparator: ", ",
beforeProperties: "(",
afterProperties: ")",
prefixLineOne: "",
prefixOtherLines: "",
prefixLastChildLineOne: "",
lineBreak: "\n",
lineBreakProperties: false,
addBlankLineIfNoChildren: false,
showChildren: false,
propertyPrefixIfChildren: " ",
propertyPrefixNoChildren: " ",
linkCharacter: "",
prefixOtherLinesRootNode: "",
afterName: ":",
isNameOnOwnLine: true
);
public static readonly TextTreeConfiguration shallowTextConfiguration = new TextTreeConfiguration(
prefixLineOne: "",
prefixLastChildLineOne: "",
prefixOtherLines: " ",
prefixOtherLinesRootNode: " ",
bodyIndent: "",
linkCharacter: "",
prefixOtherLinesRootNode: ""
linkCharacter: " ",
addBlankLineIfNoChildren: false,
afterDescriptionIfBody: ":",
isBlankLineBetweenPropertiesAndChildren: false,
showChildren: false
enum _WordWrapParseMode { inSpace, inWord, atBreak }
internal _PrefixedStringBuilder(string prefixLineOne, string prefixOtherLines) {
internal _PrefixedStringBuilder(string prefixLineOne, string prefixOtherLines, int wrapWidth) {
this.prefixOtherLines = prefixOtherLines;
this._prefixOtherLines = prefixOtherLines;
this.wrapWidth = wrapWidth;
public string prefixOtherLines;
public string prefixOtherLines {
get {
return this._nextPrefixOtherLines ?? this._prefixOtherLines;
}
set {
_prefixOtherLines = value;
_nextPrefixOtherLines = null;
}
}
private string _prefixOtherLines;
private string _nextPrefixOtherLines;
void incrementPrefixOtherLines(string suffix, bool updateCurrentLine) {
if (_currentLine.)
}
public readonly int wrapWidth;
bool _atLineStart = true;
bool _hasMultipleLines = false;
readonly StringBuilder _currentLine = new StringBuilder();
readonly List<int> _wrappableRanges = new List<int>();
public bool hasMultipleLines {
get { return _hasMultipleLines; }

object defaultValue = null,
string tooltip = null,
bool missingIfNull = false,
bool expandableValue = false,
bool allowWrap = true,
bool allowNameWrap = true,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine,
DiagnosticLevel level = DiagnosticLevel.info
) : base(

this.defaultValue = defaultValue;
this.tooltip = tooltip;
this.missingIfNull = missingIfNull;
this.expandableValue = expandableValue;
this.allowWrap = allowWrap;
this.allowNameWrap = allowNameWrap;
}
internal DiagnosticsProperty(

object defaultValue = null,
string tooltip = null,
bool missingIfNull = false,
bool expandableValue = false,
bool allowWrap = true,
bool allowNameWrap = true,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine,
DiagnosticLevel level = DiagnosticLevel.info
) : base(

this.defaultValue = defaultValue;
this.tooltip = tooltip;
this.missingIfNull = missingIfNull;
this.expandableValue = expandableValue;
this.allowWrap = allowWrap;
this.allowNameWrap = allowNameWrap;
}
public static DiagnosticsProperty<T> lazy(

object defaultValue = null,
string tooltip = null,
bool missingIfNull = false,
bool expandableValue = false,
bool allowWrap = true,
bool allowNameWrap = true,
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine,
DiagnosticLevel level = DiagnosticLevel.info
) {

defaultValue,
tooltip,
missingIfNull,
expandableValue,
allowWrap,
allowNameWrap,
public readonly bool expandableValue;
public readonly bool allowWrap;
public readonly bool allowNameWrap;
public override Dictionary<string, object> toJsonMap(DiagnosticsSerializationDelegate Delegate){
T v = value;

readonly T _value;
DiagnosticPropertiesBuilder _cachedBuilder;
DiagnosticPropertiesBuilder _builder {
protected DiagnosticPropertiesBuilder _builder {
get {
if (_cachedBuilder == null) {
_cachedBuilder = new DiagnosticPropertiesBuilder();

}
public class DiagnosticPropertiesBuilder {
public DiagnosticPropertiesBuilder(List<DiagnosticsNode> properties) {
this.properties = properties;
}
public DiagnosticPropertiesBuilder() {
}
public void add(DiagnosticsNode property) {
properties.Add(property);
}

6
com.unity.uiwidgets/Runtime/foundation/print.cs


using System.Text.RegularExpressions;
namespace Unity.UIWidgets.foundation {
enum _WordWrapParseMode {
inSpace,
inWord,
atBreak
}
public static class DebugPrint {
static readonly Regex _indentPattern = new Regex("^ *(?:[-+*] |[0-9]+[.):] )?");

正在加载...
取消
保存