Skip to content

[java] Add nullness for interactions #15095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading