Skip to content
Open
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: 1 addition & 1 deletion codegen/generators/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Generator
# Automatic Code generation overrides for the Java programming language
class Java < Base
def array_type_for(type_name)
"java.util.List<#{type_name}>"
"List<#{type_name}>"
end

def format_description(raw_description, indent_string: '')
Expand Down
25 changes: 15 additions & 10 deletions codegen/templates/java.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<%= class_name(key) %>.java
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -17,10 +18,12 @@ import static java.util.Objects.requireNonNull;
<%- end -%>
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class <%= class_name(key) %> {
<%- schema['properties'].each do |property_name, property| -%>
private final <%= type_for(class_name(key), property_name, property) -%> <%= property_name %>;
<%- schema['properties'].each do |property_name, property|
nullable = !(schema['required'] || []).index(property_name)
-%>
private final <% if nullable -%>@Nullable <%- end -%><%= type_for(class_name(key), property_name, property) -%> <%= property_name %>;
<%- end -%>
<%- if (schema['required'] || []).empty? -%>
<%- schema['properties'].each do |(property_name, property)| -%>
Expand All @@ -30,7 +33,7 @@ public final class <%= class_name(key) %> {
<%- schema['properties'].each_with_index do |(property_name_2, _property_2), index| -%>
<%- if property_name_2 == property_name -%>
<%- if property['items'] -%>
unmodifiableList(new ArrayList<>(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null")))<%= index < schema['properties'].length - 1 ? ',' : '' %>
List.copyOf(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null"))<%= index < schema['properties'].length - 1 ? ',' : '' %>
<%- else -%>
requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null")<%= index < schema['properties'].length - 1 ? ',' : '' %>
<%- end -%>
Expand All @@ -44,22 +47,24 @@ public final class <%= class_name(key) %> {
<%- end -%>

public <%= class_name(key) %>(
<%- schema['properties'].each_with_index do |(property_name, property), index| -%>
<%= type_for(class_name(key), property_name, property) -%> <%= property_name %><%= index < schema['properties'].length-1 ? ',' : ''%>
<%- schema['properties'].each_with_index do |(property_name, property), index|
nullable = !(schema['required'] || []).index(property_name)
-%>
<% if nullable -%>@Nullable <%- end -%><%= type_for(class_name(key), property_name, property) -%> <%= property_name %><%= index < schema['properties'].length-1 ? ',' : ''%>
<%- end -%>
) {
<%- schema['properties'].each do |(property_name, property)|
required = (schema['required'] || []).index(property_name)
-%>
<%- if required -%>
<%- if property['items'] -%>
this.<%= property_name %> = unmodifiableList(new ArrayList<>(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null")));
this.<%= property_name %> = List.copyOf(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null"));
<%- else -%>
this.<%= property_name %> = requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null");
<%- end -%>
<%- else -%>
<%- if property['items'] -%>
this.<%= property_name %> = <%= property_name %> == null ? null : unmodifiableList(new ArrayList<>(<%= property_name %>));
this.<%= property_name %> = <%= property_name %> == null ? null : List.copyOf(<%= property_name %>);
<%- else -%>
this.<%= property_name %> = <%= property_name %>;
<%- end -%>
Expand Down
10 changes: 10 additions & 0 deletions java/.mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
9 changes: 8 additions & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-parent</artifactId>
<version>4.5.0</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>messages</artifactId>
<version>30.1.1-SNAPSHOT</version>
Expand Down Expand Up @@ -53,6 +53,13 @@
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
39 changes: 20 additions & 19 deletions java/src/generated/java/io/cucumber/messages/types/Attachment.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -23,32 +24,32 @@
* is captured in `TestResult`.
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class Attachment {
private final String body;
private final AttachmentContentEncoding contentEncoding;
private final String fileName;
private final @Nullable String fileName;
private final String mediaType;
private final Source source;
private final String testCaseStartedId;
private final String testStepId;
private final String url;
private final String testRunStartedId;
private final String testRunHookStartedId;
private final Timestamp timestamp;
private final @Nullable Source source;
private final @Nullable String testCaseStartedId;
private final @Nullable String testStepId;
private final @Nullable String url;
private final @Nullable String testRunStartedId;
private final @Nullable String testRunHookStartedId;
private final @Nullable Timestamp timestamp;

public Attachment(
String body,
AttachmentContentEncoding contentEncoding,
String fileName,
@Nullable String fileName,
String mediaType,
Source source,
String testCaseStartedId,
String testStepId,
String url,
String testRunStartedId,
String testRunHookStartedId,
Timestamp timestamp
@Nullable Source source,
@Nullable String testCaseStartedId,
@Nullable String testStepId,
@Nullable String url,
@Nullable String testRunStartedId,
@Nullable String testRunHookStartedId,
@Nullable Timestamp timestamp
) {
this.body = requireNonNull(body, "Attachment.body cannot be null");
this.contentEncoding = requireNonNull(contentEncoding, "Attachment.contentEncoding cannot be null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
* Represents the Background message in <a href=https://github.com/cucumber/messages>Cucumber's message protocol</a>
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class Background {
private final Location location;
private final String keyword;
private final String name;
private final String description;
private final java.util.List<Step> steps;
private final List<Step> steps;
private final String id;

public Background(
Location location,
String keyword,
String name,
String description,
java.util.List<Step> steps,
List<Step> steps,
String id
) {
this.location = requireNonNull(location, "Background.location cannot be null");
this.keyword = requireNonNull(keyword, "Background.keyword cannot be null");
this.name = requireNonNull(name, "Background.name cannot be null");
this.description = requireNonNull(description, "Background.description cannot be null");
this.steps = unmodifiableList(new ArrayList<>(requireNonNull(steps, "Background.steps cannot be null")));
this.steps = List.copyOf(requireNonNull(steps, "Background.steps cannot be null"));
this.id = requireNonNull(id, "Background.id cannot be null");
}

Expand All @@ -55,7 +56,7 @@ public String getDescription() {
return description;
}

public java.util.List<Step> getSteps() {
public List<Step> getSteps() {
return steps;
}

Expand Down
19 changes: 10 additions & 9 deletions java/src/generated/java/io/cucumber/messages/types/Ci.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -13,18 +14,18 @@
* CI environment
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class Ci {
private final String name;
private final String url;
private final String buildNumber;
private final Git git;
private final @Nullable String url;
private final @Nullable String buildNumber;
private final @Nullable Git git;

public Ci(
String name,
String url,
String buildNumber,
Git git
@Nullable String url,
@Nullable String buildNumber,
@Nullable Git git
) {
this.name = requireNonNull(name, "Ci.name cannot be null");
this.url = url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -13,7 +14,7 @@
* A comment in a Gherkin document
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class Comment {
private final Location location;
private final String text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
* Represents the DataTable message in <a href=https://github.com/cucumber/messages>Cucumber's message protocol</a>
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class DataTable {
private final Location location;
private final java.util.List<TableRow> rows;
private final List<TableRow> rows;

public DataTable(
Location location,
java.util.List<TableRow> rows
List<TableRow> rows
) {
this.location = requireNonNull(location, "DataTable.location cannot be null");
this.rows = unmodifiableList(new ArrayList<>(requireNonNull(rows, "DataTable.rows cannot be null")));
this.rows = List.copyOf(requireNonNull(rows, "DataTable.rows cannot be null"));
}

public Location getLocation() {
return location;
}

public java.util.List<TableRow> getRows() {
public List<TableRow> getRows() {
return rows;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
* Represents the DocString message in <a href=https://github.com/cucumber/messages>Cucumber's message protocol</a>
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class DocString {
private final Location location;
private final String mediaType;
private final @Nullable String mediaType;
private final String content;
private final String delimiter;

public DocString(
Location location,
String mediaType,
@Nullable String mediaType,
String content,
String delimiter
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -14,7 +15,7 @@
* of message is used.
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class Duration {
private final Long seconds;
private final Long nanos;
Expand Down
Loading
Loading