Skip to content

Commit

Permalink
[java] Add nullness for interactions (#15095)
Browse files Browse the repository at this point in the history
  • Loading branch information
mk868 authored Jan 15, 2025
1 parent 9ef48bf commit dbe3f27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/interactions/Encodable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
package org.openqa.selenium.interactions;

import java.util.Map;
import org.jspecify.annotations.NullMarked;

/**
* This interface allows a custom {@link Interaction} to be JSON encoded for the W3C wire format. It
* should not normally be exposed or used by user-facing APIs. Instead, these should traffic in the
* {@link Interaction} interface.
*/
@NullMarked
public interface Encodable {
Map<String, Object> encode();
}
3 changes: 3 additions & 0 deletions java/src/org/openqa/selenium/interactions/InputSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.openqa.selenium.interactions;

import org.jspecify.annotations.NullMarked;

/**
* Models an <a href="https://www.w3.org/TR/webdriver/#dfn-input-source">input source</a> as defined
* and used by the W3C WebDriver spec.
*/
@NullMarked
public interface InputSource {
SourceType getInputType();

Expand Down
5 changes: 4 additions & 1 deletion java/src/org/openqa/selenium/interactions/KeyInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* Models a <a href="https://www.w3.org/TR/webdriver/#dfn-key-input-source">key input source</a>.
*/
@NullMarked
public class KeyInput implements InputSource, Encodable {

private final String name;

public KeyInput(String name) {
public KeyInput(@Nullable String name) {
this.name = Optional.ofNullable(name).orElse(UUID.randomUUID().toString());
}

Expand Down
23 changes: 13 additions & 10 deletions java/src/org/openqa/selenium/interactions/PointerInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WrapsElement;
Expand All @@ -33,12 +35,13 @@
* Models a <a href="https://www.w3.org/TR/webdriver/#dfn-pointer-input-source">pointer input
* source</a>.
*/
@NullMarked
public class PointerInput implements InputSource, Encodable {

private final Kind kind;
private final String name;

public PointerInput(Kind kind, String name) {
public PointerInput(Kind kind, @Nullable String name) {
this.kind = Require.nonNull("Kind of pointer device", kind);
this.name = Optional.ofNullable(name).orElse(UUID.randomUUID().toString());
}
Expand Down Expand Up @@ -283,15 +286,15 @@ public static PointerEventProperties eventProperties() {
}

public static class PointerEventProperties implements Encodable {
private Float width = null;
private Float height = null;
private Float pressure = null;
private Float tangentialPressure = null;
private Integer tiltX = null;
private Integer tiltY = null;
private Integer twist = null;
private Float altitudeAngle = null;
private Float azimuthAngle = null;
private @Nullable Float width = null;
private @Nullable Float height = null;
private @Nullable Float pressure = null;
private @Nullable Float tangentialPressure = null;
private @Nullable Integer tiltX = null;
private @Nullable Integer tiltY = null;
private @Nullable Integer twist = null;
private @Nullable Float altitudeAngle = null;
private @Nullable Float azimuthAngle = null;

public PointerEventProperties setWidth(float width) {
Require.nonNull("width", width);
Expand Down

0 comments on commit dbe3f27

Please sign in to comment.