Skip to content

Commit

Permalink
Add Nullable reference type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
udaken committed Jun 23, 2022
1 parent 768de4d commit 44824be
Show file tree
Hide file tree
Showing 82 changed files with 504 additions and 366 deletions.
16 changes: 8 additions & 8 deletions src/SharpYaml/Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public class Emitter : IEmitter

private class MutableStringLookAheadBuffer : ILookAheadBuffer
{
private string value;
private string? value;

public string Value
public string? Value
{
get { return value; }
set
Expand Down Expand Up @@ -135,16 +135,16 @@ public void Cache(int length) { }

private struct AnchorData
{
public string anchor;
public string? anchor;
public bool isAlias;
}

private AnchorData anchorData;

private struct TagData
{
public string handle;
public string suffix;
public string? handle;
public string? suffix;
}

private TagData tagData;
Expand Down Expand Up @@ -313,7 +313,7 @@ private bool NeedMoreEvents()
return true;
}

private void AnalyzeAnchor(string anchor, bool isAlias)
private void AnalyzeAnchor(string? anchor, bool isAlias)
{
anchorData.anchor = anchor;
anchorData.isAlias = isAlias;
Expand Down Expand Up @@ -1680,7 +1680,7 @@ private void EmitFlowMappingKey(ParsingEvent evt, bool isFirst)

private const int MaxAliasLength = 128;

private static int SafeStringLength(string value)
private static int SafeStringLength(string? value)
{
return value != null ? value.Length : 0;
}
Expand Down Expand Up @@ -1851,7 +1851,7 @@ private void WriteBlockScalarHints(string value)

isOpenEnded = false;

string chomp_hint = null;
string? chomp_hint = null;
if (value.Length == 0 || !analyzer.IsBreak(value.Length - 1))
{
chomp_hint = "-";
Expand Down
8 changes: 4 additions & 4 deletions src/SharpYaml/EventReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ public bool Accept<T>() where T : Event
/// </summary>
/// <typeparam name="T">Type of the <see cref="Event"/>.</typeparam>
/// <returns>Returns the current event if it is of type T; otherwise returns null.</returns>
public T Allow<T>() where T : Event
public T? Allow<T>() where T : Event
{
if (!Accept<T>())
{
return null;
}
var yamlEvent = (T)Parser.Current;
var yamlEvent = (T?)Parser.Current;
MoveNext();
return yamlEvent;
}
Expand All @@ -144,13 +144,13 @@ public T Allow<T>() where T : Event
/// </summary>
/// <typeparam name="T">Type of the <see cref="Event"/>.</typeparam>
/// <returns>Returns the current event if it is of type T; otherwise returns null.</returns>
public T Peek<T>() where T : Event
public T? Peek<T>() where T : Event
{
if (!Accept<T>())
{
return null;
}
var yamlEvent = (T)Parser.Current;
var yamlEvent = (T?)Parser.Current;
return yamlEvent;
}

Expand Down
8 changes: 4 additions & 4 deletions src/SharpYaml/Events/DocumentStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public sealed class DocumentStart : ParsingEvent
/// Gets the tags.
/// </summary>
/// <value>The tags.</value>
public TagDirectiveCollection Tags { get; }
public TagDirectiveCollection? Tags { get; }

/// <summary>
/// Gets the version.
/// </summary>
/// <value>The version.</value>
public VersionDirective Version { get; }
public VersionDirective? Version { get; }

/// <summary>
/// Gets a value indicating whether this instance is implicit.
Expand All @@ -94,7 +94,7 @@ public sealed class DocumentStart : ParsingEvent
/// <param name="isImplicit">Indicates whether the event is implicit.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public DocumentStart(VersionDirective version, TagDirectiveCollection tags, bool isImplicit, Mark start, Mark end)
public DocumentStart(VersionDirective? version, TagDirectiveCollection? tags, bool isImplicit, Mark start, Mark end)
: base(start, end)
{
this.Version = version;
Expand All @@ -108,7 +108,7 @@ public DocumentStart(VersionDirective version, TagDirectiveCollection tags, bool
/// <param name="version">The version.</param>
/// <param name="tags">The tags.</param>
/// <param name="isImplicit">Indicates whether the event is implicit.</param>
public DocumentStart(VersionDirective version, TagDirectiveCollection tags, bool isImplicit)
public DocumentStart(VersionDirective? version, TagDirectiveCollection? tags, bool isImplicit)
: this(version, tags, isImplicit, Mark.Empty, Mark.Empty)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/SharpYaml/Events/MappingStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public sealed class MappingStart : NodeEvent
/// <param name="style">The style of the mapping.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public MappingStart(string anchor, string tag, bool isImplicit, YamlStyle style, Mark start, Mark end)
public MappingStart(string? anchor, string? tag, bool isImplicit, YamlStyle style, Mark start, Mark end)
: base(anchor, tag, start, end)
{
this.IsImplicit = isImplicit;
Expand All @@ -107,7 +107,7 @@ public MappingStart(string anchor, string tag, bool isImplicit, YamlStyle style,
/// <param name="tag">The tag.</param>
/// <param name="isImplicit">Indicates whether the event is implicit.</param>
/// <param name="style">The style of the mapping.</param>
public MappingStart(string anchor, string tag, bool isImplicit, YamlStyle style)
public MappingStart(string? anchor, string? tag, bool isImplicit, YamlStyle style)
: this(anchor, tag, isImplicit, style, Mark.Empty, Mark.Empty)
{
}
Expand Down
8 changes: 4 additions & 4 deletions src/SharpYaml/Events/NodeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public abstract class NodeEvent : ParsingEvent
/// Gets the anchor.
/// </summary>
/// <value></value>
public string Anchor { get; }
public string? Anchor { get; }

/// <summary>
/// Gets the tag.
/// </summary>
/// <value></value>
public string Tag { get; }
public string? Tag { get; }

/// <summary>
/// Gets a value indicating whether this instance is canonical.
Expand All @@ -80,7 +80,7 @@ public abstract class NodeEvent : ParsingEvent
/// <param name="tag">The tag.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
protected NodeEvent(string anchor, string tag, Mark start, Mark end)
protected NodeEvent(string? anchor, string? tag, Mark start, Mark end)
: base(start, end)
{
if (anchor != null)
Expand Down Expand Up @@ -108,7 +108,7 @@ protected NodeEvent(string anchor, string tag, Mark start, Mark end)
/// <summary>
/// Initializes a new instance of the <see cref="NodeEvent"/> class.
/// </summary>
protected NodeEvent(string anchor, string tag)
protected NodeEvent(string? anchor, string? tag)
: this(anchor, tag, Mark.Empty, Mark.Empty)
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/SharpYaml/Events/Scalar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public sealed class Scalar : NodeEvent
/// <param name="isQuotedImplicit">.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public Scalar(string anchor, string tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit, Mark start, Mark end)
public Scalar(string? anchor, string? tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit, Mark start, Mark end)
: base(anchor, tag, start, end)
{
this.Value = value;
Expand All @@ -123,7 +123,7 @@ public Scalar(string anchor, string tag, string value, ScalarStyle style, bool i
/// <param name="style">The style.</param>
/// <param name="isPlainImplicit">.</param>
/// <param name="isQuotedImplicit">.</param>
public Scalar(string anchor, string tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit)
public Scalar(string? anchor, string? tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit)
: this(anchor, tag, value, style, isPlainImplicit, isQuotedImplicit, Mark.Empty, Mark.Empty)
{
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public Scalar(string value, ScalarStyle style)
/// </summary>
/// <param name="tag">The tag.</param>
/// <param name="value">The value.</param>
public Scalar(string tag, string value)
public Scalar(string? tag, string value)
: this(null, tag, value, ScalarStyle.Any, true, true, Mark.Empty, Mark.Empty)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/SharpYaml/Events/SequenceStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public SequenceStart() : base(null, null)
/// <param name="style">The style.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public SequenceStart(string anchor, string tag, bool isImplicit, YamlStyle style, Mark start, Mark end)
public SequenceStart(string? anchor, string? tag, bool isImplicit, YamlStyle style, Mark start, Mark end)
: base(anchor, tag, start, end)
{
this.IsImplicit = isImplicit;
Expand All @@ -111,7 +111,7 @@ public SequenceStart(string anchor, string tag, bool isImplicit, YamlStyle style
/// <summary>
/// Initializes a new instance of the <see cref="SequenceStart"/> class.
/// </summary>
public SequenceStart(string anchor, string tag, bool isImplicit, YamlStyle style)
public SequenceStart(string? anchor, string? tag, bool isImplicit, YamlStyle style)
: this(anchor, tag, isImplicit, style, Mark.Empty, Mark.Empty)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/SharpYaml/IParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface IParser
/// <summary>
/// Gets the current event.
/// </summary>
ParsingEvent Current { get; }
ParsingEvent? Current { get; }

/// <summary>
/// Moves to the next event.
Expand Down
2 changes: 1 addition & 1 deletion src/SharpYaml/Model/PathTrie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public bool IsEmpty
get { return !Self && subPaths.Count == 0; }
}

public PathTrieNode Find(IList<ChildIndex> indices, int start)
public PathTrieNode? Find(IList<ChildIndex> indices, int start)
{
if (start == indices.Count)
return this;
Expand Down
14 changes: 7 additions & 7 deletions src/SharpYaml/Model/YamlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class YamlDocument : YamlNode
{
private DocumentStart _documentStart;
private DocumentEnd _documentEnd;
private YamlElement _contents;
private YamlElement? _contents;

public YamlDocument()
{
_documentStart = new DocumentStart(null, new TagDirectiveCollection(), true);
_documentEnd = new DocumentEnd(true);
}

YamlDocument(DocumentStart documentStart, DocumentEnd documentEnd, YamlElement contents, YamlNodeTracker tracker)
YamlDocument(DocumentStart documentStart, DocumentEnd documentEnd, YamlElement? contents, YamlNodeTracker? tracker)
{
Tracker = tracker;

Expand All @@ -46,7 +46,7 @@ public YamlDocument()
Contents = contents;
}

public static YamlDocument Load(EventReader eventReader, YamlNodeTracker tracker = null)
public static YamlDocument Load(EventReader eventReader, YamlNodeTracker? tracker = null)
{
var documentStart = eventReader.Allow<DocumentStart>();

Expand Down Expand Up @@ -85,7 +85,7 @@ public DocumentEnd DocumentEnd
}
}

public YamlElement Contents
public YamlElement? Contents
{
get { return _contents; }
set
Expand All @@ -102,7 +102,7 @@ public YamlElement Contents
}
}

public override YamlNodeTracker Tracker
public override YamlNodeTracker? Tracker
{
get { return base.Tracker; }
internal set
Expand All @@ -120,9 +120,9 @@ internal set
}
}

public override YamlNode DeepClone(YamlNodeTracker tracker = null)
public override YamlNode DeepClone(YamlNodeTracker? tracker = null)
{
return new YamlDocument(_documentStart, _documentEnd, (YamlElement)Contents?.DeepClone(), tracker);
return new YamlDocument(_documentStart, _documentEnd, (YamlElement?)Contents?.DeepClone(), tracker);
}
}
}
4 changes: 2 additions & 2 deletions src/SharpYaml/Model/YamlElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace SharpYaml.Model
{
public abstract class YamlElement : YamlNode
{
public abstract string Anchor { get; set; }
public abstract string Tag { get; set; }
public abstract string? Anchor { get; set; }
public abstract string? Tag { get; set; }
public abstract bool IsCanonical { get; }
}
}
Loading

0 comments on commit 44824be

Please sign in to comment.