Skip to content
Draft
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
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
22 changes: 20 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-parent</artifactId>
<version>4.5.0</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>gherkin-utils</artifactId>
Expand Down Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>[24.1.0,37.0.0)</version>
<version>[38.0.0-SNAPSHOT,39.0.0)</version>
</dependency>

<dependency>
Expand All @@ -55,4 +55,22 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
5 changes: 3 additions & 2 deletions java/src/main/java/io/cucumber/gherkin/utils/Accumulator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.cucumber.gherkin.utils;

public interface Accumulator {
void setDeepestLine(Long line);
Long getDeepestLine();
void setDeepestLine(Integer line);

Integer getDeepestLine();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private Acc walkTags(List<Tag> tags, GherkinDocumentHandlers<Acc> h, Acc acc, Li
return acc;
}

private Acc walkTag(Tag tag, GherkinDocumentHandlers<Acc> h, Acc acc, List<Comment> comments) {
private Acc walkTag(Tag tag, GherkinDocumentHandlers<Acc> h, Acc acc, @SuppressWarnings("unused") List<Comment> comments) {
acc.setDeepestLine(tag.getLocation().getLine());
acc = h.handleTag(tag, acc);
return acc;
Expand Down Expand Up @@ -118,7 +118,7 @@ private Acc walkTableRows(List<TableRow> tableRows, GherkinDocumentHandlers<Acc>
return acc;
}

private Acc walkTableRow(TableRow tableRow, GherkinDocumentHandlers<Acc> h, Acc acc, List<Comment> comments) {
private Acc walkTableRow(TableRow tableRow, GherkinDocumentHandlers<Acc> h, Acc acc, @SuppressWarnings("unused") List<Comment> comments) {
acc.setDeepestLine(tableRow.getLocation().getLine());
acc = h.handleTableRow(tableRow, acc);
for (TableCell tableCell : tableRow.getCells()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NullMarked
package io.cucumber.gherkin.utils;

import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.ArrayList;

public class Pretty {
public final class Pretty {
/**
* Pretty print a GherkinDocument as either markdown or gherkin.
*
Expand All @@ -24,5 +24,6 @@ public static String prettyPrint(GherkinDocument gherkinDocument, Syntax syntax)
}

private Pretty() {
// utility class
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PrettyHandlers implements GherkinDocumentHandlers<Result> {
private final Syntax syntax;
private int scenarioLevel = 1;

public PrettyHandlers(List<Comment> comments, Syntax syntax) {
PrettyHandlers(List<Comment> comments, Syntax syntax) {
this.comments = comments;
this.syntax = syntax;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ private static String prettyLanguageHeader(String language) {

private String semiColumnAndName(String name) {
return (name == null || name.isEmpty()) ? ":" : ": " + name;
}
}

private Result appendScenario(
Result result,
Expand All @@ -151,7 +151,7 @@ private Result appendScenario(
appendComments(stepContainer.getLocation(), result, comments, level, true);
result.append(level == 0 ? "" : "\n");
appendComments(stepContainer.getLocation(), result, comments, level, false);

List<Tag> tags = stepContainer.getTags() != null ? stepContainer.getTags() : Collections.emptyList();
int stepCount = stepContainer.getSteps() != null ? stepContainer.getSteps().size() : 0;
String description = prettyDescription(stepContainer.getDescription(), syntax);
Expand All @@ -172,7 +172,7 @@ private Result appendFeature(
appendComments(stepContainer.getLocation(), result, comments, level, true);
result.append(level == 0 ? "" : "\n");
appendComments(stepContainer.getLocation(), result, comments, level, false);

List<Tag> tags = stepContainer.getTags() != null ? stepContainer.getTags() : Collections.emptyList();
appendTags(result, tags, syntax, level, comments);
return result.append(level == 0 ? "" : "\n")
Expand All @@ -192,7 +192,7 @@ private Result appendRule(
appendComments(stepContainer.getLocation(), result, comments, level, true);
result.append(level == 0 ? "" : "\n");
appendComments(stepContainer.getLocation(), result, comments, level, false);

List<Tag> tags = stepContainer.getTags() != null ? stepContainer.getTags() : Collections.emptyList();
String description = prettyDescription(stepContainer.getDescription(), syntax);
appendTags(result, tags, syntax, level, comments);
Expand All @@ -213,7 +213,7 @@ private Result appendExamples(
appendComments(stepContainer.getLocation(), result, comments, level, true);
result.append(level == 0 ? "" : "\n");
appendComments(stepContainer.getLocation(), result, comments, level, false);

List<Tag> tags = stepContainer.getTags() != null ? stepContainer.getTags() : Collections.emptyList();
String description = prettyDescription(stepContainer.getDescription(), syntax);
appendTags(result, tags, syntax, level, comments);
Expand All @@ -234,7 +234,7 @@ private Result appendBackground(
appendComments(stepContainer.getLocation(), result, comments, level, true);
result.append(level == 0 ? "" : "\n");
appendComments(stepContainer.getLocation(), result, comments, level, false);

int stepCount = stepContainer.getSteps() != null ? stepContainer.getSteps().size() : 0;
String description = prettyDescription(stepContainer.getDescription(), syntax);
return result
Expand Down Expand Up @@ -356,13 +356,13 @@ private List<Comment> popComments(Location currentLocation, List<Comment> commen
while (iter.hasNext()) {
Comment comment = iter.next();
if (currentLocation.getLine() > comment.getLocation().getLine()) {
if (previousBlock && comment.getText().startsWith(repeatString(level, " "))) {
// We skip this comment as we are appending previous block comments, and this comment has enough indents
// to be attached to the current block
} else {
res.add(comment);
iter.remove();
}
if (previousBlock && comment.getText().startsWith(repeatString(level, " "))) {
// We skip this comment as we are appending previous block comments, and this comment has enough indents
// to be attached to the current block
continue;
}
res.add(comment);
iter.remove();
}
}
return res;
Expand Down Expand Up @@ -396,12 +396,12 @@ private Result appendTableRow(
}

private Result appendComments(Location location, Result result, List<Comment> comments, int level, boolean previousBlock) {
int actualLevel = previousBlock ? level - 1 : level;
int actualLevel = previousBlock ? level - 1 : level;

for (Comment nextComment : popComments(location, comments, level, previousBlock)) {
appendComment(actualLevel, result, nextComment);
}

return result;
}

Expand All @@ -419,8 +419,8 @@ private void appendComment(int actualLevel, Result result, Comment nextComment)

private static int getStringWidth(String s) {
int width = 0;
for (char character : s.toCharArray()) {
width += isCJKorFullWidth(character) ? 2 : 1;
for (int i = 0, length = s.length(); i < length; i++) {
width += isCJKorFullWidth(s.charAt(i)) ? 2 : 1;
}
return width;
}
Expand All @@ -435,17 +435,10 @@ private String escapeCell(String s) {
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
switch (c) {
case '\\':
e.append("\\\\");
break;
case '\n':
e.append("\\n");
break;
case '|':
e.append("\\|");
break;
default:
e.append(c);
case '\\' -> e.append("\\\\");
case '\n' -> e.append("\\n");
case '|' -> e.append("\\|");
default -> e.append(c);
}
}
return e.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.cucumber.gherkin.utils.Accumulator;

class Result implements Accumulator {
private Long deepestLine = 0L;
private Integer deepestLine = 0;
private final StringBuilder builder = new StringBuilder();

Result append(String s) {
Expand All @@ -12,12 +12,12 @@ Result append(String s) {
}

@Override
public void setDeepestLine(Long line) {
public void setDeepestLine(Integer line) {
deepestLine = line;
}

@Override
public Long getDeepestLine() {
public Integer getDeepestLine() {
return deepestLine;
}

Expand Down
Loading
Loading