Skip to content

Commit 0bf5e9e

Browse files
[dotnet] Annotate nullability on interactions (#15152)
1 parent c882e14 commit 0bf5e9e

File tree

8 files changed

+31
-49
lines changed

8 files changed

+31
-49
lines changed

dotnet/src/webdriver/ElementCoordinates.cs

+9-22
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,40 @@
2121
using OpenQA.Selenium.Internal;
2222
using System;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium
2527
{
2628
/// <summary>
2729
/// Defines the interface through which the user can discover where an element is on the screen.
2830
/// </summary>
29-
internal class ElementCoordinates : ICoordinates
31+
internal sealed class ElementCoordinates : ICoordinates
3032
{
31-
private WebElement element;
33+
private readonly WebElement element;
3234

3335
/// <summary>
3436
/// Initializes a new instance of the <see cref="ElementCoordinates"/> class.
3537
/// </summary>
3638
/// <param name="element">The <see cref="WebElement"/> to be located.</param>
3739
public ElementCoordinates(WebElement element)
3840
{
39-
this.element = element;
41+
this.element = element ?? throw new ArgumentNullException(nameof(element));
4042
}
4143

4244
/// <summary>
4345
/// Gets the location of an element in absolute screen coordinates.
4446
/// </summary>
45-
public System.Drawing.Point LocationOnScreen
46-
{
47-
get { throw new NotImplementedException(); }
48-
}
47+
public System.Drawing.Point LocationOnScreen => throw new NotImplementedException();
4948

5049
/// <summary>
5150
/// Gets the location of an element relative to the origin of the view port.
5251
/// </summary>
53-
public System.Drawing.Point LocationInViewport
54-
{
55-
get { return this.element.LocationOnScreenOnceScrolledIntoView; }
56-
}
52+
public System.Drawing.Point LocationInViewport => this.element.LocationOnScreenOnceScrolledIntoView;
5753

5854
/// <summary>
5955
/// Gets the location of an element's position within the HTML DOM.
6056
/// </summary>
61-
public System.Drawing.Point LocationInDom
62-
{
63-
get { return this.element.Location; }
64-
}
57+
public System.Drawing.Point LocationInDom => this.element.Location;
6558

6659
/// <summary>
6760
/// Gets a locator providing a user-defined location for this element.
@@ -70,17 +63,11 @@ public object AuxiliaryLocator
7063
{
7164
get
7265
{
73-
IWebDriverObjectReference elementReference = this.element as IWebDriverObjectReference;
74-
if (elementReference == null)
75-
{
76-
return null;
77-
}
78-
7966
// Note that the OSS dialect of the wire protocol for the Actions API
8067
// uses the raw ID of the element, not an element reference. To use this,
8168
// extract the ID using the well-known key to the dictionary for element
8269
// references.
83-
return elementReference.ObjectReferenceId;
70+
return ((IWebDriverObjectReference)this.element).ObjectReferenceId;
8471
}
8572
}
8673
}

dotnet/src/webdriver/Interactions/ActionSequence.cs

+6-12
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
using System.Globalization;
2323
using System.Text;
2424

25+
#nullable enable
26+
2527
namespace OpenQA.Selenium.Interactions
2628
{
2729
/// <summary>
2830
/// Represents a sequence of actions to be performed in the target browser.
2931
/// </summary>
3032
public class ActionSequence
3133
{
32-
private List<Interaction> interactions = new List<Interaction>();
34+
private readonly List<Interaction> interactions = new List<Interaction>();
3335

3436
/// <summary>
3537
/// Initializes a new instance of the <see cref="ActionSequence"/> class.
@@ -47,26 +49,18 @@ public ActionSequence(InputDevice device)
4749
/// <param name="initialSize">the initial size of the sequence.</param>
4850
public ActionSequence(InputDevice device, int initialSize)
4951
{
50-
if (device == null)
51-
{
52-
throw new ArgumentNullException(nameof(device), "Input device cannot be null.");
53-
}
54-
55-
this.InputDevice = device;
52+
this.InputDevice = device ?? throw new ArgumentNullException(nameof(device), "Input device cannot be null.");
5653

5754
for (int i = 0; i < initialSize; i++)
5855
{
59-
this.AddAction(new PauseInteraction(device, TimeSpan.Zero));
56+
this.AddAction(new PauseInteraction(this.InputDevice, TimeSpan.Zero));
6057
}
6158
}
6259

6360
/// <summary>
6461
/// Gets the count of actions in the sequence.
6562
/// </summary>
66-
public int Count
67-
{
68-
get { return this.interactions.Count; }
69-
}
63+
public int Count => this.interactions.Count;
7064

7165
/// <summary>
7266
/// Gets the input device for this Action sequence.

dotnet/src/webdriver/Interactions/IAction.cs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
2022
namespace OpenQA.Selenium.Interactions
2123
{
2224
/// <summary>

dotnet/src/webdriver/Interactions/ICoordinates.cs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
using System.Drawing;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium.Interactions.Internal
2325
{
2426
/// <summary>

dotnet/src/webdriver/Interactions/InputDeviceKind.cs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
2022
namespace OpenQA.Selenium.Interactions
2123
{
2224
/// <summary>

dotnet/src/webdriver/Interactions/Interaction.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,28 @@
2020
using System;
2121
using System.Collections.Generic;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium.Interactions
2426
{
2527
/// <summary>
2628
/// Represents a single interaction for a given input device.
2729
/// </summary>
2830
public abstract class Interaction
2931
{
30-
private InputDevice sourceDevice;
31-
3232
/// <summary>
3333
/// Initializes a new instance of the <see cref="Interaction"/> class.
3434
/// </summary>
3535
/// <param name="sourceDevice">The input device which performs this action.</param>
3636
protected Interaction(InputDevice sourceDevice)
3737
{
38-
if (sourceDevice == null)
39-
{
40-
throw new ArgumentNullException(nameof(sourceDevice), "Source device cannot be null");
41-
}
42-
43-
this.sourceDevice = sourceDevice;
38+
this.SourceDevice = sourceDevice ?? throw new ArgumentNullException(nameof(sourceDevice), "Source device cannot be null");
4439
}
4540

4641
/// <summary>
4742
/// Gets the device for which this action is intended.
4843
/// </summary>
49-
public InputDevice SourceDevice
50-
{
51-
get { return this.sourceDevice; }
52-
}
44+
public InputDevice SourceDevice { get; }
5345

5446
/// <summary>
5547
/// Returns a value for this action that can be transmitted across the wire to a remote end.
@@ -65,7 +57,7 @@ public InputDevice SourceDevice
6557
/// otherwise, <see langword="false"/>.</returns>
6658
public virtual bool IsValidFor(InputDeviceKind sourceDeviceKind)
6759
{
68-
return this.sourceDevice.DeviceKind == sourceDeviceKind;
60+
return this.SourceDevice.DeviceKind == sourceDeviceKind;
6961
}
7062
}
7163
}

dotnet/src/webdriver/Interactions/PauseInteraction.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
using System.Collections.Generic;
2222
using System.Globalization;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.Interactions
2527
{
2628
/// <summary>
2729
/// Represents a pause action.
2830
/// </summary>
2931
internal class PauseInteraction : Interaction
3032
{
31-
private TimeSpan duration = TimeSpan.Zero;
33+
private readonly TimeSpan duration = TimeSpan.Zero;
3234

3335
/// <summary>
3436
/// Initializes a new instance of the <see cref="PauseInteraction"/> class.

dotnet/src/webdriver/WebElement.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable,
4848
/// </summary>
4949
/// <param name="parentDriver">The <see cref="WebDriver"/> instance that is driving this element.</param>
5050
/// <param name="id">The ID value provided to identify the element.</param>
51+
/// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langword="null"/>.</exception>
5152
public WebElement(WebDriver parentDriver, string id)
5253
{
5354
this.driver = parentDriver;
54-
this.elementId = id;
55+
this.elementId = id ?? throw new ArgumentNullException(nameof(id));
5556
}
5657

5758
/// <summary>

0 commit comments

Comments
 (0)