Skip to content

Commit 12139fa

Browse files
author
Kapil Borle
committed
Add argument checking to textedit constructors
1 parent 717da67 commit 12139fa

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

Engine/TextEdit.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer
77
{
8-
// TODO instead of deriving from Range, make Range a member type.
98
/// <summary>
109
/// Class to provide information about an edit
1110
/// </summary>
@@ -55,14 +54,23 @@ public TextEdit(
5554
string newText)
5655
: base(startLineNumber, startColumnNumber, endLineNumber, endColumnNumber)
5756
{
58-
// Instead of outputting a text object TextEdit should output an array of strings
59-
// such that each string represents a line. Also for each each line, there should
60-
// be some information to encode the indentation level. Let the client decide the
61-
// new line characters to insert between each line and the indentation type (space or tab)
57+
if (newText == null)
58+
{
59+
throw new ArgumentNullException(nameof(newText));
60+
}
61+
6262
Text = newText;
6363
Lines = Text.GetLines().ToArray();
6464
}
6565

66+
/// <summary>
67+
/// Constructs a TextEdit object.
68+
/// </summary>
69+
/// <param name="startLineNumber">1-based line number on which the text, which needs to be replaced, starts. </param>
70+
/// <param name="startColumnNumber">1-based offset on start line at which the text, which needs to be replaced, starts. This includes the first character of the text. </param>
71+
/// <param name="endLineNumber">1-based line number on which the text, which needs to be replace, ends. </param>
72+
/// <param name="endColumnNumber">1-based offset on end line at which the text, which needs to be replaced, ends. This offset value is 1 more than the offset of the last character of the text. </param>
73+
/// <param name="lines">The contiguous lines that will replace the text bounded by the Line/Column number properties. </param>
6674
public TextEdit(
6775
int startLineNumber,
6876
int startColumnNumber,
@@ -71,11 +79,19 @@ public TextEdit(
7179
IEnumerable<String> lines)
7280
: base(startLineNumber, startColumnNumber, endLineNumber, endColumnNumber)
7381
{
74-
// TODO check arguments
82+
if (lines == null)
83+
{
84+
throw new ArgumentNullException(nameof(lines));
85+
}
86+
87+
if (lines.Any(line => line == null))
88+
{
89+
// TODO localize
90+
throw new ArgumentException("Lines cannot contain a null element.", nameof(lines));
91+
}
92+
7593
Lines = lines.ToArray();
7694
Text = String.Join(Environment.NewLine, Lines);
7795
}
78-
79-
8096
}
8197
}

0 commit comments

Comments
 (0)